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_Filters.h"
13 #include "PartSet_Tools.h"
15 #include <ModelAPI_Feature.h>
16 #include <ModelAPI_Attribute.h>
17 #include <ModelAPI_CompositeFeature.h>
18 #include <ModelAPI_Result.h>
20 #include <ModuleBase_ViewerFilters.h>
21 #include <ModuleBase_Definitions.h>
22 #include <ModuleBase_ModelWidget.h>
24 #include <GeomAPI_Pln.h>
25 #include <SelectMgr_IndexedMapOfOwner.hxx>
32 class ModuleBase_IViewWindow;
33 class ModuleBase_ModelWidget;
34 class ModuleBase_Operation;
35 class XGUI_OperationMgr;
38 class Handle_AIS_InteractiveObject;
44 * A class for management of sketch operations
45 At the time of the sketcher operation active, only the sketch sub-feature results are
46 displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
47 are hidden, the sketch feature result is displayed
49 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
52 /// Struct to define gp point, with the state is the point is initialized
58 myIsInitialized = false;
65 /// clear the initialized flag.
68 myIsInitialized = false;
70 /// set the point and switch on the initialized flag
71 /// \param thePoint the point
72 void setValue(const double theX, const double theY)
74 myIsInitialized = true;
79 bool myIsInitialized; /// the state whether the point is set
80 double myCurX, myCurY; /// the point coordinates
84 /// \param theModule a pointer to PartSet module
85 PartSet_SketcherMgr(PartSet_Module* theModule);
87 virtual ~PartSet_SketcherMgr();
89 /// Returns true if the operation is the sketch
90 /// \param theOperation an operation
91 /// \return the boolean result
92 static bool isSketchOperation(ModuleBase_Operation* theOperation);
94 /// Returns true if the operation id is in the sketch operation id list
95 /// \param theOperation an operation
96 /// \return the boolean result
97 static bool isNestedSketchOperation(ModuleBase_Operation* theOperation);
99 /// Returns true if the operation is a create nested feature one
100 /// \param theOperation a checked operation
101 //// \return boolean value
102 static bool isNestedCreateOperation(ModuleBase_Operation* theOperation);
104 /// Returns true if the operation is an edit nested feature one
105 /// \param theOperation a checked operation
106 //// \return boolean value
107 static bool isNestedEditOperation(ModuleBase_Operation* theOperation);
109 /// Returns whether the current operation is a sketch entity - line, point, arc or circle
110 /// \param theId is an id of object
111 /// \return a boolean value
112 static bool isEntity(const std::string& theId);
114 /// Returns whether the current operation is a sketch distance - lenght, distance or radius
115 /// \param theOperation the operation
116 /// \return a boolean value
117 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
119 /// Returns whether the feature kind is a sketch distance - lenght, distance or radius
120 /// \param theKind the feature kind
121 /// \return a boolean value
122 static bool isDistanceKind(std::string& theKind);
124 /// Returns true if a mouse cursor is over viewer window
125 bool isMouseOverWindow() { return myIsMouseOverWindow; }
127 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
128 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
130 /// Starts sketch operation
131 void startSketch(ModuleBase_Operation* );
133 /// Stops sketch operation
134 void stopSketch(ModuleBase_Operation* );
136 /// Starts sketch operation, connects to the opeation property panel
137 /// \param theOperation a committed operation
138 void startNestedSketch(ModuleBase_Operation* theOperation);
140 /// Stop sketch operation, disconnects from the opeation property panel
141 /// \param theOperation a stopped operation
142 void stopNestedSketch(ModuleBase_Operation* theOperation);
144 /// Visualizes the operation feature if it is a creation nested feature operation
145 /// \param theOperation a committed operation
146 void commitNestedSketch(ModuleBase_Operation* theOperation);
148 /// Append the sketch plane filter into the current viewer
149 /// \param toActivate state whether the filter should be activated/deactivated
150 void activatePlaneFilter(const bool& toActivate);
152 /// Commit the operation if it is possible. If the operation is dimention constraint,
153 /// it gives widget editor to input dimention value
154 /// \return true if the operation is stopped after activation
155 bool operationActivatedByPreselection();
157 /// Returns True if there are available Undos and the sketch manager allows undo
158 /// \return the boolean result
159 bool canUndo() const;
161 //! Returns True if there are available Redos and the sketch manager allows redo
162 /// \return the boolean result
163 bool canRedo() const;
165 /// Returns False only if the sketch creating feature can not be visualized.
166 /// \return a boolean value
167 //bool canCommitOperation() const;
169 /// Returns whether the object can be erased at the bounds of the active operation.
170 /// Sketch sub-entities can not be erased during the sketch operation
171 /// \param theObject a model object
172 bool canEraseObject(const ObjectPtr& theObject) const;
174 /// Returns whether the object can be displayed at the bounds of the active operation.
175 /// Display only current operation results for usual operation and ask the sketcher manager
176 /// if it is a sketch operation
177 /// \param theObject a model object
178 bool canDisplayObject(const ObjectPtr& theObject) const;
180 /// Returns whether the constraint object can be displayed. It depends on the sketch check
182 /// \param theObject a model object
183 /// \param theState the constraint visible state state to be checked
184 /// \param isProcessed an output parameter if it is processed
185 /// \return result value
186 bool canDisplayConstraint(const FeaturePtr& theObject,
187 const PartSet_Tools::ConstraintVisibleState& theState,
188 bool& isProcessed) const;
190 /// Check the given objects either there are some results of the current sketch. If so,
191 /// it suggests to delete them as there are no functionality to show back hidden sketch objects
192 /// \param theObjects a list of hidden objects
193 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
195 /// Returns true if the mouse is over viewer or property panel value is changed
196 /// \return boolean result
197 bool canDisplayCurrentCreatedFeature() const;
199 /// Returns true if the current operation is nested creation or internal reentrant edit
200 /// \param theOperation an operation
201 bool canChangeCursor(ModuleBase_Operation* theOperation) const;
203 /// Returns state of constraints showing flag
204 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
206 /// Returns true if the object is a current sketch sub feature of a result of the feature
207 /// \param theObject an object
208 /// \return boolean value
209 bool isObjectOfSketch(const ObjectPtr& theObject) const;
211 /// Saves the current selection in the viewer into an internal container
212 /// It obtains the selected attributes. The highlighted objects can be processes as the selected ones
213 /// \param theHighlightedOnly a boolean flag
214 void storeSelection(const bool theHighlightedOnly = false);
216 /// Restores previously saved selection state
217 void restoreSelection();
219 /// Return error state of the sketch feature, true if the error has happened
220 /// \return boolean value
221 bool sketchSolverError();
223 //! Returns the feature error if the current state of the feature in the sketch is not correct
224 //! If the feature is correct, it returns an empty value
225 //! Incorrect states: the feature is sketch, the solver error value
226 //! The feature value is reset, this is the flag of sketch mgr
227 //! \return string value
228 QString getFeatureError(const FeaturePtr& theFeature);
230 /// It nullify internal flags concerned to clicked mouse event
231 void clearClickedFlags();
233 /// Returns list of strings which contains id's of sketch operations
234 static const QStringList& sketchOperationIdList();
236 /// Returns list of strings which contains id's of constraints operations
237 static const QStringList& constraintsIdList();
239 /// Returns a list of modes, where the AIS objects should be activated
240 /// \param theModes a list of modes
241 static void sketchSelectionModes(QIntList& theModes);
243 /// Create specific for the module presentation
244 /// \param theResult an object for presentation
245 /// \return created presentation or NULL(default value)
246 virtual Handle_AIS_InteractiveObject createPresentation(const ResultPtr& theResult);
248 /// Connects or disconnects to the value changed signal of the property panel widgets
249 /// \param theWidget a property contol widget
250 /// \param isToConnect a boolean value whether connect or disconnect
251 void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
253 /// Visualize the operation feature if the previous state is modified value in property panel
254 /// \param thePreviousState the previous widget value state
255 void widgetStateChanged(int thePreviousState);
257 /// If the current operation is a dimention one, the style of dimension visualization is send for
258 /// the current object
259 /// \param theObject an object to be customized
260 void customizePresentation(const ObjectPtr& theObject);
262 /// Update sketch presentations according to the the state
263 /// \param theType a type of sketch visualization style
264 /// \param theState a boolean state
265 void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
269 /// Process sketch plane selected event
270 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
273 /// Toggle show constraints
274 void onShowConstraintsToggle(int theType, bool theState);
275 /// Process the enter mouse to the view port. If the current operation is a create of
276 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
277 void onEnterViewPort();
278 /// Process the leave mouse of the view port. If the current operation is a create of
279 /// a nested sketch feature, it hides the feature in the viewer
280 void onLeaveViewPort();
281 /// Listens to the value changed signal and display the current operation feature
282 void onBeforeValuesChangedInPropertyPanel();
283 /// Listens to the signal about the modification of the values have been done in the property panel
284 void onAfterValuesChangedInPropertyPanel();
286 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
287 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
288 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
289 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
290 void onApplicationStarted();
291 //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
293 void onBeforeContextMenu();
294 void onAfterContextMenu();
297 /// Launches the operation from current highlighting
298 void launchEditing();
300 /// Converts mouse position to 2d coordinates.
301 /// Member myCurrentSketch has to be correctly defined
302 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
305 /// Show distance value editor if it is a distance operation and all attribute references
306 /// are filled by preseletion
307 /// \return true if the value is accepted
308 static bool setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
309 ModuleBase_IWorkshop* theWorkshop,
310 bool& theCanCommitOperation);
312 typedef QMap<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
313 FeatureToSelectionMap;
315 /// Obtains the current selection of the object in the workshop viewer
316 /// It includes the selection in all modes of activation, even local context - vertices, edges
317 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
318 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
319 /// the feature, if the owner is edge, the current result is added to the container of results.
320 /// \param theFeature a feature or result object
321 /// \param theSketch a current sketch feature
322 /// \param theWorkshop a workshop to have an access to AIS context and displayer
323 /// \param theSelection a container for the selection, to save results and attributres for a feature
324 static void getCurrentSelection(const FeaturePtr& theFeature,
325 const FeaturePtr& theSketch,
326 ModuleBase_IWorkshop* theWorkshop,
327 FeatureToSelectionMap& theSelection);
329 /// Applyes the current selection to the object in the workshop viewer
330 /// It includes the selection in all modes of activation, even local context - vertexes, edges
331 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
332 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
333 /// the feature and if it is in the container of selected attributes, the owner is put in the
334 /// out container. If the owner is edge and the current result is in the container of selected
335 /// results, the owner is put in the out container.
336 /// \param theFeature a feature or result object
337 /// \param theSketch a current sketch feature
338 /// \param theWorkshop a workshop to have an access to AIS context and displayer
339 /// \param theSelection a container of the selection, it has results and attributres for a feature
340 /// \param theOwnersToSelect an out container of found owners
341 static void getSelectionOwners(const FeaturePtr& theFeature,
342 const FeaturePtr& theSketch,
343 ModuleBase_IWorkshop* theWorkshop,
344 const FeatureToSelectionMap& theSelection,
345 SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
347 /// Returns true if the created feature is visible
349 bool isVisibleCreatedFeature() const;
351 /// Returns a current operation
352 /// \return an operation
353 ModuleBase_Operation* getCurrentOperation() const;
355 /// Get the active widget in the property panel
356 ModuleBase_ModelWidget* getActiveWidget() const;
358 /// Erase or display the feature of the current operation. If the mouse over the active view or
359 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
360 /// \param theOperation an operation which feature is to be displayed, it is nested create operation
361 /// \param isToDisplay a flag about the display or erase the feature
362 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
363 const bool isToDisplay, const bool isFlushRedisplay = true);
366 /// Returns current workshop
367 XGUI_Workshop* workshop() const;
368 /// Returns operation manager
369 XGUI_OperationMgr* operationMgr() const;
372 PartSet_Module* myModule;
374 bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
377 bool myIsMouseOverWindow; /// the state that the mouse over the view
378 bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
379 bool myIsPopupMenuActive; /// the state of the popup menu is shown
380 Point myCurrentPoint;
381 //Point myClickedPoint;
383 CompositeFeaturePtr myCurrentSketch;
385 Handle(PartSet_CirclePointFilter) myCirclePointFilter;
386 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
387 FeatureToSelectionMap myCurrentSelection;
388 bool myPreviousUpdateViewerEnabled;
390 QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;