OCC22256 Add mechanism based on malloc/free callback for debugging memory problems
[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
59 myStructure->Clear(Standard_True);
60 // myStructure->Clear(Standard_False);
61
62 myStructure->RemoveAll();
63}
64
65void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){
66 Standard_Boolean ImmMode = myPresentationManager->IsImmediateModeOn();
67 if(!ImmMode){
68 if(!myStructure->IsDisplayed()) {
69 myStructure->Display();
70 myDisplayReason = Standard_True;
71 }
72 }
73 myStructure->Color(aColor);
74}
75
76void PrsMgr_Presentation3d::BoundBox() const {
77 myStructure->BoundBox();
78}
79
80Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const {
81 return myStructure->IsDisplayed() && !myDisplayReason;
82}
83
84Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const {
85 return myStructure->IsHighlighted();
86}
87
88
89Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const {
90return myStructure->DisplayPriority();
91}
92
93void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior)
94{
95 myStructure->SetDisplayPriority(TheNewPrior);
96}
97
98Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const {
99 return myStructure;
100}
101void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const {
102 myStructure->Connect(anOtherPresentation->Presentation());
103}
104
105void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const {
106 myStructure->Transform(aTransformation);
107}
108
109void PrsMgr_Presentation3d::Place (const Quantity_Length X,
110 const Quantity_Length Y,
111 const Quantity_Length Z) const {
112 myStructure->Place(X,Y,Z);
113}
114
115void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const {
116 myStructure->Multiply(aTransformation);
117}
118
119void PrsMgr_Presentation3d::Move (const Quantity_Length X,
120 const Quantity_Length Y,
121 const Quantity_Length Z) const {
122 myStructure->Move(X,Y,Z);
123}
124
125void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const {
126 myStructure->SetShadingAspect(aShadingAspect);
127}
128
129
130
131//=======================================================================
132//function : Compute
81bba717 133//purpose : Methods for hidden parts...
7fd59977 134//=======================================================================
135
136Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
137Compute(const Handle(Graphic3d_DataStructureManager)& aProjector)
138{
139#ifdef DEB
81bba717 140 cout<<"passage in g = Compute(P) "<<endl;
7fd59977 141#endif
142 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
143 myPresentableObject->Compute(Projector(aProjector),g);
144 return g;
145}
146
147//=======================================================================
148//function : Compute
149//purpose :
150//=======================================================================
151
152void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
153 const Handle(Graphic3d_Structure)& TheStructToFill)
154{
155#ifdef DEB
81bba717 156 cout<<"passage in Compute(P,Str)"<<endl;
7fd59977 157#endif
158 TheStructToFill->Clear();
159 const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill);
160 myPresentableObject->Compute(Projector(aProjector),P);
161}
162
163//=======================================================================
164//function : Compute
165//purpose :
166//=======================================================================
167Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
168Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
169 const Handle(Geom_Transformation)& TheTrsf)
170{
171#ifdef DEB
81bba717 172 cout<<"passage in G = Compute(P,Trsf)"<<endl;
7fd59977 173#endif
174 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
175
176
177 if(TheTrsf->Form()== gp_Translation){
178#ifdef DEB
179 cout<<"\tla Trsf est une translation"<<endl;
180#endif
181
182 myPresentableObject->Compute(Projector(aProjector),g);
183 g->Transform(TheTrsf);
184 }
185 else{
81bba717 186 // waiting that something is done in gp_Trsf...rob
7fd59977 187 Standard_Boolean good (Standard_True);
188 for (Standard_Integer i=1;i<=3 && good ;i++){
189 for (Standard_Integer j=1;j<=3 && good ;j++){
190 if(i!=j){
191 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
192 good = Standard_False;
193 }
194 }
195 }
196
197 if(good){
198#ifdef DEB
81bba717 199 cout<<"\t it is checked if Trsf is a Translation"<<endl;
7fd59977 200#endif
201 myPresentableObject->Compute(Projector(aProjector),g);
202 g->Transform(TheTrsf);
203
204 }
205 else{
206#ifdef DEB
81bba717 207 cout<<"\t Trsf is not only translation..."<<endl;
7fd59977 208#endif
209 myPresentableObject->Compute(Projector(aProjector),TheTrsf,g);
210 }
211 }
212 return g;
213}
214
215//=======================================================================
216//function : Compute
217//purpose :
218//=======================================================================
219void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
220 const Handle(Geom_Transformation)& TheTrsf,
221 const Handle(Graphic3d_Structure)& TheStructToFill)
222{
223
224#ifdef DEB
81bba717 225 cout<<"passage in Compute(P,Trsf,Str)"<<endl;
7fd59977 226#endif
227
228 Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill);
229
230#ifdef IMP040200
231 TheStructToFill->Clear();
232 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
81bba717 233#else //Does not work properly, HLR seems deactivated for view rotation
7fd59977 234 if(TheTrsf->Form()== gp_Translation){
235#ifdef DEB
81bba717 236 cout<<"\t Trsf is a translation"<<endl;
7fd59977 237#endif
238// myPresentableObject->Compute(Projector(aProjector),P);
239 P->Transform(TheTrsf);
240 }
241 else{
81bba717 242 // waiting that something is done in gp_Trsf...rob
7fd59977 243 Standard_Boolean good (Standard_True);
244 for (Standard_Integer i=1;i<=3 && good ;i++){
245 for (Standard_Integer j=1;j<=3 && good ;j++){
246 if(i!=j){
247 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
248 good = Standard_False;
249 }
250 }
251 }
252 if(good && !TheStructToFill->IsEmpty()){
253#ifdef DEB
81bba717 254 cout<<"\t it is checked if Trsf is a Translation"<<endl;
7fd59977 255#endif
256
257 P->Transform(TheTrsf);
258 }
259 else{
260 TheStructToFill->Clear();
261
262#ifdef DEB
81bba717 263 cout<<"\t Trsf is not only translation..."<<endl;
7fd59977 264#endif
265
266 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
267 }
268 }
269#endif
270}
271
272
273
274
275
276
277//=======================================================================
278//function : Projector
279//purpose :
280//=======================================================================
281
282Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector) {
283 Visual3d_ViewOrientation VO = Handle(Visual3d_View)::DownCast(aProjector)->ViewOrientation();
284 Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp;
285 VO.ViewReferencePlane().Coord(DX, DY, DZ);
286 VO.ViewReferencePoint().Coord(XAt,YAt,ZAt);
287 VO.ViewReferenceUp().Coord(XUp, YUp, ZUp);
288 Visual3d_ViewMapping VM = Handle(Visual3d_View)::DownCast(aProjector)->ViewMapping();
289 Standard_Boolean pers = (VM.Projection() == Visual3d_TOP_PERSPECTIVE);
290 Standard_Real focale = 0.0 ;
291 if (pers) {
292 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
293 Graphic3d_Vertex Prp = VM.ProjectionReferencePoint() ;
294 Prp.Coord(Xrp,Yrp,Zrp);
295 FrontPlane = VM.FrontPlaneDistance() ;
296 ViewPlane = VM.ViewPlaneDistance() ;
297 focale = FrontPlane + Zrp - ViewPlane ;
298 }
299 Handle(Prs3d_Projector) Proj = new Prs3d_Projector(pers,focale,DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp);
300 return Proj;
301
302}
303
304void PrsMgr_Presentation3d::Destroy () {
305 if (!myStructure.IsNull())
306 myStructure->Clear();
307 myStructure.Nullify();
308}