0024752: Visualization - inherit OpenGl_Group from Graphic3d_Group
[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
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17// Modified by rob 09-oct-96
81bba717 18
7fd59977 19
20#define IMP040200 //GG Recompute HLR after transformation
21// in all the case.
22
23#include <PrsMgr_Presentation3d.ixx>
24#include <PrsMgr_PresentationManager.hxx>
25#include <PrsMgr_Prs.hxx>
eb4320f2 26#include <PrsMgr_ModedPresentation.hxx>
7fd59977 27#include <Visual3d_View.hxx>
7fd59977 28#include <Graphic3d_Structure.hxx>
29#include <Precision.hxx>
30
31PrsMgr_Presentation3d::PrsMgr_Presentation3d (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
32 const Handle(PrsMgr_PresentableObject)& aPresentableObject)
33: PrsMgr_Presentation(aPresentationManager),
34 myDisplayReason(Standard_False),
35 myPresentableObject (aPresentableObject.operator->())
36{
37 myStructure = new PrsMgr_Prs(aPresentationManager->StructureManager(),
38 this, aPresentableObject->TypeOfPresentation3d());
39 myStructure->SetOwner(myPresentableObject);
40}
41
42PrsMgr_KindOfPrs PrsMgr_Presentation3d::KindOfPresentation() const
43{return PrsMgr_KOP_3D;}
44
45
eb4320f2 46void PrsMgr_Presentation3d::Display()
47{
48 Display (Standard_False);
7fd59977 49 myDisplayReason = Standard_False;
50}
51
eb4320f2 52void PrsMgr_Presentation3d::Display(const Standard_Boolean theIsHighlight)
53{
54 if (!myStructure->IsDisplayed())
55 {
56 myStructure->Display();
57 myDisplayReason = theIsHighlight;
58 }
59 else if (!myStructure->IsVisible())
60 {
61 myStructure->SetVisible (Standard_True);
62 myDisplayReason = theIsHighlight;
63 }
64}
65
eef7fc64 66void PrsMgr_Presentation3d::Erase ()
67{
b64d84be 68 if (myStructure.IsNull())
69 {
70 return;
71 }
72
eef7fc64 73 // Erase structure from structure manager
74 myStructure->Erase();
5396d9ca 75 myStructure->Clear();
6bf1bdbd 76 // Disconnect other structures
77 myStructure->DisconnectAll (Graphic3d_TOC_DESCENDANT);
eef7fc64 78 // Clear groups and remove graphic structure
79 myStructure.Nullify();
80}
7fd59977 81
eb4320f2 82void PrsMgr_Presentation3d::SetVisible (const Standard_Boolean theValue)
83{
84 myStructure->SetVisible (theValue);
85}
86
7fd59977 87void PrsMgr_Presentation3d::Highlight () {
eb4320f2 88 Display (Standard_True);
7fd59977 89 myStructure->Highlight();}
90
91void PrsMgr_Presentation3d::Unhighlight () const {
92 myStructure->UnHighlight();
eb4320f2 93 if (myDisplayReason) myStructure->SetVisible (Standard_False);
7fd59977 94}
95
96void PrsMgr_Presentation3d::Clear() {
97 // This modification remove the contain of the structure:
98 // Consequence:
99 // 1. The memory zone of the group is reused
100 // 2. The speed for animation is constant
bbf32d01
K
101 //myPresentableObject = NULL;
102 SetUpdateStatus(Standard_True);
b64d84be 103 if (myStructure.IsNull())
104 {
105 return;
106 }
107
7fd59977 108 myStructure->Clear(Standard_True);
109 // myStructure->Clear(Standard_False);
7fd59977 110 myStructure->RemoveAll();
111}
112
113void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){
eb4320f2 114 Display (Standard_True);
7fd59977 115 myStructure->Color(aColor);
116}
117
118void PrsMgr_Presentation3d::BoundBox() const {
119 myStructure->BoundBox();
120}
121
122Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const {
eb4320f2 123 return myStructure->IsDisplayed() && myStructure->IsVisible() && !myDisplayReason;
7fd59977 124}
125
126Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const {
127 return myStructure->IsHighlighted();
128}
129
130
131Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const {
132return myStructure->DisplayPriority();
133}
134
135void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior)
136{
137 myStructure->SetDisplayPriority(TheNewPrior);
138}
139
140Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const {
141 return myStructure;
142}
143void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const {
144 myStructure->Connect(anOtherPresentation->Presentation());
145}
146
147void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const {
148 myStructure->Transform(aTransformation);
149}
150
151void PrsMgr_Presentation3d::Place (const Quantity_Length X,
152 const Quantity_Length Y,
153 const Quantity_Length Z) const {
154 myStructure->Place(X,Y,Z);
155}
156
157void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const {
158 myStructure->Multiply(aTransformation);
159}
160
161void PrsMgr_Presentation3d::Move (const Quantity_Length X,
162 const Quantity_Length Y,
163 const Quantity_Length Z) const {
164 myStructure->Move(X,Y,Z);
165}
166
167void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const {
168 myStructure->SetShadingAspect(aShadingAspect);
169}
170
171
172
173//=======================================================================
174//function : Compute
81bba717 175//purpose : Methods for hidden parts...
7fd59977 176//=======================================================================
177
178Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
179Compute(const Handle(Graphic3d_DataStructureManager)& aProjector)
180{
181#ifdef DEB
81bba717 182 cout<<"passage in g = Compute(P) "<<endl;
7fd59977 183#endif
184 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
185 myPresentableObject->Compute(Projector(aProjector),g);
186 return g;
187}
188
189//=======================================================================
190//function : Compute
191//purpose :
192//=======================================================================
193
eb4320f2 194void PrsMgr_Presentation3d::Compute (const Handle(Graphic3d_Structure)& theStructure)
195{
196 Standard_Integer aDispMode = 0;
197
198 Standard_Integer aPresentationsNumber = myPresentableObject->myPresentations.Length();
199 for (Standard_Integer anIter = 1; anIter <= aPresentationsNumber; anIter++)
200 {
201 const PrsMgr_ModedPresentation& aModedPresentation = myPresentableObject->myPresentations.Value (anIter);
202 Handle(PrsMgr_Presentation) aPresentation = aModedPresentation.Presentation();
203 PrsMgr_Presentation3d* aPresentation3d = (PrsMgr_Presentation3d* )aPresentation.operator->();
204 if (aPresentation3d == this)
205 {
206 aDispMode = aModedPresentation.Mode();
207 break;
208 }
209 }
210
211 Handle(Prs3d_Presentation) aPrs3d = Handle(Prs3d_Presentation)::DownCast (theStructure);
212
213 myPresentableObject->Compute(
214 Handle(PrsMgr_PresentationManager3d)::DownCast (PresentationManager()),
215 aPrs3d,
216 aDispMode);
217}
218
219//=======================================================================
220//function : Compute
221//purpose :
222//=======================================================================
223
7fd59977 224void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
225 const Handle(Graphic3d_Structure)& TheStructToFill)
226{
227#ifdef DEB
81bba717 228 cout<<"passage in Compute(P,Str)"<<endl;
7fd59977 229#endif
230 TheStructToFill->Clear();
231 const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill);
232 myPresentableObject->Compute(Projector(aProjector),P);
233}
234
235//=======================================================================
236//function : Compute
237//purpose :
238//=======================================================================
239Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
240Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
241 const Handle(Geom_Transformation)& TheTrsf)
242{
243#ifdef DEB
81bba717 244 cout<<"passage in G = Compute(P,Trsf)"<<endl;
7fd59977 245#endif
246 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
247
248
249 if(TheTrsf->Form()== gp_Translation){
250#ifdef DEB
251 cout<<"\tla Trsf est une translation"<<endl;
252#endif
253
254 myPresentableObject->Compute(Projector(aProjector),g);
255 g->Transform(TheTrsf);
256 }
257 else{
81bba717 258 // waiting that something is done in gp_Trsf...rob
7fd59977 259 Standard_Boolean good (Standard_True);
260 for (Standard_Integer i=1;i<=3 && good ;i++){
261 for (Standard_Integer j=1;j<=3 && good ;j++){
262 if(i!=j){
263 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
264 good = Standard_False;
265 }
266 }
267 }
268
269 if(good){
270#ifdef DEB
81bba717 271 cout<<"\t it is checked if Trsf is a Translation"<<endl;
7fd59977 272#endif
273 myPresentableObject->Compute(Projector(aProjector),g);
274 g->Transform(TheTrsf);
275
276 }
277 else{
278#ifdef DEB
81bba717 279 cout<<"\t Trsf is not only translation..."<<endl;
7fd59977 280#endif
281 myPresentableObject->Compute(Projector(aProjector),TheTrsf,g);
282 }
283 }
284 return g;
285}
286
287//=======================================================================
288//function : Compute
289//purpose :
290//=======================================================================
291void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
292 const Handle(Geom_Transformation)& TheTrsf,
293 const Handle(Graphic3d_Structure)& TheStructToFill)
294{
295
296#ifdef DEB
81bba717 297 cout<<"passage in Compute(P,Trsf,Str)"<<endl;
7fd59977 298#endif
299
300 Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill);
301
302#ifdef IMP040200
303 TheStructToFill->Clear();
304 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
81bba717 305#else //Does not work properly, HLR seems deactivated for view rotation
7fd59977 306 if(TheTrsf->Form()== gp_Translation){
307#ifdef DEB
81bba717 308 cout<<"\t Trsf is a translation"<<endl;
7fd59977 309#endif
310// myPresentableObject->Compute(Projector(aProjector),P);
311 P->Transform(TheTrsf);
312 }
313 else{
81bba717 314 // waiting that something is done in gp_Trsf...rob
7fd59977 315 Standard_Boolean good (Standard_True);
316 for (Standard_Integer i=1;i<=3 && good ;i++){
317 for (Standard_Integer j=1;j<=3 && good ;j++){
318 if(i!=j){
319 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
320 good = Standard_False;
321 }
322 }
323 }
324 if(good && !TheStructToFill->IsEmpty()){
325#ifdef DEB
81bba717 326 cout<<"\t it is checked if Trsf is a Translation"<<endl;
7fd59977 327#endif
328
329 P->Transform(TheTrsf);
330 }
331 else{
332 TheStructToFill->Clear();
333
334#ifdef DEB
81bba717 335 cout<<"\t Trsf is not only translation..."<<endl;
7fd59977 336#endif
337
338 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
339 }
340 }
341#endif
342}
343
344
345
346
347
348
349//=======================================================================
350//function : Projector
351//purpose :
352//=======================================================================
353
b5ac8292 354Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector)
355{
356 const Handle(Graphic3d_Camera)& aCamera = Handle(Visual3d_View)::DownCast (aProjector)->Camera();
357
7fd59977 358 Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp;
b5ac8292 359 gp_Dir aDir = aCamera->Direction().Reversed();
360 DX = aDir.X(); DY = aDir.Y(); DZ = aDir.Z();
361
362 gp_Pnt anAt = aCamera->Center();
363 XAt = anAt.X(); YAt = anAt.Y(); ZAt = anAt.Z();
364
365 gp_Dir anUp = aCamera->Up();
366 XUp = anUp.X(); YUp = anUp.Y(); ZUp = anUp.Z();
367
368 Standard_Boolean pers = !aCamera->IsOrthographic();
369 Standard_Real focale = aCamera->Scale();
370
371 Handle(Prs3d_Projector) aProj =
372 new Prs3d_Projector(pers, focale, DX, DY, DZ, XAt, YAt, ZAt, XUp, YUp, ZUp);
373 return aProj;
7fd59977 374
375}
376
377void PrsMgr_Presentation3d::Destroy () {
378 if (!myStructure.IsNull())
379 myStructure->Clear();
380 myStructure.Nullify();
381}
59f45b7c 382
383//=======================================================================
384//function : SetZLayer
385//purpose :
386//=======================================================================
387
388void PrsMgr_Presentation3d::SetZLayer (Standard_Integer theLayerId)
389{
390 myStructure->SetZLayer (theLayerId);
391}
392
393//=======================================================================
394//function : GetZLayer
395//purpose :
396//=======================================================================
397
398Standard_Integer PrsMgr_Presentation3d::GetZLayer () const
399{
400 return myStructure->GetZLayer ();
401}