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 /// Append the sketch plane filter into the current viewer
146 /// \param toActivate state whether the filter should be activated/deactivated
147 void activatePlaneFilter(const bool& toActivate);
149 /// Commit the operation if it is possible. If the operation is dimention constraint,
150 /// it gives widget editor to input dimention value
151 void operationActivatedByPreselection();
153 /// Returns True if there are available Undos and the sketch manager allows undo
154 /// \return the boolean result
155 bool canUndo() const;
157 //! Returns True if there are available Redos and the sketch manager allows redo
158 /// \return the boolean result
159 bool canRedo() const;
161 /// Returns False only if the sketch creating feature can not be visualized.
162 /// \return a boolean value
163 //bool canCommitOperation() const;
165 /// Returns whether the object can be erased at the bounds of the active operation.
166 /// Sketch sub-entities can not be erased during the sketch operation
167 /// \param theObject a model object
168 bool canEraseObject(const ObjectPtr& theObject) const;
170 /// Returns whether the object can be displayed at the bounds of the active operation.
171 /// Display only current operation results for usual operation and ask the sketcher manager
172 /// if it is a sketch operation
173 /// \param theObject a model object
174 bool canDisplayObject(const ObjectPtr& theObject) const;
176 /// Returns whether the constraint object can be displayed. It depends on the sketch check
178 /// \param theObject a model object
179 /// \param theState the constraint visible state state to be checked
180 /// \param isProcessed an output parameter if it is processed
181 /// \return result value
182 bool canDisplayConstraint(const FeaturePtr& theObject,
183 const PartSet_Tools::ConstraintVisibleState& theState,
184 bool& isProcessed) const;
186 /// Check the given objects either there are some results of the current sketch. If so,
187 /// it suggests to delete them as there are no functionality to show back hidden sketch objects
188 /// \param theObjects a list of hidden objects
189 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
191 /// Returns true if the mouse is over viewer or property panel value is changed
192 /// \return boolean result
193 bool canDisplayCurrentCreatedFeature() const;
195 /// Returns true if the current operation is nested creation or internal reentrant edit
196 /// \param theOperation an operation
197 bool canChangeCursor(ModuleBase_Operation* theOperation) const;
199 /// Returns state of constraints showing flag
200 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
202 /// Returns true if the object is a current sketch sub feature of a result of the feature
203 /// \param theObject an object
204 /// \return boolean value
205 bool isObjectOfSketch(const ObjectPtr& theObject) const;
207 /// Saves the current selection in the viewer into an internal container
208 /// It obtains the selected attributes. The highlighted objects can be processes as the selected ones
209 /// \param theHighlightedOnly a boolean flag
210 void storeSelection(const bool theHighlightedOnly = false);
212 /// Restores previously saved selection state
213 void restoreSelection();
215 /// Return error state of the sketch feature, true if the error has happened
216 /// \return boolean value
217 bool sketchSolverError();
219 //! Returns the feature error if the current state of the feature in the sketch is not correct
220 //! If the feature is correct, it returns an empty value
221 //! Incorrect states: the feature is sketch, the solver error value
222 //! The feature value is reset, this is the flag of sketch mgr
223 //! \return string value
224 QString getFeatureError(const FeaturePtr& theFeature);
226 /// It nullify internal flags concerned to clicked mouse event
227 void clearClickedFlags();
229 /// Returns list of strings which contains id's of sketch operations
230 static const QStringList& sketchOperationIdList();
232 /// Returns list of strings which contains id's of constraints operations
233 static const QStringList& constraintsIdList();
235 /// Returns a list of modes, where the AIS objects should be activated
236 /// \param theModes a list of modes
237 static void sketchSelectionModes(QIntList& theModes);
239 /// Connects or disconnects to the value changed signal of the property panel widgets
240 /// \param theWidget a property contol widget
241 /// \param isToConnect a boolean value whether connect or disconnect
242 void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
244 /// Visualize the operation feature if the previous state is modified value in property panel
245 /// \param thePreviousState the previous widget value state
246 void widgetStateChanged(int thePreviousState);
249 /// Process sketch plane selected event
250 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
252 /// Toggle show constraints
253 void onShowConstraintsToggle(int theType, bool theState);
256 /// Process the enter mouse to the view port. If the current operation is a create of
257 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
258 void onEnterViewPort();
259 /// Process the leave mouse of the view port. If the current operation is a create of
260 /// a nested sketch feature, it hides the feature in the viewer
261 void onLeaveViewPort();
262 /// Listens to the value changed signal and display the current operation feature
263 void onBeforeValuesChangedInPropertyPanel();
264 /// Listens to the signal about the modification of the values have been done in the property panel
265 void onAfterValuesChangedInPropertyPanel();
267 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
268 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
269 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
270 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
271 void onApplicationStarted();
272 //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
274 void onBeforeContextMenu();
275 void onAfterContextMenu();
278 /// Launches the operation from current highlighting
279 void launchEditing();
281 /// Converts mouse position to 2d coordinates.
282 /// Member myCurrentSketch has to be correctly defined
283 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
286 typedef QMap<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
287 FeatureToSelectionMap;
289 /// Obtains the current selection of the object in the workshop viewer
290 /// It includes the selection in all modes of activation, even local context - vertices, 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, if the owner is edge, the current result is added to the container of results.
294 /// \param theFeature a feature or result object
295 /// \param theSketch a current sketch feature
296 /// \param theWorkshop a workshop to have an access to AIS context and displayer
297 /// \param theSelection a container for the selection, to save results and attributres for a feature
298 static void getCurrentSelection(const FeaturePtr& theFeature,
299 const FeaturePtr& theSketch,
300 ModuleBase_IWorkshop* theWorkshop,
301 FeatureToSelectionMap& theSelection);
303 /// Applyes the current selection to the object in the workshop viewer
304 /// It includes the selection in all modes of activation, even local context - vertexes, edges
305 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
306 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
307 /// the feature and if it is in the container of selected attributes, the owner is put in the
308 /// out container. If the owner is edge and the current result is in the container of selected
309 /// results, the owner is put in the out container.
310 /// \param theFeature a feature or result object
311 /// \param theSketch a current sketch feature
312 /// \param theWorkshop a workshop to have an access to AIS context and displayer
313 /// \param theSelection a container of the selection, it has results and attributres for a feature
314 /// \param theOwnersToSelect an out container of found owners
315 static void getSelectionOwners(const FeaturePtr& theFeature,
316 const FeaturePtr& theSketch,
317 ModuleBase_IWorkshop* theWorkshop,
318 const FeatureToSelectionMap& theSelection,
319 SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
321 /// Returns true if the created feature is visible
323 bool isVisibleCreatedFeature() const;
325 /// Returns a current operation
326 /// \return an operation
327 ModuleBase_Operation* getCurrentOperation() const;
329 /// Get the active widget in the property panel
330 ModuleBase_ModelWidget* getActiveWidget() const;
332 /// Erase or display the feature of the current operation. If the mouse over the active view or
333 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
334 /// \param theOperation an operation which feature is to be displayed, it is nested create operation
335 /// \param isToDisplay a flag about the display or erase the feature
336 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
337 const bool isToDisplay, const bool isFlushRedisplay = true);
340 /// Returns current workshop
341 XGUI_Workshop* workshop() const;
342 /// Returns operation manager
343 XGUI_OperationMgr* operationMgr() const;
346 PartSet_Module* myModule;
348 bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
351 bool myIsMouseOverWindow; /// the state that the mouse over the view
352 bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
353 bool myIsPopupMenuActive; /// the state of the popup menu is shown
354 Point myCurrentPoint;
355 //Point myClickedPoint;
357 CompositeFeaturePtr myCurrentSketch;
359 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
360 FeatureToSelectionMap myCurrentSelection;
361 bool myPreviousUpdateViewerEnabled;
363 QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;