Salome HOME
Commit of the current operation if the preselection is activated.
[modules/shaper.git] / src / PartSet / PartSet_Module.h
1 #ifndef PartSet_Module_H
2 #define PartSet_Module_H
3
4 #include "PartSet.h"
5 #include <PartSet_Filters.h>
6
7 #include <ModuleBase_IModule.h>
8 #include <ModuleBase_Definitions.h>
9 #include <ModelAPI_Feature.h>
10 #include <ModelAPI_Attribute.h>
11 #include <ModelAPI_CompositeFeature.h>
12
13 #include <StdSelect_FaceFilter.hxx>
14 #include <TopoDS_Shape.hxx>
15
16 #include <QMap>
17 #include <QObject>
18
19 #include <string>
20
21 #include <memory>
22
23 class ModuleBase_Operation;
24 class ModuleBase_IViewWindow;
25
26 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule
27 {
28 Q_OBJECT
29
30 /// Enumeration to specify the restart operation properties.
31 enum RestartingMode {
32   RM_None, /// the operation should not be restarted
33   RM_Forbided, /// the operation should not be restarted after there is no active widget
34   RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
35   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
36 };
37
38 public:
39   PartSet_Module(ModuleBase_IWorkshop* theWshop);
40   virtual ~PartSet_Module();
41
42   /// Creates custom widgets for property panel
43   virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
44                                       Config_WidgetAPI* theWidgetApi, std::string theParentId,
45                                       QList<ModuleBase_ModelWidget*>& theModelWidgets);
46
47   /// Call back forlast tuning of property panel before operation performance
48   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
49
50   QStringList sketchOperationIdList() const;
51
52   /// Realizes some functionality by an operation start
53   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
54   /// \param theOperation a started operation
55   virtual void operationStarted(ModuleBase_Operation* theOperation);
56
57   /// Realizes some functionality by an operation commit
58   /// Restarts sketcher operation automatically of it is necessary
59   /// \param theOperation a committed operation
60   virtual void operationCommitted(ModuleBase_Operation* theOperation);
61
62   /// Realizes some functionality by an operation abort
63   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
64   /// \param theOperation an aborted operation
65   virtual void operationAborted(ModuleBase_Operation* theOperation);
66
67   /// Realizes some functionality by an operation stop
68   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
69   /// \param theOperation a stopped operation
70   virtual void operationStopped(ModuleBase_Operation* theOperation);
71
72 public slots:
73   /// SLOT, that is called by no more widget signal emitted by property panel
74   /// Set a specific flag to restart the sketcher operation
75   void onNoMoreWidgets();
76
77 protected slots:
78   /// Called when previous operation is finished
79   virtual void onSelectionChanged();
80
81   /// SLOT, that is called by mouse press in the viewer.
82   /// \param theWnd - the window where the event happens
83   /// \param theEvent the mouse event
84   void onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
85
86   /// SLOT, that is called by mouse release in the viewer.
87   /// \param theWnd - the window where the event happens
88   /// \param theEvent the mouse event
89   void onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
90   
91   /// SLOT, that is called by mouse move in the viewer.
92   /// \param theWnd - the window where the event happens
93   /// \param theEvent the mouse event
94   void onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
95
96   /// SLOT, that is called by mouse double click in the viewer.
97   /// \param theWnd - the window where the event happens
98   /// \param theEvent the mouse event
99   void onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
100
101   /// SLOT, that is called by key release in the viewer.
102   /// The mouse moved point is sent to the current operation to be processed.
103   /// \param theEvent the key event
104   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
105
106   /// SLOT, that is called by enter key released
107   /// Set a specific type of restarting the current operation
108   void onEnterReleased();
109
110   /// SLOT, that is called by the current operation filling with the preselection.
111   /// It commits the operation of it is can be committed
112   void onOperationActivatedByPreselection();
113
114   /// Launches the operation from current highlighting
115   void launchEditing();
116
117  protected:
118   /// Returns new instance of operation object (used in createOperation for customization)
119   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
120
121   /// Register validators for this module
122   virtual void registerValidators();
123
124   /// Register selection filters for this module
125   virtual void registerFilters();
126
127  private slots:
128    void onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
129
130    void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
131
132  private:
133    /// Converts mouse position to 2d coordinates. 
134    /// Member myCurrentSketch has to be correctly defined
135   void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
136                   double& theX, double& theY);
137
138   /// Breaks sequense of automatically resterted operations
139   void breakOperationSequence();
140
141  private:
142    QString myLastOperationId;
143    FeaturePtr myLastFeature;
144
145    bool myIsDragging;
146    bool myDragDone;
147
148    // Automatical restarting mode flag
149    RestartingMode myRestartingMode;
150
151    double myCurX, myCurY;
152    CompositeFeaturePtr myCurrentSketch;
153    QList<FeaturePtr> myEditingFeatures;
154    QList<AttributePtr> myEditingAttr;
155
156    Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
157   /// A filter which provides selection within a current document or whole PartSet
158   Handle(PartSet_GlobalFilter) myDocumentShapeFilter;
159 };
160
161 #endif