Salome HOME
e08054fa3ab275cc259766af2401c7a9cf33871b
[modules/shaper.git] / src / PartSet / PartSet_SketcherReetntrantMgr.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #ifndef PartSet_SketcherReetntrantMgr_H
4 #define PartSet_SketcherReetntrantMgr_H
5
6 #include "PartSet.h"
7
8 #include <ModelAPI_Feature.h>
9
10 #include <string>
11
12 #include <QObject>
13
14 class ModuleBase_IWorkshop;
15 class ModuleBase_Operation;
16 class ModuleBase_ModelWidget;
17
18 class XGUI_Workshop;
19 class PartSet_Module;
20
21 /// \ingroup PartSet_SketcherReetntrantMgr
22 /// It provides reentrant create operations in sketch, that is when all inputs are valid,
23 /// automatic validation of the creation and switch the created entity to edit mode
24 /// ('internal' edit operation),
25 /// with the ability to simultaneously create the next entity of same type (re-entrance of the operation).
26 /// OK valids the current edition and exits from the operation (no re-entrance).
27 /// Cancel removes (undo) the entity currently edited and exits from the operation (no re-entrance).
28 class PARTSET_EXPORT PartSet_SketcherReetntrantMgr : public QObject
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   /// Constructor
42   /// \param theParent a parent object
43   PartSet_SketcherReetntrantMgr(ModuleBase_IWorkshop* theWorkshop);
44   virtual ~PartSet_SketcherReetntrantMgr();
45
46 public:
47   /// If the internal edit operation is started, this is the first widget of the operation
48   ModuleBase_ModelWidget* activeWidget() const;
49
50   /// Restarts sketcher operation automatically. If the commited operation is created, it starts
51   /// an 'internal' edit operation for the created feature. If an 'internal' operation is committed,
52   /// a create operation for a new feature with the current feature kind is started.
53   /// Some internal flags are taken into accout, such as whether the previous feature should be
54   /// used for initialization of created one or whether the restart of operation is forbidden.
55   /// \param theOperation a committed operation
56   /// \return true if an operation restarted
57   bool operationCommitted(ModuleBase_Operation* theOperation);
58
59   /// \param theOperation a committed operation
60   void operationAborted(ModuleBase_Operation* theOperation);
61
62   /// Return true if the manager processes the mouse move event
63   /// It happens if the current operation is an internal edit operation and the first
64   /// control can be filled by the mouse move event. The operation is committed.
65   /// \return true if operation is committed.
66   bool processMouseMoved();
67
68   /// Return true if the manager processes the mouse press event
69   /// \return true if the current operation is an internal edit operation.
70   bool processMousePressed();
71
72   /// Return true if the manager processes the mouse enter event
73   /// It happens if the current operation is an internal edit operation.
74   /// The operation is committed.
75   /// \return true if operation is committed.
76   bool processMouseReleased();
77
78   /// Activates the operation widgets relatively the internal reentrant flags
79   void propertyPanelDefined(ModuleBase_Operation* theOperation);
80
81   /// It is called by no more widget signal emitted by property panel
82   /// Set a specific flag to restart the sketcher operation
83   void noMoreWidgets(const std::string& thePreviousAttributeID);
84
85   /// Processing of vertex selected, if the feature is line, save flags to stop reentrant operation
86   void vertexSelected();
87
88   /// It is called by enter key released
89   /// Set a specific type of restarting the current operation
90   void enterReleased();
91
92   /// It is called by the current operation filling with the preselection.
93   /// Returns false if the reentrant mode of the operation is not empty.
94   bool canBeCommittedByPreselection();
95
96 public slots:
97   void onInternalActivateFirstWidgetSelection();
98
99 private:
100   /// Returns true if the current operation is a sketch or a nested sketch operation
101   bool isActiveMgr() const;
102
103   /// Breaks sequense of automatically resterted operations
104   void breakOperationSequence();
105
106   /// Returns the workshop
107   XGUI_Workshop* workshop() const;
108
109   /// Returns the workshop module
110   PartSet_Module* module() const;
111
112 private:
113   ModuleBase_IWorkshop* myWorkshop; /// the workshop
114
115   bool myIsInternalEditOperation; /// true when the 'internal' edit is started
116
117   std::string myLastOperationId;
118   FeaturePtr myLastFeature;
119
120   std::string myPreviousAttributeID;
121   RestartingMode myRestartingMode;  /// Automatical restarting mode flag
122 };
123
124 #endif