Página Principal | Lista Alfabética | Lista de Componentes | Lista de Arquivos | Componentes Membros | Arquivos Membros

dsp.c

Vá para a documentação deste arquivo.
00001 /*
00002 ** ---------------------------------------------------------------
00003 ** dsp.c -  Display module.
00004 **
00005 ** ---------------------------------------------------------------
00006 */
00007 
00036 /*
00037 ** ---------------------------------------------------------------
00038 ** Global variables and symbols:
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 ** Local variables and symbols:
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 ** Private functions:
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 /*========================  _dspAttSizes  ========================*/
00181 static void _dspAttSizes( void )
00182 {
00183  double    xmin;           /* left window limit */
00184  double    xmax;           /* right window limit */
00185  double    ymin;           /* bottom window limit */
00186  double    ymax;           /* top window limit */
00187  double    width, height;  /* window sizes in world coords. */
00188  double    maxsize;        /* maximum window size */
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 /*========================  _dspMember  ========================*/
00218 static void _dspMember( int id )
00219 {
00220  int    node0;       /* index of first member node */
00221  int    node1;       /* index of second member node */
00222  double x0;          /* first node x coordinate */
00223  double y0;          /* first node y coordinate */
00224  double x1;          /* second node x coordinate */
00225  double y1;          /* second node y coordinate */
00226  double q;           /* member uniform load (positive uppward in local sys.) */
00227  int    rotlib0;     /* code of first end member rotation liberation */
00228  int    rotlib1;     /* code of second end member rotation liberation */
00229  double m0;          /* bending moment at first member end */
00230  double m1;          /* bending moment at second member end */
00231  double dx;          /* difference of member end node x coords. */
00232  double dy;          /* difference of member end node y coords. */
00233  double angle;       /* orientation angle of member line */
00234  double len;         /* member length */
00235 
00236 /* Get member node data, attributes and moments.
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 /* Display member line.
00246  */
00247 /**** COMPLETE AQUI: 017 ****/
00248 
00249 /* Get member length and orientation angle in degrees.
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 /* Adjust given angle to fit right angles.
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 /* Display member attributes.
00279  */
00280  _dspMemberAtt( x0, y0, len, angle, q, rotlib0, rotlib1, m0, m1 );
00281 }
00282 
00283 /*========================  _dspMemberAtt  ========================*/
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;  /* flag for default orientation (left to right or vert.) */
00302  double text_angle;  /* angle of text orientation */
00303  double x;           /* generic point x coordinate */
00304  double y;           /* generic point y coordinate */
00305  char   s[32];       /* generic string */
00306 
00307 /* Build an affine transformation to transform points in local 
00308  * member system to global system.
00309  */
00310  t2dIdentity( );
00311  t2dRotate( angle );
00312  t2dTranslate( x0, y0 );
00313 
00314 /* Check to see whether member has a default orientation
00315  * (from left to right or vertical).
00316  */
00317  if( (angle > -90.0) && (angle <= 90.0) )
00318   def_orient = 1;
00319  else
00320   def_orient = 0;
00321 
00322 /* Define text orientation.
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 /* Display member load.
00338  */
00339  if( dsp_load && (fabs( q ) > LOAD_TOL) )
00340   _dspMemberLoad( len, q, def_orient );
00341 
00342 /* Display member end hinges (if they exist).
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 /**** COMPLETE AQUI: 018 ****/
00360  }
00361 
00362 /* Display bending moment at first end.
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 /* Display bending moment at second end.
00382  */
00383  if( rotlib1 == ROT_FIX )
00384  {
00385 /**** COMPLETE AQUI: 019 ****/
00386  }
00387 }
00388 
00389 /*========================  _dspMemberLoad  ========================*/
00397 static void _dspMemberLoad( double len, double q, int def_orient )
00398 {
00399  double x;           /* generic point x coordinate */
00400  double y;           /* generic point y coordinate */
00401  double xa;          /* generic first line point x coordinate */
00402  double ya;          /* generic first line point y coordinate */
00403  double xb;          /* generic second line point x coordinate */
00404  double yb;          /* generic second line point y coordinate */
00405  int    n_arrows;    /* number of load arrows */
00406  double step_size;   /* adjusted load arrow step size */
00407  int    i;           /* generic counter */
00408  char   s[32];       /* generic string */
00409 
00410  cdForeground( LOAD_COLOR );
00411 
00412 /* Display bottom load line.
00413  */
00414 /**** COMPLETE AQUI: 020 ****/
00415 
00416 /* Display top load line.
00417  */
00418 /**** COMPLETE AQUI: 021 ****/
00419 
00420 /* Display load arrows.
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 /* Display load value.
00433  */
00434 /**** COMPLETE AQUI: 022 ****/
00435 }
00436 
00437 /*========================  _dspLoadArrow  ========================*/
00445 static void _dspLoadArrow( double x, double q, int def_orient )
00446 {
00447 /**** COMPLETE AQUI: 023 ****/
00448 }
00449 
00450 
00451 /*
00452 ** ---------------------------------------------------------------
00453 ** Public functions:
00454 */
00455 
00456 /*===========================  dspInit  ==========================*/
00462 void dspInit( void )
00463 {
00464  cdBackground( BACKGROUND_COLOR );
00465  cdFont( CD_COURIER, CD_PLAIN, CD_SMALL );
00466 }
00467 
00468 /*==========================  dspWindow  =========================*/
00486 void dspWindow( double scale,
00487                 double *xmin, double *xmax,
00488                 double *ymin, double *ymax )
00489 {
00490  int       hsize, vsize;           /* canvas sizes in pixels    */
00491  double    vpr;                    /* viewport distortion ratio */
00492  double    cx, cy;                 /* window center             */
00493  double    sizex, sizey;           /* window sizes              */
00494 
00495 /* Compute canvas viewport ratio.
00496  */
00497  cdGetCanvasSize( &hsize, &vsize, 0L, 0L );
00498  vpr = (double)vsize / (double)hsize;
00499 
00500 /* Get given window center.
00501  */
00502 /**** COMPLETE AQUI: 024 ****/
00503 
00504 /* Set new window sizes based on scaling factor.
00505  */
00506 /**** COMPLETE AQUI: 025 ****/
00507 
00508 /* Adjust window to keep the same aspect ratio of the viewport.
00509  */
00510 /**** COMPLETE AQUI: 026 ****/
00511 
00512 /* Set new window.
00513  */
00514  wdWindow( *xmin, *xmax, *ymin, *ymax );
00515 }
00516 
00517 /*=========================  dspPanWindow  =======================*/
00535 void dspPanWindow( double dx, double dy,
00536                    double *xmin, double *xmax,
00537                    double *ymin, double *ymax )
00538 {
00539 /* Shift given window according to given displacement values.
00540  */
00541 /**** COMPLETE AQUI: 027 ****/
00542 
00543 /* Set new window.
00544  */
00545  wdWindow( *xmin, *xmax, *ymin, *ymax );
00546 }
00547 
00548 /*==========================  dspLoadDisplay  ==========================*/
00556 void dspLoadDisplay( int on_off )
00557 {
00558  dsp_load = on_off;
00559 }
00560 
00561 /*==========================  dspModel  ==========================*/
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 /* Compute attribute sizes based on maximum window size.
00580  */
00581  _dspAttSizes( );
00582 
00583 /* Display all members.
00584  */
00585  for( i = 0; i < n_member; i++ )
00586  {
00587   _dspMember( i );
00588  }
00589 
00590 /* Display node marks accoding to their status.
00591  */
00592 /**** COMPLETE AQUI: 028 ****/
00593 }
00594 

Gerado em Tue Oct 5 04:55:00 2004 para Trab3 por doxygen 1.3.4