1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #ifndef PartSet_SketcherReentrantMgr_H
4 #define PartSet_SketcherReentrantMgr_H
8 #include <ModelAPI_Feature.h>
14 class ModuleBase_IWorkshop;
15 class ModuleBase_Operation;
16 class ModuleBase_ModelWidget;
17 class ModuleBase_IViewWindow;
19 class ModelAPI_CompositeFeature;
25 class ModuleBase_ViewerPrs;
27 /// \ingroup PartSet_SketcherReentrantMgr
28 /// It provides reentrant create operations in sketch, that is when all inputs are valid,
29 /// automatic validation of the creation and switch the created entity to edit mode
30 /// ('internal' edit operation), with the ability to simultaneously create the next entity
31 /// of same type (re-entrance of the operation).
32 /// OK valids the current edition and exits from the operation (no re-entrance).
33 /// Cancel removes (undo) the entity currently edited and
34 /// exits from the operation (no re-entrance).
35 class PARTSET_EXPORT PartSet_SketcherReentrantMgr : public QObject
39 /// Enumeration to specify the restart operation properties.
41 RM_None, /// the operation should not be restarted
42 RM_Forbided, /// the operation should not be restarted after there is no active widget
43 RM_LastFeatureUsed, /// the operation is restarted and use
44 /// the previous feature for own initialization
45 RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
50 /// \param theWorkshop a workshop instance
51 PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop);
52 virtual ~PartSet_SketcherReentrantMgr();
55 /// Returns a first widget of the current opeation if the internal edit operation is active
56 /// or return null. If the current widget of the operation is a viewer selector, it returns null.
57 ModuleBase_ModelWidget* internalActiveWidget() const;
59 /// Return true if the current edit operation is an internal
60 bool isInternalEditActive() const;
62 /// Stop internal edit if the operation feature is invalid
63 void updateInternalEditActiveState();
65 /// if the internal flags allow it and the manager is active, it starts an internal edit operation
66 /// for the created operation.
67 /// \param thePreviousAttributeID an index of the previous active attribute
68 //bool restartOperation(const std::string& thePreviousAttributeID);
69 bool processEnter(const std::string& thePreviousAttributeID);
71 /// Resets the internal flags
72 /// \param theOperation a started operation
73 void operationStarted(ModuleBase_Operation* theOperation);
75 /// Resets the internal flags
76 /// \param theOperation a started operation
77 /// \return state whether the internal edit operation was active
78 bool operationCommitted(ModuleBase_Operation* theOperation);
80 /// Resets the internal flags
81 /// \param theOperation a started operation
82 void operationAborted(ModuleBase_Operation* theOperation);
84 /// Return true if the manager processes the mouse move event
85 /// It happens if the current operation is an internal edit operation and the first
86 /// control can be filled by the mouse move event. The operation is restarted.
87 /// \return true if operation is committed.
88 bool processMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
90 /// Return true if the manager processes the mouse press event
91 /// \return true if the current operation is an internal edit operation.
92 bool processMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
94 /// Return true if the manager processes the mouse enter event
95 /// It happens if the current operation is an internal edit operation.
96 /// The operation is restarted. If the first widget of the started operation is
97 /// the point 2d, it processes this mouse event
98 /// \return true if operation is committed.
99 bool processMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
101 /// It is called by the current operation filling with the preselection.
102 /// Returns false if the reentrant mode of the operation is not empty.
103 bool canBeCommittedByPreselection();
105 /// Put information about created objects into a cash. It will be processed in
106 /// restart operation.
107 /// \param theObjects a list of created objects
108 void appendCreatedObjects(const std::set<ObjectPtr>& theObjects);
111 /// SLOT, that is called by a widget activating in the property panel
112 /// If the 'internal' edit operation is started, it activates the first widget selection
113 void onWidgetActivated();
115 /// SLOT, that is called by no more widget signal emitted by property panel
116 /// Start an internal edit operation or, if the internal flag is forbided, commits
117 /// the current operation
118 /// \param thePreviousAttributeID an index of the previous active attribute
119 void onNoMoreWidgets(const std::string& thePreviousAttributeID);
121 /// Processing of vertex selected. Set an internal reentrant flag to forbiddent state if
122 /// the current feature is a line and there are not obligate widgets anymore
123 void onVertexSelected();
125 /// Listens to the signal about the modification of the values
126 /// have been done in the property panel. If the manager has active edit operation and
127 /// the active widget does not process the modification of value, the manager will
128 /// restart current operation and fill a new feature attribute by the value of current
130 void onAfterValuesChangedInPropertyPanel();
132 /// Deactivates selection and filters of the first operation widget if it is an internal
134 void onBeforeStopped();
137 /// Returns true if the current operation is a sketch or a nested sketch operation
138 bool isActiveMgr() const;
140 /// Sets the focus to the last control of the property panel and activates selection
141 /// of the first widget to can select first value of the next create operation
142 /// \param thePreviousAttributeID an index of the previous attribute to set focus to this widget
143 /// \return true if it is started
144 bool startInternalEdit(const std::string& thePreviousAttributeID);
146 /// Disconnects this manager from operation signals, deactivate selection of the first control
148 void beforeStopInternalEdit();
150 /// Commits the current operation and launches a new with the commited operation feature index
151 void restartOperation();
153 /// Creates an internal feature and controls to process it
154 void createInternalFeature();
156 /// A pair method for an internal creation to remove it and clear all created controls
157 void deleteInternalFeature();
159 /// Breaks sequense of automatically resterted operations
162 /// Copy some feature specific attributes from the source to a new feature
163 /// This is type for Circle and Arc features
164 /// \param theSourceFeature a source feature
165 /// \param theNewFeature a new feature
166 /// \param theSketch an active sketch
167 /// \param isTemporary is used to do not create additional features(e.g. coicidence for line)
168 /// \return true is something is copied
169 static bool copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
170 const FeaturePtr& theNewFeature,
171 const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
172 const bool isTemporary = false);
174 /// Checks whethe the feature of the given operation has kind an arc and the arc type is tangent
175 bool isTangentArc(ModuleBase_Operation* theOperation,
176 const std::shared_ptr<ModelAPI_CompositeFeature>& /*theSketch*/) const;
178 /// Creates selection instance by the current feature and created by restart objects
179 /// \returns viewer selection presentation
180 std::shared_ptr<ModuleBase_ViewerPrs> generatePreSelection();
182 /// Accept All action is enabled if an internal edit is started.
183 /// It updates the state of the button
184 void updateAcceptAllAction();
186 /// Returns the workshop
187 XGUI_Workshop* workshop() const;
189 /// Returns the workshop module
190 PartSet_Module* module() const;
193 ModuleBase_IWorkshop* myWorkshop; /// the workshop
195 RestartingMode myRestartingMode; /// automatical restarting mode flag
196 bool myIsFlagsBlocked; /// true when reset of flags should not be perfromed
197 bool myIsInternalEditOperation; /// true when the 'internal' edit is started
198 bool myIsValueChangedBlocked; /// blocked flag to avoid circling by value changed
200 FeaturePtr myPreviousFeature; /// feature of the previous operation, which is restarted
201 std::set<FeaturePtr> myCreatedFeatures; /// list of created features by restart operation
202 FeaturePtr myInternalFeature;
203 QWidget* myInternalWidget;
204 ModuleBase_ModelWidget* myInternalActiveWidget;
205 std::string myNoMoreWidgetsAttribute;