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