rllib  1
rlsvganimator.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                       rlsvganimator.cpp  -  description
00003                              -------------------
00004     begin                : Tue Apr 10 2006
00005     copyright            : (C) 2006 by Rainer Lehrig
00006     email                : lehrig@t-online.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
00013  *   published by the Free Software Foundation                             *
00014  *                                                                         *
00015  ***************************************************************************/
00016 #include "rlcutil.h"
00017 #include "rlsvganimator.h"
00018 #include "rlsvgcat.h"
00019 #ifndef RLWIN32
00020 #include "rlspawn.h"
00021 #endif
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include <stdarg.h>
00025 #include <stdlib.h>
00026 #include <math.h>
00027 
00028 #ifdef RLWIN32
00029 #include <windows.h>
00030 #include <io.h>
00031 #include <direct.h>
00032 #define  MSG_NOSIGNAL 0
00033 #else
00034 #include <sys/time.h>
00035 #include <sys/socket.h>
00036 #include <netinet/in.h>
00037 #include <arpa/inet.h>
00038 #include <netdb.h>
00039 #include "unistd.h"
00040 #endif
00041 
00042 #ifdef __VMS
00043 #define  MSG_NOSIGNAL 0
00044 #endif
00045 
00046 #ifdef PVMAC
00047 #define  MSG_NOSIGNAL 0
00048 #endif
00049 
00050 #define MAXLINE 256*256
00051 
00052 rlSvgPosition::rlSvgPosition()
00053 {
00054   sx = 1.0f;
00055   alpha = x0 = y0 = cx = cy = 0.0f;
00056   init.sx = init.alpha = init.x0 = init.y0 = init.w = init.h = -1;
00057 }
00058 
00059 rlSvgPosition::rlSvgPosition(float sx_init, float a_init, float x0_init, float y0_init, float w_init, float h_init)
00060 {
00061   sx = 1.0f;
00062   alpha = x0 = y0 = cx = cy = 0.0f;
00063   init.sx = sx_init;
00064   init.alpha = a_init;
00065   init.x0 = x0_init;
00066   init.y0 = y0_init;
00067   init.w = w_init;
00068   init.h = h_init;
00069 }
00070 
00071 rlSvgPosition::~rlSvgPosition()
00072 {
00073 }
00074 
00075 void rlSvgPosition::setInit(float x0_init, float y0_init, float w_init, float h_init)
00076 {
00077   init.x0 = x0_init;
00078   init.y0 = y0_init;
00079   init.w = w_init;
00080   init.h = h_init;
00081 }
00082 
00083 void rlSvgPosition::move(float x, float y)
00084 {
00085   x0 = x;
00086   y0 = y;
00087 }
00088 
00089 void rlSvgPosition::moveRelative(float dx, float dy)
00090 {
00091   x0 += dx;
00092   y0 += dy;
00093 }
00094 
00095 void rlSvgPosition::scale(float s)
00096 {
00097   sx = s;
00098 }
00099 
00100 void rlSvgPosition::scaleRelative(float ds)
00101 {
00102   sx *= ds;
00103 }
00104 
00105 void rlSvgPosition::rotate(float _alpha, float _cx, float _cy)
00106 {
00107   alpha = _alpha;
00108   cx = _cx;
00109   cy = _cy;
00110 }
00111 
00112 
00113 rlSvgAnimator::rlSvgAnimator()
00114 {
00115   s = NULL;
00116   id = 0;
00117   isModified = 1;
00118 
00119   // zoomer follows
00120   svgX0 = svgY0 = 0.0f;
00121   svgScale = 1.0f;
00122   svgWindowWidth  = 640.0f;
00123   svgWindowHeight = 480.0f;
00124   svgMouseX0 = svgMouseY0 = 0.0f;
00125   svgMouseX1 = svgMouseY1 = 0.0f;
00126   main_object_name.setText("main");
00127 }
00128 
00129 rlSvgAnimator::~rlSvgAnimator()
00130 {
00131 }
00132 
00133 int rlSvgAnimator::tcpsend(const char *buf, int len)
00134 {
00135   int ret,bytes_left,first_byte;
00136 
00137   if(s == NULL) return -1;
00138   //rlDebugPrintf("tcpsend len=%d buf=%s",len,buf);
00139   bytes_left = len;
00140   first_byte = 0;
00141   while(bytes_left > 0)
00142   {
00143     if(*s == 1) // use stdout
00144     {
00145 #ifdef __VMS
00146       ret = send(1,&buf[first_byte],bytes_left,MSG_NOSIGNAL);
00147 #else
00148       ret = write(1,&buf[first_byte],bytes_left);
00149 #endif
00150       if(ret <= 0) 
00151       {
00152         *s = -1;
00153         return -1;
00154       }
00155     }
00156     else // use socket
00157     {
00158       ret = send(*s,&buf[first_byte],bytes_left,MSG_NOSIGNAL);
00159       if(ret <= 0) 
00160       {
00161         *s = -1;
00162         return -1;
00163       }
00164     }
00165     bytes_left -= ret;
00166     first_byte += ret;
00167   }
00168   return 0;
00169 }
00170 
00171 int rlSvgAnimator::read(const char *infile, rlIniFile *inifile)
00172 {
00173   isModified = 1;
00174 #ifdef RLUNIX
00175   rlSpawn rlsvg;
00176   int ret, use_stdout;
00177   char command[MAXLINE];
00178   const char *line;
00179 
00180   inifileState = 0;
00181   inifileCount = 0;
00182   if(inifile == NULL) use_stdout = 0;
00183   use_stdout = 0;
00184   if(s != NULL && *s == 1) use_stdout = 1;
00185 
00186   rlDebugPrintf("rlSvgAnimator step=1 infile=%s\n",infile);
00187   if(use_stdout == 0) 
00188   {
00189     sprintf(command,"rlsvgcat %s",infile);
00190     ret = rlsvg.spawn(command);
00191     if(ret < 0) return -1;
00192   }
00193 
00194   rlDebugPrintf("rlSvgAnimator step=2\n");
00195 
00196   if(id != 0 && s != NULL) // new style programming
00197   {
00198     sprintf(command,"gsvgRead(%d)\n",id);
00199     tcpsend(command,strlen(command));
00200     if(use_stdout == 0)
00201     {
00202       while((line = rlsvg.readLine()) != NULL)
00203       {
00204         tcpsend(line,strlen(line));
00205         if(inifile != NULL) fillIniFile(inifile, line);
00206       }
00207     }
00208     else
00209     {
00210       sprintf(command,"/usr/bin/rlsvgcat %s",infile);
00211       ret = system(command);
00212       if(ret == -1) return -1;
00213       if(inifile != NULL) 
00214       {
00215         char outfile[80];
00216         sprintf(outfile,"PVTMP%d.svg",*s);
00217         sprintf(command,"/usr/bin/rlsvgcat %s %s",infile,outfile);
00218         ret = system(command);
00219         if(ret == -1) return -1;
00220         fileFillIniFile(outfile, inifile);
00221         unlink(outfile);
00222       }  
00223     }
00224     sprintf(command,"\n<svgend></svgend>\n");
00225     tcpsend(command,strlen(command));
00226     return 0;
00227   }
00228   else 
00229   {
00230     return -1;
00231   }  
00232 #else
00233   // Windows: use file instead of pipe
00234   FILE *fin;
00235   int  ret;
00236   char filename[1024];
00237   char cmd[1024];
00238   char command[MAXLINE];
00239   char line[MAXLINE];
00240   char *cptr;
00241 
00242   inifileState = 0;
00243   inifileCount = 0;
00244   if(s==NULL) sprintf(filename,"PVTEMP%s",infile);
00245   else        sprintf(filename,"PVTEMP%d%s",*s,infile);
00246   sprintf(cmd,"rlsvgcat %s %s",infile,filename);
00247   ret = system(cmd);
00248   if(ret < 0) return -1;
00249   fin = fopen(filename,"r");
00250   if(fin == NULL) return -1;
00251   sprintf(command,"gsvgRead(%d)\n",id);
00252   tcpsend(command,strlen(command));
00253   while(fgets(line,sizeof(line)-1,fin) != NULL)
00254   {
00255     cptr = strchr(line,0x0d);
00256     if(cptr != NULL) *cptr = '\0';
00257     cptr = strchr(line,0x0a);
00258     if(cptr != NULL) *cptr = '\0';
00259     tcpsend(line,strlen(line));
00260     tcpsend("\n",strlen("\n"));
00261     if(inifile != NULL) fillIniFile(inifile, line);
00262   }
00263   sprintf(command,"\n<svgend></svgend>\n");
00264   tcpsend(command, strlen(command));;
00265   unlink(filename);
00266   return 0;
00267 #endif
00268 }
00269 
00270 int rlSvgAnimator::setSocket(int *socket)
00271 {
00272   isModified = 1;
00273   s = socket;
00274   return 0;
00275 }
00276 
00277 int rlSvgAnimator::setId(int _id)
00278 {
00279   isModified = 1;
00280   id = _id;
00281   return 0;
00282 }
00283 
00284 int rlSvgAnimator::writeSocket()
00285 {
00286   char buf[80];
00287   
00288   isModified = 0;
00289 
00290   if(s == NULL)
00291   {
00292     printf("rlSvgAnimator: ERROR please use setSocket first\n");
00293     return -1;
00294   }
00295   if(id != 0)
00296   {
00297     sprintf(buf,"gupdateSVG(%d)\n",id);
00298     tcpsend(buf, strlen(buf));
00299     return 0;
00300   }
00301   return -1;
00302 }
00303 
00304 #define MAXBUF 1024
00305 
00306 int rlSvgAnimator::svgPrintf(const char *objectname, const char *tag, const char *format, ...)
00307 {
00308   char buf[MAXBUF+40];
00309   char text[MAXBUF];
00310   int  len = strlen(objectname);
00311 
00312   isModified = 1;
00313   if(id != 0)
00314   {
00315     sprintf(buf,"gsvgPrintf(%d)\n",id);
00316     tcpsend(buf, strlen(buf));
00317     sprintf(buf,"%s\n",objectname);
00318     tcpsend(buf, strlen(buf));
00319     sprintf(buf,"%s\n",tag);
00320     tcpsend(buf, strlen(buf));
00321     va_list ap;
00322     va_start(ap,format);
00323 #ifdef RLWIN32
00324     _vsnprintf(text, MAXBUF - 1, format, ap);
00325 #endif
00326 #ifdef __VMS
00327     vsprintf(text, format, ap);
00328 #endif
00329 #ifdef RLUNIX
00330     vsnprintf(text, MAXBUF - 1, format, ap);
00331 #endif
00332     va_end(ap);
00333     strcat(text,"\n");
00334     len = strlen(text);
00335     tcpsend(text, len);
00336     return len;
00337   }
00338   return -1;
00339 }
00340 
00341 int rlSvgAnimator::svgRecursivePrintf(const char *objectname, const char *tag, const char *format, ...)
00342 {
00343   char buf[MAXBUF+40];
00344   char text[MAXBUF];
00345   int  len;
00346 
00347   isModified = 1;
00348   sprintf(buf,"gsvgRecursivePrintf(%d)\n",id);
00349   tcpsend(buf, strlen(buf));
00350   sprintf(buf,"%s\n",objectname);
00351   tcpsend(buf, strlen(buf));
00352   sprintf(buf,"%s\n",tag);
00353   tcpsend(buf, strlen(buf));
00354   va_list ap;
00355   va_start(ap,format);
00356 #ifdef RLWIN32
00357   _vsnprintf(text, MAXBUF - 1, format, ap);
00358 #endif
00359 #ifdef __VMS
00360   vsprintf(text, format, ap);
00361 #endif
00362 #ifdef RLUNIX
00363   vsnprintf(text, MAXBUF - 1, format, ap);
00364 #endif
00365   va_end(ap);
00366   strcat(text,"\n");
00367   len = strlen(text);
00368   tcpsend(text, len);
00369   return len;
00370 }
00371 
00372 int rlSvgAnimator::svgSearchAndReplace(const char *objectname, const char *tag, const char *before, const char *after)
00373 {
00374   char buf[MAXBUF+40];
00375 
00376   isModified = 1;
00377   sprintf(buf,"gsvgSearchAndReplace(%d)\n",id);
00378   tcpsend(buf, strlen(buf));
00379   sprintf(buf,"%s\n",objectname);
00380   tcpsend(buf, strlen(buf));
00381   sprintf(buf,"%s\n",tag);
00382   tcpsend(buf, strlen(buf));
00383   sprintf(buf,"%s\n",before);
00384   tcpsend(buf, strlen(buf));
00385   sprintf(buf,"%s\n",after);
00386   tcpsend(buf, strlen(buf));
00387   return 0;
00388 }
00389 
00390 int rlSvgAnimator::svgRecursiveSearchAndReplace(const char *objectname, const char *tag, const char *before, const char *after)
00391 {
00392   char buf[MAXBUF+40];
00393 
00394   isModified = 1;
00395   sprintf(buf,"gsvgRecursiveSearchAndReplace(%d)\n",id);
00396   tcpsend(buf, strlen(buf));
00397   sprintf(buf,"%s\n",objectname);
00398   tcpsend(buf, strlen(buf));
00399   sprintf(buf,"%s\n",tag);
00400   tcpsend(buf, strlen(buf));
00401   sprintf(buf,"%s\n",before);
00402   tcpsend(buf, strlen(buf));
00403   sprintf(buf,"%s\n",after);
00404   tcpsend(buf, strlen(buf));
00405   return 0;
00406 }
00407 
00408 int rlSvgAnimator::svgTextPrintf(const char *objectname, const char *format, ...)
00409 {
00410   char buf[MAXBUF+40];
00411   char text[MAXBUF];
00412   int  len = strlen(objectname);
00413 
00414   isModified = 1;
00415   if(id != 0)
00416   {
00417     sprintf(buf,"gsvgTextPrintf(%d)\n",id);
00418     tcpsend(buf, strlen(buf));
00419     sprintf(buf,"%s\n",objectname);
00420     tcpsend(buf, strlen(buf));
00421     va_list ap;
00422     va_start(ap,format);
00423 #ifdef RLWIN32
00424     _vsnprintf(text, MAXBUF - 1, format, ap);
00425 #endif
00426 #ifdef __VMS
00427     vsprintf(text, format, ap);
00428 #endif
00429 #ifdef RLUNIX
00430     vsnprintf(text, MAXBUF - 1, format, ap);
00431 #endif
00432     va_end(ap);
00433     strcat(text,"\n");
00434     len = strlen(text);
00435     tcpsend(text, len);
00436     return len;
00437   }
00438   return -1;
00439 }
00440 
00441 int rlSvgAnimator::svgRemoveStyleOption(const char *objectname, const char *option)
00442 {
00443   char buf[MAXBUF+40];
00444 
00445   isModified = 1;
00446   sprintf(buf,"gsvgRemoveStyleOption(%d)\n",id);
00447   tcpsend(buf, strlen(buf));
00448   sprintf(buf,"%s\n",objectname);
00449   tcpsend(buf, strlen(buf));
00450   sprintf(buf,"%s\n","style=");
00451   tcpsend(buf, strlen(buf));
00452   sprintf(buf,"%s\n",option);
00453   tcpsend(buf, strlen(buf));
00454   return 0;
00455 }
00456 
00457 int rlSvgAnimator::svgRecursiveRemoveStyleOption(const char *objectname, const char *option)
00458 {
00459   char buf[MAXBUF+40];
00460 
00461   isModified = 1;
00462   sprintf(buf,"gsvgRecursiveRemoveStyleOption(%d)\n",id);
00463   tcpsend(buf, strlen(buf));
00464   sprintf(buf,"%s\n",objectname);
00465   tcpsend(buf, strlen(buf));
00466   sprintf(buf,"%s\n","style=");
00467   tcpsend(buf, strlen(buf));
00468   sprintf(buf,"%s\n",option);
00469   tcpsend(buf, strlen(buf));
00470   return 0;
00471 }
00472 
00473 int rlSvgAnimator::svgChangeStyleOption(const char *objectname, const char *option, const char *value)
00474 {
00475   char buf[MAXBUF+40];
00476 
00477   isModified = 1;
00478   sprintf(buf,"gsvgChangeStyleOption(%d)\n",id);
00479   tcpsend(buf, strlen(buf));
00480   sprintf(buf,"%s\n",objectname);
00481   tcpsend(buf, strlen(buf));
00482   sprintf(buf,"%s\n","style=");
00483   tcpsend(buf, strlen(buf));
00484   sprintf(buf,"%s\n",option);
00485   tcpsend(buf, strlen(buf));
00486   sprintf(buf,"%s\n",value);
00487   tcpsend(buf, strlen(buf));
00488   return 0;
00489 }
00490 
00491 int rlSvgAnimator::svgRecursiveChangeStyleOption(const char *objectname, const char *option, const char *value)
00492 {
00493   char buf[MAXBUF+40];
00494 
00495   isModified = 1;
00496   sprintf(buf,"gsvgRecursiveChangeStyleOption(%d)\n",id);
00497   tcpsend(buf, strlen(buf));
00498   sprintf(buf,"%s\n",objectname);
00499   tcpsend(buf, strlen(buf));
00500   sprintf(buf,"%s\n","style=");
00501   tcpsend(buf, strlen(buf));
00502   sprintf(buf,"%s\n",option);
00503   tcpsend(buf, strlen(buf));
00504   sprintf(buf,"%s\n",value);
00505   tcpsend(buf, strlen(buf));
00506   return 0;
00507 }
00508 
00509 int rlSvgAnimator::svgSetStyleOption(const char *objectname, const char *value)
00510 {
00511   char buf[MAXBUF+40];
00512 
00513   isModified = 1;
00514   sprintf(buf,"gsvgSetStyleOption(%d)\n",id);
00515   tcpsend(buf, strlen(buf));
00516   sprintf(buf,"%s\n",objectname);
00517   tcpsend(buf, strlen(buf));
00518   sprintf(buf,"%s\n","style=");
00519   tcpsend(buf, strlen(buf));
00520   sprintf(buf,"%s\n",value);
00521   tcpsend(buf, strlen(buf));
00522   return 0;
00523 }
00524 
00525 int rlSvgAnimator::svgRecursiveSetStyleOption(const char *objectname, const char *value)
00526 {
00527   char buf[MAXBUF+40];
00528 
00529   isModified = 1;
00530   sprintf(buf,"gsvgRecursiveSetStyleOption(%d)\n",id);
00531   tcpsend(buf, strlen(buf));
00532   sprintf(buf,"%s\n",objectname);
00533   tcpsend(buf, strlen(buf));
00534   sprintf(buf,"%s\n","style=");
00535   tcpsend(buf, strlen(buf));
00536   sprintf(buf,"%s\n",value);
00537   tcpsend(buf, strlen(buf));
00538   return 0;
00539 }
00540 
00541 int rlSvgAnimator::show(const char *objectname, int state)
00542 {
00543   rlDebugPrintf("rlSvgAnimator.show state=%d objectname=%s\n",state,objectname);
00544   isModified = 1;
00545   if(id != 0)
00546   {
00547     char buf[MAXLINE];
00548     sprintf(buf,"gsvgShow(%d,%d)\n",id,state);
00549     printf("buf=%s",buf);
00550     tcpsend(buf, strlen(buf));
00551     sprintf(buf,"%s\n",objectname);
00552     tcpsend(buf, strlen(buf));
00553     return 0;
00554   }
00555   return -1;
00556 }
00557 
00558 int rlSvgAnimator::setMatrix(const char *objectname, rlSvgPosition &pos)
00559 {
00560   isModified = 1;
00561   return setMatrix(objectname, pos.sx, pos.alpha, pos.x0, pos.y0, pos.cx, pos.cy);
00562 }
00563 
00564 int rlSvgAnimator::setMatrix(const char *objectname, float sx, float alpha, float x0, float y0, float cx_in, float cy_in)
00565 {
00566   // sx    = scale x
00567   // alpha = rotation
00568   // x0,y0 = tranlation
00569   // cx,cy = rotation center
00570   //
00571   // matrix:
00572   // a11 a12 a13
00573   // a21 a22 a23
00574   // a31 a32 a33
00575 
00576   float a11, a12, a13, a21, a22, a23, a31, a32, a33, cx, cy;
00577 
00578   isModified = 1;
00579   cx = cx_in + x0;
00580   cy = cy_in + y0;
00581 
00582   a11 = sx*((float) cos(alpha));
00583   a12 = -sx*((float) sin(alpha));
00584   a13 = (x0 - cx)*((float) cos(alpha)) - (y0 - cy)*((float) sin(alpha)) + cx;
00585   a21 = sx*((float) sin(alpha));
00586   a22 = sx*((float) cos(alpha));
00587   a23 = (x0 - cx)*((float) sin(alpha)) + (y0 - cy)*((float) cos(alpha)) + cy;
00588   a31 = 0.0f;
00589   a32 = 0.0f;
00590   a33 = 1.0f;
00591 
00592   return svgPrintf(objectname,"transform=","matrix(%f,%f,%f,%f,%f,%f)",a11,a21,a12,a22,a13,a23);
00593 
00594 /*********************************************************************************************
00595 
00596 Definition
00597 CTM := CurrentTransformationMatrix
00598 t   := translate
00599 r   := rotate
00600 s   := scale
00601 
00602 Equotiation
00603 CTM = t(cx,cy)*r(a)*t(-cx,-cy)*t(x0,y0)*s(sx)
00604 
00605       |1 0 cx| |cos(a) -sin(a) 0| |1 0 -cx| |1 0 x0| |sx 0  0|
00606 CTM = |0 1 cy|*|sin(a)  cos(a) 0|*|0 1 -cy|*|0 1 y0|*|0  sx 0|                            # OK
00607       |0 0 1 | |  0       0    1| |0 0  1 | |0 0 1 | |0  0  1|
00608 
00609       |1 0 cx| |cos(a) -sin(a) 0| |1 0 -cx| |sx 0  x0|
00610 CTM = |0 1 cy|*|sin(a)  cos(a) 0|*|0 1 -cy|*|0  sx y0|                                    # OK
00611       |0 0 1 | |  0       0    1| |0 0  1 | |0  0  1 |
00612 
00613       |1 0 cx| |cos(a) -sin(a) 0| |sx 0  x0-cx|
00614 CTM = |0 1 cy|*|sin(a)  cos(a) 0|*|0  sx y0-cy|                                           # OK
00615       |0 0 1 | |  0       0    1| |0  0  1    |
00616 
00617       |1 0 cx| |sx*cos(a) -sx*sin(a) (x0-cx)*cos(a)-(y0-cy)*sin(a)|
00618 CTM = |0 1 cy|*|sx*sin(a)  sx*cos(a) (x0-cx)*sin(a)+(y0-cy)*cos(a)|                       # OK
00619       |0 0 1 | |  0          0                        1           |
00620 
00621       |sx*cos(a) -sx*sin(a) (x0-cx)*cos(a)-(y0-cy)*sin(a)+cx|
00622 CTM = |sx*sin(a)  sx*cos(a) (x0-cx)*sin(a)+(y0-cy)*cos(a)+cy|                             # OK
00623       |  0          0                     1                 |
00624 
00625 Check
00626 with sx = 1 and a,x0,y0,cx,cy = 0
00627 
00628       |1 0 0|
00629 CTM = |0 1 0|                                                                             # OK
00630       |0 0 1|
00631 
00632 |x'|         |x|   |sx*cos(a)*x-sx*sin(a)*y+(x0-cx)*cos(a)-(y0-cy)*sin(a)+cx|   |1*x-0*y|
00633 |y'| = CTM * |y| = |sx*sin(a)*x+sx*cos(a)*y+(x0-cx)*sin(a)+(y0-cy)*cos(a)+cy| = |0*x+1*y| # OK
00634 |0 |         |0|   |                       0                                |   |   0   |
00635 
00636 **********************************************************************************************/
00637 }
00638 
00639 int rlSvgAnimator::fillIniFile(rlIniFile *inifile, const char *line)
00640 {
00641   char myline[MAXLINE],*cptr, *cptr2;
00642   const char *id;
00643   int i;
00644 
00645   strcpy(myline,line);
00646   cptr = strchr(myline,'\n');
00647   if(cptr != NULL) *cptr = '\0';
00648 
00649   if(myline[0] == '>' || strncmp(myline,"/>",2) == 0)
00650   { // end of data -> fill inifile
00651     if(inifileState == 1) // if id was found
00652     {
00653       for(i=0; i<inifileCount; i++)
00654       {
00655         id = inifileID.text();
00656         inifile->setText(id, inifileTable.text(1,i+1), inifileTable.text(2,i+1));
00657       }
00658     }
00659     inifileState = 0;
00660     inifileCount = 0;
00661     inifileID.clear();
00662     inifileTable.clear();
00663   }
00664   else if(myline[0] == '<')
00665   { // ignore this
00666   }
00667   else if(strncmp(myline,"id=",3) == 0)
00668   { // remenber id
00669     cptr = strchr(myline,'=');
00670     if(cptr != NULL)
00671     {
00672       cptr++; cptr++;
00673       cptr2 = strchr(cptr,'\"');
00674       if(cptr2 != NULL) *cptr2 = '\0';
00675       inifileID.setText(cptr);
00676       inifileState = 1; // id was found
00677     }
00678   }
00679   else
00680   { // fill this in table
00681     cptr = strchr(myline,'=');
00682     if(cptr != NULL)
00683     {
00684       *cptr = '\0';
00685       cptr++; cptr++;
00686       cptr2 = strrchr(cptr,'\"');
00687       if(cptr2 != NULL) *cptr2 = '\0';
00688       inifileTable.setText(1,inifileCount+1,myline);
00689       inifileTable.setText(2,inifileCount+1,cptr);
00690       inifileCount++;
00691     }
00692   }
00693 
00694   return 0;
00695 }
00696 
00697 int rlSvgAnimator::fileFillIniFile(const char *infile, rlIniFile *inifile)
00698 {
00699   char line[MAXLINE];
00700   FILE *fin;
00701 
00702   fin = fopen(infile,"r");
00703   if(fin == NULL) return -1;
00704   while(fgets(line,sizeof(line)-1,fin) != NULL)
00705   {
00706     fillIniFile(inifile, line);
00707   }
00708   fclose(fin);
00709   return 0;
00710 }
00711 
00712 // zoomer methods follows
00713 
00714 int rlSvgAnimator::setMainObject(const char *main_object)
00715 {
00716   isModified = 1;
00717   if(main_object == NULL) return -1; 
00718   main_object_name.setText(main_object);
00719   return 0;
00720 }
00721 
00722 const char *rlSvgAnimator::mainObject()
00723 {
00724   return main_object_name.text();
00725 }
00726 
00727 int rlSvgAnimator::setXY0(float x0, float y0)
00728 {
00729   isModified = 1;
00730   svgX0 = x0;
00731   svgY0 = y0;
00732   return 0;
00733 }
00734 
00735 float rlSvgAnimator::x0()
00736 {
00737   return svgX0;
00738 }
00739 
00740 float rlSvgAnimator::y0()
00741 {
00742   return svgY0;
00743 }
00744 
00745 int rlSvgAnimator::setMouseXY0(float x0, float y0)
00746 {
00747   isModified = 1;
00748   svgMouseX0 = x0;
00749   svgMouseY0 = y0;
00750   return 0;
00751 }
00752 
00753 float rlSvgAnimator::mouseX0()
00754 {
00755   return svgMouseX0;
00756 }
00757 
00758 float rlSvgAnimator::mouseY0()
00759 {
00760   return svgMouseY0;
00761 }
00762 
00763 int rlSvgAnimator::setMouseXY1(float x1, float y1)
00764 {
00765   isModified = 1;
00766   svgMouseX1 = x1;
00767   svgMouseY1 = y1;
00768   return 0;
00769 }
00770 
00771 float rlSvgAnimator::mouseX1()
00772 {
00773   return svgMouseX1;
00774 }
00775 
00776 float rlSvgAnimator::mouseY1()
00777 {
00778   return svgMouseY1;
00779 }
00780 
00781 int rlSvgAnimator::setScale(float scale)
00782 {
00783   isModified = 1;
00784   svgScale = scale;
00785   return 0;
00786 }
00787 
00788 float rlSvgAnimator::scale()
00789 {
00790   return svgScale;
00791 }
00792 
00793 int rlSvgAnimator::zoomCenter(float newScale)
00794 {
00795   float oldX0, oldY0;
00796 
00797   isModified = 1;
00798   if (newScale > 1000) newScale = 1000.0f;
00799 
00800   oldX0 = (svgX0 - ((svgWindowWidth) * (1.0f - svgScale)) / 2.0f) / svgScale;
00801   oldY0 = (svgY0 - ((svgWindowHeight) * (1.0f - svgScale)) / 2.0f) / svgScale;
00802 
00803   svgScale  = newScale;
00804 
00805   svgX0 = oldX0*svgScale + ((svgWindowWidth) * (1.0f - svgScale)) / 2.0f;
00806   svgY0 = oldY0*svgScale + ((svgWindowHeight) * (1.0f - svgScale)) / 2.0f;
00807 
00808   return 0;
00809 }
00810 
00811 int rlSvgAnimator::zoomRect()
00812 {
00813   float newScale, scale1, scale2, rectWidth, rectHeight;
00814 
00815   isModified = 1;
00816   rectWidth  = svgMouseX1-svgMouseX0;
00817   rectHeight = svgMouseY1-svgMouseY0;
00818   svgX0 = svgX0 + svgWindowWidth/2  - (svgMouseX0 + rectWidth/2);
00819   svgY0 = svgY0 + svgWindowHeight/2 - (svgMouseY0 + rectHeight/2);
00820   rectWidth  = rectWidth  / svgScale;
00821   rectHeight = rectHeight / svgScale;
00822   scale1 = svgWindowWidth  / rectWidth;
00823   scale2 = svgWindowHeight / rectHeight;
00824 
00825   if(scale1 < scale2) newScale = scale1;
00826   else                newScale = scale2;
00827   zoomCenter(newScale);
00828 
00829   return 0;
00830 }
00831 
00832 int rlSvgAnimator::setMainObjectMatrix()
00833 {
00834   isModified = 1;
00835   setMatrix(main_object_name.text(), svgScale, 0.0f, svgX0, svgY0, 0.0f, 0.0f);
00836   return 0;
00837 }
00838 
00839 int rlSvgAnimator::setWindowSize(int width, int height)
00840 {
00841   isModified = 1;
00842   svgWindowWidth  = (float) width;
00843   svgWindowHeight = (float) height;
00844   return 0;
00845 }
00846 
00847 float rlSvgAnimator::windowWidth()
00848 {
00849   return svgWindowWidth;
00850 }
00851 
00852 float rlSvgAnimator::windowHeight()
00853 {
00854   return svgWindowHeight;
00855 }
00856 
00857 int rlSvgAnimator::moveMainObject(float x, float y)
00858 {
00859   isModified = 1;
00860   float xx0 = x0() + (x - mouseX0());
00861   float yy0 = y0() + (y - mouseY0());
00862   setXY0(xx0,yy0);
00863   setMainObjectMatrix();
00864   return 0;
00865 }
00866 
00867 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines