1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #ifndef PartSet_SketcherReetntrantMgr_H
4 #define PartSet_SketcherReetntrantMgr_H
8 #include <ModelAPI_Feature.h>
14 class ModuleBase_IWorkshop;
15 class ModuleBase_Operation;
16 class ModuleBase_ModelWidget;
17 class ModuleBase_IViewWindow;
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
35 /// Enumeration to specify the restart operation properties.
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
45 /// \param theParent a parent object
46 PartSet_SketcherReetntrantMgr(ModuleBase_IWorkshop* theWorkshop);
47 virtual ~PartSet_SketcherReetntrantMgr();
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;
54 /// if the internal flags allow it and the manager is active, it starts an internal edit operation
55 /// for the created operation.
56 /// \param thePreviousAttributeID an index of the previous active attribute
57 //bool restartOperation(const std::string& thePreviousAttributeID);
58 bool processEnter(const std::string& thePreviousAttributeID);
60 /// Resets the internal flags
61 /// \param theOperation a started operation
62 void operationStarted(ModuleBase_Operation* theOperation);
64 /// Resets the internal flags
65 /// \param theOperation a started operation
66 /// \return state whether the internal edit operation was active
67 bool operationCommitted(ModuleBase_Operation* theOperation);
69 /// Resets the internal flags
70 /// \param theOperation a started operation
71 void operationAborted(ModuleBase_Operation* theOperation);
73 /// Return true if the manager processes the mouse move event
74 /// It happens if the current operation is an internal edit operation and the first
75 /// control can be filled by the mouse move event. The operation is restarted.
76 /// \return true if operation is committed.
77 bool processMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
79 /// Return true if the manager processes the mouse press event
80 /// \return true if the current operation is an internal edit operation.
81 bool processMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
83 /// Return true if the manager processes the mouse enter event
84 /// It happens if the current operation is an internal edit operation.
85 /// The operation is restarted. If the first widget of the started operation is
86 /// the point 2d, it processes this mouse event
87 /// \return true if operation is committed.
88 bool processMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
90 /// It is called by the current operation filling with the preselection.
91 /// Returns false if the reentrant mode of the operation is not empty.
92 bool canBeCommittedByPreselection();
95 /// SLOT, that is called by a widget activating in the property panel
96 /// If the 'internal' edit operation is started, it activates the first widget selection
97 void onWidgetActivated();
99 /// SLOT, that is called by no more widget signal emitted by property panel
100 /// Start an internal edit operation or, if the internal flag is forbided, commits
101 /// the current operation
102 /// \param thePreviousAttributeID an index of the previous active attribute
103 void onNoMoreWidgets(const std::string& thePreviousAttributeID);
105 /// Processing of vertex selected. Set an internal reentrant flag to forbiddent state if
106 /// the current feature is a line and there are not obligate widgets anymore
107 void onVertexSelected();
109 /// Deactivates selection and filters of the first operation widget if it is an internal
111 void onBeforeStopped();
114 /// Returns true if the current operation is a sketch or a nested sketch operation
115 bool isActiveMgr() const;
117 /// Sets the focus to the last control of the property panel and activates selection
118 /// of the first widget to can select first value of the next create operation
119 /// \param thePreviousAttributeID an index of the previous attribute to set focus to this widget
120 void startInternalEdit(const std::string& thePreviousAttributeID);
122 /// Commits the current operation and launches a new with the commited operation feature index
123 void restartOperation();
125 /// Breaks sequense of automatically resterted operations
128 /// Returns the workshop
129 XGUI_Workshop* workshop() const;
131 /// Returns the workshop module
132 PartSet_Module* module() const;
135 ModuleBase_IWorkshop* myWorkshop; /// the workshop
137 RestartingMode myRestartingMode; /// automatical restarting mode flag
138 bool myIsFlagsBlocked; /// true when reset of flags should not be perfromed
139 bool myIsInternalEditOperation; /// true when the 'internal' edit is started