X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSHAPERGUI%2FSHAPERGUI.cpp;h=b86d3fdf5c69f8a6fe1ea3ba63e9673840ca034a;hb=ae3e12ab08ba2c98c74c9f4b93812faace2af798;hp=5b69d3593ffb8e02830a296173cbdf0abf0185bb;hpb=68348d55f163db4bf58eabab1eed48b6126a4d5e;p=modules%2Fshaper.git diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp index 5b69d3593..b86d3fdf5 100644 --- a/src/SHAPERGUI/SHAPERGUI.cpp +++ b/src/SHAPERGUI/SHAPERGUI.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 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 @@ -74,7 +74,11 @@ #include #include -#define SALOME_PATCH_FOR_CTRL_WHEEL +#include + +#if OCC_VERSION_HEX < 0x070400 + #define SALOME_PATCH_FOR_CTRL_WHEEL +#endif extern "C" { SHAPERGUI_EXPORT CAM_Module* createModule() @@ -134,7 +138,8 @@ private: SHAPERGUI::SHAPERGUI() : LightApp_Module("SHAPER"), mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false), - myInspectionPanel(0), myIsToolbarsModified(false) + myInspectionPanel(0), myIsFacesPanelVisible(false), myIsToolbarsModified(false), + myAxisArrowRate(-1) { myWorkshop = new XGUI_Workshop(this); connect(myWorkshop, SIGNAL(commandStatusUpdated()), @@ -168,7 +173,7 @@ void SHAPERGUI::initialize(CAM_Application* theApp) } int aMenu = createMenu(tr("Inspection"), -1, -1, 30); - int aSubMenu = createMenu(tr("Information"), aMenu); + int aSubMenu = createMenu(tr("Information"), aMenu, -1, -1, 0); int aId = getNextCommandId(); myActionsList.append(aId); @@ -180,19 +185,35 @@ void SHAPERGUI::initialize(CAM_Application* theApp) myWhatIsAction->setData("INSPECTION_CMD"); createMenu(aId, aSubMenu, 0); - QString aToolName = tr("Inspection tool"); + QString aToolName = tr("Inspection"); int aTool = createTool(aToolName); - int aToolId = createTool(myWhatIsAction, aTool); +#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"); - QAction* aAction = createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"), +#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); - int aEditItem = createMenu(aId, aEditMenu); +#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; @@ -213,6 +234,8 @@ void SHAPERGUI::initialize(CAM_Application* theApp) } } } + SHAPERGUI_DataModel* aDataModel = dynamic_cast(dataModel()); + aDataModel->initRootObject(); } //****************************************************** @@ -254,12 +277,17 @@ void SHAPERGUI::viewManagers(QStringList& theList) const //****************************************************** bool SHAPERGUI::activateModule(SUIT_Study* theStudy) { - bool isDone = LightApp_Module::activateModule(theStudy); - loadToolbarsConfig(); + 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); @@ -267,19 +295,18 @@ 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); } - if (!myInspectionPanel) { - myInspectionPanel = myWorkshop->inspectionPanel(); - QAction* aViewAct = myInspectionPanel->toggleViewAction(); - connect(aViewAct, SIGNAL(toggled(bool)), this, SLOT(onWhatIs(bool))); - } - myInspectionPanel->toggleViewAction()->setEnabled(true); + myInspectionPanel->toggleViewAction()->setVisible(true); + + myWorkshop->facesPanel()->toggleViewAction()->setVisible(true); + if (myIsFacesPanelVisible) + myWorkshop->facesPanel()->show(); + myWorkshop->propertyPanel()->toggleViewAction()->setVisible(true); if (!mySelector) { ViewManagerList OCCViewManagers; @@ -322,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; @@ -364,29 +394,43 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy) } //****************************************************** -bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) +void SHAPERGUI::hideInternalWindows() { - saveToolbarsConfig(); - 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); } - myIsInspectionVisible = myInspectionPanel->isVisible(); myInspectionPanel->hide(); - QAction* aViewAct = myInspectionPanel->toggleViewAction(); - aViewAct->setEnabled(false); + 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. @@ -400,18 +444,36 @@ 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; } - myWorkshop->hidePanel(myWorkshop->facesPanel()); //myWorkshop->contextMenuMgr()->disconnectViewer(); SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); aResMgr->setValue("Study", "store_positions", myIsStorePositions); getApp()->setEditEnabled(myIsEditEnabled); + 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())); @@ -426,6 +488,8 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)), getApp(), SLOT(onSaveAsDoc())); + publishToStudy(); + return LightApp_Module::deactivateModule(theStudy); } @@ -500,6 +564,8 @@ void SHAPERGUI::onScriptLoaded() SUIT_DataBrowser* aBrowser = getApp()->objectBrowser(); if (aBrowser) delete aBrowser; + myWorkshop->displayer()->updateViewer(); + myWorkshop->updateCommandStatus(); } //****************************************************** @@ -531,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 @@ -544,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; @@ -604,12 +686,18 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBNam 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(theTBName, theTBName); - int aToolId = createTool(aId, aWBTool); +#ifdef _DEBUG + int aToolId = +#endif + createTool(aId, aWBTool); registerCommandToolbar(theTBName, aId); if (isAddSeparator) { createTool(separator(), aWBTool); @@ -646,7 +734,10 @@ QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName, 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); @@ -659,9 +750,14 @@ 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 = getNextCommandId(); myActionsList.append(aId); @@ -856,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(); } @@ -994,7 +1124,10 @@ void SHAPERGUI::saveToolbarsConfig() return; // Save toolbars configuration into map QMap aToolbarsConfig; - QtxActionToolMgr* aMgr = toolMgr(); +#ifdef _DEBUG + QtxActionToolMgr* aMgr = +#endif + toolMgr(); QStringList aToolbars = myToolbars.keys(); QIntList aActionsIds; foreach(QString aName, aToolbars) { @@ -1141,3 +1274,9 @@ void SHAPERGUI::resetToolbars() SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); aResMgr->remove(ToolbarsSection); } + +void SHAPERGUI::publishToStudy() +{ + if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument()) + myWorkshop->module()->launchOperation("PublishToStudy", false); +}