From: nds Date: Mon, 31 Aug 2015 05:26:27 +0000 (+0300) Subject: Bug #846 Color modification in preferences is applyed to the visualized objects after... X-Git-Tag: V_1.4.0_beta4~196 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9503b9474d57935de95296dfe6587f6422a6d85d;p=modules%2Fshaper.git Bug #846 Color modification in preferences is applyed to the visualized objects after a model modification 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 --- diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 009502dcb..66b0a51aa 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -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(); diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 01a351d1d..9a34e6423 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -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. diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index c2cc2b334..50ff8bc2c 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -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() diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index d6bd2879e..f9d7b2153 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -29,6 +30,7 @@ #include #include #include +#include #include #include @@ -306,15 +308,21 @@ void PartSet_MenuMgr::onLineDetach(QAction* theAction) XGUI_ModuleConnector* aConnector = dynamic_cast(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(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(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(); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index c863177fb..afa03ce05 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -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(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(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(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; } } diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp index 32f7e4af5..8b6fbadd1 100644 --- a/src/XGUI/XGUI_ActionsMgr.cpp +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -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: { diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h index 8be19e49d..9191021ad 100644 --- a/src/XGUI/XGUI_ActionsMgr.h +++ b/src/XGUI/XGUI_ActionsMgr.h @@ -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. diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 229801de9..8cb968b1c 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -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(); diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index 55260d6ec..bfb9fdace 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -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 diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index ab38ca8a1..804648de6 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -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 (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 (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(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& 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(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 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(); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 60926cf71..351149422 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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