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