Salome HOME
Issue #3237: Allow usage of accented characters in ObjectBrowser
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI.cpp
index 32633baa1e518d1facf3063adeb9fbf3d590c644..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
@@ -74,6 +74,8 @@
 #include <QMenu>
 #include <QToolBar>
 
+#include <ModelAPI_Session.h>
+
 #if OCC_VERSION_HEX < 0x070400
   #define SALOME_PATCH_FOR_CTRL_WHEEL
 #endif
@@ -185,17 +187,33 @@ void SHAPERGUI::initialize(CAM_Application* theApp)
 
   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;
@@ -216,6 +234,8 @@ void SHAPERGUI::initialize(CAM_Application* theApp)
       }
     }
   }
+  SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
+  aDataModel->initRootObject();
 }
 
 //******************************************************
@@ -257,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);
@@ -276,11 +301,6 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
       aObjDoc->toggleViewAction()->setVisible(true);
     }
 
-    if (!myInspectionPanel) {
-      myInspectionPanel = myWorkshop->inspectionPanel();
-      connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)),
-              this, SLOT(onWhatIs(bool)));
-    }
     myInspectionPanel->toggleViewAction()->setVisible(true);
 
     myWorkshop->facesPanel()->toggleViewAction()->setVisible(true);
@@ -374,16 +394,12 @@ 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) {
@@ -392,17 +408,30 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
     aObjDoc->toggleViewAction()->setVisible(false);
   }
 
-  myIsInspectionVisible = myInspectionPanel->isVisible();
   myInspectionPanel->hide();
   myInspectionPanel->toggleViewAction()->setVisible(false);
 
-  myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible();
   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
@@ -437,7 +466,6 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
     mySelector = 0;
   }
 
-  myWorkshop->hidePanel(myWorkshop->facesPanel());
   //myWorkshop->contextMenuMgr()->disconnectViewer();
 
   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
@@ -658,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);
@@ -700,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);
@@ -915,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();
 }
 
@@ -1058,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) {
@@ -1208,6 +1277,6 @@ void SHAPERGUI::resetToolbars()
 
 void SHAPERGUI::publishToStudy()
 {
-  if (isActiveModule())
+  if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument())
     myWorkshop->module()->launchOperation("PublishToStudy", false);
 }