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