Salome HOME
A fix for a bug: clear content in the shape selector by deselection it in the viewer.
[modules/shaper.git] / src / PartSet / PartSet_SketcherMgr.cpp
index e46d1a60c83d0695a8d2e2d86f8743a2994a3eb6..f3d5bfa320deb4f71dcd88151bbf8852f2f34089 100644 (file)
@@ -56,6 +56,8 @@
 #include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_ConstraintFillet.h>
 #include <SketchPlugin_ConstraintMirror.h>
+#include <SketchPlugin_MultiRotation.h>
+#include <SketchPlugin_MultiTranslation.h>
 
 #include <SketcherPrs_Tools.h>
 
@@ -318,24 +320,25 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
           aOperation->abort();
       return;
     }
+    // Init flyout point for radius rotation
+    FeaturePtr aFeature = myCurrentSelection.begin().key();
 
     if (isSketcher) {
       myIsDragging = true;
       get2dPoint(theWnd, theEvent, myCurrentPoint);
       myDragDone = false;
       launchEditing();
-      // Init flyout point for radius rotation
-      FeaturePtr aFeature = myCurrentSelection.begin().key();
-      std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
-                std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
-      if (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
-        DataPtr aData = aSPFeature->data();
-        AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
-        std::shared_ptr<GeomDataAPI_Point2D> aFPAttr = 
-          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
-        aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
+      if (aFeature.get() != NULL) {
+        std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+                  std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+      if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
+          DataPtr aData = aSPFeature->data();
+          AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
+          std::shared_ptr<GeomDataAPI_Point2D> aFPAttr = 
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
+          aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
+        }
       }
-
     } else if (isSketchOpe && isEditing) {
       // If selected another object commit current result
       aOperation->commit();
@@ -597,19 +600,8 @@ const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
     aIds << SketchPlugin_Point::ID().c_str();
     aIds << SketchPlugin_Arc::ID().c_str();
     aIds << SketchPlugin_Circle::ID().c_str();
-    aIds << SketchPlugin_ConstraintLength::ID().c_str();
-    aIds << SketchPlugin_ConstraintDistance::ID().c_str();
-    aIds << SketchPlugin_ConstraintRigid::ID().c_str();
-    aIds << SketchPlugin_ConstraintRadius::ID().c_str();
-    aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
-    aIds << SketchPlugin_ConstraintParallel::ID().c_str();
-    aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
-    aIds << SketchPlugin_ConstraintVertical::ID().c_str();
-    aIds << SketchPlugin_ConstraintEqual::ID().c_str();
-    aIds << SketchPlugin_ConstraintTangent::ID().c_str();
-    aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
     aIds << SketchPlugin_ConstraintFillet::ID().c_str();
-    aIds << SketchPlugin_ConstraintMirror::ID().c_str();
+    aIds.append(constraintsIdList());
   }
   return aIds;
 }
@@ -630,10 +622,22 @@ const QStringList& PartSet_SketcherMgr::constraintsIdList()
     aIds << SketchPlugin_ConstraintTangent::ID().c_str();
     aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
     aIds << SketchPlugin_ConstraintMirror::ID().c_str();
+    aIds << SketchPlugin_MultiRotation::ID().c_str();
+    aIds << SketchPlugin_MultiTranslation::ID().c_str();
   }
   return aIds;
 }
 
+void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
+{
+  theModes.clear();
+
+  theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
+  theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
+  theModes.append(SketcherPrs_Tools::Sel_Constraint);
+  theModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
+  theModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
+}
 
 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
 {
@@ -704,6 +708,9 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
     myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
   }
   aDisplayer->updateViewer();
+  // all sketch objects should be activated in the sketch selection modes by edit operation start
+  if (theOperation->isEditOperation())
+    activateObjectsInSketchMode(true);
 }
 
 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
@@ -1085,13 +1092,8 @@ void PartSet_SketcherMgr::activateObjectsInSketchMode(const bool isActive)
   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
 
   QIntList aModes;
-  if (isActive) {
-    aModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
-    aModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
-    aModes.append(SketcherPrs_Tools::Sel_Constraint);
-    aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
-    aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
-  }
+  if (isActive)
+    sketchSelectionModes(aModes);
   aDisplayer->activateObjects(aModes);
 }