1 /*****************************************************************************
2 *
3 * Elmer, A Finite Element Software for Multiphysical Problems
4 *
5 * Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program (in file fem/GPL-2); if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 *****************************************************************************/
23
24 /*******************************************************************************
25 *
26 *
27 *******************************************************************************
28 *
29 * Author: Juha Ruokolainen
30 *
31 * Address: CSC - IT Center for Science Ltd.
32 * Keilaranta 14, P.O. BOX 405
33 * 02101 Espoo, Finland
34 * Tel. +358 0 457 2723
35 * Telefax: +358 0 457 2302
36 * EMail: Juha.Ruokolainen@csc.fi
37 *
38 * Date: 27 Sep 1995
39 *
40 * Modified by:
41 *
42 * Date of modification:
43 *
44 ******************************************************************************/
45
46 #define MODULE_MAIN
47 #include "elmerpost.h"
48 #include "../config.h"
49
50 #include <tcl.h>
51 #include <tk.h>
52
53 static char str[512];
54
55 static Tcl_DString TCLCommand;
56 Tcl_Interp *TCLInterp,*TCLIntInterp;
57
58 #define MAX_COLORMAP_ENTRIES 512
59
60 double tx,ty,tz,ax,ay,az,sx=1.,sy=1.,sz=1.,br=0.0,bg=0.0,bb=0.0;
61 double XMin,XMax,YMin,YMax,ZMin,ZMax;
62
63 void opengl_draw(),Mouse();
64
65 static int UpdatePending = FALSE;
66
67 #ifndef MINGW32
68 #include <sys/time.h>
69 #endif
70
71 #define MAX_OBJECTS 10
72
73 static int ShowVectors,ShowContours,ShowColorMesh=1, ShowSpheres,
74 ShowMeshLines,ShowIsosurfaces,ShowParticles,ShowColorScale;
75
76 static int MeshStyle,MeshEdgeStyle=1,MeshLineStyle,MeshQuality = 1;
77 static double MeshRadius = 1.0;
78 static int MeshColorSetMinMax,MeshNodeNumbers=0;
79 static scalar_t MeshColor[MAX_OBJECTS];
80
81 static int ContourLines=5,ContourLineStyle,ContourQuality = 1,ContourColorSetMinMax;
82 static double ContourRadius = 1.0;
83 static scalar_t ContourColor[MAX_OBJECTS],ContourContour[MAX_OBJECTS];
84
85 static int VectorLineStyle,VectorQuality=1;
86 static double VectorRadius=1.0,VectorLengthScale=1.0;
87
88 static scalar_t VectorColor,VectorLength,VectorThreshold;
89 static scalar_t VectorArrow[4];
90 static double VectorCeiling,VectorFloor;
91
92 static int IsosurfaceStyle,IsosurfaceContours=1,IsosurfaceLineStyle,IsosurfaceQuality = 1;
93 static int IsosurfaceRecompute=TRUE, IsosurfaceContourSetMinMax;
94 static double IsosurfaceRadius = 1.0;
95 static scalar_t IsosurfaceContour,IsosurfaceColor,IsosurfaceNormal[4];
96 static int IsosurfaceColorSetMinMax;
97
98 static int ParticleLineStyle,ParticleQuality=1,ParticleNofParticles,ParticleArrowStyle;
99 static int ParticleAdvance=1;
100 static int ParticleIntegMethod=1, ParticleIntegPolicy=1,ParticleStyle;
101 static double ParticleRadius = 1.0, ParticleOutDT = 1.0E-1,
102 ParticleMaxDT = 1.0E-3, ParticleTolerance = 1.0E-5;
103 static scalar_t ParticleParticle[5],ParticleVelocity[4],ParticleColor;
104
105 static double SphereRadiusScale=1.0,SphereFloor,SphereCeiling;
106 static int SphereQuality=1;
107 static scalar_t SphereColor,SphereRadius,SphereThreshold;
108
109 static int ColorScaleEntries,ColorScaleDecimals,ColorScaleStyle,ColorScaleFontColor;
110 static scalar_t ColorScaleColor;
111 static double ColorScaleX,ColorScaleY,ColorScaleThickness,ColorScaleLength,ColorScaleFontSize = 17.0;
112 static int ColorScaleColorSetMinMax;
113
114 static int NumberOfScalarVariables, NumberOfVectorVariables, NumberOfParticleVariables;
115 int CurrentTimeStep, GraphicsClearOn = 1, KeepScale = 0, NormalUpdate = 1;
116
117 double xmin,xmax,ymin,ymax,zmin,zmax;
118
119 // Optional FTGL-text rendering functionality:
120 //=============================================
121 #if defined(HAVE_FTGL_NEW) || defined(HAVE_FTGL_OLD)
122 int FtFont(ClientData,Tcl_Interp*,int,char**);
123 int FtText(ClientData,Tcl_Interp*,int,char**);
124 #endif
125
126
fpe_sig(int sig)127 static void fpe_sig( int sig ) { signal( SIGFPE, fpe_sig ); }
128
int_sig(int sig)129 static void int_sig( int sig )
130 {
131 fprintf( stdout, "\n^C\n" );
132
133 BreakLoop = TRUE;
134 signal( SIGINT, int_sig );
135 }
136
DrawItSomeTimeWhenIdle()137 void DrawItSomeTimeWhenIdle()
138 {
139 if ( !UpdatePending )
140 {
141 UpdatePending = TRUE;
142 Tk_DoWhenIdle( (Tk_IdleProc *)opengl_draw,NULL );
143 }
144 }
145
epSwapBuffers()146 static void epSwapBuffers()
147 {
148 auxSwapBuffers();
149 UpdatePending = FALSE;
150 }
151
152 object_t *obj_find( object_t *, char * );
153 object_t *obj_add_object( object_t *, char * );
154
SetObject(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)155 static int SetObject( ClientData cl,Tcl_Interp *interp,int argc,char **argv )
156 {
157 object_t *obj;
158
159 obj = (object_t *)obj_find( &VisualObject,argv[1] );
160 if ( !obj ) obj = (object_t *)obj_add_object( &VisualObject, argv[1] );
161
162 Tcl_UnlinkVar( TCLInterp, "MeshColorMin" );
163 Tcl_UnlinkVar( TCLInterp, "MeshColorMax" );
164
165 Tcl_LinkVar( TCLInterp,"MeshColorMin",(char *)&MeshColor[obj->Id].min, TCL_LINK_DOUBLE );
166 Tcl_LinkVar( TCLInterp,"MeshColorMax",(char *)&MeshColor[obj->Id].max, TCL_LINK_DOUBLE );
167
168 Tcl_UnlinkVar( TCLInterp, "ContourColorMin" );
169 Tcl_UnlinkVar( TCLInterp, "ContourColorMax" );
170
171 Tcl_LinkVar( TCLInterp,"ContourColorMin",(char *)&ContourColor[obj->Id].min, TCL_LINK_DOUBLE );
172 Tcl_LinkVar( TCLInterp,"ContourColorMax",(char *)&ContourColor[obj->Id].max, TCL_LINK_DOUBLE );
173
174 CurrentObject = obj;
175 Tcl_Eval( TCLInterp, "math who" );
176
177 return TCL_OK;
178 }
179
SetParentObject(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)180 static int SetParentObject( ClientData cl,Tcl_Interp *interp,int argc,char **argv )
181 {
182 object_t *obj;
183
184 obj = (object_t *)obj_find( &VisualObject,argv[1] );
185 if ( !obj )
186 {
187 sprintf( interp->result, "parent: no such object [%s]", argv[1] );
188 return TCL_ERROR;
189 }
190
191 obj_set_parent( CurrentObject, obj);
192 return TCL_OK;
193 }
194
GetInterpolate(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)195 static int GetInterpolate( ClientData cl,Tcl_Interp *interp,int argc,char **argv)
196 {
197 static int r0,g0,b0,r1,g1,b1,n0,n1,i;
198 double r,g,b,dr,dg,db;
199
200 static char result[7*MAX_COLORMAP_ENTRIES],color[32];
201
202 sscanf( argv[1], "%d", &n0 );
203 sscanf( argv[2], "%d", &n1 );
204
205 sscanf( argv[3], "#%02x%02x%02x", &r0,&g0,&b0 );
206 sscanf( argv[4], "#%02x%02x%02x", &r1,&g1,&b1 );
207
208 if ( n0 < n1 )
209 {
210 dr = (r1-r0)/(double)(n1-n0);
211 dg = (g1-g0)/(double)(n1-n0);
212 db = (b1-b0)/(double)(n1-n0);
213 }
214
215 r = r0;
216 g = g0;
217 b = b0;
218
219 result[0] = '\0';
220 for( i=n0; i<n1; i++ )
221 {
222 sprintf( color, "#%02x%02x%02x ",(int)r,(int)g,(int)b );
223 strcat( result, color );
224
225 r += dr;
226 g += dg;
227 b += db;
228 }
229
230 Tcl_SetResult(interp,result,TCL_STATIC);
231
232 return TCL_OK;
233 }
234
GetColorMap(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)235 static int GetColorMap(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
236 {
237 static int first = TRUE,rr, gg, bb, i, n;
238 char *str;
239 colormap_t *cmp = &DefaultColorMap;
240
241 if ( strncmp( argv[1], "-vectors", 8 ) == 0 ) {
242 if ( ArrowColorMap != &DefaultColorMap ) {
243 free( ArrowColorMap->Values );
244 free( ArrowColorMap );
245 }
246 cmp = ArrowColorMap = (colormap_t *)malloc( sizeof(colormap_t) );
247 cmp->Values = NULL;
248 argv++;
249 }
250 else if ( strncmp( argv[1], "-mesh", 5 ) == 0 ) {
251 if ( MeshColorMap != &DefaultColorMap ) {
252 free( MeshColorMap->Values );
253 free( MeshColorMap );
254 }
255 cmp = MeshColorMap = (colormap_t *)malloc( sizeof(colormap_t) );
256 cmp->Values = NULL;
257 argv++;
258 }
259 else if ( strncmp( argv[1], "-contour", 8 ) == 0 ) {
260 if ( ContourColorMap != &DefaultColorMap ) {
261 free( ContourColorMap->Values );
262 free( ContourColorMap );
263 }
264 cmp = ContourColorMap = (colormap_t *)malloc( sizeof(colormap_t) );
265 cmp->Values = NULL;
266 argv++;
267 }
268 else if ( strncmp( argv[1], "-isosurface", 11 ) == 0 ) {
269 if ( IsoSurfaceColorMap != &DefaultColorMap ) {
270 free( IsoSurfaceColorMap->Values );
271 free( IsoSurfaceColorMap );
272 }
273 cmp = IsoSurfaceColorMap = (colormap_t *)malloc( sizeof(colormap_t) );
274 cmp->Values = NULL;
275 argv++;
276 }
277 else if ( strncmp( argv[1], "-sphere", 7 ) == 0 ) {
278 if ( SphereColorMap != &DefaultColorMap ) {
279 free( SphereColorMap->Values );
280 free( SphereColorMap );
281 }
282 argv++;
283 cmp = SphereColorMap = (colormap_t *)malloc( sizeof(colormap_t) );
284 cmp->Values = NULL;
285 }
286 else if ( strncmp( argv[1], "-particles", 9 ) == 0 ) {
287 if ( ParticleColorMap != &DefaultColorMap ) {
288 free( ParticleColorMap->Values );
289 free( ParticleColorMap );
290 }
291 argv++;
292 cmp = ParticleColorMap = (colormap_t *)malloc( sizeof(colormap_t) );
293 cmp->Values = NULL;
294 } else if ( *argv[1] == '-' ) {
295 argv++;
296 }
297
298 sscanf( argv[1], "%d", &n );
299 if ( cmp->Values ) free( cmp->Values );
300
301 cmp->Values = (rgb_t *)calloc(n,sizeof(rgb_t));
302
303 if ( !cmp->Values ) return TCL_ERROR;
304
305 str = argv[2];
306 for( i=0; i<n; i++ )
307 {
308 sscanf( &str[7*i], "#%02x%02x%02x", &rr,&gg,&bb );
309 cmp->Values[i].r = rr;
310 cmp->Values[i].g = gg;
311 cmp->Values[i].b = bb;
312 }
313
314 cmp->Changed = TRUE;
315 cmp->NumberOfEntries = n;
316
317 if ( first )
318 {
319 def_map.Values = (rgb_t *)malloc( n*sizeof(rgb_t) );
320 memcpy( def_map.Values,DefaultColorMap.Values,n*sizeof(rgb_t));
321 def_map.Changed = TRUE;
322 def_map.NumberOfEntries = n;
323 }
324
325 UpdateObject();
326 DrawItSomeTimeWhenIdle();
327
328 return TCL_OK;
329 }
330
StopProcessing(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)331 static int StopProcessing(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
332 {
333 int_sig( 0 );
334
335 return TCL_OK;
336 }
337
RecomputeNormals(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)338 static int RecomputeNormals(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
339 {
340
341 geo_vertex_normals( CurrentObject->Geometry, 50.0 );
342 return TCL_OK;
343 }
344
ClipPlane(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)345 static int ClipPlane( ClientData cl,Tcl_Interp *interp,int argc,char **argv)
346 {
347 int i,id;
348
349 if ( argc != 6 ) {
350 sprintf( interp->result, "clip: Wrong number of arguments.\n" );
351 return TCL_ERROR;
352 }
353
354 sscanf( argv[1], "%d", &id );
355 if ( id < 0 || id > 5 ) {
356 sprintf( interp->result, "clip: Plane argument should be from a int from 0..5.\n" );
357 return TCL_ERROR;
358 }
359 CurrentObject->ClipPlane[id] = id;
360 sscanf( argv[2], "%lf", &CurrentObject->ClipEquation[id][0] );
361 sscanf( argv[3], "%lf", &CurrentObject->ClipEquation[id][1] );
362 sscanf( argv[4], "%lf", &CurrentObject->ClipEquation[id][2] );
363 sscanf( argv[5], "%lf", &CurrentObject->ClipEquation[id][3] );
364
365 return TCL_OK;
366 }
367
UpdateBackColor(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)368 static int UpdateBackColor(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
369 {
370 argv++; argc--;
371 if ( strcmp( *argv, "color") != 0 ) return TCL_ERROR;
372
373 argv++; argc--;
374 if ( argc <= 0 ) return TCL_ERROR;
375
376 argv++; argc--;
377 if ( argc ) sscanf( *argv, "%lf", &br );
378
379 argv++; argc--;
380 if ( argc ) sscanf( *argv, "%lf", &bg );
381
382 argv++; argc--;
383 if ( argc ) sscanf( *argv, "%lf", &bb );
384
385 br /= 100.0;
386 bg /= 100.0;
387 bb /= 100.0;
388
389 DrawItSomeTimeWhenIdle();
390
391 return TCL_OK;
392 }
393
UpdateColor(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)394 static int UpdateColor(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
395 {
396 static int diffuse = FALSE;
397
398 static double r=1.,g=1.,b=1.,alpha=1.0,shininess=0.0,spec_r,spec_g,spec_b;
399
400 double rr,gg,bb;
401
402 material_t *mat = &DefaultMaterial;
403
404 if ( strncmp( argv[1], "-vectors", 8 ) == 0 ) {
405 if ( ArrowMaterial != &DefaultMaterial ) {
406 free( ArrowMaterial );
407 }
408 mat = ArrowMaterial = (material_t *)malloc( sizeof(material_t) );
409 argv++;
410 argc--;
411 }
412 else if ( strncmp( argv[1], "-mesh", 5 ) == 0 ) {
413 if ( MeshMaterial != &DefaultMaterial ) {
414 free( MeshMaterial );
415 }
416 mat = MeshMaterial = (material_t *)malloc( sizeof(material_t) );
417 argv++;
418 argc--;
419 }
420 else if ( strncmp( argv[1], "-contour", 8 ) == 0 ) {
421 if ( ContourMaterial != &DefaultMaterial ) {
422 free( ContourMaterial );
423 }
424 mat = ContourMaterial = (material_t *)malloc( sizeof(material_t) );
425 argv++;
426 argc--;
427 }
428 else if ( strncmp( argv[1], "-isosurface", 11 ) == 0 ) {
429 if ( IsoSurfaceMaterial != &DefaultMaterial ) {
430 free( IsoSurfaceMaterial );
431 }
432 mat = IsoSurfaceMaterial = (material_t *)malloc( sizeof(material_t) );
433 argv++;
434 argc--;
435 }
436 else if ( strncmp( argv[1], "-sphere", 7 ) == 0 ) {
437 if ( SphereMaterial != &DefaultMaterial ) {
438 free( SphereMaterial );
439 }
440 argv++;
441 argc--;
442 mat = SphereMaterial = (material_t *)malloc( sizeof(material_t) );
443 }
444 else if ( strncmp( argv[1], "-particles", 9 ) == 0 ) {
445 if ( ParticleMaterial != &DefaultMaterial ) {
446 free( ParticleMaterial );
447 }
448 argv++;
449 argc--;
450 mat = ParticleMaterial = (material_t *)malloc( sizeof(material_t) );
451 } else if ( strncmp( argv[1], "-default",8 ) ) {
452 argv++;
453 argc--;
454 }
455
456 while( argc )
457 {
458 argv++; argc--;
459 if ( argc )
460 {
461 if ( strcmp( *argv, "opacity" ) == 0 )
462 {
463 argv++; argc--;
464 if ( argc ) { sscanf( *argv, "%lf", &alpha ); alpha /= 100; } else return TCL_ERROR;
465 } else if ( strcmp( *argv, "color" ) == 0 )
466 {
467 argv++; argc--;
468 if ( argc <= 0 ) return TCL_ERROR;
469
470 diffuse = FALSE;
471 if ( strcmp( *argv,"diffuse" ) == 0 ) diffuse = TRUE;
472
473 argv++; argc--;
474 if ( argc > 0 ) sscanf( *argv, "%lf", &rr ); else return TCL_ERROR;
475
476 argv++; argc--;
477 if ( argc > 0 ) sscanf( *argv, "%lf", &gg );
478
479 argv++; argc--;
480 if ( argc > 0 ) sscanf( *argv, "%lf", &bb );
481
482 if ( diffuse )
483 {
484 r = rr / 100.0;
485 g = gg / 100.0;
486 b = bb / 100.0;
487 } else
488 {
489 spec_r = rr / 100.0;
490 spec_g = gg / 100.0;
491 spec_b = bb / 100.0;
492 }
493 } else if ( strcmp( *argv, "shininess" ) == 0 )
494 {
495 argv++; argc--;
496 if ( argc ) { sscanf( *argv, "%lf", &shininess ); } else return TCL_ERROR;
497 }
498 }
499 }
500
501 mat->Changed = TRUE;
502
503 mat->Shininess = shininess;
504
505 mat->Diffuse[0] = r;
506 mat->Diffuse[1] = g;
507 mat->Diffuse[2] = b;
508 mat->Diffuse[3] = alpha;
509
510 mat->Specular[0] = spec_r;
511 mat->Specular[1] = spec_g;
512 mat->Specular[2] = spec_b;
513 mat->Specular[3] = alpha;
514 mat->Changed = TRUE;
515
516
517 UpdateObject();
518 DrawItSomeTimeWhenIdle();
519
520 return TCL_OK;
521 }
522
UpdateEdgeColor(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)523 static int UpdateEdgeColor(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
524 {
525 static int diffuse = FALSE;
526
527 static double r=1.,g=1.,b=1.,alpha=1.0,shininess=0.0,spec_r,spec_g,spec_b;
528
529 double rr,gg,bb;
530
531 while( argc )
532 {
533 argv++; argc--;
534 if ( argc )
535 {
536 if ( strcmp( *argv, "opacity" ) == 0 )
537 {
538 argv++; argc--;
539 if ( argc ) { sscanf( *argv, "%lf", &alpha ); alpha /= 100; } else return TCL_ERROR;
540 } else if ( strcmp( *argv, "color" ) == 0 )
541 {
542 argv++; argc--;
543 if ( argc <= 0 ) return TCL_ERROR;
544
545 diffuse = FALSE;
546 if ( strcmp( *argv,"diffuse" ) == 0 ) diffuse = TRUE;
547
548 argv++; argc--;
549 if ( argc > 0 ) sscanf( *argv, "%lf", &rr ); else return TCL_ERROR;
550
551 argv++; argc--;
552 if ( argc > 0 ) sscanf( *argv, "%lf", &gg );
553
554 argv++; argc--;
555 if ( argc > 0 ) sscanf( *argv, "%lf", &bb );
556
557 if ( diffuse )
558 {
559 r = rr / 100.0;
560 g = gg / 100.0;
561 b = bb / 100.0;
562 } else
563 {
564 spec_r = rr / 100.0;
565 spec_g = gg / 100.0;
566 spec_b = bb / 100.0;
567 }
568 } else if ( strcmp( *argv, "shininess" ) == 0 )
569 {
570 argv++; argc--;
571 if ( argc ) { sscanf( *argv, "%lf", &shininess ); } else return TCL_ERROR;
572 }
573 }
574 }
575
576 DefaultEdgeMaterial.Changed = TRUE;
577
578 DefaultEdgeMaterial.Shininess = shininess;
579
580 DefaultEdgeMaterial.Diffuse[0] = r;
581 DefaultEdgeMaterial.Diffuse[1] = g;
582 DefaultEdgeMaterial.Diffuse[2] = b;
583 DefaultEdgeMaterial.Diffuse[3] = alpha;
584
585 DefaultEdgeMaterial.Specular[0] = spec_r;
586 DefaultEdgeMaterial.Specular[1] = spec_g;
587 DefaultEdgeMaterial.Specular[2] = spec_b;
588 DefaultEdgeMaterial.Specular[3] = alpha;
589
590 DrawItSomeTimeWhenIdle();
591
592 return TCL_OK;
593 }
594
595
GetScalarVariable(scalar_t * Func,char * name,element_model_t * model,int TimeAll,int SetMinMax)596 static void GetScalarVariable( scalar_t *Func, char *name, element_model_t *model, int TimeAll, int SetMinMax )
597 {
598 char str[256];
599
600 VARIABLE *var;
601
602 double *T;
603
604 int len = strlen(name)-1, index = 0, n, t, i;
605
606 strcpy(str,name);
607
608 if ( str[len-1] == '_' )
609 {
610 index = str[len] - 'x';
611 str[len-1] = 0;
612 }
613
614 Func->f = NULL;
615
616 if ( !(var = (VARIABLE *)lst_find( VARIABLES, str ) ) ) return;
617
618 n = NCOL(var) % model->NofNodes;
619 t = NCOL(var) / model->NofNodes - 1;
620
621 if ( n || t < 0 ) return;
622
623 T = &M(var,index,0);
624 if ( TimeAll )
625 Func->f = T;
626 else
627 Func->f = &T[MIN(CurrentTimeStep,t)*model->NofNodes];
628
629 if ( !SetMinMax ) return;
630
631 Func->min = 1.0e20;
632 Func->max = -1.0e20;
633 for( i=0; i<NCOL(var); i++ )
634 {
635 Func->min = MIN( Func->min, T[i] );
636 Func->max = MAX( Func->max, T[i] );
637 }
638
639 if ( Func->name ) free( Func->name );
640 Func->name = (char *)malloc( len+2 );
641 strcpy( Func->name, name );
642 }
643
GetVectorVariable(scalar_t Func[4],char * name,element_model_t * model,int TimeAll)644 static void GetVectorVariable( scalar_t Func[4], char *name, element_model_t *model, int TimeAll )
645 {
646 VARIABLE *var;
647
648 double *T;
649
650 int i,n,t,index;
651 Func[0].f = Func[1].f =
652 Func[2].f = Func[3].f = NULL;
653
654 if ( !(var = (VARIABLE *)lst_find( VARIABLES, name ) ) ) return;
655
656 n = NCOL(var) % model->NofNodes;
657 t = NCOL(var) / model->NofNodes - 1;
658
659 if ( n || t < 0 ) return;
660
661 if ( TimeAll )
662 {
663 Func[1].f = &M(var,0,0);
664 Func[2].f = &M(var,1,0);
665 Func[3].f = &M(var,2,0);
666 } else
667 {
668 T = &M(var,0,0);
669 Func[1].f = &T[MIN(CurrentTimeStep,t)*model->NofNodes];
670
671 T = &M(var,1,0);
672 Func[2].f = &T[MIN(CurrentTimeStep,t)*model->NofNodes];
673
674 T = &M(var,2,0);
675 Func[3].f = &T[MIN(CurrentTimeStep,t)*model->NofNodes];
676 }
677
678 for( n=1; n<4; n++ )
679 {
680 Func[n].min = 1.0e20;
681 Func[n].max = -1.0e20;
682 for( i=0; i<NCOL(var); i++ )
683 {
684 Func[n].min = MIN( Func[n].min, M(var,n-1,i) );
685 Func[n].max = MAX( Func[n].max, M(var,n-1,i) );
686 }
687 }
688 }
689
GetParticleVariable(scalar_t Func[5],char * name)690 static void GetParticleVariable( scalar_t Func[5], char *name )
691 {
692 VARIABLE *var;
693
694 double *T;
695
696 int i,n,index;
697
698 var = (VARIABLE *)lst_find( VARIABLES, name );
699
700 Func[0].f =
701 Func[1].f =
702 Func[2].f =
703 Func[3].f =
704 Func[4].f = NULL;
705
706 if ( !var || NROW(var) != 5 ) return;
707
708 Func[0].f = &M(var,0,0);
709 Func[1].f = &M(var,1,0);
710 Func[2].f = &M(var,2,0);
711 Func[3].f = &M(var,3,0);
712 Func[4].f = &M(var,4,0);
713
714 ParticleNofParticles = NCOL(var);
715 }
716
717
UpdateVariable(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)718 static int UpdateVariable( ClientData cl,Tcl_Interp *interp,int argc,char **argv)
719 {
720 element_model_t *model = CurrentObject->ElementModel;
721
722 if ( !model ) return TCL_OK;
723
724 if ( strcmp( argv[1], "VectorColor") == 0 )
725
726 GetScalarVariable( &VectorColor, (char *)Tcl_GetVar( TCLInterp,argv[1],TCL_GLOBAL_ONLY ),model, 0, TRUE );
727
728 else if ( strcmp( argv[1], "VectorLength" ) == 0 )
729
730 GetScalarVariable( &VectorLength, (char *)Tcl_GetVar( TCLInterp,argv[1],TCL_GLOBAL_ONLY ),model, 0, TRUE );
731
732 else if ( strcmp( argv[1], "VectorThreshold" ) == 0 )
733
734 GetScalarVariable( &VectorThreshold, (char *)Tcl_GetVar( TCLInterp,argv[1],TCL_GLOBAL_ONLY ),model, 0, TRUE );
735
736 else if ( strcmp( argv[1], "MeshColor" ) == 0 )
737
738 GetScalarVariable( &MeshColor[CurrentObject->Id],
739 (char *)Tcl_GetVar( TCLInterp,argv[1],TCL_GLOBAL_ONLY ),model,0,!MeshColorSetMinMax );
740
741 else if ( strcmp( argv[1], "ColorScaleColor" ) == 0 )
742
743 GetScalarVariable( &ColorScaleColor, (char *)Tcl_GetVar( TCLInterp,argv[1],TCL_GLOBAL_ONLY ),model, 0, !ColorScaleColorSetMinMax );
744
745 else if ( strcmp( argv[1], "ContourColor" ) == 0 )
746
747 GetScalarVariable( &ContourColor[CurrentObject->Id],
748 (char *)Tcl_GetVar( TCLInterp,argv[1],TCL_GLOBAL_ONLY ),model, 0, !ContourColorSetMinMax );
749
750 else if ( strcmp( argv[1], "ContourContour" ) == 0 )
751
752 GetScalarVariable( &ContourContour[0], (char *)Tcl_GetVar( TCLInterp,argv[1],TCL_GLOBAL_ONLY ),model, 0, TRUE );
753
754 else if ( strcmp( argv[1], "IsosurfaceColor" ) == 0 )
755
756 GetScalarVariable( &IsosurfaceColor, (char *)Tcl_GetVar( TCLInterp,argv[1],TCL_GLOBAL_ONLY ),model, 0, !IsosurfaceColorSetMinMax );
757
758 else if ( strcmp( argv[1], "IsosurfaceContour" ) == 0 )
759
760 GetScalarVariable( &IsosurfaceContour, (char *)Tcl_GetVar( TCLInterp,argv[1],TCL_GLOBAL_ONLY ),model, 0, !IsosurfaceContourSetMinMax );
761
762 else if ( strcmp( argv[1], "ParticleColor" ) == 0 )
763
764 GetScalarVariable( &ParticleColor, (char *)Tcl_GetVar( TCLInterp,argv[1],TCL_GLOBAL_ONLY ),model, 0, TRUE );
765
766 else if ( strcmp( argv[1], "SphereThreshold" ) == 0 )
767
768 GetScalarVariable( &SphereThreshold, (char *)Tcl_GetVar( TCLInterp,argv[1],TCL_GLOBAL_ONLY ),model, 0, TRUE );
769
770 return TCL_OK;
771 }
772
773
TimeStep(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)774 static int TimeStep(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
775 {
776 double s;
777 static int n,i,j;
778
779 element_model_t *ElementModel = CurrentObject->ElementModel;
780
781 if ( argc != 2 )
782 {
783 sprintf( interp->result, "c_TimeStep: wrong number of parameters.\n" );
784 return TCL_ERROR;
785 }
786
787 if ( !ElementModel ) return TCL_OK;
788
789 n = 0;
790 sscanf( argv[1], "%d", &n );
791
792 if ( n < 0 || n >= ElementModel->NofTimesteps )
793 {
794 sprintf( interp->result, "c_TimeStep: Invalid timestep.\n" );
795 return TCL_ERROR;
796 }
797
798 CurrentTimeStep = n;
799
800 {
801 static vertex_t *vertex;
802
803 vertex = CurrentObject->Geometry->Vertices;
804
805 if ( !KeepScale ) {
806 xmin = ymin = zmin = 1.0e20;
807 xmax = ymax = zmax = -1.0e20;
808
809 for( i=0; i<CurrentObject->ElementModel->NofNodes; i++ )
810 {
811 xmin = MIN( xmin,ElementModel->NodeArray[i] );
812 ymin = MIN( ymin,ElementModel->NodeArray[ElementModel->NofNodes+i] );
813 zmin = MIN( zmin,ElementModel->NodeArray[2*ElementModel->NofNodes+i] );
814
815 xmax = MAX( xmax,ElementModel->NodeArray[i] );
816 ymax = MAX( ymax,ElementModel->NodeArray[ElementModel->NofNodes+i] );
817 zmax = MAX( zmax,ElementModel->NodeArray[2*ElementModel->NofNodes+i] );
818 }
819
820 s = MAX(MAX(xmax-xmin,ymax-ymin),zmax-zmin);
821
822 CurrentObject->Geometry->Scale = s;
823 CurrentObject->Geometry->MinMax[0].x[0] = xmin;
824 CurrentObject->Geometry->MinMax[0].x[1] = ymin;
825 CurrentObject->Geometry->MinMax[0].x[2] = zmin;
826
827 CurrentObject->Geometry->MinMax[1].x[0] = xmax;
828 CurrentObject->Geometry->MinMax[1].x[1] = ymax;
829 CurrentObject->Geometry->MinMax[1].x[2] = zmax;
830 } else {
831 s = CurrentObject->Geometry->Scale;
832 xmin = CurrentObject->Geometry->MinMax[0].x[0];
833 ymin = CurrentObject->Geometry->MinMax[0].x[1];
834 zmin = CurrentObject->Geometry->MinMax[0].x[2];
835
836 xmax = CurrentObject->Geometry->MinMax[1].x[0];
837 ymax = CurrentObject->Geometry->MinMax[1].x[1];
838 zmax = CurrentObject->Geometry->MinMax[1].x[2];
839 }
840
841 for( i=0; i<ElementModel->NofNodes; i++,vertex++ )
842 {
843 vertex->x[0] = (2.0 * (ElementModel->NodeArray[i]-xmin)-(xmax-xmin))/s;
844 vertex->x[1] = (2.0 * (ElementModel->NodeArray[ElementModel->NofNodes+i]-ymin)-(ymax-ymin)) / s;
845 vertex->x[2] = (2.0 * (ElementModel->NodeArray[2*ElementModel->NofNodes+i]-zmin)-(zmax-zmin)) / s;
846 }
847 }
848
849
850 /*
851 * DrawItSomeTimeWhenIdle();
852 * opengl_draw();
853 */
854
855 return TCL_OK;
856 }
857
cam_set_current(camera_t * camera)858 static void cam_set_current( camera_t *camera )
859 {
860 static char str[200];
861
862 Tcl_SetVar2( TCLInterp, "camera","name", camera->Name, TCL_GLOBAL_ONLY );
863
864 Tcl_SetVar2( TCLInterp, "camera","display", "on", TCL_GLOBAL_ONLY );
865
866 if ( camera->ProjectionType == camera_proj_ortho )
867 Tcl_SetVar2( TCLInterp, "camera","projection", "ortho",TCL_GLOBAL_ONLY );
868 else
869 Tcl_SetVar2( TCLInterp, "camera","projection", "perspective",TCL_GLOBAL_ONLY );
870
871 sprintf( str, "%g", camera->LookFromX );
872 Tcl_SetVar2( TCLInterp, "camera","from_x", str, TCL_GLOBAL_ONLY );
873
874 sprintf( str, "%g", camera->LookFromY );
875 Tcl_SetVar2( TCLInterp, "camera","from_y", str, TCL_GLOBAL_ONLY );
876
877 sprintf( str, "%g", camera->LookFromZ );
878 Tcl_SetVar2( TCLInterp, "camera","from_z", str, TCL_GLOBAL_ONLY );
879
880 sprintf( str, "%g", camera->LookAtX );
881 Tcl_SetVar2( TCLInterp, "camera","to_x", str, TCL_GLOBAL_ONLY );
882
883 sprintf( str, "%g", camera->LookAtY );
884 Tcl_SetVar2( TCLInterp, "camera", "to_y", str, TCL_GLOBAL_ONLY );
885
886 sprintf( str, "%g", camera->LookAtZ );
887 Tcl_SetVar2( TCLInterp, "camera","to_z", str, TCL_GLOBAL_ONLY );
888
889 sprintf( str, "%g", camera->UpX );
890 Tcl_SetVar2( TCLInterp, "camera","up_x", str, TCL_GLOBAL_ONLY );
891
892 sprintf( str, "%g", camera->UpY );
893 Tcl_SetVar2( TCLInterp, "camera","up_y", str, TCL_GLOBAL_ONLY );
894
895 sprintf( str, "%g", camera->UpZ );
896 Tcl_SetVar2( TCLInterp, "camera","up_z", str, TCL_GLOBAL_ONLY );
897
898 sprintf( str, "%g", camera->FieldAngle );
899 Tcl_SetVar2( TCLInterp, "camera","field_angle", str, TCL_GLOBAL_ONLY );
900
901 sprintf( str, "%g", camera->ClipNear );
902 Tcl_SetVar2( TCLInterp, "camera","near", str, TCL_GLOBAL_ONLY );
903
904 sprintf( str, "%g", camera->ClipFar );
905 Tcl_SetVar2( TCLInterp, "camera","far", str, TCL_GLOBAL_ONLY );
906
907 sprintf( str, "%g", camera->ViewportLowX );
908 Tcl_SetVar2( TCLInterp, "camera","view_low_x", str, TCL_GLOBAL_ONLY );
909
910 sprintf( str, "%g", camera->ViewportLowY );
911 Tcl_SetVar2( TCLInterp, "camera","view_low_y", str, TCL_GLOBAL_ONLY );
912
913 sprintf( str, "%g", camera->ViewportHighX );
914 Tcl_SetVar2( TCLInterp, "camera","view_high_x", str, TCL_GLOBAL_ONLY );
915
916 sprintf( str, "%g", camera->ViewportHighY );
917 Tcl_SetVar2( TCLInterp, "camera","view_high_y", str, TCL_GLOBAL_ONLY );
918 }
919
920 /*******************************************************************************
921 *
922 * Name: cam_load_cameras
923 *
924 * Purpose: Initialize camerass from default cam setting file
925 *
926 * Parameters:
927 *
928 * Input: none
929 *
930 * Output: none
931 *
932 * Return value: New list of (camera_t *)cameras
933 *
934 *******************************************************************************/
cam_load_cameras(camera_t * camera,char * FileName)935 static camera_t *cam_load_cameras( camera_t *camera,char *FileName )
936 {
937 static char name[200],str[200],variable[64],value[64];
938 FILE *fp = NULL;
939
940 int i;
941
942 float x,y,z,w;
943
944 camera_t *first_cam = camera;
945
946 if ( !FileName || !(fp = fopen( FileName,"r") ) )
947 {
948 sprintf( name, "%s/lib/cameras/default", getenv("ELMER_POST_HOME") );
949
950 if ( !(fp = fopen( name, "r" ) ) )
951 {
952 camera = (camera_t *)cam_add_camera( NULL, "camera1" );
953 if ( !first_cam ) first_cam = camera;
954
955 cam_set_viewport( camera,0.0,0.0,1.0,1.0 );
956 cam_set_look_to( camera,0.0,0.0,0.0,FALSE );
957 cam_set_up_vector( camera,0.0,1.0,0.0 );
958 cam_set_look_from( camera,0.0,0.0,5.0,FALSE );
959 cam_set_clip( camera,1.0,20.0 );
960 cam_set_onoff( camera, TRUE );
961 }
962 }
963
964
965 if ( fp ) {
966 while( fgets( str,100, fp ) )
967 {
968 if ( sscanf( str, "camera %s", name ) == 1 )
969 {
970 camera = (camera_t *)cam_add_camera( camera, name );
971 if ( !first_cam ) first_cam = camera;
972 cam_set_onoff( camera, TRUE );
973 } else if ( sscanf( str, "from %f %f %f", &x,&y,&z ) == 3 )
974 {
975 cam_set_look_from( camera,x,y,z,FALSE );
976
977 } else if ( sscanf( str, "to %f %f %f", &x,&y,&z ) == 3)
978 {
979 cam_set_look_to( camera,x,y,z,FALSE );
980
981 } else if ( sscanf( str, "viewport %f %f %f %f", &x,&y,&z,&w ) == 4 )
982 {
983 cam_set_viewport( camera,x,y,z,w );
984
985 } else if ( sscanf( str, "up %f %f %f", &x, &y, &z ) == 3 )
986 {
987 cam_set_up_vector( camera, x,y,z );
988
989 } else if ( sscanf( str, "projection %s", name ) == 1 )
990 {
991 if ( strcmp( name,"perspective" ) == 0 )
992 cam_set_projection( camera, camera_proj_perspective );
993 else
994 cam_set_projection( camera, camera_proj_ortho );
995 } else if ( sscanf( str, "field angle %f", &x ) == 1 )
996 {
997 cam_set_field_angle( camera, x );
998 } else if ( sscanf( str, "clip %f %f", &x, &y ) == 2 )
999 {
1000 cam_set_clip( camera,x,y );
1001 }
1002 }
1003 }
1004
1005 if ( camera ) cam_set_current( camera );
1006
1007 if ( fp )
1008 {
1009 fclose( fp );
1010 }
1011
1012 i = 0;
1013 for( camera=first_cam; camera != NULL; camera=camera->Next,i++ )
1014 {
1015 sprintf( str, "%d", i );
1016 Tcl_SetVar2( TCLInterp, "camera_names",str, camera->Name, TCL_GLOBAL_ONLY );
1017 }
1018 sprintf( str, "%d", i );
1019 Tcl_SetVar( TCLInterp, "camera_n", str, TCL_GLOBAL_ONLY );
1020
1021 return first_cam;
1022 }
1023
1024
CurrentCamera(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)1025 static int CurrentCamera(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
1026 {
1027 camera_t *cam;
1028 int i;
1029
1030 if ( argc != 2 )
1031 {
1032 sprintf( interp->result, "camera: wrong number of arguments\n" );
1033 return TCL_ERROR;
1034 }
1035
1036 i = 0;
1037 for( cam=Camera; cam!=NULL; cam=cam->Next,i++ )
1038 {
1039 if ( strcmp( cam->Name, argv[1] ) == 0 )
1040 {
1041 cam_set_current( cam );
1042 sprintf( interp->result, "%d", i );
1043 return TCL_OK;
1044 }
1045 }
1046
1047 return TCL_ERROR;
1048 }
1049
1050
SetCamera(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)1051 static int SetCamera(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
1052 {
1053 static char str[200];
1054
1055 float x,y,z,w;
1056
1057 camera_t *camera = NULL;
1058
1059 camera = (camera_t *)cam_add_camera( Camera,
1060 (char *)Tcl_GetVar2( TCLInterp,"camera","name", TCL_GLOBAL_ONLY ) );
1061
1062 if ( camera ) {
1063 sscanf( Tcl_GetVar2( TCLInterp, "camera","display", TCL_GLOBAL_ONLY ), "%s", str );
1064 if ( strcmp( str, "off" ) == 0 )
1065 cam_set_onoff( camera, FALSE );
1066 else
1067 cam_set_onoff( camera, TRUE );
1068
1069 sscanf( Tcl_GetVar2( TCLInterp, "camera","from_x", TCL_GLOBAL_ONLY ), "%f", &x );
1070 sscanf( Tcl_GetVar2( TCLInterp, "camera","from_y", TCL_GLOBAL_ONLY ), "%f", &y );
1071 sscanf( Tcl_GetVar2( TCLInterp, "camera","from_z", TCL_GLOBAL_ONLY ), "%f", &z );
1072 cam_set_look_from( camera,x,y,z,FALSE );
1073
1074 sscanf( Tcl_GetVar2( TCLInterp, "camera","to_x", TCL_GLOBAL_ONLY ), "%f", &x );
1075 sscanf( Tcl_GetVar2( TCLInterp, "camera","to_y", TCL_GLOBAL_ONLY ), "%f", &y );
1076 sscanf( Tcl_GetVar2( TCLInterp, "camera","to_z", TCL_GLOBAL_ONLY ), "%f", &z );
1077 cam_set_look_to( camera,x,y,z,FALSE );
1078
1079 sscanf( Tcl_GetVar2( TCLInterp, "camera","up_x", TCL_GLOBAL_ONLY ), "%f", &x );
1080 sscanf( Tcl_GetVar2( TCLInterp, "camera","up_y", TCL_GLOBAL_ONLY ), "%f", &y );
1081 sscanf( Tcl_GetVar2( TCLInterp, "camera","up_z", TCL_GLOBAL_ONLY ), "%f", &z );
1082 cam_set_up_vector( camera,x,y,z );
1083
1084 sscanf( Tcl_GetVar2( TCLInterp, "camera","view_low_x", TCL_GLOBAL_ONLY ), "%f", &x );
1085 sscanf( Tcl_GetVar2( TCLInterp, "camera","view_low_y", TCL_GLOBAL_ONLY ), "%f", &y );
1086 sscanf( Tcl_GetVar2( TCLInterp, "camera","view_high_x", TCL_GLOBAL_ONLY ), "%f", &z );
1087 sscanf( Tcl_GetVar2( TCLInterp, "camera","view_high_y", TCL_GLOBAL_ONLY ), "%f", &w );
1088 cam_set_viewport( camera,x,y,z,w );
1089
1090 sscanf( Tcl_GetVar2( TCLInterp,"camera","projection", TCL_GLOBAL_ONLY ), "%s", str );
1091 if ( strcmp( str,"perspective" ) == 0 )
1092 cam_set_projection( camera, camera_proj_perspective );
1093 else
1094 cam_set_projection( camera, camera_proj_ortho );
1095
1096 sscanf( Tcl_GetVar2( TCLInterp,"camera","field_angle", TCL_GLOBAL_ONLY ), "%f", &x );
1097 cam_set_field_angle( camera, x );
1098
1099 sscanf( Tcl_GetVar2( TCLInterp,"camera","near", TCL_GLOBAL_ONLY ), "%f", &x );
1100 sscanf( Tcl_GetVar2( TCLInterp,"camera","far", TCL_GLOBAL_ONLY ), "%f", &y );
1101 cam_set_clip( camera, x,y );
1102 }
1103
1104 DrawItSomeTimeWhenIdle();
1105
1106 return TCL_OK;
1107 }
1108
1109
LoadCamera(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)1110 static int LoadCamera(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
1111 {
1112 if ( argc != 2 )
1113 {
1114 fprintf( stderr, "camera: wrong number of arguments\n" );
1115 return TCL_ERROR;
1116 }
1117
1118 cam_delete_list( Camera );
1119 Camera = (camera_t *)cam_load_cameras( NULL,argv[1] );
1120
1121 DrawItSomeTimeWhenIdle();
1122
1123 return TCL_OK;
1124 }
1125
GroupDisplay(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)1126 static int GroupDisplay(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
1127 {
1128 int i,gid,groupid;
1129 group_t *group;
1130
1131 if ( argc > 1 )
1132 {
1133 if ( strcmp( argv[2],"on" ) == 0 )
1134 {
1135 for( group=CurrentObject->ElementModel->Groups; group!=NULL; group=group->Next )
1136 if ( strcmp( argv[1],group->Name ) == 0 ) {
1137 group->status = 1;
1138 break;
1139 }
1140 } else {
1141 for( group=CurrentObject->ElementModel->Groups; group!=NULL; group=group->Next )
1142 if ( strcmp( argv[1],group->Name ) == 0 ) {
1143 group->status = 0;
1144 break;
1145 }
1146
1147 }
1148 }
1149
1150 for( i=0; i<CurrentObject->ElementModel->NofElements; i++ )
1151 {
1152 CurrentObject->ElementModel->Elements[i].DisplayFlag = FALSE;
1153 for ( gid=0; gid<MAX_GROUP_IDS; gid++ )
1154 {
1155 groupid = 0;
1156 for( group=CurrentObject->ElementModel->Groups; group!=NULL; group=group->Next,groupid++ )
1157 if ( groupid==CurrentObject->ElementModel->Elements[i].GroupIds[gid] ) break;
1158
1159 if ( group ) CurrentObject->ElementModel->Elements[i].DisplayFlag |= group->status;
1160 }
1161 }
1162
1163 return TCL_OK;
1164 }
1165
1166 char *mtc_domath( char * );
1167
MathCommand(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)1168 static int MathCommand(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
1169 {
1170 VARIABLE *var;
1171 LIST *lst;
1172
1173 static char name[256],value[256],*result;
1174
1175 int i,j,k,NodesChanged;
1176
1177 element_model_t *ElementModel = CurrentObject->ElementModel;
1178
1179 /*
1180 * do the given math command first ...
1181 *
1182 */
1183 var_reset_status( "nodes" );
1184
1185 result = (char *)mtc_domath( argv[1] );
1186
1187 NodesChanged = var_get_status( "nodes" );
1188
1189
1190 /*
1191 * then check the variables which are good for then
1192 * element model...
1193 *
1194 */
1195 if ( result && strncmp( result, "MATC ERROR: ", 12 ) == 0 )
1196 {
1197 Tcl_SetResult( interp, result, TCL_STATIC );
1198 return TCL_ERROR;
1199 }
1200
1201
1202 /*
1203 * if empty list return.
1204 */
1205 if ( listheaders[VARIABLES].next == (LIST *)NULL )
1206 {
1207 Tcl_SetResult( interp, result, TCL_STATIC );
1208 return TCL_OK;
1209 }
1210
1211 i = j = k = 0;
1212 for( lst = listheaders[VARIABLES].next; lst; lst = NEXT(lst))
1213 {
1214 var = (VARIABLE *)lst;
1215 if ( !NAME(var)) continue;
1216
1217 if ( NROW(var) == 5 )
1218 {
1219 sprintf( name, "%d", k++ );
1220 sprintf( value, "%s", NAME(var) );
1221 Tcl_SetVar2( TCLInterp,"ParticleVariableNames", name, value, TCL_GLOBAL_ONLY );
1222 }
1223
1224 if ( !ElementModel ) continue;
1225
1226 if ( NROW(var) == 3 )
1227 {
1228 if ( !(NCOL(var) % ElementModel->NofNodes) )
1229 {
1230 sprintf( name, "%d", i++ );
1231 sprintf( value, "%s_x", NAME(var) );
1232 Tcl_SetVar2( TCLInterp, "ScalarVariableNames", name, value, TCL_GLOBAL_ONLY );
1233
1234 sprintf( name, "%d", i++ );
1235 sprintf( value, "%s_y", NAME(var) );
1236 Tcl_SetVar2( TCLInterp, "ScalarVariableNames", name, value, TCL_GLOBAL_ONLY );
1237
1238 sprintf( name, "%d", i++ );
1239 sprintf( value, "%s_z", NAME(var) );
1240 Tcl_SetVar2( TCLInterp, "ScalarVariableNames", name, value, TCL_GLOBAL_ONLY );
1241
1242 sprintf( name, "%d", j++ );
1243 sprintf( value, "%s", NAME(var) );
1244 Tcl_SetVar2( TCLInterp, "VectorVariableNames", name, value, TCL_GLOBAL_ONLY );
1245 }
1246 }
1247 else if ( NROW(var) == 1 && !(NCOL(var) % ElementModel->NofNodes) )
1248 {
1249 sprintf( name, "%d", i++ );
1250 Tcl_SetVar2( TCLInterp, "ScalarVariableNames", name, NAME(var), TCL_GLOBAL_ONLY );
1251 }
1252 }
1253
1254
1255 NumberOfScalarVariables = i;
1256 NumberOfVectorVariables = j;
1257 NumberOfParticleVariables = k;
1258
1259
1260 /*
1261 * check if scaling required...
1262 */
1263 if ( ElementModel && NodesChanged )
1264 {
1265 static vertex_t *vertex;
1266 static double s;
1267
1268 vertex = CurrentObject->Geometry->Vertices;
1269
1270 if ( !KeepScale )
1271 {
1272 xmin = ymin = zmin = 1.0e20;
1273 xmax = ymax = zmax = -1.0e20;
1274
1275 for( i=0; i<ElementModel->NofNodes; i++ )
1276 {
1277 xmin = MIN( xmin,ElementModel->NodeArray[i] );
1278 ymin = MIN( ymin,ElementModel->NodeArray[ElementModel->NofNodes+i] );
1279 zmin = MIN( zmin,ElementModel->NodeArray[2*ElementModel->NofNodes+i] );
1280
1281 xmax = MAX( xmax,ElementModel->NodeArray[i] );
1282 ymax = MAX( ymax,ElementModel->NodeArray[ElementModel->NofNodes+i] );
1283 zmax = MAX( zmax,ElementModel->NodeArray[2*ElementModel->NofNodes+i] );
1284 }
1285 s = MAX(MAX(xmax-xmin,ymax-ymin),zmax-zmin);
1286
1287 CurrentObject->Geometry->Scale = s;
1288 CurrentObject->Geometry->MinMax[0].x[0] = xmin;
1289 CurrentObject->Geometry->MinMax[0].x[1] = ymin;
1290 CurrentObject->Geometry->MinMax[0].x[2] = zmin;
1291
1292 CurrentObject->Geometry->MinMax[1].x[0] = xmax;
1293 CurrentObject->Geometry->MinMax[1].x[1] = ymax;
1294 CurrentObject->Geometry->MinMax[1].x[2] = zmax;
1295
1296 } else {
1297 s = CurrentObject->Geometry->Scale;
1298 xmin = CurrentObject->Geometry->MinMax[0].x[0];
1299 ymin = CurrentObject->Geometry->MinMax[0].x[1];
1300 zmin = CurrentObject->Geometry->MinMax[0].x[2];
1301
1302 xmax = CurrentObject->Geometry->MinMax[1].x[0];
1303 ymax = CurrentObject->Geometry->MinMax[1].x[1];
1304 zmax = CurrentObject->Geometry->MinMax[1].x[2];
1305 }
1306
1307 for( i=0; i<CurrentObject->ElementModel->NofNodes; i++,vertex++ )
1308 {
1309 vertex->x[0] = (2.0 * (ElementModel->NodeArray[i] - xmin) - (xmax-xmin)) / s;
1310 vertex->x[1] = (2.0 * (ElementModel->NodeArray[ElementModel->NofNodes+i] - ymin) - (ymax-ymin)) / s;
1311 vertex->x[2] = (2.0 * (ElementModel->NodeArray[2*ElementModel->NofNodes+i] - zmin) - (zmax-zmin)) / s;
1312 }
1313
1314 if ( NormalUpdate ) geo_vertex_normals( CurrentObject->Geometry,50.0 );
1315 }
1316
1317
1318 Tcl_SetResult( interp, result, TCL_STATIC );
1319 return TCL_OK;
1320 }
1321
1322 #ifndef MINGW32
1323 #include <GL/glx.h>
1324 #else
1325 #include <winuser.h>
1326 #endif
1327 #include <X11/Xlib.h>
1328 #include <X11/Xutil.h>
1329
1330 static unsigned int FontBase;
1331
tkXDisplay()1332 Display *tkXDisplay()
1333 {
1334 Display *ptr = NULL;
1335 #ifndef MINGW32
1336 ptr = auxXDisplay();
1337 #endif
1338 return ptr;
1339 }
1340
tkXWindow()1341 Window tkXWindow()
1342 {
1343 Window ptr = 0;
1344
1345 #ifdef MINGW32
1346 ptr = auxGetHWND();
1347 #else
1348 ptr = auxXWindow();
1349 #endif
1350
1351 return ptr;
1352 }
1353
1354
ActivateGraphicsWindow(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)1355 static int ActivateGraphicsWindow( ClientData cl,Tcl_Interp *interp,int argc,char **argv )
1356 {
1357 #ifdef MINGW32
1358 ShowWindow( tkXWindow(), SW_SHOWNORMAL );
1359 #endif
1360 return TCL_OK;
1361 }
1362
1363
1364
1365
1366 static GLubyte rasterFont[][13] = {
1367 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1368 {0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
1369 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36},
1370 {0x00, 0x00, 0x00, 0x66, 0x66, 0xff, 0x66, 0x66, 0xff, 0x66, 0x66, 0x00, 0x00},
1371 {0x00, 0x00, 0x18, 0x7e, 0xff, 0x1b, 0x1f, 0x7e, 0xf8, 0xd8, 0xff, 0x7e, 0x18},
1372 {0x00, 0x00, 0x0e, 0x1b, 0xdb, 0x6e, 0x30, 0x18, 0x0c, 0x76, 0xdb, 0xd8, 0x70},
1373 {0x00, 0x00, 0x7f, 0xc6, 0xcf, 0xd8, 0x70, 0x70, 0xd8, 0xcc, 0xcc, 0x6c, 0x38},
1374 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1c, 0x0c, 0x0e},
1375
1376 {0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c},
1377 {0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30},
1378 {0x00, 0x00, 0x00, 0x00, 0x99, 0x5a, 0x3c, 0xff, 0x3c, 0x5a, 0x99, 0x00, 0x00},
1379 {0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0x18, 0x00, 0x00},
1380 {0x00, 0x00, 0x30, 0x18, 0x1c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1381 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00},
1382 {0x00, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1383 {0x00, 0x60, 0x60, 0x30, 0x30, 0x18, 0x18, 0x0c, 0x0c, 0x06, 0x06, 0x03, 0x03},
1384 {0x00, 0x00, 0x3c, 0x66, 0xc3, 0xe3, 0xf3, 0xdb, 0xcf, 0xc7, 0xc3, 0x66, 0x3c},
1385 {0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x38, 0x18},
1386 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0xe7, 0x7e},
1387 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0x07, 0x03, 0x03, 0xe7, 0x7e},
1388 {0x00, 0x00, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xff, 0xcc, 0x6c, 0x3c, 0x1c, 0x0c},
1389 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0xff},
1390 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
1391 {0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x03, 0x03, 0xff},
1392 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e},
1393 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x03, 0x7f, 0xe7, 0xc3, 0xc3, 0xe7, 0x7e},
1394 {0x00, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00},
1395 {0x00, 0x00, 0x30, 0x18, 0x1c, 0x1c, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x00},
1396 {0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06},
1397 {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00},
1398 {0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60},
1399 {0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x18, 0x0c, 0x06, 0x03, 0xc3, 0xc3, 0x7e},
1400 {0x00, 0x00, 0x3f, 0x60, 0xcf, 0xdb, 0xd3, 0xdd, 0xc3, 0x7e, 0x00, 0x00, 0x00},
1401 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18},
1402 {0x00, 0x00, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
1403 {0x00, 0x00, 0x7e, 0xe7, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
1404 {0x00, 0x00, 0xfc, 0xce, 0xc7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc7, 0xce, 0xfc},
1405 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xff},
1406 {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xff},
1407 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xcf, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
1408 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
1409 {0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e},
1410 {0x00, 0x00, 0x7c, 0xee, 0xc6, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06},
1411 {0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xe0, 0xf0, 0xd8, 0xcc, 0xc6, 0xc3},
1412 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0},
1413 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xdb, 0xff, 0xff, 0xe7, 0xc3},
1414 {0x00, 0x00, 0xc7, 0xc7, 0xcf, 0xcf, 0xdf, 0xdb, 0xfb, 0xf3, 0xf3, 0xe3, 0xe3},
1415 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xe7, 0x7e},
1416 {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
1417 {0x00, 0x00, 0x3f, 0x6e, 0xdf, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c},
1418 {0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
1419 {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0xe0, 0xc0, 0xc0, 0xe7, 0x7e},
1420 {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff},
1421 {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
1422 {0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
1423 {0x00, 0x00, 0xc3, 0xe7, 0xff, 0xff, 0xdb, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
1424 {0x00, 0x00, 0xc3, 0x66, 0x66, 0x3c, 0x3c, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
1425 {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
1426 {0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x7e, 0x0c, 0x06, 0x03, 0x03, 0xff},
1427 {0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c},
1428 {0x00, 0x03, 0x03, 0x06, 0x06, 0x0c, 0x0c, 0x18, 0x18, 0x30, 0x30, 0x60, 0x60},
1429 {0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c},
1430 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18},
1431 {0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1432 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x30, 0x70},
1433 {0x00, 0x00, 0x7f, 0xc3, 0xc3, 0x7f, 0x03, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
1434 {0x00, 0x00, 0xfe, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0},
1435 {0x00, 0x00, 0x7e, 0xc3, 0xc0, 0xc0, 0xc0, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
1436 {0x00, 0x00, 0x7f, 0xc3, 0xc3, 0xc3, 0xc3, 0x7f, 0x03, 0x03, 0x03, 0x03, 0x03},
1437 {0x00, 0x00, 0x7f, 0xc0, 0xc0, 0xfe, 0xc3, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
1438 {0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x33, 0x1e},
1439 {0x7e, 0xc3, 0x03, 0x03, 0x7f, 0xc3, 0xc3, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00},
1440 {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0},
1441 {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x18, 0x00},
1442 {0x38, 0x6c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x00, 0x00, 0x0c, 0x00},
1443 {0x00, 0x00, 0xc6, 0xcc, 0xf8, 0xf0, 0xd8, 0xcc, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0},
1444 {0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78},
1445 {0x00, 0x00, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0xfe, 0x00, 0x00, 0x00, 0x00},
1446 {0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xfc, 0x00, 0x00, 0x00, 0x00},
1447 {0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00},
1448 {0xc0, 0xc0, 0xc0, 0xfe, 0xc3, 0xc3, 0xc3, 0xc3, 0xfe, 0x00, 0x00, 0x00, 0x00},
1449 {0x03, 0x03, 0x03, 0x7f, 0xc3, 0xc3, 0xc3, 0xc3, 0x7f, 0x00, 0x00, 0x00, 0x00},
1450 {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe0, 0xfe, 0x00, 0x00, 0x00, 0x00},
1451 {0x00, 0x00, 0xfe, 0x03, 0x03, 0x7e, 0xc0, 0xc0, 0x7f, 0x00, 0x00, 0x00, 0x00},
1452 {0x00, 0x00, 0x1c, 0x36, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x00},
1453 {0x00, 0x00, 0x7e, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00},
1454 {0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00},
1455 {0x00, 0x00, 0xc3, 0xe7, 0xff, 0xdb, 0xc3, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00},
1456 {0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00},
1457 {0xc0, 0x60, 0x60, 0x30, 0x18, 0x3c, 0x66, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00},
1458 {0x00, 0x00, 0xff, 0x60, 0x30, 0x18, 0x0c, 0x06, 0xff, 0x00, 0x00, 0x00, 0x00},
1459 {0x00, 0x00, 0x0f, 0x18, 0x18, 0x18, 0x38, 0xf0, 0x38, 0x18, 0x18, 0x18, 0x0f},
1460 {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
1461 {0x00, 0x00, 0xf0, 0x18, 0x18, 0x18, 0x1c, 0x0f, 0x1c, 0x18, 0x18, 0x18, 0xf0},
1462 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x8f, 0xf1, 0x60, 0x00, 0x00, 0x00}
1463 };
1464
MakeRasterFontDefault()1465 void MakeRasterFontDefault()
1466 {
1467 GLuint i;
1468
1469 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1470
1471 FontBase = glGenLists(128);
1472 for (i = 32; i < 127; i++) {
1473 glNewList( i+FontBase, GL_COMPILE );
1474 glBitmap( 8, 13, 0.0f, 2.0f, 10.0f, 0.0f, rasterFont[i-32] );
1475 glEndList();
1476 }
1477 }
1478
1479
1480 #ifndef MINGW32
1481
InitializeXFonts()1482 void InitializeXFonts()
1483 {
1484 static char str[32], here = 0;
1485 int i,n;
1486 char **FontNames;
1487
1488 FontNames = XListFonts( tkXDisplay(), "*", 10000, &n );
1489
1490 for( i=0; i<n; i++ )
1491 {
1492 sprintf( str, "%d", i );
1493 Tcl_SetVar2( TCLInterp, "FontNames", str,FontNames[i], TCL_GLOBAL_ONLY );
1494 }
1495
1496 sprintf( str, "%d", i );
1497 Tcl_SetVar( TCLInterp, "NumberOfFonts", str, TCL_GLOBAL_ONLY );
1498
1499 MakeRasterFontDefault();
1500 }
1501
1502
MakeRasterFont(char * name)1503 void MakeRasterFont( char *name )
1504 {
1505 unsigned int first, last;
1506
1507 XFontStruct *fontInfo;
1508 static char str[32], here = 0;
1509
1510 CurrentXFont = fontInfo = XLoadQueryFont( tkXDisplay(),name );
1511 fprintf( stdout, "Font: [%s] %x\n", name, CurrentXFont );
1512 if ( fontInfo == NULL )
1513 {
1514 fprintf( stderr, "Can not find font: [%s]\n", name );
1515 return;
1516 }
1517
1518 first = fontInfo->min_char_or_byte2;
1519 last = fontInfo->max_char_or_byte2;
1520 ColorScaleFontSize = fontInfo->max_bounds.rbearing - fontInfo->min_bounds.lbearing;
1521
1522 FontBase = glGenLists( last + 1 );
1523 glXUseXFont( fontInfo->fid,first,last-first+1,FontBase+first );
1524 }
1525 #endif
1526
PrintString(char * s)1527 void PrintString( char *s )
1528 {
1529 double param[4],rgba[4];
1530 if ( GlobalOptions.OutputPS ) {
1531 glGetDoublev( GL_CURRENT_COLOR, rgba );
1532 glGetDoublev( GL_CURRENT_RASTER_POSITION, param );
1533 OutputPSString( param[0],param[1],ColorScaleFontSize, rgba[0],rgba[1],rgba[2], s );
1534 } else {
1535 glDisable( GL_LIGHTING );
1536 glDisable( GL_TEXTURE_1D );
1537 glPushAttrib( GL_LIST_BIT );
1538 glListBase( FontBase );
1539 glCallLists( strlen(s),GL_UNSIGNED_BYTE,(unsigned char *)s );
1540 glPopAttrib();
1541 glEnable( GL_TEXTURE_1D );
1542 glEnable( GL_LIGHTING );
1543 }
1544 }
1545
ShowString(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)1546 static int ShowString( ClientData cl,Tcl_Interp *interp,int argc,char **argv )
1547 {
1548 float x,y,z;
1549
1550 if ( argc < 5 )
1551 {
1552 sprintf( interp->result, "string: Wrong number of arguments.\n" );
1553 return TCL_ERROR;
1554 }
1555
1556 glMatrixMode( GL_PROJECTION );
1557 glLoadIdentity();
1558
1559 glMatrixMode( GL_MODELVIEW );
1560 glPushMatrix();
1561 glLoadIdentity();
1562
1563 glDisable( GL_TEXTURE_1D );
1564 glDisable( GL_DEPTH_TEST );
1565 glDrawBuffer( GL_FRONT_AND_BACK );
1566
1567 glColor3f( 1.0,1.0,1.0 );
1568
1569 x = atof( argv[1] );
1570 y = atof( argv[2] );
1571 z = atof( argv[3] );
1572
1573 glRasterPos3f( x,y,z );
1574
1575 // if ( argc >= 6 ) MakeRasterFont( argv[5] );
1576 PrintString( argv[4] );
1577
1578 glPopMatrix();
1579
1580 epSwapBuffers();
1581
1582 return TCL_OK;
1583 }
1584
1585
SetFont(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)1586 static int SetFont( ClientData cl,Tcl_Interp *interp,int argc,char **argv )
1587 {
1588 int i;
1589 if ( argc < 1 )
1590 {
1591 sprintf( interp->result, "Set font: Wrong number of arguments.\n" );
1592 return TCL_ERROR;
1593 }
1594
1595 #ifdef MINGW32
1596 MakeRasterFontDefault();
1597 #else
1598 MakeRasterFont( argv[1] );
1599 #endif
1600
1601 return TCL_OK;
1602 }
1603
1604
UpdateObject(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)1605 int UpdateObject( ClientData cl,Tcl_Interp *interp,int argc,char **argv)
1606 {
1607 static double L[1024],I[256];
1608 int i;
1609
1610 element_model_t *model;
1611
1612 char *str;
1613
1614 model = CurrentObject->ElementModel;
1615 if ( !model ) return TCL_OK;
1616
1617 vis_delete_visual( CurrentObject->VisualList );
1618 CurrentObject->VisualList = NULL;
1619
1620 if ( ShowMeshLines )
1621 {
1622 visual_t *VL = NULL;
1623
1624 if ( !VL )
1625 {
1626 VL = (visual_t *)vis_new_visual( "Mesh" );
1627 } else VL->Next = NULL;
1628 CurrentObject->VisualList = (visual_t *)vis_link_visual( CurrentObject->VisualList,VL );
1629
1630 vis_set_param( VL, "ColorMap", 0, 0.0, MeshColorMap );
1631 vis_set_param( VL, "Material", 0, 0.0, MeshMaterial );
1632 vis_set_param( VL, "ColorData", 0, 0.0, NULL );
1633 vis_set_param( VL, "Style", mesh_style_line, 0.0, NULL );
1634 vis_set_param( VL, "LineStyle", line_style_line, 0.0, NULL );
1635 vis_set_param( VL, "LineQuality", 1, 0.0, NULL );
1636 vis_set_param( VL, "EdgeStyle", edge_style_all, 0.0, NULL );
1637 }
1638
1639 if ( ShowParticles )
1640 {
1641 visual_t *VL = CurrentObject->VisualList;
1642
1643 if ( !VL )
1644 {
1645 VL = (visual_t *)vis_new_visual( "Particles" );
1646
1647 } else VL->Next = NULL;
1648 CurrentObject->VisualList = (visual_t *)vis_link_visual( CurrentObject->VisualList,VL );
1649
1650 GetScalarVariable( &ParticleColor, (char *)Tcl_GetVar( TCLInterp,
1651 "ParticleColor",TCL_GLOBAL_ONLY ), model, 1, TRUE );
1652 GetVectorVariable( ParticleVelocity, (char *)Tcl_GetVar( TCLInterp,
1653 "ParticleVelocity",TCL_GLOBAL_ONLY ),model, 1 );
1654 GetParticleVariable( ParticleParticle, (char *)Tcl_GetVar( TCLInterp,
1655 "ParticleParticle",TCL_GLOBAL_ONLY ) );
1656
1657 vis_set_param( VL, "Style", ParticleStyle, 0.0, NULL );
1658
1659 vis_set_param( VL, "VectorData1", 0, 0.0, &ParticleVelocity[1] );
1660 vis_set_param( VL, "VectorData2", 0, 0.0, &ParticleVelocity[2] );
1661 vis_set_param( VL, "VectorData3", 0, 0.0, &ParticleVelocity[3] );
1662
1663 vis_set_param( VL, "ParticleDataX", 0, 0.0, &ParticleParticle[0] );
1664 vis_set_param( VL, "ParticleDataY", 0, 0.0, &ParticleParticle[1] );
1665 vis_set_param( VL, "ParticleDataZ", 0, 0.0, &ParticleParticle[2] );
1666 vis_set_param( VL, "ParticleDataC", 0, 0.0, &ParticleParticle[3] );
1667 vis_set_param( VL, "ParticleDataI", 0, 0.0, &ParticleParticle[4] );
1668
1669 vis_set_param( VL, "ColorData", 0, 0.0, &ParticleColor );
1670
1671 vis_set_param( VL, "LineStyle", ParticleLineStyle, 0.0, NULL );
1672 vis_set_param( VL, "LineQuality", ParticleQuality, 0.0, NULL );
1673 vis_set_param( VL, "LineWidth", 0, ParticleRadius, NULL );
1674 vis_set_param( VL, "ArrowStyle", ParticleArrowStyle, 0.0, NULL );
1675 vis_set_param( VL, "OutDT", 0, ParticleOutDT, NULL );
1676 vis_set_param( VL, "MaxDT", 0, ParticleMaxDT, NULL );
1677 vis_set_param( VL, "Tolerance", 0, ParticleTolerance, NULL );
1678 vis_set_param( VL, "NofParticles", ParticleNofParticles, 0.0, NULL );
1679 vis_set_param( VL, "ColorMap", 0, 0.0, ParticleColorMap );
1680 vis_set_param( VL, "Material", 0, 0.0, ParticleMaterial );
1681
1682 vis_set_param( VL, "Advance", ParticleAdvance, 0.0, NULL );
1683 vis_set_param( VL, "IntegMethod", ParticleIntegMethod, 0.0, NULL );
1684 vis_set_param( VL, "IntegPolicy", ParticleIntegPolicy, 0.0, NULL );
1685 ParticleAdvance = FALSE;
1686 }
1687
1688 if ( ShowVectors )
1689 {
1690 visual_t *VL = NULL;
1691
1692 if ( !VL )
1693 {
1694 VL = (visual_t *)vis_new_visual( "Arrows" );
1695 } else VL->Next = NULL;
1696 CurrentObject->VisualList = (visual_t *)vis_link_visual( CurrentObject->VisualList,VL );
1697
1698 GetScalarVariable( &VectorColor, (char *)Tcl_GetVar( TCLInterp,"VectorColor",TCL_GLOBAL_ONLY ),model, 0, TRUE );
1699 GetScalarVariable( &VectorLength, (char *)Tcl_GetVar( TCLInterp,"VectorLength",TCL_GLOBAL_ONLY ),model, 0, TRUE );
1700 GetScalarVariable( &VectorThreshold, (char *)Tcl_GetVar( TCLInterp,"VectorThreshold",TCL_GLOBAL_ONLY ),model, 0, TRUE );
1701 GetVectorVariable( VectorArrow, (char *)Tcl_GetVar( TCLInterp,"VectorArrow",TCL_GLOBAL_ONLY ),model, 0 );
1702
1703 vis_set_param( VL, "VectorData0", 0, 0.0, &VectorLength );
1704 vis_set_param( VL, "VectorData1", 0, 0.0, &VectorArrow[1] );
1705 vis_set_param( VL, "VectorData2", 0, 0.0, &VectorArrow[2] );
1706 vis_set_param( VL, "VectorData3", 0, 0.0, &VectorArrow[3] );
1707
1708
1709 vis_set_param( VL, "ColorData", 0, 0.0, &VectorColor );
1710 vis_set_param( VL, "LengthData", 0, 0.0, &VectorLength );
1711
1712 vis_set_param( VL, "ThresholdData", 0, 0.0, &VectorThreshold );
1713 vis_set_param( VL, "Ceiling", 0, VectorCeiling, NULL );
1714 vis_set_param( VL, "Floor", 0, VectorFloor, NULL );
1715
1716 vis_set_param( VL, "LineStyle", VectorLineStyle, 0.0, NULL );
1717
1718 vis_set_param( VL, "LengthScale", 0, VectorLengthScale, NULL );
1719
1720 vis_set_param( VL, "EqualLength", FALSE, 0.0, NULL );
1721
1722 vis_set_param( VL, "LineQuality", VectorQuality, 0.0, NULL );
1723 vis_set_param( VL, "ColorMap", 0, 0.0, ArrowColorMap );
1724 vis_set_param( VL, "Material", 0, 0.0, ArrowMaterial );
1725 }
1726
1727 if ( ShowContours )
1728 {
1729 visual_t *VL = NULL;
1730
1731 if ( !VL )
1732 {
1733 VL = (visual_t *)vis_new_visual( "Contour Lines" );
1734 } else VL->Next = NULL;
1735 CurrentObject->VisualList = (visual_t *)vis_link_visual( CurrentObject->VisualList,VL );
1736
1737 GetScalarVariable( &ContourColor[CurrentObject->Id], (char *)Tcl_GetVar( TCLInterp,"ContourColor",
1738 TCL_GLOBAL_ONLY ),model, 0, !ContourColorSetMinMax );
1739
1740 vis_set_param( VL, "ColorData", 0, 0.0, &ContourColor[CurrentObject->Id] );
1741 vis_set_param( VL, "ContourData", 0, 0.0, &ContourColor[CurrentObject->Id] );
1742 vis_set_param( VL, "LineWidth", 0, ContourRadius, NULL );
1743 vis_set_param( VL, "LineStyle", ContourLineStyle, 0.0, NULL );
1744 vis_set_param( VL, "LineQuality", ContourQuality, 0.0, NULL );
1745
1746 for( i=0; i<ContourLines; i++ )
1747 {
1748 static char name[32];
1749
1750 sprintf( name, "%d", i );
1751 str = (char *)Tcl_GetVar2( TCLInterp, "ContourValues",name, TCL_GLOBAL_ONLY );
1752 if ( str ) sscanf( str, "%lf", &L[i] );
1753 }
1754
1755 vis_set_param( VL, "Levels",0,0.0,L );
1756 vis_set_param( VL, "NofLevels",ContourLines,0.0,NULL );
1757 vis_set_param( VL, "ColorMap", 0, 0.0, ContourColorMap );
1758 vis_set_param( VL, "Material", 0, 0.0, ContourMaterial );
1759 }
1760
1761 if ( ShowIsosurfaces )
1762 {
1763 visual_t *VL = NULL;
1764
1765 if ( !VL )
1766 {
1767 VL = (visual_t *)vis_new_visual( "Isosurfaces" );
1768 } else VL->Next = NULL;
1769 CurrentObject->VisualList = (visual_t *)vis_link_visual( CurrentObject->VisualList,VL );
1770
1771 GetScalarVariable( &IsosurfaceColor, (char *)Tcl_GetVar( TCLInterp,"IsosurfaceColor",
1772 TCL_GLOBAL_ONLY ),model, 0, !IsosurfaceColorSetMinMax );
1773
1774 GetScalarVariable( &IsosurfaceContour, (char *)Tcl_GetVar( TCLInterp,"IsosurfaceContour",
1775 TCL_GLOBAL_ONLY ),model, 0, !IsosurfaceContourSetMinMax );
1776
1777 GetVectorVariable( IsosurfaceNormal, (char *)Tcl_GetVar( TCLInterp,
1778 "IsosurfaceNormal",TCL_GLOBAL_ONLY ),model, 0 );
1779 vis_set_param( VL, "Style", IsosurfaceStyle+1, 0.0, NULL );
1780 vis_set_param( VL, "ColorData", 0, 0.0, &IsosurfaceColor );
1781 vis_set_param( VL, "ContourData", 0, 0.0, &IsosurfaceContour );
1782 vis_set_param( VL, "NormalData0", 0, 0.0, &IsosurfaceNormal[1] );
1783 vis_set_param( VL, "NormalData1", 0, 0.0, &IsosurfaceNormal[2] );
1784 vis_set_param( VL, "NormalData2", 0, 0.0, &IsosurfaceNormal[3] );
1785 vis_set_param( VL, "LineWidth", 0, IsosurfaceRadius, NULL );
1786 vis_set_param( VL, "LineStyle", IsosurfaceLineStyle, 0.0, NULL );
1787 vis_set_param( VL, "LineQuality", IsosurfaceQuality, 0.0, NULL );
1788
1789 vis_set_param( VL, "Recompute", IsosurfaceRecompute, 0.0, NULL );
1790 IsosurfaceRecompute = FALSE;
1791
1792 for( i=0; i<IsosurfaceContours; i++ )
1793 {
1794 static char name[32];
1795
1796 sprintf( name, "%d", i );
1797 sscanf( Tcl_GetVar2( TCLInterp, "IsosurfaceValues",name, TCL_GLOBAL_ONLY ), "%lf", &I[i] );
1798 }
1799
1800 vis_set_param( VL, "Levels",0,0.0,I );
1801 vis_set_param( VL, "NofLevels",IsosurfaceContours,0.0,NULL );
1802 vis_set_param( VL, "ColorMap", 0, 0.0, IsoSurfaceColorMap );
1803 vis_set_param( VL, "Material", 0, 0.0, IsoSurfaceMaterial );
1804 }
1805
1806 if ( ShowSpheres )
1807 {
1808 visual_t *VL = NULL;
1809
1810 if ( !VL )
1811 {
1812 VL = (visual_t *)vis_new_visual( "Spheres" );
1813 } else VL->Next = NULL;
1814 CurrentObject->VisualList = (visual_t *)vis_link_visual( CurrentObject->VisualList,VL );
1815
1816 GetScalarVariable( &SphereColor,(char *)Tcl_GetVar(TCLInterp,"SphereColor",TCL_GLOBAL_ONLY),model, 0, TRUE );
1817 GetScalarVariable( &SphereRadius,(char *)Tcl_GetVar(TCLInterp,"SphereRadius",TCL_GLOBAL_ONLY),model, 0, TRUE );
1818 GetScalarVariable( &SphereThreshold,(char *)Tcl_GetVar(TCLInterp,"SphereThreshold",TCL_GLOBAL_ONLY),model, 0, TRUE );
1819
1820 vis_set_param( VL, "ColorMap", 0, 0.0, SphereColorMap );
1821 vis_set_param( VL, "Material", 0, 0.0, SphereMaterial );
1822
1823 vis_set_param( VL, "ColorData", 0, 0.0, &SphereColor );
1824 vis_set_param( VL, "RadiusData", 0, 0.0, &SphereRadius );
1825 vis_set_param( VL, "RadiusScale", 0, SphereRadiusScale, NULL );
1826 vis_set_param( VL, "ThresholdData", 0, 0.0, &SphereThreshold );
1827 vis_set_param( VL, "Floor", 0, SphereFloor, NULL );
1828 vis_set_param( VL, "Ceiling", 0, SphereCeiling, NULL );
1829 vis_set_param( VL, "Quality", SphereQuality, 0.0, NULL );
1830 }
1831
1832 if ( ShowColorMesh )
1833 {
1834 visual_t *VL = NULL;
1835
1836 if ( !VL )
1837 {
1838 VL = (visual_t *)vis_new_visual( "Mesh" );
1839 } else VL->Next = NULL;
1840 CurrentObject->VisualList = (visual_t *)vis_link_visual( CurrentObject->VisualList,VL );
1841
1842 GetScalarVariable( &MeshColor[CurrentObject->Id], (char *)Tcl_GetVar( TCLInterp,"MeshColor",TCL_GLOBAL_ONLY ),
1843 model, 0, !MeshColorSetMinMax );
1844
1845 vis_set_param( VL, "ColorData", 0, 0.0, &MeshColor[CurrentObject->Id] );
1846 vis_set_param( VL, "Style", MeshStyle+1, 0.0, NULL );
1847 vis_set_param( VL, "LineStyle", MeshLineStyle, 0.0, NULL );
1848 vis_set_param( VL, "LineQuality", MeshQuality, 0.0, NULL );
1849 vis_set_param( VL, "LineWidth", 0, MeshRadius, NULL );
1850 vis_set_param( VL, "EdgeStyle", MeshEdgeStyle, 0.0, NULL );
1851 vis_set_param( VL, "NodeNumbers", MeshNodeNumbers,0.0, NULL );
1852 vis_set_param( VL, "ColorMap", 0, 0.0, MeshColorMap );
1853 vis_set_param( VL, "Material", 0, 0.0, MeshMaterial );
1854 vis_set_param( VL, "EdgeMaterial", 0, 0.0, &DefaultEdgeMaterial );
1855 }
1856
1857 if ( ShowColorScale )
1858 {
1859 visual_t *VL = NULL;
1860
1861 if ( !VL )
1862 {
1863 VL = (visual_t *)vis_new_visual( "ColorScale" );
1864 } else VL->Next = NULL;
1865 CurrentObject->VisualList = (visual_t *)vis_link_visual( CurrentObject->VisualList,VL );
1866
1867 GetScalarVariable( &ColorScaleColor, (char *)Tcl_GetVar( TCLInterp,"ColorScaleColor",TCL_GLOBAL_ONLY ),
1868 model, 0, !ColorScaleColorSetMinMax );
1869
1870 vis_set_param( VL, "ColorData", 0, 0.0, &ColorScaleColor );
1871 vis_set_param( VL, "ColorMap", 0, 0.0, &DefaultColorMap );
1872 vis_set_param( VL, "Material", 0, 0.0, &DefaultMaterial );
1873 vis_set_param( VL, "XPosition", 0, ColorScaleX, NULL );
1874 vis_set_param( VL, "YPosition", 0, ColorScaleY, NULL );
1875 vis_set_param( VL, "Length", 0, ColorScaleLength, NULL );
1876 vis_set_param( VL, "Thickness", 0, ColorScaleThickness, NULL );
1877 vis_set_param( VL, "Style", ColorScaleStyle, 0.0, NULL );
1878 vis_set_param( VL, "Font Color",ColorScaleFontColor, 0.0, NULL );
1879 vis_set_param( VL, "Font Size", 0, ColorScaleFontSize, NULL );
1880 vis_set_param( VL, "Entries", ColorScaleEntries, 0.0, NULL );
1881 vis_set_param( VL, "Decimals", ColorScaleDecimals, 0.0, NULL );
1882 }
1883
1884 return TCL_OK;
1885 }
1886
opengl_draw()1887 void opengl_draw()
1888 {
1889 Tcl_Eval( TCLInterp, ".buts.play configure -back red -relief sunken; update" );
1890
1891 glMatrixMode( GL_MODELVIEW );
1892 glLoadIdentity();
1893
1894 glClearColor( br,bg,bb,1.0 );
1895 if ( GraphicsClearOn )
1896 {
1897 glDrawBuffer( GL_BACK );
1898 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1899 } else {
1900 glDrawBuffer( GL_FRONT_AND_BACK );
1901 }
1902
1903 #if 0
1904 if ( !CurrentObject->Geometry || CurrentObject->Geometry->VertexCount <= 0 ) {
1905 Tcl_Eval( TCLInterp, ".buts.play configure -back green -relief raised; update" );
1906 epSwapBuffers(); return;
1907 }
1908 #endif
1909
1910 if ( epMouseDown && epMouseDownTakesTooLong )
1911 {
1912 glDisable( GL_BLEND );
1913 glDisable( GL_DEPTH_TEST );
1914 } else
1915 {
1916 #if 0
1917 glEnable( GL_BLEND );
1918 #endif
1919 glEnable( GL_DEPTH_TEST );
1920 }
1921
1922 if ( cam_display_list( Camera,&VisualObject ) ) epSwapBuffers();
1923
1924 Tcl_Eval( TCLInterp, ".buts.play configure -back green -relief raised; update" );
1925 }
1926
1927
Reshape(GLsizei x,GLsizei y)1928 void Reshape( GLsizei x,GLsizei y)
1929 {
1930 GraphicsXSize = x;
1931 GraphicsYSize = y;
1932 GraphicsAspect = (double)x/(double)y;
1933
1934 DrawItSomeTimeWhenIdle();
1935 }
1936
CompRot(matrix_t M)1937 void CompRot( matrix_t M ) {
1938 static double bx, by, bz;
1939
1940 bx = M[0][0]*ax + M[1][0]*ay + M[2][0]*az;
1941 by = M[0][1]*ax + M[1][1]*ay + M[2][1]*az;
1942 bz = M[0][2]*ax + M[1][2]*ay + M[2][2]*az;
1943
1944 ax = bx;
1945 ay = by;
1946 az = bz;
1947 }
1948
epMouseDownProc(int Xpos,int Ypos)1949 void epMouseDownProc(int Xpos, int Ypos)
1950 {
1951 int x,y,x_root,y_root;
1952 Window root,child;
1953 static GLint viewport[4];
1954 transform_t *transform;
1955 double scale;
1956
1957 #ifndef MINGW32
1958 XQueryPointer( tkXDisplay(),tkXWindow(),&root,&child,&x_root,&y_root,&x,&y,&epMouseDown );
1959 epMouseDown &= (ShiftMask | Button1Mask | Button2Mask);
1960 #else
1961 auxGetMouseLoc( &x, &y );
1962
1963 epMouseDown = 0;
1964 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 ) epMouseDown |= Button1Mask;
1965 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 ) epMouseDown |= Button2Mask;
1966 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 ) epMouseDown |= Button2Mask;
1967 if ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) epMouseDown |= ShiftMask;
1968 #endif
1969
1970 epMouseDownTakesTooLong = FALSE;
1971
1972 while( epMouseDown )
1973 {
1974 if ( epMouseDown & Button2Mask )
1975 {
1976 ax = ay = az = 0.0;
1977 sx = sy = sz = 0.0;
1978
1979 if ( epMouseDown & Button1Mask )
1980 {
1981 if ( ABS(Ypos-y) > ABS(Xpos-x) )
1982 {
1983 sx = 0.025*(Ypos-y);
1984 sy = 0.025*(Ypos-y);
1985 sz = 0.025*(Ypos-y);
1986 } else
1987 {
1988 sx = 0.025*(x-Xpos);
1989 sy = 0.025*(x-Xpos);
1990 sz = 0.025*(x-Xpos);
1991 }
1992
1993 obj_scale( CurrentObject,sx,sy,sz,'a',TRUE );
1994 } else
1995 {
1996 // scale = 0.4;
1997 glGetIntegerv(GL_VIEWPORT, viewport);
1998 transform = &CurrentObject->Transform;
1999 scale=180.0/(double)(viewport[3]+1)/transform->SclZ;
2000
2001 if ( epMouseDown & ShiftMask )
2002 {
2003 if ( ABS(Ypos-y) > ABS(Xpos-x) )
2004 az = scale*(y-Ypos);
2005 else
2006 az = scale*(Xpos-x);
2007 } else {
2008 if ( ABS(y-Ypos) > ABS(x-Xpos) )
2009 ax = scale*(y-Ypos);
2010 else
2011 ay = scale*(x-Xpos);
2012
2013 // Compensate for rotation matrix:
2014 //--------------------------------
2015 CompRot( transform->RotMatrix );
2016
2017 }
2018
2019 obj_rotate( CurrentObject,ax,ay,az,'a',TRUE );
2020 }
2021 }
2022 else if ( epMouseDown & Button1Mask )
2023 {
2024 tx = ty = tz = 0;
2025 if ( epMouseDown & ShiftMask )
2026 {
2027 if ( ABS(Ypos-y) > ABS(Xpos-x) )
2028 tz = 0.03*(Ypos-y);
2029 else
2030 tz = 0.03*(x-Xpos);
2031 } else {
2032 // scale = 0.01;
2033 glGetIntegerv(GL_VIEWPORT, viewport);
2034 transform = &CurrentObject->Transform;
2035 scale = 2.0/(double)(viewport[3]+1)/transform->SclZ;
2036
2037 tx = scale*(x-Xpos);
2038 ty = scale*(Ypos-y);
2039 }
2040 obj_translate( CurrentObject,tx,ty,tz,'a',TRUE );
2041 }
2042
2043 Xpos = x;
2044 Ypos = y;
2045
2046 opengl_draw();
2047
2048 #ifndef MINGW32
2049 XQueryPointer( tkXDisplay(),tkXWindow(),&root,&child,&x_root,&y_root,&x,&y,&epMouseDown );
2050 epMouseDown &= (ShiftMask | Button1Mask | Button2Mask);
2051 #else
2052 epMouseDown = 0;
2053 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 ) epMouseDown |= Button1Mask;
2054 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 ) epMouseDown |= Button2Mask;
2055 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 ) epMouseDown |= Button2Mask;
2056 if ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) epMouseDown |= ShiftMask;
2057
2058 auxGetMouseLoc( &x, &y );
2059 #endif
2060 }
2061
2062 epMouseDown = FALSE;
2063 if ( epMouseDownTakesTooLong ) { opengl_draw(); }
2064 }
2065
2066 #ifndef MINGW32
Mouse(AUX_EVENTREC * event)2067 void Mouse( AUX_EVENTREC *event )
2068 {
2069 int MouseXPosition = event->data[AUX_MOUSEX];
2070 int MouseYPosition = event->data[AUX_MOUSEY];
2071 int MouseStatus = event->data[AUX_MOUSESTATUS];
2072
2073 if ( event->event == AUX_MOUSEDOWN )
2074 {
2075 if ( MouseXPosition >= 0 && MouseXPosition < GraphicsXSize &&
2076 MouseYPosition >= 0 && MouseYPosition < GraphicsYSize )
2077 {
2078 epMouseDownProc( MouseXPosition, MouseYPosition );
2079 }
2080 }
2081 }
2082 #else
Mouse()2083 void Mouse( )
2084 {
2085 int MouseXPosition;
2086 int MouseYPosition;
2087
2088
2089 if ( GetFocus() != tkXWindow() ) return;
2090
2091
2092 auxGetMouseLoc( &MouseXPosition, &MouseYPosition );
2093
2094 if ( MouseXPosition >= 0 && MouseXPosition < GraphicsXSize &&
2095 MouseYPosition >= 0 && MouseYPosition < GraphicsYSize )
2096 {
2097 epMouseDownProc( MouseXPosition, MouseYPosition );
2098 }
2099 }
2100 #endif
2101
UpdateDisplay(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)2102 static int UpdateDisplay(ClientData cl,Tcl_Interp *interp,int argc,char **argv)
2103 {
2104 int x,y,x_root,y_root;
2105 Window root,child;
2106
2107
2108 #ifndef MINGW32
2109 XQueryPointer( tkXDisplay(),tkXWindow(),&root,&child,&x_root,&y_root,&x,&y,&epMouseDown );
2110 epMouseDown &= (ShiftMask | Button1Mask | Button2Mask);
2111 #else
2112 auxGetMouseLoc( &x, &y );
2113
2114 epMouseDown = 0;
2115 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 ) epMouseDown |= Button1Mask;
2116 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 ) epMouseDown |= Button2Mask;
2117 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 ) epMouseDown |= Button2Mask;
2118 if ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) epMouseDown |= ShiftMask;
2119 #endif
2120
2121 if ( epMouseDown ) epMouseDownProc( x,y );
2122
2123 #ifdef USE_TK
2124 tkExec( 0 );
2125 #endif
2126 return TCL_OK;
2127 }
2128
2129
TestTkEvent()2130 void TestTkEvent()
2131 {
2132 BreakLoop = FALSE;
2133
2134 while( Tcl_DoOneEvent(TCL_DONT_WAIT) );
2135 #ifdef MINGW32
2136 if ( GetKeyState( VK_LBUTTON ) & 0x8000 ) Mouse();
2137 if ( GetKeyState( VK_MBUTTON ) & 0x8000 ) Mouse();
2138 if ( GetKeyState( VK_RBUTTON ) & 0x8000 ) Mouse();
2139 #endif
2140 Tk_Sleep(100);
2141 }
2142
WindowSize(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)2143 static int WindowSize( ClientData cl,Tcl_Interp *interp,int argc,char **argv )
2144 {
2145 unsigned int width, height;
2146 int dx, dy, ox, oy, nx, ny, viewp[4];
2147
2148
2149 if ( argc < 3 ) {
2150 sprintf( interp->result, "Usage: winsize width height" );
2151 return TCL_ERROR;
2152 }
2153
2154 width = atoi( *++argv );
2155 height = atoi( *++argv );
2156
2157 #ifdef MINGW32
2158 SetWindowPos( auxGetHWND(), HWND_TOP, 0, 0, width, height, SWP_NOMOVE | SWP_NOACTIVATE );
2159
2160 // Measure the viewport size and make corrections winsize if necessary:
2161 //---------------------------------------------------------------------
2162 opengl_draw();
2163 glGetIntegerv( GL_VIEWPORT, viewp );
2164
2165 ox = viewp[0];
2166 oy = viewp[1];
2167 nx = viewp[2]+1;
2168 ny = viewp[3]+1;
2169
2170 dx = width - nx;
2171 dy = height -ny;
2172
2173 width += dx;
2174 height += dy;
2175
2176 SetWindowPos( auxGetHWND(), HWND_TOP, 0, 0, width, height, SWP_NOMOVE | SWP_NOACTIVATE );
2177
2178 #else
2179 XResizeWindow( tkXDisplay(), tkXWindow(), width, height );
2180 #endif
2181
2182 return TCL_OK;
2183 }
2184
WindowPosition(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)2185 static int WindowPosition( ClientData cl,Tcl_Interp *interp,int argc,char **argv )
2186 {
2187 if ( argc < 3 ) {
2188 sprintf( interp->result, "Usage: winpos xpos ypos" );
2189 return TCL_ERROR;
2190 }
2191
2192 int ox = atoi( *++argv );
2193 int oy = atoi( *++argv );
2194
2195 #ifdef MINGW32
2196 SetWindowPos( auxGetHWND(), HWND_TOP, ox, oy, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE );
2197 #else
2198 XMoveWindow( (Display *)tkXDisplay(), tkXWindow(), ox, oy );
2199 #endif
2200
2201 return TCL_OK;
2202 }
2203
2204
MPlayer(ClientData cl,Tcl_Interp * interp,int argc,char ** argv)2205 static int MPlayer( ClientData cl, Tcl_Interp *interp, int argc, char **argv )
2206 {
2207 #if defined(MINGW32)
2208
2209 return TCL_OK;
2210
2211 #else
2212
2213 if( argc < 2 ) {
2214 sprintf( interp->result, "Usage: mplayer filename");
2215 return TCL_ERROR;
2216 }
2217
2218 // File name:
2219 char *fileName = *++argv;
2220
2221 // Get Window Id:
2222 GLXDrawable drawable = glXGetCurrentDrawable();
2223 int winId = (int)drawable;
2224
2225 // Player command:
2226 char playCmd[1024];
2227 sprintf( playCmd, "mplayer -wid %d %s", winId, fileName );
2228
2229 // Call mplayer:
2230 system( playCmd );
2231
2232 return TCL_OK;
2233
2234 #endif
2235 }
2236
2237
main(int argc,char ** argv)2238 int main(int argc,char **argv)
2239 {
2240 static char init[1024],initcommands[1024],tmp[1024],ephome[512];
2241 int i,size[4];
2242
2243 /* For MinGW */
2244 static char szAppPath[512] = "";
2245 static char szAppDirectory[512] = "";
2246 char *exeName;
2247
2248 if((argc > 1) && (!strcmp(argv[1], "-v"))) {
2249 fprintf(stdout, "ElmerPost v.5.4\n");
2250 return 0;
2251 }
2252
2253 if ( getenv("ELMER_POST_HOME") == NULL )
2254 {
2255 /* use default installation directory just if nothing is set */
2256 #if defined(MINGW32)
2257 GetModuleFileName(NULL, szAppPath, 512);
2258 exeName = strrchr(szAppPath, '\\');
2259 i = (int)(exeName-szAppPath);
2260 if(i < 0) i = 0;
2261 if(i > 512) i = 512;
2262 strncpy(szAppDirectory, szAppPath, i);
2263
2264 _snprintf(ephome, 512,
2265 "ELMER_POST_HOME=%s\\..\\share\\elmerpost",
2266 szAppDirectory);
2267
2268 printf("%s\n", ephome);
2269 #else
2270 snprintf( ephome, 512, "ELMER_POST_HOME=%s", ELMER_POST_HOME );
2271 #endif
2272
2273 putenv( ephome );
2274 }
2275
2276
2277 Tcl_FindExecutable( *argv++ );
2278 TCLInterp = Tcl_CreateInterp();
2279
2280 auxInitDisplayMode( AUX_DOUBLE | AUX_RGB | AUX_DEPTH | AUX_DIRECT );
2281 auxInitPosition( 0, 0, 500, 500 );
2282 auxInitWindow( "ELMER POST GRAPHICS" );
2283
2284 strcpy( initcommands, "" );
2285
2286 while ( *argv ) {
2287
2288 if ( strcmp( *argv, "-id" ) == 0 ) {
2289 if ( *++argv )
2290 {
2291 Tcl_SetVar( TCLInterp, "elmerpost_id", *argv++,
2292 TCL_GLOBAL_ONLY );
2293 }
2294
2295 } else if ( strcmp( *argv, "-file" ) == 0 ) {
2296 if ( *++argv )
2297 {
2298 strcat( initcommands, "readfile " );
2299
2300 /* Quote filename if not already quoted */
2301 if ( (*argv)[strlen(*argv) - 1] != '\"' )
2302 strcat( initcommands, "\"" );
2303
2304 strcat( initcommands, *argv );
2305
2306 if ( (*argv)[strlen(*argv) - 1] != '\"' )
2307 strcat( initcommands, "\"" );
2308
2309 strcat( initcommands, " " );
2310 ++argv;
2311 }
2312
2313 } else if ( 1020 - strlen(initcommands) > strlen( *argv ) ) {
2314 strcat( initcommands, *argv++ );
2315 strcat( initcommands, " " );
2316
2317 } else break;
2318 }
2319
2320 Tcl_SetVar( TCLInterp, "argv", "-name \"ELMER POST PROCESSING\"",
2321 TCL_GLOBAL_ONLY );
2322
2323 Tcl_Init( TCLInterp );
2324 Tk_Init( TCLInterp );
2325
2326 Tcl_StaticPackage(TCLInterp, "Tk", Tk_Init, Tk_SafeInit);
2327
2328 Tcl_CreateCommand( TCLInterp, "GetInterpolate", (Tcl_CmdProc *)GetInterpolate,
2329 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2330
2331 Tcl_CreateCommand( TCLInterp, "GetColorMap", (Tcl_CmdProc *)GetColorMap,
2332 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2333
2334 Tcl_CreateCommand( TCLInterp, "StopProcessing", (Tcl_CmdProc *)StopProcessing,
2335 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2336
2337 Tcl_CreateCommand( TCLInterp, "UpdateBackColor", (Tcl_CmdProc *)UpdateBackColor,
2338 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2339
2340 Tcl_CreateCommand( TCLInterp, "UpdateColor", (Tcl_CmdProc *)UpdateColor,
2341 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2342
2343 Tcl_CreateCommand( TCLInterp, "UpdateEdgeColor", (Tcl_CmdProc *)UpdateEdgeColor,
2344 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2345
2346 Tcl_CreateCommand( TCLInterp, "UpdateVariable", (Tcl_CmdProc *)UpdateVariable,
2347 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2348
2349 Tcl_CreateCommand( TCLInterp, "c_TimeStep", (Tcl_CmdProc *)TimeStep,
2350 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2351
2352 Tcl_CreateCommand( TCLInterp, "c_LoadCamera", (Tcl_CmdProc *)LoadCamera,
2353 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2354
2355 Tcl_CreateCommand( TCLInterp, "c_CurrentCamera", (Tcl_CmdProc *)CurrentCamera,
2356 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2357
2358 Tcl_CreateCommand( TCLInterp, "c_SetCamera", (Tcl_CmdProc *)SetCamera,
2359 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2360
2361 Tcl_CreateCommand( TCLInterp, "UpdateDisplay", (Tcl_CmdProc *)UpdateDisplay,
2362 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2363
2364 Tcl_CreateCommand( TCLInterp, "c_MathCommand", (Tcl_CmdProc *)MathCommand,
2365 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2366
2367 Tcl_CreateCommand( TCLInterp, "UpdateObject", (Tcl_CmdProc *)UpdateObject,
2368 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2369
2370 Tcl_CreateCommand( TCLInterp, "group", (Tcl_CmdProc *)GroupDisplay,
2371 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2372
2373 Tcl_CreateCommand( TCLInterp, "setfont", (Tcl_CmdProc *)SetFont,
2374 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2375
2376 Tcl_CreateCommand( TCLInterp, "object", (Tcl_CmdProc *)SetObject,
2377 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2378
2379 Tcl_CreateCommand( TCLInterp, "parent", (Tcl_CmdProc *)SetParentObject,
2380 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2381
2382 Tcl_CreateCommand( TCLInterp, "normals", (Tcl_CmdProc *)RecomputeNormals,
2383 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2384
2385 Tcl_CreateCommand( TCLInterp, "clip", (Tcl_CmdProc *)ClipPlane,
2386 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2387
2388 Tcl_CreateCommand( TCLInterp, "ActivateGraphicsWindow", (Tcl_CmdProc *)ActivateGraphicsWindow,
2389 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2390
2391 Tcl_CreateCommand( TCLInterp, "winsize", (Tcl_CmdProc *)WindowSize,
2392 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2393
2394 Tcl_CreateCommand( TCLInterp, "winpos", (Tcl_CmdProc *)WindowPosition,
2395 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2396
2397 #if defined(HAVE_FTGL_NEW) || defined(HAVE_FTGL_OLD)
2398 Tcl_CreateCommand( TCLInterp, "fttext", (Tcl_CmdProc *)FtText,
2399 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2400
2401 Tcl_CreateCommand( TCLInterp, "ftfont", (Tcl_CmdProc *)FtFont,
2402 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2403 #endif
2404
2405 Tcl_CreateCommand( TCLInterp, "mplayer", (Tcl_CmdProc *)MPlayer,
2406 (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
2407
2408 CurrentObject = &VisualObject;
2409 CurrentObject->Name = strcpy( malloc(strlen("default")+1), "default" );
2410
2411 obj_object_initialize( CurrentObject );
2412
2413 Tcl_LinkVar( TCLInterp, "BreakLoop", (char *)&BreakLoop, TCL_LINK_INT );
2414
2415 if ( !(Camera = (camera_t *)cam_load_cameras( Camera,NULL ) ) )
2416 {
2417 fprintf( stderr, "ElmerPost: Can't initialize default camera. "
2418 "Something is definitely wrong here...\n" );
2419 exit( 0 );
2420 }
2421
2422 if ( !vis_initialize_visual_types() )
2423 {
2424 fprintf( stderr, "ElmerPost: Can't initialize visual types. "
2425 "Something is definitely wrong here...\n" );
2426 exit( 0 );
2427 }
2428
2429 if ( !elm_initialize_element_types() )
2430 {
2431 fprintf( stderr, "ElmerPost: Can't initialize element types. "
2432 "Something is definitely wrong here...\n" );
2433 exit( 0 );
2434 }
2435
2436 mtc_init( NULL, stdout, stderr );
2437
2438 Tcl_LinkVar( TCLInterp, "NumberOfTimesteps", (char *)&ElementModel.NofTimesteps, TCL_LINK_INT );
2439
2440 Tcl_LinkVar( TCLInterp, "NumberOfScalarVariables", (char *)&NumberOfScalarVariables, TCL_LINK_INT );
2441 Tcl_LinkVar( TCLInterp, "NumberOfVectorVariables", (char *)&NumberOfVectorVariables, TCL_LINK_INT );
2442 Tcl_LinkVar( TCLInterp, "NumberOfParticleVariables", (char *)&NumberOfParticleVariables, TCL_LINK_INT );
2443
2444 strcpy( tmp , "DisplayStyle(Vectors)" );
2445 Tcl_LinkVar( TCLInterp, tmp, (char *)&ShowVectors, TCL_LINK_INT );
2446 strcpy( tmp , "DisplayStyle(Contours)" );
2447 Tcl_LinkVar( TCLInterp, tmp, (char *)&ShowContours, TCL_LINK_INT );
2448 strcpy( tmp , "DisplayStyle(MeshLines)" );
2449 Tcl_LinkVar( TCLInterp, tmp, (char *)&ShowMeshLines, TCL_LINK_INT );
2450 strcpy( tmp , "DisplayStyle(ColorMesh)" );
2451 Tcl_LinkVar( TCLInterp, tmp, (char *)&ShowColorMesh, TCL_LINK_INT );
2452 strcpy( tmp , "DisplayStyle(Spheres)" );
2453 Tcl_LinkVar( TCLInterp, tmp, (char *)&ShowSpheres, TCL_LINK_INT );
2454 strcpy( tmp , "DisplayStyle(Isosurfaces)" );
2455 Tcl_LinkVar( TCLInterp, tmp, (char *)&ShowIsosurfaces, TCL_LINK_INT );
2456 strcpy( tmp , "DisplayStyle(Particles)" );
2457 Tcl_LinkVar( TCLInterp, tmp, (char *)&ShowParticles, TCL_LINK_INT );
2458 strcpy( tmp , "DisplayStyle(ColorScale)" );
2459 Tcl_LinkVar( TCLInterp, tmp, (char *)&ShowColorScale, TCL_LINK_INT );
2460
2461 Tcl_LinkVar( TCLInterp, "MeshStyle", (char *)&MeshStyle, TCL_LINK_INT );
2462 Tcl_LinkVar( TCLInterp, "MeshLineStyle", (char *)&MeshLineStyle, TCL_LINK_INT );
2463 Tcl_LinkVar( TCLInterp, "MeshEdgeStyle", (char *)&MeshEdgeStyle, TCL_LINK_INT );
2464 Tcl_LinkVar( TCLInterp, "MeshQuality", (char *)&MeshQuality, TCL_LINK_INT );
2465 Tcl_LinkVar( TCLInterp, "MeshRadius", (char *)&MeshRadius, TCL_LINK_DOUBLE );
2466 Tcl_LinkVar( TCLInterp, "MeshNodeNumbers", (char *)&MeshNodeNumbers, TCL_LINK_INT );
2467 Tcl_LinkVar( TCLInterp, "MeshColorMin", (char *)&MeshColor[0].min, TCL_LINK_DOUBLE );
2468 Tcl_LinkVar( TCLInterp, "MeshColorMax", (char *)&MeshColor[0].max, TCL_LINK_DOUBLE );
2469 Tcl_LinkVar( TCLInterp, "MeshColorSetMinMax", (char *)&MeshColorSetMinMax, TCL_LINK_INT );
2470
2471 Tcl_LinkVar( TCLInterp, "ContourLines", (char *)&ContourLines, TCL_LINK_INT );
2472 Tcl_LinkVar( TCLInterp, "ContourLineStyle", (char *)&ContourLineStyle, TCL_LINK_INT );
2473 Tcl_LinkVar( TCLInterp, "ContourQuality", (char *)&ContourQuality, TCL_LINK_INT );
2474 Tcl_LinkVar( TCLInterp, "ContourRadius", (char *)&ContourRadius, TCL_LINK_DOUBLE );
2475
2476 Tcl_LinkVar( TCLInterp, "ContourColorMin", (char *)&ContourColor[0].min, TCL_LINK_DOUBLE );
2477 Tcl_LinkVar( TCLInterp, "ContourColorMax", (char *)&ContourColor[0].max, TCL_LINK_DOUBLE );
2478 Tcl_LinkVar( TCLInterp, "ContourColorSetMinMax", (char *)&ContourColorSetMinMax, TCL_LINK_INT );
2479
2480 Tcl_LinkVar( TCLInterp, "VectorLineStyle", (char *)&VectorLineStyle, TCL_LINK_INT );
2481 Tcl_LinkVar( TCLInterp, "VectorQuality", (char *)&VectorQuality, TCL_LINK_INT );
2482 Tcl_LinkVar( TCLInterp, "VectorRadius", (char *)&VectorRadius, TCL_LINK_DOUBLE );
2483 Tcl_LinkVar( TCLInterp, "VectorLengthScale", (char *)&VectorLengthScale, TCL_LINK_DOUBLE );
2484
2485 Tcl_LinkVar( TCLInterp, "VectorCeiling", (char *)&VectorCeiling, TCL_LINK_DOUBLE );
2486 Tcl_LinkVar( TCLInterp, "VectorFloor", (char *)&VectorFloor, TCL_LINK_DOUBLE );
2487
2488 Tcl_LinkVar( TCLInterp, "VectorThresholdMin", (char *)&VectorThreshold.min, TCL_LINK_DOUBLE );
2489 Tcl_LinkVar( TCLInterp, "VectorThresholdMax", (char *)&VectorThreshold.max, TCL_LINK_DOUBLE );
2490
2491 Tcl_LinkVar( TCLInterp, "IsosurfaceStyle", (char *)&IsosurfaceStyle, TCL_LINK_INT );
2492 Tcl_LinkVar( TCLInterp, "IsosurfaceContours", (char *)&IsosurfaceContours, TCL_LINK_INT );
2493 Tcl_LinkVar( TCLInterp, "IsosurfaceLineStyle", (char *)&IsosurfaceLineStyle, TCL_LINK_INT );
2494 Tcl_LinkVar( TCLInterp, "IsosurfaceQuality", (char *)&IsosurfaceQuality, TCL_LINK_INT );
2495 Tcl_LinkVar( TCLInterp, "IsosurfaceRadius", (char *)&IsosurfaceRadius, TCL_LINK_DOUBLE );
2496 Tcl_LinkVar( TCLInterp, "IsosurfaceRecompute", (char *)&IsosurfaceRecompute, TCL_LINK_INT );
2497 Tcl_LinkVar( TCLInterp, "IsosurfaceColorMin", (char *)&IsosurfaceColor.min, TCL_LINK_DOUBLE );
2498 Tcl_LinkVar( TCLInterp, "IsosurfaceColorMax", (char *)&IsosurfaceColor.max, TCL_LINK_DOUBLE );
2499 Tcl_LinkVar( TCLInterp, "IsosurfaceColorSetMinMax", (char *)&IsosurfaceColorSetMinMax, TCL_LINK_INT );
2500
2501 Tcl_LinkVar( TCLInterp, "IsosurfaceContourSetMinMax", (char *)&IsosurfaceContourSetMinMax, TCL_LINK_INT );
2502 Tcl_LinkVar( TCLInterp, "IsosurfaceContourMin", (char *)&IsosurfaceContour.min, TCL_LINK_DOUBLE );
2503 Tcl_LinkVar( TCLInterp, "IsosurfaceContourMax", (char *)&IsosurfaceContour.max, TCL_LINK_DOUBLE );
2504
2505 Tcl_LinkVar( TCLInterp, "ParticleStyle", (char *)&ParticleStyle, TCL_LINK_INT );
2506 Tcl_LinkVar( TCLInterp, "ParticleLineStyle", (char *)&ParticleLineStyle, TCL_LINK_INT );
2507 Tcl_LinkVar( TCLInterp, "ParticleArrowStyle", (char *)&ParticleArrowStyle, TCL_LINK_INT );
2508 Tcl_LinkVar( TCLInterp, "ParticleQuality", (char *)&ParticleQuality, TCL_LINK_INT );
2509 Tcl_LinkVar( TCLInterp, "ParticleRadius", (char *)&ParticleRadius, TCL_LINK_DOUBLE );
2510 Tcl_LinkVar( TCLInterp, "ParticleOutDT", (char *)&ParticleOutDT, TCL_LINK_DOUBLE );
2511 Tcl_LinkVar( TCLInterp, "ParticleMaxDT", (char *)&ParticleMaxDT, TCL_LINK_DOUBLE );
2512 Tcl_LinkVar( TCLInterp, "ParticleTolerance", (char *)&ParticleTolerance, TCL_LINK_DOUBLE );
2513 Tcl_LinkVar( TCLInterp, "ParticleNofParticles", (char *)&ParticleNofParticles, TCL_LINK_INT );
2514 Tcl_LinkVar( TCLInterp, "ParticleAdvance", (char *)&ParticleAdvance, TCL_LINK_INT );
2515 Tcl_LinkVar( TCLInterp, "ParticleIntegMethod", (char *)&ParticleIntegMethod, TCL_LINK_INT );
2516 Tcl_LinkVar( TCLInterp, "ParticleIntegPolicy", (char *)&ParticleIntegPolicy, TCL_LINK_INT );
2517
2518 Tcl_LinkVar( TCLInterp, "SphereQuality", (char *)&SphereQuality, TCL_LINK_INT );
2519 Tcl_LinkVar( TCLInterp, "SphereRadiusScale", (char *)&SphereRadiusScale, TCL_LINK_DOUBLE );
2520 Tcl_LinkVar( TCLInterp, "SphereFloor", (char *)&SphereFloor, TCL_LINK_DOUBLE );
2521 Tcl_LinkVar( TCLInterp, "SphereCeiling", (char *)&SphereCeiling, TCL_LINK_DOUBLE );
2522 Tcl_LinkVar( TCLInterp, "SphereThresholdMin", (char *)&SphereThreshold.min, TCL_LINK_DOUBLE );
2523 Tcl_LinkVar( TCLInterp, "SphereThresholdMax", (char *)&SphereThreshold.max, TCL_LINK_DOUBLE );
2524
2525 Tcl_LinkVar( TCLInterp, "ColorScaleStyle", (char *)&ColorScaleStyle, TCL_LINK_INT );
2526 Tcl_LinkVar( TCLInterp, "ColorScaleEntries", (char *)&ColorScaleEntries, TCL_LINK_INT );
2527 Tcl_LinkVar( TCLInterp, "ColorScaleDecimals", (char *)&ColorScaleDecimals, TCL_LINK_INT );
2528 Tcl_LinkVar( TCLInterp, "ColorScaleX", (char *)&ColorScaleX, TCL_LINK_DOUBLE );
2529 Tcl_LinkVar( TCLInterp, "ColorScaleY", (char *)&ColorScaleY, TCL_LINK_DOUBLE );
2530 Tcl_LinkVar( TCLInterp, "ColorScaleThickness", (char *)&ColorScaleThickness, TCL_LINK_DOUBLE );
2531 Tcl_LinkVar( TCLInterp, "ColorScaleLength", (char *)&ColorScaleLength, TCL_LINK_DOUBLE );
2532 Tcl_LinkVar( TCLInterp, "ColorScaleFontColor", (char *)&ColorScaleFontColor, TCL_LINK_INT );
2533
2534 Tcl_LinkVar( TCLInterp, "ColorScaleColorMin", (char *)&ColorScaleColor.min, TCL_LINK_DOUBLE );
2535 Tcl_LinkVar( TCLInterp, "ColorScaleColorMax", (char *)&ColorScaleColor.max, TCL_LINK_DOUBLE );
2536 Tcl_LinkVar( TCLInterp, "ColorScaleColorSetMinMax", (char *)&ColorScaleColorSetMinMax, TCL_LINK_INT );
2537
2538
2539 Tcl_LinkVar( TCLInterp, "GraphicsClearOn", (char *)&GraphicsClearOn, TCL_LINK_INT );
2540
2541
2542 Tcl_LinkVar( TCLInterp, "KeepScale", (char *)&KeepScale, TCL_LINK_INT );
2543
2544 Tcl_LinkVar( TCLInterp, "NormalUpdate", (char *)&NormalUpdate, TCL_LINK_INT );
2545
2546 strcpy( tmp , "GlobalOptions(SurfaceSides)" );
2547 Tcl_LinkVar( TCLInterp, tmp, (char *)&GlobalOptions.SurfaceSides, TCL_LINK_INT );
2548
2549 strcpy( tmp , "GlobalOptions(VolumeSides)" );
2550 Tcl_LinkVar( TCLInterp, tmp, (char *)&GlobalOptions.VolumeSides, TCL_LINK_INT );
2551
2552 strcpy( tmp , "GlobalOptions(VolumeEdges)" );
2553 Tcl_LinkVar( TCLInterp, tmp, (char *)&GlobalOptions.VolumeEdges, TCL_LINK_INT );
2554
2555 strcpy( tmp , "GlobalOptions(StereoMode)" );
2556 Tcl_LinkVar( TCLInterp, tmp, (char *)&GlobalOptions.StereoMode, TCL_LINK_INT );
2557 strcpy( tmp , "GlobalOptions(StereoTran)" );
2558 Tcl_LinkVar( TCLInterp, tmp, (char *)&GlobalOptions.StereoTran, TCL_LINK_DOUBLE );
2559 strcpy( tmp , "GlobalOptions(StereoRot)" );
2560 Tcl_LinkVar( TCLInterp, tmp, (char *)&GlobalOptions.StereoRot, TCL_LINK_DOUBLE );
2561
2562 strcpy( tmp , "GlobalOptions(OutputPS)" );
2563 Tcl_LinkVar( TCLInterp, tmp, (char *)&GlobalOptions.OutputPS, TCL_LINK_INT );
2564 strcpy( tmp , "GlobalOptions(FitToPagePS)" );
2565 Tcl_LinkVar( TCLInterp, tmp, (char *)&GlobalOptions.FitToPagePS, TCL_LINK_INT );
2566
2567 Misc_Init( TCLInterp );
2568 Transforms_Init( TCLInterp );
2569 Readfile_Init( TCLInterp );
2570 Matctcl_Init( TCLInterp );
2571
2572
2573 signal( SIGFPE, SIG_IGN );
2574 signal( SIGINT, int_sig );
2575
2576
2577 *init = '\0';
2578 if ( getenv("ELMER_POST_HOME") )
2579 {
2580 strncat( init,getenv("ELMER_POST_HOME"),511);
2581 strncat( init,"/",511 );
2582 }
2583 strncat( init,"tcl/init.tcl",511 );
2584 fprintf( stdout, "Initialization File: [%s]\n", init );
2585 fflush(stdout);
2586 Tcl_EvalFile( TCLInterp,init );
2587
2588 while( Tk_DoOneEvent(TCL_DONT_WAIT) );
2589
2590 #ifdef MINGW32
2591 auxReshapeFunc( (AUXRESHAPEPROC)Reshape );
2592 auxExposeFunc( (AUXEXPOSEPROC)Reshape );
2593 auxIdleFunc( (AUXIDLEPROC)TestTkEvent );
2594 #else
2595 auxReshapeFunc( Reshape );
2596 auxExposeFunc( Reshape );
2597 auxIdleFunc( TestTkEvent );
2598 auxMouseFunc( AUX_LEFTBUTTON, AUX_MOUSEDOWN, Mouse );
2599 auxMouseFunc( AUX_MIDDLEBUTTON, AUX_MOUSEDOWN, Mouse );
2600 #endif
2601
2602
2603 gra_init();
2604
2605 #ifndef MINGW32
2606 InitializeXFonts();
2607 #else
2608 MakeRasterFontDefault();
2609 #endif
2610
2611 {
2612 Tcl_DString dstring;
2613 char *buf;
2614
2615 buf = Tcl_ExternalToUtfDString( NULL, initcommands,strlen(initcommands),&dstring);
2616 Tcl_Eval( TCLInterp, buf );
2617 Tcl_DStringFree( &dstring );
2618 }
2619
2620 if ( getenv("ELMER_POST_INIT") )
2621 {
2622 *init = '\0';
2623 strncat( init,getenv("ELMER_POST_INIT"),511);
2624 fprintf( stdout, "User initialization file: [%s]\n", init );
2625 fflush(stdout);
2626 Tcl_EvalFile( TCLInterp,init );
2627 while( Tk_DoOneEvent(TCL_DONT_WAIT) );
2628 }
2629
2630 #ifdef MINGW32
2631 auxMainLoop( (AUXMAINPROC)DrawItSomeTimeWhenIdle );
2632 #else
2633 auxMainLoop(TestTkEvent);
2634 #endif
2635 }
2636