b311480e |
1 | // Created on: 1997-12-16 |
2 | // Created by: Jean Louis Frenkel |
3 | // Copyright (c) 1997-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 |
22 | // 16-dec-1997 : Update Flag for Presentations. |
7fd59977 |
23 | |
24 | |
25 | #include <PrsMgr_PresentableObject.ixx> |
26 | #include <PrsMgr_Presentation.hxx> |
7fd59977 |
27 | #include <PrsMgr_Presentation3d.hxx> |
28 | #include <PrsMgr_ModedPresentation.hxx> |
29 | #include <PrsMgr_PresentationManager.hxx> |
30 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
31 | #include <TColStd_MapOfInteger.hxx> |
32 | #include <Graphic3d_TypeOfStructure.hxx> |
33 | #include <Geom_Transformation.hxx> |
34 | |
35 | //======================================================================= |
36 | //function : PrsMgr_PresentableObject |
37 | //purpose : |
38 | //======================================================================= |
7fd59977 |
39 | PrsMgr_PresentableObject::PrsMgr_PresentableObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d) |
40 | :myPresentations(),myTypeOfPresentation3d(aTypeOfPresentation3d) |
41 | { |
42 | myTransformPersistence.Flag = 0; |
43 | myTransformPersistence.Point.x = 0.0; |
44 | myTransformPersistence.Point.y = 0.0; |
45 | myTransformPersistence.Point.z = 0.0; |
46 | } |
47 | |
7fd59977 |
48 | //======================================================================= |
49 | //function : Fill |
50 | //purpose : |
51 | //======================================================================= |
4269bd1b |
52 | void PrsMgr_PresentableObject::Fill (const Handle(PrsMgr_PresentationManager)& aPresentationManager, |
53 | const Handle(PrsMgr_Presentation)& aPresentation, |
54 | const Standard_Integer aMode) |
55 | { |
56 | if (aPresentation->DynamicType() == STANDARD_TYPE (PrsMgr_Presentation3d)) |
57 | { |
58 | Handle(PrsMgr_PresentationManager3d) aPrsMgr3d = |
59 | (Handle(PrsMgr_PresentationManager3d)&)aPresentationManager; |
60 | Handle(PrsMgr_Presentation3d) aPrs3d = |
61 | (Handle(PrsMgr_Presentation3d)&)aPresentation; |
62 | Handle(Prs3d_Presentation) aStruct3d = aPrs3d->Presentation(); |
63 | |
64 | Compute (aPrsMgr3d, aStruct3d, aMode); |
65 | UpdateLocation (aStruct3d); |
66 | aStruct3d->SetClipPlanes (myClipPlanes); |
67 | aStruct3d->SetTransformPersistence (GetTransformPersistenceMode(), GetTransformPersistencePoint()); |
7fd59977 |
68 | } |
69 | } |
70 | |
7fd59977 |
71 | //======================================================================= |
72 | //function : Compute |
73 | //purpose : |
74 | //======================================================================= |
75 | void PrsMgr_PresentableObject::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
76 | const Handle(Prs3d_Presentation)& /*aPresentation*/, |
77 | const Standard_Integer /*aMode*/) |
78 | { |
79 | Standard_NotImplemented::Raise("cannot compute in a 3d visualizer"); |
80 | } |
4269bd1b |
81 | |
7fd59977 |
82 | //======================================================================= |
83 | //function : Compute |
84 | //purpose : |
85 | //======================================================================= |
86 | void PrsMgr_PresentableObject::Compute(const Handle(Prs3d_Projector)& /*aProjector*/, |
87 | const Handle(Prs3d_Presentation)& /*aPresentation*/) |
88 | { |
89 | Standard_NotImplemented::Raise("cannot compute under a specific projector"); |
90 | } |
4269bd1b |
91 | |
7fd59977 |
92 | //======================================================================= |
93 | //function : Compute |
94 | //purpose : |
95 | //======================================================================= |
96 | void PrsMgr_PresentableObject::Compute(const Handle(Prs3d_Projector)& /* aProjector*/, |
97 | const Handle(Geom_Transformation)& /*aTrsf*/, |
98 | const Handle(Prs3d_Presentation)& /*aPresentation*/) |
99 | { |
100 | Standard_NotImplemented::Raise("cannot compute under a specific projector"); |
101 | } |
102 | |
103 | //======================================================================= |
104 | //function : Update |
105 | //purpose : |
106 | //======================================================================= |
107 | void PrsMgr_PresentableObject::Update (const Standard_Boolean AllModes) { |
108 | Standard_Integer l = myPresentations.Length(); |
109 | Handle(PrsMgr_PresentationManager) PM; |
110 | for (Standard_Integer i=1; i <= l; i++) { |
111 | PM = myPresentations(i).Presentation()->PresentationManager(); |
112 | if(AllModes) |
113 | PM->Update(this,myPresentations(i).Mode()); |
114 | else{ |
115 | if(PM->IsDisplayed(this,myPresentations(i).Mode()) || |
116 | PM->IsHighlighted(this,myPresentations(i).Mode())){ |
117 | PM->Update(this,myPresentations(i).Mode()); |
118 | } |
119 | else |
120 | SetToUpdate(myPresentations(i).Mode()); |
121 | } |
122 | } |
123 | } |
4269bd1b |
124 | |
7fd59977 |
125 | //======================================================================= |
126 | //function : Update |
127 | //purpose : |
128 | //======================================================================= |
7fd59977 |
129 | void PrsMgr_PresentableObject::Update (const Standard_Integer aMode, const Standard_Boolean ClearOther) { |
130 | Standard_Integer l = myPresentations.Length(); |
131 | for (Standard_Integer i=1; i <= l; i++) { |
132 | if( myPresentations(i).Mode() == aMode){ |
133 | Handle(PrsMgr_PresentationManager) PM= |
134 | myPresentations(i).Presentation()->PresentationManager(); |
135 | |
136 | if(PM->IsDisplayed(this,aMode) || |
137 | PM->IsHighlighted(this,aMode)){ |
138 | PM->Update(this,aMode); |
139 | myPresentations(i).Presentation()->SetUpdateStatus(Standard_False); |
140 | |
141 | } |
142 | else |
143 | SetToUpdate(myPresentations(i).Mode()); |
144 | } |
145 | |
146 | } |
147 | if(ClearOther) { |
148 | PrsMgr_Presentations save; |
149 | save = myPresentations; |
150 | myPresentations.Clear(); |
151 | for (Standard_Integer i=1; i <= l; i++) { |
152 | if( save(i).Mode() == aMode) myPresentations.Append(save(i)); |
153 | } |
154 | } |
155 | |
156 | } |
4269bd1b |
157 | |
7fd59977 |
158 | //======================================================================= |
159 | //function : Presentations |
160 | //purpose : |
161 | //======================================================================= |
7fd59977 |
162 | PrsMgr_Presentations& PrsMgr_PresentableObject::Presentations() { |
163 | return myPresentations; |
164 | } |
165 | |
166 | //======================================================================= |
167 | //function : HasLocation |
168 | //purpose : |
169 | //======================================================================= |
7fd59977 |
170 | Standard_Boolean PrsMgr_PresentableObject::HasLocation() const |
171 | { |
4269bd1b |
172 | return !Location().IsIdentity(); |
173 | } |
7fd59977 |
174 | |
175 | //======================================================================= |
176 | //function : SetToUpdate |
177 | //purpose : |
178 | //======================================================================= |
7fd59977 |
179 | void PrsMgr_PresentableObject::SetToUpdate(const Standard_Integer aMode) |
180 | { |
181 | for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){ |
182 | if(myPresentations(IP).Mode()==aMode) |
183 | myPresentations(IP).Presentation()->SetUpdateStatus(Standard_True); |
184 | } |
185 | } |
4269bd1b |
186 | |
187 | //======================================================================= |
188 | //function : SetToUpdate |
189 | //purpose : |
190 | //======================================================================= |
7fd59977 |
191 | void PrsMgr_PresentableObject::SetToUpdate() |
192 | { |
193 | for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){ |
194 | myPresentations(IP).Presentation()->SetUpdateStatus(Standard_True); |
195 | } |
196 | } |
197 | |
198 | //======================================================================= |
199 | //function : ToBeUpdated |
200 | //purpose : gets the list of modes to be updated |
201 | //======================================================================= |
202 | void PrsMgr_PresentableObject::ToBeUpdated(TColStd_ListOfInteger& OutList) const |
203 | { |
204 | OutList.Clear(); |
205 | // on dimensionne les buckets a la taille de la seq. |
206 | static TColStd_MapOfInteger MI(myPresentations.Length()); |
207 | |
208 | for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){ |
209 | const PrsMgr_ModedPresentation& MP = myPresentations(IP); |
210 | if(MP.Presentation()->MustBeUpdated()) |
211 | if(!MI.Contains(MP.Mode())){ |
212 | OutList.Append(MP.Mode()); |
213 | MI.Add(MP.Mode()); |
214 | } |
215 | } |
216 | MI.Clear(); |
217 | } |
218 | |
219 | //======================================================================= |
220 | //function : SetTypeOfPresentation |
221 | //purpose : |
222 | //======================================================================= |
7fd59977 |
223 | void PrsMgr_PresentableObject::SetTypeOfPresentation(const PrsMgr_TypeOfPresentation3d aType) |
224 | { |
225 | myTypeOfPresentation3d = aType; |
226 | |
227 | for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){ |
228 | const Handle(PrsMgr_Presentation)& P = myPresentations(IP).Presentation(); |
229 | if(P->KindOfPresentation()==PrsMgr_KOP_3D){ |
230 | Graphic3d_TypeOfStructure Typ = |
231 | (myTypeOfPresentation3d == PrsMgr_TOP_ProjectorDependant)? |
232 | Graphic3d_TOS_COMPUTED : Graphic3d_TOS_ALL; |
233 | (*(Handle(PrsMgr_Presentation3d)*)&P)->Presentation()->SetVisual(Typ); |
234 | } |
235 | } |
236 | } |
237 | |
238 | //======================================================================= |
239 | //function : SetLocation |
240 | //purpose : WARNING : use with only 3D objects... |
241 | //======================================================================= |
242 | void PrsMgr_PresentableObject::SetLocation(const TopLoc_Location& aLoc) |
243 | { |
244 | if(aLoc.IsIdentity()) return; |
245 | myLocation = aLoc; |
246 | UpdateLocation(); |
247 | } |
248 | |
249 | //======================================================================= |
250 | //function : ReSetLocation |
251 | //purpose : |
252 | //======================================================================= |
253 | void PrsMgr_PresentableObject::ResetLocation() |
254 | { |
255 | TopLoc_Location aLoc; |
256 | Handle(Geom_Transformation) G = new Geom_Transformation(aLoc.Transformation()); |
257 | |
258 | for(Standard_Integer i=1;i<=myPresentations.Length();i++){ |
259 | const Handle(PrsMgr_Presentation)& P = myPresentations(i).Presentation(); |
260 | if(P->KindOfPresentation()==PrsMgr_KOP_3D){ |
261 | (*((Handle(PrsMgr_Presentation3d)*)&P))->Transform(G); |
262 | } |
263 | } |
264 | myLocation = aLoc; |
265 | } |
266 | |
4269bd1b |
267 | //======================================================================= |
268 | //function : UpdateLocation |
269 | //purpose : |
270 | //======================================================================= |
7fd59977 |
271 | void PrsMgr_PresentableObject::UpdateLocation() |
272 | { |
273 | if(!HasLocation()) return; |
274 | Handle(Geom_Transformation) G = new Geom_Transformation(Location().Transformation()); |
275 | if(G->Trsf().Form()==gp_Identity) return; |
276 | for (Standard_Integer i=1;i<=myPresentations.Length();i++){ |
277 | const Handle(PrsMgr_Presentation)& P = myPresentations(i).Presentation(); |
278 | if(P->KindOfPresentation()==PrsMgr_KOP_3D){ |
279 | (*((Handle(PrsMgr_Presentation3d)*)&P))->Transform(G); |
280 | } |
281 | } |
282 | } |
283 | |
7fd59977 |
284 | //======================================================================= |
285 | //function : UpdateLocation |
286 | //purpose : |
287 | //======================================================================= |
7fd59977 |
288 | void PrsMgr_PresentableObject::UpdateLocation(const Handle(Prs3d_Presentation)& P) |
289 | { |
290 | if(myLocation.IsIdentity()) return; |
291 | Handle(Geom_Transformation) G = new Geom_Transformation(Location().Transformation()); |
292 | P->Transform(G); |
293 | |
294 | } |
295 | |
296 | //======================================================================= |
297 | //function : SetTransformPersistence |
298 | //purpose : |
299 | //======================================================================= |
300 | void PrsMgr_PresentableObject::SetTransformPersistence( const Graphic3d_TransModeFlags& TheFlag, |
301 | const gp_Pnt& ThePoint ) |
302 | { |
303 | myTransformPersistence.Flag = TheFlag; |
7f4c4756 |
304 | myTransformPersistence.Point.x = (Standard_ShortReal)ThePoint.X(); |
305 | myTransformPersistence.Point.y = (Standard_ShortReal)ThePoint.Y(); |
306 | myTransformPersistence.Point.z = (Standard_ShortReal)ThePoint.Z(); |
7fd59977 |
307 | |
308 | Handle(Graphic3d_Structure) aStruct; |
309 | for( Standard_Integer i = 1, n = myPresentations.Length(); i <= n; i++ ) |
310 | { |
311 | Handle(PrsMgr_Presentation3d) aPrs3d = |
312 | Handle(PrsMgr_Presentation3d)::DownCast( myPresentations(i).Presentation() ); |
313 | if ( !aPrs3d.IsNull() ) |
314 | { |
315 | aStruct = Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() ); |
316 | if( !aStruct.IsNull() ) |
317 | aStruct->SetTransformPersistence( TheFlag, ThePoint ); |
318 | } |
319 | } |
320 | } |
321 | |
322 | //======================================================================= |
323 | //function : SetTransformPersistence |
324 | //purpose : |
325 | //======================================================================= |
326 | void PrsMgr_PresentableObject::SetTransformPersistence( |
327 | const Graphic3d_TransModeFlags& TheFlag ) |
328 | { |
329 | SetTransformPersistence( TheFlag, gp_Pnt(0,0,0) ); |
330 | } |
331 | |
332 | //======================================================================= |
333 | //function : GetTransformPersistence |
334 | //purpose : |
335 | //======================================================================= |
336 | Graphic3d_TransModeFlags PrsMgr_PresentableObject::GetTransformPersistenceMode() const |
337 | { |
338 | return myTransformPersistence.Flag; |
339 | } |
340 | |
341 | //======================================================================= |
342 | //function : GetTransformPersistence |
343 | //purpose : |
344 | //======================================================================= |
345 | gp_Pnt PrsMgr_PresentableObject::GetTransformPersistencePoint() const |
346 | { |
347 | return gp_Pnt( myTransformPersistence.Point.x, myTransformPersistence.Point.y, myTransformPersistence.Point.z ); |
348 | } |
59f45b7c |
349 | |
350 | //======================================================================= |
351 | //function : SetZLayer |
352 | //purpose : |
353 | //======================================================================= |
354 | void PrsMgr_PresentableObject::SetZLayer |
355 | (const Handle(PrsMgr_PresentationManager)& thePrsMgr, |
356 | const Standard_Integer theLayerId) |
357 | { |
358 | if (!thePrsMgr.IsNull()) |
359 | thePrsMgr->SetZLayer (this, theLayerId); |
360 | } |
361 | |
362 | //======================================================================= |
363 | //function : GetZLayer |
364 | //purpose : |
365 | //======================================================================= |
366 | Standard_Integer PrsMgr_PresentableObject::GetZLayer |
367 | (const Handle(PrsMgr_PresentationManager)& thePrsMgr) const |
368 | { |
369 | if (!thePrsMgr.IsNull()) |
370 | return thePrsMgr->GetZLayer (this); |
371 | |
372 | return -1; |
373 | } |
4269bd1b |
374 | |
375 | // ======================================================================= |
376 | // function : AddClipPlane |
377 | // purpose : |
378 | // ======================================================================= |
379 | void PrsMgr_PresentableObject::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) |
380 | { |
381 | myClipPlanes.Add (thePlane); |
382 | |
383 | UpdateClipping(); // process changes |
384 | } |
385 | |
386 | // ======================================================================= |
387 | // function : RemoveClipPlane |
388 | // purpose : |
389 | // ======================================================================= |
390 | void PrsMgr_PresentableObject::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) |
391 | { |
392 | myClipPlanes.Remove (thePlane); |
393 | |
394 | UpdateClipping(); // process changes |
395 | } |
396 | |
397 | // ======================================================================= |
398 | // function : SetClipPlanes |
399 | // purpose : |
400 | // ======================================================================= |
401 | void PrsMgr_PresentableObject::SetClipPlanes (const Graphic3d_SetOfHClipPlane& thePlanes) |
402 | { |
403 | myClipPlanes = thePlanes; |
404 | |
405 | UpdateClipping(); |
406 | } |
407 | |
408 | // ======================================================================= |
409 | // function : UpdateClipping |
410 | // purpose : |
411 | // ======================================================================= |
412 | void PrsMgr_PresentableObject::UpdateClipping() |
413 | { |
414 | // affect generated structures |
415 | for (Standard_Integer aPrsIt = 1; aPrsIt <= myPresentations.Length(); ++aPrsIt) |
416 | { |
417 | // pass over presentation manager 3d mechanism right to the structures - |
418 | // we do not interested in display mode collections. |
419 | const PrsMgr_ModedPresentation& aModedPrs = myPresentations (aPrsIt); |
420 | |
421 | Handle(PrsMgr_Presentation3d) aPrs = |
422 | Handle(PrsMgr_Presentation3d)::DownCast (aModedPrs.Presentation()); |
423 | |
424 | if (aPrs.IsNull()) |
425 | continue; |
426 | |
427 | Handle(Prs3d_Presentation) aStruct3d = aPrs->Presentation(); |
428 | if (aStruct3d.IsNull()) |
429 | continue; |
430 | |
431 | aStruct3d->SetClipPlanes (myClipPlanes); |
432 | } |
433 | } |