0029754: Coding Rules - replace Standard_Integer with Graphic3d_ZLayerId for consistency
[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
2831708b 15#include <PrsMgr_Presentation.hxx>
7fd59977 16
42cf5bc1 17#include <Geom_Transformation.hxx>
18#include <Graphic3d_DataStructureManager.hxx>
af324faa 19#include <Graphic3d_Structure.hxx>
af324faa 20#include <Precision.hxx>
f838dac4 21#include <Prs3d_Drawer.hxx>
ec357c5c 22#include <Prs3d_Presentation.hxx>
42cf5bc1 23#include <Prs3d_Projector.hxx>
42cf5bc1 24#include <PrsMgr_ModedPresentation.hxx>
25#include <PrsMgr_PresentableObject.hxx>
42cf5bc1 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
f838dac4 32IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_Presentation, Standard_Transient)
7fd59977 33
3ae59031 34namespace
35{
36 enum BeforeHighlightState
37 {
38 State_Empty,
39 State_Hidden,
40 State_Visible
41 };
42
4796758e 43 static BeforeHighlightState StructureState(const Handle(Prs3d_Presentation)& 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//=======================================================================
f838dac4 129void PrsMgr_Presentation::Highlight (const Handle(Prs3d_Drawer)& theStyle)
af324faa 130{
3ae59031 131 if (!IsHighlighted())
132 {
133 myBeforeHighlightState = StructureState (myStructure);
134 }
135
a1954302 136 display (Standard_True);
8e5fb5ea 137 myStructure->Highlight (theStyle);
af324faa 138}
139
140//=======================================================================
141//function : Unhighlight
142//purpose :
143//=======================================================================
144void PrsMgr_Presentation::Unhighlight() const
145{
146 myStructure->UnHighlight();
3ae59031 147 switch (myBeforeHighlightState)
af324faa 148 {
3ae59031 149 case State_Visible:
150 return;
151 case State_Hidden:
af324faa 152 myStructure->SetVisible (Standard_False);
3ae59031 153 break;
154 case State_Empty:
155 myStructure->Erase();
156 break;
af324faa 157 }
158}
159
160//=======================================================================
161//function : Clear
162//purpose :
163//=======================================================================
164void PrsMgr_Presentation::Clear()
165{
166 // This modification remove the contain of the structure:
167 // Consequence:
168 // 1. The memory zone of the group is reused
169 // 2. The speed for animation is constant
170 //myPresentableObject = NULL;
171 SetUpdateStatus (Standard_True);
172 if (myStructure.IsNull())
173 {
174 return;
175 }
176
177 myStructure->Clear (Standard_True);
178 // myStructure->Clear(Standard_False);
179 myStructure->RemoveAll();
180}
181
182//=======================================================================
af324faa 183//function : IsDisplayed
184//purpose :
185//=======================================================================
186Standard_Boolean PrsMgr_Presentation::IsDisplayed() const
187{
188 return myStructure->IsDisplayed()
3ae59031 189 && myStructure->IsVisible();
af324faa 190}
191
192//=======================================================================
193//function : IsHighlighted
194//purpose :
195//=======================================================================
196Standard_Boolean PrsMgr_Presentation::IsHighlighted() const
197{
198 return myStructure->IsHighlighted();
199}
200
201//=======================================================================
202//function : DisplayPriority
203//purpose :
204//=======================================================================
205Standard_Integer PrsMgr_Presentation::DisplayPriority() const
206{
207 return myStructure->DisplayPriority();
208}
209
210//=======================================================================
211//function : SetDisplayPriority
212//purpose :
213//=======================================================================
214void PrsMgr_Presentation::SetDisplayPriority (const Standard_Integer theNewPrior)
215{
216 myStructure->SetDisplayPriority (theNewPrior);
217}
218
219//=======================================================================
220//function : Connect
221//purpose :
222//=======================================================================
223void PrsMgr_Presentation::Connect (const Handle(PrsMgr_Presentation)& theOther) const
224{
225 myStructure->Connect (theOther->Presentation());
226}
227
228//=======================================================================
1f7f5a90 229//function : SetTransformation
af324faa 230//purpose :
231//=======================================================================
1f7f5a90 232void PrsMgr_Presentation::SetTransformation (const Handle(Geom_Transformation)& theTrsf) const
af324faa 233{
1f7f5a90 234 myStructure->SetTransformation (theTrsf);
af324faa 235}
236
237//=======================================================================
af324faa 238//function : Compute
239//purpose : Methods for hidden parts...
240//=======================================================================
241Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector)
242{
243 Handle(Prs3d_Presentation) aPrs = new Prs3d_Presentation (myPresentationManager->StructureManager());
244 myPresentableObject->Compute (Projector (theProjector), aPrs);
245 return aPrs;
246}
247
248//=======================================================================
249//function : Compute
250//purpose :
251//=======================================================================
252void PrsMgr_Presentation::Compute (const Handle(Graphic3d_Structure)& theStructure)
253{
254 Standard_Integer aDispMode = 0;
255 Standard_Integer aPresentationsNumber = myPresentableObject->myPresentations.Length();
256 for (Standard_Integer anIter = 1; anIter <= aPresentationsNumber; ++anIter)
257 {
258 const PrsMgr_ModedPresentation& aModedPresentation = myPresentableObject->myPresentations.Value (anIter);
259 if (aModedPresentation.Presentation().operator->() == this)
260 {
261 aDispMode = aModedPresentation.Mode();
262 break;
263 }
264 }
265
266 Handle(Prs3d_Presentation) aPrs3d = Handle(Prs3d_Presentation)::DownCast (theStructure);
267 myPresentableObject->Compute (myPresentationManager, aPrs3d, aDispMode);
268}
269
270//=======================================================================
271//function : Compute
272//purpose :
273//=======================================================================
274void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
275 const Handle(Graphic3d_Structure)& theStructToFill)
276{
277 theStructToFill->Clear();
c5f3a425 278 Handle(Prs3d_Presentation) aPrs (Handle(Prs3d_Presentation)::DownCast (theStructToFill));
af324faa 279 myPresentableObject->Compute (Projector (theProjector), aPrs);
280}
281
282//=======================================================================
283//function : Compute
284//purpose :
285//=======================================================================
286Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
287 const Handle(Geom_Transformation)& theTrsf)
288{
289 Handle(Prs3d_Presentation) aPrs3d = new Prs3d_Presentation (myPresentationManager->StructureManager());
1eeef710 290 myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs3d);
af324faa 291 return aPrs3d;
292}
293
294//=======================================================================
295//function : Compute
296//purpose :
297//=======================================================================
298void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
299 const Handle(Geom_Transformation)& theTrsf,
300 const Handle(Graphic3d_Structure)& theStructToFill)
301{
302 // recompute HLR after transformation in all the case
c5f3a425 303 Handle(Prs3d_Presentation) aPrs = Handle(Prs3d_Presentation)::DownCast (theStructToFill);
af324faa 304 theStructToFill->Clear();
305 myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs);
306}
307
308//=======================================================================
309//function : Projector
310//purpose :
311//=======================================================================
312Handle(Prs3d_Projector) PrsMgr_Presentation::Projector (const Handle(Graphic3d_DataStructureManager)& theProjector)
313{
c357e426 314 Handle(Graphic3d_Camera) aCamera = Handle(Graphic3d_CView)::DownCast (theProjector)->Camera();
af324faa 315 const gp_Dir aDir = aCamera->Direction().Reversed();
316 const gp_Pnt anAt = aCamera->Center();
317 const gp_Dir anUp = aCamera->Up();
318 Handle(Prs3d_Projector) aProj = new Prs3d_Projector (!aCamera->IsOrthographic(),
319 aCamera->Scale(),
320 aDir.X(), aDir.Y(), aDir.Z(),
321 anAt.X(), anAt.Y(), anAt.Z(),
322 anUp.X(), anUp.Y(), anUp.Z());
323 return aProj;
324}
325
326//=======================================================================
e6f550da 327//function : ~PrsMgr_Presentation
af324faa 328//purpose :
329//=======================================================================
e6f550da 330PrsMgr_Presentation::~PrsMgr_Presentation()
af324faa 331{
a69a08ee 332 Erase();
af324faa 333}
334
335//=======================================================================
336//function : SetZLayer
337//purpose :
338//=======================================================================
8f138407 339void PrsMgr_Presentation::SetZLayer (Graphic3d_ZLayerId theLayerId)
af324faa 340{
341 myStructure->SetZLayer (theLayerId);
342}
343
344//=======================================================================
345//function : GetZLayer
346//purpose :
347//=======================================================================
8f138407 348Graphic3d_ZLayerId PrsMgr_Presentation::GetZLayer() const
af324faa 349{
350 return myStructure->GetZLayer();
7fd59977 351}