X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSHAPERGUI%2FSHAPERGUI.cpp;h=5b69d3593ffb8e02830a296173cbdf0abf0185bb;hb=97c06c5cd9fc736f9b5a1dacde369a9d7b5be703;hp=7361accf94421d29e9b30b002e81130a35d37007;hpb=a9bdd72e4748283ea455fef89e11eb0eae3b7b48;p=modules%2Fshaper.git diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp index 7361accf9..5b69d3593 100644 --- a/src/SHAPERGUI/SHAPERGUI.cpp +++ b/src/SHAPERGUI/SHAPERGUI.cpp @@ -1,10 +1,27 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - - -#include "NewGeom_Module.h" -#include "NewGeom_DataModel.h" -#include "NewGeom_OCCSelector.h" -#include +// 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "SHAPERGUI.h" +#include "SHAPERGUI_DataModel.h" +#include "SHAPERGUI_OCCSelector.h" +#include "SHAPERGUI_NestedButton.h" +#include "SHAPERGUI_ToolbarsMgr.h" #include #include @@ -12,22 +29,33 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include #include +#include + #include #include #include #include + #include +#include #include #include #include +#include #include +#include #include #include @@ -44,32 +72,40 @@ #include #include #include +#include +#define SALOME_PATCH_FOR_CTRL_WHEEL extern "C" { -NewGeom_EXPORT CAM_Module* createModule() +SHAPERGUI_EXPORT CAM_Module* createModule() { - return new NewGeom_Module(); + return new SHAPERGUI(); } -NewGeom_EXPORT char* getModuleVersion() +SHAPERGUI_EXPORT char* getModuleVersion() { return (char*)"0.0"; } } // extern "C" + +static const QString ToolbarsSection("SHAPER_Toolbars"); +static const QString FreeCommandsParam("OutOFToolbars"); + + /** * Class for preferences management */ -class NewGeom_PrefMgr: public ModuleBase_IPrefMgr +class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr { public: /// Constructor /// \param theMgr preferences manager of SALOME /// \param theModName name of the module - NewGeom_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):myMgr(theMgr), myModName(theModName) {} + SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName): + myMgr(theMgr), myModName(theModName) {} - virtual int addPreference(const QString& theLbl, int pId, + virtual int addPreference(const QString& theLbl, int pId, SUIT_PreferenceMgr::PrefItemType theType, const QString& theSection, const QString& theName ) { @@ -95,30 +131,34 @@ private: //****************************************************** -NewGeom_Module::NewGeom_Module() - : LightApp_Module("NewGeom"), - mySelector(0), myIsOpened(0), myPopupMgr(0) +SHAPERGUI::SHAPERGUI() + : LightApp_Module("SHAPER"), + mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false), + myInspectionPanel(0), myIsToolbarsModified(false) { myWorkshop = new XGUI_Workshop(this); connect(myWorkshop, SIGNAL(commandStatusUpdated()), this, SLOT(onUpdateCommandStatus())); - myProxyViewer = new NewGeom_SalomeViewer(this); + myProxyViewer = new SHAPERGUI_SalomeViewer(this); ModuleBase_Preferences::setResourceMgr(application()->resourceMgr()); - ModuleBase_Preferences::loadCustomProps(); + + // It will be called in XGUI_Workshop::startApplication + // ModuleBase_Preferences::loadCustomProps(); } //****************************************************** -NewGeom_Module::~NewGeom_Module() +SHAPERGUI::~SHAPERGUI() { + delete myWorkshop; + delete myProxyViewer; } //****************************************************** -void NewGeom_Module::initialize(CAM_Application* theApp) +void SHAPERGUI::initialize(CAM_Application* theApp) { LightApp_Module::initialize(theApp); - inspectSalomeModules(); myWorkshop->startApplication(); LightApp_Application* anApp = dynamic_cast(theApp); @@ -126,44 +166,98 @@ void NewGeom_Module::initialize(CAM_Application* theApp) { connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences())); } + + int aMenu = createMenu(tr("Inspection"), -1, -1, 30); + int aSubMenu = createMenu(tr("Information"), aMenu); + + 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"), + aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool))); + myWhatIsAction->setStatusTip(aTip); + myWhatIsAction->setData("INSPECTION_CMD"); + createMenu(aId, aSubMenu, 0); + + 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); + + // Initialize viewer proxy if OCC viewer is already exist + ViewManagerList aOCCViewManagers; + application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers); + if (aOCCViewManagers.size() > 0) { + SUIT_ViewManager* aMgr = aOCCViewManagers.first(); + SUIT_ViewWindow* aWnd = aMgr->getActiveView(); + if (aWnd) { + OCCViewer_ViewWindow* aOccWnd = static_cast(aWnd); + OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort(); + if (aViewPort) { + XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); + aViewPort->installEventFilter(aViewer); + Handle(V3d_View) aView = aViewPort->getView(); + aViewer->SetScale(aView, aView->Camera()->Scale()); + // We can not create selector here because other modules will be deactivated later + //onViewManagerAdded(aMgr); + } + } + } } //****************************************************** -void NewGeom_Module::windows(QMap& theWndMap) const +void SHAPERGUI::windows(QMap& theWndMap) const { theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea); } //****************************************************** -void NewGeom_Module::viewManagers(QStringList& theList) const +void SHAPERGUI::viewManagers(QStringList& theList) const { theList.append(OCCViewer_Viewer::Type()); } //****************************************************** -void NewGeom_Module::connectToStudy(CAM_Study* theStudy) -{ - // if there are created viewer managers, we should try to create viewer - // selector and initialize viewer with it. It sets interactive contect to the - // proxy viewer. If study is opened, CAM application calls this method before the open() of data model - // the NewGeom data model is specific and during open(load) redisplay signals are flushed, so - // we need to connect to the viewer before it. Here, it seems the most appropriate place for this - // according to SALOME architecture. - if (!mySelector) { - ViewManagerList OCCViewManagers; - application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers); - if (OCCViewManagers.size() > 0) { - mySelector = createSelector(OCCViewManagers.first()); - } - } - LightApp_Module::connectToStudy(theStudy); -} +// We can not create selector in this method because it can be called when +// SHAPER module is not active. Take into account that creation of our selector +// leads to switching OFF all other selectors +//void SHAPERGUI::connectToStudy(CAM_Study* theStudy) +//{ +// // if there are created viewer managers, we should try to create viewer +// // selector and initialize viewer with it. It sets interactive context to the +// // proxy viewer. If study is opened, CAM application calls this method before the open() +// // of data model +// // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so +// // we need to connect to the viewer before it. Here, +// // it seems the most appropriate place for this +// // according to SALOME architecture. +// if (!mySelector) { +// ViewManagerList OCCViewManagers; +// application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers); +// if (OCCViewManagers.size() > 0) { +// mySelector = createSelector(OCCViewManagers.first()); +// } +// } +// LightApp_Module::connectToStudy(theStudy); +//} //****************************************************** -bool NewGeom_Module::activateModule(SUIT_Study* theStudy) +bool SHAPERGUI::activateModule(SUIT_Study* theStudy) { bool isDone = LightApp_Module::activateModule(theStudy); - NewGeom_DataModel* aDataModel = dynamic_cast(dataModel()); + loadToolbarsConfig(); + + SHAPERGUI_DataModel* aDataModel = dynamic_cast(dataModel()); aDataModel->initRootObject(); if (isDone) { @@ -180,14 +274,21 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy) desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel()); } + 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; application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers); if (OCCViewManagers.size() > 0) { - mySelector = createSelector(OCCViewManagers.first()); + onViewManagerAdded(OCCViewManagers.first()); } } - // it should be pefromed after the selector creation in order to have AISContext + // it should be performed after the selector creation in order to have AISContext myWorkshop->activateModule(); //action(myEraseAll)->setEnabled(false); @@ -231,7 +332,7 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy) bool aFound = false; for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) { anAISIO = aLIt.Value(); - if (anAISIO.Access() == aAIS.Access()) { + if (anAISIO.get() == aAIS.get()) { aFound = true; break; } @@ -244,12 +345,29 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy) Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); } myProxyViewer->activateViewer(true); + + // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser + connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)), + this, SLOT(onScriptLoaded())); + + disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)), + getApp(), SLOT(onSaveDoc())); + disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)), + getApp(), SLOT(onSaveAsDoc())); + + connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)), + this, SLOT(onSaveDocByShaper())); + connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)), + this, SLOT(onSaveAsDocByShaper())); + return isDone; } //****************************************************** -bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy) +bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) { + saveToolbarsConfig(); + myProxyViewer->activateViewer(false); setMenuShown(false); setToolShown(false); @@ -265,6 +383,11 @@ bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy) 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. // Abort operation should be performed before the selection's remove @@ -282,27 +405,43 @@ bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy) mySelector = 0; } + myWorkshop->hidePanel(myWorkshop->facesPanel()); //myWorkshop->contextMenuMgr()->disconnectViewer(); SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); aResMgr->setValue("Study", "store_positions", myIsStorePositions); getApp()->setEditEnabled(myIsEditEnabled); + // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser + disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)), + this, SLOT(onScriptLoaded())); + + disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)), + this, SLOT(onSaveDocByShaper())); + disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)), + this, SLOT(onSaveAsDocByShaper())); + + connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)), + getApp(), SLOT(onSaveDoc())); + connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)), + getApp(), SLOT(onSaveAsDoc())); + return LightApp_Module::deactivateModule(theStudy); } //****************************************************** -void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr) +void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr) { if (!mySelector) { mySelector = createSelector(theMgr); - myWorkshop->module()->activateSelectionFilters(); + myWorkshop->selectionActivate()->updateSelectionFilters(); + myWorkshop->selectionActivate()->updateSelectionModes(); myWorkshop->synchronizeViewer(); } } //****************************************************** -void NewGeom_Module::onViewManagerRemoved(SUIT_ViewManager* theMgr) +void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr) { if (mySelector) { if (theMgr->getType() == OCCViewer_Viewer::Type()) { @@ -310,8 +449,16 @@ void NewGeom_Module::onViewManagerRemoved(SUIT_ViewManager* theMgr) if (mySelector->viewer() == aViewer) { XGUI_Displayer* aDisp = myWorkshop->displayer(); QObjectPtrList aObjects = aDisp->displayedObjects(); - foreach(ObjectPtr aObj, aObjects) + ResultPtr aRes; + foreach(ObjectPtr aObj, aObjects) { aObj->setDisplayed(false); + aRes = std::dynamic_pointer_cast(aObj); + if (aRes.get()) { + while (aRes = ModelAPI_Tools::bodyOwner(aRes)) { + aRes->setDisplayed(false); + } + } + } Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); myProxyViewer->setSelector(0); delete mySelector; @@ -324,7 +471,7 @@ void NewGeom_Module::onViewManagerRemoved(SUIT_ViewManager* theMgr) } //****************************************************** -QtxPopupMgr* NewGeom_Module::popupMgr() +QtxPopupMgr* SHAPERGUI::popupMgr() { if (!myPopupMgr) myPopupMgr = new QtxPopupMgr( 0, this ); @@ -332,7 +479,7 @@ QtxPopupMgr* NewGeom_Module::popupMgr() } //****************************************************** -void NewGeom_Module::onDefaultPreferences() +void SHAPERGUI::onDefaultPreferences() { // reset main resources ModuleBase_Preferences::resetResourcePreferences(preferences()); @@ -343,17 +490,52 @@ void NewGeom_Module::onDefaultPreferences() } //****************************************************** -void NewGeom_Module::onUpdateCommandStatus() +void SHAPERGUI::onScriptLoaded() +{ + // this slot is called after processing of the LoadScriptId action of SalomeApp Application + // Each dumped script contains updateObjBrowser() that creates a new instance of Object + // Browser. When SHAPER module is active, this browser should not be used. It might be removed + // as hidden by means of updateWindows() of SalomeApp_Application or to remove + // it manually (because this method of application is protected) + SUIT_DataBrowser* aBrowser = getApp()->objectBrowser(); + if (aBrowser) + delete aBrowser; +} + +//****************************************************** +void SHAPERGUI::onSaveDocByShaper() +{ + if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage)) + return; + + getApp()->onSaveDoc(); +} + +//****************************************************** +void SHAPERGUI::onSaveAsDocByShaper() +{ + if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage)) + return; + + getApp()->onSaveAsDoc(); +} + +//****************************************************** +void SHAPERGUI::onUpdateCommandStatus() { getApp()->updateActions(); } //****************************************************** -NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr) +SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr) { if (theMgr->getType() == OCCViewer_Viewer::Type()) { OCCViewer_Viewer* aViewer = static_cast(theMgr->getViewModel()); - NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, getApp()->selectionMgr()); + SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer, + getApp()->selectionMgr()); +#ifdef SALOME_PATCH_FOR_CTRL_WHEEL + aViewer->setUseLocalSelection(true); +#endif LightApp_SelectionMgr* aMgr = getApp()->selectionMgr(); QList aList; aMgr->selectors(aList); @@ -368,27 +550,33 @@ NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr) } //****************************************************** -CAM_DataModel* NewGeom_Module::createDataModel() +CAM_DataModel* SHAPERGUI::createDataModel() { - return new NewGeom_DataModel(this); + return new SHAPERGUI_DataModel(this); } -QAction* NewGeom_Module::addFeature(const QString& theWBName, const ActionInfo& theInfo) +QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo, + const bool isAddSeparator) { return addFeature(theWBName, + theInfo.toolBar, theInfo.id, theInfo.text, - theInfo.toolTip, + //Issue #650: in the SALOME mode the tooltip should be same as text + theInfo.text, theInfo.icon, theInfo.shortcut, - theInfo.checkable); + theInfo.checkable, + isAddSeparator, + theInfo.toolTip); } //****************************************************** -QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& theId, - const QString& theTitle, const QString& theTip, - const QIcon& theIcon, const QKeySequence& theKeys, - bool isCheckable) +QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName, + const QString& theId, const QString& theTitle, const QString& theTip, + const QIcon& theIcon, const QKeySequence& theKeys, + bool isCheckable, const bool isAddSeparator, + const QString& theStatusTip) { static QString aLastTool = ""; static int aNb = 0; @@ -403,40 +591,44 @@ QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& the } aNb++; - int aMenu = createMenu(theWBName, -1, -1, 50); - int aTool = createTool(theWBName, theWBName); - - int aId = myActionsList.size(); - myActionsList.append(theId); + int aId = getNextCommandId(); + myActionsList.append(aId); SUIT_Desktop* aDesk = application()->desktop(); int aKeys = 0; - for (unsigned int i = 0; i < theKeys.count(); i++) + for (int i = 0; i < theKeys.count(); i++) aKeys += theKeys[i]; QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, isCheckable); + aAction->setStatusTip(theStatusTip); + aAction->setData(theId); - int aItemId = createMenu(aId, aMenu, -1, 10); - int aToolId = createTool(aId, aTool); + int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/); + int aItemId = createMenu(aId, aWBMenu); + if (isAddSeparator) + createMenu(separator(), aWBMenu); + + int aWBTool = createTool(theTBName, theTBName); + int aToolId = createTool(aId, aWBTool); + registerCommandToolbar(theTBName, aId); + if (isAddSeparator) { + createTool(separator(), aWBTool); + registerCommandToolbar(theTBName, -1); + } return aAction; } -bool NewGeom_Module::isFeatureOfNested(const QAction* theAction) +bool SHAPERGUI::isFeatureOfNested(const QAction* theAction) { - return dynamic_cast(theAction); + return dynamic_cast(theAction); } -QAction* NewGeom_Module::addFeatureOfNested(const QString& theWBName, - const ActionInfo& theInfo, - const QList& theNestedActions) +QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName, + const ActionInfo& theInfo, + const QList& theNestedActions) { - int aMenu = createMenu(theWBName, -1, -1, 50); - int aTool = createTool(theWBName, theWBName); - - int aId = myActionsList.size(); - myActionsList.append(theInfo.id); SUIT_Desktop* aDesk = application()->desktop(); - NewGeom_NestedButton* anAction = new NewGeom_NestedButton(aDesk, theNestedActions); + SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions); anAction->setData(theInfo.id); anAction->setCheckable(theInfo.checkable); anAction->setChecked(theInfo.checked); @@ -448,42 +640,52 @@ QAction* NewGeom_Module::addFeatureOfNested(const QString& theWBName, anAction->setShortcut(theInfo.shortcut); anAction->setFont(theInfo.font); - //int aItemId = createMenu(aId, aMenu, -1, 10); - int aToolId = createTool(anAction, aTool, aId); + 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; } //****************************************************** -QAction* NewGeom_Module::addDesktopCommand(const QString& theId, const QString& theTitle, +QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle, const QString& theTip, const QIcon& theIcon, const QKeySequence& theKeys, bool isCheckable, const char* theMenuSourceText, const int theMenuPosition) { 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 (unsigned int i = 0; i < theKeys.count(); i++) + for (int i = 0; i < theKeys.count(); i++) aKeys += theKeys[i]; QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, isCheckable); + aAction->setStatusTip(theTip); aAction->setData(theId); createMenu(aId, aMenu, theMenuPosition); return aAction; } //****************************************************** -void NewGeom_Module::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition) +void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition) { int aMenu = createMenu(tr(theMenuSourceText), -1, -1); createMenu(separator(), aMenu, -1, theMenuPosition); } -bool NewGeom_Module::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ) +//****************************************************** +bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ) { if( !theAction ) return false; @@ -501,86 +703,47 @@ bool NewGeom_Module::addActionInToolbar( QAction* theAction, const QString& theT } //****************************************************** -QList NewGeom_Module::commandList() const +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); } - return aActions; -} -//****************************************************** -QStringList NewGeom_Module::commandIdList() const -{ - return myActionsList; + return aActions; } //****************************************************** -QMainWindow* NewGeom_Module::desktop() const +QMainWindow* SHAPERGUI::desktop() const { return application()->desktop(); } -//****************************************************** -QString NewGeom_Module::commandId(const QAction* theCmd) const -{ - int aId = actionId(theCmd); - if (aId < myActionsList.size()) - return myActionsList[aId]; - return QString(); -} - -//****************************************************** -QAction* NewGeom_Module::command(const QString& theId) const -{ - int aId = myActionsList.indexOf(theId); - if ((aId != -1) && (aId < myActionsList.size())) { - return action(aId); - } - return 0; -} - -//****************************************************** -void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions) -{ - myNestedActions[theId] = theActions; -} - -//****************************************************** -QStringList NewGeom_Module::nestedActions(const QString& theId) const -{ - if (myNestedActions.contains(theId)) - return myNestedActions[theId]; - return QStringList(); -} - -//****************************************************** -void NewGeom_Module::setDocumentKind(const QString& theId, const QString& theKind) +void SHAPERGUI::setFeatureInfo(const QString& theFeatureId, + const std::shared_ptr& theMessage) { - myDocumentType[theId] = theKind; + myFeaturesInfo.insert(theFeatureId, theMessage); } -//****************************************************** -QString NewGeom_Module::documentKind(const QString& theId) const +std::shared_ptr SHAPERGUI::featureInfo(const QString& theFeatureId) { - if (myDocumentType.contains(theId)) - return myDocumentType[theId]; - return QString(); - + std::shared_ptr aMessage; + if (myFeaturesInfo.contains(theFeatureId)) + aMessage = myFeaturesInfo[theFeatureId]; + return aMessage; } //****************************************************** -void NewGeom_Module::selectionChanged() +void SHAPERGUI::selectionChanged() { LightApp_Module::selectionChanged(); myWorkshop->salomeViewerSelectionChanged(); } //****************************************************** -void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle) +void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle) { myWorkshop->contextMenuMgr()->updateViewerMenu(); myWorkshop->contextMenuMgr()->addViewerMenu(theMenu); @@ -589,7 +752,7 @@ void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, //****************************************************** -void NewGeom_Module::createPreferences() +void SHAPERGUI::createPreferences() { LightApp_Preferences* pref = preferences(); if (!pref) @@ -606,17 +769,82 @@ void NewGeom_Module::createPreferences() int catId = pref->addPreference(aModName, -1 ); if ( catId == -1 ) return; - NewGeom_PrefMgr aMgr(pref, aModName); + SHAPERGUI_PrefMgr aMgr(pref, aModName); ModuleBase_Preferences::createEditContent(&aMgr, catId); + + int viewTab = pref->addItem(tr("Viewer"), catId); + // Create other parameters group in viewer tab + int otherGroup = pref->addItem(tr("Default selection"), viewTab); + pref->setItemProperty("columns", 3, otherGroup); + pref->addItem(tr("Faces"), otherGroup, + SUIT_PreferenceMgr::Bool, + ModuleBase_Preferences::VIEWER_SECTION, "face-selection"); + pref->addItem(tr("Edges"), otherGroup, + SUIT_PreferenceMgr::Bool, + ModuleBase_Preferences::VIEWER_SECTION, "edge-selection"); + pref->addItem(tr("Vertices"), otherGroup, + SUIT_PreferenceMgr::Bool, + ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection"); + + int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab); + pref->setItemProperty("columns", 2, sensitivityGroup); + pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin, + ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity"); + pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin, + ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity"); + + int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab); + pref->setItemProperty("columns", 2, highlightGroup); + pref->addItem(tr("In 3d mode"), highlightGroup, + SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d"); + pref->addItem(tr("In 2d mode"), highlightGroup, + SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d"); + + int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab); + pref->setItemProperty("columns", 4, colorScaleGroup); + int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup, + SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position"); + pref->setItemProperty("min", 0, aItem); + pref->setItemProperty("max", 1, aItem); + + aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup, + SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position"); + pref->setItemProperty("min", 0, aItem); + pref->setItemProperty("max", 1, aItem); + + aItem = aMgr.addPreference(tr("Width"), colorScaleGroup, + SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width"); + pref->setItemProperty("min", 0, aItem); + pref->setItemProperty("max", 1, aItem); + + aItem = aMgr.addPreference(tr("Height"), colorScaleGroup, + SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height"); + pref->setItemProperty("min", 0, aItem); + pref->setItemProperty("max", 1, aItem); + + aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup, + SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals"); + pref->setItemProperty("min", 0, aItem); + pref->setItemProperty("max", 100, aItem); + + aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup, + SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height"); + pref->setItemProperty("min", 0, aItem); + pref->setItemProperty("max", 100, aItem); + + aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup, + SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color"); + pref->retrieve(); } //****************************************************** -void NewGeom_Module::preferencesChanged(const QString& theSection, const QString& theParam) +void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam) { SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); QString aVal = aResMgr->stringValue(theSection, theParam); - Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString()); + Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), + theParam.toStdString()); std::string aValue = aVal.toStdString(); if (aValue.empty()) { aValue = aProp->defaultValue(); @@ -631,16 +859,285 @@ void NewGeom_Module::preferencesChanged(const QString& theSection, const QString myWorkshop->displayer()->redisplayObjects(); } -void NewGeom_Module::inspectSalomeModules() +void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs) { - QStringList aModuleNames; - getApp()->modules(aModuleNames, false); - foreach(QString eachModule, aModuleNames) { - Config_ModuleReader::addDependencyModule(eachModule.toStdString()); - } + application()->putInfo(theInfo, theMSecs); } -bool NewGeom_Module::abortAllOperations() +bool SHAPERGUI::abortAllOperations() { return workshop()->operationMgr()->abortAllOperations(); } + +void SHAPERGUI::createFeatureActions() +{ + myWorkshop->menuMgr()->createFeatureActions(); +} + +void SHAPERGUI::onWhatIs(bool isToggled) +{ + if (sender() == myWhatIsAction) { + QAction* aViewAct = myInspectionPanel->toggleViewAction(); + aViewAct->blockSignals(true); + aViewAct->setChecked(isToggled); + aViewAct->blockSignals(false); + 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 configuration 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 configuration 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; + } + + // 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); +}