1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_SketcherMgr.h
4 // Created: 19 Dec 2014
5 // Author: Vitaly SMETANNIKOV
7 #ifndef PartSet_SketcherMgr_H
8 #define PartSet_SketcherMgr_H
12 #include "PartSet_Tools.h"
14 #include <ModelAPI_Feature.h>
15 #include <ModelAPI_Attribute.h>
16 #include <ModelAPI_CompositeFeature.h>
17 #include <ModelAPI_Result.h>
19 #include <ModuleBase_ViewerFilters.h>
20 #include <ModuleBase_Definitions.h>
21 #include <ModuleBase_ModelWidget.h>
23 #include <GeomAPI_Pln.h>
24 #include <SelectMgr_IndexedMapOfOwner.hxx>
31 class ModuleBase_IViewWindow;
32 class ModuleBase_ModelWidget;
33 class ModuleBase_Operation;
34 class XGUI_OperationMgr;
41 * A class for management of sketch operations
42 At the time of the sketcher operation active, only the sketch sub-feature results are
43 displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
44 are hidden, the sketch feature result is displayed
46 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
49 /// Struct to define gp point, with the state is the point is initialized
55 myIsInitialized = false;
62 /// clear the initialized flag.
65 myIsInitialized = false;
67 /// set the point and switch on the initialized flag
68 /// \param thePoint the point
69 void setValue(const double theX, const double theY)
71 myIsInitialized = true;
76 bool myIsInitialized; /// the state whether the point is set
77 double myCurX, myCurY; /// the point coordinates
81 /// \param theModule a pointer to PartSet module
82 PartSet_SketcherMgr(PartSet_Module* theModule);
84 virtual ~PartSet_SketcherMgr();
86 /// Returns true if the operation is the sketch
87 /// \param theOperation an operation
88 /// \return the boolean result
89 static bool isSketchOperation(ModuleBase_Operation* theOperation);
91 /// Returns true if the operation id is in the sketch operation id list
92 /// \param theOperation an operation
93 /// \return the boolean result
94 static bool isNestedSketchOperation(ModuleBase_Operation* theOperation);
96 /// Returns true if the operation is a create nested feature one
97 /// \param theOperation a checked operation
98 //// \return boolean value
99 static bool isNestedCreateOperation(ModuleBase_Operation* theOperation);
101 /// Returns true if the operation is an edit nested feature one
102 /// \param theOperation a checked operation
103 //// \return boolean value
104 static bool isNestedEditOperation(ModuleBase_Operation* theOperation);
106 /// Returns whether the current operation is a sketch entity - line, point, arc or circle
107 /// \param theId is an id of object
108 /// \return a boolean value
109 static bool isEntity(const std::string& theId);
111 /// Returns whether the current operation is a sketch distance - lenght, distance or radius
112 /// \param theOperation the operation
113 /// \return a boolean value
114 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
116 /// Returns whether the feature kind is a sketch distance - lenght, distance or radius
117 /// \param theKind the feature kind
118 /// \return a boolean value
119 static bool isDistanceKind(std::string& theKind);
121 /// Returns true if a mouse cursor is over viewer window
122 bool isMouseOverWindow() { return myIsMouseOverWindow; }
124 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
125 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
127 /// Starts sketch operation
128 void startSketch(ModuleBase_Operation* );
130 /// Stops sketch operation
131 void stopSketch(ModuleBase_Operation* );
133 /// Starts sketch operation, connects to the opeation property panel
134 /// \param theOperation a committed operation
135 void startNestedSketch(ModuleBase_Operation* theOperation);
137 /// Stop sketch operation, disconnects from the opeation property panel
138 /// \param theOperation a stopped operation
139 void stopNestedSketch(ModuleBase_Operation* theOperation);
141 /// Visualizes the operation feature if it is a creation nested feature operation
142 /// \param theOperation a committed operation
143 void commitNestedSketch(ModuleBase_Operation* theOperation);
145 /// Commit the operation if it is possible. If the operation is dimention constraint,
146 /// it gives widget editor to input dimention value
147 void operationActivatedByPreselection();
149 /// Returns True if there are available Undos and the sketch manager allows undo
150 /// \return the boolean result
151 bool canUndo() const;
153 //! Returns True if there are available Redos and the sketch manager allows redo
154 /// \return the boolean result
155 bool canRedo() const;
157 /// Returns False only if the sketch creating feature can not be visualized.
158 /// \return a boolean value
159 //bool canCommitOperation() const;
161 /// Returns whether the object can be erased at the bounds of the active operation.
162 /// Sketch sub-entities can not be erased during the sketch operation
163 /// \param theObject a model object
164 bool canEraseObject(const ObjectPtr& theObject) const;
166 /// Returns whether the object can be displayed at the bounds of the active operation.
167 /// Display only current operation results for usual operation and ask the sketcher manager
168 /// if it is a sketch operation
169 /// \param theObject a model object
170 bool canDisplayObject(const ObjectPtr& theObject) const;
172 /// Check the given objects either there are some results of the current sketch. If so,
173 /// it suggests to delete them as there are no functionality to show back hidden sketch objects
174 /// \param theObjects a list of hidden objects
175 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
177 /// Returns true if the mouse is over viewer or property panel value is changed
178 /// \return boolean result
179 bool canDisplayCurrentCreatedFeature() const;
181 /// Returns true if the current operation is nested creation or internal reentrant edit
182 /// \param theOperation an operation
183 bool canChangeCursor(ModuleBase_Operation* theOperation) const;
185 /// Returns state of constraints showing flag
186 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
188 /// Returns true if the object is a current sketch sub feature of a result of the feature
189 /// \param theObject an object
190 /// \return boolean value
191 bool isObjectOfSketch(const ObjectPtr& theObject) const;
193 /// Saves the current selection in the viewer into an internal container
194 /// It obtains the selected attributes. The highlighted objects can be processes as the selected ones
195 /// \param theHighlightedOnly a boolean flag
196 void storeSelection(const bool theHighlightedOnly = false);
198 /// Restores previously saved selection state
199 void restoreSelection();
201 /// Return error state of the sketch feature, true if the error has happened
202 /// \return boolean value
203 bool sketchSolverError();
205 //! Returns the feature error if the current state of the feature in the sketch is not correct
206 //! If the feature is correct, it returns an empty value
207 //! Incorrect states: the feature is sketch, the solver error value
208 //! The feature value is reset, this is the flag of sketch mgr
209 //! \return string value
210 QString getFeatureError(const FeaturePtr& theFeature);
212 /// It nullify internal flags concerned to clicked mouse event
213 void clearClickedFlags();
215 /// Returns list of strings which contains id's of sketch operations
216 static const QStringList& sketchOperationIdList();
218 /// Returns list of strings which contains id's of constraints operations
219 static const QStringList& constraintsIdList();
221 /// Returns a list of modes, where the AIS objects should be activated
222 /// \param theModes a list of modes
223 static void sketchSelectionModes(QIntList& theModes);
225 /// Connects or disconnects to the value changed signal of the property panel widgets
226 /// \param theWidget a property contol widget
227 /// \param isToConnect a boolean value whether connect or disconnect
228 void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
230 /// Visualize the operation feature if the previous state is modified value in property panel
231 /// \param thePreviousState the previous widget value state
232 void widgetStateChanged(int thePreviousState);
235 /// Process sketch plane selected event
236 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
238 /// Toggle show constraints
239 void onShowConstraintsToggle(bool theState, int theType);
242 /// Process the enter mouse to the view port. If the current operation is a create of
243 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
244 void onEnterViewPort();
245 /// Process the leave mouse of the view port. If the current operation is a create of
246 /// a nested sketch feature, it hides the feature in the viewer
247 void onLeaveViewPort();
248 /// Listens to the value changed signal and display the current operation feature
249 void onBeforeValuesChangedInPropertyPanel();
250 /// Listens to the signal about the modification of the values have been done in the property panel
251 void onAfterValuesChangedInPropertyPanel();
253 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
254 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
255 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
256 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
257 void onApplicationStarted();
258 //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
260 void onBeforeContextMenu();
261 void onAfterContextMenu();
264 /// Launches the operation from current highlighting
265 void launchEditing();
267 /// Converts mouse position to 2d coordinates.
268 /// Member myCurrentSketch has to be correctly defined
269 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
272 typedef QMap<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
273 FeatureToSelectionMap;
275 /// Obtains the current selection of the object in the workshop viewer
276 /// It includes the selection in all modes of activation, even local context - vertices, edges
277 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
278 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
279 /// the feature, if the owner is edge, the current result is added to the container of results.
280 /// \param theFeature a feature or result object
281 /// \param theSketch a current sketch feature
282 /// \param theWorkshop a workshop to have an access to AIS context and displayer
283 /// \param theSelection a container for the selection, to save results and attributres for a feature
284 static void getCurrentSelection(const FeaturePtr& theFeature,
285 const FeaturePtr& theSketch,
286 ModuleBase_IWorkshop* theWorkshop,
287 FeatureToSelectionMap& theSelection);
289 /// Applyes the current selection to the object in the workshop viewer
290 /// It includes the selection in all modes of activation, even local context - vertexes, edges
291 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
292 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
293 /// the feature and if it is in the container of selected attributes, the owner is put in the
294 /// out container. If the owner is edge and the current result is in the container of selected
295 /// results, the owner is put in the out container.
296 /// \param theFeature a feature or result object
297 /// \param theSketch a current sketch feature
298 /// \param theWorkshop a workshop to have an access to AIS context and displayer
299 /// \param theSelection a container of the selection, it has results and attributres for a feature
300 /// \param theOwnersToSelect an out container of found owners
301 static void getSelectionOwners(const FeaturePtr& theFeature,
302 const FeaturePtr& theSketch,
303 ModuleBase_IWorkshop* theWorkshop,
304 const FeatureToSelectionMap& theSelection,
305 SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
307 /// Returns true if the created feature is visible
309 bool isVisibleCreatedFeature() const;
311 /// Returns a current operation
312 /// \return an operation
313 ModuleBase_Operation* getCurrentOperation() const;
315 /// Get the active widget in the property panel
316 ModuleBase_ModelWidget* getActiveWidget() const;
318 /// Erase or display the feature of the current operation. If the mouse over the active view or
319 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
320 /// \param theOperation an operation which feature is to be displayed, it is nested create operation
321 /// \param isToDisplay a flag about the display or erase the feature
322 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
323 const bool isToDisplay, const bool isFlushRedisplay = true);
326 /// Returns current workshop
327 XGUI_Workshop* workshop() const;
328 /// Returns operation manager
329 XGUI_OperationMgr* operationMgr() const;
332 PartSet_Module* myModule;
334 bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
337 bool myIsMouseOverWindow; /// the state that the mouse over the view
338 bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
339 bool myIsPopupMenuActive; /// the state of the popup menu is shown
340 Point myCurrentPoint;
341 //Point myClickedPoint;
343 CompositeFeaturePtr myCurrentSketch;
345 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
346 FeatureToSelectionMap myCurrentSelection;
347 bool myPreviousUpdateViewerEnabled;
349 QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;