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