Back to index

wims  3.65+svn20090927
vimg.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018 
00019 void vimg_init (void)
00020 {
00021     double x1,x2,y1,y2,t;
00022     char *p, *p1, namebuf[2048];
00023     vimgf=NULL;
00024     if(vimgfilename[0]==0) vimgf=stdout;
00025     else {
00026        p=getenv("flydraw_filebase");
00027        if(p!=NULL && *p!=0) {      /* secured execution */
00028            if(vimgfilename[0]=='/' || strstr(vimgfilename,"..")!=NULL) goto init_fail;
00029            for(p1=vimgfilename;*p1;p1++)
00030              if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL) goto init_fail;
00031            p1=getenv("w_wims_session");
00032            if(p1!=NULL && *p1!=0) {
00033               snprintf(namebuf,sizeof(namebuf),"../s2/%s/%s",p1,vimgfilename);
00034               vimgf=fopen(namebuf,"w");
00035            }
00036            else goto init_fail;
00037        }
00038        else vimgf=fopen(vimgfilename,"w");
00039     }
00040     if(vimgf==NULL) {
00041 init_fail:    vimg_enable=0; return;
00042     }
00043     x1=xstart; y1=ystart;
00044     x2=sizex/xscale+xstart;
00045     y2=sizey/yscale+ystart;
00046     if(x2<x1) {t=x1;x1=x2;x2=t;}
00047     if(y2<y1) {t=y1;y1=y2;y2=t;}
00048     fprintf(vimgf,"999\nDXF created by Flydraw\n\
00049   0\nSECTION\n  2\nHEADER\n\
00050   9\n$ACADVER\n  1\nAC1006\n\
00051   9\n$INSBASE\n  10\n0.0\n  20\n0.0\n  30\n0.0\n\
00052   9\n$EXTMIN\n  10\n%f\n  20\n%f\n\
00053   9\n$EXTMAX\n  10\n%f\n  20\n%f\n\
00054   9\n$LIMMIN\n  10\n%f\n  20\n%f\n\
00055   9\n$LIMMAX\n  10\n%f\n  20\n%f\n\
00056   9\n$MEASUREMENT\n  70\n1\n  0\nENDSEC\n\
00057   0\nSECTION\n  2\nCLASSES\n  0\nENDSEC\n\
00058   0\nSECTION\n  2\nTABLES\n\
00059   0\nTABLE\n  2\nLTYPE\n  70\n1\n\
00060   0\nLTYPE\n  2\nCONTINUOUS\n  70\n64\n  3\nSolid line\n\
00061   72\n65\n  73\n0\n  40\n0.0000\n  0\nENDTAB\n\
00062   0\nTABLE\n  2\nLAYER\n  70\n1\n\
00063   0\nLAYER\n  2\n1\n  70\n64\n  62\n7\n  6\nCONTINUOUS\n\
00064   0\nENDTAB\n\
00065   0\nTABLE\n  2\nSTYLE\n  70\n0\n  0\nENDTAB\n\
00066   0\nENDSEC\n\
00067   0\nSECTION\n  2\nBLOCKS\n  0\nENDSEC\n\
00068   0\nSECTION\n  2\nENTITIES\n",
00069            x1,y1,x2,y2, x1,y1,x2,y2);
00070     vimg_ready=1;
00071 }
00072 
00073 void vimg_close (void)
00074 {
00075     if(vimgf==NULL || vimg_ready==0) return;
00076     fprintf(vimgf,"  0\nENDSEC  \n  0\nEOF\n");
00077     fclose(vimgf); vimg_ready=vimg_enable=0; vimgf=NULL;
00078 }
00079 
00080 void vimg_arc (double x0,double y0, double rx, double ry,double a1, double a2)
00081 {
00082     double mx,my,ratio;
00083     if(rx==ry) {
00084        fprintf(vimgf,"  0\nARC\n  8\n1\n  10\n%f\n  20\n%f\n  40\n%f\n\
00085   50\n%f\n51\n%f\n",x0,y0,rx,a1,a2);
00086        return;
00087     }
00088     if(rx>ry) {mx=rx;my=0;ratio=ry/rx;}
00089     else {mx=0;my=ry;ratio=rx/ry;}
00090     fprintf(vimgf,"  0\nELLIPSE\n  10\n%f\n  20\n%f\n\
00091   11\n%f\n  21\n%f\n  40\n%f\n  41\n%f\n  42\n%f\n",
00092            x0,y0,mx,my,ratio,
00093            a1*3.14159265/180,a2*3.14159265/180);
00094     
00095 }
00096 
00097 void vimg_ellipse (double x0, double y0, double rx, double ry)
00098 {
00099     if(rx==ry) {
00100        fprintf(vimgf,"  0\nCIRCLE\n  8\n1\n  10\n%f\n  20\n%f\n\
00101   40\n%f\n",x0,y0,rx);
00102        return;
00103     }
00104     else vimg_arc (x0,y0,rx,ry,0,360);
00105 }
00106 
00107 void vimg_line (double x1,double y1,double x2,double y2)
00108 {
00109     fprintf(vimgf,"  0\nLINE\n  8\n1\n10\n%f\n  20\n%f\n  11\n%f\n  21\n%f\n",
00110           x1,y1,x2,y2);
00111 }
00112 
00113 void vimg_polyline (double xy[], int cnt, int closed)
00114 {
00115     int i;
00116     fprintf(vimgf,"  0\nPOLYLINE\n  70\n%d\n",closed);
00117     for(i=0;i<2*cnt;i++,i++) {
00118        fprintf(vimgf,"  0\nVERTEX\n  8\n1\n  10\n%f\n  20\n%f\n",
00119               xy[i],xy[i+1]);
00120     }
00121     fprintf(vimgf,"  0\nSEQEND\n");
00122 }
00123 
00124 void vimg_rect (double x1, double y1, double x2, double y2)
00125 {
00126     double d[8];
00127     d[0]=x1; d[1]=y1; d[2]=x1; d[3]=y2;
00128     d[4]=x2; d[5]=y2; d[6]=x2; d[7]=y1;
00129     vimg_polyline (d,4,1);
00130 }
00131 
00132 void vimg_plotstart (void)
00133 {
00134     fprintf(vimgf,"  0\nPOLYLINE\n  8\n1\n  70\n0\n");
00135 }
00136 
00137 void vimg_plot1 (double x, double y)
00138 {
00139     fprintf(vimgf,"  0\nVERTEX\n  8\n1\n  10\n%f\n  20\n%f\n", x,y);
00140 }
00141 
00142 void vimg_plotend (void)
00143 {
00144     fprintf(vimgf,"  0\nSEQEND\n");
00145 }
00146