/* * DXF2FIG : Converter for Autocad DXF format to FIG format. * Aug 1990 : Atari ST and VAX/VMS version by KL * Nov 2003 : Modified for Linux and Xfig by KL * Copyright (c) 1990-2003 by Kees Lemmens * * This software is distributed under the Gnu Public License and as such * may be copied, redistributed and modified freely as long as the original * Copyright above is retained and as long as any software derived from * this is distributed under the Gnu Public License as well. Use of this * software in any patented or closed source software is strictly * prohibited. * * For more information see the GPL : http://www.gnu.org/licenses/gpl.txt * */ #include #include #include #include #include #include "hrgraph.h" #include "dxfstuff.h" #define STAP 0.1 extern double sin(),cos(); /* Some global (static) variables */ /* End global variables */ #if (DEBUG > 2) /* disable graphics for debug or else debugger may hang */ # define dot(x,y) # define plot(x,y) # define setplot(x,y) # define linestyle(s,t) #endif long lookupcolor(int color) { switch(color) { case 0: return BLACK; // byblock or white case 1: return RED; // red case 2: return YELLOW; // yellow case 3: return GREEN; // green case 4: return CYAN; // cyan case 5: return BLUE; // blue case 6: return MAGENTA; // magenta case 7: return BLACK; // black case 8: return WHITE; // gray case 15: return WHITE; // white default : return WHITE; } } int lookupltype(int ltype) { switch(ltype) { case DXFSOLID : return SOLID; case DXFDASHED : return DASHED; case DXFDOTTED : return DOTTED; case DXFDOTDASHED: return DOTDASHED; default : return SOLID; } } int lookuphorjust(int txthjst) { return -1; /* justification not supported */ } int getxres() { return XRES; } int getyres() { return YRES; } void dopoint(Plotdata *d) { debug("Doing Dot ..."); if( filter(d) > 0) return; setcol(DOT,d->rgbcolor); dot(d->xi[0],d->yi[0]); } void doline(Plotdata *d) { debug("Doing Line ..."); if( filter(d) > 0) return; linestyle(d->ltype,d->width); setcol(LINE,d->rgbcolor); setplot(d->xi[0],d->yi[0]); plot(d->xi[1],d->yi[1]); } void dopline(Plotdata *d) { int t; debug("Doing Polyline with %d vertices, color %d, depth %d ...", d->nrvrt,d->rgbcolor,d->depth); if( filter(d) > 0) return; linestyle(d->ltype,d->width); setcol(LINE,d->rgbcolor); setplot(d->xvrt[0],d->yvrt[0]); for(t=0;tnrvrt;t++) plot(d->xvrt[t],d->yvrt[t]); } void dosolid(Plotdata *d) { debug("Doing Solid ..."); if( filter(d) > 0) return; linestyle(d->ltype,d->width); setcol(LINE,d->rgbcolor); setplot(d->xi[0],d->yi[0]); plot(d->xi[1],d->yi[1]); plot(d->xi[3],d->yi[3]); plot(d->xi[2],d->yi[2]); plot(d->xi[0],d->yi[0]); } void do3dface(Plotdata *d) { debug("Doing 3DFace ...."); if( filter(d) > 0) return; linestyle(d->ltype,d->width); setcol(LINE,d->rgbcolor); setplot(d->xi[0],d->yi[0]); plot(d->xi[1],d->yi[1]); plot(d->xi[2],d->yi[2]); plot(d->xi[3],d->yi[3]); plot(d->xi[0],d->yi[0]); } void docircle(Plotdata *d) { float x; debug("Doing Circle ...."); if( filter(d) > 0) return; linestyle(d->ltype,d->width); setcol(LINE,d->rgbcolor); /* Note that this routine also plots ellipses in contrast with circle() ! */ setplot((int)(d->xi[0]+d->rx),d->yi[0]); for(x=0;xxi[0]+d->rx*cos(x)), (int)(d->yi[0]+d->ry*sin(x))); plot((int)(d->xi[0]+d->rx),d->yi[0]); } void doarc(Plotdata *d) { debug("Doing Arc ...."); if( filter(d) > 0) return; linestyle(d->ltype,d->width); setcol(LINE,d->rgbcolor); while(d->angle1>d->angle2) d->angle1-=PI2; d->angle2+=0.5*STAP; setplot((int)(d->xi[0]+d->rx*cos(d->angle1)), (int)(d->yi[0]+d->ry*sin(d->angle1))); while(d->angle1+=STAP,d->angle1angle2) { plot((int)(d->xi[0]+d->rx*cos(d->angle1)), (int)(d->yi[0]+d->ry*sin(d->angle1))); } } void dotext(Plotdata *d) { debug("Doing Text ...."); if( filter(d) > 0) return; setcol(TEXT,d->rgbcolor); text(d->xi[0],d->yi[0],d->text,d->theight,d->theight,d->angle1); } void openblock(Plotdata *d) { return; /* dummy */ } void closeblock(void) { return; /* dummy */ } void startgraphics() { #if (DEBUG <= 1) graphon(); setcol(BACKGR,0xa090ff); setcol(LINE,BLACK); setcol(TEXT,RED); clrmap(); #endif } void usage(char *basename, char *title) { fprintf(stderr,"\n%s\n",title); fprintf(stderr, "\n Usage : %s [[options] ]\n\n" " Options: -p <1-3> : viewplane , 1=xy, 2=xz, 3=yz\n" " -v [-v ...] : give (lots of) debug information\n" ,basename); fprintf(stderr,filterhelp()); exit(1); } int main(int argc, char *argv[]) { char *title= " *** PLOT DXFFORMATS (AUTOCAD-DRAWINGS) USING HR GRAPHICS ***\n" " KL, Jan 1990; " VERSION " (Linux version); KL " MODDATE; char *basename=argv[0]; /* should be preserved from option parser */ char dxfname[STRSIZE]; int x; int viewp; char *filters=""; /* no filter */ #if DEBUG >= 2 verbose = 2; #endif graphic(); viewp = 1; /* defaults */ if(argc == 1) { printf("\n%s\n",title); printf("\nDXF input name (excl .dxf) : "); scanf("%250s",dxfname); printf("\nViewplane 3D (1=xy,2=xz,3=yz) : "); scanf("%1d",&viewp); while(fgetc(stdin) != '\n'); /* empty stdin buffer (linebuffer) */ } else { /* parse options */ x=argc; while(--x>0) { if(*argv[1]=='-') { switch(*(++argv[1])) { case 'p': if(argc <= 2) usage(basename,title); sscanf(argv[2],"%d",&viewp); ++argv; --argc; --x; break; case 'i': if(argc <= 2) usage(basename,title); filters = argv[2]; ++argv; --argc; --x; break; case 'v': verbose++; break; default: usage(basename,title); break; } ++argv; --argc; } } if(argc < 2) usage(basename,title); sscanf(argv[1],"%250s",dxfname); } startgraphics(); startparser(dxfname,viewp,filters); fprintf(stderr,"Press to exit ...\n"); while(getchar() != '\n') sleep(1); #if (DEBUG <= 1) graphoff(); #endif endgraph(); exit(0); }