1 // Copyright (C) 2014-2023 CEA, EDF
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 XGUI_ISelectionActivate_H
21 #define XGUI_ISelectionActivate_H
25 #include "ModuleBase_Definitions.h"
26 #include "ModuleBase_ISelectionActivate.h"
28 #include "SelectMgr_ListOfFilter.hxx"
32 class AIS_InteractiveContext;
33 class AIS_InteractiveObject;
34 class ModelAPI_Object;
39 /// A class which implements activation/deactivate selection modes and using selection filters.
40 class XGUI_SelectionActivate : public ModuleBase_ISelectionActivate
43 /// Types of the activation place
44 enum SelectionPlace { Workshop, PropertyPanel, FacesPanel };
48 XGUI_EXPORT XGUI_SelectionActivate(ModuleBase_IWorkshop* theWorkshop);
51 ~XGUI_SelectionActivate() {}
53 /// Returns place of activation modes that now is active
55 SelectionPlace activeSelectionPlace() const;
57 /// Updates active selection modes in the viewer depending on the application state
58 XGUI_EXPORT virtual void updateSelectionModes();
60 /// Updates active selection filters in the viewer depending on the application state
61 XGUI_EXPORT virtual void updateSelectionFilters();
63 /// Activates parameter filters in the workshop, deactivate active out of the container
64 /// Please find a possibility to use updateSelectionFilters instead of direct call this method.
65 /// \param theSelectionFilters a filtes
66 XGUI_EXPORT virtual void activateSelectionFilters
67 (const SelectMgr_ListOfFilter& theSelectionFilters);
69 /// Returns list of currently active selection modes
70 /// Selection modes will be returned according to TopAbs_ShapeEnum
71 XGUI_EXPORT QIntList activeSelectionModes() const;
73 /// Returns true if the given object can be selected
74 /// \param theObject object to check
75 XGUI_EXPORT bool isActive(ObjectPtr theObject) const;
77 /// Activates in local context displayed outside of the context.
78 /// \param theModes - modes on which it has to be activated (can be empty)
79 /// \param theObjList - list of objects which has to be activated.
80 /// \param theUpdateViewer an update viewer flag
81 XGUI_EXPORT void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
82 const bool theUpdateViewer = true);
84 /// Fill container of current selection modes
85 /// \param theModes selection modes
86 XGUI_EXPORT void setSelectionModes(const QIntList& theModes);
88 /// Activate object in the selection modes
89 /// \param theIO an object
90 /// \param theUpdateViewer an update viewer flag
91 XGUI_EXPORT void activateOnDisplay(const Handle(AIS_InteractiveObject)& theIO,
92 const bool theUpdateViewer);
94 /// Activate interactive object
95 /// \param theIO an interactive object
96 /// \param theMode activation mode
97 /// \param theUpdateViewer update viewer flag
98 XGUI_EXPORT void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
99 const bool theUpdateViewer) const;
101 /// Activate interactive object. It is necessary to call ClearOutdatedSelection
102 /// after deactivation
103 /// \param theIO an interactive object
104 /// \param theMode a mode to deactivate. When theMode=-1 then all modes will be deactivated
105 XGUI_EXPORT void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
106 const int theMode = -1) const;
108 /// Activates the interactive object in the local context.
109 /// \param theIO an interactive object
110 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
111 /// \return a flag is object activated or not
112 XGUI_EXPORT bool activate(const Handle(AIS_InteractiveObject)& theIO,
113 const bool theUpdateViewer) const;
115 /// Deactivates the given object (not allow selection)
116 /// \param theObject object to deactivate
117 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
118 XGUI_EXPORT void deactivate(const std::shared_ptr<ModelAPI_Object>& theObject,
119 const bool theUpdateViewer);
121 /// Returns true if the trihedron should be activated in current selection modes
122 bool isTrihedronActive() const { return myIsTrihedronActive; }
124 /// Set trihedron active (used in selection) or non active
125 XGUI_EXPORT void activateTrihedron(bool theIsActive);
127 /// Find a trihedron in a list of displayed presentations and deactivate it.
128 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
129 XGUI_EXPORT void deactivateTrihedron(const bool theUpdateViewer) const;
131 /// Get selection modes of trihedron and deactivate it in it.
132 XGUI_EXPORT void deactivateTrihedronInSelectionModes();
135 /// Returns selection modes of the widget
136 /// \param theWidget model widget
137 /// \param theModes selection modes
138 void getSelectionModes(ModuleBase_ModelWidget* theWidget, QIntList& theModes);
140 /// Returns Trihedron object if it is displayed
141 Handle(AIS_InteractiveObject) getTrihedron() const;
143 /// Returns context of the 3D viewer
144 /// \return context instance
145 Handle(AIS_InteractiveContext) AISContext() const;
147 /// Returns displayer
148 /// \return displayer
149 XGUI_Displayer* getDisplayer() const;
151 /// Returns AIS object displayed in 3D viewer for the given model object
152 /// \param theObject source object
153 /// \returns interactive object
154 AISObjectPtr getDisplayedAISObject(std::shared_ptr<ModelAPI_Object> theObject) const;
156 /// Converts shape type (TopAbs_ShapeEnum) to selection mode
157 /// \param theShapeType a shape type from TopAbs_ShapeEnum
158 static int getSelectionMode(int theShapeType);
161 QIntList myActiveSelectionModes; ///< Current activated selection modes
162 bool myIsTrihedronActive; ///< Flag: use trihedgon for selection or not