Salome HOME
Issue #2024 Redesign of circle and arc of circle : restart operation will not happen...
authornds <nds@opencascade.com>
Tue, 4 Apr 2017 05:49:30 +0000 (08:49 +0300)
committernds <nds@opencascade.com>
Tue, 4 Apr 2017 05:49:30 +0000 (08:49 +0300)
Sometimes there is a crash by line restart if the previous Line creation is aborted: in processEvent of Line feature, where the attribute of previous created feature is used to build coincidence to start point of new feature Line.

12 files changed:
src/ModuleBase/ModuleBase_IModule.cpp
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_IWorkshop.h
src/PartSet/PartSet_MenuMgr.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherReentrantMgr.cpp
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_ModuleConnector.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h

index 7dc2d8f82e28c7b550a6c4919cb2151340858b92..39f9abc799b7e20de9e6ba9aa09aba247b15d782 100644 (file)
@@ -56,7 +56,8 @@ ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent)
 
 void ModuleBase_IModule::launchModal(const QString& theCmdId)
 {
-  if (!myWorkshop->canStartOperation(theCmdId))
+  bool isCommitted;
+  if (!myWorkshop->canStartOperation(theCmdId, isCommitted))
     return;
 
   std::string aXmlCfg, aDescription;
@@ -74,7 +75,8 @@ void ModuleBase_IModule::launchModal(const QString& theCmdId)
 }
 
 
-void ModuleBase_IModule::launchOperation(const QString& theCmdId)
+void ModuleBase_IModule::launchOperation(const QString& theCmdId,
+                                         const bool& isStartAfterCommitOnly)
 {
   /// selection should be obtained from workshop before ask if the operation can be started as
   /// the canStartOperation method performs commit/abort of previous operation.
@@ -84,7 +86,12 @@ void ModuleBase_IModule::launchOperation(const QString& theCmdId)
   QList<ModuleBase_ViewerPrsPtr> aPreSelected =
     aSelection->getSelected(ModuleBase_ISelection::AllControls);
 
-  if (!myWorkshop->canStartOperation(theCmdId))
+  bool isCommitted;
+  if (!myWorkshop->canStartOperation(theCmdId, isCommitted))
+    return;
+
+  /// reentrant operation(Sketch Line) should not be started if operation is aborted
+  if (isStartAfterCommitOnly && !isCommitted)
     return;
 
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
@@ -220,8 +227,10 @@ void ModuleBase_IModule::onFeatureTriggered()
   //Do nothing on uncheck
   if (aCmd->isCheckable() && !aCmd->isChecked()) {
     ModuleBase_Operation* anOperation = myWorkshop->findStartedOperation(aCmd->data().toString());
-    if (myWorkshop->canStopOperation(anOperation))
-      myWorkshop->stopOperation(anOperation);
+    if (myWorkshop->canStopOperation(anOperation)) {
+      bool isCommitted;
+      myWorkshop->stopOperation(anOperation, isCommitted);
+    }
     else {
       aCmd->setChecked(true);
     }
@@ -232,7 +241,7 @@ void ModuleBase_IModule::onFeatureTriggered()
     if (aInfo.get() && aInfo->isModal()) {
       launchModal(aCmdId);
     } else {
-      launchOperation(aCmdId);
+      launchOperation(aCmdId, false);
       emit operationLaunched();
     }
   }
@@ -241,7 +250,8 @@ void ModuleBase_IModule::onFeatureTriggered()
 void ModuleBase_IModule::editFeature(FeaturePtr theFeature)
 {
   std::string aFeatureId = theFeature->getKind();
-  if (!myWorkshop->canStartOperation(aFeatureId.c_str()))
+  bool isCommitted;
+  if (!myWorkshop->canStartOperation(aFeatureId.c_str(), isCommitted))
     return;
 
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
index 62b746eabb821cd8fe4c368bbece1eb705162d6c..11a32c888e23b37930f0c333e2081eb6e8aa1045 100755 (executable)
@@ -85,7 +85,10 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
 
   /// Creates an operation and send it to loop
   /// \param theCmdId the operation name
-  virtual void launchOperation(const QString& theCmdId);
+  /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
+  ///        it is committed
+  virtual void launchOperation(const QString& theCmdId,
+                               const bool& isStartAfterCommitOnly);
 
   /// Executes feature as a modal dialog box
   /// \param theCmdId the operation name
index a9c66405d9a8836758299ebe1ceee3920f6c2fd5..97e13ffbbd59674b111db54177da1fd9e5781496 100644 (file)
@@ -74,7 +74,7 @@ Q_OBJECT
   virtual ModuleBase_Operation* currentOperation() const = 0;
 
   //! Returns true if the operation with id theId can be started
-  virtual bool canStartOperation(QString theId) = 0;
+  virtual bool canStartOperation(QString theId, bool& isCommitted) = 0;
 
   //! Performs the operation launch
   //! \param theOperation an operation to be launched
@@ -92,7 +92,9 @@ Q_OBJECT
 
   //! Commits if possible or aborts the given operation.
   //! \param theOperation an aborted operation
-  virtual void stopOperation(ModuleBase_Operation* theOperation) = 0;
+  /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
+  virtual void stopOperation(ModuleBase_Operation* theOperation,
+                             bool& isCommitted) = 0;
 
   //! Returns AIS object by data object
   //! \param theObject a data object
index b249f2311983ade7c75c110a9b176c1c74c641d9..c65d42515b6d585fba3d8e195bed6c497166622f 100644 (file)
@@ -299,7 +299,8 @@ void PartSet_MenuMgr::onLineDetach(QAction* theAction)
     // 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(tr("Detach")))
+    bool isCommitted;
+    if (!anOpMgr->canStartOperation(tr("Detach"), isCommitted))
       return; // the objects are processed but can not be deleted
 
     anOpMgr->startOperation(anOpAction);
@@ -358,7 +359,8 @@ void PartSet_MenuMgr::setAuxiliary(const bool isChecked)
     anOpAction = new ModuleBase_OperationAction(anAction->text(), myModule);
     bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation);
 
-    if (!anOpMgr->canStartOperation(anOpAction->id()))
+    bool isCommitted;
+    if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
       return; // the objects are processed but can not be deleted
 
     anOpMgr->startOperation(anOpAction);
index 41c2d3b04db528cb807b85e8bab3ff3fd3310732..e1bac3b35ead0d0ad08436dfc1cfc9ed6ec74aa5 100755 (executable)
@@ -828,7 +828,8 @@ bool PartSet_Module::deleteObjects()
     // 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()))
+    bool isCommitted;
+    if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
       return true; // the objects are processed but can not be deleted
 
     anOpMgr->startOperation(anOpAction);
@@ -850,29 +851,6 @@ bool PartSet_Module::deleteObjects()
   return isProcessed;
 }
 
-void PartSet_Module::onFeatureTriggered()
-{
-  // is commented for imp: Unpressing the button of the current action must behave like
-  // a validation if the entity can be created (instead of Cancel, as currently)
-  /*QAction* aCmd = dynamic_cast<QAction*>(sender());
-  if (aCmd->isCheckable() && aCmd->isChecked()) {
-    // 1. check whether the delete should be processed in the module
-    ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
-    bool isNestedOp = myModule->sketchMgr()->isNestedCreateOperation(anOperation);
-    if (isNestedOp) {
-      // in case if in the viewer nothing is displayed, the create operation should not be
-      // comitted even if all values of the feature are initialized
-      if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
-        // the action information should be saved before the operation is aborted
-        // because this abort leads to update command status, which unchecks this action
-        anOperation->abort();
-        launchOperation(aCmd->data().toString());
-      }
-    }
-  }*/
-  ModuleBase_IModule::onFeatureTriggered();
-}
-
 void PartSet_Module::editFeature(FeaturePtr theFeature)
 {
   storeConstraintsState(theFeature->getKind());
@@ -884,13 +862,13 @@ bool PartSet_Module::canCommitOperation() const
   return true;
 }
 
-void PartSet_Module::launchOperation(const QString& theCmdId)
+void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
 {
   myIsOperationIsLaunched = true;
   storeConstraintsState(theCmdId.toStdString());
   updateConstraintsState(theCmdId.toStdString());
 
-  ModuleBase_IModule::launchOperation(theCmdId);
+  ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
 
   myIsOperationIsLaunched = false;
 }
index 7292bb30ad20c54e0ffc28aa478573394d6e782a..649e3d3e289e2c0e8af307c434b5874ef4c4eecf 100755 (executable)
@@ -106,7 +106,10 @@ public:
 
   /// Creates an operation and send it to loop
   /// \param theCmdId the operation name
-  virtual void launchOperation(const QString& theCmdId);
+  /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
+  ///        it is committed
+  virtual void launchOperation(const QString& theCmdId,
+                               const bool& isStartAfterCommitOnly);
 
   /// Realizes some functionality by an operation start
   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
@@ -349,11 +352,6 @@ public:
   XGUI_Workshop* getWorkshop() const;
 
 public slots:
-  /// Redefines the parent method in order to customize the next case:
-  /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
-  /// the operation should be always aborted.
-  virtual void onFeatureTriggered();
-
   /// Slolt called on object display
   /// \param theObject a data object
   /// \param theAIS a presentation object
index a63586cef8adb0c093ee969f3730e483d029477f..f724f3aa64619fdb862a6802234b490320057cd1 100755 (executable)
@@ -306,17 +306,15 @@ void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
 
 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  // Clear dragging mode
+  myIsDragging = false;
+
   if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
     return;
-
   //get2dPoint(theWnd, theEvent, myClickedPoint);
-
   if (!(theEvent->buttons() & Qt::LeftButton))
     return;
 
-  // Clear dragging mode
-  myIsDragging = false;
-
   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
   ModuleBase_IViewer* aViewer = aWorkshop->viewer();
   if (!aViewer->canDragByMouse())
@@ -425,6 +423,9 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
 
 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  bool aWasDragging = myIsDragging;
+  myIsDragging = false;
+
   if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
     return;
 
@@ -440,7 +441,7 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
   if (aOp) {
     if (isNestedSketchOperation(aOp)) {
       // Only for sketcher operations
-      if (myIsDragging) {
+      if (aWasDragging) {
         if (myDragDone) {
           myCurrentSelection.clear();
         }
@@ -449,7 +450,6 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
   }
 
   aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
-  myIsDragging = false;
 
   ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
   PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
index b355a8869e1bb8be90d1ee1b49b804fdfd1c5639..b9c92f940c6a08d417f4ea475cb1d873f8698882 100644 (file)
@@ -546,15 +546,16 @@ void PartSet_SketcherReentrantMgr::restartOperation()
       QList<ModuleBase_ViewerPrsPtr> aPreSelected =
         aSelection->getSelected(ModuleBase_ISelection::AllControls);
 
-
-
       if (myInternalFeature.get())
         copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
                                   module()->sketchMgr()->activeSketch());
 
       myNoMoreWidgetsAttribute = "";
       myIsFlagsBlocked = true;
-      module()->launchOperation(aFOperation->id());
+      /// launch has 'false' parameter to do not start new operation if the previous operation
+      /// is not committed. It is important for Line Sketch feature as it uses the previous
+      /// created feature parameter(to build coincidence), but by abort the previous is removed
+      module()->launchOperation(aFOperation->id(), true);
       myIsFlagsBlocked = false;
       resetFlags();
 
index e6b6cf73fe249565817b83988643a47659e149df..51358f13c1246adc1cffa9591ced1e38f6404037 100644 (file)
@@ -131,9 +131,9 @@ void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
   myWorkshop->setStatusBarMessage(theMessage);
 }
 
-bool XGUI_ModuleConnector::canStartOperation(QString theId)
+bool XGUI_ModuleConnector::canStartOperation(QString theId, bool& isCommitted)
 {
-  return myWorkshop->operationMgr()->canStartOperation(theId);
+  return myWorkshop->operationMgr()->canStartOperation(theId, isCommitted);
 }
 
 void XGUI_ModuleConnector::processLaunchOperation(ModuleBase_Operation* theOperation)
@@ -164,9 +164,10 @@ bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
   return myWorkshop->operationMgr()->canStopOperation(theOperation);
 }
 
-void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation)
+void XGUI_ModuleConnector::stopOperation(ModuleBase_Operation* theOperation,
+                                         bool& isCommitted)
 {
-  myWorkshop->operationMgr()->stopOperation(theOperation);
+  myWorkshop->operationMgr()->stopOperation(theOperation, isCommitted);
 }
 
 void XGUI_ModuleConnector::updateCommandStatus()
index eb4c37c4f27de2caeda07fe73b2ef6b94c45e589..543d0279a62df6adb33c38fe6877d8c2c5e5ac96 100644 (file)
@@ -57,7 +57,9 @@ Q_OBJECT
   virtual ModuleBase_Operation* currentOperation() const;
 
   //! Returns true if the operation with id theId can be started
-  virtual bool canStartOperation(QString theId);
+  /// \param theId id of the operation which is going to start
+  /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
+  virtual bool canStartOperation(QString theId, bool& isCommitted);
 
   //! Performs the operation launch
   //! \param theOperation an operation to be launched
@@ -75,7 +77,9 @@ Q_OBJECT
 
   //! Commits if possible or aborts the given operation.
   //! \param theOperation an aborted operation
-  virtual void stopOperation(ModuleBase_Operation* theOperation);
+  /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
+  virtual void stopOperation(ModuleBase_Operation* theOperation,
+                             bool& isCommitted);
 
   //! Returns AIS object by data object
   virtual AISObjectPtr findPresentation(const ObjectPtr& theObject) const;
index 6c234bee827ee14ad0639ccc8172e473cb5ca567..61adc99ea80937249f3c07a803ca494ad3c98561 100644 (file)
@@ -355,9 +355,10 @@ void XGUI_OperationMgr::setCurrentFeature(const FeaturePtr& theFeature)
     aMgr->finishOperation();
 }
 
-bool XGUI_OperationMgr::canStartOperation(const QString& theId)
+bool XGUI_OperationMgr::canStartOperation(const QString& theId, bool& isCommitted)
 {
   bool aCanStart = true;
+  isCommitted = false;
   ModuleBase_Operation* aCurrentOp = currentOperation();
   if (aCurrentOp) {
     bool aGranted = aCurrentOp->isGranted(theId);
@@ -375,7 +376,7 @@ bool XGUI_OperationMgr::canStartOperation(const QString& theId)
       else if (canStopOperation(aCurrentOp)) {
         // the started operation is granted in the parrent operation,
         // e.g. current - Line in Sketch, started Circle
-        stopOperation(aCurrentOp);
+        stopOperation(aCurrentOp, isCommitted);
       } else {
         aCanStart = false;
       }
@@ -384,12 +385,14 @@ bool XGUI_OperationMgr::canStartOperation(const QString& theId)
   return aCanStart;
 }
 
-void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation)
+void XGUI_OperationMgr::stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted)
 {
   if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() && theOperation->isModified())
-    theOperation->commit();
-  else
+    isCommitted = theOperation->commit();
+  else {
+    isCommitted = false;
     abortOperation(theOperation);
+  }
 }
 
 void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
index cca5bb926a37e9c32b903f1a7b36e28ceea54b3e..c8ccf9d08a7b2d1380db13cfe2f550e6f21ca277 100755 (executable)
@@ -101,11 +101,13 @@ Q_OBJECT
   /// Returns whether the operation can be started. Check if there is already started operation and
   /// the granted parameter of the launched operation
   /// \param theId id of the operation which is going to start
-  bool canStartOperation(const QString& theId);
+  /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
+  bool canStartOperation(const QString& theId, bool& isCommitted);
 
   /// If Apply is enabled and operation has modification, it is applyed, otherwise aborted
   /// \param theOperation the started operation
-  void stopOperation(ModuleBase_Operation* theOperation);
+  /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
+  void stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted);
 
   /// Aborts the parameter operation if it is current, else abort operations from the stack
   /// of operations until the operation is found. All operations upper the parameter one are