b311480e |
1 | // Created on: 1997-12-16 |
2 | // Created by: Jean Louis Frenkel |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
778cd667 |
17 | #include <PrsMgr_PresentableObject.hxx> |
42cf5bc1 |
18 | |
2b886265 |
19 | #include <Graphic3d_AspectFillArea3d.hxx> |
f838dac4 |
20 | #include <Prs3d_Drawer.hxx> |
2b886265 |
21 | #include <Prs3d_LineAspect.hxx> |
22 | #include <Prs3d_PointAspect.hxx> |
42cf5bc1 |
23 | #include <Prs3d_Presentation.hxx> |
24 | #include <Prs3d_Projector.hxx> |
2b886265 |
25 | #include <Prs3d_ShadingAspect.hxx> |
7dd7c146 |
26 | #include <PrsMgr_Presentation.hxx> |
27 | #include <PrsMgr_PresentationManager.hxx> |
42cf5bc1 |
28 | #include <Standard_NotImplemented.hxx> |
7fd59977 |
29 | #include <TColStd_MapOfInteger.hxx> |
7fd59977 |
30 | |
f838dac4 |
31 | IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_PresentableObject, Standard_Transient) |
92efcf78 |
32 | |
1f7f5a90 |
33 | //======================================================================= |
34 | //function : getIdentityTrsf |
35 | //purpose : |
36 | //======================================================================= |
37 | const gp_Trsf& PrsMgr_PresentableObject::getIdentityTrsf() |
38 | { |
2b886265 |
39 | static const gp_Trsf THE_IDENTITY_TRSF; |
1f7f5a90 |
40 | return THE_IDENTITY_TRSF; |
41 | } |
42 | |
7fd59977 |
43 | //======================================================================= |
44 | //function : PrsMgr_PresentableObject |
b7cd4ba7 |
45 | //purpose : |
7fd59977 |
46 | //======================================================================= |
b7cd4ba7 |
47 | PrsMgr_PresentableObject::PrsMgr_PresentableObject (const PrsMgr_TypeOfPresentation3d theType) |
2b886265 |
48 | : myParent (NULL), |
49 | myDrawer (new Prs3d_Drawer()), |
f838dac4 |
50 | myTypeOfPresentation3d (theType), |
2b886265 |
51 | // |
52 | myCurrentFacingModel (Aspect_TOFM_BOTH_SIDE), |
53 | myOwnWidth (0.0f), |
54 | hasOwnColor (Standard_False), |
55 | hasOwnMaterial (Standard_False), |
56 | // |
57 | myInfiniteState (Standard_False), |
0717ddc1 |
58 | myIsMutable (Standard_False), |
0d56f743 |
59 | myHasOwnPresentations (Standard_True), |
60 | myToPropagateVisualState (Standard_True) |
7fd59977 |
61 | { |
f838dac4 |
62 | myDrawer->SetDisplayMode (-1); |
7fd59977 |
63 | } |
64 | |
0717ddc1 |
65 | //======================================================================= |
66 | //function : ~PrsMgr_PresentableObject |
67 | //purpose : destructor |
68 | //======================================================================= |
69 | PrsMgr_PresentableObject::~PrsMgr_PresentableObject() |
70 | { |
7dd7c146 |
71 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
72 | { |
73 | // should never happen - assertion can be used |
74 | const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.Value(); |
75 | aPrs3d->Erase(); |
76 | aPrs3d->myPresentableObject = NULL; |
77 | } |
78 | |
0717ddc1 |
79 | for (PrsMgr_ListOfPresentableObjectsIter anIter (myChildren); anIter.More(); anIter.Next()) |
80 | { |
1f7f5a90 |
81 | anIter.Value()->SetCombinedParentTransform (Handle(Geom_Transformation)()); |
0717ddc1 |
82 | anIter.Value()->myParent = NULL; |
83 | } |
84 | } |
85 | |
7fd59977 |
86 | //======================================================================= |
87 | //function : Fill |
88 | //purpose : |
89 | //======================================================================= |
af324faa |
90 | void PrsMgr_PresentableObject::Fill (const Handle(PrsMgr_PresentationManager)& thePrsMgr, |
91 | const Handle(PrsMgr_Presentation)& thePrs, |
92 | const Standard_Integer theMode) |
4269bd1b |
93 | { |
7dd7c146 |
94 | const Handle(Prs3d_Presentation)& aStruct3d = thePrs; |
af324faa |
95 | Compute (thePrsMgr, aStruct3d, theMode); |
1b63268e |
96 | aStruct3d->SetTransformation (myTransformation); |
af324faa |
97 | aStruct3d->SetClipPlanes (myClipPlanes); |
778cd667 |
98 | aStruct3d->SetTransformPersistence (TransformPersistence()); |
7fd59977 |
99 | } |
100 | |
7fd59977 |
101 | //======================================================================= |
102 | //function : Compute |
103 | //purpose : |
104 | //======================================================================= |
105 | void PrsMgr_PresentableObject::Compute(const Handle(Prs3d_Projector)& /*aProjector*/, |
106 | const Handle(Prs3d_Presentation)& /*aPresentation*/) |
107 | { |
9775fa61 |
108 | throw Standard_NotImplemented("cannot compute under a specific projector"); |
7fd59977 |
109 | } |
4269bd1b |
110 | |
7fd59977 |
111 | //======================================================================= |
112 | //function : Compute |
113 | //purpose : |
114 | //======================================================================= |
115 | void PrsMgr_PresentableObject::Compute(const Handle(Prs3d_Projector)& /* aProjector*/, |
116 | const Handle(Geom_Transformation)& /*aTrsf*/, |
117 | const Handle(Prs3d_Presentation)& /*aPresentation*/) |
118 | { |
9775fa61 |
119 | throw Standard_NotImplemented("cannot compute under a specific projector"); |
7fd59977 |
120 | } |
121 | |
122 | //======================================================================= |
226fce20 |
123 | //function : ToBeUpdated |
124 | //purpose : |
7fd59977 |
125 | //======================================================================= |
226fce20 |
126 | Standard_Boolean PrsMgr_PresentableObject::ToBeUpdated (Standard_Boolean theToIncludeHidden) const |
127 | { |
128 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
129 | { |
7dd7c146 |
130 | const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value(); |
131 | if (aModedPrs->MustBeUpdated()) |
226fce20 |
132 | { |
133 | if (theToIncludeHidden) |
134 | { |
135 | return Standard_True; |
136 | } |
137 | |
7dd7c146 |
138 | Handle(PrsMgr_PresentationManager) aPrsMgr = aModedPrs->PresentationManager(); |
139 | if (aPrsMgr->IsDisplayed (this, aModedPrs->Mode()) |
140 | || aPrsMgr->IsHighlighted(this, aModedPrs->Mode())) |
226fce20 |
141 | { |
142 | return Standard_True; |
7fd59977 |
143 | } |
7fd59977 |
144 | } |
145 | } |
226fce20 |
146 | return Standard_False; |
7fd59977 |
147 | } |
4269bd1b |
148 | |
7fd59977 |
149 | //======================================================================= |
226fce20 |
150 | //function : UpdatePresentations |
151 | //purpose : |
7fd59977 |
152 | //======================================================================= |
226fce20 |
153 | Standard_Boolean PrsMgr_PresentableObject::UpdatePresentations (Standard_Boolean theToIncludeHidden) |
154 | { |
155 | Standard_Boolean hasUpdates = Standard_False; |
156 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
157 | { |
7dd7c146 |
158 | const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value(); |
159 | if (aModedPrs->MustBeUpdated()) |
226fce20 |
160 | { |
7dd7c146 |
161 | Handle(PrsMgr_PresentationManager) aPrsMgr = aModedPrs->PresentationManager(); |
226fce20 |
162 | if (theToIncludeHidden |
7dd7c146 |
163 | || aPrsMgr->IsDisplayed (this, aModedPrs->Mode()) |
164 | || aPrsMgr->IsHighlighted(this, aModedPrs->Mode())) |
226fce20 |
165 | { |
166 | hasUpdates = Standard_True; |
7dd7c146 |
167 | aPrsMgr->Update (this, aModedPrs->Mode()); |
226fce20 |
168 | } |
7fd59977 |
169 | } |
170 | } |
226fce20 |
171 | return hasUpdates; |
7fd59977 |
172 | } |
4269bd1b |
173 | |
7fd59977 |
174 | //======================================================================= |
226fce20 |
175 | //function : Update |
176 | //purpose : |
7fd59977 |
177 | //======================================================================= |
226fce20 |
178 | void PrsMgr_PresentableObject::Update (Standard_Integer theMode, Standard_Boolean theToClearOther) |
7fd59977 |
179 | { |
226fce20 |
180 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More();) |
181 | { |
7dd7c146 |
182 | if (aPrsIter.Value()->Mode() == theMode) |
226fce20 |
183 | { |
7dd7c146 |
184 | Handle(PrsMgr_PresentationManager) aPrsMgr = aPrsIter.Value()->PresentationManager(); |
226fce20 |
185 | if (aPrsMgr->IsDisplayed (this, theMode) |
186 | || aPrsMgr->IsHighlighted(this, theMode)) |
187 | { |
188 | aPrsMgr->Update (this, theMode); |
7dd7c146 |
189 | aPrsIter.Value()->SetUpdateStatus (Standard_False); |
226fce20 |
190 | } |
191 | else |
192 | { |
7dd7c146 |
193 | SetToUpdate (aPrsIter.Value()->Mode()); |
226fce20 |
194 | } |
195 | } |
196 | else if (theToClearOther) |
197 | { |
198 | myPresentations.Remove (aPrsIter); |
199 | continue; |
200 | } |
201 | aPrsIter.Next(); |
7fd59977 |
202 | } |
203 | } |
4269bd1b |
204 | |
205 | //======================================================================= |
206 | //function : SetToUpdate |
226fce20 |
207 | //purpose : |
4269bd1b |
208 | //======================================================================= |
226fce20 |
209 | void PrsMgr_PresentableObject::SetToUpdate (Standard_Integer theMode) |
7fd59977 |
210 | { |
226fce20 |
211 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
212 | { |
213 | if (theMode == -1 |
7dd7c146 |
214 | || aPrsIter.Value()->Mode() == theMode) |
226fce20 |
215 | { |
7dd7c146 |
216 | aPrsIter.ChangeValue()->SetUpdateStatus (Standard_True); |
226fce20 |
217 | } |
7fd59977 |
218 | } |
219 | } |
220 | |
221 | //======================================================================= |
222 | //function : ToBeUpdated |
223 | //purpose : gets the list of modes to be updated |
224 | //======================================================================= |
226fce20 |
225 | void PrsMgr_PresentableObject::ToBeUpdated (TColStd_ListOfInteger& theOutList) const |
7fd59977 |
226 | { |
226fce20 |
227 | theOutList.Clear(); |
016e5959 |
228 | TColStd_MapOfInteger MI(myPresentations.Length()); |
226fce20 |
229 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
230 | { |
7dd7c146 |
231 | const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value(); |
232 | if (aModedPrs->MustBeUpdated() |
233 | && MI.Add (aModedPrs->Mode())) |
226fce20 |
234 | { |
7dd7c146 |
235 | theOutList.Append (aModedPrs->Mode()); |
226fce20 |
236 | } |
7fd59977 |
237 | } |
7fd59977 |
238 | } |
239 | |
240 | //======================================================================= |
241 | //function : SetTypeOfPresentation |
af324faa |
242 | //purpose : |
7fd59977 |
243 | //======================================================================= |
af324faa |
244 | void PrsMgr_PresentableObject::SetTypeOfPresentation (const PrsMgr_TypeOfPresentation3d theType) |
7fd59977 |
245 | { |
af324faa |
246 | myTypeOfPresentation3d = theType; |
226fce20 |
247 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
af324faa |
248 | { |
7dd7c146 |
249 | const Handle(PrsMgr_Presentation)& aPrs = aPrsIter.Value(); |
250 | aPrs->SetVisual (myTypeOfPresentation3d == PrsMgr_TOP_ProjectorDependant |
251 | ? Graphic3d_TOS_COMPUTED |
252 | : Graphic3d_TOS_ALL); |
7fd59977 |
253 | } |
254 | } |
255 | |
256 | //======================================================================= |
1f7f5a90 |
257 | //function : setLocalTransformation |
258 | //purpose : |
7fd59977 |
259 | //======================================================================= |
1f7f5a90 |
260 | void PrsMgr_PresentableObject::setLocalTransformation (const Handle(Geom_Transformation)& theTransformation) |
7fd59977 |
261 | { |
0717ddc1 |
262 | myLocalTransformation = theTransformation; |
263 | UpdateTransformation(); |
7fd59977 |
264 | } |
265 | |
266 | //======================================================================= |
0717ddc1 |
267 | //function : ResetTransformation |
7fd59977 |
268 | //purpose : |
269 | //======================================================================= |
0717ddc1 |
270 | void PrsMgr_PresentableObject::ResetTransformation() |
7fd59977 |
271 | { |
1f7f5a90 |
272 | setLocalTransformation (Handle(Geom_Transformation)()); |
7fd59977 |
273 | } |
274 | |
4269bd1b |
275 | //======================================================================= |
0717ddc1 |
276 | //function : SetCombinedParentTransform |
277 | //purpose : |
278 | //======================================================================= |
1f7f5a90 |
279 | void PrsMgr_PresentableObject::SetCombinedParentTransform (const Handle(Geom_Transformation)& theTrsf) |
0717ddc1 |
280 | { |
1f7f5a90 |
281 | myCombinedParentTransform = theTrsf; |
0717ddc1 |
282 | UpdateTransformation(); |
283 | } |
284 | |
285 | //======================================================================= |
286 | //function : UpdateTransformation |
4269bd1b |
287 | //purpose : |
288 | //======================================================================= |
0717ddc1 |
289 | void PrsMgr_PresentableObject::UpdateTransformation() |
7fd59977 |
290 | { |
1f7f5a90 |
291 | myTransformation.Nullify(); |
292 | myInvTransformation = gp_Trsf(); |
293 | if (!myCombinedParentTransform.IsNull() && myCombinedParentTransform->Form() != gp_Identity) |
294 | { |
295 | if (!myLocalTransformation.IsNull() && myLocalTransformation->Form() != gp_Identity) |
296 | { |
297 | const gp_Trsf aTrsf = myCombinedParentTransform->Trsf() * myLocalTransformation->Trsf(); |
298 | myTransformation = new Geom_Transformation (aTrsf); |
299 | myInvTransformation = aTrsf.Inverted(); |
300 | } |
301 | else |
302 | { |
303 | myTransformation = myCombinedParentTransform; |
304 | myInvTransformation = myCombinedParentTransform->Trsf().Inverted(); |
305 | } |
306 | } |
307 | else if (!myLocalTransformation.IsNull() && myLocalTransformation->Form() != gp_Identity) |
308 | { |
309 | myTransformation = myLocalTransformation; |
310 | myInvTransformation = myLocalTransformation->Trsf().Inverted(); |
311 | } |
af324faa |
312 | |
226fce20 |
313 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
af324faa |
314 | { |
7dd7c146 |
315 | aPrsIter.ChangeValue()->SetTransformation (myTransformation); |
af324faa |
316 | } |
317 | |
1f7f5a90 |
318 | for (PrsMgr_ListOfPresentableObjectsIter aChildIter (myChildren); aChildIter.More(); aChildIter.Next()) |
af324faa |
319 | { |
1f7f5a90 |
320 | aChildIter.Value()->SetCombinedParentTransform (myTransformation); |
7fd59977 |
321 | } |
322 | } |
323 | |
bf5f0ca2 |
324 | //======================================================================= |
325 | //function : recomputeComputed |
326 | //purpose : |
327 | //======================================================================= |
328 | void PrsMgr_PresentableObject::recomputeComputed() const |
329 | { |
226fce20 |
330 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
bf5f0ca2 |
331 | { |
7dd7c146 |
332 | const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.Value(); |
333 | aPrs3d->ReCompute(); |
bf5f0ca2 |
334 | } |
335 | } |
336 | |
7fd59977 |
337 | //======================================================================= |
338 | //function : SetTransformPersistence |
af324faa |
339 | //purpose : |
7fd59977 |
340 | //======================================================================= |
778cd667 |
341 | void PrsMgr_PresentableObject::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) |
7fd59977 |
342 | { |
778cd667 |
343 | myTransformPersistence = theTrsfPers; |
226fce20 |
344 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
af324faa |
345 | { |
7dd7c146 |
346 | const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.Value(); |
347 | aPrs3d->SetTransformPersistence (myTransformPersistence); |
348 | aPrs3d->ReCompute(); |
af324faa |
349 | } |
7fd59977 |
350 | } |
351 | |
7fd59977 |
352 | //======================================================================= |
353 | //function : GetTransformPersistence |
778cd667 |
354 | //purpose : |
7fd59977 |
355 | //======================================================================= |
825aa485 |
356 | gp_Pnt PrsMgr_PresentableObject::GetTransformPersistencePoint() const |
7fd59977 |
357 | { |
778cd667 |
358 | if (myTransformPersistence.IsNull()) |
359 | { |
360 | return gp_Pnt(); |
361 | } |
362 | else if (myTransformPersistence->IsZoomOrRotate()) |
363 | { |
364 | return myTransformPersistence->AnchorPoint(); |
365 | } |
366 | else if (!myTransformPersistence->IsTrihedronOr2d()) |
367 | { |
368 | return gp_Pnt(); |
369 | } |
370 | |
371 | Standard_Real anX = 0.0; |
372 | if ((myTransformPersistence->Corner2d() & Aspect_TOTP_RIGHT) != 0) |
373 | { |
374 | anX = 1.0; |
375 | } |
376 | else if ((myTransformPersistence->Corner2d() & Aspect_TOTP_LEFT) != 0) |
377 | { |
378 | anX = -1.0; |
379 | } |
380 | |
381 | Standard_Real anY = 0.0; |
382 | if ((myTransformPersistence->Corner2d() & Aspect_TOTP_TOP) != 0) |
383 | { |
384 | anY = 1.0; |
385 | } |
386 | else if ((myTransformPersistence->Corner2d() & Aspect_TOTP_BOTTOM) != 0) |
387 | { |
388 | anY = -1.0; |
389 | } |
390 | |
391 | return gp_Pnt (anX, anY, myTransformPersistence->Offset2d().x()); |
7fd59977 |
392 | } |
59f45b7c |
393 | |
0717ddc1 |
394 | //======================================================================= |
395 | //function : AddChild |
396 | //purpose : |
397 | //======================================================================= |
398 | void PrsMgr_PresentableObject::AddChild (const Handle(PrsMgr_PresentableObject)& theObject) |
399 | { |
400 | Handle(PrsMgr_PresentableObject) aHandleGuard = theObject; |
401 | if (theObject->myParent != NULL) |
402 | { |
403 | theObject->myParent->RemoveChild (aHandleGuard); |
404 | } |
405 | |
406 | myChildren.Append (theObject); |
407 | theObject->myParent = this; |
408 | theObject->SetCombinedParentTransform (myTransformation); |
409 | } |
410 | |
52c38ce1 |
411 | //======================================================================= |
412 | //function : AddChildWithCurrentTransformation |
413 | //purpose : |
414 | //======================================================================= |
415 | void PrsMgr_PresentableObject::AddChildWithCurrentTransformation(const Handle(PrsMgr_PresentableObject)& theObject) |
416 | { |
417 | gp_Trsf aTrsf = Transformation().Inverted() * theObject->Transformation(); |
418 | theObject->SetLocalTransformation(aTrsf); |
419 | AddChild(theObject); |
420 | } |
421 | |
0717ddc1 |
422 | //======================================================================= |
423 | //function : RemoveChild |
424 | //purpose : |
425 | //======================================================================= |
426 | void PrsMgr_PresentableObject::RemoveChild (const Handle(PrsMgr_PresentableObject)& theObject) |
427 | { |
428 | PrsMgr_ListOfPresentableObjectsIter anIter (myChildren); |
429 | for (; anIter.More(); anIter.Next()) |
430 | { |
431 | if (anIter.Value() == theObject) |
432 | { |
433 | theObject->myParent = NULL; |
1f7f5a90 |
434 | theObject->SetCombinedParentTransform (Handle(Geom_Transformation)()); |
0717ddc1 |
435 | myChildren.Remove (anIter); |
436 | break; |
437 | } |
438 | } |
439 | } |
440 | |
52c38ce1 |
441 | //======================================================================= |
442 | //function : RemoveChildWithRestoreTransformation |
443 | //purpose : |
444 | //======================================================================= |
445 | void PrsMgr_PresentableObject::RemoveChildWithRestoreTransformation(const Handle(PrsMgr_PresentableObject)& theObject) |
446 | { |
447 | gp_Trsf aTrsf = theObject->Transformation(); |
448 | RemoveChild(theObject); |
449 | theObject->SetLocalTransformation(aTrsf); |
450 | } |
451 | |
59f45b7c |
452 | //======================================================================= |
453 | //function : SetZLayer |
454 | //purpose : |
455 | //======================================================================= |
a1954302 |
456 | void PrsMgr_PresentableObject::SetZLayer (const Graphic3d_ZLayerId theLayerId) |
59f45b7c |
457 | { |
f838dac4 |
458 | if (myDrawer->ZLayer() == theLayerId) |
a1954302 |
459 | { |
460 | return; |
461 | } |
462 | |
f838dac4 |
463 | myDrawer->SetZLayer (theLayerId); |
226fce20 |
464 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
a1954302 |
465 | { |
7dd7c146 |
466 | const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value(); |
467 | aModedPrs->SetZLayer (theLayerId); |
a1954302 |
468 | } |
59f45b7c |
469 | } |
470 | |
4269bd1b |
471 | // ======================================================================= |
472 | // function : AddClipPlane |
473 | // purpose : |
474 | // ======================================================================= |
475 | void PrsMgr_PresentableObject::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) |
476 | { |
51b10cd4 |
477 | // add to collection and process changes |
3202bf1e |
478 | if (myClipPlanes.IsNull()) |
479 | { |
480 | myClipPlanes = new Graphic3d_SequenceOfHClipPlane(); |
481 | } |
482 | |
483 | myClipPlanes->Append (thePlane); |
51b10cd4 |
484 | UpdateClipping(); |
4269bd1b |
485 | } |
486 | |
487 | // ======================================================================= |
488 | // function : RemoveClipPlane |
489 | // purpose : |
490 | // ======================================================================= |
491 | void PrsMgr_PresentableObject::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) |
492 | { |
3202bf1e |
493 | if (myClipPlanes.IsNull()) |
494 | { |
495 | return; |
496 | } |
497 | |
51b10cd4 |
498 | // remove from collection and process changes |
3202bf1e |
499 | for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*myClipPlanes); aPlaneIt.More(); aPlaneIt.Next()) |
51b10cd4 |
500 | { |
501 | const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value(); |
502 | if (aPlane != thePlane) |
503 | continue; |
4269bd1b |
504 | |
3202bf1e |
505 | myClipPlanes->Remove (aPlaneIt); |
51b10cd4 |
506 | UpdateClipping(); |
507 | return; |
508 | } |
4269bd1b |
509 | } |
510 | |
511 | // ======================================================================= |
512 | // function : SetClipPlanes |
513 | // purpose : |
514 | // ======================================================================= |
3202bf1e |
515 | void PrsMgr_PresentableObject::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) |
4269bd1b |
516 | { |
51b10cd4 |
517 | // change collection and process changes |
4269bd1b |
518 | myClipPlanes = thePlanes; |
4269bd1b |
519 | UpdateClipping(); |
520 | } |
521 | |
522 | // ======================================================================= |
523 | // function : UpdateClipping |
524 | // purpose : |
525 | // ======================================================================= |
526 | void PrsMgr_PresentableObject::UpdateClipping() |
527 | { |
226fce20 |
528 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
4269bd1b |
529 | { |
7dd7c146 |
530 | const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value(); |
531 | aModedPrs->SetClipPlanes (myClipPlanes); |
4269bd1b |
532 | } |
533 | } |
b7cd4ba7 |
534 | |
2b886265 |
535 | //======================================================================= |
536 | //function : SetInfiniteState |
537 | //purpose : |
538 | //======================================================================= |
539 | void PrsMgr_PresentableObject::SetInfiniteState (const Standard_Boolean theFlag) |
540 | { |
541 | if (myInfiniteState == theFlag) |
542 | { |
543 | return; |
544 | } |
545 | |
546 | myInfiniteState = theFlag; |
547 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
548 | { |
7dd7c146 |
549 | const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value(); |
550 | aModedPrs->SetInfiniteState (theFlag); |
2b886265 |
551 | } |
552 | } |
553 | |
b7cd4ba7 |
554 | // ======================================================================= |
555 | // function : SetMutable |
556 | // purpose : |
557 | // ======================================================================= |
558 | void PrsMgr_PresentableObject::SetMutable (const Standard_Boolean theIsMutable) |
559 | { |
560 | if (myIsMutable == theIsMutable) |
561 | { |
562 | return; |
563 | } |
564 | |
565 | myIsMutable = theIsMutable; |
226fce20 |
566 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
b7cd4ba7 |
567 | { |
7dd7c146 |
568 | const Handle(PrsMgr_Presentation)& aModedPrs = aPrsIter.Value(); |
569 | aModedPrs->SetMutable (theIsMutable); |
b7cd4ba7 |
570 | } |
571 | } |
f838dac4 |
572 | |
f838dac4 |
573 | // ======================================================================= |
574 | // function : UnsetAttributes |
575 | // purpose : |
576 | // ======================================================================= |
577 | void PrsMgr_PresentableObject::UnsetAttributes() |
578 | { |
579 | Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer(); |
580 | if (myDrawer->HasLink()) |
581 | { |
582 | aDrawer->Link(myDrawer->Link()); |
583 | } |
584 | myDrawer = aDrawer; |
2b886265 |
585 | |
586 | hasOwnColor = Standard_False; |
587 | hasOwnMaterial = Standard_False; |
588 | myOwnWidth = 0.0f; |
589 | myDrawer->SetTransparency (0.0f); |
590 | } |
591 | |
592 | //======================================================================= |
593 | //function : SetHilightMode |
594 | //purpose : |
595 | //======================================================================= |
596 | void PrsMgr_PresentableObject::SetHilightMode (const Standard_Integer theMode) |
597 | { |
598 | if (myHilightDrawer.IsNull()) |
599 | { |
600 | myHilightDrawer = new Prs3d_Drawer(); |
601 | myHilightDrawer->Link (myDrawer); |
602 | myHilightDrawer->SetAutoTriangulation (Standard_False); |
603 | myHilightDrawer->SetColor (Quantity_NOC_GRAY80); |
604 | myHilightDrawer->SetZLayer(Graphic3d_ZLayerId_UNKNOWN); |
605 | } |
606 | if (myDynHilightDrawer.IsNull()) |
607 | { |
608 | myDynHilightDrawer = new Prs3d_Drawer(); |
609 | myDynHilightDrawer->Link (myDrawer); |
610 | myDynHilightDrawer->SetColor (Quantity_NOC_CYAN1); |
611 | myDynHilightDrawer->SetAutoTriangulation (Standard_False); |
612 | myDynHilightDrawer->SetZLayer(Graphic3d_ZLayerId_Top); |
613 | } |
614 | myHilightDrawer ->SetDisplayMode (theMode); |
615 | myDynHilightDrawer->SetDisplayMode (theMode); |
616 | } |
617 | |
618 | //======================================================================= |
619 | //function : SynchronizeAspects |
620 | //purpose : |
621 | //======================================================================= |
622 | void PrsMgr_PresentableObject::SynchronizeAspects() |
623 | { |
624 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
625 | { |
7dd7c146 |
626 | const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue(); |
627 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPrs3d->Groups()); aGroupIter.More(); aGroupIter.Next()) |
2b886265 |
628 | { |
629 | if (!aGroupIter.Value().IsNull()) |
630 | { |
631 | aGroupIter.ChangeValue()->SynchronizeAspects(); |
632 | } |
633 | } |
634 | } |
635 | } |
636 | |
637 | //======================================================================= |
638 | //function : replaceAspects |
639 | //purpose : |
640 | //======================================================================= |
641 | void PrsMgr_PresentableObject::replaceAspects (const Graphic3d_MapOfAspectsToAspects& theMap) |
642 | { |
643 | if (theMap.IsEmpty()) |
644 | { |
645 | return; |
646 | } |
647 | |
648 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
649 | { |
7dd7c146 |
650 | const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue(); |
651 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPrs3d->Groups()); aGroupIter.More(); aGroupIter.Next()) |
2b886265 |
652 | { |
653 | if (!aGroupIter.Value().IsNull()) |
654 | { |
655 | aGroupIter.ChangeValue()->ReplaceAspects (theMap); |
656 | } |
657 | } |
658 | } |
659 | } |
660 | |
661 | //======================================================================= |
662 | //function : BoundingBox |
663 | //purpose : |
664 | //======================================================================= |
665 | void PrsMgr_PresentableObject::BoundingBox (Bnd_Box& theBndBox) |
666 | { |
667 | if (myDrawer->DisplayMode() == -1) |
668 | { |
669 | if (!myPresentations.IsEmpty()) |
670 | { |
7dd7c146 |
671 | const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations.First(); |
672 | const Graphic3d_BndBox3d& aBndBox = aPrs3d->CStructure()->BoundingBox(); |
2b886265 |
673 | if (aBndBox.IsValid()) |
674 | { |
675 | theBndBox.Update (aBndBox.CornerMin().x(), aBndBox.CornerMin().y(), aBndBox.CornerMin().z(), |
676 | aBndBox.CornerMax().x(), aBndBox.CornerMax().y(), aBndBox.CornerMax().z()); |
677 | } |
678 | else |
679 | { |
680 | theBndBox.SetVoid(); |
681 | } |
682 | return; |
683 | } |
684 | |
685 | for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (myChildren); aPrsIter.More(); aPrsIter.Next()) |
686 | { |
687 | if (const Handle(PrsMgr_PresentableObject)& aChild = aPrsIter.Value()) |
688 | { |
689 | Bnd_Box aBox; |
690 | aChild->BoundingBox (aBox); |
691 | theBndBox.Add (aBox); |
692 | } |
693 | } |
694 | return; |
695 | } |
696 | |
7dd7c146 |
697 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
2b886265 |
698 | { |
7dd7c146 |
699 | const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue(); |
700 | if (aPrs3d->Mode() == myDrawer->DisplayMode()) |
2b886265 |
701 | { |
7dd7c146 |
702 | const Graphic3d_BndBox3d& aBndBox = aPrs3d->CStructure()->BoundingBox(); |
2b886265 |
703 | if (aBndBox.IsValid()) |
704 | { |
705 | theBndBox.Update (aBndBox.CornerMin().x(), aBndBox.CornerMin().y(), aBndBox.CornerMin().z(), |
706 | aBndBox.CornerMax().x(), aBndBox.CornerMax().y(), aBndBox.CornerMax().z()); |
707 | } |
708 | else |
709 | { |
710 | theBndBox.SetVoid(); |
711 | } |
712 | return; |
713 | } |
714 | } |
715 | } |
716 | |
717 | //======================================================================= |
718 | //function : Material |
719 | //purpose : |
720 | //======================================================================= |
721 | Graphic3d_NameOfMaterial PrsMgr_PresentableObject::Material() const |
722 | { |
723 | return myDrawer->ShadingAspect()->Material().Name(); |
724 | } |
725 | |
726 | //======================================================================= |
727 | //function : SetMaterial |
728 | //purpose : |
729 | //======================================================================= |
730 | void PrsMgr_PresentableObject::SetMaterial (const Graphic3d_MaterialAspect& theMaterial) |
731 | { |
732 | myDrawer->SetupOwnShadingAspect(); |
733 | myDrawer->ShadingAspect()->SetMaterial (theMaterial); |
734 | hasOwnMaterial = Standard_True; |
735 | } |
736 | |
737 | //======================================================================= |
738 | //function : UnsetMaterial |
739 | //purpose : |
740 | //======================================================================= |
741 | void PrsMgr_PresentableObject::UnsetMaterial() |
742 | { |
743 | if (!HasMaterial()) |
744 | { |
745 | return; |
746 | } |
747 | |
748 | if (HasColor() || IsTransparent()) |
749 | { |
750 | if (myDrawer->HasLink()) |
751 | { |
752 | myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Aspect()->BackMaterial()); |
753 | } |
754 | |
755 | if (HasColor()) |
756 | { |
757 | SetColor (myDrawer->Color()); |
758 | } |
759 | |
760 | if (IsTransparent()) |
761 | { |
762 | SetTransparency (myDrawer->Transparency()); |
763 | } |
764 | } |
765 | else |
766 | { |
767 | myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); |
768 | } |
769 | |
770 | hasOwnMaterial = Standard_False; |
771 | } |
772 | |
773 | //======================================================================= |
774 | //function : SetTransparency |
775 | //purpose : |
776 | //======================================================================= |
777 | void PrsMgr_PresentableObject::SetTransparency (const Standard_Real theValue) |
778 | { |
779 | myDrawer->SetupOwnShadingAspect(); |
780 | myDrawer->ShadingAspect()->Aspect()->ChangeFrontMaterial().SetTransparency (Standard_ShortReal(theValue)); |
781 | myDrawer->ShadingAspect()->Aspect()->ChangeBackMaterial() .SetTransparency (Standard_ShortReal(theValue)); |
782 | myDrawer->SetTransparency (Standard_ShortReal(theValue)); |
783 | } |
784 | |
785 | //======================================================================= |
786 | //function : UnsetTransparency |
787 | //purpose : |
788 | //======================================================================= |
789 | void PrsMgr_PresentableObject::UnsetTransparency() |
790 | { |
791 | if (HasColor() || HasMaterial()) |
792 | { |
793 | myDrawer->ShadingAspect()->Aspect()->ChangeFrontMaterial().SetTransparency (0.0f); |
794 | myDrawer->ShadingAspect()->Aspect()->ChangeBackMaterial() .SetTransparency (0.0f); |
795 | } |
796 | else |
797 | { |
798 | myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)()); |
799 | } |
800 | myDrawer->SetTransparency (0.0f); |
801 | } |
802 | |
803 | //======================================================================= |
804 | //function : SetPolygonOffsets |
805 | //purpose : |
806 | //======================================================================= |
807 | void PrsMgr_PresentableObject::SetPolygonOffsets (const Standard_Integer theMode, |
808 | const Standard_ShortReal theFactor, |
809 | const Standard_ShortReal theUnits) |
810 | { |
811 | myDrawer->SetupOwnShadingAspect(); |
812 | myDrawer->ShadingAspect()->Aspect()->SetPolygonOffsets (theMode, theFactor, theUnits); |
813 | SynchronizeAspects(); |
814 | } |
815 | |
816 | //======================================================================= |
817 | //function : HasPolygonOffsets |
818 | //purpose : |
819 | //======================================================================= |
820 | Standard_Boolean PrsMgr_PresentableObject::HasPolygonOffsets() const |
821 | { |
822 | return !(myDrawer->HasOwnShadingAspect() |
823 | || (myDrawer->HasLink() |
824 | && myDrawer->ShadingAspect() == myDrawer->Link()->ShadingAspect())); |
825 | } |
826 | |
827 | //======================================================================= |
828 | //function : PolygonOffsets |
829 | //purpose : |
830 | //======================================================================= |
831 | void PrsMgr_PresentableObject::PolygonOffsets (Standard_Integer& theMode, |
832 | Standard_ShortReal& theFactor, |
833 | Standard_ShortReal& theUnits) const |
834 | { |
835 | if (HasPolygonOffsets()) |
836 | { |
837 | myDrawer->ShadingAspect()->Aspect()->PolygonOffsets (theMode, theFactor, theUnits); |
838 | } |
f838dac4 |
839 | } |