1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #ifndef PartSet_SketcherMgr_H
21 #define PartSet_SketcherMgr_H
25 #include "PartSet_PreviewSketchPlane.h"
26 #include "PartSet_Tools.h"
28 #include <ModelAPI_Feature.h>
29 #include <ModelAPI_Attribute.h>
30 #include <ModelAPI_CompositeFeature.h>
31 #include <ModelAPI_Result.h>
32 #include <ModuleBase_SelectionFilterType.h>
34 #include <ModuleBase_Definitions.h>
35 #include <ModuleBase_ModelWidget.h>
37 #include <GeomAPI_Pln.h>
40 #include <OCCViewer_ViewModel.h>
42 #include <AppElements_Viewer.h>
46 #include <SelectMgr_IndexedMapOfOwner.hxx>
47 #include <SelectMgr_ListOfFilter.hxx>
49 #include <TopoDS_Shape.hxx>
50 #include <TopTools_MapOfShape.hxx>
51 #include <AIS_Shape.hxx>
60 class ModuleBase_IViewWindow;
61 class ModuleBase_ModelWidget;
62 class ModuleBase_Operation;
63 class XGUI_OperationMgr;
66 class PartSet_ExternalPointsMgr;
68 class AIS_InteractiveObject;
74 class PartSet_Fitter : public OCCViewer_Fitter
76 class PartSet_Fitter : public AppElements_Fitter
80 PartSet_Fitter(CompositeFeaturePtr theCurrentSketch):
81 mySketch(theCurrentSketch) {}
83 /// A method which has top be reimplemented to provide alterantive implementation FitAll command
84 /// \param theView - a view which has to be fit
85 virtual void fitAll(Handle(V3d_View) theView);
88 CompositeFeaturePtr mySketch;
95 * A class for management of sketch operations
96 At the time of the sketcher operation active, only the sketch sub-feature results are
97 displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
98 are hidden, the sketch feature result is displayed
100 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
103 /// Struct to define gp point, with the state is the point is initialized
109 myIsInitialized = false;
116 /// clear the initialized flag.
119 myIsInitialized = false;
121 /// set the point and switch on the initialized flag
122 /// \param thePoint the point
123 void setValue(const double theX, const double theY)
125 myIsInitialized = true;
130 bool myIsInitialized; /// the state whether the point is set
131 double myCurX, myCurY; /// the point coordinates
135 /// Struct to define selection model information to store/restore selection
138 std::set<AttributePtr> myAttributes; /// the selected attributes
139 std::set<ResultPtr> myResults; /// the selected results
140 TopoDS_Shape myFirstResultShape; /// the first shape of feature result
141 TopTools_MapOfShape myLocalSelectedShapes; /// shapes of local selection
143 typedef QMap<FeaturePtr, SelectionInfo> FeatureToSelectionMap;
147 /// \param theModule a pointer to PartSet module
148 PartSet_SketcherMgr(PartSet_Module* theModule);
150 virtual ~PartSet_SketcherMgr();
152 /// Returns true if the operation is the sketch
153 /// \param theOperation an operation
154 /// \return the boolean result
155 static bool isSketchOperation(ModuleBase_Operation* theOperation);
157 /// Returns true if the operation feature belongs to list of granted features of Sketch
158 /// operation. An operation of a sketch should be started before.
159 /// \param theOperation an operation
160 /// \return the boolean result
161 bool isNestedSketchOperation(ModuleBase_Operation* theOperation) const;
163 /// Returns true if the feature kind belongs to list of granted features of Sketch
164 /// operation. An operation of a sketch should be started before.
165 /// \param theOperation an operation
166 /// \return the boolean result
167 bool isNestedSketchFeature(const QString& theFeatureKind) const;
169 /// Returns true if the operation is a create and nested sketch operationn
170 /// \param theOperation a checked operation
171 /// \param theSketch a sketch feature
172 //// \return boolean value
173 bool isNestedCreateOperation(ModuleBase_Operation* theOperation,
174 const CompositeFeaturePtr& /*theSketch*/) const;
176 /// Returns true if the operation is an edit nested feature one
177 /// \param theOperation a checked operation
178 //// \return boolean value
179 bool isNestedEditOperation(ModuleBase_Operation* theOperation,
180 const CompositeFeaturePtr& /*theSketch*/) const;
182 /// Returns whether the current operation is a sketch entity - line, point, arc or circle
183 /// \param theId is an id of object
184 /// \return a boolean value
185 static bool isEntity(const std::string& theId);
187 /// Returns whether the feature has external attribute filled with 'true' value
188 /// \param theFeature a feature object
189 /// \return a boolean value
190 static bool isExternalFeature(const FeaturePtr& theFeature);
192 /// Returns whether the current operation is a sketch distance - lenght, distance or radius
193 /// \param theOperation the operation
194 /// \return a boolean value
195 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
197 /// Returns whether the feature kind is a sketch distance - lenght, distance or radius
198 /// \param theKind the feature kind
199 /// \return a boolean value
200 static bool isDistanceKind(std::string& theKind);
202 /// Returns true if a mouse cursor is over viewer window
203 bool isMouseOverWindow() { return myIsMouseOverWindow; }
205 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
206 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
208 /// Returns help class to visualize sketcher plane
209 /// \return a preview plane
210 PartSet_PreviewSketchPlane* previewSketchPlane() const { return mySketchPlane; }
212 /// Starts sketch operation
213 void startSketch(ModuleBase_Operation* );
215 /// Stops sketch operation
216 void stopSketch(ModuleBase_Operation* );
218 /// Starts sketch operation, connects to the opeation property panel
219 /// \param theOperation a committed operation
220 void startNestedSketch(ModuleBase_Operation* theOperation);
222 /// Stop sketch operation, disconnects from the opeation property panel
223 /// \param theOperation a stopped operation
224 void stopNestedSketch(ModuleBase_Operation* theOperation);
226 /// Visualizes the operation feature if it is a creation nested feature operation
227 /// \param theOperation a committed operation
228 void commitNestedSketch(ModuleBase_Operation* theOperation);
230 /// Returns true if the filter is created by the sketch manager
231 /// \param theFilterType a checked type
232 /// \return boolean value
233 bool sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType);
235 /// Append selection filter into the module and type of the filter in internal container
236 /// \param theFilterType selection filter type
237 /// \param theFilter added filter
238 void registerSelectionFilter(const ModuleBase_SelectionFilterType theFilterType,
239 const Handle(SelectMgr_Filter)& theFilter);
241 /// Commit the operation if it is possible. If the operation is dimention constraint,
242 /// it gives widget editor to input dimention value
243 /// \return true if the operation is stopped after activation
244 bool operationActivatedByPreselection();
246 /// Returns True if there are available Undos and the sketch manager allows undo
247 /// \return the boolean result
248 bool canUndo() const;
250 //! Returns True if there are available Redos and the sketch manager allows redo
251 /// \return the boolean result
252 bool canRedo() const;
254 /// Returns False only if the sketch creating feature can not be visualized.
255 /// \return a boolean value
256 //bool canCommitOperation() const;
258 /// Returns whether the object can be erased at the bounds of the active operation.
259 /// Sketch sub-entities can not be erased during the sketch operation
260 /// \param theObject a model object
261 bool canEraseObject(const ObjectPtr& theObject) const;
263 /// Returns whether the object can be displayed at the bounds of the active operation.
264 /// Display only current operation results for usual operation and ask the sketcher manager
265 /// if it is a sketch operation
266 /// \param theObject a model object
267 bool canDisplayObject(const ObjectPtr& theObject) const;
269 /// Returns whether the constraint object can be displayed. It depends on the sketch check
271 /// \param theObject a model object
272 /// \param theState the constraint visible state state to be checked
273 /// \param isProcessed an output parameter if it is processed
274 /// \return result value
275 bool canDisplayConstraint(const FeaturePtr& theObject,
276 const PartSet_Tools::ConstraintVisibleState& theState,
277 bool& isProcessed) const;
279 /// Check the given objects either there are some results of the current sketch. If so,
280 /// it suggests to delete them as there are no functionality to show back hidden sketch objects
281 /// \param theObjects a list of hidden objects
282 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
284 /// Returns true if the mouse is over viewer or property panel value is changed
285 /// \return boolean result
286 bool canDisplayCurrentCreatedFeature() const;
288 /// Returns true if the current operation is nested creation or internal reentrant edit
289 /// \param theOperation an operation
290 bool canChangeCursor(ModuleBase_Operation* theOperation) const;
292 /// Returns state of constraints showing flag
293 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
295 /// Returns true if the object is a current sketch sub feature of a result of the feature
296 /// \param theObject an object
297 /// \return boolean value
298 bool isObjectOfSketch(const ObjectPtr& theObject) const;
300 /// Enumeration for selection mode used
302 ST_HighlightType, /// Only highlighted objects
303 ST_SelectType, /// Only selected objects
304 ST_SelectAndHighlightType /// Both, highlighted and selected objects
307 /// Saves the current selection in the viewer into an internal container
308 /// It obtains the selected attributes.
309 /// The highlighted objects can be processes as the selected ones
310 /// \param theHighlightedOnly a boolean flag
311 /// \param theCurrentSelection a container filled by the current selection
312 void storeSelection(const SelectionType theType, FeatureToSelectionMap& theCurrentSelection);
314 /// Restores previously saved selection state
315 /// \param theCurrentSelection a container filled by the current selection
316 void restoreSelection(FeatureToSelectionMap& theCurrentSelection);
318 /// Return error state of the sketch feature, true if the error has happened
319 /// \return boolean value
320 bool sketchSolverError();
322 //! Returns the feature error if the current state of the feature in the sketch is not correct
323 //! If the feature is correct, it returns an empty value
324 //! Incorrect states: the feature is sketch, the solver error value
325 //! The feature value is reset, this is the flag of sketch mgr
326 //! \return string value
327 QString getFeatureError(const FeaturePtr& theFeature);
329 /// It nullify internal flags concerned to clicked mouse event
330 void clearClickedFlags();
332 /// Returns list of strings which contains id's of sketch replication operations
333 static const QStringList& replicationsIdList();
335 /// Returns list of strings which contains id's of constraints operations
336 static const QStringList& constraintsIdList();
338 /// Returns a list of modes, where the AIS objects should be activated
339 /// \param theSketch a sketch object, modes are empty if sketch plane is not defined yet
340 /// \param theModes a list of modes
341 static void sketchSelectionModes(const CompositeFeaturePtr& theSketch, QIntList& theModes);
343 /// Create specific for the module presentation
344 /// \param theResult an object for presentation
345 /// \return created presentation or NULL(default value)
346 virtual Handle(AIS_InteractiveObject) createPresentation(const ResultPtr& theResult);
348 /// Connects or disconnects to the value changed signal of the property panel widgets
349 /// \param theWidget a property contol widget
350 /// \param isToConnect a boolean value whether connect or disconnect
351 void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
353 /// Visualize the operation feature if the previous state is modified value in property panel
354 /// \param thePreviousState the previous widget value state
355 void widgetStateChanged(int thePreviousState);
357 /// If the current operation is a dimention one, the style of dimension visualization is send for
358 /// the current object
359 /// \param theObject an object to be customized
360 void customizePresentation(const ObjectPtr& theObject);
362 /// Update sketch presentations according to the the state
363 /// \param theType a type of sketch visualization style
364 /// \param theState a boolean state
365 void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
368 bool isShowFreePointsShown() const {
369 return myPointsHighlight.size() > 0;
373 /// Process sketch plane selected event
374 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
376 /// The slot is called when user checks "Show free points" button
377 /// \param toShow a state of the check box
378 void onShowPoints(bool toShow);
381 /// Toggle show constraints
382 void onShowConstraintsToggle(int theType, bool theState);
383 /// Process the enter mouse to the view port. If the current operation is a create of
384 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
385 void onEnterViewPort();
386 /// Process the leave mouse of the view port. If the current operation is a create of
387 /// a nested sketch feature, it hides the feature in the viewer
388 void onLeaveViewPort();
389 /// Listens to the value changed signal and display the current operation feature
390 //void onBeforeValuesChangedInPropertyPanel();
391 /// Listens to the signal about the modification of the values
392 /// have been done in the property panel
393 //void onAfterValuesChangedInPropertyPanel();
395 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
396 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
397 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
398 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
399 void onApplicationStarted();
400 //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
402 void onBeforeContextMenu();
403 void onAfterContextMenu();
406 /// Launches the operation from current highlighting
407 void launchEditing();
409 /// Converts mouse position to 2d coordinates.
410 /// Member myCurrentSketch has to be correctly defined
411 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
414 /// Show distance value editor if it is a distance operation and all attribute references
415 /// are filled by preseletion
416 /// \return true if the value is accepted
417 static bool setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
418 ModuleBase_IWorkshop* theWorkshop,
419 bool& theCanCommitOperation);
421 /// Applyes the current selection to the object in the workshop viewer
422 /// It includes the selection in all modes of activation, even local context - vertexes, edges
423 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
424 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
425 /// the feature and if it is in the container of selected attributes, the owner is put in the
426 /// out container. If the owner is edge and the current result is in the container of selected
427 /// results, the owner is put in the out container.
428 /// \param theFeature a feature or result object
429 /// \param theSketch a current sketch feature
430 /// \param theWorkshop a workshop to have an access to AIS context and displayer
431 /// \param theSelection a container of the selection, it has results and attributres for a feature
432 /// \param theOwnersToSelect an out container of found owners
433 static void getSelectionOwners(const FeaturePtr& theFeature,
434 const FeaturePtr& theSketch,
435 ModuleBase_IWorkshop* theWorkshop,
436 const FeatureToSelectionMap& theSelection,
437 SelectMgr_IndexedMapOfOwner& theOwnersToSelect);
439 /// Returns true if the created feature is visible
441 bool isVisibleCreatedFeature() const;
443 /// Returns a current operation
444 /// \return an operation
445 ModuleBase_Operation* getCurrentOperation() const;
447 /// Get the active widget in the property panel
448 ModuleBase_ModelWidget* getActiveWidget() const;
450 /// Erase or display the feature of the current operation. If the mouse over the active view or
451 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
452 /// \param theOperation an operation which feature is to be displayed,
453 /// it is nested create operation
454 /// \param isToDisplay a flag about the display or erase the feature
455 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
456 const bool isToDisplay, const bool isFlushRedisplay = true);
459 /// Updates selection priority of the presentation
460 /// \param theObject object to find a presentation which will be corrected
461 /// \param theFeature a feature of the presentation
462 void updateSelectionPriority(ObjectPtr theObject, FeaturePtr theFeature);
463 /// Returns current workshop
464 XGUI_Workshop* workshop() const;
465 /// Returns operation manager
466 XGUI_OperationMgr* operationMgr() const;
469 PartSet_Module* myModule;
470 PartSet_PreviewSketchPlane* mySketchPlane; // display/erase sketch plane on start/stop sketch
472 bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
473 bool myIsEditLaunching;
476 bool myIsMouseOverWindow; /// the state that the mouse over the view
477 /// the state whether the over view state is processed by mouseMove method
478 bool myIsMouseOverViewProcessed;
479 bool myIsPopupMenuActive; /// the state of the popup menu is shown
480 Point myCurrentPoint;
481 //Point myClickedPoint;
483 CompositeFeaturePtr myCurrentSketch;
485 std::set<ModuleBase_SelectionFilterType> mySelectionFilterTypes;
487 FeatureToSelectionMap myCurrentSelection;
488 bool myPreviousUpdateViewerEnabled;
490 QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;
492 PartSet_ExternalPointsMgr* myExternalPointsMgr;
494 QMap<ResultPtr, Handle(AIS_Shape)> myPointsHighlight;