Salome HOME
Porting on OCCT 7.4.0
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI.cpp
index 8a961e01a95ee3e3eaa086615401cda99bbbf5c5..c9fffc916452dd9f1c75b2e122f8db374968198a 100644 (file)
@@ -40,6 +40,8 @@
 #include <ModuleBase_ActionInfo.h>
 #include <ModuleBase_IModule.h>
 
+#include <ModelAPI_Tools.h>
+
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 #include <LightApp_OCCSelector.h>
@@ -72,7 +74,9 @@
 #include <QMenu>
 #include <QToolBar>
 
-#define SALOME_PATCH_FOR_CTRL_WHEEL
+#if OCC_VERSION_HEX < 0x070400
+  #define SALOME_PATCH_FOR_CTRL_WHEEL
+#endif
 
 extern "C" {
 SHAPERGUI_EXPORT CAM_Module* createModule()
@@ -141,7 +145,9 @@ SHAPERGUI::SHAPERGUI()
   myProxyViewer = new SHAPERGUI_SalomeViewer(this);
 
   ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
-  ModuleBase_Preferences::loadCustomProps();
+
+  // It will be called in XGUI_Workshop::startApplication
+  // ModuleBase_Preferences::loadCustomProps();
 }
 
 //******************************************************
@@ -164,7 +170,7 @@ void SHAPERGUI::initialize(CAM_Application* theApp)
   }
 
   int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
-  int aSubMenu = createMenu(tr("Information"), aMenu);
+  int aSubMenu = createMenu(tr("Information"), aMenu, -1, -1, 0);
 
   int aId = getNextCommandId();
   myActionsList.append(aId);
@@ -176,7 +182,7 @@ void SHAPERGUI::initialize(CAM_Application* theApp)
   myWhatIsAction->setData("INSPECTION_CMD");
   createMenu(aId, aSubMenu, 0);
 
-  QString aToolName = tr("Inspection tool");
+  QString aToolName = tr("Inspection");
   int aTool = createTool(aToolName);
   int aToolId = createTool(myWhatIsAction, aTool);
   registerCommandToolbar(aToolName, aId);
@@ -281,7 +287,7 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
       ViewManagerList OCCViewManagers;
       application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
       if (OCCViewManagers.size() > 0) {
-        mySelector = createSelector(OCCViewManagers.first());
+        onViewManagerAdded(OCCViewManagers.first());
       }
     }
     // it should be performed after the selector creation in order to have AISContext
@@ -318,6 +324,14 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
     XGUI_Displayer* aDisp = myWorkshop->displayer();
     QObjectPtrList aObjList = aDisp->displayedObjects();
 
+    //if (myHighlightPointAspect.IsNull()) {
+    //  Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
+    //  myHighlightPointAspect =
+    //    new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
+    //}
+    if (myOldSelectionColor.size() == 0)
+      myOldSelectionColor = aDisp->selectionColor();
+
     AIS_ListOfInteractive aList;
     aContext->DisplayedObjects(aList);
     AIS_ListIteratorOfListOfInteractive aLIt;
@@ -396,6 +410,12 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
   }
   // Delete selector because it has to be redefined on next activation
   if (mySelector) {
+    //if (!myHighlightPointAspect.IsNull()) {
+    //  Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
+    //  aTrihedron->getHighlightPointAspect()->SetAspect(myHighlightPointAspect);
+    //  myHighlightPointAspect.Nullify();
+    //}
+    myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
     myProxyViewer->setSelector(0);
     delete mySelector;
     mySelector = 0;
@@ -408,6 +428,8 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
   aResMgr->setValue("Study", "store_positions", myIsStorePositions);
   getApp()->setEditEnabled(myIsEditEnabled);
 
+  myOldSelectionColor.clear();
+
   // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
   disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
              this, SLOT(onScriptLoaded()));
@@ -445,8 +467,16 @@ void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
       if (mySelector->viewer() == aViewer) {
         XGUI_Displayer* aDisp = myWorkshop->displayer();
         QObjectPtrList aObjects = aDisp->displayedObjects();
-        foreach(ObjectPtr aObj, aObjects)
+        ResultPtr aRes;
+        foreach(ObjectPtr aObj, aObjects) {
           aObj->setDisplayed(false);
+          aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+          if (aRes.get()) {
+            while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
+              aRes->setDisplayed(false);
+            }
+          }
+        }
         Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
         myProxyViewer->setSelector(0);
         delete mySelector;
@@ -488,6 +518,8 @@ void SHAPERGUI::onScriptLoaded()
   SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
   if (aBrowser)
     delete aBrowser;
+  myWorkshop->displayer()->updateViewer();
+  myWorkshop->updateCommandStatus();
 }
 
 //******************************************************
@@ -519,6 +551,12 @@ SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
 {
   if (theMgr->getType() == OCCViewer_Viewer::Type()) {
     OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
+
+    //if (myHighlightPointAspect.IsNull()) {
+    //  Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
+    //  myHighlightPointAspect =
+    //    new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
+    //}
     SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
                                                                  getApp()->selectionMgr());
 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
@@ -532,6 +570,12 @@ SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
       aSel->setEnabled(aSel == aSelector);
     }
     myProxyViewer->setSelector(aSelector);
+
+    if (myOldSelectionColor.size() == 0)
+      myOldSelectionColor = myWorkshop->displayer()->selectionColor();
+
+    std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
+    myWorkshop->displayer()->setSelectionColor(aColor);
     return aSelector;
   }
   return 0;
@@ -780,6 +824,49 @@ void SHAPERGUI::createPreferences()
                 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
   pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
                 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
+
+  int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
+  pref->setItemProperty("columns", 2, highlightGroup);
+  pref->addItem(tr("In 3d mode"), highlightGroup,
+    SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
+  pref->addItem(tr("In 2d mode"), highlightGroup,
+    SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
+
+  int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
+  pref->setItemProperty("columns", 4, colorScaleGroup);
+  int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
+    SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
+  pref->setItemProperty("min", 0, aItem);
+  pref->setItemProperty("max", 1, aItem);
+
+  aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
+    SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
+  pref->setItemProperty("min", 0, aItem);
+  pref->setItemProperty("max", 1, aItem);
+
+  aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
+    SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
+  pref->setItemProperty("min", 0, aItem);
+  pref->setItemProperty("max", 1, aItem);
+
+  aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
+    SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
+  pref->setItemProperty("min", 0, aItem);
+  pref->setItemProperty("max", 1, aItem);
+
+  aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
+    SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
+  pref->setItemProperty("min", 0, aItem);
+  pref->setItemProperty("max", 100, aItem);
+
+  aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
+    SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
+  pref->setItemProperty("min", 0, aItem);
+  pref->setItemProperty("max", 100, aItem);
+
+  aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
+    SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
+
   pref->retrieve();
 }
 
@@ -801,6 +888,11 @@ void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& the
   }
   aProp->setValue(aValue);
 
+  if ((theSection == "Visualization") && (theParam == "selection_color")) {
+    std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
+    myWorkshop->displayer()->setSelectionColor(aColor);
+  }
+
   myWorkshop->displayer()->redisplayObjects();
 }