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_Tools.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>
21 #include <ModuleBase_ModelWidget.h>
23 #include <GeomAPI_Pln.h>
24 #include <SelectMgr_IndexedMapOfOwner.hxx>
31 class ModuleBase_IViewWindow;
32 class ModuleBase_ModelWidget;
33 class ModuleBase_Operation;
34 class XGUI_OperationMgr;
41 * A class for management of sketch operations
42 At the time of the sketcher operation active, only the sketch sub-feature results are
43 displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
44 are hidden, the sketch feature result is displayed
46 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
49 /// Struct to define gp point, with the state is the point is initialized
55 myIsInitialized = false;
62 /// clear the initialized flag.
65 myIsInitialized = false;
67 /// set the point and switch on the initialized flag
68 /// \param thePoint the point
69 void setValue(const double theX, const double theY)
71 myIsInitialized = true;
76 bool myIsInitialized; /// the state whether the point is set
77 double myCurX, myCurY; /// the point coordinates
81 /// \param theModule a pointer to PartSet module
82 PartSet_SketcherMgr(PartSet_Module* theModule);
84 virtual ~PartSet_SketcherMgr();
86 /// Returns true if the operation is the sketch
87 /// \param theOperation an operation
88 /// \return the boolean result
89 static bool isSketchOperation(ModuleBase_Operation* theOperation);
91 /// Returns true if the operation id is in the sketch operation id list
92 /// \param theOperation an operation
93 /// \return the boolean result
94 static bool isNestedSketchOperation(ModuleBase_Operation* theOperation);
96 /// Returns true if the operation is a create nested feature one
97 /// \param theOperation a checked operation
98 //// \return boolean value
99 static bool isNestedCreateOperation(ModuleBase_Operation* theOperation);
101 /// Returns true if the operation is an edit nested feature one
102 /// \param theOperation a checked operation
103 //// \return boolean value
104 static bool isNestedEditOperation(ModuleBase_Operation* theOperation);
106 /// Returns whether the current operation is a sketch entity - line, point, arc or circle
107 /// \param theId is an id of object
108 /// \return a boolean value
109 static bool isEntity(const std::string& theId);
111 /// Returns whether the current operation is a sketch distance - lenght, distance or radius
112 /// \param theOperation the operation
113 /// \return a boolean value
114 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
116 /// Returns whether the feature kind is a sketch distance - lenght, distance or radius
117 /// \param theKind the feature kind
118 /// \return a boolean value
119 static bool isDistanceKind(std::string& theKind);
121 /// Returns true if a mouse cursor is over viewer window
122 bool isMouseOverWindow() { return myIsMouseOverWindow; }
124 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
125 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
127 /// Starts sketch operation
128 void startSketch(ModuleBase_Operation* );
130 /// Stops sketch operation
131 void stopSketch(ModuleBase_Operation* );
133 /// Starts sketch operation, connects to the opeation property panel
134 /// \param theOperation a committed operation
135 void startNestedSketch(ModuleBase_Operation* theOperation);
137 /// Stop sketch operation, disconnects from the opeation property panel
138 /// \param theOperation a stopped operation
139 void stopNestedSketch(ModuleBase_Operation* theOperation);
141 /// Visualizes the operation feature if it is a creation nested feature operation
142 /// \param theOperation a committed operation
143 void commitNestedSketch(ModuleBase_Operation* theOperation);
145 /// Append the sketch plane filter into the current viewer
146 /// \param toActivate state whether the filter should be activated/deactivated
147 void activatePlaneFilter(const bool& toActivate);
149 /// Commit the operation if it is possible. If the operation is dimention constraint,
150 /// it gives widget editor to input dimention value
151 void operationActivatedByPreselection();
153 /// Returns True if there are available Undos and the sketch manager allows undo
154 /// \return the boolean result
155 bool canUndo() const;
157 //! Returns True if there are available Redos and the sketch manager allows redo
158 /// \return the boolean result
159 bool canRedo() const;
161 /// Returns False only if the sketch creating feature can not be visualized.
162 /// \return a boolean value
163 //bool canCommitOperation() const;
165 /// Returns whether the object can be erased at the bounds of the active operation.
166 /// Sketch sub-entities can not be erased during the sketch operation
167 /// \param theObject a model object
168 bool canEraseObject(const ObjectPtr& theObject) const;
170 /// Returns whether the object can be displayed at the bounds of the active operation.
171 /// Display only current operation results for usual operation and ask the sketcher manager
172 /// if it is a sketch operation
173 /// \param theObject a model object
174 bool canDisplayObject(const ObjectPtr& theObject) const;
176 /// Check the given objects either there are some results of the current sketch. If so,
177 /// it suggests to delete them as there are no functionality to show back hidden sketch objects
178 /// \param theObjects a list of hidden objects
179 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
181 /// Returns true if the mouse is over viewer or property panel value is changed
182 /// \return boolean result
183 bool canDisplayCurrentCreatedFeature() const;
185 /// Returns true if the current operation is nested creation or internal reentrant edit
186 /// \param theOperation an operation
187 bool canChangeCursor(ModuleBase_Operation* theOperation) const;
189 /// Returns state of constraints showing flag
190 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
192 /// Returns true if the object is a current sketch sub feature of a result of the feature
193 /// \param theObject an object
194 /// \return boolean value
195 bool isObjectOfSketch(const ObjectPtr& theObject) const;
197 /// Saves the current selection in the viewer into an internal container
198 /// It obtains the selected attributes. The highlighted objects can be processes as the selected ones
199 /// \param theHighlightedOnly a boolean flag
200 void storeSelection(const bool theHighlightedOnly = false);
202 /// Restores previously saved selection state
203 void restoreSelection();
205 /// Return error state of the sketch feature, true if the error has happened
206 /// \return boolean value
207 bool sketchSolverError();
209 //! Returns the feature error if the current state of the feature in the sketch is not correct
210 //! If the feature is correct, it returns an empty value
211 //! Incorrect states: the feature is sketch, the solver error value
212 //! The feature value is reset, this is the flag of sketch mgr
213 //! \return string value
214 QString getFeatureError(const FeaturePtr& theFeature);
216 /// It nullify internal flags concerned to clicked mouse event
217 void clearClickedFlags();
219 /// Returns list of strings which contains id's of sketch operations
220 static const QStringList& sketchOperationIdList();
222 /// Returns list of strings which contains id's of constraints operations
223 static const QStringList& constraintsIdList();
225 /// Returns a list of modes, where the AIS objects should be activated
226 /// \param theModes a list of modes
227 static void sketchSelectionModes(QIntList& theModes);
229 /// Connects or disconnects to the value changed signal of the property panel widgets
230 /// \param theWidget a property contol widget
231 /// \param isToConnect a boolean value whether connect or disconnect
232 void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
234 /// Visualize the operation feature if the previous state is modified value in property panel
235 /// \param thePreviousState the previous widget value state
236 void widgetStateChanged(int thePreviousState);
239 /// Process sketch plane selected event
240 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
242 /// Toggle show constraints
243 void onShowConstraintsToggle(bool theState, int theType);
246 /// Process the enter mouse to the view port. If the current operation is a create of
247 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
248 void onEnterViewPort();
249 /// Process the leave mouse of the view port. If the current operation is a create of
250 /// a nested sketch feature, it hides the feature in the viewer
251 void onLeaveViewPort();
252 /// Listens to the value changed signal and display the current operation feature
253 void onBeforeValuesChangedInPropertyPanel();
254 /// Listens to the signal about the modification of the values have been done in the property panel
255 void onAfterValuesChangedInPropertyPanel();
257 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
258 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
259 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
260 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
261 void onApplicationStarted();
262 //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
264 void onBeforeContextMenu();
265 void onAfterContextMenu();
268 /// Launches the operation from current highlighting
269 void launchEditing();
271 /// Converts mouse position to 2d coordinates.
272 /// Member myCurrentSketch has to be correctly defined
273 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
276 typedef QMap<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
277 FeatureToSelectionMap;
279 /// Obtains the current selection of the object in the workshop viewer
280 /// It includes the selection in all modes of activation, even local context - vertices, edges
281 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
282 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
283 /// the feature, if the owner is edge, the current result is added to the container of results.
284 /// \param theFeature a feature or result object
285 /// \param theSketch a current sketch feature
286 /// \param theWorkshop a workshop to have an access to AIS context and displayer
287 /// \param theSelection a container for the selection, to save results and attributres for a feature
288 static void getCurrentSelection(const FeaturePtr& theFeature,
289 const FeaturePtr& theSketch,
290 ModuleBase_IWorkshop* theWorkshop,
291 FeatureToSelectionMap& theSelection);
293 /// Applyes the current selection to the object in the workshop viewer
294 /// It includes the selection in all modes of activation, even local context - vertexes, edges
295 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
296 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
297 /// the feature and if it is in the container of selected attributes, the owner is put in the
298 /// out container. If the owner is edge and the current result is in the container of selected
299 /// results, the owner is put in the out container.
300 /// \param theFeature a feature or result object
301 /// \param theSketch a current sketch feature
302 /// \param theWorkshop a workshop to have an access to AIS context and displayer
303 /// \param theSelection a container of the selection, it has results and attributres for a feature
304 /// \param theOwnersToSelect an out container of found owners
305 static void getSelectionOwners(const FeaturePtr& theFeature,
306 const FeaturePtr& theSketch,
307 ModuleBase_IWorkshop* theWorkshop,
308 const FeatureToSelectionMap& theSelection,
309 SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
311 /// Returns true if the created feature is visible
313 bool isVisibleCreatedFeature() const;
315 /// Returns a current operation
316 /// \return an operation
317 ModuleBase_Operation* getCurrentOperation() const;
319 /// Get the active widget in the property panel
320 ModuleBase_ModelWidget* getActiveWidget() const;
322 /// Erase or display the feature of the current operation. If the mouse over the active view or
323 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
324 /// \param theOperation an operation which feature is to be displayed, it is nested create operation
325 /// \param isToDisplay a flag about the display or erase the feature
326 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
327 const bool isToDisplay, const bool isFlushRedisplay = true);
330 /// Returns current workshop
331 XGUI_Workshop* workshop() const;
332 /// Returns operation manager
333 XGUI_OperationMgr* operationMgr() const;
336 PartSet_Module* myModule;
338 bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
341 bool myIsMouseOverWindow; /// the state that the mouse over the view
342 bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
343 bool myIsPopupMenuActive; /// the state of the popup menu is shown
344 Point myCurrentPoint;
345 //Point myClickedPoint;
347 CompositeFeaturePtr myCurrentSketch;
349 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
350 FeatureToSelectionMap myCurrentSelection;
351 bool myPreviousUpdateViewerEnabled;
353 QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;