0023000: Improve the way the gradient and textured background is managed in 3d viewer
[occt.git] / src / PrsMgr / PrsMgr_Presentation3d.cxx
CommitLineData
7fd59977 1// File: PrsMgr_Presentation3d.cxx
2// Created: Thu Oct 21 13:11:19 1993
3// Author: Jean-Louis FRENKEL
4// Modified by rob 09-oct-96
5// <jlf@stylox>
81bba717 6
7fd59977 7
8#define IMP040200 //GG Recompute HLR after transformation
9// in all the case.
10
11#include <PrsMgr_Presentation3d.ixx>
12#include <PrsMgr_PresentationManager.hxx>
13#include <PrsMgr_Prs.hxx>
14#include <Visual3d_View.hxx>
15#include <Visual3d_ViewOrientation.hxx>
16#include <Graphic3d_Structure.hxx>
17#include <Precision.hxx>
18
19PrsMgr_Presentation3d::PrsMgr_Presentation3d (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
20 const Handle(PrsMgr_PresentableObject)& aPresentableObject)
21: PrsMgr_Presentation(aPresentationManager),
22 myDisplayReason(Standard_False),
23 myPresentableObject (aPresentableObject.operator->())
24{
25 myStructure = new PrsMgr_Prs(aPresentationManager->StructureManager(),
26 this, aPresentableObject->TypeOfPresentation3d());
27 myStructure->SetOwner(myPresentableObject);
28}
29
30PrsMgr_KindOfPrs PrsMgr_Presentation3d::KindOfPresentation() const
31{return PrsMgr_KOP_3D;}
32
33
34void PrsMgr_Presentation3d::Display () {
35 myStructure->Display();
36 myDisplayReason = Standard_False;
37}
38
39void PrsMgr_Presentation3d::Erase () const {
40 myStructure->Erase();}
41
42void PrsMgr_Presentation3d::Highlight () {
43 if(!myStructure->IsDisplayed()) {
44 myStructure->Display();
45 myDisplayReason = Standard_True;
46 }
47 myStructure->Highlight();}
48
49void PrsMgr_Presentation3d::Unhighlight () const {
50 myStructure->UnHighlight();
51 if(myDisplayReason) myStructure->Erase();
52}
53
54void PrsMgr_Presentation3d::Clear() {
55 // This modification remove the contain of the structure:
56 // Consequence:
57 // 1. The memory zone of the group is reused
58 // 2. The speed for animation is constant
bbf32d01
K
59 //myPresentableObject = NULL;
60 SetUpdateStatus(Standard_True);
7fd59977 61 myStructure->Clear(Standard_True);
62 // myStructure->Clear(Standard_False);
63
64 myStructure->RemoveAll();
65}
66
67void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){
68 Standard_Boolean ImmMode = myPresentationManager->IsImmediateModeOn();
69 if(!ImmMode){
70 if(!myStructure->IsDisplayed()) {
71 myStructure->Display();
72 myDisplayReason = Standard_True;
73 }
74 }
75 myStructure->Color(aColor);
76}
77
78void PrsMgr_Presentation3d::BoundBox() const {
79 myStructure->BoundBox();
80}
81
82Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const {
83 return myStructure->IsDisplayed() && !myDisplayReason;
84}
85
86Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const {
87 return myStructure->IsHighlighted();
88}
89
90
91Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const {
92return myStructure->DisplayPriority();
93}
94
95void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior)
96{
97 myStructure->SetDisplayPriority(TheNewPrior);
98}
99
100Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const {
101 return myStructure;
102}
103void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const {
104 myStructure->Connect(anOtherPresentation->Presentation());
105}
106
107void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const {
108 myStructure->Transform(aTransformation);
109}
110
111void PrsMgr_Presentation3d::Place (const Quantity_Length X,
112 const Quantity_Length Y,
113 const Quantity_Length Z) const {
114 myStructure->Place(X,Y,Z);
115}
116
117void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const {
118 myStructure->Multiply(aTransformation);
119}
120
121void PrsMgr_Presentation3d::Move (const Quantity_Length X,
122 const Quantity_Length Y,
123 const Quantity_Length Z) const {
124 myStructure->Move(X,Y,Z);
125}
126
127void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const {
128 myStructure->SetShadingAspect(aShadingAspect);
129}
130
131
132
133//=======================================================================
134//function : Compute
81bba717 135//purpose : Methods for hidden parts...
7fd59977 136//=======================================================================
137
138Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
139Compute(const Handle(Graphic3d_DataStructureManager)& aProjector)
140{
141#ifdef DEB
81bba717 142 cout<<"passage in g = Compute(P) "<<endl;
7fd59977 143#endif
144 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
145 myPresentableObject->Compute(Projector(aProjector),g);
146 return g;
147}
148
149//=======================================================================
150//function : Compute
151//purpose :
152//=======================================================================
153
154void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
155 const Handle(Graphic3d_Structure)& TheStructToFill)
156{
157#ifdef DEB
81bba717 158 cout<<"passage in Compute(P,Str)"<<endl;
7fd59977 159#endif
160 TheStructToFill->Clear();
161 const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill);
162 myPresentableObject->Compute(Projector(aProjector),P);
163}
164
165//=======================================================================
166//function : Compute
167//purpose :
168//=======================================================================
169Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
170Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
171 const Handle(Geom_Transformation)& TheTrsf)
172{
173#ifdef DEB
81bba717 174 cout<<"passage in G = Compute(P,Trsf)"<<endl;
7fd59977 175#endif
176 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
177
178
179 if(TheTrsf->Form()== gp_Translation){
180#ifdef DEB
181 cout<<"\tla Trsf est une translation"<<endl;
182#endif
183
184 myPresentableObject->Compute(Projector(aProjector),g);
185 g->Transform(TheTrsf);
186 }
187 else{
81bba717 188 // waiting that something is done in gp_Trsf...rob
7fd59977 189 Standard_Boolean good (Standard_True);
190 for (Standard_Integer i=1;i<=3 && good ;i++){
191 for (Standard_Integer j=1;j<=3 && good ;j++){
192 if(i!=j){
193 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
194 good = Standard_False;
195 }
196 }
197 }
198
199 if(good){
200#ifdef DEB
81bba717 201 cout<<"\t it is checked if Trsf is a Translation"<<endl;
7fd59977 202#endif
203 myPresentableObject->Compute(Projector(aProjector),g);
204 g->Transform(TheTrsf);
205
206 }
207 else{
208#ifdef DEB
81bba717 209 cout<<"\t Trsf is not only translation..."<<endl;
7fd59977 210#endif
211 myPresentableObject->Compute(Projector(aProjector),TheTrsf,g);
212 }
213 }
214 return g;
215}
216
217//=======================================================================
218//function : Compute
219//purpose :
220//=======================================================================
221void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
222 const Handle(Geom_Transformation)& TheTrsf,
223 const Handle(Graphic3d_Structure)& TheStructToFill)
224{
225
226#ifdef DEB
81bba717 227 cout<<"passage in Compute(P,Trsf,Str)"<<endl;
7fd59977 228#endif
229
230 Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill);
231
232#ifdef IMP040200
233 TheStructToFill->Clear();
234 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
81bba717 235#else //Does not work properly, HLR seems deactivated for view rotation
7fd59977 236 if(TheTrsf->Form()== gp_Translation){
237#ifdef DEB
81bba717 238 cout<<"\t Trsf is a translation"<<endl;
7fd59977 239#endif
240// myPresentableObject->Compute(Projector(aProjector),P);
241 P->Transform(TheTrsf);
242 }
243 else{
81bba717 244 // waiting that something is done in gp_Trsf...rob
7fd59977 245 Standard_Boolean good (Standard_True);
246 for (Standard_Integer i=1;i<=3 && good ;i++){
247 for (Standard_Integer j=1;j<=3 && good ;j++){
248 if(i!=j){
249 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
250 good = Standard_False;
251 }
252 }
253 }
254 if(good && !TheStructToFill->IsEmpty()){
255#ifdef DEB
81bba717 256 cout<<"\t it is checked if Trsf is a Translation"<<endl;
7fd59977 257#endif
258
259 P->Transform(TheTrsf);
260 }
261 else{
262 TheStructToFill->Clear();
263
264#ifdef DEB
81bba717 265 cout<<"\t Trsf is not only translation..."<<endl;
7fd59977 266#endif
267
268 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
269 }
270 }
271#endif
272}
273
274
275
276
277
278
279//=======================================================================
280//function : Projector
281//purpose :
282//=======================================================================
283
284Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector) {
285 Visual3d_ViewOrientation VO = Handle(Visual3d_View)::DownCast(aProjector)->ViewOrientation();
286 Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp;
287 VO.ViewReferencePlane().Coord(DX, DY, DZ);
288 VO.ViewReferencePoint().Coord(XAt,YAt,ZAt);
289 VO.ViewReferenceUp().Coord(XUp, YUp, ZUp);
290 Visual3d_ViewMapping VM = Handle(Visual3d_View)::DownCast(aProjector)->ViewMapping();
291 Standard_Boolean pers = (VM.Projection() == Visual3d_TOP_PERSPECTIVE);
292 Standard_Real focale = 0.0 ;
293 if (pers) {
294 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
295 Graphic3d_Vertex Prp = VM.ProjectionReferencePoint() ;
296 Prp.Coord(Xrp,Yrp,Zrp);
297 FrontPlane = VM.FrontPlaneDistance() ;
298 ViewPlane = VM.ViewPlaneDistance() ;
299 focale = FrontPlane + Zrp - ViewPlane ;
300 }
301 Handle(Prs3d_Projector) Proj = new Prs3d_Projector(pers,focale,DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp);
302 return Proj;
303
304}
305
306void PrsMgr_Presentation3d::Destroy () {
307 if (!myStructure.IsNull())
308 myStructure->Clear();
309 myStructure.Nullify();
310}