00001
00002
00003
00004
00005
00006
00007 #define _PRJ_C
00008
00037
00038
00039
00040
00041 #include <stdio.h>
00042
00043 #include "iup.h"
00044 #include "cd.h"
00045 #include "cdiup.h"
00046 #include "cdclipbd.h"
00047 #include "cdprint.h"
00048 #include "wd.h"
00049
00050 #include "prj.h"
00051 #include "crs.h"
00052 #include "nfr.h"
00053 #include "dsp.h"
00054
00055
00056
00057
00058
00059
00061 #define SOLUTION_TOL 0.01
00062
00065 #define FIT_FACTOR 0.10
00066
00068 #define ZOOM_FACTOR 0.20
00069
00072 #define PAN_FACTOR 0.05
00073
00076 #define PICK_FACTOR 0.01
00077
00080 static char *trab_info =
00081 {
00082 "\n"
00083 "\n"
00084 " CIV-2801 -- 2004.2 \n"
00085 "\n"
00086 " Fundamentos de Computacao Grafica Aplicada \n"
00087 "\n"
00088 " Departamento de Engenharia Civil \n"
00089 " PUC-Rio \n"
00090 "\n"
00091 " Trabalho No.: 3 \n"
00092 " Aluno: \n"
00093 " Data: \n"
00094 "\n"
00095 };
00096
00099 static double win_xmin = 0.0;
00100
00103 static double win_xmax = 50.0;
00104
00107 static double win_ymin = 0.0;
00108
00111 static double win_ymax = 50.0;
00112
00115 static void *crs_model = NULL;
00116
00117
00118
00119
00120
00121
00122
00123
00127 static void prjResetWindow( void )
00128 {
00129 win_xmin = 0.0;
00130 win_xmax = 50.0;
00131 win_ymin = 0.0;
00132 win_ymax = 50.0;
00133 }
00134
00135
00136
00137
00138
00139
00140
00145 void prjInit( void )
00146 {
00147 int width, height;
00148
00149
00150
00151 Gdatascreen = cdCreateCanvas( CD_IUP, Odatascreen );
00152 wdActivate( Gdatascreen );
00153
00154
00155
00156 cdGetCanvasSize( &width, &height, 0L, 0L );
00157 cdClipArea( 0, width-1, 0, height-1 );
00158 wdViewport( 0, width-1, 0, height-1 );
00159
00160
00161
00162 dspInit( );
00163 dspWindow( 1.0, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00164 cdClear( );
00165 }
00166
00167
00172 void prjQuit( void )
00173 {
00174 if( crs_model != NULL )
00175 crsFreeModel( crs_model );
00176 cdKillCanvas( Gdatascreen );
00177 }
00178
00179
00188 int prjChkEmptyModel( void )
00189 {
00190 if( crsGetNumMembers( ) == 0 )
00191 return( 1 );
00192
00193 return( 0 );
00194 }
00195
00196
00204 void prjResize( int width, int height )
00205 {
00206 wdActivate( Gdatascreen );
00207
00208
00209
00210 cdClipArea( 0, width-1, 0, height-1 );
00211 wdViewport( 0, width-1, 0, height-1 );
00212
00213
00214
00215 dspWindow( 1.0, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00216 }
00217
00218
00223 void prjRedisplay( void )
00224 {
00225 cdClear( );
00226 dspModel( );
00227 }
00228
00229
00234 void prjInfo( void )
00235 {
00236 IupMessage( " Informacoes do Projeto ", trab_info );
00237 }
00238
00239
00244 void prjHelp( void )
00245 {
00246 double win_xmin_help, win_xmax_help, win_ymin_help, win_ymax_help;
00247 int text_alignment;
00248
00249 cdClear( );
00250 win_xmin_help = 0.0;
00251 win_xmax_help = 11.5;
00252 win_ymin_help = 0.0;
00253 win_ymax_help = 11.5;
00254 dspWindow( 1.0+FIT_FACTOR, &win_xmin_help, &win_xmax_help,
00255 &win_ymin_help, &win_ymax_help );
00256
00257 cdForeground( CD_BLACK );
00258 text_alignment = cdTextAlignment( CD_BASE_LEFT );
00259
00260 wdText( 0.0, 11.0,
00261 "Selecione uma tecla indicada. Aperte qualquer outra tecla para retornar." );
00262
00263 wdText( 0.0, 10.0, "H (de Help)" );
00264 wdText( 3.0, 10.0, "==> Exibe este help" );
00265 wdText( 0.0, 9.5, "Ctrl+Q (de Quit)" );
00266 wdText( 3.0, 9.5, "==> Sai do programa" );
00267 wdText( 0.0, 9.0, "Ctrl+I (de Info)" );
00268 wdText( 3.0, 9.0, "==> Informacoes sobre o programa" );
00269 wdText( 0.0, 8.5, "Ctrl+N (de New)" );
00270 wdText( 3.0, 8.5, "==> Comeca um novo modelo" );
00271 wdText( 0.0, 8.0, "Ctrl+O (de Open)" );
00272 wdText( 3.0, 8.0, "==> Carrega um novo modelo de arquivo" );
00273 wdText( 0.0, 7.5, "Ctrl+S (de Save)" );
00274 wdText( 3.0, 7.5, "==> Salva resultados do modelo em arquivo" );
00275
00276 wdText( 0.0, 6.5, "I" );
00277 wdText( 3.0, 6.5, "==> Inicializa o processo iterativo de solucao" );
00278 wdText( 0.0, 6.0, "S" );
00279 wdText( 3.0, 6.0, "==> Processa um passo (Step) da solucao iterativa" );
00280 wdText( 0.0, 5.5, "G" );
00281 wdText( 3.0, 5.5, "==> Resolve (Go through) todo o processo iterativo" );
00282
00283 wdText( 0.0, 4.5, "L (de Load)" );
00284 wdText( 3.0, 4.5, "==> Liga/desliga desenho de cargas de barras" );
00285 wdText( 0.0, 4.0, "Ctrl+P (de Print)" );
00286 wdText( 3.0, 4.0, "==> Imprime desenho da janela" );
00287 wdText( 0.0, 3.5, "Ctrl+C (de Copy)" );
00288 wdText( 3.0, 3.5, "==> Copia para a area de transferencia (Clipboard)" );
00289 wdText( 0.0, 3.0, "F (de Fit)" );
00290 wdText( 3.0, 3.0, "==> Ajusta desenho na janela" );
00291 wdText( 0.0, 2.5, "+" );
00292 wdText( 3.0, 2.5, "==> Zoom +" );
00293 wdText( 0.0, 2.0, "-" );
00294 wdText( 3.0, 2.0, "==> Zoom -" );
00295 wdText( 0.0, 1.5, "<-" );
00296 wdText( 3.0, 1.5, "==> Translada imagem para esquerda" );
00297 wdText( 0.0, 1.0, "->" );
00298 wdText( 3.0, 1.0, "==> Translada imagem para direita" );
00299 wdText( 0.0, 0.7, "|" );
00300 wdText( 0.0, 0.5, "v" );
00301 wdText( 3.0, 0.5, "==> Translada imagem para baixo" );
00302 wdText( 0.0, 0.1, "^" );
00303 wdText( 0.0, 0.0, "|" );
00304 wdText( 3.0, 0.0, "==> Translada imagem para cima" );
00305
00306
00307
00308 dspWindow( 1.0, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00309 cdTextAlignment( text_alignment );
00310 }
00311
00312
00317 void prjNew( void )
00318 {
00319 if( crs_model != NULL )
00320 {
00321 crsFreeModel( crs_model );
00322 crs_model = NULL;
00323 }
00324 prjResetWindow( );
00325 dspWindow( 1.0, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00326 prjRedisplay( );
00327 }
00328
00329
00343 int prjOpenModel( FILE *fd )
00344 {
00345
00346
00347 if( crs_model != NULL )
00348 crsFreeModel( crs_model );
00349 prjResetWindow( );
00350
00351
00352
00353
00354
00355 crs_model = nfrCrsModel( fd );
00356 if( crs_model == NULL )
00357 {
00358 return( 0 );
00359 }
00360 crsActivateModel( crs_model );
00361
00362
00363
00364
00365 if( ! nfrCrsNodes( fd ) )
00366 {
00367 crsFreeModel( crs_model );
00368 crs_model = NULL;
00369 return( 0 );
00370 }
00371
00372
00373
00374
00375
00376 if( ! nfrCrsMembers( fd ) )
00377 {
00378 crsFreeModel( crs_model );
00379 crs_model = NULL;
00380 return( 0 );
00381 }
00382
00383
00384
00385 crsCompleteModel( );
00386
00387
00388
00389 crsResetSolution( SOLUTION_TOL );
00390
00391
00392
00393
00394
00395 if( crsGetGlobalBox( &win_xmin, &win_xmax, &win_ymin, &win_ymax ) ==
00396 CRS_SUCCESS )
00397 {
00398 dspWindow( 1.0+FIT_FACTOR, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00399 }
00400
00401
00402
00403 prjRedisplay( );
00404
00405 return( 1 );
00406 }
00407
00408
00415 void prjSaveResults( FILE *fd )
00416 {
00417 int n_member;
00418 int i;
00419 int node0;
00420 int node1;
00421 double m0;
00422 double m1;
00423 double x;
00424 double y;
00425
00426 n_member = crsGetNumMembers( );
00427
00428 for( i = 0; i < n_member; i++ )
00429 {
00430 fprintf( fd, "Barra: %d\n", i+1 );
00431 crsGetMemberNodes( i, &node0, &node1 );
00432 crsGetMemberMoments( i, &m0, &m1 );
00433 crsGetNodeCoords( node0, &x, &y );
00434 fprintf( fd, " Pos. inicial: (%.2f,%.2f), Mom.:%.2f\n", x, y, m0 );
00435 crsGetNodeCoords( node1, &x, &y );
00436 fprintf( fd, " Pos. inicial: (%.2f,%.2f), Mom.:%.2f\n", x, y, m1 );
00437 fprintf( fd, "\n" );
00438 }
00439 }
00440
00441
00447 void prjProcessInit( void )
00448 {
00449 if( crsGetNumMembers( ) == 0 )
00450 return;
00451
00452 crsResetSolution( SOLUTION_TOL );
00453 prjRedisplay( );
00454 }
00455
00456
00466 int prjProcessGoThru( void )
00467 {
00468 int status;
00469
00470 if( crsGetNumMembers( ) == 0 )
00471 return( CRS_NO_MODEL_DEFINED );
00472
00473 status = crsSolveModel( );
00474 if( status == CRS_SUCCESS )
00475 prjRedisplay( );
00476
00477 return( status );
00478 }
00479
00480
00490 int prjProcessStep( void )
00491 {
00492 int status;
00493
00494 if( crsGetNumMembers( ) == 0 )
00495 return( CRS_NO_MODEL_DEFINED );
00496
00497 status = crsStepSolution( );
00498 if( status == CRS_SUCCESS )
00499 prjRedisplay( );
00500
00501 return( status );
00502 }
00503
00504
00518 int prjProcessNode( double x, double y )
00519 {
00520 double width;
00521 double height;
00522 double minsize;
00523 double tol;
00524 int n;
00525 int status;
00526
00527 if( crsGetNumMembers( ) == 0 )
00528 return( CRS_NO_MODEL_DEFINED );
00529
00530 width = win_xmax - win_xmin;
00531 height = win_ymax - win_ymin;
00532 minsize = ( width < height ) ? width : height;
00533 tol = minsize * PICK_FACTOR;
00534
00535 n = crsPickNode( x, y, tol );
00536 if( n < 0 )
00537 return( CRS_FAILURE );
00538
00539 status = crsProcessNode( n );
00540 if( status == CRS_SUCCESS )
00541 prjRedisplay( );
00542
00543 return( status );
00544 }
00545
00546
00554 void prjLoadDisplay( int on_off )
00555 {
00556 dspLoadDisplay( on_off );
00557 prjRedisplay( );
00558 }
00559
00560
00565 void prjPrint( void )
00566 {
00567 if( crsGetNumMembers( ) == 0 )
00568 return;
00569
00570 wdHardcopy( CD_PRINTER, "trab3.prn", Gdatascreen, dspModel );
00571 }
00572
00573
00579 void prjClipboard( void )
00580 {
00581 int width, height;
00582 char data[40];
00583
00584 if( crsGetNumMembers( ) == 0 )
00585 return;
00586
00587 cdActivate( Gdatascreen );
00588 cdGetCanvasSize( &width, &height, 0L, 0L );
00589 sprintf( data, "%dx%d", width, height );
00590
00591 wdHardcopy( CD_CLIPBOARD, data, Gdatascreen, dspModel );
00592 }
00593
00594
00601 void prjFit( void )
00602 {
00603 if( crsGetGlobalBox( &win_xmin, &win_xmax, &win_ymin, &win_ymax ) ==
00604 CRS_SUCCESS )
00605 {
00606 dspWindow( 1.0+FIT_FACTOR, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00607 prjRedisplay( );
00608 }
00609 }
00610
00611
00619 void prjZoomIn( void )
00620 {
00621 if( crsGetNumMembers( ) == 0 )
00622 return;
00623
00624 dspWindow( 1.0-ZOOM_FACTOR, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00625 prjRedisplay( );
00626 }
00627
00628
00636 void prjZoomOut( void )
00637 {
00638 if( crsGetNumMembers( ) == 0 )
00639 return;
00640
00641 dspWindow( 1.0+ZOOM_FACTOR, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00642 prjRedisplay( );
00643 }
00644
00645
00652 void prjPanLeft( void )
00653 {
00654 double sizex, dx;
00655
00656 if( crsGetNumMembers( ) == 0 )
00657 return;
00658
00659 sizex = win_xmax - win_xmin;
00660 dx = sizex * PAN_FACTOR;
00661 dspPanWindow( dx, 0.0, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00662 prjRedisplay( );
00663 }
00664
00665
00672 void prjPanRight( void )
00673 {
00674 double sizex, dx;
00675
00676 if( crsGetNumMembers( ) == 0 )
00677 return;
00678
00679 sizex = win_xmax - win_xmin;
00680 dx = -(sizex * PAN_FACTOR);
00681 dspPanWindow( dx, 0.0, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00682 prjRedisplay( );
00683 }
00684
00685
00692 void prjPanDown( void )
00693 {
00694 double sizey, dy;
00695
00696 if( crsGetNumMembers( ) == 0 )
00697 return;
00698
00699 sizey = win_ymax - win_ymin;
00700 dy = sizey * PAN_FACTOR;
00701 dspPanWindow( 0.0, dy, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00702 prjRedisplay( );
00703 }
00704
00705
00712 void prjPanUp( void )
00713 {
00714 double sizey, dy;
00715
00716 if( crsGetNumMembers( ) == 0 )
00717 return;
00718
00719 sizey = win_ymax - win_ymin;
00720 dy = -(sizey * PAN_FACTOR);
00721 dspPanWindow( 0.0, dy, &win_xmin, &win_xmax, &win_ymin, &win_ymax );
00722 prjRedisplay( );
00723 }
00724