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