1 // Created on: 1996-12-20
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <AIS_Shape.hxx>
19 #include <AIS_GraphicTool.hxx>
20 #include <AIS_InteractiveContext.hxx>
21 #include <Aspect_TypeOfLine.hxx>
22 #include <BRep_Builder.hxx>
23 #include <BRepBndLib.hxx>
24 #include <BRepTools.hxx>
25 #include <BRepTools_ShapeSet.hxx>
26 #include <Geom_Transformation.hxx>
28 #include <Graphic3d_ArrayOfPolylines.hxx>
29 #include <Graphic3d_AspectFillArea3d.hxx>
30 #include <Graphic3d_AspectLine3d.hxx>
31 #include <Graphic3d_AspectMarker3d.hxx>
32 #include <Graphic3d_AspectText3d.hxx>
33 #include <Graphic3d_Group.hxx>
34 #include <Graphic3d_MaterialAspect.hxx>
35 #include <Graphic3d_SequenceOfGroup.hxx>
36 #include <Graphic3d_Structure.hxx>
37 #include <Message.hxx>
38 #include <Message_Messenger.hxx>
39 #include <HLRBRep.hxx>
40 #include <OSD_Timer.hxx>
41 #include <Precision.hxx>
43 #include <Prs3d_Drawer.hxx>
44 #include <Prs3d_IsoAspect.hxx>
45 #include <Prs3d_Presentation.hxx>
46 #include <Prs3d_Root.hxx>
47 #include <Prs3d_ShadingAspect.hxx>
48 #include <StdPrs_BndBox.hxx>
49 #include <StdPrs_ToolTriangulatedShape.hxx>
50 #include <Quantity_Color.hxx>
51 #include <Select3D_SensitiveBox.hxx>
52 #include <Select3D_SensitiveEntity.hxx>
53 #include <Standard_ErrorHandler.hxx>
54 #include <Standard_Failure.hxx>
55 #include <Standard_Type.hxx>
56 #include <StdPrs_HLRPolyShape.hxx>
57 #include <StdPrs_HLRShape.hxx>
58 #include <StdPrs_ShadedShape.hxx>
59 #include <StdPrs_WFShape.hxx>
60 #include <StdSelect.hxx>
61 #include <StdSelect_BRepOwner.hxx>
62 #include <StdSelect_BRepSelectionTool.hxx>
63 #include <StdSelect_DisplayMode.hxx>
64 #include <TColStd_ListIteratorOfListOfInteger.hxx>
67 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
70 #define replaceAspectWithDef(theMap, theAspect) \
71 if (myDrawer->Link()->theAspect()->Aspect() != myDrawer->theAspect()->Aspect()) \
73 theMap.Bind (myDrawer->theAspect()->Aspect(), myDrawer->Link()->theAspect()->Aspect()); \
76 // Auxiliary macros for replaceWithNewOwnAspects()
77 #define replaceAspectWithOwn(theMap, theAspect) \
78 if (myDrawer->Link()->theAspect()->Aspect() != myDrawer->theAspect()->Aspect()) \
80 theMap.Bind (myDrawer->Link()->theAspect()->Aspect(), myDrawer->theAspect()->Aspect()); \
83 //=======================================================================
84 //function : replaceWithNewOwnAspects
86 //=======================================================================
87 void AIS_Shape::replaceWithNewOwnAspects()
89 Graphic3d_MapOfAspectsToAspects aReplaceMap;
91 replaceAspectWithOwn (aReplaceMap, ShadingAspect);
92 replaceAspectWithOwn (aReplaceMap, LineAspect);
93 replaceAspectWithOwn (aReplaceMap, WireAspect);
94 replaceAspectWithOwn (aReplaceMap, FreeBoundaryAspect);
95 replaceAspectWithOwn (aReplaceMap, UnFreeBoundaryAspect);
96 replaceAspectWithOwn (aReplaceMap, SeenLineAspect);
97 replaceAspectWithOwn (aReplaceMap, FaceBoundaryAspect);
98 replaceAspectWithOwn (aReplaceMap, PointAspect);
100 replaceAspects (aReplaceMap);
103 //==================================================
104 // Function: AIS_Shape
106 //==================================================
107 AIS_Shape::AIS_Shape(const TopoDS_Shape& theShape)
108 : AIS_InteractiveObject (PrsMgr_TOP_ProjectorDependant),
110 myUVOrigin(0.0, 0.0),
111 myUVRepeat(1.0, 1.0),
112 myUVScale (1.0, 1.0),
114 myCompBB (Standard_True)
119 //=======================================================================
122 //=======================================================================
123 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
124 const Handle(Prs3d_Presentation)& aPrs,
125 const Standard_Integer theMode)
127 if(myshape.IsNull()) return;
129 // wire,edge,vertex -> pas de HLR + priorite display superieure
130 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
131 if(TheType>4 && TheType<8) {
132 aPrs->SetVisual(Graphic3d_TOS_ALL);
133 aPrs->SetDisplayPriority(TheType+2);
135 // Shape vide -> Assemblage vide.
136 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
143 aPrs->SetInfiniteState (Standard_True); //not taken in account during FITALL
150 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
154 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
156 catch (Standard_Failure const& anException)
158 Message::DefaultMessenger()->Send (TCollection_AsciiString()
159 + "Error: AIS_Shape::Compute() wireframe presentation builder has failed ("
160 + anException.GetMessageString() + ")", Message_Fail);
166 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
167 if ((Standard_Integer) myshape.ShapeType() > 4)
169 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
175 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
182 StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer,
183 myDrawer->ShadingAspect()->Aspect()->ToMapTexture()
184 && !myDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
185 myUVOrigin, myUVRepeat, myUVScale);
187 catch (Standard_Failure const& anException)
189 Message::DefaultMessenger()->Send (TCollection_AsciiString()
190 + "Error: AIS_Shape::Compute() shaded presentation builder has failed ("
191 + anException.GetMessageString() + ")", Message_Fail);
192 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
196 Standard_Real aTransparency = Transparency() ;
197 if (aTransparency > 0.0)
199 SetTransparency (aTransparency);
209 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
213 StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
218 // Recompute hidden line presentation (if necessary).
222 //=======================================================================
223 //function : computeHlrPresentation
225 //=======================================================================
226 void AIS_Shape::computeHlrPresentation (const Handle(Graphic3d_Camera)& theProjector,
227 const Handle(Prs3d_Presentation)& thePrs,
228 const TopoDS_Shape& theShape,
229 const Handle(Prs3d_Drawer)& theDrawer)
231 if (theShape.IsNull())
236 switch (theShape.ShapeType())
242 thePrs->SetDisplayPriority (4);
243 StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
246 case TopAbs_COMPOUND:
248 if (theShape.NbChildren() == 0)
260 const Handle(Prs3d_Drawer)& aDefDrawer = theDrawer->Link();
261 if (aDefDrawer->DrawHiddenLine())
263 theDrawer->EnableDrawHiddenLine();
267 theDrawer->DisableDrawHiddenLine();
270 const Aspect_TypeOfDeflection aPrevDef = aDefDrawer->TypeOfDeflection();
271 aDefDrawer->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
272 if (theDrawer->IsAutoTriangulation())
274 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (theShape, theDrawer, Standard_True);
281 switch (theDrawer->TypeOfHLR())
285 StdPrs_HLRShape aBuilder;
286 aBuilder.ComputeHLR (thePrs, theShape, theDrawer, theProjector);
289 case Prs3d_TOH_PolyAlgo:
290 case Prs3d_TOH_NotSet:
292 StdPrs_HLRPolyShape aBuilder;
293 aBuilder.ComputeHLR (thePrs, theShape, theDrawer, theProjector);
298 catch (Standard_Failure const& anException)
300 Message::DefaultMessenger()->Send (TCollection_AsciiString()
301 + "Error: AIS_Shape::Compute() HLR Algorithm has failed ("
302 + anException.GetMessageString() + ")", Message_Fail);
303 StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
307 aDefDrawer->SetTypeOfDeflection (aPrevDef);
310 //=======================================================================
311 //function : ComputeSelection
313 //=======================================================================
315 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
316 const Standard_Integer aMode)
318 if(myshape.IsNull()) return;
319 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
321 // empty Shape -> empty Assembly.
325 TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
326 TopoDS_Shape shape = myshape;
328 // POP protection against crash in low layers
330 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
334 StdSelect_BRepSelectionTool::Load(aSelection,
339 myDrawer->DeviationAngle(),
340 myDrawer->IsAutoTriangulation());
342 catch (Standard_Failure const& anException)
344 Message::DefaultMessenger()->Send (TCollection_AsciiString()
345 + "Error: AIS_Shape::ComputeSelection(" + aMode + ") has failed ("
346 + anException.GetMessageString() + ")", Message_Fail);
350 Bnd_Box B = BoundingBox();
351 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
352 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
353 aSelection->Add(aSensitiveBox);
357 // insert the drawer in the BrepOwners for hilight...
358 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
361 void AIS_Shape::Color( Quantity_Color& aColor ) const {
362 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
365 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
366 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
369 Standard_Real AIS_Shape::Transparency() const {
370 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
373 //=======================================================================
374 //function : setColor
376 //=======================================================================
378 bool AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
379 const Quantity_Color& theColor) const
381 bool toRecompute = false;
382 toRecompute = theDrawer->SetupOwnShadingAspect() || toRecompute;
383 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
384 toRecompute = theDrawer->SetupOwnPointAspect() || toRecompute;
387 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
388 theDrawer->LineAspect()->SetColor (theColor);
389 theDrawer->WireAspect()->SetColor (theColor);
390 theDrawer->PointAspect()->SetColor (theColor);
391 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
392 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
393 theDrawer->SeenLineAspect()->SetColor (theColor);
394 theDrawer->FaceBoundaryAspect()->SetColor (theColor);
398 //=======================================================================
399 //function : SetColor
401 //=======================================================================
403 void AIS_Shape::SetColor (const Quantity_Color& theColor)
405 const bool toRecompute = setColor (myDrawer, theColor);
406 myDrawer->SetColor (theColor);
407 hasOwnColor = Standard_True;
410 || !myDrawer->HasLink())
412 SynchronizeAspects();
416 replaceWithNewOwnAspects();
421 //=======================================================================
422 //function : UnsetColor
424 //=======================================================================
426 void AIS_Shape::UnsetColor()
433 hasOwnColor = Standard_False;
434 myDrawer->SetColor (myDrawer->HasLink() ? myDrawer->Link()->Color() : Quantity_Color (Quantity_NOC_WHITE));
436 Graphic3d_MapOfAspectsToAspects aReplaceMap;
439 replaceAspectWithDef (aReplaceMap, LineAspect);
440 replaceAspectWithDef (aReplaceMap, WireAspect);
441 replaceAspectWithDef (aReplaceMap, FreeBoundaryAspect);
442 replaceAspectWithDef (aReplaceMap, UnFreeBoundaryAspect);
443 replaceAspectWithDef (aReplaceMap, SeenLineAspect);
444 replaceAspectWithDef (aReplaceMap, FaceBoundaryAspect);
445 myDrawer->SetLineAspect (Handle(Prs3d_LineAspect)());
446 myDrawer->SetWireAspect (Handle(Prs3d_LineAspect)());
447 myDrawer->SetFreeBoundaryAspect (Handle(Prs3d_LineAspect)());
448 myDrawer->SetUnFreeBoundaryAspect(Handle(Prs3d_LineAspect)());
449 myDrawer->SetSeenLineAspect (Handle(Prs3d_LineAspect)());
450 myDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
454 Quantity_Color aColor = Quantity_NOC_YELLOW;
455 if (myDrawer->HasLink())
457 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
459 myDrawer->LineAspect()->SetColor (aColor);
460 aColor = Quantity_NOC_RED;
461 if (myDrawer->HasLink())
463 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
465 myDrawer->WireAspect()->SetColor (aColor);
466 aColor = Quantity_NOC_GREEN;
467 if (myDrawer->HasLink())
469 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
471 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
472 aColor = Quantity_NOC_YELLOW;
473 if (myDrawer->HasLink())
475 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
477 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
478 if (myDrawer->HasLink())
480 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
482 myDrawer->SeenLineAspect()->SetColor (aColor);
483 aColor = Quantity_NOC_BLACK;
484 if (myDrawer->HasLink())
486 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_FaceBoundary, aColor);
488 myDrawer->FaceBoundaryAspect()->SetColor (aColor);
491 if (!myDrawer->HasOwnShadingAspect())
495 else if (HasMaterial()
497 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
499 const Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
500 Graphic3d_MaterialAspect mat = aDefaultMat;
501 Quantity_Color anInteriorColors[2] = {Quantity_NOC_CYAN1, Quantity_NOC_CYAN1};
502 if (myDrawer->HasLink())
504 anInteriorColors[0] = myDrawer->Link()->ShadingAspect()->Aspect()->InteriorColor();
505 anInteriorColors[1] = myDrawer->Link()->ShadingAspect()->Aspect()->BackInteriorColor();
507 if (HasMaterial() || myDrawer->HasLink())
509 const Handle(Graphic3d_AspectFillArea3d)& aSrcAspect = (HasMaterial() ? myDrawer : myDrawer->Link())->ShadingAspect()->Aspect();
510 mat = myCurrentFacingModel != Aspect_TOFM_BACK_SIDE
511 ? aSrcAspect->FrontMaterial()
512 : aSrcAspect->BackMaterial();
516 const Quantity_Color aColor = myDrawer->HasLink()
517 ? myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel)
518 : aDefaultMat.AmbientColor();
519 mat.SetColor (aColor);
523 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
524 mat.SetTransparency (Standard_ShortReal(aTransp));
526 myDrawer->ShadingAspect()->SetMaterial (mat, myCurrentFacingModel);
527 myDrawer->ShadingAspect()->Aspect()->SetInteriorColor (anInteriorColors[0]);
528 myDrawer->ShadingAspect()->Aspect()->SetBackInteriorColor(anInteriorColors[1]);
532 replaceAspectWithDef (aReplaceMap, ShadingAspect);
533 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
535 if (myDrawer->HasOwnPointAspect())
537 replaceAspectWithDef (aReplaceMap, PointAspect);
538 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
540 replaceAspects (aReplaceMap);
541 SynchronizeAspects();
545 //=======================================================================
546 //function : setWidth
548 //=======================================================================
550 bool AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
551 const Standard_Real theLineWidth) const
553 bool toRecompute = theDrawer->SetOwnLineAspects();
556 theDrawer->LineAspect()->SetWidth (theLineWidth);
557 theDrawer->WireAspect()->SetWidth (theLineWidth);
558 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
559 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
560 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
561 theDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth);
565 //=======================================================================
566 //function : SetWidth
568 //=======================================================================
570 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
572 myOwnWidth = (Standard_ShortReal )theLineWidth;
574 if (!setWidth (myDrawer, theLineWidth)
575 || !myDrawer->HasLink())
577 SynchronizeAspects();
581 replaceWithNewOwnAspects();
586 //=======================================================================
587 //function : UnsetWidth
589 //=======================================================================
591 void AIS_Shape::UnsetWidth()
593 if (myOwnWidth == 0.0f)
601 Graphic3d_MapOfAspectsToAspects aReplaceMap;
602 replaceAspectWithDef (aReplaceMap, LineAspect);
603 replaceAspectWithDef (aReplaceMap, WireAspect);
604 replaceAspectWithDef (aReplaceMap, FreeBoundaryAspect);
605 replaceAspectWithDef (aReplaceMap, UnFreeBoundaryAspect);
606 replaceAspectWithDef (aReplaceMap, SeenLineAspect);
607 replaceAspectWithDef (aReplaceMap, FaceBoundaryAspect);
608 myDrawer->SetLineAspect (Handle(Prs3d_LineAspect)());
609 myDrawer->SetWireAspect (Handle(Prs3d_LineAspect)());
610 myDrawer->SetFreeBoundaryAspect (Handle(Prs3d_LineAspect)());
611 myDrawer->SetUnFreeBoundaryAspect(Handle(Prs3d_LineAspect)());
612 myDrawer->SetSeenLineAspect (Handle(Prs3d_LineAspect)());
613 myDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
614 replaceAspects (aReplaceMap);
618 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
619 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
620 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
621 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
622 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
623 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
624 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
625 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
626 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
627 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
628 myDrawer->FaceBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
629 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_FaceBoundary) : 1.);
630 SynchronizeAspects();
635 //=======================================================================
636 //function : setMaterial
638 //=======================================================================
640 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
641 const Graphic3d_MaterialAspect& theMaterial,
642 const Standard_Boolean theToKeepColor,
643 const Standard_Boolean theToKeepTransp) const
645 const Quantity_Color aColor = theDrawer->ShadingAspect()->Color (myCurrentFacingModel);
646 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
647 theDrawer->SetupOwnShadingAspect();
648 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
652 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
656 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
660 //=======================================================================
661 //function : SetMaterial
663 //=======================================================================
665 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
667 const bool toRecompute = !myDrawer->HasOwnShadingAspect();
668 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
669 hasOwnMaterial = Standard_True;
672 || !myDrawer->HasLink())
674 SynchronizeAspects();
678 replaceWithNewOwnAspects();
682 //=======================================================================
683 //function : UnsetMaterial
685 //=======================================================================
687 void AIS_Shape::UnsetMaterial()
694 if (!myDrawer->HasOwnShadingAspect())
700 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
702 if(myDrawer->HasLink())
704 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
705 myCurrentFacingModel);
709 myDrawer->ShadingAspect()->SetColor (myDrawer->Color(), myCurrentFacingModel);
710 myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
712 SynchronizeAspects();
716 Graphic3d_MapOfAspectsToAspects aReplaceMap;
717 replaceAspectWithDef (aReplaceMap, ShadingAspect);
718 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
719 replaceAspects (aReplaceMap);
723 //=======================================================================
724 //function : setTransparency
726 //=======================================================================
728 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
729 const Standard_Real theValue) const
731 theDrawer->SetupOwnShadingAspect();
732 // override transparency
733 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
736 //=======================================================================
737 //function : SetTransparency
739 //=======================================================================
741 void AIS_Shape::SetTransparency (const Standard_Real theValue)
743 const bool toRecompute = !myDrawer->HasOwnShadingAspect();
744 setTransparency (myDrawer, theValue);
745 myDrawer->SetTransparency ((Standard_ShortReal )theValue);
748 || !myDrawer->HasLink())
750 SynchronizeAspects();
754 replaceWithNewOwnAspects();
758 //=======================================================================
759 //function : UnsetTransparency
761 //=======================================================================
763 void AIS_Shape::UnsetTransparency()
765 myDrawer->SetTransparency (0.0f);
766 if (!myDrawer->HasOwnShadingAspect())
772 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
774 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
775 SynchronizeAspects();
779 Graphic3d_MapOfAspectsToAspects aReplaceMap;
780 replaceAspectWithDef (aReplaceMap, ShadingAspect);
781 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
782 replaceAspects (aReplaceMap);
786 //=======================================================================
787 //function : BoundingBox
789 //=======================================================================
791 const Bnd_Box& AIS_Shape::BoundingBox()
793 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
795 // empty Shape -> empty Assembly.
801 BRepBndLib::Add (myshape, myBB, false);
802 myCompBB = Standard_False;
809 //=======================================================================
810 //function : SetOwnDeviationCoefficient
811 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
812 // returns Standard_True if it change
813 //=======================================================================
815 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
817 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
818 if(itSet) myDrawer->SetDeviationCoefficient();
822 //=======================================================================
823 //function : SetOwnDeviationAngle
824 //purpose : resets myhasOwnDeviationAngle to Standard_False and
825 // returns Standard_True if it change
826 //=======================================================================
828 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
830 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
831 if(itSet) myDrawer->SetDeviationAngle();
836 //=======================================================================
837 //function : SetOwnDeviationCoefficient
839 //=======================================================================
841 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
843 myDrawer->SetDeviationCoefficient( aCoefficient );
847 //=======================================================================
848 //function : SetOwnDeviationAngle
850 //=======================================================================
852 void AIS_Shape::SetOwnDeviationAngle (const Standard_Real theAngle)
854 myDrawer->SetDeviationAngle (theAngle);
855 SetToUpdate (AIS_WireFrame);
857 //=======================================================================
858 //function : SetOwnDeviationAngle
860 //=======================================================================
862 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
864 Standard_Real OutAngl,OutDefl;
865 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
866 SetOwnDeviationAngle(anAngle) ;
867 SetOwnDeviationCoefficient(OutDefl) ;
872 //=======================================================================
873 //function : UserAngle
875 //=======================================================================
877 Standard_Real AIS_Shape::UserAngle() const
879 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
882 //=======================================================================
883 //function : OwnDeviationCoefficient
885 //=======================================================================
887 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
888 Standard_Real & aPreviousCoefficient ) const
890 aCoefficient = myDrawer->DeviationCoefficient();
891 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
892 return myDrawer->HasOwnDeviationCoefficient() ;
895 //=======================================================================
896 //function : OwnDeviationAngle
898 //=======================================================================
900 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
901 Standard_Real & aPreviousAngle ) const
903 anAngle = myDrawer->DeviationAngle();
904 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
905 return myDrawer->HasOwnDeviationAngle();
908 //=======================================================================
909 //function : DumpJson
911 //=======================================================================
912 void AIS_Shape::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
914 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
915 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, AIS_InteractiveObject)
917 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myshape)
918 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myBB)
920 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myInitAng)
921 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCompBB)