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 XGUI_ISelectionActivate_H
22 #define XGUI_ISelectionActivate_H
26 #include "ModuleBase_Definitions.h"
27 #include "ModuleBase_ISelectionActivate.h"
29 #include "SelectMgr_ListOfFilter.hxx"
33 class AIS_InteractiveContext;
34 class AIS_InteractiveObject;
35 class ModelAPI_Object;
40 /// A class which implements activation/deactivate selection modes and using selection filters.
41 class XGUI_SelectionActivate : public ModuleBase_ISelectionActivate
44 /// Types of the activation place
45 enum SelectionPlace { Workshop, PropertyPanel, FacesPanel };
49 XGUI_EXPORT XGUI_SelectionActivate(ModuleBase_IWorkshop* theWorkshop);
52 ~XGUI_SelectionActivate() {}
54 /// Returns place of activation modes that now is active
56 SelectionPlace activeSelectionPlace() const;
58 /// Updates active selection modes in the viewer depending on the application state
59 XGUI_EXPORT virtual void updateSelectionModes();
61 /// Updates active selection filters in the viewer depending on the application state
62 XGUI_EXPORT virtual void updateSelectionFilters();
64 /// Activates parameter filters in the workshop, deactivate active out of the container
65 /// Please find a possibility to use updateSelectionFilters instead of direct call this method.
66 /// \param theSelectionFilters a filtes
67 XGUI_EXPORT virtual void activateSelectionFilters
68 (const SelectMgr_ListOfFilter& theSelectionFilters);
70 /// Returns list of currently active selection modes
71 /// Selection modes will be returned according to TopAbs_ShapeEnum
72 XGUI_EXPORT QIntList activeSelectionModes() const;
74 /// Returns true if the given object can be selected
75 /// \param theObject object to check
76 XGUI_EXPORT bool isActive(ObjectPtr theObject) const;
78 /// Activates in local context displayed outside of the context.
79 /// \param theModes - modes on which it has to be activated (can be empty)
80 /// \param theObjList - list of objects which has to be activated.
81 /// \param theUpdateViewer an update viewer flag
82 XGUI_EXPORT void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
83 const bool theUpdateViewer = true);
85 /// Fill container of current selection modes
86 /// \param theModes selection modes
87 XGUI_EXPORT void setSelectionModes(const QIntList& theModes);
89 /// Activate object in the selection modes
90 /// \param theIO an object
91 /// \param theUpdateViewer an update viewer flag
92 XGUI_EXPORT void activateOnDisplay(const Handle(AIS_InteractiveObject)& theIO,
93 const bool theUpdateViewer);
95 /// Activate interactive object
96 /// \param theIO an interactive object
97 /// \param theMode activation mode
98 /// \param theUpdateViewer update viewer flag
99 XGUI_EXPORT void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
100 const bool theUpdateViewer) const;
102 /// Activate interactive object. It is necessary to call ClearOutdatedSelection
103 /// after deactivation
104 /// \param theIO an interactive object
105 /// \param theMode a mode to deactivate. When theMode=-1 then all modes will be deactivated
106 XGUI_EXPORT void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
107 const int theMode = -1) const;
109 /// Activates the interactive object in the local context.
110 /// \param theIO an interactive object
111 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
112 /// \return a flag is object activated or not
113 XGUI_EXPORT bool activate(const Handle(AIS_InteractiveObject)& theIO,
114 const bool theUpdateViewer) const;
116 /// Deactivates the given object (not allow selection)
117 /// \param theObject object to deactivate
118 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
119 XGUI_EXPORT void deactivate(const std::shared_ptr<ModelAPI_Object>& theObject,
120 const bool theUpdateViewer);
122 /// Returns true if the trihedron should be activated in current selection modes
123 bool isTrihedronActive() const { return myIsTrihedronActive; }
125 /// Set trihedron active (used in selection) or non active
126 XGUI_EXPORT void activateTrihedron(bool theIsActive);
128 /// Find a trihedron in a list of displayed presentations and deactivate it.
129 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
130 XGUI_EXPORT void deactivateTrihedron(const bool theUpdateViewer) const;
132 /// Get selection modes of trihedron and deactivate it in it.
133 XGUI_EXPORT void deactivateTrihedronInSelectionModes();
136 /// Returns selection modes of the widget
137 /// \param theWidget model widget
138 /// \param theModes selection modes
139 void getSelectionModes(ModuleBase_ModelWidget* theWidget, QIntList& theModes);
141 /// Returns selection filters of the widget
142 /// \param theWidget model widget
143 /// \param theSelectionFilters selection filters
144 void getSelectionFilters(ModuleBase_ModelWidget* theWidget,
145 SelectMgr_ListOfFilter& theSelectionFilters);
147 /// Returns Trihedron object if it is displayed
148 Handle(AIS_InteractiveObject) getTrihedron() const;
150 /// Returns context of the 3D viewer
151 /// \return context instance
152 Handle(AIS_InteractiveContext) AISContext() const;
154 /// Returns displayer
155 /// \return displayer
156 XGUI_Displayer* getDisplayer() const;
158 /// Returns AIS object displayed in 3D viewer for the given model object
159 /// \param theObject source object
160 /// \returns interactive object
161 AISObjectPtr getDisplayedAISObject(std::shared_ptr<ModelAPI_Object> theObject) const;
163 /// Converts shape type (TopAbs_ShapeEnum) to selection mode
164 /// \param theShapeType a shape type from TopAbs_ShapeEnum
165 static int getSelectionMode(int theShapeType);
168 QIntList myActiveSelectionModes; ///< Current activated selection modes
169 bool myIsTrihedronActive; ///< Flag: use trihedgon for selection or not