Salome HOME
Issue #1011 In sketch edition, the cross cursor must be displayed only in the 3D...
[modules/shaper.git] / src / PartSet / PartSet_MenuMgr.cpp
index d6bd2879eb950d2d42d655a1b39d90b562f0daac..9b82b66c3460a2bba5e43223dd5def81c76164ae 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_Operation.h>
+#include <ModuleBase_OperationAction.h>
 #include <ModuleBase_OperationFeature.h>
 
 #include <XGUI_ModuleConnector.h>
@@ -29,6 +30,7 @@
 #include <XGUI_Displayer.h>
 #include <XGUI_DataModel.h>
 #include <XGUI_ObjectsBrowser.h>
+#include <XGUI_OperationMgr.h>
 
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
@@ -77,10 +79,6 @@ void PartSet_MenuMgr::createActions()
   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onActivatePart(bool)));
   myActions["ACTIVATE_PART_CMD"] = aAction;
 
-  aAction = new QAction(QIcon(":icons/deactivate.png"), tr("Deactivate"), this);
-  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onActivatePartSet(bool)));
-  myActions["DEACTIVATE_PART_CMD"] = aAction;
-
   // Activate PartSet
   aAction = new QAction(QIcon(":icons/activate.png"), tr("Activate"), this);
   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onActivatePartSet(bool)));
@@ -306,15 +304,21 @@ void PartSet_MenuMgr::onLineDetach(QAction* theAction)
     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
     XGUI_Workshop* aWorkshop = aConnector->workshop();
     ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation();
-    if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
-      anOperation->abort();
 
-    SessionPtr aMgr = ModelAPI_Session::get();
-
-    QString aName = tr("Detach %1").arg(aLine->data()->name().c_str());
-    aMgr->startOperation(aName.toStdString());
+    ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(
+                                   tr("Detach %1").arg(aLine->data()->name().c_str()), myModule);
+    bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation);
+    XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
+    // the active nested sketch operation should be aborted unconditionally
+    // the Delete action should be additionally granted for the Sketch operation
+    // in order to do not abort/commit it
+    if (!anOpMgr->canStartOperation(anOpAction->id(), isSketchOp/*granted*/))
+      return; // the objects are processed but can not be deleted
+
+    anOpMgr->startOperation(anOpAction);
     aWorkshop->deleteFeatures(aToDelFeatures);
-    aMgr->finishOperation();
+    
+    anOpMgr->commitOperation();
   }
   myCoinsideLines.clear();
 }
@@ -358,11 +362,18 @@ void PartSet_MenuMgr::setAuxiliary(const bool isChecked)
   }
 
   QAction* anAction = action("AUXILIARY_CMD");
-  SessionPtr aMgr = ModelAPI_Session::get();
+  //SessionPtr aMgr = ModelAPI_Session::get();
+  ModuleBase_OperationAction* anOpAction = 0;
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
+  XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
   if (isUseTransaction) {
-    if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
-      anOperation->abort();
-    aMgr->startOperation(anAction->text().toStdString());
+    anOpAction = new ModuleBase_OperationAction(anAction->text(), myModule);
+    bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation);
+
+    if (!anOpMgr->canStartOperation(anOpAction->id(), isSketchOp/*granted*/))
+      return; // the objects are processed but can not be deleted
+
+    anOpMgr->startOperation(anOpAction);
   }
   myModule->sketchMgr()->storeSelection();
 
@@ -384,12 +395,8 @@ void PartSet_MenuMgr::setAuxiliary(const bool isChecked)
       }
     }
   }
-  if (isUseTransaction) {
-    aMgr->finishOperation();
-    XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
-    XGUI_Workshop* aWorkshop = aConnector->workshop();
-    aWorkshop->updateCommandStatus();
-  }
+  if (isUseTransaction)
+    anOpMgr->commitOperation();
 
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
   myModule->sketchMgr()->restoreSelection();
@@ -470,16 +477,17 @@ void PartSet_MenuMgr::onActivatePartSet(bool)
 {
   if (myModule->workshop()->currentOperation())
     return;
+  activatePartSet();
+}
+
+void PartSet_MenuMgr::activatePartSet() const
+{
   SessionPtr aMgr = ModelAPI_Session::get();
   bool isNewTransaction = !aMgr->isOperation();
   // activation may cause changes in current features in document, so it must be in transaction
-  if (isNewTransaction) {
-    aMgr->startOperation("Activation");
-  }
+  if (isNewTransaction) aMgr->startOperation("Activation");
   aMgr->setActiveDocument(aMgr->moduleDocument());
-  if (isNewTransaction) {
-    aMgr->finishOperation();
-  }
+  if (isNewTransaction) aMgr->finishOperation();
 }
 
 void PartSet_MenuMgr::onEdit(bool)