rllib  1
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
rlSvgAnimator Class Reference

#include <rlsvganimator.h>

Collaboration diagram for rlSvgAnimator:
Collaboration graph
[legend]

Public Member Functions

 rlSvgAnimator ()
 
virtual ~rlSvgAnimator ()
 
int setSocket (int *socket)
 
int setId (int Id)
 
int read (const char *infile, rlIniFile *inifile=NULL)
 
int writeSocket ()
 The following methods are for modifying a object within a SVG graphic identified by objectname. More...
 
int svgPrintf (const char *objectname, const char *tag, const char *format,...)
 
int svgRecursivePrintf (const char *objectname, const char *tag, const char *format,...)
 
int svgSearchAndReplace (const char *objectname, const char *tag, const char *before, const char *after)
 
int svgRecursiveSearchAndReplace (const char *objectname, const char *tag, const char *before, const char *after)
 
int svgTextPrintf (const char *objectname, const char *format,...)
 
int svgRemoveStyleOption (const char *objectname, const char *option)
 
int svgRecursiveRemoveStyleOption (const char *objectname, const char *option)
 
int svgChangeStyleOption (const char *objectname, const char *option, const char *value)
 
int svgRecursiveChangeStyleOption (const char *objectname, const char *option, const char *value)
 
int svgSetStyleOption (const char *objectname, const char *value)
 
int svgRecursiveSetStyleOption (const char *objectname, const char *value)
 
int show (const char *objectname, int state)
 
int setMatrix (const char *objectname, float sx, float alpha, float x0, float y0, float cx, float cy)
 
int setMatrix (const char *objectname, rlSvgPosition &pos)
 The following methods are for moveing and zooming the whole SVG identified by mainObject. default: main. More...
 
int setMainObject (const char *main_object)
 
const char * mainObject ()
 
int setXY0 (float x0, float y0)
 
float x0 ()
 
float y0 ()
 
int setMouseXY0 (float x0, float y0)
 
float mouseX0 ()
 
float mouseY0 ()
 
int setMouseXY1 (float x1, float y1)
 
float mouseX1 ()
 
float mouseY1 ()
 
int setScale (float scale)
 
float scale ()
 
int zoomCenter (float newScale)
 
int zoomRect ()
 
int setMainObjectMatrix ()
 
int setWindowSize (int width, int height)
 
float windowWidth ()
 
float windowHeight ()
 
int moveMainObject (float x, float y)
 

Public Attributes

int isModified
 

Private Member Functions

int tcpsend (const char *buf, int len)
 
int fillIniFile (rlIniFile *inifile, const char *line)
 
int fileFillIniFile (const char *infile, rlIniFile *inifile)
 

Private Attributes

int inifileState
 
int inifileCount
 
rlSpreadsheetCell inifileID
 
rlSpreadsheetTable inifileTable
 
int * s
 
int id
 
float svgX0
 
float svgY0
 
float svgWindowWidth
 
float svgWindowHeight
 
float svgScale
 
float svgMouseX0
 
float svgMouseY0
 
float svgMouseX1
 
float svgMouseY1
 
rlString main_object_name
 

Detailed Description

This class allows you to animate SVG graphics within pvbrowser.
First the SVG is send to pvbrowser.
Then you may modify the SVG within the pvbrowser client.

Definition at line 48 of file rlsvganimator.h.

Constructor & Destructor Documentation

◆ rlSvgAnimator()

rlSvgAnimator::rlSvgAnimator ( )

Definition at line 113 of file rlsvganimator.cpp.

114 {
115  s = NULL;
116  id = 0;
117  isModified = 1;
118 
119  // zoomer follows
120  svgX0 = svgY0 = 0.0f;
121  svgScale = 1.0f;
122  svgWindowWidth = 640.0f;
123  svgWindowHeight = 480.0f;
124  svgMouseX0 = svgMouseY0 = 0.0f;
125  svgMouseX1 = svgMouseY1 = 0.0f;
126  main_object_name.setText("main");
127 }
float svgWindowHeight
int setText(const char *text)
Definition: rlstring.cpp:136
float svgWindowWidth
rlString main_object_name

◆ ~rlSvgAnimator()

rlSvgAnimator::~rlSvgAnimator ( )
virtual

Definition at line 129 of file rlsvganimator.cpp.

130 {
131 }

Member Function Documentation

◆ fileFillIniFile()

int rlSvgAnimator::fileFillIniFile ( const char *  infile,
rlIniFile inifile 
)
private

Definition at line 698 of file rlsvganimator.cpp.

699 {
700  char line[MAXLINE];
701  FILE *fin;
702 
703  fin = fopen(infile,"r");
704  if(fin == NULL) return -1;
705  while(fgets(line,sizeof(line)-1,fin) != NULL)
706  {
707  fillIniFile(inifile, line);
708  }
709  fclose(fin);
710  return 0;
711 }
int fillIniFile(rlIniFile *inifile, const char *line)
#define MAXLINE

◆ fillIniFile()

int rlSvgAnimator::fillIniFile ( rlIniFile inifile,
const char *  line 
)
private

Definition at line 640 of file rlsvganimator.cpp.

641 {
642  char myline[MAXLINE],*cptr, *cptr2;
643  const char *id;
644  int i;
645 
646  strcpy(myline,line);
647  cptr = strchr(myline,'\n');
648  if(cptr != NULL) *cptr = '\0';
649 
650  if(myline[0] == '>' || strncmp(myline,"/>",2) == 0)
651  { // end of data -> fill inifile
652  if(inifileState == 1) // if id was found
653  {
654  for(i=0; i<inifileCount; i++)
655  {
656  id = inifileID.text();
657  inifile->setText(id, inifileTable.text(1,i+1), inifileTable.text(2,i+1));
658  }
659  }
660  inifileState = 0;
661  inifileCount = 0;
662  inifileID.clear();
664  }
665  else if(myline[0] == '<')
666  { // ignore this
667  }
668  else if(strncmp(myline,"id=",3) == 0)
669  { // remenber id
670  cptr = strchr(myline,'=');
671  if(cptr != NULL)
672  {
673  cptr++; cptr++;
674  cptr2 = strchr(cptr,'\"');
675  if(cptr2 != NULL) *cptr2 = '\0';
676  inifileID.setText(cptr);
677  inifileState = 1; // id was found
678  }
679  }
680  else
681  { // fill this in table
682  cptr = strchr(myline,'=');
683  if(cptr != NULL)
684  {
685  *cptr = '\0';
686  cptr++; cptr++;
687  cptr2 = strrchr(cptr,'\"');
688  if(cptr2 != NULL) *cptr2 = '\0';
689  inifileTable.setText(1,inifileCount+1,myline);
691  inifileCount++;
692  }
693  }
694 
695  return 0;
696 }
const char * text(int column, int row)
void setText(int column, int row, const char *text)
rlSpreadsheetTable inifileTable
const char * text()
void setText(const char *section, const char *name, const char *text)
Definition: rlinifile.cpp:234
#define MAXLINE
void setText(const char *text)
rlSpreadsheetCell inifileID

◆ mainObject()

const char * rlSvgAnimator::mainObject ( )

Definition at line 723 of file rlsvganimator.cpp.

724 {
725  return main_object_name.text();
726 }
char * text()
Definition: rlstring.cpp:126
rlString main_object_name

◆ mouseX0()

float rlSvgAnimator::mouseX0 ( )

Definition at line 754 of file rlsvganimator.cpp.

755 {
756  return svgMouseX0;
757 }

◆ mouseX1()

float rlSvgAnimator::mouseX1 ( )

Definition at line 772 of file rlsvganimator.cpp.

773 {
774  return svgMouseX1;
775 }

◆ mouseY0()

float rlSvgAnimator::mouseY0 ( )

Definition at line 759 of file rlsvganimator.cpp.

760 {
761  return svgMouseY0;
762 }

◆ mouseY1()

float rlSvgAnimator::mouseY1 ( )

Definition at line 777 of file rlsvganimator.cpp.

778 {
779  return svgMouseY1;
780 }

◆ moveMainObject()

int rlSvgAnimator::moveMainObject ( float  x,
float  y 
)

move MainObject to position

Definition at line 858 of file rlsvganimator.cpp.

859 {
860  isModified = 1;
861  float xx0 = x0() + (x - mouseX0());
862  float yy0 = y0() + (y - mouseY0());
863  setXY0(xx0,yy0);
865  return 0;
866 }
int setXY0(float x0, float y0)
int setMainObjectMatrix()

◆ read()

int rlSvgAnimator::read ( const char *  infile,
rlIniFile inifile = NULL 
)

read SVG file infile and load it into the pvbrowser client. if inifile is given inifile will be set with properties within the SVG XML file. The id's of the SVG objects will result in section names of the inifile.

Definition at line 171 of file rlsvganimator.cpp.

172 {
173  isModified = 1;
174 #ifdef RLUNIX
175  rlSpawn rlsvg;
176  int ret, use_stdout;
177  char command[MAXLINE];
178  const char *line;
179 
180  inifileState = 0;
181  inifileCount = 0;
182  if(inifile == NULL) use_stdout = 0;
183  use_stdout = 0;
184  if(s != NULL && *s == 1) use_stdout = 1;
185 
186  rlDebugPrintf("rlSvgAnimator step=1 infile=%s\n",infile);
187  if(use_stdout == 0)
188  {
189  sprintf(command,"rlsvgcat %s",infile);
190  ret = rlsvg.spawn(command);
191  if(ret < 0) return -1;
192  }
193 
194  rlDebugPrintf("rlSvgAnimator step=2\n");
195 
196  if(id != 0 && s != NULL) // new style programming
197  {
198  sprintf(command,"gsvgRead(%d)\n",id);
199  tcpsend(command,strlen(command));
200  if(use_stdout == 0)
201  {
202  while((line = rlsvg.readLine()) != NULL)
203  {
204  tcpsend(line,strlen(line));
205  if(inifile != NULL) fillIniFile(inifile, line);
206  }
207  }
208  else
209  {
210  sprintf(command,"/usr/bin/rlsvgcat %s",infile);
211  ret = system(command);
212  if(ret == -1) return -1;
213  if(inifile != NULL)
214  {
215  char outfile[80];
216  sprintf(outfile,"PVTMP%d.svg",*s);
217  sprintf(command,"/usr/bin/rlsvgcat %s %s",infile,outfile);
218  ret = system(command);
219  if(ret == -1) return -1;
220  fileFillIniFile(outfile, inifile);
221  unlink(outfile);
222  }
223  }
224  sprintf(command,"\n<svgend></svgend>\n");
225  tcpsend(command,strlen(command));
226  return 0;
227  }
228  else
229  {
230  return -1;
231  }
232 #else
233  // Windows: use file instead of pipe
234  FILE *fin;
235  int ret;
236  char filename[1024];
237  char cmd[1024];
238  char command[MAXLINE];
239  char line[MAXLINE];
240  char *cptr;
241 
242  inifileState = 0;
243  inifileCount = 0;
244  if(s==NULL) sprintf(filename,"PVTEMP%s",infile);
245  else sprintf(filename,"PVTEMP%d%s",*s,infile);
246  sprintf(cmd,"rlsvgcat %s %s",infile,filename);
247  ret = system(cmd);
248  if(ret < 0) return -1;
249  fin = fopen(filename,"r");
250  if(fin == NULL) return -1;
251  sprintf(command,"gsvgRead(%d)\n",id);
252  tcpsend(command,strlen(command));
253  while(fgets(line,sizeof(line)-1,fin) != NULL)
254  {
255  cptr = strchr(line,0x0d);
256  if(cptr != NULL) *cptr = '\0';
257  cptr = strchr(line,0x0a);
258  if(cptr != NULL) *cptr = '\0';
259  tcpsend(line,strlen(line));
260  tcpsend("\n",strlen("\n"));
261  if(inifile != NULL) fillIniFile(inifile, line);
262  }
263  sprintf(command,"\n<svgend></svgend>\n");
264  tcpsend(command, strlen(command));;
265  unlink(filename);
266  return 0;
267 #endif
268 }
int rlDebugPrintf(const char *format,...)
Definition: rlcutil.cpp:61
int tcpsend(const char *buf, int len)
int fillIniFile(rlIniFile *inifile, const char *line)
#define MAXLINE
const char * readLine()
Definition: rlspawn.cpp:307
int fileFillIniFile(const char *infile, rlIniFile *inifile)
int spawn(const char *command)
Definition: rlspawn.cpp:168

◆ scale()

float rlSvgAnimator::scale ( )

Definition at line 789 of file rlsvganimator.cpp.

790 {
791  return svgScale;
792 }

◆ setId()

int rlSvgAnimator::setId ( int  Id)

initialize the id with the pvbrowser object id

Definition at line 277 of file rlsvganimator.cpp.

278 {
279  isModified = 1;
280  id = _id;
281  return 0;
282 }

◆ setMainObject()

int rlSvgAnimator::setMainObject ( const char *  main_object)

set/get the name of the MainObject . The object name holding the whole SVG graphic. default: main

Definition at line 715 of file rlsvganimator.cpp.

716 {
717  isModified = 1;
718  if(main_object == NULL) return -1;
719  main_object_name.setText(main_object);
720  return 0;
721 }
int setText(const char *text)
Definition: rlstring.cpp:136
rlString main_object_name

◆ setMainObjectMatrix()

int rlSvgAnimator::setMainObjectMatrix ( )

sets the MainObject matrix according to scale,x0,y0

Definition at line 833 of file rlsvganimator.cpp.

834 {
835  isModified = 1;
836  setMatrix(main_object_name.text(), svgScale, 0.0f, svgX0, svgY0, 0.0f, 0.0f);
837  return 0;
838 }
char * text()
Definition: rlstring.cpp:126
int setMatrix(const char *objectname, float sx, float alpha, float x0, float y0, float cx, float cy)
rlString main_object_name

◆ setMatrix() [1/2]

int rlSvgAnimator::setMatrix ( const char *  objectname,
float  sx,
float  alpha,
float  x0,
float  y0,
float  cx,
float  cy 
)

set transformation matrix of object

Definition at line 564 of file rlsvganimator.cpp.

565 {
566  // sx = scale x
567  // alpha = rotation
568  // x0,y0 = tranlation
569  // cx,cy = rotation center
570  //
571  // matrix:
572  // a11 a12 a13
573  // a21 a22 a23
574  // a31 a32 a33
575 
576  float a11, a12, a13, a21, a22, a23; // a31, a32, a33;
577  float cx, cy;
578 
579  isModified = 1;
580  cx = cx_in + x0;
581  cy = cy_in + y0;
582 
583  a11 = sx*((float) cos(alpha));
584  a12 = -sx*((float) sin(alpha));
585  a13 = (x0 - cx)*((float) cos(alpha)) - (y0 - cy)*((float) sin(alpha)) + cx;
586  a21 = sx*((float) sin(alpha));
587  a22 = sx*((float) cos(alpha));
588  a23 = (x0 - cx)*((float) sin(alpha)) + (y0 - cy)*((float) cos(alpha)) + cy;
589  //a31 = 0.0f;
590  //a32 = 0.0f;
591  //a33 = 1.0f;
592 
593  return svgPrintf(objectname,"transform=","matrix(%f,%f,%f,%f,%f,%f)",a11,a21,a12,a22,a13,a23);
594 
595 /*********************************************************************************************
596 
597 Definition
598 CTM := CurrentTransformationMatrix
599 t := translate
600 r := rotate
601 s := scale
602 
603 Equotiation
604 CTM = t(cx,cy)*r(a)*t(-cx,-cy)*t(x0,y0)*s(sx)
605 
606  |1 0 cx| |cos(a) -sin(a) 0| |1 0 -cx| |1 0 x0| |sx 0 0|
607 CTM = |0 1 cy|*|sin(a) cos(a) 0|*|0 1 -cy|*|0 1 y0|*|0 sx 0| # OK
608  |0 0 1 | | 0 0 1| |0 0 1 | |0 0 1 | |0 0 1|
609 
610  |1 0 cx| |cos(a) -sin(a) 0| |1 0 -cx| |sx 0 x0|
611 CTM = |0 1 cy|*|sin(a) cos(a) 0|*|0 1 -cy|*|0 sx y0| # OK
612  |0 0 1 | | 0 0 1| |0 0 1 | |0 0 1 |
613 
614  |1 0 cx| |cos(a) -sin(a) 0| |sx 0 x0-cx|
615 CTM = |0 1 cy|*|sin(a) cos(a) 0|*|0 sx y0-cy| # OK
616  |0 0 1 | | 0 0 1| |0 0 1 |
617 
618  |1 0 cx| |sx*cos(a) -sx*sin(a) (x0-cx)*cos(a)-(y0-cy)*sin(a)|
619 CTM = |0 1 cy|*|sx*sin(a) sx*cos(a) (x0-cx)*sin(a)+(y0-cy)*cos(a)| # OK
620  |0 0 1 | | 0 0 1 |
621 
622  |sx*cos(a) -sx*sin(a) (x0-cx)*cos(a)-(y0-cy)*sin(a)+cx|
623 CTM = |sx*sin(a) sx*cos(a) (x0-cx)*sin(a)+(y0-cy)*cos(a)+cy| # OK
624  | 0 0 1 |
625 
626 Check
627 with sx = 1 and a,x0,y0,cx,cy = 0
628 
629  |1 0 0|
630 CTM = |0 1 0| # OK
631  |0 0 1|
632 
633 |x'| |x| |sx*cos(a)*x-sx*sin(a)*y+(x0-cx)*cos(a)-(y0-cy)*sin(a)+cx| |1*x-0*y|
634 |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
635 |0 | |0| | 0 | | 0 |
636 
637 **********************************************************************************************/
638 }
int svgPrintf(const char *objectname, const char *tag, const char *format,...)

◆ setMatrix() [2/2]

int rlSvgAnimator::setMatrix ( const char *  objectname,
rlSvgPosition pos 
)

The following methods are for moveing and zooming the whole SVG identified by mainObject. default: main.

set transformation matrix of object

Definition at line 558 of file rlsvganimator.cpp.

559 {
560  isModified = 1;
561  return setMatrix(objectname, pos.sx, pos.alpha, pos.x0, pos.y0, pos.cx, pos.cy);
562 }
int setMatrix(const char *objectname, float sx, float alpha, float x0, float y0, float cx, float cy)

◆ setMouseXY0()

int rlSvgAnimator::setMouseXY0 ( float  x0,
float  y0 
)

set/get mouse position 0 for the MainObject

Definition at line 746 of file rlsvganimator.cpp.

747 {
748  isModified = 1;
749  svgMouseX0 = x0;
750  svgMouseY0 = y0;
751  return 0;
752 }

◆ setMouseXY1()

int rlSvgAnimator::setMouseXY1 ( float  x1,
float  y1 
)

set/get mouse position 1 for the MainObject

Definition at line 764 of file rlsvganimator.cpp.

765 {
766  isModified = 1;
767  svgMouseX1 = x1;
768  svgMouseY1 = y1;
769  return 0;
770 }

◆ setScale()

int rlSvgAnimator::setScale ( float  scale)

set/get the scaling factor for the MainObject

Definition at line 782 of file rlsvganimator.cpp.

783 {
784  isModified = 1;
785  svgScale = scale;
786  return 0;
787 }

◆ setSocket()

int rlSvgAnimator::setSocket ( int *  socket)

initialize the socket with pvbrowser p->s

Definition at line 270 of file rlsvganimator.cpp.

271 {
272  isModified = 1;
273  s = socket;
274  return 0;
275 }

◆ setWindowSize()

int rlSvgAnimator::setWindowSize ( int  width,
int  height 
)

call this method when the widget is resized

Definition at line 840 of file rlsvganimator.cpp.

841 {
842  isModified = 1;
843  svgWindowWidth = (float) width;
844  svgWindowHeight = (float) height;
845  return 0;
846 }
float svgWindowHeight
float svgWindowWidth

◆ setXY0()

int rlSvgAnimator::setXY0 ( float  x0,
float  y0 
)

set/get x0,y0 coordinates for the MainObject

Definition at line 728 of file rlsvganimator.cpp.

729 {
730  isModified = 1;
731  svgX0 = x0;
732  svgY0 = y0;
733  return 0;
734 }

◆ show()

int rlSvgAnimator::show ( const char *  objectname,
int  state 
)

hide/show object state := 0=hide 1=show

Definition at line 541 of file rlsvganimator.cpp.

542 {
543  rlDebugPrintf("rlSvgAnimator.show state=%d objectname=%s\n",state,objectname);
544  isModified = 1;
545  if(id != 0)
546  {
547  char buf[MAXLINE];
548  sprintf(buf,"gsvgShow(%d,%d)\n",id,state);
549  //printf("buf=%s",buf);
550  tcpsend(buf, strlen(buf));
551  sprintf(buf,"%s\n",objectname);
552  tcpsend(buf, strlen(buf));
553  return 0;
554  }
555  return -1;
556 }
int rlDebugPrintf(const char *format,...)
Definition: rlcutil.cpp:61
int tcpsend(const char *buf, int len)
#define MAXLINE

◆ svgChangeStyleOption()

int rlSvgAnimator::svgChangeStyleOption ( const char *  objectname,
const char *  option,
const char *  value 
)

change a style option of "objectname". option must end with ':'. Example: option="stroke:" value="#000000"

Definition at line 473 of file rlsvganimator.cpp.

474 {
475  char buf[MAXBUF+40];
476 
477  isModified = 1;
478  sprintf(buf,"gsvgChangeStyleOption(%d)\n",id);
479  tcpsend(buf, strlen(buf));
480  sprintf(buf,"%s\n",objectname);
481  tcpsend(buf, strlen(buf));
482  sprintf(buf,"%s\n","style=");
483  tcpsend(buf, strlen(buf));
484  sprintf(buf,"%s\n",option);
485  tcpsend(buf, strlen(buf));
486  sprintf(buf,"%s\n",value);
487  tcpsend(buf, strlen(buf));
488  return 0;
489 }
int tcpsend(const char *buf, int len)
#define MAXBUF

◆ svgPrintf()

int rlSvgAnimator::svgPrintf ( const char *  objectname,
const char *  tag,
const char *  format,
  ... 
)

change a property of tag = "name="

Definition at line 306 of file rlsvganimator.cpp.

307 {
308  char buf[MAXBUF+40];
309  char text[MAXBUF];
310  int len = strlen(objectname);
311 
312  isModified = 1;
313  if(id != 0)
314  {
315  sprintf(buf,"gsvgPrintf(%d)\n",id);
316  tcpsend(buf, strlen(buf));
317  sprintf(buf,"%s\n",objectname);
318  tcpsend(buf, strlen(buf));
319  sprintf(buf,"%s\n",tag);
320  tcpsend(buf, strlen(buf));
321  va_list ap;
322  va_start(ap,format);
323 #ifdef RLWIN32
324  _vsnprintf(text, MAXBUF - 1, format, ap);
325 #endif
326 #ifdef __VMS
327  vsprintf(text, format, ap);
328 #endif
329 #ifdef RLUNIX
330  vsnprintf(text, MAXBUF - 1, format, ap);
331 #endif
332  va_end(ap);
333  strcat(text,"\n");
334  len = strlen(text);
335  tcpsend(text, len);
336  return len;
337  }
338  return -1;
339 }
int tcpsend(const char *buf, int len)
#define MAXBUF

◆ svgRecursiveChangeStyleOption()

int rlSvgAnimator::svgRecursiveChangeStyleOption ( const char *  objectname,
const char *  option,
const char *  value 
)

recursively change a style option of "objectname". option must end with ':'. Example: option="stroke:" value="#000000"

Definition at line 491 of file rlsvganimator.cpp.

492 {
493  char buf[MAXBUF+40];
494 
495  isModified = 1;
496  sprintf(buf,"gsvgRecursiveChangeStyleOption(%d)\n",id);
497  tcpsend(buf, strlen(buf));
498  sprintf(buf,"%s\n",objectname);
499  tcpsend(buf, strlen(buf));
500  sprintf(buf,"%s\n","style=");
501  tcpsend(buf, strlen(buf));
502  sprintf(buf,"%s\n",option);
503  tcpsend(buf, strlen(buf));
504  sprintf(buf,"%s\n",value);
505  tcpsend(buf, strlen(buf));
506  return 0;
507 }
int tcpsend(const char *buf, int len)
#define MAXBUF

◆ svgRecursivePrintf()

int rlSvgAnimator::svgRecursivePrintf ( const char *  objectname,
const char *  tag,
const char *  format,
  ... 
)

recursively change a property of tag = "name="

Definition at line 341 of file rlsvganimator.cpp.

342 {
343  char buf[MAXBUF+40];
344  char text[MAXBUF];
345  int len;
346 
347  isModified = 1;
348  sprintf(buf,"gsvgRecursivePrintf(%d)\n",id);
349  tcpsend(buf, strlen(buf));
350  sprintf(buf,"%s\n",objectname);
351  tcpsend(buf, strlen(buf));
352  sprintf(buf,"%s\n",tag);
353  tcpsend(buf, strlen(buf));
354  va_list ap;
355  va_start(ap,format);
356 #ifdef RLWIN32
357  _vsnprintf(text, MAXBUF - 1, format, ap);
358 #endif
359 #ifdef __VMS
360  vsprintf(text, format, ap);
361 #endif
362 #ifdef RLUNIX
363  vsnprintf(text, MAXBUF - 1, format, ap);
364 #endif
365  va_end(ap);
366  strcat(text,"\n");
367  len = strlen(text);
368  tcpsend(text, len);
369  return len;
370 }
int tcpsend(const char *buf, int len)
#define MAXBUF

◆ svgRecursiveRemoveStyleOption()

int rlSvgAnimator::svgRecursiveRemoveStyleOption ( const char *  objectname,
const char *  option 
)

recursively remove a style option of "objectname". option must end with ':'. Example: option="stroke:"

Definition at line 457 of file rlsvganimator.cpp.

458 {
459  char buf[MAXBUF+40];
460 
461  isModified = 1;
462  sprintf(buf,"gsvgRecursiveRemoveStyleOption(%d)\n",id);
463  tcpsend(buf, strlen(buf));
464  sprintf(buf,"%s\n",objectname);
465  tcpsend(buf, strlen(buf));
466  sprintf(buf,"%s\n","style=");
467  tcpsend(buf, strlen(buf));
468  sprintf(buf,"%s\n",option);
469  tcpsend(buf, strlen(buf));
470  return 0;
471 }
int tcpsend(const char *buf, int len)
#define MAXBUF

◆ svgRecursiveSearchAndReplace()

int rlSvgAnimator::svgRecursiveSearchAndReplace ( const char *  objectname,
const char *  tag,
const char *  before,
const char *  after 
)

recursively search for "before" within "tag=" property and replace it with "after". You may use wildcards within "before"

Definition at line 390 of file rlsvganimator.cpp.

391 {
392  char buf[MAXBUF+40];
393 
394  isModified = 1;
395  sprintf(buf,"gsvgRecursiveSearchAndReplace(%d)\n",id);
396  tcpsend(buf, strlen(buf));
397  sprintf(buf,"%s\n",objectname);
398  tcpsend(buf, strlen(buf));
399  sprintf(buf,"%s\n",tag);
400  tcpsend(buf, strlen(buf));
401  sprintf(buf,"%s\n",before);
402  tcpsend(buf, strlen(buf));
403  sprintf(buf,"%s\n",after);
404  tcpsend(buf, strlen(buf));
405  return 0;
406 }
int tcpsend(const char *buf, int len)
#define MAXBUF

◆ svgRecursiveSetStyleOption()

int rlSvgAnimator::svgRecursiveSetStyleOption ( const char *  objectname,
const char *  value 
)

recursively set a style option of "objectname". option must end with ':'. Example: value="fill:#9d9d9d;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:3.5;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"

Definition at line 525 of file rlsvganimator.cpp.

526 {
527  char buf[MAXBUF+40];
528 
529  isModified = 1;
530  sprintf(buf,"gsvgRecursiveSetStyleOption(%d)\n",id);
531  tcpsend(buf, strlen(buf));
532  sprintf(buf,"%s\n",objectname);
533  tcpsend(buf, strlen(buf));
534  sprintf(buf,"%s\n","style=");
535  tcpsend(buf, strlen(buf));
536  sprintf(buf,"%s\n",value);
537  tcpsend(buf, strlen(buf));
538  return 0;
539 }
int tcpsend(const char *buf, int len)
#define MAXBUF

◆ svgRemoveStyleOption()

int rlSvgAnimator::svgRemoveStyleOption ( const char *  objectname,
const char *  option 
)

remove a style option of "objectname". option must end with ':'. Example: option="stroke:"

Definition at line 441 of file rlsvganimator.cpp.

442 {
443  char buf[MAXBUF+40];
444 
445  isModified = 1;
446  sprintf(buf,"gsvgRemoveStyleOption(%d)\n",id);
447  tcpsend(buf, strlen(buf));
448  sprintf(buf,"%s\n",objectname);
449  tcpsend(buf, strlen(buf));
450  sprintf(buf,"%s\n","style=");
451  tcpsend(buf, strlen(buf));
452  sprintf(buf,"%s\n",option);
453  tcpsend(buf, strlen(buf));
454  return 0;
455 }
int tcpsend(const char *buf, int len)
#define MAXBUF

◆ svgSearchAndReplace()

int rlSvgAnimator::svgSearchAndReplace ( const char *  objectname,
const char *  tag,
const char *  before,
const char *  after 
)

search for "before" within "tag=" property and replace it with "after". You may use wildcards whin "before"

Definition at line 372 of file rlsvganimator.cpp.

373 {
374  char buf[MAXBUF+40];
375 
376  isModified = 1;
377  sprintf(buf,"gsvgSearchAndReplace(%d)\n",id);
378  tcpsend(buf, strlen(buf));
379  sprintf(buf,"%s\n",objectname);
380  tcpsend(buf, strlen(buf));
381  sprintf(buf,"%s\n",tag);
382  tcpsend(buf, strlen(buf));
383  sprintf(buf,"%s\n",before);
384  tcpsend(buf, strlen(buf));
385  sprintf(buf,"%s\n",after);
386  tcpsend(buf, strlen(buf));
387  return 0;
388 }
int tcpsend(const char *buf, int len)
#define MAXBUF

◆ svgSetStyleOption()

int rlSvgAnimator::svgSetStyleOption ( const char *  objectname,
const char *  value 
)

set a style option of "objectname". option must end with ':'. Example: value="fill:#9d9d9d;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:3.5;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"

Definition at line 509 of file rlsvganimator.cpp.

510 {
511  char buf[MAXBUF+40];
512 
513  isModified = 1;
514  sprintf(buf,"gsvgSetStyleOption(%d)\n",id);
515  tcpsend(buf, strlen(buf));
516  sprintf(buf,"%s\n",objectname);
517  tcpsend(buf, strlen(buf));
518  sprintf(buf,"%s\n","style=");
519  tcpsend(buf, strlen(buf));
520  sprintf(buf,"%s\n",value);
521  tcpsend(buf, strlen(buf));
522  return 0;
523 }
int tcpsend(const char *buf, int len)
#define MAXBUF

◆ svgTextPrintf()

int rlSvgAnimator::svgTextPrintf ( const char *  objectname,
const char *  format,
  ... 
)

change the text of "objectname"

Definition at line 408 of file rlsvganimator.cpp.

409 {
410  char buf[MAXBUF+40];
411  char text[MAXBUF];
412  int len = strlen(objectname);
413 
414  isModified = 1;
415  if(id != 0)
416  {
417  sprintf(buf,"gsvgTextPrintf(%d)\n",id);
418  tcpsend(buf, strlen(buf));
419  sprintf(buf,"%s\n",objectname);
420  tcpsend(buf, strlen(buf));
421  va_list ap;
422  va_start(ap,format);
423 #ifdef RLWIN32
424  _vsnprintf(text, MAXBUF - 1, format, ap);
425 #endif
426 #ifdef __VMS
427  vsprintf(text, format, ap);
428 #endif
429 #ifdef RLUNIX
430  vsnprintf(text, MAXBUF - 1, format, ap);
431 #endif
432  va_end(ap);
433  strcat(text,"\n");
434  len = strlen(text);
435  tcpsend(text, len);
436  return len;
437  }
438  return -1;
439 }
int tcpsend(const char *buf, int len)
#define MAXBUF

◆ tcpsend()

int rlSvgAnimator::tcpsend ( const char *  buf,
int  len 
)
private

Definition at line 133 of file rlsvganimator.cpp.

134 {
135  int ret,bytes_left,first_byte;
136 
137  if(s == NULL) return -1;
138  //rlDebugPrintf("tcpsend len=%d buf=%s",len,buf);
139  bytes_left = len;
140  first_byte = 0;
141  while(bytes_left > 0)
142  {
143  if(*s == 1) // use stdout
144  {
145 #ifdef __VMS
146  ret = send(1,&buf[first_byte],bytes_left,MSG_NOSIGNAL);
147 #else
148  ret = write(1,&buf[first_byte],bytes_left);
149 #endif
150  if(ret <= 0)
151  {
152  *s = -1;
153  return -1;
154  }
155  }
156  else // use socket
157  {
158  ret = send(*s,&buf[first_byte],bytes_left,MSG_NOSIGNAL);
159  if(ret <= 0)
160  {
161  *s = -1;
162  return -1;
163  }
164  }
165  bytes_left -= ret;
166  first_byte += ret;
167  }
168  return 0;
169 }
#define MSG_NOSIGNAL

◆ windowHeight()

float rlSvgAnimator::windowHeight ( )

Definition at line 853 of file rlsvganimator.cpp.

854 {
855  return svgWindowHeight;
856 }
float svgWindowHeight

◆ windowWidth()

float rlSvgAnimator::windowWidth ( )

Definition at line 848 of file rlsvganimator.cpp.

849 {
850  return svgWindowWidth;
851 }
float svgWindowWidth

◆ writeSocket()

int rlSvgAnimator::writeSocket ( )

The following methods are for modifying a object within a SVG graphic identified by objectname.

update the SVG graphic with: gBeginDraw(p,id); d->svgAnimator.writeSocket(); gEndDraw(p);

Definition at line 284 of file rlsvganimator.cpp.

285 {
286  char buf[80];
287 
288  isModified = 0;
289 
290  if(s == NULL)
291  {
292  printf("rlSvgAnimator: ERROR please use setSocket first\n");
293  return -1;
294  }
295  if(id != 0)
296  {
297  sprintf(buf,"gupdateSVG(%d)\n",id);
298  tcpsend(buf, strlen(buf));
299  return 0;
300  }
301  return -1;
302 }
int tcpsend(const char *buf, int len)

◆ x0()

float rlSvgAnimator::x0 ( )

Definition at line 736 of file rlsvganimator.cpp.

737 {
738  return svgX0;
739 }

◆ y0()

float rlSvgAnimator::y0 ( )

Definition at line 741 of file rlsvganimator.cpp.

742 {
743  return svgY0;
744 }

◆ zoomCenter()

int rlSvgAnimator::zoomCenter ( float  newScale)

zooms the whole SVG graphic keeping it centered to the viewport

Definition at line 794 of file rlsvganimator.cpp.

795 {
796  float oldX0, oldY0;
797 
798  isModified = 1;
799  if (newScale > 1000) newScale = 1000.0f;
800 
801  oldX0 = (svgX0 - ((svgWindowWidth) * (1.0f - svgScale)) / 2.0f) / svgScale;
802  oldY0 = (svgY0 - ((svgWindowHeight) * (1.0f - svgScale)) / 2.0f) / svgScale;
803 
804  svgScale = newScale;
805 
806  svgX0 = oldX0*svgScale + ((svgWindowWidth) * (1.0f - svgScale)) / 2.0f;
807  svgY0 = oldY0*svgScale + ((svgWindowHeight) * (1.0f - svgScale)) / 2.0f;
808 
809  return 0;
810 }
float svgWindowHeight
float svgWindowWidth

◆ zoomRect()

int rlSvgAnimator::zoomRect ( )

zooms the whole SVG graphic so that the visible section is from x0,x0 to x1,y1

Definition at line 812 of file rlsvganimator.cpp.

813 {
814  float newScale, scale1, scale2, rectWidth, rectHeight;
815 
816  isModified = 1;
817  rectWidth = svgMouseX1-svgMouseX0;
818  rectHeight = svgMouseY1-svgMouseY0;
819  svgX0 = svgX0 + svgWindowWidth/2 - (svgMouseX0 + rectWidth/2);
820  svgY0 = svgY0 + svgWindowHeight/2 - (svgMouseY0 + rectHeight/2);
821  rectWidth = rectWidth / svgScale;
822  rectHeight = rectHeight / svgScale;
823  scale1 = svgWindowWidth / rectWidth;
824  scale2 = svgWindowHeight / rectHeight;
825 
826  if(scale1 < scale2) newScale = scale1;
827  else newScale = scale2;
828  zoomCenter(newScale);
829 
830  return 0;
831 }
float svgWindowHeight
int zoomCenter(float newScale)
float svgWindowWidth

Member Data Documentation

◆ id

int rlSvgAnimator::id
private

Definition at line 138 of file rlsvganimator.h.

◆ inifileCount

int rlSvgAnimator::inifileCount
private

Definition at line 134 of file rlsvganimator.h.

◆ inifileID

rlSpreadsheetCell rlSvgAnimator::inifileID
private

Definition at line 135 of file rlsvganimator.h.

◆ inifileState

int rlSvgAnimator::inifileState
private

Definition at line 134 of file rlsvganimator.h.

◆ inifileTable

rlSpreadsheetTable rlSvgAnimator::inifileTable
private

Definition at line 136 of file rlsvganimator.h.

◆ isModified

int rlSvgAnimator::isModified

Definition at line 128 of file rlsvganimator.h.

◆ main_object_name

rlString rlSvgAnimator::main_object_name
private

Definition at line 141 of file rlsvganimator.h.

◆ s

int* rlSvgAnimator::s
private

Definition at line 137 of file rlsvganimator.h.

◆ svgMouseX0

float rlSvgAnimator::svgMouseX0
private

Definition at line 140 of file rlsvganimator.h.

◆ svgMouseX1

float rlSvgAnimator::svgMouseX1
private

Definition at line 140 of file rlsvganimator.h.

◆ svgMouseY0

float rlSvgAnimator::svgMouseY0
private

Definition at line 140 of file rlsvganimator.h.

◆ svgMouseY1

float rlSvgAnimator::svgMouseY1
private

Definition at line 140 of file rlsvganimator.h.

◆ svgScale

float rlSvgAnimator::svgScale
private

Definition at line 140 of file rlsvganimator.h.

◆ svgWindowHeight

float rlSvgAnimator::svgWindowHeight
private

Definition at line 140 of file rlsvganimator.h.

◆ svgWindowWidth

float rlSvgAnimator::svgWindowWidth
private

Definition at line 140 of file rlsvganimator.h.

◆ svgX0

float rlSvgAnimator::svgX0
private

Definition at line 140 of file rlsvganimator.h.

◆ svgY0

float rlSvgAnimator::svgY0
private

Definition at line 140 of file rlsvganimator.h.


The documentation for this class was generated from the following files: