summaryrefslogtreecommitdiff
path: root/src/Prs2d/Prs2d_RadiusIndep.cxx
blob: 7fb77a674c9fd3a79adf3ebe12c2db5e54784240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#include <Prs2d_RadiusIndep.ixx>

#define VERTEXMARKER 2
#define DEFAULTMARKERSIZE 3.0

Prs2d_RadiusIndep::Prs2d_RadiusIndep( const Handle(Graphic2d_GraphicObject) & aGO, 
                                      const gp_Pnt2d                        & anAttachPnt, 
                                      const gp_Pnt2d                        & aCenter,
                                      const Standard_Real                     aRad,
                                      const TCollection_ExtendedString      & aText,
                                      const Standard_Real                     aLength, 
                                      const Prs2d_TypeOfRadius                aTypeRad,
                                      const Standard_Real                     aTxtScale ) 

  : Graphic2d_Line( aGO ),
  
    myX1( Standard_ShortReal( anAttachPnt.X() ) ),
	myY1( Standard_ShortReal( anAttachPnt.Y() ) ),
	myX2( Standard_ShortReal( aCenter.X() ) ),
	myY2( Standard_ShortReal( aCenter.Y() ) ),
    myTextScale( Standard_ShortReal( aTxtScale ) ),
    myText( aText ),
    myXVert( 1, 3 ),
	myYVert( 1, 3 ),
    myIsSymbol( Standard_False ),
    mySymbCode( 198 ),
    myTextFont( 0 ),
    mySymbFont( 0 ),
    myAttPnt( anAttachPnt ),
    myCenter( aCenter ),
    myRadius( aRad ),
    myLength( aLength ),
    myRadType( aTypeRad )
    
{
   gp_Vec2d theVec1( gp_Pnt2d( myX2, myY2 ), gp_Pnt2d( myX1, myY1 ) );
   gp_Vec2d theUnVec( 1., 0. );
   myTextAng = Standard_ShortReal( theUnVec.Angle( theVec1 ) );
   Standard_Real theLen = sqrt( (myX2-myX1)*(myX2-myX1) + (myY2-myY1)*(myY2-myY1) );
   gp_Vec2d VecAdd = theVec1.Normalized();
   theVec1.Normalize();
   theVec1 *= ( theLen + aLength );
   gp_Pnt2d P1 = aCenter.Translated( theVec1 );
   myTextX = Standard_ShortReal( P1.X() );
   myTextY = Standard_ShortReal( P1.Y() );
   gp_Pnt2d PArr( myX1, myY1 );
    
   if ( ( theLen + aLength ) > theLen ) 
     myInside = Standard_False;
   else 
     myInside = Standard_True;

  switch( aTypeRad ) {
   default:
   case Prs2d_TOR_STANDARD : {

     myX2 = Standard_ShortReal( P1.X() );
	 myY2 = Standard_ShortReal( P1.Y() );
     if  ( ( theLen + aLength ) > theLen ) {
         theVec1.Reverse();    
     }
   }
   break;          
   case Prs2d_TOR_CENTER : {
     
     if ( aLength > 0.0 ) {
       myX1 = Standard_ShortReal( P1.X() );
	   myY1 = Standard_ShortReal( P1.Y() );
       theVec1.Reverse();      
     }
   }
   break;
   case Prs2d_TOR_REVARROW : {
       
     myX2 = Standard_ShortReal( P1.X() );
	 myY2 = Standard_ShortReal( P1.Y() );
     if  ( ( theLen + aLength ) <= theLen ) 
         theVec1.Reverse();    
     else 
         VecAdd.Reverse();
     Standard_Real Dt = sqrt( ( myX2 - myX1 )*( myX2 - myX1 ) + ( myY2 - myY1 )*( myY2 - myY1 ) );
     VecAdd *= Dt/2;
     gp_Pnt2d PTmpn = PArr.Translated( VecAdd );
     myX1 = Standard_ShortReal( PTmpn.X() );
     myY1 = Standard_ShortReal( PTmpn.Y() );
   }

   break;
   case Prs2d_TOR_CENTREV : {

     if ( aLength > 0.0 ) {
       myX1 = Standard_ShortReal( P1.X() );
	   myY1 = Standard_ShortReal( P1.Y() );
     } else { 
       theVec1.Reverse();
       Standard_Real Dt = sqrt( ( myX2 - myX1 )*( myX2 - myX1 ) + ( myY2 - myY1 )*( myY2 - myY1 ) );
       VecAdd *= Dt/2;
       gp_Pnt2d PTmpn = PArr.Translated( VecAdd );
       myX1 = Standard_ShortReal( PTmpn.X() );
       myY1 = Standard_ShortReal( PTmpn.Y() );
     }
    }
    break;    
   } // end switch

   myMinX	= myX1;
   myMinY	= myY1;
   myMaxX	= myX1;
   myMaxY	= myY1;

   if ( myX2 < myMinX ) myMinX = myX2;
   if ( myY2 < myMinY ) myMinY = myY2;
   if ( myX2 > myMaxX ) myMaxX = myX2;
   if ( myY2 > myMaxY ) myMaxY = myY2;
   
   Standard_Real ArrANG = Standard_PI/6., theArrLN  = aRad/5., theANG;
   gp_Pnt2d theOrig( 0., 0. ), P2, P3;
   gp_Vec2d VX( 1., 0. );
 
   P2 = gp_Pnt2d( theArrLN,  theArrLN*Tan( ArrANG/2. ) );
   P3 = gp_Pnt2d( theArrLN, -theArrLN*Tan( ArrANG/2. ) );
   theVec1.Reverse();
   theANG = VX.Angle( theVec1 );
   P2.Rotate( theOrig, theANG );
   P3.Rotate( theOrig, theANG );
  
   P2.Translate( gp_Vec2d( theOrig, PArr ) );
   P3.Translate( gp_Vec2d( theOrig, PArr ) );
  
   myXVert(1) = Standard_ShortReal( P2.X() );
   myYVert(1) = Standard_ShortReal( P2.Y() );
   myXVert(2) = Standard_ShortReal( PArr.X() );
   myYVert(2) = Standard_ShortReal( PArr.Y() );
   myXVert(3) = Standard_ShortReal( P3.X() );
   myYVert(3) = Standard_ShortReal( P3.Y() );

   for ( Standard_Integer i = 1; i <= 3; i++ ) {
	   
	   if ( myXVert(i) < myMinX ) myMinX = myXVert(i);
       if ( myYVert(i) < myMinY ) myMinY = myYVert(i);
       if ( myXVert(i) > myMaxX ) myMaxX = myXVert(i);
	   if ( myYVert(i) > myMaxY ) myMaxY = myYVert(i);
	   
   }
}

void Prs2d_RadiusIndep::Values(gp_Pnt2d& anAttPnt,
                               gp_Pnt2d& aCenter,
                               Standard_Real& aRad,
                               TCollection_ExtendedString& aText,
                               Standard_Real& aLength,
                               Prs2d_TypeOfRadius& aTypeRad,
                               Standard_Real& aTxtScale) const {

    anAttPnt   = myAttPnt;
    aCenter    = myCenter;
    aRad       = myRadius;
    aText      = myText;
    aLength    = myLength;
    aTypeRad   = myRadType;
    aTxtScale  = myTextScale;
}

void Prs2d_RadiusIndep::Draw( const Handle(Graphic2d_Drawer)& aDrawer ) {

  Standard_Boolean IsIn = Standard_False;

  if ( ! myGOPtr->IsTransformed() )
    IsIn = aDrawer->IsIn (myMinX,myMaxX,myMinY,myMaxY);
  else {
    Standard_ShortReal minx, miny, maxx, maxy;
    MinMax(minx,maxx,miny,maxy);
    IsIn = aDrawer->IsIn (minx,maxx,miny,maxy);
  }

  if ( IsIn ) {

    DrawLineAttrib(aDrawer);
    aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, Standard_ShortReal( myTextScale*aDrawer->Scale() ), 
                            Standard_ShortReal( myTextScale*aDrawer->Scale()), Standard_False );

    Standard_ShortReal aWidth, aHeight;
    aDrawer->GetTextSize( myText, aWidth, aHeight );
    Standard_ShortReal Xt = myTextX, Yt = myTextY;
    if ( !myInside ) {
        gp_Pnt2d P1( myX1, myY1 ), P2( myX2, myY2 ), 
                 PT( myTextX, myTextY ), PTMP;
        ( PT.IsEqual( P1, 0. ) ) 
        ? PTMP.SetCoord( P2.X(), P2.Y() ) 
        : PTMP.SetCoord( P1.X(), P1.Y() );
        gp_Vec2d theVec1( PT, PTMP );
        theVec1.Normalize();
        theVec1 *= aWidth;
        gp_Pnt2d PTT = PT.Translated( theVec1 );
        Xt = Standard_ShortReal( PTT.X() ); 
        Yt = Standard_ShortReal( PTT.Y() );
    }

    Standard_Real theSmbX = 0., theSmbY = 0.;
    
    if ( myIsSymbol ) {
      aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()), 
                              Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False );
      TCollection_ExtendedString txtSymb = TCollection_ExtendedString( char( mySymbCode ) );
      theSmbX = Xt; theSmbY = Yt;
      gp_Pnt2d pntText( Xt, Yt );
      Standard_ShortReal ws, hs;
      aDrawer->GetTextSize( txtSymb, ws, hs );
      Standard_ShortReal ddd = aDrawer->Convert(2);
      gp_Vec2d VX( 1., 0. ), theVec;
      theVec = VX.Rotated( myTextAng );
      theVec *= ( ws + ddd );
      gp_Pnt2d pntSymb = pntText.Translated( theVec );
      Standard_Real txtX, txtY;
      pntSymb.Coord( txtX, txtY );
      Xt = Standard_ShortReal( txtX ); 
      Yt = Standard_ShortReal( txtY );
    } 

    Standard_ShortReal a = myX1, b = myY1, 
                       c = myX2, d = myY2,
                       e = Xt,   f = Yt, 
                       w = 0.,   h = Standard_ShortReal( aHeight/5 ),
                       ts1 = Standard_ShortReal( theSmbX ), 
                       ts2 = Standard_ShortReal( theSmbY );

    TShort_Array1OfShortReal Xpoint( 1, 3 ), Ypoint( 1, 3 );
    Xpoint.Assign( myXVert );
    Ypoint.Assign( myYVert ); 

    if ( myGOPtr->IsTransformed() ) {

      gp_GTrsf2d aTrsf = myGOPtr->Transform();
      Standard_Real A1, B1;
      A1 = Standard_Real( a ); B1 = Standard_Real( b );
      aTrsf.Transforms( A1, B1 );
      a = Standard_ShortReal( A1 ); b = Standard_ShortReal( B1 );
      A1 = Standard_Real( c ); B1 = Standard_Real( d );
      aTrsf.Transforms( A1, B1 );
      c = Standard_ShortReal( A1 ); d = Standard_ShortReal( B1 );
      A1 = Standard_Real( e ); B1 = Standard_Real( f );
      aTrsf.Transforms( A1, B1 );
      e = Standard_ShortReal( A1 ); f = Standard_ShortReal( B1 );
      A1 = Standard_Real( w ); B1 = Standard_Real( h );
      aTrsf.Transforms( A1, B1 );
      w = Standard_ShortReal( A1 ); h = Standard_ShortReal( B1 );
      A1 = Standard_Real( ts1 ); B1 = Standard_Real( ts2 );
      aTrsf.Transforms( A1, B1 );
      ts1 = Standard_ShortReal( A1 ); ts2 = Standard_ShortReal( B1 );
  
      for ( int j = 1; j <= 3; j++ ) {
	   A1 = Standard_Real( myXVert(j) );
	   B1 = Standard_Real( myYVert(j) );
       aTrsf.Transforms( A1, B1 );
       Xpoint(j) = Standard_ShortReal(A1);
	   Ypoint(j) = Standard_ShortReal(B1);
      }
   
     }

     DrawLineAttrib( aDrawer );
     aDrawer->MapSegmentFromTo( a, b, c, d );
     aDrawer->MapPolygonFromTo( Xpoint, Ypoint);
     if ( myIsSymbol ) {
      aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()), 
                              Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False );
      TCollection_ExtendedString txtSymb = TCollection_ExtendedString( char( mySymbCode ) );
      aDrawer->MapTextFromTo( txtSymb, ts1, ts2, myTextAng, 0., 0., Aspect_TOT_SOLID );
    }

     aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, Standard_ShortReal( myTextScale*aDrawer->Scale() ), 
                            Standard_ShortReal( myTextScale*aDrawer->Scale()), Standard_False );

     aDrawer->MapTextFromTo( myText, e, f, myTextAng, 0., 0., Aspect_TOT_SOLID ); 
     
  }
}

void Prs2d_RadiusIndep::DrawElement( const Handle(Graphic2d_Drawer)& /*aDrawer*/, 
                                     const Standard_Integer /*anIndex*/ ) {

}

void Prs2d_RadiusIndep::DrawVertex( const Handle(Graphic2d_Drawer)& /*aDrawer*/, 
                                    const Standard_Integer /*anIndex*/ ) {
}

Standard_Boolean Prs2d_RadiusIndep::Pick( const Standard_ShortReal X,
                                          const Standard_ShortReal Y,
                                          const Standard_ShortReal aPrecision,
                                          const Handle(Graphic2d_Drawer)& /*aDrawer*/) {
   Standard_ShortReal SRX = X, SRY = Y;
   Standard_Boolean Result = Standard_False;
   
   if ( IsInMinMax( X, Y, aPrecision ) ) {
      if ( myGOPtr->IsTransformed () ) {
         gp_GTrsf2d aTrsf = ( myGOPtr->Transform() ).Inverted();
         Standard_Real RX = Standard_Real(SRX), RY = Standard_Real(SRY);
		 aTrsf.Transforms(RX, RY);
		 SRX = Standard_ShortReal(RX);
		 SRY = Standard_ShortReal(RY);
      }
   Result = IsOn( SRX, SRY, myX1, myY1, myX2, myY2, aPrecision );
   }
   return Result;

}

void Prs2d_RadiusIndep::SetTextScale( const Standard_Real aTxtScale ) {
     myTextScale = Standard_ShortReal( aTxtScale );
}

void Prs2d_RadiusIndep::SetText( const TCollection_ExtendedString & aText ) {
     myText = aText;
}

void Prs2d_RadiusIndep::DrawSymbol(const Standard_Boolean isDraw ) {
  myIsSymbol = isDraw;
}
 
void Prs2d_RadiusIndep::SetSymbolCode( const Standard_Integer aCode ) {
  mySymbCode = aCode;
}

void Prs2d_RadiusIndep::SetTextFont(const Standard_Integer aTF) {
    myTextFont = aTF;
}
 
void Prs2d_RadiusIndep::SetFontOfSymb(const Standard_Integer aFS) {
   mySymbFont = aFS;
}

Standard_Boolean Prs2d_RadiusIndep::IsDrawSymbol() const {
  return myIsSymbol;
}

Standard_Integer Prs2d_RadiusIndep::SymbolCode() const {
  return mySymbCode;
 
}

Standard_Integer Prs2d_RadiusIndep::TextFont() const {
  return myTextFont;
}
 
Standard_Integer Prs2d_RadiusIndep::FontOfSymb() const {
  return mySymbFont;
}

void Prs2d_RadiusIndep::Save(Aspect_FStream& aFStream) const
{
}