0023510: Integration of test grid "vis" into the new testing system
[occt.git] / src / Prs2d / Prs2d_Length.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
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.
7 //
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.
10 //
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.
17
18 #include <Prs2d_Length.ixx>
19 #include <Geom2d_Line.hxx>
20 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
21
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)
26 #define ADDPIX 17
27
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 ) 
40
41  : Prs2d_Dimension( aGO, aText, aTxtScale, anArrAngle, 
42                     anArrLength, anArrType, anArrow, IsRevArrow ),
43   
44    myTypeDist( aTypeDist )
45      
46 {
47    SetSymbolCode( 198 );
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 );
54
55 }
56
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 ) 
68
69  : Prs2d_Dimension( aGO, aText, aTxtScale, anArrAngle, 
70                     anArrLength, anArrType, anArrow, IsRevArrow ),
71     
72    myTypeDist( Prs2d_TOD_AUTOMATIC )
73
74 {
75     SetSymbolCode( 198 );
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);
80
81     myX1 = Standard_ShortReal( aPntProj1.X() );
82     myY1 = Standard_ShortReal( aPntProj1.Y() );
83     myX2 = Standard_ShortReal( aPntProj2.X() );
84     myY2 = Standard_ShortReal( aPntProj2.Y() );
85         
86     myAX1 = myX1;
87     myAY1 = myY1; 
88     myAX2 = myX2;
89     myAY2 = myY2;
90     
91     myMinX = myX1;
92     myMinY = myY1;
93     myMaxX = myX1;
94     myMaxY = myY1;
95
96     if ( myX2 < myMinX ) myMinX = myX2;
97     if ( myY2 < myMinY ) myMinY = myY2;
98     if ( myX2 > myMaxX ) myMaxX = myX2;
99     if ( myY2 > myMaxY ) myMaxY = myY2;
100     
101     ComputeArrows( Standard_True );
102 }
103
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 ),
117     
118    myTypeDist( Prs2d_TOD_AUTOMATIC )
119
120 {
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);
127
128     myX1 = Standard_ShortReal( aPntProj1.X() );
129     myY1 = Standard_ShortReal( aPntProj1.Y() );
130     myX2 = Standard_ShortReal( aPntProj2.X() );
131     myY2 = Standard_ShortReal( aPntProj2.Y() );
132         
133     myAX1 = myX1;
134     myAY1 = myY1; 
135     myAX2 = myX2;
136     myAY2 = myY2;
137     
138     myMinX = myX1;
139     myMinY = myY1;
140     myMaxX = myX1;
141     myMaxY = myY1;
142
143     if ( myX2 < myMinX ) myMinX = myX2;
144     if ( myY2 < myMinY ) myMinY = myY2;
145     if ( myX2 > myMaxX ) myMaxX = myX2;
146     if ( myY2 > myMaxY ) myMaxY = myY2;
147     
148    ComputeArrows( Standard_True ); 
149
150 }
151
152 void Prs2d_Length::Draw( const Handle(Graphic2d_Drawer)& aDrawer )  
153 {
154   Standard_Boolean IsIn = Standard_False;
155
156   if ( ! myGOPtr->IsTransformed() )
157     IsIn = aDrawer->IsIn( myMinX,myMaxX,myMinY,myMaxY );
158   else
159   {
160     Standard_ShortReal minx, miny, maxx, maxy;
161     MinMax(minx,maxx,miny,maxy);
162     IsIn = aDrawer->IsIn( minx,maxx,miny,maxy );
163   }
164
165   if ( IsIn ) 
166   {
167
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);
174     theTxtX=myAbsX;
175     theTxtY=myAbsY;
176     theTxtAngle=myAbsAngle;
177     gp_Pnt2d pntText(theTxtX,theTxtY);
178     Standard_Real theSmbX = 0., theSmbY = 0.;
179 // end enk code    
180     if ( myIsSymbol ) 
181     {
182       aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0, 
183                               Standard_ShortReal(myTextScale*aDrawer->Scale()), 
184                               Standard_ShortReal(myTextScale*aDrawer->Scale()), 
185                               Standard_False );
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 );
191         
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 );
197     } else 
198     {
199       pntText.Coord( theTxtX, theTxtY );            
200     }
201
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);
208
209     Standard_ShortReal at = myXT1, bt = myYT1, ct = myXT2, dt = myYT2;
210
211     TShort_Array1OfShortReal Xpoint1( 1, 3 ), Ypoint1( 1, 3 ), 
212                             Xpoint2( 1, 3 ), Ypoint2( 1, 3 );
213
214     if ( myGOPtr->IsTransformed() ) 
215     {
216       gp_GTrsf2d aTrsf = myGOPtr->Transform();
217       Standard_Real AT, BT;
218        
219       if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
220       {
221         for ( Standard_Integer j = 1; j <= 3; j++ ) 
222         {
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 );
228         }
229       } // end if myArrow is FIRSTAR ot BOTHAR
230    
231       if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ) 
232       {
233         for ( Standard_Integer j = 1; j <= 3; j++ ) 
234         {
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 );
240         }
241       } // end if myArrow is LASTAR ot BOTHAR   
242
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 );
248            
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 );
254        
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 );
260
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 );
266            
267        AT = Standard_Real( c1 );
268        BT = Standard_Real( d1 );
269        aTrsf.Transforms( AT, BT );
270
271        c1 = Standard_ShortReal( AT );
272        d1 = Standard_ShortReal( BT );
273
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 );
279
280        if ( ArrowIsReversed() ) 
281        {
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 );
287            
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 );
293        }
294     }   else 
295     {
296        if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ) 
297        {
298                 Xpoint1.Assign( myXVert1 );
299                 Ypoint1.Assign( myYVert1 );
300        }
301        if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ) 
302        {
303                 Xpoint2.Assign( myXVert2 );
304                 Ypoint2.Assign( myYVert2 );
305        }
306     }  // end if GO is transformed
307
308     if ( ArrowIsReversed() ) 
309         aDrawer->MapSegmentFromTo( at, bt, ct, dt );
310     else
311         aDrawer->MapSegmentFromTo( a, b, c, d );
312
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)))
316     {
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);
321       aAuxVec.Normalize();
322         
323       aAuxVec*=dxx;
324     
325       aAuxLinePnt1.Translate(aAuxVec);
326       aAuxLinePnt2.Translate(aAuxVec);
327       aAuxLinePnt3.Translate(aAuxVec);
328       aAuxLinePnt4.Translate(aAuxVec);
329     
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());
338     }
339     //end enk code 
340  
341     aDrawer->MapSegmentFromTo( a, b, a1, b1 );
342     aDrawer->MapSegmentFromTo( c, d, c1, d1 );
343
344     if ( myIsSymbol ) 
345     {
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 );
350     }
351     aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, 
352                             Standard_ShortReal(myTextScale*aDrawer->Scale()), 
353                             Standard_ShortReal(myTextScale*aDrawer->Scale()), 
354                             Standard_False );
355     aDrawer->MapTextFromTo( myText, t1, t2, Standard_ShortReal(theTxtAngle), 
356                             0., 0., Aspect_TOT_SOLID );
357
358 // Drawing arrows
359     if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
360     {
361        if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) 
362        {
363             aDrawer->MapPolygonFromTo( Xpoint1, Ypoint1 );
364        } else 
365        {
366         aDrawer->MapPolylineFromTo( Xpoint1, Ypoint1 );
367        } 
368     }
369
370    if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
371    {
372        if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) 
373        {
374             aDrawer->MapPolygonFromTo( Xpoint2, Ypoint2 );
375        } else 
376        {
377         aDrawer->MapPolylineFromTo( Xpoint2, Ypoint2 );
378        } 
379    }
380
381   } // end if IsIn is true 
382
383 }
384
385 void Prs2d_Length::DrawElement( const Handle(Graphic2d_Drawer)& aDrawer,
386                                 const Standard_Integer anIndex )
387 {
388   Standard_Boolean IsIn = Standard_False;
389
390   if ( ! myGOPtr->IsTransformed() )
391     IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY );
392   else 
393   {
394     Standard_ShortReal minx, miny, maxx, maxy;
395     MinMax( minx, maxx, miny, maxy );
396     IsIn = aDrawer->IsIn( minx, maxx, miny, maxy );
397   }
398
399   if ( IsIn ) 
400   {
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);
407     theTxtX=myAbsX;
408     theTxtY=myAbsY;
409     theTxtAngle=myAbsAngle;
410     gp_Pnt2d pntText(theTxtX,theTxtY);
411 // end enk code
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 ); 
417
418     if ( anIndex == 1 ) 
419     {
420      Xpoint.Assign( myXVert1 );
421      Ypoint.Assign( myYVert1 );
422     } else if ( anIndex == 2 ) 
423     {
424      Xpoint.Assign( myXVert2 );
425      Ypoint.Assign( myYVert2 );    
426     } 
427
428     if ( myGOPtr->IsTransformed () ) 
429     {
430       gp_GTrsf2d aTrsf = myGOPtr->Transform ();
431       Standard_Real a1, b1, c1, d1, aa11, ba11, aa21, ba21;
432       
433       if ( anIndex == 1 ) 
434       {
435         for ( Standard_Integer j = 1; j <= 3; j++ ) 
436         {
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 );
442          }
443       } else if ( anIndex == 2 ) 
444       {
445         for ( Standard_Integer j = 1; j <= 3; j++ ) 
446         {
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 );
452          }
453       } else if ( anIndex == 4 ) 
454       {
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 ) 
466       {
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 ) 
473       {
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 );
479                   
480       } else if ( anIndex == 6 ) 
481       {
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 );
487       } 
488     } 
489
490     if ( anIndex == 1 || anIndex == 2 ) 
491       if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) 
492       {
493             aDrawer->MapPolygonFromTo( Xpoint, Ypoint );
494       } else 
495       {
496         aDrawer->MapPolylineFromTo( Xpoint, Ypoint );
497       } 
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 );
507
508   } // end if IsIn is true 
509
510 }
511
512 void Prs2d_Length::DrawVertex( const Handle(Graphic2d_Drawer)& aDrawer,
513                                const Standard_Integer anIndex ) 
514 {
515  Standard_Boolean IsIn = Standard_False;
516
517  if ( ! myGOPtr->IsTransformed() )
518     IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY );
519  else 
520  {
521    Standard_ShortReal minx, miny, maxx, maxy;
522    MinMax( minx, maxx, miny, maxy );
523    IsIn = aDrawer->IsIn( minx, maxx, miny, maxy );
524  }
525  if ( IsIn ) 
526  {
527   if ( anIndex == 1 || anIndex == 2 ) 
528   {
529    Standard_ShortReal X=0., Y=0.;
530    if ( anIndex == 1 ) 
531    {
532      X = myX1; Y = myY1;
533    } else if ( anIndex == 2 ) 
534    {
535      X = myX2; Y = myY2;
536    }
537    DrawMarkerAttrib( aDrawer );
538    if ( myGOPtr->IsTransformed() ) 
539    {
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 );
545    } 
546    aDrawer->MapMarkerFromTo(VERTEXMARKER,X,Y, DEFAULTMARKERSIZE,
547                             DEFAULTMARKERSIZE,0.0);
548   }
549  }
550 }
551
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 )  
556 {
557    Standard_ShortReal SRX = X, SRY = Y;
558    Standard_Boolean Result = Standard_False;
559    
560    if (IsInMinMax (X, Y, aPrecision) ) 
561    {
562       if ( myGOPtr->IsTransformed () ) 
563       {
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);
569       }
570
571       if ( Graphic2d_Primitive::IsOn( SRX, SRY, myX1, myY1, aPrecision ) ) 
572       {
573         SetPickedIndex(-1);    
574         return Standard_True;
575       } else if ( Graphic2d_Primitive::IsOn( SRX, SRY, myX2, myY2, aPrecision ) ) 
576       {
577         SetPickedIndex(-2);    
578         return Standard_True;
579       }
580
581       if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ) 
582       {
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 ) ) 
586             {
587               SetPickedIndex(1);
588               return Standard_True;
589             }
590         
591             if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) 
592              if ( IsIn( SRX, SRY,  myXVert1, myYVert1, aPrecision ) ) 
593              {
594                SetPickedIndex(1);
595                return Standard_True;
596              }
597       } // end if myArrow == FIRSTAR or BOTHAR
598
599     if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
600     {
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 ) ) 
604             {
605               SetPickedIndex(2);
606               return Standard_True;
607             }
608         
609           if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) 
610             if ( IsIn( SRX, SRY, myXVert2, myYVert2, aPrecision ) ) 
611             {
612               SetPickedIndex(2);
613               return Standard_True;
614             }
615     } // end if myArrow == LASTAR or BOTHAR
616
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;
621     
622     aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, hscale, wscale, 
623                             Standard_False );
624     if ( !aDrawer->GetTextSize( myText, width, height, xoffset, yoffset ) ) 
625     {
626       width = height = xoffset = yoffset = 0.;
627     }
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);
633     theTxtX=myAbsX;
634     theTxtY=myAbsY;
635     theTxtAngle=myAbsAngle;
636     gp_Pnt2d pntText(theTxtX,theTxtY);
637 // end enk code
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), 
642                        x = XROTATE(dx,dy),
643                        y = YROTATE(dx,dy);
644  
645     Result   =   (x >= -aPrecision + xoffset)            
646             &&   (x <= width + xoffset + aPrecision)
647             &&   (y >= -yoffset - aPrecision) 
648             &&   (y <= height - yoffset + aPrecision);
649   
650     if ( Result ) 
651     {
652       SetPickedIndex(3);
653       return Standard_True;
654     }
655 // begin enk code auxiality lines
656     Standard_ShortReal a,b,c,d,a1,b1,c1,d1;
657       a = myX1;
658       b = myY1;
659       a1= myAX1;
660       b1= myAY1;
661       c = myX2;
662       d = myY2; 
663       c1= myAX2;
664       d1= myAY2;
665     if (!((a==a1 && b==b1)||(c==c1 && d==d1)))
666     {
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);
671     
672       aAuxVec.Normalize();
673       aAuxVec*=dxx;
674       aAuxLinePnt1.Translate(aAuxVec);
675       aAuxLinePnt2.Translate(aAuxVec);
676       aAuxLinePnt3.Translate(aAuxVec);
677       aAuxLinePnt4.Translate(aAuxVec);
678     
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());
687     }
688       // end enk code  
689       
690     if ( IsOn( SRX, SRY, myX1, myY1, myX2, myY2, aPrecision ) ) 
691     {
692        SetPickedIndex( 4 );
693        return Standard_True;
694     } else if ( IsOn( SRX, SRY, a, b, a1, b1, aPrecision ) ) 
695     {
696        SetPickedIndex( 5 );
697        return Standard_True;
698     } else if ( IsOn( SRX, SRY, c, d, c1, d1, aPrecision ) ) 
699     {
700        SetPickedIndex( 6 );
701        return Standard_True;    
702     }
703   }
704         return Standard_False;
705 }
706
707 void Prs2d_Length::GetPntProject( const Standard_Real aLength ) 
708 {
709    
710    gp_Pnt2d myPntAttach1( myAX1, myAY1 ), myPntAttach2( myAX2, myAY2 );
711    gp_Pnt2d aPntProj1, aPntProj2, MinMaxPnt = myPntAttach1;
712
713    switch ( myTypeDist ) 
714    {
715      case Prs2d_TOD_HORIZONTAL: 
716      {
717        if ( aLength < 0 ) 
718        {
719          if ( MinMaxPnt.Y() > myPntAttach2.Y() ) 
720          {
721            myPntAttach1 = myPntAttach2;
722            myPntAttach2 = MinMaxPnt;                
723          }
724        } else 
725        {
726          if ( MinMaxPnt.Y() < myPntAttach2.Y() ) 
727          {
728            myPntAttach1 = myPntAttach2;
729            myPntAttach2 = MinMaxPnt;                           
730          }         
731        }
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);
737            
738        break;
739       }
740
741      case Prs2d_TOD_VERTICAL: 
742      {
743        if ( aLength < 0 ) 
744        {
745          if ( MinMaxPnt.X() > myPntAttach2.X() ) 
746          {
747            myPntAttach1 = myPntAttach2;
748            myPntAttach2 = MinMaxPnt;                
749          }
750        } else 
751        {
752          if ( MinMaxPnt.X() < myPntAttach2.X() ) 
753          {
754            myPntAttach1 = myPntAttach2;
755            myPntAttach2 = MinMaxPnt;                           
756          }
757        }
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);
763        break;
764      }
765  
766 /*   case Prs2d_TOD_OBLIQUE: 
767      {
768        gp_Vec2d DirLin1( myPntAttach1, myPntAttach2 );
769        gp_Vec2d DirLin2 = DirLin1.Reversed();
770        DirLin1.Normalize();
771        DirLin2.Normalize();
772        DirLin1 *= aLength;
773        DirLin2 *= aLength;
774        DirLin1.Rotate( M_PI/2. );
775        DirLin2.Rotate( -M_PI/2. );
776        aPntProj1 = myPntAttach1.Translated( DirLin1 );
777        aPntProj2 = myPntAttach2.Translated( DirLin2 );;
778        break;
779      } */ // commented by enk
780      
781    case Prs2d_TOD_AUTOMATIC:
782    case Prs2d_TOD_OBLIQUE: 
783      default: 
784      {
785        gp_Vec2d DirLin1( myPntAttach1, myPntAttach2 );
786        gp_Vec2d DirLin2 = DirLin1.Reversed();
787        DirLin1.Normalize();
788        DirLin2.Normalize();
789        DirLin1 *= aLength;
790        DirLin2 *= aLength;
791        DirLin1.Rotate( M_PI/2. );
792        DirLin2.Rotate( -M_PI/2. );
793        aPntProj1 = myPntAttach1.Translated( DirLin1 );
794        aPntProj2 = myPntAttach2.Translated( DirLin2 );;
795        break;
796      }
797    } // end switch TypeOfDist
798
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() );
807
808    myMinX = Min( myX1, myX2 );
809    myMinY = Min( myY1, myY2 );
810    myMaxX = Max( myX1, myX2 );
811    myMaxY = Max( myY1, myY2 );
812
813    if ( myAX1 < myMinX ) myMinX = myAX1;
814    if ( myAY1 < myMinY ) myMinY = myAY1;
815    if ( myAX1 > myMaxX ) myMaxX = myAX1;
816    if ( myAY1 > myMaxY ) myMaxY = myAY1;
817     
818    if ( myAX2 < myMinX ) myMinX = myAX2;
819    if ( myAY2 < myMinY ) myMinY = myAY2;
820    if ( myAX2 > myMaxX ) myMaxX = myAX2;
821    if ( myAY2 > myMaxY ) myMaxY = myAY2;
822    
823 }
824
825 void Prs2d_Length::ComputeArrows( const Standard_Boolean /*isnotPoints*/ ) 
826 {
827   
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;
832  
833   myXT1 = myX1;
834   myYT1 = myY1;
835   myXT2 = myX2;
836   myYT2 = myY2;
837
838   if ( ArrowIsReversed() ) 
839   {
840     gp_Pnt2d tP1 = aPnt1, tP2 = aPnt2;
841     gp_Vec2d tVD( aPnt1, aPnt2 );
842     tVD.Normalize();
843     tVD *= ( 1.3 * myArrowLen );
844     tP1.Translate( -tVD );
845     tP2.Translate( tVD );  
846     Standard_Real X1, Y1, X2, Y2;
847     tP1.Coord( X1, Y1 );
848     tP2.Coord( X2, Y2 );  
849
850     myXT1 = Standard_ShortReal( X1 );
851     myYT1 = Standard_ShortReal( Y1 );
852     myXT2 = Standard_ShortReal( X2 );
853     myYT2 = Standard_ShortReal( Y2 );
854   }
855
856   if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ) 
857   {
858      P1 = aPnt1;
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 ) );
868   
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() );
875
876      for ( Standard_Integer i = 1; i <= 3; i++ ) 
877      {
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);
882      }
883    } // end if myArrow is FIRSTAR or BOTHAR
884  
885   if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) )
886   {
887     P1 = aPnt2;
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 ) );
897   
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() );
904
905     for ( Standard_Integer i = 1; i <= 3; i++ ) 
906     {
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);
911     }
912   } // end if myArrow is FIRSTAR or BOTHAR
913
914   myNumOfElem = 6;
915   myNumOfVert = 2;
916 }
917
918 void Prs2d_Length::SetAttachLinLength( const Standard_Real aLength ) 
919 {
920   GetPntProject(aLength);
921   ComputeArrows( Standard_False );
922 }
923
924 void Prs2d_Length::Save(Aspect_FStream& aFStream) const
925 {
926 }
927
928 void Prs2d_Length::LineCoord( gp_Pnt2d& aFirstPnt, gp_Pnt2d& aSecondPnt ) const
929 {
930   aFirstPnt = gp_Pnt2d( myXT1, myYT1 );
931   aSecondPnt = gp_Pnt2d( myXT2, myYT2 );
932 }
933
934 void Prs2d_Length::CallOutCoord( gp_Pnt2d& aFirstPnt, gp_Pnt2d& aSecondPnt ) const
935 {
936   aFirstPnt = gp_Pnt2d( myAX1, myAY1 );
937   aSecondPnt = gp_Pnt2d( myAX2, myAY2 );
938 }
939
940 Prs2d_TypeOfDist Prs2d_Length::TypeOfDist() const
941 {
942   return myTypeDist;
943 }