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