1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef PartSet_SketcherReentrantMgr_H
21 #define PartSet_SketcherReentrantMgr_H
25 #include <ModelAPI_Feature.h>
32 class ModuleBase_IWorkshop;
33 class ModuleBase_Operation;
34 class ModuleBase_ModelWidget;
35 class ModuleBase_IViewWindow;
37 class ModelAPI_CompositeFeature;
43 class ModuleBase_ViewerPrs;
45 class ModelAPI_Attribute;
48 /// \ingroup PartSet_SketcherReentrantMgr
49 /// It provides reentrant create operations in sketch, that is when all inputs are valid,
50 /// automatic validation of the creation and switch the created entity to edit mode
51 /// ('internal' edit operation), with the ability to simultaneously create the next entity
52 /// of same type (re-entrance of the operation).
53 /// OK valids the current edition and exits from the operation (no re-entrance).
54 /// Cancel removes (undo) the entity currently edited and
55 /// exits from the operation (no re-entrance).
56 class PARTSET_EXPORT PartSet_SketcherReentrantMgr : public QObject
60 /// Enumeration to specify the restart operation properties.
62 RM_None, /// the operation should not be restarted
63 RM_Forbided, /// the operation should not be restarted after there is no active widget
64 RM_LastFeatureUsed, /// the operation is restarted and use
65 /// the previous feature for own initialization
66 RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
71 /// \param theWorkshop a workshop instance
72 PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop);
73 virtual ~PartSet_SketcherReentrantMgr();
76 /// Return true if the current edit operation is an internal
77 bool isInternalEditActive() const;
79 /// Stop internal edit if the operation feature is invalid
80 void updateInternalEditActiveState();
82 /// if the internal flags allow it and the manager is active, it starts an internal edit operation
83 /// for the created operation.
84 /// \param thePreviousAttributeID an index of the previous active attribute
85 //bool restartOperation(const std::string& thePreviousAttributeID);
86 bool processEnter(const std::string& thePreviousAttributeID);
88 /// Resets the internal flags
89 /// \param theOperation a started operation
90 void operationStarted(ModuleBase_Operation* theOperation);
92 /// Resets the internal flags
93 /// \param theOperation a started operation
94 /// \return state whether the internal edit operation was active
95 bool operationCommitted(ModuleBase_Operation* theOperation);
97 /// Resets the internal flags
98 /// \param theOperation a started operation
99 void operationAborted(ModuleBase_Operation* theOperation);
101 /// Return true if the manager processes the mouse move event
102 /// It happens if the current operation is an internal edit operation and the first
103 /// control can be filled by the mouse move event. The operation is restarted.
104 /// \return true if operation is committed.
105 bool processMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
107 /// Return true if the manager processes the mouse press event
108 /// \return true if the current operation is an internal edit operation.
109 bool processMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
111 /// Return true if the manager processes the mouse enter event
112 /// It happens if the current operation is an internal edit operation.
113 /// The operation is restarted. If the first widget of the started operation is
114 /// the point 2d, it processes this mouse event
115 /// \return true if operation is committed.
116 bool processMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
118 /// It is called by the current operation filling with the preselection.
119 /// Returns false if the reentrant mode of the operation is not empty.
120 bool canBeCommittedByPreselection();
122 /// Fills reentrant message during restarting operation
123 /// \param theMessage reentrant message
124 void setReentrantMessage(const std::shared_ptr<Events_Message>& theMessage)
125 { myReentrantMessage = theMessage; }
127 /// Returnss reentrant message
128 std::shared_ptr<Events_Message> reentrantMessage() const { return myReentrantMessage; }
130 /// Put current selection into reentrant message
131 /// \param theMessage a message of reentrant operation
132 void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage);
135 /// SLOT, that is called by a widget activating in the property panel
136 /// If the 'internal' edit operation is started, it activates the first widget selection
137 //void onWidgetActivated();
139 /// SLOT, that is called by no more widget signal emitted by property panel
140 /// Start an internal edit operation or, if the internal flag is forbided, commits
141 /// the current operation
142 /// \param thePreviousAttributeID an index of the previous active attribute
143 void onNoMoreWidgets(const std::string& thePreviousAttributeID);
145 /// Processing of vertex selected. Set an internal reentrant flag to forbiddent state if
146 /// the current feature is a line and there are not obligate widgets anymore
147 void onVertexSelected();
149 /// Listens to the signal about the modification of the values
150 /// have been done in the property panel. If the manager has active edit operation and
151 /// the active widget does not process the modification of value, the manager will
152 /// restart current operation and fill a new feature attribute by the value of current
154 void onAfterValuesChangedInPropertyPanel();
156 /// Deactivates selection and filters of the first operation widget if it is an internal
158 void onBeforeStopped();
161 /// Returns true if the current operation is a sketch or a nested sketch operation
162 bool isActiveMgr() const;
164 /// Sets the focus to the last control of the property panel and activates selection
165 /// of the first widget to can select first value of the next create operation
166 /// \param thePreviousAttributeID an index of the previous attribute to set focus to this widget
167 /// \return true if it is started
168 bool startInternalEdit(const std::string& thePreviousAttributeID);
170 /// Disconnects this manager from operation signals, deactivate selection of the first control
172 void beforeStopInternalEdit();
174 /// Commits the current operation and launches a new with the commited operation feature index
175 void restartOperation();
177 /// Creates an internal feature and controls to process it
178 void createInternalFeature();
180 /// A pair method for an internal creation to remove it and clear all created controls
181 void deleteInternalFeature();
183 /// Breaks sequense of automatically resterted operations
186 /// Copy some feature specific attributes from the source to a new feature
187 /// This is type for Circle and Arc features
188 /// \param theSourceFeature a source feature
189 /// \param theNewFeature a new feature
190 /// \param theSketch an active sketch
191 /// \param isTemporary is used to do not create additional features(e.g. coicidence for line)
192 /// \return true is something is copied
193 static bool copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
194 const FeaturePtr& theNewFeature,
195 const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
196 const bool isTemporary = false);
198 /// Checks whethe the feature of the given operation has kind an arc and the arc type is tangent
199 bool isTangentArc(ModuleBase_Operation* theOperation,
200 const std::shared_ptr<ModelAPI_CompositeFeature>& /*theSketch*/) const;
202 /// Accept All action is enabled if an internal edit is started.
203 /// It updates the state of the button
204 void updateAcceptAllAction();
206 /// Returns the workshop
207 XGUI_Workshop* workshop() const;
209 /// Returns the workshop module
210 PartSet_Module* module() const;
212 void setInternalActiveWidget(ModuleBase_ModelWidget* theWidget);
215 ModuleBase_IWorkshop* myWorkshop; /// the workshop
217 RestartingMode myRestartingMode; /// automatical restarting mode flag
218 bool myIsFlagsBlocked; /// true when reset of flags should not be perfromed
219 bool myIsInternalEditOperation; /// true when the 'internal' edit is started
221 FeaturePtr myPreviousFeature; /// feature of the previous operation, which is restarted
222 FeaturePtr myInternalFeature;
223 QWidget* myInternalWidget;
224 std::string myNoMoreWidgetsAttribute;
226 std::shared_ptr<Events_Message> myReentrantMessage; /// message obtained by operation restart
227 ObjectPtr mySelectedObject; /// cashed selected object
228 std::shared_ptr<ModelAPI_Attribute> mySelectedAttribute; /// cashed selected attribute
229 std::shared_ptr<GeomAPI_Pnt2d> myClickedSketchPoint; /// cashed clicked point