b311480e |
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 | |
7fd59977 |
21 | |
22 | #define GER61351 //GG_171199 Enable to set an object RGB color |
23 | // instead a restricted object NameOfColor. |
24 | |
25 | #include <AIS_Circle.ixx> |
26 | #include <Aspect_TypeOfLine.hxx> |
27 | #include <Prs3d_Drawer.hxx> |
28 | #include <Prs3d_LineAspect.hxx> |
29 | #include <Graphic3d_ArrayOfPrimitives.hxx> |
30 | #include <Graphic3d_AspectLine3d.hxx> |
31 | #include <Graphic3d_Structure.hxx> |
32 | #include <TColgp_Array1OfPnt.hxx> |
33 | #include <SelectMgr_EntityOwner.hxx> |
34 | #include <Select3D_SensitiveCircle.hxx> |
35 | #include <StdPrs_DeflectionCurve.hxx> |
36 | #include <TopoDS.hxx> |
37 | #include <Geom_Circle.hxx> |
38 | #include <GeomAdaptor_Curve.hxx> |
39 | #include <AIS_Drawer.hxx> |
40 | #include <GC_MakeArcOfCircle.hxx> |
41 | #include <Quantity_Color.hxx> |
42 | #include <AIS_GraphicTool.hxx> |
43 | |
44 | //======================================================================= |
45 | //function : AIS_Circle |
46 | //purpose : |
47 | //======================================================================= |
48 | AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent): |
49 | AIS_InteractiveObject(PrsMgr_TOP_AllView), |
50 | myComponent(aComponent), |
51 | myUStart(0.), |
c6541a0c |
52 | myUEnd(2*M_PI), |
7fd59977 |
53 | myCircleIsArc(Standard_False) |
54 | { |
55 | } |
56 | |
57 | //======================================================================= |
58 | //function : AIS_Circle |
59 | //purpose : |
60 | //======================================================================= |
61 | AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent, |
62 | const Standard_Real aUStart, |
63 | const Standard_Real aUEnd, |
64 | const Standard_Boolean aSens): |
65 | AIS_InteractiveObject(PrsMgr_TOP_AllView) |
66 | { |
67 | myComponent = aComponent; |
68 | myUStart = aUStart; |
69 | myUEnd = aUEnd; |
70 | mySens = aSens; |
71 | myCircleIsArc = Standard_True; |
72 | } |
73 | |
74 | //======================================================================= |
75 | //function : Compute |
76 | //purpose : |
77 | //======================================================================= |
78 | void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
79 | const Handle(Prs3d_Presentation)& aPresentation, |
80 | const Standard_Integer /*aMode*/) |
81 | { |
82 | aPresentation->Clear(); |
83 | |
84 | aPresentation->SetDisplayPriority(5); |
85 | |
86 | if (myCircleIsArc) ComputeArc(aPresentation); |
87 | else ComputeCircle(aPresentation); |
88 | |
89 | } |
90 | |
91 | //======================================================================= |
92 | //function : Compute |
93 | //purpose : |
94 | //======================================================================= |
95 | |
96 | void AIS_Circle::Compute(const Handle_Prs3d_Projector& aProjector, |
97 | const Handle_Geom_Transformation& aTransformation, |
98 | const Handle_Prs3d_Presentation& aPresentation) |
99 | { |
100 | // Standard_NotImplemented::Raise("AIS_Circle::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)"); |
101 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ; |
102 | } |
103 | |
104 | //======================================================================= |
105 | //function : ComputeSelection |
106 | //purpose : |
107 | //======================================================================= |
108 | |
109 | void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, |
110 | const Standard_Integer /*aMode*/) |
111 | { |
112 | |
113 | if (myCircleIsArc) ComputeArcSelection(aSelection); |
114 | else ComputeCircleSelection(aSelection); |
115 | |
116 | } |
117 | |
118 | |
119 | //======================================================================= |
120 | //function : SetColor |
121 | //purpose : |
122 | //======================================================================= |
123 | |
124 | void AIS_Circle::SetColor(const Quantity_NameOfColor aCol) |
125 | #ifdef GER61351 |
126 | { |
127 | SetColor(Quantity_Color(aCol)); |
128 | } |
129 | |
130 | //======================================================================= |
131 | //function : SetColor |
132 | //purpose : |
133 | //======================================================================= |
134 | |
135 | void AIS_Circle::SetColor(const Quantity_Color &aCol) |
136 | #endif |
137 | { |
138 | hasOwnColor=Standard_True; |
139 | myOwnColor=aCol; |
140 | |
141 | Standard_Real WW = HasWidth()? myOwnWidth: |
142 | AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line); |
143 | |
144 | if (!myDrawer->HasLineAspect ()) |
145 | myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW)); |
146 | else |
147 | myDrawer->LineAspect()->SetColor(aCol); |
148 | } |
149 | |
150 | |
151 | |
152 | //======================================================================= |
153 | //function : SetWidth |
154 | //purpose : |
155 | //======================================================================= |
156 | void AIS_Circle::SetWidth(const Standard_Real aValue) |
157 | { |
158 | myOwnWidth=aValue; |
159 | |
160 | #ifndef GER61351 |
161 | Quantity_NameOfColor CC = |
162 | HasColor() ? myOwnColor : AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line); |
163 | #endif |
164 | |
165 | if (!myDrawer->HasLineAspect ()) { |
166 | #ifdef GER61351 |
167 | Quantity_Color CC; |
168 | if( HasColor() ) CC = myOwnColor; |
169 | else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); |
170 | #endif |
171 | myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue)); |
172 | } else |
173 | myDrawer->LineAspect()->SetWidth(aValue); |
174 | } |
175 | |
176 | |
177 | //======================================================================= |
178 | //function : UnsetColor |
179 | //purpose : |
180 | //======================================================================= |
181 | void AIS_Circle::UnsetColor() |
182 | { |
183 | hasOwnColor = Standard_False; |
184 | |
185 | Handle(Prs3d_LineAspect) NullAsp; |
186 | |
187 | if (!HasWidth()) myDrawer->SetLineAspect(NullAsp); |
188 | else{ |
189 | #ifdef GER61351 |
190 | Quantity_Color CC; |
191 | if( HasColor() ) CC = myOwnColor; |
192 | else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); |
193 | #else |
194 | Quantity_NameOfColor CC = |
195 | #endif |
196 | AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line); |
197 | myDrawer->LineAspect()->SetColor(CC); |
198 | myOwnColor = CC; |
199 | } |
200 | } |
201 | |
202 | //======================================================================= |
203 | //function : UnsetWidth |
204 | //purpose : |
205 | //======================================================================= |
206 | void AIS_Circle::UnsetWidth() |
207 | { |
208 | Handle(Prs3d_LineAspect) NullAsp; |
209 | |
210 | if (!HasColor()) myDrawer->SetLineAspect(NullAsp); |
211 | else{ |
212 | Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line); |
213 | myDrawer->LineAspect()->SetWidth(WW); |
214 | myOwnWidth = WW; |
215 | } |
216 | } |
217 | |
218 | //======================================================================= |
219 | //function : ComputeCircle |
220 | //purpose : |
221 | //======================================================================= |
222 | void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation) |
223 | { |
224 | |
225 | GeomAdaptor_Curve curv(myComponent); |
226 | Standard_Real prevdev = myDrawer->DeviationCoefficient(); |
227 | myDrawer->SetDeviationCoefficient(1.e-5); |
228 | Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable(); |
229 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable(); |
230 | StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer); |
231 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable(); |
232 | myDrawer->SetDeviationCoefficient(prevdev); |
233 | |
234 | } |
235 | |
236 | //======================================================================= |
237 | //function : ComputeArc |
238 | |
239 | //purpose : |
240 | //======================================================================= |
241 | void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation) |
242 | { |
243 | |
244 | GeomAdaptor_Curve curv(myComponent,myUStart,myUEnd); |
245 | Standard_Real prevdev = myDrawer->DeviationCoefficient(); |
246 | myDrawer->SetDeviationCoefficient(1.e-5); |
247 | Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable(); |
248 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable(); |
249 | StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer); |
250 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable(); |
251 | myDrawer->SetDeviationCoefficient(prevdev); |
252 | |
253 | } |
254 | |
255 | //======================================================================= |
256 | //function : ComputeCircleSelection |
257 | //purpose : |
258 | //======================================================================= |
259 | |
260 | void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection) |
261 | { |
262 | Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this); |
263 | Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle(eown, |
264 | myComponent); |
265 | aSelection->Add(seg); |
266 | } |
267 | //======================================================================= |
268 | //function : ComputeArcSelection |
269 | //purpose : |
270 | //======================================================================= |
271 | |
272 | void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection) |
273 | { |
274 | |
275 | |
276 | Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this); |
277 | Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle(eown, |
278 | myComponent,myUStart,myUEnd); |
279 | aSelection->Add(seg); |
280 | } |
281 | //======================================================================= |
282 | //function : Compute |
283 | //purpose : to avoid warning |
284 | //======================================================================= |
285 | void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager2d)&, |
286 | const Handle(Graphic2d_GraphicObject)&, |
287 | const Standard_Integer) |
288 | { |
289 | } |
290 | |
291 | //======================================================================= |
292 | //function : Compute |
293 | //purpose : to avoid warning |
294 | //======================================================================= |
295 | void AIS_Circle::Compute(const Handle(Prs3d_Projector)&, |
296 | const Handle(Prs3d_Presentation)&) |
297 | { |
298 | } |