b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
2831708b |
15 | #include <PrsMgr_Presentation.hxx> |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <Geom_Transformation.hxx> |
18 | #include <Graphic3d_DataStructureManager.hxx> |
af324faa |
19 | #include <Precision.hxx> |
f838dac4 |
20 | #include <Prs3d_Drawer.hxx> |
42cf5bc1 |
21 | #include <Prs3d_Projector.hxx> |
42cf5bc1 |
22 | #include <PrsMgr_PresentableObject.hxx> |
42cf5bc1 |
23 | #include <PrsMgr_PresentationManager.hxx> |
42cf5bc1 |
24 | #include <Quantity_Color.hxx> |
92efcf78 |
25 | #include <Graphic3d_CView.hxx> |
26 | |
7dd7c146 |
27 | IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_Presentation, Graphic3d_Structure) |
7fd59977 |
28 | |
3ae59031 |
29 | namespace |
30 | { |
31 | enum BeforeHighlightState |
32 | { |
33 | State_Empty, |
34 | State_Hidden, |
35 | State_Visible |
36 | }; |
37 | |
7dd7c146 |
38 | static BeforeHighlightState StructureState (const Graphic3d_Structure* theStructure) |
3ae59031 |
39 | { |
40 | return !theStructure->IsDisplayed() ? |
41 | State_Empty : !theStructure->IsVisible() ? |
42 | State_Hidden : State_Visible; |
43 | } |
44 | } |
45 | |
af324faa |
46 | //======================================================================= |
47 | //function : PrsMgr_Presentation |
48 | //purpose : |
49 | //======================================================================= |
50 | PrsMgr_Presentation::PrsMgr_Presentation (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, |
7dd7c146 |
51 | const Handle(PrsMgr_PresentableObject)& thePrsObject, |
52 | const Standard_Integer theMode) |
53 | : Graphic3d_Structure (thePrsMgr->StructureManager()), |
54 | myPresentationManager (thePrsMgr), |
55 | myPresentableObject (thePrsObject.get()), |
56 | myBeforeHighlightState (State_Empty), |
57 | myMode (theMode), |
58 | myMustBeUpdated (Standard_False) |
af324faa |
59 | { |
7dd7c146 |
60 | if (thePrsObject->TypeOfPresentation3d() == PrsMgr_TOP_ProjectorDependant) |
61 | { |
62 | SetVisual (Graphic3d_TOS_COMPUTED); |
63 | } |
64 | SetOwner (myPresentableObject); |
65 | SetMutable (myPresentableObject->IsMutable()); |
af324faa |
66 | } |
67 | |
68 | //======================================================================= |
69 | //function : Display |
70 | //purpose : |
71 | //======================================================================= |
72 | void PrsMgr_Presentation::Display() |
73 | { |
a1954302 |
74 | display (Standard_False); |
3ae59031 |
75 | myBeforeHighlightState = State_Visible; |
af324faa |
76 | } |
77 | |
78 | //======================================================================= |
a1954302 |
79 | //function : display |
af324faa |
80 | //purpose : |
81 | //======================================================================= |
a1954302 |
82 | void PrsMgr_Presentation::display (const Standard_Boolean theIsHighlight) |
af324faa |
83 | { |
7dd7c146 |
84 | if (!base_type::IsDisplayed()) |
af324faa |
85 | { |
49dfdb7a |
86 | base_type::SetIsForHighlight (theIsHighlight); // optimization - disable frustum culling for this presentation |
7dd7c146 |
87 | base_type::Display(); |
af324faa |
88 | } |
7dd7c146 |
89 | else if (!base_type::IsVisible()) |
af324faa |
90 | { |
7dd7c146 |
91 | base_type::SetVisible (Standard_True); |
af324faa |
92 | } |
93 | } |
94 | |
95 | //======================================================================= |
96 | //function : Erase |
97 | //purpose : |
98 | //======================================================================= |
99 | void PrsMgr_Presentation::Erase() |
100 | { |
7dd7c146 |
101 | if (IsDeleted()) |
af324faa |
102 | { |
103 | return; |
104 | } |
105 | |
106 | // Erase structure from structure manager |
7dd7c146 |
107 | base_type::Erase(); |
108 | base_type::Clear(); |
af324faa |
109 | // Disconnect other structures |
7dd7c146 |
110 | base_type::DisconnectAll (Graphic3d_TOC_DESCENDANT); |
af324faa |
111 | // Clear groups and remove graphic structure |
7dd7c146 |
112 | base_type::Remove(); |
af324faa |
113 | } |
114 | |
115 | //======================================================================= |
116 | //function : Highlight |
117 | //purpose : |
118 | //======================================================================= |
f838dac4 |
119 | void PrsMgr_Presentation::Highlight (const Handle(Prs3d_Drawer)& theStyle) |
af324faa |
120 | { |
3ae59031 |
121 | if (!IsHighlighted()) |
122 | { |
7dd7c146 |
123 | myBeforeHighlightState = StructureState (this); |
3ae59031 |
124 | } |
125 | |
a1954302 |
126 | display (Standard_True); |
7dd7c146 |
127 | base_type::Highlight (theStyle); |
af324faa |
128 | } |
129 | |
130 | //======================================================================= |
131 | //function : Unhighlight |
132 | //purpose : |
133 | //======================================================================= |
7dd7c146 |
134 | void PrsMgr_Presentation::Unhighlight() |
af324faa |
135 | { |
7dd7c146 |
136 | base_type::UnHighlight(); |
3ae59031 |
137 | switch (myBeforeHighlightState) |
af324faa |
138 | { |
7dd7c146 |
139 | case State_Visible: |
140 | return; |
141 | case State_Hidden: |
142 | base_type::SetVisible (Standard_False); |
143 | break; |
144 | case State_Empty: |
145 | base_type::Erase(); |
146 | break; |
af324faa |
147 | } |
148 | } |
149 | |
150 | //======================================================================= |
151 | //function : Clear |
152 | //purpose : |
153 | //======================================================================= |
7dd7c146 |
154 | void PrsMgr_Presentation::Clear (const Standard_Boolean theWithDestruction) |
af324faa |
155 | { |
156 | // This modification remove the contain of the structure: |
157 | // Consequence: |
158 | // 1. The memory zone of the group is reused |
159 | // 2. The speed for animation is constant |
160 | //myPresentableObject = NULL; |
161 | SetUpdateStatus (Standard_True); |
7dd7c146 |
162 | if (IsDeleted()) |
af324faa |
163 | { |
164 | return; |
165 | } |
166 | |
7dd7c146 |
167 | base_type::Clear (theWithDestruction); |
168 | base_type::DisconnectAll (Graphic3d_TOC_DESCENDANT); |
af324faa |
169 | } |
170 | |
af324faa |
171 | //======================================================================= |
7dd7c146 |
172 | //function : Compute |
af324faa |
173 | //purpose : |
174 | //======================================================================= |
7dd7c146 |
175 | void PrsMgr_Presentation::Compute() |
af324faa |
176 | { |
7dd7c146 |
177 | Standard_Integer aDispMode = 0; |
178 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentableObject->myPresentations); aPrsIter.More(); aPrsIter.Next()) |
179 | { |
180 | const Handle(PrsMgr_Presentation)& aModedPresentation = aPrsIter.Value(); |
181 | if (aModedPresentation == this) |
182 | { |
183 | aDispMode = aModedPresentation->Mode(); |
184 | break; |
185 | } |
186 | } |
af324faa |
187 | |
7dd7c146 |
188 | myPresentableObject->Compute (myPresentationManager, this, aDispMode); |
af324faa |
189 | } |
190 | |
af324faa |
191 | //======================================================================= |
192 | //function : Compute |
193 | //purpose : Methods for hidden parts... |
194 | //======================================================================= |
195 | Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector) |
196 | { |
7dd7c146 |
197 | Handle(Graphic3d_Structure) aPrs = new Graphic3d_Structure (myPresentationManager->StructureManager()); |
af324faa |
198 | myPresentableObject->Compute (Projector (theProjector), aPrs); |
199 | return aPrs; |
200 | } |
201 | |
af324faa |
202 | //======================================================================= |
203 | //function : Compute |
204 | //purpose : |
205 | //======================================================================= |
206 | void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, |
7dd7c146 |
207 | Handle(Graphic3d_Structure)& theStructToFill) |
af324faa |
208 | { |
209 | theStructToFill->Clear(); |
7dd7c146 |
210 | Handle(Prs3d_Presentation) aPrs = theStructToFill; |
af324faa |
211 | myPresentableObject->Compute (Projector (theProjector), aPrs); |
212 | } |
213 | |
214 | //======================================================================= |
215 | //function : Compute |
216 | //purpose : |
217 | //======================================================================= |
218 | Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, |
219 | const Handle(Geom_Transformation)& theTrsf) |
220 | { |
221 | Handle(Prs3d_Presentation) aPrs3d = new Prs3d_Presentation (myPresentationManager->StructureManager()); |
1eeef710 |
222 | myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs3d); |
af324faa |
223 | return aPrs3d; |
224 | } |
225 | |
226 | //======================================================================= |
227 | //function : Compute |
228 | //purpose : |
229 | //======================================================================= |
230 | void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, |
7dd7c146 |
231 | const Handle(Geom_Transformation)& theTrsf, |
232 | Handle(Graphic3d_Structure)& theStructToFill) |
af324faa |
233 | { |
234 | // recompute HLR after transformation in all the case |
7dd7c146 |
235 | Handle(Graphic3d_Structure) aPrs = theStructToFill; |
af324faa |
236 | theStructToFill->Clear(); |
237 | myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs); |
238 | } |
239 | |
240 | //======================================================================= |
241 | //function : Projector |
242 | //purpose : |
243 | //======================================================================= |
244 | Handle(Prs3d_Projector) PrsMgr_Presentation::Projector (const Handle(Graphic3d_DataStructureManager)& theProjector) |
245 | { |
c357e426 |
246 | Handle(Graphic3d_Camera) aCamera = Handle(Graphic3d_CView)::DownCast (theProjector)->Camera(); |
af324faa |
247 | const gp_Dir aDir = aCamera->Direction().Reversed(); |
248 | const gp_Pnt anAt = aCamera->Center(); |
249 | const gp_Dir anUp = aCamera->Up(); |
250 | Handle(Prs3d_Projector) aProj = new Prs3d_Projector (!aCamera->IsOrthographic(), |
251 | aCamera->Scale(), |
252 | aDir.X(), aDir.Y(), aDir.Z(), |
253 | anAt.X(), anAt.Y(), anAt.Z(), |
254 | anUp.X(), anUp.Y(), anUp.Z()); |
255 | return aProj; |
256 | } |
257 | |
258 | //======================================================================= |
e6f550da |
259 | //function : ~PrsMgr_Presentation |
af324faa |
260 | //purpose : |
261 | //======================================================================= |
e6f550da |
262 | PrsMgr_Presentation::~PrsMgr_Presentation() |
af324faa |
263 | { |
a69a08ee |
264 | Erase(); |
af324faa |
265 | } |