/* * 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 * May 2005 : Implemented some basic filtering * Copyright (c) 1990-2005 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 * */ /* This is an initial and premature attempt to add filtering on several * entity properties such as linetype, color and layernumber */ #include #include #include #include #include #include "dxfstuff.h" #define IGNORE 0 #define FILTER 1 #define INVERT 2 #define LESSTHAN 3 #define MORETHAN 4 static struct filters_t { char ltypeflag; /* 0=ignore , 1=filter, 2=inverse filter, 3=less than, 4=larger than */ int ltypefilter; char widthflag; int widthfilter; char colorflag; int colorfilter; char depthflag; int depthfilter; } f = { IGNORE , 0, IGNORE , 0, IGNORE , 0, IGNORE , 0 }; char *filterhelp() { return " -i : call one or more filters\n" "\n" " Currently available filters are : \n" " ltype= (CONTINUOUS,DASHED,DASHDOT,DOT etc.)\n" " width=\n" " color= : XFIG color number or RGB value for plot programs\n" " depth= : layername converted to number, i.e. XFIG depth (50 up)\n" "\n" " You can combine filters using ':' and invert them using '!=' but note that\n" " combined filters always are applied in Boolean mode.\n" " Example : COMMAND -i 'ltype!=CONTINUOUS:color3:depth=52' test.dxf\n"; } void setltypefilter(char *item) { char *normal = "ltype="; char *invert = "ltype!="; int ltype; if(compare(normal, item, 6) == 0) { f.ltypeflag = FILTER; ltype = lookupdxfltype(item + strlen(normal)); /* convert names to numbers */ f.ltypefilter = lookupltype(ltype); /* and lookup in the table */ } else if(compare(invert, item, 6) == 0) { f.ltypeflag = INVERT; ltype = lookupdxfltype(item + strlen(invert)); /* convert names to numbers */ f.ltypefilter = lookupltype(ltype); /* and lookup in the table */ } } void setwidthfilter(char *item) { char *normal = "width="; char *invert = "width!="; if(compare(normal, item, 6) == 0) { f.widthflag = FILTER; sscanf(item + strlen(normal),"%d",&f.widthfilter); } else if(compare(invert, item, 6) == 0) { f.widthflag = INVERT; sscanf(item + strlen(invert),"%d",&f.widthfilter); } } void setcolorfilter(char *item) { char *normal = "color="; char *invert = "color!="; int color; if(compare(normal, item, 6) == 0) { f.colorflag = FILTER; sscanf(item + strlen(normal),"%d",&color); f.colorfilter = lookupcolor(color); } else if(compare(invert, item, 6) == 0) { f.colorflag = INVERT; sscanf(item + strlen(invert),"%d",&color); f.colorfilter = lookupcolor(color); } } void setdepthfilter(char *item) { char *normal = "depth="; char *invert = "depth!="; if(compare(normal, item, 6) == 0) { f.depthflag = FILTER; sscanf(item + strlen(normal),"%d",&f.depthfilter); } else if(compare(invert, item, 6) == 0) { f.depthflag = INVERT; sscanf(item + strlen(invert),"%d",&f.depthfilter); } } void parsefilteritem(char *item) { if(compare("ltype" ,item,5) == 0) setltypefilter(item); if(compare("width" ,item,5) == 0) setwidthfilter(item); if(compare("color" ,item,5) == 0) setcolorfilter(item); if(compare("depth" ,item,5) == 0) setdepthfilter(item); } void initfilters(char *filters) { int x; char *nextitem=filters; for(x=0;xltype == f.ltypefilter) return 0; if(f.ltypeflag == INVERT && d->ltype != f.ltypefilter) return 0; return 1; } if(f.widthflag != IGNORE) { if(f.widthflag == FILTER && d->width == f.widthfilter) return 0; if(f.widthflag == INVERT && d->width != f.widthfilter) return 0; if(f.widthflag == LESSTHAN && d->width < f.widthfilter) return 0; if(f.widthflag == MORETHAN && d->width < f.widthfilter) return 0; return 1; } if(f.colorflag != IGNORE) { if(f.colorflag == FILTER && d->rgbcolor == f.colorfilter) return 0; if(f.colorflag == INVERT && d->rgbcolor != f.colorfilter) return 0; return 1; } if(f.depthflag != IGNORE) { if(f.depthflag == FILTER && d->depth == f.depthfilter) return 0; if(f.depthflag == INVERT && d->depth != f.depthfilter) return 0; return 1; } return 0; }