]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Bug #846 Color modification in preferences is applyed to the visualized objects after...
authornds <nds@opencascade.com>
Mon, 31 Aug 2015 05:26:27 +0000 (08:26 +0300)
committernds <nds@opencascade.com>
Mon, 31 Aug 2015 05:26:27 +0000 (08:26 +0300)
Auxiliary,Detach,Delete are corrected to use OperationAction in order to:
1. update AcceptAll button enabled state
2. set into the parent operation isModified state, to show warning about the operation abort, if it happens

src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/NewGeom/NewGeom_Module.cpp
src/PartSet/PartSet_MenuMgr.cpp
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_ActionsMgr.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 009502dcb6f525c7076369ec593aff5780cfed70..66b0a51aaea3e7bba7235649affbb0df5912f54d 100644 (file)
@@ -60,16 +60,6 @@ void ModuleBase_Operation::setGrantedOperationIds(const QStringList& theList)
   myGrantedIds = theList;
 }
 
-void ModuleBase_Operation::addGrantedOperationId(const QString& theId)
-{
-  myGrantedIds.append(theId);
-}
-
-void ModuleBase_Operation::removeGrantedOperationId(const QString& theId)
-{
-  myGrantedIds.removeAll(theId);
-}
-
 QString ModuleBase_Operation::id() const
 {
   return getDescription()->operationId();
index 01a351d1ddc19ed1ea0821057c22c2e242847b7c..9a34e6423d326db9d12ac3012448614579acda58 100644 (file)
@@ -63,14 +63,6 @@ Q_OBJECT
   /// \param theList an ids
   void setGrantedOperationIds(const QStringList& theList);
 
-  /// Appends an operation index to be granted
-  /// \param theId an index
-  void addGrantedOperationId(const QString& theId);
-
-  /// Removes an operation index from the granted
-  /// \param theId an index
-  void removeGrantedOperationId(const QString& theId);
-
   /// Must return true if this operation can be launched as nested for any current operation
   /// and it is not necessary to check this operation on validity. By default 
   /// the operation is not granted.
index c2cc2b33440ba6da239cc87937871ab0211e8ef8..50ff8bc2cd41c60021b55ea6f1c0b78964875032 100644 (file)
@@ -608,6 +608,16 @@ void NewGeom_Module::preferencesChanged(const QString& theSection, const QString
   }
   aProp->setValue(aValue);
 
+  // redisplay objects visualized in the viewer
+  static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+  QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
+  QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
+  for (; anIt != aLast; anIt++) {
+    aECreator->sendUpdated(*anIt, EVENT_DISP);
+  }
+  Events_Loop::loop()->flush(EVENT_DISP);
+
 }
 
 void NewGeom_Module::inspectSalomeModules()
index d6bd2879eb950d2d42d655a1b39d90b562f0daac..f9d7b2153ec2d071851a106f0302fb85b59b0850 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>
@@ -306,15 +308,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 +366,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 +399,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();
index c863177fb495c1dceed15c97976b1fdaeaac5f83..afa03ce055134516a11a457d5440f597601525ee 100755 (executable)
@@ -604,7 +604,11 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
 
 bool PartSet_Module::deleteObjects()
 {
-  SessionPtr aMgr = ModelAPI_Session::get();
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
+
+  //SessionPtr aMgr = ModelAPI_Session::get();
   // 1. check whether the delete should be processed in the module
   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
@@ -613,8 +617,6 @@ bool PartSet_Module::deleteObjects()
     // 2. find selected presentations
     // selected objects should be collected before the current operation abort because
     // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
-    XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
-    XGUI_Workshop* aWorkshop = aConnector->workshop();
     ModuleBase_ISelection* aSel = workshop()->selection();
     QObjectPtrList aSelectedObj = aSel->selectedPresentations();
     // if there are no selected objects in the viewer, that means that the selection in another
@@ -643,25 +645,24 @@ bool PartSet_Module::deleteObjects()
 
     // 3. start operation
     QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
-    ModuleBase_OperationAction* anAction = new ModuleBase_OperationAction(aDescription, this);
+    ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
 
-    XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
     // the active nested sketch operation should be aborted unconditionally
-    if (isSketchOp)
-      anOperation->addGrantedOperationId(anAction->id());
-    if (!anOpMgr->canStartOperation(anAction->id()))
+    // 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 true; // the objects are processed but can not be deleted
-    if (isSketchOp)
-      anOperation->removeGrantedOperationId(anAction->id());
 
-    anOpMgr->startOperation(anAction);
+    anOpMgr->startOperation(anOpAction);
+
     // 4. delete features
     // sketch feature should be skipped, only sub-features can be removed
     // when sketch operation is active
     aWorkshop->deleteFeatures(aSketchObjects);
     // 5. stop operation
     anOpMgr->commitOperation();
-  } else {
+  }
+  else {
     bool isPartRemoved = false;
     // Delete part with help of PartSet plugin
     // TODO: the deleted objects has to be processed by multiselection
@@ -677,10 +678,17 @@ bool PartSet_Module::deleteObjects()
                        std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
           DocumentPtr aPartDoc = aPart->partDoc();
           if (aPartDoc.get()) {
-            aMgr->startOperation(PartSetPlugin_Remove::ID());
+            ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction
+                                              (PartSetPlugin_Remove::ID().c_str(), this);
+            if (!anOpMgr->canStartOperation(anOpAction->id()))
+              return true; // the objects are processed but can not be deleted
+
+            anOpMgr->startOperation(anOpAction);
+
             FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
             aFeature->execute();
-            aMgr->finishOperation();
+
+            anOpMgr->commitOperation();
             isPartRemoved = true;
           }
         }
index 32f7e4af556fdd5b49a985298734a12de3336b92..8b6fbadd1c685e94305ef78d791405823e73c060 100644 (file)
@@ -173,14 +173,6 @@ void XGUI_ActionsMgr::updateOnViewSelection()
   }
 }
 
-void XGUI_ActionsMgr::onAcceptAllToggled(bool theState)
-{
-  if (!theState) {
-    QAction* anAcceptAllAction = operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
-    anAcceptAllAction->setEnabled(theState);
-  }
-}
-
 QKeySequence XGUI_ActionsMgr::registerShortcut(const QKeySequence& theKeySequence)
 {
   if (theKeySequence.isEmpty()) {
@@ -246,9 +238,6 @@ QAction* XGUI_ActionsMgr::operationStateAction(OperationStateActionId theId, QOb
       case Accept:
       case AcceptAll:
         aResult = new QAction(QIcon(":pictures/button_ok.png"), "", theParent);
-        // the default value is disabled, so the next connect is used to restore this
-        // default state by untoggle this action
-        connect(this, SIGNAL(toggled(bool)), this, SLOT(onAcceptAllToggled(bool)));
         break;
       case Abort:
       case AbortAll: {
index 8be19e49ddc77ab93a48a990865e2b8ffb87d27b..9191021ad42650baaae1df0944df3cea0f5d55ee 100644 (file)
@@ -96,9 +96,6 @@ public slots:
   void updateCheckState();
   //! Updates actions according to current selection in the viewer
   void updateOnViewSelection();
-  //! Update the default enable state of the action by untoggle it. The default value is disabled.
-  //! \param theState the new state of the AcceptAll action
-  void onAcceptAllToggled(bool theState);
 
  protected:
   //! Sets all actions to isEnabled state.
index 229801de9664c36f3b383a1716fc703d01a4bb04..8cb968b1c1314fdb58a30613fb9af27f43888926 100644 (file)
@@ -290,12 +290,13 @@ bool XGUI_OperationMgr::isGrantedOperation(ModuleBase_Operation* theOperation)
   return isGranted;
 }
 
-bool XGUI_OperationMgr::canStartOperation(QString theId)
+bool XGUI_OperationMgr::canStartOperation(const QString& theId, const bool isAdditionallyGranted)
 {
   bool aCanStart = true;
   ModuleBase_Operation* aCurrentOp = currentOperation();
   if (aCurrentOp) {
-    if (!aCurrentOp->isGranted(theId)) {
+    bool aGranted = aCurrentOp->isGranted(theId) || isAdditionallyGranted;
+    if (!aGranted) {
       if (canStopOperation(aCurrentOp)) {
         if (myIsApplyEnabled && aCurrentOp->isModified())
           aCurrentOp->commit();
index 55260d6ec1d0eb096d24605a28f109bd5b6d57b6..bfb9fdace117a8d821e8371bb9fbcc05f950d140 100644 (file)
@@ -84,7 +84,8 @@ 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(QString theId);
+  /// \param isAdditionallyGranted a boolean flag whether the id operation is granted in the previous one
+  bool canStartOperation(const QString& theId, const bool isAdditionallyGranted = false);
 
   /// 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
index ab38ca8a1020e0daa6972f7f9db4395528c7417d..804648de6046bb821a56cc9257551918c5357b12 100644 (file)
@@ -63,6 +63,7 @@
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_WidgetFactory.h>
 #include <ModuleBase_OperationFeature.h>
+#include <ModuleBase_OperationAction.h>
 
 #include <Config_Common.h>
 #include <Config_FeatureMessage.h>
@@ -375,7 +376,7 @@ void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const boo
 //******************************************************
 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
 {
-  setNestedFeatures(theOperation);
+  setGrantedFeatures(theOperation);
 
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                                                (theOperation);
@@ -416,7 +417,7 @@ void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
 //******************************************************
 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
 {
-  setNestedFeatures(theOperation);
+  setGrantedFeatures(theOperation);
 
   if (theOperation->getDescription()->hasXmlRepresentation()) {  //!< No need for property panel
     setPropertyPanel(theOperation);
@@ -430,6 +431,8 @@ void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
 //******************************************************
 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
 {
+  updateCommandStatus();
+
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                                         (theOperation);
   if (!aFOperation)
@@ -438,7 +441,6 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
   ModuleBase_ISelection* aSel = mySelector->selection();
   QObjectPtrList aObj = aSel->selectedPresentations();
   //!< No need for property panel
-  updateCommandStatus();
   hidePropertyPanel();
   myPropertyPanel->cleanContent();
 
@@ -474,16 +476,19 @@ void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
   myModule->onOperationAborted(theOperation);
 }
 
-void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
+void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
 {
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
   if (!aFOperation)
     return;
 
+  QStringList aGrantedIds;
   if (isSalomeMode())
-    aFOperation->setGrantedOperationIds(mySalomeConnector->nestedActions(theOperation->id()));
+    aGrantedIds = mySalomeConnector->nestedActions(theOperation->id());
   else
-    aFOperation->setGrantedOperationIds(myActionsMgr->nestedCommands(theOperation->id()));
+    aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
+
+  aFOperation->setGrantedOperationIds(aGrantedIds);
 }
 
 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
@@ -530,7 +535,7 @@ void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>&
   QApplication::restoreOverrideCursor();
 }
 
-bool XGUI_Workshop::isActiveOperationAborted()
+bool XGUI_Workshop::abortAllOperations()
 {
   return myOperationMgr->abortAllOperations();
 }
@@ -578,7 +583,7 @@ void XGUI_Workshop::onNew()
 //******************************************************
 void XGUI_Workshop::onOpen()
 {
-  if(!isActiveOperationAborted())
+  if(!abortAllOperations())
     return;
   //save current file before close if modified
   SessionPtr aSession = ModelAPI_Session::get();
@@ -618,7 +623,7 @@ void XGUI_Workshop::onOpen()
 //******************************************************
 bool XGUI_Workshop::onSave()
 {
-  if(!isActiveOperationAborted())
+  if(!abortAllOperations())
     return false;
   if (myCurrentDir.isEmpty()) {
     return onSaveAs();
@@ -634,7 +639,7 @@ bool XGUI_Workshop::onSave()
 //******************************************************
 bool XGUI_Workshop::onSaveAs()
 {
-  if(!isActiveOperationAborted())
+  if(!abortAllOperations())
     return false;
   QFileDialog dialog(mainWindow());
   dialog.setWindowTitle(tr("Select directory to save files..."));
@@ -750,6 +755,15 @@ void XGUI_Workshop::onPreferences()
           myMainWindow->menuObject()->updateFromResources();
       }
     }
+    // redisplay objects visualized in the viewer
+    static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+    static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+    QObjectPtrList aDisplayed = displayer()->displayedObjects();
+    QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
+    for (; anIt != aLast; anIt++) {
+      aECreator->sendUpdated(*anIt, EVENT_DISP);
+    }
+    Events_Loop::loop()->flush(EVENT_DISP);
   }
 }
 
@@ -1013,7 +1027,7 @@ void XGUI_Workshop::deleteObjects()
     return;
   }
 
-  if (!isActiveOperationAborted())
+  if (!abortAllOperations())
     return;
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
   // It is necessary to clear selection in order to avoid selection changed event during
@@ -1041,39 +1055,24 @@ void XGUI_Workshop::deleteObjects()
     aObjectNames << QString::fromStdString(aObj->data()->name());
   }
   aDescription = aDescription.arg(aObjectNames.join(", "));
+  ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
 
-  SessionPtr aMgr = ModelAPI_Session::get();
-  aMgr->startOperation(aDescription.toStdString());
-  // 2. close the documents of the removed parts if the result part is in a list of selected objects
-  // this is performed in the RemoveFeature of Part object.
-  /*foreach (ObjectPtr aObj, anObjects)
-  {
-    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
-    if (aPart) {
-      DocumentPtr aDoc = aObj->document();
-      if (aDoc == aMgr->activeDocument()) {
-        aDoc->close();
-      }
-    }
-  }*/
+  operationMgr()->startOperation(anOpAction);
   // 3. delete objects
   QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
   std::set<FeaturePtr> anIgnoredFeatures;
   if (deleteFeatures(anObjects, anIgnoredFeatures, aDesktop, true)) {
-    myDisplayer->updateViewer();
-    aMgr->finishOperation();
-    operationMgr()->updateApplyOfOperations();
-    updateCommandStatus();
+    operationMgr()->commitOperation();
   }
   else {
-    aMgr->abortOperation();
+    operationMgr()->abortOperation(operationMgr()->currentOperation());
   }
 }
 
 //**************************************************************
 void XGUI_Workshop::moveObjects()
 {
-  if (!isActiveOperationAborted())
+  if (!abortAllOperations())
     return;
 
   SessionPtr aMgr = ModelAPI_Session::get();
index 60926cf71c6b1b0f2b40d9fa9b36cd37ac32327c..351149422277926dee96b37af8b04e28976fe8a5 100644 (file)
@@ -214,7 +214,7 @@ Q_OBJECT
    * - operation aborted successfully
    * - there is no active operation
    */
-  bool isActiveOperationAborted();
+  bool abortAllOperations();
 
   //! Delete features. Delete the referenced features. There can be a question with a list of referenced
   //! objects.
@@ -304,9 +304,10 @@ signals:
   void closeDocument();
 
  protected:
-  /// Find the nested features and set them into the operation
+  /// Sets the granted operations for the parameter operation. Firtsly, it finds the nested features
+  /// and set them into the operation. Secondly, it asks the module about ids of granted operations.
   /// \param theOperation an operation
-  void setNestedFeatures(ModuleBase_Operation* theOperation);
+   void setGrantedFeatures(ModuleBase_Operation* theOperation);
 
   /// Update the property panel content by the XML description of the operation and set the panel
   /// into the operation