b311480e |
1 | // Created on: 1998-01-27 |
2 | // Created by: Sergey ZARITCHNY |
3 | // Copyright (c) 1998-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 <Standard_NotImplemented.hxx> |
18 | |
19 | #include <AIS_MinRadiusDimension.ixx> |
20 | |
21 | #include <AIS_EllipseRadiusDimension.hxx> |
22 | #include <TCollection_ExtendedString.hxx> |
23 | |
a6eb515f |
24 | #include <Prs3d_DimensionAspect.hxx> |
7fd59977 |
25 | #include <Prs3d_ArrowAspect.hxx> |
26 | #include <Prs3d_Drawer.hxx> |
27 | #include <Prs3d_TextAspect.hxx> |
28 | #include <Prs3d_Text.hxx> |
29 | |
30 | #include <Select3D_SensitiveSegment.hxx> |
31 | #include <Select3D_SensitiveCurve.hxx> |
32 | #include <Select3D_SensitiveBox.hxx> |
33 | #include <SelectMgr_EntityOwner.hxx> |
f751596e |
34 | #include <SelectMgr_Selection.hxx> |
7fd59977 |
35 | |
36 | #include <ElCLib.hxx> |
37 | #include <ElSLib.hxx> |
38 | |
39 | #include <TopoDS.hxx> |
40 | |
41 | #include <BRepAdaptor_Surface.hxx> |
42 | #include <BRepAdaptor_Curve.hxx> |
43 | |
44 | #include <Geom_Ellipse.hxx> |
c04c30b3 |
45 | #include <Geom_OffsetCurve.hxx> |
7fd59977 |
46 | #include <Geom_TrimmedCurve.hxx> |
47 | #include <Geom_Plane.hxx> |
48 | #include <Geom_Surface.hxx> |
49 | #include <Geom_CylindricalSurface.hxx> |
50 | #include <Geom_SurfaceOfRevolution.hxx> |
51 | #include <Geom_CylindricalSurface.hxx> |
52 | #include <Geom_SurfaceOfLinearExtrusion.hxx> |
53 | |
54 | #include <gp_Pln.hxx> |
55 | #include <gp_Pnt.hxx> |
56 | #include <gp_Lin.hxx> |
57 | #include <gp_Ax1.hxx> |
58 | #include <gp_Dir.hxx> |
59 | #include <gp_Vec.hxx> |
60 | |
61 | #include <AIS.hxx> |
7fd59977 |
62 | |
63 | #include <Precision.hxx> |
64 | #include <DsgPrs_EllipseRadiusPresentation.hxx> |
65 | |
66 | |
67 | //======================================================================= |
68 | //function : AIS_MinRadiusDimension |
69 | //purpose : |
70 | //======================================================================= |
71 | |
72 | AIS_MinRadiusDimension::AIS_MinRadiusDimension(const TopoDS_Shape& aShape, |
73 | const Standard_Real aVal, |
74 | const TCollection_ExtendedString& aText) |
75 | :AIS_EllipseRadiusDimension(aShape, aText) |
76 | { |
77 | myVal = aVal; |
78 | mySymbolPrs = DsgPrs_AS_LASTAR; |
79 | myAutomaticPosition = Standard_True; |
80 | myArrowSize = myVal / 100.; |
81 | } |
82 | |
83 | //======================================================================= |
84 | //function : AIS_MinRadiusDimension |
85 | //purpose : |
86 | //======================================================================= |
87 | |
88 | AIS_MinRadiusDimension::AIS_MinRadiusDimension(const TopoDS_Shape& aShape, |
89 | const Standard_Real aVal, |
90 | const TCollection_ExtendedString& aText, |
91 | const gp_Pnt& aPosition, |
92 | const DsgPrs_ArrowSide aSymbolPrs, |
93 | const Standard_Real anArrowSize) |
94 | :AIS_EllipseRadiusDimension(aShape, aText) |
95 | { |
96 | myVal = aVal; |
97 | mySymbolPrs = aSymbolPrs; |
98 | myPosition = aPosition; |
99 | myAutomaticPosition = Standard_False; |
7fd59977 |
100 | SetArrowSize( anArrowSize ); |
7fd59977 |
101 | } |
102 | |
103 | //======================================================================= |
104 | //function : Compute |
105 | //purpose : |
106 | //======================================================================= |
107 | |
108 | void AIS_MinRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
109 | const Handle(Prs3d_Presentation)& aPresentation, |
110 | const Standard_Integer /*aMode*/) |
111 | { |
112 | aPresentation->Clear(); |
113 | |
114 | // if( myAutomaticPosition ) |
115 | //{ //ota : recompute ellipse always |
116 | ComputeGeometry(); |
117 | myEllipse.SetMinorRadius(myVal); |
118 | gp_Vec v1(myEllipse.YAxis().Direction()); |
119 | v1 *=myVal; |
120 | myApexP = myEllipse.Location().Translated(v1); |
121 | myApexN = myEllipse.Location().Translated(-v1); |
122 | // } |
123 | if(myIsAnArc) ComputeArcOfEllipse(aPresentation); |
124 | else |
125 | ComputeEllipse(aPresentation); |
126 | } |
127 | |
128 | //======================================================================= |
129 | //function : Compute |
130 | //purpose : to avoid warning |
131 | //======================================================================= |
132 | |
133 | void AIS_MinRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector, |
134 | const Handle(Prs3d_Presentation)& aPresentation) |
135 | { |
136 | // Standard_NotImplemented::Raise("AIS_MinRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)"); |
137 | PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ; |
138 | } |
139 | |
7fd59977 |
140 | //======================================================================= |
141 | //function : Compute |
142 | //purpose : |
143 | //======================================================================= |
144 | |
857ffd5e |
145 | void AIS_MinRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector, |
146 | const Handle(Geom_Transformation)& aTransformation, |
147 | const Handle(Prs3d_Presentation)& aPresentation) |
7fd59977 |
148 | { |
857ffd5e |
149 | // Standard_NotImplemented::Raise("AIS_MinRadiusDimension::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)"); |
7fd59977 |
150 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ; |
151 | } |
152 | |
153 | //======================================================================= |
154 | //function : ComputeEllipse |
155 | //purpose : |
156 | //======================================================================= |
157 | |
158 | void AIS_MinRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation) |
159 | { |
160 | |
a6eb515f |
161 | Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect(); |
162 | Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect(); |
7fd59977 |
163 | |
164 | // size |
7fd59977 |
165 | if( !myArrowSizeIsDefined ) { |
166 | myArrowSize = Min(myArrowSize,myVal/5.); |
167 | } |
168 | arr->SetLength(myArrowSize); |
7fd59977 |
169 | |
170 | Standard_Real U;//,V; |
171 | gp_Pnt curPos, Center; |
172 | Center = myEllipse.Location(); |
173 | if( myAutomaticPosition ) |
174 | { |
175 | myPosition = Center; |
176 | myEndOfArrow = myApexP; |
177 | myAutomaticPosition = Standard_True; |
178 | |
179 | if ( myIsSetBndBox ) |
180 | myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )), |
181 | myBndBox ); |
182 | curPos = myPosition; |
183 | } |
184 | else //!AutomaticPosition |
185 | { |
186 | curPos = myPosition; |
187 | gp_Lin L1(myEllipse.YAxis()); |
188 | U = ElCLib::Parameter ( L1, curPos ); |
189 | curPos = ElCLib::Value (U, L1); |
190 | if (curPos.Distance(myApexP) < curPos.Distance(myApexN)) |
191 | myEndOfArrow = myApexP ; |
192 | else |
193 | myEndOfArrow = myApexN ; |
194 | myPosition = curPos; |
195 | } |
196 | |
197 | // Presenatation |
198 | DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, curPos, |
199 | myEndOfArrow, Center, Standard_False, mySymbolPrs); |
200 | |
201 | } |
202 | |
203 | //======================================================================= |
204 | //function : ComputeArcOfEllipse |
205 | //purpose : |
206 | //======================================================================= |
207 | |
208 | void AIS_MinRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation) |
209 | { |
210 | |
a6eb515f |
211 | Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect(); |
212 | Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect(); |
7fd59977 |
213 | |
214 | // size |
7fd59977 |
215 | if( !myArrowSizeIsDefined ) { |
216 | myArrowSize = Min(myArrowSize,myVal/5.); |
217 | } |
218 | arr->SetLength(myArrowSize); |
7fd59977 |
219 | |
220 | Standard_Real par; |
221 | gp_Pnt curPos, Center; |
222 | Center = myEllipse.Location(); |
223 | Standard_Boolean IsInDomain = Standard_True; |
224 | if( myAutomaticPosition ) |
225 | { |
226 | myEndOfArrow = AIS::NearestApex(myEllipse, myApexP, myApexN, |
227 | myFirstPar, myLastPar, IsInDomain); |
228 | myPosition = Center; |
229 | myAutomaticPosition = Standard_True; |
230 | if ( myIsSetBndBox ) |
231 | myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )), |
232 | myBndBox ); |
233 | curPos = myPosition; |
234 | |
235 | } |
236 | else //!AutomaticPosition |
237 | { |
238 | curPos = myPosition; |
239 | gp_Lin L1(myEllipse.YAxis()); |
240 | par = ElCLib::Parameter ( L1, curPos ); |
241 | curPos = ElCLib::Value (par, L1); |
242 | if (curPos.Distance(myApexP) < curPos.Distance(myApexN)) |
243 | myEndOfArrow = myApexP ; |
244 | else |
245 | myEndOfArrow = myApexN ; |
246 | par = ElCLib::Parameter ( myEllipse, myEndOfArrow ); |
247 | IsInDomain = AIS::InDomain(myFirstPar, myLastPar, par); |
248 | myPosition = curPos; |
249 | } |
250 | |
251 | Standard_Real parStart =0.; |
252 | if( !IsInDomain ) |
253 | { |
254 | if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) < |
255 | AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar)) |
256 | parStart = myFirstPar; |
257 | else |
258 | parStart = myLastPar; |
259 | |
260 | } |
261 | |
262 | if(!myIsOffset) |
263 | DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myEllipse, |
264 | curPos, myEndOfArrow, Center, parStart, IsInDomain, |
265 | Standard_True, mySymbolPrs); |
266 | else |
267 | DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myOffsetCurve, |
268 | curPos, myEndOfArrow, Center, parStart, IsInDomain, |
269 | Standard_True, mySymbolPrs); |
270 | } |
271 | |
272 | |
273 | //======================================================================= |
274 | //function : ComputeSelection |
275 | //purpose : |
276 | //======================================================================= |
277 | |
278 | void AIS_MinRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, |
279 | const Standard_Integer /*aMode*/) |
280 | { |
281 | |
282 | gp_Pnt center = myEllipse.Location(); |
283 | gp_Pnt AttachmentPoint = myPosition; |
284 | Standard_Real dist = center.Distance(AttachmentPoint); |
285 | Standard_Real aRadius = myVal; |
286 | //Standard_Real inside = Standard_False; |
287 | gp_Pnt pt1; |
288 | if (dist > aRadius) pt1 = AttachmentPoint; |
289 | else |
290 | pt1 = myEndOfArrow; |
291 | Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7); |
292 | Handle(Select3D_SensitiveSegment) |
293 | seg = new Select3D_SensitiveSegment(own, center , pt1); |
294 | aSelection->Add(seg); |
295 | |
296 | // Text |
297 | Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6)); |
298 | Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own, |
299 | AttachmentPoint.X(), |
300 | AttachmentPoint.Y(), |
301 | AttachmentPoint.Z(), |
302 | AttachmentPoint.X()+size, |
303 | AttachmentPoint.Y()+size, |
304 | AttachmentPoint.Z()+size); |
305 | aSelection->Add(box); |
306 | |
307 | // Arc of Ellipse |
308 | if(myIsAnArc) |
309 | { |
310 | |
311 | Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow ); |
312 | if(!AIS::InDomain(myFirstPar, myLastPar, parEnd)) |
313 | { |
314 | Standard_Real parStart, par; |
315 | if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) < |
316 | AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar)) |
317 | par = myFirstPar; |
318 | else |
319 | par = myLastPar; |
320 | gp_Vec Vapex(center, ElCLib::Value( parEnd, myEllipse )) ; |
321 | gp_Vec Vpnt (center, ElCLib::Value( par, myEllipse )) ; |
322 | gp_Dir dir(Vpnt ^ Vapex); |
323 | if(myEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())) { |
324 | parStart = parEnd; |
325 | parEnd = par; |
326 | } |
327 | else |
328 | parStart = par; |
c04c30b3 |
329 | Handle(Geom_Curve)TrimCurve; |
7fd59977 |
330 | if(myIsOffset) |
331 | { |
332 | Handle(Geom_Curve) aCurve = myOffsetCurve; |
333 | TrimCurve = new Geom_TrimmedCurve( aCurve, parStart, parEnd ); |
334 | } |
335 | else |
336 | { |
337 | Handle(Geom_Ellipse) Ellipse = new Geom_Ellipse( myEllipse ); |
338 | TrimCurve = new Geom_TrimmedCurve( Ellipse, parStart, parEnd ); |
339 | } |
340 | Handle( Select3D_SensitiveCurve ) SensArc; |
341 | SensArc = new Select3D_SensitiveCurve( own, TrimCurve ); |
342 | aSelection->Add( SensArc ); |
343 | } |
344 | } |
345 | |
346 | } |