1 // Created on: 1997-01-21
2 // Created by: Prestataire Christiane ARMAND
3 // Copyright (c) 1997-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_Circle.hxx>
19 #include <AIS_GraphicTool.hxx>
20 #include <Aspect_TypeOfLine.hxx>
21 #include <GC_MakeArcOfCircle.hxx>
22 #include <Geom_Circle.hxx>
23 #include <Geom_Transformation.hxx>
24 #include <GeomAdaptor_Curve.hxx>
25 #include <Graphic3d_AspectLine3d.hxx>
26 #include <Graphic3d_Structure.hxx>
27 #include <Prs3d_Drawer.hxx>
28 #include <Prs3d_LineAspect.hxx>
29 #include <Prs3d_Presentation.hxx>
30 #include <Prs3d_Projector.hxx>
31 #include <Quantity_Color.hxx>
32 #include <Select3D_SensitiveCircle.hxx>
33 #include <SelectMgr_EntityOwner.hxx>
34 #include <SelectMgr_Selection.hxx>
35 #include <Standard_Type.hxx>
36 #include <StdPrs_DeflectionCurve.hxx>
37 #include <TColgp_Array1OfPnt.hxx>
40 IMPLEMENT_STANDARD_RTTIEXT(AIS_Circle,AIS_InteractiveObject)
42 //=======================================================================
43 //function : AIS_Circle
45 //=======================================================================
46 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent):
47 AIS_InteractiveObject(PrsMgr_TOP_AllView),
48 myComponent(aComponent),
51 myCircleIsArc(Standard_False),
52 myIsFilledCircleSens (Standard_False)
56 //=======================================================================
57 //function : AIS_Circle
59 //=======================================================================
60 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& theComponent,
61 const Standard_Real theUStart,
62 const Standard_Real theUEnd,
63 const Standard_Boolean theIsFilledCircleSens)
64 : AIS_InteractiveObject(PrsMgr_TOP_AllView),
65 myComponent (theComponent),
68 myCircleIsArc (Standard_True),
69 myIsFilledCircleSens (theIsFilledCircleSens)
73 //=======================================================================
76 //=======================================================================
77 void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
78 const Handle(Prs3d_Presentation)& aPresentation,
79 const Standard_Integer /*aMode*/)
81 aPresentation->Clear();
83 aPresentation->SetDisplayPriority(5);
85 if (myCircleIsArc) ComputeArc(aPresentation);
86 else ComputeCircle(aPresentation);
90 //=======================================================================
93 //=======================================================================
95 void AIS_Circle::Compute(const Handle(Prs3d_Projector)& aProjector,
96 const Handle(Geom_Transformation)& aTransformation,
97 const Handle(Prs3d_Presentation)& aPresentation)
99 // Standard_NotImplemented::Raise("AIS_Circle::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
100 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
103 //=======================================================================
104 //function : ComputeSelection
106 //=======================================================================
108 void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
109 const Standard_Integer /*aMode*/)
112 if (myCircleIsArc) ComputeArcSelection(aSelection);
113 else ComputeCircleSelection(aSelection);
118 //=======================================================================
119 //function : SetColor
121 //=======================================================================
123 void AIS_Circle::SetColor(const Quantity_NameOfColor aCol)
125 SetColor(Quantity_Color(aCol));
128 //=======================================================================
129 //function : SetColor
131 //=======================================================================
133 void AIS_Circle::SetColor(const Quantity_Color &aCol)
135 hasOwnColor=Standard_True;
138 Standard_Real WW = HasWidth() ? myOwnWidth :
139 myDrawer->HasLink() ?
140 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) :
143 if (!myDrawer->HasOwnLineAspect ())
144 myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
146 myDrawer->LineAspect()->SetColor(aCol);
151 //=======================================================================
152 //function : SetWidth
154 //=======================================================================
155 void AIS_Circle::SetWidth(const Standard_Real aValue)
159 if (!myDrawer->HasOwnLineAspect ()) {
160 Quantity_Color CC = Quantity_NOC_YELLOW;
161 if( HasColor() ) CC = myOwnColor;
162 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
163 myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
165 myDrawer->LineAspect()->SetWidth(aValue);
169 //=======================================================================
170 //function : UnsetColor
172 //=======================================================================
173 void AIS_Circle::UnsetColor()
175 hasOwnColor = Standard_False;
177 Handle(Prs3d_LineAspect) NullAsp;
179 if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
181 Quantity_Color CC = Quantity_NOC_YELLOW;;
182 if( HasColor() ) CC = myOwnColor;
183 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
184 myDrawer->LineAspect()->SetColor(CC);
189 //=======================================================================
190 //function : UnsetWidth
192 //=======================================================================
193 void AIS_Circle::UnsetWidth()
195 Handle(Prs3d_LineAspect) NullAsp;
197 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
199 Standard_Real WW = myDrawer->HasLink() ? AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.;
200 myDrawer->LineAspect()->SetWidth(WW);
205 //=======================================================================
206 //function : ComputeCircle
208 //=======================================================================
209 void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation)
212 GeomAdaptor_Curve curv(myComponent);
213 Standard_Real prevdev = myDrawer->DeviationCoefficient();
214 myDrawer->SetDeviationCoefficient(1.e-5);
215 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
216 myDrawer->SetDeviationCoefficient(prevdev);
220 //=======================================================================
221 //function : ComputeArc
224 //=======================================================================
225 void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation)
227 GeomAdaptor_Curve curv(myComponent,myUStart,myUEnd);
228 Standard_Real prevdev = myDrawer->DeviationCoefficient();
229 myDrawer->SetDeviationCoefficient(1.e-5);
230 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
231 myDrawer->SetDeviationCoefficient(prevdev);
234 //=======================================================================
235 //function : ComputeCircleSelection
237 //=======================================================================
239 void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection)
241 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
242 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
244 myIsFilledCircleSens);
245 aSelection->Add(seg);
247 //=======================================================================
248 //function : ComputeArcSelection
250 //=======================================================================
252 void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
256 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
257 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
260 myIsFilledCircleSens);
261 aSelection->Add(seg);
264 //=======================================================================
266 //purpose : to avoid warning
267 //=======================================================================
268 void AIS_Circle::Compute(const Handle(Prs3d_Projector)&,
269 const Handle(Prs3d_Presentation)&)