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