rui.c

Go to the documentation of this file.
00001 /*
00002  * $Id: rui.c,v 1.2 2004/06/22 17:53:10 joaoluiz Exp $
00003  * (C) COPYRIGHT 2004, Joao Luiz Elias Campos.
00004  * All Rights Reserved
00005  * Duplication of this program or any part thereof without the express
00006  * written consent of the author is prohibited
00007  */
00008 
00015 /*
00016  * Global variables and symbols:
00017  */
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 #include <string.h>
00021 #if !defined(WIN32)
00022 # include <dlfcn.h>
00023 #endif
00024 #include "rui.h"
00025 #include "node.h"
00026 #include "elm.h"
00027 
00028 #define MODEL_CB void (*)(int, void *, int, void *, void **)
00029 
00030 struct UI_State {
00031  void *uilib;
00032  int (*open)(char *);
00033  void (*close)(void);
00034  int (*event)(void);
00035  void (*events)(void);
00036  void (*draw)(void);
00037  void (*model)(int, void *, int, void *, void **);
00038  void (*disp)(int, double *);
00039 };
00040 
00041 static char *size = NULL;
00042 
00046 UI_State *UIStart(int argc, char *argv[])
00047 {
00048  int i = 1;
00049  int have_ui = 0;
00050  char uiname[256];
00051  char *opt = NULL;
00052  char *relax_dir = NULL;
00053  char *tec_uname = NULL;
00054  UI_State *state = NULL;
00055 
00056  for( opt = argv[1]; opt != NULL; opt = argv[i] ) {
00057   if( strcmp(opt, "--ui") == 0 ) {
00058    have_ui = 1;
00059   }
00060   else if( strcmp(opt, "--geometry") == 0 ) {
00061    have_ui = 1;
00062    size = strdup(argv[i+1]);
00063    i++;
00064   }
00065   i++;
00066  }
00067  if( !have_ui ) {
00068   return state;
00069  }
00070  if( size == NULL ) {
00071   size = strdup("300x300");
00072  }
00073 
00074  if( (relax_dir = getenv("RELAX_DIR")) == NULL ) {
00075   fprintf(stderr, "Could not start Relax user interface, RELAX_DIR ");
00076   fprintf(stderr, "must be defined.\n\n");
00077   return state;
00078  }
00079  if( (tec_uname = getenv("TEC_UNAME")) == NULL ) {
00080   fprintf(stderr, "Could not start Relax user interface, TEC_UNAME ");
00081   fprintf(stderr, "must be defined.\n\n");
00082   return state;
00083  }
00084 #if defined(WIN32)
00085  sprintf(uiname, "%s\\lib\\%s\\relax_ui.dll", relax_dir, tec_uname);
00086 #else
00087  sprintf(uiname, "%s/lib/%s/librelax_ui.so", relax_dir, tec_uname);
00088 #endif
00089 #if 0 /* Tem que fazer funcionar para Windows esse trecho AQUI */
00090  state = (UI_State *)malloc(sizeof(UI_State));
00091  if( (state->uilib = dlopen(uiname, RTLD_LAZY)) == NULL ) {
00092   fprintf(stderr, "Could not load %s user interface library.\n\n", uiname);
00093   free(state);
00094   return NULL;
00095  }
00096 
00097  state->open = (int (*)(char *))dlsym(state->uilib, "RelaxUIOpen");
00098  state->close = (void (*)(void))dlsym(state->uilib, "RelaxUIClose");
00099  state->event = (int (*)(void))dlsym(state->uilib, "RelaxUIProcessEvent");
00100  state->events = (void (*)(void))dlsym(state->uilib, "RelaxUIProcessEvents");
00101  state->draw = (void (*)(void))dlsym(state->uilib, "RelaxUIDraw");
00102  state->model = (MODEL_CB)dlsym(state->uilib, "RelaxUISetModel");
00103  state->disp = (void (*)(int, double *))dlsym(state->uilib, "RelaxUISetDisplacement");
00104 #endif
00105  if( state->open == NULL ) {
00106   fprintf(stderr, "Could not get %s function from library.\n", "RelaxUIOpen");
00107   /* dlclose(state->uilib); AQUI */
00108   free(state);
00109   return NULL;
00110  }
00111  if( state->close == NULL ) {
00112   fprintf(stderr, "Could not get %s function from library.\n", "RelaxUIClose");
00113   /* dlclose(state->uilib); AQUI */
00114   free(state);
00115   return NULL;
00116  }
00117  if( state->event == NULL ) {
00118   fprintf(stderr, "Could not get %s function from library.\n", "RelaxUIProcessEvent");
00119   /* dlclose(state->uilib); AQUI */
00120   free(state);
00121   return NULL;
00122  }
00123  if( state->events == NULL ) {
00124   fprintf(stderr, "Could not get %s function from library.\n", "RelaxUIProcessEvents");
00125   /* dlclose(state->uilib); AQUI */
00126   free(state);
00127   return NULL;
00128  }
00129  if( state->draw == NULL ) {
00130   fprintf(stderr, "Could not get %s function from library.\n", "RelaxUIDraw");
00131   /* dlclose(state->uilib); AQUI */
00132   free(state);
00133   return NULL;
00134  }
00135  if( state->model == NULL ) {
00136   fprintf(stderr, "Could not get %s function from library.\n", "RelaxUISetModel");
00137   /* dlclose(state->uilib); AQUI */
00138   free(state);
00139   return NULL;
00140  }
00141  if( state->disp == NULL ) {
00142   fprintf(stderr, "Could not get %s function from library.\n", "RelaxUISetDisplacement");
00143   /* dlclose(state->uilib); AQUI */
00144   free(state);
00145   return NULL;
00146  }
00147 
00148  (*state->model)(NumNodes, NodeVector, NumElements, (void *)ElmClass, (void **)ElmList);
00149  if( !(*state->open)(size) ) {
00150   fprintf(stderr, "Could not open %s library.\n", uiname);
00151   /* dlclose(state->uilib); AQUI */
00152   free(state);
00153   return NULL;
00154  }
00155  return state;
00156 
00157 } /* End of UIStart */
00158 
00162 void UIFinish(UI_State *state)
00163 {
00164  (*state->close)();
00165  /* dlclose(state->uilib); AQUI */
00166  free(state);
00167 
00168 } /* End of UIFinish */
00169 
00173 void UIDraw(UI_State *state)
00174 {
00175  (*state->draw)();
00176 
00177 } /* End of UIDraw */
00178 
00182 void UISetDisplacement(UI_State *state, int ndof, double *u)
00183 {
00184  (*state->disp)(ndof, u);
00185 
00186 } /* End of UISetDisplacement */
00187 
00188 /*
00189  * End of File.
00190  */
00191 
00192 

Generated on Tue Oct 23 11:23:30 2007 for Relax by  doxygen 1.5.3