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;
31 class XGUI_OperationMgr;
36 * A class for management of sketch operations
37 At the time of the sketcher operation active, only the sketch sub-feature results are
38 displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
39 are hidden, the sketch feature result is displayed
41 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
44 /// Struct to define gp point, with the state is the point is initialized
50 myIsInitialized = false;
57 /// clear the initialized flag.
60 myIsInitialized = false;
62 /// set the point and switch on the initialized flag
63 /// \param thePoint the point
64 void setValue(const double theX, const double theY)
66 myIsInitialized = true;
71 bool myIsInitialized; /// the state whether the point is set
72 double myCurX, myCurY; /// the point coordinates
76 /// \param theModule a pointer to PartSet module
77 PartSet_SketcherMgr(PartSet_Module* theModule);
79 virtual ~PartSet_SketcherMgr();
81 /// Returns true if the operation is the sketch
82 /// \param theOperation an operation
83 /// \return the boolean result
84 static bool isSketchOperation(ModuleBase_Operation* theOperation);
86 /// Returns true if the operation id is in the sketch operation id list
87 /// \param theOperation an operation
88 /// \return the boolean result
89 static bool isNestedSketchOperation(ModuleBase_Operation* theOperation);
91 /// Returns true if the operation is a create nested feature one
92 /// \param theOperation a checked operation
93 //// \return boolean value
94 static bool isNestedCreateOperation(ModuleBase_Operation* theOperation);
96 /// Returns whether the current operation is a sketch entity - line, point, arc or circle
97 /// \param theId is an id of object
98 /// \return a boolean value
99 static bool isEntity(const std::string& theId);
101 /// Returns whether the current operation is a sketch distance - lenght, distance or radius
102 /// \param theOperation the operation
103 /// \return a boolean value
104 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
106 /// Returns true if a mouse cursor is over viewer window
107 bool isMouseOverWindow() { return myIsMouseOverWindow; }
109 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
110 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
112 /// Starts sketch operation
113 void startSketch(ModuleBase_Operation* );
115 /// Stops sketch operation
116 void stopSketch(ModuleBase_Operation* );
118 /// Starts sketch operation, connects to the opeation property panel
119 /// \param theOperation a committed operation
120 void startNestedSketch(ModuleBase_Operation* theOperation);
122 /// Stop sketch operation, disconnects from the opeation property panel
123 /// \param theOperation a stopped operation
124 void stopNestedSketch(ModuleBase_Operation* theOperation);
126 /// Visualizes the operation feature if it is a creation nested feature operation
127 /// \param theOperation a committed operation
128 void commitNestedSketch(ModuleBase_Operation* theOperation);
130 /// Returns True if there are available Undos and the sketch manager allows undo
131 /// \return the boolean result
132 bool canUndo() const;
134 //! Returns True if there are available Redos and the sketch manager allows redo
135 /// \return the boolean result
136 bool canRedo() const;
138 /// Returns False only if the sketch creating feature can not be visualized.
139 /// \return a boolean value
140 bool canCommitOperation() const;
142 /// Returns whether the object can be erased at the bounds of the active operation.
143 /// Sketch sub-entities can not be erased during the sketch operation
144 /// \param theObject a model object
145 bool canEraseObject(const ObjectPtr& theObject) const;
147 /// Returns whether the object can be displayed at the bounds of the active operation.
148 /// Display only current operation results for usual operation and ask the sketcher manager
149 /// if it is a sketch operation
150 /// \param theObject a model object
151 bool canDisplayObject(const ObjectPtr& theObject) const;
153 /// Returns true if the mouse is over viewer or property panel value is changed
154 /// \return boolean result
155 bool canDisplayCurrentCreatedFeature() const;
157 /// Returns state of constraints showing flag
158 bool isConstraintsShown() const { return myIsConstraintsShown; }
160 /// Returns true if the object is a current sketch sub feature of a result of the feature
161 /// \param theObject an object
162 /// \return boolean value
163 bool isObjectOfSketch(const ObjectPtr& theObject) const;
165 /// Saves the current selection in the viewer into an internal container
166 /// It obtains the selected attributes. The highlighted objects can be processes as the selected ones
167 /// \param theHighlightedUse a boolean flag
168 void storeSelection(const bool theHighlightedOnly = false);
170 /// Restores previously saved selection state
171 void restoreSelection();
173 /// Returns list of strings which contains id's of sketch operations
174 static const QStringList& sketchOperationIdList();
176 /// Returns list of strings which contains id's of constraints operations
177 static const QStringList& constraintsIdList();
179 /// Returns a list of modes, where the AIS objects should be activated
180 /// \param theModes a list of modes
181 static void sketchSelectionModes(QIntList& theModes);
184 /// Process sketch plane selected event
185 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
188 /// Process the enter mouse to the view port. If the current operation is a create of
189 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
190 void onEnterViewPort();
191 /// Process the leave mouse of the view port. If the current operation is a create of
192 /// a nested sketch feature, it hides the feature in the viewer
193 void onLeaveViewPort();
194 /// Listens to the value changed signal and display the current operation feature
195 void onBeforeValuesChangedInPropertyPanel();
196 /// Listens to the signal about values are to be changed in the property panel
197 void onValuesChangedInPropertyPanel();
198 /// Listens to the signal about the modification of the values have been done in the property panel
199 void onAfterValuesChangedInPropertyPanel();
201 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
202 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
203 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
204 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
205 void onApplicationStarted();
206 void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
208 void onBeforeContextMenu();
209 void onAfterContextMenu();
211 void onShowConstraintsToggle(bool);
214 /// Launches the operation from current highlighting
215 void launchEditing();
217 /// Converts mouse position to 2d coordinates.
218 /// Member myCurrentSketch has to be correctly defined
219 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
222 typedef QMap<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
223 FeatureToSelectionMap;
225 /// Obtains the current selection of the object in the workshop viewer
226 /// It includes the selection in all modes of activation, even local context - vertices, edges
227 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
228 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
229 /// the feature, if the owner is edge, the current result is added to the container of results.
230 /// \param theFeature a feature or result object
231 /// \param theSketch a current sketch feature
232 /// \param theWorkshop a workshop to have an access to AIS context and displayer
233 /// \param theSelection a container for the selection, to save results and attributres for a feature
234 static void getCurrentSelection(const FeaturePtr& theFeature,
235 const FeaturePtr& theSketch,
236 ModuleBase_IWorkshop* theWorkshop,
237 FeatureToSelectionMap& theSelection);
239 /// Applyes the current selection to the object in the workshop viewer
240 /// It includes the selection in all modes of activation, even local context - vertexes, edges
241 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
242 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
243 /// the feature and if it is in the container of selected attributes, the owner is put in the
244 /// out container. If the owner is edge and the current result is in the container of selected
245 /// results, the owner is put in the out container.
246 /// \param theFeature a feature or result object
247 /// \param theSketch a current sketch feature
248 /// \param theWorkshop a workshop to have an access to AIS context and displayer
249 /// \param theSelection a container of the selection, it has results and attributres for a feature
250 /// \param theOwnersToSelect an out container of found owners
251 static void getSelectionOwners(const FeaturePtr& theFeature,
252 const FeaturePtr& theSketch,
253 ModuleBase_IWorkshop* theWorkshop,
254 const FeatureToSelectionMap& theSelection,
255 SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
257 /// Connects or disconnects to the value changed signal of the property panel widgets
258 /// \param isToConnect a boolean value whether connect or disconnect
259 void connectToPropertyPanel(const bool isToConnect);
261 /// Returns true if the created feature is visible
263 bool isVisibleCreatedFeature() const;
265 /// Returns a current operation
266 /// \return an operation
267 ModuleBase_Operation* getCurrentOperation() const;
269 /// Erase or display the feature of the current operation. If the mouse over the active view or
270 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
271 /// \param theOperation an operation which feature is to be displayed, it is nested create operation
272 /// \param isToDisplay a flag about the display or erase the feature
273 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
274 const bool isToDisplay, const bool isFlushRedisplay = true);
276 /// Gives a debug information about internal flags myIsMouseOverWindow and myIsResetCurrentValue
277 /// \return a string value
278 QString mouseOverWindowFlagsInfo() const;
280 XGUI_OperationMgr* operationMgr() const;
283 PartSet_Module* myModule;
285 bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
288 bool myIsResetCurrentValue; /// the state that value in the property panel is reset
289 bool myIsMouseOverWindow; /// the state that the mouse over the view
290 bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
291 bool myIsPopupMenuActive; /// the state of the popup menu is shown
292 Point myCurrentPoint;
293 Point myClickedPoint;
295 CompositeFeaturePtr myCurrentSketch;
297 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
298 FeatureToSelectionMap myCurrentSelection;
299 bool myPreviousUpdateViewerEnabled;
301 bool myIsConstraintsShown;