1 // Copyright (C) 2014-2024 CEA, EDF
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 email : webmaster.salome@opencascade.com
23 #include "SHAPER_SHAPERGUI.h"
24 #include "SHAPERGUI_SalomeViewer.h"
26 #include <LightApp_Module.h>
27 #include <XGUI_SalomeConnector.h>
29 #include <ModuleBase_ActionInfo.h>
35 class SHAPERGUI_OCCSelector;
36 class OCCViewer_Viewer;
39 class ModuleBase_Operation;
43 * An implementation of SALOME connector class for implementation of
44 * XGUI functionality as a module of SALOME
46 class SHAPERGUI_EXPORT SHAPERGUI : public LightApp_Module, public XGUI_SalomeConnector
53 //----- LightAPP_Module interface ---------------
55 /// \brief Initializing of the module
56 /// \param theApp application instance
57 virtual void initialize(CAM_Application* theApp);
59 /// \brief Definition of module standard windows
60 virtual void windows(QMap<int, int>& theWndMap) const;
62 /// \brief Definition of module viewer
63 virtual void viewManagers(QStringList& theList) const;
65 /// \brief The method is called on selection changed event
66 virtual void selectionChanged();
68 //--- XGUI connector interface -----
70 virtual QAction* addFeature(const QString& theWBName, const QString& theTBName,
71 const QString& theId, const QString& theTitle,
72 const QString& theTip, const QIcon& theIcon,
73 const QKeySequence& theKeys/* = QKeySequence()*/,
74 bool isCheckable /*= false*/, const bool isAddSeparator/* = false*/,
75 const QString& theStatusTip);
77 //! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action
78 virtual QAction* addFeature(const QString& theWBName,
79 const ActionInfo& theInfo, const bool isAddSeparator);
81 /// Add a nested feature
82 /// \param theWBName a workbench name
83 /// \param theInfo the action parameters
84 /// \param theNestedActions a list of nested actions
85 virtual QAction* addFeatureOfNested(const QString& theWBName,
86 const ActionInfo& theInfo,
87 const QList<QAction*>& theNestedActions);
89 //! Returns true if the feature action is a nested action, in other words,
90 //! it is created by addNestedFeature().
91 //! \param theAction - an action of a feature
92 //! returns boolean result
93 virtual bool isFeatureOfNested(const QAction* theAction);
95 virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle,
96 const QString& theTip, const QIcon& theIcon,
97 const QKeySequence& theKeys, bool isCheckable,
98 const char* theMenuSourceText, const QString& theSubMenu = QString(),
99 const int theMenuPosition = 10,
100 const int theSuibMenuPosition = -1) Standard_OVERRIDE;
102 virtual void addDesktopMenuSeparator(const char* theMenuSourceText,
103 const int theMenuPosition = 10);
105 /// Add an action to a tool bar
106 /// \param theAction an ation to add
107 /// \param theToolBarTitle a name of tool bar
108 virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle );
110 /// Creates menu/tool bar actions for loaded features stored in the menu manager
111 virtual void createFeatureActions();
113 virtual QMainWindow* desktop() const;
115 //! Stores XML information for the feature kind
116 //! \param theFeatureId a feature kind
117 //! \param theMessage a container of the feature XML properties
118 virtual void setFeatureInfo(const QString& theFeatureId,
119 const std::shared_ptr<Config_FeatureMessage>& theMessage);
121 //! Returns XML information for the feature kind
122 //! \param theFeatureId a feature kind
123 //! \return theMessage a container of the feature XML properties
124 virtual std::shared_ptr<Config_FeatureMessage> featureInfo(const QString& theFeatureId);
126 //! Returns interface to Salome viewer
127 virtual ModuleBase_IViewer* viewer() const
129 return myProxyViewer;
132 //! Returns list of defined actions (just by SHAPER module)
133 virtual QList<QAction*> commandList() const;
135 /// Redefinition of virtual function.
136 /// \param theClient name of pop-up client
137 /// \param theMenu popup menu instance
138 /// \param theTitle menu title.
139 virtual void contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle);
141 /// Redefinition of virtual function for preferences creation.
142 virtual void createPreferences();
144 /// Redefinition of virtual function for preferences changed event.
145 virtual void preferencesChanged(const QString& theSection, const QString& theParam);
147 //! Shows the given text in status bar as a permanent text
148 //! \theInfo a string value
149 //! \theMsecs interval of msec milliseconds when the message will be hidden, if -1, it stays.
150 // If 0, default value is used, it is 3000
151 virtual void putInfo(const QString& theInfo, const int theMSecs = 0);
153 /// \return Workshop class instance
154 XGUI_Workshop* workshop() const { return myWorkshop; }
156 /// \brief Set flag about opened document state
157 void setIsOpened(bool theOpened) { myIsOpened = theOpened; }
159 virtual void updateModuleVisibilityState();
161 /// Returns list of the module commands
162 QIntList shaperActions() const { return myActionsList; }
164 /// Returns structure of tool bars
165 QMap<QString, QIntList> shaperToolbars() const { return myToolbars; }
167 /// Returns free commands which are not in toolbars in the module
168 QIntList getFreeCommands() const;
170 /// Returns structure of default tool bars
171 QMap<QString, QIntList> defaultToolbars() const
172 { return (myDefaultToolbars.size() == 0)? myToolbars : myDefaultToolbars; }
174 void resetToolbars();
176 void publishToStudy();
178 virtual void updateInfoPanel();
181 /// \brief The method is redefined to connect to the study viewer before the data
182 /// model is filled by opened file. This file open will flush redisplay signals for,
183 /// objects which should be visualized
184 //virtual void connectToStudy(CAM_Study* theStudy);
186 /// \brief The method is called on the module activation
187 /// \param theStudy current study
188 virtual bool activateModule(SUIT_Study* theStudy);
190 /// \brief The method is called on the module activation
191 /// \param theStudy current study
192 virtual bool deactivateModule(SUIT_Study* theStudy);
195 /// Redefinition of virtual function
196 /// \param theMgr view manager
197 virtual void onViewManagerAdded(SUIT_ViewManager* theMgr);
199 /// Redefinition of virtual function
200 /// \param theMgr view manager
201 virtual void onViewManagerRemoved(SUIT_ViewManager* theMgr);
203 /// Set preferences to default
204 void onDefaultPreferences();
206 /// Hide object browser if it was created during loading script
207 void onScriptLoaded();
209 /// Save application functionality with additional processing of aborting the current operation
210 void onSaveDocByShaper();
212 /// Save application functionality with additional processing of aborting the current operation
213 void onSaveAsDocByShaper();
215 /// Obtains the current application and updates its actions
216 void onUpdateCommandStatus();
218 /// \brief The method is called on any GUI action
219 virtual void logShaperGUIEvent();
222 /// Create data model
223 CAM_DataModel* createDataModel();
225 /// Create popup menu manager
226 virtual QtxPopupMgr* popupMgr();
228 /// Abort all operations
229 virtual bool abortAllOperations();
232 void onWhatIs(bool isToggled);
234 void onEditToolbars();
236 void onOperationCommitted(ModuleBase_Operation*);
237 void onOperationAborted(ModuleBase_Operation*);
240 /// Create selector for OCC Viewer
241 /// \param theMgr view manager
242 SHAPERGUI_OCCSelector* createSelector(SUIT_ViewManager* theMgr);
244 void registerCommandToolbar(const QString& theToolName, int theCommandId);
246 int getNextCommandId() const;
248 // Update current toolbars
249 void updateToolbars(const QMap<QString, QIntList>& theNewToolbars);
251 void saveToolbarsConfig();
252 void loadToolbarsConfig();
254 //! Fill Info Panel in Part set mode
255 void fillPartSetInfoPanel(QtxInfoPanel* theInfoPanel);
257 //! Fill Info Panel in Part mode
258 void fillPartInfoPanel(QtxInfoPanel* theInfoPanel);
260 //! Fill Info Panel in Sketcher mode
261 void fillSketcherInfoPanel(QtxInfoPanel* theInfoPanel);
263 //! Fill Info Panel in Sketcher mode
264 void addActionsToInfoGroup(QtxInfoPanel* theInfoPanel, const QString& theGroup, const QSet<QString>& theActions);
266 void hideInternalWindows();
268 /// List of registered nested actions
269 QStringList myNestedActionsList;
271 /// Reference to workshop
272 XGUI_Workshop* myWorkshop;
274 /// OCC viewer selector instance
275 SHAPERGUI_OCCSelector* mySelector;
277 /// Proxy viewer for connection to OCC Viewer in SALOME
278 SHAPERGUI_SalomeViewer* myProxyViewer;
280 /// Map of feature kind to a container of XML properties for the feature
281 QMap<QString, std::shared_ptr<Config_FeatureMessage> > myFeaturesInfo;
283 /// Flag of opened document state
286 // the next parameter should be restored after this module deactivation
287 /// The application value
288 bool myIsEditEnabled;
291 QtxPopupMgr* myPopupMgr;
293 QAction* myWhatIsAction;
295 bool myIsInspectionVisible;
296 QDockWidget* myInspectionPanel;
297 bool myIsFacesPanelVisible;
299 /// List of registered actions
300 QIntList myActionsList;
301 QMap<QString, QIntList> myToolbars;
302 QMap<QString, QIntList> myDefaultToolbars;
303 bool myIsToolbarsModified;
305 std::vector<int> myOldSelectionColor;
306 Handle(Graphic3d_AspectMarker3d) myHighlightPointAspect;
308 double myAxisArrowRate;