0024167: Compiler warnings 'unreacheable code' and 'conditional expression is constan...
[occt.git] / src / PrsMgr / PrsMgr_Presentation3d.cxx
CommitLineData
b311480e 1// Created on: 1993-10-21
2// Created by: Jean-Louis FRENKEL
3// Copyright (c) 1993-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21// Modified by rob 09-oct-96
81bba717 22
7fd59977 23
24#define IMP040200 //GG Recompute HLR after transformation
25// in all the case.
26
27#include <PrsMgr_Presentation3d.ixx>
28#include <PrsMgr_PresentationManager.hxx>
29#include <PrsMgr_Prs.hxx>
30#include <Visual3d_View.hxx>
31#include <Visual3d_ViewOrientation.hxx>
32#include <Graphic3d_Structure.hxx>
33#include <Precision.hxx>
34
35PrsMgr_Presentation3d::PrsMgr_Presentation3d (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
36 const Handle(PrsMgr_PresentableObject)& aPresentableObject)
37: PrsMgr_Presentation(aPresentationManager),
38 myDisplayReason(Standard_False),
39 myPresentableObject (aPresentableObject.operator->())
40{
41 myStructure = new PrsMgr_Prs(aPresentationManager->StructureManager(),
42 this, aPresentableObject->TypeOfPresentation3d());
43 myStructure->SetOwner(myPresentableObject);
44}
45
46PrsMgr_KindOfPrs PrsMgr_Presentation3d::KindOfPresentation() const
47{return PrsMgr_KOP_3D;}
48
49
50void PrsMgr_Presentation3d::Display () {
51 myStructure->Display();
52 myDisplayReason = Standard_False;
53}
54
55void PrsMgr_Presentation3d::Erase () const {
56 myStructure->Erase();}
57
58void PrsMgr_Presentation3d::Highlight () {
59 if(!myStructure->IsDisplayed()) {
60 myStructure->Display();
61 myDisplayReason = Standard_True;
62 }
63 myStructure->Highlight();}
64
65void PrsMgr_Presentation3d::Unhighlight () const {
66 myStructure->UnHighlight();
67 if(myDisplayReason) myStructure->Erase();
68}
69
70void PrsMgr_Presentation3d::Clear() {
71 // This modification remove the contain of the structure:
72 // Consequence:
73 // 1. The memory zone of the group is reused
74 // 2. The speed for animation is constant
bbf32d01
K
75 //myPresentableObject = NULL;
76 SetUpdateStatus(Standard_True);
7fd59977 77 myStructure->Clear(Standard_True);
78 // myStructure->Clear(Standard_False);
79
80 myStructure->RemoveAll();
81}
82
83void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){
84 Standard_Boolean ImmMode = myPresentationManager->IsImmediateModeOn();
85 if(!ImmMode){
86 if(!myStructure->IsDisplayed()) {
87 myStructure->Display();
88 myDisplayReason = Standard_True;
89 }
90 }
91 myStructure->Color(aColor);
92}
93
94void PrsMgr_Presentation3d::BoundBox() const {
95 myStructure->BoundBox();
96}
97
98Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const {
99 return myStructure->IsDisplayed() && !myDisplayReason;
100}
101
102Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const {
103 return myStructure->IsHighlighted();
104}
105
106
107Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const {
108return myStructure->DisplayPriority();
109}
110
111void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior)
112{
113 myStructure->SetDisplayPriority(TheNewPrior);
114}
115
116Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const {
117 return myStructure;
118}
119void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const {
120 myStructure->Connect(anOtherPresentation->Presentation());
121}
122
123void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const {
124 myStructure->Transform(aTransformation);
125}
126
127void PrsMgr_Presentation3d::Place (const Quantity_Length X,
128 const Quantity_Length Y,
129 const Quantity_Length Z) const {
130 myStructure->Place(X,Y,Z);
131}
132
133void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const {
134 myStructure->Multiply(aTransformation);
135}
136
137void PrsMgr_Presentation3d::Move (const Quantity_Length X,
138 const Quantity_Length Y,
139 const Quantity_Length Z) const {
140 myStructure->Move(X,Y,Z);
141}
142
143void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const {
144 myStructure->SetShadingAspect(aShadingAspect);
145}
146
147
148
149//=======================================================================
150//function : Compute
81bba717 151//purpose : Methods for hidden parts...
7fd59977 152//=======================================================================
153
154Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
155Compute(const Handle(Graphic3d_DataStructureManager)& aProjector)
156{
157#ifdef DEB
81bba717 158 cout<<"passage in g = Compute(P) "<<endl;
7fd59977 159#endif
160 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
161 myPresentableObject->Compute(Projector(aProjector),g);
162 return g;
163}
164
165//=======================================================================
166//function : Compute
167//purpose :
168//=======================================================================
169
170void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
171 const Handle(Graphic3d_Structure)& TheStructToFill)
172{
173#ifdef DEB
81bba717 174 cout<<"passage in Compute(P,Str)"<<endl;
7fd59977 175#endif
176 TheStructToFill->Clear();
177 const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill);
178 myPresentableObject->Compute(Projector(aProjector),P);
179}
180
181//=======================================================================
182//function : Compute
183//purpose :
184//=======================================================================
185Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
186Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
187 const Handle(Geom_Transformation)& TheTrsf)
188{
189#ifdef DEB
81bba717 190 cout<<"passage in G = Compute(P,Trsf)"<<endl;
7fd59977 191#endif
192 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
193
194
195 if(TheTrsf->Form()== gp_Translation){
196#ifdef DEB
197 cout<<"\tla Trsf est une translation"<<endl;
198#endif
199
200 myPresentableObject->Compute(Projector(aProjector),g);
201 g->Transform(TheTrsf);
202 }
203 else{
81bba717 204 // waiting that something is done in gp_Trsf...rob
7fd59977 205 Standard_Boolean good (Standard_True);
206 for (Standard_Integer i=1;i<=3 && good ;i++){
207 for (Standard_Integer j=1;j<=3 && good ;j++){
208 if(i!=j){
209 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
210 good = Standard_False;
211 }
212 }
213 }
214
215 if(good){
216#ifdef DEB
81bba717 217 cout<<"\t it is checked if Trsf is a Translation"<<endl;
7fd59977 218#endif
219 myPresentableObject->Compute(Projector(aProjector),g);
220 g->Transform(TheTrsf);
221
222 }
223 else{
224#ifdef DEB
81bba717 225 cout<<"\t Trsf is not only translation..."<<endl;
7fd59977 226#endif
227 myPresentableObject->Compute(Projector(aProjector),TheTrsf,g);
228 }
229 }
230 return g;
231}
232
233//=======================================================================
234//function : Compute
235//purpose :
236//=======================================================================
237void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
238 const Handle(Geom_Transformation)& TheTrsf,
239 const Handle(Graphic3d_Structure)& TheStructToFill)
240{
241
242#ifdef DEB
81bba717 243 cout<<"passage in Compute(P,Trsf,Str)"<<endl;
7fd59977 244#endif
245
246 Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill);
247
248#ifdef IMP040200
249 TheStructToFill->Clear();
250 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
81bba717 251#else //Does not work properly, HLR seems deactivated for view rotation
7fd59977 252 if(TheTrsf->Form()== gp_Translation){
253#ifdef DEB
81bba717 254 cout<<"\t Trsf is a translation"<<endl;
7fd59977 255#endif
256// myPresentableObject->Compute(Projector(aProjector),P);
257 P->Transform(TheTrsf);
258 }
259 else{
81bba717 260 // waiting that something is done in gp_Trsf...rob
7fd59977 261 Standard_Boolean good (Standard_True);
262 for (Standard_Integer i=1;i<=3 && good ;i++){
263 for (Standard_Integer j=1;j<=3 && good ;j++){
264 if(i!=j){
265 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
266 good = Standard_False;
267 }
268 }
269 }
270 if(good && !TheStructToFill->IsEmpty()){
271#ifdef DEB
81bba717 272 cout<<"\t it is checked if Trsf is a Translation"<<endl;
7fd59977 273#endif
274
275 P->Transform(TheTrsf);
276 }
277 else{
278 TheStructToFill->Clear();
279
280#ifdef DEB
81bba717 281 cout<<"\t Trsf is not only translation..."<<endl;
7fd59977 282#endif
283
284 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
285 }
286 }
287#endif
288}
289
290
291
292
293
294
295//=======================================================================
296//function : Projector
297//purpose :
298//=======================================================================
299
300Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector) {
301 Visual3d_ViewOrientation VO = Handle(Visual3d_View)::DownCast(aProjector)->ViewOrientation();
302 Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp;
303 VO.ViewReferencePlane().Coord(DX, DY, DZ);
304 VO.ViewReferencePoint().Coord(XAt,YAt,ZAt);
305 VO.ViewReferenceUp().Coord(XUp, YUp, ZUp);
306 Visual3d_ViewMapping VM = Handle(Visual3d_View)::DownCast(aProjector)->ViewMapping();
307 Standard_Boolean pers = (VM.Projection() == Visual3d_TOP_PERSPECTIVE);
308 Standard_Real focale = 0.0 ;
309 if (pers) {
310 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
311 Graphic3d_Vertex Prp = VM.ProjectionReferencePoint() ;
312 Prp.Coord(Xrp,Yrp,Zrp);
313 FrontPlane = VM.FrontPlaneDistance() ;
314 ViewPlane = VM.ViewPlaneDistance() ;
315 focale = FrontPlane + Zrp - ViewPlane ;
316 }
317 Handle(Prs3d_Projector) Proj = new Prs3d_Projector(pers,focale,DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp);
318 return Proj;
319
320}
321
322void PrsMgr_Presentation3d::Destroy () {
323 if (!myStructure.IsNull())
324 myStructure->Clear();
325 myStructure.Nullify();
326}
59f45b7c 327
328//=======================================================================
329//function : SetZLayer
330//purpose :
331//=======================================================================
332
333void PrsMgr_Presentation3d::SetZLayer (Standard_Integer theLayerId)
334{
335 myStructure->SetZLayer (theLayerId);
336}
337
338//=======================================================================
339//function : GetZLayer
340//purpose :
341//=======================================================================
342
343Standard_Integer PrsMgr_Presentation3d::GetZLayer () const
344{
345 return myStructure->GetZLayer ();
346}