00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "jed_defs.h"
00024 #include "jed_gl.h"
00025
00026 #include "framework/visual/visor.h"
00027
00028 #ifdef VEL_ROSITA
00029 #include "framework/visual/v_sensor.h"
00030 #endif
00031
00032 #include <stdio.h>
00033 #include <string.h>
00034 #include <stdlib.h>
00035
00036
00037
00038
00039
00040 #define ESPERO(tipo, msg) \
00041 if ( tipo_token != (tipo) ) { \
00042 fprintf(stderr, "<VISOR_SENSOR_FLOAT> " \
00043 "ERROR: Esperaba %s y recibi [%s].\n", \
00044 (msg), cad); fflush(stderr); return FALSE; \
00045 }
00046
00047 #define VERIFICAR(c) \
00048 if ( !(c) ) {\
00049 fprintf(stderr, \
00050 "<VISOR_SENSOR_FLOAT> " \
00051 "ERROR: No se pudo crear un objeto dinamico!\n");\
00052 fflush(stderr);\
00053 exit(1);\
00054 }
00055
00056 #define DATA_PERCENT() ((data[pos]-min_val)/(max_val-min_val))
00057 #define DATA_I_PERCENT(i) ((data[(i)]-min_val)/(max_val-min_val))
00058
00059
00060
00061
00062
00063 VISOR_SENSOR_FLOAT::VISOR_SENSOR_FLOAT() : VISOR_SENSOR()
00064 {
00065 Sensor = NULL;
00066 _nombre_variable = NULL;
00067 _tipo = 1;
00068 min_val = 0;
00069 max_val = 1.0;
00070
00071
00072 data = NULL;
00073 configurar_vector_de_estado(1);
00074 }
00075
00076 VISOR_SENSOR_FLOAT::VISOR_SENSOR_FLOAT(int nuevo_tipo, float min, float max)
00077 {
00078 Sensor = NULL;
00079 _nombre_variable = NULL;
00080 _tipo = nuevo_tipo;
00081 min_val = min;
00082 max_val = max;
00083
00084
00085 data = NULL;
00086 configurar_vector_de_estado(1);
00087 }
00088
00089 VISOR_SENSOR_FLOAT::~VISOR_SENSOR_FLOAT()
00090 {
00091 if ( data ) delete data;
00092 }
00093
00094 void
00095 VISOR_SENSOR_FLOAT::configurar_vector_de_estado(int tam)
00096 {
00097 if ( data ) delete data;
00098
00099 pos = 0;
00100 data = new float[tam];
00101 if ( !data ) {
00102 _tipo = 0;
00103 tam_data = 0;
00104 }
00105 tam_data = tam;
00106 data[pos] = min_val;
00107 }
00108
00109 #ifdef GL_ENABLED
00110 void
00111 VISOR_SENSOR_FLOAT::pintar_gl(void)
00116 {
00117
00118
00119 pos++;
00120 if ( pos >= tam_data ) {
00121 pos = 0;
00122 }
00123
00124
00125 if ( Sensor ) data[pos] = Sensor->evaluar();
00126 else data[pos] = 0;
00127
00128 if ( data[pos] < min_val ) data[pos] = min_val;
00129 if ( data[pos] > max_val ) data[pos] = max_val;
00130
00131
00132 float split1_tam = 1.75f, x_split2 = 0.85f;
00133 int i;
00134
00135 camara.subbillboard_gl(tam_grilla,
00136 x_grilla, y_grilla, dx_grilla, dy_grilla,
00137 cuadre_grilla);
00138 glDisable(GL_DEPTH_TEST);
00139 glDisable(GL_LIGHTING);
00140 glShadeModel(GL_FLAT);
00141 ACTIVAR_TRANSPARENCIA(_transparencia);
00142
00143 switch ( _tipo ) {
00144
00145 case 1:
00146
00147 glColor4f(1, 0, 0, (float)_transparencia);
00148 jvs_cuadro_gl(-1, -1, 2, 2, DATA_PERCENT(), _transparencia);
00149 break;
00150
00151 case 2:
00152 glColor4f(DATA_PERCENT(), 0, 1 - DATA_PERCENT(), (float)_transparencia);
00153 jvs_cuadro_gl(-1, -1, split1_tam, 2, 1.0, _transparencia);
00154 jvs_pintar_paleta(x_split2, -1, 0.15f, 2, _transparencia);
00155 break;
00156
00157 case 3:
00158 glColor4f(1, 1, 1, (float)_transparencia);
00159 glBegin(GL_LINES);
00160 glVertex2f(-1, -1); glVertex2f(-1, 1);
00161 glVertex2f(-1, -1); glVertex2f(1, -1);
00162 glEnd();
00163
00164 glColor4f(1, 1, 0, (float)_transparencia);
00165 glBegin(GL_LINE_STRIP);
00166 for ( i = 0; i < tam_data && i <= pos; i++ ) {
00167 glVertex2f(-1 + 2*(float)i/tam_data, 2*DATA_I_PERCENT(i)-1);
00168 glVertex2f(-1 + 2*(float)(i+1)/tam_data, 2*DATA_I_PERCENT(i)-1);
00169 }
00170 glEnd();
00171 break;
00172
00173
00174 case 4:
00175 glColor4f(1, 1, 1, (float)_transparencia);
00176 glBegin(GL_LINES);
00177 glVertex2f(-1, -1); glVertex2f(-1, 1);
00178 glVertex2f(-1, -1); glVertex2f(1, -1);
00179 glEnd();
00180
00181 glBegin(GL_LINES);
00182 for ( i = 0; i < tam_data && i <= pos; i++ ) {
00183 glColor4f(DATA_I_PERCENT(i), 0, 1 - DATA_I_PERCENT(i), (float)_transparencia);
00184 glVertex2f(-1 + 2*((float)i)/tam_data, -1);
00185 glVertex2f(-1 + 2*((float)i+1)/tam_data, 2*DATA_I_PERCENT(i)-1);
00186 }
00187 glEnd();
00188 break;
00189
00190
00191 default:
00192 glColor3f(1.0f, 1.0f, 1.0f);
00193 glBegin(GL_LINES);
00194 glVertex2f(-1, -1); glVertex2f(1, 1);
00195 glVertex2f(-1, 1); glVertex2f(1, -1);
00196 glEnd();
00197 break;
00198
00199 }
00200
00201 }
00202 #endif // GL_ENABLED
00203
00204 int
00205 VISOR_SENSOR_FLOAT::tipo(void)
00206 {
00207 return T_FLOAT;
00208 }
00209
00210
00211
00212 BOOLEAN
00213 VISOR_SENSOR_FLOAT::leer(TOKENIZADOR *Sabiondo)
00214 {
00215 char cad[1000];
00216 int tipo_token = TK_DESCONOCIDO, pos;
00217
00218
00219 pos = 1;
00220 while ( tipo_token != TK_CERRAR) {
00221 tipo_token = Sabiondo->siguiente_token(cad);
00222 switch ( pos ) {
00223 case 1:
00224 ESPERO(TK_CADENA, "un nombre de variable de estado");
00225 des_comille(cad);
00226 _nombre_variable = new char [strlen(cad) + 1];
00227 VERIFICAR(_nombre_variable);
00228 strcpy(_nombre_variable, cad);
00229 pos++;
00230 break;
00231 case 2: ESPERO(TK_ABRIR, "\"{\""); pos++; break;
00232 default:
00233 if ( tipo_token == TK_CERRAR ) break;
00234 ESPERO(TK_IDENTIFICADOR, "un identificador (3)");
00235 if ( strcmp(cad, "tipo") == 0 ) {
00236 tipo_token = Sabiondo->siguiente_token(cad);
00237 ESPERO(TK_NUMERO, "un numero");
00238 _tipo = atoi(cad);
00239 if ( _tipo == 3 || _tipo == 4 ) {
00240 configurar_vector_de_estado(100);
00241 }
00242 }
00243 else if ( strcmp(cad, "min") == 0 ) {
00244 tipo_token = Sabiondo->siguiente_token(cad);
00245 ESPERO(TK_NUMERO, "un numero");
00246 min_val = (float)atof(cad);
00247 }
00248 else if ( strcmp(cad, "max") == 0 ) {
00249 tipo_token = Sabiondo->siguiente_token(cad);
00250 ESPERO(TK_NUMERO, "un numero");
00251 max_val = (float)atof(cad);
00252 }
00253 if ( !leer_sensor(Sabiondo, cad) ) {
00254 return FALSE;
00255 }
00256 ;
00257 break;
00258 }
00259 }
00260
00261 return TRUE;
00262 }
00263
00264 BOOLEAN
00265 VISOR_SENSOR_FLOAT::asociar_sensor(SENSOR *S)
00266 {
00267 if ( S->tipo() != T_FLOAT ) return FALSE;
00268 Sensor = (SENSOR_FLOAT *)S;
00269 Sensor->sensar();
00270 return TRUE;
00271 }
00272
00273
00274
00275
00276