]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.h
Salome HOME
ee0595b132bb9708b9b73abeefb5d555ea752f2b
[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_DocumentDataModel.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 <GeomAPI_ICustomPrs.h>
16
17 #include <Events_Listener.h>
18
19 //#include <StdSelect_FaceFilter.hxx>
20 #include <TopoDS_Shape.hxx>
21 #include <SelectMgr_ListOfFilter.hxx>
22
23 #include <QMap>
24 #include <QMenu>
25 #include <QObject>
26
27 #include <string>
28
29 #include <memory>
30
31 class ModuleBase_Operation;
32 class ModuleBase_IViewWindow;
33 class PartSet_MenuMgr;
34 class PartSet_SketcherMgr;
35
36 class QAction;
37
38 /**
39 * \ingroup Modules
40 * Implementation of Partset module
41 */
42 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
43 {
44 Q_OBJECT
45
46 /// Enumeration to specify the restart operation properties.
47 enum RestartingMode {
48   RM_None, /// the operation should not be restarted
49   RM_Forbided, /// the operation should not be restarted after there is no active widget
50   RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
51   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
52 };
53
54 public:
55
56   /// Constructor
57   /// \param theWshop a pointer to a workshop
58   PartSet_Module(ModuleBase_IWorkshop* theWshop);
59   virtual ~PartSet_Module();
60
61   // Add default selection filters of the module to the current viewer
62   virtual void activateSelectionFilters();
63   // Remove default selection filters of the module from the current viewer
64   virtual void deactivateSelectionFilters();
65
66   /// Creates custom widgets for property panel
67   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
68                                                      Config_WidgetAPI* theWidgetApi, std::string theParentId);
69
70   /// Call back forlast tuning of property panel before operation performance
71   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
72
73   /// Realizes some functionality by an operation start
74   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
75   /// \param theOperation a started operation
76   virtual void onOperationStarted(ModuleBase_Operation* theOperation);
77
78   /// Realizes some functionality by an operation commit
79   /// Restarts sketcher operation automatically of it is necessary
80   /// \param theOperation a committed operation
81   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
82
83   /// Realizes some functionality by an operation abort
84   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
85   /// \param theOperation an aborted operation
86   virtual void onOperationAborted(ModuleBase_Operation* theOperation);
87
88   /// Realizes some functionality by an operation stop
89   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
90   /// \param theOperation a stopped operation
91   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
92
93   /// Returns current operation
94   virtual ModuleBase_Operation* currentOperation() const;
95
96   /// Returns True if there are available Undos and the sketch manager allows undo
97   /// \return the boolean result
98   virtual bool canUndo() const;
99
100   //! Returns True if there are available Redos and the sketch manager allows redo
101   /// \return the boolean result
102   virtual bool canRedo() const;
103
104   /// Returns True if the current operation can be committed. Asks the sketch manager.
105   /// \return a boolean value
106   virtual bool canCommitOperation() const;
107
108   /// Returns whether the object can be displayed at the bounds of the active operation.
109   /// Display only current operation results for usual operation and ask the sketcher manager
110   /// if it is a sketch operation
111   /// \param theObject a model object
112   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
113
114   /// Returns true if selection for the object can be activate.
115   /// For sketch operation allow the selection activation if the operation is edit, for other
116   /// operation uses the default result
117   /// \param theObject a model object
118   virtual bool canActivateSelection(const ObjectPtr& theObject) const;
119
120   /// Add menu atems for object browser into the given menu
121   /// \param theMenu a popup menu to be shown in the object browser
122   virtual void addObjectBrowserMenu(QMenu* theMenu) const;
123
124   /// Add menu atems for viewer into the given menu
125   /// \param theMenu a popup menu to be shown in the viewer
126   /// \param theStdActions a map of standard actions
127   /// \return true if items are added and there is no necessity to provide standard menu
128   virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
129
130   /// Returns a list of modes, where the AIS objects should be activated
131   /// \param theModes a list of modes
132   virtual void activeSelectionModes(QIntList& theModes);
133
134   /// Returns whether the mouse enter the viewer's window
135   /// \return true if items are added and there is no necessity to provide standard menu
136   bool isMouseOverWindow();
137
138   PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
139
140   /// Returns data model object for representation of data tree in Object browser
141   virtual ModuleBase_IDocumentDataModel* dataModel() const { return myDataModel; }
142
143   /// Event Listener method
144   /// \param theMessage an event message
145   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
146
147   /// Set the object with the object results are customized
148   /// \param theFeature a feature
149   void setCustomized(const FeaturePtr& theFeature);
150
151   /** Update the object presentable properties such as color, lines width and other
152   * If the object is result with the color attribute value set, it is used,
153   * otherwise the customize is applyed to the object's feature if it is a custom prs
154   * \param theObject an object instance
155   * \return the true state if there is changes and the presentation is customized
156   */
157   virtual bool customizeObject(ObjectPtr theObject);
158
159   /// This method is called on object browser creation for customisation of module specific features
160   /// \param theObjectBrowser a pinter on Object Browser widget
161   virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
162
163 public slots:
164   /// SLOT, that is called by no more widget signal emitted by property panel
165   /// Set a specific flag to restart the sketcher operation
166   void onNoMoreWidgets();
167
168   /// Redefines the parent method in order to customize the next case:
169   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
170   /// the operation should be always aborted.
171   virtual void onFeatureTriggered();
172
173   /// Slolt called on object display
174   /// \param theObject a data object
175   /// \param theAIS a presentation object
176   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
177
178   /// Called on transformation in current viewer
179   /// \param theTrsfType type of tranformation
180   void onViewTransformed(int theTrsfType = 2);
181
182 protected slots:
183   /// Called when previous operation is finished
184   virtual void onSelectionChanged();
185
186   /// SLOT, that is called by key release in the viewer.
187   /// \param theWnd a view window
188   /// \param theEvent the key event
189   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
190
191   /// SLOT, that is called by enter key released
192   /// Set a specific type of restarting the current operation
193   void onEnterReleased();
194
195   /// SLOT, that is called by the current operation filling with the preselection.
196   /// It commits the operation of it is can be committed
197   void onOperationActivatedByPreselection();
198
199  protected:
200   /// Register validators for this module
201   virtual void registerValidators();
202
203   /// Register selection filters for this module
204   virtual void registerFilters();
205
206   /// Register properties of this module
207   virtual void registerProperties();
208
209  private slots:
210    /// Processing of vertex selected
211    void onVertexSelected();
212
213    void onTreeViewDoubleClick(const QModelIndex&);
214
215  private:
216   /// Breaks sequense of automatically resterted operations
217   void breakOperationSequence();
218
219   //! Delete features
220   virtual bool deleteObjects();
221
222  private:
223    QString myLastOperationId;
224    FeaturePtr myLastFeature;
225
226    // Automatical restarting mode flag
227    RestartingMode myRestartingMode;
228
229   SelectMgr_ListOfFilter mySelectionFilters;
230
231   PartSet_SketcherMgr* mySketchMgr;
232   PartSet_MenuMgr* myMenuMgr;
233   /// A default custom presentation, which is used for references objects of started operation
234   GeomCustomPrsPtr myCustomPrs;
235
236   int myVisualLayerId;
237
238   PartSet_DocumentDataModel* myDataModel;
239 };
240
241 #endif