b311480e |
1 | // Created on: 1997-01-21 |
2 | // Created by: Prestataire Christiane ARMAND |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <AIS_Circle.hxx> |
87432b82 |
18 | |
42cf5bc1 |
19 | #include <AIS_GraphicTool.hxx> |
7fd59977 |
20 | #include <Aspect_TypeOfLine.hxx> |
42cf5bc1 |
21 | #include <GC_MakeArcOfCircle.hxx> |
22 | #include <Geom_Circle.hxx> |
23 | #include <Geom_Transformation.hxx> |
24 | #include <GeomAdaptor_Curve.hxx> |
7fd59977 |
25 | #include <Graphic3d_AspectLine3d.hxx> |
26 | #include <Graphic3d_Structure.hxx> |
42cf5bc1 |
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> |
7fd59977 |
33 | #include <SelectMgr_EntityOwner.hxx> |
f751596e |
34 | #include <SelectMgr_Selection.hxx> |
42cf5bc1 |
35 | #include <Standard_Type.hxx> |
7fd59977 |
36 | #include <StdPrs_DeflectionCurve.hxx> |
42cf5bc1 |
37 | #include <TColgp_Array1OfPnt.hxx> |
7fd59977 |
38 | #include <TopoDS.hxx> |
7fd59977 |
39 | |
92efcf78 |
40 | IMPLEMENT_STANDARD_RTTIEXT(AIS_Circle,AIS_InteractiveObject) |
41 | |
7fd59977 |
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.), |
c6541a0c |
50 | myUEnd(2*M_PI), |
9e8804b6 |
51 | myCircleIsArc(Standard_False), |
52 | myIsFilledCircleSens (Standard_False) |
7fd59977 |
53 | { |
54 | } |
55 | |
56 | //======================================================================= |
57 | //function : AIS_Circle |
58 | //purpose : |
59 | //======================================================================= |
9e8804b6 |
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) |
7fd59977 |
70 | { |
7fd59977 |
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 | { |
7fd59977 |
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 | |
857ffd5e |
93 | void AIS_Circle::Compute(const Handle(Prs3d_Projector)& aProjector, |
94 | const Handle(Geom_Transformation)& aTransformation, |
95 | const Handle(Prs3d_Presentation)& aPresentation) |
7fd59977 |
96 | { |
9775fa61 |
97 | // throw Standard_NotImplemented("AIS_Circle::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)"); |
7fd59977 |
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 | |
226fce20 |
115 | //======================================================================= |
116 | //function : replaceWithNewLineAspect |
117 | //purpose : |
118 | //======================================================================= |
119 | void AIS_Circle::replaceWithNewLineAspect (const Handle(Prs3d_LineAspect)& theAspect) |
120 | { |
121 | if (!myDrawer->HasLink()) |
122 | { |
123 | myDrawer->SetLineAspect (theAspect); |
124 | return; |
125 | } |
126 | |
127 | const Handle(Graphic3d_AspectLine3d) anAspectOld = myDrawer->LineAspect()->Aspect(); |
128 | const Handle(Graphic3d_AspectLine3d) anAspectNew = !theAspect.IsNull() ? theAspect->Aspect() : myDrawer->Link()->LineAspect()->Aspect(); |
129 | if (anAspectNew != anAspectOld) |
130 | { |
131 | myDrawer->SetLineAspect (theAspect); |
132 | Graphic3d_MapOfAspectsToAspects aReplaceMap; |
133 | aReplaceMap.Bind (anAspectOld, anAspectNew); |
134 | replaceAspects (aReplaceMap); |
135 | } |
136 | } |
137 | |
7fd59977 |
138 | //======================================================================= |
139 | //function : SetColor |
140 | //purpose : |
141 | //======================================================================= |
142 | |
143 | void AIS_Circle::SetColor(const Quantity_Color &aCol) |
7fd59977 |
144 | { |
145 | hasOwnColor=Standard_True; |
f838dac4 |
146 | myDrawer->SetColor (aCol); |
7fd59977 |
147 | |
226fce20 |
148 | if (!myDrawer->HasOwnLineAspect()) |
149 | { |
150 | Standard_Real WW = HasWidth() ? myOwnWidth : |
151 | myDrawer->HasLink() ? |
152 | AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : |
153 | 1.; |
154 | replaceWithNewLineAspect (new Prs3d_LineAspect (aCol, Aspect_TOL_SOLID, WW)); |
155 | } |
7fd59977 |
156 | else |
226fce20 |
157 | { |
7fd59977 |
158 | myDrawer->LineAspect()->SetColor(aCol); |
226fce20 |
159 | SynchronizeAspects(); |
160 | } |
7fd59977 |
161 | } |
162 | |
7fd59977 |
163 | //======================================================================= |
164 | //function : SetWidth |
165 | //purpose : |
166 | //======================================================================= |
167 | void AIS_Circle::SetWidth(const Standard_Real aValue) |
168 | { |
226fce20 |
169 | myOwnWidth = (Standard_ShortReal )aValue; |
7fd59977 |
170 | |
226fce20 |
171 | if (!myDrawer->HasOwnLineAspect()) |
172 | { |
6262338c |
173 | Quantity_Color CC = Quantity_NOC_YELLOW; |
f838dac4 |
174 | if( HasColor() ) CC = myDrawer->Color(); |
6262338c |
175 | else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC); |
226fce20 |
176 | replaceWithNewLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue)); |
177 | } |
178 | else |
179 | { |
7fd59977 |
180 | myDrawer->LineAspect()->SetWidth(aValue); |
226fce20 |
181 | SynchronizeAspects(); |
182 | } |
7fd59977 |
183 | } |
184 | |
185 | |
186 | //======================================================================= |
187 | //function : UnsetColor |
188 | //purpose : |
189 | //======================================================================= |
190 | void AIS_Circle::UnsetColor() |
191 | { |
192 | hasOwnColor = Standard_False; |
193 | |
226fce20 |
194 | if (!HasWidth()) |
195 | { |
196 | replaceWithNewLineAspect (Handle(Prs3d_LineAspect)()); |
197 | } |
198 | else |
199 | { |
6262338c |
200 | Quantity_Color CC = Quantity_NOC_YELLOW;; |
f838dac4 |
201 | if( HasColor() ) CC = myDrawer->Color(); |
6262338c |
202 | else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); |
7fd59977 |
203 | myDrawer->LineAspect()->SetColor(CC); |
f838dac4 |
204 | myDrawer->SetColor (CC); |
226fce20 |
205 | SynchronizeAspects(); |
b8ddfc2f |
206 | } |
7fd59977 |
207 | } |
208 | |
209 | //======================================================================= |
210 | //function : UnsetWidth |
211 | //purpose : |
212 | //======================================================================= |
213 | void AIS_Circle::UnsetWidth() |
214 | { |
226fce20 |
215 | if (!HasColor()) |
216 | { |
217 | replaceWithNewLineAspect (Handle(Prs3d_LineAspect)()); |
218 | } |
219 | else |
220 | { |
221 | Standard_ShortReal WW = myDrawer->HasLink() ? (Standard_ShortReal )AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.0f; |
7fd59977 |
222 | myDrawer->LineAspect()->SetWidth(WW); |
223 | myOwnWidth = WW; |
224 | } |
225 | } |
226 | |
227 | //======================================================================= |
228 | //function : ComputeCircle |
229 | //purpose : |
230 | //======================================================================= |
231 | void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation) |
232 | { |
233 | |
234 | GeomAdaptor_Curve curv(myComponent); |
235 | Standard_Real prevdev = myDrawer->DeviationCoefficient(); |
236 | myDrawer->SetDeviationCoefficient(1.e-5); |
7fd59977 |
237 | StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer); |
7fd59977 |
238 | myDrawer->SetDeviationCoefficient(prevdev); |
239 | |
240 | } |
241 | |
242 | //======================================================================= |
243 | //function : ComputeArc |
244 | |
245 | //purpose : |
246 | //======================================================================= |
247 | void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation) |
248 | { |
7fd59977 |
249 | GeomAdaptor_Curve curv(myComponent,myUStart,myUEnd); |
250 | Standard_Real prevdev = myDrawer->DeviationCoefficient(); |
251 | myDrawer->SetDeviationCoefficient(1.e-5); |
7fd59977 |
252 | StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer); |
7fd59977 |
253 | myDrawer->SetDeviationCoefficient(prevdev); |
7fd59977 |
254 | } |
255 | |
256 | //======================================================================= |
257 | //function : ComputeCircleSelection |
258 | //purpose : |
259 | //======================================================================= |
260 | |
261 | void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection) |
262 | { |
263 | Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this); |
9e8804b6 |
264 | Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown, |
265 | myComponent, |
266 | myIsFilledCircleSens); |
7fd59977 |
267 | aSelection->Add(seg); |
268 | } |
269 | //======================================================================= |
270 | //function : ComputeArcSelection |
271 | //purpose : |
272 | //======================================================================= |
273 | |
274 | void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection) |
275 | { |
276 | |
277 | |
278 | Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this); |
9e8804b6 |
279 | Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown, |
280 | myComponent, |
281 | myUStart, myUEnd, |
282 | myIsFilledCircleSens); |
7fd59977 |
283 | aSelection->Add(seg); |
284 | } |
7fd59977 |
285 | |
286 | //======================================================================= |
287 | //function : Compute |
288 | //purpose : to avoid warning |
289 | //======================================================================= |
290 | void AIS_Circle::Compute(const Handle(Prs3d_Projector)&, |
291 | const Handle(Prs3d_Presentation)&) |
292 | { |
293 | } |