]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_SketcherReentrantMgr.h
Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / PartSet / PartSet_SketcherReentrantMgr.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #ifndef PartSet_SketcherReentrantMgr_H
21 #define PartSet_SketcherReentrantMgr_H
22
23 #include "PartSet.h"
24
25 #include <ModelAPI_Feature.h>
26
27 #include <string>
28 #include <memory>
29
30 #include <QObject>
31
32 class ModuleBase_IWorkshop;
33 class ModuleBase_Operation;
34 class ModuleBase_ModelWidget;
35 class ModuleBase_IViewWindow;
36
37 class ModelAPI_CompositeFeature;
38
39 class QMouseEvent;
40
41 class XGUI_Workshop;
42 class PartSet_Module;
43 class ModuleBase_ViewerPrs;
44 class Events_Message;
45 class ModelAPI_Attribute;
46 class GeomAPI_Pnt2d;
47
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
57 {
58 Q_OBJECT
59
60 /// Enumeration to specify the restart operation properties.
61 enum RestartingMode {
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
67 };
68
69 public:
70   /// Constructor
71   /// \param theWorkshop a workshop instance
72   PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop);
73   virtual ~PartSet_SketcherReentrantMgr();
74
75 public:
76   /// Returns a first widget of the current opeation if the internal edit operation is active
77   /// or return null. If the current widget of the operation is a viewer selector, it returns null.
78   ModuleBase_ModelWidget* internalActiveWidget() const;
79
80   /// Return true if the current edit operation is an internal
81   bool isInternalEditActive() const;
82
83   /// Stop internal edit if the operation feature is invalid
84   void updateInternalEditActiveState();
85
86   /// if the internal flags allow it and the manager is active, it starts an internal edit operation
87   /// for the created operation.
88   /// \param thePreviousAttributeID an index of the previous active attribute
89   //bool restartOperation(const std::string& thePreviousAttributeID);
90   bool processEnter(const std::string& thePreviousAttributeID);
91
92   /// Resets the internal flags
93   /// \param theOperation a started operation
94   void operationStarted(ModuleBase_Operation* theOperation);
95
96   /// Resets the internal flags
97   /// \param theOperation a started operation
98   /// \return state whether the internal edit operation was active
99   bool operationCommitted(ModuleBase_Operation* theOperation);
100
101   /// Resets the internal flags
102   /// \param theOperation a started operation
103   void operationAborted(ModuleBase_Operation* theOperation);
104
105   /// Return true if the manager processes the mouse move event
106   /// It happens if the current operation is an internal edit operation and the first
107   /// control can be filled by the mouse move event. The operation is restarted.
108   /// \return true if operation is committed.
109   bool processMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
110
111   /// Return true if the manager processes the mouse press event
112   /// \return true if the current operation is an internal edit operation.
113   bool processMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
114
115   /// Return true if the manager processes the mouse enter event
116   /// It happens if the current operation is an internal edit operation.
117   /// The operation is restarted. If the first widget of the started operation is
118   /// the point 2d, it processes this mouse event
119   /// \return true if operation is committed.
120   bool processMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
121
122   /// It is called by the current operation filling with the preselection.
123   /// Returns false if the reentrant mode of the operation is not empty.
124   bool canBeCommittedByPreselection();
125
126   /// Fills reentrant message during restarting operation
127   /// \param theMessage reentrant message
128   void setReentrantMessage(const std::shared_ptr<Events_Message>& theMessage)
129   { myReentrantMessage = theMessage; }
130
131   /// Returnss reentrant message
132   std::shared_ptr<Events_Message> reentrantMessage() const { return myReentrantMessage; }
133
134   /// Put current selection into reentrant message
135   /// \param theMessage a message of reentrant operation
136   void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage);
137
138 private slots:
139   /// SLOT, that is called by a widget activating in the property panel
140   /// If the 'internal' edit operation is started, it activates the first widget selection
141   void onWidgetActivated();
142
143   /// SLOT, that is called by no more widget signal emitted by property panel
144   /// Start an internal edit operation or, if the internal flag is forbided, commits
145   /// the current operation
146   /// \param thePreviousAttributeID an index of the previous active attribute
147   void onNoMoreWidgets(const std::string& thePreviousAttributeID);
148
149   /// Processing of vertex selected. Set an internal reentrant flag to forbiddent state if
150   /// the current feature is a line and there are not obligate widgets anymore
151   void onVertexSelected();
152
153   /// Listens to the signal about the modification of the values
154   /// have been done in the property panel. If the manager has active edit operation and
155   /// the active widget does not process the modification of value, the manager will
156   /// restart current operation and fill a new feature attribute by the value of current
157   /// widget
158   void onAfterValuesChangedInPropertyPanel();
159
160   /// Deactivates selection and filters of the first operation widget if it is an internal
161   /// 'edit' operation
162   void onBeforeStopped();
163
164 private:
165   /// Returns true if the current operation is a sketch or a nested sketch operation
166   bool isActiveMgr() const;
167
168   /// Sets the focus to the last control of the property panel and activates selection
169   /// of the first widget to can select first value of the next create operation
170   /// \param thePreviousAttributeID an index of the previous attribute to set focus to this widget
171   /// \return true if it is started
172   bool startInternalEdit(const std::string& thePreviousAttributeID);
173
174   /// Disconnects this manager from operation signals, deactivate selection of the first control
175   /// in the viewer.
176   void beforeStopInternalEdit();
177
178   /// Commits the current operation and launches a new with the commited operation feature index
179   void restartOperation();
180
181   /// Creates an internal feature and controls to process it
182   void createInternalFeature();
183
184   /// A pair method for an internal creation to remove it and clear all created controls
185   void deleteInternalFeature();
186
187   /// Breaks sequense of automatically resterted operations
188   void resetFlags();
189
190   /// Copy some feature specific attributes from the source to a new feature
191   /// This is type for Circle and Arc features
192   /// \param theSourceFeature a source feature
193   /// \param theNewFeature a new feature
194   /// \param theSketch an active sketch
195   /// \param isTemporary is used to do not create additional features(e.g. coicidence for line)
196   /// \return true is something is copied
197   static bool copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
198                                       const FeaturePtr& theNewFeature,
199                                       const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
200                                       const bool isTemporary = false);
201
202   /// Checks whethe the feature of the given operation has kind an arc and the arc type is tangent
203   bool isTangentArc(ModuleBase_Operation* theOperation,
204                     const std::shared_ptr<ModelAPI_CompositeFeature>& /*theSketch*/) const;
205
206   /// Accept All action is enabled if an internal edit is started.
207   /// It updates the state of the button
208   void updateAcceptAllAction();
209
210   /// Returns the workshop
211   XGUI_Workshop* workshop() const;
212
213   /// Returns the workshop module
214   PartSet_Module* module() const;
215
216 private:
217   ModuleBase_IWorkshop* myWorkshop; /// the workshop
218
219   RestartingMode myRestartingMode;  /// automatical restarting mode flag
220   bool myIsFlagsBlocked; /// true when reset of flags should not be perfromed
221   bool myIsInternalEditOperation; /// true when the 'internal' edit is started
222
223   FeaturePtr myPreviousFeature; /// feature of the previous operation, which is restarted
224   FeaturePtr myInternalFeature;
225   QWidget* myInternalWidget;
226   ModuleBase_ModelWidget* myInternalActiveWidget;
227   std::string myNoMoreWidgetsAttribute;
228
229   std::shared_ptr<Events_Message> myReentrantMessage; /// message obtained by operation restart
230   ObjectPtr mySelectedObject; /// cashed selected object
231   std::shared_ptr<ModelAPI_Attribute> mySelectedAttribute; /// cashed selected attribute
232   std::shared_ptr<GeomAPI_Pnt2d> myClickedSketchPoint; /// cashed clicked point
233 };
234
235 #endif