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_Projector.hxx>
47 #include <Prs3d_Root.hxx>
48 #include <Prs3d_ShadingAspect.hxx>
49 #include <StdPrs_BndBox.hxx>
50 #include <StdPrs_ToolTriangulatedShape.hxx>
51 #include <PrsMgr_ModedPresentation.hxx>
52 #include <Quantity_Color.hxx>
53 #include <Select3D_SensitiveBox.hxx>
54 #include <Select3D_SensitiveEntity.hxx>
55 #include <Standard_ErrorHandler.hxx>
56 #include <Standard_Failure.hxx>
57 #include <Standard_Type.hxx>
58 #include <StdPrs_HLRPolyShape.hxx>
59 #include <StdPrs_HLRShape.hxx>
60 #include <StdPrs_ShadedShape.hxx>
61 #include <StdPrs_WFShape.hxx>
62 #include <StdSelect.hxx>
63 #include <StdSelect_BRepOwner.hxx>
64 #include <StdSelect_BRepSelectionTool.hxx>
65 #include <StdSelect_DisplayMode.hxx>
66 #include <TColStd_ListIteratorOfListOfInteger.hxx>
69 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
71 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
73 TColStd_ListIteratorOfListOfInteger It(LL);
74 for(;It.More();It.Next()){
76 return Standard_True;}
77 return Standard_False;
80 //==================================================
81 // Function: AIS_Shape
83 //==================================================
84 AIS_Shape::AIS_Shape(const TopoDS_Shape& theShape)
85 : AIS_InteractiveObject (PrsMgr_TOP_ProjectorDependant),
91 myCompBB (Standard_True)
96 //=======================================================================
99 //=======================================================================
100 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
101 const Handle(Prs3d_Presentation)& aPrs,
102 const Standard_Integer theMode)
104 if(myshape.IsNull()) return;
106 // wire,edge,vertex -> pas de HLR + priorite display superieure
107 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
108 if(TheType>4 && TheType<8) {
109 aPrs->SetVisual(Graphic3d_TOS_ALL);
110 aPrs->SetDisplayPriority(TheType+2);
112 // Shape vide -> Assemblage vide.
113 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
120 aPrs->SetInfiniteState (Standard_True); //not taken in account during FITALL
127 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
131 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
133 catch (Standard_Failure const& anException)
135 Message::DefaultMessenger()->Send (TCollection_AsciiString()
136 + "Error: AIS_Shape::Compute() wireframe presentation builder has failed ("
137 + anException.GetMessageString() + ")", Message_Fail);
143 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
144 if ((Standard_Integer) myshape.ShapeType() > 4)
146 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
152 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
159 StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer,
160 myDrawer->ShadingAspect()->Aspect()->ToMapTexture()
161 && !myDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
162 myUVOrigin, myUVRepeat, myUVScale);
164 catch (Standard_Failure const& anException)
166 Message::DefaultMessenger()->Send (TCollection_AsciiString()
167 + "Error: AIS_Shape::Compute() shaded presentation builder has failed ("
168 + anException.GetMessageString() + ")", Message_Fail);
169 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
173 Standard_Real aTransparency = Transparency() ;
174 if (aTransparency > 0.0)
176 SetTransparency (aTransparency);
186 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
190 StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
195 // Recompute hidden line presentation (if necessary).
199 //=======================================================================
200 //function : computeHlrPresentation
202 //=======================================================================
203 void AIS_Shape::computeHlrPresentation (const Handle(Prs3d_Projector)& theProjector,
204 const Handle(Prs3d_Presentation)& thePrs,
205 const TopoDS_Shape& theShape,
206 const Handle(Prs3d_Drawer)& theDrawer)
208 if (theShape.IsNull())
213 switch (theShape.ShapeType())
219 thePrs->SetDisplayPriority (4);
220 StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
223 case TopAbs_COMPOUND:
225 if (theShape.NbChildren() == 0)
237 const Handle(Prs3d_Drawer)& aDefDrawer = theDrawer->Link();
238 if (aDefDrawer->DrawHiddenLine())
240 theDrawer->EnableDrawHiddenLine();
244 theDrawer->DisableDrawHiddenLine();
247 const Aspect_TypeOfDeflection aPrevDef = aDefDrawer->TypeOfDeflection();
248 aDefDrawer->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
249 if (theDrawer->IsAutoTriangulation())
251 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (theShape, theDrawer, Standard_True);
258 switch (theDrawer->TypeOfHLR())
261 StdPrs_HLRShape::Add (thePrs, theShape, theDrawer, theProjector);
263 case Prs3d_TOH_PolyAlgo:
265 StdPrs_HLRPolyShape::Add (thePrs, theShape, theDrawer, theProjector);
269 catch (Standard_Failure const& anException)
271 Message::DefaultMessenger()->Send (TCollection_AsciiString()
272 + "Error: AIS_Shape::Compute() HLR Algorithm has failed ("
273 + anException.GetMessageString() + ")", Message_Fail);
274 StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
278 aDefDrawer->SetTypeOfDeflection (aPrevDef);
281 //=======================================================================
282 //function : ComputeSelection
284 //=======================================================================
286 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
287 const Standard_Integer aMode)
289 if(myshape.IsNull()) return;
290 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
292 // empty Shape -> empty Assembly.
296 TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
297 TopoDS_Shape shape = myshape;
299 // POP protection against crash in low layers
301 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
305 StdSelect_BRepSelectionTool::Load(aSelection,
310 myDrawer->HLRAngle(),
311 myDrawer->IsAutoTriangulation());
313 catch (Standard_Failure const& anException)
315 Message::DefaultMessenger()->Send (TCollection_AsciiString()
316 + "Error: AIS_Shape::ComputeSelection(" + aMode + ") has failed ("
317 + anException.GetMessageString() + ")", Message_Fail);
321 Bnd_Box B = BoundingBox();
322 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
323 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
324 aSelection->Add(aSensitiveBox);
328 // insert the drawer in the BrepOwners for hilight...
329 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
332 void AIS_Shape::Color( Quantity_Color& aColor ) const {
333 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
336 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
337 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
340 Standard_Real AIS_Shape::Transparency() const {
341 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
344 //=======================================================================
345 //function : setColor
347 //=======================================================================
349 bool AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
350 const Quantity_Color& theColor) const
352 bool toRecompute = false;
353 toRecompute = theDrawer->SetupOwnShadingAspect() || toRecompute;
354 toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
356 if (theDrawer->SetupOwnPointAspect())
362 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
363 theDrawer->LineAspect()->SetColor (theColor);
364 theDrawer->WireAspect()->SetColor (theColor);
365 theDrawer->PointAspect()->SetColor (theColor);
366 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
367 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
368 theDrawer->SeenLineAspect()->SetColor (theColor);
369 theDrawer->FaceBoundaryAspect()->SetColor (theColor);
373 //=======================================================================
374 //function : SetColor
376 //=======================================================================
378 void AIS_Shape::SetColor (const Quantity_Color& theColor)
380 const bool toRecompute = setColor (myDrawer, theColor);
381 myDrawer->SetColor (theColor);
382 hasOwnColor = Standard_True;
385 myToRecomputeModes.Clear();
386 myRecomputeEveryPrs = false;
387 SynchronizeAspects();
391 // modify shading presentation without re-computation
392 const PrsMgr_Presentations& aPrsList = Presentations();
393 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
394 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
395 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
396 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
398 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
399 if (aPrsModed.Mode() != AIS_Shaded)
404 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
405 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
407 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
409 // Check if aspect of given type is set for the group,
410 // because setting aspect for group with no already set aspect
411 // can lead to loss of presentation data
412 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
414 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
416 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
418 aGroup->SetGroupPrimitivesAspect (aLineAspect);
420 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
422 aGroup->SetGroupPrimitivesAspect (aPointAspect);
427 LoadRecomputable (AIS_WireFrame);
428 LoadRecomputable (2);
431 //=======================================================================
432 //function : UnsetColor
434 //=======================================================================
436 void AIS_Shape::UnsetColor()
440 myToRecomputeModes.Clear();
441 myRecomputeEveryPrs = false;
445 hasOwnColor = Standard_False;
446 myDrawer->SetColor (myDrawer->HasLink() ? myDrawer->Link()->Color() : Quantity_Color (Quantity_NOC_WHITE));
450 Handle(Prs3d_LineAspect) anEmptyAsp;
451 myDrawer->SetLineAspect (anEmptyAsp);
452 myDrawer->SetWireAspect (anEmptyAsp);
453 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
454 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
455 myDrawer->SetSeenLineAspect (anEmptyAsp);
456 myDrawer->SetFaceBoundaryAspect (anEmptyAsp);
460 Quantity_Color aColor = Quantity_NOC_YELLOW;
461 if (myDrawer->HasLink())
463 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
465 myDrawer->LineAspect()->SetColor (aColor);
466 aColor = Quantity_NOC_RED;
467 if (myDrawer->HasLink())
469 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
471 myDrawer->WireAspect()->SetColor (aColor);
472 aColor = Quantity_NOC_GREEN;
473 if (myDrawer->HasLink())
475 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
477 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
478 aColor = Quantity_NOC_YELLOW;
479 if (myDrawer->HasLink())
481 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
483 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
484 if (myDrawer->HasLink())
486 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
488 myDrawer->SeenLineAspect()->SetColor (aColor);
489 aColor = Quantity_NOC_BLACK;
490 if (myDrawer->HasLink())
492 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_FaceBoundary, aColor);
494 myDrawer->FaceBoundaryAspect()->SetColor (aColor);
497 if (!myDrawer->HasOwnShadingAspect())
501 else if (HasMaterial()
503 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
505 const Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
506 Graphic3d_MaterialAspect mat = aDefaultMat;
507 Quantity_Color anInteriorColors[2] = {Quantity_NOC_CYAN1, Quantity_NOC_CYAN1};
508 if (myDrawer->HasLink())
510 anInteriorColors[0] = myDrawer->Link()->ShadingAspect()->Aspect()->InteriorColor();
511 anInteriorColors[1] = myDrawer->Link()->ShadingAspect()->Aspect()->BackInteriorColor();
513 if (HasMaterial() || myDrawer->HasLink())
515 const Handle(Graphic3d_AspectFillArea3d)& aSrcAspect = (HasMaterial() ? myDrawer : myDrawer->Link())->ShadingAspect()->Aspect();
516 mat = myCurrentFacingModel != Aspect_TOFM_BACK_SIDE
517 ? aSrcAspect->FrontMaterial()
518 : aSrcAspect->BackMaterial();
522 const Quantity_Color aColor = myDrawer->HasLink()
523 ? myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel)
524 : aDefaultMat.AmbientColor();
525 mat.SetColor (aColor);
529 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
530 mat.SetTransparency (Standard_ShortReal(aTransp));
532 myDrawer->ShadingAspect()->SetMaterial (mat, myCurrentFacingModel);
533 myDrawer->ShadingAspect()->Aspect()->SetInteriorColor (anInteriorColors[0]);
534 myDrawer->ShadingAspect()->Aspect()->SetBackInteriorColor(anInteriorColors[1]);
538 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
540 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
541 myRecomputeEveryPrs = true;
544 //=======================================================================
545 //function : setWidth
547 //=======================================================================
549 bool AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
550 const Standard_Real theLineWidth) const
552 bool toRecompute = theDrawer->SetOwnLineAspects();
555 theDrawer->LineAspect()->SetWidth (theLineWidth);
556 theDrawer->WireAspect()->SetWidth (theLineWidth);
557 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
558 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
559 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
560 theDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth);
564 //=======================================================================
565 //function : SetWidth
567 //=======================================================================
569 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
571 myOwnWidth = theLineWidth;
572 if (setWidth (myDrawer, theLineWidth))
574 myRecomputeEveryPrs = true;
578 myRecomputeEveryPrs = false;
579 myToRecomputeModes.Clear();
580 SynchronizeAspects();
584 //=======================================================================
585 //function : UnsetWidth
587 //=======================================================================
589 void AIS_Shape::UnsetWidth()
591 if (myOwnWidth == 0.0)
593 myToRecomputeModes.Clear();
594 myRecomputeEveryPrs = false;
601 const Handle(Prs3d_LineAspect) anEmptyAsp;
602 myDrawer->SetLineAspect (anEmptyAsp);
603 myDrawer->SetWireAspect (anEmptyAsp);
604 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
605 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
606 myDrawer->SetSeenLineAspect (anEmptyAsp);
607 myDrawer->SetFaceBoundaryAspect (anEmptyAsp);
608 myRecomputeEveryPrs = true;
612 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
613 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
614 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
615 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
616 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
617 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
618 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
619 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
620 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
621 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
622 myDrawer->FaceBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
623 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_FaceBoundary) : 1.);
624 SynchronizeAspects();
625 myToRecomputeModes.Clear();
626 myRecomputeEveryPrs = false;
630 //=======================================================================
631 //function : setMaterial
633 //=======================================================================
635 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
636 const Graphic3d_MaterialAspect& theMaterial,
637 const Standard_Boolean theToKeepColor,
638 const Standard_Boolean theToKeepTransp) const
640 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
641 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
642 theDrawer->SetupOwnShadingAspect();
643 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
647 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
651 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
655 //=======================================================================
656 //function : SetMaterial
658 //=======================================================================
660 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
662 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
663 hasOwnMaterial = Standard_True;
665 // modify shading presentation without re-computation
666 const PrsMgr_Presentations& aPrsList = Presentations();
667 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
668 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
670 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
671 if (aPrsModed.Mode() != AIS_Shaded)
676 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
677 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
679 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
681 // Check if aspect of given type is set for the group,
682 // because setting aspect for group with no already set aspect
683 // can lead to loss of presentation data
684 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
686 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
691 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
692 myToRecomputeModes.Clear();
695 //=======================================================================
696 //function : UnsetMaterial
698 //=======================================================================
700 void AIS_Shape::UnsetMaterial()
707 if (!myDrawer->HasOwnShadingAspect())
713 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
715 if(myDrawer->HasLink())
717 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
718 myCurrentFacingModel);
722 myDrawer->ShadingAspect()->SetColor (myDrawer->Color(), myCurrentFacingModel);
723 myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
728 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
730 hasOwnMaterial = Standard_False;
732 // modify shading presentation without re-computation
733 const PrsMgr_Presentations& aPrsList = Presentations();
734 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
735 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
737 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
738 if (aPrsModed.Mode() != AIS_Shaded)
743 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
744 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
746 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
747 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
749 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
754 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
755 myToRecomputeModes.Clear();
758 //=======================================================================
759 //function : setTransparency
761 //=======================================================================
763 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
764 const Standard_Real theValue) const
766 theDrawer->SetupOwnShadingAspect();
767 // override transparency
768 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
771 //=======================================================================
772 //function : SetTransparency
774 //=======================================================================
776 void AIS_Shape::SetTransparency (const Standard_Real theValue)
778 setTransparency (myDrawer, theValue);
779 myDrawer->SetTransparency ((Standard_ShortReal )theValue);
781 // modify shading presentation without re-computation
782 const PrsMgr_Presentations& aPrsList = Presentations();
783 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
784 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
786 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
787 if (aPrsModed.Mode() != AIS_Shaded)
792 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
793 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
795 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
796 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
798 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
803 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
804 myToRecomputeModes.Clear();
807 //=======================================================================
808 //function : UnsetTransparency
810 //=======================================================================
812 void AIS_Shape::UnsetTransparency()
814 myDrawer->SetTransparency (0.0f);
815 if (!myDrawer->HasOwnShadingAspect())
821 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
823 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
827 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
830 // modify shading presentation without re-computation
831 const PrsMgr_Presentations& aPrsList = Presentations();
832 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
833 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
835 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
836 if (aPrsModed.Mode() != AIS_Shaded)
841 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
842 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
844 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
845 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
847 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
852 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
853 myToRecomputeModes.Clear();
856 //=======================================================================
857 //function : LoadRecomputable
859 //=======================================================================
861 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
863 myRecomputeEveryPrs = Standard_False;
864 if(!IsInList(myToRecomputeModes,TheMode))
865 myToRecomputeModes.Append(TheMode);
868 //=======================================================================
869 //function : BoundingBox
871 //=======================================================================
873 const Bnd_Box& AIS_Shape::BoundingBox()
875 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
877 // empty Shape -> empty Assembly.
883 BRepBndLib::AddClose(myshape, myBB);
884 myCompBB = Standard_False;
891 //=======================================================================
892 //function : SetOwnDeviationCoefficient
893 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
894 // returns Standard_True if it change
895 //=======================================================================
897 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
899 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
900 if(itSet) myDrawer->SetDeviationCoefficient();
904 //=======================================================================
905 //function : SetHLROwnDeviationCoefficient
906 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
907 // returns Standard_True if it change
908 //=======================================================================
910 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
912 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
913 if(itSet) myDrawer->SetHLRDeviationCoefficient();
918 //=======================================================================
919 //function : SetOwnDeviationAngle
920 //purpose : resets myhasOwnDeviationAngle to Standard_False and
921 // returns Standard_True if it change
922 //=======================================================================
924 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
926 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
927 if(itSet) myDrawer->SetDeviationAngle();
932 //=======================================================================
933 //function : SetOwnHLRDeviationAngle
934 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
935 // returns Standard_True if it change
936 //=======================================================================
938 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
940 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
941 if(itSet) myDrawer->SetHLRAngle();
946 //=======================================================================
947 //function : SetOwnDeviationCoefficient
949 //=======================================================================
951 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
953 myDrawer->SetDeviationCoefficient( aCoefficient );
954 SetToUpdate(0) ; // WireFrame
955 SetToUpdate(1) ; // Shadding
958 //=======================================================================
959 //function : SetOwnHLRDeviationCoefficient
961 //=======================================================================
963 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
965 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
969 //=======================================================================
970 //function : SetOwnDeviationAngle
972 //=======================================================================
974 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
977 myDrawer->SetDeviationAngle(anAngle );
978 SetToUpdate(0) ; // WireFrame
980 //=======================================================================
981 //function : SetOwnDeviationAngle
983 //=======================================================================
985 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
987 Standard_Real OutAngl,OutDefl;
988 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
989 SetOwnDeviationAngle(anAngle) ;
990 SetOwnDeviationCoefficient(OutDefl) ;
996 //=======================================================================
997 //function : UserAngle
999 //=======================================================================
1001 Standard_Real AIS_Shape::UserAngle() const
1003 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1007 //=======================================================================
1008 //function : SetHLRAngleAndDeviation
1010 //=======================================================================
1012 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1014 Standard_Real OutAngl,OutDefl;
1015 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1016 SetOwnHLRDeviationAngle( OutAngl );
1017 SetOwnHLRDeviationCoefficient(OutDefl);
1020 //=======================================================================
1021 //function : SetOwnHLRDeviationAngle
1023 //=======================================================================
1025 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1027 myDrawer->SetHLRAngle( anAngle );
1031 //=======================================================================
1032 //function : OwnDeviationCoefficient
1034 //=======================================================================
1036 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1037 Standard_Real & aPreviousCoefficient ) const
1039 aCoefficient = myDrawer->DeviationCoefficient();
1040 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1041 return myDrawer->HasOwnDeviationCoefficient() ;
1044 //=======================================================================
1045 //function : OwnHLRDeviationCoefficient
1047 //=======================================================================
1049 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1050 Standard_Real & aPreviousCoefficient ) const
1052 aCoefficient = myDrawer->HLRDeviationCoefficient();
1053 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1054 return myDrawer->HasOwnHLRDeviationCoefficient();
1058 //=======================================================================
1059 //function : OwnDeviationAngle
1061 //=======================================================================
1063 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1064 Standard_Real & aPreviousAngle ) const
1066 anAngle = myDrawer->DeviationAngle();
1067 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1068 return myDrawer->HasOwnDeviationAngle();
1071 //=======================================================================
1072 //function : OwnHLRDeviationAngle
1074 //=======================================================================
1076 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1077 Standard_Real & aPreviousAngle ) const
1079 anAngle = myDrawer->HLRAngle();
1080 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1081 return myDrawer->HasOwnHLRDeviationAngle();