Salome HOME
2f981fd66755e93eb3b2356d158e9480282cbb4d
[modules/shaper.git] / src / PartSet / PartSet_Module.h
1 #ifndef PartSet_Module_H
2 #define PartSet_Module_H
3
4 #include "PartSet.h"
5
6 #include <ModuleBase_IModule.h>
7 #include <ModuleBase_Definitions.h>
8 #include <ModuleBase_ViewerFilters.h>
9 #include <XGUI_Command.h>
10 #include <ModelAPI_Feature.h>
11 #include <ModelAPI_Attribute.h>
12 #include <ModelAPI_CompositeFeature.h>
13
14 #include <StdSelect_FaceFilter.hxx>
15 #include <TopoDS_Shape.hxx>
16
17 #include <QMap>
18 #include <QObject>
19
20 #include <string>
21
22 #include <memory>
23
24 class ModuleBase_Operation;
25 class ModuleBase_IViewWindow;
26
27 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule
28 {
29 Q_OBJECT
30
31 /// Enumeration to specify the restart operation properties.
32 enum RestartingMode {
33   RM_None, /// the operation should not be restarted
34   RM_LastFeatureUse, /// the operation is restarted and use the previous feature for own initialization
35   RM_LastFeatureEmpty /// 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   /// The mouse released point is sent to the current operation to be processed.
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   /// The mouse released point is sent to the current operation to be processed.
77   /// \param theEvent the mouse event
78   virtual void onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
79   
80   /// SLOT, that is called by mouse move in the viewer.
81   /// The mouse moved point is sent to the current operation to be processed.
82   /// \param theEvent the mouse event
83   virtual void onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
84
85   /// SLOT, that is called by key release in the viewer.
86   /// The mouse moved point is sent to the current operation to be processed.
87   /// \param theEvent the key event
88   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
89
90   /// SLOT, that is called by enter key released
91   /// Set a specific type of restarting the current operation
92   void onEnterReleased();
93
94   /// Launches the operation from current highlighting
95   void launchEditing();
96
97  protected:
98   /// Returns new instance of operation object (used in createOperation for customization)
99   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
100
101   /// Register validators for this module
102   virtual void registerValidators();
103
104  private slots:
105    void onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
106
107    void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
108
109  private:
110    /// Converts mouse position to 2d coordinates. 
111    /// Member myCurrentSketch has to be correctly defined
112   void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
113                   double& theX, double& theY);
114
115   /// Breaks sequense of automatically resterted operations
116   void breakOperationSequence();
117
118  private:
119    QString myLastOperationId;
120    FeaturePtr myLastFeature;
121
122    bool myIsDragging;
123    bool myDragDone;
124
125    // Automatical restarting mode flag
126    RestartingMode myRestartingMode;
127
128    double myCurX, myCurY;
129    CompositeFeaturePtr myCurrentSketch;
130    QList<FeaturePtr> myEditingFeatures;
131    QList<AttributePtr> myEditingAttr;
132
133    Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
134   /// A filter which provides selection within a current document or whole PartSet
135   Handle(ModuleBase_ShapeDocumentFilter) myDocumentShapeFilter;
136 };
137
138 #endif