1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef View_Displayer_H
17 #define View_Displayer_H
19 #include <AIS_ListOfInteractive.hxx>
20 #include <AIS_InteractiveContext.hxx>
22 #include <NCollection_DataMap.hxx>
23 #include <NCollection_Shared.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <Quantity_Color.hxx>
27 #include <inspector/View_PresentationType.hxx>
28 #include <inspector/View_DisplayActionType.hxx>
33 class View_DisplayPreview;
35 //! \class View_Displayer
36 //! \brief It is responsible for communication with AIS Interactive Context to:
37 //! - display/erase presentations;
38 //! - change display mode of visualized presentations (Shaded or WireFrame mode)
40 //! It contains containers of visualized presentations to obtain presentations relating only to this displayer.
41 //! Displayer is connected to AIS Interactive Context
47 Standard_EXPORT View_Displayer();
50 virtual ~View_Displayer() {}
52 //! Returns preview display instance
53 View_DisplayPreview* DisplayPreview() const { return myDisplayPreview; }
55 //! Stores the current context where the presentations will be displayed/erased.
56 //! Erases previuously displayed presentations if there were some displayed
57 //! \param theContext a context instance
58 Standard_EXPORT void SetContext (const Handle(AIS_InteractiveContext)& theContext);
60 //! Stores boolean value if presentations should be keeped. If true, new displayed presentation is added to already
61 //! displayed ones, otherwise the displayed presentation is shown only.
62 //! \param theToKeepPresentation boolean state
63 void KeepPresentations (const bool theToKeepPresentations) { myIsKeepPresentations = theToKeepPresentations; }
65 //! Returns true if fit Fit All should be performed automatically by each Display
66 bool IsFitAllActive() const { return myFitAllActive; }
68 //! Stores flag whether the FitAll should be done automatically for each display
69 //! \param theFitAllActive boolean value
70 void SetFitAllActive (const bool theFitAllActive) { myFitAllActive = theFitAllActive; }
72 //! Returns current display mode: 0 - AIS_WireFrame, 1 - AIS_Shaded
73 int DisplayMode() const { return myDisplayMode; }
75 //! Stores display mode and changes display mode of displayed presentations
76 //! \param theDisplayMode a mode: 0 - AIS_WireFrame, 1 - AIS_Shaded
77 //! \param theType presentation type
78 //! \param isToUpdateView boolean state if viewer should be updated
79 Standard_EXPORT void SetDisplayMode (const int theDisplayMode,
80 const View_PresentationType theType = View_PresentationType_Main,
81 const bool theToUpdateViewer = true);
83 //! Displays presentation in context, erase previous presentations if KeepPresentations is false,
84 //! Color of presentation is from attribute color if exists or the default color
85 //! Display mode is equal to the view state
86 //! If KeepPresentations is false, the viewer is fit all
87 //! Displayed presentation is stored in an internal map of displayed presentations
88 //! \param thePresentation a presentation, it will be casted to AIS_InteractiveObject
89 //! \param theType presentation type
90 //! \param isToUpdateView boolean state if viewer should be updated
91 Standard_EXPORT void DisplayPresentation (const Handle(Standard_Transient)& thePresentation,
92 const View_PresentationType theType = View_PresentationType_Main,
93 const bool theToUpdateViewer = true);
95 //! Redisplays the parameter presentation in current context
96 //! \param thePresentation a presentation, it will be casted to AIS_InteractiveObject
97 //! \param isToUpdateView boolean state if viewer should be updated
98 Standard_EXPORT void RedisplayPresentation (const Handle(Standard_Transient)& thePresentation,
99 const bool theToUpdateViewer = true);
101 //! Erases all presentations from viewer. Iterates by internal map of displayed presentations and
102 //! erase these presentations.
103 //! \param isToUpdateView boolean state if viewer should be updated
104 Standard_EXPORT void EraseAllPresentations (const bool theToUpdateViewer = true);
106 //! Erases presentations of the given type
107 //! \param theType presentation type
108 //! \param isToUpdateView boolean state if viewer should be updated
109 Standard_EXPORT void ErasePresentations (const View_PresentationType theType = View_PresentationType_Main,
110 const bool theToUpdateViewer = true);
112 //! Erases presentation from viewer
113 //! \param thePresentation a presentation, it will be casted to AIS_InteractiveObject
114 //! \param theType presentation type
115 //! \param isToUpdateView boolean state if viewer should be updated
116 Standard_EXPORT void ErasePresentation (const Handle(Standard_Transient)& thePresentation,
117 const View_PresentationType theType = View_PresentationType_Main,
118 const bool theToUpdateViewer = true);
120 //! Displays presentation of default trihedron, create it by the first call
121 //! \param toDisplay flag to display presentation if true, or erase it
122 //! \param isToUpdateView boolean state if viewer should be updated
123 Standard_EXPORT void DisplayDefaultTrihedron (const Standard_Boolean toDisplay, const bool theToUpdateViewer);
125 //! Displays presentation of view cube, create it by the first call
126 //! \param toDisplay flag to display presentation if true, or erase it
127 //! \param isToUpdateView boolean state if viewer should be updated
128 Standard_EXPORT void DisplayViewCube (const Standard_Boolean toDisplay, const bool theToUpdateViewer);
130 //! Sets shape visible/invisible
131 //! \theShape shape instance
132 //! \theState visibility state
133 Standard_EXPORT void SetVisible (const TopoDS_Shape& theShape, const bool theState,
134 const View_PresentationType theType = View_PresentationType_Main);
136 //! Returns visibility state value
137 //! \theShape shape instance
138 Standard_EXPORT bool IsVisible (const TopoDS_Shape& theShape,
139 const View_PresentationType theType = View_PresentationType_Main) const;
141 //! Updates visibility of the presentations for the display type
142 Standard_EXPORT void UpdatePreview (const View_DisplayActionType theType,
143 const NCollection_List<Handle(Standard_Transient)>& thePresentations);
145 //! Calls UpdateCurrentViewer of context
146 Standard_EXPORT void UpdateViewer();
148 //! Stores color for type of presentation. During display of presentation of the given type, the color is used
149 //! \param theColor a presentation color
150 //! \param theType presentation type
151 Standard_EXPORT void SetAttributeColor (const Quantity_Color& theColor,
152 const View_PresentationType theType = View_PresentationType_Main);
154 //! Returns container of displayed presentations for the given type
155 //! \param thePresentations a container to be filled
156 //! \param theType presentation type
157 Standard_EXPORT void DisplayedPresentations (NCollection_Shared<AIS_ListOfInteractive>& thePresentations,
158 const View_PresentationType theType = View_PresentationType_Main) const;
160 //! Returns all displayed by the trihedron objects
161 const NCollection_DataMap<View_PresentationType, NCollection_Shared<AIS_ListOfInteractive>>& GetDisplayed() const { return myDisplayed; }
163 //! Returns presentation if there is displayed AIS_Shape presentation for the parameter shape
164 //! \param theShape a shape instance
165 //! \param theType presentation type
166 //! \return presentation instance or NULL
167 Standard_EXPORT Handle(AIS_InteractiveObject) FindPresentation (const TopoDS_Shape& theShape,
168 const View_PresentationType theType = View_PresentationType_Main) const;
170 //! Creates AIS_Shape for the shape
171 //! \param theShape a shape
172 //! \return presentation
173 Standard_EXPORT static Handle(Standard_Transient) CreatePresentation (const TopoDS_Shape& theShape);
177 //! Returns the current context
178 const Handle(AIS_InteractiveContext)& GetContext() const { return myContext; }
181 Handle(V3d_View) GetView() const;
186 //! Returns default trihedron, create it if flag allows
187 //! \param toCreate boolean state if trihedron should be created if it is NULL
188 const Handle(AIS_Trihedron)& defaultTrihedron (const bool toCreate);
192 View_DisplayPreview* myDisplayPreview; //!< class for preview display
194 Handle(AIS_InteractiveContext) myContext; //!< context, where the displayer works
195 Handle(AIS_Trihedron) myDefaultTrihedron; //!< trihedron presentation for the current context
196 Handle(AIS_ViewCube) myViewCube; //!< view cube presentation for current context
198 NCollection_DataMap<View_PresentationType, NCollection_Shared<AIS_ListOfInteractive>> myDisplayed; //!< visualized presentations
199 NCollection_DataMap<View_PresentationType, Quantity_Color> myColorAttributes; //!< color properties of presentations
201 bool myIsKeepPresentations; //!< flag if previously shown presentations stays in the context by displaying a new one
202 bool myFitAllActive; //!< flag if Fit All should be performed automatically by each Display
203 int myDisplayMode; //!< display mode: 0 - AIS_WireFrame, 1 - AIS_Shaded