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 /// Saves the current selection in the viewer into an internal container
235 /// It obtains the selected attributes.
236 /// The highlighted objects can be processes as the selected ones
237 /// \param theHighlightedOnly a boolean flag
238 /// \param theCurrentSelection a container filled by the current selection
239 void storeSelection(const bool theHighlightedOnly, FeatureToSelectionMap& theCurrentSelection);
241 /// Restores previously saved selection state
242 /// \param theCurrentSelection a container filled by the current selection
243 void restoreSelection(FeatureToSelectionMap& theCurrentSelection);
245 /// Return error state of the sketch feature, true if the error has happened
246 /// \return boolean value
247 bool sketchSolverError();
249 //! Returns the feature error if the current state of the feature in the sketch is not correct
250 //! If the feature is correct, it returns an empty value
251 //! Incorrect states: the feature is sketch, the solver error value
252 //! The feature value is reset, this is the flag of sketch mgr
253 //! \return string value
254 QString getFeatureError(const FeaturePtr& theFeature);
256 /// It nullify internal flags concerned to clicked mouse event
257 void clearClickedFlags();
259 /// Returns list of strings which contains id's of sketch replication operations
260 static const QStringList& replicationsIdList();
262 /// Returns list of strings which contains id's of constraints operations
263 static const QStringList& constraintsIdList();
265 /// Returns a list of modes, where the AIS objects should be activated
266 /// \param theModes a list of modes
267 static void sketchSelectionModes(QIntList& theModes);
269 /// Create specific for the module presentation
270 /// \param theResult an object for presentation
271 /// \return created presentation or NULL(default value)
272 virtual Handle(AIS_InteractiveObject) createPresentation(const ResultPtr& theResult);
274 /// Connects or disconnects to the value changed signal of the property panel widgets
275 /// \param theWidget a property contol widget
276 /// \param isToConnect a boolean value whether connect or disconnect
277 void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
279 /// Visualize the operation feature if the previous state is modified value in property panel
280 /// \param thePreviousState the previous widget value state
281 void widgetStateChanged(int thePreviousState);
283 /// If the current operation is a dimention one, the style of dimension visualization is send for
284 /// the current object
285 /// \param theObject an object to be customized
286 void customizePresentation(const ObjectPtr& theObject);
288 /// Update sketch presentations according to the the state
289 /// \param theType a type of sketch visualization style
290 /// \param theState a boolean state
291 void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
295 /// Process sketch plane selected event
296 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
299 /// Toggle show constraints
300 void onShowConstraintsToggle(int theType, bool theState);
301 /// Process the enter mouse to the view port. If the current operation is a create of
302 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
303 void onEnterViewPort();
304 /// Process the leave mouse of the view port. If the current operation is a create of
305 /// a nested sketch feature, it hides the feature in the viewer
306 void onLeaveViewPort();
307 /// Listens to the value changed signal and display the current operation feature
308 //void onBeforeValuesChangedInPropertyPanel();
309 /// Listens to the signal about the modification of the values
310 /// have been done in the property panel
311 //void onAfterValuesChangedInPropertyPanel();
313 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
314 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
315 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
316 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
317 void onApplicationStarted();
318 //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
320 void onBeforeContextMenu();
321 void onAfterContextMenu();
324 /// Launches the operation from current highlighting
325 void launchEditing();
327 /// Converts mouse position to 2d coordinates.
328 /// Member myCurrentSketch has to be correctly defined
329 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
332 /// Show distance value editor if it is a distance operation and all attribute references
333 /// are filled by preseletion
334 /// \return true if the value is accepted
335 static bool setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
336 ModuleBase_IWorkshop* theWorkshop,
337 bool& theCanCommitOperation);
339 /// Applyes the current selection to the object in the workshop viewer
340 /// It includes the selection in all modes of activation, even local context - vertexes, edges
341 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
342 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
343 /// the feature and if it is in the container of selected attributes, the owner is put in the
344 /// out container. If the owner is edge and the current result is in the container of selected
345 /// results, the owner is put in the out container.
346 /// \param theFeature a feature or result object
347 /// \param theSketch a current sketch feature
348 /// \param theWorkshop a workshop to have an access to AIS context and displayer
349 /// \param theSelection a container of the selection, it has results and attributres for a feature
350 /// \param theOwnersToSelect an out container of found owners
351 static void getSelectionOwners(const FeaturePtr& theFeature,
352 const FeaturePtr& theSketch,
353 ModuleBase_IWorkshop* theWorkshop,
354 const FeatureToSelectionMap& theSelection,
355 SelectMgr_IndexedMapOfOwner& theOwnersToSelect);
357 /// Returns true if the created feature is visible
359 bool isVisibleCreatedFeature() const;
361 /// Returns a current operation
362 /// \return an operation
363 ModuleBase_Operation* getCurrentOperation() const;
365 /// Get the active widget in the property panel
366 ModuleBase_ModelWidget* getActiveWidget() const;
368 /// Erase or display the feature of the current operation. If the mouse over the active view or
369 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
370 /// \param theOperation an operation which feature is to be displayed,
371 /// it is nested create operation
372 /// \param isToDisplay a flag about the display or erase the feature
373 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
374 const bool isToDisplay, const bool isFlushRedisplay = true);
377 /// Updates selection priority of the presentation
378 /// \param theObject object to find a presentation which will be corrected
379 /// \param theFeature a feature of the presentation
380 void updateSelectionPriority(ObjectPtr theObject, FeaturePtr theFeature);
381 /// Returns current workshop
382 XGUI_Workshop* workshop() const;
383 /// Returns operation manager
384 XGUI_OperationMgr* operationMgr() const;
387 PartSet_Module* myModule;
389 bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
390 bool myIsEditLaunching;
393 bool myIsMouseOverWindow; /// the state that the mouse over the view
394 /// the state whether the over view state is processed by mouseMove method
395 bool myIsMouseOverViewProcessed;
396 bool myIsPopupMenuActive; /// the state of the popup menu is shown
397 Point myCurrentPoint;
398 //Point myClickedPoint;
400 CompositeFeaturePtr myCurrentSketch;
402 Handle(PartSet_CirclePointFilter) myCirclePointFilter;
403 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
404 FeatureToSelectionMap myCurrentSelection;
405 bool myPreviousUpdateViewerEnabled;
407 QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;