Commit | Line | Data |
---|---|---|
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> | |
eb4320f2 | 30 | #include <PrsMgr_ModedPresentation.hxx> |
7fd59977 | 31 | #include <Visual3d_View.hxx> |
32 | #include <Visual3d_ViewOrientation.hxx> | |
33 | #include <Graphic3d_Structure.hxx> | |
34 | #include <Precision.hxx> | |
35 | ||
36 | PrsMgr_Presentation3d::PrsMgr_Presentation3d (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
37 | const Handle(PrsMgr_PresentableObject)& aPresentableObject) | |
38 | : PrsMgr_Presentation(aPresentationManager), | |
39 | myDisplayReason(Standard_False), | |
40 | myPresentableObject (aPresentableObject.operator->()) | |
41 | { | |
42 | myStructure = new PrsMgr_Prs(aPresentationManager->StructureManager(), | |
43 | this, aPresentableObject->TypeOfPresentation3d()); | |
44 | myStructure->SetOwner(myPresentableObject); | |
45 | } | |
46 | ||
47 | PrsMgr_KindOfPrs PrsMgr_Presentation3d::KindOfPresentation() const | |
48 | {return PrsMgr_KOP_3D;} | |
49 | ||
50 | ||
eb4320f2 | 51 | void PrsMgr_Presentation3d::Display() |
52 | { | |
53 | Display (Standard_False); | |
7fd59977 | 54 | myDisplayReason = Standard_False; |
55 | } | |
56 | ||
eb4320f2 | 57 | void PrsMgr_Presentation3d::Display(const Standard_Boolean theIsHighlight) |
58 | { | |
59 | if (!myStructure->IsDisplayed()) | |
60 | { | |
61 | myStructure->Display(); | |
62 | myDisplayReason = theIsHighlight; | |
63 | } | |
64 | else if (!myStructure->IsVisible()) | |
65 | { | |
66 | myStructure->SetVisible (Standard_True); | |
67 | myDisplayReason = theIsHighlight; | |
68 | } | |
69 | } | |
70 | ||
7fd59977 | 71 | void PrsMgr_Presentation3d::Erase () const { |
72 | myStructure->Erase();} | |
73 | ||
eb4320f2 | 74 | void PrsMgr_Presentation3d::SetVisible (const Standard_Boolean theValue) |
75 | { | |
76 | myStructure->SetVisible (theValue); | |
77 | } | |
78 | ||
7fd59977 | 79 | void PrsMgr_Presentation3d::Highlight () { |
eb4320f2 | 80 | Display (Standard_True); |
7fd59977 | 81 | myStructure->Highlight();} |
82 | ||
83 | void PrsMgr_Presentation3d::Unhighlight () const { | |
84 | myStructure->UnHighlight(); | |
eb4320f2 | 85 | if (myDisplayReason) myStructure->SetVisible (Standard_False); |
7fd59977 | 86 | } |
87 | ||
88 | void PrsMgr_Presentation3d::Clear() { | |
89 | // This modification remove the contain of the structure: | |
90 | // Consequence: | |
91 | // 1. The memory zone of the group is reused | |
92 | // 2. The speed for animation is constant | |
bbf32d01 K |
93 | //myPresentableObject = NULL; |
94 | SetUpdateStatus(Standard_True); | |
7fd59977 | 95 | myStructure->Clear(Standard_True); |
96 | // myStructure->Clear(Standard_False); | |
97 | ||
98 | myStructure->RemoveAll(); | |
99 | } | |
100 | ||
101 | void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){ | |
eb4320f2 | 102 | Display (Standard_True); |
7fd59977 | 103 | myStructure->Color(aColor); |
104 | } | |
105 | ||
106 | void PrsMgr_Presentation3d::BoundBox() const { | |
107 | myStructure->BoundBox(); | |
108 | } | |
109 | ||
110 | Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const { | |
eb4320f2 | 111 | return myStructure->IsDisplayed() && myStructure->IsVisible() && !myDisplayReason; |
7fd59977 | 112 | } |
113 | ||
114 | Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const { | |
115 | return myStructure->IsHighlighted(); | |
116 | } | |
117 | ||
118 | ||
119 | Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const { | |
120 | return myStructure->DisplayPriority(); | |
121 | } | |
122 | ||
123 | void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior) | |
124 | { | |
125 | myStructure->SetDisplayPriority(TheNewPrior); | |
126 | } | |
127 | ||
128 | Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const { | |
129 | return myStructure; | |
130 | } | |
131 | void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const { | |
132 | myStructure->Connect(anOtherPresentation->Presentation()); | |
133 | } | |
134 | ||
135 | void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const { | |
136 | myStructure->Transform(aTransformation); | |
137 | } | |
138 | ||
139 | void PrsMgr_Presentation3d::Place (const Quantity_Length X, | |
140 | const Quantity_Length Y, | |
141 | const Quantity_Length Z) const { | |
142 | myStructure->Place(X,Y,Z); | |
143 | } | |
144 | ||
145 | void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const { | |
146 | myStructure->Multiply(aTransformation); | |
147 | } | |
148 | ||
149 | void PrsMgr_Presentation3d::Move (const Quantity_Length X, | |
150 | const Quantity_Length Y, | |
151 | const Quantity_Length Z) const { | |
152 | myStructure->Move(X,Y,Z); | |
153 | } | |
154 | ||
155 | void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const { | |
156 | myStructure->SetShadingAspect(aShadingAspect); | |
157 | } | |
158 | ||
159 | ||
160 | ||
161 | //======================================================================= | |
162 | //function : Compute | |
81bba717 | 163 | //purpose : Methods for hidden parts... |
7fd59977 | 164 | //======================================================================= |
165 | ||
166 | Handle(Graphic3d_Structure) PrsMgr_Presentation3d:: | |
167 | Compute(const Handle(Graphic3d_DataStructureManager)& aProjector) | |
168 | { | |
169 | #ifdef DEB | |
81bba717 | 170 | cout<<"passage in g = Compute(P) "<<endl; |
7fd59977 | 171 | #endif |
172 | Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager()); | |
173 | myPresentableObject->Compute(Projector(aProjector),g); | |
174 | return g; | |
175 | } | |
176 | ||
177 | //======================================================================= | |
178 | //function : Compute | |
179 | //purpose : | |
180 | //======================================================================= | |
181 | ||
eb4320f2 | 182 | void PrsMgr_Presentation3d::Compute (const Handle(Graphic3d_Structure)& theStructure) |
183 | { | |
184 | Standard_Integer aDispMode = 0; | |
185 | ||
186 | Standard_Integer aPresentationsNumber = myPresentableObject->myPresentations.Length(); | |
187 | for (Standard_Integer anIter = 1; anIter <= aPresentationsNumber; anIter++) | |
188 | { | |
189 | const PrsMgr_ModedPresentation& aModedPresentation = myPresentableObject->myPresentations.Value (anIter); | |
190 | Handle(PrsMgr_Presentation) aPresentation = aModedPresentation.Presentation(); | |
191 | PrsMgr_Presentation3d* aPresentation3d = (PrsMgr_Presentation3d* )aPresentation.operator->(); | |
192 | if (aPresentation3d == this) | |
193 | { | |
194 | aDispMode = aModedPresentation.Mode(); | |
195 | break; | |
196 | } | |
197 | } | |
198 | ||
199 | Handle(Prs3d_Presentation) aPrs3d = Handle(Prs3d_Presentation)::DownCast (theStructure); | |
200 | ||
201 | myPresentableObject->Compute( | |
202 | Handle(PrsMgr_PresentationManager3d)::DownCast (PresentationManager()), | |
203 | aPrs3d, | |
204 | aDispMode); | |
205 | } | |
206 | ||
207 | //======================================================================= | |
208 | //function : Compute | |
209 | //purpose : | |
210 | //======================================================================= | |
211 | ||
7fd59977 | 212 | void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector, |
213 | const Handle(Graphic3d_Structure)& TheStructToFill) | |
214 | { | |
215 | #ifdef DEB | |
81bba717 | 216 | cout<<"passage in Compute(P,Str)"<<endl; |
7fd59977 | 217 | #endif |
218 | TheStructToFill->Clear(); | |
219 | const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill); | |
220 | myPresentableObject->Compute(Projector(aProjector),P); | |
221 | } | |
222 | ||
223 | //======================================================================= | |
224 | //function : Compute | |
225 | //purpose : | |
226 | //======================================================================= | |
227 | Handle(Graphic3d_Structure) PrsMgr_Presentation3d:: | |
228 | Compute(const Handle(Graphic3d_DataStructureManager)& aProjector, | |
229 | const Handle(Geom_Transformation)& TheTrsf) | |
230 | { | |
231 | #ifdef DEB | |
81bba717 | 232 | cout<<"passage in G = Compute(P,Trsf)"<<endl; |
7fd59977 | 233 | #endif |
234 | Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager()); | |
235 | ||
236 | ||
237 | if(TheTrsf->Form()== gp_Translation){ | |
238 | #ifdef DEB | |
239 | cout<<"\tla Trsf est une translation"<<endl; | |
240 | #endif | |
241 | ||
242 | myPresentableObject->Compute(Projector(aProjector),g); | |
243 | g->Transform(TheTrsf); | |
244 | } | |
245 | else{ | |
81bba717 | 246 | // waiting that something is done in gp_Trsf...rob |
7fd59977 | 247 | Standard_Boolean good (Standard_True); |
248 | for (Standard_Integer i=1;i<=3 && good ;i++){ | |
249 | for (Standard_Integer j=1;j<=3 && good ;j++){ | |
250 | if(i!=j){ | |
251 | if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion()) | |
252 | good = Standard_False; | |
253 | } | |
254 | } | |
255 | } | |
256 | ||
257 | if(good){ | |
258 | #ifdef DEB | |
81bba717 | 259 | cout<<"\t it is checked if Trsf is a Translation"<<endl; |
7fd59977 | 260 | #endif |
261 | myPresentableObject->Compute(Projector(aProjector),g); | |
262 | g->Transform(TheTrsf); | |
263 | ||
264 | } | |
265 | else{ | |
266 | #ifdef DEB | |
81bba717 | 267 | cout<<"\t Trsf is not only translation..."<<endl; |
7fd59977 | 268 | #endif |
269 | myPresentableObject->Compute(Projector(aProjector),TheTrsf,g); | |
270 | } | |
271 | } | |
272 | return g; | |
273 | } | |
274 | ||
275 | //======================================================================= | |
276 | //function : Compute | |
277 | //purpose : | |
278 | //======================================================================= | |
279 | void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector, | |
280 | const Handle(Geom_Transformation)& TheTrsf, | |
281 | const Handle(Graphic3d_Structure)& TheStructToFill) | |
282 | { | |
283 | ||
284 | #ifdef DEB | |
81bba717 | 285 | cout<<"passage in Compute(P,Trsf,Str)"<<endl; |
7fd59977 | 286 | #endif |
287 | ||
288 | Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill); | |
289 | ||
290 | #ifdef IMP040200 | |
291 | TheStructToFill->Clear(); | |
292 | myPresentableObject->Compute(Projector(aProjector),TheTrsf,P); | |
81bba717 | 293 | #else //Does not work properly, HLR seems deactivated for view rotation |
7fd59977 | 294 | if(TheTrsf->Form()== gp_Translation){ |
295 | #ifdef DEB | |
81bba717 | 296 | cout<<"\t Trsf is a translation"<<endl; |
7fd59977 | 297 | #endif |
298 | // myPresentableObject->Compute(Projector(aProjector),P); | |
299 | P->Transform(TheTrsf); | |
300 | } | |
301 | else{ | |
81bba717 | 302 | // waiting that something is done in gp_Trsf...rob |
7fd59977 | 303 | Standard_Boolean good (Standard_True); |
304 | for (Standard_Integer i=1;i<=3 && good ;i++){ | |
305 | for (Standard_Integer j=1;j<=3 && good ;j++){ | |
306 | if(i!=j){ | |
307 | if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion()) | |
308 | good = Standard_False; | |
309 | } | |
310 | } | |
311 | } | |
312 | if(good && !TheStructToFill->IsEmpty()){ | |
313 | #ifdef DEB | |
81bba717 | 314 | cout<<"\t it is checked if Trsf is a Translation"<<endl; |
7fd59977 | 315 | #endif |
316 | ||
317 | P->Transform(TheTrsf); | |
318 | } | |
319 | else{ | |
320 | TheStructToFill->Clear(); | |
321 | ||
322 | #ifdef DEB | |
81bba717 | 323 | cout<<"\t Trsf is not only translation..."<<endl; |
7fd59977 | 324 | #endif |
325 | ||
326 | myPresentableObject->Compute(Projector(aProjector),TheTrsf,P); | |
327 | } | |
328 | } | |
329 | #endif | |
330 | } | |
331 | ||
332 | ||
333 | ||
334 | ||
335 | ||
336 | ||
337 | //======================================================================= | |
338 | //function : Projector | |
339 | //purpose : | |
340 | //======================================================================= | |
341 | ||
342 | Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector) { | |
343 | Visual3d_ViewOrientation VO = Handle(Visual3d_View)::DownCast(aProjector)->ViewOrientation(); | |
344 | Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp; | |
345 | VO.ViewReferencePlane().Coord(DX, DY, DZ); | |
346 | VO.ViewReferencePoint().Coord(XAt,YAt,ZAt); | |
347 | VO.ViewReferenceUp().Coord(XUp, YUp, ZUp); | |
348 | Visual3d_ViewMapping VM = Handle(Visual3d_View)::DownCast(aProjector)->ViewMapping(); | |
349 | Standard_Boolean pers = (VM.Projection() == Visual3d_TOP_PERSPECTIVE); | |
350 | Standard_Real focale = 0.0 ; | |
351 | if (pers) { | |
352 | Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ; | |
353 | Graphic3d_Vertex Prp = VM.ProjectionReferencePoint() ; | |
354 | Prp.Coord(Xrp,Yrp,Zrp); | |
355 | FrontPlane = VM.FrontPlaneDistance() ; | |
356 | ViewPlane = VM.ViewPlaneDistance() ; | |
357 | focale = FrontPlane + Zrp - ViewPlane ; | |
358 | } | |
359 | Handle(Prs3d_Projector) Proj = new Prs3d_Projector(pers,focale,DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp); | |
360 | return Proj; | |
361 | ||
362 | } | |
363 | ||
364 | void PrsMgr_Presentation3d::Destroy () { | |
365 | if (!myStructure.IsNull()) | |
366 | myStructure->Clear(); | |
367 | myStructure.Nullify(); | |
368 | } | |
59f45b7c | 369 | |
370 | //======================================================================= | |
371 | //function : SetZLayer | |
372 | //purpose : | |
373 | //======================================================================= | |
374 | ||
375 | void PrsMgr_Presentation3d::SetZLayer (Standard_Integer theLayerId) | |
376 | { | |
377 | myStructure->SetZLayer (theLayerId); | |
378 | } | |
379 | ||
380 | //======================================================================= | |
381 | //function : GetZLayer | |
382 | //purpose : | |
383 | //======================================================================= | |
384 | ||
385 | Standard_Integer PrsMgr_Presentation3d::GetZLayer () const | |
386 | { | |
387 | return myStructure->GetZLayer (); | |
388 | } |