Salome HOME
Issue #1774: Can't select edge for tangent constraint creation
[modules/shaper.git] / src / PartSet / PartSet_SketcherReetntrantMgr.cpp
index 291382149facf63b05cf4b44ca86d5ac7a19ef91..4cfcf167d8f49f9726c1ca2cb94d447d257c2013 100755 (executable)
 #include <ModuleBase_WidgetFactory.h>
 #include <ModuleBase_OperationDescription.h>
 #include "ModuleBase_ToolBox.h"
+#include "ModuleBase_ISelection.h"
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Point.h>
 
 #include <XGUI_Workshop.h>
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_OperationMgr.h>
 #include <XGUI_PropertyPanel.h>
 #include <XGUI_ErrorMgr.h>
+#include <XGUI_SelectionMgr.h>
 
 #include <QToolButton>
 
@@ -85,7 +88,6 @@ void PartSet_SketcherReetntrantMgr::updateInternalEditActiveState()
       if (!anError.isEmpty()) {
         aFOperation->setEditOperation(false);
         //workshop()->operationMgr()->updateApplyOfOperations();
-        beforeStopInternalEdit();
         myIsInternalEditOperation = false;
         updateAcceptAllAction();
       }
@@ -156,6 +158,11 @@ bool PartSet_SketcherReetntrantMgr::processMouseMoved(ModuleBase_IViewWindow* th
       }
       bool aCanBeActivatedByMove = isLineFeature || isArcFeature;
       if (aCanBeActivatedByMove) {
+        /// before restarting of operation we need to clear selection, as it may take part in
+        /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
+        /// by mouse release when the operation was restarted.
+        workshop()->selector()->clearSelection();\r
+
         myPreviousFeature = aFOperation->feature();
         restartOperation();
         myPreviousFeature = FeaturePtr();
@@ -209,6 +216,13 @@ bool PartSet_SketcherReetntrantMgr::processMouseReleased(ModuleBase_IViewWindow*
       ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                            (myWorkshop->currentOperation());
       myPreviousFeature = aFOperation->feature();
+
+      /// selection should be obtained from workshop before ask if the operation can be started as
+      /// the canStartOperation method performs commit/abort of previous operation. Sometimes commit/abort
+      /// may cause selection clear(Sketch operation) as a result it will be lost and is not used for preselection.
+      ModuleBase_ISelection* aSelection = myWorkshop->selection();
+      QList<ModuleBase_ViewerPrsPtr> aPreSelected = aSelection->getSelected(ModuleBase_ISelection::AllControls);
+
       restartOperation();
       myPreviousFeature = FeaturePtr();
       aProcessed = true;
@@ -219,7 +233,11 @@ bool PartSet_SketcherReetntrantMgr::processMouseReleased(ModuleBase_IViewWindow*
       PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
       ModuleBase_ModelWidget* aFirstWidget = aPanel->findFirstAcceptingValueWidget();
       if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
+        if (!aPreSelected.empty())
+          aPoint2DWdg->setPreSelection(aPreSelected.front());
         aPoint2DWdg->mouseReleased(theWnd, theEvent);
+        if (!aPreSelected.empty())
+          aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
       }
       // unblock viewer update
       ModuleBase_Tools::blockUpdateViewer(false);
@@ -265,8 +283,7 @@ void PartSet_SketcherReetntrantMgr::onNoMoreWidgets(const std::string& thePrevio
   if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
     return;
 
-  if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation,
-                                                    module()->sketchMgr()->activeSketch())) {
+  if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
     bool isStarted = false;
     if (!module()->sketchMgr()->sketchSolverError()) {
       if (myRestartingMode != RM_Forbided) {
@@ -357,8 +374,7 @@ bool PartSet_SketcherReetntrantMgr::isActiveMgr() const
 
   bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
   if (!anActive) {
-    anActive = PartSet_SketcherMgr::isNestedSketchOperation(aCurrentOperation,
-                                                    module()->sketchMgr()->activeSketch());
+    anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
     if (anActive) { // the manager is not active when the current operation is a usual Edit
       ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                        (myWorkshop->currentOperation());
@@ -381,8 +397,7 @@ bool PartSet_SketcherReetntrantMgr::startInternalEdit(const std::string& thePrev
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                      (myWorkshop->currentOperation());
 
-  if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation,
-                                                module()->sketchMgr()->activeSketch())) {
+  if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
     aFOperation->setEditOperation(true/*, false*/);
     createInternalFeature();
 
@@ -461,8 +476,6 @@ void PartSet_SketcherReetntrantMgr::restartOperation()
     if (aFOperation) {
       myNoMoreWidgetsAttribute = "";
       myIsFlagsBlocked = true;
-      FeaturePtr aPrevFeature = aFOperation->feature();
-      aFOperation->commit();
       module()->launchOperation(aFOperation->id());
       myIsFlagsBlocked = false;
       resetFlags();
@@ -483,8 +496,7 @@ void PartSet_SketcherReetntrantMgr::createInternalFeature()
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                      (myWorkshop->currentOperation());
 
-  if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation,
-                                                          module()->sketchMgr()->activeSketch())) {
+  if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
     FeaturePtr anOperationFeature = aFOperation->feature();
 
     CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
@@ -554,7 +566,8 @@ bool PartSet_SketcherReetntrantMgr::copyReetntrantAttributes(const FeaturePtr& t
                                                              const bool isTemporary)
 {
   bool aChanged = false;
-  if (!theSourceFeature.get())
+  if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
+      !theSourceFeature->data()->isValid())
     return aChanged;
 
   std::string aFeatureKind = theSourceFeature->getKind();
@@ -615,12 +628,12 @@ bool PartSet_SketcherReetntrantMgr::copyReetntrantAttributes(const FeaturePtr& t
 }
 
 bool PartSet_SketcherReetntrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
-                                                 const CompositeFeaturePtr& theSketch)
+                                                 const CompositeFeaturePtr& /*theSketch*/) const
 {
   bool aTangentArc = false;
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                                         (theOperation);
-  if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation, theSketch)) {
+  if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
     FeaturePtr aFeature = aFOperation->feature();
     if (aFeature.get() && aFeature->getKind() == SketchPlugin_Arc::ID()) {
       AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_Arc::ARC_TYPE());