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