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_FilterInfinite.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>
22 #include <GeomAPI_Pln.h>
23 #include <SelectMgr_IndexedMapOfOwner.hxx>
30 class ModuleBase_IViewWindow;
31 class ModuleBase_ModelWidget;
32 class ModuleBase_Operation;
37 * A class for management of sketch operations
38 At the time of the sketcher operation active, only the sketch sub-feature results are
39 displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
40 are hidden, the sketch feature result is displayed
42 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
45 /// Struct to define gp point, with the state is the point is initialized
51 myIsInitialized = false;
58 /// clear the initialized flag.
61 myIsInitialized = false;
63 /// set the point and switch on the initialized flag
64 /// \param thePoint the point
65 void setValue(const double theX, const double theY)
67 myIsInitialized = true;
72 bool myIsInitialized; /// the state whether the point is set
73 double myCurX, myCurY; /// the point coordinates
77 /// \param theModule a pointer to PartSet module
78 PartSet_SketcherMgr(PartSet_Module* theModule);
80 virtual ~PartSet_SketcherMgr();
82 /// Returns true if the operation is the sketch
83 /// \param theOperation an operation
84 /// \return the boolean result
85 static bool isSketchOperation(ModuleBase_Operation* theOperation);
87 /// Returns true if the operation id is in the sketch operation id list
88 /// \param theOperation an operation
89 /// \return the boolean result
90 static bool isNestedSketchOperation(ModuleBase_Operation* theOperation);
92 /// Returns true if the operation is a create nested feature one
93 /// \param theOperation a checked operation
94 //// \return boolean value
95 static bool isNestedCreateOperation(ModuleBase_Operation* theOperation);
97 /// Returns whether the current operation is a sketch entity - line, point, arc or circle
98 /// \param theId is an id of object
99 /// \return a boolean value
100 static bool isEntity(const std::string& theId);
102 /// Returns whether the current operation is a sketch distance - lenght, distance or radius
103 /// \param theOperation the operation
104 /// \return a boolean value
105 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
107 /// Returns true if a mouse cursor is over viewer window
108 bool isMouseOverWindow() { return myIsMouseOverWindow; }
110 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
111 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
113 /// Starts sketch operation
114 void startSketch(ModuleBase_Operation* );
116 /// Stops sketch operation
117 void stopSketch(ModuleBase_Operation* );
119 /// Starts sketch operation, connects to the opeation property panel
120 /// \param theOperation a committed operation
121 void startNestedSketch(ModuleBase_Operation* theOperation);
123 /// Stop sketch operation, disconnects from the opeation property panel
124 /// \param theOperation a stopped operation
125 void stopNestedSketch(ModuleBase_Operation* theOperation);
127 /// Visualizes the operation feature if it is a creation nested feature operation
128 /// \param theOperation a committed operation
129 void commitNestedSketch(ModuleBase_Operation* theOperation);
131 /// Returns True if there are available Undos and the sketch manager allows undo
132 /// \return the boolean result
133 bool canUndo() const;
135 //! Returns True if there are available Redos and the sketch manager allows redo
136 /// \return the boolean result
137 bool canRedo() const;
139 /// Returns whether the object can be displayed at the bounds of the active operation.
140 /// Display only current operation results for usual operation and ask the sketcher manager
141 /// if it is a sketch operation
142 /// \param theObject a model object
143 bool canDisplayObject(const ObjectPtr& theObject) const;
145 /// Returns true if the mouse is over viewer or property panel value is changed
146 /// \return boolean result
147 bool canDisplayCurrentCreatedFeature() const;
149 /// Returns state of constraints showing flag
150 bool isConstraintsShown() const { return myIsConstraintsShown; }
152 /// Returns true if the object is a current sketch sub feature of a result of the feature
153 /// \param theObject an object
154 /// \return boolean value
155 bool isObjectOfSketch(const ObjectPtr& theObject) const;
157 /// Saves the current selection in the viewer into an internal container
158 /// It obtains the selected attributes. The highlighted objects can be processes as the selected ones
159 /// \param theHighlightedUse a boolean flag
160 void storeSelection(const bool theHighlightedOnly = false);
162 /// Restores previously saved selection state
163 void restoreSelection();
165 /// Returns list of strings which contains id's of sketch operations
166 static const QStringList& sketchOperationIdList();
168 /// Returns list of strings which contains id's of constraints operations
169 static const QStringList& constraintsIdList();
171 /// Returns a list of modes, where the AIS objects should be activated
172 /// \param theModes a list of modes
173 static void sketchSelectionModes(QIntList& theModes);
176 /// Process sketch plane selected event
177 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
180 /// Process the enter mouse to the view port. If the current operation is a create of
181 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
182 void onEnterViewPort();
183 /// Process the leave mouse of the view port. If the current operation is a create of
184 /// a nested sketch feature, it hides the feature in the viewer
185 void onLeaveViewPort();
186 /// Listens to the value changed signal and display the current operation feature
187 void onBeforeValuesChangedInPropertyPanel();
188 /// Listens to the signal about values are to be changed in the property panel
189 void onValuesChangedInPropertyPanel();
190 /// Listens to the signal about the modification of the values have been done in the property panel
191 void onAfterValuesChangedInPropertyPanel();
193 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
194 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
195 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
196 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
197 void onApplicationStarted();
198 void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
200 void onBeforeContextMenu();
201 void onAfterContextMenu();
203 void onShowConstraintsToggle(bool);
206 /// Launches the operation from current highlighting
207 void launchEditing();
209 /// Converts mouse position to 2d coordinates.
210 /// Member myCurrentSketch has to be correctly defined
211 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
214 typedef QMap<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
215 FeatureToSelectionMap;
217 /// Obtains the current selection of the object in the workshop viewer
218 /// It includes the selection in all modes of activation, even local context - vertices, edges
219 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
220 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
221 /// the feature, if the owner is edge, the current result is added to the container of results.
222 /// \param theFeature a feature or result object
223 /// \param theSketch a current sketch feature
224 /// \param theWorkshop a workshop to have an access to AIS context and displayer
225 /// \param theSelection a container for the selection, to save results and attributres for a feature
226 static void getCurrentSelection(const FeaturePtr& theFeature,
227 const FeaturePtr& theSketch,
228 ModuleBase_IWorkshop* theWorkshop,
229 FeatureToSelectionMap& theSelection);
231 /// Applyes the current selection to the object in the workshop viewer
232 /// It includes the selection in all modes of activation, even local context - vertexes, edges
233 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
234 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
235 /// the feature and if it is in the container of selected attributes, the owner is put in the
236 /// out container. If the owner is edge and the current result is in the container of selected
237 /// results, the owner is put in the out container.
238 /// \param theFeature a feature or result object
239 /// \param theSketch a current sketch feature
240 /// \param theWorkshop a workshop to have an access to AIS context and displayer
241 /// \param theSelection a container of the selection, it has results and attributres for a feature
242 /// \param theOwnersToSelect an out container of found owners
243 static void getSelectionOwners(const FeaturePtr& theFeature,
244 const FeaturePtr& theSketch,
245 ModuleBase_IWorkshop* theWorkshop,
246 const FeatureToSelectionMap& theSelection,
247 SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
249 /// Connects or disconnects to the value changed signal of the property panel widgets
250 /// \param isToConnect a boolean value whether connect or disconnect
251 void connectToPropertyPanel(const bool isToConnect);
253 /// Returns true if the created feature is visible
255 bool isVisibleCreatedFeature() const;
257 /// Returns a current operation
258 /// \return an operation
259 ModuleBase_Operation* getCurrentOperation() const;
261 /// Erase or display the feature of the current operation. If the mouse over the active view or
262 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
263 /// \param theOperation an operation which feature is to be displayed, it is nested create operation
264 /// \param isToDisplay a flag about the display or erase the feature
265 void visualizeFeature(ModuleBase_Operation* theOperation, const bool isToDisplay,
266 const bool isFlushRedisplay = true);
268 /// Gives a debug information about internal flags myIsMouseOverWindow and myIsPropertyPanelValueChanged
269 /// \return a string value
270 QString mouseOverWindowFlagsInfo() const;
273 PartSet_Module* myModule;
275 bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
278 bool myIsPropertyPanelValueChanged; /// the state that value in the property panel is changed
279 bool myIsMouseOverWindow; /// the state that the mouse over the view
280 bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
281 bool myIsPopupMenuActive; /// the state of the popup menu is shown
282 Point myCurrentPoint;
283 Point myClickedPoint;
285 CompositeFeaturePtr myCurrentSketch;
287 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
288 Handle(PartSet_FilterInfinite) myFilterInfinite;
289 FeatureToSelectionMap myCurrentSelection;
290 bool myPreviousUpdateViewerEnabled;
292 bool myIsConstraintsShown;