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.
17 #include <AIS_Circle.ixx>
18 #include <Aspect_TypeOfLine.hxx>
19 #include <Prs3d_Drawer.hxx>
20 #include <Prs3d_LineAspect.hxx>
21 #include <Graphic3d_AspectLine3d.hxx>
22 #include <Graphic3d_Structure.hxx>
23 #include <TColgp_Array1OfPnt.hxx>
24 #include <SelectMgr_EntityOwner.hxx>
25 #include <Select3D_SensitiveCircle.hxx>
26 #include <StdPrs_DeflectionCurve.hxx>
28 #include <Geom_Circle.hxx>
29 #include <GeomAdaptor_Curve.hxx>
30 #include <GC_MakeArcOfCircle.hxx>
31 #include <Quantity_Color.hxx>
32 #include <AIS_GraphicTool.hxx>
34 //=======================================================================
35 //function : AIS_Circle
37 //=======================================================================
38 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent):
39 AIS_InteractiveObject(PrsMgr_TOP_AllView),
40 myComponent(aComponent),
43 myCircleIsArc(Standard_False),
44 myIsFilledCircleSens (Standard_False)
48 //=======================================================================
49 //function : AIS_Circle
51 //=======================================================================
52 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& theComponent,
53 const Standard_Real theUStart,
54 const Standard_Real theUEnd,
55 const Standard_Boolean theIsFilledCircleSens)
56 : AIS_InteractiveObject(PrsMgr_TOP_AllView),
57 myComponent (theComponent),
60 myCircleIsArc (Standard_True),
61 myIsFilledCircleSens (theIsFilledCircleSens)
65 //=======================================================================
68 //=======================================================================
69 void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
70 const Handle(Prs3d_Presentation)& aPresentation,
71 const Standard_Integer /*aMode*/)
73 aPresentation->Clear();
75 aPresentation->SetDisplayPriority(5);
77 if (myCircleIsArc) ComputeArc(aPresentation);
78 else ComputeCircle(aPresentation);
82 //=======================================================================
85 //=======================================================================
87 void AIS_Circle::Compute(const Handle(Prs3d_Projector)& aProjector,
88 const Handle(Geom_Transformation)& aTransformation,
89 const Handle(Prs3d_Presentation)& aPresentation)
91 // Standard_NotImplemented::Raise("AIS_Circle::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
92 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
95 //=======================================================================
96 //function : ComputeSelection
98 //=======================================================================
100 void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
101 const Standard_Integer /*aMode*/)
104 if (myCircleIsArc) ComputeArcSelection(aSelection);
105 else ComputeCircleSelection(aSelection);
110 //=======================================================================
111 //function : SetColor
113 //=======================================================================
115 void AIS_Circle::SetColor(const Quantity_NameOfColor aCol)
117 SetColor(Quantity_Color(aCol));
120 //=======================================================================
121 //function : SetColor
123 //=======================================================================
125 void AIS_Circle::SetColor(const Quantity_Color &aCol)
127 hasOwnColor=Standard_True;
130 Standard_Real WW = HasWidth() ? myOwnWidth :
131 myDrawer->HasLink() ?
132 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) :
135 if (!myDrawer->HasOwnLineAspect ())
136 myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
138 myDrawer->LineAspect()->SetColor(aCol);
143 //=======================================================================
144 //function : SetWidth
146 //=======================================================================
147 void AIS_Circle::SetWidth(const Standard_Real aValue)
151 if (!myDrawer->HasOwnLineAspect ()) {
152 Quantity_Color CC = Quantity_NOC_YELLOW;
153 if( HasColor() ) CC = myOwnColor;
154 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
155 myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
157 myDrawer->LineAspect()->SetWidth(aValue);
161 //=======================================================================
162 //function : UnsetColor
164 //=======================================================================
165 void AIS_Circle::UnsetColor()
167 hasOwnColor = Standard_False;
169 Handle(Prs3d_LineAspect) NullAsp;
171 if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
173 Quantity_Color CC = Quantity_NOC_YELLOW;;
174 if( HasColor() ) CC = myOwnColor;
175 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
176 myDrawer->LineAspect()->SetColor(CC);
181 //=======================================================================
182 //function : UnsetWidth
184 //=======================================================================
185 void AIS_Circle::UnsetWidth()
187 Handle(Prs3d_LineAspect) NullAsp;
189 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
191 Standard_Real WW = myDrawer->HasLink() ? AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.;
192 myDrawer->LineAspect()->SetWidth(WW);
197 //=======================================================================
198 //function : ComputeCircle
200 //=======================================================================
201 void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation)
204 GeomAdaptor_Curve curv(myComponent);
205 Standard_Real prevdev = myDrawer->DeviationCoefficient();
206 myDrawer->SetDeviationCoefficient(1.e-5);
207 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
208 myDrawer->SetDeviationCoefficient(prevdev);
212 //=======================================================================
213 //function : ComputeArc
216 //=======================================================================
217 void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation)
219 GeomAdaptor_Curve curv(myComponent,myUStart,myUEnd);
220 Standard_Real prevdev = myDrawer->DeviationCoefficient();
221 myDrawer->SetDeviationCoefficient(1.e-5);
222 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
223 myDrawer->SetDeviationCoefficient(prevdev);
226 //=======================================================================
227 //function : ComputeCircleSelection
229 //=======================================================================
231 void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection)
233 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
234 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
236 myIsFilledCircleSens);
237 aSelection->Add(seg);
239 //=======================================================================
240 //function : ComputeArcSelection
242 //=======================================================================
244 void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
248 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
249 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
252 myIsFilledCircleSens);
253 aSelection->Add(seg);
256 //=======================================================================
258 //purpose : to avoid warning
259 //=======================================================================
260 void AIS_Circle::Compute(const Handle(Prs3d_Projector)&,
261 const Handle(Prs3d_Presentation)&)