Salome HOME
Activation objects redesign.
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI.cpp
index fecbbb031be34f7f22b092cc3709357fe7ef1249..20524c9030f8fa31d56b65aa199c8ec559f6b905 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"
@@ -12,6 +29,9 @@
 #include <XGUI_ObjectsBrowser.h>
 #include <XGUI_OperationMgr.h>
 #include <XGUI_Displayer.h>
+#include <XGUI_MenuMgr.h>
+#include <XGUI_FacesPanel.h>
+#include <XGUI_SelectionActivate.h>
 
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_Preferences.h>
@@ -28,6 +48,7 @@
 #include <SUIT_Desktop.h>
 #include <SUIT_ViewManager.h>
 #include <SUIT_ResourceMgr.h>
+#include <SUIT_DataBrowser.h>
 
 #include <QtxPopupMgr.h>
 #include <QtxActionMenuMgr.h>
@@ -45,6 +66,7 @@
 #include <QTimer>
 #include <QMenu>
 
+#define SALOME_PATCH_FOR_CTRL_WHEEL
 
 extern "C" {
 SHAPERGUI_EXPORT CAM_Module* createModule()
@@ -67,9 +89,10 @@ public:
   /// Constructor
   /// \param theMgr preferences manager of SALOME
   /// \param theModName name of the module
-  SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):myMgr(theMgr), myModName(theModName) {}
+  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 )
   {
@@ -118,7 +141,6 @@ SHAPERGUI::~SHAPERGUI()
 void SHAPERGUI::initialize(CAM_Application* theApp)
 {
   LightApp_Module::initialize(theApp);
-  inspectSalomeModules();
 
   myWorkshop->startApplication();
   LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
@@ -141,23 +163,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)
@@ -187,7 +214,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);
 
@@ -231,7 +258,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;
         }
@@ -244,6 +271,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;
 }
 
@@ -282,12 +324,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);
 }
 
@@ -296,7 +354,8 @@ void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
 {
   if (!mySelector) {
     mySelector = createSelector(theMgr);
-    myWorkshop->module()->activateSelectionFilters();
+    myWorkshop->selectionActivate()->updateSelectionFilters();
+    myWorkshop->selectionActivate()->updateSelectionModes();
     myWorkshop->synchronizeViewer();
   }
 }
@@ -342,6 +401,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()
 {
@@ -353,7 +443,11 @@ SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
 {
   if (theMgr->getType() == OCCViewer_Viewer::Type()) {
     OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
-    SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer, getApp()->selectionMgr());
+    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);
@@ -373,22 +467,27 @@ CAM_DataModel* SHAPERGUI::createDataModel()
   return new SHAPERGUI_DataModel(this);
 }
 
-QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo)
+QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
+                               const bool isAddSeparator)
 {
   return addFeature(theWBName,
                     theInfo.id,
                     theInfo.text,
-                    theInfo.toolTip,
+                    //Issue #650: in the SALOME mode the tooltip should be same as text
+                    theInfo.text,
                     theInfo.icon,
                     theInfo.shortcut,
-                    theInfo.checkable);
+                    theInfo.checkable,
+                    isAddSeparator,
+                    theInfo.toolTip);
 }
 
 //******************************************************
 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId,
-                                    const QString& theTitle, const QString& theTip,
-                                    const QIcon& theIcon, const QKeySequence& theKeys,
-                                    bool isCheckable)
+                               const QString& theTitle, const QString& theTip,
+                               const QIcon& theIcon, const QKeySequence& theKeys,
+                               bool isCheckable, const bool isAddSeparator,
+                               const QString& theStatusTip)
 {
   static QString aLastTool = "";
   static int aNb = 0;
@@ -403,20 +502,27 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId,
   }
   aNb++;
 
-  int aMenu = createMenu(theWBName, -1, -1, 50);
-  int aTool = createTool(theWBName, theWBName);
-
   int aId = myActionsList.size();
   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);
+  aAction->setStatusTip(theStatusTip);
+
   aAction->setData(theId);
-  int aItemId = createMenu(aId, aMenu, -1, 10);
-  int aToolId = createTool(aId, aTool);
+
+  int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
+  int aItemId = createMenu(aId, aWBMenu);
+  if (isAddSeparator)
+    createMenu(separator(), aWBMenu);
+
+  int aWBTool = createTool(theWBName, theWBName);
+  int aToolId = createTool(aId, aWBTool);
+  if (isAddSeparator)
+    createTool(separator(), aWBTool);
 
   return aAction;
 }
@@ -427,13 +533,9 @@ bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
 }
 
 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
-                                            const ActionInfo& theInfo,
-                                            const QList<QAction*>& theNestedActions)
+                                       const ActionInfo& theInfo,
+                                       const QList<QAction*>& theNestedActions)
 {
-  int aMenu = createMenu(theWBName, -1, -1, 50);
-  int aTool = createTool(theWBName, theWBName);
-
-  int aId = myActionsList.size();
   myActionsList.append(theInfo.id);
   SUIT_Desktop* aDesk = application()->desktop();
   SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
@@ -448,8 +550,13 @@ QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
   anAction->setShortcut(theInfo.shortcut);
   anAction->setFont(theInfo.font);
 
-  //int aItemId = createMenu(aId, aMenu, -1, 10);
-  int aToolId = createTool(anAction, aTool, aId);
+  int aWBMenu = createMenu(theWBName, -1, -1, 30);
+  int aItemId = createMenu(anAction, aWBMenu);
+  createMenu(separator(), aWBMenu); /// nested action is always separated of others
+
+  int aWBTool = createTool(theWBName, theWBName);
+  int aToolId = createTool(anAction, aWBTool);
+  createTool(separator(), aWBTool); /// nested action is always separated of others
 
   return anAction;
 }
@@ -467,10 +574,11 @@ 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);
+  aAction->setStatusTip(theTip);
   aAction->setData(theId);
   createMenu(aId, aMenu, theMenuPosition);
   return aAction;
@@ -509,13 +617,8 @@ QList<QAction*> SHAPERGUI::commandList() const
     if (aCmd && myActionsList.contains(aCmd->data().toString()))
       aActions.append(aCmd);
   }
-  return aActions;
-}
 
-//******************************************************
-QStringList SHAPERGUI::commandIdList() const
-{
-  return myActionsList;
+  return aActions;
 }
 
 //******************************************************
@@ -524,25 +627,6 @@ QMainWindow* SHAPERGUI::desktop() const
   return application()->desktop();
 }
 
-//******************************************************
-QString SHAPERGUI::commandId(const QAction* theCmd) const
-{
-  int aId = actionId(theCmd);
-  if (aId < myActionsList.size())
-    return myActionsList[aId];
-  return QString();
-}
-
-//******************************************************
-QAction* SHAPERGUI::command(const QString& theId) const
-{
-  int aId = myActionsList.indexOf(theId);
-  if ((aId != -1) && (aId < myActionsList.size())) {
-    return action(aId);
-  }
-  return 0;
-}
-
 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
                                const std::shared_ptr<Config_FeatureMessage>& theMessage)
 {
@@ -551,7 +635,10 @@ void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
 
 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
 {
-  return myFeaturesInfo.contains(theFeatureId) ? myFeaturesInfo[theFeatureId] : NULL;
+  std::shared_ptr<Config_FeatureMessage> aMessage;
+  if (myFeaturesInfo.contains(theFeatureId))
+    aMessage =  myFeaturesInfo[theFeatureId];
+  return aMessage;
 }
 
 //******************************************************
@@ -593,25 +680,24 @@ void SHAPERGUI::createPreferences()
 
   int viewTab = pref->addItem(tr("Viewer"), catId);
   // Create other parameters group in viewer tab
-  int otherGroup = pref->addItem(tr("Other parameters"), viewTab);
-  int selId = pref->addItem(tr("Default selection type"), otherGroup, 
-                                     SUIT_PreferenceMgr::Selector,
-                                     ModuleBase_Preferences::VIEWER_SECTION, "selection");
-  QStringList aSelectionList;
-  aSelectionList.append( tr("Vertices") );
-  aSelectionList.append( tr("Edges") );
-  aSelectionList.append( tr("Faces") );
-  aSelectionList.append( tr("Results") );
-
-  QList<QVariant> anIndexesList;
-  anIndexesList.append(TopAbs_VERTEX);
-  anIndexesList.append(TopAbs_EDGE);
-  anIndexesList.append(TopAbs_FACE);
-  anIndexesList.append(-1);
-
-  pref->setItemProperty( "strings", aSelectionList, selId );
-  pref->setItemProperty( "indexes", anIndexesList, selId );
-  
+  int otherGroup = pref->addItem(tr("Default selection"), viewTab);
+  pref->setItemProperty("columns", 3, otherGroup);
+  pref->addItem(tr("Faces"), otherGroup,
+                         SUIT_PreferenceMgr::Bool,
+                         ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
+  pref->addItem(tr("Edges"), otherGroup,
+                         SUIT_PreferenceMgr::Bool,
+                         ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
+  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,
+                ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
+  pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::Double,
+                ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
   pref->retrieve();
 }
 
@@ -620,7 +706,8 @@ void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& the
 {
   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
   QString aVal = aResMgr->stringValue(theSection, theParam);
-  Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
+  Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
+                                                    theParam.toStdString());
   std::string aValue = aVal.toStdString();
   if (aValue.empty()) {
     aValue = aProp->defaultValue();
@@ -635,16 +722,17 @@ void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& the
   myWorkshop->displayer()->redisplayObjects();
 }
 
-void SHAPERGUI::inspectSalomeModules()
+void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
 {
-  QStringList aModuleNames;
-  getApp()->modules(aModuleNames, false);
-  foreach(QString eachModule, aModuleNames) {
-    Config_ModuleReader::addDependencyModule(eachModule.toStdString());
-  }
+  application()->putInfo(theInfo, theMSecs);
 }
 
 bool SHAPERGUI::abortAllOperations()
 {
   return workshop()->operationMgr()->abortAllOperations();
 }
+
+void SHAPERGUI::createFeatureActions()
+{
+  myWorkshop->menuMgr()->createFeatureActions();
+}