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 <Graphic3d_DataStructureManager.hxx>
18 #include <Precision.hxx>
19 #include <Prs3d_Drawer.hxx>
20 #include <PrsMgr_PresentableObject.hxx>
21 #include <PrsMgr_PresentationManager.hxx>
22 #include <Quantity_Color.hxx>
23 #include <Graphic3d_CView.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_Presentation, Graphic3d_Structure)
29 enum BeforeHighlightState
36 static BeforeHighlightState StructureState (const Graphic3d_Structure* theStructure)
38 return !theStructure->IsDisplayed() ?
39 State_Empty : !theStructure->IsVisible() ?
40 State_Hidden : State_Visible;
44 //=======================================================================
45 //function : PrsMgr_Presentation
47 //=======================================================================
48 PrsMgr_Presentation::PrsMgr_Presentation (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
49 const Handle(PrsMgr_PresentableObject)& thePrsObject,
50 const Standard_Integer theMode)
51 : Graphic3d_Structure (thePrsMgr->StructureManager()),
52 myPresentationManager (thePrsMgr),
53 myPresentableObject (thePrsObject.get()),
54 myBeforeHighlightState (State_Empty),
56 myMustBeUpdated (Standard_False)
58 if (thePrsObject->TypeOfPresentation3d() == PrsMgr_TOP_ProjectorDependant)
60 SetVisual (Graphic3d_TOS_COMPUTED);
62 SetOwner (myPresentableObject);
63 SetMutable (myPresentableObject->IsMutable());
66 //=======================================================================
69 //=======================================================================
70 void PrsMgr_Presentation::Display()
72 display (Standard_False);
73 myBeforeHighlightState = State_Visible;
76 //=======================================================================
79 //=======================================================================
80 void PrsMgr_Presentation::display (const Standard_Boolean theIsHighlight)
82 if (!base_type::IsDisplayed())
84 base_type::SetIsForHighlight (theIsHighlight); // optimization - disable frustum culling for this presentation
87 else if (!base_type::IsVisible())
89 base_type::SetVisible (Standard_True);
93 //=======================================================================
96 //=======================================================================
97 void PrsMgr_Presentation::Erase()
104 // Erase structure from structure manager
107 // Disconnect other structures
108 DisconnectAll (Graphic3d_TOC_DESCENDANT);
109 // Clear groups and remove graphic structure
113 //=======================================================================
114 //function : Highlight
116 //=======================================================================
117 void PrsMgr_Presentation::Highlight (const Handle(Prs3d_Drawer)& theStyle)
119 if (!IsHighlighted())
121 myBeforeHighlightState = StructureState (this);
124 display (Standard_True);
125 base_type::Highlight (theStyle);
128 //=======================================================================
129 //function : Unhighlight
131 //=======================================================================
132 void PrsMgr_Presentation::Unhighlight()
134 base_type::UnHighlight();
135 switch (myBeforeHighlightState)
140 base_type::SetVisible (Standard_False);
148 //=======================================================================
151 //=======================================================================
152 void PrsMgr_Presentation::Clear (const Standard_Boolean theWithDestruction)
154 // This modification remove the contain of the structure:
156 // 1. The memory zone of the group is reused
157 // 2. The speed for animation is constant
158 //myPresentableObject = NULL;
159 SetUpdateStatus (Standard_True);
165 clear (theWithDestruction);
166 DisconnectAll (Graphic3d_TOC_DESCENDANT);
169 //=======================================================================
172 //=======================================================================
173 void PrsMgr_Presentation::Compute()
175 Standard_Integer aDispMode = 0;
176 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentableObject->myPresentations); aPrsIter.More(); aPrsIter.Next())
178 const Handle(PrsMgr_Presentation)& aModedPresentation = aPrsIter.Value();
179 if (aModedPresentation == this)
181 aDispMode = aModedPresentation->Mode();
186 myPresentableObject->Compute (myPresentationManager, this, aDispMode);
189 //=======================================================================
192 //=======================================================================
193 void PrsMgr_Presentation::computeHLR (const Handle(Graphic3d_Camera)& theProjector,
194 Handle(Graphic3d_Structure)& theStructToFill)
196 if (theStructToFill.IsNull())
198 theStructToFill = new Prs3d_Presentation (myPresentationManager->StructureManager());
200 Handle(Graphic3d_Structure) aPrs = theStructToFill;
201 theStructToFill->Clear();
202 myPresentableObject->computeHLR (theProjector, Transformation(), aPrs);
205 //=======================================================================
206 //function : ~PrsMgr_Presentation
208 //=======================================================================
209 PrsMgr_Presentation::~PrsMgr_Presentation()
214 // =======================================================================
215 // function : DumpJson
217 // =======================================================================
218 void PrsMgr_Presentation::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
220 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
221 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Graphic3d_Structure)
223 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myPresentableObject)
225 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myBeforeHighlightState)
226 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMode)
227 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMustBeUpdated)