]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.h
Salome HOME
7135b7c9ba1695e8ede67ef25c6a5528afd99ead
[modules/shaper.git] / src / PartSet / PartSet_Module.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #ifndef PartSet_Module_H
4 #define PartSet_Module_H
5
6 #include "PartSet.h"
7 #include "PartSet_Tools.h"
8
9 #include <ModuleBase_IModule.h>
10 #include <ModuleBase_Definitions.h>
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_Attribute.h>
13 #include <ModelAPI_CompositeFeature.h>
14
15 #include <Events_Listener.h>
16
17 //#include <StdSelect_FaceFilter.hxx>
18 #include <TopoDS_Shape.hxx>
19 #include <SelectMgr_ListOfFilter.hxx>
20
21 #include <QMap>
22 #include <QMenu>
23 #include <QObject>
24 #include <QModelIndex>
25
26 #include <string>
27
28 #include <memory>
29
30 class ModuleBase_Operation;
31 class ModuleBase_IViewWindow;
32 class PartSet_MenuMgr;
33 class PartSet_CustomPrs;
34 class PartSet_SketcherMgr;
35 class PartSet_SketcherReetntrantMgr;
36
37 class QAction;
38
39 /**
40 * \ingroup Modules
41 * Implementation of Partset module
42 */
43 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
44 {
45 Q_OBJECT
46
47 /// Enumeration to specify the restart operation properties.
48 enum RestartingMode {
49   RM_None, /// the operation should not be restarted
50   RM_Forbided, /// the operation should not be restarted after there is no active widget
51   RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
52   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
53 };
54
55 public:
56
57   /// Constructor
58   /// \param theWshop a pointer to a workshop
59   PartSet_Module(ModuleBase_IWorkshop* theWshop);
60   virtual ~PartSet_Module();
61
62   // Add default selection filters of the module to the current viewer
63   virtual void activateSelectionFilters();
64   // Remove default selection filters of the module from the current viewer
65   virtual void deactivateSelectionFilters();
66
67   /// Creates custom widgets for property panel
68   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
69                                                      Config_WidgetAPI* theWidgetApi, std::string theParentId);
70
71   /// Returns the active widget, by default it is the property panel active widget
72   /// If the internal edit operation is started, this is the first widget of the operation
73   virtual ModuleBase_ModelWidget* activeWidget() const;
74
75   /// Call back forlast tuning of property panel before operation performance
76   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
77
78   /// Creates an operation and send it to loop
79   /// \param theCmdId the operation name
80   virtual void launchOperation(const QString& theCmdId);
81
82   /// Realizes some functionality by an operation start
83   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
84   /// Activate the operation presentation
85   /// \param theOperation a started operation
86   virtual void operationStarted(ModuleBase_Operation* theOperation);
87
88   /// Realizes some functionality by an operation resume
89   /// Activate the operation presentation
90   /// \param theOperation a resumed operation
91   virtual void operationResumed(ModuleBase_Operation* theOperation);
92
93   /// Realizes some functionality by an operation commit
94   /// Restarts sketcher operation automatically of it is necessary
95   /// \param theOperation a committed operation
96   virtual void operationCommitted(ModuleBase_Operation* theOperation);
97
98   /// Realizes some functionality by an operation abort
99   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
100   /// \param theOperation an aborted operation
101   virtual void operationAborted(ModuleBase_Operation* theOperation);
102
103   /// Realizes some functionality by an operation stop
104   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
105   /// \param theOperation a stopped operation
106   virtual void operationStopped(ModuleBase_Operation* theOperation);
107
108   /// Returns current operation
109   virtual ModuleBase_Operation* currentOperation() const;
110
111   /// Returns True if there are available Undos and the sketch manager allows undo
112   /// \return the boolean result
113   virtual bool canUndo() const;
114
115   //! Returns True if there are available Redos and the sketch manager allows redo
116   /// \return the boolean result
117   virtual bool canRedo() const;
118
119   /// Returnas true if the action can be applyed to the object
120   /// \param theObject a checked object
121   /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
122   /// \return the a booean result
123   virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
124
125   /// Returns True if the current operation can be committed. Asks the sketch manager.
126   /// \return a boolean value
127   //virtual bool canCommitOperation() const;
128
129   /// Returns whether the object can be erased at the bounds of the active operation.
130   /// The sub-objects of the current operation can not be erased
131   /// \param theObject a model object
132   virtual bool canEraseObject(const ObjectPtr& theObject) const;
133
134   /// Returns whether the object can be displayed at the bounds of the active operation.
135   /// Display only current operation results for usual operation and ask the sketcher manager
136   /// if it is a sketch operation
137   /// \param theObject a model object
138   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
139
140   /// Returns true if selection for the object can be activate.
141   /// For sketch operation allow the selection activation if the operation is edit, for other
142   /// operation uses the default result
143   /// \param theObject a model object
144   virtual bool canActivateSelection(const ObjectPtr& theObject) const;
145
146   /// Add menu atems for object browser into the given menu
147   /// \param theMenu a popup menu to be shown in the object browser
148   virtual void addObjectBrowserMenu(QMenu* theMenu) const;
149
150   /// Add menu atems for viewer into the given menu
151   /// \param theMenu a popup menu to be shown in the viewer
152   /// \param theStdActions a map of standard actions
153   /// \return true if items are added and there is no necessity to provide standard menu
154   virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
155
156   /// Returns a list of modes, where the AIS objects should be activated
157   /// \param theModes a list of modes
158   virtual void activeSelectionModes(QIntList& theModes);
159
160   /// Returns whether the mouse enter the viewer's window
161   /// \return true if items are added and there is no necessity to provide standard menu
162   bool isMouseOverWindow();
163
164   /// Returns sketch manager object
165   PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
166
167   /// Returns sketch reentrant manager
168   PartSet_SketcherReetntrantMgr* sketchReentranceMgr() { return mySketchReentrantMgr; }
169
170   /// Performs functionality on closing document
171   virtual void closeDocument();
172
173   /// Clears specific presentations in the viewer
174   virtual void clearViewer();
175
176   /// Event Listener method
177   /// \param theMessage an event message
178   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
179
180   /// Set the object with the object results are customized
181   /// \param theFeature a feature
182   void setCustomized(const FeaturePtr& theFeature);
183
184   /** Update the object presentable properties such as color, lines width and other
185   * If the object is result with the color attribute value set, it is used,
186   * otherwise the customize is applyed to the object's feature if it is a custom prs
187   * \param theObject an object instance
188   * \param theFlag a flag of level of customization, which means that only part of sub-elements
189   * should be updated(e.g. only highlighted elements)
190   * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
191   * \returns true if the object is modified
192   */
193   virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
194                                const bool theUpdateViewer);
195
196   /// This method is called on object browser creation for customisation of module specific features
197   /// \param theObjectBrowser a pinter on Object Browser widget
198   virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
199
200   /// Returns the viewer Z layer
201   int getVisualLayerId() const { return myVisualLayerId; }
202
203   //! Returns data object by AIS
204   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
205
206   /// Update state of pop-up menu items in viewer
207   /// \param theStdActions - a map of standard actions
208   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions); 
209
210   //! Returns the feature error if the current state of the feature in the module is not correct
211   //! If the feature is correct, it returns an empty value
212   //! \return string value
213   virtual QString getFeatureError(const FeaturePtr& theFeature);
214
215   /// Returns list of granted operation indices
216   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
217
218   /// Validates the current operation and send the state change to sketch manager
219   /// \param thePreviousState the previous widget value state
220   virtual void widgetStateChanged(int thePreviousState);
221
222   /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
223   /// \param thePreviousAttributeID an index of the previous active attribute
224   virtual bool processEnter(const std::string& thePreviousAttributeID);
225
226   /// Performs some GUI actions after an operation transaction is opened
227   /// Default realization is empty
228   virtual void beforeOperationStarted(ModuleBase_Operation* theOperation);
229
230   /// Performs some GUI actions before an operation transaction is stopped
231   /// Default realization is empty
232   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
233
234 public slots:
235   /// Redefines the parent method in order to customize the next case:
236   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
237   /// the operation should be always aborted.
238   virtual void onFeatureTriggered();
239
240   /// Slolt called on object display
241   /// \param theObject a data object
242   /// \param theAIS a presentation object
243   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
244
245   /// Slot called on before object erase
246   /// \param theObject a data object
247   /// \param theAIS a presentation object
248   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
249
250   /// Called on transformation in current viewer
251   /// \param theTrsfType type of tranformation
252   void onViewTransformed(int theTrsfType = 2);
253
254 protected slots:
255   /// Called when previous operation is finished
256   virtual void onSelectionChanged();
257
258   /// SLOT, that is called by key release in the viewer.
259   /// \param theWnd a view window
260   /// \param theEvent the key event
261   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
262
263   /// SLOT, that is called by the current operation filling with the preselection.
264   /// It commits the operation of it is can be committed
265   void onOperationActivatedByPreselection();
266
267   /// A slot called on view window creation
268   void onViewCreated(ModuleBase_IViewWindow*);
269
270   /// A slot to change property panel title on change of boolean operation type
271   /// \param theOperation the operation type
272   void onBooleanOperationChange(int theOperation);
273
274 protected:
275   /// Register validators for this module
276   virtual void registerValidators();
277
278   /// Register selection filters for this module
279   virtual void registerFilters();
280
281   /// Register properties of this module
282   virtual void registerProperties();
283
284   /// Connects or disconnects to the value changed signal of the property panel widgets
285   /// \param theWidget a property contol widget
286   /// \param isToConnect a boolean value whether connect or disconnect
287   virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
288
289  private slots:
290    void onTreeViewDoubleClick(const QModelIndex&);
291
292    void onActiveDocPopup(const QPoint&);
293
294  private:
295
296   //! Delete features
297   virtual bool deleteObjects();
298
299  private:
300   SelectMgr_ListOfFilter mySelectionFilters;
301
302   PartSet_SketcherMgr* mySketchMgr;
303   PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
304   PartSet_MenuMgr* myMenuMgr;
305   /// A default custom presentation, which is used for references objects of started operation
306   PartSet_CustomPrs* myCustomPrs;
307   int myVisualLayerId;
308
309   /// backup of the visible state to restore them by operation stop
310   QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
311
312   QModelIndex aActivePartIndex;
313 };
314
315 #endif