Salome HOME
Copyright update 2021
[modules/shaper.git] / src / PartSet / PartSet_SketcherReentrantMgr.cpp
index d46c5d30dddae5eb37e7604f55e779e7877358f3..ea08becbc2b3469d2d0ea38ea35e296136e7e14d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -75,7 +75,8 @@ PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop*
   myIsFlagsBlocked(false),
   myIsInternalEditOperation(false),
   myNoMoreWidgetsAttribute(""),
-  myIsAutoConstraints(true)
+  myIsAutoConstraints(true),
+  myLastAutoConstraint(0)
 {
 }
 
@@ -188,8 +189,8 @@ bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* the
         }
       } else {
         // processing mouse move in active widget of restarted operation
-        ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
-        PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
+        ModuleBase_ModelWidget* anActiveWdg = module()->activeWidget();
+        PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWdg);
         if (aProcessor)
           aProcessor->mouseMoved(theWnd, theEvent);
       }
@@ -361,6 +362,11 @@ void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviou
 
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                        (myWorkshop->currentOperation());
+  if (module()->sketchMgr()->isDragModeCreation()) {
+    if (aFOperation && myIsAutoConstraints)
+      addConstraints(aFOperation->feature());
+    return;
+  }
   if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
     return;
 
@@ -443,10 +449,7 @@ void PartSet_SketcherReentrantMgr::onVertexSelected()
 
 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
 {
-
   if (isInternalEditActive()) {
-    ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
-                                                       (myWorkshop->currentOperation());
     ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
     if (!aWidget->isModifiedInEdit().empty())
       restartOperation();
@@ -529,9 +532,9 @@ bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePrevi
         QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
         for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
           if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
-          /// workaround for the same attributes used in different stacked widgets(attribute types)
-          if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
-            continue;
+            // workaround for the same attributes used in different stacked widgets(attribute types)
+            if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
+              continue;
             aPreviousAttributeWidget = aWidgets[i];
           }
         }
@@ -867,16 +870,24 @@ void PartSet_SketcherReentrantMgr::addConstraints(const FeaturePtr& theFeature)
     double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance");
     CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
     FeaturePtr aFeature;
-    if (aHorAngle < aTolerance)
+    if (aHorAngle < aTolerance) {
       // Add horizontal constraint
       aFeature = aSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID());
-    else if (aVertAngle < aTolerance)
+    }
+    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());
+      myLastAutoConstraint = aFeature.get();
     }
   }
 }
+
+
+bool PartSet_SketcherReentrantMgr::isLastAutoConstraint(const ObjectPtr& theObj) const
+{
+  return theObj.get() == myLastAutoConstraint;
+}