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 <stdlib.h>
00034 #include <string.h>
00035 #include <glib.h>
00036 #include <math.h>
00037
00038 #include "gerbv.h"
00039 #include "gerb_stats.h"
00040
00041
00042
00043 #define dprintf if(DEBUG) printf
00044
00045
00048 gerbv_stats_t *
00049 gerbv_stats_new(void) {
00050
00051 gerbv_stats_t *stats;
00052 gerbv_error_list_t *error_list;
00053 gerbv_aperture_list_t *aperture_list;
00054 gerbv_aperture_list_t *D_code_list;
00055
00056
00057 if ((stats = (gerbv_stats_t *)g_malloc(sizeof(gerbv_stats_t))) == NULL) {
00058 return NULL;
00059 }
00060
00061
00062 memset((void *)stats, 0, sizeof(gerbv_stats_t));
00063
00064
00065 error_list = gerbv_stats_new_error_list();
00066 if (error_list == NULL)
00067 GERB_FATAL_ERROR("malloc error_list failed\n");
00068 stats->error_list = (gerbv_error_list_t *) error_list;
00069
00070
00071 aperture_list = gerbv_stats_new_aperture_list();
00072 if (aperture_list == NULL)
00073 GERB_FATAL_ERROR("malloc aperture_list failed\n");
00074 stats->aperture_list = (gerbv_aperture_list_t *) aperture_list;
00075
00076
00077 D_code_list = gerbv_stats_new_aperture_list();
00078 if (D_code_list == NULL)
00079 GERB_FATAL_ERROR("malloc D_code_list failed\n");
00080 stats->D_code_list = (gerbv_aperture_list_t *) D_code_list;
00081
00082 return stats;
00083 }
00084
00085
00086
00093 void
00094 gerbv_stats_add_layer(gerbv_stats_t *accum_stats,
00095 gerbv_stats_t *input_stats,
00096 int this_layer) {
00097
00098 dprintf("---> Entering gerbv_stats_add_layer ... \n");
00099
00100 gerbv_error_list_t *error;
00101 gerbv_aperture_list_t *aperture;
00102 gerbv_aperture_list_t *D_code;
00103
00104 accum_stats->layer_count++;
00105 accum_stats->G0 += input_stats->G0;
00106 accum_stats->G1 += input_stats->G1;
00107 accum_stats->G2 += input_stats->G2;
00108 accum_stats->G3 += input_stats->G3;
00109 accum_stats->G4 += input_stats->G4;
00110 accum_stats->G10 += input_stats->G10;
00111 accum_stats->G11 += input_stats->G11;
00112 accum_stats->G12 += input_stats->G12;
00113 accum_stats->G36 += input_stats->G36;
00114 accum_stats->G37 += input_stats->G37;
00115 accum_stats->G54 += input_stats->G54;
00116 accum_stats->G55 += input_stats->G55;
00117 accum_stats->G70 += input_stats->G70;
00118 accum_stats->G71 += input_stats->G71;
00119 accum_stats->G74 += input_stats->G74;
00120 accum_stats->G75 += input_stats->G75;
00121 accum_stats->G90 += input_stats->G90;
00122 accum_stats->G91 += input_stats->G91;
00123 accum_stats->G_unknown += input_stats->G_unknown;
00124
00125 accum_stats->D1 += input_stats->D1;
00126 accum_stats->D2 += input_stats->D2;
00127 accum_stats->D3 += input_stats->D3;
00128
00129 for (D_code = input_stats->D_code_list;
00130 D_code != NULL;
00131 D_code = D_code->next) {
00132 if (D_code->number != -1) {
00133 dprintf(" .... In gerbv_stats_add_layer, D code section, adding number = %d to accum_stats D list ...\n",
00134 D_code->number);
00135 gerbv_stats_add_to_D_list(accum_stats->D_code_list,
00136 D_code->number);
00137 dprintf(" .... In gerbv_stats_add_layer, D code section, calling increment_D_count with count %d ...\n",
00138 D_code->count);
00139 gerbv_stats_increment_D_list_count(accum_stats->D_code_list,
00140 D_code->number,
00141 D_code->count,
00142 accum_stats->error_list);
00143 }
00144 }
00145 accum_stats->D_unknown += input_stats->D_unknown;
00146 accum_stats->D_error += input_stats->D_error;
00147
00148 accum_stats->M0 += input_stats->M0;
00149 accum_stats->M1 += input_stats->M1;
00150 accum_stats->M2 += input_stats->M2;
00151 accum_stats->M_unknown += input_stats->M_unknown;
00152
00153 accum_stats->X += input_stats->X;
00154 accum_stats->Y += input_stats->Y;
00155 accum_stats->I += input_stats->I;
00156 accum_stats->J += input_stats->J;
00157
00158 accum_stats->star += input_stats->star;
00159 accum_stats->unknown += input_stats->unknown;
00160
00161
00162 for (error = input_stats->error_list;
00163 error != NULL;
00164 error = error->next) {
00165 if (error->error_text != NULL) {
00166 gerbv_stats_add_error(accum_stats->error_list,
00167 this_layer,
00168 error->error_text,
00169 error->type);
00170 }
00171 }
00172
00173
00174 for (aperture = input_stats->aperture_list;
00175 aperture != NULL;
00176 aperture = aperture->next) {
00177 if (aperture->number != -1) {
00178 gerbv_stats_add_aperture(accum_stats->aperture_list,
00179 this_layer,
00180 aperture->number,
00181 aperture->type,
00182 aperture->parameter);
00183 }
00184 }
00185
00186 dprintf("<---- .... Leaving gerbv_stats_add_layer. \n");
00187
00188 return;
00189 }
00190
00191
00192 gerbv_error_list_t *
00193 gerbv_stats_new_error_list() {
00194 gerbv_error_list_t *error_list;
00195
00196
00197 if ((error_list = (gerbv_error_list_t *)g_malloc(sizeof(gerbv_error_list_t))) == NULL) {
00198 return NULL;
00199 }
00200
00201 error_list->layer = -1;
00202 error_list->error_text = NULL;
00203 error_list->next = NULL;
00204 return error_list;
00205 }
00206
00207
00208
00209 void
00210 gerbv_stats_add_error(gerbv_error_list_t *error_list_in,
00211 int layer, const char *error_text,
00212 gerbv_message_type_t type) {
00213
00214 gerbv_error_list_t *error_list_new;
00215 gerbv_error_list_t *error_last = NULL;
00216 gerbv_error_list_t *error;
00217
00218
00219 switch (type) {
00220 case GERBV_MESSAGE_FATAL:
00221 GERB_FATAL_ERROR(error_text);
00222 break;
00223 case GERBV_MESSAGE_ERROR:
00224 GERB_COMPILE_ERROR(error_text);
00225 break;
00226 case GERBV_MESSAGE_WARNING:
00227 GERB_COMPILE_WARNING(error_text);
00228 break;
00229 case GERBV_MESSAGE_NOTE:
00230 break;
00231 }
00232
00233
00234 if (error_list_in->error_text == NULL) {
00235 error_list_in->layer = layer;
00236 error_list_in->error_text = g_strdup_printf("%s", error_text);
00237 error_list_in->type = type;
00238 error_list_in->next = NULL;
00239 return;
00240 }
00241
00242
00243 for(error = error_list_in; error != NULL; error = error->next) {
00244 if ((strcmp(error->error_text, error_text) == 0) &&
00245 (error->layer == layer) ) {
00246 return;
00247 }
00248 error_last = error;
00249 }
00250
00251
00252
00253 error_list_new = (gerbv_error_list_t *) g_malloc(sizeof(gerbv_error_list_t));
00254 if (error_list_new == NULL) {
00255 GERB_FATAL_ERROR("malloc error_list failed\n");
00256 }
00257
00258
00259 error_list_new->layer = layer;
00260 error_list_new->error_text = g_strdup_printf("%s", error_text);
00261 error_list_new->type = type;
00262 error_list_new->next = NULL;
00263 error_last->next = error_list_new;
00264
00265 return;
00266 }
00267
00268
00269 gerbv_aperture_list_t *
00270 gerbv_stats_new_aperture_list() {
00271 gerbv_aperture_list_t *aperture_list;
00272 int i;
00273
00274 dprintf("Mallocing new gerb aperture list\n");
00275
00276 if ((aperture_list = (gerbv_aperture_list_t *)g_malloc(sizeof(gerbv_aperture_list_t)))
00277 == NULL) {
00278 return NULL;
00279 }
00280
00281 dprintf(" Placing values in certain structs.\n");
00282 aperture_list->number = -1;
00283 aperture_list->count = 0;
00284 aperture_list->type = 0;
00285 for (i = 0; i<5; i++) {
00286 aperture_list->parameter[i] = 0.0;
00287 }
00288 aperture_list->next = NULL;
00289 return aperture_list;
00290 }
00291
00292
00293
00294 void
00295 gerbv_stats_add_aperture(gerbv_aperture_list_t *aperture_list_in,
00296 int layer, int number, gerbv_aperture_type_t type,
00297 double parameter[5]) {
00298
00299 gerbv_aperture_list_t *aperture_list_new;
00300 gerbv_aperture_list_t *aperture_last = NULL;
00301 gerbv_aperture_list_t *aperture;
00302 int i;
00303
00304 dprintf(" ---> Entering gerbv_stats_add_aperture ....\n");
00305
00306
00307 if (aperture_list_in->number == -1) {
00308 dprintf(" .... Adding first aperture to aperture list ... \n");
00309 dprintf(" .... Aperture type = %d ... \n", type);
00310 aperture_list_in->number = number;
00311 aperture_list_in->type = type;
00312 aperture_list_in->layer = layer;
00313 for(i=0; i<5; i++) {
00314 aperture_list_in->parameter[i] = parameter[i];
00315 }
00316 aperture_list_in->next = NULL;
00317 dprintf(" <--- .... Leaving gerbv_stats_add_aperture.\n");
00318 return;
00319 }
00320
00321
00322 for(aperture = aperture_list_in;
00323 aperture != NULL;
00324 aperture = aperture->next) {
00325 if ((aperture->number == number) &&
00326 (aperture->layer == layer) ) {
00327 dprintf(" .... This aperture is already in the list ... \n");
00328 dprintf(" <--- .... Leaving gerbv_stats_add_aperture.\n");
00329 return;
00330 }
00331 aperture_last = aperture;
00332 }
00333
00334 dprintf(" .... Adding another aperture to list ... \n");
00335 dprintf(" .... Aperture type = %d ... \n", type);
00336
00337
00338 aperture_list_new = (gerbv_aperture_list_t *) g_malloc(sizeof(gerbv_aperture_list_t));
00339 if (aperture_list_new == NULL) {
00340 GERB_FATAL_ERROR("malloc aperture_list failed\n");
00341 }
00342
00343
00344 aperture_list_new->layer = layer;
00345 aperture_list_new->number = number;
00346 aperture_list_new->type = type;
00347 aperture_list_new->next = NULL;
00348 for(i=0; i<5; i++) {
00349 aperture_list_new->parameter[i] = parameter[i];
00350 }
00351 aperture_last->next = aperture_list_new;
00352
00353 dprintf(" <--- .... Leaving gerbv_stats_add_aperture.\n");
00354
00355 return;
00356 }
00357
00358
00359 void
00360 gerbv_stats_add_to_D_list(gerbv_aperture_list_t *D_list_in,
00361 int number) {
00362
00363 gerbv_aperture_list_t *D_list;
00364 gerbv_aperture_list_t *D_list_last=NULL;
00365 gerbv_aperture_list_t *D_list_new;
00366
00367 dprintf(" ----> Entering add_to_D_list, numbr = %d\n", number);
00368
00369
00370 if (D_list_in->number == -1) {
00371 dprintf(" .... Adding first D code to D code list ... \n");
00372 dprintf(" .... Aperture number = %d ... \n", number);
00373 D_list_in->number = number;
00374 D_list_in->count = 0;
00375 D_list_in->next = NULL;
00376 dprintf(" <--- .... Leaving add_to_D_list.\n");
00377 return;
00378 }
00379
00380
00381 for(D_list = D_list_in;
00382 D_list != NULL;
00383 D_list = D_list->next) {
00384 if (D_list->number == number) {
00385 dprintf(" .... Found in D list .... \n");
00386 dprintf(" <--- .... Leaving add_to_D_list.\n");
00387 return;
00388 }
00389 D_list_last = D_list;
00390 }
00391
00392
00393 dprintf(" .... Adding another D code to D code list ... \n");
00394
00395
00396 D_list_new = (gerbv_aperture_list_t *) g_malloc(sizeof(gerbv_aperture_list_t));
00397 if (D_list_new == NULL) {
00398 GERB_FATAL_ERROR("malloc D_list failed\n");
00399 }
00400
00401
00402 D_list_new->number = number;
00403 D_list_new->count = 0;
00404 D_list_new->next = NULL;
00405 D_list_last->next = D_list_new;
00406
00407 dprintf(" <--- .... Leaving add_to_D_list.\n");
00408
00409 return;
00410 }
00411
00412
00413 int
00414 gerbv_stats_increment_D_list_count(gerbv_aperture_list_t *D_list_in,
00415 int number,
00416 int count,
00417 gerbv_error_list_t *error) {
00418
00419 gerbv_aperture_list_t *D_list;
00420
00421 dprintf(" Entering inc_D_list_count, code = D%d, input count to add = %d\n", number, count);
00422
00423
00424 for(D_list = D_list_in;
00425 D_list != NULL;
00426 D_list = D_list->next) {
00427 if (D_list->number == number) {
00428 dprintf(" old count = %d\n", D_list->count);
00429 D_list->count += count;
00430 dprintf(" updated count = %d\n", D_list->count);
00431 return 0;
00432 }
00433 }
00434
00435
00436 dprintf(" .... Didn't find this D code in defined list .... \n");
00437 dprintf(" <--- .... Leaving inc_D_list_count.\n");
00438 gerbv_stats_add_error(error,
00439 -1,
00440 "Undefined aperture number called out in D code.\n",
00441 GERBV_MESSAGE_ERROR);
00442 return -1;
00443 }
00444