X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Workshop.cpp;h=ded693fcf6894aace0670d1b8a44ae95c3594fae;hb=053bed33433b464fc9dc4f876310cb7b344b3031;hp=43f8e9f83b66c7c86331fdc6caacc3909def4cfe;hpb=537afa7e604c3b071def66b40f00a04cb74261de;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 43f8e9f83..ded693fcf 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -16,6 +16,7 @@ #include "XGUI_ContextMenuMgr.h" #include "XGUI_ModuleConnector.h" #include +#include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include #include #include @@ -68,6 +70,9 @@ #include #include #include +#include +#include +#include #ifdef _DEBUG #include @@ -222,10 +227,14 @@ void XGUI_Workshop::initMenu() QIcon(":pictures/undo.png"), QKeySequence::Undo, false, "MEN_DESK_EDIT"); connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo())); + addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList&)), SLOT(onUndo(int))); + aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"), QIcon(":pictures/redo.png"), QKeySequence::Redo, false, "MEN_DESK_EDIT"); connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo())); + addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList&)), SLOT(onRedo(int))); + salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT"); aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"), QIcon(":pictures/rebuild.png"), QKeySequence(), @@ -256,13 +265,23 @@ void XGUI_Workshop::initMenu() aCommand->connectTo(this, SLOT(onSave())); //aCommand->disable(); - aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"), + QString aUndoId = "UNDO_CMD"; + aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"), QIcon(":pictures/undo.png"), QKeySequence::Undo); aCommand->connectTo(this, SLOT(onUndo())); + AppElements_Button* aUndoButton = qobject_cast(aGroup->widget(aUndoId)); + addHistoryMenu(aUndoButton, + SIGNAL(updateUndoHistory(const QList&)), + SLOT(onUndo(int))); - aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"), + QString aRedoId = "REDO_CMD"; + aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"), QIcon(":pictures/redo.png"), QKeySequence::Redo); aCommand->connectTo(this, SLOT(onRedo())); + AppElements_Button* aRedoButton = qobject_cast(aGroup->widget(aRedoId)); + addHistoryMenu(aRedoButton, + SIGNAL(updateRedoHistory(const QList&)), + SLOT(onRedo(int))); aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"), QIcon(":pictures/rebuild.png"), QKeySequence()); @@ -444,6 +463,11 @@ void XGUI_Workshop::processEvent(const std::shared_ptr& theMessa } } +//****************************************************** +QMainWindow* XGUI_Workshop::desktop() const +{ + return isSalomeMode() ? salomeConnector()->desktop() : myMainWindow; +} //****************************************************** void XGUI_Workshop::onStartWaiting() @@ -480,6 +504,7 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr::const_iterator aIt; for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) { ObjectPtr aObj = (*aIt); + bool aHide = !aObj->data() || !aObj->data()->isValid(); if (!aHide) { // check that this is not hidden result ResultPtr aRes = std::dynamic_pointer_cast(aObj); @@ -499,8 +524,7 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptrhasOperation()) { ModuleBase_Operation* aOperation = myOperationMgr->currentOperation(); - // Display only current operation results if operation has preview - if (aOperation->hasObject(aObj)/* && aOperation->hasPreview()*/) { + if (myModule->canDisplayObject(aObj)) { displayObject(aObj); // Deactivate object of current operation from selection if (myDisplayer->isActive(aObj)) @@ -522,17 +546,15 @@ void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr(*aIt); if (aPart) { aHasPart = true; // If a feature is created from the aplication's python console // it doesn't stored in the operation mgr and doesn't displayed - } else if (myOperationMgr->hasOperation()) { - ModuleBase_Operation* aOperation = myOperationMgr->currentOperation(); - if (aOperation->hasObject(*aIt)) { // Display only current operation results - displayObject(*aIt); - isDisplayed = true; - } + } else if (myModule->canDisplayObject(*aIt)) { + displayObject(*aIt); + isDisplayed = true; } } if (myObjectBrowser) @@ -572,7 +594,7 @@ void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation) setNestedFeatures(theOperation); if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel - connectWithOperation(theOperation); + // connectWithOperation(theOperation); already connected setPropertyPanel(theOperation); } updateCommandStatus(); @@ -630,13 +652,10 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation) QList aWidgets = aFactory.getModelWidgets(); foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { - aWidget->setFeature(theOperation->feature()); + bool isStoreValue = !theOperation->isEditOperation() && + aWidget->isValueDefault() && !aWidget->isComputedDefault(); + aWidget->setFeature(theOperation->feature(), isStoreValue); aWidget->enableFocusProcessing(); - QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged())); - // Init default values - if (!theOperation->isEditOperation() && aWidget->isValueDefault() && !aWidget->isComputedDefault()) { - aWidget->storeValue(); - } } myPropertyPanel->setModelWidgets(aWidgets); @@ -669,28 +688,24 @@ void XGUI_Workshop::addFeature(const std::shared_ptr& the #endif return; } + ActionInfo aFeatureInfo; + aFeatureInfo.initFrom(theMessage); // Remember features icons - myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon()); + myIcons[QString::fromStdString(theMessage->id())] = aFeatureInfo.iconFile; - //Find or create Workbench QString aWchName = QString::fromStdString(theMessage->workbenchId()); - QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures()); - bool isUsePropPanel = theMessage->isUseInput(); - QString aFeatureId = QString::fromStdString(theMessage->id()); + QStringList aNestedFeatures = + QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts); + QString aDocKind = QString::fromStdString(theMessage->documentKind()); if (isSalomeMode()) { - QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureId, - QString::fromStdString(theMessage->text()), - QString::fromStdString(theMessage->tooltip()), - QIcon(theMessage->icon().c_str()), - QKeySequence(), - isUsePropPanel); - salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts)); - salomeConnector()->setDocumentKind(aFeatureId, QString::fromStdString(theMessage->documentKind())); + QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureInfo); + salomeConnector()->setNestedActions(aFeatureInfo.id, aNestedFeatures); + salomeConnector()->setDocumentKind(aFeatureInfo.id, aDocKind); myActionsMgr->addCommand(aAction); myModule->actionCreated(aAction); } else { - + //Find or create Workbench AppElements_MainMenu* aMenuBar = myMainWindow->menuObject(); AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName); if (!aPage) { @@ -702,19 +717,32 @@ void XGUI_Workshop::addFeature(const std::shared_ptr& the if (!aGroup) { aGroup = aPage->addGroup(aGroupName); } - QString aDocKind = QString::fromStdString(theMessage->documentKind()); // Check if hotkey sequence is already defined: - QKeySequence aHotKey = myActionsMgr->registerShortcut( - QString::fromStdString(theMessage->keysequence())); + QKeySequence aHotKey = myActionsMgr->registerShortcut(aFeatureInfo.shortcut); + if(aHotKey != aFeatureInfo.shortcut) { + aFeatureInfo.shortcut = aHotKey; + } // Create feature... - AppElements_Command* aCommand = aGroup->addFeature(aFeatureId, - QString::fromStdString(theMessage->text()), - QString::fromStdString(theMessage->tooltip()), - QIcon(theMessage->icon().c_str()), - aDocKind, - aHotKey, - isUsePropPanel); - aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts)); + AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo, + aDocKind, + aNestedFeatures); + // Enrich created button with accept/abort buttons if necessary + AppElements_Button* aButton = aCommand->button(); + if (aButton->isColumnButton()) { + QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested()); + QList anActList; + if (aNestedActions.contains("accept")) { + QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, aButton); + connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(commitAllOperations())); + anActList << anAction; + } + if (aNestedActions.contains("abort")) { + QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, aButton); + connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(abortAllOperations())); + anActList << anAction; + } + aButton->setAdditionalButtons(anActList); + } myActionsMgr->addCommand(aCommand); myModule->actionCreated(aCommand); } @@ -891,24 +919,28 @@ bool XGUI_Workshop::onSaveAs() } //****************************************************** -void XGUI_Workshop::onUndo() +void XGUI_Workshop::onUndo(int theTimes) { objectBrowser()->treeView()->setCurrentIndex(QModelIndex()); SessionPtr aMgr = ModelAPI_Session::get(); if (aMgr->isOperation()) operationMgr()->onAbortOperation(); - aMgr->undo(); + for (int i = 0; i < theTimes; ++i) { + aMgr->undo(); + } updateCommandStatus(); } //****************************************************** -void XGUI_Workshop::onRedo() +void XGUI_Workshop::onRedo(int theTimes) { objectBrowser()->treeView()->setCurrentIndex(QModelIndex()); SessionPtr aMgr = ModelAPI_Session::get(); if (aMgr->isOperation()) operationMgr()->onAbortOperation(); - aMgr->redo(); + for (int i = 0; i < theTimes; ++i) { + aMgr->redo(); + } updateCommandStatus(); } @@ -918,7 +950,7 @@ void XGUI_Workshop::onRebuild() SessionPtr aMgr = ModelAPI_Session::get(); bool aWasOperation = aMgr->isOperation(); // keep this value if (!aWasOperation) { - aMgr->startOperation(); + aMgr->startOperation("Rebuild"); } static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild"); Events_Loop::loop()->send(std::shared_ptr( @@ -1045,8 +1077,10 @@ void XGUI_Workshop::updateCommandStatus() // Enable all commands aCmd->setEnabled(true); } - aUndoCmd->setEnabled(aMgr->canUndo() && !aMgr->isOperation()); - aRedoCmd->setEnabled(aMgr->canRedo() && !aMgr->isOperation()); + + aUndoCmd->setEnabled(myModule->canUndo()); + aRedoCmd->setEnabled(myModule->canRedo()); + updateHistory(); } else { foreach(QAction* aCmd, aCommands) { QString aId = aCmd->data().toString(); @@ -1062,6 +1096,17 @@ void XGUI_Workshop::updateCommandStatus() emit commandStatusUpdated(); } +void XGUI_Workshop::updateHistory() +{ + std::list aUndoList = ModelAPI_Session::get()->undoList(); + QList aUndoRes = processHistoryList(aUndoList); + emit updateUndoHistory(aUndoRes); + + std::list aRedoList = ModelAPI_Session::get()->redoList(); + QList aRedoRes = processHistoryList(aRedoList); + emit updateRedoHistory(aRedoRes); +} + //****************************************************** QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent) { @@ -1090,24 +1135,26 @@ void XGUI_Workshop::createDockWidgets() QDockWidget* aObjDock = createObjectBrowser(aDesktop); aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock); myPropertyPanel = new XGUI_PropertyPanel(aDesktop); + myPropertyPanel->setupActions(myActionsMgr); myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea); - - connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets())); - aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel); - hidePropertyPanel(); //tabifyDockWidget(aObjDock, myPropertyPanel); myPropertyPanel->installEventFilter(myOperationMgr); - QPushButton* aOkBtn = myPropertyPanel->findChild(PROP_PANEL_OK); - connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation())); - QPushButton* aCancelBtn = myPropertyPanel->findChild(PROP_PANEL_CANCEL); - connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation())); - connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr, - SLOT(onKeyReleased(QKeyEvent*))); - connect(myOperationMgr, SIGNAL(applyEnableChanged(bool)), myPropertyPanel, - SLOT(setAcceptEnabled(bool))); + QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept); + connect(aOkAct, SIGNAL(triggered()), myOperationMgr, SLOT(onCommitOperation())); + QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort); + connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation())); + connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets())); + connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), + myOperationMgr, SLOT(onKeyReleased(QKeyEvent*))); + connect(myOperationMgr, SIGNAL(validationStateChanged(bool)), + aOkAct, SLOT(setEnabled(bool))); + QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll); + connect(myOperationMgr, SIGNAL(nestedStateChanged(bool)), + aAcceptAllAct, SLOT(setEnabled(bool))); } @@ -1115,7 +1162,7 @@ void XGUI_Workshop::createDockWidgets() void XGUI_Workshop::showPropertyPanel() { QAction* aViewAct = myPropertyPanel->toggleViewAction(); - //setEnabled(true); myPropertyPanel->show(); myPropertyPanel->raise(); @@ -1125,7 +1172,7 @@ void XGUI_Workshop::showPropertyPanel() void XGUI_Workshop::hidePropertyPanel() { QAction* aViewAct = myPropertyPanel->toggleViewAction(); - //setEnabled(false); myPropertyPanel->hide(); } @@ -1212,24 +1259,6 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) } } -//************************************************************** -void XGUI_Workshop::onWidgetValuesChanged() -{ - ModuleBase_Operation* anOperation = myOperationMgr->currentOperation(); - FeaturePtr aFeature = anOperation->feature(); - - ModuleBase_ModelWidget* aSenderWidget = dynamic_cast(sender()); - - const QList& aWidgets = myPropertyPanel->modelWidgets(); - QList::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end(); - for (; anIt != aLast; anIt++) { - ModuleBase_ModelWidget* aCustom = *anIt; - if (aCustom && (aCustom == aSenderWidget)) { - aCustom->storeValue(); - } - } -} - //************************************************************** void XGUI_Workshop::activatePart(ResultPartPtr theFeature) { @@ -1261,31 +1290,81 @@ void XGUI_Workshop::activatePart(ResultPartPtr theFeature) void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList) { QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow; - QMessageBox::StandardButton aRes = QMessageBox::warning( - aDesktop, tr("Delete features"), tr("Seleted features will be deleted. Continue?"), - QMessageBox::No | QMessageBox::Yes, QMessageBox::No); - // ToDo: definbe deleting method - if (aRes == QMessageBox::Yes) { - SessionPtr aMgr = ModelAPI_Session::get(); - aMgr->startOperation(); - foreach (ObjectPtr aObj, theList) - { - ResultPartPtr aPart = std::dynamic_pointer_cast(aObj); - if (aPart) { - DocumentPtr aDoc = aPart->document(); - if (aDoc == aMgr->activeDocument()) { - aDoc->close(); - } - //aMgr->moduleDocument()->removeFeature(aPart->owner()); - } else { - FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); - if (aFeature) - aObj->document()->removeFeature(aFeature); + + std::set aRefFeatures; + foreach (ObjectPtr aObj, theList) + { + ResultPartPtr aPart = std::dynamic_pointer_cast(aObj); + if (aPart) { + // TODO: check for what there is this condition. It is placed here historicaly because + // ther is this condition during remove features. + } else { + FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); + if (aFeature.get() != NULL) { + aObj->document()->refsToFeature(aFeature, aRefFeatures, false); + } + } + } + + if (!aRefFeatures.empty()) { + QStringList aRefNames; + std::set::const_iterator anIt = aRefFeatures.begin(), + aLast = aRefFeatures.end(); + for (; anIt != aLast; anIt++) { + FeaturePtr aFeature = (*anIt); + std::string aFName = aFeature->data()->name().c_str(); + std::string aName = (*anIt)->name().c_str(); + aRefNames.append((*anIt)->name().c_str()); + } + QString aNames = aRefNames.join(", "); + + QMessageBox::StandardButton aRes = QMessageBox::warning( + aDesktop, tr("Delete features"), + QString(tr("Selected features are used in the following features: %1.\ +These features will be deleted also. Would you like to continue?")).arg(aNames), + QMessageBox::No | QMessageBox::Yes, QMessageBox::No); + if (aRes != QMessageBox::Yes) + return; + } + + SessionPtr aMgr = ModelAPI_Session::get(); + QString aDescription = tr("Delete %1"); + QStringList aObjectNames; + foreach (ObjectPtr aObj, theList) { + if (!aObj->data().get()) + continue; + aObjectNames << QString::fromStdString(aObj->data()->name()); + } + aDescription = aDescription.arg(aObjectNames.join(", ")); + aMgr->startOperation(aDescription.toStdString()); + std::set::const_iterator anIt = aRefFeatures.begin(), + aLast = aRefFeatures.end(); + for (; anIt != aLast; anIt++) { + FeaturePtr aRefFeature = (*anIt); + DocumentPtr aDoc = aRefFeature->document(); + aDoc->removeFeature(aRefFeature); + } + + + foreach (ObjectPtr aObj, theList) + { + DocumentPtr aDoc = aObj->document(); + ResultPartPtr aPart = std::dynamic_pointer_cast(aObj); + if (aPart) { + if (aDoc == aMgr->activeDocument()) { + aDoc->close(); + } + } else { + FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); + if (aFeature) { + aDoc->removeFeature(aFeature); } } - myDisplayer->updateViewer(); - aMgr->finishOperation(); } + + myDisplayer->updateViewer(); + aMgr->finishOperation(); + updateCommandStatus(); } //************************************************************** @@ -1385,3 +1464,38 @@ void XGUI_Workshop::displayObject(ObjectPtr theObj) } else myDisplayer->display(theObj, false); } + +void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot) +{ + XGUI_HistoryMenu* aMenu = NULL; + if (isSalomeMode()) { + QAction* anAction = qobject_cast(theObject); + if (!anAction) + return; + aMenu = new XGUI_HistoryMenu(anAction); + } else { + QToolButton* aButton = qobject_cast(theObject); + aMenu = new XGUI_HistoryMenu(aButton); + } + connect(this, theSignal, aMenu, SLOT(setHistory(const QList&))); + connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot); +} + +QList XGUI_Workshop::processHistoryList(const std::list& theList) const +{ + QList aResult; + std::list::const_iterator it = theList.cbegin(); + for (; it != theList.cend(); it++) { + QString anId = QString::fromStdString(*it); + bool isEditing = anId.endsWith(ModuleBase_Operation::EditSuffix()); + if (isEditing) { + anId.chop(ModuleBase_Operation::EditSuffix().size()); + } + ActionInfo anInfo = myActionsMgr->actionInfoById(anId); + if (isEditing) { + anInfo.text = anInfo.text.prepend("Modify "); + } + aResult << anInfo; + } + return aResult; +}