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