Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / PartSet / PartSet_SketcherReentrantMgr.cpp
index 0e4aebf79659148efb77fa162fe1e4e4f941771d..d861c2b52a210dd4738a937476dc076a4c32752a 100644 (file)
@@ -19,6 +19,7 @@
 //
 
 #include "PartSet_SketcherReentrantMgr.h"
+#include "PartSet_ExternalObjectsMgr.h"
 #include "PartSet_Module.h"
 #include "PartSet_SketcherMgr.h"
 #include "PartSet_WidgetPoint2d.h"
@@ -43,7 +44,6 @@
 #include <ModuleBase_OperationDescription.h>
 #include "ModuleBase_ToolBox.h"
 #include "ModuleBase_ISelection.h"
-#include "ModuleBase_ISelectionActivate.h"
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Line.h>
@@ -70,7 +70,6 @@ PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop*
   myRestartingMode(RM_None),
   myIsFlagsBlocked(false),
   myIsInternalEditOperation(false),
-  myInternalActiveWidget(0),
   myNoMoreWidgetsAttribute("")
 {
 }
@@ -79,24 +78,6 @@ PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
 {
 }
 
-ModuleBase_ModelWidget* PartSet_SketcherReentrantMgr::internalActiveWidget() const
-{
-  ModuleBase_ModelWidget* aWidget = 0;
-  if (!isActiveMgr())
-    return aWidget;
-
-  ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
-  if (anOperation) {
-    ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
-    if (aPanel) { // check for case when the operation is started but property panel is not filled
-      ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
-      if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector()))
-        aWidget = myInternalActiveWidget;
-    }
-  }
-  return aWidget;
-}
-
 bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
 {
   return myIsInternalEditOperation;
@@ -254,6 +235,7 @@ bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow*
 
       myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
                                                      module()->sketchMgr()->activeSketch());
+      FeaturePtr anExternalCreatedFeature;
       if (!aPreSelected.empty()) {
         ModuleBase_ViewerPrsPtr aValue = aPreSelected.first();
         module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute);
@@ -262,10 +244,23 @@ bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow*
         if (aPointWidget) {
           GeomShapePtr aShape;
           aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape);
+          ObjectPtr anExternalObject =
+            aPointWidget->getExternalObjectMgr()->getExternalObjectValidated();
+          // if external object is during reentrant operation and is used as a parameter of feature
+          // it should be removed after the operation is restarted. (Circle feature, Projection)
+          if (anExternalObject.get())
+            anExternalCreatedFeature = ModelAPI_Feature::feature(anExternalObject);
         }
       }
 
       restartOperation();
+      // remove created external feature
+      if (anExternalCreatedFeature.get()) {
+        QObjectPtrList anObjects;
+        anObjects.append(anExternalCreatedFeature);
+        workshop()->deleteFeatures(anObjects);
+      }
+
       myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
       mySelectedObject = ObjectPtr();
       mySelectedAttribute = AttributePtr();
@@ -333,9 +328,10 @@ void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
 //  ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
 //  ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
 //  if (aFirstWidget != aPanel->activeWidget()) {
-//    ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
+//    ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>
+//      (aFirstWidget);
 //    if (aWSelector) {
-//      myWorkshop->selectionActivate()->activateSelectionAndFilters(aWSelector);
+//      myWorkshop->selectionActivate()->updateSelectionModesAndFilters(aWSelector);
 //    }
 //  }
 //}
@@ -364,15 +360,20 @@ void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviou
     return;
 
   if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
-    bool isStarted = false;
-    if (!module()->sketchMgr()->sketchSolverError()) {
-      if (myRestartingMode != RM_Forbided) {
-        myRestartingMode = RM_LastFeatureUsed;
-        isStarted = startInternalEdit(thePreviousAttributeID);
+    if (aFOperation->isNeedToBeAborted()) {
+      aFOperation->abort();
+    }
+    else {
+      bool isStarted = false;
+      if (!module()->sketchMgr()->sketchSolverError()) {
+        if (myRestartingMode != RM_Forbided) {
+          myRestartingMode = RM_LastFeatureUsed;
+          isStarted = startInternalEdit(thePreviousAttributeID);
+        }
       }
+      if (!isStarted)
+        aFOperation->commit();
     }
-    if (!isStarted)
-      aFOperation->commit();
   }
 }
 
@@ -649,7 +650,7 @@ void PartSet_SketcherReentrantMgr::createInternalFeature()
     ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
                                                                                         (aWidgets);
     if (aFirstWidget)
-      myInternalActiveWidget = aFirstWidget;
+      setInternalActiveWidget(aFirstWidget);
   }
 }
 
@@ -659,13 +660,7 @@ void PartSet_SketcherReentrantMgr::deleteInternalFeature()
   std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
             << myInternalFeature->data()->name() << std::endl;
 #endif
-  if (myInternalActiveWidget) {
-    ModuleBase_WidgetSelector* aWSelector =
-      dynamic_cast<ModuleBase_WidgetSelector*>(myInternalActiveWidget);
-    if (aWSelector)
-      myWorkshop->selectionActivate()->activateSelectionAndFilters(aWSelector);
-    myInternalActiveWidget = 0;
-  }
+  setInternalActiveWidget(0);
   delete myInternalWidget;
   myInternalWidget = 0;
 
@@ -814,3 +809,16 @@ PartSet_Module* PartSet_SketcherReentrantMgr::module() const
 {
   return dynamic_cast<PartSet_Module*>(myWorkshop->module());
 }
+
+void PartSet_SketcherReentrantMgr::setInternalActiveWidget(ModuleBase_ModelWidget* theWidget)
+{
+  ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+    (myWorkshop->currentOperation());
+  if (aFOperation)
+  {
+    XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
+      (aFOperation->propertyPanel());
+    if (aPropertyPanel)
+      aPropertyPanel->setInternalActiveWidget(theWidget);
+  }
+}