00001
00002
00003 #include "Iguana/WebFramework/interface/IgWebRZService.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/nodes/SoOrthographicCamera.h>
00013 #include <Inventor/SbLinear.h>
00014 #include <qtextstream.h>
00015 #include <qdatastream.h>
00016 #include <qsocket.h>
00017 #include <qfile.h>
00018 #include <iostream>
00019
00020 lat::logflag LFwebRZ = { 0, "webRZ", true, -1 };
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 IgWebRZService::IgWebRZService (IgState *state)
00033 : IgWebService (state)
00034 {
00035
00036 registerCallback ("create", lat::CreateCallback (this, &IgWebRZService::create));
00037 registerCallback ("browse", lat::CreateCallback (this, &IgWebRZService::browse));
00038 }
00039
00040
00041 void
00042 IgWebRZService::create (Arguments *arguments)
00043 {
00044 IgState *state = arguments->state ();
00045 QIODevice *outputDevice = arguments->outputDevice ();
00046 ArgumentsMap &args = *arguments->args ();
00047
00048
00049 std::string lookupName = "";
00050
00051 if (args.find ("name") != args.end ())
00052 lookupName = args["name"];
00053
00054 doCreate (state, lookupName);
00055 this->sendDone (outputDevice);
00056 }
00057
00058 void
00059 IgWebRZService::doCreate (IgState *state, const std::string &name)
00060 {
00061 IgBrowserManager *manager = IgBrowserManager::get (state);
00062 ASSERT (manager);
00063
00064 IgOIVBrowser *browser = manager->lookup<IgOIVBrowser> (name);
00065
00066 if (browser == 0)
00067 {
00068
00069 LOG (0, trace, LFwebRZ, "Creating RZ browser");
00070
00071 browser = new IgOIVBrowser (state, 0, (Ig3DBaseModel *) -3);
00072 browser->setCamera ();
00073 browser->setCameraType (SoOrthographicCamera::getClassTypeId ());
00074
00075 SoOrthographicCamera * const camera
00076 = dynamic_cast <SoOrthographicCamera *> (browser->getCamera ());
00077 if (!camera) return;
00078
00079 camera->position = SbVec3f (-14.815891, 0, 0);
00080 camera->orientation = SbRotation (SbVec3f (-0, -1, -0), 1.5707964);
00081 camera->aspectRatio = 1;
00082 camera->focalDistance = 14.815891;
00083 camera->height = 12.273887;
00084 camera->nearDistance = 0.1;
00085 camera->farDistance = 32767;
00086
00087
00088 manager->add (browser, name);
00089 }
00090 }
00091
00092
00093 void
00094 IgWebRZService::browse (Arguments *arguments)
00095 {
00096 using namespace lat;
00097 IgState *state = arguments->state ();
00098 QIODevice *outputDevice = arguments->outputDevice ();
00099 ArgumentsMap &args = *arguments->args ();
00100
00101 IgDocumentData *dd = IgDocumentData::get (state);
00102 IgBrowserManager *manager = IgBrowserManager::get (state);
00103
00104 std::string rootName = "";
00105 if (args.find ("root") != args.end ())
00106 rootName = args["root"];
00107
00108 IgTwig *twig = dynamic_cast <IgTwig *> (dd->root (rootName));
00109
00110 std::string browserName = "";
00111 if (args.find ("browserName") != args.end ())
00112 browserName = args["browserName"];
00113
00114
00115 IgOIVBrowser *browser = manager->lookup<IgOIVBrowser> (browserName);
00116 ASSERT (browser);
00117
00118 browser->browse (twig);
00119 browser->viewAll ();
00120
00121 if (args.find ("position") != args.end ())
00122 {
00123 float x, y, z;
00124 StringList coords = StringOps::split (args["position"], ",");
00125 if (coords.size () == 3)
00126 {
00127 x = strtof (coords[0].c_str (), 0);
00128 y = strtof (coords[1].c_str (), 0);
00129 z = strtof (coords[2].c_str (), 0);
00130 browser->getCamera ()->position = SbVec3f (x, y ,z);
00131 }
00132 }
00133
00134 if (args.find ("orientation") != args.end ())
00135 {
00136 float x,y,z,a;
00137 StringList coords = StringOps::split (args["orientation"], ",");
00138 if (coords.size () == 4)
00139 {
00140 x = strtof (coords[0].c_str (), 0);
00141 y = strtof (coords[1].c_str (), 0);
00142 z = strtof (coords[2].c_str (), 0);
00143 a = strtof (coords[3].c_str (), 0);
00144 browser->getCamera ()->orientation
00145 = SbRotation (SbVec3f (x, y ,z), a);
00146 }
00147 }
00148
00149 if (args.find ("pointAt") != args.end ())
00150 {
00151 float x,y,z;
00152 StringList coords = StringOps::split (args["pointAt"], ",");
00153 if (coords.size () == 3)
00154 {
00155 x = strtof (coords[0].c_str (), 0);
00156 y = strtof (coords[1].c_str (), 0);
00157 z = strtof (coords[2].c_str (), 0);
00158 browser->getCamera ()->pointAt (SbVec3f (x, y ,z));
00159 }
00160 }
00161
00162
00163 if (args.find ("viewAll") != args.end ())
00164 {
00165 browser->viewAll ();
00166 }
00167
00168 if (args.find ("moveCameraScreen") != args.end ())
00169 {
00170 float x, y;
00171 StringList coords
00172 = StringOps::split (args["moveCameraScreen"], ",");
00173 if (coords.size () == 2)
00174 {
00175 x = strtof (coords[0].c_str (), 0);
00176 y = strtof (coords[1].c_str (), 0);
00177 browser->moveCameraScreen (SbVec2f (x, y));
00178 }
00179 }
00180
00181 if (args.find ("zoom") != args.end ())
00182 {
00183 float diffValue = 0;
00184 diffValue = strtof (args["zoom"].c_str (), 0);
00185 browser->zoom (diffValue);
00186 }
00187
00188 if (args.find ("spin") != args.end ())
00189 {
00190 float x, y;
00191 StringList pos
00192 = StringOps::split (args["spin"], ",");
00193 if (pos.size () == 2)
00194 {
00195 x = strtof (pos[0].c_str (), 0);
00196 y = strtof (pos[1].c_str (), 0);
00197 const SbVec2f posn (x, y);
00198
00199 browser->addToLog (posn, SbTime::getTimeOfDay ());
00200 browser->spin (posn);
00201 }
00202 }
00203
00204 if (args.find ("lastSpin") != args.end ())
00205 {
00206 float x, y;
00207 StringList pos
00208 = StringOps::split (args["lastSpin"], ",");
00209 if (pos.size () == 2)
00210 {
00211 x = strtof (pos[0].c_str (), 0);
00212 y = strtof (pos[1].c_str (), 0);
00213
00214 const SbVec2f posn (x, y);
00215
00216 browser->addToLog (posn, SbTime::getTimeOfDay ());
00217 browser->spin (posn);
00218 }
00219 browser->clearLog ();
00220 }
00221
00222 QByteArray tmpArray = browser->getJPGBuffer ();
00223 outputDevice->writeBlock (tmpArray.data (), tmpArray.size ());
00224 }
00225
00226 const char *
00227 IgWebRZService::catalogLabel (void)
00228 {
00229 return "RZ";
00230 }