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 <Graphic3d_Structure.hxx> |
af324faa |
20 | #include <Precision.hxx> |
ec357c5c |
21 | #include <Prs3d_Presentation.hxx> |
42cf5bc1 |
22 | #include <Prs3d_Projector.hxx> |
42cf5bc1 |
23 | #include <PrsMgr_ModedPresentation.hxx> |
24 | #include <PrsMgr_PresentableObject.hxx> |
42cf5bc1 |
25 | #include <PrsMgr_PresentationManager.hxx> |
26 | #include <PrsMgr_Prs.hxx> |
27 | #include <Quantity_Color.hxx> |
28 | #include <Standard_Type.hxx> |
92efcf78 |
29 | #include <Graphic3d_CView.hxx> |
30 | |
31 | IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_Presentation,MMgt_TShared) |
7fd59977 |
32 | |
3ae59031 |
33 | namespace |
34 | { |
35 | enum BeforeHighlightState |
36 | { |
37 | State_Empty, |
38 | State_Hidden, |
39 | State_Visible |
40 | }; |
41 | |
4796758e |
42 | static BeforeHighlightState StructureState(const Handle(Prs3d_Presentation)& theStructure) |
3ae59031 |
43 | { |
44 | return !theStructure->IsDisplayed() ? |
45 | State_Empty : !theStructure->IsVisible() ? |
46 | State_Hidden : State_Visible; |
47 | } |
48 | } |
49 | |
af324faa |
50 | //======================================================================= |
51 | //function : PrsMgr_Presentation |
52 | //purpose : |
53 | //======================================================================= |
54 | PrsMgr_Presentation::PrsMgr_Presentation (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, |
55 | const Handle(PrsMgr_PresentableObject)& thePrsObject) |
3ae59031 |
56 | : myPresentationManager (thePrsMgr), |
57 | myPresentableObject (thePrsObject.operator->()), |
58 | myMustBeUpdated (Standard_False), |
59 | myBeforeHighlightState (State_Empty) |
af324faa |
60 | { |
61 | myStructure = new PrsMgr_Prs (thePrsMgr->StructureManager(), |
62 | this, thePrsObject->TypeOfPresentation3d()); |
63 | myStructure->SetOwner (myPresentableObject); |
b7cd4ba7 |
64 | myStructure->SetMutable (myPresentableObject->IsMutable()); |
af324faa |
65 | } |
66 | |
67 | //======================================================================= |
68 | //function : Display |
69 | //purpose : |
70 | //======================================================================= |
71 | void PrsMgr_Presentation::Display() |
72 | { |
a1954302 |
73 | display (Standard_False); |
3ae59031 |
74 | myBeforeHighlightState = State_Visible; |
af324faa |
75 | } |
76 | |
77 | //======================================================================= |
a1954302 |
78 | //function : display |
af324faa |
79 | //purpose : |
80 | //======================================================================= |
a1954302 |
81 | void PrsMgr_Presentation::display (const Standard_Boolean theIsHighlight) |
af324faa |
82 | { |
83 | if (!myStructure->IsDisplayed()) |
84 | { |
b7cd4ba7 |
85 | myStructure->SetIsForHighlight (theIsHighlight); |
af324faa |
86 | myStructure->Display(); |
af324faa |
87 | } |
88 | else if (!myStructure->IsVisible()) |
89 | { |
3ae59031 |
90 | SetVisible (Standard_True); |
b7cd4ba7 |
91 | myStructure->SetIsForHighlight (theIsHighlight); |
af324faa |
92 | } |
93 | } |
94 | |
95 | //======================================================================= |
96 | //function : Erase |
97 | //purpose : |
98 | //======================================================================= |
99 | void PrsMgr_Presentation::Erase() |
100 | { |
101 | if (myStructure.IsNull()) |
102 | { |
103 | return; |
104 | } |
105 | |
106 | // Erase structure from structure manager |
107 | myStructure->Erase(); |
108 | myStructure->Clear(); |
109 | // Disconnect other structures |
110 | myStructure->DisconnectAll (Graphic3d_TOC_DESCENDANT); |
111 | // Clear groups and remove graphic structure |
112 | myStructure.Nullify(); |
113 | } |
114 | |
115 | //======================================================================= |
116 | //function : SetVisible |
117 | //purpose : |
118 | //======================================================================= |
119 | void PrsMgr_Presentation::SetVisible (const Standard_Boolean theValue) |
120 | { |
121 | myStructure->SetVisible (theValue); |
122 | } |
123 | |
124 | //======================================================================= |
125 | //function : Highlight |
126 | //purpose : |
127 | //======================================================================= |
a1954302 |
128 | void PrsMgr_Presentation::Highlight (const Aspect_TypeOfHighlightMethod theMethod, |
129 | const Quantity_Color& theColor) |
af324faa |
130 | { |
3ae59031 |
131 | if (!IsHighlighted()) |
132 | { |
133 | myBeforeHighlightState = StructureState (myStructure); |
134 | } |
135 | |
a1954302 |
136 | display (Standard_True); |
137 | myStructure->Highlight (theMethod, theColor); |
af324faa |
138 | } |
139 | |
140 | //======================================================================= |
141 | //function : Unhighlight |
142 | //purpose : |
143 | //======================================================================= |
144 | void PrsMgr_Presentation::Unhighlight() const |
145 | { |
146 | myStructure->UnHighlight(); |
3ae59031 |
147 | switch (myBeforeHighlightState) |
af324faa |
148 | { |
3ae59031 |
149 | case State_Visible: |
150 | return; |
151 | case State_Hidden: |
af324faa |
152 | myStructure->SetVisible (Standard_False); |
3ae59031 |
153 | break; |
154 | case State_Empty: |
155 | myStructure->Erase(); |
156 | break; |
af324faa |
157 | } |
158 | } |
159 | |
160 | //======================================================================= |
161 | //function : Clear |
162 | //purpose : |
163 | //======================================================================= |
164 | void PrsMgr_Presentation::Clear() |
165 | { |
166 | // This modification remove the contain of the structure: |
167 | // Consequence: |
168 | // 1. The memory zone of the group is reused |
169 | // 2. The speed for animation is constant |
170 | //myPresentableObject = NULL; |
171 | SetUpdateStatus (Standard_True); |
172 | if (myStructure.IsNull()) |
173 | { |
174 | return; |
175 | } |
176 | |
177 | myStructure->Clear (Standard_True); |
178 | // myStructure->Clear(Standard_False); |
179 | myStructure->RemoveAll(); |
180 | } |
181 | |
af324faa |
182 | //======================================================================= |
183 | //function : IsDisplayed |
184 | //purpose : |
185 | //======================================================================= |
186 | Standard_Boolean PrsMgr_Presentation::IsDisplayed() const |
187 | { |
188 | return myStructure->IsDisplayed() |
3ae59031 |
189 | && myStructure->IsVisible(); |
af324faa |
190 | } |
191 | |
192 | //======================================================================= |
193 | //function : IsHighlighted |
194 | //purpose : |
195 | //======================================================================= |
196 | Standard_Boolean PrsMgr_Presentation::IsHighlighted() const |
197 | { |
198 | return myStructure->IsHighlighted(); |
199 | } |
200 | |
201 | //======================================================================= |
202 | //function : DisplayPriority |
203 | //purpose : |
204 | //======================================================================= |
205 | Standard_Integer PrsMgr_Presentation::DisplayPriority() const |
206 | { |
207 | return myStructure->DisplayPriority(); |
208 | } |
209 | |
210 | //======================================================================= |
211 | //function : SetDisplayPriority |
212 | //purpose : |
213 | //======================================================================= |
214 | void PrsMgr_Presentation::SetDisplayPriority (const Standard_Integer theNewPrior) |
215 | { |
216 | myStructure->SetDisplayPriority (theNewPrior); |
217 | } |
218 | |
219 | //======================================================================= |
220 | //function : Connect |
221 | //purpose : |
222 | //======================================================================= |
223 | void PrsMgr_Presentation::Connect (const Handle(PrsMgr_Presentation)& theOther) const |
224 | { |
225 | myStructure->Connect (theOther->Presentation()); |
226 | } |
227 | |
228 | //======================================================================= |
1f7f5a90 |
229 | //function : SetTransformation |
af324faa |
230 | //purpose : |
231 | //======================================================================= |
1f7f5a90 |
232 | void PrsMgr_Presentation::SetTransformation (const Handle(Geom_Transformation)& theTrsf) const |
af324faa |
233 | { |
1f7f5a90 |
234 | myStructure->SetTransformation (theTrsf); |
af324faa |
235 | } |
236 | |
af324faa |
237 | //======================================================================= |
238 | //function : Compute |
239 | //purpose : Methods for hidden parts... |
240 | //======================================================================= |
241 | Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector) |
242 | { |
243 | Handle(Prs3d_Presentation) aPrs = new Prs3d_Presentation (myPresentationManager->StructureManager()); |
244 | myPresentableObject->Compute (Projector (theProjector), aPrs); |
245 | return aPrs; |
246 | } |
247 | |
248 | //======================================================================= |
249 | //function : Compute |
250 | //purpose : |
251 | //======================================================================= |
252 | void PrsMgr_Presentation::Compute (const Handle(Graphic3d_Structure)& theStructure) |
253 | { |
254 | Standard_Integer aDispMode = 0; |
255 | Standard_Integer aPresentationsNumber = myPresentableObject->myPresentations.Length(); |
256 | for (Standard_Integer anIter = 1; anIter <= aPresentationsNumber; ++anIter) |
257 | { |
258 | const PrsMgr_ModedPresentation& aModedPresentation = myPresentableObject->myPresentations.Value (anIter); |
259 | if (aModedPresentation.Presentation().operator->() == this) |
260 | { |
261 | aDispMode = aModedPresentation.Mode(); |
262 | break; |
263 | } |
264 | } |
265 | |
266 | Handle(Prs3d_Presentation) aPrs3d = Handle(Prs3d_Presentation)::DownCast (theStructure); |
267 | myPresentableObject->Compute (myPresentationManager, aPrs3d, aDispMode); |
268 | } |
269 | |
270 | //======================================================================= |
271 | //function : Compute |
272 | //purpose : |
273 | //======================================================================= |
274 | void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, |
275 | const Handle(Graphic3d_Structure)& theStructToFill) |
276 | { |
277 | theStructToFill->Clear(); |
c5f3a425 |
278 | Handle(Prs3d_Presentation) aPrs (Handle(Prs3d_Presentation)::DownCast (theStructToFill)); |
af324faa |
279 | myPresentableObject->Compute (Projector (theProjector), aPrs); |
280 | } |
281 | |
282 | //======================================================================= |
283 | //function : Compute |
284 | //purpose : |
285 | //======================================================================= |
286 | Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, |
287 | const Handle(Geom_Transformation)& theTrsf) |
288 | { |
289 | Handle(Prs3d_Presentation) aPrs3d = new Prs3d_Presentation (myPresentationManager->StructureManager()); |
290 | if (theTrsf->Form() == gp_Translation) |
291 | { |
292 | myPresentableObject->Compute (Projector (theProjector), aPrs3d); |
1f7f5a90 |
293 | aPrs3d->SetTransformation (theTrsf); |
af324faa |
294 | return aPrs3d; |
295 | } |
296 | |
297 | // waiting that something is done in gp_Trsf...rob |
298 | for (Standard_Integer i = 1; i <= 3; ++i) |
299 | { |
300 | for (Standard_Integer j = 1; j <= 3; ++j) |
301 | { |
302 | if (i != j) |
303 | { |
304 | if (Abs (theTrsf->Value (i, j)) > Precision::Confusion()) |
305 | { |
306 | myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs3d); |
307 | return aPrs3d; |
308 | } |
309 | } |
310 | } |
311 | } |
312 | |
313 | myPresentableObject->Compute (Projector (theProjector), aPrs3d); |
1f7f5a90 |
314 | aPrs3d->SetTransformation (theTrsf); |
af324faa |
315 | return aPrs3d; |
316 | } |
317 | |
318 | //======================================================================= |
319 | //function : Compute |
320 | //purpose : |
321 | //======================================================================= |
322 | void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, |
323 | const Handle(Geom_Transformation)& theTrsf, |
324 | const Handle(Graphic3d_Structure)& theStructToFill) |
325 | { |
326 | // recompute HLR after transformation in all the case |
c5f3a425 |
327 | Handle(Prs3d_Presentation) aPrs = Handle(Prs3d_Presentation)::DownCast (theStructToFill); |
af324faa |
328 | theStructToFill->Clear(); |
329 | myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs); |
330 | } |
331 | |
332 | //======================================================================= |
333 | //function : Projector |
334 | //purpose : |
335 | //======================================================================= |
336 | Handle(Prs3d_Projector) PrsMgr_Presentation::Projector (const Handle(Graphic3d_DataStructureManager)& theProjector) |
337 | { |
c357e426 |
338 | Handle(Graphic3d_Camera) aCamera = Handle(Graphic3d_CView)::DownCast (theProjector)->Camera(); |
af324faa |
339 | const gp_Dir aDir = aCamera->Direction().Reversed(); |
340 | const gp_Pnt anAt = aCamera->Center(); |
341 | const gp_Dir anUp = aCamera->Up(); |
342 | Handle(Prs3d_Projector) aProj = new Prs3d_Projector (!aCamera->IsOrthographic(), |
343 | aCamera->Scale(), |
344 | aDir.X(), aDir.Y(), aDir.Z(), |
345 | anAt.X(), anAt.Y(), anAt.Z(), |
346 | anUp.X(), anUp.Y(), anUp.Z()); |
347 | return aProj; |
348 | } |
349 | |
350 | //======================================================================= |
e6f550da |
351 | //function : ~PrsMgr_Presentation |
af324faa |
352 | //purpose : |
353 | //======================================================================= |
e6f550da |
354 | PrsMgr_Presentation::~PrsMgr_Presentation() |
af324faa |
355 | { |
a69a08ee |
356 | Erase(); |
af324faa |
357 | } |
358 | |
359 | //======================================================================= |
360 | //function : SetZLayer |
361 | //purpose : |
362 | //======================================================================= |
363 | void PrsMgr_Presentation::SetZLayer (Standard_Integer theLayerId) |
364 | { |
365 | myStructure->SetZLayer (theLayerId); |
366 | } |
367 | |
368 | //======================================================================= |
369 | //function : GetZLayer |
370 | //purpose : |
371 | //======================================================================= |
372 | Standard_Integer PrsMgr_Presentation::GetZLayer() const |
373 | { |
374 | return myStructure->GetZLayer(); |
7fd59977 |
375 | } |