1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef PartSet_SketcherMgr_H
22 #define PartSet_SketcherMgr_H
26 #include "PartSet_Filters.h"
27 #include "PartSet_Tools.h"
28 #include "PartSet_PreviewSketchPlane.h"
30 #include <ModelAPI_Feature.h>
31 #include <ModelAPI_Attribute.h>
32 #include <ModelAPI_CompositeFeature.h>
33 #include <ModelAPI_Result.h>
35 #include <ModuleBase_ViewerFilters.h>
36 #include <ModuleBase_Definitions.h>
37 #include <ModuleBase_ModelWidget.h>
39 #include <GeomAPI_Pln.h>
40 #include <SelectMgr_IndexedMapOfOwner.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <TopTools_MapOfShape.hxx>
49 class ModuleBase_IViewWindow;
50 class ModuleBase_ModelWidget;
51 class ModuleBase_Operation;
52 class XGUI_OperationMgr;
54 class PartSet_ExternalPointsMgr;
56 class AIS_InteractiveObject;
62 * A class for management of sketch operations
63 At the time of the sketcher operation active, only the sketch sub-feature results are
64 displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
65 are hidden, the sketch feature result is displayed
67 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
70 /// Struct to define gp point, with the state is the point is initialized
76 myIsInitialized = false;
83 /// clear the initialized flag.
86 myIsInitialized = false;
88 /// set the point and switch on the initialized flag
89 /// \param thePoint the point
90 void setValue(const double theX, const double theY)
92 myIsInitialized = true;
97 bool myIsInitialized; /// the state whether the point is set
98 double myCurX, myCurY; /// the point coordinates
102 /// Struct to define selection model information to store/restore selection
105 std::set<AttributePtr> myAttributes; /// the selected attributes
106 std::set<ResultPtr> myResults; /// the selected results
107 TopoDS_Shape myFirstResultShape; /// the first shape of feature result
108 TopTools_MapOfShape myLocalSelectedShapes; /// shapes of local selection
110 typedef QMap<FeaturePtr, SelectionInfo> FeatureToSelectionMap;
114 /// \param theModule a pointer to PartSet module
115 PartSet_SketcherMgr(PartSet_Module* theModule);
117 virtual ~PartSet_SketcherMgr();
119 /// Returns true if the operation is the sketch
120 /// \param theOperation an operation
121 /// \return the boolean result
122 static bool isSketchOperation(ModuleBase_Operation* theOperation);
124 /// Returns true if the operation feature belongs to list of granted features of Sketch
125 /// operation. An operation of a sketch should be started before.
126 /// \param theOperation an operation
127 /// \return the boolean result
128 bool isNestedSketchOperation(ModuleBase_Operation* theOperation) const;
130 /// Returns true if the feature kind belongs to list of granted features of Sketch
131 /// operation. An operation of a sketch should be started before.
132 /// \param theOperation an operation
133 /// \return the boolean result
134 bool isNestedSketchFeature(const QString& theFeatureKind) const;
136 /// Returns true if the operation is a create and nested sketch operationn
137 /// \param theOperation a checked operation
138 /// \param theSketch a sketch feature
139 //// \return boolean value
140 bool isNestedCreateOperation(ModuleBase_Operation* theOperation,
141 const CompositeFeaturePtr& /*theSketch*/) const;
143 /// Returns true if the operation is an edit nested feature one
144 /// \param theOperation a checked operation
145 //// \return boolean value
146 bool isNestedEditOperation(ModuleBase_Operation* theOperation,
147 const CompositeFeaturePtr& /*theSketch*/) const;
149 /// Returns whether the current operation is a sketch entity - line, point, arc or circle
150 /// \param theId is an id of object
151 /// \return a boolean value
152 static bool isEntity(const std::string& theId);
154 /// Returns whether the feature has external attribute filled with 'true' value
155 /// \param theFeature a feature object
156 /// \return a boolean value
157 static bool isExternalFeature(const FeaturePtr& theFeature);
159 /// Returns whether the current operation is a sketch distance - lenght, distance or radius
160 /// \param theOperation the operation
161 /// \return a boolean value
162 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
164 /// Returns whether the feature kind is a sketch distance - lenght, distance or radius
165 /// \param theKind the feature kind
166 /// \return a boolean value
167 static bool isDistanceKind(std::string& theKind);
169 /// Returns true if a mouse cursor is over viewer window
170 bool isMouseOverWindow() { return myIsMouseOverWindow; }
172 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
173 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
175 /// Returns help class to visualize sketcher plane
176 /// \return a preview plane
177 PartSet_PreviewSketchPlane* previewSketchPlane() const { return mySketchPlane; }
179 /// Starts sketch operation
180 void startSketch(ModuleBase_Operation* );
182 /// Stops sketch operation
183 void stopSketch(ModuleBase_Operation* );
185 /// Starts sketch operation, connects to the opeation property panel
186 /// \param theOperation a committed operation
187 void startNestedSketch(ModuleBase_Operation* theOperation);
189 /// Stop sketch operation, disconnects from the opeation property panel
190 /// \param theOperation a stopped operation
191 void stopNestedSketch(ModuleBase_Operation* theOperation);
193 /// Visualizes the operation feature if it is a creation nested feature operation
194 /// \param theOperation a committed operation
195 void commitNestedSketch(ModuleBase_Operation* theOperation);
197 /// Append the sketch plane filter into the current viewer
198 /// \param toActivate state whether the filter should be activated/deactivated
199 void activatePlaneFilter(const bool& toActivate);
201 /// Commit the operation if it is possible. If the operation is dimention constraint,
202 /// it gives widget editor to input dimention value
203 /// \return true if the operation is stopped after activation
204 bool operationActivatedByPreselection();
206 /// Returns True if there are available Undos and the sketch manager allows undo
207 /// \return the boolean result
208 bool canUndo() const;
210 //! Returns True if there are available Redos and the sketch manager allows redo
211 /// \return the boolean result
212 bool canRedo() const;
214 /// Returns False only if the sketch creating feature can not be visualized.
215 /// \return a boolean value
216 //bool canCommitOperation() const;
218 /// Returns whether the object can be erased at the bounds of the active operation.
219 /// Sketch sub-entities can not be erased during the sketch operation
220 /// \param theObject a model object
221 bool canEraseObject(const ObjectPtr& theObject) const;
223 /// Returns whether the object can be displayed at the bounds of the active operation.
224 /// Display only current operation results for usual operation and ask the sketcher manager
225 /// if it is a sketch operation
226 /// \param theObject a model object
227 bool canDisplayObject(const ObjectPtr& theObject) const;
229 /// Returns whether the constraint object can be displayed. It depends on the sketch check
231 /// \param theObject a model object
232 /// \param theState the constraint visible state state to be checked
233 /// \param isProcessed an output parameter if it is processed
234 /// \return result value
235 bool canDisplayConstraint(const FeaturePtr& theObject,
236 const PartSet_Tools::ConstraintVisibleState& theState,
237 bool& isProcessed) const;
239 /// Check the given objects either there are some results of the current sketch. If so,
240 /// it suggests to delete them as there are no functionality to show back hidden sketch objects
241 /// \param theObjects a list of hidden objects
242 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
244 /// Returns true if the mouse is over viewer or property panel value is changed
245 /// \return boolean result
246 bool canDisplayCurrentCreatedFeature() const;
248 /// Returns true if the current operation is nested creation or internal reentrant edit
249 /// \param theOperation an operation
250 bool canChangeCursor(ModuleBase_Operation* theOperation) const;
252 /// Returns state of constraints showing flag
253 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
255 /// Returns true if the object is a current sketch sub feature of a result of the feature
256 /// \param theObject an object
257 /// \return boolean value
258 bool isObjectOfSketch(const ObjectPtr& theObject) const;
260 /// Enumeration for selection mode used
262 ST_HighlightType, /// Only highlighted objects
263 ST_SelectType, /// Only selected objects
264 ST_SelectAndHighlightType /// Both, highlighted and selected objects
267 /// Saves the current selection in the viewer into an internal container
268 /// It obtains the selected attributes.
269 /// The highlighted objects can be processes as the selected ones
270 /// \param theHighlightedOnly a boolean flag
271 /// \param theCurrentSelection a container filled by the current selection
272 void storeSelection(const SelectionType theType, FeatureToSelectionMap& theCurrentSelection);
274 /// Restores previously saved selection state
275 /// \param theCurrentSelection a container filled by the current selection
276 void restoreSelection(FeatureToSelectionMap& theCurrentSelection);
278 /// Return error state of the sketch feature, true if the error has happened
279 /// \return boolean value
280 bool sketchSolverError();
282 //! Returns the feature error if the current state of the feature in the sketch is not correct
283 //! If the feature is correct, it returns an empty value
284 //! Incorrect states: the feature is sketch, the solver error value
285 //! The feature value is reset, this is the flag of sketch mgr
286 //! \return string value
287 QString getFeatureError(const FeaturePtr& theFeature);
289 /// It nullify internal flags concerned to clicked mouse event
290 void clearClickedFlags();
292 /// Returns list of strings which contains id's of sketch replication operations
293 static const QStringList& replicationsIdList();
295 /// Returns list of strings which contains id's of constraints operations
296 static const QStringList& constraintsIdList();
298 /// Returns a list of modes, where the AIS objects should be activated
299 /// \param theModes a list of modes
300 static void sketchSelectionModes(QIntList& theModes);
302 /// Create specific for the module presentation
303 /// \param theResult an object for presentation
304 /// \return created presentation or NULL(default value)
305 virtual Handle(AIS_InteractiveObject) createPresentation(const ResultPtr& theResult);
307 /// Connects or disconnects to the value changed signal of the property panel widgets
308 /// \param theWidget a property contol widget
309 /// \param isToConnect a boolean value whether connect or disconnect
310 void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
312 /// Visualize the operation feature if the previous state is modified value in property panel
313 /// \param thePreviousState the previous widget value state
314 void widgetStateChanged(int thePreviousState);
316 /// If the current operation is a dimention one, the style of dimension visualization is send for
317 /// the current object
318 /// \param theObject an object to be customized
319 void customizePresentation(const ObjectPtr& theObject);
321 /// Update sketch presentations according to the the state
322 /// \param theType a type of sketch visualization style
323 /// \param theState a boolean state
324 void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
328 /// Process sketch plane selected event
329 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
332 /// Toggle show constraints
333 void onShowConstraintsToggle(int theType, bool theState);
334 /// Process the enter mouse to the view port. If the current operation is a create of
335 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
336 void onEnterViewPort();
337 /// Process the leave mouse of the view port. If the current operation is a create of
338 /// a nested sketch feature, it hides the feature in the viewer
339 void onLeaveViewPort();
340 /// Listens to the value changed signal and display the current operation feature
341 //void onBeforeValuesChangedInPropertyPanel();
342 /// Listens to the signal about the modification of the values
343 /// have been done in the property panel
344 //void onAfterValuesChangedInPropertyPanel();
346 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
347 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
348 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
349 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
350 void onApplicationStarted();
351 //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
353 void onBeforeContextMenu();
354 void onAfterContextMenu();
357 /// Launches the operation from current highlighting
358 void launchEditing();
360 /// Converts mouse position to 2d coordinates.
361 /// Member myCurrentSketch has to be correctly defined
362 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
365 /// Show distance value editor if it is a distance operation and all attribute references
366 /// are filled by preseletion
367 /// \return true if the value is accepted
368 static bool setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
369 ModuleBase_IWorkshop* theWorkshop,
370 bool& theCanCommitOperation);
372 /// Applyes the current selection to the object in the workshop viewer
373 /// It includes the selection in all modes of activation, even local context - vertexes, edges
374 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
375 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
376 /// the feature and if it is in the container of selected attributes, the owner is put in the
377 /// out container. If the owner is edge and the current result is in the container of selected
378 /// results, the owner is put in the out container.
379 /// \param theFeature a feature or result object
380 /// \param theSketch a current sketch feature
381 /// \param theWorkshop a workshop to have an access to AIS context and displayer
382 /// \param theSelection a container of the selection, it has results and attributres for a feature
383 /// \param theOwnersToSelect an out container of found owners
384 static void getSelectionOwners(const FeaturePtr& theFeature,
385 const FeaturePtr& theSketch,
386 ModuleBase_IWorkshop* theWorkshop,
387 const FeatureToSelectionMap& theSelection,
388 SelectMgr_IndexedMapOfOwner& theOwnersToSelect);
390 /// Returns true if the created feature is visible
392 bool isVisibleCreatedFeature() const;
394 /// Returns a current operation
395 /// \return an operation
396 ModuleBase_Operation* getCurrentOperation() const;
398 /// Get the active widget in the property panel
399 ModuleBase_ModelWidget* getActiveWidget() const;
401 /// Erase or display the feature of the current operation. If the mouse over the active view or
402 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
403 /// \param theOperation an operation which feature is to be displayed,
404 /// it is nested create operation
405 /// \param isToDisplay a flag about the display or erase the feature
406 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
407 const bool isToDisplay, const bool isFlushRedisplay = true);
410 /// Updates selection priority of the presentation
411 /// \param theObject object to find a presentation which will be corrected
412 /// \param theFeature a feature of the presentation
413 void updateSelectionPriority(ObjectPtr theObject, FeaturePtr theFeature);
414 /// Returns current workshop
415 XGUI_Workshop* workshop() const;
416 /// Returns operation manager
417 XGUI_OperationMgr* operationMgr() const;
420 PartSet_Module* myModule;
421 PartSet_PreviewSketchPlane* mySketchPlane; // display/erase sketch plane on start/stop sketch
423 bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
424 bool myIsEditLaunching;
427 bool myIsMouseOverWindow; /// the state that the mouse over the view
428 /// the state whether the over view state is processed by mouseMove method
429 bool myIsMouseOverViewProcessed;
430 bool myIsPopupMenuActive; /// the state of the popup menu is shown
431 Point myCurrentPoint;
432 //Point myClickedPoint;
434 CompositeFeaturePtr myCurrentSketch;
436 Handle(PartSet_CirclePointFilter) myCirclePointFilter;
437 Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
438 FeatureToSelectionMap myCurrentSelection;
439 bool myPreviousUpdateViewerEnabled;
441 QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;
443 PartSet_ExternalPointsMgr* myExternalPointsMgr;