int main(int argc, char *argv[]) { gerbv_image_t *workingImage; /* create a new, blank, image */ workingImage = gerbv_create_image(NULL, NULL); /* draw the nose */ gerbv_image_create_line_object (workingImage, 1.5, 1.5, 1.6, 1.3, 0.020, GERBV_APTYPE_CIRCLE); gerbv_image_create_line_object (workingImage, 1.5, 1.5, 1.4, 1.3, 0.020, GERBV_APTYPE_CIRCLE); gerbv_image_create_line_object (workingImage, 1.4, 1.3, 1.6, 1.3, 0.020, GERBV_APTYPE_CIRCLE); /* draw the eyes */ gerbv_image_create_arc_object (workingImage, 1, 2, 0.1, 0, 360, 0.020, GERBV_APTYPE_CIRCLE); gerbv_image_create_arc_object (workingImage, 2, 2, 0.1, 0, 360, 0.020, GERBV_APTYPE_CIRCLE); /* draw the mouth */ gerbv_image_create_arc_object (workingImage, 1.5, 1.5, 0.75, -30, -150, 0.20, GERBV_APTYPE_CIRCLE); /* draw the head */ gerbv_image_create_arc_object (workingImage, 1.5, 1.5, 1.5, 0, 360, 0.02, GERBV_APTYPE_CIRCLE); /* draw the ears */ gerbv_image_create_rectangle_object (workingImage, -0.2, 1.3, 0.2, 0.4); gerbv_image_create_rectangle_object (workingImage, 3, 1.3, 0.2, 0.4); /* export the drawn image to a new rs274x file */ gerbv_export_rs274x_file_from_image ("example5-output.gbx", workingImage, NULL); /* destroy all created structures */ gerbv_destroy_image (workingImage); return 0; }
int main(int argc, char *argv[]) { gerbv_image_t *workingImage; gerbv_net_t *currentNet; FILE * file; struct point polygon[100000]; int start_polygon = 0; int current_point = 0; int were_was_some_clear = 0; int polarity_clear = 0; int i; int opt; char *input_file = NULL; char *output_file = NULL; char *object_name = NULL; struct point upper_left; struct point bottom_right; while ((opt = getopt (argc, argv, "i:o:n:")) != -1) { switch (opt) { case 'i': if(optarg != NULL) input_file = strdup(optarg); break; case 'o': if(optarg != NULL) output_file = strdup(optarg); break; case 'n': if(optarg != NULL) object_name = strdup(optarg); break; default: printf("Unknown option\n"); } } /* parse and create the image */ workingImage = gerbv_create_rs274x_image_from_filename (input_file); /* make sure we parsed the file */ if (workingImage == NULL) { printf("There was an error parsing the file."); return 0; } find_gerb_size(workingImage, &upper_left, &bottom_right); printf("upper_left.x = %f, upper_left.y = %f\n", upper_left.x, upper_left.y); printf("bottom_right.x = %f, bottom_right.y = %f\n", bottom_right.x, bottom_right.y); file = fopen (output_file,"w"); fprintf (file, "// Auto generated pov file\n\n"); fprintf (file, "#version 3.5;\n\n"); fprintf (file, "#include \"math.inc\"\n"); fprintf (file, "#include \"colors.inc\"\n"); fprintf (file, "#include \"shapes.inc\"\n\n"); fprintf (file, "camera {\n"); fprintf (file, " location <%f, %f, -300.0>\n", (bottom_right.x + upper_left.x) / 2, (bottom_right.y + upper_left.y) / 2); fprintf (file, " look_at <%f, %f, 0.0>\n", (bottom_right.x + upper_left.x) / 2, (bottom_right.y + upper_left.y) / 2); fprintf (file, " angle %f\n", 2 * atan((((bottom_right.x + upper_left.x) / 2) - upper_left.x) / 300) * 180 / PI); fprintf (file, "}\n\n"); fprintf (file, "light_source {\n"); fprintf (file, " <%f, %f, -320>\n", (bottom_right.x + upper_left.x) / 2, (bottom_right.y + upper_left.y) / 2); fprintf (file, " color rgb <1, 1, 1>\n"); fprintf (file, "}\n\n"); if(object_name) fprintf (file, "#declare %s =\n\n", object_name); fprintf (file, "difference {\n"); fprintf (file, "\tunion {\n"); /* run through all the nets in the layer */ for (currentNet = workingImage->netlist; currentNet; currentNet = currentNet->next) { dbgprintf("*******************************\n"); dbgprintf("currentNet->layer->polarity = %s\n", gerbv_polarity[currentNet->layer->polarity]); if (currentNet->aperture_state != GERBV_APERTURE_STATE_FLASH) { dbgprintf("currentNet->start_x = %f\n", currentNet->start_x); dbgprintf("currentNet->start_y = %f\n", currentNet->start_y); } dbgprintf("currentNet->stop_x = %f\n", currentNet->stop_x); dbgprintf("currentNet->stop_y = %f\n", currentNet->stop_y); dbgprintf("currentNet->aperture = %d\n", currentNet->aperture); dbgprintf("currentNet->aperture_state = %s\n", gerbv_aperture_state[currentNet->aperture_state]); dbgprintf("currentNet->interpolation = %s\n", gerbv_interpolation[currentNet->interpolation]); if(currentNet->cirseg != NULL) { dbgprintf("currentNet->cirseg->cp_x = %f\n", currentNet->cirseg->cp_x); dbgprintf("currentNet->cirseg->cp_x = %f\n", currentNet->cirseg->cp_y); dbgprintf("currentNet->cirseg->angle1 = %f\n", currentNet->cirseg->angle1); dbgprintf("currentNet->cirseg->angle2 = %f\n", currentNet->cirseg->angle2); } if(currentNet->label != NULL) dbgprintf("currentNet->label = %s\n", currentNet->label->str); if((workingImage->aperture[currentNet->aperture]) != NULL) { dbgprintf("aperture->type = %s\n", gerbv_aperture_type[workingImage->aperture[currentNet->aperture]->type]); dbgprintf("aperture->parameter[0] = %f\n", workingImage->aperture[currentNet->aperture]->parameter[0]); dbgprintf("aperture->parameter[1] = %f\n", workingImage->aperture[currentNet->aperture]->parameter[1]); } dbgprintf("*******************************\n\n"); if(currentNet->interpolation == GERBV_INTERPOLATION_PAREA_START) { start_polygon = 1; current_point = 0; } if(currentNet->layer->polarity == GERBV_POLARITY_CLEAR && polarity_clear == 0) { polarity_clear = 1; were_was_some_clear = 1; fprintf(file, "\t}\n\n"); fprintf(file, "\tunion {\n"); } if(currentNet->layer->polarity == GERBV_POLARITY_DARK && polarity_clear == 1) { fprintf(file, "\t}\n"); fprintf(file, "}\n"); polarity_clear = 0; } switch(currentNet->aperture_state) { case GERBV_APERTURE_STATE_OFF: break; case GERBV_APERTURE_STATE_FLASH: if(currentNet->interpolation != GERBV_INTERPOLATION_PAREA_START) { switch(workingImage->aperture[currentNet->aperture]->type) { case GERBV_APTYPE_RECTANGLE: fprintf(file, "\t\tbox {\n"); fprintf(file, "\t\t\t<%f, %f, %f>, <%f, %f, %f>\n", (currentNet->stop_x) - ((workingImage->aperture[currentNet->aperture]->parameter[0] / 2)), (currentNet->stop_y) + ((workingImage->aperture[currentNet->aperture]->parameter[1] / 2)), polarity_clear?-1.0:0, (currentNet->stop_x) + ((workingImage->aperture[currentNet->aperture]->parameter[0] / 2)), (currentNet->stop_y) - ((workingImage->aperture[currentNet->aperture]->parameter[1] / 2)), polarity_clear?1.0:COPPER_WIDTH); fprintf(file, "\t\t\tpigment {%s}\n", COLOR); fprintf(file, "\t\t}\n"); break; case GERBV_APTYPE_CIRCLE: fprintf(file, "\t\tcylinder {\n"); fprintf(file, "\t\t\t <%f, %f, %f>, <%f, %f, %f>, %f\n", (currentNet->stop_x), (currentNet->stop_y), polarity_clear?-1.0:0, (currentNet->stop_x), (currentNet->stop_y), polarity_clear?1.0:COPPER_WIDTH, (workingImage->aperture[currentNet->aperture]->parameter[0] / 2)); fprintf(file, "\t\t\tpigment {%s}\n", COLOR); fprintf(file, "\t\t}\n"); break; default: printf("aperture not handled !!!\n"); } break; } case GERBV_APERTURE_STATE_ON: switch(currentNet->interpolation) { case GERBV_INTERPOLATION_PAREA_END: polygon[current_point].x = currentNet->start_x; polygon[current_point].y = currentNet->start_y; current_point++; start_polygon = 0; for(i=0;i<current_point;i++) dbgprintf("polygon[%d].x = %f, polygon[%d].y = %f\n", i, polygon[i].x, i, polygon[i].y); draw_polygon(file, polygon, current_point); break; case GERBV_INTERPOLATION_LINEARx1: dbgprintf("------------- Start polygon = %d\n", start_polygon); dbgprintf("------------- current_point = %d\n", current_point); if(start_polygon) { polygon[current_point].x = currentNet->start_x; polygon[current_point].y = currentNet->start_y; current_point++; } else generate_pov_line(file, currentNet->start_x, currentNet->start_y, currentNet->stop_x, currentNet->stop_y, (workingImage->aperture[currentNet->aperture]->parameter[0] / 2)); break; case GERBV_INTERPOLATION_CCW_CIRCULAR: if(start_polygon) generate_arc_points(currentNet->start_x, currentNet->start_y, currentNet->stop_x, currentNet->stop_y, currentNet->cirseg->cp_x, currentNet->cirseg->cp_y, polygon, COUNTER_CLOCKWISE, NB_ARC_POINT, ¤t_point); break; case GERBV_INTERPOLATION_CW_CIRCULAR: if(start_polygon) generate_arc_points(currentNet->start_x, currentNet->start_y, currentNet->stop_x, currentNet->stop_y, currentNet->cirseg->cp_x, currentNet->cirseg->cp_y, polygon, CLOCKWISE, NB_ARC_POINT, ¤t_point); break; case GERBV_INTERPOLATION_PAREA_START: break; default: printf("interpolation not handled -> %s!!!\n", gerbv_interpolation[currentNet->interpolation]); } break; default: printf("aperture_state not handled -> %s!!!\n", gerbv_aperture_type[workingImage->aperture[currentNet->aperture]->type]); } } gerbv_destroy_image (workingImage); if(!were_was_some_clear || polarity_clear) { fprintf(file, "\t}\n"); fprintf(file, "}\n"); } fclose(file); return 0; }
gerbv_image_t * gerbv_create_image(gerbv_image_t *image, const gchar *type) { gerbv_destroy_image(image); /* Malloc space for image */ if ((image = (gerbv_image_t *)g_malloc(sizeof(gerbv_image_t))) == NULL) { return NULL; } memset((void *)image, 0, sizeof(gerbv_image_t)); /* Malloc space for image->netlist */ if ((image->netlist = (gerbv_net_t *)g_malloc(sizeof(gerbv_net_t))) == NULL) { g_free(image); return NULL; } memset((void *)image->netlist, 0, sizeof(gerbv_net_t)); /* Malloc space for image->info */ if ((image->info = (gerbv_image_info_t *)g_malloc(sizeof(gerbv_image_info_t))) == NULL) { g_free(image->netlist); g_free(image); return NULL; } memset((void *)image->info, 0, sizeof(gerbv_image_info_t)); /* Set aside position for stats struct */ image->gerbv_stats = NULL; image->drill_stats = NULL; image->info->min_x = HUGE_VAL; image->info->min_y = HUGE_VAL; image->info->max_x = -HUGE_VAL; image->info->max_y = -HUGE_VAL; /* create our first layer and fill with non-zero default values */ image->layers = g_new0 (gerbv_layer_t, 1); image->layers->stepAndRepeat.X = 1; image->layers->stepAndRepeat.Y = 1; image->layers->polarity = GERBV_POLARITY_DARK; /* create our first netstate and fill with non-zero default values */ image->states = g_new0 (gerbv_netstate_t, 1); image->states->scaleA = 1; image->states->scaleB = 1; /* fill in some values for our first net */ image->netlist->layer = image->layers; image->netlist->state = image->states; if (type == NULL) image->info->type = g_strdup ("unknown"); else image->info->type = g_strdup (type); /* the individual file parsers will have to set this. */ image->info->attr_list = NULL; image->info->n_attr = 0; return image; }
/* ------------------------------------------------------------------ */ int main(int argc, char *argv[]) { int read_opt; int i,r,g,b,a; int req_width = -1, req_height = -1; #ifdef HAVE_GETOPT_LONG /*int req_x = 0, req_y = 0;*/ char *rest; #endif char *project_filename = NULL; gboolean exportFromCommandline = FALSE, userSuppliedOrigin=FALSE, userSuppliedWindow=FALSE, userSuppliedAntiAlias=FALSE, userSuppliedWindowInPixels=FALSE, userSuppliedDpi=FALSE; gint layerctr =0, transformCount = 0, exportType = 0; gdouble initial_rotation = 0.0; gboolean initial_mirror_x = FALSE; gboolean initial_mirror_y = FALSE; gchar *exportFilename = NULL; gfloat userSuppliedOriginX=0.0,userSuppliedOriginY=0.0,userSuppliedDpiX=72.0, userSuppliedDpiY=72.0, userSuppliedWidth=0, userSuppliedHeight=0, userSuppliedBorder=0.05; #if ENABLE_NLS setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif /* * Setup the screen info. Must do this before getopt, since getopt * eventually will set some variables in screen. */ memset((void *)&screen, 0, sizeof(gerbv_screen_t)); screen.state = NORMAL; mainProject = gerbv_create_project(); mainProject->execname = g_strdup(argv[0]); mainProject->execpath = g_path_get_dirname(argv[0]); /* set default rendering mode */ #ifdef WIN32 /* Cairo seems to render faster on Windows, so use it for default */ screenRenderInfo.renderType = GERBV_RENDER_TYPE_CAIRO_NORMAL; #else screenRenderInfo.renderType = GERBV_RENDER_TYPE_GDK; #endif logToFileOption = FALSE; logToFileFilename = NULL; /* * Now process command line flags */ while ( #ifdef HAVE_GETOPT_LONG (read_opt = getopt_long(argc, argv, opt_options, longopts, &longopt_idx)) #else (read_opt = getopt(argc, argv, opt_options)) #endif /* HAVE_GETOPT_LONG */ != -1) { switch (read_opt) { #ifdef HAVE_GETOPT_LONG case 0: /* Only long options like GDK/GTK debug */ switch (longopt_val) { case 0: /* default value if nothing is set */ fprintf(stderr, _("Not handled option %s\n"), longopts[longopt_idx].name); break; case 1: /* geometry */ errno = 0; req_width = (int)strtol(optarg, &rest, 10); if (errno) { perror(_("Width")); break; } if (rest[0] != 'x'){ fprintf(stderr, _("Split X and Y parameters with an x\n")); break; } rest++; errno = 0; req_height = (int)strtol(rest, &rest, 10); if (errno) { perror(_("Height")); break; } /* if ((rest[0] == 0) || ((rest[0] != '-') && (rest[0] != '+'))) break; errno = 0; req_x = (int)strtol(rest, &rest, 10); if (errno) { perror("X"); break; } if ((rest[0] == 0) || ((rest[0] != '-') && (rest[0] != '+'))) break; errno = 0; req_y = (int)strtol(rest, &rest, 10); if (errno) { perror("Y"); break; } */ break; default: break; } break; #endif /* HAVE_GETOPT_LONG */ case 'B' : if (optarg == NULL) { fprintf(stderr, _("You must specify the border in the format <alpha>.\n")); exit(1); } if (strlen (optarg) > 10) { fprintf(stderr, _("Specified border is not recognized.\n")); exit(1); } sscanf (optarg,"%f",&userSuppliedBorder); if (userSuppliedBorder < 0) { fprintf(stderr, _("Specified border is smaller than zero!\n")); exit(1); } userSuppliedBorder/=100.0; break; case 'D' : if (optarg == NULL) { fprintf(stderr, _("You must give an resolution in the format <DPI XxDPI Y> or <DPI_X_and_Y>.\n")); exit(1); } if (strlen (optarg) > 20) { fprintf(stderr, _("Specified resolution is not recognized.\n")); exit(1); } if(strchr(optarg, 'x')!=NULL){ sscanf (optarg,"%fx%f",&userSuppliedDpiX,&userSuppliedDpiY); }else{ sscanf (optarg,"%f",&userSuppliedDpiX); userSuppliedDpiY = userSuppliedDpiX; } if ((userSuppliedDpiX <= 0) || (userSuppliedDpiY <= 0)) { fprintf(stderr, _("Specified resolution should be greater than 0.\n")); exit(1); } userSuppliedDpi=TRUE; break; case 'O' : if (optarg == NULL) { fprintf(stderr, _("You must give an origin in the format <lower_left_X x lower_left_Y>.\n")); exit(1); } if (strlen (optarg) > 20) { fprintf(stderr, _("Specified origin is not recognized.\n")); exit(1); } sscanf (optarg,"%fx%f",&userSuppliedOriginX,&userSuppliedOriginY); userSuppliedOrigin=TRUE; break; case 'V' : printf(_("gerbv version %s\n"), VERSION); printf(_("Copyright (C) 2001 -- 2008 by Stefan Petersen\n" "and the respective original authors listed in the source files.\n")); exit(0); case 'a' : userSuppliedAntiAlias = TRUE; break; case 'b' : // Set background to this color if (optarg == NULL) { fprintf(stderr, _("You must give an background color in the hex-format <#RRGGBB>.\n")); exit(1); } if ((strlen (optarg) != 7)||(optarg[0]!='#')) { fprintf(stderr, _("Specified color format is not recognized.\n")); exit(1); } r=g=b=-1; sscanf (optarg,"#%2x%2x%2x",&r,&g,&b); if ( (r<0)||(r>255)||(g<0)||(g>255)||(b<0)||(b>255)) { fprintf(stderr, _("Specified color values should be between 00 and FF.\n")); exit(1); } mainProject->background.red = r*257; mainProject->background.green = g*257; mainProject->background.blue = b*257; break; case 'f' : // Set layer colors to this color (foreground color) if (optarg == NULL) { fprintf(stderr, _("You must give an foreground color in the hex-format <#RRGGBB> or <#RRGGBBAA>.\n")); exit(1); } if (((strlen (optarg) != 7)&&(strlen (optarg) != 9))||(optarg[0]!='#')) { fprintf(stderr, _("Specified color format is not recognized.\n")); exit(1); } r=g=b=a=-1; if(strlen(optarg)==7){ sscanf (optarg,"#%2x%2x%2x",&r,&g,&b); a=177; } else{ sscanf (optarg,"#%2x%2x%2x%2x",&r,&g,&b,&a); } if ( (r<0)||(r>255)||(g<0)||(g>255)||(b<0)||(b>255)||(a<0)||(a>255) ) { fprintf(stderr, _("Specified color values should be between 0x00 (0) and 0xFF (255).\n")); exit(1); } mainDefaultColors[layerctr].red = r; mainDefaultColors[layerctr].green = g; mainDefaultColors[layerctr].blue = b; mainDefaultColors[layerctr].alpha = a; layerctr++; /* just reset the counter back to 0 if we read too many */ if (layerctr == NUMBER_OF_DEFAULT_COLORS) layerctr = 0; break; case 'r' : // Set initial orientation for all layers (rotation) if (optarg == NULL) { fprintf(stderr, _("You must give the initial rotation angle\n")); exit(1); } errno = 0; initial_rotation = (gdouble)strtod(optarg, &rest); if (errno) { perror(_("Rotate")); exit(1); } if (*rest) { fprintf(stderr, _("Failed parsing rotate value\n")); exit(1); } break; case 'm' : // Set initial mirroring state for all layers if (optarg == NULL) { fprintf(stderr, _("You must give the axis to mirror about\n")); exit(1); } if (strchr(optarg, 'x') != NULL || strchr(optarg, 'X') != NULL) { initial_mirror_x = TRUE; } if (strchr(optarg, 'y') != NULL || strchr(optarg, 'Y') != NULL) { initial_mirror_y = TRUE; } if (!(initial_mirror_x || initial_mirror_y)) { fprintf(stderr, _("Failed parsing mirror axis\n")); exit(1); } break; case 'l' : if (optarg == NULL) { fprintf(stderr, _("You must give a filename to send log to\n")); exit(1); } logToFileOption = TRUE; logToFileFilename = optarg; break; case 'o' : if (optarg == NULL) { fprintf(stderr, _("You must give a filename to export to.\n")); exit(1); } exportFilename = optarg; break; case 'p' : if (optarg == NULL) { fprintf(stderr, _("You must give a project filename\n")); exit(1); } project_filename = optarg; break; case 't' : if (optarg == NULL) { fprintf(stderr, _("You must give a filename to read the tools from.\n")); exit(1); } if (!gerbv_process_tools_file(optarg)) { fprintf(stderr, _("*** ERROR processing tools file \"%s\".\n"), optarg); fprintf(stderr, _("Make sure all lines of the file are formatted like this:\n" "T01 0.024\nT02 0.032\nT03 0.040\n...\n" "*** EXITING to prevent erroneous display.\n")); exit(1); } break; case 'T' : // Translate the layer if (optarg == NULL) { fprintf(stderr, _("You must give a translation in the format <X,Y>.\n")); exit(1); } if (strlen (optarg) > 30) { fprintf(stderr, _("The translation format is not recognized.\n")); exit(1); } float transX=0, transY=0; sscanf (optarg,"%f,%f",&transX,&transY); mainDefaultTransformations[transformCount].translateX = transX; mainDefaultTransformations[transformCount].translateY = transY; transformCount++; /* just reset the counter back to 0 if we read too many */ if (transformCount == NUMBER_OF_DEFAULT_TRANSFORMATIONS) transformCount = 0; break; case 'w': userSuppliedWindowInPixels = TRUE; case 'W' : if (optarg == NULL) { fprintf(stderr, _("You must give a window size in the format <width x height>.\n")); exit(1); } if (strlen (optarg) > 20) { fprintf(stderr, _("Specified window size is not recognized.\n")); exit(1); } sscanf (optarg, "%fx%f", &userSuppliedWidth, &userSuppliedHeight); if (((userSuppliedWidth < 0.001) || (userSuppliedHeight < 0.001)) || ((userSuppliedWidth > 2000) || (userSuppliedHeight > 2000))) { fprintf(stderr, _("Specified window size is out of bounds.\n")); exit(1); } userSuppliedWindow = TRUE; break; case 'x' : if (optarg == NULL) { fprintf(stderr, _("You must supply an export type.\n")); exit(1); } if (strcmp (optarg,"png") == 0) { exportType = 1; exportFromCommandline = TRUE; } else if (strcmp (optarg,"pdf") == 0) { exportType = 2; exportFromCommandline = TRUE; } else if (strcmp (optarg,"svg") == 0) { exportType = 3; exportFromCommandline = TRUE; } else if (strcmp (optarg,"ps") == 0) { exportType = 4; exportFromCommandline = TRUE; } else if (strcmp (optarg,"rs274x") == 0) { exportType = 5; exportFromCommandline = TRUE; } else if (strcmp (optarg,"drill") == 0) { exportType = 6; exportFromCommandline = TRUE; } else { fprintf(stderr, _("Unrecognized export type.\n")); exit(1); } break; case 'd': screen.dump_parsed_image = 1; break; case '?': case 'h': #ifdef HAVE_GETOPT_LONG printf(_("Usage: gerbv [OPTIONS...] [FILE...]\n\n" "Available options:\n" " -B, --border=<b> Border around the image in percent of the\n" " width/height. Defaults to 5%%.\n" " -D, --dpi=<XxY>or<R> Resolution (Dots per inch) for the output\n" " bitmap. With the format <XxY>, different\n" " resolutions for X- and Y-direction are used.\n" " With the format <R>, both are the same.\n" " -O, --origin=<XxY> Use the specified coordinates (in inches).\n" " for the lower left corner.\n" " -V, --version Print version of gerbv.\n" " -a, --antialias Use antialiasing for generated bitmap output.\n" " -b, --background=<hex> Use background color <hex> (like #RRGGBB).\n" " -f, --foreground=<hex> Use foreground color <hex> (like #RRGGBB or\n" " #RRGGBBAA for setting the alpha).\n" " Use multiple -f flags to set the color for\n" " multiple layers.\n" " -r, --rotate=<degree> Set initial orientation for all layers.\n" " -m, --mirror=<axis> Set initial mirroring axis (X or Y).\n" " -h, --help Print this help message.\n" " -l, --log=<logfile> Send error messages to <logfile>.\n" " -o, --output=<filename> Export to <filename>.\n" " -p, --project=<prjfile> Load project file <prjfile>.\n" " -W, --window_inch=<WxH> Window size in inches <WxH> for the\n" " exported image.\n" " -w, --window=<WxH> Window size in pixels <WxH> for the\n" " exported image. Autoscales to fit\n" " if no resolution is specified. If a\n" " resolution is specified, it will clip.\n" " -t, --tools=<toolfile> Read Excellon tools from file <toolfile>.\n" " -T, --translate=<X,Y> Translate the image by <X,Y> (useful for\n" " arranging panels). Use multiple -T flags\n" " for multiple layers.\n" " -x, --export=<png/pdf/ps/svg/ Export a rendered picture to a file with\n" " rs274x/drill> the specified format.\n")); #else printf(_("Usage: gerbv [OPTIONS...] [FILE...]\n\n" "Available options:\n" " -B<b> Border around the image in percent of the\n" " width/height. Defaults to 5%%.\n" " -D<XxY>or<R> Resolution (Dots per inch) for the output\n" " bitmap. With the format <XxY>, different\n" " resolutions for X- and Y-direction are used.\n" " With the format <R>, both are the same.\n" " -O<XxY> Use the specified coordinates (in inches)\n" " for the lower left corner.\n" " -V Print version of gerbv.\n" " -a Use antialiasing for generated bitmap output.\n" " -b<hexcolor> Use background color <hexcolor> (like #RRGGBB).\n" " -f<hexcolor> Use foreground color <hexcolor> (like #RRGGBB or\n" " #RRGGBBAA for setting the alpha).\n" " Use multiple -f flags to set the color for\n" " multiple layers.\n" " -r<degree> Set initial orientation for all layers.\n" " -m<axis> Set initial mirroring axis (X or Y).\n" " -h Print this help message.\n" " -l<logfile> Send error messages to <logfile>.\n" " -o<filename> Export to <filename>.\n" " -p<prjfile> Load project file <prjfile>.\n" " -W<WxH> Window size in inches <WxH> for the\n" " exported image.\n" " -w<WxH> Window size in pixels <WxH> for the\n" " exported image. Autoscales to fit\n" " if no resolution is specified. If a\n" " resolution is specified, it will clip.\n" " exported image.\n" " -t<toolfile> Read Excellon tools from file <toolfile>\n" " -T<X,Y> Translate the image by <X,Y> (useful for\n" " arranging panels). Use multiple -T flags\n" " for multiple layers.\n" " -x <png/pdf/ps/svg/ Export a rendered picture to a file with\n" " rs274x/drill> the specified format.\n")); #endif /* HAVE_GETOPT_LONG */ exit(1); break; default : printf(_("Not handled option [%d=%c]\n"), read_opt, read_opt); } } /* * If project is given, load that one and use it for files and colors. * Else load files (eventually) given on the command line. * This limits you to either give files on the commandline or just load * a project. */ if (project_filename) { printf(_("Loading project %s...\n"), project_filename); /* calculate the absolute pathname to the project if the user used a relative path */ g_free (mainProject->path); if (!g_path_is_absolute(project_filename)) { gchar *fullName = g_build_filename (g_get_current_dir (), project_filename, NULL); main_open_project_from_filename (mainProject, fullName); mainProject->path = g_path_get_dirname (fullName); g_free (fullName); } else { main_open_project_from_filename (mainProject, project_filename); mainProject->path = g_path_get_dirname (project_filename); } } else { gint loadedIndex = 0; for(i = optind ; i < argc; i++) { g_free (mainProject->path); if (!g_path_is_absolute(argv[i])) { gchar *fullName = g_build_filename (g_get_current_dir (), argv[i], NULL); gerbv_open_layer_from_filename_with_color (mainProject, fullName, mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].red*257, mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].green*257, mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].blue*257, mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].alpha*257); mainProject->path = g_path_get_dirname (fullName); g_free (fullName); } else { gerbv_open_layer_from_filename_with_color (mainProject, argv[i], mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].red*257, mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].green*257, mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].blue*257, mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].alpha*257); mainProject->path = g_path_get_dirname (argv[i]); } loadedIndex++; } } if (initial_rotation != 0.0) { /* Set initial layer orientation */ gdouble initial_radians = M_PI*initial_rotation/180; dprintf("Rotating all layers by %.0f degrees\n", (float) initial_rotation); for(i = 0; i < mainProject->max_files; i++) { if (mainProject->file[i]) mainProject->file[i]->transform.rotation = initial_radians; } } if (initial_mirror_x || initial_mirror_y) { /* Set initial mirroring of all layers */ if (initial_mirror_x) { dprintf("Mirroring all layers about x axis\n"); } if (initial_mirror_y) { dprintf("Mirroring all layers about y axis\n"); } for (i = 0; i < mainProject->max_files; i++) { if (mainProject->file[i]) { mainProject->file[i]->transform.mirrorAroundX = initial_mirror_x; mainProject->file[i]->transform.mirrorAroundY = initial_mirror_y; } } } screen.unit = GERBV_DEFAULT_UNIT; if (exportFromCommandline) { /* load the info struct with the default values */ gboolean freeFilename = FALSE; if (!exportFilename) { if (exportType == 1) { exportFilename = g_strdup ("output.png"); } else if (exportType == 2) { exportFilename = g_strdup ("output.pdf"); } else if (exportType == 3) { exportFilename = g_strdup ("output.svg"); } else if (exportType == 4){ exportFilename = g_strdup ("output.ps"); } else if (exportType == 5){ exportFilename = g_strdup ("output.gbx"); } else { exportFilename = g_strdup ("output.cnc"); } freeFilename = TRUE; } gerbv_render_size_t bb; gerbv_render_get_boundingbox(mainProject, &bb); // Set origin to the left-bottom corner if it is not specified if(!userSuppliedOrigin){ userSuppliedOriginX = bb.left; userSuppliedOriginY = bb.top; } float width = bb.right - userSuppliedOriginX + 0.001; // Plus a little extra to prevent from float height = bb.bottom - userSuppliedOriginY + 0.001; // missing items due to round-off errors // If the user did not specify a height and width, autoscale w&h till full size from origin. if(!userSuppliedWindow){ userSuppliedWidth = width; userSuppliedHeight = height; }else{ // If size was specified in pixels, and no resolution was specified, autoscale resolution till fit if( (!userSuppliedDpi)&& userSuppliedWindowInPixels){ userSuppliedDpiX = MIN(((userSuppliedWidth-0.5) / width),((userSuppliedHeight-0.5) / height)); userSuppliedDpiY = userSuppliedDpiX; userSuppliedOriginX -= 0.5/userSuppliedDpiX; userSuppliedOriginY -= 0.5/userSuppliedDpiY; } } // Add the border size (if there is one) if(userSuppliedBorder!=0){ // If supplied in inches, add a border around the image if(!userSuppliedWindowInPixels){ userSuppliedOriginX -= (userSuppliedWidth*userSuppliedBorder)/2.0; userSuppliedOriginY -= (userSuppliedHeight*userSuppliedBorder)/2.0; userSuppliedWidth += userSuppliedWidth*userSuppliedBorder; userSuppliedHeight += userSuppliedHeight*userSuppliedBorder; } // If supplied in pixels, shrink image content for border_size else{ userSuppliedOriginX -= ((userSuppliedWidth/userSuppliedDpiX)*userSuppliedBorder)/2.0; userSuppliedOriginY -= ((userSuppliedHeight/userSuppliedDpiX)*userSuppliedBorder)/2.0; userSuppliedDpiX -= (userSuppliedDpiX*userSuppliedBorder); userSuppliedDpiY -= (userSuppliedDpiY*userSuppliedBorder); } } if(!userSuppliedWindowInPixels){ userSuppliedWidth *= userSuppliedDpiX; userSuppliedHeight *= userSuppliedDpiY; } // Make sure there is something valid in it. It could become negative if // the userSuppliedOrigin is further than the bb.right or bb.top. if(userSuppliedWidth <=0) userSuppliedWidth = 1; if(userSuppliedHeight <=0) userSuppliedHeight = 1; gerbv_render_info_t renderInfo = {userSuppliedDpiX, userSuppliedDpiY, userSuppliedOriginX, userSuppliedOriginY, userSuppliedAntiAlias?3:2, userSuppliedWidth,userSuppliedHeight }; if (exportType == 1) { gerbv_export_png_file_from_project (mainProject, &renderInfo, exportFilename); } else if (exportType == 2) { gerbv_export_pdf_file_from_project (mainProject, &renderInfo, exportFilename); } else if (exportType == 3) { gerbv_export_svg_file_from_project (mainProject, &renderInfo, exportFilename); } else if (exportType == 4) { gerbv_export_postscript_file_from_project (mainProject, &renderInfo, exportFilename); } else if (exportType == 5) { if (mainProject->file[0]->image) { gerbv_image_t *exportImage; exportImage = gerbv_image_duplicate_image (mainProject->file[0]->image, &mainDefaultTransformations[0]); /* if we have more than one file, we need to merge them before exporting */ for(i = mainProject->last_loaded; i > 0; i--) { if (mainProject->file[i]) { gerbv_image_copy_image (mainProject->file[i]->image, &mainDefaultTransformations[i], exportImage); } } gerbv_export_rs274x_file_from_image (exportFilename, exportImage, &mainProject->file[0]->transform); gerbv_destroy_image (exportImage); } else { fprintf(stderr, _("A valid file was not loaded.\n")); exit(1); } } else if (exportType == 6) { if (mainProject->file[0]->image) { gerbv_image_t *exportImage; exportImage = gerbv_image_duplicate_image (mainProject->file[0]->image, &mainDefaultTransformations[0]); /* if we have more than one file, we need to merge them before exporting */ for(i = mainProject->last_loaded; i > 0; i--) { if (mainProject->file[i]) { gerbv_image_copy_image (mainProject->file[i]->image, &mainDefaultTransformations[i], exportImage); } } gerbv_export_drill_file_from_image (exportFilename, exportImage, &mainProject->file[0]->transform); gerbv_destroy_image (exportImage); } else { fprintf(stderr, _("A valid file was not loaded.\n")); exit(1); } } if (freeFilename) free (exportFilename); /* exit now and don't start up gtk if this is a command line export */ exit(0); } gtk_init (&argc, &argv); interface_create_gui (req_width, req_height); /* we've exited the GTK loop, so free all resources */ render_free_screen_resources(); gerbv_destroy_project (mainProject); return 0; } /* main */