7fd59977 |
1 | // File: DsgPrs_AnglePresentation.cxx |
2 | // Created: Tue Feb 7 12:18:14 1995 |
3 | |
4 | |
5 | #include <DsgPrs_AnglePresentation.ixx> |
6 | #include <gp_Lin.hxx> |
7 | #include <gp_Dir.hxx> |
8 | #include <ElCLib.hxx> |
9 | #include <Graphic3d_Group.hxx> |
10 | #include <Graphic3d_Array1OfVertex.hxx> |
11 | #include <Prs3d_AngleAspect.hxx> |
12 | #include <Prs3d_Arrow.hxx> |
13 | #include <Prs3d_ArrowAspect.hxx> |
14 | #include <Prs3d_LineAspect.hxx> |
15 | #include <Prs3d_LengthAspect.hxx> |
16 | #include <Prs3d_Text.hxx> |
17 | #include <TCollection_AsciiString.hxx> |
18 | #include <TCollection_ExtendedString.hxx> |
19 | |
20 | #include <ElCLib.hxx> |
21 | |
22 | #include <Graphic3d_Vertex.hxx> |
23 | #include <Graphic3d_AspectMarker3d.hxx> |
24 | #include <Graphic3d_AspectLine3d.hxx> |
25 | #include <Aspect_TypeOfLine.hxx> |
26 | #include <Aspect_TypeOfMarker.hxx> |
27 | #include <Aspect_AspectMarker.hxx> |
28 | #include <Quantity_Color.hxx> |
29 | #include <DsgPrs.hxx> |
30 | #include <Precision.hxx> |
31 | |
32 | #include <Geom_Circle.hxx> |
33 | #include <Geom_Line.hxx> |
34 | #include <GeomAPI_ExtremaCurveCurve.hxx> |
35 | #include <GC_MakeCircle.hxx> |
36 | #include <gce_MakePln.hxx> |
37 | |
38 | #include <UnitsAPI.hxx> |
39 | |
40 | //pop pour NT |
41 | //#if WNT |
42 | #include <stdio.h> |
43 | //#endif |
44 | |
45 | |
46 | static Standard_Integer AboveInBelowCone(gp_Circ CMax, gp_Circ CMin, gp_Circ C); |
47 | |
48 | |
49 | //========================================================================== |
50 | // function : DsgPrs_AnglePresentation::Add |
51 | // purpose : draws the presentation of the cone's angle; |
52 | //========================================================================== |
53 | void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
54 | const Handle(Prs3d_Drawer)& aDrawer, |
55 | const Standard_Real aVal, |
56 | const TCollection_ExtendedString& aText, |
57 | const gp_Circ& aCircle, |
58 | const gp_Pnt& aPosition, |
59 | const gp_Pnt& Apex, |
60 | const gp_Circ& VminCircle, |
61 | const gp_Circ& VmaxCircle, |
62 | const Standard_Real aArrowSize) |
63 | { |
64 | |
65 | |
66 | |
67 | Handle(Prs3d_AngleAspect) anAngleAspect = aDrawer->AngleAspect(); |
68 | Handle(Prs3d_LengthAspect) aLengthAspect = aDrawer->LengthAspect(); |
69 | Standard_Real myArrowSize; |
70 | |
71 | TCollection_ExtendedString txt = aText; |
72 | if( aArrowSize == 0.0 ) myArrowSize = aCircle.Radius()/ 10.; |
73 | else myArrowSize = aArrowSize; |
74 | |
75 | anAngleAspect->ArrowAspect()->SetLength(myArrowSize); |
76 | aDrawer->ArrowAspect()->SetLength(myArrowSize); |
77 | |
78 | Standard_Boolean IsArrowOut = Standard_True; //Is arrows inside or outside of the cone |
79 | Standard_Boolean IsConeTrimmed = Standard_False; |
80 | gp_Circ myCircle = aCircle; |
81 | |
82 | |
83 | if( VminCircle.Radius() > 0.01 ) { |
84 | IsConeTrimmed = Standard_True; |
85 | if( AboveInBelowCone( VmaxCircle, VminCircle, myCircle ) == 1 ) myCircle = VminCircle; |
86 | } |
87 | |
88 | gp_Pnt AttachmentPnt; |
89 | gp_Pnt OppositePnt; |
90 | gp_Pnt aPnt, tmpPnt; |
91 | |
92 | |
93 | Quantity_Length X,Y,Z; |
94 | |
95 | Standard_Real param = 0.; //ElCLib::Parameter(myCircle, aPosition); |
96 | |
97 | aPnt = Apex; |
98 | gp_Pnt P1 = ElCLib::Value(0., myCircle); |
99 | gp_Pnt P2 = ElCLib::Value(Standard_PI, myCircle); |
100 | |
101 | gce_MakePln mkPln(P1, P2, aPnt); // create a plane whitch defines plane for projection aPosition on it |
102 | |
103 | gp_Vec aVector( mkPln.Value().Location(), aPosition ); //project aPosition on a plane |
104 | gp_Vec Normal = mkPln.Value().Axis().Direction(); |
105 | Normal = (aVector * Normal) * Normal; |
106 | aPnt = aPosition; |
107 | |
108 | aPnt = aPnt.Translated( -Normal ); |
109 | |
110 | tmpPnt = aPnt; |
111 | |
112 | if( aPnt.Distance(P1) < aPnt.Distance(P2) ){ |
113 | AttachmentPnt = P1; |
114 | OppositePnt = P2; |
115 | } |
116 | else { |
117 | AttachmentPnt = P2; |
118 | OppositePnt = P1; |
119 | } |
120 | |
121 | aPnt = AttachmentPnt ; // Creating of circle whitch defines a plane for a dimension arc |
122 | gp_Vec Vec(AttachmentPnt, Apex); // Dimension arc is a part of the circle |
123 | Vec.Scale(2); |
124 | aPnt.Translate(Vec); |
125 | GC_MakeCircle mkCirc(AttachmentPnt, OppositePnt, aPnt); |
126 | gp_Circ aCircle2 = mkCirc.Value()->Circ(); |
127 | |
128 | Standard_Integer i; |
129 | Standard_Real AttParam = ElCLib::Parameter(aCircle2, AttachmentPnt); //must be equal to zero (look circle construction) |
130 | Standard_Real OppParam = ElCLib::Parameter(aCircle2, OppositePnt); |
131 | gp_Dir aDir, aDir2; |
132 | |
133 | while ( AttParam >= 2*Standard_PI ) AttParam -= 2*Standard_PI; |
134 | while ( OppParam >= 2*Standard_PI ) OppParam -= 2*Standard_PI; |
135 | |
136 | //-------------------------- Compute angle ------------------------ |
137 | if( txt.Length() == 0 ) { |
138 | Standard_Real angle = UnitsAPI::CurrentFromLS( Abs( OppParam ),"PLANE ANGLE"); |
139 | char res[80]; |
140 | sprintf(res, "%g", angle ); |
141 | txt = TCollection_ExtendedString(res); |
142 | } |
143 | //----------------------------------------------------------------- |
144 | |
145 | |
146 | |
147 | if( ElCLib::Parameter(aCircle2, tmpPnt) < OppParam ) |
148 | // if( aPosition.Distance( myCircle.Location() ) <= myCircle.Radius() ) |
149 | if( 2 * myCircle.Radius() > 4 * myArrowSize ) IsArrowOut = Standard_False; //four times more than an arrow size |
150 | |
151 | |
152 | Graphic3d_Array1OfVertex V(1, 12); |
153 | |
154 | Standard_Real angle; |
155 | // param = ElCLib::Parameter(aCircle2, tmpPnt); |
156 | angle = OppParam - AttParam; |
157 | param = AttParam; |
158 | |
159 | if(IsArrowOut) { |
160 | aDir = gp_Dir( ( gp_Vec( ElCLib::Value( AttParam - Standard_PI/12, aCircle2 ), AttachmentPnt) ) ); |
161 | aDir2 = gp_Dir( ( gp_Vec( ElCLib::Value( OppParam + Standard_PI/12, aCircle2 ), OppositePnt) ) ); |
162 | } |
163 | else { |
164 | aDir = gp_Dir( ( gp_Vec( ElCLib::Value( AttParam + Standard_PI/12, aCircle2 ), AttachmentPnt ) ) ); |
165 | aDir2 = gp_Dir( ( gp_Vec( ElCLib::Value( OppParam - Standard_PI/12, aCircle2 ), OppositePnt ) ) ); |
166 | } |
167 | |
168 | while ( angle > 2*Standard_PI ) angle -= 2*Standard_PI; |
169 | for( i = 0; i <= 11; i++ ) { //calculating of arc |
170 | ( ElCLib::Value(param + angle/11 * i, aCircle2) ).Coord(X, Y, Z); |
171 | V(i+1).SetCoord(X, Y, Z); |
172 | } |
173 | |
174 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V); //add the arc |
175 | |
176 | DsgPrs::ComputeSymbol(aPresentation, anAngleAspect, AttachmentPnt, |
177 | AttachmentPnt, aDir, aDir, DsgPrs_AS_LASTAR); |
178 | DsgPrs::ComputeSymbol(aPresentation, anAngleAspect, OppositePnt, |
179 | OppositePnt, aDir2, aDir2, DsgPrs_AS_LASTAR); |
180 | |
181 | param = ElCLib::Parameter(aCircle2, tmpPnt); |
182 | tmpPnt = ElCLib::Value(param, aCircle2); |
183 | tmpPnt = tmpPnt.Translated(gp_Vec(0, 0, -1)*2); |
184 | Prs3d_Text::Draw(aPresentation,aLengthAspect->TextAspect(), txt, tmpPnt); //add the TCollection_ExtendedString |
185 | |
186 | angle = 2*Standard_PI - param ; |
187 | if( param > OppParam ) { |
188 | while ( angle > 2*Standard_PI ) angle -= 2*Standard_PI; |
189 | for( i = 11; i >= 0; i-- ) { //calculating of arc |
190 | ( ElCLib::Value(-angle/11 * i, aCircle2) ).Coord(X, Y, Z); |
191 | V(i+1).SetCoord(X, Y, Z); |
192 | } |
193 | |
194 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V); //add additional line |
195 | } |
196 | |
197 | if( AboveInBelowCone( VmaxCircle, VminCircle, myCircle ) == 1 && !IsConeTrimmed ) { //above |
198 | Graphic3d_Array1OfVertex V2(1,3); |
199 | AttachmentPnt.Coord(X, Y, Z); |
200 | V2(1).SetCoord(X, Y, Z); |
201 | Apex.Coord(X, Y, Z); |
202 | V2(2).SetCoord(X, Y, Z); |
203 | OppositePnt.Coord(X, Y, Z); |
204 | V2(3).SetCoord(X, Y, Z); |
205 | |
206 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V2); //add the additional lines |
207 | } |
208 | else { |
209 | aPnt = OppositePnt ; |
210 | if ( AboveInBelowCone( VmaxCircle, VminCircle, myCircle ) == 0 ) return; |
211 | Graphic3d_Array1OfVertex V3(1,2); |
212 | gp_Pnt P11 = ElCLib::Value( 0., VmaxCircle ); |
213 | gp_Pnt P12 = ElCLib::Value( Standard_PI, VmaxCircle ); |
214 | |
215 | AttachmentPnt.Coord(X, Y, Z); |
216 | V3(1).SetCoord(X, Y, Z); |
217 | if( aPnt.Distance(P1) < aPnt.Distance(P2) ) P12.Coord(X, Y, Z); |
218 | else P11.Coord(X, Y, Z); |
219 | V3(2).SetCoord(X, Y, Z); |
220 | |
221 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V3); |
222 | |
223 | OppositePnt.Coord(X, Y, Z); |
224 | V3(1).SetCoord(X, Y, Z); |
225 | if( aPnt.Distance(P1) < aPnt.Distance(P2) ) P11.Coord(X, Y, Z); |
226 | else P12.Coord(X, Y, Z); |
227 | V3(2).SetCoord(X, Y, Z); |
228 | |
229 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V3); |
230 | } |
231 | } |
232 | |
233 | //------------------------------------------------------------------------------------------------------------------ |
234 | // Returns 1 if C is above of CMin; 0 if C is bitween CMin and CMax; -1 if C is Below CMax |
235 | //----------------------------------------------------------------------------------------------------------------- |
236 | static Standard_Integer AboveInBelowCone(gp_Circ CMax, gp_Circ CMin, gp_Circ C) |
237 | { |
238 | Standard_Real D, D1, D2; |
239 | |
240 | D = CMax.Location().Distance( CMin.Location() ); |
241 | D1 = CMax.Location().Distance( C.Location() ); |
242 | D2 = CMin.Location().Distance( C.Location() ); |
243 | |
244 | |
245 | if ( D >= D1 && D >= D2 ) return 0; |
246 | if ( D < D2 && D1 < D2 ) return -1; |
247 | if ( D < D1 && D2 < D1 ) return 1; |
248 | |
249 | return 0; |
250 | } |
251 | |
252 | |
253 | //========================================================================== |
254 | // function : DsgPrs_AnglePresentation::Add |
255 | // purpose : |
256 | // |
257 | //========================================================================== |
258 | |
259 | void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
260 | const Handle(Prs3d_Drawer)& aDrawer, |
261 | const Standard_Real theval, |
262 | const TCollection_ExtendedString& aText, |
263 | const gp_Pnt& CenterPoint, |
264 | const gp_Pnt& AttachmentPoint1, |
265 | const gp_Pnt& AttachmentPoint2, |
266 | const gp_Dir& dir1, |
267 | const gp_Dir& dir2, |
268 | const gp_Dir& axisdir, |
269 | const gp_Pnt& OffsetPoint) { |
270 | char valcar[80]; |
271 | sprintf(valcar,"%5.2f",theval); |
272 | |
273 | Handle(Prs3d_AngleAspect) LA = aDrawer->AngleAspect(); |
274 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
275 | |
276 | gp_Ax2 ax(CenterPoint,axisdir,dir1); |
277 | gp_Circ cer(ax,CenterPoint.Distance(OffsetPoint)); |
278 | gp_Vec vec1(dir1); |
279 | vec1 *= cer.Radius(); |
280 | #ifdef DEB |
281 | gp_Pnt p1 = |
282 | #endif |
283 | CenterPoint.Translated(vec1); |
284 | gp_Vec vec2(dir2); |
285 | vec2 *= cer.Radius(); |
286 | gp_Pnt p2 = CenterPoint.Translated(vec2); |
287 | |
288 | Standard_Real uc1 = 0.; |
289 | Standard_Real uc2 = ElCLib::Parameter(cer,p2); |
290 | Standard_Real uco = ElCLib::Parameter(cer,OffsetPoint); |
291 | |
292 | Standard_Real udeb = uc1; |
293 | Standard_Real ufin = uc2; |
294 | |
295 | if (uco > ufin) { |
296 | if (Abs(theval)<PI) { |
81bba717 |
297 | // test if uco is in the opposite sector |
7fd59977 |
298 | if (uco > udeb+PI && uco < ufin+PI){ |
299 | udeb = udeb + PI; |
300 | ufin = ufin + PI; |
301 | uc1 = udeb; |
302 | uc2 = ufin; |
303 | } |
304 | } |
305 | } |
306 | |
307 | if (uco > ufin) { |
308 | if ((uco-uc2) < (uc1-uco+(2*PI))) { |
309 | ufin = uco; |
310 | } |
311 | else { |
312 | udeb = uco - 2*PI; |
313 | } |
314 | } |
315 | |
316 | Standard_Real alpha = Abs(ufin-udeb); |
317 | Standard_Integer nbp = Max (4 , Standard_Integer (50. * alpha / PI)); |
318 | Graphic3d_Array1OfVertex V(1,nbp); |
319 | Standard_Real dteta = alpha/(nbp-1); |
320 | gp_Pnt ptcur; |
321 | for (Standard_Integer i = 1; i<=nbp; i++) { |
322 | ptcur = ElCLib::Value(udeb+ dteta*(i-1),cer); |
323 | V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z()); |
324 | } |
325 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V); |
326 | |
327 | Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,OffsetPoint); |
328 | |
329 | gp_Vec vecarr; |
330 | gp_Pnt ptarr; |
331 | ElCLib::D1(uc1,cer,ptarr,vecarr); |
332 | gp_Ax1 ax1(ptarr, axisdir); |
333 | gp_Dir dirarr(-vecarr); |
81bba717 |
334 | //calculate angle of rotation |
7fd59977 |
335 | Standard_Real beta(0.); |
336 | Standard_Real length = LA->ArrowAspect()->Length(); |
337 | if (length < Precision::Confusion()) length = 1.e-04; |
338 | gp_Pnt ptarr2(ptarr.XYZ() + length*dirarr.XYZ()); |
339 | Standard_Real parcir = ElCLib::Parameter(cer, ptarr2); |
340 | gp_Pnt ptarr3 = ElCLib::Value(parcir, cer); |
341 | gp_Vec v1(ptarr,ptarr2 ); |
342 | gp_Vec v2(ptarr, ptarr3); |
343 | beta = v1.Angle(v2); |
344 | dirarr.Rotate(ax1, beta); |
345 | Prs3d_Arrow::Draw(aPresentation, |
346 | ptarr, |
347 | dirarr, |
348 | LA->ArrowAspect()->Angle(), |
349 | length); |
350 | |
351 | Graphic3d_Array1OfVertex Vrap(1,2); |
352 | Vrap(1).SetCoord(AttachmentPoint1.X(), |
353 | AttachmentPoint1.Y(), |
354 | AttachmentPoint1.Z()); |
355 | Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z()); |
356 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap); |
357 | |
358 | ElCLib::D1(uc2,cer,ptarr,vecarr); |
359 | ax1.SetLocation(ptarr); |
360 | gp_Dir dirarr2(vecarr); |
361 | dirarr2.Rotate(ax1,-beta); |
362 | Prs3d_Arrow::Draw(aPresentation, |
363 | ptarr, |
364 | dirarr2, |
365 | LA->ArrowAspect()->Angle(), |
366 | length); |
367 | |
368 | Vrap(1).SetCoord(AttachmentPoint2.X(), |
369 | AttachmentPoint2.Y(), |
370 | AttachmentPoint2.Z()); |
371 | Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z()); |
372 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap); |
373 | } |
374 | |
375 | |
376 | //========================================================================== |
377 | // function : DsgPrs_AnglePresentation::Add |
378 | // purpose : Adds prezentation of angle between two faces |
379 | //========================================================================== |
380 | |
381 | void DsgPrs_AnglePresentation::Add( const Handle(Prs3d_Presentation)& aPresentation, |
382 | const Handle(Prs3d_Drawer)& aDrawer, |
383 | const Standard_Real theval, |
384 | const TCollection_ExtendedString& aText, |
385 | const gp_Pnt& CenterPoint, |
386 | const gp_Pnt& AttachmentPoint1, |
387 | const gp_Pnt& AttachmentPoint2, |
388 | const gp_Dir& dir1, |
389 | const gp_Dir& dir2, |
390 | const gp_Dir& axisdir, |
391 | const Standard_Boolean isPlane, |
392 | const gp_Ax1& AxisOfSurf, |
393 | const gp_Pnt& OffsetPoint, |
394 | const DsgPrs_ArrowSide ArrowPrs ) |
395 | { |
396 | char valcar[80]; |
397 | sprintf( valcar, "%5.2f", theval ); |
398 | |
399 | Handle( Prs3d_AngleAspect ) LA = aDrawer->AngleAspect(); |
400 | Prs3d_Root::CurrentGroup( aPresentation )->SetPrimitivesAspect( LA->LineAspect()->Aspect() ); |
401 | |
402 | gp_Circ AngleCirc, AttachCirc; |
403 | Standard_Real FirstParAngleCirc, LastParAngleCirc, FirstParAttachCirc, LastParAttachCirc; |
404 | gp_Pnt EndOfArrow1, EndOfArrow2, ProjAttachPoint2; |
405 | gp_Dir DirOfArrow1, DirOfArrow2; |
406 | DsgPrs::ComputeFacesAnglePresentation( LA->ArrowAspect()->Length(), |
407 | theval, |
408 | CenterPoint, |
409 | AttachmentPoint1, |
410 | AttachmentPoint2, |
411 | dir1, |
412 | dir2, |
413 | axisdir, |
414 | isPlane, |
415 | AxisOfSurf, |
416 | OffsetPoint, |
417 | AngleCirc, |
418 | FirstParAngleCirc, |
419 | LastParAngleCirc, |
420 | EndOfArrow1, |
421 | EndOfArrow2, |
422 | DirOfArrow1, |
423 | DirOfArrow2, |
424 | ProjAttachPoint2, |
425 | AttachCirc, |
426 | FirstParAttachCirc, |
427 | LastParAttachCirc ); |
428 | |
429 | Graphic3d_Array1OfVertex Vrap(1,2); |
430 | |
431 | // Creating the angle's arc or line if null angle |
432 | if (theval > Precision::Angular() && Abs( PI-theval ) > Precision::Angular()) |
433 | { |
434 | Standard_Real Alpha = Abs( LastParAngleCirc - FirstParAngleCirc ); |
435 | Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / PI)); |
436 | Graphic3d_Array1OfVertex ApproxArc( 0, NodeNumber-1 ); |
437 | Standard_Real delta = Alpha / (Standard_Real)( NodeNumber - 1 ); |
438 | gp_Pnt CurPnt; |
439 | for (Standard_Integer i = 0 ; i < NodeNumber; i++) |
440 | { |
441 | CurPnt = ElCLib::Value( FirstParAngleCirc, AngleCirc ); |
442 | ApproxArc(i).SetCoord( CurPnt.X(), CurPnt.Y(), CurPnt.Z() ); |
443 | FirstParAngleCirc += delta ; |
444 | } |
445 | Prs3d_Root::CurrentGroup( aPresentation )->Polyline( ApproxArc ); |
446 | } |
447 | else // null angle |
448 | { |
449 | Vrap(1).SetCoord( OffsetPoint.X(), |
450 | OffsetPoint.Y(), |
451 | OffsetPoint.Z()); |
452 | Vrap(2).SetCoord( EndOfArrow1.X(), EndOfArrow1.Y(), EndOfArrow1.Z() ); |
453 | Prs3d_Root::CurrentGroup( aPresentation )->Polyline( Vrap ); |
454 | } |
455 | |
456 | // Add presentation of arrows |
457 | DsgPrs::ComputeSymbol( aPresentation, LA, EndOfArrow1, EndOfArrow2, DirOfArrow1, DirOfArrow2, ArrowPrs ); |
458 | |
459 | // Drawing the text |
460 | Prs3d_Text::Draw( aPresentation, LA->TextAspect(), aText, OffsetPoint ); |
461 | |
462 | // Line from AttachmentPoint1 to end of Arrow1 |
463 | Vrap(1).SetCoord(AttachmentPoint1.X(), |
464 | AttachmentPoint1.Y(), |
465 | AttachmentPoint1.Z()); |
466 | Vrap(2).SetCoord( EndOfArrow1.X(), EndOfArrow1.Y(), EndOfArrow1.Z() ); |
467 | Prs3d_Root::CurrentGroup( aPresentation )->Polyline( Vrap ); |
468 | |
469 | // Line or arc from AttachmentPoint2 to its "projection" |
470 | if (AttachmentPoint2.Distance( ProjAttachPoint2 ) > Precision::Confusion()) |
471 | { |
472 | if (isPlane) |
473 | { |
474 | // Creating the line from AttachmentPoint2 to its projection |
475 | Vrap(1).SetCoord( AttachmentPoint2.X(), |
476 | AttachmentPoint2.Y(), |
477 | AttachmentPoint2.Z() ); |
478 | Vrap(2).SetCoord( ProjAttachPoint2.X(), |
479 | ProjAttachPoint2.Y(), |
480 | ProjAttachPoint2.Z() ); |
481 | Prs3d_Root::CurrentGroup( aPresentation )->Polyline( Vrap ); |
482 | } |
483 | else |
484 | { |
81bba717 |
485 | // Creating the arc from AttachmentPoint2 to its projection |
7fd59977 |
486 | Standard_Real Alpha = Abs( LastParAttachCirc - FirstParAttachCirc ); |
487 | Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / PI)); |
488 | Graphic3d_Array1OfVertex ApproxArc( 0, NodeNumber-1 ); |
489 | Standard_Real delta = Alpha / (Standard_Real)( NodeNumber - 1 ); |
490 | gp_Pnt CurPnt; |
491 | for (Standard_Integer i = 0 ; i < NodeNumber; i++) |
492 | { |
493 | CurPnt = ElCLib::Value( FirstParAttachCirc, AttachCirc ); |
494 | ApproxArc(i).SetCoord( CurPnt.X(), CurPnt.Y(), CurPnt.Z() ); |
495 | FirstParAttachCirc += delta ; |
496 | } |
497 | Prs3d_Root::CurrentGroup( aPresentation )->Polyline( ApproxArc ); |
498 | } |
499 | } |
500 | // Line from "projection" of AttachmentPoint2 to end of Arrow2 |
501 | Vrap(1).SetCoord( ProjAttachPoint2.X(), |
502 | ProjAttachPoint2.Y(), |
503 | ProjAttachPoint2.Z() ); |
504 | Vrap(2).SetCoord( EndOfArrow2.X(), EndOfArrow2.Y(), EndOfArrow2.Z()); |
505 | Prs3d_Root::CurrentGroup( aPresentation )->Polyline( Vrap ); |
506 | } |
507 | |
508 | |
509 | //========================================================================== |
510 | // function : DsgPrs_AnglePresentation::Add |
511 | // purpose : |
512 | // |
513 | //========================================================================== |
514 | |
515 | void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
516 | const Handle(Prs3d_Drawer)& aDrawer, |
517 | const Standard_Real theval, |
518 | const TCollection_ExtendedString& aText, |
519 | const gp_Pnt& CenterPoint, |
520 | const gp_Pnt& AttachmentPoint1, |
521 | const gp_Pnt& AttachmentPoint2, |
522 | const gp_Dir& dir1, |
523 | const gp_Dir& dir2, |
524 | const gp_Pnt& OffsetPoint) { |
525 | char valcar[80]; |
526 | sprintf(valcar,"%5.2f",theval); |
527 | |
528 | Handle(Prs3d_AngleAspect) LA = aDrawer->AngleAspect(); |
529 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
530 | gp_Dir Norm; |
531 | if (!dir1.IsParallel(dir2, Precision::Angular())) { |
532 | Norm = dir1.Crossed(dir2); |
533 | } |
534 | else { |
535 | gp_Dir dir2B = gp_Dir(gp_Vec(CenterPoint, OffsetPoint)); |
536 | Norm = dir1.Crossed(dir2B); |
537 | } |
538 | |
539 | if (Abs(theval) > PI) Norm.Reverse(); |
540 | |
541 | gp_Ax2 ax(CenterPoint,Norm,dir1); |
542 | gp_Circ cer(ax,CenterPoint.Distance(OffsetPoint)); |
543 | gp_Vec vec1(dir1); |
544 | vec1 *= cer.Radius(); |
545 | #ifdef DEB |
546 | gp_Pnt p1 = |
547 | #endif |
548 | CenterPoint.Translated(vec1); |
549 | gp_Vec vec2(dir2); |
550 | vec2 *= cer.Radius(); |
551 | gp_Pnt p2 = CenterPoint.Translated(vec2); |
552 | |
553 | Standard_Real uc1 = 0.; |
554 | Standard_Real uc2 = ElCLib::Parameter(cer,p2); |
555 | Standard_Real uco = ElCLib::Parameter(cer,OffsetPoint); |
556 | |
557 | Standard_Real udeb = uc1; |
558 | Standard_Real ufin = uc2; |
559 | |
560 | if (uco > ufin) { |
561 | if (Abs(theval)<PI) { |
81bba717 |
562 | // test if uco is in the opposite sector |
7fd59977 |
563 | if (uco > udeb+PI && uco < ufin+PI){ |
564 | udeb = udeb + PI; |
565 | ufin = ufin + PI; |
566 | uc1 = udeb; |
567 | uc2 = ufin; |
568 | } |
569 | } |
570 | } |
571 | |
572 | if (uco > ufin) { |
573 | if ((uco-uc2) < (uc1-uco+(2*PI))) { |
574 | ufin = uco; |
575 | } |
576 | else { |
577 | udeb = uco - 2*PI; |
578 | } |
579 | } |
580 | |
581 | Standard_Real alpha = Abs(ufin-udeb); |
582 | Standard_Integer nbp = Max (4 , Standard_Integer (50. * alpha / PI)); |
583 | Graphic3d_Array1OfVertex V(1,nbp); |
584 | Standard_Real dteta = alpha/(nbp-1); |
585 | gp_Pnt ptcur; |
586 | for (Standard_Integer i = 1; i<=nbp; i++) { |
587 | ptcur = ElCLib::Value(udeb+ dteta*(i-1),cer); |
588 | V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z()); |
589 | } |
590 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V); |
591 | |
592 | Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,OffsetPoint); |
593 | |
594 | gp_Vec vecarr; |
595 | gp_Pnt ptarr; |
596 | ElCLib::D1(uc1,cer,ptarr,vecarr); |
597 | gp_Ax1 ax1(ptarr, Norm); |
598 | gp_Dir dirarr(-vecarr); |
81bba717 |
599 | //calculate the angle of rotation |
7fd59977 |
600 | Standard_Real beta; |
601 | Standard_Real length = LA->ArrowAspect()->Length(); |
602 | if (length < Precision::Confusion()) length = 1.e-04; |
603 | gp_Pnt ptarr2(ptarr.XYZ() + length*dirarr.XYZ()); |
604 | Standard_Real parcir = ElCLib::Parameter(cer, ptarr2); |
605 | gp_Pnt ptarr3 = ElCLib::Value(parcir, cer); |
606 | gp_Vec v1(ptarr,ptarr2 ); |
607 | gp_Vec v2(ptarr, ptarr3); |
608 | beta = v1.Angle(v2); |
609 | dirarr.Rotate(ax1, beta); |
610 | Prs3d_Arrow::Draw(aPresentation, |
611 | ptarr, |
612 | dirarr, |
613 | LA->ArrowAspect()->Angle(), |
614 | length); |
615 | Graphic3d_Array1OfVertex Vrap(1,2); |
616 | Vrap(1).SetCoord(AttachmentPoint1.X(), |
617 | AttachmentPoint1.Y(), |
618 | AttachmentPoint1.Z()); |
619 | Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z()); |
620 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap); |
621 | |
622 | ElCLib::D1(uc2,cer,ptarr,vecarr); |
623 | ax1.SetLocation(ptarr); |
624 | gp_Dir dirarr2(vecarr); |
625 | dirarr2.Rotate(ax1, - beta); |
626 | Prs3d_Arrow::Draw(aPresentation, |
627 | ptarr, |
628 | dirarr2, |
629 | LA->ArrowAspect()->Angle(), |
630 | length); |
631 | |
632 | Vrap(1).SetCoord(AttachmentPoint2.X(), |
633 | AttachmentPoint2.Y(), |
634 | AttachmentPoint2.Z()); |
635 | Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z()); |
636 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap); |
637 | } |
638 | |
639 | //========================================================================== |
640 | // function : DsgPrs_AnglePresentation::Add |
81bba717 |
641 | // purpose : It is possible to choose the symbol of extremities of the face (arrow, point...) |
7fd59977 |
642 | //========================================================================== |
643 | |
644 | void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
645 | const Handle(Prs3d_Drawer)& aDrawer, |
646 | const Standard_Real theval, |
647 | const TCollection_ExtendedString& aText, |
648 | const gp_Pnt& CenterPoint, |
649 | const gp_Pnt& AttachmentPoint1, |
650 | const gp_Pnt& AttachmentPoint2, |
651 | const gp_Dir& dir1, |
652 | const gp_Dir& dir2, |
653 | const gp_Pnt& OffsetPoint, |
654 | const DsgPrs_ArrowSide ArrowPrs) |
655 | { |
656 | char valcar[80]; |
657 | sprintf(valcar,"%5.2f",theval); |
658 | |
659 | Handle(Prs3d_AngleAspect) LA = aDrawer->AngleAspect(); |
660 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
661 | gp_Dir Norm = dir1.Crossed(dir2); |
662 | |
663 | if (Abs(theval) > PI) Norm.Reverse(); |
664 | |
665 | gp_Ax2 ax(CenterPoint,Norm,dir1); |
666 | gp_Circ cer(ax,CenterPoint.Distance(OffsetPoint)); |
667 | gp_Vec vec1(dir1); |
668 | vec1 *= cer.Radius(); |
669 | #ifdef DEB |
670 | gp_Pnt p1 = |
671 | #endif |
672 | CenterPoint.Translated(vec1); |
673 | gp_Vec vec2(dir2); |
674 | vec2 *= cer.Radius(); |
675 | gp_Pnt p2 = CenterPoint.Translated(vec2); |
676 | |
677 | Standard_Real uc1 = 0.; |
678 | Standard_Real uc2 = ElCLib::Parameter(cer,p2); |
679 | Standard_Real uco = ElCLib::Parameter(cer,OffsetPoint); |
680 | |
681 | Standard_Real udeb = uc1; |
682 | Standard_Real ufin = uc2; |
683 | |
684 | if (uco > ufin) { |
685 | if (Abs(theval)<PI) { |
81bba717 |
686 | // test if uco is in the opposite sector |
7fd59977 |
687 | if (uco > udeb+PI && uco < ufin+PI){ |
688 | udeb = udeb + PI; |
689 | ufin = ufin + PI; |
690 | uc1 = udeb; |
691 | uc2 = ufin; |
692 | } |
693 | } |
694 | } |
695 | |
696 | if (uco > ufin) { |
697 | if ((uco-uc2) < (uc1-uco+(2*PI))) { |
698 | ufin = uco; |
699 | } |
700 | else { |
701 | udeb = uco - 2*PI; |
702 | } |
703 | } |
704 | |
705 | Standard_Real alpha = Abs(ufin-udeb); |
706 | Standard_Integer nbp = Max (4 , Standard_Integer (50. * alpha / PI)); |
707 | Graphic3d_Array1OfVertex V(1,nbp); |
708 | Standard_Real dteta = alpha/(nbp-1); |
709 | gp_Pnt ptcur; |
710 | for (Standard_Integer i = 1; i<=nbp; i++) { |
711 | ptcur = ElCLib::Value(udeb+ dteta*(i-1),cer); |
712 | V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z()); |
713 | } |
714 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V); |
715 | |
716 | Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,OffsetPoint); |
717 | |
81bba717 |
718 | // Lines of recall |
7fd59977 |
719 | gp_Vec vecarr; |
720 | gp_Pnt ptarr; |
721 | ElCLib::D1(uc1,cer,ptarr,vecarr); |
722 | gp_Ax1 ax1(ptarr, Norm); |
723 | gp_Dir dirarr(-vecarr); |
81bba717 |
724 | //calculate angle of rotation |
7fd59977 |
725 | Standard_Real beta(0.); |
726 | Standard_Real length = LA->ArrowAspect()->Length(); |
727 | if (length < Precision::Confusion()) length = 1.e-04; |
728 | gp_Pnt ptarr2(ptarr.XYZ() + length*dirarr.XYZ()); |
729 | Standard_Real parcir = ElCLib::Parameter(cer, ptarr2); |
730 | gp_Pnt ptarr3 = ElCLib::Value(parcir, cer); |
731 | gp_Vec v1(ptarr,ptarr2 ); |
732 | gp_Vec v2(ptarr, ptarr3); |
733 | beta = v1.Angle(v2); |
734 | dirarr.Rotate(ax1, beta); |
735 | |
736 | Graphic3d_Array1OfVertex Vrap(1,2); |
737 | Vrap(1).SetCoord(AttachmentPoint1.X(), |
738 | AttachmentPoint1.Y(), |
739 | AttachmentPoint1.Z()); |
740 | Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z()); |
741 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap); |
742 | |
743 | gp_Vec vecarr1; |
744 | gp_Pnt ptarr1; |
745 | ElCLib::D1(uc2,cer,ptarr1,vecarr1); |
746 | ax1.SetLocation(ptarr1); |
747 | gp_Dir dirarr2(vecarr1); |
748 | dirarr2.Rotate(ax1, - beta); |
749 | |
750 | |
751 | Vrap(1).SetCoord(AttachmentPoint2.X(), |
752 | AttachmentPoint2.Y(), |
753 | AttachmentPoint2.Z()); |
754 | Vrap(2).SetCoord(ptarr1.X(),ptarr1.Y(),ptarr1.Z()); |
755 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap); |
756 | |
757 | |
81bba717 |
758 | // One traces the arrows |
7fd59977 |
759 | DsgPrs::ComputeSymbol(aPresentation,LA,ptarr,ptarr1,dirarr,dirarr2,ArrowPrs); |
760 | } |
761 | |
762 | |
763 | |
764 | |
765 | //========================================================================== |
766 | // function : DsgPrs_AnglePresentation::Add |
767 | // purpose : |
768 | // |
769 | //========================================================================== |
770 | |
771 | void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
772 | const Handle(Prs3d_Drawer)& aDrawer, |
773 | const Standard_Real theval, |
774 | const gp_Pnt& CenterPoint, |
775 | const gp_Pnt& AttachmentPoint1, |
776 | const gp_Pnt& AttachmentPoint2, |
777 | const gp_Dir& dir1, |
778 | const gp_Dir& dir2, |
779 | const gp_Pnt& OffsetPoint) { |
780 | |
781 | |
782 | char valcar[80]; |
783 | sprintf(valcar,"%5.2f",theval); |
784 | TCollection_AsciiString valas(valcar); |
785 | TCollection_ExtendedString aText(valas); |
786 | |
787 | Handle(Prs3d_AngleAspect) LA = aDrawer->AngleAspect(); |
788 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
789 | gp_Dir Norm = dir1.Crossed(dir2); |
790 | |
791 | if (Abs(theval) > PI) Norm.Reverse(); |
792 | |
793 | gp_Ax2 ax(CenterPoint,Norm,dir1); |
794 | gp_Circ cer(ax,CenterPoint.Distance(OffsetPoint)); |
795 | gp_Vec vec1(dir1); |
796 | vec1 *= cer.Radius(); |
797 | #ifdef DEB |
798 | gp_Pnt p1 = |
799 | #endif |
800 | CenterPoint.Translated(vec1); |
801 | gp_Vec vec2(dir2); |
802 | vec2 *= cer.Radius(); |
803 | gp_Pnt p2 = CenterPoint.Translated(vec2); |
804 | |
805 | Standard_Real uc1 = 0.; |
806 | Standard_Real uc2 = ElCLib::Parameter(cer,p2); |
807 | Standard_Real uco = ElCLib::Parameter(cer,OffsetPoint); |
808 | |
809 | Standard_Real udeb = uc1; |
810 | Standard_Real ufin = uc2; |
811 | |
812 | if (uco > ufin) { |
813 | if (Abs(theval)<PI) { |
81bba717 |
814 | // test if uco is in the opposite sector |
7fd59977 |
815 | if (uco > udeb+PI && uco < ufin+PI){ |
816 | udeb = udeb + PI; |
817 | ufin = ufin + PI; |
818 | uc1 = udeb; |
819 | uc2 = ufin; |
820 | } |
821 | } |
822 | } |
823 | |
824 | if (uco > ufin) { |
825 | if ((uco-uc2) < (uc1-uco+(2*PI))) { |
826 | ufin = uco; |
827 | } |
828 | else { |
829 | udeb = uco - 2*PI; |
830 | } |
831 | } |
832 | |
833 | Standard_Real alpha = Abs(ufin-udeb); |
834 | Standard_Integer nbp = Max (4 , Standard_Integer (50. * alpha / PI)); |
835 | Graphic3d_Array1OfVertex V(1,nbp); |
836 | Standard_Real dteta = alpha/(nbp-1); |
837 | gp_Pnt ptcur; |
838 | for (Standard_Integer i = 1; i<=nbp; i++) { |
839 | ptcur = ElCLib::Value(udeb+ dteta*(i-1),cer); |
840 | V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z()); |
841 | } |
842 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V); |
843 | |
844 | Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,OffsetPoint); |
845 | |
846 | gp_Vec vecarr; |
847 | gp_Pnt ptarr; |
848 | ElCLib::D1(uc1,cer,ptarr,vecarr); |
849 | gp_Ax1 ax1(ptarr, Norm); |
850 | gp_Dir dirarr(-vecarr); |
81bba717 |
851 | //calculate the angle of rotation |
7fd59977 |
852 | Standard_Real beta; |
853 | Standard_Real length = LA->ArrowAspect()->Length(); |
854 | if (length < Precision::Confusion()) length = 1.e-04; |
855 | gp_Pnt ptarr2(ptarr.XYZ() + length*dirarr.XYZ()); |
856 | Standard_Real parcir = ElCLib::Parameter(cer, ptarr2); |
857 | gp_Pnt ptarr3 = ElCLib::Value(parcir, cer); |
858 | gp_Vec v1(ptarr,ptarr2 ); |
859 | gp_Vec v2(ptarr, ptarr3); |
860 | beta = v1.Angle(v2); |
861 | dirarr.Rotate(ax1, beta); |
862 | Prs3d_Arrow::Draw(aPresentation, |
863 | ptarr, |
864 | dirarr, |
865 | LA->ArrowAspect()->Angle(), |
866 | length); |
867 | |
868 | Graphic3d_Array1OfVertex Vrap(1,2); |
869 | Vrap(1).SetCoord(AttachmentPoint1.X(), |
870 | AttachmentPoint1.Y(), |
871 | AttachmentPoint1.Z()); |
872 | Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z()); |
873 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap); |
874 | |
875 | ElCLib::D1(uc2,cer,ptarr,vecarr); |
876 | ax1.SetLocation(ptarr); |
877 | gp_Dir dirarr2(vecarr); |
878 | dirarr2.Rotate(ax1, - beta); |
879 | Prs3d_Arrow::Draw(aPresentation, |
880 | ptarr, |
881 | dirarr2, |
882 | LA->ArrowAspect()->Angle(), |
883 | length); |
884 | |
885 | Vrap(1).SetCoord(AttachmentPoint2.X(), |
886 | AttachmentPoint2.Y(), |
887 | AttachmentPoint2.Z()); |
888 | Vrap(2).SetCoord(ptarr.X(),ptarr.Y(),ptarr.Z()); |
889 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap); |
890 | } |
891 | |
892 | void DsgPrs_AnglePresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
893 | const Handle(Prs3d_Drawer)& aDrawer, |
894 | const Standard_Real theval, |
895 | const gp_Pnt& CenterPoint, |
896 | const gp_Pnt& AttachmentPoint1, |
897 | const gp_Ax1& theAxe, |
898 | const DsgPrs_ArrowSide ArrowSide) |
899 | { |
900 | Handle(Prs3d_AngleAspect) LA = aDrawer->AngleAspect(); |
901 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
902 | |
903 | gp_Dir dir1(gp_Vec(CenterPoint, AttachmentPoint1)); |
904 | gp_Ax2 ax(CenterPoint,theAxe.Direction(),dir1); |
905 | gp_Circ cer(ax,CenterPoint.Distance(AttachmentPoint1)); |
906 | |
907 | Standard_Integer nbp = Max (4 , Standard_Integer (50. * theval / PI)); |
908 | Graphic3d_Array1OfVertex V(1,nbp); |
909 | Standard_Real dteta = theval/(nbp-1); |
910 | gp_Pnt ptcur; |
911 | for (Standard_Integer i = 1; i<=nbp; i++) { |
912 | ptcur = ElCLib::Value(dteta*(i-1),cer); |
913 | V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z()); |
914 | } |
915 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V); |
916 | |
917 | Standard_Real uc1 = 0.; |
918 | Standard_Real uc2 = ElCLib::Parameter(cer,AttachmentPoint1.Rotated(theAxe,theval)); |
919 | |
920 | gp_Vec vecarr; |
921 | gp_Pnt ptarr; |
922 | Standard_Real length = LA->ArrowAspect()->Length(); |
923 | if (length < Precision::Confusion()) length = 1.e-04; |
924 | |
925 | switch(ArrowSide) { |
926 | case DsgPrs_AS_NONE: |
927 | { |
928 | break; |
929 | } |
930 | case DsgPrs_AS_FIRSTAR: |
931 | { |
932 | ElCLib::D1(uc1,cer,ptarr,vecarr); |
933 | Prs3d_Arrow::Draw(aPresentation, |
934 | ptarr, |
935 | gp_Dir(-vecarr), |
936 | LA->ArrowAspect()->Angle(), |
937 | length); |
938 | break; |
939 | } |
940 | case DsgPrs_AS_LASTAR: |
941 | { |
942 | ElCLib::D1(uc2,cer,ptarr,vecarr); |
943 | Prs3d_Arrow::Draw(aPresentation, |
944 | ptarr, |
945 | gp_Dir(vecarr), |
946 | LA->ArrowAspect()->Angle(), |
947 | length); |
948 | break; |
949 | } |
950 | case DsgPrs_AS_BOTHAR: |
951 | { |
952 | ElCLib::D1(uc1,cer,ptarr,vecarr); |
953 | Prs3d_Arrow::Draw(aPresentation, |
954 | ptarr, |
955 | gp_Dir(-vecarr), |
956 | LA->ArrowAspect()->Angle(), |
957 | length); |
958 | ElCLib::D1(uc2,cer,ptarr,vecarr); |
959 | Prs3d_Arrow::Draw(aPresentation, |
960 | ptarr, |
961 | gp_Dir(vecarr), |
962 | LA->ArrowAspect()->Angle(), |
963 | length); |
964 | break; |
965 | } |
966 | #ifndef DEB |
967 | default: |
968 | break; |
969 | #endif |
970 | } |
971 | } |
972 | |