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>
26 #include <TopoDS_Shape.hxx>
27 #include <TopTools_MapOfShape.hxx>
34 class ModuleBase_IViewWindow;
35 class ModuleBase_ModelWidget;
36 class ModuleBase_Operation;
37 class XGUI_OperationMgr;
40 class AIS_InteractiveObject;
46 * A class for management of sketch operations
47 At the time of the sketcher operation active, only the sketch sub-feature results are
48 displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
49 are hidden, the sketch feature result is displayed
51 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
54 /// Struct to define gp point, with the state is the point is initialized
60 myIsInitialized = false;
67 /// clear the initialized flag.
70 myIsInitialized = false;
72 /// set the point and switch on the initialized flag
73 /// \param thePoint the point
74 void setValue(const double theX, const double theY)
76 myIsInitialized = true;
81 bool myIsInitialized; /// the state whether the point is set
82 double myCurX, myCurY; /// the point coordinates
86 /// Struct to define selection model information to store/restore selection
89 std::set<AttributePtr> myAttributes; /// the selected attributes
90 std::set<ResultPtr> myResults; /// the selected results
91 TopoDS_Shape myFirstResultShape; /// the first shape of feature result
92 TopTools_MapOfShape myLocalSelectedShapes; /// shapes of local selection
94 typedef QMap<FeaturePtr, SelectionInfo> FeatureToSelectionMap;
98 /// \param theModule a pointer to PartSet module
99 PartSet_SketcherMgr(PartSet_Module* theModule);
101 virtual ~PartSet_SketcherMgr();
103 /// Returns true if the operation is the sketch
104 /// \param theOperation an operation
105 /// \return the boolean result
106 static bool isSketchOperation(ModuleBase_Operation* theOperation);
108 /// Returns true if the operation feature belongs to list of granted features of Sketch
109 /// operation. An operation of a sketch should be started before.
110 /// \param theOperation an operation
111 /// \return the boolean result
112 bool isNestedSketchOperation(ModuleBase_Operation* theOperation) const;
114 /// Returns true if the operation is a create and nested sketch operationn
115 /// \param theOperation a checked operation
116 /// \param theSketch a sketch feature
117 //// \return boolean value
118 bool isNestedCreateOperation(ModuleBase_Operation* theOperation,
119 const CompositeFeaturePtr& /*theSketch*/) const;
121 /// Returns true if the operation is an edit nested feature one
122 /// \param theOperation a checked operation
123 //// \return boolean value
124 bool isNestedEditOperation(ModuleBase_Operation* theOperation,
125 const CompositeFeaturePtr& /*theSketch*/) const;
127 /// Returns whether the current operation is a sketch entity - line, point, arc or circle
128 /// \param theId is an id of object
129 /// \return a boolean value
130 static bool isEntity(const std::string& theId);
132 /// Returns whether the feature has external attribute filled with 'true' value
133 /// \param theFeature a feature object
134 /// \return a boolean value
135 static bool isExternalFeature(const FeaturePtr& theFeature);
137 /// Returns whether the current operation is a sketch distance - lenght, distance or radius
138 /// \param theOperation the operation
139 /// \return a boolean value
140 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
142 /// Returns whether the feature kind is a sketch distance - lenght, distance or radius
143 /// \param theKind the feature kind
144 /// \return a boolean value
145 static bool isDistanceKind(std::string& theKind);
147 /// Returns true if a mouse cursor is over viewer window
148 bool isMouseOverWindow() { return myIsMouseOverWindow; }
150 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
151 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
153 /// Starts sketch operation
154 void startSketch(ModuleBase_Operation* );
156 /// Stops sketch operation
157 void stopSketch(ModuleBase_Operation* );
159 /// Starts sketch operation, connects to the opeation property panel
160 /// \param theOperation a committed operation
161 void startNestedSketch(ModuleBase_Operation* theOperation);
163 /// Stop sketch operation, disconnects from the opeation property panel
164 /// \param theOperation a stopped operation
165 void stopNestedSketch(ModuleBase_Operation* theOperation);
167 /// Visualizes the operation feature if it is a creation nested feature operation
168 /// \param theOperation a committed operation
169 void commitNestedSketch(ModuleBase_Operation* theOperation);
171 /// Append the sketch plane filter into the current viewer
172 /// \param toActivate state whether the filter should be activated/deactivated
173 void activatePlaneFilter(const bool& toActivate);
175 /// Commit the operation if it is possible. If the operation is dimention constraint,
176 /// it gives widget editor to input dimention value
177 /// \return true if the operation is stopped after activation
178 bool operationActivatedByPreselection();
180 /// Returns True if there are available Undos and the sketch manager allows undo
181 /// \return the boolean result
182 bool canUndo() const;
184 //! Returns True if there are available Redos and the sketch manager allows redo
185 /// \return the boolean result
186 bool canRedo() const;
188 /// Returns False only if the sketch creating feature can not be visualized.
189 /// \return a boolean value
190 //bool canCommitOperation() const;
192 /// Returns whether the object can be erased at the bounds of the active operation.
193 /// Sketch sub-entities can not be erased during the sketch operation
194 /// \param theObject a model object
195 bool canEraseObject(const ObjectPtr& theObject) const;
197 /// Returns whether the object can be displayed at the bounds of the active operation.
198 /// Display only current operation results for usual operation and ask the sketcher manager
199 /// if it is a sketch operation
200 /// \param theObject a model object
201 bool canDisplayObject(const ObjectPtr& theObject) const;
203 /// Returns whether the constraint object can be displayed. It depends on the sketch check
205 /// \param theObject a model object
206 /// \param theState the constraint visible state state to be checked
207 /// \param isProcessed an output parameter if it is processed
208 /// \return result value
209 bool canDisplayConstraint(const FeaturePtr& theObject,
210 const PartSet_Tools::ConstraintVisibleState& theState,
211 bool& isProcessed) const;
213 /// Check the given objects either there are some results of the current sketch. If so,
214 /// it suggests to delete them as there are no functionality to show back hidden sketch objects
215 /// \param theObjects a list of hidden objects
216 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
218 /// Returns true if the mouse is over viewer or property panel value is changed
219 /// \return boolean result
220 bool canDisplayCurrentCreatedFeature() const;
222 /// Returns true if the current operation is nested creation or internal reentrant edit
223 /// \param theOperation an operation
224 bool canChangeCursor(ModuleBase_Operation* theOperation) const;
226 /// Returns state of constraints showing flag
227 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
229 /// Returns true if the object is a current sketch sub feature of a result of the feature
230 /// \param theObject an object
231 /// \return boolean value
232 bool isObjectOfSketch(const ObjectPtr& theObject) const;
234 /// Enumeration for selection mode used
236 ST_HighlightType, /// Only highlighted objects
237 ST_SelectType, /// Only selected objects
238 ST_SelectAndHighlightType /// Both, highlighted and selected objects
241 /// Saves the current selection in the viewer into an internal container
242 /// It obtains the selected attributes.
243 /// The highlighted objects can be processes as the selected ones
244 /// \param theHighlightedOnly a boolean flag
245 /// \param theCurrentSelection a container filled by the current selection
246 void storeSelection(const SelectionType theType, FeatureToSelectionMap& theCurrentSelection);
248 /// Restores previously saved selection state
249 /// \param theCurrentSelection a container filled by the current selection
250 void restoreSelection(FeatureToSelectionMap& theCurrentSelection);
252 /// Return error state of the sketch feature, true if the error has happened
253 /// \return boolean value
254 bool sketchSolverError();
256 //! Returns the feature error if the current state of the feature in the sketch is not correct
257 //! If the feature is correct, it returns an empty value
258 //! Incorrect states: the feature is sketch, the solver error value
259 //! The feature value is reset, this is the flag of sketch mgr
260 //! \return string value
261 QString getFeatureError(const FeaturePtr& theFeature);
263 /// It nullify internal flags concerned to clicked mouse event
264 void clearClickedFlags();
266 /// Returns list of strings which contains id's of sketch replication operations
267 static const QStringList& replicationsIdList();
269 /// Returns list of strings which contains id's of constraints operations
270 static const QStringList& constraintsIdList();
272 /// Returns a list of modes, where the AIS objects should be activated
273 /// \param theModes a list of modes
274 static void sketchSelectionModes(QIntList& theModes);
276 /// Create specific for the module presentation
277 /// \param theResult an object for presentation
278 /// \return created presentation or NULL(default value)
279 virtual Handle(AIS_InteractiveObject) createPresentation(const ResultPtr& theResult);
281 /// Connects or disconnects to the value changed signal of the property panel widgets
282 /// \param theWidget a property contol widget
283 /// \param isToConnect a boolean value whether connect or disconnect
284 void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
286 /// Visualize the operation feature if the previous state is modified value in property panel
287 /// \param thePreviousState the previous widget value state
288 void widgetStateChanged(int thePreviousState);
290 /// If the current operation is a dimention one, the style of dimension visualization is send for
291 /// the current object
292 /// \param theObject an object to be customized
293 void customizePresentation(const ObjectPtr& theObject);
295 /// Update sketch presentations according to the the state
296 /// \param theType a type of sketch visualization style
297 /// \param theState a boolean state
298 void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
302 /// Process sketch plane selected event
303 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
306 /// Toggle show constraints
307 void onShowConstraintsToggle(int theType, bool theState);
308 /// Process the enter mouse to the view port. If the current operation is a create of
309 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
310 void onEnterViewPort();
311 /// Process the leave mouse of the view port. If the current operation is a create of
312 /// a nested sketch feature, it hides the feature in the viewer
313 void onLeaveViewPort();
314 /// Listens to the value changed signal and display the current operation feature
315 //void onBeforeValuesChangedInPropertyPanel();
316 /// Listens to the signal about the modification of the values
317 /// have been done in the property panel
318 //void onAfterValuesChangedInPropertyPanel();
320 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
321 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
322 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
323 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
324 void onApplicationStarted();
325 //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
327 void onBeforeContextMenu();
328 void onAfterContextMenu();
331 /// Launches the operation from current highlighting
332 void launchEditing();
334 /// Converts mouse position to 2d coordinates.
335 /// Member myCurrentSketch has to be correctly defined
336 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
339 /// Show distance value editor if it is a distance operation and all attribute references
340 /// are filled by preseletion
341 /// \return true if the value is accepted
342 static bool setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
343 ModuleBase_IWorkshop* theWorkshop,
344 bool& theCanCommitOperation);
346 /// Applyes the current selection to the object in the workshop viewer
347 /// It includes the selection in all modes of activation, even local context - vertexes, edges
348 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
349 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
350 /// the feature and if it is in the container of selected attributes, the owner is put in the
351 /// out container. If the owner is edge and the current result is in the container of selected
352 /// results, the owner is put in the out container.
353 /// \param theFeature a feature or result object
354 /// \param theSketch a current sketch feature
355 /// \param theWorkshop a workshop to have an access to AIS context and displayer
356 /// \param theSelection a container of the selection, it has results and attributres for a feature
357 /// \param theOwnersToSelect an out container of found owners
358 static void getSelectionOwners(const FeaturePtr& theFeature,
359 const FeaturePtr& theSketch,
360 ModuleBase_IWorkshop* theWorkshop,
361 const FeatureToSelectionMap& theSelection,
362 SelectMgr_IndexedMapOfOwner& theOwnersToSelect);
364 /// Returns true if the created feature is visible
366 bool isVisibleCreatedFeature() const;
368 /// Returns a current operation
369 /// \return an operation
370 ModuleBase_Operation* getCurrentOperation() const;
372 /// Get the active widget in the property panel
373 ModuleBase_ModelWidget* getActiveWidget() const;
375 /// Erase or display the feature of the current operation. If the mouse over the active view or
376 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
377 /// \param theOperation an operation which feature is to be displayed,
378 /// it is nested create operation
379 /// \param isToDisplay a flag about the display or erase the feature
380 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
381 const bool isToDisplay, const bool isFlushRedisplay = true);
384 /// Updates selection priority of the presentation
385 /// \param theObject object to find a presentation which will be corrected
386 /// \param theFeature a feature of the presentation
387 void updateSelectionPriority(ObjectPtr theObject, FeaturePtr theFeature);
388 /// Returns current workshop
389 XGUI_Workshop* workshop() const;
390 /// Returns operation manager
391 XGUI_OperationMgr* operationMgr() const;
394 PartSet_Module* myModule;
396 bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
397 bool myIsEditLaunching;
400 bool myIsMouseOverWindow; /// the state that the mouse over the view
401 /// the state whether the over view state is processed by mouseMove method
402 bool myIsMouseOverViewProcessed;
403 bool myIsPopupMenuActive; /// the state of the popup menu is shown
404 Point myCurrentPoint;
405 //Point myClickedPoint;
407 CompositeFeaturePtr myCurrentSketch;
409 Handle(PartSet_CirclePointFilter) myCirclePointFilter;
410 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
411 FeatureToSelectionMap myCurrentSelection;
412 bool myPreviousUpdateViewerEnabled;
414 QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;