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 void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
350 const Quantity_Color& theColor) const
352 if (!theDrawer->HasOwnShadingAspect())
354 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
355 if (theDrawer->HasLink())
357 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
360 if (!theDrawer->HasOwnLineAspect())
362 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
363 if (theDrawer->HasLink())
365 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
368 if (!theDrawer->HasOwnWireAspect())
370 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
371 if (theDrawer->HasLink())
373 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
376 if (!theDrawer->HasOwnPointAspect())
378 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0));
379 if (theDrawer->HasLink())
381 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
384 if (!theDrawer->HasOwnFreeBoundaryAspect())
386 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
387 if (theDrawer->HasLink())
389 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
392 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
394 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
395 if (theDrawer->HasLink())
397 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
400 if (!theDrawer->HasOwnSeenLineAspect())
402 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
403 if (theDrawer->HasLink())
405 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
410 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
411 theDrawer->LineAspect()->SetColor (theColor);
412 theDrawer->WireAspect()->SetColor (theColor);
413 theDrawer->PointAspect()->SetColor (theColor);
414 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
415 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
416 theDrawer->SeenLineAspect()->SetColor (theColor);
419 //=======================================================================
420 //function : SetColor
422 //=======================================================================
424 void AIS_Shape::SetColor (const Quantity_Color& theColor)
426 setColor (myDrawer, theColor);
427 myDrawer->SetColor (theColor);
428 hasOwnColor = Standard_True;
430 // modify shading presentation without re-computation
431 const PrsMgr_Presentations& aPrsList = Presentations();
432 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
433 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
434 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
435 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
437 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
438 if (aPrsModed.Mode() != AIS_Shaded)
443 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
444 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
446 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
448 // Check if aspect of given type is set for the group,
449 // because setting aspect for group with no already set aspect
450 // can lead to loss of presentation data
451 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
453 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
455 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
457 aGroup->SetGroupPrimitivesAspect (aLineAspect);
459 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
461 aGroup->SetGroupPrimitivesAspect (aPointAspect);
466 LoadRecomputable (AIS_WireFrame);
467 LoadRecomputable (2);
470 //=======================================================================
471 //function : UnsetColor
473 //=======================================================================
475 void AIS_Shape::UnsetColor()
479 myToRecomputeModes.Clear();
482 hasOwnColor = Standard_False;
483 myDrawer->SetColor (myDrawer->HasLink() ? myDrawer->Link()->Color() : Quantity_Color (Quantity_NOC_WHITE));
487 Handle(Prs3d_LineAspect) anEmptyAsp;
488 myDrawer->SetLineAspect (anEmptyAsp);
489 myDrawer->SetWireAspect (anEmptyAsp);
490 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
491 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
492 myDrawer->SetSeenLineAspect (anEmptyAsp);
496 Quantity_Color aColor = Quantity_NOC_YELLOW;
497 if (myDrawer->HasLink())
499 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
501 myDrawer->LineAspect()->SetColor (aColor);
502 aColor = Quantity_NOC_RED;
503 if (myDrawer->HasLink())
505 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
507 myDrawer->WireAspect()->SetColor (aColor);
508 aColor = Quantity_NOC_GREEN;
509 if (myDrawer->HasLink())
511 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
513 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
514 aColor = Quantity_NOC_YELLOW;
515 if (myDrawer->HasLink())
517 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
519 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
520 if (myDrawer->HasLink())
522 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
524 myDrawer->SeenLineAspect()->SetColor (aColor);
527 if (!myDrawer->HasOwnShadingAspect())
531 else if (HasMaterial()
533 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
535 const Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
536 Graphic3d_MaterialAspect mat = aDefaultMat;
537 Quantity_Color anInteriorColors[2] = {Quantity_NOC_CYAN1, Quantity_NOC_CYAN1};
538 if (myDrawer->HasLink())
540 anInteriorColors[0] = myDrawer->Link()->ShadingAspect()->Aspect()->InteriorColor();
541 anInteriorColors[1] = myDrawer->Link()->ShadingAspect()->Aspect()->BackInteriorColor();
543 if (HasMaterial() || myDrawer->HasLink())
545 const Handle(Graphic3d_AspectFillArea3d)& aSrcAspect = (HasMaterial() ? myDrawer : myDrawer->Link())->ShadingAspect()->Aspect();
546 mat = myCurrentFacingModel != Aspect_TOFM_BACK_SIDE
547 ? aSrcAspect->FrontMaterial()
548 : aSrcAspect->BackMaterial();
552 const Quantity_Color aColor = myDrawer->HasLink()
553 ? myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel)
554 : aDefaultMat.AmbientColor();
555 mat.SetColor (aColor);
559 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
560 mat.SetTransparency (Standard_ShortReal(aTransp));
562 myDrawer->ShadingAspect()->SetMaterial (mat, myCurrentFacingModel);
563 myDrawer->ShadingAspect()->Aspect()->SetInteriorColor (anInteriorColors[0]);
564 myDrawer->ShadingAspect()->Aspect()->SetBackInteriorColor(anInteriorColors[1]);
568 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
570 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
572 // modify shading presentation without re-computation
573 const PrsMgr_Presentations& aPrsList = Presentations();
574 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
575 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->LineAspect()->Aspect();
576 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
578 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
579 if (aPrsModed.Mode() != AIS_Shaded)
584 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
585 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
587 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
589 // Check if aspect of given type is set for the group,
590 // because setting aspect for group with no already set aspect
591 // can lead to loss of presentation data
592 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
594 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
596 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
598 aGroup->SetGroupPrimitivesAspect (aLineAsp);
603 LoadRecomputable (AIS_WireFrame);
604 LoadRecomputable (2);
607 //=======================================================================
608 //function : setWidth
610 //=======================================================================
612 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
613 const Standard_Real theLineWidth) const
615 if (!theDrawer->HasOwnLineAspect())
617 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
618 if (theDrawer->HasLink())
620 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
623 if (!theDrawer->HasOwnWireAspect())
625 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
626 if (theDrawer->HasLink())
628 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
631 if (!theDrawer->HasOwnFreeBoundaryAspect())
633 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
634 if (theDrawer->HasLink())
636 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
639 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
641 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
642 if (theDrawer->HasLink())
644 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
647 if (!theDrawer->HasOwnSeenLineAspect())
649 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
650 if (theDrawer->HasLink())
652 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
657 theDrawer->LineAspect()->SetWidth (theLineWidth);
658 theDrawer->WireAspect()->SetWidth (theLineWidth);
659 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
660 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
661 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
664 //=======================================================================
665 //function : SetWidth
667 //=======================================================================
669 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
671 setWidth (myDrawer, theLineWidth);
672 myOwnWidth = theLineWidth;
673 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
674 LoadRecomputable (2); // and the bounding box...
677 //=======================================================================
678 //function : UnsetWidth
680 //=======================================================================
682 void AIS_Shape::UnsetWidth()
684 if (myOwnWidth == 0.0)
686 myToRecomputeModes.Clear();
692 Handle(Prs3d_LineAspect) anEmptyAsp;
696 myDrawer->SetLineAspect (anEmptyAsp);
697 myDrawer->SetWireAspect (anEmptyAsp);
698 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
699 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
700 myDrawer->SetSeenLineAspect (anEmptyAsp);
704 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
705 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
706 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
707 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
708 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
709 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
710 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
711 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
712 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
713 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
715 LoadRecomputable (AIS_WireFrame);
718 //=======================================================================
719 //function : setMaterial
721 //=======================================================================
723 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
724 const Graphic3d_MaterialAspect& theMaterial,
725 const Standard_Boolean theToKeepColor,
726 const Standard_Boolean theToKeepTransp) const
728 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
729 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
730 if (!theDrawer->HasOwnShadingAspect())
732 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
733 if (theDrawer->HasLink())
735 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
738 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
742 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
746 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
750 //=======================================================================
751 //function : SetMaterial
753 //=======================================================================
755 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
757 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
758 hasOwnMaterial = Standard_True;
760 // modify shading presentation without re-computation
761 const PrsMgr_Presentations& aPrsList = Presentations();
762 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
763 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
765 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
766 if (aPrsModed.Mode() != AIS_Shaded)
771 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
772 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
774 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
776 // Check if aspect of given type is set for the group,
777 // because setting aspect for group with no already set aspect
778 // can lead to loss of presentation data
779 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
781 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
786 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
787 myToRecomputeModes.Clear();
790 //=======================================================================
791 //function : UnsetMaterial
793 //=======================================================================
795 void AIS_Shape::UnsetMaterial()
802 if (!myDrawer->HasOwnShadingAspect())
808 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
810 if(myDrawer->HasLink())
812 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
813 myCurrentFacingModel);
817 myDrawer->ShadingAspect()->SetColor (myDrawer->Color(), myCurrentFacingModel);
818 myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
823 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
825 hasOwnMaterial = Standard_False;
827 // modify shading presentation without re-computation
828 const PrsMgr_Presentations& aPrsList = Presentations();
829 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
830 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
832 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
833 if (aPrsModed.Mode() != AIS_Shaded)
838 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
839 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
841 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
842 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
844 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
849 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
850 myToRecomputeModes.Clear();
853 //=======================================================================
854 //function : setTransparency
856 //=======================================================================
858 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
859 const Standard_Real theValue) const
861 if (!theDrawer->HasOwnShadingAspect())
863 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
864 if (theDrawer->HasLink())
866 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
870 // override transparency
871 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
874 //=======================================================================
875 //function : SetTransparency
877 //=======================================================================
879 void AIS_Shape::SetTransparency (const Standard_Real theValue)
881 setTransparency (myDrawer, theValue);
882 myDrawer->SetTransparency ((Standard_ShortReal )theValue);
884 // modify shading presentation without re-computation
885 const PrsMgr_Presentations& aPrsList = Presentations();
886 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
887 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
889 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
890 if (aPrsModed.Mode() != AIS_Shaded)
895 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
896 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
898 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
899 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
901 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
906 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
907 myToRecomputeModes.Clear();
910 //=======================================================================
911 //function : UnsetTransparency
913 //=======================================================================
915 void AIS_Shape::UnsetTransparency()
917 myDrawer->SetTransparency (0.0f);
918 if (!myDrawer->HasOwnShadingAspect())
924 || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
926 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
930 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
933 // modify shading presentation without re-computation
934 const PrsMgr_Presentations& aPrsList = Presentations();
935 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
936 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
938 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
939 if (aPrsModed.Mode() != AIS_Shaded)
944 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
945 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
947 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
948 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
950 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
955 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
956 myToRecomputeModes.Clear();
959 //=======================================================================
960 //function : LoadRecomputable
962 //=======================================================================
964 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
966 myRecomputeEveryPrs = Standard_False;
967 if(!IsInList(myToRecomputeModes,TheMode))
968 myToRecomputeModes.Append(TheMode);
971 //=======================================================================
972 //function : BoundingBox
974 //=======================================================================
976 const Bnd_Box& AIS_Shape::BoundingBox()
978 if (myshape.ShapeType() == TopAbs_COMPOUND && myshape.NbChildren() == 0)
980 // empty Shape -> empty Assembly.
986 BRepBndLib::AddClose(myshape, myBB);
987 myCompBB = Standard_False;
994 //=======================================================================
995 //function : SetOwnDeviationCoefficient
996 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
997 // returns Standard_True if it change
998 //=======================================================================
1000 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1002 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1003 if(itSet) myDrawer->SetDeviationCoefficient();
1007 //=======================================================================
1008 //function : SetHLROwnDeviationCoefficient
1009 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1010 // returns Standard_True if it change
1011 //=======================================================================
1013 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1015 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1016 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1021 //=======================================================================
1022 //function : SetOwnDeviationAngle
1023 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1024 // returns Standard_True if it change
1025 //=======================================================================
1027 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1029 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1030 if(itSet) myDrawer->SetDeviationAngle();
1035 //=======================================================================
1036 //function : SetOwnHLRDeviationAngle
1037 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1038 // returns Standard_True if it change
1039 //=======================================================================
1041 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1043 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1044 if(itSet) myDrawer->SetHLRAngle();
1049 //=======================================================================
1050 //function : SetOwnDeviationCoefficient
1052 //=======================================================================
1054 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1056 myDrawer->SetDeviationCoefficient( aCoefficient );
1057 SetToUpdate(0) ; // WireFrame
1058 SetToUpdate(1) ; // Shadding
1061 //=======================================================================
1062 //function : SetOwnHLRDeviationCoefficient
1064 //=======================================================================
1066 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1068 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1072 //=======================================================================
1073 //function : SetOwnDeviationAngle
1075 //=======================================================================
1077 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1080 myDrawer->SetDeviationAngle(anAngle );
1081 SetToUpdate(0) ; // WireFrame
1083 //=======================================================================
1084 //function : SetOwnDeviationAngle
1086 //=======================================================================
1088 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1090 Standard_Real OutAngl,OutDefl;
1091 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1092 SetOwnDeviationAngle(anAngle) ;
1093 SetOwnDeviationCoefficient(OutDefl) ;
1094 myInitAng = anAngle;
1099 //=======================================================================
1100 //function : UserAngle
1102 //=======================================================================
1104 Standard_Real AIS_Shape::UserAngle() const
1106 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1110 //=======================================================================
1111 //function : SetHLRAngleAndDeviation
1113 //=======================================================================
1115 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1117 Standard_Real OutAngl,OutDefl;
1118 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1119 SetOwnHLRDeviationAngle( OutAngl );
1120 SetOwnHLRDeviationCoefficient(OutDefl);
1123 //=======================================================================
1124 //function : SetOwnHLRDeviationAngle
1126 //=======================================================================
1128 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1130 myDrawer->SetHLRAngle( anAngle );
1134 //=======================================================================
1135 //function : OwnDeviationCoefficient
1137 //=======================================================================
1139 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1140 Standard_Real & aPreviousCoefficient ) const
1142 aCoefficient = myDrawer->DeviationCoefficient();
1143 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1144 return myDrawer->HasOwnDeviationCoefficient() ;
1147 //=======================================================================
1148 //function : OwnHLRDeviationCoefficient
1150 //=======================================================================
1152 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1153 Standard_Real & aPreviousCoefficient ) const
1155 aCoefficient = myDrawer->HLRDeviationCoefficient();
1156 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1157 return myDrawer->HasOwnHLRDeviationCoefficient();
1161 //=======================================================================
1162 //function : OwnDeviationAngle
1164 //=======================================================================
1166 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1167 Standard_Real & aPreviousAngle ) const
1169 anAngle = myDrawer->DeviationAngle();
1170 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1171 return myDrawer->HasOwnDeviationAngle();
1174 //=======================================================================
1175 //function : OwnHLRDeviationAngle
1177 //=======================================================================
1179 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1180 Standard_Real & aPreviousAngle ) const
1182 anAngle = myDrawer->HLRAngle();
1183 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1184 return myDrawer->HasOwnHLRDeviationAngle();