1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
24 #include "SHAPER_SHAPERGUI.h"
25 #include "SHAPERGUI_SalomeViewer.h"
27 #include <LightApp_Module.h>
28 #include <XGUI_SalomeConnector.h>
30 #include <ModuleBase_ActionInfo.h>
36 class SHAPERGUI_OCCSelector;
37 class OCCViewer_Viewer;
42 * An implementation of SALOME connector class for implementation of
43 * XGUI functionality as a module of SALOME
45 class SHAPERGUI_EXPORT SHAPERGUI : public LightApp_Module, public XGUI_SalomeConnector
52 //----- LightAPP_Module interface ---------------
54 /// \brief Initializing of the module
55 /// \param theApp application instance
56 virtual void initialize(CAM_Application* theApp);
58 /// \brief Definition of module standard windows
59 virtual void windows(QMap<int, int>& theWndMap) const;
61 /// \brief Definition of module viewer
62 virtual void viewManagers(QStringList& theList) const;
64 /// \brief The method is called on selection changed event
65 virtual void selectionChanged();
67 //--- XGUI connector interface -----
69 virtual QAction* addFeature(const QString& theWBName, const QString& theTBName,
70 const QString& theId, const QString& theTitle,
71 const QString& theTip, const QIcon& theIcon,
72 const QKeySequence& theKeys/* = QKeySequence()*/,
73 bool isCheckable /*= false*/, const bool isAddSeparator/* = false*/,
74 const QString& theStatusTip);
76 //! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action
77 virtual QAction* addFeature(const QString& theWBName,
78 const ActionInfo& theInfo, const bool isAddSeparator);
80 /// Add a nested feature
81 /// \param theWBName a workbench name
82 /// \param theInfo the action parameters
83 /// \param theNestedActions a list of nested actions
84 virtual QAction* addFeatureOfNested(const QString& theWBName,
85 const ActionInfo& theInfo,
86 const QList<QAction*>& theNestedActions);
88 //! Returns true if the feature action is a nested action, in other words,
89 //! it is created by addNestedFeature().
90 //! \param theAction - an action of a feature
91 //! returns boolean result
92 virtual bool isFeatureOfNested(const QAction* theAction);
94 virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle,
95 const QString& theTip, const QIcon& theIcon,
96 const QKeySequence& theKeys, bool isCheckable,
97 const char* theMenuSourceText,
98 const int theMenuPosition = 10);
100 virtual void addDesktopMenuSeparator(const char* theMenuSourceText,
101 const int theMenuPosition = 10);
103 /// Add an action to a tool bar
104 /// \param theAction an ation to add
105 /// \param theToolBarTitle a name of tool bar
106 virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle );
108 /// Creates menu/tool bar actions for loaded features stored in the menu manager
109 virtual void createFeatureActions();
111 virtual QMainWindow* desktop() const;
113 //! Stores XML information for the feature kind
114 //! \param theFeatureId a feature kind
115 //! \param theMessage a container of the feature XML properties
116 virtual void setFeatureInfo(const QString& theFeatureId,
117 const std::shared_ptr<Config_FeatureMessage>& theMessage);
119 //! Returns XML information for the feature kind
120 //! \param theFeatureId a feature kind
121 //! \return theMessage a container of the feature XML properties
122 virtual std::shared_ptr<Config_FeatureMessage> featureInfo(const QString& theFeatureId);
124 //! Returns interface to Salome viewer
125 virtual ModuleBase_IViewer* viewer() const
127 return myProxyViewer;
130 //! Returns list of defined actions (just by SHAPER module)
131 virtual QList<QAction*> commandList() const;
133 /// Redefinition of virtual function.
134 /// \param theClient name of pop-up client
135 /// \param theMenu popup menu instance
136 /// \param theTitle menu title.
137 virtual void contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle);
139 /// Redefinition of virtual function for preferences creation.
140 virtual void createPreferences();
142 /// Redefinition of virtual function for preferences changed event.
143 virtual void preferencesChanged(const QString& theSection, const QString& theParam);
145 //! Shows the given text in status bar as a permanent text
146 //! \theInfo a string value
147 //! \theMsecs interval of msec milliseconds when the message will be hidden, if -1, it stays.
148 // If 0, default value is used, it is 3000
149 virtual void putInfo(const QString& theInfo, const int theMSecs = 0);
151 /// \return Workshop class instance
152 XGUI_Workshop* workshop() const { return myWorkshop; }
154 /// \brief Set flag about opened document state
155 void setIsOpened(bool theOpened) { myIsOpened = theOpened; }
157 virtual void updateModuleVisibilityState();
160 QIntList shaperActions() const { return myActionsList; }
161 QMap<QString, QIntList> shaperToolbars() const { return myToolbars; }
165 /// \brief The method is redefined to connect to the study viewer before the data
166 /// model is filled by opened file. This file open will flush redisplay signals for,
167 /// objects which should be visualized
168 //virtual void connectToStudy(CAM_Study* theStudy);
170 /// \brief The method is called on the module activation
171 /// \param theStudy current study
172 virtual bool activateModule(SUIT_Study* theStudy);
174 /// \brief The method is called on the module activation
175 /// \param theStudy current study
176 virtual bool deactivateModule(SUIT_Study* theStudy);
179 /// Redefinition of virtual function
180 /// \param theMgr view manager
181 virtual void onViewManagerAdded(SUIT_ViewManager* theMgr);
183 /// Redefinition of virtual function
184 /// \param theMgr view manager
185 virtual void onViewManagerRemoved(SUIT_ViewManager* theMgr);
187 /// Set preferences to default
188 void onDefaultPreferences();
190 /// Hide object browser if it was created during loading script
191 void onScriptLoaded();
193 /// Save application functionality with additional processing of aborting the current operation
194 void onSaveDocByShaper();
196 /// Save application functionality with additional processing of aborting the current operation
197 void onSaveAsDocByShaper();
199 /// Obtains the current application and updates its actions
200 void onUpdateCommandStatus();
203 /// Create data model
204 CAM_DataModel* createDataModel();
206 /// Create popup menu manager
207 virtual QtxPopupMgr* popupMgr();
209 /// Abort all operations
210 virtual bool abortAllOperations();
213 void onWhatIs(bool isToggled);
215 void onEditToolbars();
218 /// Create selector for OCC Viewer
219 /// \param theMgr view manager
220 SHAPERGUI_OCCSelector* createSelector(SUIT_ViewManager* theMgr);
222 void registerCommandToolbar(const QString& theToolName, int theCommandId);
224 int getNextCommandId() const;
226 // Update current toolbars
227 void updateToolbars(const QMap<QString, QIntList>& theNewToolbars);
229 void saveToolbarsConfig();
230 void loadToolbarsConfig();
232 /// List of registered nested actions
233 QStringList myNestedActionsList;
235 /// Reference to workshop
236 XGUI_Workshop* myWorkshop;
238 /// OCC viewer selector instance
239 SHAPERGUI_OCCSelector* mySelector;
241 /// Proxy viewer for connection to OCC Viewer in SALOME
242 SHAPERGUI_SalomeViewer* myProxyViewer;
244 /// Map of feature kind to a container of XML properties for the feature
245 QMap<QString, std::shared_ptr<Config_FeatureMessage> > myFeaturesInfo;
247 /// Flag of opened document state
250 // the next parameters should be restored after this module deactivation
252 /// The application value of the preferences parameter
253 bool myIsStorePositions;
255 /// The application value
256 bool myIsEditEnabled;
259 QtxPopupMgr* myPopupMgr;
261 QAction* myWhatIsAction;
263 bool myIsInspectionVisible;
264 QDockWidget* myInspectionPanel;
266 /// List of registered actions
267 QIntList myActionsList;
268 QMap<QString, QIntList> myToolbars;
269 bool myIsToolbarsModified;