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();
/// \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.
}
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()
#include <ModuleBase_ISelection.h>
#include <ModuleBase_Operation.h>
+#include <ModuleBase_OperationAction.h>
#include <ModuleBase_OperationFeature.h>
#include <XGUI_ModuleConnector.h>
#include <XGUI_Displayer.h>
#include <XGUI_DataModel.h>
#include <XGUI_ObjectsBrowser.h>
+#include <XGUI_OperationMgr.h>
#include <Events_Loop.h>
#include <ModelAPI_Events.h>
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();
}
}
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();
}
}
}
- 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();
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),
// 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
// 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
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;
}
}
}
}
-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()) {
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: {
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.
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();
/// 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
#include <ModuleBase_Tools.h>
#include <ModuleBase_WidgetFactory.h>
#include <ModuleBase_OperationFeature.h>
+#include <ModuleBase_OperationAction.h>
#include <Config_Common.h>
#include <Config_FeatureMessage.h>
//******************************************************
void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
{
- setNestedFeatures(theOperation);
+ setGrantedFeatures(theOperation);
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(theOperation);
//******************************************************
void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
{
- setNestedFeatures(theOperation);
+ setGrantedFeatures(theOperation);
if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
setPropertyPanel(theOperation);
//******************************************************
void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
{
+ updateCommandStatus();
+
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(theOperation);
if (!aFOperation)
ModuleBase_ISelection* aSel = mySelector->selection();
QObjectPtrList aObj = aSel->selectedPresentations();
//!< No need for property panel
- updateCommandStatus();
hidePropertyPanel();
myPropertyPanel->cleanContent();
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)
QApplication::restoreOverrideCursor();
}
-bool XGUI_Workshop::isActiveOperationAborted()
+bool XGUI_Workshop::abortAllOperations()
{
return myOperationMgr->abortAllOperations();
}
//******************************************************
void XGUI_Workshop::onOpen()
{
- if(!isActiveOperationAborted())
+ if(!abortAllOperations())
return;
//save current file before close if modified
SessionPtr aSession = ModelAPI_Session::get();
//******************************************************
bool XGUI_Workshop::onSave()
{
- if(!isActiveOperationAborted())
+ if(!abortAllOperations())
return false;
if (myCurrentDir.isEmpty()) {
return onSaveAs();
//******************************************************
bool XGUI_Workshop::onSaveAs()
{
- if(!isActiveOperationAborted())
+ if(!abortAllOperations())
return false;
QFileDialog dialog(mainWindow());
dialog.setWindowTitle(tr("Select directory to save files..."));
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);
}
}
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
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();
* - 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.
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