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);
89 else if (!base_type::IsVisible())
91 base_type::SetVisible (Standard_True);
92 base_type::SetIsForHighlight (theIsHighlight);
96 //=======================================================================
99 //=======================================================================
100 void PrsMgr_Presentation::Erase()
107 // Erase structure from structure manager
110 // Disconnect other structures
111 base_type::DisconnectAll (Graphic3d_TOC_DESCENDANT);
112 // Clear groups and remove graphic structure
116 //=======================================================================
117 //function : Highlight
119 //=======================================================================
120 void PrsMgr_Presentation::Highlight (const Handle(Prs3d_Drawer)& theStyle)
122 if (!IsHighlighted())
124 myBeforeHighlightState = StructureState (this);
127 display (Standard_True);
128 base_type::Highlight (theStyle);
131 //=======================================================================
132 //function : Unhighlight
134 //=======================================================================
135 void PrsMgr_Presentation::Unhighlight()
137 base_type::UnHighlight();
138 switch (myBeforeHighlightState)
143 base_type::SetVisible (Standard_False);
151 //=======================================================================
154 //=======================================================================
155 void PrsMgr_Presentation::Clear (const Standard_Boolean theWithDestruction)
157 // This modification remove the contain of the structure:
159 // 1. The memory zone of the group is reused
160 // 2. The speed for animation is constant
161 //myPresentableObject = NULL;
162 SetUpdateStatus (Standard_True);
168 base_type::Clear (theWithDestruction);
169 base_type::DisconnectAll (Graphic3d_TOC_DESCENDANT);
172 //=======================================================================
175 //=======================================================================
176 void PrsMgr_Presentation::Compute()
178 Standard_Integer aDispMode = 0;
179 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentableObject->myPresentations); aPrsIter.More(); aPrsIter.Next())
181 const Handle(PrsMgr_Presentation)& aModedPresentation = aPrsIter.Value();
182 if (aModedPresentation == this)
184 aDispMode = aModedPresentation->Mode();
189 myPresentableObject->Compute (myPresentationManager, this, aDispMode);
192 //=======================================================================
194 //purpose : Methods for hidden parts...
195 //=======================================================================
196 Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector)
198 Handle(Graphic3d_Structure) aPrs = new Graphic3d_Structure (myPresentationManager->StructureManager());
199 myPresentableObject->Compute (Projector (theProjector), aPrs);
203 //=======================================================================
206 //=======================================================================
207 void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
208 Handle(Graphic3d_Structure)& theStructToFill)
210 theStructToFill->Clear();
211 Handle(Prs3d_Presentation) aPrs = theStructToFill;
212 myPresentableObject->Compute (Projector (theProjector), aPrs);
215 //=======================================================================
218 //=======================================================================
219 Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
220 const Handle(Geom_Transformation)& theTrsf)
222 Handle(Prs3d_Presentation) aPrs3d = new Prs3d_Presentation (myPresentationManager->StructureManager());
223 myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs3d);
227 //=======================================================================
230 //=======================================================================
231 void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
232 const Handle(Geom_Transformation)& theTrsf,
233 Handle(Graphic3d_Structure)& theStructToFill)
235 // recompute HLR after transformation in all the case
236 Handle(Graphic3d_Structure) aPrs = theStructToFill;
237 theStructToFill->Clear();
238 myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs);
241 //=======================================================================
242 //function : Projector
244 //=======================================================================
245 Handle(Prs3d_Projector) PrsMgr_Presentation::Projector (const Handle(Graphic3d_DataStructureManager)& theProjector)
247 Handle(Graphic3d_Camera) aCamera = Handle(Graphic3d_CView)::DownCast (theProjector)->Camera();
248 const gp_Dir aDir = aCamera->Direction().Reversed();
249 const gp_Pnt anAt = aCamera->Center();
250 const gp_Dir anUp = aCamera->Up();
251 Handle(Prs3d_Projector) aProj = new Prs3d_Projector (!aCamera->IsOrthographic(),
253 aDir.X(), aDir.Y(), aDir.Z(),
254 anAt.X(), anAt.Y(), anAt.Z(),
255 anUp.X(), anUp.Y(), anUp.Z());
259 //=======================================================================
260 //function : ~PrsMgr_Presentation
262 //=======================================================================
263 PrsMgr_Presentation::~PrsMgr_Presentation()