0027724: Visualization, TKV3d - Null handle check missing in AIS_InteractiveContext...
[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->Clear();
82
83   aPresentation->SetDisplayPriority(5);
84
85   if (myCircleIsArc) ComputeArc(aPresentation);
86   else ComputeCircle(aPresentation);
87
88 }
89
90 //=======================================================================
91 //function : Compute
92 //purpose  : 
93 //=======================================================================
94
95 void AIS_Circle::Compute(const Handle(Prs3d_Projector)& aProjector,
96                          const Handle(Geom_Transformation)& aTransformation,
97                          const Handle(Prs3d_Presentation)& aPresentation)
98 {
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 ) ;
101 }
102
103 //=======================================================================
104 //function : ComputeSelection
105 //purpose  : 
106 //=======================================================================
107
108 void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
109                                   const Standard_Integer /*aMode*/)
110 {
111
112   if (myCircleIsArc) ComputeArcSelection(aSelection);
113   else ComputeCircleSelection(aSelection);
114
115 }
116
117
118 //=======================================================================
119 //function : SetColor
120 //purpose  : 
121 //=======================================================================
122
123 void AIS_Circle::SetColor(const Quantity_NameOfColor aCol)
124 {
125   SetColor(Quantity_Color(aCol));
126 }
127
128 //=======================================================================
129 //function : SetColor
130 //purpose  : 
131 //=======================================================================
132
133 void AIS_Circle::SetColor(const Quantity_Color &aCol)
134 {
135   hasOwnColor=Standard_True;
136   myOwnColor=aCol;
137
138   Standard_Real WW = HasWidth() ? myOwnWidth :
139                                   myDrawer->HasLink() ?
140                                   AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) :
141                                   1.;
142
143   if (!myDrawer->HasOwnLineAspect ())
144     myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
145   else
146     myDrawer->LineAspect()->SetColor(aCol);
147 }
148
149
150
151 //=======================================================================
152 //function : SetWidth 
153 //purpose  : 
154 //=======================================================================
155 void AIS_Circle::SetWidth(const Standard_Real aValue)
156 {
157   myOwnWidth=aValue;
158
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));
164   } else
165     myDrawer->LineAspect()->SetWidth(aValue);
166 }
167
168
169 //=======================================================================
170 //function : UnsetColor 
171 //purpose  : 
172 //=======================================================================
173 void AIS_Circle::UnsetColor()
174 {
175   hasOwnColor = Standard_False;
176
177   Handle(Prs3d_LineAspect) NullAsp;
178
179   if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
180   else{
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);
185     myOwnColor = CC;
186   }
187 }
188
189 //=======================================================================
190 //function : UnsetWidth 
191 //purpose  : 
192 //=======================================================================
193 void AIS_Circle::UnsetWidth()
194 {
195   Handle(Prs3d_LineAspect) NullAsp;
196
197   if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
198   else{
199    Standard_Real WW = myDrawer->HasLink() ? AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.;
200    myDrawer->LineAspect()->SetWidth(WW);
201    myOwnWidth = WW;
202   }
203 }
204
205 //=======================================================================
206 //function : ComputeCircle
207 //purpose  : 
208 //=======================================================================
209 void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation)
210 {
211
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);
217
218 }
219
220 //=======================================================================
221 //function : ComputeArc
222
223 //purpose  : 
224 //=======================================================================
225 void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation)
226 {
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);
232 }
233
234 //=======================================================================
235 //function : ComputeCircleSelection
236 //purpose  : 
237 //=======================================================================
238
239 void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection)
240 {
241   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
242   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
243                                                                        myComponent,
244                                                                        myIsFilledCircleSens);
245   aSelection->Add(seg);
246 }
247 //=======================================================================
248 //function : ComputeArcSelection
249 //purpose  : 
250 //=======================================================================
251
252 void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
253 {
254
255
256   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
257   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
258                                                                        myComponent,
259                                                                        myUStart, myUEnd,
260                                                                        myIsFilledCircleSens);
261   aSelection->Add(seg);
262 }
263
264 //=======================================================================
265 //function : Compute
266 //purpose  : to avoid warning
267 //=======================================================================
268 void AIS_Circle::Compute(const Handle(Prs3d_Projector)&, 
269                          const Handle(Prs3d_Presentation)&)
270 {
271 }