00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00029 #ifdef HAVE_CONFIG_H
00030 #include "config.h"
00031 #endif
00032
00033 #include <assert.h>
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <errno.h>
00037
00038 #ifdef HAVE_STRING_H
00039 #include <string.h>
00040 #endif
00041
00042 #ifdef HAVE_UNISTD_H
00043 #include <unistd.h>
00044 #endif
00045
00046 #include <glib.h>
00047 #include <gtk/gtk.h>
00048 #include <gdk/gdk.h>
00049 #include <gdk/gdkkeysyms.h>
00050
00051 #ifdef HAVE_GETOPT_H
00052 #include <getopt.h>
00053 #endif
00054
00055 #include <locale.h>
00056
00057 #include "gerbv.h"
00058 #include "main.h"
00059 #include "callbacks.h"
00060 #include "interface.h"
00061 #include "render.h"
00062 #include "project.h"
00063
00064
00065 #define dprintf if(DEBUG) printf
00066
00067 #define NUMBER_OF_DEFAULT_COLORS 18
00068 #define NUMBER_OF_DEFAULT_TRANSFORMATIONS 20
00069
00070 static gerbv_layer_color mainDefaultColors[NUMBER_OF_DEFAULT_COLORS] = {
00071 {115,115,222,177},
00072 {255,127,115,177},
00073 {193,0,224,177},
00074 {117,242,103,177},
00075 {0,195,195,177},
00076 {213,253,51,177},
00077 {209,27,104,177},
00078 {255,197,51,177},
00079 {186,186,186,177},
00080 {211,211,255,177},
00081 {253,210,206,177},
00082 {236,194,242,177},
00083 {208,249,204,177},
00084 {183,255,255,177},
00085 {241,255,183,177},
00086 {255,202,225,177},
00087 {253,238,197,177},
00088 {226,226,226,177}
00089 };
00090
00091 static gerbv_user_transformation_t mainDefaultTransformations[NUMBER_OF_DEFAULT_TRANSFORMATIONS] = {
00092 {0,0,0,0,FALSE},
00093 {0,0,0,0,FALSE},
00094 {0,0,0,0,FALSE},
00095 {0,0,0,0,FALSE},
00096 {0,0,0,0,FALSE},
00097 {0,0,0,0,FALSE},
00098 {0,0,0,0,FALSE},
00099 {0,0,0,0,FALSE},
00100 {0,0,0,0,FALSE},
00101 {0,0,0,0,FALSE},
00102 {0,0,0,0,FALSE},
00103 {0,0,0,0,FALSE},
00104 {0,0,0,0,FALSE},
00105 {0,0,0,0,FALSE},
00106 {0,0,0,0,FALSE},
00107 {0,0,0,0,FALSE},
00108 {0,0,0,0,FALSE},
00109 {0,0,0,0,FALSE},
00110 {0,0,0,0,FALSE},
00111 {0,0,0,0,FALSE},
00112 };
00113
00114 #ifdef HAVE_GETOPT_LONG
00115 int longopt_val = 0;
00116 int longopt_idx = 0;
00117 const struct option longopts[] = {
00118
00119 {"border", required_argument, NULL, 'B'},
00120 {"dpi", required_argument, NULL, 'D'},
00121 {"version", no_argument, NULL, 'V'},
00122 {"origin", required_argument, NULL, 'O'},
00123 {"window_inch", required_argument, NULL, 'W'},
00124 {"antialias", no_argument, NULL, 'a'},
00125 {"background", required_argument, NULL, 'b'},
00126 {"dump", no_argument, NULL, 'd'},
00127 {"foreground", required_argument, NULL, 'f'},
00128 {"help", no_argument, NULL, 'h'},
00129 {"log", required_argument, NULL, 'l'},
00130 {"output", required_argument, NULL, 'o'},
00131 {"project", required_argument, NULL, 'p'},
00132 {"tools", required_argument, NULL, 't'},
00133 {"translate", required_argument, NULL, 'T'},
00134 {"window", required_argument, NULL, 'w'},
00135 {"export", required_argument, NULL, 'x'},
00136 {"geometry", required_argument, &longopt_val, 1},
00137
00138 {"gtk-module", required_argument, &longopt_val, 2},
00139 {"g-fatal-warnings",no_argument, &longopt_val, 2},
00140 {"gtk-debug", required_argument, &longopt_val, 2},
00141 {"gtk-no-debug", required_argument, &longopt_val, 2},
00142 {"gdk-debug", required_argument, &longopt_val, 2},
00143 {"gdk-no-debug", required_argument, &longopt_val, 2},
00144 {"display", required_argument, &longopt_val, 2},
00145 {"sync", no_argument, &longopt_val, 2},
00146 {"no-xshm", no_argument, &longopt_val, 2},
00147 {"name", required_argument, &longopt_val, 2},
00148 {"class", required_argument, &longopt_val, 2},
00149 {0, 0, 0, 0},
00150 };
00151 #endif
00152 const char *opt_options = "Vadh:B:D:O:W:b:f:l:o:p:t:T:w:x:";
00153
00157 gerbv_project_t *mainProject;
00158 gerbv_screen_t screen;
00159
00160 gboolean logToFileOption;
00161 gchar *logToFileFilename;
00162
00163
00164 void
00165 main_open_project_from_filename(gerbv_project_t *gerbvProject, gchar *filename)
00166 {
00167 project_list_t *project_list = NULL;
00168
00169 dprintf("Opening project = %s\n", (gchar *) filename);
00170 project_list = read_project_file(filename);
00171
00172 if (project_list) {
00173 project_list_t *pl_tmp;
00174
00175 while (project_list) {
00176 GdkColor colorTemplate = {0,project_list->rgb[0],
00177 project_list->rgb[1],project_list->rgb[2]};
00178 if (project_list->layerno == -1) {
00179 gerbvProject->background = colorTemplate;
00180 } else {
00181 int idx = project_list->layerno;
00182 gchar *fullName = NULL;
00183 gchar *dirName = NULL;
00184
00185 if (!g_path_is_absolute (project_list->filename)) {
00186
00187 dirName = g_path_get_dirname (filename);
00188 fullName = g_build_filename (dirName, project_list->filename, NULL);
00189 } else {
00190 fullName = g_strdup (project_list->filename);
00191 }
00192 if (gerbv_open_image(gerbvProject, fullName, idx, FALSE,
00193 project_list->attr_list,
00194 project_list->n_attr, TRUE) == -1) {
00195 GERB_MESSAGE("could not read %s[%d]", fullName, idx);
00196 goto next_layer;
00197 }
00198 g_free (dirName);
00199 g_free (fullName);
00200
00201
00202
00203 gerbvProject->file[idx]->color = colorTemplate;
00204 gerbvProject->file[idx]->transform.inverted = project_list->inverted;
00205 gerbvProject->file[idx]->isVisible = project_list->visible;
00206 }
00207 next_layer:
00208 pl_tmp = project_list;
00209 project_list = project_list->next;
00210 g_free(pl_tmp->filename);
00211 g_free(pl_tmp);
00212 }
00213
00214
00215
00216
00217 if (gerbvProject->project) {
00218 g_free(gerbvProject->project);
00219 gerbvProject->project = NULL;
00220 }
00221 gerbvProject->project = g_strdup (filename);
00222 if (gerbvProject->project == NULL)
00223 GERB_FATAL_ERROR("malloc gerbvProject->project failed\n");
00224 } else {
00225 GERB_MESSAGE("could not read %s[%d]\n", (gchar *) filename,
00226 gerbvProject->last_loaded);
00227 }
00228 }
00229
00230
00231 void
00232 main_save_project_from_filename(gerbv_project_t *gerbvProject, gchar *filename)
00233 {
00234 project_list_t *project_list = NULL, *tmp;
00235 int idx;
00236 gchar *dirName = g_path_get_dirname (filename);
00237
00238 project_list = g_new0 (project_list_t, 1);
00239 project_list->next = project_list;
00240 project_list->layerno = -1;
00241 project_list->filename = gerbvProject->path;
00242 project_list->rgb[0] = gerbvProject->background.red;
00243 project_list->rgb[1] = gerbvProject->background.green;
00244 project_list->rgb[2] = gerbvProject->background.blue;
00245 project_list->next = NULL;
00246
00247
00248 for (idx = 0; idx < gerbvProject->max_files; idx++) {
00249 if (gerbvProject->file[idx]) {
00250 tmp = g_new0 (project_list_t, 1);
00251 tmp->next = project_list;
00252 tmp->layerno = idx;
00253
00254
00255
00256 if (strncmp (dirName, gerbvProject->file[idx]->name, strlen(dirName)) == 0) {
00257
00258 tmp->filename = (gerbvProject->file[idx]->name + strlen(dirName) + 1);
00259 } else {
00260
00261
00262 tmp->filename = gerbvProject->file[idx]->name;
00263 }
00264 tmp->rgb[0] = gerbvProject->file[idx]->color.red;
00265 tmp->rgb[1] = gerbvProject->file[idx]->color.green;
00266 tmp->rgb[2] = gerbvProject->file[idx]->color.blue;
00267 tmp->inverted = gerbvProject->file[idx]->transform.inverted;
00268 tmp->visible = gerbvProject->file[idx]->isVisible;
00269
00270 gerbv_save_layer_from_index(gerbvProject, idx, tmp->filename);
00271
00272 project_list = tmp;
00273 }
00274 }
00275
00276 if (write_project_file(gerbvProject, gerbvProject->project, project_list)) {
00277 GERB_MESSAGE("Failed to write project\n");
00278 }
00279 g_free (dirName);
00280 }
00281
00282
00283 void
00284 main_save_as_project_from_filename(gerbv_project_t *gerbvProject, gchar *filename)
00285 {
00286
00287
00288
00289
00290 if (gerbvProject->project) {
00291 g_free(gerbvProject->project);
00292 gerbvProject->project = NULL;
00293 }
00294 gerbvProject->project = g_strdup(filename);
00295 if (gerbvProject->project == NULL)
00296 GERB_FATAL_ERROR("malloc gerbvProject->project failed\n");
00297 main_save_project_from_filename (gerbvProject, filename);
00298 }
00299
00300
00301
00302 int
00303 main(int argc, char *argv[])
00304 {
00305 int read_opt;
00306 int i,r,g,b,a;
00307 int req_width = -1, req_height = -1;
00308 #ifdef HAVE_GETOPT_LONG
00309 int req_x = 0, req_y = 0;
00310 char *rest;
00311 #endif
00312 char *project_filename = NULL;
00313 gboolean exportFromCommandline = FALSE, userSuppliedOrigin=FALSE, userSuppliedWindow=FALSE,
00314 userSuppliedAntiAlias=FALSE, userSuppliedWindowInPixels=FALSE, userSuppliedDpi=FALSE;
00315 gint layerctr =0, transformCount = 0, exportType = 0;
00316 gchar *exportFilename = NULL;
00317 gfloat userSuppliedOriginX=0.0,userSuppliedOriginY=0.0,userSuppliedDpiX=72.0, userSuppliedDpiY=72.0,
00318 userSuppliedWidth=0, userSuppliedHeight=0, userSuppliedBorder=0.05;
00319
00320
00321
00322
00323
00324
00325 memset((void *)&screen, 0, sizeof(gerbv_screen_t));
00326 screen.state = NORMAL;
00327
00328 mainProject = gerbv_create_project();
00329 mainProject->execpath = g_path_get_dirname(argv[0]);
00330
00331 logToFileOption = FALSE;
00332 logToFileFilename = NULL;
00333
00334
00335
00336 while (
00337 #ifdef HAVE_GETOPT_LONG
00338 (read_opt = getopt_long(argc, argv, opt_options,
00339 longopts, &longopt_idx))
00340 #else
00341 (read_opt = getopt(argc, argv, opt_options))
00342 #endif
00343 != -1) {
00344
00345 switch (read_opt) {
00346 #ifdef HAVE_GETOPT_LONG
00347 case 0:
00348
00349 switch (longopt_val) {
00350 case 0:
00351 fprintf(stderr, "Not handled option %s\n", longopts[longopt_idx].name);
00352 break;
00353 case 1:
00354 errno = 0;
00355 req_width = (int)strtol(optarg, &rest, 10);
00356 if (errno) {
00357 perror("Width");
00358 break;
00359 }
00360 if (rest[0] != 'x'){
00361 fprintf(stderr, "Split X and Y parameters with an x\n");
00362 break;
00363 }
00364 rest++;
00365 errno = 0;
00366 req_height = (int)strtol(rest, &rest, 10);
00367 if (errno) {
00368 perror("Height");
00369 break;
00370 }
00371 if ((rest[0] == 0) || ((rest[0] != '-') && (rest[0] != '+')))
00372 break;
00373 errno = 0;
00374 req_x = (int)strtol(rest, &rest, 10);
00375 if (errno) {
00376 perror("X");
00377 break;
00378 }
00379 if ((rest[0] == 0) || ((rest[0] != '-') && (rest[0] != '+')))
00380 break;
00381 errno = 0;
00382 req_y = (int)strtol(rest, &rest, 10);
00383 if (errno) {
00384 perror("Y");
00385 break;
00386 }
00387 break;
00388 default:
00389 break;
00390 }
00391 break;
00392 #endif
00393 case 'B' :
00394 if (optarg == NULL) {
00395 fprintf(stderr, "You must specify the border in the format <alpha>.\n");
00396 exit(1);
00397 }
00398 if (strlen (optarg) > 10) {
00399 fprintf(stderr, "Specified border is not recognized.\n");
00400 exit(1);
00401 }
00402 sscanf (optarg,"%f",&userSuppliedBorder);
00403 if (userSuppliedBorder < 0) {
00404 fprintf(stderr, "Specified border is smaller than zero!\n");
00405 exit(1);
00406 }
00407 userSuppliedBorder/=100.0;
00408 break;
00409 case 'D' :
00410 if (optarg == NULL) {
00411 fprintf(stderr, "You must give an resolution in the format <DPI X,DPI Y> or <DPI_X_and_Y>.\n");
00412 exit(1);
00413 }
00414 if (strlen (optarg) > 20) {
00415 fprintf(stderr, "Specified resolution is not recognized.\n");
00416 exit(1);
00417 }
00418 if(strchr(optarg, 'x')!=NULL){
00419 sscanf (optarg,"%fx%f",&userSuppliedDpiX,&userSuppliedDpiY);
00420 }else{
00421 sscanf (optarg,"%f",&userSuppliedDpiX);
00422 userSuppliedDpiY = userSuppliedDpiX;
00423 }
00424 if ((userSuppliedDpiX <= 0) || (userSuppliedDpiY <= 0)) {
00425 fprintf(stderr, "Specified resolution should be greater than 0.\n");
00426 exit(1);
00427 }
00428 userSuppliedDpi=TRUE;
00429 break;
00430 case 'O' :
00431 if (optarg == NULL) {
00432 fprintf(stderr, "You must give an origin in the format <lower_left_X x lower_left_Y>.\n");
00433 exit(1);
00434 }
00435 if (strlen (optarg) > 20) {
00436 fprintf(stderr, "Specified origin is not recognized.\n");
00437 exit(1);
00438 }
00439 sscanf (optarg,"%fx%f",&userSuppliedOriginX,&userSuppliedOriginY);
00440 userSuppliedOrigin=TRUE;
00441 break;
00442 case 'V' :
00443 printf("gerbv version %s\n", VERSION);
00444 printf("(C) Stefan Petersen (spe@stacken.kth.se)\n");
00445 exit(0);
00446 case 'a' :
00447 userSuppliedAntiAlias = TRUE;
00448 break;
00449 case 'b' :
00450 if (optarg == NULL) {
00451 fprintf(stderr, "You must give an background color in the hex-format <#RRGGBB>.\n");
00452 exit(1);
00453 }
00454 if ((strlen (optarg) != 7)||(optarg[0]!='#')) {
00455 fprintf(stderr, "Specified color format is not recognized.\n");
00456 exit(1);
00457 }
00458 r=g=b=-1;
00459 sscanf (optarg,"#%2x%2x%2x",&r,&g,&b);
00460 if ( (r<0)||(r>255)||(g<0)||(g>255)||(b<0)||(b>255)) {
00461
00462 fprintf(stderr, "Specified color values should be between 00 and FF.\n");
00463 exit(1);
00464 }
00465 mainProject->background.red = r*257;
00466 mainProject->background.green = g*257;
00467 mainProject->background.blue = b*257;
00468 break;
00469 case 'f' :
00470 if (optarg == NULL) {
00471 #ifdef RENDER_USING_GDK
00472 fprintf(stderr, "You must give an foreground color in the hex-format <#RRGGBB>.\n");
00473 #else
00474 fprintf(stderr, "You must give an foreground color in the hex-format <#RRGGBB> or <#RRGGBBAA>.\n");
00475 #endif
00476 exit(1);
00477 }
00478 if (((strlen (optarg) != 7)&&(strlen (optarg) != 9))||(optarg[0]!='#')) {
00479 fprintf(stderr, "Specified color format is not recognized.\n");
00480 exit(1);
00481 }
00482 r=g=b=a=-1;
00483 if(strlen(optarg)==7){
00484 sscanf (optarg,"#%2x%2x%2x",&r,&g,&b);
00485 a=177;
00486 }
00487 else{
00488 sscanf (optarg,"#%2x%2x%2x%2x",&r,&g,&b,&a);
00489 }
00490
00491 if ( (r<0)||(r>255)||(g<0)||(g>255)||(b<0)||(b>255)||(a<0)||(a>255) ) {
00492
00493 fprintf(stderr, "Specified color values should be between 0x00 (0) and 0xFF (255).\n");
00494 exit(1);
00495 }
00496 mainDefaultColors[layerctr].red = r;
00497 mainDefaultColors[layerctr].green = g;
00498 mainDefaultColors[layerctr].blue = b;
00499 mainDefaultColors[layerctr].alpha = a;
00500 layerctr++;
00501
00502 if (layerctr == NUMBER_OF_DEFAULT_COLORS)
00503 layerctr = 0;
00504 break;
00505 case 'l' :
00506 if (optarg == NULL) {
00507 fprintf(stderr, "You must give a filename to send log to\n");
00508 exit(1);
00509 }
00510 logToFileOption = TRUE;
00511 logToFileFilename = optarg;
00512 break;
00513 case 'o' :
00514 if (optarg == NULL) {
00515 fprintf(stderr, "You must give a filename to export to.\n");
00516 exit(1);
00517 }
00518 exportFilename = optarg;
00519 break;
00520 case 'p' :
00521 if (optarg == NULL) {
00522 fprintf(stderr, "You must give a project filename\n");
00523 exit(1);
00524 }
00525 project_filename = optarg;
00526 break;
00527 case 't' :
00528 if (optarg == NULL) {
00529 fprintf(stderr, "You must give a filename to read the tools from.\n");
00530 exit(1);
00531 }
00532 if (!gerbv_process_tools_file(optarg)) {
00533 fprintf(stderr, "*** ERROR processing tools file \"%s\".\n", optarg);
00534 fprintf(stderr, "Make sure all lines of the file are formatted like this:\n");
00535 fprintf(stderr, "T01 0.024\nT02 0.032\nT03 0.040\n...\n");
00536 fprintf(stderr, "*** EXITING to prevent erroneous display.\n");
00537 exit(1);
00538 }
00539 break;
00540 case 'T' :
00541 if (optarg == NULL) {
00542 fprintf(stderr, "You must give a translation in the format <X,Y>.\n");
00543 exit(1);
00544 }
00545 if (strlen (optarg) > 30) {
00546 fprintf(stderr, "The translation format is not recognized.\n");
00547 exit(1);
00548 }
00549 float transX=0, transY=0;
00550
00551 sscanf (optarg,"%f,%f",&transX,&transY);
00552 mainDefaultTransformations[transformCount].translateX = transX;
00553 mainDefaultTransformations[transformCount].translateY = transY;
00554 transformCount++;
00555
00556 if (transformCount == NUMBER_OF_DEFAULT_TRANSFORMATIONS)
00557 transformCount = 0;
00558 break;
00559 case 'w':
00560 userSuppliedWindowInPixels = TRUE;
00561 case 'W' :
00562 if (optarg == NULL) {
00563 fprintf(stderr, "You must give a window size in the format <width x height>.\n");
00564 exit(1);
00565 }
00566 if (strlen (optarg) > 20) {
00567 fprintf(stderr, "Specified window size is not recognized.\n");
00568 exit(1);
00569 }
00570 sscanf (optarg, "%fx%f", &userSuppliedWidth, &userSuppliedHeight);
00571 if (((userSuppliedWidth < 0.001) || (userSuppliedHeight < 0.001)) ||
00572 ((userSuppliedWidth > 2000) || (userSuppliedHeight > 2000))) {
00573 fprintf(stderr, "Specified window size is out of bounds.\n");
00574 exit(1);
00575 }
00576 userSuppliedWindow = TRUE;
00577 break;
00578 case 'x' :
00579 if (optarg == NULL) {
00580 fprintf(stderr, "You must supply an export type.\n");
00581 exit(1);
00582 }
00583 if (strcmp (optarg,"png") == 0) {
00584 exportType = 1;
00585 exportFromCommandline = TRUE;
00586 }
00587 #ifndef RENDER_USING_GDK
00588 else if (strcmp (optarg,"pdf") == 0) {
00589 exportType = 2;
00590 exportFromCommandline = TRUE;
00591 } else if (strcmp (optarg,"svg") == 0) {
00592 exportType = 3;
00593 exportFromCommandline = TRUE;
00594 } else if (strcmp (optarg,"ps") == 0) {
00595 exportType = 4;
00596 exportFromCommandline = TRUE;
00597 }
00598 #endif
00599 else if (strcmp (optarg,"rs274x") == 0) {
00600 exportType = 5;
00601 exportFromCommandline = TRUE;
00602 }
00603 else if (strcmp (optarg,"drill") == 0) {
00604 exportType = 6;
00605 exportFromCommandline = TRUE;
00606 }
00607 else {
00608 fprintf(stderr, "Unrecognized export type.\n");
00609 exit(1);
00610 }
00611 break;
00612 case 'd':
00613 screen.dump_parsed_image = 1;
00614 break;
00615 case '?':
00616 case 'h':
00617 #ifdef HAVE_GETOPT_LONG
00618 printf("Usage: gerbv [OPTIONS...] [FILE...]\n\n");
00619 printf("Available options:\n");
00620 printf(" -B, --border=<b> Border around the image in percent of the\n");
00621 printf(" width/height. Defaults to 5%%.\n");
00622 #ifdef RENDER_USING_GDK
00623 printf(" -D, --dpi=<R> Resolution (Dots per inch) for the output\n");
00624 printf(" bitmap.\n");
00625 #else
00626 printf(" -D, --dpi=<XxY>or<R> Resolution (Dots per inch) for the output\n");
00627 printf(" bitmap. With the format <XxY>, different\n");
00628 printf(" resolutions for X- and Y-direction are used.\n");
00629 printf(" With the format <R>, both are the same.\n");
00630 #endif
00631 printf(" -O, --origin=<XxY> Use the specified coordinates (in inches)\n");
00632 printf(" for the lower left corner.\n");
00633 printf(" -V, --version Print version of gerbv.\n");
00634 printf(" -a, --antialias Use antialiasing for generated bitmap output.\n");
00635 printf(" -b, --background=<hex> Use background color <hex> (like #RRGGBB).\n");
00636 #ifdef RENDER_USING_GDK
00637 printf(" -f, --foreground=<hex> Use foreground color <hex> (like #RRGGBB)\n");
00638 #else
00639 printf(" -f, --foreground=<hex> Use foreground color <hex> (like #RRGGBB or\n");
00640 printf(" #RRGGBBAA for setting the alpha).\n");
00641 #endif
00642 printf(" Use multiple -f flags to set the color for\n");
00643 printf(" multiple layers.\n");
00644 printf(" -h, --help Print this help message.\n");
00645 printf(" -l, --log=<logfile> Send error messages to <logfile>.\n");
00646 printf(" -o, --output=<filename> Export to <filename>\n");
00647 printf(" -p, --project=<prjfile> Load project file <prjfile>\n");
00648 printf(" -W, --window_inch=<WxH> Window size in inches <WxH> for the\n");
00649 printf(" exported image.\n");
00650 printf(" -w, --window=<WxH> Window size in pixels <WxH> for the\n");
00651 printf(" exported image. Autoscales to fit\n");
00652 printf(" if no resolution is specified. If a\n");
00653 printf(" resolution is specified, it will clip.\n");
00654 printf(" -t, --tools=<toolfile> Read Excellon tools from file <toolfile>.\n");
00655 printf(" -T, --translate=<X,Y> Translate the image by <X,Y> (useful for\n");
00656 printf(" arranging panels). Use multiple -T flags\n");
00657 printf(" for multiple layers.\n");
00658 #ifdef RENDER_USING_GDK
00659 printf(" -x, --export=<png> Export a rendered picture to a PNG file.\n");
00660 #else
00661 printf(" -x, --export=<png/pdf/ps/svg/ Export a rendered picture to a file with\n");
00662 printf(" rs274x/drill> the specified format.\n");
00663 #endif
00664
00665
00666 #else
00667 printf("Usage: gerbv [OPTIONS...] [FILE...]\n\n");
00668 printf("Available options:\n");
00669 printf(" -B<b> Border around the image in percent of the\n");
00670 printf(" width/height. Defaults to 5%%.\n");
00671 #ifdef RENDER_USING_GDK
00672 printf(" -D<R> Resolution (Dots per inch) for the output\n");
00673 printf(" bitmap\n");
00674 #else
00675 printf(" -D<XxY>or<R> Resolution (Dots per inch) for the output\n");
00676 printf(" bitmap. With the format <XxY>, different\n");
00677 printf(" resolutions for X- and Y-direction are used.\n");
00678 printf(" With the format <R>, both are the same.\n");
00679 #endif
00680 printf(" -O<XxY> Use the specified coordinates (in inches)\n");
00681 printf(" for the lower left corner.\n");
00682 printf(" -V Print version of gerbv.\n");
00683 printf(" -a Use antialiasing for generated bitmap output.\n");
00684 printf(" -b<hexcolor> Use background color <hexcolor> (like #RRGGBB)\n");
00685 #ifdef RENDER_USING_GDK
00686 printf(" -f<hexcolor> Use foreground color <hexcolor> (like #RRGGBB)\n");
00687 #else
00688 printf(" -f<hexcolor> Use foreground color <hexcolor> (like #RRGGBB or\n");
00689 printf(" #RRGGBBAA for setting the alpha).\n");
00690 #endif
00691 printf(" Use multiple -f flags to set the color for\n");
00692 printf(" multiple layers.\n");
00693 printf(" -h Print this help message.\n");
00694 printf(" -l<logfile> Send error messages to <logfile>\n");
00695 printf(" -o<filename> Export to <filename>\n");
00696 printf(" -p<prjfile> Load project file <prjfile>\n");
00697 printf(" -W<WxH> Window size in inches <WxH> for the\n");
00698 printf(" exported image\n");
00699 printf(" -w<WxH> Window size in pixels <WxH> for the\n");
00700 printf(" exported image. Autoscales to fit\n");
00701 printf(" if no resolution is specified. If a\n");
00702 printf(" resolution is specified, it will clip.\n");
00703 printf(" exported image\n");
00704 printf(" -t<toolfile> Read Excellon tools from file <toolfile>\n");
00705 printf(" -T<X,Y> Translate the image by <X,Y> (useful for\n");
00706 printf(" arranging panels). Use multiple -T flags\n");
00707 printf(" for multiple layers.\n");
00708 #ifdef RENDER_USING_GDK
00709 printf(" -x<png> Export a rendered picture to a PNG file\n");
00710 #else
00711 printf(" -x <png/pdf/ps/svg/ Export a rendered picture to a file with\n");
00712 printf(" rs274x/drill> the specified format\n");
00713 #endif
00714
00715 #endif
00716 exit(1);
00717 break;
00718 default :
00719 printf("Not handled option [%d=%c]\n", read_opt, read_opt);
00720 }
00721 }
00722
00723
00724
00725
00726
00727
00728
00729 if (project_filename) {
00730
00731
00732 g_free (mainProject->path);
00733 if (!g_path_is_absolute(project_filename)) {
00734 gchar *fullName = g_build_filename (g_get_current_dir (),
00735 project_filename, NULL);
00736 main_open_project_from_filename (mainProject, fullName);
00737 mainProject->path = g_path_get_dirname (fullName);
00738 g_free (fullName);
00739 } else {
00740 main_open_project_from_filename (mainProject, project_filename);
00741 mainProject->path = g_path_get_dirname (project_filename);
00742 }
00743
00744 } else {
00745 gint loadedIndex = 0;
00746 for(i = optind ; i < argc; i++) {
00747 g_free (mainProject->path);
00748 if (!g_path_is_absolute(argv[i])) {
00749 gchar *fullName = g_build_filename (g_get_current_dir (),
00750 argv[i], NULL);
00751 gerbv_open_layer_from_filename_with_color (mainProject, fullName,
00752 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].red*257,
00753 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].green*257,
00754 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].blue*257,
00755 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].alpha*257);
00756 mainProject->path = g_path_get_dirname (fullName);
00757 g_free (fullName);
00758 } else {
00759 gerbv_open_layer_from_filename_with_color (mainProject, argv[i],
00760 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].red*257,
00761 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].green*257,
00762 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].blue*257,
00763 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].alpha*257);
00764 mainProject->path = g_path_get_dirname (argv[i]);
00765 }
00766 loadedIndex++;
00767 }
00768 }
00769
00770 screen.unit = GERBV_DEFAULT_UNIT;
00771 #ifdef RENDER_USING_GDK
00772
00773 gtk_init (&argc, &argv);
00774 #endif
00775
00776 if (exportFromCommandline) {
00777
00778
00779 gboolean freeFilename = FALSE;
00780
00781 if (!exportFilename) {
00782 if (exportType == 1) {
00783 exportFilename = g_strdup ("output.png");
00784 } else if (exportType == 2) {
00785 exportFilename = g_strdup ("output.pdf");
00786 } else if (exportType == 3) {
00787 exportFilename = g_strdup ("output.svg");
00788 } else if (exportType == 4){
00789 exportFilename = g_strdup ("output.ps");
00790 } else if (exportType == 5){
00791 exportFilename = g_strdup ("output.gbx");
00792 } else {
00793 exportFilename = g_strdup ("output.cnc");
00794 }
00795 freeFilename = TRUE;
00796 }
00797
00798 gerbv_render_size_t bb;
00799 gerbv_render_get_boundingbox(mainProject, &bb);
00800
00801 if(!userSuppliedOrigin){
00802 userSuppliedOriginX = bb.left;
00803 userSuppliedOriginY = bb.top;
00804 }
00805
00806 float width = bb.right - userSuppliedOriginX + 0.001;
00807 float height = bb.bottom - userSuppliedOriginY + 0.001;
00808
00809 if(!userSuppliedWindow){
00810 userSuppliedWidth = width;
00811 userSuppliedHeight = height;
00812 }else{
00813
00814 if( (!userSuppliedDpi)&& userSuppliedWindowInPixels){
00815 userSuppliedDpiX = MIN(((userSuppliedWidth-0.5) / width),((userSuppliedHeight-0.5) / height));
00816 userSuppliedDpiY = userSuppliedDpiX;
00817 userSuppliedOriginX -= 0.5/userSuppliedDpiX;
00818 userSuppliedOriginY -= 0.5/userSuppliedDpiY;
00819 }
00820 }
00821
00822
00823
00824 if(userSuppliedBorder!=0){
00825
00826 if(!userSuppliedWindowInPixels){
00827 userSuppliedWidth += userSuppliedWidth*userSuppliedBorder;
00828 userSuppliedHeight += userSuppliedHeight*userSuppliedBorder;
00829 userSuppliedOriginX -= (userSuppliedWidth*userSuppliedBorder)/2.0;
00830 userSuppliedOriginY -= (userSuppliedHeight*userSuppliedBorder)/2.0;
00831 }
00832
00833 else{
00834 userSuppliedDpiX -= (userSuppliedDpiX*userSuppliedBorder);
00835 userSuppliedDpiY -= (userSuppliedDpiY*userSuppliedBorder);
00836 userSuppliedOriginX -= ((userSuppliedWidth/userSuppliedDpiX)*userSuppliedBorder)/2.0;
00837 userSuppliedOriginY -= ((userSuppliedHeight/userSuppliedDpiX)*userSuppliedBorder)/2.0;
00838 }
00839 }
00840
00841 if(!userSuppliedWindowInPixels){
00842 userSuppliedWidth *= userSuppliedDpiX;
00843 userSuppliedHeight *= userSuppliedDpiY;
00844 }
00845
00846
00847
00848 if(userSuppliedWidth <=0)
00849 userSuppliedWidth = 1;
00850 if(userSuppliedHeight <=0)
00851 userSuppliedHeight = 1;
00852
00853
00854 #ifdef RENDER_USING_GDK
00855 gerbv_render_info_t renderInfo = {MIN(userSuppliedDpiX, userSuppliedDpiY), MIN(userSuppliedDpiX, userSuppliedDpiY),
00856 userSuppliedOriginX, userSuppliedOriginY,1,
00857 userSuppliedWidth,userSuppliedHeight };
00858 #else
00859 gerbv_render_info_t renderInfo = {userSuppliedDpiX, userSuppliedDpiY,
00860 userSuppliedOriginX, userSuppliedOriginY, userSuppliedAntiAlias?3:2,
00861 userSuppliedWidth,userSuppliedHeight };
00862 #endif
00863
00864 if (exportType == 1) {
00865 #ifdef EXPORT_PNG
00866 gerbv_export_png_file_from_project (mainProject, &renderInfo, exportFilename);
00867 #endif
00868 } else if (exportType == 2) {
00869 gerbv_export_pdf_file_from_project (mainProject, &renderInfo, exportFilename);
00870 } else if (exportType == 3) {
00871 gerbv_export_svg_file_from_project (mainProject, &renderInfo, exportFilename);
00872 } else if (exportType == 4) {
00873 gerbv_export_postscript_file_from_project (mainProject, &renderInfo, exportFilename);
00874 } else if (exportType == 5) {
00875 if (mainProject->file[0]->image) {
00876
00877 if (mainProject->file[1]) {
00878 gerbv_image_t *exportImage;
00879 exportImage = gerbv_image_duplicate_image (mainProject->file[0]->image, &mainProject->file[0]->transform);
00880 for(i = mainProject->max_files-1; i > 0; i--) {
00881 if (mainProject->file[i]) {
00882 gerbv_image_copy_image (mainProject->file[i]->image, &mainProject->file[i]->transform, exportImage);
00883 }
00884 }
00885 gerbv_export_rs274x_file_from_image (exportFilename, exportImage);
00886 gerbv_destroy_image (exportImage);
00887 }
00888
00889 else {
00890 gerbv_export_rs274x_file_from_image (exportFilename, mainProject->file[0]->image);
00891 }
00892 }
00893 else {
00894 fprintf(stderr, "A valid file was not loaded.\n");
00895 exit(1);
00896 }
00897 } else if (exportType == 6) {
00898 if (mainProject->file[0]->image) {
00899
00900 if (mainProject->file[1]) {
00901 gerbv_image_t *exportImage;
00902 exportImage = gerbv_image_duplicate_image (mainProject->file[0]->image, &mainProject->file[0]->transform);
00903 for(i = mainProject->max_files-1; i > 0; i--) {
00904 if (mainProject->file[i]) {
00905 gerbv_image_copy_image (mainProject->file[i]->image, &mainProject->file[i]->transform, exportImage);
00906 }
00907 }
00908 gerbv_export_drill_file_from_image (exportFilename, exportImage);
00909 gerbv_destroy_image (exportImage);
00910 }
00911
00912 else {
00913 gerbv_export_drill_file_from_image (exportFilename, mainProject->file[0]->image);
00914 }
00915 }
00916 else {
00917 fprintf(stderr, "A valid file was not loaded.\n");
00918 exit(1);
00919 }
00920 }
00921
00922 if (freeFilename)
00923 free (exportFilename);
00924
00925 exit(1);
00926 }
00927 #ifndef RENDER_USING_GDK
00928 gtk_init (&argc, &argv);
00929 #endif
00930 interface_create_gui (req_width, req_height);
00931
00932 return 0;
00933 }
00934