Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI.cpp
index fd929836dbba36b008763e68da7ddcb12fb3e7d0..e7189ffd8e38023950240ac34bb8d7198691c283 100644 (file)
@@ -1,5 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
+// Copyright (C) 2014-2017  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<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "SHAPERGUI.h"
 #include "SHAPERGUI_DataModel.h"
@@ -13,6 +30,9 @@
 #include <XGUI_OperationMgr.h>
 #include <XGUI_Displayer.h>
 #include <XGUI_MenuMgr.h>
+#include <XGUI_FacesPanel.h>
+#include <XGUI_SelectionActivate.h>
+#include <XGUI_InspectionPanel.h>
 
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_Preferences.h>
@@ -29,6 +49,7 @@
 #include <SUIT_Desktop.h>
 #include <SUIT_ViewManager.h>
 #include <SUIT_ResourceMgr.h>
+#include <SUIT_DataBrowser.h>
 
 #include <QtxPopupMgr.h>
 #include <QtxActionMenuMgr.h>
@@ -46,6 +67,7 @@
 #include <QTimer>
 #include <QMenu>
 
+#define SALOME_PATCH_FOR_CTRL_WHEEL
 
 extern "C" {
 SHAPERGUI_EXPORT CAM_Module* createModule()
@@ -71,7 +93,7 @@ public:
   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 )
   {
@@ -99,7 +121,8 @@ private:
 //******************************************************
 SHAPERGUI::SHAPERGUI()
     : LightApp_Module("SHAPER"),
-      mySelector(0), myIsOpened(0), myPopupMgr(0)
+      mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
+  myInspectionPanel(0)
 {
   myWorkshop = new XGUI_Workshop(this);
   connect(myWorkshop, SIGNAL(commandStatusUpdated()),
@@ -114,13 +137,14 @@ SHAPERGUI::SHAPERGUI()
 //******************************************************
 SHAPERGUI::~SHAPERGUI()
 {
+  delete myWorkshop;
+  delete myProxyViewer;
 }
 
 //******************************************************
 void SHAPERGUI::initialize(CAM_Application* theApp)
 {
   LightApp_Module::initialize(theApp);
-  inspectSalomeModules();
 
   myWorkshop->startApplication();
   LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
@@ -128,6 +152,22 @@ 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);
+
+  int aId = myActionsList.size();
+  myActionsList.append("INSPECTION_CMD");
+  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);
+
+  int aTool = createTool(tr("Inspection tool"));
+  int aToolId = createTool(myWhatIsAction, aTool);
 }
 
 //******************************************************
@@ -143,24 +183,28 @@ 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 
-  // 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);
-}
+// 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 contect 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 SHAPERGUI::activateModule(SUIT_Study* theStudy)
@@ -183,6 +227,13 @@ bool SHAPERGUI::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);
@@ -190,7 +241,7 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
         mySelector = createSelector(OCCViewManagers.first());
       }
     }
-    // it should be pefromed after the selector creation in order to have AISContext 
+    // it should be pefromed after the selector creation in order to have AISContext
     myWorkshop->activateModule();
     //action(myEraseAll)->setEnabled(false);
 
@@ -234,7 +285,7 @@ bool SHAPERGUI::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;
         }
@@ -247,6 +298,21 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   }
   myProxyViewer->activateViewer(true);
+
+  // Postrrocessing 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;
 }
 
@@ -268,6 +334,11 @@ bool SHAPERGUI::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
@@ -285,12 +356,28 @@ bool SHAPERGUI::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);
 
+  // Postrrocessing 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);
 }
 
@@ -299,7 +386,8 @@ void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
 {
   if (!mySelector) {
     mySelector = createSelector(theMgr);
-    myWorkshop->module()->activateSelectionFilters();
+    myWorkshop->selectionActivate()->updateSelectionFilters();
+    myWorkshop->selectionActivate()->updateSelectionModes();
     myWorkshop->synchronizeViewer();
   }
 }
@@ -345,6 +433,37 @@ void SHAPERGUI::onDefaultPreferences()
   myWorkshop->displayer()->redisplayObjects();
 }
 
+//******************************************************
+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()
 {
@@ -358,6 +477,9 @@ SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
     OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
     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<SUIT_Selector*> aList;
     aMgr->selectors(aList);
@@ -381,10 +503,11 @@ 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
-                    theInfo.text, 
+                    theInfo.text,
                     theInfo.icon,
                     theInfo.shortcut,
                     theInfo.checkable,
@@ -393,8 +516,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)
@@ -416,7 +539,7 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId,
   myActionsList.append(theId);
   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);
@@ -429,7 +552,7 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId,
   if (isAddSeparator)
     createMenu(separator(), aWBMenu);
 
-  int aWBTool = createTool(theWBName, theWBName);
+  int aWBTool = createTool(theTBName, theTBName);
   int aToolId = createTool(aId, aWBTool);
   if (isAddSeparator)
     createTool(separator(), aWBTool);
@@ -484,7 +607,7 @@ QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTi
   myActionsList.append(theId);
   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);
@@ -592,21 +715,21 @@ void SHAPERGUI::createPreferences()
   // 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, 
+  pref->addItem(tr("Faces"), otherGroup,
                          SUIT_PreferenceMgr::Bool,
                          ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
-  pref->addItem(tr("Edges"), otherGroup, 
+  pref->addItem(tr("Edges"), otherGroup,
                          SUIT_PreferenceMgr::Bool,
                          ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
-  pref->addItem(tr("Vertices"), otherGroup, 
+  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::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");
   pref->retrieve();
 }
@@ -637,15 +760,6 @@ void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
   application()->putInfo(theInfo, theMSecs);
 }
 
-void SHAPERGUI::inspectSalomeModules()
-{
-  QStringList aModuleNames;
-  getApp()->modules(aModuleNames, false);
-  foreach(QString eachModule, aModuleNames) {
-    Config_ModuleReader::addDependencyModule(eachModule.toStdString());
-  }
-}
-
 bool SHAPERGUI::abortAllOperations()
 {
   return workshop()->operationMgr()->abortAllOperations();
@@ -655,3 +769,26 @@ 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);
+}