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