Salome HOME
updated copyright message
[modules/shaper.git] / src / PartSet / PartSet_SketcherReentrantMgr.cpp
index 3a003a708396e376f5547075dc0e8b0b8aad871f..5dfd5a26ffdcead2416ca5dab32e7c9a41104dff 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // 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)
 {
 }
 
@@ -177,8 +178,6 @@ bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* the
         workshop()->selector()->clearSelection();
 
         myPreviousFeature = aFOperation->feature();
-        if (myIsAutoConstraints)
-          addConstraints(myPreviousFeature);
         restartOperation();
         myPreviousFeature = FeaturePtr();
 
@@ -190,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);
       }
@@ -363,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;
 
@@ -378,8 +382,11 @@ void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviou
           isStarted = startInternalEdit(thePreviousAttributeID);
         }
       }
-      if (!isStarted)
+      if (!isStarted) {
+        if (myIsAutoConstraints)
+          addConstraints(aFOperation->feature());
         aFOperation->commit();
+      }
     }
   }
 }
@@ -405,7 +412,9 @@ bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAt
 
   if (!isSketchSolverError) {
     myRestartingMode = RM_EmptyFeatureUsed;
-    isDone = startInternalEdit(thePreviousAttributeID);
+    // It seems that the call is obsolete for Enter key processing
+    // It prevent finalysing of the current operation by Enter key
+    //isDone = startInternalEdit(thePreviousAttributeID);
   }
 
   return isDone;
@@ -440,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();
@@ -501,6 +507,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();
 
@@ -523,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];
           }
         }
@@ -837,39 +846,48 @@ 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());
+      myLastAutoConstraint = aFeature.get();
     }
   }
 }
+
+
+bool PartSet_SketcherReentrantMgr::isLastAutoConstraint(const ObjectPtr& theObj) const
+{
+  return theObj.get() == myLastAutoConstraint;
+}