X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSHAPERGUI%2FSHAPERGUI.cpp;h=56f665801398467ea0463e9f877dc0028c832ec3;hb=97917d3698f5a2f7fc9596e7c755ff8f6751e373;hp=50ca7585f762de2a0cc5de11f48b8208235b01d1;hpb=e1f69437a6b63da2aa4710c0f921cd4c7636632b;p=modules%2Fshaper.git diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp index 50ca7585f..56f665801 100644 --- a/src/SHAPERGUI/SHAPERGUI.cpp +++ b/src/SHAPERGUI/SHAPERGUI.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,16 +12,16 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "SHAPERGUI.h" #include "SHAPERGUI_DataModel.h" #include "SHAPERGUI_OCCSelector.h" -#include +#include "SHAPERGUI_NestedButton.h" +#include "SHAPERGUI_ToolbarsMgr.h" #include #include @@ -66,6 +66,7 @@ #include #include #include +#include #define SALOME_PATCH_FOR_CTRL_WHEEL @@ -81,6 +82,11 @@ SHAPERGUI_EXPORT char* getModuleVersion() } } // extern "C" + +static const QString ToolbarsSection("SHAPER_Toolbars"); +static const QString FreeCommandsParam("OutOFToolbars"); + + /** * Class for preferences management */ @@ -121,7 +127,8 @@ private: //****************************************************** SHAPERGUI::SHAPERGUI() : LightApp_Module("SHAPER"), - mySelector(0), myIsOpened(0), myPopupMgr(0) + mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false), + myInspectionPanel(0), myIsToolbarsModified(false) { myWorkshop = new XGUI_Workshop(this); connect(myWorkshop, SIGNAL(commandStatusUpdated()), @@ -136,6 +143,8 @@ SHAPERGUI::SHAPERGUI() //****************************************************** SHAPERGUI::~SHAPERGUI() { + delete myWorkshop; + delete myProxyViewer; } //****************************************************** @@ -153,8 +162,8 @@ void SHAPERGUI::initialize(CAM_Application* theApp) int aMenu = createMenu(tr("Inspection"), -1, -1, 30); int aSubMenu = createMenu(tr("Information"), aMenu); - int aId = myActionsList.size(); - myActionsList.append("INSPECTION_CMD"); + int aId = getNextCommandId(); + myActionsList.append(aId); SUIT_Desktop* aDesk = application()->desktop(); QString aTip = tr("Show inspection window"); myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"), @@ -163,8 +172,19 @@ void SHAPERGUI::initialize(CAM_Application* theApp) myWhatIsAction->setData("INSPECTION_CMD"); createMenu(aId, aSubMenu, 0); - int aTool = createTool(tr("Inspection tool")); + QString aToolName = tr("Inspection tool"); + int aTool = createTool(aToolName); int aToolId = createTool(myWhatIsAction, aTool); + registerCommandToolbar(aToolName, aId); + + // Define Edit toolbars command + aId = getNextCommandId(); + //myActionsList.append(aId); Do not use it for editing of toolbars + aTip = tr("Edit toolbars of the module"); + QAction* aAction = createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"), + tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars())); + int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30); + int aEditItem = createMenu(aId, aEditMenu); } //****************************************************** @@ -207,6 +227,8 @@ void SHAPERGUI::viewManagers(QStringList& theList) const bool SHAPERGUI::activateModule(SUIT_Study* theStudy) { bool isDone = LightApp_Module::activateModule(theStudy); + loadToolbarsConfig(); + SHAPERGUI_DataModel* aDataModel = dynamic_cast(dataModel()); aDataModel->initRootObject(); @@ -224,12 +246,12 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy) desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel()); } - QDockWidget* aInspection = myWorkshop->inspectionPanel(); - if (aInspection) { - QAction* aViewAct = aInspection->toggleViewAction(); - aViewAct->setEnabled(true); + if (!myInspectionPanel) { + myInspectionPanel = myWorkshop->inspectionPanel(); + QAction* aViewAct = myInspectionPanel->toggleViewAction(); connect(aViewAct, SIGNAL(toggled(bool)), this, SLOT(onWhatIs(bool))); } + myInspectionPanel->toggleViewAction()->setEnabled(true); if (!mySelector) { ViewManagerList OCCViewManagers; @@ -316,6 +338,8 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy) //****************************************************** bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) { + saveToolbarsConfig(); + myProxyViewer->activateViewer(false); setMenuShown(false); setToolShown(false); @@ -330,12 +354,11 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) QAction* aViewAct = aObjDoc->toggleViewAction(); aViewAct->setEnabled(false); } - QDockWidget* aInspection = myWorkshop->inspectionPanel(); - if (aInspection) { - aInspection->setVisible(false); - QAction* aViewAct = aInspection->toggleViewAction(); - aViewAct->setEnabled(false); - } + + myIsInspectionVisible = myInspectionPanel->isVisible(); + myInspectionPanel->hide(); + QAction* aViewAct = myInspectionPanel->toggleViewAction(); + aViewAct->setEnabled(false); // the active operation should be stopped for the next activation. // There should not be active operation and visualized preview. @@ -375,7 +398,6 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)), getApp(), SLOT(onSaveAsDoc())); - return LightApp_Module::deactivateModule(theStudy); } @@ -533,8 +555,8 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBNam } aNb++; - int aId = myActionsList.size(); - myActionsList.append(theId); + int aId = getNextCommandId(); + myActionsList.append(aId); SUIT_Desktop* aDesk = application()->desktop(); int aKeys = 0; for (int i = 0; i < theKeys.count(); i++) @@ -552,9 +574,11 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBNam int aWBTool = createTool(theTBName, theTBName); int aToolId = createTool(aId, aWBTool); - if (isAddSeparator) + registerCommandToolbar(theTBName, aId); + if (isAddSeparator) { createTool(separator(), aWBTool); - + registerCommandToolbar(theTBName, -1); + } return aAction; } @@ -567,7 +591,6 @@ QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName, const ActionInfo& theInfo, const QList& theNestedActions) { - myActionsList.append(theInfo.id); SUIT_Desktop* aDesk = application()->desktop(); SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions); anAction->setData(theInfo.id); @@ -583,11 +606,14 @@ QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName, int aWBMenu = createMenu(theWBName, -1, -1, 30); int aItemId = createMenu(anAction, aWBMenu); + myActionsList.append(aItemId); createMenu(separator(), aWBMenu); /// nested action is always separated of others int aWBTool = createTool(theWBName, theWBName); int aToolId = createTool(anAction, aWBTool); + registerCommandToolbar(theWBName, aItemId); createTool(separator(), aWBTool); /// nested action is always separated of others + registerCommandToolbar(theWBName, -1); return anAction; } @@ -601,8 +627,8 @@ QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTi { int aMenu = createMenu(tr(theMenuSourceText), -1, -1); - int aId = myActionsList.size(); - myActionsList.append(theId); + int aId = getNextCommandId(); + myActionsList.append(aId); SUIT_Desktop* aDesk = application()->desktop(); int aKeys = 0; for (int i = 0; i < theKeys.count(); i++) @@ -622,6 +648,7 @@ void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int createMenu(separator(), aMenu, -1, theMenuPosition); } +//****************************************************** bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ) { if( !theAction ) @@ -643,9 +670,9 @@ bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBa QList SHAPERGUI::commandList() const { QList aActions; - for (int i = 0; i < myActionsList.size(); i++) { - QAction* aCmd = action(i); - if (aCmd && myActionsList.contains(aCmd->data().toString())) + foreach (int aId, myActionsList) { + QAction* aCmd = action(aId); + if (aCmd) aActions.append(aCmd); } @@ -770,17 +797,268 @@ void SHAPERGUI::createFeatureActions() void SHAPERGUI::onWhatIs(bool isToggled) { - QDockWidget* aInspection = myWorkshop->inspectionPanel(); if (sender() == myWhatIsAction) { - QAction* aViewAct = aInspection->toggleViewAction(); + QAction* aViewAct = myInspectionPanel->toggleViewAction(); aViewAct->blockSignals(true); aViewAct->setChecked(isToggled); aViewAct->blockSignals(false); - aInspection->setVisible(isToggled); + myInspectionPanel->setVisible(isToggled); } else { myWhatIsAction->blockSignals(true); myWhatIsAction->setChecked(isToggled); myWhatIsAction->blockSignals(false); + myInspectionPanel->setVisible(isToggled); + } +} + +void SHAPERGUI::updateModuleVisibilityState() +{ + LightApp_Module::updateModuleVisibilityState(); + onWhatIs(myIsInspectionVisible); +} + +void SHAPERGUI::onEditToolbars() +{ + SHAPERGUI_ToolbarsDlg aDlg(this); + if (aDlg.exec() == QDialog::Accepted) { + if (aDlg.isReset()) + resetToolbars(); + else + updateToolbars(aDlg.result()); + } +} + +void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId) +{ + if (!myToolbars.contains(theToolName)) + myToolbars[theToolName] = QList(); + myToolbars[theToolName].append(theCommandId); +} + +int SHAPERGUI::getNextCommandId() const +{ + QtxActionMenuMgr* aMenuMgr = menuMgr(); + QIntList aIds = aMenuMgr->idList(); + int aId = aIds.count(); + while (action(aId) || myActionsList.contains(aId)) + aId++; + return aId; +} + +void SHAPERGUI::updateToolbars(const QMap& theNewToolbars) +{ + // Store default toolbars + if (myDefaultToolbars.size() == 0) + myDefaultToolbars = myToolbars; + + QtxActionToolMgr* aMgr = toolMgr(); + QStringList aToolbars = theNewToolbars.keys(); + QIntList aCommands, aOldCmd; + int aToolbarId; + QAction* aAction; + int aActionId; + foreach(QString aName, aToolbars) { + aCommands = theNewToolbars[aName]; + // Find or create toolbar + if (aMgr->hasToolBar(aName)) { + aToolbarId = aMgr->find(aMgr->toolBar(aName)); + aOldCmd = myToolbars[aName]; + } + else { + aToolbarId = aMgr->createToolBar(aName); + } + int aPos = 0; + foreach(int aCmd, aCommands) { + // Find action + if (aCmd == -1) + aAction = separator(); + else + aAction = action(aCmd); + aActionId = aMgr->actionId(aAction); + if (aActionId == -1) { + // Add new action + aMgr->insert(aAction, aToolbarId, aPos); + } + else { + // Change position of action + if (aMgr->index(aActionId, aToolbarId) != aPos) { + if (aMgr->containsAction(aActionId, aToolbarId)) + aMgr->remove(aActionId, aToolbarId); + aMgr->insert(aActionId, aToolbarId, aPos); + } + } + aOldCmd.removeAll(aCmd); + aPos++; + } + // remove extra actions + foreach(int aCmd, aOldCmd) { + aAction = action(aCmd); + aActionId = aMgr->actionId(aAction); + aMgr->remove(aActionId, aToolbarId); + } + myToolbars.remove(aName); + } + // Remove extra toolbars + aToolbars = myToolbars.keys(); + foreach(QString aName, aToolbars) { + aMgr->removeToolBar(aName); + } + // Set new toolbars structure + myToolbars = theNewToolbars; + myIsToolbarsModified = true; +} + +void SHAPERGUI::saveToolbarsConfig() +{ + if (!myIsToolbarsModified) + return; + // Save toolbars config into map + QMap aToolbarsConfig; + QtxActionToolMgr* aMgr = toolMgr(); + QStringList aToolbars = myToolbars.keys(); + QIntList aActionsIds; + foreach(QString aName, aToolbars) { + aActionsIds = myToolbars[aName]; + QStringList aContent; + foreach(int aId, aActionsIds) { + if (aId == -1) + aContent.append(""); + else + aContent.append(action(aId)->data().toString()); + } + aToolbarsConfig[aName] = aContent; + } + // Store the config into resources + SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); + QStringList aNames = aToolbarsConfig.keys(); + QStringList aValues; + foreach(QString aToolbar, aNames) { + aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(",")); + } + // Remove obsolete parameters from resources + QStringList aOldParams = aResMgr->parameters(ToolbarsSection); + foreach(QString aName, aOldParams) { + if (!aToolbars.contains(aName)) + aResMgr->remove(ToolbarsSection, aName); + } + // Store current list of free commands + QIntList aFreeCommands = getFreeCommands(); + QStringList aFreeList; + foreach(int aId, aFreeCommands) { + aFreeList.append(action(aId)->data().toString()); + } + if (aFreeList.size() > 0) + aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(",")); + + myIsToolbarsModified = false; +} + +void SHAPERGUI::loadToolbarsConfig() +{ + SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); + QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection); + if (aToolbarNames.size() == 0) + return; + + // Create commands map + QMap aCommandsMap; + QString aCmdIdStr; + foreach(int aId, myActionsList) { + aCmdIdStr = action(aId)->data().toString(); + aCommandsMap[aCmdIdStr] = aId; } -} \ No newline at end of file + + // Create new toolbars structure + QMap aToolbars; + QStringList aCommands; + QIntList aKnownCommands; + QList aActions; + foreach(QString aName, aToolbarNames) { + aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(","); + if (aName == FreeCommandsParam) { + // The value is a list of free commands + foreach(QString aCommand, aCommands) { + aKnownCommands.append(aCommandsMap[aCommand]); + } + } + else { + aToolbars[aName] = QIntList(); + if (aCommands.size() > 0) { + foreach(QString aCommand, aCommands) { + if (aCommand.isEmpty()) + aToolbars[aName].append(-1); + else if (aCommandsMap.contains(aCommand)) { + int aId = aCommandsMap[aCommand]; + aToolbars[aName].append(aId); + aKnownCommands.append(aId); + } + } + } + } + } + // Find new and obsolete commands + QIntList aNewCommands = myActionsList; + foreach(int aId, myActionsList) { + if (aKnownCommands.contains(aId)) { + aKnownCommands.removeAll(aId); + aNewCommands.removeAll(aId); + } + } + if (aNewCommands.size() > 0) { + // Add new commands to toolbars structure + QStringList aKeys = myToolbars.keys(); + foreach(int aNewId, aNewCommands) { + foreach(QString aName, aKeys) { + if (myToolbars[aName].contains(aNewId)) { + if (!aToolbars.contains(aName)) { + aToolbars[aName] = QIntList(); + } + aToolbars[aName].append(aNewId); + } + } + } + } + if (aKnownCommands.size() > 0) { + // Remove obsolete commands from the toolbars structure + QStringList aKeys = aToolbars.keys(); + foreach(int aOldId, aKnownCommands) { + foreach(QString aName, aKeys) { + if (aToolbars[aName].contains(aOldId)) { + aToolbars[aName].removeAll(aOldId); + if (aToolbars[aName].size() == 0) + aToolbars.remove(aName); + } + } + } + } + updateToolbars(aToolbars); + myIsToolbarsModified = false; +} + + +QIntList SHAPERGUI::getFreeCommands() const +{ + QIntList aFreeCommands; + QtxActionToolMgr* aMgr = toolMgr(); + QAction* anAction; + int aId; + QMap::const_iterator aIt; + QIntList aShaperActions = shaperActions(); + foreach(int aCmd, aShaperActions) { + anAction = action(aCmd); + aId = aMgr->actionId(anAction); + if (!aMgr->containsAction(aId)) + aFreeCommands.append(aCmd); + } + return aFreeCommands; +} + +void SHAPERGUI::resetToolbars() +{ + if (!myDefaultToolbars.isEmpty()) + updateToolbars(myDefaultToolbars); + myIsToolbarsModified = false; + SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); + aResMgr->remove(ToolbarsSection); +}