Salome HOME
Put dimensions presentations on a layer 1
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 25 Mar 2015 16:13:58 +0000 (19:13 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 25 Mar 2015 16:13:58 +0000 (19:13 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_Workshop.cpp

index ffe5139479fdc09fdcc09043798e4b6fcd413786..b29b4e51d97c4e383b40d0a2b422c1038f0c81d3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D\r
+ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D\r
 \r
 #ifndef ModuleBase_IModule_H\r
 #define ModuleBase_IModule_H\r
@@ -122,6 +122,16 @@ public slots:
   /// Called on call of command corresponded to a feature\r
   void onFeatureTriggered();\r
 \r
+  /// Slolt called on object display\r
+  /// \param theObject a data object\r
+  /// \param theAIS a presentation object\r
+  virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
+\r
+  /// Slot called on before object erase\r
+  /// \param theObject a data object\r
+  /// \param theAIS a presentation object\r
+  virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}\r
+\r
 protected slots:\r
   /// Called on selection changed event\r
   virtual void onSelectionChanged() {}\r
index 0b2e410b160e640a4df884d4605cbb9cb6701534..ad9296bc84645741f6bbe984554fc8624a0c81e3 100644 (file)
@@ -67,6 +67,7 @@
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <BRep_Tool.hxx>
+#include <AIS_Dimension.hxx>
 
 #include <QObject>
 #include <QMouseEvent>
@@ -91,7 +92,7 @@ extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop*
 
 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   : ModuleBase_IModule(theWshop), 
-  myRestartingMode(RM_None)
+  myRestartingMode(RM_None), myVisualLayerId(0)
 {
   //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
   mySketchMgr = new PartSet_SketcherMgr(this);
@@ -211,6 +212,8 @@ void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
 {
   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
+    Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
+    aViewer->AddZLayer(myVisualLayerId);
     mySketchMgr->startSketch(theOperation);
   }
   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
@@ -226,6 +229,9 @@ void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
 {
   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
     mySketchMgr->stopSketch(theOperation);
+    Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
+    aViewer->RemoveZLayer(myVisualLayerId);
+    myVisualLayerId = 0;
   }
   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
     mySketchMgr->stopNestedSketch(theOperation);
@@ -651,3 +657,17 @@ bool PartSet_Module::deleteObjects()
 
   return true;
 }
+
+
+void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) 
+{
+  Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
+    if (!aDim.IsNull()) {
+      Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
+      aCtx->SetZLayer(aDim, myVisualLayerId);
+    }
+  }
+}
+
index 11214c096ee79f5a970eaa214becfcd71ae4230c..6bacf2d778dd514376b82b3ae8815396bf7d5360 100644 (file)
@@ -113,6 +113,11 @@ public slots:
   /// \param isChecked a state of toggle if the action is checkable
   void onAction(bool isChecked);
 
+  /// Slolt called on object display
+  /// \param theObject a data object
+  /// \param theAIS a presentation object
+  virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
+
 protected slots:
   /// Called when previous operation is finished
   virtual void onSelectionChanged();
@@ -173,6 +178,8 @@ protected slots:
   PartSet_SketcherMgr* mySketchMgr;
 
   QMap<QString, QAction*> myActions; // the popup menu actions
+
+  int myVisualLayerId;
 };
 
 #endif
index 7d4ae0012ba5db8b645726cedd4d3cc806ac92e1..fef7ed06d1b89a2dfc55d4633ae5ca2ff9bc5446 100644 (file)
@@ -158,8 +158,8 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
       closeLocalContexts(false);
     }
     aContext->Display(anAISIO, false);
-
     aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
+    emit objectDisplayed(theObject, theAIS);
 
     bool isCustomized = customizeObject(theObject);
     if (isCustomized)
@@ -189,6 +189,7 @@ void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
   if (anObject) {
     Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
     if (!anAIS.IsNull()) {
+      emit beforeObjectErase(theObject, anObject);
       aContext->Remove(anAIS, isUpdateViewer);
     }
   }
@@ -444,14 +445,17 @@ void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
   if (!aContext.IsNull()) {
-   foreach (AISObjectPtr aAISObj, myResult2AISObjectMap) {
-     // erase an object
-     Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
-     if (!anIO.IsNull())
-       aContext->Remove(anIO, false);
-   }
-   if (isUpdateViewer)
-     updateViewer();
+    foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
+      AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
+      // erase an object
+      Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+      if (!anIO.IsNull()) {
+        emit beforeObjectErase(aObj, aAISObj);
+        aContext->Remove(anIO, false);
+      }
+    }
+    if (isUpdateViewer)
+      updateViewer();
   }
   myResult2AISObjectMap.clear();
 }
index da11c4d8ef6f65ba1ca039fe7f9c208d41c92a43..dc3dd6cba29d18d7ef282b5e29c90a3a441e5774 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <QString>
 #include <QMap>
+#include <QObject>
 
 class ModelAPI_Feature;
 class XGUI_Workshop;
@@ -34,8 +35,9 @@ class XGUI_Workshop;
  * \ingroup GUI
  * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
  */
-class XGUI_EXPORT XGUI_Displayer
+class XGUI_EXPORT XGUI_Displayer: public QObject
 {
+  Q_OBJECT
  public:
    /// \enum DisplayMode display mode
    enum DisplayMode { 
@@ -185,6 +187,18 @@ class XGUI_EXPORT XGUI_Displayer
   /// \param theObject object to check
   bool canBeShaded(ObjectPtr theObject) const;
 
+
+signals:
+  /// Signal on object display
+  /// \param theObject a data object
+  /// \param theAIS a presentation object
+  void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
+
+  /// Signal on before object erase
+  /// \param theObject a data object
+  /// \param theAIS a presentation object
+  void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
+
  protected:
   /// Returns currently installed AIS_InteractiveContext
   Handle(AIS_InteractiveContext) AISContext() const;
index 6100b9ecf43cc37efde993545ed6e9db1067a45d..2997907c04b2d3853880af22aa1ee59d6c573653 100644 (file)
@@ -1053,6 +1053,12 @@ bool XGUI_Workshop::activateModule()
   myModule = loadModule(moduleName);
   if (!myModule)
     return false;
+
+  connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
+    myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
+  connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
+    myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
+
   myModule->createFeatures();
   myActionsMgr->update();
   return true;