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 <stdio.h>
00034 #include <stdlib.h>
00035 #include <string.h>
00036 #include <glib.h>
00037 #include <math.h>
00038
00039 #include "gerbv.h"
00040 #include "drill_stats.h"
00041
00042
00043 #define dprintf if(DEBUG) printf
00044
00045
00046
00049 gerbv_drill_stats_t *
00050 gerbv_drill_stats_new(void) {
00051
00052 gerbv_drill_stats_t *stats;
00053 gerbv_drill_list_t *drill_list;
00054 gerbv_error_list_t *error_list;
00055
00056
00057 if ((stats = (gerbv_drill_stats_t *)g_malloc(sizeof(gerbv_drill_stats_t))) == NULL) {
00058 return NULL;
00059 }
00060
00061
00062 memset((void *)stats, 0, sizeof(gerbv_drill_stats_t));
00063
00064
00065 drill_list = gerbv_drill_stats_new_drill_list();
00066 if (drill_list == NULL)
00067 GERB_FATAL_ERROR("malloc drill_list failed\n");
00068 stats->drill_list = (gerbv_drill_list_t *) drill_list;
00069
00070
00071 error_list = gerbv_drill_stats_new_error_list();
00072 if (error_list == NULL)
00073 GERB_FATAL_ERROR("malloc error_list failed\n");
00074 stats->error_list = (gerbv_error_list_t *) error_list;
00075
00076 stats->detect = NULL;
00077 return stats;
00078 }
00079
00080
00081
00082 void
00083 gerbv_drill_stats_add_layer(gerbv_drill_stats_t *accum_stats,
00084 gerbv_drill_stats_t *input_stats,
00085 int this_layer) {
00086
00087 gerbv_drill_list_t *drill;
00088 gerbv_error_list_t *error;
00089 char *tmps, *tmps2;
00090
00091 dprintf("---> Entering gerbv_drill_stats_add_layer ..... \n");
00092
00093 accum_stats->layer_count++;
00094
00095 accum_stats->comment += input_stats->comment;
00096
00097
00098 accum_stats->G00 += input_stats->G00;
00099 accum_stats->G01 += input_stats->G01;
00100 accum_stats->G02 += input_stats->G02;
00101 accum_stats->G03 += input_stats->G03;
00102 accum_stats->G04 += input_stats->G04;
00103 accum_stats->G05 += input_stats->G05;
00104 accum_stats->G90 += input_stats->G90;
00105 accum_stats->G91 += input_stats->G91;
00106 accum_stats->G93 += input_stats->G93;
00107 accum_stats->G_unknown += input_stats->G_unknown;
00108
00109 accum_stats->M00 += input_stats->M00;
00110 accum_stats->M01 += input_stats->M01;
00111 accum_stats->M18 += input_stats->M18;
00112 accum_stats->M25 += input_stats->M25;
00113 accum_stats->M30 += input_stats->M30;
00114 accum_stats->M31 += input_stats->M31;
00115 accum_stats->M45 += input_stats->M45;
00116 accum_stats->M47 += input_stats->M47;
00117 accum_stats->M48 += input_stats->M48;
00118 accum_stats->M71 += input_stats->M71;
00119 accum_stats->M72 += input_stats->M72;
00120 accum_stats->M95 += input_stats->M95;
00121 accum_stats->M97 += input_stats->M97;
00122 accum_stats->M98 += input_stats->M98;
00123 accum_stats->M_unknown += input_stats->M_unknown;
00124
00125
00126 for (drill = input_stats->drill_list;
00127 drill != NULL;
00128 drill = drill->next) {
00129 dprintf(" In gerbv_drill_stats_add_layer, adding drill_num = %d to list\n",
00130 drill->drill_num);
00131
00132
00133 drill_stats_add_to_drill_list(accum_stats->drill_list,
00134 drill->drill_num,
00135 drill->drill_size,
00136 drill->drill_unit);
00137
00138
00139 dprintf(" adding count %d of drills for drill %d\n",
00140 drill->drill_count, drill->drill_num);
00141 drill_stats_add_to_drill_counter(accum_stats->drill_list,
00142 drill->drill_num,
00143 drill->drill_count);
00144 }
00145
00146
00147 for (error = input_stats->error_list;
00148 error != NULL;
00149 error = error->next) {
00150 if (error->error_text != NULL) {
00151 drill_stats_add_error(accum_stats->error_list,
00152 this_layer,
00153 error->error_text,
00154 error->type);
00155 }
00156 }
00157
00158
00159 tmps = NULL;
00160 tmps2 = NULL;
00161 if (input_stats->detect) {
00162 tmps2 = g_strdup_printf ("Broken tool detect %s (layer %d)", input_stats->detect, this_layer);
00163 }
00164 if (accum_stats->detect) {
00165 if (tmps2) {
00166 tmps = g_strdup_printf ("%s\n%s", accum_stats->detect, tmps2);
00167 g_free (accum_stats->detect);
00168 accum_stats->detect = NULL;
00169 }
00170 } else {
00171 if (tmps2) {
00172 tmps = g_strdup_printf ("%s", tmps2);
00173 }
00174 }
00175 if (tmps2) {
00176 g_free (tmps2);
00177 }
00178 if (tmps != NULL) {
00179 accum_stats->detect = tmps;
00180 }
00181
00182 for (error = input_stats->error_list;
00183 error != NULL;
00184 error = error->next) {
00185 if (error->error_text != NULL) {
00186 drill_stats_add_error(accum_stats->error_list,
00187 this_layer,
00188 error->error_text,
00189 error->type);
00190 }
00191 }
00192
00193
00194 dprintf("<--- .... Leaving gerbv_drill_stats_add_layer.\n");
00195
00196 return;
00197 }
00198
00199
00200
00201 gboolean
00202 drill_stats_in_drill_list(gerbv_drill_list_t *drill_list_in,
00203 int drill_num_in) {
00204 gerbv_drill_list_t *drill;
00205 for(drill = drill_list_in; drill != NULL; drill = drill->next) {
00206 if (drill_num_in == drill->drill_num) {
00207 return TRUE;
00208 }
00209 }
00210 return FALSE;
00211
00212 }
00213
00214
00215 gerbv_drill_list_t *
00216 gerbv_drill_stats_new_drill_list() {
00217 gerbv_drill_list_t *drill_list;
00218
00219
00220 if ((drill_list = (gerbv_drill_list_t *)g_malloc(sizeof(gerbv_drill_list_t))) == NULL) {
00221 return NULL;
00222 }
00223
00224 drill_list->drill_count = 0;
00225 drill_list->drill_num = -1;
00226 drill_list->drill_size = 0.0;
00227 drill_list->drill_unit = NULL;
00228 drill_list->next = NULL;
00229 return drill_list;
00230 }
00231
00232
00233
00234 void
00235 drill_stats_add_to_drill_list(gerbv_drill_list_t *drill_list_in,
00236 int drill_num_in, double drill_size_in,
00237 char *drill_unit_in) {
00238
00239 gerbv_drill_list_t *drill_list_new;
00240 gerbv_drill_list_t *drill;
00241 gerbv_drill_list_t *drill_last = NULL;
00242
00243 dprintf ("%s(%p, %d, %g, \"%s\")\n", __FUNCTION__, drill_list_in, drill_num_in,
00244 drill_size_in, drill_unit_in);
00245
00246 dprintf(" ---> Entering drill_stats_add_to_drill_list, first drill_num in list = %d ...\n",
00247 drill_list_in->drill_num);
00248
00249
00250 if (drill_list_in->drill_num == -1) {
00251 dprintf(" .... In drill_stats_add_to_drill_list, adding first drill, no %d\n",
00252 drill_num_in);
00253 drill_list_in->drill_num = drill_num_in;
00254 drill_list_in->drill_size = drill_size_in;
00255 drill_list_in->drill_count = 0;
00256 drill_list_in->drill_unit = g_strdup_printf("%s", drill_unit_in);
00257 drill_list_in->next = NULL;
00258 return;
00259 }
00260
00261 for(drill = drill_list_in;
00262 drill != NULL;
00263 drill = (gerbv_drill_list_t *) drill->next) {
00264 dprintf("checking this drill_num %d against that in list %d.\n",
00265 drill_num_in, drill->drill_num);
00266 if (drill_num_in == drill->drill_num) {
00267 dprintf(" .... In drill_stats_add_to_drill_list, drill no %d already in list\n",
00268 drill_num_in);
00269 return;
00270 }
00271 drill_last = drill;
00272 }
00273
00274
00275 drill_list_new = (gerbv_drill_list_t *) g_malloc(sizeof(gerbv_drill_list_t));
00276 if (drill_list_new == NULL) {
00277 GERB_FATAL_ERROR("malloc format failed\n");
00278 }
00279
00280
00281 dprintf(" .... In drill_stats_add_to_drill_list, adding new drill, no %d\n",
00282 drill_num_in);
00283 drill_list_new->drill_num = drill_num_in;
00284 drill_list_new->drill_size = drill_size_in;
00285 drill_list_new->drill_count = 0;
00286 drill_list_new->drill_unit = g_strdup_printf("%s", drill_unit_in);
00287 drill_list_new->next = NULL;
00288 drill_last->next = drill_list_new;
00289
00290 dprintf(" <---- ... leaving drill_stats_add_to_drill_list.\n");
00291 return;
00292 }
00293
00294
00295 void
00296 drill_stats_modify_drill_list(gerbv_drill_list_t *drill_list_in,
00297 int drill_num_in, double drill_size_in,
00298 char *drill_unit_in) {
00299
00300 gerbv_drill_list_t *drill;
00301
00302 dprintf(" ---> Entering drill_stats_modify_drill_list, first drill_num in list = %d ...\n",
00303 drill_list_in->drill_num);
00304
00305
00306 for(drill = drill_list_in;
00307 drill != NULL;
00308 drill = (gerbv_drill_list_t *) drill->next) {
00309 dprintf("checking this drill_num %d against that in list %d.\n",
00310 drill_num_in, drill->drill_num);
00311 if (drill_num_in == drill->drill_num) {
00312 dprintf(" .... Found it, now update it ....\n");
00313 drill->drill_size = drill_size_in;
00314 if (drill->drill_unit)
00315 g_free(drill->drill_unit);
00316 drill->drill_unit = g_strdup_printf("%s", drill_unit_in);
00317 dprintf(" <---- ... Modified drill. leaving drill_stats_modify_drill_list.\n");
00318 return;
00319 }
00320 }
00321 dprintf(" <---- ... Did not find drill. leaving drill_stats_modify_drill_list.\n");
00322 return;
00323 }
00324
00325
00326 void
00327 drill_stats_increment_drill_counter(gerbv_drill_list_t *drill_list_in,
00328 int drill_num_in) {
00329
00330 dprintf(" ----> Entering drill_stats_increment_drill_counter......\n");
00331
00332 gerbv_drill_list_t *drill;
00333 for(drill = drill_list_in; drill != NULL; drill = drill->next) {
00334 if (drill_num_in == drill->drill_num) {
00335 drill->drill_count++;
00336 dprintf(" .... incrementing drill count. drill_num = %d, drill_count = %d.\n",
00337 drill_list_in->drill_num, drill->drill_count);
00338 dprintf(" <---- .... Leaving drill_stats_increment_drill_counter after incrementing counter.\n");
00339 return;
00340 }
00341 }
00342 dprintf(" <---- .... Leaving drill_stats_increment_drill_counter without incrementing any counter.\n");
00343
00344 }
00345
00346
00347 void
00348 drill_stats_add_to_drill_counter(gerbv_drill_list_t *drill_list_in,
00349 int drill_num_in,
00350 int increment) {
00351
00352 gerbv_drill_list_t *drill;
00353 for(drill = drill_list_in; drill != NULL; drill = drill->next) {
00354 if (drill_num_in == drill->drill_num) {
00355 dprintf(" In drill_stats_add_to_drill_counter, adding increment = %d drills to drill list\n", increment);
00356 drill->drill_count += increment;
00357 return;
00358 }
00359 }
00360 }
00361
00362
00363
00364 gerbv_error_list_t *
00365 gerbv_drill_stats_new_error_list() {
00366 gerbv_error_list_t *error_list;
00367
00368
00369 if ((error_list = (gerbv_error_list_t *)g_malloc(sizeof(gerbv_error_list_t))) == NULL) {
00370 return NULL;
00371 }
00372
00373 error_list->layer = -1;
00374 error_list->error_text = NULL;
00375 error_list->next = NULL;
00376 return error_list;
00377 }
00378
00379
00380
00381
00382 void
00383 drill_stats_add_error(gerbv_error_list_t *error_list_in,
00384 int layer, const char *error_text,
00385 gerbv_message_type_t type) {
00386
00387 gerbv_error_list_t *error_list_new;
00388 gerbv_error_list_t *error_last = NULL;
00389 gerbv_error_list_t *error;
00390
00391 dprintf(" ----> Entering drill_stats_add_error......\n");
00392
00393
00394 switch (type) {
00395 case GERBV_MESSAGE_FATAL:
00396 GERB_FATAL_ERROR(error_text);
00397 break;
00398 case GERBV_MESSAGE_ERROR:
00399 GERB_COMPILE_ERROR(error_text);
00400 break;
00401 case GERBV_MESSAGE_WARNING:
00402 GERB_COMPILE_WARNING(error_text);
00403 break;
00404 case GERBV_MESSAGE_NOTE:
00405 break;
00406 }
00407
00408
00409
00410 if (error_list_in->error_text == NULL) {
00411 error_list_in->layer = layer;
00412 error_list_in->error_text = g_strdup_printf("%s", error_text);
00413 error_list_in->type = type;
00414 error_list_in->next = NULL;
00415 dprintf(" <---- .... Leaving drill_stats_add_error after adding first error message.\n");
00416 return;
00417 }
00418
00419
00420 for(error = error_list_in; error != NULL; error = error->next) {
00421 if ((strcmp(error->error_text, error_text) == 0) &&
00422 (error->layer == layer) ) {
00423 return;
00424 }
00425 error_last = error;
00426 }
00427
00428
00429
00430 error_list_new = (gerbv_error_list_t *) g_malloc(sizeof(gerbv_error_list_t));
00431 if (error_list_new == NULL) {
00432 GERB_FATAL_ERROR("malloc error_list failed\n");
00433 }
00434
00435
00436 error_list_new->layer = layer;
00437 error_list_new->error_text = g_strdup_printf("%s", error_text);
00438 error_list_new->type = type;
00439 error_list_new->next = NULL;
00440 error_last->next = error_list_new;
00441
00442 dprintf(" <---- .... Leaving drill_stats_add_error after adding new error message.\n");
00443 return;
00444
00445 }