Salome HOME
5.1.5 Sketcher: highlighting of the origin point of trihedron
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI.cpp
index 2ff3a28874415bd6772648bd2e833123fcd47a71..53e372458ba3f0d2f40090438e2965b62a5e30ff 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>
@@ -283,7 +285,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
@@ -320,6 +322,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;
@@ -398,6 +408,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;
@@ -410,6 +426,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()));
@@ -447,8 +465,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;
@@ -521,6 +547,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
@@ -534,6 +566,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;
@@ -846,6 +884,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();
 }