Salome HOME
Issue #3237: Allow usage of accented characters in ObjectBrowser
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI.cpp
index bfac1ab628b70ac844930099f6fa4bddcbeaf581..b86d3fdf5c69f8a6fe1ea3ba63e9673840ca034a 100644 (file)
@@ -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
 #include <QMenu>
 #include <QToolBar>
 
-#define SALOME_PATCH_FOR_CTRL_WHEEL
+#include <ModelAPI_Session.h>
+
+#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<SHAPERGUI_DataModel*>(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<SHAPERGUI_DataModel*>(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<QDockWidget*>(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,11 +349,6 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
     XGUI_Displayer* aDisp = myWorkshop->displayer();
     QObjectPtrList aObjList = aDisp->displayedObjects();
 
-    //if (myHighlightPointAspect.IsNull()) {
-    //  Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
-    //  myHighlightPointAspect =
-    //    new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
-    //}
     if (myOldSelectionColor.size() == 0)
       myOldSelectionColor = aDisp->selectionColor();
 
@@ -372,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<QDockWidget*>(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.
@@ -408,18 +444,28 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
   }
   // Delete selector because it has to be redefined on next activation
   if (mySelector) {
-    //if (!myHighlightPointAspect.IsNull()) {
-    //  Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
-    //  aTrihedron->getHighlightPointAspect()->SetAspect(myHighlightPointAspect);
-    //  myHighlightPointAspect.Nullify();
-    //}
+    // 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<SUIT_Selector*> 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();
@@ -442,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);
 }
 
@@ -550,11 +598,11 @@ SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
   if (theMgr->getType() == OCCViewer_Viewer::Type()) {
     OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
 
-    //if (myHighlightPointAspect.IsNull()) {
-    //  Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
-    //  myHighlightPointAspect =
-    //    new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
-    //}
+    // 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
@@ -574,6 +622,10 @@ SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
 
     std::vector<int> 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;
@@ -634,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);
@@ -676,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);
@@ -689,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);
@@ -886,11 +952,40 @@ void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& the
   }
   aProp->setValue(aValue);
 
-  if ((theSection == "Visualization") && (theParam == "selection_color")) {
-    std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
-    myWorkshop->displayer()->setSelectionColor(aColor);
-  }
+  if (theSection == "Visualization") {
+    if (theParam == "selection_color") {
+      std::vector<int> 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();
 }
 
@@ -1029,7 +1124,10 @@ void SHAPERGUI::saveToolbarsConfig()
     return;
   // Save toolbars configuration into map
   QMap<QString, QStringList> aToolbarsConfig;
-  QtxActionToolMgr* aMgr = toolMgr();
+#ifdef _DEBUG
+  QtxActionToolMgr* aMgr =
+#endif
+    toolMgr();
   QStringList aToolbars = myToolbars.keys();
   QIntList aActionsIds;
   foreach(QString aName, aToolbars) {
@@ -1176,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);
+}