CMS 3D CMS Logo

IgRZWindow.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/GLBrowsers/interface/IgRZWindow.h"
00004 #include "Iguana/GLModels/interface/IgRZModel.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/IgRZBrowser.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/IgRZViewPropertiesCategory.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 
00035 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00036 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00037 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00038 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00039 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00040 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00041 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00042 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00043 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00044 
00045 IgRZWindow::IgRZWindow (IgPage *page)
00046     : Ig3DBaseWindow (page),
00047       m_rzViewPropertiesCategory (0),
00048       m_lightsCategory (0)
00049 {   
00050     static int lastWindowNumber = 0;    
00051     IgRZModel *rzModel = 0;
00052     IgModelManager *manager = IgModelManager::get (page->state ());
00053     if (!manager)
00054         manager = new IgModelManager (page->state ());
00055     manager->lookup (&rzModel);
00056     if (!rzModel)
00057     {
00058       IgDocumentDataManager* dm = IgDocumentDataManager::get(page->state ());
00059       rzModel = new  IgRZModel (dm->lookup(0));
00060       manager->add (dm->lookup(0), rzModel);
00061     }
00062     
00063     QString t = "RZ Window #" + QString::number (lastWindowNumber++);
00064     IgView::setTitle (t.ascii ());   
00065     
00066     watchBrowser (new IgRZBrowser (state (), 
00067                                    page->workspace ()->hostWithName (t), 
00068                                    rzModel));
00069 
00070     initCategories ();
00071     initMenu ();
00072     initToolBar ();    
00073 
00074     show ();
00075 }
00076 
00077 IgRZWindow::~IgRZWindow (void)
00078 {
00079 }
00080 
00081 void
00082 IgRZWindow::initCategories (void)
00083 {
00084     Ig3DBaseWindow::initCategories ();
00085     
00086     //Create a Lights Category and add it in control centre
00087     m_lightsCategory = Ig3DLightsCategory::get (page ()->state ());
00088     if (!m_lightsCategory)
00089     {
00090         m_lightsCategory = new Ig3DLightsCategory (page ()->state ());
00091     }    
00092 /*    m_lightsCategory = IgRZLightsCategory::get (page ()->state ());
00093     if (!m_lightsCategory)
00094     {
00095         m_lightsCategory = new IgRZLightsCategory (page ()->state ());
00096     }    
00097 */    
00098     m_lightsCategory->registerBrowser (state (), browser ());
00099 
00100     // Create a RZ Window Properties Category and add it in control
00101     // centre
00102     m_rzViewPropertiesCategory = IgRZViewPropertiesCategory::get (page ()->state ());
00103     
00104     if (!m_rzViewPropertiesCategory)
00105     {
00106         m_rzViewPropertiesCategory = new IgRZViewPropertiesCategory (
00107             page ()->state (),
00108             dynamic_cast <IgRZBrowser *> (browser ()));
00109     }
00110 
00111     m_rzViewPropertiesCategory->registerBrowser (state (),
00112           dynamic_cast <IgRZBrowser *> (browser ()));    
00113 }
00114 
00115 void
00116 IgRZWindow::initMenu (void)
00117 {
00118     Ig3DBaseWindow::initMenu ();    
00119 
00120     ASSERT (IgQtAppMenuService::get (state ()));
00121     
00122     // Get the menu as it has already been initialised in the
00123     // baseClass.
00124     QPopupMenu *menu = IgQtAppMenuService::get (state ())->subMenu
00125                        (Ig3DBaseBrowser::MENU_ID_3D);
00126 
00127     // Submenus
00128     if (IgQtAppMenuService::isIdThere (menu, Ig3DBaseBrowser::MENU_ID_3D_RZ_VIEW_PROPERTIES) == -1)
00129     {
00130         menu->insertItem
00131             ("RZ View properties...", this, SLOT (showRZViewProperties ()), 0,
00132              Ig3DBaseBrowser::MENU_ID_3D_RZ_VIEW_PROPERTIES, IgQtAppMenuService::index
00133              (menu, Ig3DBaseBrowser::MENU_ID_3D_RZ_VIEW_PROPERTIES));
00134     }
00135     if (IgQtAppMenuService::isIdThere (menu, Ig3DBaseBrowser::MENU_ID_3D_Z_SLICE) == -1)
00136     {
00137         menu->insertItem
00138             ("&Lights...", this, SLOT (showLights ()), 0,
00139              Ig3DBaseBrowser::MENU_ID_3D_LIGHTS, IgQtAppMenuService::index
00140              (menu, Ig3DBaseBrowser::MENU_ID_3D_LIGHTS));
00141     }    
00142 }
00143 
00144 void
00145 IgRZWindow::focusIn (void)
00146 {
00147     Ig3DBaseWindow::focusIn ();
00148     
00149     ASSERT (IgQtObjectMenuService::get (state ()));
00150     IgQtObjectMenuService::get (state ())
00151         ->add (lat::CreateCallback (this, &IgRZWindow::repMenu));
00152 }
00153 
00154 void
00155 IgRZWindow::focusOut (void)
00156 {
00157     Ig3DBaseWindow::focusOut ();
00158 
00159     ASSERT (IgQtObjectMenuService::get (state ()));
00160     IgQtObjectMenuService::get (state ())
00161         ->remove (lat::CreateCallback (this, &IgRZWindow::repMenu));
00162 }
00163 
00164 static void
00165 feedbackButtonCallback (Ig3DBaseBrowser *browser, QToolButton *button)
00166 {
00167     button->setOn (browser->isFeedbackVisible ());    
00168 }
00169 
00170 static void
00171 orthogonalButtonCallback (Ig3DBaseBrowser *browser, QToolButton *button)
00172 {
00173     SoCamera *camera = browser->getCamera ();
00174     if (camera->getTypeId ()==SoOrthographicCamera::getClassTypeId ())
00175     {
00176         button->setOn (true);    
00177     }else
00178     {
00179         button->setOn (false);  
00180     }
00181 }
00182 
00183 static void
00184 qtSetOff (QToolButton *button)
00185 {
00186     button->setOn (false);    
00187 }
00188 
00189 typedef void (*FeedbackButtonCallback) (IgRZBrowser *browser, QToolButton *button);
00190 
00191 void
00192 IgRZWindow::initToolBar (void)
00193 {
00194     Ig3DBaseWindow::initToolBar ();    
00195 
00196     // This creates a toolbar with the general widgets.
00197     IgQtAppToolBarService *toolBarService = IgQtAppToolBarService::get (state ());
00198     IgQtAppImageService *is = IgQtAppImageService::get (state ());
00199     IgQtAppContextService *cs = IgQtAppContextService::get (state ());
00200 
00201     ASSERT (is);
00202 
00203     QToolButton *button = 0;
00204     button = toolBarService->toolBarButton (state (),
00205                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00206                                             Ig3DBaseWindow::TOOLBAR_ID_3D2D_SHOW_AXIS,
00207                                             *is->pixmapById (IgImageIDs::IMAGE_ID_YX_SMALL_COL), 
00208                                             "Show Axis",
00209                                             browser (),
00210                                             SLOT (setFeedbackVisibility (bool)),
00211                                             SIGNAL (toggled (bool)));
00212     button->setToggleButton (true);    
00213 
00214     toolBarService->toolBarButton (state (),
00215                                    Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00216                                    Ig3DBaseWindow::TOOLBAR_ID_3D2D_INVERT, 
00217                                    *is->pixmapById (IgImageIDs::IMAGE_ID_INVERSE),
00218                                    "Invert normals",
00219                                    browser (),
00220                                    SLOT (invertCamera ()));
00221 
00222     // FIXME: this needs to be a togglable button. Create a service
00223     // for doing so.
00224     QIconSet iconSet(*is->pixmapById (IgImageIDs::IMAGE_ID_PERSPECTIVE));
00225     iconSet.setPixmap (*is->pixmapById (IgImageIDs::IMAGE_ID_ORTHO), QIconSet::Automatic,
00226                        QIconSet::Normal, QIconSet::On);
00227     QToolButton *cpButton 
00228         = toolBarService->toolBarButton (state (),
00229                                          Ig3DBaseWindow::TOOLBAR_ID_3D2D,
00230                                          Ig3DBaseWindow::TOOLBAR_ID_3D2D_ORTHO, 
00231                                          //*is->pixmapById (IgImageIDs::IMAGE_ID_ORTHO),
00232                                          iconSet,
00233                                          "Change projection",
00234                                          browser (),
00235                                          SLOT (toggleCameraType ()));
00236 
00237     cpButton->setToggleButton (true);
00238     
00239     cs->addOnFocusIn (lat::CreateCallback (&feedbackButtonCallback, 
00240                                            browser (), 
00241                                            button));    
00242     cs->addOnFocusOut (lat::CreateCallback (&qtSetOff,
00243                                             button));
00244 
00245     cs->addOnFocusIn (lat::CreateCallback (&orthogonalButtonCallback, 
00246                                            browser (), 
00247                                            cpButton));
00248     cs->addOnFocusOut (lat::CreateCallback (&qtSetOff,
00249                                             cpButton));    
00250 }
00251 
00252 void
00253 IgRZWindow::showRZViewProperties (void)
00254 {
00255     centre ()->selectCategory (m_rzViewPropertiesCategory);
00256     centre ()->show ();
00257 }
00258 
00259 void
00260 IgRZWindow::showLights (void)
00261 {
00262     centre ()->selectCategory (m_lightsCategory);
00263     centre ()->show ();
00264 }
00265 
00267 void
00268 IgRZWindow::repMenu (IgQtObjectMenuMessage message)
00269 {
00270     static const IgQtObjectMenu::ItemDef defs [] = {
00271         { -1, Ig3DBaseBrowser::MENU_3D_OPS, 0, 0, -1 }
00272         //      { -1, IgRZWindow::MENU_RZ_MANIP, "Manipulate", SLOT(repNode ()), -1 },
00273     };
00274     static const int    ndefs = sizeof (defs)/sizeof (defs [0]);
00275 
00276     IgRepresentable     *object = message.object ();
00277 
00278     IgRep *m_menuRep = dynamic_cast<IgRep *>
00279                 (IgRepSet::lookup (object, model (), false));
00280 
00281     // An irrelevant object or already added item, remove our items.
00282     message.menu ()->removeFromDefs (defs, ndefs);
00283     if (m_menuRep)
00284         // Add our items if they aren't there yet.
00285         message.menu ()->insertFromDefs (this, defs, ndefs);
00286 }

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