1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <Prs2d_Length.ixx>
19 #include <Geom2d_Line.hxx>
20 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
22 #define VERTEXMARKER 2
23 #define DEFAULTMARKERSIZE 3.0
24 #define XROTATE(x,y) ((x)*cosa - (y)*sina)
25 #define YROTATE(x,y) ((y)*cosa + (x)*sina)
28 Prs2d_Length::Prs2d_Length( const Handle(Graphic2d_GraphicObject)& aGO,
29 const gp_Pnt2d& anAttachPnt1,
30 const gp_Pnt2d& anAttachPnt2,
31 const TCollection_ExtendedString& aText,
32 const Standard_Real aTxtScale,
33 const Standard_Real aLength,
34 const Prs2d_TypeOfDist aTypeDist,
35 const Standard_Real anArrAngle,
36 const Standard_Real anArrLength,
37 const Prs2d_TypeOfArrow anArrType,
38 const Prs2d_ArrowSide anArrow,
39 const Standard_Boolean IsRevArrow )
41 : Prs2d_Dimension( aGO, aText, aTxtScale, anArrAngle,
42 anArrLength, anArrType, anArrow, IsRevArrow ),
44 myTypeDist( aTypeDist )
48 myAX1 = Standard_ShortReal( anAttachPnt1.X() );
49 myAY1 = Standard_ShortReal( anAttachPnt1.Y() );
50 myAX2 = Standard_ShortReal( anAttachPnt2.X() );
51 myAY2 = Standard_ShortReal( anAttachPnt2.Y() );
52 GetPntProject( aLength );
53 ComputeArrows( Standard_False );
57 Prs2d_Length::Prs2d_Length( const Handle(Graphic2d_GraphicObject)& aGO,
58 const gp_Pnt2d& anAttachPnt,
59 const gp_Lin2d& anAttachLin,
60 const TCollection_ExtendedString& aText,
61 const Standard_Real aTxtScale,
62 const Standard_Real /*aLenAttachLin*/,
63 const Standard_Real anArrAngle,
64 const Standard_Real anArrLength,
65 const Prs2d_TypeOfArrow anArrType,
66 const Prs2d_ArrowSide anArrow,
67 const Standard_Boolean IsRevArrow )
69 : Prs2d_Dimension( aGO, aText, aTxtScale, anArrAngle,
70 anArrLength, anArrType, anArrow, IsRevArrow ),
72 myTypeDist( Prs2d_TOD_AUTOMATIC )
76 gp_Pnt2d aPntProj1 = anAttachPnt, aPntProj2;
77 Handle(Geom2d_Line) theLine = new Geom2d_Line( anAttachLin );
78 Geom2dAPI_ProjectPointOnCurve theProj( aPntProj1, theLine );
79 aPntProj2 = theProj.Point(1);
81 myX1 = Standard_ShortReal( aPntProj1.X() );
82 myY1 = Standard_ShortReal( aPntProj1.Y() );
83 myX2 = Standard_ShortReal( aPntProj2.X() );
84 myY2 = Standard_ShortReal( aPntProj2.Y() );
96 if ( myX2 < myMinX ) myMinX = myX2;
97 if ( myY2 < myMinY ) myMinY = myY2;
98 if ( myX2 > myMaxX ) myMaxX = myX2;
99 if ( myY2 > myMaxY ) myMaxY = myY2;
101 ComputeArrows( Standard_True );
104 Prs2d_Length::Prs2d_Length( const Handle(Graphic2d_GraphicObject)& aGO,
105 const gp_Lin2d& anAttachLin1,
106 const gp_Lin2d& anAttachLin2,
107 const TCollection_ExtendedString& aText,
108 const Standard_Real aTxtScale,
109 const Standard_Real /*aLenAttachLin*/,
110 const Standard_Real anArrAngle,
111 const Standard_Real anArrLength,
112 const Prs2d_TypeOfArrow anArrType,
113 const Prs2d_ArrowSide anArrow,
114 const Standard_Boolean IsRevArrow )
115 : Prs2d_Dimension( aGO, aText, aTxtScale, anArrAngle,
116 anArrLength, anArrType, anArrow, IsRevArrow ),
118 myTypeDist( Prs2d_TOD_AUTOMATIC )
121 SetSymbolCode( 198 );
122 gp_Pnt2d aPntProj1, aPntProj2;
123 aPntProj1 = anAttachLin1.Location();
124 Handle(Geom2d_Line) theLine = new Geom2d_Line( anAttachLin2 );
125 Geom2dAPI_ProjectPointOnCurve theProj( aPntProj1, theLine );
126 aPntProj2 = theProj.Point(1);
128 myX1 = Standard_ShortReal( aPntProj1.X() );
129 myY1 = Standard_ShortReal( aPntProj1.Y() );
130 myX2 = Standard_ShortReal( aPntProj2.X() );
131 myY2 = Standard_ShortReal( aPntProj2.Y() );
143 if ( myX2 < myMinX ) myMinX = myX2;
144 if ( myY2 < myMinY ) myMinY = myY2;
145 if ( myX2 > myMaxX ) myMaxX = myX2;
146 if ( myY2 > myMaxY ) myMaxY = myY2;
148 ComputeArrows( Standard_True );
152 void Prs2d_Length::Draw( const Handle(Graphic2d_Drawer)& aDrawer )
154 Standard_Boolean IsIn = Standard_False;
156 if ( ! myGOPtr->IsTransformed() )
157 IsIn = aDrawer->IsIn( myMinX,myMaxX,myMinY,myMaxY );
160 Standard_ShortReal minx, miny, maxx, maxy;
161 MinMax(minx,maxx,miny,maxy);
162 IsIn = aDrawer->IsIn( minx,maxx,miny,maxy );
168 DrawLineAttrib(aDrawer);
169 // enk code get absolute coordinates for text
170 Standard_Real theTxtX, theTxtY,theTxtAngle;
171 gp_Pnt2d thePnt1(myX1,myY1), thePnt2(myX2,myY2);
172 gp_Vec2d VX(1.,0.), theVec(thePnt2,thePnt1);
173 theVec.Rotate(myTextAngle);
176 theTxtAngle=myAbsAngle;
177 gp_Pnt2d pntText(theTxtX,theTxtY);
178 Standard_Real theSmbX = 0., theSmbY = 0.;
182 aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0,
183 Standard_ShortReal(myTextScale*aDrawer->Scale()),
184 Standard_ShortReal(myTextScale*aDrawer->Scale()),
186 Standard_Character code = SymbolCode();
187 TCollection_ExtendedString txtSymb( code );
188 pntText.Coord( theSmbX, theSmbY );
189 Standard_ShortReal ws, hs;
190 aDrawer->GetTextSize( txtSymb, ws, hs );
192 Standard_ShortReal ddd = aDrawer->Convert(2);
193 theVec = VX.Rotated( theTxtAngle );
194 theVec *= ( ws + ddd );
195 gp_Pnt2d pntSymb = pntText.Translated( theVec );
196 pntSymb.Coord( theTxtX, theTxtY );
199 pntText.Coord( theTxtX, theTxtY );
202 Standard_ShortReal a = myX1 , b = myY1 , c = myX2 , d = myY2;
203 Standard_ShortReal a1 = myAX1, b1 = myAY1, c1 = myAX2, d1 = myAY2,
204 t1 = Standard_ShortReal(theTxtX),
205 t2 = Standard_ShortReal(theTxtY),
206 ts1 = Standard_ShortReal(theSmbX),
207 ts2 = Standard_ShortReal(theSmbY);
209 Standard_ShortReal at = myXT1, bt = myYT1, ct = myXT2, dt = myYT2;
211 TShort_Array1OfShortReal Xpoint1( 1, 3 ), Ypoint1( 1, 3 ),
212 Xpoint2( 1, 3 ), Ypoint2( 1, 3 );
214 if ( myGOPtr->IsTransformed() )
216 gp_GTrsf2d aTrsf = myGOPtr->Transform();
217 Standard_Real AT, BT;
219 if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
221 for ( Standard_Integer j = 1; j <= 3; j++ )
223 AT = Standard_Real( myXVert1(j) );
224 BT = Standard_Real( myYVert1(j) );
225 aTrsf.Transforms( AT, BT );
226 Xpoint1(j) = Standard_ShortReal( AT );
227 Ypoint1(j) = Standard_ShortReal( BT );
229 } // end if myArrow is FIRSTAR ot BOTHAR
231 if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
233 for ( Standard_Integer j = 1; j <= 3; j++ )
235 AT = Standard_Real( myXVert2(j) );
236 BT = Standard_Real( myYVert2(j) );
237 aTrsf.Transforms( AT, BT );
238 Xpoint2(j) = Standard_ShortReal( AT );
239 Ypoint2(j) = Standard_ShortReal( BT );
241 } // end if myArrow is LASTAR ot BOTHAR
243 AT = Standard_Real( a );
244 BT = Standard_Real( b );
245 aTrsf.Transforms( AT, BT );
246 a = Standard_ShortReal( AT );
247 b = Standard_ShortReal( BT );
249 AT = Standard_Real( c );
250 BT = Standard_Real( d );
251 aTrsf.Transforms( AT, BT );
252 c = Standard_ShortReal( AT );
253 d = Standard_ShortReal( BT );
255 AT = Standard_Real( t1 );
256 BT = Standard_Real( t2 );
257 aTrsf.Transforms( AT, BT );
258 t1 = Standard_ShortReal( AT );
259 t2 = Standard_ShortReal( BT );
261 AT = Standard_Real( a1 );
262 BT = Standard_Real( b1 );
263 aTrsf.Transforms( AT, BT );
264 a1 = Standard_ShortReal( AT );
265 b1 = Standard_ShortReal( BT );
267 AT = Standard_Real( c1 );
268 BT = Standard_Real( d1 );
269 aTrsf.Transforms( AT, BT );
271 c1 = Standard_ShortReal( AT );
272 d1 = Standard_ShortReal( BT );
274 AT = Standard_Real( ts1 );
275 BT = Standard_Real( ts2 );
276 aTrsf.Transforms( AT, BT );
277 ts1 = Standard_ShortReal( AT );
278 ts2 = Standard_ShortReal( BT );
280 if ( ArrowIsReversed() )
282 AT = Standard_Real( at );
283 BT = Standard_Real( bt );
284 aTrsf.Transforms( AT, BT );
285 at = Standard_ShortReal( AT );
286 bt = Standard_ShortReal( BT );
288 AT = Standard_Real( ct );
289 BT = Standard_Real( dt );
290 aTrsf.Transforms( AT, BT );
291 ct = Standard_ShortReal( AT );
292 dt = Standard_ShortReal( BT );
296 if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
298 Xpoint1.Assign( myXVert1 );
299 Ypoint1.Assign( myYVert1 );
301 if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
303 Xpoint2.Assign( myXVert2 );
304 Ypoint2.Assign( myYVert2 );
306 } // end if GO is transformed
308 if ( ArrowIsReversed() )
309 aDrawer->MapSegmentFromTo( at, bt, ct, dt );
311 aDrawer->MapSegmentFromTo( a, b, c, d );
313 // Drawing auxiliary lines which connect a model and a dimension
314 // begin enk code. Auxiliary lines which connect to model with same tolerance
315 if (!((a==a1 && b==b1)||(c==c1 && d==d1)))
317 gp_Pnt2d aAuxLinePnt1( a, b) , aAuxLinePnt2( a1, b1);
318 gp_Pnt2d aAuxLinePnt3( c, d) , aAuxLinePnt4( c1, d1);
319 gp_Vec2d aAuxVec(aAuxLinePnt2,aAuxLinePnt1);
320 Standard_ShortReal dxx = aDrawer->Convert(ADDPIX);
325 aAuxLinePnt1.Translate(aAuxVec);
326 aAuxLinePnt2.Translate(aAuxVec);
327 aAuxLinePnt3.Translate(aAuxVec);
328 aAuxLinePnt4.Translate(aAuxVec);
330 a =Standard_ShortReal(aAuxLinePnt1.X());
331 b =Standard_ShortReal(aAuxLinePnt1.Y());
332 a1=Standard_ShortReal(aAuxLinePnt2.X());
333 b1=Standard_ShortReal(aAuxLinePnt2.Y());
334 c =Standard_ShortReal(aAuxLinePnt3.X());
335 d =Standard_ShortReal(aAuxLinePnt3.Y());
336 c1=Standard_ShortReal(aAuxLinePnt4.X());
337 d1=Standard_ShortReal(aAuxLinePnt4.Y());
341 aDrawer->MapSegmentFromTo( a, b, a1, b1 );
342 aDrawer->MapSegmentFromTo( c, d, c1, d1 );
346 Standard_Character code = SymbolCode();
347 TCollection_ExtendedString txtSymb( code );
348 aDrawer->MapTextFromTo( txtSymb, ts1, ts2,Standard_ShortReal(theTxtAngle),
349 0., 0., Aspect_TOT_SOLID );
351 aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0,
352 Standard_ShortReal(myTextScale*aDrawer->Scale()),
353 Standard_ShortReal(myTextScale*aDrawer->Scale()),
355 aDrawer->MapTextFromTo( myText, t1, t2, Standard_ShortReal(theTxtAngle),
356 0., 0., Aspect_TOT_SOLID );
359 if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
361 if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED )
363 aDrawer->MapPolygonFromTo( Xpoint1, Ypoint1 );
366 aDrawer->MapPolylineFromTo( Xpoint1, Ypoint1 );
370 if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
372 if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED )
374 aDrawer->MapPolygonFromTo( Xpoint2, Ypoint2 );
377 aDrawer->MapPolylineFromTo( Xpoint2, Ypoint2 );
381 } // end if IsIn is true
385 void Prs2d_Length::DrawElement( const Handle(Graphic2d_Drawer)& aDrawer,
386 const Standard_Integer anIndex )
388 Standard_Boolean IsIn = Standard_False;
390 if ( ! myGOPtr->IsTransformed() )
391 IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY );
394 Standard_ShortReal minx, miny, maxx, maxy;
395 MinMax( minx, maxx, miny, maxy );
396 IsIn = aDrawer->IsIn( minx, maxx, miny, maxy );
401 DrawLineAttrib( aDrawer );
402 // begin enk code text location
403 Standard_Real theTxtX, theTxtY,theTxtAngle;
404 gp_Pnt2d thePnt1(myX1,myY1), thePnt2(myX2,myY2);
405 gp_Vec2d VX(1.,0.), theVec(thePnt2,thePnt1);
406 theVec.Rotate(myTextAngle);
409 theTxtAngle=myAbsAngle;
410 gp_Pnt2d pntText(theTxtX,theTxtY);
412 Standard_ShortReal a = myX1, b = myY1, c = myX2, d = myY2,
413 t1 = Standard_ShortReal(theTxtX),
414 t2 = Standard_ShortReal(theTxtY),
415 aa1 = myAX1, ba1 = myAY1, aa2 = myAX2, ba2 = myAY2;
416 TShort_Array1OfShortReal Xpoint( 1, 3 ), Ypoint( 1, 3 );
420 Xpoint.Assign( myXVert1 );
421 Ypoint.Assign( myYVert1 );
422 } else if ( anIndex == 2 )
424 Xpoint.Assign( myXVert2 );
425 Ypoint.Assign( myYVert2 );
428 if ( myGOPtr->IsTransformed () )
430 gp_GTrsf2d aTrsf = myGOPtr->Transform ();
431 Standard_Real a1, b1, c1, d1, aa11, ba11, aa21, ba21;
435 for ( Standard_Integer j = 1; j <= 3; j++ )
437 a1 = Standard_Real( Xpoint(j) );
438 b1 = Standard_Real( Xpoint(j) );
439 aTrsf.Transforms( a1, b1 );
440 Xpoint(j) = Standard_ShortReal( a1 );
441 Ypoint(j) = Standard_ShortReal( b1 );
443 } else if ( anIndex == 2 )
445 for ( Standard_Integer j = 1; j <= 3; j++ )
447 a1 = Standard_Real( Xpoint(j) );
448 b1 = Standard_Real( Xpoint(j) );
449 aTrsf.Transforms( a1, b1 );
450 Xpoint(j) = Standard_ShortReal( a1 );
451 Ypoint(j) = Standard_ShortReal( b1 );
453 } else if ( anIndex == 4 )
455 a1 = Standard_Real( a );
456 b1 = Standard_Real( b );
457 c1 = Standard_Real( c );
458 d1 = Standard_Real( d );
459 aTrsf.Transforms( a1, b1 );
460 aTrsf.Transforms( c1, d1 );
461 a = Standard_ShortReal( a1 );
462 b = Standard_ShortReal( b1 );
463 c = Standard_ShortReal( c1 );
464 d = Standard_ShortReal( d1 );
465 } else if ( anIndex == 3 )
467 a1 = Standard_Real( t1 );
468 b1 = Standard_Real( t2);
469 aTrsf.Transforms( a1, b1 );
470 t1 = Standard_ShortReal( a1 );
471 t2 = Standard_ShortReal( b1);
472 } else if ( anIndex == 5 )
474 aa11 = Standard_Real( aa1 );
475 ba11 = Standard_Real( ba1 );
476 aTrsf.Transforms( aa11, ba11 );
477 aa1 = Standard_ShortReal( aa11 );
478 ba1 = Standard_ShortReal( ba11 );
480 } else if ( anIndex == 6 )
482 aa21 = Standard_Real( aa2 );
483 ba21 = Standard_Real( ba2 );
484 aTrsf.Transforms( aa21, ba21 );
485 aa2 = Standard_ShortReal( aa21 );
486 ba2 = Standard_ShortReal( ba21 );
490 if ( anIndex == 1 || anIndex == 2 )
491 if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED )
493 aDrawer->MapPolygonFromTo( Xpoint, Ypoint );
496 aDrawer->MapPolylineFromTo( Xpoint, Ypoint );
498 else if ( anIndex == 4 )
499 aDrawer->MapSegmentFromTo( a, b, c, d );
500 else if ( anIndex == 3 )
501 aDrawer->MapTextFromTo( myText, t1, t2, Standard_ShortReal(theTxtAngle),
502 0., 0., Aspect_TOT_SOLID );
503 else if ( anIndex == 5 )
504 aDrawer->MapSegmentFromTo( a, b, aa1, ba1 );
505 else if ( anIndex == 6 )
506 aDrawer->MapSegmentFromTo( c, d, aa2, ba2 );
508 } // end if IsIn is true
512 void Prs2d_Length::DrawVertex( const Handle(Graphic2d_Drawer)& aDrawer,
513 const Standard_Integer anIndex )
515 Standard_Boolean IsIn = Standard_False;
517 if ( ! myGOPtr->IsTransformed() )
518 IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY );
521 Standard_ShortReal minx, miny, maxx, maxy;
522 MinMax( minx, maxx, miny, maxy );
523 IsIn = aDrawer->IsIn( minx, maxx, miny, maxy );
527 if ( anIndex == 1 || anIndex == 2 )
529 Standard_ShortReal X=0., Y=0.;
533 } else if ( anIndex == 2 )
537 DrawMarkerAttrib( aDrawer );
538 if ( myGOPtr->IsTransformed() )
540 gp_GTrsf2d aTrsf = myGOPtr->Transform();
541 Standard_Real A = Standard_Real( X ), B = Standard_Real( Y );
542 aTrsf.Transforms( A, B );
543 X = Standard_ShortReal( A );
544 Y = Standard_ShortReal( B );
546 aDrawer->MapMarkerFromTo(VERTEXMARKER,X,Y, DEFAULTMARKERSIZE,
547 DEFAULTMARKERSIZE,0.0);
552 Standard_Boolean Prs2d_Length::Pick( const Standard_ShortReal X,
553 const Standard_ShortReal Y,
554 const Standard_ShortReal aPrecision,
555 const Handle(Graphic2d_Drawer)& aDrawer )
557 Standard_ShortReal SRX = X, SRY = Y;
558 Standard_Boolean Result = Standard_False;
560 if (IsInMinMax (X, Y, aPrecision) )
562 if ( myGOPtr->IsTransformed () )
564 gp_GTrsf2d aTrsf = ( myGOPtr->Transform() ).Inverted();
565 Standard_Real RX = Standard_Real(SRX), RY = Standard_Real(SRY);
566 aTrsf.Transforms(RX, RY);
567 SRX = Standard_ShortReal(RX);
568 SRY = Standard_ShortReal(RY);
571 if ( Graphic2d_Primitive::IsOn( SRX, SRY, myX1, myY1, aPrecision ) )
574 return Standard_True;
575 } else if ( Graphic2d_Primitive::IsOn( SRX, SRY, myX2, myY2, aPrecision ) )
578 return Standard_True;
581 if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
583 for ( Standard_Integer i = 1; i < 3 ; i++)
584 if ( IsOn( SRX, SRY, myXVert1(i), myYVert1(i),
585 myXVert1(i+1), myYVert1( i+1 ), aPrecision ) )
588 return Standard_True;
591 if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED )
592 if ( IsIn( SRX, SRY, myXVert1, myYVert1, aPrecision ) )
595 return Standard_True;
597 } // end if myArrow == FIRSTAR or BOTHAR
599 if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
601 for ( Standard_Integer i = 1; i < 3 ; i++)
602 if ( IsOn( SRX, SRY, myXVert2(i), myYVert2(i),
603 myXVert2(i+1), myYVert2( i+1 ), aPrecision ) )
606 return Standard_True;
609 if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED )
610 if ( IsIn( SRX, SRY, myXVert2, myYVert2, aPrecision ) )
613 return Standard_True;
615 } // end if myArrow == LASTAR or BOTHAR
617 Standard_ShortReal width,height,xoffset,yoffset;
618 Standard_ShortReal hscale = Standard_ShortReal(myTextScale*aDrawer->Scale()),
619 wscale = Standard_ShortReal(myTextScale*aDrawer->Scale());
620 Standard_ShortReal TX = X, TY = Y;
622 aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, hscale, wscale,
624 if ( !aDrawer->GetTextSize( myText, width, height, xoffset, yoffset ) )
626 width = height = xoffset = yoffset = 0.;
628 // begin enk code text location
629 Standard_Real theTxtX, theTxtY,theTxtAngle;
630 gp_Pnt2d thePnt1(myX1,myY1), thePnt2(myX2,myY2);
631 gp_Vec2d VX(1.,0.), theVec(thePnt2,thePnt1);
632 theVec.Rotate(myTextAngle);
635 theTxtAngle=myAbsAngle;
636 gp_Pnt2d pntText(theTxtX,theTxtY);
638 Standard_ShortReal cosa = Standard_ShortReal(Cos( -theTxtAngle )),
639 sina = Standard_ShortReal(Sin( -theTxtAngle )),
640 dx = TX-Standard_ShortReal(theTxtX),
641 dy = TY-Standard_ShortReal(theTxtY),
645 Result = (x >= -aPrecision + xoffset)
646 && (x <= width + xoffset + aPrecision)
647 && (y >= -yoffset - aPrecision)
648 && (y <= height - yoffset + aPrecision);
653 return Standard_True;
655 // begin enk code auxiality lines
656 Standard_ShortReal a,b,c,d,a1,b1,c1,d1;
665 if (!((a==a1 && b==b1)||(c==c1 && d==d1)))
667 gp_Pnt2d aAuxLinePnt1( myX1, myY1) , aAuxLinePnt2( myAX1, myAY1);
668 gp_Pnt2d aAuxLinePnt3( myX2, myY2) , aAuxLinePnt4( myAX2, myAY2);
669 gp_Vec2d aAuxVec(aAuxLinePnt2,aAuxLinePnt1);
670 Standard_ShortReal dxx = aDrawer->Convert(ADDPIX);
674 aAuxLinePnt1.Translate(aAuxVec);
675 aAuxLinePnt2.Translate(aAuxVec);
676 aAuxLinePnt3.Translate(aAuxVec);
677 aAuxLinePnt4.Translate(aAuxVec);
679 a =Standard_ShortReal(aAuxLinePnt1.X());
680 b =Standard_ShortReal(aAuxLinePnt1.Y());
681 a1=Standard_ShortReal(aAuxLinePnt2.X());
682 b1=Standard_ShortReal(aAuxLinePnt2.Y());
683 c =Standard_ShortReal(aAuxLinePnt3.X());
684 d =Standard_ShortReal(aAuxLinePnt3.Y());
685 c1=Standard_ShortReal(aAuxLinePnt4.X());
686 d1=Standard_ShortReal(aAuxLinePnt4.Y());
690 if ( IsOn( SRX, SRY, myX1, myY1, myX2, myY2, aPrecision ) )
693 return Standard_True;
694 } else if ( IsOn( SRX, SRY, a, b, a1, b1, aPrecision ) )
697 return Standard_True;
698 } else if ( IsOn( SRX, SRY, c, d, c1, d1, aPrecision ) )
701 return Standard_True;
704 return Standard_False;
707 void Prs2d_Length::GetPntProject( const Standard_Real aLength )
710 gp_Pnt2d myPntAttach1( myAX1, myAY1 ), myPntAttach2( myAX2, myAY2 );
711 gp_Pnt2d aPntProj1, aPntProj2, MinMaxPnt = myPntAttach1;
713 switch ( myTypeDist )
715 case Prs2d_TOD_HORIZONTAL:
719 if ( MinMaxPnt.Y() > myPntAttach2.Y() )
721 myPntAttach1 = myPntAttach2;
722 myPntAttach2 = MinMaxPnt;
726 if ( MinMaxPnt.Y() < myPntAttach2.Y() )
728 myPntAttach1 = myPntAttach2;
729 myPntAttach2 = MinMaxPnt;
732 aPntProj1 = gp_Pnt2d( myPntAttach1.X(), myPntAttach1.Y() + aLength );
733 Handle(Geom2d_Line) theLine = new Geom2d_Line( aPntProj1,
734 gp_Dir2d( aPntProj1.X(), 0. ) );
735 Geom2dAPI_ProjectPointOnCurve theProj( myPntAttach2, theLine );
736 aPntProj2 = theProj.Point(1);
741 case Prs2d_TOD_VERTICAL:
745 if ( MinMaxPnt.X() > myPntAttach2.X() )
747 myPntAttach1 = myPntAttach2;
748 myPntAttach2 = MinMaxPnt;
752 if ( MinMaxPnt.X() < myPntAttach2.X() )
754 myPntAttach1 = myPntAttach2;
755 myPntAttach2 = MinMaxPnt;
758 aPntProj1 = gp_Pnt2d( myPntAttach1.X() + aLength , myPntAttach1.Y());
759 Handle(Geom2d_Line) theLine = new Geom2d_Line( aPntProj1,
760 gp_Dir2d( 0., aPntProj1.Y() ) );
761 Geom2dAPI_ProjectPointOnCurve theProj( myPntAttach2, theLine );
762 aPntProj2 = theProj.Point(1);
766 /* case Prs2d_TOD_OBLIQUE:
768 gp_Vec2d DirLin1( myPntAttach1, myPntAttach2 );
769 gp_Vec2d DirLin2 = DirLin1.Reversed();
774 DirLin1.Rotate( M_PI/2. );
775 DirLin2.Rotate( -M_PI/2. );
776 aPntProj1 = myPntAttach1.Translated( DirLin1 );
777 aPntProj2 = myPntAttach2.Translated( DirLin2 );;
779 } */ // commented by enk
781 case Prs2d_TOD_AUTOMATIC:
782 case Prs2d_TOD_OBLIQUE:
785 gp_Vec2d DirLin1( myPntAttach1, myPntAttach2 );
786 gp_Vec2d DirLin2 = DirLin1.Reversed();
791 DirLin1.Rotate( M_PI/2. );
792 DirLin2.Rotate( -M_PI/2. );
793 aPntProj1 = myPntAttach1.Translated( DirLin1 );
794 aPntProj2 = myPntAttach2.Translated( DirLin2 );;
797 } // end switch TypeOfDist
799 myAX1 = Standard_ShortReal( myPntAttach1.X() );
800 myAY1 = Standard_ShortReal( myPntAttach1.Y() );
801 myAX2 = Standard_ShortReal( myPntAttach2.X() );
802 myAY2 = Standard_ShortReal( myPntAttach2.Y() );
803 myX1 = Standard_ShortReal( aPntProj1.X() );
804 myY1 = Standard_ShortReal( aPntProj1.Y() );
805 myX2 = Standard_ShortReal( aPntProj2.X() );
806 myY2 = Standard_ShortReal( aPntProj2.Y() );
808 myMinX = Min( myX1, myX2 );
809 myMinY = Min( myY1, myY2 );
810 myMaxX = Max( myX1, myX2 );
811 myMaxY = Max( myY1, myY2 );
813 if ( myAX1 < myMinX ) myMinX = myAX1;
814 if ( myAY1 < myMinY ) myMinY = myAY1;
815 if ( myAX1 > myMaxX ) myMaxX = myAX1;
816 if ( myAY1 > myMaxY ) myMaxY = myAY1;
818 if ( myAX2 < myMinX ) myMinX = myAX2;
819 if ( myAY2 < myMinY ) myMinY = myAY2;
820 if ( myAX2 > myMaxX ) myMaxX = myAX2;
821 if ( myAY2 > myMaxY ) myMaxY = myAY2;
825 void Prs2d_Length::ComputeArrows( const Standard_Boolean /*isnotPoints*/ )
828 Standard_Real ArrAngle = M_PI/180. * ArrowAngle(), theAngle;
829 gp_Pnt2d aPnt1( myX1, myY1 ), aPnt2( myX2, myY2 );
830 gp_Pnt2d theOrigine( 0., 0.), P1, P2, P3;
831 gp_Vec2d VX( 1., 0. ), VDir;
838 if ( ArrowIsReversed() )
840 gp_Pnt2d tP1 = aPnt1, tP2 = aPnt2;
841 gp_Vec2d tVD( aPnt1, aPnt2 );
843 tVD *= ( 1.3 * myArrowLen );
844 tP1.Translate( -tVD );
845 tP2.Translate( tVD );
846 Standard_Real X1, Y1, X2, Y2;
850 myXT1 = Standard_ShortReal( X1 );
851 myYT1 = Standard_ShortReal( Y1 );
852 myXT2 = Standard_ShortReal( X2 );
853 myYT2 = Standard_ShortReal( Y2 );
856 if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
859 P2 = gp_Pnt2d( myArrowLen, myArrowLen*Tan( ArrAngle/2. ) );
860 P3 = gp_Pnt2d( myArrowLen, -myArrowLen*Tan( ArrAngle/2. ) );
861 VDir = gp_Vec2d( aPnt1, aPnt2 );
862 if ( ArrowIsReversed() ) VDir.Reverse();
863 theAngle = VX.Angle( VDir );
864 P2.Rotate( theOrigine, theAngle );
865 P3.Rotate( theOrigine, theAngle );
866 P2.Translate( gp_Vec2d( theOrigine, P1 ) );
867 P3.Translate( gp_Vec2d( theOrigine, P1 ) );
869 myXVert1(1) = Standard_ShortReal( P2.X() );
870 myYVert1(1) = Standard_ShortReal( P2.Y() );
871 myXVert1(2) = Standard_ShortReal( P1.X() );
872 myYVert1(2) = Standard_ShortReal( P1.Y() );
873 myXVert1(3) = Standard_ShortReal( P3.X() );
874 myYVert1(3) = Standard_ShortReal( P3.Y() );
876 for ( Standard_Integer i = 1; i <= 3; i++ )
878 if ( myXVert1(i) < myMinX ) myMinX = myXVert1(i);
879 if ( myYVert1(i) < myMinY ) myMinY = myYVert1(i);
880 if ( myXVert1(i) > myMaxX ) myMaxX = myXVert1(i);
881 if ( myYVert1(i) > myMaxY ) myMaxY = myYVert1(i);
883 } // end if myArrow is FIRSTAR or BOTHAR
885 if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
888 P2 = gp_Pnt2d( myArrowLen, myArrowLen * Tan( ArrAngle/2. ) );
889 P3 = gp_Pnt2d( myArrowLen, -myArrowLen * Tan( ArrAngle/2. ) );
890 VDir = gp_Vec2d( aPnt2, aPnt1 );
891 if ( ArrowIsReversed() ) VDir.Reverse();
892 theAngle = VX.Angle( VDir );
893 P2.Rotate( theOrigine, theAngle );
894 P3.Rotate( theOrigine, theAngle );
895 P2.Translate( gp_Vec2d( theOrigine, P1 ) );
896 P3.Translate( gp_Vec2d( theOrigine, P1 ) );
898 myXVert2(1) = Standard_ShortReal( P2.X() );
899 myYVert2(1) = Standard_ShortReal( P2.Y() );
900 myXVert2(2) = Standard_ShortReal( P1.X() );
901 myYVert2(2) = Standard_ShortReal( P1.Y() );
902 myXVert2(3) = Standard_ShortReal( P3.X() );
903 myYVert2(3) = Standard_ShortReal( P3.Y() );
905 for ( Standard_Integer i = 1; i <= 3; i++ )
907 if ( myXVert2(i) < myMinX ) myMinX = myXVert2(i);
908 if ( myYVert2(i) < myMinY ) myMinY = myYVert2(i);
909 if ( myXVert2(i) > myMaxX ) myMaxX = myXVert2(i);
910 if ( myYVert2(i) > myMaxY ) myMaxY = myYVert2(i);
912 } // end if myArrow is FIRSTAR or BOTHAR
918 void Prs2d_Length::SetAttachLinLength( const Standard_Real aLength )
920 GetPntProject(aLength);
921 ComputeArrows( Standard_False );
924 void Prs2d_Length::Save(Aspect_FStream& aFStream) const
928 void Prs2d_Length::LineCoord( gp_Pnt2d& aFirstPnt, gp_Pnt2d& aSecondPnt ) const
930 aFirstPnt = gp_Pnt2d( myXT1, myYT1 );
931 aSecondPnt = gp_Pnt2d( myXT2, myYT2 );
934 void Prs2d_Length::CallOutCoord( gp_Pnt2d& aFirstPnt, gp_Pnt2d& aSecondPnt ) const
936 aFirstPnt = gp_Pnt2d( myAX1, myAY1 );
937 aSecondPnt = gp_Pnt2d( myAX2, myAY2 );
940 Prs2d_TypeOfDist Prs2d_Length::TypeOfDist() const