00001
00002
00003 #include "Iguana/GLBrowsers/interface/Ig3DWindow.h"
00004 #include "Iguana/Framework/interface/IgSite.h"
00005 #include "Iguana/GLModels/interface/Ig3DModel.h"
00006 #include "Iguana/GLModels/interface/Ig3DBaseModel.h"
00007 #include "Iguana/GLBrowsers/interface/Ig3DSystem.h"
00008 #include "Iguana/Studio/interface/IgDocumentData.h"
00009 #include "Iguana/Studio/interface/IgPage.h"
00010 #include "Iguana/Framework/interface/IgTwig.h"
00011 #include "Iguana/GLBrowsers/interface/Ig3DBrowser.h"
00012 #include "Iguana/GLBrowsers/interface/Ig3DLightsCategory.h"
00013 #include "Iguana/GLBrowsers/interface/Ig3DSlicersCategory.h"
00014 #include "Iguana/GLBrowsers/interface/Ig3DClipsCategory.h"
00015 #include "Iguana/GLBrowsers/interface/Ig3DAnimsCategory.h"
00016 #include "Iguana/GLBrowsers/interface/Ig3DNodeCategory.h"
00017 #include "Iguana/GLBrowsers/interface/Ig3DViewpointsCategory.h"
00018 #include "Iguana/GLBrowsers/interface/Ig3DGridCategory.h"
00019 #include "Iguana/Studio/interface/IgQtSite.h"
00020 #include "Iguana/Studio/interface/IgQtSiteStack.h"
00021 #include "Iguana/Studio/interface/IgQtAppContextService.h"
00022 #include "Iguana/Studio/interface/IgQtAppMenuService.h"
00023 #include "Iguana/Studio/interface/IgQtObjectMenuService.h"
00024 #include "Iguana/Studio/interface/IgQtObjectMenuMessage.h"
00025 #include "Iguana/Studio/interface/IgQtObjectMenu.h"
00026 #include "Iguana/Framework/interface/IgRepSet.h"
00027 #include "Iguana/Framework/interface/IgRepContext.h"
00028 #include "Iguana/Studio/interface/IgQtCallbacks.h"
00029 #include "Iguana/Studio/interface/IgQtAppToolBarService.h"
00030 #include "Iguana/Studio/interface/IgQtAppImageService.h"
00031 #include "Iguana/GLBrowsers/interface/IgStudioCentre.h"
00032 #include "Iguana/GLBrowsers/interface/IgControlCentre.h"
00033 #include "Iguana/GLModels/interface/Ig3DBaseRep.h"
00034 #include "Iguana/Studio/interface/IgImageIDs.h"
00035 #include <Inventor/nodes/SoDirectionalLight.h>
00036 #include <Inventor/nodes/SoOrthographicCamera.h>
00037 #include <Inventor/nodes/SoCamera.h>
00038 #include <Inventor/SoOffscreenRenderer.h>
00039 #include <classlib/utils/Callback.h>
00040 #include <qpopupmenu.h>
00041 #include <qmenudata.h>
00042 #include <qmenubar.h>
00043 #include <qtoolbutton.h>
00044 #include <qtoolbar.h>
00045 #include <qwhatsthis.h>
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 Ig3DWindow::Ig3DWindow (IgPage *page)
00058 : Ig3DBaseWindow (page),
00059 m_slicersCategory (0),
00060 m_clipsCategory (0),
00061 m_lightsCategory (0),
00062 m_materialsCategory (0),
00063 m_animsCategory (0),
00064 m_viewpointsCategory (0),
00065 m_nodeCategory (0),
00066 m_gridCategory (0)
00067 {
00068 static int lastWindowNumber = 0;
00069 QString t = "3D Window #" + QString::number (lastWindowNumber++);
00070 setTitle (t.ascii ());
00071
00072 Ig3DBrowser *b = new Ig3DBrowser (state (),
00073 page->workspace ()->hostWithName (t),
00074 dynamic_cast<Ig3DModel *> (model ()));
00075
00076 watchBrowser (b);
00077
00078
00079 initCategories ();
00080
00081 initMenu ();
00082 initToolBar ();
00083
00084 show ();
00085 }
00086
00087 Ig3DWindow::~Ig3DWindow (void)
00088 {
00089 }
00090
00091 void
00092 Ig3DWindow::initCategories (void)
00093 {
00094 Ig3DBaseWindow::initCategories ();
00095
00096
00097 m_lightsCategory = Ig3DLightsCategory::get (page ()->state ());
00098 if (!m_lightsCategory)
00099 {
00100 m_lightsCategory = new Ig3DLightsCategory (page ()->state ());
00101 }
00102
00103
00104 m_slicersCategory = Ig3DSlicersCategory::get (page ()->state ());
00105 if (!m_slicersCategory)
00106 {
00107 m_slicersCategory = new Ig3DSlicersCategory (page ()->state (),
00108 browser ());
00109 }
00110
00111
00112 m_clipsCategory = Ig3DClipsCategory::get (page ()->state ());
00113 if (!m_clipsCategory)
00114 {
00115 m_clipsCategory = new Ig3DClipsCategory (page ()->state (),
00116 browser ());
00117 }
00118
00119
00120
00121 m_animsCategory = Ig3DAnimsCategory::get (page ()->state ());
00122 if (!m_animsCategory)
00123 {
00124 m_animsCategory = new Ig3DAnimsCategory (page ()->state (),
00125 browser ());
00126 }
00127
00128
00129 m_viewpointsCategory = Ig3DViewpointsCategory::get (page ()->state ());
00130 if (!m_viewpointsCategory)
00131 {
00132 m_viewpointsCategory = new Ig3DViewpointsCategory(page ()->state (),
00133 dynamic_cast<Ig3DBrowser *> (browser ()));
00134 }
00135
00136
00137 m_nodeCategory = Ig3DNodeCategory::get (page ()->state ());
00138 if (!m_nodeCategory)
00139 {
00140 m_nodeCategory = new Ig3DNodeCategory(page ()->state (), browser ());
00141 }
00142
00143
00144 m_gridCategory = Ig3DGridCategory::get (page ()->state ());
00145 if (!m_gridCategory)
00146 {
00147 m_gridCategory = new Ig3DGridCategory (page ()->state (),
00148 browser ());
00149 }
00150
00151 m_lightsCategory->registerBrowser (state (), browser ());
00152 m_slicersCategory->registerBrowser (state (), browser ());
00153 m_clipsCategory->registerBrowser (state (), browser ());
00154 m_animsCategory->registerBrowser (state (), browser ());
00155 m_viewpointsCategory->registerBrowser (state (), browser ());
00156 m_nodeCategory->registerBrowser (state (), browser ());
00157 m_gridCategory->registerBrowser (state (), browser ());
00158 }
00159
00160 void
00161 Ig3DWindow::initMenu (void)
00162 {
00163
00164
00165 Ig3DBaseWindow::initMenu ();
00166
00167 ASSERT (IgQtAppMenuService::get (state ()));
00168
00169
00170
00171 QPopupMenu *menu = IgQtAppMenuService::get (state ())->
00172 subMenu (Ig3DBaseBrowser::MENU_ID_3D);
00173
00174
00175
00176
00177
00178 if (IgQtAppMenuService::isIdThere (menu, Ig3DBaseBrowser::MENU_ID_3D_Z_SLICE) == -1)
00179 {
00180 menu->insertItem
00181 ("&Slicers...", this, SLOT (showSlicers ()), 0,
00182 Ig3DBaseBrowser::MENU_ID_3D_Z_SLICE, IgQtAppMenuService::index
00183 (menu, Ig3DBaseBrowser::MENU_ID_3D_Z_SLICE));
00184
00185 menu->insertItem
00186 ("&Clips...", this, SLOT (showClips ()), 0,
00187 Ig3DBaseBrowser::MENU_ID_3D_CLIPS, IgQtAppMenuService::index
00188 (menu, Ig3DBaseBrowser::MENU_ID_3D_CLIPS));
00189
00190 menu->insertItem
00191 ("&Lights...", this, SLOT (showLights ()), 0,
00192 Ig3DBaseBrowser::MENU_ID_3D_LIGHTS, IgQtAppMenuService::index
00193 (menu, Ig3DBaseBrowser::MENU_ID_3D_LIGHTS));
00194
00195 menu->insertItem
00196 ("&Animations...", this, SLOT (showAnims ()), 0,
00197 Ig3DBaseBrowser::MENU_ID_3D_ANIMS, IgQtAppMenuService::index
00198 (menu, Ig3DBaseBrowser::MENU_ID_3D_ANIMS));
00199
00200 menu->insertItem
00201 ("&Viewpoints...", this, SLOT (showViewpoints ()), 0,
00202 Ig3DBaseBrowser::MENU_ID_3D_VIEWPOINTS, IgQtAppMenuService::index
00203 (menu, Ig3DBaseBrowser::MENU_ID_3D_VIEWPOINTS));
00204
00205 menu->insertItem
00206 ("&Node Manipulator...", this, SLOT (showNodeManip ()), 0,
00207 Ig3DBaseBrowser::MENU_ID_3D_NODEMANIP, IgQtAppMenuService::index
00208 (menu, Ig3DBaseBrowser::MENU_ID_3D_NODEMANIP));
00209
00210 menu->insertItem
00211 ("&Grids...", this, SLOT (showGrids ()), 0,
00212 Ig3DBaseBrowser::MENU_ID_3D_GRIDS, IgQtAppMenuService::index
00213 (menu, Ig3DBaseBrowser::MENU_ID_3D_GRIDS));
00214 }
00215 }
00216
00217 void
00218 Ig3DWindow::focusIn (void)
00219 {
00220 Ig3DBaseWindow::focusIn ();
00221
00222 ASSERT (IgQtObjectMenuService::get (state ()));
00223 IgQtObjectMenuService::get (state ())
00224 ->add (lat::CreateCallback (this, &Ig3DWindow::repMenu));
00225 }
00226
00227 void
00228 Ig3DWindow::focusOut (void)
00229 {
00230 Ig3DBaseWindow::focusOut ();
00231
00232 ASSERT (IgQtObjectMenuService::get (state ()));
00233 IgQtObjectMenuService::get (state ())
00234 ->remove (lat::CreateCallback (this, &Ig3DWindow::repMenu));
00235 }
00236
00237 static void
00238 feedbackButtonCallback (Ig3DBaseBrowser *browser, QToolButton *button)
00239 {
00240 button->setOn (browser->isFeedbackVisible ());
00241 }
00242
00243 static void
00244 gridButtonCallback (Ig3DBaseBrowser *browser, QToolButton *button)
00245 {
00246 button->setOn (browser->isGridVisible ());
00247 }
00248
00249 static void
00250 orthogonalButtonCallback (Ig3DBaseBrowser *browser, QToolButton *button)
00251 {
00252 SoCamera *camera = browser->getCamera ();
00253 if (camera->getTypeId ()==SoOrthographicCamera::getClassTypeId ())
00254 {
00255 button->setOn (true);
00256 }else
00257 {
00258 button->setOn (false);
00259 }
00260 }
00261
00262 static void
00263 qtSetOff (QToolButton *button)
00264 {
00265 button->setOn (false);
00266 }
00267
00268 void
00269 Ig3DWindow::cameraToggled (void)
00270 {
00271 IgQtAppToolBarService *tb = IgQtAppToolBarService::get (state ());
00272 orthogonalButtonCallback(browser (),
00273 tb->getToolBarButton(
00274 Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00275 Ig3DBaseWindow::TOOLBAR_ID_3D2D_ORTHO));
00276 }
00277
00278 void
00279 Ig3DWindow::initToolBar (void)
00280 {
00281 Ig3DBaseWindow::initToolBar ();
00282
00283 IgQtAppToolBarService *toolBarService = IgQtAppToolBarService::get (state ());
00284 IgQtAppImageService *is = IgQtAppImageService::get (state ());
00285 IgQtAppContextService *cs = IgQtAppContextService::get (state ());
00286
00287 ASSERT (is);
00288
00289 QToolButton *button = 0;
00290
00291 button = toolBarService->toolBarButton (state (),
00292 Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00293 Ig3DBaseWindow::TOOLBAR_ID_3D2D_GRID,
00294 *is->pixmapById (IgImageIDs::IMAGE_ID_GRID),
00295 "Show/Hide Grid",
00296 browser (),
00297 SLOT (setGridVisibility (bool)),
00298 SIGNAL (toggled (bool)));
00299 button->setToggleButton (true);
00300 QWhatsThis::add (button, "Enable/disable the grid ont he scene graph.");
00301 cs->addOnFocusIn (lat::CreateCallback (&gridButtonCallback,
00302 browser (),
00303 button));
00304 cs->addOnFocusOut (lat::CreateCallback (&qtSetOff,
00305 button));
00306
00307 button = toolBarService->toolBarButton (state (),
00308 Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00309 Ig3DBaseWindow::TOOLBAR_ID_3D2D_SHOW_AXIS,
00310 *is->pixmapById (IgImageIDs::IMAGE_ID_YX_SMALL_COL),
00311 "Show/Hide Axis",
00312 browser (),
00313 SLOT (setFeedbackVisibility (bool)),
00314 SIGNAL (toggled (bool)));
00315 button->setToggleButton (true);
00316 QWhatsThis::add (button, "Show/Hide the axis on the 3D scene.");
00317 cs->addOnFocusIn (lat::CreateCallback (&feedbackButtonCallback,
00318 browser (),
00319 button));
00320 cs->addOnFocusOut (lat::CreateCallback (&qtSetOff,
00321 button));
00322
00323 button = toolBarService->toolBarButton (state (),
00324 Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00325 Ig3DBaseWindow::TOOLBAR_ID_3D2D_INVERT,
00326 *is->pixmapById (IgImageIDs::IMAGE_ID_INVERSE),
00327 "Invert normals",
00328 browser (),
00329 SLOT (invertCamera ()));
00330 QWhatsThis::add (button, "Invert the camera orientation and "
00331 "position through the origin.");
00332
00333
00334
00335 QIconSet iconSet(*is->pixmapById (IgImageIDs::IMAGE_ID_PERSPECTIVE));
00336 iconSet.setPixmap (*is->pixmapById (IgImageIDs::IMAGE_ID_ORTHO), QIconSet::Automatic,
00337 QIconSet::Normal, QIconSet::On);
00338
00339 button = toolBarService->toolBarButton (state (),
00340 Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00341 Ig3DBaseWindow::TOOLBAR_ID_3D2D_ORTHO,
00342 iconSet,
00343 "Change projection",
00344 browser (),
00345 SLOT (toggleCameraType ()));
00346
00347 button->setToggleButton (true);
00348 QWhatsThis::add (button, "Set the camera projection by toggling "
00349 "between the perspective and "
00350 "orthographic modes.");
00351 cs->addOnFocusIn (lat::CreateCallback (&orthogonalButtonCallback,
00352 browser (),
00353 button));
00354 cs->addOnFocusOut (lat::CreateCallback (&qtSetOff,
00355 button));
00356 connect (browser (), SIGNAL (cameraToggled (void)),
00357 this, SLOT (cameraToggled (void)));
00358
00359 button = toolBarService->toolBarButton (state (),
00360 Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00361 Ig3DBaseWindow::TOOLBAR_ID_3D2D_PRINT_DEFAULT_VIEWS,
00362 *is->pixmapById (IgImageIDs::IMAGE_ID_PRINT_DEFAULT_VIEWS),
00363 "Print the default views",
00364 this,
00365 SLOT (printViews ()));
00366 QWhatsThis::add (button, "Print the default views.");
00367 }
00368
00369 void
00370 Ig3DWindow::showClips (void)
00371 {
00372 centre ()->selectCategory (m_clipsCategory);
00373 centre ()->show ();
00374 }
00375
00376 void
00377 Ig3DWindow::showSlicers (void)
00378 {
00379 centre ()->selectCategory (m_slicersCategory);
00380 centre ()->show ();
00381 }
00382
00383 void
00384 Ig3DWindow::showGrids (void)
00385 {
00386 centre ()->selectCategory (m_gridCategory);
00387 centre ()->show ();
00388 }
00389
00390 void
00391 Ig3DWindow::showLights (void)
00392 {
00393 centre ()->selectCategory (m_lightsCategory);
00394 centre ()->show ();
00395 }
00396
00397 void
00398 Ig3DWindow::showAnims (void)
00399 {
00400 centre ()->selectCategory (m_animsCategory);
00401 centre ()->show ();
00402 }
00403
00404 void
00405 Ig3DWindow::showViewpoints (void)
00406 {
00407 centre ()->selectCategory (m_viewpointsCategory);
00408 centre ()->show ();
00409 }
00410
00411 void
00412 Ig3DWindow::showNodeManip (void)
00413 {
00414 centre ()->selectCategory (m_nodeCategory);
00415 centre ()->show ();
00416 }
00417
00419 void
00420 Ig3DWindow::repMenu (IgQtObjectMenuMessage message)
00421 {
00422 static const IgQtObjectMenu::ItemDef defs [] = {
00423 { -1, Ig3DBaseBrowser::MENU_3D_OPS, 0, 0, -1 },
00424 { -1, Ig3DBaseBrowser::MENU_SLICE, "Slice", SLOT(repSlice()), -1 },
00425 { -1, Ig3DBaseBrowser::MENU_CLIP, "Clip", SLOT(repClip()), -1 },
00426 };
00427 static const int ndefs = sizeof (defs)/sizeof (defs [0]);
00428
00429 IgRepresentable *object = message.object ();
00430
00431 IgRep *m_menuRep = dynamic_cast<IgRep *>
00432 (IgRepSet::lookup (object, model (), false));
00433
00434
00435 message.menu ()->removeFromDefs (defs, ndefs);
00436 if (m_menuRep)
00437
00438 message.menu ()->insertFromDefs (this, defs, ndefs);
00439 }
00440
00442 void
00443 Ig3DWindow::repSlice (void)
00444 {
00445 ASSERT (browser ()->menuRep ());
00446 ASSERT (m_slicersCategory);
00447 m_slicersCategory->makeOne (browser ()->menuRep ());
00448 }
00449
00450 void
00451 Ig3DWindow::repClip (void)
00452 {
00453 ASSERT (browser ()->menuRep ());
00454 ASSERT (m_clipsCategory);
00455 m_clipsCategory->makeOne (browser ()->menuRep ());
00456 }
00457
00459 void
00460 Ig3DWindow::printViews (void)
00461 {
00462 static SoNode * node = 0;
00463 if (! node)
00464 {
00465 node = browser ()->openNode (Ig3DBaseModel::encode
00466 ("Default View Points").getString (),
00467 "Select viewpoints to load",
00468 browser ()->getWidget ()->parentWidget ());
00469 }
00470
00471 if (node)
00472 {
00473 ASSERT (node->isOfType (SoGroup::getClassTypeId ()));
00474 SoGroup *views = static_cast<SoGroup *> (node);
00475 IgSoViewpoint *currentView = new IgSoViewpoint ();
00476 Ig3DViewpointsCategory::setViewpoint (browser (), currentView);
00477 for (int i = 1, n = views->getNumChildren (); i < n; ++i)
00478 {
00479 ASSERT (views->getChild (i)->isOfType (IgSoViewpoint::getClassTypeId ()));
00480 IgSoViewpoint *obj = static_cast<IgSoViewpoint *>(views->getChild (i));
00481 Ig3DViewpointsCategory::setCamera (browser (), obj);
00482 QString filename = obj->getName ().getString ();
00483
00484 browser ()->printVector (filename + ".pdf", "pdf", 2);
00485 browser ()->printBitmap (filename + ".jpg",
00486 SoOffscreenRenderer::getScreenPixelsPerInch (),
00487 300, "jpg");
00488 }
00489 Ig3DViewpointsCategory::setCamera (browser (), currentView);
00490 }
00491 }