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>
27 #include <Graphic3d_ArrayOfPolylines.hxx>
28 #include <Graphic3d_AspectFillArea3d.hxx>
29 #include <Graphic3d_AspectLine3d.hxx>
30 #include <Graphic3d_AspectMarker3d.hxx>
31 #include <Graphic3d_AspectText3d.hxx>
32 #include <Graphic3d_Group.hxx>
33 #include <Graphic3d_MaterialAspect.hxx>
34 #include <Graphic3d_SequenceOfGroup.hxx>
35 #include <Graphic3d_Structure.hxx>
36 #include <Message.hxx>
37 #include <Message_Messenger.hxx>
38 #include <HLRBRep.hxx>
39 #include <OSD_Timer.hxx>
40 #include <Precision.hxx>
42 #include <Prs3d_Drawer.hxx>
43 #include <Prs3d_IsoAspect.hxx>
44 #include <Prs3d_Presentation.hxx>
45 #include <Prs3d_Root.hxx>
46 #include <Prs3d_ShadingAspect.hxx>
47 #include <Prs3d_BndBox.hxx>
48 #include <StdPrs_ToolTriangulatedShape.hxx>
49 #include <Quantity_Color.hxx>
50 #include <Select3D_SensitiveBox.hxx>
51 #include <Select3D_SensitiveEntity.hxx>
52 #include <Standard_ErrorHandler.hxx>
53 #include <Standard_Failure.hxx>
54 #include <Standard_Type.hxx>
55 #include <StdPrs_HLRPolyShape.hxx>
56 #include <StdPrs_HLRShape.hxx>
57 #include <StdPrs_ShadedShape.hxx>
58 #include <StdPrs_WFShape.hxx>
59 #include <StdSelect.hxx>
60 #include <StdSelect_BRepOwner.hxx>
61 #include <StdSelect_BRepSelectionTool.hxx>
62 #include <TColStd_ListIteratorOfListOfInteger.hxx>
65 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
68 #define replaceAspectWithDef(theMap, theAspect) \
69 if (myDrawer->Link()->theAspect()->Aspect() != myDrawer->theAspect()->Aspect()) \
71 theMap.Bind (myDrawer->theAspect()->Aspect(), myDrawer->Link()->theAspect()->Aspect()); \
74 // Auxiliary macros for replaceWithNewOwnAspects()
75 #define replaceAspectWithOwn(theMap, theAspect) \
76 if (myDrawer->Link()->theAspect()->Aspect() != myDrawer->theAspect()->Aspect()) \
78 theMap.Bind (myDrawer->Link()->theAspect()->Aspect(), myDrawer->theAspect()->Aspect()); \
81 //=======================================================================
82 //function : replaceWithNewOwnAspects
84 //=======================================================================
85 void AIS_Shape::replaceWithNewOwnAspects()
87 Graphic3d_MapOfAspectsToAspects aReplaceMap;
89 replaceAspectWithOwn (aReplaceMap, ShadingAspect);
90 replaceAspectWithOwn (aReplaceMap, LineAspect);
91 replaceAspectWithOwn (aReplaceMap, WireAspect);
92 replaceAspectWithOwn (aReplaceMap, FreeBoundaryAspect);
93 replaceAspectWithOwn (aReplaceMap, UnFreeBoundaryAspect);
94 replaceAspectWithOwn (aReplaceMap, SeenLineAspect);
95 replaceAspectWithOwn (aReplaceMap, FaceBoundaryAspect);
96 replaceAspectWithOwn (aReplaceMap, PointAspect);
98 replaceAspects (aReplaceMap);
101 //==================================================
102 // Function: AIS_Shape
104 //==================================================
105 AIS_Shape::AIS_Shape(const TopoDS_Shape& theShape)
106 : AIS_InteractiveObject (PrsMgr_TOP_ProjectorDependant),
108 myUVOrigin(0.0, 0.0),
109 myUVRepeat(1.0, 1.0),
110 myUVScale (1.0, 1.0),
112 myCompBB (Standard_True)
117 //=======================================================================
120 //=======================================================================
121 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
122 const Handle(Prs3d_Presentation)& aPrs,
123 const Standard_Integer theMode)
125 if(myshape.IsNull()) return;
127 // wire,edge,vertex -> pas de HLR + priorite display superieure
128 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
129 if(TheType>4 && TheType<8) {
130 aPrs->SetVisual(Graphic3d_TOS_ALL);
131 aPrs->SetDisplayPriority(TheType+2);
133 // Shape vide -> Assemblage vide.
134 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
141 aPrs->SetInfiniteState (Standard_True); //not taken in account during FITALL
148 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
152 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
154 catch (Standard_Failure const& anException)
156 Message::DefaultMessenger()->Send (TCollection_AsciiString()
157 + "Error: AIS_Shape::Compute() wireframe presentation builder has failed ("
158 + anException.GetMessageString() + ")", Message_Fail);
164 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
165 if ((Standard_Integer) myshape.ShapeType() > 4)
167 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
173 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
180 StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer,
181 myDrawer->ShadingAspect()->Aspect()->ToMapTexture()
182 && !myDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
183 myUVOrigin, myUVRepeat, myUVScale);
185 catch (Standard_Failure const& anException)
187 Message::DefaultMessenger()->Send (TCollection_AsciiString()
188 + "Error: AIS_Shape::Compute() shaded presentation builder has failed ("
189 + anException.GetMessageString() + ")", Message_Fail);
190 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
194 Standard_Real aTransparency = Transparency() ;
195 if (aTransparency > 0.0)
197 SetTransparency (aTransparency);
207 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
211 Prs3d_BndBox::Add (aPrs, BoundingBox(), myDrawer);
216 // Recompute hidden line presentation (if necessary).
220 //=======================================================================
221 //function : computeHlrPresentation
223 //=======================================================================
224 void AIS_Shape::computeHlrPresentation (const Handle(Graphic3d_Camera)& theProjector,
225 const Handle(Prs3d_Presentation)& thePrs,
226 const TopoDS_Shape& theShape,
227 const Handle(Prs3d_Drawer)& theDrawer)
229 if (theShape.IsNull())
234 switch (theShape.ShapeType())
240 thePrs->SetDisplayPriority (4);
241 StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
244 case TopAbs_COMPOUND:
246 if (theShape.NbChildren() == 0)
258 const Handle(Prs3d_Drawer)& aDefDrawer = theDrawer->Link();
259 if (aDefDrawer->DrawHiddenLine())
261 theDrawer->EnableDrawHiddenLine();
265 theDrawer->DisableDrawHiddenLine();
268 const Aspect_TypeOfDeflection aPrevDef = aDefDrawer->TypeOfDeflection();
269 aDefDrawer->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
270 if (theDrawer->IsAutoTriangulation())
272 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (theShape, theDrawer, Standard_True);
279 switch (theDrawer->TypeOfHLR())
283 StdPrs_HLRShape aBuilder;
284 aBuilder.ComputeHLR (thePrs, theShape, theDrawer, theProjector);
287 case Prs3d_TOH_PolyAlgo:
288 case Prs3d_TOH_NotSet:
290 StdPrs_HLRPolyShape aBuilder;
291 aBuilder.ComputeHLR (thePrs, theShape, theDrawer, theProjector);
296 catch (Standard_Failure const& anException)
298 Message::DefaultMessenger()->Send (TCollection_AsciiString()
299 + "Error: AIS_Shape::Compute() HLR Algorithm has failed ("
300 + anException.GetMessageString() + ")", Message_Fail);
301 StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
305 aDefDrawer->SetTypeOfDeflection (aPrevDef);
308 //=======================================================================
309 //function : ComputeSelection
311 //=======================================================================
313 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
314 const Standard_Integer aMode)
316 if(myshape.IsNull()) return;
317 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
319 // empty Shape -> empty Assembly.
323 TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
324 TopoDS_Shape shape = myshape;
326 // POP protection against crash in low layers
328 Standard_Real aDeflection = StdPrs_ToolTriangulatedShape::GetDeflection(shape, myDrawer);
332 StdSelect_BRepSelectionTool::Load(aSelection,
337 myDrawer->DeviationAngle(),
338 myDrawer->IsAutoTriangulation());
340 catch (Standard_Failure const& anException)
342 Message::DefaultMessenger()->Send (TCollection_AsciiString()
343 + "Error: AIS_Shape::ComputeSelection(" + aMode + ") has failed ("
344 + anException.GetMessageString() + ")", Message_Fail);
348 Bnd_Box B = BoundingBox();
349 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
350 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
351 aSelection->Add(aSensitiveBox);
355 // insert the drawer in the BrepOwners for hilight...
356 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
359 void AIS_Shape::Color( Quantity_Color& aColor ) const {
360 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
363 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
364 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
367 Standard_Real AIS_Shape::Transparency() const {
368 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
371 //=======================================================================
372 //function : setColor
374 //=======================================================================
376 bool AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
377 const Quantity_Color& theColor) const
379 bool toRecompute = false;
380 toRecompute = theDrawer->SetupOwnShadingAspect() || toRecompute;
381 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
382 toRecompute = theDrawer->SetupOwnPointAspect() || toRecompute;
385 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
386 theDrawer->LineAspect()->SetColor (theColor);
387 theDrawer->WireAspect()->SetColor (theColor);
388 theDrawer->PointAspect()->SetColor (theColor);
389 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
390 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
391 theDrawer->SeenLineAspect()->SetColor (theColor);
392 theDrawer->FaceBoundaryAspect()->SetColor (theColor);
396 //=======================================================================
397 //function : SetColor
399 //=======================================================================
401 void AIS_Shape::SetColor (const Quantity_Color& theColor)
403 const bool toRecompute = setColor (myDrawer, theColor);
404 myDrawer->SetColor (theColor);
405 hasOwnColor = Standard_True;
408 || !myDrawer->HasLink())
410 SynchronizeAspects();
414 replaceWithNewOwnAspects();
419 //=======================================================================
420 //function : UnsetColor
422 //=======================================================================
424 void AIS_Shape::UnsetColor()
431 hasOwnColor = Standard_False;
432 myDrawer->SetColor (myDrawer->HasLink() ? myDrawer->Link()->Color() : Quantity_Color (Quantity_NOC_WHITE));
434 Graphic3d_MapOfAspectsToAspects aReplaceMap;
437 replaceAspectWithDef (aReplaceMap, LineAspect);
438 replaceAspectWithDef (aReplaceMap, WireAspect);
439 replaceAspectWithDef (aReplaceMap, FreeBoundaryAspect);
440 replaceAspectWithDef (aReplaceMap, UnFreeBoundaryAspect);
441 replaceAspectWithDef (aReplaceMap, SeenLineAspect);
442 replaceAspectWithDef (aReplaceMap, FaceBoundaryAspect);
443 myDrawer->SetLineAspect (Handle(Prs3d_LineAspect)());
444 myDrawer->SetWireAspect (Handle(Prs3d_LineAspect)());
445 myDrawer->SetFreeBoundaryAspect (Handle(Prs3d_LineAspect)());
446 myDrawer->SetUnFreeBoundaryAspect(Handle(Prs3d_LineAspect)());
447 myDrawer->SetSeenLineAspect (Handle(Prs3d_LineAspect)());
448 myDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
452 Quantity_Color aColor = Quantity_NOC_YELLOW;
453 if (myDrawer->HasLink())
455 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
457 myDrawer->LineAspect()->SetColor (aColor);
458 aColor = Quantity_NOC_RED;
459 if (myDrawer->HasLink())
461 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
463 myDrawer->WireAspect()->SetColor (aColor);
464 aColor = Quantity_NOC_GREEN;
465 if (myDrawer->HasLink())
467 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
469 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
470 aColor = Quantity_NOC_YELLOW;
471 if (myDrawer->HasLink())
473 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
475 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
476 if (myDrawer->HasLink())
478 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
480 myDrawer->SeenLineAspect()->SetColor (aColor);
481 aColor = Quantity_NOC_BLACK;
482 if (myDrawer->HasLink())
484 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_FaceBoundary, aColor);
486 myDrawer->FaceBoundaryAspect()->SetColor (aColor);
489 if (!myDrawer->HasOwnShadingAspect())
493 else if (HasMaterial()
495 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
497 const Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
498 Graphic3d_MaterialAspect mat = aDefaultMat;
499 Quantity_Color anInteriorColors[2] = {Quantity_NOC_CYAN1, Quantity_NOC_CYAN1};
500 if (myDrawer->HasLink())
502 anInteriorColors[0] = myDrawer->Link()->ShadingAspect()->Aspect()->InteriorColor();
503 anInteriorColors[1] = myDrawer->Link()->ShadingAspect()->Aspect()->BackInteriorColor();
505 if (HasMaterial() || myDrawer->HasLink())
507 const Handle(Graphic3d_AspectFillArea3d)& aSrcAspect = (HasMaterial() ? myDrawer : myDrawer->Link())->ShadingAspect()->Aspect();
508 mat = myCurrentFacingModel != Aspect_TOFM_BACK_SIDE
509 ? aSrcAspect->FrontMaterial()
510 : aSrcAspect->BackMaterial();
514 const Quantity_Color aColor = myDrawer->HasLink()
515 ? myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel)
516 : aDefaultMat.AmbientColor();
517 mat.SetColor (aColor);
521 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
522 mat.SetTransparency (Standard_ShortReal(aTransp));
524 myDrawer->ShadingAspect()->SetMaterial (mat, myCurrentFacingModel);
525 myDrawer->ShadingAspect()->Aspect()->SetInteriorColor (anInteriorColors[0]);
526 myDrawer->ShadingAspect()->Aspect()->SetBackInteriorColor(anInteriorColors[1]);
530 replaceAspectWithDef (aReplaceMap, ShadingAspect);
531 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
533 if (myDrawer->HasOwnPointAspect())
535 replaceAspectWithDef (aReplaceMap, PointAspect);
536 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
538 replaceAspects (aReplaceMap);
539 SynchronizeAspects();
543 //=======================================================================
544 //function : setWidth
546 //=======================================================================
548 bool AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
549 const Standard_Real theLineWidth) const
551 bool toRecompute = theDrawer->SetOwnLineAspects();
554 theDrawer->LineAspect()->SetWidth (theLineWidth);
555 theDrawer->WireAspect()->SetWidth (theLineWidth);
556 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
557 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
558 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
559 theDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth);
563 //=======================================================================
564 //function : SetWidth
566 //=======================================================================
568 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
570 myOwnWidth = (Standard_ShortReal )theLineWidth;
572 if (!setWidth (myDrawer, theLineWidth)
573 || !myDrawer->HasLink())
575 SynchronizeAspects();
579 replaceWithNewOwnAspects();
584 //=======================================================================
585 //function : UnsetWidth
587 //=======================================================================
589 void AIS_Shape::UnsetWidth()
591 if (myOwnWidth == 0.0f)
599 Graphic3d_MapOfAspectsToAspects aReplaceMap;
600 replaceAspectWithDef (aReplaceMap, LineAspect);
601 replaceAspectWithDef (aReplaceMap, WireAspect);
602 replaceAspectWithDef (aReplaceMap, FreeBoundaryAspect);
603 replaceAspectWithDef (aReplaceMap, UnFreeBoundaryAspect);
604 replaceAspectWithDef (aReplaceMap, SeenLineAspect);
605 replaceAspectWithDef (aReplaceMap, FaceBoundaryAspect);
606 myDrawer->SetLineAspect (Handle(Prs3d_LineAspect)());
607 myDrawer->SetWireAspect (Handle(Prs3d_LineAspect)());
608 myDrawer->SetFreeBoundaryAspect (Handle(Prs3d_LineAspect)());
609 myDrawer->SetUnFreeBoundaryAspect(Handle(Prs3d_LineAspect)());
610 myDrawer->SetSeenLineAspect (Handle(Prs3d_LineAspect)());
611 myDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)());
612 replaceAspects (aReplaceMap);
616 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
617 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
618 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
619 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
620 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
621 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
622 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
623 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
624 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
625 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
626 myDrawer->FaceBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
627 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_FaceBoundary) : 1.);
628 SynchronizeAspects();
633 //=======================================================================
634 //function : setMaterial
636 //=======================================================================
638 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
639 const Graphic3d_MaterialAspect& theMaterial,
640 const Standard_Boolean theToKeepColor,
641 const Standard_Boolean theToKeepTransp) const
643 const Quantity_Color aColor = theDrawer->ShadingAspect()->Color (myCurrentFacingModel);
644 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
645 theDrawer->SetupOwnShadingAspect();
646 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
650 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
654 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
658 //=======================================================================
659 //function : SetMaterial
661 //=======================================================================
663 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
665 const bool toRecompute = !myDrawer->HasOwnShadingAspect();
666 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
667 hasOwnMaterial = Standard_True;
670 || !myDrawer->HasLink())
672 SynchronizeAspects();
676 replaceWithNewOwnAspects();
680 //=======================================================================
681 //function : UnsetMaterial
683 //=======================================================================
685 void AIS_Shape::UnsetMaterial()
692 if (!myDrawer->HasOwnShadingAspect())
698 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
700 if(myDrawer->HasLink())
702 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
703 myCurrentFacingModel);
707 myDrawer->ShadingAspect()->SetColor (myDrawer->Color(), myCurrentFacingModel);
708 myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
710 SynchronizeAspects();
714 Graphic3d_MapOfAspectsToAspects aReplaceMap;
715 replaceAspectWithDef (aReplaceMap, ShadingAspect);
716 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
717 replaceAspects (aReplaceMap);
721 //=======================================================================
722 //function : setTransparency
724 //=======================================================================
726 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
727 const Standard_Real theValue) const
729 theDrawer->SetupOwnShadingAspect();
730 // override transparency
731 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
734 //=======================================================================
735 //function : SetTransparency
737 //=======================================================================
739 void AIS_Shape::SetTransparency (const Standard_Real theValue)
741 const bool toRecompute = !myDrawer->HasOwnShadingAspect();
742 setTransparency (myDrawer, theValue);
743 myDrawer->SetTransparency ((Standard_ShortReal )theValue);
746 || !myDrawer->HasLink())
748 SynchronizeAspects();
752 replaceWithNewOwnAspects();
756 //=======================================================================
757 //function : UnsetTransparency
759 //=======================================================================
761 void AIS_Shape::UnsetTransparency()
763 myDrawer->SetTransparency (0.0f);
764 if (!myDrawer->HasOwnShadingAspect())
770 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
772 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
773 SynchronizeAspects();
777 Graphic3d_MapOfAspectsToAspects aReplaceMap;
778 replaceAspectWithDef (aReplaceMap, ShadingAspect);
779 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
780 replaceAspects (aReplaceMap);
784 //=======================================================================
785 //function : BoundingBox
787 //=======================================================================
789 const Bnd_Box& AIS_Shape::BoundingBox()
791 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
793 // empty Shape -> empty Assembly.
799 BRepBndLib::Add (myshape, myBB, false);
800 myCompBB = Standard_False;
807 //=======================================================================
808 //function : SetOwnDeviationCoefficient
809 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
810 // returns Standard_True if it change
811 //=======================================================================
813 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
815 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
816 if(itSet) myDrawer->SetDeviationCoefficient();
820 //=======================================================================
821 //function : SetOwnDeviationAngle
822 //purpose : resets myhasOwnDeviationAngle to Standard_False and
823 // returns Standard_True if it change
824 //=======================================================================
826 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
828 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
829 if(itSet) myDrawer->SetDeviationAngle();
834 //=======================================================================
835 //function : SetOwnDeviationCoefficient
837 //=======================================================================
839 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
841 myDrawer->SetDeviationCoefficient( aCoefficient );
845 //=======================================================================
846 //function : SetOwnDeviationAngle
848 //=======================================================================
850 void AIS_Shape::SetOwnDeviationAngle (const Standard_Real theAngle)
852 myDrawer->SetDeviationAngle (theAngle);
853 SetToUpdate (AIS_WireFrame);
855 //=======================================================================
856 //function : SetOwnDeviationAngle
858 //=======================================================================
860 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
862 Standard_Real OutAngl,OutDefl;
863 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
864 SetOwnDeviationAngle(anAngle) ;
865 SetOwnDeviationCoefficient(OutDefl) ;
870 //=======================================================================
871 //function : UserAngle
873 //=======================================================================
875 Standard_Real AIS_Shape::UserAngle() const
877 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
880 //=======================================================================
881 //function : OwnDeviationCoefficient
883 //=======================================================================
885 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
886 Standard_Real & aPreviousCoefficient ) const
888 aCoefficient = myDrawer->DeviationCoefficient();
889 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
890 return myDrawer->HasOwnDeviationCoefficient() ;
893 //=======================================================================
894 //function : OwnDeviationAngle
896 //=======================================================================
898 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
899 Standard_Real & aPreviousAngle ) const
901 anAngle = myDrawer->DeviationAngle();
902 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
903 return myDrawer->HasOwnDeviationAngle();
906 //=======================================================================
907 //function : DumpJson
909 //=======================================================================
910 void AIS_Shape::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
912 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
913 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, AIS_InteractiveObject)
915 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myshape)
916 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myBB)
918 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myInitAng)
919 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCompBB)