0023663: Removing 2D viewer library
[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-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 //GER61351              //GG_171199     Enable to set an object RGB color instead a restricted object NameOfColor.
23
24 #include <AIS_Circle.ixx>
25 #include <Aspect_TypeOfLine.hxx>
26 #include <Prs3d_Drawer.hxx>
27 #include <Prs3d_LineAspect.hxx>
28 #include <Graphic3d_AspectLine3d.hxx>
29 #include <Graphic3d_Structure.hxx>
30 #include <TColgp_Array1OfPnt.hxx>
31 #include <SelectMgr_EntityOwner.hxx>
32 #include <Select3D_SensitiveCircle.hxx>
33 #include <StdPrs_DeflectionCurve.hxx>
34 #include <TopoDS.hxx>
35 #include <Geom_Circle.hxx>
36 #include <GeomAdaptor_Curve.hxx>
37 #include <AIS_Drawer.hxx>
38 #include <GC_MakeArcOfCircle.hxx>
39 #include <Quantity_Color.hxx>
40 #include <AIS_GraphicTool.hxx>
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 {
53 }
54
55 //=======================================================================
56 //function : AIS_Circle
57 //purpose  : 
58 //=======================================================================
59 AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent,
60                        const Standard_Real aUStart,
61                        const Standard_Real aUEnd,
62                        const Standard_Boolean aSens):
63        AIS_InteractiveObject(PrsMgr_TOP_AllView)
64 {
65   myComponent = aComponent;
66   myUStart    = aUStart;
67   myUEnd      = aUEnd;
68   mySens      = aSens;
69   myCircleIsArc = Standard_True;
70 }
71
72 //=======================================================================
73 //function : Compute
74 //purpose  : 
75 //=======================================================================
76 void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
77                          const Handle(Prs3d_Presentation)& aPresentation, 
78                          const Standard_Integer /*aMode*/)
79 {
80   aPresentation->Clear();
81
82   aPresentation->SetDisplayPriority(5);
83
84   if (myCircleIsArc) ComputeArc(aPresentation);
85   else ComputeCircle(aPresentation);
86
87 }
88
89 //=======================================================================
90 //function : Compute
91 //purpose  : 
92 //=======================================================================
93
94 void AIS_Circle::Compute(const Handle_Prs3d_Projector& aProjector,
95                          const Handle_Geom_Transformation& aTransformation,
96                          const Handle_Prs3d_Presentation& aPresentation)
97 {
98 // Standard_NotImplemented::Raise("AIS_Circle::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
99   PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
100 }
101
102 //=======================================================================
103 //function : ComputeSelection
104 //purpose  : 
105 //=======================================================================
106
107 void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
108                                   const Standard_Integer /*aMode*/)
109 {
110
111   if (myCircleIsArc) ComputeArcSelection(aSelection);
112   else ComputeCircleSelection(aSelection);
113
114 }
115
116
117 //=======================================================================
118 //function : SetColor
119 //purpose  : 
120 //=======================================================================
121
122 void AIS_Circle::SetColor(const Quantity_NameOfColor aCol)
123 {
124   SetColor(Quantity_Color(aCol));
125 }
126
127 //=======================================================================
128 //function : SetColor
129 //purpose  : 
130 //=======================================================================
131
132 void AIS_Circle::SetColor(const Quantity_Color &aCol)
133 {
134   hasOwnColor=Standard_True;
135   myOwnColor=aCol;
136
137   Standard_Real WW = HasWidth()? myOwnWidth:
138                                  AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
139
140   if (!myDrawer->HasLineAspect ())
141     myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
142   else
143     myDrawer->LineAspect()->SetColor(aCol);
144 }
145
146
147
148 //=======================================================================
149 //function : SetWidth 
150 //purpose  : 
151 //=======================================================================
152 void AIS_Circle::SetWidth(const Standard_Real aValue)
153 {
154   myOwnWidth=aValue;
155
156   if (!myDrawer->HasLineAspect ()) {
157     Quantity_Color CC;
158     if( HasColor() ) CC = myOwnColor;
159     else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
160     myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
161   } else
162     myDrawer->LineAspect()->SetWidth(aValue);
163 }
164
165
166 //=======================================================================
167 //function : UnsetColor 
168 //purpose  : 
169 //=======================================================================
170 void AIS_Circle::UnsetColor()
171 {
172   hasOwnColor = Standard_False;
173
174   Handle(Prs3d_LineAspect) NullAsp;
175
176   if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
177   else{
178     Quantity_Color CC;
179     if( HasColor() ) CC = myOwnColor;
180     else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
181     myDrawer->LineAspect()->SetColor(CC);
182     myOwnColor = CC;
183   }
184 }
185
186 //=======================================================================
187 //function : UnsetWidth 
188 //purpose  : 
189 //=======================================================================
190 void AIS_Circle::UnsetWidth()
191 {
192   Handle(Prs3d_LineAspect) NullAsp;
193
194   if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
195   else{
196    Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
197    myDrawer->LineAspect()->SetWidth(WW);
198    myOwnWidth = WW;
199   }
200 }
201
202 //=======================================================================
203 //function : ComputeCircle
204 //purpose  : 
205 //=======================================================================
206 void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation)
207 {
208
209   GeomAdaptor_Curve curv(myComponent);
210   Standard_Real prevdev = myDrawer->DeviationCoefficient();
211   myDrawer->SetDeviationCoefficient(1.e-5);
212   StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
213   myDrawer->SetDeviationCoefficient(prevdev);
214
215 }
216
217 //=======================================================================
218 //function : ComputeArc
219
220 //purpose  : 
221 //=======================================================================
222 void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation)
223 {
224   GeomAdaptor_Curve curv(myComponent,myUStart,myUEnd);
225   Standard_Real prevdev = myDrawer->DeviationCoefficient();
226   myDrawer->SetDeviationCoefficient(1.e-5);
227   StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer);
228   myDrawer->SetDeviationCoefficient(prevdev);
229 }
230
231 //=======================================================================
232 //function : ComputeCircleSelection
233 //purpose  : 
234 //=======================================================================
235
236 void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection)
237 {
238   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
239   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle(eown,
240                                                                        myComponent);
241   aSelection->Add(seg);
242 }
243 //=======================================================================
244 //function : ComputeArcSelection
245 //purpose  : 
246 //=======================================================================
247
248 void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection)
249 {
250
251
252   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
253   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle(eown,
254                                                                       myComponent,myUStart,myUEnd);
255   aSelection->Add(seg);
256 }
257
258 //=======================================================================
259 //function : Compute
260 //purpose  : to avoid warning
261 //=======================================================================
262 void AIS_Circle::Compute(const Handle(Prs3d_Projector)&, 
263                          const Handle(Prs3d_Presentation)&)
264 {
265 }