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