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