Rev 8102 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1027 | bpr | 1 | /* Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis |
2 | * |
||
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program; if not, write to the Free Software |
||
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
||
16 | */ |
||
17 | |||
8102 | bpr | 18 | #include "flydraw.h" |
1027 | bpr | 19 | |
20 | void vimg_init (void) |
||
21 | { |
||
12473 | bpr | 22 | double x1,x2,y1,y2,t; |
23 | char *p, *p1, namebuf[2048]; |
||
24 | vimgf=NULL; |
||
25 | if(vimgfilename[0]==0) vimgf=stdout; |
||
26 | else { |
||
27 | p=getenv("flydraw_filebase"); |
||
28 | if(p!=NULL && *p!=0) { /* secured execution */ |
||
29 | if(vimgfilename[0]=='/' || strstr(vimgfilename,"..")!=NULL) goto init_fail; |
||
30 | for(p1=vimgfilename;*p1;p1++) |
||
31 | if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL) goto init_fail; |
||
32 | p1=getenv("w_wims_session"); |
||
33 | if(p1!=NULL && *p1!=0) { |
||
34 | snprintf(namebuf,sizeof(namebuf),"../s2/%s/%s",p1,vimgfilename); |
||
35 | vimgf=fopen(namebuf,"w"); |
||
7675 | bpr | 36 | } |
12473 | bpr | 37 | else goto init_fail; |
1027 | bpr | 38 | } |
12473 | bpr | 39 | else vimgf=fopen(vimgfilename,"w"); |
40 | } |
||
41 | if(vimgf==NULL) { |
||
42 | init_fail: vimg_enable=0; return; |
||
43 | } |
||
44 | x1=xstart; y1=ystart; |
||
45 | x2=sizex/xscale+xstart; |
||
46 | y2=sizey/yscale+ystart; |
||
47 | if(x2<x1) {t=x1;x1=x2;x2=t;} |
||
48 | if(y2<y1) {t=y1;y1=y2;y2=t;} |
||
49 | fprintf(vimgf,"999\nDXF created by Flydraw\n\ |
||
1027 | bpr | 50 | 0\nSECTION\n 2\nHEADER\n\ |
51 | 9\n$ACADVER\n 1\nAC1006\n\ |
||
52 | 9\n$INSBASE\n 10\n0.0\n 20\n0.0\n 30\n0.0\n\ |
||
53 | 9\n$EXTMIN\n 10\n%f\n 20\n%f\n\ |
||
54 | 9\n$EXTMAX\n 10\n%f\n 20\n%f\n\ |
||
55 | 9\n$LIMMIN\n 10\n%f\n 20\n%f\n\ |
||
56 | 9\n$LIMMAX\n 10\n%f\n 20\n%f\n\ |
||
57 | 9\n$MEASUREMENT\n 70\n1\n 0\nENDSEC\n\ |
||
58 | 0\nSECTION\n 2\nCLASSES\n 0\nENDSEC\n\ |
||
59 | 0\nSECTION\n 2\nTABLES\n\ |
||
60 | 0\nTABLE\n 2\nLTYPE\n 70\n1\n\ |
||
61 | 0\nLTYPE\n 2\nCONTINUOUS\n 70\n64\n 3\nSolid line\n\ |
||
62 | 72\n65\n 73\n0\n 40\n0.0000\n 0\nENDTAB\n\ |
||
63 | 0\nTABLE\n 2\nLAYER\n 70\n1\n\ |
||
64 | 0\nLAYER\n 2\n1\n 70\n64\n 62\n7\n 6\nCONTINUOUS\n\ |
||
65 | 0\nENDTAB\n\ |
||
66 | 0\nTABLE\n 2\nSTYLE\n 70\n0\n 0\nENDTAB\n\ |
||
67 | 0\nENDSEC\n\ |
||
68 | 0\nSECTION\n 2\nBLOCKS\n 0\nENDSEC\n\ |
||
69 | 0\nSECTION\n 2\nENTITIES\n", |
||
7675 | bpr | 70 | x1,y1,x2,y2, x1,y1,x2,y2); |
1027 | bpr | 71 | vimg_ready=1; |
72 | } |
||
73 | |||
74 | void vimg_close (void) |
||
75 | { |
||
12473 | bpr | 76 | if(vimgf==NULL || vimg_ready==0) return; |
77 | fprintf(vimgf," 0\nENDSEC \n 0\nEOF\n"); |
||
78 | fclose(vimgf); vimg_ready=vimg_enable=0; vimgf=NULL; |
||
1027 | bpr | 79 | } |
80 | |||
81 | void vimg_arc (double x0,double y0, double rx, double ry,double a1, double a2) |
||
82 | { |
||
12473 | bpr | 83 | double mx,my,ratio; |
84 | if(rx==ry) { |
||
85 | fprintf(vimgf," 0\nARC\n 8\n1\n 10\n%f\n 20\n%f\n 40\n%f\n\ |
||
1027 | bpr | 86 | 50\n%f\n51\n%f\n",x0,y0,rx,a1,a2); |
12473 | bpr | 87 | return; |
88 | } |
||
89 | if(rx>ry) {mx=rx;my=0;ratio=ry/rx;} |
||
90 | else {mx=0;my=ry;ratio=rx/ry;} |
||
91 | fprintf(vimgf," 0\nELLIPSE\n 10\n%f\n 20\n%f\n\ |
||
1027 | bpr | 92 | 11\n%f\n 21\n%f\n 40\n%f\n 41\n%f\n 42\n%f\n", |
7675 | bpr | 93 | x0,y0,mx,my,ratio, |
94 | a1*3.14159265/180,a2*3.14159265/180); |
||
95 | |||
1027 | bpr | 96 | } |
97 | |||
98 | void vimg_ellipse (double x0, double y0, double rx, double ry) |
||
99 | { |
||
12473 | bpr | 100 | if(rx==ry) { |
101 | fprintf(vimgf," 0\nCIRCLE\n 8\n1\n 10\n%f\n 20\n%f\n\ |
||
102 | 40\n%f\n",x0,y0,rx); |
||
103 | return; |
||
104 | } |
||
105 | else vimg_arc (x0,y0,rx,ry,0,360); |
||
1027 | bpr | 106 | } |
107 | |||
108 | void vimg_line (double x1,double y1,double x2,double y2) |
||
109 | { |
||
12473 | bpr | 110 | fprintf(vimgf," 0\nLINE\n 8\n1\n10\n%f\n 20\n%f\n 11\n%f\n 21\n%f\n", |
111 | x1,y1,x2,y2); |
||
1027 | bpr | 112 | } |
113 | |||
114 | void vimg_polyline (double xy[], int cnt, int closed) |
||
115 | { |
||
12473 | bpr | 116 | int i; |
117 | fprintf(vimgf," 0\nPOLYLINE\n 70\n%d\n",closed); |
||
118 | for(i=0;i<2*cnt;i++,i++) { |
||
119 | fprintf(vimgf," 0\nVERTEX\n 8\n1\n 10\n%f\n 20\n%f\n", |
||
120 | xy[i],xy[i+1]); |
||
121 | } |
||
122 | fprintf(vimgf," 0\nSEQEND\n"); |
||
1027 | bpr | 123 | } |
124 | |||
125 | void vimg_rect (double x1, double y1, double x2, double y2) |
||
126 | { |
||
12473 | bpr | 127 | double d[8]; |
128 | d[0]=x1; d[1]=y1; d[2]=x1; d[3]=y2; |
||
129 | d[4]=x2; d[5]=y2; d[6]=x2; d[7]=y1; |
||
130 | vimg_polyline (d,4,1); |
||
1027 | bpr | 131 | } |
132 | |||
133 | void vimg_plotstart (void) |
||
134 | { |
||
12473 | bpr | 135 | fprintf(vimgf," 0\nPOLYLINE\n 8\n1\n 70\n0\n"); |
1027 | bpr | 136 | } |
137 | |||
138 | void vimg_plot1 (double x, double y) |
||
139 | { |
||
12473 | bpr | 140 | fprintf(vimgf," 0\nVERTEX\n 8\n1\n 10\n%f\n 20\n%f\n", x,y); |
1027 | bpr | 141 | } |
142 | |||
143 | void vimg_plotend (void) |
||
144 | { |
||
12473 | bpr | 145 | fprintf(vimgf," 0\nSEQEND\n"); |
1027 | bpr | 146 | } |