]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #3039: Add a constraint on a last line of a contour
authorvsv <vsv@opencascade.com>
Fri, 4 Oct 2019 08:43:01 +0000 (11:43 +0300)
committervsv <vsv@opencascade.com>
Fri, 4 Oct 2019 08:43:01 +0000 (11:43 +0300)
src/PartSet/PartSet_SketcherReentrantMgr.cpp

index 5ae47888989d7855d7ec04174d6044d4c5fa3794..d46c5d30dddae5eb37e7604f55e779e7877358f3 100644 (file)
@@ -177,8 +177,6 @@ bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* the
         workshop()->selector()->clearSelection();
 
         myPreviousFeature = aFOperation->feature();
-        if (myIsAutoConstraints)
-          addConstraints(myPreviousFeature);
         restartOperation();
         myPreviousFeature = FeaturePtr();
 
@@ -378,8 +376,11 @@ void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviou
           isStarted = startInternalEdit(thePreviousAttributeID);
         }
       }
-      if (!isStarted)
+      if (!isStarted) {
+        if (myIsAutoConstraints)
+          addConstraints(aFOperation->feature());
         aFOperation->commit();
+      }
     }
   }
 }
@@ -503,6 +504,9 @@ bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePrevi
     // returning to the neutral point of the Sketcher or start internal edit
     workshop()->selector()->clearSelection();
 
+    if (myIsAutoConstraints)
+      addConstraints(aFOperation->feature());
+
     aFOperation->setEditOperation(true/*, false*/);
     createInternalFeature();
 
@@ -839,39 +843,40 @@ void PartSet_SketcherReentrantMgr::onAutoConstraints(bool isOn)
 
 void PartSet_SketcherReentrantMgr::addConstraints(const FeaturePtr& theFeature)
 {
+  if (theFeature->getKind() != SketchPlugin_Line::ID())
+    return;
+
   static GeomDir2dPtr myHorDir(new GeomAPI_Dir2d(1, 0));
   static GeomDir2dPtr myVertDir(new GeomAPI_Dir2d(0, 1));
 
-  if (theFeature->getKind() == SketchPlugin_Line::ID()) {
-    std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-    std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        aData->attribute(SketchPlugin_Line::START_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        aData->attribute(SketchPlugin_Line::END_ID()));
-    if (aPoint1.get() && aPoint2.get()) {
-      GeomLine2dPtr aLine(new GeomAPI_Lin2d(aPoint1->pnt(), aPoint2->pnt()));
-      GeomDir2dPtr aDir = aLine->direction();
-      double aHorAngle = fabs(myHorDir->angle(aDir));
-      double aVertAngle = fabs(myVertDir->angle(aDir));
-      if (aHorAngle > M_PI/2.)
-        aHorAngle = M_PI - aHorAngle;
-      if (aVertAngle > M_PI/2.)
-        aVertAngle = M_PI - aVertAngle;
-
-      double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance");
-      CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
-      FeaturePtr aFeature;
-      if (aHorAngle < aTolerance)
-        // Add horizontal constraint
-        aFeature = aSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID());
-      else if (aVertAngle < aTolerance)
-        // Add vertical constraint
-        aFeature = aSketch->addFeature(SketchPlugin_ConstraintVertical::ID());
-
-      if (aFeature.get()) {
-        aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(
-            theFeature->firstResult());
-      }
+  std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aData->attribute(SketchPlugin_Line::START_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aData->attribute(SketchPlugin_Line::END_ID()));
+  if (aPoint1.get() && aPoint2.get()) {
+    GeomLine2dPtr aLine(new GeomAPI_Lin2d(aPoint1->pnt(), aPoint2->pnt()));
+    GeomDir2dPtr aDir = aLine->direction();
+    double aHorAngle = fabs(myHorDir->angle(aDir));
+    double aVertAngle = fabs(myVertDir->angle(aDir));
+    if (aHorAngle > M_PI/2.)
+      aHorAngle = M_PI - aHorAngle;
+    if (aVertAngle > M_PI/2.)
+      aVertAngle = M_PI - aVertAngle;
+
+    double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance");
+    CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
+    FeaturePtr aFeature;
+    if (aHorAngle < aTolerance)
+      // Add horizontal constraint
+      aFeature = aSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID());
+    else if (aVertAngle < aTolerance)
+      // Add vertical constraint
+      aFeature = aSketch->addFeature(SketchPlugin_ConstraintVertical::ID());
+
+    if (aFeature.get()) {
+      aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(
+          theFeature->firstResult());
     }
   }
 }