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 <ModelAPI_Feature.h>
13 #include <ModelAPI_Attribute.h>
14 #include <ModelAPI_CompositeFeature.h>
15 #include <ModelAPI_Result.h>
17 #include <ModuleBase_ViewerFilters.h>
18 #include <ModuleBase_Definitions.h>
20 #include <GeomAPI_Pln.h>
21 #include <SelectMgr_IndexedMapOfOwner.hxx>
28 class ModuleBase_IViewWindow;
29 class ModuleBase_ModelWidget;
30 class ModuleBase_Operation;
35 * A class for management of sketch operations
36 At the time of the sketcher operation active, only the sketch sub-feature results are
37 displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
38 are hidden, the sketch feature result is displayed
40 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
43 /// Struct to define gp point, with the state is the point is initialized
49 myIsInitialized = false;
56 /// clear the initialized flag.
59 myIsInitialized = false;
61 /// set the point and switch on the initialized flag
62 /// \param thePoint the point
63 void setValue(const double theX, const double theY)
65 myIsInitialized = true;
70 bool myIsInitialized; /// the state whether the point is set
71 double myCurX, myCurY; /// the point coordinates
75 /// \param theModule a pointer to PartSet module
76 PartSet_SketcherMgr(PartSet_Module* theModule);
78 virtual ~PartSet_SketcherMgr();
80 /// Returns true if the operation is the sketch
81 /// \param theOperation an operation
82 /// \return the boolean result
83 static bool isSketchOperation(ModuleBase_Operation* theOperation);
85 /// Returns true if the operation id is in the sketch operation id list
86 /// \param theOperation an operation
87 /// \return the boolean result
88 static bool isNestedSketchOperation(ModuleBase_Operation* theOperation);
90 /// Returns true if the operation is a create nested feature one
91 /// \param theOperation a checked operation
92 //// \return boolean value
93 static bool isNestedCreateOperation(ModuleBase_Operation* theOperation);
95 /// Returns whether the current operation is a sketch entity - line, point, arc or circle
96 /// \param theId is an id of object
97 /// \return a boolean value
98 static bool isEntity(const std::string& theId);
100 /// Returns whether the current operation is a sketch distance - lenght, distance or radius
101 /// \param theOperation the operation
102 /// \return a boolean value
103 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
105 /// Returns true if a mouse cursor is over viewer window
106 bool isMouseOverWindow() { return myIsMouseOverWindow; }
108 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
109 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
111 /// Starts sketch operation
112 void startSketch(ModuleBase_Operation* );
114 /// Stops sketch operation
115 void stopSketch(ModuleBase_Operation* );
117 /// Starts sketch operation, connects to the opeation property panel
118 /// \param theOperation a committed operation
119 void startNestedSketch(ModuleBase_Operation* theOperation);
121 /// Stop sketch operation, disconnects from the opeation property panel
122 /// \param theOperation a stopped operation
123 void stopNestedSketch(ModuleBase_Operation* theOperation);
125 /// Visualizes the operation feature if it is a creation nested feature operation
126 /// \param theOperation a committed operation
127 void commitNestedSketch(ModuleBase_Operation* theOperation);
129 /// Returns True if there are available Undos and the sketch manager allows undo
130 /// \return the boolean result
131 bool canUndo() const;
133 //! Returns True if there are available Redos and the sketch manager allows redo
134 /// \return the boolean result
135 bool canRedo() const;
137 /// Returns whether the object can be displayed at the bounds of the active operation.
138 /// Display only current operation results for usual operation and ask the sketcher manager
139 /// if it is a sketch operation
140 /// \param theObject a model object
141 bool canDisplayObject(const ObjectPtr& theObject) const;
143 /// Returns true if the mouse is over viewer or property panel value is changed
144 /// \return boolean result
145 bool canDisplayCurrentCreatedFeature() const;
147 /// Returns state of constraints showing flag
148 bool isConstraintsShown() const { return myIsConstraintsShown; }
150 /// Returns true if the object is a current sketch sub feature of a result of the feature
151 /// \param theObject an object
152 /// \return boolean value
153 bool isObjectOfSketch(const ObjectPtr& theObject) const;
155 /// Saves the current selection in the viewer into an internal container
156 /// It obtains the selected attributes. The highlighted objects can be processes as the selected ones
157 /// \param theHighlightedUse a boolean flag
158 void storeSelection(const bool theHighlightedOnly = false);
160 /// Restores previously saved selection state
161 void restoreSelection();
163 /// Returns list of strings which contains id's of sketch operations
164 static const QStringList& sketchOperationIdList();
166 /// Returns list of strings which contains id's of constraints operations
167 static const QStringList& constraintsIdList();
169 /// Returns a list of modes, where the AIS objects should be activated
170 /// \param theModes a list of modes
171 static void sketchSelectionModes(QIntList& theModes);
174 /// Process sketch plane selected event
175 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
178 /// Process the enter mouse to the view port. If the current operation is a create of
179 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
180 void onEnterViewPort();
181 /// Process the leave mouse of the view port. If the current operation is a create of
182 /// a nested sketch feature, it hides the feature in the viewer
183 void onLeaveViewPort();
184 /// Listens to the value changed signal and display the current operation feature
185 void onBeforeValuesChangedInPropertyPanel();
186 /// Listens to the signal about values are to be changed in the property panel
187 void onValuesChangedInPropertyPanel();
188 /// Listens to the signal about the modification of the values have been done in the property panel
189 void onAfterValuesChangedInPropertyPanel();
191 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
192 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
193 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
194 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
195 void onApplicationStarted();
196 void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
198 void onBeforeContextMenu();
199 void onAfterContextMenu();
201 void onShowConstraintsToggle(bool);
204 /// Launches the operation from current highlighting
205 void launchEditing();
207 /// Converts mouse position to 2d coordinates.
208 /// Member myCurrentSketch has to be correctly defined
209 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
212 typedef QMap<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
213 FeatureToSelectionMap;
215 /// Obtains the current selection of the object in the workshop viewer
216 /// It includes the selection in all modes of activation, even local context - vertices, edges
217 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
218 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
219 /// the feature, if the owner is edge, the current result is added to the container of results.
220 /// \param theFeature a feature or result object
221 /// \param theSketch a current sketch feature
222 /// \param theWorkshop a workshop to have an access to AIS context and displayer
223 /// \param theSelection a container for the selection, to save results and attributres for a feature
224 static void getCurrentSelection(const FeaturePtr& theFeature,
225 const FeaturePtr& theSketch,
226 ModuleBase_IWorkshop* theWorkshop,
227 FeatureToSelectionMap& theSelection);
229 /// Applyes the current selection to the object in the workshop viewer
230 /// It includes the selection in all modes of activation, even local context - vertexes, edges
231 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
232 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
233 /// the feature and if it is in the container of selected attributes, the owner is put in the
234 /// out container. If the owner is edge and the current result is in the container of selected
235 /// results, the owner is put in the out container.
236 /// \param theFeature a feature or result object
237 /// \param theSketch a current sketch feature
238 /// \param theWorkshop a workshop to have an access to AIS context and displayer
239 /// \param theSelection a container of the selection, it has results and attributres for a feature
240 /// \param theOwnersToSelect an out container of found owners
241 static void getSelectionOwners(const FeaturePtr& theFeature,
242 const FeaturePtr& theSketch,
243 ModuleBase_IWorkshop* theWorkshop,
244 const FeatureToSelectionMap& theSelection,
245 SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
247 /// Connects or disconnects to the value changed signal of the property panel widgets
248 /// \param isToConnect a boolean value whether connect or disconnect
249 void connectToPropertyPanel(const bool isToConnect);
251 /// Returns true if the created feature is visible
253 bool isVisibleCreatedFeature() const;
255 /// Returns a current operation
256 /// \return an operation
257 ModuleBase_Operation* getCurrentOperation() const;
259 /// Erase or display the feature of the current operation. If the mouse over the active view or
260 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
261 /// \param theOperation an operation which feature is to be displayed, it is nested create operation
262 /// \param isToDisplay a flag about the display or erase the feature
263 void visualizeFeature(ModuleBase_Operation* theOperation, const bool isToDisplay,
264 const bool isFlushRedisplay = true);
266 /// Activates all visualized objects in the following selection modes: Dimension_Text/Line/Constraint,
267 /// Shape Edge and Vertex. If the active flag is empty, it deactivates all modes
268 /// \param isActive the flag whether the modes should be activated or deactivated
269 void activateObjectsInSketchMode(const bool isActive);
272 /// Gives a debug information about internal flags myIsMouseOverWindow and myIsPropertyPanelValueChanged
273 /// \return a string value
274 QString mouseOverWindowFlagsInfo() const;
277 PartSet_Module* myModule;
279 bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
282 bool myIsPropertyPanelValueChanged; /// the state that value in the property panel is changed
283 bool myIsMouseOverWindow; /// the state that the mouse over the view
284 bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
285 bool myIsPopupMenuActive; /// the state of the popup menu is shown
286 Point myCurrentPoint;
287 Point myClickedPoint;
289 CompositeFeaturePtr myCurrentSketch;
291 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
292 FeatureToSelectionMap myCurrentSelection;
293 bool myPreviousUpdateViewerEnabled;
295 bool myIsConstraintsShown;