1bc4635eeaa3eab11bade6eec56133239b25feef
[occt.git] / src / AIS / AIS_Circle.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
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>
27 #include <TopoDS.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>
34
35 //=======================================================================
36 //function : AIS_Circle
37 //purpose  : 
38 //=======================================================================
39 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent):
40 AIS_InteractiveObject(PrsMgr_TOP_AllView),
41 myComponent(aComponent),
42 myUStart(0.),
43 myUEnd(2*M_PI),
44 myCircleIsArc(Standard_False),
45 myIsFilledCircleSens (Standard_False)
46 {
47 }
48
49 //=======================================================================
50 //function : AIS_Circle
51 //purpose  : 
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),
59   myUStart (theUStart),
60   myUEnd (theUEnd),
61   myCircleIsArc (Standard_True),
62   myIsFilledCircleSens (theIsFilledCircleSens)
63 {
64 }
65
66 //=======================================================================
67 //function : Compute
68 //purpose  : 
69 //=======================================================================
70 void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
71                          const Handle(Prs3d_Presentation)& aPresentation, 
72                          const Standard_Integer /*aMode*/)
73 {
74   aPresentation->Clear();
75
76   aPresentation->SetDisplayPriority(5);
77
78   if (myCircleIsArc) ComputeArc(aPresentation);
79   else ComputeCircle(aPresentation);
80
81 }
82
83 //=======================================================================
84 //function : Compute
85 //purpose  : 
86 //=======================================================================
87
88 void AIS_Circle::Compute(const Handle(Prs3d_Projector)& aProjector,
89                          const Handle(Geom_Transformation)& aTransformation,
90                          const Handle(Prs3d_Presentation)& aPresentation)
91 {
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 ) ;
94 }
95
96 //=======================================================================
97 //function : ComputeSelection
98 //purpose  : 
99 //=======================================================================
100
101 void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
102                                   const Standard_Integer /*aMode*/)
103 {
104
105   if (myCircleIsArc) ComputeArcSelection(aSelection);
106   else ComputeCircleSelection(aSelection);
107
108 }
109
110
111 //=======================================================================
112 //function : SetColor
113 //purpose  : 
114 //=======================================================================
115
116 void AIS_Circle::SetColor(const Quantity_NameOfColor aCol)
117 {
118   SetColor(Quantity_Color(aCol));
119 }
120
121 //=======================================================================
122 //function : SetColor
123 //purpose  : 
124 //=======================================================================
125
126 void AIS_Circle::SetColor(const Quantity_Color &aCol)
127 {
128   hasOwnColor=Standard_True;
129   myOwnColor=aCol;
130
131   Standard_Real WW = HasWidth()? myOwnWidth:
132                                  AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
133
134   if (!myDrawer->HasLineAspect ())
135     myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
136   else
137     myDrawer->LineAspect()->SetColor(aCol);
138 }
139
140
141
142 //=======================================================================
143 //function : SetWidth 
144 //purpose  : 
145 //=======================================================================
146 void AIS_Circle::SetWidth(const Standard_Real aValue)
147 {
148   myOwnWidth=aValue;
149
150   if (!myDrawer->HasLineAspect ()) {
151     Quantity_Color CC;
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));
155   } else
156     myDrawer->LineAspect()->SetWidth(aValue);
157 }
158
159
160 //=======================================================================
161 //function : UnsetColor 
162 //purpose  : 
163 //=======================================================================
164 void AIS_Circle::UnsetColor()
165 {
166   hasOwnColor = Standard_False;
167
168   Handle(Prs3d_LineAspect) NullAsp;
169
170   if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
171   else{
172     Quantity_Color CC;
173     if( HasColor() ) CC = myOwnColor;
174     else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
175     myDrawer->LineAspect()->SetColor(CC);
176     myOwnColor = CC;
177   }
178 }
179
180 //=======================================================================
181 //function : UnsetWidth 
182 //purpose  : 
183 //=======================================================================
184 void AIS_Circle::UnsetWidth()
185 {
186   Handle(Prs3d_LineAspect) NullAsp;
187
188   if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
189   else{
190    Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
191    myDrawer->LineAspect()->SetWidth(WW);
192    myOwnWidth = WW;
193   }
194 }
195
196 //=======================================================================
197 //function : ComputeCircle
198 //purpose  : 
199 //=======================================================================
200 void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation)
201 {
202
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);
208
209 }
210
211 //=======================================================================
212 //function : ComputeArc
213
214 //purpose  : 
215 //=======================================================================
216 void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation)
217 {
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);
223 }
224
225 //=======================================================================
226 //function : ComputeCircleSelection
227 //purpose  : 
228 //=======================================================================
229
230 void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection)
231 {
232   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
233   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
234                                                                        myComponent,
235                                                                        myIsFilledCircleSens);
236   aSelection->Add(seg);
237 }
238 //=======================================================================
239 //function : ComputeArcSelection
240 //purpose  : 
241 //=======================================================================
242
243 void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
244 {
245
246
247   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
248   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
249                                                                        myComponent,
250                                                                        myUStart, myUEnd,
251                                                                        myIsFilledCircleSens);
252   aSelection->Add(seg);
253 }
254
255 //=======================================================================
256 //function : Compute
257 //purpose  : to avoid warning
258 //=======================================================================
259 void AIS_Circle::Compute(const Handle(Prs3d_Projector)&, 
260                          const Handle(Prs3d_Presentation)&)
261 {
262 }