X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSHAPERGUI%2FSHAPERGUI.cpp;h=b86d3fdf5c69f8a6fe1ea3ba63e9673840ca034a;hb=ae3e12ab08ba2c98c74c9f4b93812faace2af798;hp=da00b44bf2f5ad620b2d47b690f7d0993ecfcbb1;hpb=7074394f8f08413d885f63be01df6bd5007b868c;p=modules%2Fshaper.git diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp index da00b44bf..b86d3fdf5 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-2020 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 @@ -30,21 +30,30 @@ #include #include #include +#include +#include +#include +#include #include #include #include #include +#include + #include #include #include #include + #include +#include #include #include #include +#include #include #include @@ -63,8 +72,13 @@ #include #include #include +#include + +#include -//#define SALOME_PATCH_FOR_CTRL_WHEEL +#if OCC_VERSION_HEX < 0x070400 + #define SALOME_PATCH_FOR_CTRL_WHEEL +#endif extern "C" { SHAPERGUI_EXPORT CAM_Module* createModule() @@ -78,6 +92,11 @@ SHAPERGUI_EXPORT char* getModuleVersion() } } // extern "C" + +static const QString ToolbarsSection("SHAPER_Toolbars"); +static const QString FreeCommandsParam("OutOFToolbars"); + + /** * Class for preferences management */ @@ -118,7 +137,9 @@ private: //****************************************************** SHAPERGUI::SHAPERGUI() : LightApp_Module("SHAPER"), - mySelector(0), myIsOpened(0), myPopupMgr(0) + mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false), + myInspectionPanel(0), myIsFacesPanelVisible(false), myIsToolbarsModified(false), + myAxisArrowRate(-1) { myWorkshop = new XGUI_Workshop(this); connect(myWorkshop, SIGNAL(commandStatusUpdated()), @@ -127,12 +148,16 @@ SHAPERGUI::SHAPERGUI() myProxyViewer = new SHAPERGUI_SalomeViewer(this); ModuleBase_Preferences::setResourceMgr(application()->resourceMgr()); - ModuleBase_Preferences::loadCustomProps(); + + // It will be called in XGUI_Workshop::startApplication + // ModuleBase_Preferences::loadCustomProps(); } //****************************************************** SHAPERGUI::~SHAPERGUI() { + delete myWorkshop; + delete myProxyViewer; } //****************************************************** @@ -146,6 +171,71 @@ void SHAPERGUI::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, -1, -1, 0); + + 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"); + int aTool = createTool(aToolName); +#ifdef _DEBUG + int aToolId = +#endif + 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"); +#ifdef _DEBUG + QAction* aAction = +#endif + 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); +#ifdef _DEBUG + int aEditItem = +#endif + createMenu(aId, aEditMenu); + + if (!myInspectionPanel) { + myInspectionPanel = myWorkshop->inspectionPanel(); + connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)), + this, SLOT(onWhatIs(bool))); + } + hideInternalWindows(); + + // 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); + } + } + } + SHAPERGUI_DataModel* aDataModel = dynamic_cast(dataModel()); + aDataModel->initRootObject(); } //****************************************************** @@ -167,7 +257,7 @@ void SHAPERGUI::viewManagers(QStringList& theList) const //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 contect to the +// // 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 @@ -187,10 +277,17 @@ void SHAPERGUI::viewManagers(QStringList& theList) const //****************************************************** bool SHAPERGUI::activateModule(SUIT_Study* theStudy) { - bool isDone = LightApp_Module::activateModule(theStudy); + ModelAPI_Session::get()->moduleDocument(); // initialize a root document if not done yet + + // this must be done in the initialization and in activation (on the second activation + // initialization in not called, so SComponent must be added anyway SHAPERGUI_DataModel* aDataModel = dynamic_cast(dataModel()); aDataModel->initRootObject(); + + bool isDone = LightApp_Module::activateModule(theStudy); + loadToolbarsConfig(); + if (isDone) { setMenuShown(true); setToolShown(true); @@ -198,21 +295,27 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy) QObject* aObj = myWorkshop->objectBrowser()->parent(); QDockWidget* aObjDoc = dynamic_cast(aObj); if (aObjDoc) { - QAction* aViewAct = aObjDoc->toggleViewAction(); - aViewAct->setEnabled(true); myWorkshop->objectBrowser()->setVisible(true); aObjDoc->setVisible(true); desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel()); + aObjDoc->toggleViewAction()->setVisible(true); } + myInspectionPanel->toggleViewAction()->setVisible(true); + + myWorkshop->facesPanel()->toggleViewAction()->setVisible(true); + if (myIsFacesPanelVisible) + myWorkshop->facesPanel()->show(); + myWorkshop->propertyPanel()->toggleViewAction()->setVisible(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); @@ -246,6 +349,9 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy) XGUI_Displayer* aDisp = myWorkshop->displayer(); QObjectPtrList aObjList = aDisp->displayedObjects(); + if (myOldSelectionColor.size() == 0) + myOldSelectionColor = aDisp->selectionColor(); + AIS_ListOfInteractive aList; aContext->DisplayedObjects(aList); AIS_ListIteratorOfListOfInteractive aLIt; @@ -270,30 +376,62 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy) } myProxyViewer->activateViewer(true); - // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser + // 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 SHAPERGUI::deactivateModule(SUIT_Study* theStudy) +void SHAPERGUI::hideInternalWindows() { myProxyViewer->activateViewer(false); setMenuShown(false); setToolShown(false); - myWorkshop->deactivateModule(); - QObject* aObj = myWorkshop->objectBrowser()->parent(); QDockWidget* aObjDoc = dynamic_cast(aObj); if (aObjDoc) { aObjDoc->setVisible(false); myWorkshop->objectBrowser()->setVisible(false); - QAction* aViewAct = aObjDoc->toggleViewAction(); - aViewAct->setEnabled(false); + aObjDoc->toggleViewAction()->setVisible(false); } + myInspectionPanel->hide(); + myInspectionPanel->toggleViewAction()->setVisible(false); + + myWorkshop->facesPanel()->hide(); + myWorkshop->facesPanel()->toggleViewAction()->setVisible(false); + + myWorkshop->propertyPanel()->hide(); + myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false); + + myWorkshop->hidePanel(myWorkshop->facesPanel()); +} + + +//****************************************************** +bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) +{ + saveToolbarsConfig(); + myWorkshop->deactivateModule(); + + myIsInspectionVisible = myInspectionPanel->isVisible(); + myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible(); + hideInternalWindows(); + + // 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 @@ -306,7 +444,24 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) } // Delete selector because it has to be redefined on next activation if (mySelector) { + // Restore size of arrows of trihedron + if (myAxisArrowRate > 0) { + Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron(); + Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect(); + aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate); + Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext(); + aContext->Redisplay(aTrihedron, false); + } + myWorkshop->displayer()->setSelectionColor(myOldSelectionColor); myProxyViewer->setSelector(0); + + LightApp_SelectionMgr* aMgr = getApp()->selectionMgr(); + QList aList; + aMgr->selectors(aList); + foreach(SUIT_Selector* aSel, aList) { + aSel->setEnabled(aSel != mySelector); + } + delete mySelector; mySelector = 0; } @@ -317,10 +472,24 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) aResMgr->setValue("Study", "store_positions", myIsStorePositions); getApp()->setEditEnabled(myIsEditEnabled); - // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser + myOldSelectionColor.clear(); + + // 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())); + + publishToStudy(); + return LightApp_Module::deactivateModule(theStudy); } @@ -329,7 +498,8 @@ void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr) { if (!mySelector) { mySelector = createSelector(theMgr); - myWorkshop->module()->activateSelectionFilters(); + myWorkshop->selectionActivate()->updateSelectionFilters(); + myWorkshop->selectionActivate()->updateSelectionModes(); myWorkshop->synchronizeViewer(); } } @@ -343,8 +513,16 @@ void SHAPERGUI::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; @@ -386,6 +564,26 @@ void SHAPERGUI::onScriptLoaded() SUIT_DataBrowser* aBrowser = getApp()->objectBrowser(); if (aBrowser) delete aBrowser; + myWorkshop->displayer()->updateViewer(); + myWorkshop->updateCommandStatus(); +} + +//****************************************************** +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(); } //****************************************************** @@ -399,6 +597,12 @@ SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr) { if (theMgr->getType() == OCCViewer_Viewer::Type()) { OCCViewer_Viewer* aViewer = static_cast(theMgr->getViewModel()); + + // Remember current length of arrow of axis + Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron(); + Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect(); + myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent); + SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer, getApp()->selectionMgr()); #ifdef SALOME_PATCH_FOR_CTRL_WHEEL @@ -412,6 +616,16 @@ SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr) aSel->setEnabled(aSel == aSelector); } myProxyViewer->setSelector(aSelector); + + if (myOldSelectionColor.size() == 0) + myOldSelectionColor = myWorkshop->displayer()->selectionColor(); + + std::vector aColor = Config_PropManager::color("Visualization", "selection_color"); + myWorkshop->displayer()->setSelectionColor(aColor); + + // Cause scaling of arrows of axis and dimensions + myWorkshop->module()->onViewTransformed(); + return aSelector; } return 0; @@ -427,6 +641,7 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theIn const bool isAddSeparator) { return addFeature(theWBName, + theInfo.toolBar, theInfo.id, theInfo.text, //Issue #650: in the SALOME mode the tooltip should be same as text @@ -439,8 +654,8 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theIn } //****************************************************** -QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId, - const QString& theTitle, const QString& theTip, +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) @@ -458,8 +673,8 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId, } 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++) @@ -471,15 +686,23 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId, aAction->setData(theId); int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/); - int aItemId = createMenu(aId, aWBMenu); +#ifdef _DEBUG + int aItemId = +#endif + createMenu(aId, aWBMenu); if (isAddSeparator) createMenu(separator(), aWBMenu); - int aWBTool = createTool(theWBName, theWBName); - int aToolId = createTool(aId, aWBTool); - if (isAddSeparator) + int aWBTool = createTool(theTBName, theTBName); +#ifdef _DEBUG + int aToolId = +#endif + createTool(aId, aWBTool); + registerCommandToolbar(theTBName, aId); + if (isAddSeparator) { createTool(separator(), aWBTool); - + registerCommandToolbar(theTBName, -1); + } return aAction; } @@ -492,7 +715,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); @@ -508,11 +730,17 @@ 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); +#ifdef _DEBUG + int aToolId = +#endif + createTool(anAction, aWBTool); + registerCommandToolbar(theWBName, aItemId); createTool(separator(), aWBTool); /// nested action is always separated of others + registerCommandToolbar(theWBName, -1); return anAction; } @@ -522,12 +750,17 @@ QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName, 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) + const char* theMenuSourceText, + const QString& theSubMenu, + const int theMenuPosition, + const int theSuibMenuPosition) { int aMenu = createMenu(tr(theMenuSourceText), -1, -1); + if (!theSubMenu.isNull()) + aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition); - 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++) @@ -547,6 +780,7 @@ void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int createMenu(separator(), aMenu, -1, theMenuPosition); } +//****************************************************** bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ) { if( !theAction ) @@ -568,9 +802,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); } @@ -650,10 +884,53 @@ void SHAPERGUI::createPreferences() int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab); pref->setItemProperty("columns", 2, sensitivityGroup); - pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::Double, + pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin, ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity"); - pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::Double, + 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(); } @@ -675,6 +952,40 @@ void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& the } aProp->setValue(aValue); + if (theSection == "Visualization") { + if (theParam == "selection_color") { + std::vector aColor = Config_PropManager::color("Visualization", "selection_color"); + myWorkshop->displayer()->setSelectionColor(aColor); + } + if ((theParam == "zoom_trihedron_arrows") || (theParam == "axis_arrow_size")) { + if (mySelector) { + Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron(); + if (!aTrihedron.IsNull()) { + bool aZoom = Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows"); + Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext(); + + ModuleBase_IViewer* aViewer = myWorkshop->viewer(); + Handle(V3d_View) aView = aViewer->activeView(); + if (aZoom) { + double aAxLen = + aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size")); + Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect(); + double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis); + myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent); + aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen); + aTrihedron->Attributes()->SetDatumAspect(aDatumAspect); + aContext->Redisplay(aTrihedron, true); + + } + else if (myAxisArrowRate > 0) { + Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect(); + aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate); + aContext->Redisplay(aTrihedron, true); + } + } + } + } + } myWorkshop->displayer()->redisplayObjects(); } @@ -692,3 +1003,280 @@ 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; +#ifdef _DEBUG + QtxActionToolMgr* aMgr = +#endif + 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); +} + +void SHAPERGUI::publishToStudy() +{ + if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument()) + myWorkshop->module()->launchOperation("PublishToStudy", false); +}