00001 #include "Iguana/GLBrowsers/interface/IgRPhiBrowser.h"
00002 #include "Iguana/GLModels/interface/Ig3DBaseRep.h"
00003 #include "Iguana/GLModels/interface/IgRPhiModel.h"
00004 #include "Iguana/Inventor/interface/IgXYGrid.h"
00005 #include <Inventor/nodes/SoGroup.h>
00006 #include <Inventor/nodes/SoOrthographicCamera.h>
00007 #include <Inventor/SbLinear.h>
00008 #include <Inventor/nodes/SoCamera.h>
00009 #include <Inventor/fields/SoSFVec3f.h>
00010 #include <iostream>
00011 #include <qpopupmenu.h>
00012 #include <cmath>
00013
00014 const char *
00015 IgRPhiBrowser::catalogLabel (void)
00016 { return "RPhi"; }
00017
00018 IgRPhiBrowser::IgRPhiBrowser (IgState *state,
00019 IgSite *site,
00020 IgRPhiModel *model)
00021 : Ig3DBaseBrowser (state,
00022 site,
00023 model ? model : new IgRPhiModel (state)),
00024 m_grid (false)
00025 {
00026 init ();
00027
00028 SoNode *node = model->attachPoint ()->findMagic (
00029 Ig3DBaseModel::encode ("Default Grid Group"));
00030 if (node && dynamic_cast<SoGroup*>(node)->getNumChildren ())
00031 m_grid = true;
00032 }
00033
00034 void
00035 IgRPhiBrowser::init (void)
00036 {
00037 SoQtExaminerViewer::setCameraType (SoOrthographicCamera::getClassTypeId ());
00038 SoOrthographicCamera * const camera = dynamic_cast <SoOrthographicCamera *> (this->getCamera ());
00039 if (! camera) return;
00040
00041 if (SoQtViewer::isHeadlight ()) SoQtViewer::setHeadlight (false);
00042
00043
00044
00045
00046 camera->position = SbVec3f (-2.3816285e-07, -5.9540713e-07, 14.8);
00047 camera->orientation = SbRotation (SbVec3f (0, 1, 0), 0);
00048 camera->aspectRatio = 1;
00049 camera->focalDistance = 14.815891;
00050 camera->height = 12.273887;
00051 camera->nearDistance = 0.1;
00052 camera->farDistance = 32767;
00053
00054 setEventCallback (eventCallback, this);
00055 setBackgroundColor (SbColor (1.0, 1.0, 1.0));
00056 }
00057
00058 SbBool
00059 IgRPhiBrowser::eventCallback (void *closure, QEvent *event)
00060 {
00061 static bool firstEvent = true;
00062 static float oldX = 0.;
00063 static float oldY = 0.;
00064 IgRPhiBrowser *browser = static_cast<IgRPhiBrowser *> (closure);
00065 if (! browser->isViewing ())
00066 return false;
00067 if (! browser->getParentWidget ()->hasMouse () && firstEvent)
00068 return false;
00069 if (! Ig3DBaseBrowser::eventCallback (closure, event))
00070 {
00071 if (QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *> (event))
00072 {
00073 if (mouseEvent->type () == QEvent::MouseMove
00074 && mouseEvent->stateAfter () == Qt::NoButton)
00075 {
00076 if (! firstEvent)
00077 {
00078 firstEvent = true;
00079 return true;
00080 }
00081 }
00082 else if (mouseEvent->state () == Qt::LeftButton)
00083 {
00084 if (mouseEvent->stateAfter () == Qt::NoButton)
00085 firstEvent = true;
00086 else if (mouseEvent->type () == QEvent::MouseMove)
00087 {
00088 if (firstEvent)
00089 {
00090 oldX = mouseEvent->x ();
00091 oldY = mouseEvent->y ();
00092 firstEvent = false;
00093 }
00094 else
00095 {
00096 float deltaX = mouseEvent->x () - oldX;
00097 float deltaY = oldY - mouseEvent->y ();
00098 SoCamera *camera = browser->getCamera ();
00099 SbVec3f oldPosition = camera->position.getValue ();
00100 camera->position = oldPosition -
00101 SbVec3f (deltaX/10, deltaY/10, 0);
00102 oldX = mouseEvent->x ();
00103 oldY = mouseEvent->y ();
00104 }
00105 return true;
00106 }
00107 }
00108 return false;
00109 }
00110 return false;
00111 }
00112 return true;
00113 }
00114
00115 QWidget *
00116 IgRPhiBrowser::buildLeftTrim (QWidget *parent)
00117 {
00118 QWidget *result = new QWidget (parent);
00119 result->setFixedWidth (0);
00120 return result;
00121 }
00122
00123 QWidget *
00124 IgRPhiBrowser::buildBottomTrim (QWidget *parent)
00125 {
00126 QWidget *result = new QWidget (parent);
00127 result->setFixedHeight (0);
00128 return result;
00129 }
00130
00131 QWidget *
00132 IgRPhiBrowser::buildRightTrim (QWidget *parent)
00133 {
00134 QWidget *result = new QWidget (parent);
00135 result->setFixedWidth (0);
00136 return result;
00137 }
00138
00139 void
00140 IgRPhiBrowser::buildDecoration (QWidget *parent)
00141 {
00142 Ig3DBaseBrowser::buildDecoration (parent);
00143 return;
00144 }
00145
00146 void
00147 IgRPhiBrowser::toggleCameraType (void)
00148 {
00149 SoQtExaminerViewer::toggleCameraType ();
00150 Ig3DBaseBrowser::toggleCameraType ();
00151 }
00152
00153 void
00154 IgRPhiBrowser::invertCamera (void)
00155 {
00156 SoCamera * const camera = this->getCamera ();
00157 if (!camera) return;
00158
00159 camera->position = camera->position.getValue () * -1.0F;
00160 }
00161
00162 void
00163 IgRPhiBrowser::setGridVisibility (bool enable)
00164 {
00165 IgRPhiBrowser::drawGrid (enable);
00166 }
00167
00168 void
00169 IgRPhiBrowser::drawGrid (bool enable)
00170 {
00171 SoGroup *group = 0;
00172 SoNode *node = model ()->attachPoint ()->findMagic (
00173 Ig3DBaseModel::encode ("Default Grid Group"));
00174 if (!node)
00175 {
00176 group = new SoGroup;
00177 group->setName (Ig3DBaseModel::encode ("Default Grid Group"));
00178 model ()->attachPoint ()->magic ()->insertChild (group, 0);
00179 }
00180 else
00181 {
00182 group = dynamic_cast<SoGroup *> (node);
00183 }
00184
00185 if (! enable)
00186 {
00187 if (group->getNumChildren () > 0)
00188 group->removeChild (0);
00189 }
00190 else if (group->getNumChildren () == 0)
00191 {
00192 SoNode *xyGrid;
00193 SoInput in;
00194 in.putBack (IV_GRID);
00195 SoDB::read (&in, xyGrid);
00196
00197 xyGrid->setName (Ig3DBaseModel::encode ("XY Grid"));
00198 group->addChild (xyGrid);
00199 }
00200 m_grid = enable;
00201 }
00202
00203 bool
00204 IgRPhiBrowser::isGridVisible (void)
00205 {
00206 return m_grid;
00207 }
00208
00209 void
00210 IgRPhiBrowser::viewPlaneX (void)
00211 {
00212 SoCamera * const camera = this->getCamera ();
00213 if (!camera) return;
00214
00215 camera->position = SbVec3f (-1, 0, 0) * camera->position.getValue ().length ();
00216 camera->orientation = SbRotation (SbVec3f (0, 1, 0), -M_PI / 2.f);
00217 }
00218
00219 void
00220 IgRPhiBrowser::viewPlaneY (void)
00221 {
00222 SoCamera * const camera = this->getCamera ();
00223 if (!camera) return;
00224
00225 SbVec3f norient = SbVec3f (0, -1, 0);
00226 camera->position = -norient * camera->position.getValue().length();
00227 camera->orientation = SbRotation (SbVec3f (0, 0, 1), -M_PI / 2.f) *
00228 SbRotation (SbVec3f (0, 0, -1), norient);
00229 }
00230
00231 void
00232 IgRPhiBrowser::viewPlaneZ (void)
00233 {
00234 SoCamera * const camera = this->getCamera ();
00235 if (!camera) return;
00236
00237 camera->position = SbVec3f (0, 0, 1) * camera->position.getValue ().length ();
00238 camera->orientation = SbRotation::identity ();
00239 }