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 <Events_Listener.h>
33 #include <ModuleBase_SelectionFilterType.h>
35 #include <ModuleBase_Definitions.h>
36 #include <ModuleBase_ModelWidget.h>
38 #include <GeomAPI_Pln.h>
39 #include <GeomAPI_AISObject.h>
42 #include <OCCViewer_ViewModel.h>
44 #include <AppElements_Viewer.h>
48 #include <SelectMgr_IndexedMapOfOwner.hxx>
49 #include <SelectMgr_ListOfFilter.hxx>
51 #include <TopoDS_Shape.hxx>
52 #include <TopTools_MapOfShape.hxx>
53 #include <AIS_Shape.hxx>
62 class ModuleBase_IViewWindow;
63 class ModuleBase_ModelWidget;
64 class ModuleBase_Operation;
65 class XGUI_OperationMgr;
68 class PartSet_ExternalPointsMgr;
70 class AIS_InteractiveObject;
73 class PartSet_SketcherMgr;
76 class PartSet_Fitter : public OCCViewer_Fitter
78 class PartSet_Fitter : public AppElements_Fitter
82 PartSet_Fitter(PartSet_SketcherMgr* theSketchMgr):
83 mySketchMgr(theSketchMgr) {}
85 /// A method which has top be reimplemented to provide alterantive implementation FitAll command
86 /// \param theView - a view which has to be fit
87 virtual void fitAll(Handle(V3d_View) theView);
90 PartSet_SketcherMgr* mySketchMgr;
97 * A class for management of sketch operations
98 At the time of the sketcher operation active, only the sketch sub-feature results are
99 displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
100 are hidden, the sketch feature result is displayed
102 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject, public Events_Listener
105 /// Struct to define gp point, with the state is the point is initialized
111 myIsInitialized = false;
118 /// clear the initialized flag.
121 myIsInitialized = false;
123 /// set the point and switch on the initialized flag
124 /// \param thePoint the point
125 void setValue(const double theX, const double theY)
127 myIsInitialized = true;
132 bool myIsInitialized; /// the state whether the point is set
133 double myCurX, myCurY; /// the point coordinates
137 /// Struct to define selection model information to store/restore selection
140 std::set<AttributePtr> myAttributes; /// the selected attributes
141 std::set<ResultPtr> myResults; /// the selected results
142 TopoDS_Shape myFirstResultShape; /// the first shape of feature result
143 TopTools_MapOfShape myLocalSelectedShapes; /// shapes of local selection
145 typedef QMap<FeaturePtr, SelectionInfo> FeatureToSelectionMap;
149 /// \param theModule a pointer to PartSet module
150 PartSet_SketcherMgr(PartSet_Module* theModule);
152 virtual ~PartSet_SketcherMgr();
154 /// Returns true if the operation is the sketch
155 /// \param theOperation an operation
156 /// \return the boolean result
157 static bool isSketchOperation(ModuleBase_Operation* theOperation);
159 /// Returns true if the operation feature belongs to list of granted features of Sketch
160 /// operation. An operation of a sketch should be started before.
161 /// \param theOperation an operation
162 /// \return the boolean result
163 bool isNestedSketchOperation(ModuleBase_Operation* theOperation) const;
165 /// Returns true if the feature kind belongs to list of granted features of Sketch
166 /// operation. An operation of a sketch should be started before.
167 /// \param theOperation an operation
168 /// \return the boolean result
169 bool isNestedSketchFeature(const QString& theFeatureKind) const;
171 /// Returns true if the operation is a create and nested sketch operationn
172 /// \param theOperation a checked operation
173 /// \param theSketch a sketch feature
174 //// \return boolean value
175 bool isNestedCreateOperation(ModuleBase_Operation* theOperation,
176 const CompositeFeaturePtr& /*theSketch*/) const;
178 /// Returns true if the operation is an edit nested feature one
179 /// \param theOperation a checked operation
180 //// \return boolean value
181 bool isNestedEditOperation(ModuleBase_Operation* theOperation,
182 const CompositeFeaturePtr& /*theSketch*/) const;
184 /// Returns whether the current operation is a sketch entity - line, point, arc or circle
185 /// \param theId is an id of object
186 /// \return a boolean value
187 static bool isEntity(const std::string& theId);
189 /// Returns whether the feature has external attribute filled with 'true' value
190 /// \param theFeature a feature object
191 /// \return a boolean value
192 static bool isExternalFeature(const FeaturePtr& theFeature);
194 /// Returns whether the current operation is a sketch distance - lenght, distance or radius
195 /// \param theOperation the operation
196 /// \return a boolean value
197 static bool isDistanceOperation(ModuleBase_Operation* theOperation);
199 /// Returns whether the feature kind is a sketch distance - lenght, distance or radius
200 /// \param theKind the feature kind
201 /// \return a boolean value
202 static bool isDistanceKind(std::string& theKind);
204 /// Returns true if a mouse cursor is over viewer window
205 bool isMouseOverWindow() { return myIsMouseOverWindow; }
207 /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
208 CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
210 /// Returns help class to visualize sketcher plane
211 /// \return a preview plane
212 PartSet_PreviewSketchPlane* previewSketchPlane() const { return mySketchPlane; }
214 /// Starts sketch operation
215 void startSketch(ModuleBase_Operation* );
217 /// Stops sketch operation
218 void stopSketch(ModuleBase_Operation* );
220 /// Starts sketch operation, connects to the opeation property panel
221 /// \param theOperation a committed operation
222 void startNestedSketch(ModuleBase_Operation* theOperation);
224 /// Stop sketch operation, disconnects from the opeation property panel
225 /// \param theOperation a stopped operation
226 void stopNestedSketch(ModuleBase_Operation* theOperation);
228 /// Visualizes the operation feature if it is a creation nested feature operation
229 /// \param theOperation a committed operation
230 void commitNestedSketch(ModuleBase_Operation* theOperation);
232 /// Returns true if the filter is created by the sketch manager
233 /// \param theFilterType a checked type
234 /// \return boolean value
235 bool sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType);
237 /// Append selection filter into the module and type of the filter in internal container
238 /// \param theFilterType selection filter type
239 /// \param theFilter added filter
240 void registerSelectionFilter(const ModuleBase_SelectionFilterType theFilterType,
241 const Handle(SelectMgr_Filter)& theFilter);
243 /// Commit the operation if it is possible. If the operation is dimention constraint,
244 /// it gives widget editor to input dimention value
245 /// \return true if the operation is stopped after activation
246 bool operationActivatedByPreselection();
248 /// Returns True if there are available Undos and the sketch manager allows undo
249 /// \return the boolean result
250 bool canUndo() const;
252 //! Returns True if there are available Redos and the sketch manager allows redo
253 /// \return the boolean result
254 bool canRedo() const;
256 /// Returns False only if the sketch creating feature can not be visualized.
257 /// \return a boolean value
258 //bool canCommitOperation() const;
260 /// Returns whether the object can be erased at the bounds of the active operation.
261 /// Sketch sub-entities can not be erased during the sketch operation
262 /// \param theObject a model object
263 bool canEraseObject(const ObjectPtr& theObject) const;
265 /// Returns whether the object can be displayed at the bounds of the active operation.
266 /// Display only current operation results for usual operation and ask the sketcher manager
267 /// if it is a sketch operation
268 /// \param theObject a model object
269 bool canDisplayObject(const ObjectPtr& theObject) const;
271 /// Returns whether the constraint object can be displayed. It depends on the sketch check
273 /// \param theObject a model object
274 /// \param theState the constraint visible state state to be checked
275 /// \param isProcessed an output parameter if it is processed
276 /// \return result value
277 bool canDisplayConstraint(const FeaturePtr& theObject,
278 const PartSet_Tools::ConstraintVisibleState& theState,
279 bool& isProcessed) const;
281 /// Check the given objects either there are some results of the current sketch. If so,
282 /// it suggests to delete them as there are no functionality to show back hidden sketch objects
283 /// \param theObjects a list of hidden objects
284 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
286 /// Returns true if the mouse is over viewer or property panel value is changed
287 /// \return boolean result
288 bool canDisplayCurrentCreatedFeature() const;
290 /// Returns true if the current operation is nested creation or internal reentrant edit
291 /// \param theOperation an operation
292 bool canChangeCursor(ModuleBase_Operation* theOperation) const;
294 /// Returns state of constraints showing flag
295 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
297 /// Returns true if the object is a current sketch sub feature of a result of the feature
298 /// \param theObject an object
299 /// \return boolean value
300 bool isObjectOfSketch(const ObjectPtr& theObject) const;
302 /// Enumeration for selection mode used
304 ST_HighlightType, /// Only highlighted objects
305 ST_SelectType, /// Only selected objects
306 ST_SelectAndHighlightType /// Both, highlighted and selected objects
309 /// Saves the current selection in the viewer into an internal container
310 /// It obtains the selected attributes.
311 /// The highlighted objects can be processes as the selected ones
312 /// \param theHighlightedOnly a boolean flag
313 /// \param theCurrentSelection a container filled by the current selection
314 void storeSelection(const SelectionType theType, FeatureToSelectionMap& theCurrentSelection);
316 /// Restores previously saved selection state
317 /// \param theCurrentSelection a container filled by the current selection
318 void restoreSelection(FeatureToSelectionMap& theCurrentSelection);
320 /// Return error state of the sketch feature, true if the error has happened
321 /// \return boolean value
322 bool sketchSolverError();
324 //! Returns the feature error if the current state of the feature in the sketch is not correct
325 //! If the feature is correct, it returns an empty value
326 //! Incorrect states: the feature is sketch, the solver error value
327 //! The feature value is reset, this is the flag of sketch mgr
328 //! \return string value
329 QString getFeatureError(const FeaturePtr& theFeature);
331 /// It nullify internal flags concerned to clicked mouse event
332 void clearClickedFlags();
334 /// Returns list of strings which contains id's of sketch replication operations
335 static const QStringList& replicationsIdList();
337 /// Returns list of strings which contains id's of constraints operations
338 static const QStringList& constraintsIdList();
340 /// Returns a list of modes, where the AIS objects should be activated
341 /// \param theSketch a sketch object, modes are empty if sketch plane is not defined yet
342 /// \param theModes a list of modes
343 static void sketchSelectionModes(const CompositeFeaturePtr& theSketch, QIntList& theModes);
345 /// Create specific for the module presentation
346 /// \param theResult an object for presentation
347 /// \return created presentation or NULL(default value)
348 Handle(AIS_InteractiveObject) createPresentation(const ObjectPtr& theResult);
350 /// Connects or disconnects to the value changed signal of the property panel widgets
351 /// \param theWidget a property contol widget
352 /// \param isToConnect a boolean value whether connect or disconnect
353 void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
355 /// Visualize the operation feature if the previous state is modified value in property panel
356 /// \param thePreviousState the previous widget value state
357 void widgetStateChanged(int thePreviousState);
359 /// If the current operation is a dimention one, the style of dimension visualization is send for
360 /// the current object
361 /// \param theObject an object to be customized
362 //void customisePresentation(const ObjectPtr& theObject);
364 void customizeSketchPresentation(const ObjectPtr& theObject, const AISObjectPtr& thePrs) const;
366 /// Update sketch presentations according to the the state
367 /// \param theType a type of sketch visualization style
368 /// \param theState a boolean state
369 void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
372 bool isShowFreePointsShown() const {
373 return myPointsHighlight.size() > 0;
376 PartSet_Module* module() const { return myModule; }
378 /** \brief Implementation of Event Listener method
379 * \param[in] theMessage the data of the event
381 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
385 /// Process sketch plane selected event
386 void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
388 /// The slot is called when user checks "Show free points" button
389 /// \param toShow a state of the check box
390 void onShowPoints(bool toShow);
393 /// Toggle show constraints
394 void onShowConstraintsToggle(int theType, bool theState);
395 /// Process the enter mouse to the view port. If the current operation is a create of
396 /// a nested sketch feature, it updates internal flags to display the feature on mouse move
397 void onEnterViewPort();
398 /// Process the leave mouse of the view port. If the current operation is a create of
399 /// a nested sketch feature, it hides the feature in the viewer
400 void onLeaveViewPort();
401 /// Listens to the value changed signal and display the current operation feature
402 //void onBeforeValuesChangedInPropertyPanel();
403 /// Listens to the signal about the modification of the values
404 /// have been done in the property panel
405 //void onAfterValuesChangedInPropertyPanel();
407 void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
408 void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
409 void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
410 void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
411 void onApplicationStarted();
412 //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
414 void onBeforeContextMenu();
415 void onAfterContextMenu();
418 /// Launches the operation from current highlighting
419 void launchEditing();
421 /// Converts mouse position to 2d coordinates.
422 /// Member myCurrentSketch has to be correctly defined
423 void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
426 /// Show distance value editor if it is a distance operation and all attribute references
427 /// are filled by preseletion
428 /// \return true if the value is accepted
429 static bool setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
430 ModuleBase_IWorkshop* theWorkshop,
431 bool& theCanCommitOperation);
433 /// Applyes the current selection to the object in the workshop viewer
434 /// It includes the selection in all modes of activation, even local context - vertexes, edges
435 /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
436 /// selection owners. If the owner is vertex, the corresponded attribute is seached in
437 /// the feature and if it is in the container of selected attributes, the owner is put in the
438 /// out container. If the owner is edge and the current result is in the container of selected
439 /// results, the owner is put in the out container.
440 /// \param theFeature a feature or result object
441 /// \param theSketch a current sketch feature
442 /// \param theWorkshop a workshop to have an access to AIS context and displayer
443 /// \param theSelection a container of the selection, it has results and attributres for a feature
444 /// \param theOwnersToSelect an out container of found owners
445 static void getSelectionOwners(const FeaturePtr& theFeature,
446 const FeaturePtr& theSketch,
447 ModuleBase_IWorkshop* theWorkshop,
448 const FeatureToSelectionMap& theSelection,
449 SelectMgr_IndexedMapOfOwner& theOwnersToSelect);
451 /// Returns true if the created feature is visible
453 bool isVisibleCreatedFeature() const;
455 /// Returns a current operation
456 /// \return an operation
457 ModuleBase_Operation* getCurrentOperation() const;
459 /// Get the active widget in the property panel
460 ModuleBase_ModelWidget* getActiveWidget() const;
462 /// Erase or display the feature of the current operation. If the mouse over the active view or
463 /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
464 /// \param theOperation an operation which feature is to be displayed,
465 /// it is nested create operation
466 /// \param isToDisplay a flag about the display or erase the feature
467 void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
468 const bool isToDisplay, const bool isFlushRedisplay = true);
471 /// Updates selection priority of the presentation
472 /// \param theObject object to find a presentation which will be corrected
473 /// \param theFeature a feature of the presentation
474 void updateSelectionPriority(ObjectPtr theObject, FeaturePtr theFeature);
475 /// Returns current workshop
476 XGUI_Workshop* workshop() const;
477 /// Returns operation manager
478 XGUI_OperationMgr* operationMgr() const;
480 std::vector<int> colorOfObject(const ObjectPtr& theObject,
481 const FeaturePtr& aFeature, bool isConstruction) const;
484 PartSet_Module* myModule;
485 PartSet_PreviewSketchPlane* mySketchPlane; // display/erase sketch plane on start/stop sketch
487 bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
488 bool myIsEditLaunching;
491 bool myIsMouseOverWindow; /// the state that the mouse over the view
492 /// the state whether the over view state is processed by mouseMove method
493 bool myIsMouseOverViewProcessed;
494 bool myIsPopupMenuActive; /// the state of the popup menu is shown
495 Point myCurrentPoint;
496 //Point myClickedPoint;
498 CompositeFeaturePtr myCurrentSketch;
500 std::set<ModuleBase_SelectionFilterType> mySelectionFilterTypes;
502 FeatureToSelectionMap myCurrentSelection;
503 bool myPreviousUpdateViewerEnabled;
505 QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;
507 PartSet_ExternalPointsMgr* myExternalPointsMgr;
509 QMap<ResultPtr, Handle(AIS_Shape)> myPointsHighlight;