FreeCalypso > hg > ueda-linux
comparison pads2gpcb/decals.c @ 41:a2d304ec3817
pads2gpcb: decal processing code compiles
| author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
|---|---|
| date | Mon, 11 Jan 2016 18:31:44 +0000 |
| parents | 1c37bec20596 |
| children | 4a50888d09ce |
comparison
equal
deleted
inserted
replaced
| 40:1c37bec20596 | 41:a2d304ec3817 |
|---|---|
| 9 extern long convert_input_dim(); | 9 extern long convert_input_dim(); |
| 10 | 10 |
| 11 static struct part_decal *current_decal; | 11 static struct part_decal *current_decal; |
| 12 static struct footprint_body fpbody; | 12 static struct footprint_body fpbody; |
| 13 static struct footprint_pad *pins_array; | 13 static struct footprint_pad *pins_array; |
| 14 static int num_drawing_pieces, num_padstack_defs; | 14 |
| 15 static int num_text_items, num_attr_labels; | 15 #define SOLDERMASK_DELTA (600 * 254) |
| 16 #define CLEARANCE_SETTING (2000 * 254) | |
| 16 | 17 |
| 17 static void | 18 static void |
| 18 enter_decal() | 19 enter_decal() |
| 19 { | 20 { |
| 20 struct part_decal *p, **pp; | 21 struct part_decal *p, **pp; |
| 34 } | 35 } |
| 35 p->name = (char *)(p + 1); | 36 p->name = (char *)(p + 1); |
| 36 strcpy(p->name, name); | 37 strcpy(p->name, name); |
| 37 p->body = 0; | 38 p->body = 0; |
| 38 p->next = 0; | 39 p->next = 0; |
| 39 **pp = p; | 40 *pp = p; |
| 40 current_decal = p; | 41 current_decal = p; |
| 41 } | 42 } |
| 42 | 43 |
| 43 static void | 44 static void |
| 44 get_line_internal() | 45 get_line_internal() |
| 102 input_filename, input_lineno); | 103 input_filename, input_lineno); |
| 103 exit(1); | 104 exit(1); |
| 104 } | 105 } |
| 105 input_line_fields[0]++; | 106 input_line_fields[0]++; |
| 106 | 107 |
| 107 if (atoi(input_line_fields[4]) != i + 1) { | 108 if (atoi(input_line_fields[4]) != idx + 1) { |
| 108 fprintf(stderr, | 109 fprintf(stderr, |
| 109 "%s line %d: expected %d in the pin number field\n", | 110 "%s line %d: expected %d in the pin number field\n", |
| 110 input_filename, input_lineno); | 111 input_filename, input_lineno); |
| 111 exit(1); | 112 exit(1); |
| 112 } | 113 } |
| 113 pins_array[i].x1 = convert_input_dim(input_line_fields[0]); | 114 pins_array[idx].x1 = convert_input_dim(input_line_fields[0]); |
| 114 pins_array[i].y1 = -convert_input_dim(input_line_fields[1]); | 115 pins_array[idx].y1 = -convert_input_dim(input_line_fields[1]); |
| 116 } | |
| 117 | |
| 118 static void | |
| 119 process_pad_shape(padptr) | |
| 120 struct pad_shape_info *padptr; | |
| 121 { | |
| 122 padptr->short_dim = convert_input_dim(input_line_fields[1]); | |
| 123 if (padptr->short_dim <= 0) { | |
| 124 printf("line %d: pad short dim <= 0\n", input_lineno); | |
| 125 return; | |
| 126 } | |
| 127 if (!strcmp(input_line_fields[2], "R")) { | |
| 128 padptr->rounded = 1; | |
| 129 padptr->elongated = 0; | |
| 130 } else if (!strcmp(input_line_fields[2], "S")) { | |
| 131 padptr->rounded = 0; | |
| 132 padptr->elongated = 0; | |
| 133 } else if (!strcmp(input_line_fields[2], "OF")) { | |
| 134 padptr->rounded = 1; | |
| 135 padptr->elongated = 1; | |
| 136 } else if (!strcmp(input_line_fields[2], "RF")) { | |
| 137 padptr->rounded = 0; | |
| 138 padptr->elongated = 1; | |
| 139 } else { | |
| 140 printf("line %d: unsupported pad shape %s\n", input_lineno, | |
| 141 input_line_fields[2]); | |
| 142 return; | |
| 143 } | |
| 144 if (padptr->elongated) { | |
| 145 if (input_line_nfields < 6) { | |
| 146 fprintf(stderr, | |
| 147 "%s line %d: too few fields in OF/RF pad stack line\n", | |
| 148 input_filename, input_lineno); | |
| 149 exit(1); | |
| 150 } | |
| 151 padptr->angle = parse_input_angle_90s(input_line_fields[3]); | |
| 152 if (padptr->angle != 0 && padptr->angle != 90) { | |
| 153 printf("line %d: unsupported OF/RF angle\n", | |
| 154 input_lineno); | |
| 155 return; | |
| 156 } | |
| 157 padptr->long_dim = convert_input_dim(input_line_fields[4]); | |
| 158 if (strcmp(input_line_fields[5], "0")) { | |
| 159 printf("line %d: unsupported nonzero finoffset\n", | |
| 160 input_lineno); | |
| 161 return; | |
| 162 } | |
| 163 if (padptr->long_dim <= padptr->short_dim) { | |
| 164 printf("line %d: OF/RF long dim <= short dim\n", | |
| 165 input_lineno); | |
| 166 return; | |
| 167 } | |
| 168 } | |
| 169 padptr->valid = 1; | |
| 115 } | 170 } |
| 116 | 171 |
| 117 static void | 172 static void |
| 118 one_padstack_def() | 173 one_padstack_def() |
| 119 { | 174 { |
| 120 | 175 int pinno, stacklines, i; |
| 121 | 176 struct pad_shape_info *padptr; |
| 177 | |
| 178 get_line_internal(); | |
| 179 parse_input_line_fields(); | |
| 180 if (input_line_nfields != 3 || strcmp(input_line_fields[0], "PAD")) { | |
| 181 fprintf(stderr, "%s line %d: expected PAD header line\n", | |
| 182 input_filename, input_lineno); | |
| 183 exit(1); | |
| 184 } | |
| 185 pinno = atoi(input_line_fields[1]); | |
| 186 stacklines = atoi(input_line_fields[2]); | |
| 187 | |
| 188 if (pinno < 0 || pinno > fpbody.npins) { | |
| 189 fprintf(stderr, "%s line %d: PAD pinno field invalid\n", | |
| 190 input_filename, input_lineno); | |
| 191 exit(1); | |
| 192 } | |
| 193 if (pinno) | |
| 194 padptr = &pins_array[pinno-1].shape; | |
| 195 else | |
| 196 padptr = &fpbody.default_pad; | |
| 197 | |
| 198 for (i = 0; i < stacklines; i++) { | |
| 199 get_line_internal(); | |
| 200 parse_input_line_fields(); | |
| 201 if (input_line_nfields < 3) { | |
| 202 fprintf(stderr, | |
| 203 "%s line %d: too few fields in pad stack line\n", | |
| 204 input_filename, input_lineno); | |
| 205 exit(1); | |
| 206 } | |
| 207 if (!strcmp(input_line_fields[0], "-2")) | |
| 208 process_pad_shape(padptr); | |
| 209 } | |
| 210 } | |
| 211 | |
| 212 static void | |
| 213 apply_default_padstack() | |
| 214 { | |
| 215 int i; | |
| 216 | |
| 217 if (!fpbody.default_pad.valid) | |
| 218 return; | |
| 219 for (i = 0; i < fpbody.npins; i++) | |
| 220 if (!pins_array[i].shape.valid) | |
| 221 pins_array[i].shape = fpbody.default_pad; | |
| 222 } | |
| 223 | |
| 224 static | |
| 225 convert_pad_to_gpcb(pinidx) | |
| 226 { | |
| 227 struct footprint_pad *pin = pins_array + pinidx; | |
| 228 long long_minus_short; | |
| 229 | |
| 230 if (!pin->shape.valid) { | |
| 231 printf("error: no pad shape for pin #%d\n", pinidx + 1); | |
| 232 return(-1); | |
| 233 } | |
| 234 pin->thickness = pin->shape.short_dim; | |
| 235 pin->clearance = CLEARANCE_SETTING; | |
| 236 pin->mask = pin->thickness + SOLDERMASK_DELTA; | |
| 237 if (!pin->shape.elongated) { | |
| 238 pin->x2 = pin->x1; | |
| 239 pin->y2 = pin->y1; | |
| 240 return(0); | |
| 241 } | |
| 242 long_minus_short = pin->shape.long_dim - pin->shape.short_dim; | |
| 243 switch (pin->shape.angle) { | |
| 244 case 0: | |
| 245 pin->x2 = pin->x1 + long_minus_short; | |
| 246 pin->y2 = pin->y1; | |
| 247 return(0); | |
| 248 case 90: | |
| 249 pin->x2 = pin->x1; | |
| 250 pin->y2 = pin->y1 - long_minus_short; | |
| 251 return(0); | |
| 252 } | |
| 253 return(-1); | |
| 122 } | 254 } |
| 123 | 255 |
| 124 static void | 256 static void |
| 125 process_one_decal() | 257 process_one_decal() |
| 126 { | 258 { |
| 127 int i; | 259 int num_drawing_pieces, num_padstack_defs; |
| 260 int num_text_items, num_attr_labels; | |
| 261 int i, valid; | |
| 128 | 262 |
| 129 if (input_line_nfields < 7 || input_line_nfields > 9) { | 263 if (input_line_nfields < 7 || input_line_nfields > 9) { |
| 130 fprintf(stderr, | 264 fprintf(stderr, |
| 131 "%s line %d: expected beginning of part decal definition, wrong # of fields\n", | 265 "%s line %d: expected beginning of part decal definition, wrong # of fields\n", |
| 132 input_filename, input_lineno); | 266 input_filename, input_lineno); |
| 133 exit(1); | 267 exit(1); |
| 134 } | 268 } |
| 135 enter_decal(); | 269 enter_decal(); |
| 270 printf("Processing decal %s\n", current_decal->name); | |
| 136 bzero(&fpbody, sizeof fpbody); | 271 bzero(&fpbody, sizeof fpbody); |
| 137 if (input_line_fields[1][0] != 'I' && input_line_fields[1][0] != 'M' | 272 if (input_line_fields[1][0] != 'I' && input_line_fields[1][0] != 'M' |
| 138 || input_line_fields[1][1]) { | 273 || input_line_fields[1][1]) { |
| 139 fprintf(stderr, "%s line %d: expected 'I' or 'M' in field 1\n", | 274 fprintf(stderr, "%s line %d: expected 'I' or 'M' in field 1\n", |
| 140 input_filename, input_lineno); | 275 input_filename, input_lineno); |
| 194 read_pindef_line(i); | 329 read_pindef_line(i); |
| 195 /* read and process the pad stack definitions */ | 330 /* read and process the pad stack definitions */ |
| 196 for (i = 0; i < num_padstack_defs; i++) | 331 for (i = 0; i < num_padstack_defs; i++) |
| 197 one_padstack_def(); | 332 one_padstack_def(); |
| 198 | 333 |
| 199 | 334 /* post-processing */ |
| 335 apply_default_padstack(); | |
| 336 valid = 1; | |
| 337 for (i = 0; i < fpbody.npins; i++) | |
| 338 if (convert_pad_to_gpcb(i) < 0) | |
| 339 valid = 0; | |
| 340 if (valid) { | |
| 341 /* good, save it */ | |
| 342 current_decal->body = malloc(sizeof(struct footprint_body)); | |
| 343 if (!current_decal->body) { | |
| 344 perror("malloc to save footprint body"); | |
| 345 exit(1); | |
| 346 } | |
| 347 *current_decal->body = fpbody; | |
| 348 /* optional file output will go here */ | |
| 349 } else { | |
| 350 printf("decal to gpcb fp conversion FAILED\n"); | |
| 351 free(pins_array); | |
| 352 } | |
| 200 } | 353 } |
| 201 | 354 |
| 202 process_partdecal_section() | 355 process_partdecal_section() |
| 203 { | 356 { |
| 204 for (;;) { | 357 for (;;) { |
