00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00037
00038
00039
00040
00041 #include <stdlib.h>
00042 #include <stdio.h>
00043 #include <string.h>
00044
00045 #include "iup.h"
00046 #include "iupkey.h"
00047 #include "iupgl.h"
00048 #include "iupcontrols.h"
00049
00050 #include "prj.h"
00051 #include "prm.h"
00052
00053
00054
00055
00056
00058 static Ihandle* Omain;
00060 static Ihandle* Otopmsg;
00062 static Ihandle* Oheightval;
00064 static int cv_height;
00066 static int cv_width;
00068 int doing_help = 0;
00070 static char file_name[256];
00071
00072
00073
00074
00075
00076
00077
00078
00079
00088 static FILE* drvOpenFile( char* mode )
00089 {
00090 FILE* fd;
00091 Ihandle* dlg;
00092 int status;
00093
00094 strcpy( file_name, "*.*" );
00095
00096
00097
00098 dlg = IupFileDlg( );
00099 if( strcmp( mode, "r" ) == 0 )
00100 {
00101 IupSetAttribute( dlg, IUP_DIALOGTYPE, "OPEN" );
00102 }
00103 else
00104 {
00105 IupSetAttribute( dlg, IUP_DIALOGTYPE, "SAVE" );
00106 }
00107 IupSetAttribute( dlg, IUP_TITLE, "Trab4: Dialogo para selecionar arquivo" );
00108 IupSetAttribute( dlg, IUP_FILTER, "*.*" );
00109 IupSetAttribute( dlg, IUP_FILE, file_name );
00110
00111
00112
00113 IupPopup( dlg, IUP_CURRENT, IUP_CURRENT );
00114 status = IupGetInt( dlg, IUP_STATUS );
00115 if( status >= 0 )
00116 {
00117 strcpy( file_name, IupGetAttribute( dlg, IUP_VALUE ) );
00118 }
00119 else
00120 {
00121 return( NULL );
00122 }
00123
00124
00125
00126 fd = fopen( file_name, mode );
00127 if( fd == NULL )
00128 {
00129 IupMessage( " Mensagem de Erro ",
00130 "\n Nao foi possivel abrir arquivo! \n" );
00131 return( NULL );
00132 }
00133
00134 return( fd );
00135 }
00136
00137
00138
00139
00140
00141
00142 static void drvResize( int width, int height, void* h );
00143 static void drvRedisplay( void* h );
00144 static void drvMouseBt( int bt, int mode,
00145 float x, float y, void* data );
00146 static void drvMouseMv( int bt, float x, float y, void* data );
00147
00148
00149
00159 static void drvResize( int width, int height, void* h )
00160 {
00161 IupGLMakeCurrent( Prj::Odatascreen );
00162 cv_height = height;
00163 cv_width = width;
00164 Prj::Resize( width, height );
00165 }
00166
00167
00168
00175 static void drvRedisplay( void* h )
00176 {
00177 if( (Prm::First( ) == NULL) || doing_help )
00178 {
00179
00180
00181 Prj::Help( );
00182 IupSetAttribute( Otopmsg, IUP_TITLE,
00183 " Os comandos abaixo podem ser acionados"
00184 " de acordo com as teclas indicadas. " );
00185 }
00186 else
00187 {
00188 Prj::Redisplay( );
00189 }
00190 }
00191
00192
00193
00202 static void drvMouseBt( int bt, int mode,
00203 float x, float y, void* data )
00204 {
00205 double xw, yw;
00206 double factor;
00207 int rx, ry;
00208 static char fac_string[20];
00209
00210
00211
00212
00213
00214
00215
00216 if( (bt == VGL_BUTTON_LEFT) && (mode == VGL_PRESS) )
00217 {
00218
00219
00220
00221 rx = (int) (x*(float)cv_width);
00222 ry = (int) (y*(float)cv_height);
00223 if( ! Prj::Raster2WorldXY( rx, ry, &xw, &yw ) )
00224 return;
00225
00226 Prj::SelectPrm( xw, yw );
00227 factor = Prj::GetHeightFac( );
00228 sprintf( fac_string, "%.2f", factor );
00229 IupSetAttribute( Oheightval, IUP_VALUE, fac_string );
00230 doing_help = 0;
00231 }
00232 else
00233 {
00234 IupSetAttribute( Otopmsg, IUP_TITLE, " " );
00235 }
00236 }
00237
00238
00239
00247 static void drvMouseMv( int bt, float x, float y, void* data )
00248 {
00249 }
00250
00251
00252
00253
00254
00255
00256 static int drvSetHeightFac( Ihandle* val, double fac );
00257 static int drvKeyCrtl( Ihandle* dg, int key );
00258
00259
00260
00272 static int drvSetHeightFac( Ihandle* val, double fac )
00273 {
00274 Prj::SetHeightFac( fac );
00275 return( IUP_DEFAULT );
00276 }
00277
00278
00279
00291 static int drvKeyCrtl( Ihandle* dg, int key )
00292 {
00293 FILE* fd;
00294
00295
00296
00297 IupSetAttribute( Otopmsg, IUP_TITLE, " " );
00298
00299
00300
00301 switch( key )
00302 {
00303 case K_h:
00304 case K_H:
00305 doing_help =! doing_help;
00306 vglRedraw( Prj::vglcanvas );
00307 break;
00308
00309 case K_cQ:
00310 Prj::Quit( );
00311 return( IUP_CLOSE );
00312
00313 case K_cI:
00314 Prj::Info( );
00315 break;
00316
00317 case K_cO:
00318 if( (fd = drvOpenFile( "r" )) != NULL )
00319 {
00320 if( ! Prj::OpenModel( fd ) )
00321 {
00322 IupMessage( " Mensagem de Erro ",
00323 "\n Erro nos dados do arquivo lido!\n" );
00324 }
00325 else
00326 {
00327 IupSetAttribute( Otopmsg, IUP_TITLE,
00328 " Use o mouse para manipular o modelo na tela. " );
00329 }
00330 fclose( fd );
00331 }
00332 break;
00333
00334 case K_cS:
00335 Prj::ZbufferSnapShot( );
00336 break;
00337
00338 case K_r:
00339 Prj::ResetView( );
00340 break;
00341
00342 case K_f:
00343 Prj::Fit( );
00344 break;
00345
00346 case K_p:
00347 Prj::Persp( );
00348 break;
00349
00350 case K_o:
00351 Prj::Ortho( );
00352 break;
00353
00354 case K_x:
00355 Prj::ProjX( );
00356 break;
00357
00358 case K_y:
00359 Prj::ProjY( );
00360 break;
00361
00362 case K_z:
00363 Prj::ProjZ( );
00364 break;
00365
00366 case K_cM:
00367 Prj::ManipMode( );
00368 break;
00369
00370 case K_cN:
00371 Prj::NavigMode( );
00372 break;
00373
00374 case K_cZ:
00375 Prj::ZoomMode( );
00376 break;
00377
00378 default:
00379 break;
00380 }
00381
00382 return( IUP_DEFAULT );
00383 }
00384
00385
00386
00387
00388
00389
00390
00391
00403 int main( int argc, char* argv[] )
00404 {
00405 static char msg_alarm[512];
00406 char* msg_error;
00407
00408 IupOpen( &argc, &argv );
00409 IupControlsOpen( );
00410 IupGLCanvasOpen( );
00411
00412 msg_error = IupLoad( "trab4.led" );
00413 if( msg_error )
00414 {
00415 sprintf( msg_alarm, "\n%s\n", msg_error );
00416 IupAlarm( "Erro no arquivo trab4.led!", msg_alarm, " OK ", NULL, NULL );
00417 IupClose( );
00418 exit( 1 );
00419 }
00420
00421
00422
00423 Omain = IupGetHandle( "main" );
00424 Otopmsg = IupGetHandle( "topmsg" );
00425 Prj::Odatascreen = IupGetHandle( "datascreen" );
00426 Oheightval = IupGetHandle( "heightval" );
00427
00428
00429
00430 IupMap( Omain );
00431
00432
00433
00434 IupSetFunction( "drvSetHeightFac", (Icallback)drvSetHeightFac );
00435 IupSetFunction( "drvKeyCrtl", (Icallback)drvKeyCrtl );
00436
00437
00438
00439
00440
00441
00442 Prj::vglcanvas = vglIupCanvas( Prj::Odatascreen );
00443 vglSetReshapeFunc( Prj::vglcanvas, drvResize, 0L );
00444 vglSetRedrawFunc( Prj::vglcanvas, drvRedisplay, 0L );
00445 vglSetMouseButtonFunc( Prj::vglcanvas, drvMouseBt, Prj::vglcanvas );
00446 vglSetMouseMotionFunc( Prj::vglcanvas, drvMouseMv, Prj::vglcanvas );
00447
00448
00449
00450 Prj::Init( );
00451
00452
00453
00454 IupShowXY( Omain, IUP_CENTER, IUP_CENTER );
00455
00456
00457
00458 IupMainLoop( );
00459
00460 IupClose( );
00461
00462 return( 0 );
00463 }
00464