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.hxx>
17 #include <Geom_Transformation.hxx>
18 #include <Graphic3d_DataStructureManager.hxx>
19 #include <Precision.hxx>
20 #include <Prs3d_Drawer.hxx>
21 #include <Prs3d_Projector.hxx>
22 #include <PrsMgr_PresentableObject.hxx>
23 #include <PrsMgr_PresentationManager.hxx>
24 #include <Quantity_Color.hxx>
25 #include <Graphic3d_CView.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_Presentation, Graphic3d_Structure)
31 enum BeforeHighlightState
38 static BeforeHighlightState StructureState (const Graphic3d_Structure* theStructure)
40 return !theStructure->IsDisplayed() ?
41 State_Empty : !theStructure->IsVisible() ?
42 State_Hidden : State_Visible;
46 //=======================================================================
47 //function : PrsMgr_Presentation
49 //=======================================================================
50 PrsMgr_Presentation::PrsMgr_Presentation (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
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),
58 myMustBeUpdated (Standard_False)
60 if (thePrsObject->TypeOfPresentation3d() == PrsMgr_TOP_ProjectorDependant)
62 SetVisual (Graphic3d_TOS_COMPUTED);
64 SetOwner (myPresentableObject);
65 SetMutable (myPresentableObject->IsMutable());
68 //=======================================================================
71 //=======================================================================
72 void PrsMgr_Presentation::Display()
74 display (Standard_False);
75 myBeforeHighlightState = State_Visible;
78 //=======================================================================
81 //=======================================================================
82 void PrsMgr_Presentation::display (const Standard_Boolean theIsHighlight)
84 if (!base_type::IsDisplayed())
86 base_type::SetIsForHighlight (theIsHighlight); // optimization - disable frustum culling for this presentation
89 else if (!base_type::IsVisible())
91 base_type::SetVisible (Standard_True);
95 //=======================================================================
98 //=======================================================================
99 void PrsMgr_Presentation::Erase()
106 // Erase structure from structure manager
109 // Disconnect other structures
110 base_type::DisconnectAll (Graphic3d_TOC_DESCENDANT);
111 // Clear groups and remove graphic structure
115 //=======================================================================
116 //function : Highlight
118 //=======================================================================
119 void PrsMgr_Presentation::Highlight (const Handle(Prs3d_Drawer)& theStyle)
121 if (!IsHighlighted())
123 myBeforeHighlightState = StructureState (this);
126 display (Standard_True);
127 base_type::Highlight (theStyle);
130 //=======================================================================
131 //function : Unhighlight
133 //=======================================================================
134 void PrsMgr_Presentation::Unhighlight()
136 base_type::UnHighlight();
137 switch (myBeforeHighlightState)
142 base_type::SetVisible (Standard_False);
150 //=======================================================================
153 //=======================================================================
154 void PrsMgr_Presentation::Clear (const Standard_Boolean theWithDestruction)
156 // This modification remove the contain of the structure:
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);
167 base_type::Clear (theWithDestruction);
168 base_type::DisconnectAll (Graphic3d_TOC_DESCENDANT);
171 //=======================================================================
174 //=======================================================================
175 void PrsMgr_Presentation::Compute()
177 Standard_Integer aDispMode = 0;
178 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentableObject->myPresentations); aPrsIter.More(); aPrsIter.Next())
180 const Handle(PrsMgr_Presentation)& aModedPresentation = aPrsIter.Value();
181 if (aModedPresentation == this)
183 aDispMode = aModedPresentation->Mode();
188 myPresentableObject->Compute (myPresentationManager, this, aDispMode);
191 //=======================================================================
193 //purpose : Methods for hidden parts...
194 //=======================================================================
195 Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector)
197 Handle(Graphic3d_Structure) aPrs = new Graphic3d_Structure (myPresentationManager->StructureManager());
198 myPresentableObject->Compute (Projector (theProjector), aPrs);
202 //=======================================================================
205 //=======================================================================
206 void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
207 Handle(Graphic3d_Structure)& theStructToFill)
209 theStructToFill->Clear();
210 Handle(Prs3d_Presentation) aPrs = theStructToFill;
211 myPresentableObject->Compute (Projector (theProjector), aPrs);
214 //=======================================================================
217 //=======================================================================
218 Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
219 const Handle(Geom_Transformation)& theTrsf)
221 Handle(Prs3d_Presentation) aPrs3d = new Prs3d_Presentation (myPresentationManager->StructureManager());
222 myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs3d);
226 //=======================================================================
229 //=======================================================================
230 void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
231 const Handle(Geom_Transformation)& theTrsf,
232 Handle(Graphic3d_Structure)& theStructToFill)
234 // recompute HLR after transformation in all the case
235 Handle(Graphic3d_Structure) aPrs = theStructToFill;
236 theStructToFill->Clear();
237 myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs);
240 //=======================================================================
241 //function : Projector
243 //=======================================================================
244 Handle(Prs3d_Projector) PrsMgr_Presentation::Projector (const Handle(Graphic3d_DataStructureManager)& theProjector)
246 Handle(Graphic3d_Camera) aCamera = Handle(Graphic3d_CView)::DownCast (theProjector)->Camera();
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(),
252 aDir.X(), aDir.Y(), aDir.Z(),
253 anAt.X(), anAt.Y(), anAt.Z(),
254 anUp.X(), anUp.Y(), anUp.Z());
258 //=======================================================================
259 //function : ~PrsMgr_Presentation
261 //=======================================================================
262 PrsMgr_Presentation::~PrsMgr_Presentation()
267 // =======================================================================
268 // function : DumpJson
270 // =======================================================================
271 void PrsMgr_Presentation::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
273 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
274 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Graphic3d_Structure)
276 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myPresentableObject)
278 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myBeforeHighlightState)
279 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMode)
280 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMustBeUpdated)