Salome HOME
f4b2b978cba07dc2308d29a4f2f6ed2cd4135b71
[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_Filters.h"
8 #include "PartSet_DocumentDataModel.h"
9 #include "PartSet_FilterInfinite.h"
10
11 #include <ModuleBase_IModule.h>
12 #include <ModuleBase_Definitions.h>
13 #include <ModelAPI_Feature.h>
14 #include <ModelAPI_Attribute.h>
15 #include <ModelAPI_CompositeFeature.h>
16
17 #include <Events_Listener.h>
18
19 //#include <StdSelect_FaceFilter.hxx>
20 #include <TopoDS_Shape.hxx>
21
22 #include <QMap>
23 #include <QMenu>
24 #include <QObject>
25
26 #include <string>
27
28 #include <memory>
29
30 class ModuleBase_Operation;
31 class ModuleBase_IViewWindow;
32 class PartSet_MenuMgr;
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   /// Creates custom widgets for property panel
61   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
62                                                      Config_WidgetAPI* theWidgetApi, std::string theParentId);
63
64   /// Call back forlast tuning of property panel before operation performance
65   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
66
67
68   /// Realizes some functionality by an operation start
69   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
70   /// \param theOperation a started operation
71   virtual void onOperationStarted(ModuleBase_Operation* theOperation);
72
73   /// Realizes some functionality by an operation commit
74   /// Restarts sketcher operation automatically of it is necessary
75   /// \param theOperation a committed operation
76   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
77
78   /// Realizes some functionality by an operation abort
79   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
80   /// \param theOperation an aborted operation
81   virtual void onOperationAborted(ModuleBase_Operation* theOperation);
82
83   /// Realizes some functionality by an operation stop
84   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
85   /// \param theOperation a stopped operation
86   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
87
88   /// Returns current operation
89   virtual ModuleBase_Operation* currentOperation() const;
90
91   /// Returns True if there are available Undos and the sketch manager allows undo
92   /// \return the boolean result
93   virtual bool canUndo() const;
94
95   //! Returns True if there are available Redos and the sketch manager allows redo
96   /// \return the boolean result
97   virtual bool canRedo() const;
98
99   /// Returns whether the object can be displayed at the bounds of the active operation.
100   /// Display only current operation results for usual operation and ask the sketcher manager
101   /// if it is a sketch operation
102   /// \param theObject a model object
103   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
104
105   /// Returns true if selection for the object can be activate.
106   /// For sketch operation allow the selection activation if the operation is edit, for other
107   /// operation uses the default result
108   /// \param theObject a model object
109   virtual bool canActivateSelection(const ObjectPtr& theObject) const;
110
111   /// Add menu atems for object browser into the given menu
112   /// \param theMenu a popup menu to be shown in the object browser
113   virtual void addObjectBrowserMenu(QMenu* theMenu) const;
114
115   /// Add menu atems for viewer into the given menu
116   /// \param theMenu a popup menu to be shown in the viewer
117   /// \param theStdActions a map of standard actions
118   /// \return true if items are added and there is no necessity to provide standard menu
119   virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
120
121   /// Returns a list of modes, where the AIS objects should be activated
122   /// \param theModes a list of modes
123   virtual void activeSelectionModes(QIntList& theModes);
124
125   /// Returns whether the mouse enter the viewer's window
126   /// \return true if items are added and there is no necessity to provide standard menu
127   bool isMouseOverWindow();
128
129   PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
130
131   /// Returns data model object for representation of data tree in Object browser
132   virtual ModuleBase_IDocumentDataModel* dataModel() const { return myDataModel; }
133
134   /// Event Listener method
135   /// \param theMessage an event message
136   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
137
138   /// This method is called on object browser creation for customisation of module specific features
139   /// \param theObjectBrowser a pinter on Object Browser widget
140   virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
141
142   /// Sends the operation for launching
143   /// \param theOperation the operation
144   virtual void sendOperation(ModuleBase_Operation* theOperation);
145
146 public slots:
147   /// SLOT, that is called by no more widget signal emitted by property panel
148   /// Set a specific flag to restart the sketcher operation
149   void onNoMoreWidgets();
150
151   /// Redefines the parent method in order to customize the next case:
152   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
153   /// the operation should be always aborted.
154   virtual void onFeatureTriggered();
155
156   /// Slolt called on object display
157   /// \param theObject a data object
158   /// \param theAIS a presentation object
159   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
160
161   /// Called on transformation in current viewer
162   /// \param theTrsfType type of tranformation
163   void onViewTransformed(int theTrsfType = 2);
164
165 protected slots:
166   /// Called when previous operation is finished
167   virtual void onSelectionChanged();
168
169   /// SLOT, that is called by key release in the viewer.
170   /// \param theWnd a view window
171   /// \param theEvent the key event
172   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
173
174   /// SLOT, that is called by enter key released
175   /// Set a specific type of restarting the current operation
176   void onEnterReleased();
177
178   /// SLOT, that is called by the current operation filling with the preselection.
179   /// It commits the operation of it is can be committed
180   void onOperationActivatedByPreselection();
181
182  protected:
183   /// Register validators for this module
184   virtual void registerValidators();
185
186   /// Register selection filters for this module
187   virtual void registerFilters();
188
189   /// Register properties of this module
190   virtual void registerProperties();
191
192  private slots:
193    /// Processing of vertex selected
194    void onVertexSelected();
195
196    void onTreeViewDoubleClick(const QModelIndex&);
197
198  private:
199   /// Breaks sequense of automatically resterted operations
200   void breakOperationSequence();
201
202   //! Delete features
203   virtual bool deleteObjects();
204
205  private:
206    QString myLastOperationId;
207    FeaturePtr myLastFeature;
208
209    // Automatical restarting mode flag
210    RestartingMode myRestartingMode;
211
212   /// A filter which provides selection within a current document or whole PartSet
213   Handle(PartSet_GlobalFilter) myDocumentShapeFilter;
214   Handle(PartSet_FilterInfinite) myFilterInfinite;
215
216   PartSet_SketcherMgr* mySketchMgr;
217
218   PartSet_MenuMgr* myMenuMgr;
219
220   int myVisualLayerId;
221
222   PartSet_DocumentDataModel* myDataModel;
223 };
224
225 #endif