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 feature kind belongs to list of granted features of Sketch
115 /// operation. An operation of a sketch should be started before.
116 /// \param theOperation an operation
117 /// \return the boolean result
118 bool isNestedSketchFeature(const QString& theFeatureKind) const;
120 /// Returns true if the operation is a create and nested sketch operationn
121 /// \param theOperation a checked operation
122 /// \param theSketch a sketch feature
123 //// \return boolean value
124 bool isNestedCreateOperation(ModuleBase_Operation* theOperation,
125 const CompositeFeaturePtr& /*theSketch*/) const;
127 /// Returns true if the operation is an edit nested feature one
128 /// \param theOperation a checked operation
129 //// \return boolean value
130 bool isNestedEditOperation(ModuleBase_Operation* theOperation,
131 const CompositeFeaturePtr& /*theSketch*/) const;
133 /// Returns whether the current operation is a sketch entity - line, point, arc or circle
134 /// \param theId is an id of object
135 /// \return a boolean value
136 static bool isEntity(const std::string& theId);
138 /// Returns whether the feature has external attribute filled with 'true' value
139 /// \param theFeature a feature object
140 /// \return a boolean value
141 static bool isExternalFeature(const FeaturePtr& theFeature);
143 /// Returns whether the current operation is a sketch distance - lenght, distance or radius
144 /// \param theOperation the operation
145 /// \return a boolean value
146 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
148 /// Returns whether the feature kind is a sketch distance - lenght, distance or radius
149 /// \param theKind the feature kind
150 /// \return a boolean value
151 static bool isDistanceKind(std::string& theKind);
153 /// Returns true if a mouse cursor is over viewer window
154 bool isMouseOverWindow() { return myIsMouseOverWindow; }
156 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
157 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
159 /// Starts sketch operation
160 void startSketch(ModuleBase_Operation* );
162 /// Stops sketch operation
163 void stopSketch(ModuleBase_Operation* );
165 /// Starts sketch operation, connects to the opeation property panel
166 /// \param theOperation a committed operation
167 void startNestedSketch(ModuleBase_Operation* theOperation);
169 /// Stop sketch operation, disconnects from the opeation property panel
170 /// \param theOperation a stopped operation
171 void stopNestedSketch(ModuleBase_Operation* theOperation);
173 /// Visualizes the operation feature if it is a creation nested feature operation
174 /// \param theOperation a committed operation
175 void commitNestedSketch(ModuleBase_Operation* theOperation);
177 /// Append the sketch plane filter into the current viewer
178 /// \param toActivate state whether the filter should be activated/deactivated
179 void activatePlaneFilter(const bool& toActivate);
181 /// Commit the operation if it is possible. If the operation is dimention constraint,
182 /// it gives widget editor to input dimention value
183 /// \return true if the operation is stopped after activation
184 bool operationActivatedByPreselection();
186 /// Returns True if there are available Undos and the sketch manager allows undo
187 /// \return the boolean result
188 bool canUndo() const;
190 //! Returns True if there are available Redos and the sketch manager allows redo
191 /// \return the boolean result
192 bool canRedo() const;
194 /// Returns False only if the sketch creating feature can not be visualized.
195 /// \return a boolean value
196 //bool canCommitOperation() const;
198 /// Returns whether the object can be erased at the bounds of the active operation.
199 /// Sketch sub-entities can not be erased during the sketch operation
200 /// \param theObject a model object
201 bool canEraseObject(const ObjectPtr& theObject) const;
203 /// Returns whether the object can be displayed at the bounds of the active operation.
204 /// Display only current operation results for usual operation and ask the sketcher manager
205 /// if it is a sketch operation
206 /// \param theObject a model object
207 bool canDisplayObject(const ObjectPtr& theObject) const;
209 /// Returns whether the constraint object can be displayed. It depends on the sketch check
211 /// \param theObject a model object
212 /// \param theState the constraint visible state state to be checked
213 /// \param isProcessed an output parameter if it is processed
214 /// \return result value
215 bool canDisplayConstraint(const FeaturePtr& theObject,
216 const PartSet_Tools::ConstraintVisibleState& theState,
217 bool& isProcessed) const;
219 /// Check the given objects either there are some results of the current sketch. If so,
220 /// it suggests to delete them as there are no functionality to show back hidden sketch objects
221 /// \param theObjects a list of hidden objects
222 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
224 /// Returns true if the mouse is over viewer or property panel value is changed
225 /// \return boolean result
226 bool canDisplayCurrentCreatedFeature() const;
228 /// Returns true if the current operation is nested creation or internal reentrant edit
229 /// \param theOperation an operation
230 bool canChangeCursor(ModuleBase_Operation* theOperation) const;
232 /// Returns state of constraints showing flag
233 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
235 /// Returns true if the object is a current sketch sub feature of a result of the feature
236 /// \param theObject an object
237 /// \return boolean value
238 bool isObjectOfSketch(const ObjectPtr& theObject) const;
240 /// Enumeration for selection mode used
242 ST_HighlightType, /// Only highlighted objects
243 ST_SelectType, /// Only selected objects
244 ST_SelectAndHighlightType /// Both, highlighted and selected objects
247 /// Saves the current selection in the viewer into an internal container
248 /// It obtains the selected attributes.
249 /// The highlighted objects can be processes as the selected ones
250 /// \param theHighlightedOnly a boolean flag
251 /// \param theCurrentSelection a container filled by the current selection
252 void storeSelection(const SelectionType theType, FeatureToSelectionMap& theCurrentSelection);
254 /// Restores previously saved selection state
255 /// \param theCurrentSelection a container filled by the current selection
256 void restoreSelection(FeatureToSelectionMap& theCurrentSelection);
258 /// Return error state of the sketch feature, true if the error has happened
259 /// \return boolean value
260 bool sketchSolverError();
262 //! Returns the feature error if the current state of the feature in the sketch is not correct
263 //! If the feature is correct, it returns an empty value
264 //! Incorrect states: the feature is sketch, the solver error value
265 //! The feature value is reset, this is the flag of sketch mgr
266 //! \return string value
267 QString getFeatureError(const FeaturePtr& theFeature);
269 /// It nullify internal flags concerned to clicked mouse event
270 void clearClickedFlags();
272 /// Returns list of strings which contains id's of sketch replication operations
273 static const QStringList& replicationsIdList();
275 /// Returns list of strings which contains id's of constraints operations
276 static const QStringList& constraintsIdList();
278 /// Returns a list of modes, where the AIS objects should be activated
279 /// \param theModes a list of modes
280 static void sketchSelectionModes(QIntList& theModes);
282 /// Create specific for the module presentation
283 /// \param theResult an object for presentation
284 /// \return created presentation or NULL(default value)
285 virtual Handle(AIS_InteractiveObject) createPresentation(const ResultPtr& theResult);
287 /// Connects or disconnects to the value changed signal of the property panel widgets
288 /// \param theWidget a property contol widget
289 /// \param isToConnect a boolean value whether connect or disconnect
290 void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
292 /// Visualize the operation feature if the previous state is modified value in property panel
293 /// \param thePreviousState the previous widget value state
294 void widgetStateChanged(int thePreviousState);
296 /// If the current operation is a dimention one, the style of dimension visualization is send for
297 /// the current object
298 /// \param theObject an object to be customized
299 void customizePresentation(const ObjectPtr& theObject);
301 /// Update sketch presentations according to the the state
302 /// \param theType a type of sketch visualization style
303 /// \param theState a boolean state
304 void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
308 /// Process sketch plane selected event
309 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
312 /// Toggle show constraints
313 void onShowConstraintsToggle(int theType, bool theState);
314 /// Process the enter mouse to the view port. If the current operation is a create of
315 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
316 void onEnterViewPort();
317 /// Process the leave mouse of the view port. If the current operation is a create of
318 /// a nested sketch feature, it hides the feature in the viewer
319 void onLeaveViewPort();
320 /// Listens to the value changed signal and display the current operation feature
321 //void onBeforeValuesChangedInPropertyPanel();
322 /// Listens to the signal about the modification of the values
323 /// have been done in the property panel
324 //void onAfterValuesChangedInPropertyPanel();
326 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
327 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
328 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
329 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
330 void onApplicationStarted();
331 //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
333 void onBeforeContextMenu();
334 void onAfterContextMenu();
337 /// Launches the operation from current highlighting
338 void launchEditing();
340 /// Converts mouse position to 2d coordinates.
341 /// Member myCurrentSketch has to be correctly defined
342 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
345 /// Show distance value editor if it is a distance operation and all attribute references
346 /// are filled by preseletion
347 /// \return true if the value is accepted
348 static bool setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
349 ModuleBase_IWorkshop* theWorkshop,
350 bool& theCanCommitOperation);
352 /// Applyes the current selection to the object in the workshop viewer
353 /// It includes the selection in all modes of activation, even local context - vertexes, edges
354 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
355 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
356 /// the feature and if it is in the container of selected attributes, the owner is put in the
357 /// out container. If the owner is edge and the current result is in the container of selected
358 /// results, the owner is put in the out container.
359 /// \param theFeature a feature or result object
360 /// \param theSketch a current sketch feature
361 /// \param theWorkshop a workshop to have an access to AIS context and displayer
362 /// \param theSelection a container of the selection, it has results and attributres for a feature
363 /// \param theOwnersToSelect an out container of found owners
364 static void getSelectionOwners(const FeaturePtr& theFeature,
365 const FeaturePtr& theSketch,
366 ModuleBase_IWorkshop* theWorkshop,
367 const FeatureToSelectionMap& theSelection,
368 SelectMgr_IndexedMapOfOwner& theOwnersToSelect);
370 /// Returns true if the created feature is visible
372 bool isVisibleCreatedFeature() const;
374 /// Returns a current operation
375 /// \return an operation
376 ModuleBase_Operation* getCurrentOperation() const;
378 /// Get the active widget in the property panel
379 ModuleBase_ModelWidget* getActiveWidget() const;
381 /// Erase or display the feature of the current operation. If the mouse over the active view or
382 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
383 /// \param theOperation an operation which feature is to be displayed,
384 /// it is nested create operation
385 /// \param isToDisplay a flag about the display or erase the feature
386 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
387 const bool isToDisplay, const bool isFlushRedisplay = true);
390 /// Updates selection priority of the presentation
391 /// \param theObject object to find a presentation which will be corrected
392 /// \param theFeature a feature of the presentation
393 void updateSelectionPriority(ObjectPtr theObject, FeaturePtr theFeature);
394 /// Returns current workshop
395 XGUI_Workshop* workshop() const;
396 /// Returns operation manager
397 XGUI_OperationMgr* operationMgr() const;
400 PartSet_Module* myModule;
402 bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
403 bool myIsEditLaunching;
406 bool myIsMouseOverWindow; /// the state that the mouse over the view
407 /// the state whether the over view state is processed by mouseMove method
408 bool myIsMouseOverViewProcessed;
409 bool myIsPopupMenuActive; /// the state of the popup menu is shown
410 Point myCurrentPoint;
411 //Point myClickedPoint;
413 CompositeFeaturePtr myCurrentSketch;
415 Handle(PartSet_CirclePointFilter) myCirclePointFilter;
416 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
417 FeatureToSelectionMap myCurrentSelection;
418 bool myPreviousUpdateViewerEnabled;
420 QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;