Salome HOME
Update of the ExportToGEOM test
[modules/shaper.git] / src / PartSet / PartSet_SketcherReentrantMgr.cpp
index c5a4e3cb1b5919da873604ff8f623e1ca257c5a9..839da3fa082c2d3a161d055e2527272ab2e100ee 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"
@@ -32,6 +33,7 @@
 #include "GeomDataAPI_Point2D.h"
 
 #include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_ISelectionActivate.h>
 #include <ModuleBase_OperationFeature.h>
 #include <ModuleBase_ModelWidget.h>
 #include <ModuleBase_ViewerPrs.h>
@@ -42,6 +44,7 @@
 #include <ModuleBase_OperationDescription.h>
 #include "ModuleBase_ToolBox.h"
 #include "ModuleBase_ISelection.h"
+#include "ModuleBase_ISelectionActivate.h"
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Line.h>
@@ -252,6 +255,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);
@@ -260,10 +264,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();
@@ -320,22 +337,24 @@ void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
   aReentrantMessage->setClickedPoint(myClickedSketchPoint);
 }
 
-void PartSet_SketcherReentrantMgr::onWidgetActivated()
-{
-  if (!isActiveMgr())
-    return;
-  if (!myIsInternalEditOperation)
-    return;
-
-  PartSet_Module* aModule = module();
-  ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
-  ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
-  if (aFirstWidget != aPanel->activeWidget()) {
-    ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
-    if (aWSelector)
-      aWSelector->activateSelectionAndFilters(true);
-  }
-}
+//void PartSet_SketcherReentrantMgr::onWidgetActivated()
+//{
+//  if (!isActiveMgr())
+//    return;
+//  if (!myIsInternalEditOperation)
+//    return;
+//
+//  PartSet_Module* aModule = module();
+//  ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
+//  ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
+//  if (aFirstWidget != aPanel->activeWidget()) {
+//    ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>
+//      (aFirstWidget);
+//    if (aWSelector) {
+//      myWorkshop->selectionActivate()->updateSelectionModesAndFilters(aWSelector);
+//    }
+//  }
+//}
 
 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
 {
@@ -361,15 +380,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();
   }
 }
 
@@ -486,6 +510,10 @@ bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePrevi
                                                      (myWorkshop->currentOperation());
 
   if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
+    /// improvement to deselect automatically all eventual selected objects, when
+    // returning to the neutral point of the Sketcher or start internal edit
+    workshop()->selector()->clearSelection();
+
     aFOperation->setEditOperation(true/*, false*/);
     createInternalFeature();
 
@@ -497,7 +525,7 @@ bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePrevi
     connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
 
     // activate selection filters of the first widget in the viewer
-    onWidgetActivated();
+    //onWidgetActivated();
 
     // activate the last active widget in the Property Panel
     if (!thePreviousAttributeID.empty()) {
@@ -652,13 +680,8 @@ 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)
-      aWSelector->activateSelectionAndFilters(false);
+  if (myInternalActiveWidget)
     myInternalActiveWidget = 0;
-  }
   delete myInternalWidget;
   myInternalWidget = 0;