Salome HOME
74e8bd92b49eaa997976531bc291c82bd95e304a
[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 class ModuleBase_IViewWindow;
18
19 class QMouseEvent;
20
21 class XGUI_Workshop;
22 class PartSet_Module;
23
24 /// \ingroup PartSet_SketcherReetntrantMgr
25 /// It provides reentrant create operations in sketch, that is when all inputs are valid,
26 /// automatic validation of the creation and switch the created entity to edit mode
27 /// ('internal' edit operation), with the ability to simultaneously create the next entity
28 /// of same type (re-entrance of the operation).
29 /// OK valids the current edition and exits from the operation (no re-entrance).
30 /// Cancel removes (undo) the entity currently edited and exits from the operation (no re-entrance).
31 class PARTSET_EXPORT PartSet_SketcherReetntrantMgr : public QObject
32 {
33 Q_OBJECT
34
35 /// Enumeration to specify the restart operation properties.
36 enum RestartingMode {
37   RM_None, /// the operation should not be restarted
38   RM_Forbided, /// the operation should not be restarted after there is no active widget
39   RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
40   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
41 };
42
43 public:
44   /// Constructor
45   /// \param theWorkshop a workshop instance
46   PartSet_SketcherReetntrantMgr(ModuleBase_IWorkshop* theWorkshop);
47   virtual ~PartSet_SketcherReetntrantMgr();
48
49 public:
50   /// Returns a first widget of the current opeation if the internal edit operation is active
51   /// or return null. If the current widget of the operation is a viewer selector, it returns null.
52   ModuleBase_ModelWidget* internalActiveWidget() const;
53
54   /// Return true if the current edit operation is an internal
55   bool isInternalEditActive() const;
56
57   /// Stop internal edit if the operation feature is invalid
58   void updateInternalEditActiveState();
59
60   /// if the internal flags allow it and the manager is active, it starts an internal edit operation
61   /// for the created operation.
62   /// \param thePreviousAttributeID an index of the previous active attribute
63   //bool restartOperation(const std::string& thePreviousAttributeID);
64   bool processEnter(const std::string& thePreviousAttributeID);
65
66   /// Resets the internal flags
67   /// \param theOperation a started operation
68   void operationStarted(ModuleBase_Operation* theOperation);
69
70   /// Resets the internal flags
71   /// \param theOperation a started operation
72   /// \return state whether the internal edit operation was active
73   bool operationCommitted(ModuleBase_Operation* theOperation);
74
75   /// Resets the internal flags
76   /// \param theOperation a started operation
77   void operationAborted(ModuleBase_Operation* theOperation);
78
79   /// Return true if the manager processes the mouse move event
80   /// It happens if the current operation is an internal edit operation and the first
81   /// control can be filled by the mouse move event. The operation is restarted.
82   /// \return true if operation is committed.
83   bool processMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
84
85   /// Return true if the manager processes the mouse press event
86   /// \return true if the current operation is an internal edit operation.
87   bool processMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
88
89   /// Return true if the manager processes the mouse enter event
90   /// It happens if the current operation is an internal edit operation.
91   /// The operation is restarted. If the first widget of the started operation is
92   /// the point 2d, it processes this mouse event
93   /// \return true if operation is committed.
94   bool processMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
95
96   /// It is called by the current operation filling with the preselection.
97   /// Returns false if the reentrant mode of the operation is not empty.
98   bool canBeCommittedByPreselection();
99
100   /// returns true if an internal edit operation is started
101   /// \return boolean value
102   bool isInternalEditStarted() const;
103
104 private slots:
105   /// SLOT, that is called by a widget activating in the property panel
106   /// If the 'internal' edit operation is started, it activates the first widget selection
107   void onWidgetActivated();
108
109   /// SLOT, that is called by no more widget signal emitted by property panel
110   /// Start an internal edit operation or, if the internal flag is forbided, commits
111   /// the current operation
112   /// \param thePreviousAttributeID an index of the previous active attribute
113   void onNoMoreWidgets(const std::string& thePreviousAttributeID);
114
115   /// Processing of vertex selected. Set an internal reentrant flag to forbiddent state if
116   /// the current feature is a line and there are not obligate widgets anymore
117   void onVertexSelected();
118
119   /// Deactivates selection and filters of the first operation widget if it is an internal
120   /// 'edit' operation
121   void onBeforeStopped();
122
123 private:
124   /// Returns true if the current operation is a sketch or a nested sketch operation
125   bool isActiveMgr() const;
126
127   /// Sets the focus to the last control of the property panel and activates selection
128   /// of the first widget to can select first value of the next create operation
129   /// \param thePreviousAttributeID an index of the previous attribute to set focus to this widget
130   /// \return true if it is started
131   bool startInternalEdit(const std::string& thePreviousAttributeID);
132
133   /// Disconnects this manager from operation signals, deactivate selection of the first control
134   /// in the viewer.
135   void beforeStopInternalEdit();
136
137   /// Commits the current operation and launches a new with the commited operation feature index
138   void restartOperation();
139
140   /// Creates an internal feature and controls to process it
141   void createInternalFeature();
142
143   /// A pair method for an internal creation to remove it and clear all created controls
144   void deleteInternalFeature();
145
146   /// Breaks sequense of automatically resterted operations
147   void resetFlags();
148
149   /// Copy some feature specific attributes from the source to a new feature
150   /// This is type for Circle and Arc features
151   /// \param theSourceFeature a source feature
152   /// \param theNewFeature a new feature
153   /// \return true is something is copied
154   static bool copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
155                                        const FeaturePtr& theNewFeature);
156
157   static bool isTangentArc(ModuleBase_Operation* theOperation);
158
159   /// Accept All action is enabled if an internal edit is started. It updates the state of the button
160   void updateAcceptAllAction();
161
162   /// Returns the workshop
163   XGUI_Workshop* workshop() const;
164
165   /// Returns the workshop module
166   PartSet_Module* module() const;
167
168 private:
169   ModuleBase_IWorkshop* myWorkshop; /// the workshop
170
171   RestartingMode myRestartingMode;  /// automatical restarting mode flag
172   bool myIsFlagsBlocked; /// true when reset of flags should not be perfromed
173   bool myIsInternalEditOperation; /// true when the 'internal' edit is started
174
175   FeaturePtr myInternalFeature;
176   QWidget* myInternalWidget;
177   ModuleBase_ModelWidget* myInternalActiveWidget;
178   std::string myNoMoreWidgetsAttribute;
179 };
180
181 #endif