Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 | 2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 3 | // |
973c2be1 | 4 | // This file is part of Open CASCADE Technology software library. |
b311480e | 5 | // |
d5f74e42 | 6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
10 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 11 | // |
973c2be1 | 12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. | |
b311480e | 14 | |
7fd59977 | 15 | #include <Aspect_TypeOfLine.hxx> |
16 | #include <Aspect_TypeOfMarker.hxx> | |
42cf5bc1 | 17 | #include <DsgPrs.hxx> |
7fd59977 | 18 | #include <ElCLib.hxx> |
42cf5bc1 | 19 | #include <gce_MakeLin.hxx> |
7fd59977 | 20 | #include <Geom_Circle.hxx> |
42cf5bc1 | 21 | #include <Geom_Curve.hxx> |
22 | #include <Geom_Line.hxx> | |
23 | #include <Geom_Surface.hxx> | |
7fd59977 | 24 | #include <GeomAPI_ExtremaCurveCurve.hxx> |
7fd59977 | 25 | #include <GeomAPI_ProjectPointOnCurve.hxx> |
42cf5bc1 | 26 | #include <GeomAPI_ProjectPointOnSurf.hxx> |
27 | #include <gp_Ax1.hxx> | |
28 | #include <gp_Circ.hxx> | |
29 | #include <gp_Dir.hxx> | |
30 | #include <gp_Elips.hxx> | |
31 | #include <gp_Pln.hxx> | |
32 | #include <gp_Pnt.hxx> | |
33 | #include <gp_Vec.hxx> | |
34 | #include <Graphic3d_ArrayOfPoints.hxx> | |
35 | #include <Graphic3d_AspectLine3d.hxx> | |
36 | #include <Graphic3d_AspectMarker3d.hxx> | |
37 | #include <Graphic3d_Group.hxx> | |
38 | #include <Graphic3d_Vertex.hxx> | |
39 | #include <Precision.hxx> | |
40 | #include <Prs3d_Arrow.hxx> | |
41 | #include <Prs3d_ArrowAspect.hxx> | |
42 | #include <Prs3d_DimensionAspect.hxx> | |
43 | #include <Prs3d_LineAspect.hxx> | |
44 | #include <Prs3d_Presentation.hxx> | |
45 | #include <Prs3d_Root.hxx> | |
46 | #include <Quantity_Color.hxx> | |
47 | #include <TCollection_AsciiString.hxx> | |
48 | #include <TCollection_ExtendedString.hxx> | |
7fd59977 | 49 | |
7fd59977 | 50 | void DsgPrs::ComputeSymbol (const Handle(Prs3d_Presentation)& aPresentation, |
a6eb515f | 51 | const Handle(Prs3d_DimensionAspect)& LA, |
7fd59977 | 52 | const gp_Pnt& pt1, |
53 | const gp_Pnt& pt2, | |
54 | const gp_Dir& dir1, | |
55 | const gp_Dir& dir2, | |
a6eb515f | 56 | const DsgPrs_ArrowSide ArrowSide, |
57 | const Standard_Boolean drawFromCenter) | |
7fd59977 | 58 | { |
59 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); | |
a577aaab | 60 | |
b6472664 | 61 | Quantity_Color aColor = LA->LineAspect()->Aspect()->Color(); |
a577aaab | 62 | Handle(Graphic3d_AspectMarker3d) aMarkerAsp = new Graphic3d_AspectMarker3d (Aspect_TOM_O, aColor, 1.0); |
63 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect (aMarkerAsp); | |
a6eb515f | 64 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
7fd59977 | 65 | |
66 | switch(ArrowSide) { | |
67 | case DsgPrs_AS_NONE: | |
68 | { | |
69 | break; | |
70 | } | |
71 | case DsgPrs_AS_FIRSTAR: | |
72 | { | |
73 | ||
74 | Prs3d_Arrow::Draw(aPresentation, | |
75 | pt1, | |
76 | dir1, | |
77 | LA->ArrowAspect()->Angle(), | |
78 | LA->ArrowAspect()->Length()); | |
79 | break; | |
80 | } | |
81 | case DsgPrs_AS_LASTAR: | |
82 | { | |
83 | ||
84 | Prs3d_Arrow::Draw(aPresentation, | |
85 | pt2, | |
86 | dir2, | |
87 | LA->ArrowAspect()->Angle(), | |
88 | LA->ArrowAspect()->Length()); | |
89 | break; | |
90 | } | |
91 | ||
92 | case DsgPrs_AS_BOTHAR: | |
93 | { | |
94 | Prs3d_Arrow::Draw(aPresentation, | |
95 | pt1, | |
96 | dir1, | |
97 | LA->ArrowAspect()->Angle(), | |
98 | LA->ArrowAspect()->Length()); | |
99 | Prs3d_Arrow::Draw(aPresentation, | |
100 | pt2, | |
101 | dir2, | |
102 | LA->ArrowAspect()->Angle(), | |
103 | LA->ArrowAspect()->Length()); | |
104 | ||
105 | break; | |
106 | } | |
107 | ||
108 | case DsgPrs_AS_FIRSTPT: | |
109 | { | |
a6eb515f | 110 | if(drawFromCenter) |
a577aaab | 111 | { |
112 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1); | |
113 | anArrayOfPoints->AddVertex (pt1.X(), pt1.Y(), pt1.Z()); | |
114 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints); | |
115 | } | |
7fd59977 | 116 | break; |
117 | } | |
118 | ||
119 | case DsgPrs_AS_LASTPT: | |
120 | { | |
121 | // On dessine un rond | |
a577aaab | 122 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1); |
123 | anArrayOfPoints->AddVertex (pt2.X(), pt2.Y(), pt2.Z()); | |
124 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints); | |
7fd59977 | 125 | break; |
126 | } | |
127 | ||
128 | case DsgPrs_AS_BOTHPT: | |
129 | { | |
a6eb515f | 130 | if(drawFromCenter) |
a577aaab | 131 | { |
132 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints1 = new Graphic3d_ArrayOfPoints (1); | |
133 | anArrayOfPoints1->AddVertex (pt1.X(), pt1.Y(), pt1.Z()); | |
134 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints1); | |
135 | } | |
a6eb515f | 136 | if(drawFromCenter) |
137 | { | |
138 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints2 = new Graphic3d_ArrayOfPoints (1); | |
139 | anArrayOfPoints2->AddVertex (pt2.X(), pt2.Y(), pt2.Z()); | |
140 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints2); | |
141 | } | |
7fd59977 | 142 | break; |
143 | } | |
144 | ||
145 | case DsgPrs_AS_FIRSTAR_LASTPT: | |
146 | { | |
147 | // an Arrow | |
a6eb515f | 148 | Prs3d_Arrow::Draw(aPresentation, |
149 | pt1, | |
150 | dir1, | |
151 | LA->ArrowAspect()->Angle(), | |
152 | LA->ArrowAspect()->Length()); | |
7fd59977 | 153 | // a Round |
a577aaab | 154 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1); |
155 | anArrayOfPoints->AddVertex (pt2.X(), pt2.Y(), pt2.Z()); | |
156 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints); | |
7fd59977 | 157 | break; |
158 | } | |
159 | ||
160 | case DsgPrs_AS_FIRSTPT_LASTAR: | |
161 | { | |
162 | // a Round | |
a6eb515f | 163 | if(drawFromCenter) |
a577aaab | 164 | { |
165 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1); | |
166 | anArrayOfPoints->AddVertex (pt1.X(), pt1.Y(), pt1.Z()); | |
167 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints); | |
168 | } | |
7fd59977 | 169 | // an Arrow |
a6eb515f | 170 | Prs3d_Arrow::Draw(aPresentation, |
171 | pt2, | |
172 | dir2, | |
173 | LA->ArrowAspect()->Angle(), | |
174 | LA->ArrowAspect()->Length()); | |
7fd59977 | 175 | break; |
176 | } | |
177 | } | |
178 | } | |
179 | ||
180 | ||
181 | //======================================================================= | |
182 | //function : ComputePlanarFacesLengthPresentation | |
183 | //purpose : | |
184 | //======================================================================= | |
185 | ||
186 | void DsgPrs::ComputePlanarFacesLengthPresentation( const Standard_Real FirstArrowLength, | |
187 | const Standard_Real SecondArrowLength, | |
188 | const gp_Pnt& AttachmentPoint1, | |
189 | const gp_Pnt& AttachmentPoint2, | |
190 | const gp_Dir& DirAttach, | |
191 | const gp_Pnt& OffsetPoint, | |
192 | const gp_Pln& PlaneOfFaces, | |
193 | gp_Pnt & EndOfArrow1, | |
194 | gp_Pnt & EndOfArrow2, | |
195 | gp_Dir & DirOfArrow1 ) | |
196 | { | |
197 | gp_Lin FirstLin( AttachmentPoint1, DirAttach ); | |
198 | gp_Lin SecondLin( AttachmentPoint2, DirAttach ); | |
199 | ||
200 | EndOfArrow1 = ElCLib::Value( ElCLib::Parameter( FirstLin, OffsetPoint ), FirstLin ); | |
201 | EndOfArrow2 = ElCLib::Value( ElCLib::Parameter( SecondLin, OffsetPoint ), SecondLin ); | |
202 | ||
08cd2f6b | 203 | if (EndOfArrow1.SquareDistance( EndOfArrow2 ) > Precision::SquareConfusion()) // not null length |
7fd59977 | 204 | { |
205 | gp_Dir LengthDir( gp_Vec( EndOfArrow1, EndOfArrow2 ) ); | |
206 | if ((FirstArrowLength + SecondArrowLength)*(FirstArrowLength + SecondArrowLength) < | |
207 | EndOfArrow1.SquareDistance( EndOfArrow2 )) | |
208 | DirOfArrow1 = -LengthDir; | |
209 | else | |
210 | DirOfArrow1 = LengthDir; | |
211 | } | |
212 | else // null length | |
213 | DirOfArrow1 = PlaneOfFaces.Axis().Direction(); | |
214 | } | |
215 | ||
216 | //======================================================================= | |
217 | //function : ComputeCurvilinearFacesLengthPresentation | |
218 | //purpose : | |
219 | //======================================================================= | |
220 | ||
221 | void DsgPrs::ComputeCurvilinearFacesLengthPresentation( const Standard_Real FirstArrowLength, | |
222 | const Standard_Real SecondArrowLength, | |
223 | const Handle( Geom_Surface )& SecondSurf, | |
224 | const gp_Pnt& AttachmentPoint1, | |
225 | const gp_Pnt& AttachmentPoint2, | |
226 | const gp_Dir& DirAttach, | |
227 | gp_Pnt & EndOfArrow2, | |
228 | gp_Dir & DirOfArrow1, | |
229 | Handle( Geom_Curve )& VCurve, | |
230 | Handle( Geom_Curve )& UCurve, | |
231 | Standard_Real & FirstU, | |
232 | Standard_Real & deltaU, | |
233 | Standard_Real & FirstV, | |
234 | Standard_Real & deltaV ) | |
235 | { | |
236 | GeomAPI_ProjectPointOnSurf ProjectorOnSurface; | |
237 | GeomAPI_ProjectPointOnCurve ProjectorOnCurve; | |
238 | Quantity_Parameter U1, V1, U2, V2; | |
239 | Standard_Real LastU, LastV; | |
08cd2f6b | 240 | Standard_Real SquareTolerance = Precision::SquareConfusion(); |
7fd59977 | 241 | |
242 | ProjectorOnSurface.Init( AttachmentPoint1, SecondSurf ); | |
243 | Standard_Integer Index(1); | |
244 | Quantity_Length MinDist = RealLast(); | |
245 | Quantity_Parameter LocalU, LocalV; | |
246 | gp_Vec D1U, D1V; | |
247 | gp_Dir LocalDir; | |
248 | for (Standard_Integer i = 1; i <= ProjectorOnSurface.NbPoints(); i++) | |
249 | { | |
250 | ProjectorOnSurface.Parameters( i, LocalU, LocalV ); | |
251 | ||
252 | SecondSurf->D1( LocalU, LocalV, EndOfArrow2, D1U, D1V ); | |
253 | if (D1U.SquareMagnitude() <= SquareTolerance || D1V.SquareMagnitude() <= SquareTolerance) | |
254 | LocalDir = gp_Dir( gp_Vec( AttachmentPoint1, ProjectorOnSurface.Point( i ) ) ); | |
255 | else | |
256 | LocalDir = gp_Dir( D1U ^ D1V ); | |
257 | if (DirAttach.IsParallel( LocalDir, Precision::Angular() ) && ProjectorOnSurface.Distance( i ) < MinDist) | |
258 | { | |
259 | Index = i; | |
260 | MinDist = ProjectorOnSurface.Distance( i ); | |
261 | } | |
262 | } | |
263 | EndOfArrow2 = ProjectorOnSurface.Point( Index ); | |
264 | ProjectorOnSurface.Parameters( Index, U1, V1 ); | |
265 | ||
266 | if ((FirstArrowLength + SecondArrowLength)*(FirstArrowLength + SecondArrowLength) < | |
267 | AttachmentPoint1.SquareDistance( EndOfArrow2 )) | |
268 | DirOfArrow1 = -DirAttach; | |
269 | else | |
270 | DirOfArrow1 = DirAttach; | |
271 | ||
08cd2f6b | 272 | if (EndOfArrow2.SquareDistance( AttachmentPoint2 ) > Precision::SquareConfusion()) |
7fd59977 | 273 | { |
274 | VCurve = SecondSurf->VIso( V1 ); | |
275 | ProjectorOnCurve.Init( EndOfArrow2, VCurve ); | |
276 | FirstU = ProjectorOnCurve.LowerDistanceParameter(); | |
277 | ||
278 | ProjectorOnSurface.Init( AttachmentPoint2, SecondSurf ); | |
279 | ProjectorOnSurface.LowerDistanceParameters( U2, V2 ); | |
280 | UCurve = SecondSurf->UIso( U2 ); | |
281 | ||
282 | ProjectorOnCurve.Init( AttachmentPoint2, UCurve ); | |
283 | LastV = ProjectorOnCurve.LowerDistanceParameter(); | |
284 | ||
285 | gp_Pnt Intersection = SecondSurf->Value( U2, V1 ); | |
286 | ProjectorOnCurve.Init( Intersection, VCurve ); | |
287 | LastU = ProjectorOnCurve.LowerDistanceParameter(); | |
288 | ProjectorOnCurve.Init( Intersection, UCurve ); | |
289 | FirstV = ProjectorOnCurve.LowerDistanceParameter(); | |
290 | ||
291 | deltaU = LastU - FirstU; | |
292 | deltaV = LastV - FirstV; | |
293 | ||
294 | if (VCurve->IsPeriodic() && Abs( deltaU ) > VCurve->Period()/2) | |
295 | { | |
296 | Standard_Real Sign = (deltaU > 0.0)? -1.0 : 1.0; | |
297 | deltaU = VCurve->Period() - Abs( deltaU ); | |
298 | deltaU *= Sign; | |
299 | } | |
300 | if (UCurve->IsPeriodic() && Abs( deltaV ) > UCurve->Period()/2) | |
301 | { | |
302 | Standard_Real Sign = (deltaV > 0.0)? -1.0 : 1.0; | |
303 | deltaV = UCurve->Period() - Abs( deltaV ); | |
304 | deltaV *= Sign; | |
305 | } | |
306 | } | |
307 | } | |
308 | ||
309 | ||
310 | //======================================================================= | |
311 | //function : ComputeFacesAnglePresentation | |
312 | //purpose : | |
313 | //======================================================================= | |
314 | ||
315 | void DsgPrs::ComputeFacesAnglePresentation( const Standard_Real ArrowLength, | |
316 | const Standard_Real Value, | |
317 | const gp_Pnt& CenterPoint, | |
318 | const gp_Pnt& AttachmentPoint1, | |
319 | const gp_Pnt& AttachmentPoint2, | |
320 | const gp_Dir& dir1, | |
321 | const gp_Dir& dir2, | |
322 | const gp_Dir& axisdir, | |
323 | const Standard_Boolean isPlane, | |
324 | const gp_Ax1& AxisOfSurf, | |
325 | const gp_Pnt& OffsetPoint, | |
326 | gp_Circ & AngleCirc, | |
327 | Standard_Real & FirstParAngleCirc, | |
328 | Standard_Real & LastParAngleCirc, | |
329 | gp_Pnt & EndOfArrow1, | |
330 | gp_Pnt & EndOfArrow2, | |
331 | gp_Dir & DirOfArrow1, | |
332 | gp_Dir & DirOfArrow2, | |
333 | gp_Pnt & ProjAttachPoint2, | |
334 | gp_Circ & AttachCirc, | |
335 | Standard_Real & FirstParAttachCirc, | |
336 | Standard_Real & LastParAttachCirc ) | |
337 | { | |
c6541a0c | 338 | if (Value > Precision::Angular() && Abs( M_PI-Value ) > Precision::Angular()) |
7fd59977 | 339 | { |
340 | // Computing presentation of angle's arc | |
341 | gp_Ax2 ax( CenterPoint, axisdir, dir1 ); | |
342 | AngleCirc.SetPosition( ax ); | |
343 | AngleCirc.SetRadius( CenterPoint.Distance( OffsetPoint ) ); | |
344 | gp_Vec vec1( dir1 ); | |
345 | vec1 *= AngleCirc.Radius(); | |
346 | gp_Pnt p1 = CenterPoint.Translated( vec1 ); | |
347 | gp_Vec vec2( dir2 ); | |
348 | vec2 *= AngleCirc.Radius(); | |
349 | gp_Pnt p2 = CenterPoint.Translated( vec2 ); | |
350 | ||
351 | Standard_Real Par1 = 0.; | |
352 | Standard_Real Par2 = ElCLib::Parameter( AngleCirc, p2 ); | |
353 | Standard_Real Par0 = ElCLib::Parameter( AngleCirc, OffsetPoint ); | |
354 | ||
355 | gp_Vec PosVec( CenterPoint, OffsetPoint ); | |
356 | gp_Vec NormalOfPlane = vec1 ^ vec2; | |
357 | ||
358 | gp_Vec Normal1 = NormalOfPlane ^ vec1; | |
359 | gp_Vec Normal2 = NormalOfPlane ^ vec2; | |
360 | Standard_Integer Sign1 = (PosVec * Normal1 >= 0)? 1 : -1; | |
361 | Standard_Integer Sign2 = (PosVec * Normal2 >= 0)? 1 : -1; | |
362 | if (Sign1 == 1 && Sign2 == -1) | |
363 | { | |
364 | FirstParAngleCirc = Par1; | |
365 | LastParAngleCirc = Par2; | |
366 | } | |
367 | else if (Sign1 == 1 && Sign2 == 1) | |
368 | { | |
369 | FirstParAngleCirc = Par1; | |
370 | LastParAngleCirc = Par0; | |
371 | } | |
372 | else if (Sign1 == -1 && Sign2 == 1) | |
373 | { | |
c6541a0c D |
374 | Par1 += M_PI; |
375 | Par2 += M_PI; | |
7fd59977 | 376 | FirstParAngleCirc = Par1; |
377 | LastParAngleCirc = Par2; | |
378 | } | |
379 | else //Sign1 == -1 && Sign2 == -1 | |
380 | { | |
381 | AngleCirc.SetPosition( gp_Ax2( CenterPoint, axisdir, gp_Dir( PosVec ) ) ); | |
382 | Par0 = 0.; | |
383 | Par1 = ElCLib::Parameter( AngleCirc, p1 ); | |
384 | Par2 = ElCLib::Parameter( AngleCirc, p2 ); | |
385 | FirstParAngleCirc = Par0; | |
386 | LastParAngleCirc = Par2; | |
387 | } | |
388 | ||
389 | // Computing presentation of arrows | |
390 | EndOfArrow1 = ElCLib::Value( Par1, AngleCirc ); | |
391 | EndOfArrow2 = ElCLib::Value( Par2, AngleCirc ); | |
392 | Standard_Real beta = 0.; | |
393 | if (AngleCirc.Radius() > Precision::Confusion()) | |
394 | beta = ArrowLength / AngleCirc.Radius(); | |
395 | gp_Pnt OriginOfArrow1 = ElCLib::Value( Par1 + beta, AngleCirc ); | |
396 | gp_Pnt OriginOfArrow2 = ElCLib::Value( Par2 - beta, AngleCirc ); | |
397 | DirOfArrow1 = gp_Dir( gp_Vec( OriginOfArrow1, EndOfArrow1 ) ); | |
398 | DirOfArrow2 = gp_Dir( gp_Vec( OriginOfArrow2, EndOfArrow2 ) ); | |
399 | if (EndOfArrow1.SquareDistance( EndOfArrow2 ) <= (ArrowLength + ArrowLength)*(ArrowLength + ArrowLength)) | |
400 | { | |
401 | DirOfArrow1.Reverse(); | |
402 | DirOfArrow2.Reverse(); | |
403 | } | |
404 | } | |
405 | else // dir1 and dir2 are parallel | |
406 | { | |
407 | gp_Dir ArrowDir = axisdir ^ dir1; | |
408 | DirOfArrow1 = ArrowDir; | |
409 | DirOfArrow2 = -ArrowDir; | |
410 | gp_Lin DirLine( AttachmentPoint1, dir1 ); | |
411 | EndOfArrow1 = ElCLib::Value( ElCLib::Parameter( DirLine, OffsetPoint ), DirLine ); | |
412 | EndOfArrow2 = EndOfArrow1; | |
413 | } | |
414 | ||
415 | // Line or arc from AttachmentPoint2 to its "projection" | |
416 | gp_Lin SecondLin( CenterPoint, dir2 ); | |
417 | if (SecondLin.Contains( AttachmentPoint2, Precision::Confusion() )) | |
418 | ProjAttachPoint2 = AttachmentPoint2; | |
419 | else | |
420 | { | |
421 | if (isPlane) | |
422 | ProjAttachPoint2 = ElCLib::Value( ElCLib::Parameter( SecondLin, AttachmentPoint2 ), SecondLin ); | |
423 | else | |
424 | { | |
425 | gp_Lin LineOfAxis( AxisOfSurf ); | |
426 | gp_Pnt CenterOfArc = ElCLib::Value( ElCLib::Parameter( LineOfAxis, AttachmentPoint2 ), | |
427 | LineOfAxis ); | |
428 | ||
429 | gp_Ax2 Ax2( CenterOfArc, | |
430 | AxisOfSurf.Direction(), | |
431 | gp_Dir( gp_Vec( CenterOfArc, AttachmentPoint2 ) ) ); | |
432 | AttachCirc.SetPosition( Ax2 ); | |
433 | AttachCirc.SetRadius( CenterOfArc.Distance( AttachmentPoint2 ) ); | |
434 | ||
435 | GeomAPI_ExtremaCurveCurve Intersection( new Geom_Circle( AttachCirc ), | |
436 | new Geom_Line( SecondLin ) ); | |
437 | Intersection.NearestPoints( ProjAttachPoint2, ProjAttachPoint2 ); | |
438 | ||
439 | Standard_Real U2 = ElCLib::Parameter( AttachCirc, ProjAttachPoint2 ); | |
c6541a0c | 440 | if (U2 <= M_PI) |
7fd59977 | 441 | { |
442 | FirstParAttachCirc = 0; | |
443 | LastParAttachCirc = U2; | |
444 | } | |
445 | else | |
446 | { | |
447 | FirstParAttachCirc = U2; | |
c6541a0c | 448 | LastParAttachCirc = 2*M_PI; |
7fd59977 | 449 | } |
450 | } | |
451 | } | |
452 | } | |
453 | ||
454 | ||
455 | ||
35e08fe8 | 456 | void DsgPrs::ComputeFilletRadiusPresentation( const Standard_Real /*ArrowLength*/, |
7fd59977 | 457 | const Standard_Real Value, |
458 | const gp_Pnt & Position, | |
459 | const gp_Dir & NormalDir, | |
460 | const gp_Pnt & FirstPoint, | |
461 | const gp_Pnt & SecondPoint, | |
462 | const gp_Pnt & Center, | |
463 | const gp_Pnt & BasePnt, | |
464 | const Standard_Boolean drawRevers, | |
465 | Standard_Boolean & SpecCase, | |
466 | gp_Circ & FilletCirc, | |
467 | Standard_Real & FirstParCirc, | |
468 | Standard_Real & LastParCirc, | |
469 | gp_Pnt & EndOfArrow, | |
470 | gp_Dir & DirOfArrow, | |
471 | gp_Pnt & DrawPosition) | |
472 | { | |
473 | gp_Dir dir1(gp_Vec(Center, FirstPoint)); | |
474 | gp_Dir dir2(gp_Vec(Center, SecondPoint)); | |
475 | Standard_Real Angle = dir1.Angle(dir2); | |
c6541a0c | 476 | if(Angle <= Precision::Angular() || ( M_PI - Angle ) <= Precision::Angular() || |
7fd59977 | 477 | Value <= Precision::Confusion()) SpecCase = Standard_True; |
478 | else SpecCase = Standard_False; | |
479 | if ( !SpecCase ) | |
480 | { | |
481 | // Computing presentation of fillet's arc | |
482 | gp_Ax2 ax( Center, NormalDir, dir1 ); | |
483 | FilletCirc.SetPosition( ax ); | |
484 | FilletCirc.SetRadius( Center.Distance( FirstPoint ) ); //*** | |
485 | gp_Vec vec1( dir1 ); | |
486 | vec1 *= FilletCirc.Radius(); | |
7fd59977 | 487 | gp_Vec vec2( dir2 ); |
488 | vec2 *= FilletCirc.Radius(); | |
7fd59977 | 489 | gp_Vec PosVec; |
490 | if(! Center.IsEqual( Position, Precision::Confusion() )) | |
491 | PosVec.SetXYZ( gp_Vec(Center, Position).XYZ() ); | |
492 | else | |
493 | PosVec.SetXYZ( (vec1.Added(vec2)).XYZ() ); | |
494 | gp_Vec NormalOfPlane = vec1 ^ vec2; | |
495 | gp_Vec Normal1 = NormalOfPlane ^ vec1; | |
496 | gp_Vec Normal2 = NormalOfPlane ^ vec2; | |
497 | Standard_Integer Sign1 = (PosVec * Normal1 >= 0)? 1 : -1; | |
498 | Standard_Integer Sign2 = (PosVec * Normal2 >= 0)? 1 : -1; | |
499 | gp_Lin L1( Center, dir1 ); | |
500 | gp_Lin L2( Center, dir2 ); | |
501 | if ( Sign1 != Sign2 ) | |
502 | { | |
503 | DrawPosition = Position; //*** | |
504 | gp_Dir direction(PosVec) ; | |
505 | Standard_Real angle = dir1.Angle(direction) ; | |
506 | if (( dir1 ^ direction) * NormalDir < 0.0e0) angle = -angle ; | |
c6541a0c | 507 | if(Sign1 == -1) angle += M_PI; |
7fd59977 | 508 | EndOfArrow = ElCLib::Value(angle, FilletCirc); //*** |
509 | ||
510 | } | |
511 | else | |
512 | { | |
513 | if(L1.Distance(Position) < L2.Distance(Position)) | |
514 | { | |
515 | EndOfArrow = FirstPoint; //*** | |
516 | DrawPosition = ElCLib::Value(ElCLib::Parameter(L1, Position), L1); | |
517 | } | |
518 | else | |
519 | { | |
520 | EndOfArrow = SecondPoint; //*** | |
521 | DrawPosition = ElCLib::Value(ElCLib::Parameter(L2, Position), L2); | |
522 | } | |
523 | } | |
524 | if((dir1^dir2).IsOpposite(NormalDir, Precision::Angular())) | |
525 | { | |
526 | gp_Dir newdir = NormalDir.Reversed() ; | |
527 | gp_Ax2 axnew( Center, newdir, dir1 ); | |
528 | FilletCirc.SetPosition( axnew ); | |
529 | } | |
530 | FirstParCirc = ElCLib::Parameter( FilletCirc, FirstPoint ); | |
531 | LastParCirc = ElCLib::Parameter( FilletCirc, SecondPoint ); | |
7fd59977 | 532 | } |
533 | else //Angle equal 0 or PI or R = 0 | |
534 | { | |
535 | DrawPosition = Position; | |
536 | EndOfArrow = BasePnt; | |
537 | } | |
538 | ||
7fd59977 | 539 | if(drawRevers) |
540 | { | |
541 | gp_Vec Vd(DrawPosition, EndOfArrow); | |
542 | DrawPosition.Translate(Vd *2); | |
543 | } | |
544 | DirOfArrow.SetXYZ(gp_Dir(gp_Vec(DrawPosition, EndOfArrow)).XYZ()); | |
545 | } | |
546 | ||
547 | //======================================================================= | |
548 | //function : ComputeRadiusLine | |
549 | //purpose : | |
550 | //======================================================================= | |
551 | ||
552 | void DsgPrs::ComputeRadiusLine(const gp_Pnt & aCenter, | |
553 | const gp_Pnt & anEndOfArrow, | |
554 | const gp_Pnt & aPosition, | |
555 | const Standard_Boolean drawFromCenter, | |
556 | gp_Pnt & aRadLineOrign, | |
557 | gp_Pnt & aRadLineEnd) | |
558 | { | |
559 | if(drawFromCenter) | |
560 | { | |
561 | gp_Lin RadiusLine = gce_MakeLin( aCenter, anEndOfArrow ); | |
562 | Standard_Real PosParOnLine = ElCLib::Parameter( RadiusLine, aPosition ); | |
563 | Standard_Real EndOfArrowPar = ElCLib::Parameter( RadiusLine, anEndOfArrow ); | |
564 | if (PosParOnLine < 0.0) | |
565 | { | |
566 | aRadLineOrign = aPosition; | |
567 | aRadLineEnd = anEndOfArrow; | |
568 | } | |
569 | else if (PosParOnLine > EndOfArrowPar) | |
570 | { | |
571 | aRadLineOrign = aPosition; | |
572 | aRadLineEnd = aCenter; | |
573 | } | |
574 | else | |
575 | { | |
576 | aRadLineOrign = aCenter; | |
577 | aRadLineEnd = anEndOfArrow; | |
578 | } | |
579 | } | |
580 | else | |
581 | { | |
582 | aRadLineOrign = aPosition; | |
583 | aRadLineEnd = anEndOfArrow; | |
584 | } | |
585 | } | |
586 | ||
587 | ||
588 | //======================================================================= | |
589 | //function : DistanceFromApex | |
590 | //purpose : | |
591 | //======================================================================= | |
592 | ||
593 | Standard_Real DsgPrs::DistanceFromApex(const gp_Elips & elips, | |
594 | const gp_Pnt & Apex, | |
595 | const Standard_Real par) | |
596 | { | |
597 | Standard_Real dist; | |
598 | Standard_Real parApex = ElCLib::Parameter ( elips, Apex ); | |
c6541a0c | 599 | if(parApex == 0.0 || parApex == M_PI) |
7fd59977 | 600 | {//Major case |
601 | if(parApex == 0.0) //pos Apex | |
c6541a0c | 602 | dist = (par < M_PI) ? par : (2*M_PI - par); |
7fd59977 | 603 | else //neg Apex |
c6541a0c | 604 | dist = (par < M_PI) ? ( M_PI - par) : ( par - M_PI ); |
7fd59977 | 605 | } |
606 | else | |
607 | {// Minor case | |
c6541a0c | 608 | if(parApex == M_PI / 2) //pos Apex |
7fd59977 | 609 | { |
c6541a0c | 610 | if(par <= parApex + M_PI && par > parApex ) |
7fd59977 | 611 | dist = par - parApex; |
612 | else | |
613 | { | |
c6541a0c D |
614 | if(par > parApex + M_PI) |
615 | dist = 2*M_PI - par + parApex; | |
7fd59977 | 616 | else |
c6541a0c | 617 | dist = parApex - par; // 0 < par < M_PI/2 |
7fd59977 | 618 | } |
619 | } | |
620 | else //neg Apex == 3/2 PI | |
621 | { | |
c6541a0c | 622 | if(par <= parApex && par >= M_PI/2) |
7fd59977 | 623 | dist = parApex - par; |
624 | else | |
625 | { | |
626 | if(par > parApex) | |
627 | dist = par - parApex; | |
628 | else | |
c6541a0c | 629 | dist = par + M_PI/2; // 0 < par < PI/2 |
7fd59977 | 630 | } |
631 | } | |
632 | } | |
633 | return dist; | |
634 | } |