CMS 3D CMS Logo

IgRPhiWindow.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/GLBrowsers/interface/IgRPhiWindow.h"
00004 #include "Iguana/GLModels/interface/IgRPhiModel.h"
00005 #include "Iguana/GLModels/interface/Ig3DBaseRep.h"
00006 #include "Iguana/GLBrowsers/interface/Ig3DSystem.h"
00007 #include "Iguana/Studio/interface/IgPage.h"
00008 #include "Iguana/Studio/interface/IgDocumentData.h"
00009 #include "Iguana/GLBrowsers/interface/IgRPhiBrowser.h"
00010 #include "Iguana/Studio/interface/IgQtAppImageService.h"
00011 #include "Iguana/Studio/interface/IgQtAppContextService.h"
00012 #include "Iguana/Studio/interface/IgQtAppMenuService.h"
00013 #include "Iguana/Studio/interface/IgQtAppToolBarService.h"
00014 #include "Iguana/Studio/interface/IgQtObjectMenu.h"
00015 #include "Iguana/Studio/interface/IgQtObjectMenuMessage.h"
00016 #include "Iguana/Studio/interface/IgQtObjectMenuService.h"
00017 #include "Iguana/Studio/interface/IgQtSiteStack.h"
00018 #include "Iguana/GLBrowsers/interface/IgControlCentre.h"
00019 #include "Iguana/GLBrowsers/interface/IgStudioCentre.h"
00020 #include "Iguana/GLBrowsers/interface/IgRPhiViewPropertiesCategory.h"
00021 #include "Iguana/GLBrowsers/interface/Ig3DLightsCategory.h"
00022 #include "Iguana/Framework/interface/IgRepSet.h"
00023 #include "Iguana/Studio/interface/IgImageIDs.h"
00024 #include "Iguana/Studio/interface/IgModelManager.h"
00025 #include "Iguana/Studio/interface/IgDocumentDataManager.h"
00026 #include <Inventor/nodes/SoDirectionalLight.h>
00027 #include <Inventor/nodes/SoOrthographicCamera.h>
00028 #include <Inventor/nodes/SoCamera.h>
00029 
00030 #include <qpopupmenu.h>
00031 #include <qmenubar.h>
00032 #include <qmenudata.h>
00033 #include <qtoolbutton.h>
00034 #include <qwhatsthis.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 IgRPhiWindow::IgRPhiWindow (IgPage *page)
00047     : Ig3DBaseWindow (page),
00048       m_rphiViewPropertiesCategory (0),
00049       m_lightsCategory (0)
00050 {   
00051     static int lastWindowNumber = 0;    
00052     IgRPhiModel *rphiModel = 0;
00053     IgModelManager *manager = IgModelManager::get (page->state ());
00054     if (!manager)
00055         manager = new IgModelManager (page->state ());
00056     manager->lookup (&rphiModel);
00057     if (!rphiModel)
00058     {
00059       IgDocumentDataManager* dm = IgDocumentDataManager::get(page->state ());
00060       rphiModel = new  IgRPhiModel (dm->lookup(0));
00061       manager->add (dm->lookup(0), rphiModel);
00062     }
00063     
00064     QString t = "RPhi Window #" + QString::number (lastWindowNumber++);
00065     IgView::setTitle (t.ascii ());   
00066     
00067     watchBrowser (new IgRPhiBrowser (state (), 
00068                                    page->workspace ()->hostWithName (t), 
00069                                    rphiModel));
00070 
00071     initCategories ();
00072     initMenu ();
00073     initToolBar ();    
00074 
00075     show ();
00076 }
00077 
00078 IgRPhiWindow::~IgRPhiWindow (void)
00079 {
00080 }
00081 
00082 void
00083 IgRPhiWindow::initCategories (void)
00084 {
00085     Ig3DBaseWindow::initCategories ();
00086     
00087     //Create a Lights Category and add it in control centre
00088     m_lightsCategory = Ig3DLightsCategory::get (page ()->state ());
00089     if (!m_lightsCategory)
00090     {
00091         m_lightsCategory = new Ig3DLightsCategory (page ()->state ());
00092     }    
00093     m_lightsCategory->registerBrowser (state (), browser ());
00094 
00095     // Create a RPhi Window Properties Category and add it in control
00096     // centre
00097     m_rphiViewPropertiesCategory = IgRPhiViewPropertiesCategory::get (page ()->state ());
00098     
00099     if (!m_rphiViewPropertiesCategory)
00100     {
00101         m_rphiViewPropertiesCategory = new IgRPhiViewPropertiesCategory (
00102             page ()->state (),
00103             dynamic_cast <IgRPhiBrowser *> (browser ()));
00104     }
00105 
00106     m_rphiViewPropertiesCategory->registerBrowser (state (),
00107           dynamic_cast <IgRPhiBrowser *> (browser ()));    
00108 }
00109 
00110 void
00111 IgRPhiWindow::initMenu (void)
00112 {
00113     Ig3DBaseWindow::initMenu ();    
00114 
00115     ASSERT (IgQtAppMenuService::get (state ()));
00116     
00117     // Get the menu as it has already been initialised in the
00118     // baseClass.
00119     QPopupMenu *menu = IgQtAppMenuService::get (state ())->subMenu
00120                        (Ig3DBaseBrowser::MENU_ID_3D);
00121 
00122     // Submenus
00123     if (IgQtAppMenuService::isIdThere (menu, Ig3DBaseBrowser::MENU_ID_3D_RPHI_VIEW_PROPERTIES) == -1)
00124     {
00125         menu->insertItem
00126             ("R-Phi View properties...", this, SLOT (showRPhiViewProperties ()), 0,
00127              Ig3DBaseBrowser::MENU_ID_3D_RPHI_VIEW_PROPERTIES, IgQtAppMenuService::index
00128              (menu, Ig3DBaseBrowser::MENU_ID_3D_RPHI_VIEW_PROPERTIES));
00129     }
00130     if (IgQtAppMenuService::isIdThere (menu, Ig3DBaseBrowser::MENU_ID_3D_Z_SLICE) == -1)
00131     {
00132         menu->insertItem
00133             ("&Lights...", this, SLOT (showLights ()), 0,
00134              Ig3DBaseBrowser::MENU_ID_3D_LIGHTS, IgQtAppMenuService::index
00135              (menu, Ig3DBaseBrowser::MENU_ID_3D_LIGHTS));
00136     }    
00137 }
00138 
00139 void
00140 IgRPhiWindow::focusIn (void)
00141 {
00142     Ig3DBaseWindow::focusIn ();
00143     
00144     ASSERT (IgQtObjectMenuService::get (state ()));
00145     IgQtObjectMenuService::get (state ())
00146         ->add (lat::CreateCallback (this, &IgRPhiWindow::repMenu));
00147 }
00148 
00149 void
00150 IgRPhiWindow::focusOut (void)
00151 {
00152     Ig3DBaseWindow::focusOut ();
00153 
00154     ASSERT (IgQtObjectMenuService::get (state ()));
00155     IgQtObjectMenuService::get (state ())
00156         ->remove (lat::CreateCallback (this, &IgRPhiWindow::repMenu));
00157 }
00158 
00159 static void
00160 feedbackButtonCallback (Ig3DBaseBrowser *browser, QToolButton *button)
00161 {
00162     button->setOn (browser->isFeedbackVisible ());    
00163 }
00164 
00165 static void
00166 gridButtonCallback (Ig3DBaseBrowser *browser, QToolButton *button)
00167 {
00168     button->setOn (browser->isGridVisible ());    
00169 }
00170 
00171 static void
00172 qtSetOff (QToolButton *button)
00173 {
00174     button->setOn (false);    
00175 }
00176 
00177 typedef void (*FeedbackButtonCallback) (IgRPhiBrowser *browser, QToolButton *button);
00178 
00179 void
00180 IgRPhiWindow::initToolBar (void)
00181 {
00182     Ig3DBaseWindow::initToolBar ();    
00183 
00184     // This creates a toolbar with the general widgets.
00185     IgQtAppToolBarService *toolBarService = IgQtAppToolBarService::get (state ());
00186     IgQtAppImageService *is = IgQtAppImageService::get (state ());
00187     IgQtAppContextService *cs = IgQtAppContextService::get (state ());
00188     
00189     ASSERT (is);
00190 
00191     QToolButton *button = 0;
00192 
00193     button = toolBarService->toolBarButton (state (),
00194                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00195                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D_GRID, 
00196                                             *is->pixmapById (IgImageIDs::IMAGE_ID_GRID),
00197                                             "Show/Hide Grid",
00198                                             browser (),
00199                                             SLOT (setGridVisibility (bool)),
00200                                             SIGNAL (toggled (bool)));
00201     button->setToggleButton (true); 
00202     QWhatsThis::add (button, "Enable/disable the grid ont he scene graph.");
00203     cs->addOnFocusIn (lat::CreateCallback (&gridButtonCallback, 
00204                                            browser (),
00205                                            button));
00206     cs->addOnFocusOut (lat::CreateCallback (&qtSetOff,
00207                                             button));    
00208 
00209     button = toolBarService->toolBarButton (state (),
00210                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00211                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D_SHOW_AXIS,
00212                                             *is->pixmapById (IgImageIDs::IMAGE_ID_YX_SMALL_COL), 
00213                                             "Show Axis",
00214                                             browser (),
00215                                             SLOT (setFeedbackVisibility (bool)),
00216                                             SIGNAL (toggled (bool)));
00217     button->setToggleButton (true);    
00218     QWhatsThis::add (button, "Show/Hide the axis on the 3D scene.");
00219     cs->addOnFocusIn (lat::CreateCallback (&feedbackButtonCallback, 
00220                                            browser (), 
00221                                            button));    
00222     cs->addOnFocusOut (lat::CreateCallback (&qtSetOff,
00223                                             button));
00224 }
00225 
00226 void
00227 IgRPhiWindow::showRPhiViewProperties (void)
00228 {
00229     centre ()->selectCategory (m_rphiViewPropertiesCategory);
00230     centre ()->show ();
00231 }
00232 
00233 void
00234 IgRPhiWindow::showLights (void)
00235 {
00236     centre ()->selectCategory (m_lightsCategory);
00237     centre ()->show ();
00238 }
00239 
00241 void
00242 IgRPhiWindow::repMenu (IgQtObjectMenuMessage message)
00243 {
00244     static const IgQtObjectMenu::ItemDef defs [] = {
00245         { -1, Ig3DBaseBrowser::MENU_3D_OPS, 0, 0, -1 }
00246     };
00247     static const int    ndefs = sizeof (defs) / sizeof (defs [0]);
00248 
00249     IgRepresentable     *object = message.object ();
00250 
00251     IgRep *m_menuRep = dynamic_cast<IgRep *>
00252                 (IgRepSet::lookup (object, model (), false));
00253 
00254     // An irrelevant object or already added item, remove our items.
00255     message.menu ()->removeFromDefs (defs, ndefs);
00256     if (m_menuRep)
00257         // Add our items if they aren't there yet.
00258         message.menu ()->insertFromDefs (this, defs, ndefs);
00259 }

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