00001
00002
00003 #include "Iguana/WebFramework/interface/IgWeb2DService.h"
00004 #include "Iguana/GLModels/interface/IgOIVBrowser.h"
00005 #include "Iguana/Studio/interface/IgDocumentData.h"
00006 #include "Iguana/Framework/interface/IgTwig.h"
00007 #include "Iguana/WebFramework/interface/IgBrowserManager.h"
00008 #include <classlib/utils/Log.h>
00009 #include <classlib/utils/DebugAids.h>
00010 #include <classlib/utils/StringOps.h>
00011 #include <Inventor/nodes/SoCamera.h>
00012 #include <Inventor/SbLinear.h>
00013 #include <qtextstream.h>
00014 #include <qdatastream.h>
00015 #include <qiodevice.h>
00016 #include <qfile.h>
00017 #include <iostream>
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 IgWeb2DService::IgWeb2DService (IgState *state)
00031 : IgWebService (state)
00032 {
00033 registerCallback ("create", lat::CreateCallback (this, &IgWeb2DService::create));
00034 registerCallback ("browse", lat::CreateCallback (this, &IgWeb2DService::browse));
00035 }
00036
00037 void
00038 IgWeb2DService::create (Arguments *arguments)
00039 {
00040 IgState *state = arguments->state ();
00041 ArgumentsMap &args = *arguments->args ();
00042
00043 IgBrowserManager *manager = IgBrowserManager::get (state);
00044 ASSERT (manager);
00045
00046 IgBrowser *browser = new IgOIVBrowser (state, 0, (Ig3DBaseModel *) -1);
00047 std::string lookupName = "";
00048
00049 if (args.find ("name") != args.end ())
00050 lookupName = args["name"];
00051
00052 manager->add (browser, lookupName);
00053 }
00054
00055
00056 void
00057 IgWeb2DService::browse (Arguments *arguments)
00058 {
00059 using namespace lat;
00060 IgState *state = arguments->state ();
00061 QIODevice *outputDevice = arguments->outputDevice ();
00062 ArgumentsMap &args = *arguments->args ();
00063
00064 IgDocumentData *dd = IgDocumentData::get (state);
00065 IgBrowserManager *manager = IgBrowserManager::get (state);
00066
00067 std::string rootName = "";
00068 if (args.find ("root") != args.end ())
00069 rootName = args["root"];
00070
00071 IgTwig *twig = dynamic_cast <IgTwig *> (dd->root (rootName));
00072
00073 std::string browserName = "";
00074 if (args.find ("browserName") != args.end ())
00075 browserName = args["browserName"];
00076
00077 IgOIVBrowser *browser = manager->lookup<IgOIVBrowser> (browserName);
00078 ASSERT (browser);
00079
00080 browser->browse (twig);
00081
00082 if (args.find ("position") != args.end ())
00083 {
00084 float x, y, z;
00085 StringList coords = StringOps::split (args["position"], ",");
00086 if (coords.size () == 3)
00087 {
00088 x = strtof (coords[0].c_str (), 0);
00089 y = strtof (coords[1].c_str (), 0);
00090 z = strtof (coords[2].c_str (), 0);
00091 browser->getCamera ()->position = SbVec3f (x, y ,z);
00092 }
00093 }
00094
00095 if (args.find ("orientation") != args.end ())
00096 {
00097 float x,y,z,a;
00098 StringList coords = StringOps::split (args["orientation"], ",");
00099 if (coords.size () == 4)
00100 {
00101 x = strtof (coords[0].c_str (), 0);
00102 y = strtof (coords[1].c_str (), 0);
00103 z = strtof (coords[2].c_str (), 0);
00104 a = strtof (coords[3].c_str (), 0);
00105 browser->getCamera ()->orientation
00106 = SbRotation (SbVec3f (x, y ,z), a);
00107 }
00108 }
00109
00110 if (args.find ("pointAt") != args.end ())
00111 {
00112 float x,y,z;
00113 StringList coords = StringOps::split (args["pointAt"], ",");
00114 if (coords.size () == 3)
00115 {
00116 x = strtof (coords[0].c_str (), 0);
00117 y = strtof (coords[1].c_str (), 0);
00118 z = strtof (coords[2].c_str (), 0);
00119 browser->getCamera ()->pointAt (SbVec3f (x, y ,z));
00120 }
00121 }
00122
00123
00124 if (args.find ("viewAll") != args.end ())
00125 {
00126 browser->viewAll ();
00127 }
00128
00129 if (args.find ("moveCameraScreen") != args.end ())
00130 {
00131 float x, y;
00132 StringList coords
00133 = StringOps::split (args["moveCameraScreen"], ",");
00134 if (coords.size () == 2)
00135 {
00136 x = strtof (coords[0].c_str (), 0);
00137 y = strtof (coords[1].c_str (), 0);
00138 std::cerr << x << " " << y << std::endl;
00139
00140 browser->moveCameraScreen (SbVec2f (x, y));
00141 }
00142 }
00143
00144 if (args.find ("zoom") != args.end ())
00145 {
00146 float diffValue = 0;
00147 diffValue = strtof (args["zoom"].c_str (), 0);
00148 browser->zoom (diffValue);
00149 }
00150
00151 QByteArray tmpArray = browser->getJPGBuffer ();
00152 outputDevice->writeBlock (tmpArray.data (), tmpArray.size ());
00153 }
00154
00155
00156
00157 const char *
00158 IgWeb2DService::catalogLabel (void)
00159 {
00160 return "2D";
00161 }