00001
00002
00003
00004
00005
00006
00007
00036
00037
00038
00039
00040 #include <stdio.h>
00041 #include <math.h>
00042
00043 #include "cd.h"
00044 #include "wd.h"
00045
00046 #include "crs.h"
00047 #include "dsp.h"
00048 #include "t2d.h"
00049
00050
00051
00052
00053
00054
00056 #define ToDegree(a) ((a)*(double)57.295779513)
00057
00059 #define ANGLE_TOL 0.01
00060
00062 #define LOAD_TOL 0.01
00063
00065 #define BACKGROUND_COLOR CD_WHITE
00066
00068 #define MEMBER_COLOR CD_DARK_YELLOW
00069
00071 #define LOAD_COLOR CD_DARK_BLUE
00072
00074 #define MOMENT_COLOR CD_BLACK
00075
00077 #define UNBALANCED_COLOR CD_RED
00078
00080 #define BALANCED_COLOR CD_GREEN
00081
00083 #define FIXED_COLOR CD_BLACK
00084
00086 #define UNBALANCED_MARK CD_BOX
00087
00089 #define BALANCED_MARK CD_DIAMOND
00090
00092 #define FIXED_MARK CD_BOX
00093
00095 #define NODE_MARK_SIZE 7
00096
00098 #define HINGE_BACKGROUND_MARK CD_CIRCLE
00099
00101 #define HINGE_FOREGROUND_MARK CD_HOLLOW_CIRCLE
00102
00104 #define HINGE_MARK_SIZE 9
00105
00107 #define HINGE_AXIAL_SHIFT 0.015
00108
00110 static double hinge_axial_shift;
00111
00114 #define MOMENT_AXIAL_SHIFT 0.01
00115
00117 static double moment_axial_shift;
00118
00121 #define MOMENT_TRANSV_SHIFT 0.007
00122
00124 static double moment_transv_shift;
00125
00128 #define LOAD_AXIAL_SHIFT 0.01
00129
00131 static double load_axial_shift;
00132
00135 #define LOAD_TRANSV_SHIFT 0.008
00136
00138 static double load_transv_shift;
00139
00142 #define LOAD_ARROW_SIZE 0.02
00143
00145 static double load_arrow_size;
00146
00149 #define LOAD_TIP_SIZE 0.004
00150
00152 static double load_tip_size;
00153
00156 #define LOAD_STEP_SIZE 0.02
00157
00159 static double load_step_size;
00160
00162 static int dsp_load = 1;
00163
00164
00165
00166
00167
00168 static void _dspAttSizes( void );
00169 static void _dspMember( int id );
00170 static void _dspMemberAtt( double x0, double y0, double len, double angle,
00171 double q, int rotlib0, int rotlib1,
00172 double m0, double m1 );
00173 static void _dspMemberLoad( double len, double q, int def_orient );
00174 static void _dspLoadArrow( double x, double q, int def_orient );
00175
00176
00181 static void _dspAttSizes( void )
00182 {
00183 double xmin;
00184 double xmax;
00185 double ymin;
00186 double ymax;
00187 double width, height;
00188 double maxsize;
00189
00190 wdGetWindow( &xmin, &xmax, &ymin, &ymax );
00191 width = xmax - xmin;
00192 height = ymax - ymin;
00193
00194 maxsize = ( width > height ) ? width : height;
00195
00196 hinge_axial_shift = HINGE_AXIAL_SHIFT * maxsize;
00197
00198 moment_axial_shift = MOMENT_AXIAL_SHIFT * maxsize;
00199 moment_transv_shift = MOMENT_TRANSV_SHIFT * maxsize;
00200
00201 load_axial_shift = LOAD_AXIAL_SHIFT * maxsize;
00202 load_transv_shift = LOAD_TRANSV_SHIFT * maxsize;
00203 load_arrow_size = LOAD_ARROW_SIZE * maxsize;
00204 load_tip_size = LOAD_TIP_SIZE * maxsize;
00205 load_step_size = LOAD_STEP_SIZE * maxsize;
00206 }
00207
00208
00218 static void _dspMember( int id )
00219 {
00220 int node0;
00221 int node1;
00222 double x0;
00223 double y0;
00224 double x1;
00225 double y1;
00226 double q;
00227 int rotlib0;
00228 int rotlib1;
00229 double m0;
00230 double m1;
00231 double dx;
00232 double dy;
00233 double angle;
00234 double len;
00235
00236
00237
00238 crsGetMemberNodes( id, &node0, &node1 );
00239 crsGetNodeCoords( node0, &x0, &y0 );
00240 crsGetNodeCoords( node1, &x1, &y1 );
00241 crsGetMemberUnifLoad( id, &q );
00242 crsGetMemberRotLibs( id, &rotlib0, &rotlib1 );
00243 crsGetMemberMoments( id, &m0, &m1 );
00244
00245
00246
00247
00248
00249
00250
00251 dx = x1 - x0;
00252 dy = y1 - y0;
00253 len = sqrt( dx*dx + dy*dy );
00254 angle = atan2( dy, dx );
00255 angle = ToDegree( angle );
00256
00257
00258
00259 if( fabs( angle ) < ANGLE_TOL )
00260 {
00261 angle = 0.0;
00262 }
00263 else if( angle < 0.0 )
00264 {
00265 if( fabs( angle + 90.0 ) < ANGLE_TOL )
00266 angle = -90.0;
00267 else if( fabs( angle + 180.0 ) < ANGLE_TOL )
00268 angle = -180.0;
00269 }
00270 else
00271 {
00272 if( fabs( angle - 90.0 ) < ANGLE_TOL )
00273 angle = 90.0;
00274 else if( fabs( angle - 180.0 ) < ANGLE_TOL )
00275 angle = 180.0;
00276 }
00277
00278
00279
00280 _dspMemberAtt( x0, y0, len, angle, q, rotlib0, rotlib1, m0, m1 );
00281 }
00282
00283
00297 static void _dspMemberAtt( double x0, double y0, double len, double angle,
00298 double q, int rotlib0, int rotlib1,
00299 double m0, double m1 )
00300 {
00301 int def_orient;
00302 double text_angle;
00303 double x;
00304 double y;
00305 char s[32];
00306
00307
00308
00309
00310 t2dIdentity( );
00311 t2dRotate( angle );
00312 t2dTranslate( x0, y0 );
00313
00314
00315
00316
00317 if( (angle > -90.0) && (angle <= 90.0) )
00318 def_orient = 1;
00319 else
00320 def_orient = 0;
00321
00322
00323
00324 if( def_orient )
00325 {
00326 text_angle = angle;
00327 }
00328 else
00329 {
00330 if( angle > 90.0 )
00331 text_angle = angle - 180.0;
00332 else
00333 text_angle = angle + 180.0;
00334 }
00335 cdTextOrientation( text_angle );
00336
00337
00338
00339 if( dsp_load && (fabs( q ) > LOAD_TOL) )
00340 _dspMemberLoad( len, q, def_orient );
00341
00342
00343
00344 if( rotlib0 == ROT_FREE )
00345 {
00346 x = hinge_axial_shift;
00347 y = 0.0;
00348 t2dTransform( &x, &y );
00349 cdMarkSize( HINGE_MARK_SIZE );
00350 cdForeground( BACKGROUND_COLOR );
00351 cdMarkType( HINGE_BACKGROUND_MARK );
00352 wdMark( x, y );
00353 cdForeground( MEMBER_COLOR );
00354 cdMarkType( HINGE_FOREGROUND_MARK );
00355 wdMark( x, y );
00356 }
00357 if( rotlib1 == ROT_FREE )
00358 {
00359
00360 }
00361
00362
00363
00364 if( rotlib0 == ROT_FIX )
00365 {
00366 x = moment_axial_shift;
00367 if( def_orient )
00368 y = -moment_transv_shift;
00369 else
00370 y = moment_transv_shift;
00371 t2dTransform( &x, &y );
00372 sprintf( s, "%.2f", m0 );
00373 cdForeground( MOMENT_COLOR );
00374 if( def_orient )
00375 cdTextAlignment( CD_WEST );
00376 else
00377 cdTextAlignment( CD_EAST );
00378 wdText( x, y, s );
00379 }
00380
00381
00382
00383 if( rotlib1 == ROT_FIX )
00384 {
00385
00386 }
00387 }
00388
00389
00397 static void _dspMemberLoad( double len, double q, int def_orient )
00398 {
00399 double x;
00400 double y;
00401 double xa;
00402 double ya;
00403 double xb;
00404 double yb;
00405 int n_arrows;
00406 double step_size;
00407 int i;
00408 char s[32];
00409
00410 cdForeground( LOAD_COLOR );
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422 n_arrows = (int)((len - 2.0*load_axial_shift) / load_step_size);
00423 if( n_arrows < 1 )
00424 n_arrows = 1;
00425 step_size = (len - 2.0*load_axial_shift) / (double)n_arrows;
00426 n_arrows += 1;
00427 for( i = 0, x = load_axial_shift; i < n_arrows ; i++, x += step_size )
00428 {
00429 _dspLoadArrow( x, q, def_orient );
00430 }
00431
00432
00433
00434
00435 }
00436
00437
00445 static void _dspLoadArrow( double x, double q, int def_orient )
00446 {
00447
00448 }
00449
00450
00451
00452
00453
00454
00455
00456
00462 void dspInit( void )
00463 {
00464 cdBackground( BACKGROUND_COLOR );
00465 cdFont( CD_COURIER, CD_PLAIN, CD_SMALL );
00466 }
00467
00468
00486 void dspWindow( double scale,
00487 double *xmin, double *xmax,
00488 double *ymin, double *ymax )
00489 {
00490 int hsize, vsize;
00491 double vpr;
00492 double cx, cy;
00493 double sizex, sizey;
00494
00495
00496
00497 cdGetCanvasSize( &hsize, &vsize, 0L, 0L );
00498 vpr = (double)vsize / (double)hsize;
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514 wdWindow( *xmin, *xmax, *ymin, *ymax );
00515 }
00516
00517
00535 void dspPanWindow( double dx, double dy,
00536 double *xmin, double *xmax,
00537 double *ymin, double *ymax )
00538 {
00539
00540
00541
00542
00543
00544
00545 wdWindow( *xmin, *xmax, *ymin, *ymax );
00546 }
00547
00548
00556 void dspLoadDisplay( int on_off )
00557 {
00558 dsp_load = on_off;
00559 }
00560
00561
00566 void dspModel( void )
00567 {
00568 int n_member;
00569 int n_node;
00570 int i;
00571 double x;
00572 double y;
00573 int node_status;
00574
00575 n_member = crsGetNumMembers( );
00576 if( n_member == 0 )
00577 return;
00578
00579
00580
00581 _dspAttSizes( );
00582
00583
00584
00585 for( i = 0; i < n_member; i++ )
00586 {
00587 _dspMember( i );
00588 }
00589
00590
00591
00592
00593 }
00594