CMS 3D CMS Logo

Ig3DBaseWindow.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/GLBrowsers/interface/Ig3DBaseWindow.h"
00004 #include "Iguana/Studio/interface/IgModelManager.h"
00005 #include "Iguana/Studio/interface/IgDocumentDataManager.h"
00006 #include "Iguana/GLModels/interface/Ig3DModel.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/Ig3DBaseBrowser.h"
00012 #include "Iguana/GLBrowsers/interface/IgCommonViewPropertiesCategory.h"
00013 #include "Iguana/GLBrowsers/interface/IgTwigConfigElement.h"
00014 #include "Iguana/Studio/interface/IgQtSite.h"
00015 #include "Iguana/Studio/interface/IgQtSiteStack.h"
00016 #include "Iguana/Studio/interface/IgQtAppMenuService.h"
00017 #include "Iguana/Studio/interface/IgQtAppWindowService.h"
00018 #include "Iguana/Studio/interface/IgQtAppContextService.h"
00019 #include "Iguana/Studio/interface/IgQtAppToolBarService.h"
00020 #include "Iguana/Studio/interface/IgQtAppImageService.h"
00021 #include "Iguana/Studio/interface/IgQtObjectMenuService.h"
00022 #include "Iguana/Studio/interface/IgQtObjectMenuMessage.h"
00023 #include "Iguana/GLBrowsers/interface/IgStudioCentre.h"
00024 #include "Iguana/GLBrowsers/interface/IgControlCentre.h"
00025 #include "Iguana/Studio/interface/IgQtWorkspace.h"
00026 #include "Iguana/Studio/interface/IgImageIDs.h"
00027 #include <qmenubar.h>
00028 #include <qpopupmenu.h>
00029 #include <qmenudata.h>
00030 #include <qtoolbar.h>
00031 #include <qtoolbutton.h>
00032 #include <qwhatsthis.h>
00033 #include <qbuttongroup.h>
00034 #include <qmainwindow.h>
00035 
00036 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00037 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00038 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00039 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00040 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00041 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00042 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00043 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00044 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00045 
00046 
00047 static void autoinit (IgState *state, IgSite *site)
00048 { Ig3DSystem::init (state, IgQtSite::selfFrom (site)->topLevelWidget ()); }
00049 
00050 static Ig3DModel *getModelFromManager (IgPage *page)
00051 {
00052     autoinit (page->state (), page->workspace ());
00053     
00054     IgModelManager *manager = IgModelManager::get (page->state ());
00055     if (!manager)
00056         manager = new IgModelManager (page->state ());
00057     
00058     Ig3DModel *model = 0;
00059     manager->lookup (page->state (), &model);
00060     return model;
00061 }
00062 
00063 Ig3DBaseWindow::Ig3DBaseWindow (IgPage *page)
00064     : IgView (page),
00065       m_site (page->workspace ()),
00066       m_browser (0)
00067 { 
00068      m_model = getModelFromManager (page);
00069      m_state = new IgState (IgDocumentDataManager::get(page->state ())->
00070                             lookup (page->state ()));
00071      m_centre = IgStudioCentre::get (m_state)->controlCentre ();
00072      
00073      if (! IgTwigConfigElement::get (m_state))
00074          new IgTwigConfigElement (page->state ());
00075 
00076     // This is the context for this window 
00077     new IgQtAppContextService (m_state,
00078                                IgQtAppWindowService::get (m_state)->mainWindow ());    
00079 }
00080 
00081 void
00082 Ig3DBaseWindow::watchBrowser (Ig3DBaseBrowser *browser)
00083 {
00084     m_browser = browser;
00085     // Show myself and show all the document data (FIXME: select?).
00086     QString t (IgDocumentDataRoot::getCurrentRoot());
00087     t += QString(" ( ") + title ().c_str () + " )";
00088                     
00089     m_browser->getWidget ()->parentWidget ()->setCaption (t);
00090     setTitle (t.latin1 ());
00091     
00092     browse (IgDocumentData::get (m_state)->root ());
00093     // register the MDI window used by this view.
00094     page ()->registerView (dynamic_cast <IgView *> (this), 
00095                            m_browser->getWidget ()->parentWidget ());
00096     connect (page (), SIGNAL (autoPrint (const QString &)), this, SLOT (print (const QString &)));    
00097 }
00098 
00099 void
00100 Ig3DBaseWindow::initCategories (void)
00101 {
00102     // Make sure this is called only once.
00103     // Create a 3D View Properties Category and add it in control
00104     // centre.
00105     
00106     m_viewPropertiesCategory = IgCommonViewPropertiesCategory::get (page ()->state ());
00107     if (!m_viewPropertiesCategory)
00108     {
00109         // Category is added to the global state.
00110         m_viewPropertiesCategory = 
00111             new IgCommonViewPropertiesCategory (page ()->state ());
00112     }
00113     m_viewPropertiesCategory->registerBrowser (m_state, browser ());
00114 }
00115 
00116 void 
00117 Ig3DBaseWindow::initMenu (void)
00118 {
00119     ASSERT (m_state);    
00120     // Initialise menus. FIXME: share a global one with all browsers?
00121     // need to maintain a 3D context service...  This needs to come
00122     // after we've set scene graph so that camera exists.
00123 
00124     // FIXME! get main window from somewhere
00125     // FIXME: deal with absence of main window!
00126 
00127     ASSERT (IgQtAppMenuService::get (m_state));
00128     QMenuBar *bar = IgQtAppMenuService::get (m_state)->menuBar ();    
00129     
00130     IgQtAppMenuService *menuService = IgQtAppMenuService::get (m_state);
00131 
00132     QPopupMenu *menu = menuService->subMenu (Ig3DBaseBrowser::MENU_ID_3D);
00133     
00134     if (!menu)
00135     {
00136         menu = new QPopupMenu (m_browser->getShellWidget ());
00137         menu->setCaption ("View");
00138         menu->insertTearOffHandle ();
00139         bar->insertItem ("&View", menu, Ig3DBaseBrowser::MENU_ID_3D,
00140                          IgQtAppMenuService::index (bar, Ig3DBaseBrowser::MENU_ID_3D));
00141     }
00142     
00143     menu->setCheckable(true);
00144     // FIXME: also drag/drop!
00145     //menu->insertItem ("&Open...", this, SLOT(open()));
00146     
00147     if (IgQtAppMenuService::isIdThere (menu, Ig3DBaseBrowser::MENU_ID_3D_TOOLBAR) == -1)
00148     {
00149         // Miscellaneous controls
00150         menu->insertItem
00151             ("&Tool Bar", 
00152              this, SLOT (showToolbar ()), 0,
00153              Ig3DBaseBrowser::MENU_ID_3D_TOOLBAR, 
00154              IgQtAppMenuService::index (menu, Ig3DBaseBrowser::MENU_ID_3D_TOOLBAR));
00155         menu->setItemChecked (Ig3DBaseBrowser::MENU_ID_3D_TOOLBAR, true);
00156         menu->insertSeparator (IgQtAppMenuService::index (
00157                                 menu, Ig3DBaseBrowser::MENU_ID_3D_TOOLBAR_SEP));
00158         
00159         QToolBar *tb = IgQtAppToolBarService::get (m_state)
00160            ->toolBar (TOOLBAR_ID_3D2D, "General graphics ops");
00161         tb->setCloseMode (QDockWindow::Always);
00162         
00163         connect (tb,   SIGNAL (visibilityChanged (bool)),
00164              this, SLOT (toolbarVisibilityChanged (bool)));
00165     }
00166 
00167     if (IgQtAppMenuService::isIdThere (menu, Ig3DBaseBrowser::MENU_ID_3D_VIEW_PROPERTIES) == -1)
00168     {
00169         // Miscellaneous controls
00170         menu->insertItem
00171             ("&Print/View Settings...", 
00172              this, SLOT (showViewProperties ()), 0,
00173              Ig3DBaseBrowser::MENU_ID_3D_VIEW_PROPERTIES, 
00174              IgQtAppMenuService::index (menu, Ig3DBaseBrowser::MENU_ID_3D_VIEW_PROPERTIES));
00175     }
00176 
00177     menu = menuService->subMenu (IgQtAppMenuService::MENU_ID_FILE);
00178 
00179     ASSERT (m_browser);
00180     
00181     IgQtAppMenuService::insertItem (menu,
00182                                     "&Save As...",
00183                                     m_browser,
00184                                     SLOT(save()),
00185                                     IgQtAppMenuService::MENU_ID_FILE_SAVE,
00186                                     m_state);    
00187 
00188     IgQtAppMenuService::insertItem (menu,
00189                                     "&Print As...", 
00190                                     m_browser,
00191                                     SLOT(print()),
00192                                     IgQtAppMenuService::MENU_ID_FILE_PRINT,
00193                                     m_state);
00194 
00195     // Register the message broadcasting only when the window is
00196     // focused, unregister on focus out.
00197     ASSERT (IgQtAppContextService::get (state ()));
00198     IgQtAppContextService *cs = IgQtAppContextService::get (state ());
00199     cs->addOnFocusIn (lat::CreateCallback (this, &Ig3DBaseWindow::focusIn));
00200     cs->addOnFocusOut (lat::CreateCallback (this, &Ig3DBaseWindow::focusOut));
00201 }
00202 
00203 void
00204 Ig3DBaseWindow::viewingModeCallback (void)
00205 {
00206     IgQtAppToolBarService *ts = IgQtAppToolBarService::get (state ());
00207     ASSERT (ts);
00208     
00209     QToolButton *vb = ts->getToolBarButton (TOOLBAR_ID_3D2D, TOOLBAR_ID_3D2D_VIEW);
00210     QToolButton *pb = ts->getToolBarButton (TOOLBAR_ID_3D2D, TOOLBAR_ID_3D2D_PICK);
00211     QToolButton *sb = ts->getToolBarButton (TOOLBAR_ID_3D2D, TOOLBAR_ID_3D2D_SEEK);
00212     
00213     bool view = m_browser->isViewing();
00214     vb->setOn(view);
00215     sb->setEnabled (view);
00216     pb->setOn(!view);
00217 }
00218 
00219 void
00220 Ig3DBaseWindow::initToolBar (void)
00221 {
00222     // This creates a toolbar with the general widgets.
00223     IgQtAppToolBarService *toolBarService = IgQtAppToolBarService::get (m_state);
00224     IgQtAppImageService *is = IgQtAppImageService::get (m_state);
00225     IgQtAppContextService *cs = IgQtAppContextService::get (state ());
00226     ASSERT (is);
00227     ASSERT (cs);
00228     
00229     QToolButton *button = 0;
00230     button = toolBarService->toolBarButton (m_state,
00231                                             TOOLBAR_ID_3D2D,
00232                                             TOOLBAR_ID_3D2D_SAVE_AS, 
00233                                             *is->pixmapById (IgImageIDs::IMAGE_ID_SAVE_AS), 
00234                                             "Save As",
00235                                             m_browser,
00236                                             SLOT (save ()));
00237     QWhatsThis::add (button, "Save scene graph.");
00238     
00239     button = toolBarService->toolBarButton (m_state,
00240                                             TOOLBAR_ID_3D2D,
00241                                             TOOLBAR_ID_3D2D_PRINT, 
00242                                             *is->pixmapById (IgImageIDs::IMAGE_ID_PRINT), 
00243                                             "Print scene graph",
00244                                             m_browser,
00245                                             SLOT (print ()));
00246     QWhatsThis::add (button, "Print scene graph.");
00247 
00248     button = toolBarService->toolBarButton (m_state,
00249                                             TOOLBAR_ID_3D2D,
00250                                             TOOLBAR_ID_3D2D_CONTROL_CENTRE, 
00251                                             *is->pixmapById (IgImageIDs::IMAGE_ID_CONTROL_CENTRE), 
00252                                             "Show Control Centre",
00253                                             m_centre,
00254                                             SLOT (show ()));
00255     QWhatsThis::add (button, "Show Control Centre. You can manipulate Clip "
00256                             "planes, slicers, lights, camera, view/print "
00257                             "setting via control centre.");
00258 
00259     button = toolBarService->toolBarButton (m_state,
00260                                             TOOLBAR_ID_3D2D,
00261                                             TOOLBAR_ID_3D2D_ZOOM_IN, 
00262                                             *is->pixmapById (IgImageIDs::IMAGE_ID_ZOOM_PLUS), 
00263                                             "Zoom in",
00264                                             m_browser,
00265                                             SLOT (zoomIn ()));
00266     QWhatsThis::add (button, "Zoom in to the scene graph");
00267     
00268     button = toolBarService->toolBarButton (m_state,
00269                                             TOOLBAR_ID_3D2D,
00270                                             TOOLBAR_ID_3D2D_ZOOM_OUT, 
00271                                             *is->pixmapById (IgImageIDs::IMAGE_ID_ZOOM_MINUS),
00272                                             "Zoom out",
00273                                             m_browser,
00274                                             SLOT (zoomOut ()));
00275     QWhatsThis::add (button, "Zoom out of the scene graph");
00276     
00277     button = toolBarService->toolBarButton (m_state,
00278                                             TOOLBAR_ID_3D2D,
00279                                             TOOLBAR_ID_3D2D_PICK,                                
00280                                             *is->pixmapById (IgImageIDs::IMAGE_ID_PICK),
00281                                             "Pick/Select mode",
00282                                             this,
00283                                             SLOT (pick ()));
00284     button->setToggleButton (true);
00285     button->setOn (false);
00286     QWhatsThis::add (button, "Switch to the object pick/select mode. "
00287                      "In this mode you can pick/select 3D objects in the "
00288                      "scene graph");
00289     
00290     button = toolBarService->toolBarButton (m_state,
00291                                             TOOLBAR_ID_3D2D,
00292                                             TOOLBAR_ID_3D2D_VIEW, 
00293                                             *is->pixmapById (IgImageIDs::IMAGE_ID_VIEW),
00294                                             "View mode",
00295                                             this,
00296                                             SLOT (view ()));
00297     button->setToggleButton (true);
00298     button->setOn (true);
00299     QWhatsThis::add (button, "Switch to the camera or viewer mode. "
00300                      "In this mode you can move/re-orient "
00301                      "the camera in 3D space.");
00302     
00303     button = toolBarService->toolBarButton (m_state,
00304                                             TOOLBAR_ID_3D2D,
00305                                             TOOLBAR_ID_3D2D_SEEK, 
00306                                             *is->pixmapById (IgImageIDs::IMAGE_ID_SEEK),
00307                                             "Seek mode",
00308                                             m_browser,
00309                                             SLOT (seek ()));
00310     QWhatsThis::add (button, "Seek towards an object. Click on the object and "
00311                      "camera will either jump (if Seet Time is 0) or "
00312                      "animate (otherwise) to this new position. Seek "
00313                      "time can be change via the View Setting control "
00314                      "category.");
00315 
00316     button = toolBarService->toolBarButton (m_state,
00317                                             TOOLBAR_ID_3D2D,
00318                                             TOOLBAR_ID_3D2D_HOME, 
00319                                             *is->pixmapById (IgImageIDs::IMAGE_ID_HOME),
00320                                             "Go to Home",
00321                                             m_browser,
00322                                             SLOT (resetToHomePosition ()));
00323     QWhatsThis::add (button, "Return camera to its home position or "
00324                      "initial one if no home position was set.");
00325     
00326     button = toolBarService->toolBarButton (m_state,
00327                                             TOOLBAR_ID_3D2D,
00328                                             TOOLBAR_ID_3D2D_SET_HOME,
00329                                             *is->pixmapById (IgImageIDs::IMAGE_ID_SET_HOME),
00330                                             "Set this as home",
00331                                             m_browser,
00332                                             SLOT (saveHomePosition ()));
00333     QWhatsThis::add (button, "Mark current camera position as Home. "
00334                      "You can click on Home button to come back "
00335                      "to this position.");
00336     
00337     button = toolBarService->toolBarButton (m_state,
00338                                             TOOLBAR_ID_3D2D,
00339                                             TOOLBAR_ID_3D2D_ALL, 
00340                                             *is->pixmapById (IgImageIDs::IMAGE_ID_VIEW_ALL),
00341                                             "View All scene",
00342                                             m_browser,
00343                                             SLOT (viewAll ()));
00344     QWhatsThis::add (button, "Adjust the view to include the entire secne graph.");
00345         
00346     button = toolBarService->toolBarButton (state (),
00347                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00348                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D_YX_PLANE, 
00349                                             *is->pixmapById (IgImageIDs::IMAGE_ID_YX_SMALL),
00350                                             "YX plane",
00351                                             browser (),
00352                                             SLOT (viewPlaneZ ()));
00353     QWhatsThis::add (button, "Align camera along -ve Z-axis.");  
00354 
00355     button = toolBarService->toolBarButton (state (),
00356                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00357                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D_XZ_PLANE, 
00358                                             *is->pixmapById (IgImageIDs::IMAGE_ID_XZ_SMALL),
00359                                             "XZ plane",
00360                                             browser (),
00361                                             SLOT (viewPlaneY ()));
00362     QWhatsThis::add (button, "Align camera along -ve Y-axis.");
00363     button = toolBarService->toolBarButton (state (),
00364                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00365                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D_YZ_PLANE, 
00366                                             *is->pixmapById (IgImageIDs::IMAGE_ID_YZ_SMALL),
00367                                             "YZ plane",
00368                                             browser (),
00369                                             SLOT (viewPlaneX ()));
00370     QWhatsThis::add (button, "Align camera along +ve X-axis.");
00371 
00372     button = toolBarService->toolBarButton (m_state,
00373                                             TOOLBAR_ID_3D2D,
00374                                             TOOLBAR_ID_3D2D_AUTO_PRINT, 
00375                                             *is->pixmapById (IgImageIDs::IMAGE_ID_AUTO_PRINT), 
00376                                             "Auto Print",
00377                                             m_browser,
00378                                             SLOT (autoPrint ()));
00379     QWhatsThis::add (button, "Print JPEG.");
00380 
00381     cs->addOnFocusIn (lat::CreateCallback (this,
00382                                            &Ig3DBaseWindow::viewingModeCallback));
00383 }
00384 
00385 void
00386 Ig3DBaseWindow::showViewProperties (void)
00387 {
00388     QString label (m_viewPropertiesCategory->catalogLabel ());
00389     m_centre->selectCategory (
00390         label.right (label.length ()- label.findRev ("/") - 1));
00391     m_centre->show ();
00392 }
00393 
00394 Ig3DBaseWindow::~Ig3DBaseWindow (void)
00395 {
00396 }
00397 
00398 void
00399 Ig3DBaseWindow::show (void)
00400 {
00401     ASSERT (m_browser);
00402     m_browser->getWidget ()->parentWidget ()->show ();
00403     IgQtWorkspace *ws = dynamic_cast <IgQtWorkspace*>(IgQtSite::hostFrom (m_site));
00404     QWidget *pw = ws->activeWindow ()->parentWidget();
00405     if (!pw)
00406         pw = ws->activeWindow ();
00407       
00408     if (ws->windowList (QWorkspace::CreationOrder).count () == 1)
00409     {
00410         pw->resize (600, 600);
00411         pw->showMaximized ();
00412     }
00413     else if (ws)      
00414     {
00415         if (! pw->isMaximized ())
00416             pw->setGeometry (0, 0, ws->width (), ws->height ());
00417     }
00418     else
00419         pw->showMaximized ();
00420 }
00421 
00422 void
00423 Ig3DBaseWindow::hide (void)
00424 {
00425     ASSERT (m_browser);
00426     m_browser->getWidget ()->parentWidget ()->hide ();
00427 }
00428 
00429 IgState *
00430 Ig3DBaseWindow::state (void)
00431 {
00432     return m_state;
00433 }
00434 
00435 Ig3DBaseBrowser *
00436 Ig3DBaseWindow::browser (void)
00437 {
00438     return m_browser;
00439 }
00440 
00441 Ig3DBaseModel *
00442 Ig3DBaseWindow::model (void)
00443 {
00444     return m_model;
00445 }
00446 
00447 IgControlCentre * 
00448 Ig3DBaseWindow::centre  (void)
00449 { return m_centre; }
00450 
00454 void
00455 Ig3DBaseWindow::browse (IgRepresentable *object)
00456 {
00457     ASSERT (m_browser);
00458     // FIXME: This should be replaced with some sort of automatic
00459     // registration of models into the view/page/document to get all
00460     // this done more automatically.
00461     m_browser->browse (object);
00462 }
00463 
00467 void
00468 Ig3DBaseWindow::focusIn (void)
00469 { 
00470     ASSERT (IgQtObjectMenuService::get (state ()));
00471     ASSERT (m_browser);
00472 
00473     IgQtObjectMenuService::get (state ())
00474         ->add (lat::CreateCallback (m_browser, &Ig3DBaseBrowser::repMenu));
00475     m_browser->focusIn ();
00476     m_centre->updateOnWindowActive ();
00477     
00478 }
00479 
00480 void
00481 Ig3DBaseWindow::focusOut (void)
00482 {
00483     ASSERT (IgQtObjectMenuService::get (state ()));
00484     ASSERT (m_browser);
00485     
00486     IgQtObjectMenuService::get (state ())
00487         ->remove (lat::CreateCallback (m_browser, &Ig3DBaseBrowser::repMenu));
00488     m_browser->focusOut ();
00489 }
00490 
00491 void
00492 Ig3DBaseWindow::pick (void)
00493 {
00494     m_browser->pick ();
00495     viewingModeCallback ();
00496 }
00497 
00498 void
00499 Ig3DBaseWindow::view (void)
00500 {
00501     m_browser->view ();
00502     viewingModeCallback ();
00503 }
00504 
00505 void
00506 Ig3DBaseWindow::showToolbar (void)
00507 {
00508     QToolBar *tb = IgQtAppToolBarService::get (m_state)
00509                    ->toolBar (TOOLBAR_ID_3D2D, "");
00510     QPopupMenu *menu = IgQtAppMenuService::get (m_state)
00511                        ->subMenu (Ig3DBaseBrowser::MENU_ID_3D);
00512     ASSERT (menu);
00513 
00514     disconnect (tb,   SIGNAL (visibilityChanged (bool)),
00515                 this, SLOT (toolbarVisibilityChanged (bool)));
00516 
00517     if (tb->isShown ())
00518         tb->hide ();
00519     else
00520         tb->show ();
00521 
00522     connect (tb,   SIGNAL (visibilityChanged (bool)),
00523              this, SLOT (toolbarVisibilityChanged (bool)));
00524     toolbarVisibilityChanged (tb->isShown ());
00525 }
00526 
00527 void
00528 Ig3DBaseWindow::toolbarVisibilityChanged (bool visibility)
00529 {
00530     QPopupMenu *menu = IgQtAppMenuService::get (m_state)
00531                        ->subMenu (Ig3DBaseBrowser::MENU_ID_3D);
00532     ASSERT (menu);
00533     menu->setItemChecked (Ig3DBaseBrowser::MENU_ID_3D_TOOLBAR, visibility);
00534 }
00535 
00536 void
00537 Ig3DBaseWindow::print (const QString &text)
00538 {
00539     QString t = title ();
00540     t.append (QString ("\n"));    
00541     t.append (text);
00542     
00543     m_browser->autoPrint (t);
00544 }

Generated on Tue Jun 9 17:38:35 2009 for CMSSW by  doxygen 1.5.4