]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.h
Salome HOME
ecb1dffdcba1b2ad6df7ee806a4d37f69f03f1ba
[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 <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
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   /// Realizes some functionality by an operation start
73   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
74   /// \param theOperation a started operation
75   virtual void onOperationStarted(ModuleBase_Operation* theOperation);
76
77   /// Realizes some functionality by an operation commit
78   /// Restarts sketcher operation automatically of it is necessary
79   /// \param theOperation a committed operation
80   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
81
82   /// Realizes some functionality by an operation abort
83   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
84   /// \param theOperation an aborted operation
85   virtual void onOperationAborted(ModuleBase_Operation* theOperation);
86
87   /// Realizes some functionality by an operation stop
88   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
89   /// \param theOperation a stopped operation
90   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
91
92   /// Returns current operation
93   virtual ModuleBase_Operation* currentOperation() const;
94
95   /// Returns True if there are available Undos and the sketch manager allows undo
96   /// \return the boolean result
97   virtual bool canUndo() const;
98
99   //! Returns True if there are available Redos and the sketch manager allows redo
100   /// \return the boolean result
101   virtual bool canRedo() const;
102
103   /// Returns True if the current operation can be committed. Asks the sketch manager.
104   /// \return a boolean value
105   virtual bool canCommitOperation() const;
106
107   /// Returns whether the object can be displayed at the bounds of the active operation.
108   /// Display only current operation results for usual operation and ask the sketcher manager
109   /// if it is a sketch operation
110   /// \param theObject a model object
111   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
112
113   /// Returns true if selection for the object can be activate.
114   /// For sketch operation allow the selection activation if the operation is edit, for other
115   /// operation uses the default result
116   /// \param theObject a model object
117   virtual bool canActivateSelection(const ObjectPtr& theObject) const;
118
119   /// Add menu atems for object browser into the given menu
120   /// \param theMenu a popup menu to be shown in the object browser
121   virtual void addObjectBrowserMenu(QMenu* theMenu) const;
122
123   /// Add menu atems for viewer into the given menu
124   /// \param theMenu a popup menu to be shown in the viewer
125   /// \param theStdActions a map of standard actions
126   /// \return true if items are added and there is no necessity to provide standard menu
127   virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
128
129   /// Returns a list of modes, where the AIS objects should be activated
130   /// \param theModes a list of modes
131   virtual void activeSelectionModes(QIntList& theModes);
132
133   /// Returns whether the mouse enter the viewer's window
134   /// \return true if items are added and there is no necessity to provide standard menu
135   bool isMouseOverWindow();
136
137   PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
138
139   /// Returns data model object for representation of data tree in Object browser
140   virtual ModuleBase_IDocumentDataModel* dataModel() const { return myDataModel; }
141
142   /// Event Listener method
143   /// \param theMessage an event message
144   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
145
146   /// Set the object with the object results are customized
147   /// \param theFeature a feature
148   void setCustomized(const FeaturePtr& theFeature);
149
150   /** Update the object presentable properties such as color, lines width and other
151   * If the object is result with the color attribute value set, it is used,
152   * otherwise the customize is applyed to the object's feature if it is a custom prs
153   * \param theObject an object instance
154   */
155   virtual void customizeObject(ObjectPtr theObject);
156
157   /// This method is called on object browser creation for customisation of module specific features
158   /// \param theObjectBrowser a pinter on Object Browser widget
159   virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
160
161   /// Returns the viewer Z layer
162   int getVisualLayerId() const { return myVisualLayerId; }
163
164   //! Returns data object by AIS
165   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
166
167 public slots:
168   /// SLOT, that is called by no more widget signal emitted by property panel
169   /// Set a specific flag to restart the sketcher operation
170   void onNoMoreWidgets();
171
172   /// Redefines the parent method in order to customize the next case:
173   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
174   /// the operation should be always aborted.
175   virtual void onFeatureTriggered();
176
177   /// Slolt called on object display
178   /// \param theObject a data object
179   /// \param theAIS a presentation object
180   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
181
182   /// Called on transformation in current viewer
183   /// \param theTrsfType type of tranformation
184   void onViewTransformed(int theTrsfType = 2);
185
186 protected slots:
187   /// Called when previous operation is finished
188   virtual void onSelectionChanged();
189
190   /// SLOT, that is called by key release in the viewer.
191   /// \param theWnd a view window
192   /// \param theEvent the key event
193   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
194
195   /// SLOT, that is called by enter key released
196   /// Set a specific type of restarting the current operation
197   void onEnterReleased();
198
199   /// SLOT, that is called by the current operation filling with the preselection.
200   /// It commits the operation of it is can be committed
201   void onOperationActivatedByPreselection();
202
203   /// A slot called on view window creation
204   void onViewCreated(ModuleBase_IViewWindow*);
205
206  protected:
207   /// Register validators for this module
208   virtual void registerValidators();
209
210   /// Register selection filters for this module
211   virtual void registerFilters();
212
213   /// Register properties of this module
214   virtual void registerProperties();
215
216  private slots:
217    /// Processing of vertex selected
218    void onVertexSelected();
219
220    void onTreeViewDoubleClick(const QModelIndex&);
221
222  private:
223   /// Breaks sequense of automatically resterted operations
224   void breakOperationSequence();
225
226   //! Delete features
227   virtual bool deleteObjects();
228
229  private:
230    QString myLastOperationId;
231    FeaturePtr myLastFeature;
232
233    // Automatical restarting mode flag
234    RestartingMode myRestartingMode;
235
236   SelectMgr_ListOfFilter mySelectionFilters;
237
238   PartSet_SketcherMgr* mySketchMgr;
239   PartSet_MenuMgr* myMenuMgr;
240   /// A default custom presentation, which is used for references objects of started operation
241   PartSet_CustomPrs* myCustomPrs;
242   int myVisualLayerId;
243
244   PartSet_DocumentDataModel* myDataModel;
245 };
246
247 #endif