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