0025695: Visualization, AIS_InteractiveContext - define default HilightMode
[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
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>
38 #include <TopoDS.hxx>
39
40 IMPLEMENT_STANDARD_RTTIEXT(AIS_Circle,AIS_InteractiveObject)
41
42 //=======================================================================
43 //function : AIS_Circle
44 //purpose  : 
45 //=======================================================================
46 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent):
47 AIS_InteractiveObject(PrsMgr_TOP_AllView),
48 myComponent(aComponent),
49 myUStart(0.),
50 myUEnd(2*M_PI),
51 myCircleIsArc(Standard_False),
52 myIsFilledCircleSens (Standard_False)
53 {
54 }
55
56 //=======================================================================
57 //function : AIS_Circle
58 //purpose  : 
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),
66   myUStart (theUStart),
67   myUEnd (theUEnd),
68   myCircleIsArc (Standard_True),
69   myIsFilledCircleSens (theIsFilledCircleSens)
70 {
71 }
72
73 //=======================================================================
74 //function : Compute
75 //purpose  : 
76 //=======================================================================
77 void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
78                          const Handle(Prs3d_Presentation)& aPresentation, 
79                          const Standard_Integer /*aMode*/)
80 {
81   aPresentation->SetDisplayPriority(5);
82
83   if (myCircleIsArc) ComputeArc(aPresentation);
84   else ComputeCircle(aPresentation);
85
86 }
87
88 //=======================================================================
89 //function : Compute
90 //purpose  : 
91 //=======================================================================
92
93 void AIS_Circle::Compute(const Handle(Prs3d_Projector)& aProjector,
94                          const Handle(Geom_Transformation)& aTransformation,
95                          const Handle(Prs3d_Presentation)& aPresentation)
96 {
97 // Standard_NotImplemented::Raise("AIS_Circle::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
98   PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
99 }
100
101 //=======================================================================
102 //function : ComputeSelection
103 //purpose  : 
104 //=======================================================================
105
106 void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
107                                   const Standard_Integer /*aMode*/)
108 {
109
110   if (myCircleIsArc) ComputeArcSelection(aSelection);
111   else ComputeCircleSelection(aSelection);
112
113 }
114
115
116 //=======================================================================
117 //function : SetColor
118 //purpose  : 
119 //=======================================================================
120
121 void AIS_Circle::SetColor(const Quantity_NameOfColor aCol)
122 {
123   SetColor(Quantity_Color(aCol));
124 }
125
126 //=======================================================================
127 //function : SetColor
128 //purpose  : 
129 //=======================================================================
130
131 void AIS_Circle::SetColor(const Quantity_Color &aCol)
132 {
133   hasOwnColor=Standard_True;
134   myDrawer->SetColor (aCol);
135
136   Standard_Real WW = HasWidth() ? myOwnWidth :
137                                   myDrawer->HasLink() ?
138                                   AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) :
139                                   1.;
140
141   if (!myDrawer->HasOwnLineAspect ())
142     myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
143   else
144     myDrawer->LineAspect()->SetColor(aCol);
145 }
146
147
148
149 //=======================================================================
150 //function : SetWidth 
151 //purpose  : 
152 //=======================================================================
153 void AIS_Circle::SetWidth(const Standard_Real aValue)
154 {
155   myOwnWidth=aValue;
156
157   if (!myDrawer->HasOwnLineAspect ()) {
158     Quantity_Color CC = Quantity_NOC_YELLOW;
159     if( HasColor() ) CC = myDrawer->Color();
160     else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
161     myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
162   } else
163     myDrawer->LineAspect()->SetWidth(aValue);
164 }
165
166
167 //=======================================================================
168 //function : UnsetColor 
169 //purpose  : 
170 //=======================================================================
171 void AIS_Circle::UnsetColor()
172 {
173   hasOwnColor = Standard_False;
174
175   Handle(Prs3d_LineAspect) NullAsp;
176
177   if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
178   else{
179     Quantity_Color CC = Quantity_NOC_YELLOW;;
180     if( HasColor() ) CC = myDrawer->Color();
181     else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
182     myDrawer->LineAspect()->SetColor(CC);
183     myDrawer->SetColor (CC);
184   }
185 }
186
187 //=======================================================================
188 //function : UnsetWidth 
189 //purpose  : 
190 //=======================================================================
191 void AIS_Circle::UnsetWidth()
192 {
193   Handle(Prs3d_LineAspect) NullAsp;
194
195   if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
196   else{
197    Standard_Real WW = myDrawer->HasLink() ? AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.;
198    myDrawer->LineAspect()->SetWidth(WW);
199    myOwnWidth = WW;
200   }
201 }
202
203 //=======================================================================
204 //function : ComputeCircle
205 //purpose  : 
206 //=======================================================================
207 void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation)
208 {
209
210   GeomAdaptor_Curve curv(myComponent);
211   Standard_Real prevdev = myDrawer->DeviationCoefficient();
212   myDrawer->SetDeviationCoefficient(1.e-5);
213   StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
214   myDrawer->SetDeviationCoefficient(prevdev);
215
216 }
217
218 //=======================================================================
219 //function : ComputeArc
220
221 //purpose  : 
222 //=======================================================================
223 void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation)
224 {
225   GeomAdaptor_Curve curv(myComponent,myUStart,myUEnd);
226   Standard_Real prevdev = myDrawer->DeviationCoefficient();
227   myDrawer->SetDeviationCoefficient(1.e-5);
228   StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
229   myDrawer->SetDeviationCoefficient(prevdev);
230 }
231
232 //=======================================================================
233 //function : ComputeCircleSelection
234 //purpose  : 
235 //=======================================================================
236
237 void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection)
238 {
239   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
240   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
241                                                                        myComponent,
242                                                                        myIsFilledCircleSens);
243   aSelection->Add(seg);
244 }
245 //=======================================================================
246 //function : ComputeArcSelection
247 //purpose  : 
248 //=======================================================================
249
250 void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
251 {
252
253
254   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
255   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
256                                                                        myComponent,
257                                                                        myUStart, myUEnd,
258                                                                        myIsFilledCircleSens);
259   aSelection->Add(seg);
260 }
261
262 //=======================================================================
263 //function : Compute
264 //purpose  : to avoid warning
265 //=======================================================================
266 void AIS_Circle::Compute(const Handle(Prs3d_Projector)&, 
267                          const Handle(Prs3d_Presentation)&)
268 {
269 }