Salome HOME
129df5353712c3eee24cb768c238807cdadfb8be
[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 public slots:
53   /// SLOT, that is called by no more widget signal emitted by property panel
54   /// Set a specific flag to restart the sketcher operation
55   void onNoMoreWidgets();
56
57 protected slots:
58   /// Called when previous operation is finished
59   virtual void onOperationComitted(ModuleBase_Operation* theOperation);
60
61   virtual void onOperationAborted(ModuleBase_Operation* theOperation);
62
63   virtual void onOperationStarted(ModuleBase_Operation* theOperation);
64
65   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
66
67   /// Called when previous operation is finished
68   virtual void onSelectionChanged();
69
70   /// SLOT, that is called by mouse press in the viewer.
71   /// \param theWnd - the window where the event happens
72   /// \param theEvent the mouse event
73   void onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
74
75   /// SLOT, that is called by mouse release in the viewer.
76   /// \param theWnd - the window where the event happens
77   /// \param theEvent the mouse event
78   void onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
79   
80   /// SLOT, that is called by mouse move in the viewer.
81   /// \param theWnd - the window where the event happens
82   /// \param theEvent the mouse event
83   void onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
84
85   /// SLOT, that is called by mouse double click in the viewer.
86   /// \param theWnd - the window where the event happens
87   /// \param theEvent the mouse event
88   void onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
89
90   /// SLOT, that is called by key release in the viewer.
91   /// The mouse moved point is sent to the current operation to be processed.
92   /// \param theEvent the key event
93   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
94
95   /// SLOT, that is called by enter key released
96   /// Set a specific type of restarting the current operation
97   void onEnterReleased();
98
99   /// SLOT, that is called by the current operation filling with the preselection.
100   /// It commits the operation of it is can be committed
101   void onOperationActivatedByPreselection();
102
103   /// Launches the operation from current highlighting
104   void launchEditing();
105
106  protected:
107   /// Returns new instance of operation object (used in createOperation for customization)
108   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
109
110   /// Register validators for this module
111   virtual void registerValidators();
112
113   /// Register selection filters for this module
114   virtual void registerFilters();
115
116  private slots:
117    void onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
118
119    void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
120
121  private:
122    /// Converts mouse position to 2d coordinates. 
123    /// Member myCurrentSketch has to be correctly defined
124   void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
125                   double& theX, double& theY);
126
127   /// Breaks sequense of automatically resterted operations
128   void breakOperationSequence();
129
130  private:
131    QString myLastOperationId;
132    FeaturePtr myLastFeature;
133
134    bool myIsDragging;
135    bool myDragDone;
136
137    // Automatical restarting mode flag
138    RestartingMode myRestartingMode;
139
140    double myCurX, myCurY;
141    CompositeFeaturePtr myCurrentSketch;
142    QList<FeaturePtr> myEditingFeatures;
143    QList<AttributePtr> myEditingAttr;
144
145    Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
146   /// A filter which provides selection within a current document or whole PartSet
147   Handle(PartSet_GlobalFilter) myDocumentShapeFilter;
148 };
149
150 #endif