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