Salome HOME
Transfer data model for object browser under module responsibility
[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
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
20 #include <QMap>
21 #include <QMenu>
22 #include <QObject>
23
24 #include <string>
25
26 #include <memory>
27
28 class ModuleBase_Operation;
29 class ModuleBase_IViewWindow;
30 class PartSet_MenuMgr;
31 class PartSet_SketcherMgr;
32 class PartSet_DocumentDataModel;
33
34 class QAction;
35
36 /**
37 * \ingroup Modules
38 * Implementation of Partset module
39 */
40 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
41 {
42 Q_OBJECT
43
44 /// Enumeration to specify the restart operation properties.
45 enum RestartingMode {
46   RM_None, /// the operation should not be restarted
47   RM_Forbided, /// the operation should not be restarted after there is no active widget
48   RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
49   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
50 };
51
52 public:
53
54   /// Constructor
55   /// \param theWshop a pointer to a workshop
56   PartSet_Module(ModuleBase_IWorkshop* theWshop);
57   virtual ~PartSet_Module();
58
59   /// Creates custom widgets for property panel
60   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
61                                                      Config_WidgetAPI* theWidgetApi, std::string theParentId);
62
63   /// Call back forlast tuning of property panel before operation performance
64   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
65
66
67   /// Realizes some functionality by an operation start
68   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
69   /// \param theOperation a started operation
70   virtual void operationStarted(ModuleBase_Operation* theOperation);
71
72   /// Realizes some functionality by an operation commit
73   /// Restarts sketcher operation automatically of it is necessary
74   /// \param theOperation a committed operation
75   virtual void operationCommitted(ModuleBase_Operation* theOperation);
76
77   /// Realizes some functionality by an operation abort
78   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
79   /// \param theOperation an aborted operation
80   virtual void operationAborted(ModuleBase_Operation* theOperation);
81
82   /// Realizes some functionality by an operation stop
83   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
84   /// \param theOperation a stopped operation
85   virtual void operationStopped(ModuleBase_Operation* theOperation);
86
87   /// Returns current operation
88   virtual ModuleBase_Operation* currentOperation() const;
89
90   /// Returns True if there are available Undos and the sketch manager allows undo
91   /// \return the boolean result
92   virtual bool canUndo() const;
93
94   //! Returns True if there are available Redos and the sketch manager allows redo
95   /// \return the boolean result
96   virtual bool canRedo() const;
97
98   /// Returns whether the object can be displayed at the bounds of the active operation.
99   /// Display only current operation results for usual operation and ask the sketcher manager
100   /// if it is a sketch operation
101   /// \param theObject a model object
102   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
103
104   /// Add menu atems for object browser into the given menu
105   /// \param theMenu a popup menu to be shown in the object browser
106   virtual void addObjectBrowserMenu(QMenu* theMenu) const;
107
108   /// Add menu atems for viewer into the given menu
109   /// \param theMenu a popup menu to be shown in the viewer
110   /// \param theStdActions a map of standard actions
111   /// \return true if items are added and there is no necessity to provide standard menu
112   virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
113
114   /// Returns whether the mouse enter the viewer's window
115   /// \return true if items are added and there is no necessity to provide standard menu
116   bool isMouseOverWindow();
117
118   PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
119
120   /// Returns data model object for representation of data tree in Object browser
121   virtual ModuleBase_IDocumentDataModel* dataModel() const;
122
123   /// Event Listener method
124   /// \param theMessage an event message
125   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
126
127 public slots:
128   /// SLOT, that is called by no more widget signal emitted by property panel
129   /// Set a specific flag to restart the sketcher operation
130   void onNoMoreWidgets();
131
132   /// Slolt called on object display
133   /// \param theObject a data object
134   /// \param theAIS a presentation object
135   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
136
137 protected slots:
138   /// Called when previous operation is finished
139   virtual void onSelectionChanged();
140
141   /// SLOT, that is called by key release in the viewer.
142   /// \param theWnd a view window
143   /// \param theEvent the key event
144   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
145
146   /// SLOT, that is called by enter key released
147   /// Set a specific type of restarting the current operation
148   void onEnterReleased();
149
150   /// SLOT, that is called by the current operation filling with the preselection.
151   /// It commits the operation of it is can be committed
152   void onOperationActivatedByPreselection();
153
154  protected:
155   /// Register validators for this module
156   virtual void registerValidators();
157
158   /// Register selection filters for this module
159   virtual void registerFilters();
160
161   /// Register properties of this module
162   virtual void registerProperties();
163
164   /// Sends the operation for launching
165   /// \param theOperation the operation
166   virtual void sendOperation(ModuleBase_Operation* theOperation);
167
168   //! Activates or deactivates a part
169   //! If PartPtr is Null pointer then PartSet will be activated
170   //void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
171
172  private slots:
173    /// Processing of vertex selected
174    void onVertexSelected();
175
176    /// Called on transformation in current viewer
177    /// \param theTrsfType type of tranformation
178    void onViewTransformed(int theTrsfType = 2);
179
180  private:
181   /// Breaks sequense of automatically resterted operations
182   void breakOperationSequence();
183
184   //! Delete features
185   virtual bool deleteObjects();
186
187  private:
188    QString myLastOperationId;
189    FeaturePtr myLastFeature;
190
191    // Automatical restarting mode flag
192    RestartingMode myRestartingMode;
193
194   /// A filter which provides selection within a current document or whole PartSet
195   Handle(PartSet_GlobalFilter) myDocumentShapeFilter;
196
197   PartSet_SketcherMgr* mySketchMgr;
198
199   PartSet_MenuMgr* myMenuMgr;
200
201   int myVisualLayerId;
202
203   PartSet_DocumentDataModel* myDataModel;
204 };
205
206 #endif