1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <PrsMgr_Presentation.ixx>
16 #include <PrsMgr_PresentationManager.hxx>
17 #include <PrsMgr_Prs.hxx>
18 #include <PrsMgr_ModedPresentation.hxx>
20 #include <Graphic3d_Structure.hxx>
21 #include <Visual3d_View.hxx>
22 #include <Precision.hxx>
26 enum BeforeHighlightState
33 static BeforeHighlightState StructureState(const Handle(PrsMgr_Prs) theStructure)
35 return !theStructure->IsDisplayed() ?
36 State_Empty : !theStructure->IsVisible() ?
37 State_Hidden : State_Visible;
41 //=======================================================================
42 //function : PrsMgr_Presentation
44 //=======================================================================
45 PrsMgr_Presentation::PrsMgr_Presentation (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
46 const Handle(PrsMgr_PresentableObject)& thePrsObject)
47 : myPresentationManager (thePrsMgr),
48 myPresentableObject (thePrsObject.operator->()),
49 myMustBeUpdated (Standard_False),
50 myBeforeHighlightState (State_Empty)
52 myStructure = new PrsMgr_Prs (thePrsMgr->StructureManager(),
53 this, thePrsObject->TypeOfPresentation3d());
54 myStructure->SetOwner (myPresentableObject);
57 //=======================================================================
60 //=======================================================================
61 void PrsMgr_Presentation::Display()
63 Display (Standard_False);
64 myBeforeHighlightState = State_Visible;
67 //=======================================================================
70 //=======================================================================
71 void PrsMgr_Presentation::Display (const Standard_Boolean /*theIsHighlight*/)
73 if (!myStructure->IsDisplayed())
75 myStructure->Display();
77 else if (!myStructure->IsVisible())
79 SetVisible (Standard_True);
83 //=======================================================================
86 //=======================================================================
87 void PrsMgr_Presentation::Erase()
89 if (myStructure.IsNull())
94 // Erase structure from structure manager
97 // Disconnect other structures
98 myStructure->DisconnectAll (Graphic3d_TOC_DESCENDANT);
99 // Clear groups and remove graphic structure
100 myStructure.Nullify();
103 //=======================================================================
104 //function : SetVisible
106 //=======================================================================
107 void PrsMgr_Presentation::SetVisible (const Standard_Boolean theValue)
109 myStructure->SetVisible (theValue);
112 //=======================================================================
113 //function : Highlight
115 //=======================================================================
116 void PrsMgr_Presentation::Highlight()
118 if (!IsHighlighted())
120 myBeforeHighlightState = StructureState (myStructure);
123 Display (Standard_True);
124 myStructure->Highlight();
127 //=======================================================================
128 //function : Unhighlight
130 //=======================================================================
131 void PrsMgr_Presentation::Unhighlight() const
133 myStructure->UnHighlight();
134 switch (myBeforeHighlightState)
139 myStructure->SetVisible (Standard_False);
142 myStructure->Erase();
147 //=======================================================================
150 //=======================================================================
151 void PrsMgr_Presentation::Clear()
153 // This modification remove the contain of the structure:
155 // 1. The memory zone of the group is reused
156 // 2. The speed for animation is constant
157 //myPresentableObject = NULL;
158 SetUpdateStatus (Standard_True);
159 if (myStructure.IsNull())
164 myStructure->Clear (Standard_True);
165 // myStructure->Clear(Standard_False);
166 myStructure->RemoveAll();
169 //=======================================================================
172 //=======================================================================
173 void PrsMgr_Presentation::Color (const Quantity_NameOfColor theColor)
175 if (!IsHighlighted())
177 myBeforeHighlightState = StructureState (myStructure);
180 Display (Standard_True);
181 myStructure->Color (theColor);
184 //=======================================================================
185 //function : BoundBox
187 //=======================================================================
188 void PrsMgr_Presentation::BoundBox() const
190 myStructure->BoundBox();
193 //=======================================================================
194 //function : IsDisplayed
196 //=======================================================================
197 Standard_Boolean PrsMgr_Presentation::IsDisplayed() const
199 return myStructure->IsDisplayed()
200 && myStructure->IsVisible();
203 //=======================================================================
204 //function : IsHighlighted
206 //=======================================================================
207 Standard_Boolean PrsMgr_Presentation::IsHighlighted() const
209 return myStructure->IsHighlighted();
212 //=======================================================================
213 //function : DisplayPriority
215 //=======================================================================
216 Standard_Integer PrsMgr_Presentation::DisplayPriority() const
218 return myStructure->DisplayPriority();
221 //=======================================================================
222 //function : SetDisplayPriority
224 //=======================================================================
225 void PrsMgr_Presentation::SetDisplayPriority (const Standard_Integer theNewPrior)
227 myStructure->SetDisplayPriority (theNewPrior);
230 //=======================================================================
233 //=======================================================================
234 void PrsMgr_Presentation::Connect (const Handle(PrsMgr_Presentation)& theOther) const
236 myStructure->Connect (theOther->Presentation());
239 //=======================================================================
240 //function : Transform
242 //=======================================================================
243 void PrsMgr_Presentation::Transform (const Handle(Geom_Transformation)& theTrsf) const
245 myStructure->Transform (theTrsf);
248 //=======================================================================
251 //=======================================================================
252 void PrsMgr_Presentation::Place (const Quantity_Length theX,
253 const Quantity_Length theY,
254 const Quantity_Length theZ) const
256 myStructure->Place (theX, theY, theZ);
259 //=======================================================================
260 //function : Multiply
262 //=======================================================================
263 void PrsMgr_Presentation::Multiply (const Handle(Geom_Transformation)& theTrsf) const
265 myStructure->Multiply (theTrsf);
268 //=======================================================================
271 //=======================================================================
272 void PrsMgr_Presentation::Move (const Quantity_Length theX,
273 const Quantity_Length theY,
274 const Quantity_Length theZ) const
276 myStructure->Move (theX, theY, theZ);
279 //=======================================================================
280 //function : SetShadingAspect
282 //=======================================================================
283 void PrsMgr_Presentation::SetShadingAspect (const Handle(Prs3d_ShadingAspect)& theShadingAspect) const
285 myStructure->SetShadingAspect (theShadingAspect);
288 //=======================================================================
290 //purpose : Methods for hidden parts...
291 //=======================================================================
292 Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector)
294 Handle(Prs3d_Presentation) aPrs = new Prs3d_Presentation (myPresentationManager->StructureManager());
295 myPresentableObject->Compute (Projector (theProjector), aPrs);
299 //=======================================================================
302 //=======================================================================
303 void PrsMgr_Presentation::Compute (const Handle(Graphic3d_Structure)& theStructure)
305 Standard_Integer aDispMode = 0;
306 Standard_Integer aPresentationsNumber = myPresentableObject->myPresentations.Length();
307 for (Standard_Integer anIter = 1; anIter <= aPresentationsNumber; ++anIter)
309 const PrsMgr_ModedPresentation& aModedPresentation = myPresentableObject->myPresentations.Value (anIter);
310 if (aModedPresentation.Presentation().operator->() == this)
312 aDispMode = aModedPresentation.Mode();
317 Handle(Prs3d_Presentation) aPrs3d = Handle(Prs3d_Presentation)::DownCast (theStructure);
318 myPresentableObject->Compute (myPresentationManager, aPrs3d, aDispMode);
321 //=======================================================================
324 //=======================================================================
325 void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
326 const Handle(Graphic3d_Structure)& theStructToFill)
328 theStructToFill->Clear();
329 const Handle(Prs3d_Presentation)& aPrs = *((Handle(Prs3d_Presentation)* )&theStructToFill);
330 myPresentableObject->Compute (Projector (theProjector), aPrs);
333 //=======================================================================
336 //=======================================================================
337 Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
338 const Handle(Geom_Transformation)& theTrsf)
340 Handle(Prs3d_Presentation) aPrs3d = new Prs3d_Presentation (myPresentationManager->StructureManager());
341 if (theTrsf->Form() == gp_Translation)
343 myPresentableObject->Compute (Projector (theProjector), aPrs3d);
344 aPrs3d->Transform (theTrsf);
348 // waiting that something is done in gp_Trsf...rob
349 for (Standard_Integer i = 1; i <= 3; ++i)
351 for (Standard_Integer j = 1; j <= 3; ++j)
355 if (Abs (theTrsf->Value (i, j)) > Precision::Confusion())
357 myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs3d);
364 myPresentableObject->Compute (Projector (theProjector), aPrs3d);
365 aPrs3d->Transform (theTrsf);
369 //=======================================================================
372 //=======================================================================
373 void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
374 const Handle(Geom_Transformation)& theTrsf,
375 const Handle(Graphic3d_Structure)& theStructToFill)
377 // recompute HLR after transformation in all the case
378 Handle(Prs3d_Presentation) aPrs = *((Handle(Prs3d_Presentation)*)&theStructToFill);
379 theStructToFill->Clear();
380 myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs);
383 //=======================================================================
384 //function : Projector
386 //=======================================================================
387 Handle(Prs3d_Projector) PrsMgr_Presentation::Projector (const Handle(Graphic3d_DataStructureManager)& theProjector)
389 const Handle(Graphic3d_Camera)& aCamera = Handle(Visual3d_View)::DownCast (theProjector)->Camera();
390 const gp_Dir aDir = aCamera->Direction().Reversed();
391 const gp_Pnt anAt = aCamera->Center();
392 const gp_Dir anUp = aCamera->Up();
393 Handle(Prs3d_Projector) aProj = new Prs3d_Projector (!aCamera->IsOrthographic(),
395 aDir.X(), aDir.Y(), aDir.Z(),
396 anAt.X(), anAt.Y(), anAt.Z(),
397 anUp.X(), anUp.Y(), anUp.Z());
401 //=======================================================================
404 //=======================================================================
405 void PrsMgr_Presentation::Destroy()
407 if (!myStructure.IsNull())
409 // Remove structure from the list of displayed structures.
410 myStructure->Erase();
411 myStructure->Clear();
412 myStructure.Nullify();
416 //=======================================================================
417 //function : SetZLayer
419 //=======================================================================
420 void PrsMgr_Presentation::SetZLayer (Standard_Integer theLayerId)
422 myStructure->SetZLayer (theLayerId);
425 //=======================================================================
426 //function : GetZLayer
428 //=======================================================================
429 Standard_Integer PrsMgr_Presentation::GetZLayer() const
431 return myStructure->GetZLayer();