Salome HOME
#748 - move part problem
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index 9559e6bb5d7d74c9016dcae054f9bc466391242b..0d493f7f20f36032d55c98f80cd3e94b0263da21 100644 (file)
@@ -133,6 +133,8 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
   connect(aViewer, SIGNAL(viewTransformed(int)),
           SLOT(onViewTransformed(int)));
+  connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
+          SLOT(onViewCreated(ModuleBase_IViewWindow*)));
 
   myMenuMgr = new PartSet_MenuMgr(this);
   myCustomPrs = new PartSet_CustomPrs(theWshop);
@@ -276,11 +278,6 @@ void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
 
 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
 {
-  // z layer is created for all started operations in order to visualize operation AIS presentation
-  // over the object
-  Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
-  aViewer->AddZLayer(myVisualLayerId);
-
   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
     mySketchMgr->startSketch(theOperation);
   }
@@ -293,11 +290,6 @@ void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
 
 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
 {
-  // the custom presentation should be deactivated before stop sketch,
-  // because it uses the active sketch of the sketch manager without checking if it is not null
-  Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
-  aViewer->RemoveZLayer(myVisualLayerId);
-  myVisualLayerId = 0;
   myCustomPrs->deactivate();
 
   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
@@ -339,6 +331,20 @@ bool PartSet_Module::canRedo() const
   return aCanRedo;
 }
 
+bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
+{
+  bool aValid = true;
+  if (theActionId == "DELETE_CMD" || theActionId == "MOVE_CMD") {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+    if (aFeature) {
+      // part features are removed in the PartSet module only.
+      if (aFeature->getKind() == PartSetPlugin_Part::ID())
+        aValid = false;
+    }
+  }
+  return aValid;
+}
+
 bool PartSet_Module::canCommitOperation() const
 {
   return mySketchMgr->canCommitOperation();
@@ -370,6 +376,12 @@ bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>
   return myMenuMgr->addViewerMenu(theMenu, theStdActions);
 }
 
+void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
+{
+  myMenuMgr->updateViewerMenu(theStdActions);
+}
+
+
 void PartSet_Module::activeSelectionModes(QIntList& theModes)
 {
   theModes.clear();
@@ -605,10 +617,7 @@ bool PartSet_Module::deleteObjects()
     // 4. delete features
     // sketch feature should be skipped, only sub-features can be removed
     // when sketch operation is active
-    std::set<FeaturePtr> anIgnoredFeatures;
-    anIgnoredFeatures.insert(mySketchMgr->activeSketch());
-    aWorkshop->deleteFeatures(aSketchObjects, anIgnoredFeatures);
-  
+    aWorkshop->deleteFeatures(aSketchObjects);
     // 5. stop operation
     aWorkshop->displayer()->updateViewer();
     aMgr->finishOperation();
@@ -914,3 +923,27 @@ void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
     }
   }
 }
+
+
+void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
+{
+  // z layer is created for all started operations in order to visualize operation AIS presentation
+  // over the object
+  Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
+  if (myVisualLayerId == 0) {
+    if (myVisualLayerId == 0)
+      aViewer->AddZLayer(myVisualLayerId);
+  } else {
+    TColStd_SequenceOfInteger aZList;
+    aViewer->GetAllZLayers(aZList);
+    bool aFound = false;
+    for (int i = 1; i <= aZList.Length(); i++) {
+      if (aZList(i) == myVisualLayerId) {
+        aFound = true;
+        break;
+      }
+    }
+    if (!aFound)
+      aViewer->AddZLayer(myVisualLayerId);
+  }
+}