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 <AIS_Drawer.hxx>
31 #include <GC_MakeArcOfCircle.hxx>
32 #include <Quantity_Color.hxx>
33 #include <AIS_GraphicTool.hxx>
35 //=======================================================================
36 //function : AIS_Circle
38 //=======================================================================
39 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent):
40 AIS_InteractiveObject(PrsMgr_TOP_AllView),
41 myComponent(aComponent),
44 myCircleIsArc(Standard_False),
45 myIsFilledCircleSens (Standard_False)
49 //=======================================================================
50 //function : AIS_Circle
52 //=======================================================================
53 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& theComponent,
54 const Standard_Real theUStart,
55 const Standard_Real theUEnd,
56 const Standard_Boolean theIsFilledCircleSens)
57 : AIS_InteractiveObject(PrsMgr_TOP_AllView),
58 myComponent (theComponent),
61 myCircleIsArc (Standard_True),
62 myIsFilledCircleSens (theIsFilledCircleSens)
66 //=======================================================================
69 //=======================================================================
70 void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
71 const Handle(Prs3d_Presentation)& aPresentation,
72 const Standard_Integer /*aMode*/)
74 aPresentation->Clear();
76 aPresentation->SetDisplayPriority(5);
78 if (myCircleIsArc) ComputeArc(aPresentation);
79 else ComputeCircle(aPresentation);
83 //=======================================================================
86 //=======================================================================
88 void AIS_Circle::Compute(const Handle(Prs3d_Projector)& aProjector,
89 const Handle(Geom_Transformation)& aTransformation,
90 const Handle(Prs3d_Presentation)& aPresentation)
92 // Standard_NotImplemented::Raise("AIS_Circle::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
93 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
96 //=======================================================================
97 //function : ComputeSelection
99 //=======================================================================
101 void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
102 const Standard_Integer /*aMode*/)
105 if (myCircleIsArc) ComputeArcSelection(aSelection);
106 else ComputeCircleSelection(aSelection);
111 //=======================================================================
112 //function : SetColor
114 //=======================================================================
116 void AIS_Circle::SetColor(const Quantity_NameOfColor aCol)
118 SetColor(Quantity_Color(aCol));
121 //=======================================================================
122 //function : SetColor
124 //=======================================================================
126 void AIS_Circle::SetColor(const Quantity_Color &aCol)
128 hasOwnColor=Standard_True;
131 Standard_Real WW = HasWidth()? myOwnWidth:
132 AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
134 if (!myDrawer->HasLineAspect ())
135 myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
137 myDrawer->LineAspect()->SetColor(aCol);
142 //=======================================================================
143 //function : SetWidth
145 //=======================================================================
146 void AIS_Circle::SetWidth(const Standard_Real aValue)
150 if (!myDrawer->HasLineAspect ()) {
152 if( HasColor() ) CC = myOwnColor;
153 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
154 myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
156 myDrawer->LineAspect()->SetWidth(aValue);
160 //=======================================================================
161 //function : UnsetColor
163 //=======================================================================
164 void AIS_Circle::UnsetColor()
166 hasOwnColor = Standard_False;
168 Handle(Prs3d_LineAspect) NullAsp;
170 if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
173 if( HasColor() ) CC = myOwnColor;
174 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
175 myDrawer->LineAspect()->SetColor(CC);
180 //=======================================================================
181 //function : UnsetWidth
183 //=======================================================================
184 void AIS_Circle::UnsetWidth()
186 Handle(Prs3d_LineAspect) NullAsp;
188 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
190 Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
191 myDrawer->LineAspect()->SetWidth(WW);
196 //=======================================================================
197 //function : ComputeCircle
199 //=======================================================================
200 void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation)
203 GeomAdaptor_Curve curv(myComponent);
204 Standard_Real prevdev = myDrawer->DeviationCoefficient();
205 myDrawer->SetDeviationCoefficient(1.e-5);
206 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
207 myDrawer->SetDeviationCoefficient(prevdev);
211 //=======================================================================
212 //function : ComputeArc
215 //=======================================================================
216 void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation)
218 GeomAdaptor_Curve curv(myComponent,myUStart,myUEnd);
219 Standard_Real prevdev = myDrawer->DeviationCoefficient();
220 myDrawer->SetDeviationCoefficient(1.e-5);
221 StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
222 myDrawer->SetDeviationCoefficient(prevdev);
225 //=======================================================================
226 //function : ComputeCircleSelection
228 //=======================================================================
230 void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection)
232 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
233 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
235 myIsFilledCircleSens);
236 aSelection->Add(seg);
238 //=======================================================================
239 //function : ComputeArcSelection
241 //=======================================================================
243 void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
247 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
248 Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
251 myIsFilledCircleSens);
252 aSelection->Add(seg);
255 //=======================================================================
257 //purpose : to avoid warning
258 //=======================================================================
259 void AIS_Circle::Compute(const Handle(Prs3d_Projector)&,
260 const Handle(Prs3d_Presentation)&)