]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.h
Salome HOME
Imrove multi-selector control to provide items multi-selection. Activate/deactivate...
[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   /// Activate custom presentation for the object
185   /// \param theFeature a feature instance
186   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
187   /// \param theUpdateViewer the parameter whether the viewer should be update immediately
188   virtual void activateCustomPrs(const FeaturePtr& theFeature,
189                                  const ModuleBase_CustomizeFlag& theFlag,
190                                  const bool theUpdateViewer);
191
192   /// Deactivate custom presentation for the object
193   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
194   /// \param theUpdateViewer the parameter whether the viewer should be update immediately
195   virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
196                                    const bool theUpdateViewer);
197
198   /// Update the object presentable properties such as color, lines width and other
199   /// If the object is result with the color attribute value set, it is used,
200   /// otherwise the customize is applyed to the object's feature if it is a custom prs
201   /// \param theObject an object instance
202   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
203   /// should be updated(e.g. only highlighted elements)
204   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
205   /// \returns true if the object is modified
206   virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
207                                const bool theUpdateViewer);
208
209   /// This method is called on object browser creation for customisation of module specific features
210   /// \param theObjectBrowser a pinter on Object Browser widget
211   virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
212
213   /// Returns the viewer Z layer
214   int getVisualLayerId() const { return myVisualLayerId; }
215
216   //! Returns data object by AIS
217   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
218
219   /// Update state of pop-up menu items in viewer
220   /// \param theStdActions - a map of standard actions
221   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions); 
222
223   //! Returns the feature error if the current state of the feature in the module is not correct
224   //! If the feature is correct, it returns an empty value
225   //! \return string value
226   virtual QString getFeatureError(const FeaturePtr& theFeature);
227
228   /// Returns list of granted operation indices
229   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
230
231   /// Validates the current operation and send the state change to sketch manager
232   /// \param thePreviousState the previous widget value state
233   virtual void widgetStateChanged(int thePreviousState);
234
235   /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
236   /// \param thePreviousAttributeID an index of the previous active attribute
237   virtual bool processEnter(const std::string& thePreviousAttributeID);
238
239   /// Performs some GUI actions after an operation transaction is opened
240   /// Default realization is empty
241   virtual void beforeOperationStarted(ModuleBase_Operation* theOperation);
242
243   /// Performs some GUI actions before an operation transaction is stopped
244   /// Default realization is empty
245   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
246
247 public slots:
248   /// Redefines the parent method in order to customize the next case:
249   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
250   /// the operation should be always aborted.
251   virtual void onFeatureTriggered();
252
253   /// Slolt called on object display
254   /// \param theObject a data object
255   /// \param theAIS a presentation object
256   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
257
258   /// Slot called on before object erase
259   /// \param theObject a data object
260   /// \param theAIS a presentation object
261   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
262
263   /// Called on transformation in current viewer
264   /// \param theTrsfType type of tranformation
265   void onViewTransformed(int theTrsfType = 2);
266
267 protected slots:
268   /// Called when previous operation is finished
269   virtual void onSelectionChanged();
270
271   /// SLOT, that is called by key release in the viewer.
272   /// \param theWnd a view window
273   /// \param theEvent the key event
274   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
275
276   /// SLOT, that is called by the current operation filling with the preselection.
277   /// It commits the operation of it is can be committed
278   void onOperationActivatedByPreselection();
279
280   /// A slot called on view window creation
281   void onViewCreated(ModuleBase_IViewWindow*);
282
283   /// A slot to change property panel title on change of boolean operation type
284   /// \param theOperation the operation type
285   void onBooleanOperationChange(int theOperation);
286
287 protected:
288   /// Register validators for this module
289   virtual void registerValidators();
290
291   /// Register selection filters for this module
292   virtual void registerFilters();
293
294   /// Register properties of this module
295   virtual void registerProperties();
296
297   /// Connects or disconnects to the value changed signal of the property panel widgets
298   /// \param theWidget a property contol widget
299   /// \param isToConnect a boolean value whether connect or disconnect
300   virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
301
302  private slots:
303    void onTreeViewDoubleClick(const QModelIndex&);
304
305    void onActiveDocPopup(const QPoint&);
306
307  private:
308
309   //! Delete features
310   virtual bool deleteObjects();
311
312  private:
313   SelectMgr_ListOfFilter mySelectionFilters;
314
315   PartSet_SketcherMgr* mySketchMgr;
316   PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
317   PartSet_MenuMgr* myMenuMgr;
318   /// A default custom presentation, which is used for references objects of started operation
319   PartSet_CustomPrs* myCustomPrs;
320   int myVisualLayerId;
321
322   /// backup of the visible state to restore them by operation stop
323   QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
324
325   QModelIndex aActivePartIndex;
326 };
327
328 #endif