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.
18 #include <AIS_GraphicTool.hxx>
19 #include <AIS_InteractiveContext.hxx>
20 #include <AIS_Shape.hxx>
21 #include <Aspect_TypeOfLine.hxx>
22 #include <Bnd_Box.hxx>
23 #include <BRep_Builder.hxx>
24 #include <BRepBndLib.hxx>
25 #include <BRepTools.hxx>
26 #include <BRepTools_ShapeSet.hxx>
27 #include <Geom_Transformation.hxx>
29 #include <Graphic3d_ArrayOfPolylines.hxx>
30 #include <Graphic3d_AspectFillArea3d.hxx>
31 #include <Graphic3d_AspectLine3d.hxx>
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_AspectText3d.hxx>
34 #include <Graphic3d_Group.hxx>
35 #include <Graphic3d_MaterialAspect.hxx>
36 #include <Graphic3d_SequenceOfGroup.hxx>
37 #include <Graphic3d_Structure.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_Projector.hxx>
46 #include <Prs3d_Root.hxx>
47 #include <Prs3d_ShadingAspect.hxx>
48 #include <StdPrs_BndBox.hxx>
49 #include <StdPrs_ToolTriangulatedShape.hxx>
50 #include <PrsMgr_ModedPresentation.hxx>
51 #include <Quantity_Color.hxx>
52 #include <Select3D_SensitiveBox.hxx>
53 #include <Select3D_SensitiveEntity.hxx>
54 #include <Standard_ErrorHandler.hxx>
55 #include <Standard_Failure.hxx>
56 #include <Standard_Type.hxx>
57 #include <StdPrs_HLRPolyShape.hxx>
58 #include <StdPrs_HLRShape.hxx>
59 #include <StdPrs_ShadedShape.hxx>
60 #include <StdPrs_WFShape.hxx>
61 #include <StdSelect.hxx>
62 #include <StdSelect_BRepOwner.hxx>
63 #include <StdSelect_BRepSelectionTool.hxx>
64 #include <StdSelect_DisplayMode.hxx>
65 #include <TColStd_ListIteratorOfListOfInteger.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopoDS_Iterator.hxx>
69 #include <TopoDS_Shape.hxx>
71 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
73 static Standard_Boolean myFirstCompute;
75 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
77 TColStd_ListIteratorOfListOfInteger It(LL);
78 for(;It.More();It.Next()){
80 return Standard_True;}
81 return Standard_False;
84 //==================================================
87 //==================================================
90 AIS_Shape(const TopoDS_Shape& shap):
91 AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
95 myFirstCompute = Standard_True;
97 myDrawer->SetShadingAspectGlobal(Standard_False);
100 //=======================================================================
103 //=======================================================================
104 AIS_KindOfInteractive AIS_Shape::Type() const
105 {return AIS_KOI_Shape;}
108 //=======================================================================
109 //function : Signature
111 //=======================================================================
112 Standard_Integer AIS_Shape::Signature() const
115 //=======================================================================
116 //function : AcceptShapeDecomposition
118 //=======================================================================
119 Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
120 {return Standard_True;}
122 //=======================================================================
125 //=======================================================================
126 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
127 const Handle(Prs3d_Presentation)& aPrs,
128 const Standard_Integer aMode)
131 if(myshape.IsNull()) return;
133 // wire,edge,vertex -> pas de HLR + priorite display superieure
134 Standard_Integer TheType = (Standard_Integer) myshape.ShapeType();
135 if(TheType>4 && TheType<8) {
136 aPrs->SetVisual(Graphic3d_TOS_ALL);
137 aPrs->SetDisplayPriority(TheType+2);
139 // Shape vide -> Assemblage vide.
140 if (myshape.ShapeType() == TopAbs_COMPOUND) {
141 TopoDS_Iterator anExplor (myshape);
143 if (!anExplor.More()) {
150 aPrs->SetInfiniteState (Standard_True); //not taken in account duting FITALL
160 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
162 catch (Standard_Failure)
165 cout << "AIS_Shape::Compute() failed" << endl;
166 cout << "a Shape should be incorrect : No Compute can be maked on it " << endl;
168 // presentation of the bounding box is calculated
169 // Compute(aPresentationManager,aPrs,2);
175 if (myDrawer->IsAutoTriangulation())
177 Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
178 Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
179 Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
180 if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
181 || (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
183 BRepTools::Clean (myshape);
187 if ((Standard_Integer) myshape.ShapeType() > 4)
189 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
193 myDrawer->SetShadingAspectGlobal (Standard_False);
196 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
203 StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer);
205 catch (Standard_Failure)
208 cout << "AIS_Shape::Compute() in ShadingMode failed" << endl;
210 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
214 Standard_Real aTransparency = Transparency() ;
215 if (aTransparency > 0.0)
217 SetTransparency (aTransparency);
227 StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
231 StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
236 // Recompute hidden line presentation (if necessary).
240 //=======================================================================
242 //purpose : Hidden Line Removal
243 //=======================================================================
244 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
245 const Handle(Prs3d_Presentation)& aPresentation)
247 Compute(aProjector,aPresentation,myshape);
250 //=======================================================================
253 //=======================================================================
255 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
256 const Handle(Geom_Transformation)& TheTrsf,
257 const Handle(Prs3d_Presentation)& aPresentation)
259 const TopLoc_Location& loc = myshape.Location();
260 TopoDS_Shape shbis = myshape.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
261 Compute(aProjector,aPresentation,shbis);
264 //=======================================================================
267 //=======================================================================
269 void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
270 const Handle(Prs3d_Presentation)& aPresentation,
271 const TopoDS_Shape& SH)
273 if (SH.ShapeType() == TopAbs_COMPOUND) {
274 TopoDS_Iterator anExplor (SH);
276 if (!anExplor.More()) // Shape vide -> Assemblage vide.
280 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
281 if (defdrawer->DrawHiddenLine())
282 {myDrawer->EnableDrawHiddenLine();}
283 else {myDrawer->DisableDrawHiddenLine();}
285 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
286 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
288 if (myDrawer->IsAutoTriangulation())
290 // coefficients for calculation
291 Standard_Real aPrevAngle, aNewAngle, aPrevCoeff, aNewCoeff;
292 Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle (aNewAngle, aPrevAngle);
293 Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient (aNewCoeff, aPrevCoeff);
294 if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
295 ((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient))
297 BRepTools::Clean(SH);
304 switch (TypeOfHLR()) {
306 StdPrs_HLRShape::Add (aPresentation, SH, myDrawer, aProjector);
308 case Prs3d_TOH_PolyAlgo:
310 StdPrs_HLRPolyShape::Add (aPresentation, SH, myDrawer, aProjector);
314 catch (Standard_Failure) {
316 cout <<"AIS_Shape::Compute(Proj) HLR Algorithm failed" << endl;
318 StdPrs_WFShape::Add(aPresentation,SH,myDrawer);
322 defdrawer->SetTypeOfDeflection (prevdef);
325 //=======================================================================
326 //function : SelectionType
327 //purpose : gives the type according to the Index of Selection Mode
328 //=======================================================================
330 TopAbs_ShapeEnum AIS_Shape::SelectionType(const Standard_Integer aMode)
334 return TopAbs_VERTEX;
346 return TopAbs_COMPSOLID;
348 return TopAbs_COMPOUND;
355 //=======================================================================
356 //function : SelectionType
357 //purpose : gives the SelectionMode according to the Type od Decomposition...
358 //=======================================================================
359 Standard_Integer AIS_Shape::SelectionMode(const TopAbs_ShapeEnum aType)
374 case TopAbs_COMPSOLID:
376 case TopAbs_COMPOUND:
385 //=======================================================================
386 //function : ComputeSelection
388 //=======================================================================
390 void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
391 const Standard_Integer aMode)
393 if(myshape.IsNull()) return;
394 if (myshape.ShapeType() == TopAbs_COMPOUND) {
395 TopoDS_Iterator anExplor (myshape);
397 if (!anExplor.More()) // empty Shape -> empty Assembly.
401 static TopAbs_ShapeEnum TypOfSel;
402 TypOfSel = AIS_Shape::SelectionType(aMode);
403 TopoDS_Shape shape = myshape;
405 // POP protection against crash in low layers
407 Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
410 StdSelect_BRepSelectionTool::Load(aSelection,
415 myDrawer->HLRAngle(),
416 myDrawer->IsAutoTriangulation());
417 } catch ( Standard_Failure ) {
418 // cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
421 Bnd_Box B = BoundingBox();
422 Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(shape,this);
423 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox(aOwner,B);
424 aSelection->Add(aSensitiveBox);
428 // insert the drawer in the BrepOwners for hilight...
429 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
432 Quantity_NameOfColor AIS_Shape::Color() const {
433 Quantity_Color aColor;
435 return aColor.Name();
438 void AIS_Shape::Color( Quantity_Color& aColor ) const {
439 aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
442 Graphic3d_NameOfMaterial AIS_Shape::Material() const {
443 return (myDrawer->ShadingAspect()->Material(myCurrentFacingModel)).Name();
446 Standard_Real AIS_Shape::Transparency() const {
447 return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
450 //=======================================================================
451 //function : SetColor
453 //=======================================================================
455 void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
457 SetColor(Quantity_Color(aCol));
460 //=======================================================================
461 //function : setColor
463 //=======================================================================
465 void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
466 const Quantity_Color& theColor) const
468 if (!theDrawer->HasOwnShadingAspect())
470 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
471 if (theDrawer->HasLink())
473 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
476 if (!theDrawer->HasOwnLineAspect())
478 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
479 if (theDrawer->HasLink())
481 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
484 if (!theDrawer->HasOwnWireAspect())
486 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
487 if (theDrawer->HasLink())
489 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
492 if (!theDrawer->HasOwnPointAspect())
494 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0));
495 if (theDrawer->HasLink())
497 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
500 if (!theDrawer->HasOwnFreeBoundaryAspect())
502 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
503 if (theDrawer->HasLink())
505 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
508 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
510 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
511 if (theDrawer->HasLink())
513 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
516 if (!theDrawer->HasOwnSeenLineAspect())
518 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
519 if (theDrawer->HasLink())
521 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
526 theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
527 theDrawer->SetShadingAspectGlobal (Standard_False);
528 theDrawer->LineAspect()->SetColor (theColor);
529 theDrawer->WireAspect()->SetColor (theColor);
530 theDrawer->PointAspect()->SetColor (theColor);
531 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
532 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
533 theDrawer->SeenLineAspect()->SetColor (theColor);
536 //=======================================================================
537 //function : SetColor
539 //=======================================================================
541 void AIS_Shape::SetColor (const Quantity_Color& theColor)
543 setColor (myDrawer, theColor);
544 myOwnColor = theColor;
545 hasOwnColor = Standard_True;
547 // modify shading presentation without re-computation
548 const PrsMgr_Presentations& aPrsList = Presentations();
549 Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
550 Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
551 Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
552 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
554 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
555 if (aPrsModed.Mode() != AIS_Shaded)
560 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
562 // Set aspects for presentation
563 aPrs->SetPrimitivesAspect (anAreaAspect);
564 aPrs->SetPrimitivesAspect (aLineAspect);
565 aPrs->SetPrimitivesAspect (aPointAspect);
567 // Go through all groups to change color for all primitives
568 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
570 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
572 // Check if aspect of given type is set for the group,
573 // because setting aspect for group with no already set aspect
574 // can lead to loss of presentation data
575 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
577 aGroup->SetGroupPrimitivesAspect (anAreaAspect);
579 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
581 aGroup->SetGroupPrimitivesAspect (aLineAspect);
583 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
585 aGroup->SetGroupPrimitivesAspect (aPointAspect);
590 LoadRecomputable (AIS_WireFrame);
591 LoadRecomputable (2);
594 //=======================================================================
595 //function : UnsetColor
597 //=======================================================================
599 void AIS_Shape::UnsetColor()
603 myToRecomputeModes.Clear();
606 hasOwnColor = Standard_False;
610 Handle(Prs3d_LineAspect) anEmptyAsp;
611 myDrawer->SetLineAspect (anEmptyAsp);
612 myDrawer->SetWireAspect (anEmptyAsp);
613 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
614 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
615 myDrawer->SetSeenLineAspect (anEmptyAsp);
619 Quantity_Color aColor = Quantity_NOC_YELLOW;
620 if (myDrawer->HasLink())
622 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
624 myDrawer->LineAspect()->SetColor (aColor);
625 aColor = Quantity_NOC_RED;
626 if (myDrawer->HasLink())
628 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
630 myDrawer->WireAspect()->SetColor (aColor);
631 aColor = Quantity_NOC_GREEN;
632 if (myDrawer->HasLink())
634 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
636 myDrawer->FreeBoundaryAspect()->SetColor (aColor);
637 aColor = Quantity_NOC_YELLOW;
638 if (myDrawer->HasLink())
640 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
642 myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
643 if (myDrawer->HasLink())
645 AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
647 myDrawer->SeenLineAspect()->SetColor (aColor);
653 Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
654 Graphic3d_MaterialAspect mat = aDefaultMat;
655 if (HasMaterial() || myDrawer->HasLink())
657 mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
661 Quantity_Color aColor = aDefaultMat.AmbientColor();
662 if (myDrawer->HasLink())
664 aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
666 mat.SetColor (aColor);
670 Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
671 mat.SetTransparency (aTransp);
673 myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
677 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
679 myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
681 // modify shading presentation without re-computation
682 const PrsMgr_Presentations& aPrsList = Presentations();
683 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
684 Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
685 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
687 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
688 if (aPrsModed.Mode() != AIS_Shaded)
693 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
695 aPrs->SetPrimitivesAspect (anAreaAsp);
696 aPrs->SetPrimitivesAspect (aLineAsp);
698 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
700 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
702 // Check if aspect of given type is set for the group,
703 // because setting aspect for group with no already set aspect
704 // can lead to loss of presentation data
705 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
707 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
709 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
711 aGroup->SetGroupPrimitivesAspect (aLineAsp);
716 LoadRecomputable (AIS_WireFrame);
717 LoadRecomputable (2);
720 //=======================================================================
721 //function : setWidth
723 //=======================================================================
725 void AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
726 const Standard_Real theLineWidth) const
728 if (!theDrawer->HasOwnLineAspect())
730 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
731 if (theDrawer->HasLink())
733 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
736 if (!theDrawer->HasOwnWireAspect())
738 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
739 if (theDrawer->HasLink())
741 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
744 if (!theDrawer->HasOwnFreeBoundaryAspect())
746 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
747 if (theDrawer->HasLink())
749 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
752 if (!theDrawer->HasOwnUnFreeBoundaryAspect())
754 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
755 if (theDrawer->HasLink())
757 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
760 if (!theDrawer->HasOwnSeenLineAspect())
762 theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
763 if (theDrawer->HasLink())
765 *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
770 theDrawer->LineAspect()->SetWidth (theLineWidth);
771 theDrawer->WireAspect()->SetWidth (theLineWidth);
772 theDrawer->FreeBoundaryAspect()->SetWidth (theLineWidth);
773 theDrawer->UnFreeBoundaryAspect()->SetWidth (theLineWidth);
774 theDrawer->SeenLineAspect()->SetWidth (theLineWidth);
777 //=======================================================================
778 //function : SetWidth
780 //=======================================================================
782 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
784 setWidth (myDrawer, theLineWidth);
785 myOwnWidth = theLineWidth;
786 LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
787 LoadRecomputable (2); // and the bounding box...
790 //=======================================================================
791 //function : UnsetWidth
793 //=======================================================================
795 void AIS_Shape::UnsetWidth()
797 if (myOwnWidth == 0.0)
799 myToRecomputeModes.Clear();
805 Handle(Prs3d_LineAspect) anEmptyAsp;
809 myDrawer->SetLineAspect (anEmptyAsp);
810 myDrawer->SetWireAspect (anEmptyAsp);
811 myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
812 myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
813 myDrawer->SetSeenLineAspect (anEmptyAsp);
817 myDrawer->LineAspect() ->SetWidth (myDrawer->HasLink() ?
818 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.);
819 myDrawer->WireAspect() ->SetWidth (myDrawer->HasLink() ?
820 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire) : 1.);
821 myDrawer->FreeBoundaryAspect() ->SetWidth (myDrawer->HasLink() ?
822 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free) : 1.);
823 myDrawer->UnFreeBoundaryAspect()->SetWidth (myDrawer->HasLink() ?
824 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree) : 1.);
825 myDrawer->SeenLineAspect() ->SetWidth (myDrawer->HasLink() ?
826 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen) : 1.);
828 LoadRecomputable (AIS_WireFrame);
831 //=======================================================================
832 //function : setMaterial
834 //=======================================================================
836 void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
837 const Graphic3d_MaterialAspect& theMaterial,
838 const Standard_Boolean theToKeepColor,
839 const Standard_Boolean theToKeepTransp) const
841 const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
842 const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
843 if (!theDrawer->HasOwnShadingAspect())
845 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
846 if (theDrawer->HasLink())
848 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
851 theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
855 theDrawer->ShadingAspect()->SetColor (aColor, myCurrentFacingModel);
859 theDrawer->ShadingAspect()->SetTransparency (aTransp, myCurrentFacingModel);
863 //=======================================================================
864 //function : SetMaterial
866 //=======================================================================
868 void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
870 SetMaterial(Graphic3d_MaterialAspect(aMat));
873 //=======================================================================
874 //function : SetMaterial
876 //=======================================================================
878 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
880 setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
881 hasOwnMaterial = Standard_True;
883 // modify shading presentation without re-computation
884 const PrsMgr_Presentations& aPrsList = Presentations();
885 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
886 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
888 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
889 if (aPrsModed.Mode() != AIS_Shaded)
894 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
895 aPrs->SetPrimitivesAspect (anAreaAsp);
896 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
898 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
900 // Check if aspect of given type is set for the group,
901 // because setting aspect for group with no already set aspect
902 // can lead to loss of presentation data
903 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
905 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
910 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
911 myToRecomputeModes.Clear();
914 //=======================================================================
915 //function : UnsetMaterial
917 //=======================================================================
919 void AIS_Shape::UnsetMaterial()
929 if(myDrawer->HasLink())
931 myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
932 myCurrentFacingModel);
936 myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
937 myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
942 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
944 hasOwnMaterial = Standard_False;
946 // modify shading presentation without re-computation
947 const PrsMgr_Presentations& aPrsList = Presentations();
948 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
949 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
951 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
952 if (aPrsModed.Mode() != AIS_Shaded)
957 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
958 aPrs->SetPrimitivesAspect (anAreaAsp);
959 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
961 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
962 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
964 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
969 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
970 myToRecomputeModes.Clear();
973 //=======================================================================
974 //function : setTransparency
976 //=======================================================================
978 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
979 const Standard_Real theValue) const
981 if (!theDrawer->HasOwnShadingAspect())
983 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
984 if (theDrawer->HasLink())
986 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
990 // override transparency
991 theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
994 //=======================================================================
995 //function : SetTransparency
997 //=======================================================================
999 void AIS_Shape::SetTransparency (const Standard_Real theValue)
1001 setTransparency (myDrawer, theValue);
1002 myTransparency = theValue;
1004 // modify shading presentation without re-computation
1005 const PrsMgr_Presentations& aPrsList = Presentations();
1006 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1007 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1009 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1010 if (aPrsModed.Mode() != AIS_Shaded)
1015 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1016 aPrs->SetPrimitivesAspect (anAreaAsp);
1017 aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
1018 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1020 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1021 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1023 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1028 myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
1029 myToRecomputeModes.Clear();
1032 //=======================================================================
1033 //function : UnsetTransparency
1035 //=======================================================================
1037 void AIS_Shape::UnsetTransparency()
1039 myTransparency = 0.0;
1040 if (!myDrawer->HasOwnShadingAspect())
1044 else if (HasColor() || HasMaterial())
1046 myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
1050 myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
1053 // modify shading presentation without re-computation
1054 const PrsMgr_Presentations& aPrsList = Presentations();
1055 Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
1056 for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
1058 const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
1059 if (aPrsModed.Mode() != AIS_Shaded)
1064 const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
1065 aPrs->SetPrimitivesAspect (anAreaAsp);
1066 for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
1068 const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
1069 if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
1071 aGroup->SetGroupPrimitivesAspect (anAreaAsp);
1074 aPrs->ResetDisplayPriority();
1077 myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
1078 myToRecomputeModes.Clear();
1081 //=======================================================================
1082 //function : LoadRecomputable
1084 //=======================================================================
1086 void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
1088 myRecomputeEveryPrs = Standard_False;
1089 if(!IsInList(myToRecomputeModes,TheMode))
1090 myToRecomputeModes.Append(TheMode);
1093 //=======================================================================
1094 //function : BoundingBox
1096 //=======================================================================
1098 const Bnd_Box& AIS_Shape::BoundingBox()
1100 if (myshape.ShapeType() == TopAbs_COMPOUND) {
1101 TopoDS_Iterator anExplor (myshape);
1103 if (!anExplor.More()) { // empty Shape -> empty Assembly.
1110 BRepBndLib::AddClose(myshape, myBB);
1111 myCompBB = Standard_False;
1118 //=======================================================================
1119 //function : SetOwnDeviationCoefficient
1120 //purpose : resets myhasOwnDeviationCoefficient to Standard_False and
1121 // returns Standard_True if it change
1122 //=======================================================================
1124 Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
1126 Standard_Boolean itSet = myDrawer->HasOwnDeviationCoefficient();
1127 if(itSet) myDrawer->SetDeviationCoefficient();
1131 //=======================================================================
1132 //function : SetHLROwnDeviationCoefficient
1133 //purpose : resets myhasOwnHLRDeviationCoefficient to Standard_False and
1134 // returns Standard_True if it change
1135 //=======================================================================
1137 Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
1139 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
1140 if(itSet) myDrawer->SetHLRDeviationCoefficient();
1145 //=======================================================================
1146 //function : SetOwnDeviationAngle
1147 //purpose : resets myhasOwnDeviationAngle to Standard_False and
1148 // returns Standard_True if it change
1149 //=======================================================================
1151 Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
1153 Standard_Boolean itSet = myDrawer->HasOwnDeviationAngle();
1154 if(itSet) myDrawer->SetDeviationAngle();
1159 //=======================================================================
1160 //function : SetOwnHLRDeviationAngle
1161 //purpose : resets myhasOwnHLRDeviationAngle to Standard_False and
1162 // returns Standard_True if it change
1163 //=======================================================================
1165 Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
1167 Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
1168 if(itSet) myDrawer->SetHLRAngle();
1173 //=======================================================================
1174 //function : SetOwnDeviationCoefficient
1176 //=======================================================================
1178 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real aCoefficient )
1180 myDrawer->SetDeviationCoefficient( aCoefficient );
1181 SetToUpdate(0) ; // WireFrame
1182 SetToUpdate(1) ; // Shadding
1185 //=======================================================================
1186 //function : SetOwnHLRDeviationCoefficient
1188 //=======================================================================
1190 void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real aCoefficient )
1192 myDrawer->SetHLRDeviationCoefficient( aCoefficient );
1196 //=======================================================================
1197 //function : SetOwnDeviationAngle
1199 //=======================================================================
1201 void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real anAngle )
1204 myDrawer->SetDeviationAngle(anAngle );
1205 SetToUpdate(0) ; // WireFrame
1207 //=======================================================================
1208 //function : SetOwnDeviationAngle
1210 //=======================================================================
1212 void AIS_Shape::SetAngleAndDeviation ( const Standard_Real anAngle )
1214 Standard_Real OutAngl,OutDefl;
1215 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1216 SetOwnDeviationAngle(anAngle) ;
1217 SetOwnDeviationCoefficient(OutDefl) ;
1218 myInitAng = anAngle;
1223 //=======================================================================
1224 //function : UserAngle
1226 //=======================================================================
1228 Standard_Real AIS_Shape::UserAngle() const
1230 return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
1234 //=======================================================================
1235 //function : SetHLRAngleAndDeviation
1237 //=======================================================================
1239 void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real anAngle )
1241 Standard_Real OutAngl,OutDefl;
1242 HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1243 SetOwnHLRDeviationAngle( OutAngl );
1244 SetOwnHLRDeviationCoefficient(OutDefl);
1247 //=======================================================================
1248 //function : SetOwnHLRDeviationAngle
1250 //=======================================================================
1252 void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real anAngle )
1254 myDrawer->SetHLRAngle( anAngle );
1258 //=======================================================================
1259 //function : OwnDeviationCoefficient
1261 //=======================================================================
1263 Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real & aCoefficient,
1264 Standard_Real & aPreviousCoefficient ) const
1266 aCoefficient = myDrawer->DeviationCoefficient();
1267 aPreviousCoefficient = myDrawer->PreviousDeviationCoefficient ();
1268 return myDrawer->HasOwnDeviationCoefficient() ;
1271 //=======================================================================
1272 //function : OwnHLRDeviationCoefficient
1274 //=======================================================================
1276 Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
1277 Standard_Real & aPreviousCoefficient ) const
1279 aCoefficient = myDrawer->HLRDeviationCoefficient();
1280 aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
1281 return myDrawer->HasOwnHLRDeviationCoefficient();
1285 //=======================================================================
1286 //function : OwnDeviationAngle
1288 //=======================================================================
1290 Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real & anAngle,
1291 Standard_Real & aPreviousAngle ) const
1293 anAngle = myDrawer->DeviationAngle();
1294 aPreviousAngle = myDrawer->PreviousDeviationAngle ();
1295 return myDrawer->HasOwnDeviationAngle();
1298 //=======================================================================
1299 //function : OwnHLRDeviationAngle
1301 //=======================================================================
1303 Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real & anAngle,
1304 Standard_Real & aPreviousAngle ) const
1306 anAngle = myDrawer->HLRAngle();
1307 aPreviousAngle = myDrawer->PreviousHLRDeviationAngle ();
1308 return myDrawer->HasOwnHLRDeviationAngle();