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