-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbom_TURAG.ulp
771 lines (668 loc) · 22.7 KB
/
bom_TURAG.ulp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
#require 6.0500 //Version 6.5.0
#usage "<b>Teileliste exportieren</b>"
"<p>"
"Erzeugt die Teileliste (Bill of Material) eines Projektes"
"<p>"
///start define
//arguments
string ARG_NOUPDATE = "--noupdate";
string ARG_ABS_OCPATH = "--ocpath";
string ARG_ABS_BLACKLISTPATH = "--blpath";
//special attributes
string NO_ORDER = "NOORDER";
string PROTOTYPE = "PROTOTYPE";
string KEEP_AS_IS = "KEEP_AS_IS";
//providers
string PROVIDER_NAMES[] = {"FARNELL","REICHELT","DIGIKEY","WUERTH","MINICIRCUITS","RS"}; ///Only these attributes are important; all other will be ignored without warning
int PROVIDER_COUNT = 6;
//pathes
string ORDER_CODE_RELPATH = "order_codes/";
string BLACKLIST_RELPATH = "";
///end define
string msg;
int row=0;
numeric string list_rows[];
enum {output_text, output_farnell, output_reichelt, output_DigiKey, output_Excel};
// arrays for order codes from file
numeric string oc_device[], oc_package[], oc_value[], oc_provider[], oc_ordercode[];
int oc_index[], oc_count;
//arrays for order codes from schematic
numeric string part_name[], part_value[], part_device[], part_package[], part_headline[], part_description[], part_attributes[];
int part_amount[];
int num_parts = 0, output_format;
//run the update!
int run_update;
//order code path
string oc_path = "";
string bl_path = "";
/**
* \brief Returns the path to the directory of the ULP-file
*/
string get_pwd(void){
int index = strrchr(argv[0], '\\');
if (index < 0){
index = strrchr(argv[0], '/');
}
return strsub(argv[0], 0, index + 1 );
}
string remove_whitespaces(string input){
int start=0;
while(isspace(input[start])){
start++;
}
int end=strlen(input)-1;
if(start >= end){
return "";
}
while(isspace(input[end])){
end--;
}
return strsub(input, start, end-start+1);
}
/**
* \brief Collects part data from all files in ORDER_CODE_RELPATH directory and subdirectories
*/
void collectFilePartData(void){
string files[], lines[], line[], path;
int filecount, line_count, line_nargs;
oc_count = 0;
path = oc_path + "*.txt";
//dlgMessageBox(path);
filecount = fileglob(files,path);
fileerror(); //reset error buffer
for (int i=0;i<filecount;i++){
line_count = fileread(lines, files[i]);
if(fileerror()){
sprintf(msg, ":Error reading file %s", files[i]); dlgMessageBox(msg);
exit(1);
}
for (int line_nr=0;line_nr<line_count;line_nr++){
lines[line_nr] = remove_whitespaces(lines[line_nr]);
if( !(lines[line_nr]) ){
//ignore empty lines
continue;
}
if(strchr(lines[line_nr],'#') == 0){
//line starts with a '#' -> ignore
continue;
}
line_nargs = strsplit(line, lines[line_nr], ';');
//remove whitespaces
for(int j=0;j<line_nargs;j++){
line[j] = remove_whitespaces(line[j]);
}
if( line_nargs < 4 ){
string err;
sprintf(err, ":File '%s' has not enough arguments in line %d.", files[i], line_nr+1);
dlgMessageBox(err);
exit(-1);
}
if( strlen(line[0]) == 0){
string err;
sprintf(err, ":File '%s' has no device argument in line %d.", files[i], line_nr+1);
dlgMessageBox(err);
exit(-1);
}
if( strlen(line[1]) == 0){
string err;
sprintf(err, ":File '%s' has no package argument in line %d.", files[i], line_nr+1);
dlgMessageBox(err);
exit(-1);
}
for(j=0; j<(line_nargs-3); j++){
oc_device[oc_count] = strlwr(line[0]);
oc_package[oc_count] = strlwr(line[1]);
oc_value[oc_count] = strlwr(line[2]);
string order_codes[];
strsplit(order_codes, line[j+3], '>');
oc_provider[oc_count] = order_codes[0];
oc_ordercode[oc_count] = order_codes[1];
++oc_count;
}
}
}
sort(oc_count, oc_index, oc_device, oc_package, oc_value, oc_provider, oc_ordercode);
//print for debug
if(0){
sprintf(msg, "%d codes found", oc_count);
for(i=0; i<oc_count; i++){
int idx = oc_index[i];
sprintf(msg, "%s\n%d|%d|%s|%s|%s|%s|%s", msg, i, idx, oc_device[idx], oc_package[idx], oc_value[idx], oc_provider[idx], oc_ordercode[idx]);
}
dlgMessageBox(msg);
} //if(0)
}
/**
* \brief Updates and collects part data from schematic
*/
void updateCollectPartData(){
int printed_no_attributes_error = 0;
string update_cmd = "";
schematic(schem){
schem.parts(part){
if(part.device.package){
int keep_as_is = 0;
int attr_count, i, index;
numeric string attr_value[];
///get the properties
part_name[num_parts] = part.name;
part_value[num_parts] = strlwr(part.value);
part_device[num_parts] = strlwr(part.device.name);
part_package[num_parts] = strlwr(part.device.package.name);
part_headline[num_parts] = part.device.headline;
part_description[num_parts] = part.device.description;
part_attributes[num_parts] = "";
part_amount[num_parts]=1;
///simplify part package
if (part.device.prefix == "R" || part.device.prefix == "C" || part.device.prefix == "L") {
if (strstr(part_package[num_parts], "rcl_") == 0) { // remove "RCL_" from start of package name
part_package[num_parts] = strsub(part_package[num_parts], 4);
}
}
if (part.device.prefix == "C") {
if (strrchr(part_package[num_parts], 'k') == (strlen(part_package[num_parts])-1)) { // remove "K" from end of package name (Cs without Keepout)
part_package[num_parts] = strsub(part_package[num_parts], 0, strlen(part_package[num_parts])-1);
}
if( strrchr(part_device[num_parts], 'k') == (strlen(part_device[num_parts])-1) ){//remove 'K' from end of device name (Cs without Keepout
part_device[num_parts] = strsub(part_device[num_parts], 0, strlen(part_device[num_parts])-1);
}
}
///search for special attributes
part.attributes(attribute){
if(attribute.name == KEEP_AS_IS){
keep_as_is = 1;
}
}
///prepare part values
string new_value = part_value[num_parts];
int pos;
pos = strchr(new_value, 'µ'); if( pos >= 0 ) new_value[pos] = 'u';
pos = strchr(new_value, '.'); if( pos >= 0 ) new_value[pos] = ',';
if(new_value != part_value[num_parts]){
update_cmd += " VALUE " + part_name[num_parts] + " " + new_value + ";";
//sprintf(msg, "old value:%s, new:%s",part_value[num_parts], new_value); dlgMessageBox(msg);
}
///update attributes
if(run_update && !keep_as_is){
//try to find order code for the part in codes read from files
string updated_providers[];
int updated_providers_count = 0;
for(i=(oc_count-1); i>=0; i--){ //reverse search: empty value-entries should be used last. (like a wildcard)
index = oc_index[i];
if(oc_device[index] == part_device[num_parts]){
if(oc_package[index] == part_package[num_parts]){
//correspoinding entry found
break;
}
}
}
int debug = 0;//(part_name[num_parts] == ("UST$1"));
if(debug){sprintf(msg, "name:%s, dev:%s, pack:%s, %d",part_name[num_parts], part_device[num_parts], part_package[num_parts], i);dlgMessageBox(msg);}
while(i >= 0){
index = oc_index[i];
if(oc_package[index] != part_package[num_parts]){
if(debug>0){sprintf(msg, "no pack, i:%d", i); dlgMessageBox(msg); }
break;
}
if(oc_device[index] != part_device[num_parts]){
if(debug>0) dlgMessageBox("no dev");
break;
}
for(int j=0; j<updated_providers_count; j++){
if(oc_provider[index] == updated_providers[j]){
break;
}
}
if(j<updated_providers_count){
if(debug>0) dlgMessageBox("provider already updated");
//this provider was already updated. Trying to find another provider for the part
--i;
continue;
}
if(debug){sprintf(msg, "oc_val:%s, part_val:%s, i:%d", oc_value[index], part_value[num_parts], i); dlgMessageBox(msg);}
if( (!oc_value[index]) /*|| (!part_value[num_parts])*/ || (oc_value[index] == part_value[num_parts]) ){
//we (probably) found a suitable order code for the part
if(debug){sprintf(msg, "found. part attr:%s, oc:%s", part.attribute[oc_provider[index]], oc_ordercode[index]); dlgMessageBox(msg); debug=-1;}
if( part.attribute[oc_provider[index]] != oc_ordercode[index] ){
update_cmd += " ATTRIBUTE " + part_name[num_parts] + " " + oc_provider[index] + " '" + oc_ordercode[index] + "';";
}
updated_providers[updated_providers_count++] = oc_provider[index];
}
--i;
}
if(debug){ if(dlgMessageBox("continue?", "+Yes", "-No") == 1) exit(0); }
} //Update attributes ready
///collect Data for BOM
if(!update_cmd){
//only collect necessary data, when there is no part, that requires an update
///get the attributes
attr_count = 0;
part.attributes(attribute){
if(attr_count != -1){
for(int i=0;i<PROVIDER_COUNT;i++){
if( PROVIDER_NAMES[i] == attribute.name ){
if(attribute.value != ""){
attr_value[i] = attribute.value;
attr_count++;
}
break;
}
if( attribute.name == NO_ORDER){
attr_count = -1;
break;
} else if(attribute.name == PROTOTYPE){
string msg;
sprintf(msg,":Part '%s' is marked as PROTOTYPE and will be ordered twice.\n Please check, if the board is still in prototyping and you really want to order it twice", part_name[num_parts]);
if(dlgMessageBox(msg, "+Continue", "-Abort") == 1){
exit(1);
}
attr_value[PROVIDER_COUNT]=PROTOTYPE; //create an additional value in this array; PROVIDER_COUNT is the last+1 index
break;
}
}
}
}
///Check, whether there is at least one order code
if ( (attr_count == 0) && !printed_no_attributes_error){
string err_msg;
err_msg = "No order code found for part '" + part.name + "'";
dlgDialog("Order code not found"){
dlgVBoxLayout{
dlgHBoxLayout{
dlgLabel("<img src=warning.bmp>");
dlgStretch(1);
dlgLabel(err_msg);
dlgStretch(1);
}
//dlgSpacing(40);
dlgHBoxLayout{
dlgPushButton("I&gnore") {
dlgReject();
}
dlgPushButton("Ignore &All") {
printed_no_attributes_error = 1;
dlgAccept();
}
dlgPushButton("&Show Part"){
dlgReject();
exit("SHOW " + part.name);
}
dlgPushButton("+Show Part &Info"){
dlgReject();
exit("Info " + part.name);
}
dlgPushButton("-&Abort"){
dlgReject();
exit(0);
}
}
}
}; //dlgDialog
/*switch( dlgMessageBox(err_msg,"+Ignore","Ignore all","-Abort") ){
case 1: //Ignore all
printed_no_attributes_error = 1; break;
case 2: //abort
exit(0);
break;
}*/
}
} //if(!update_cmd)
///Check blacklisted parts
fileerror(); //reset error memory
string file[], line[];
string path = bl_path;//get_pwd() + "Blacklist.txt";
fileread(file, path);
if(fileerror()){
sprintf(msg, ":Error reading blacklist file %s", path); dlgMessageBox(msg);
exit(1);
}
for (int k=0; file[k]; k++){
if(!strchr(file[k],'#')){ /// ignore Lines beginning with '#'
continue;
}
int splitcount=strsplit(line, file[k], ';');
for(int j=0;j<PROVIDER_COUNT;j++){
if( (attr_value[j] == line[0]) && (PROVIDER_NAMES[j] == line[1]) ){
string err_msg;
err_msg = ":Part '" + part.name + "' with order code '" + attr_value[j] + "' is no longer available at "+ line[1] + " !!";
if(splitcount >2){
err_msg += "\n\nPossible alternative: '" + line[2] + "'";
}
if (dlgMessageBox(err_msg,"Ignore","+Abort") == 1) exit(0);
}
}
}
///separate the order codes if there is more than one (numbers are seperated by an ':')
int num_add_attr_total = 0;
int prototype_multi= 1;
string substr;
for(i=0;i<PROVIDER_COUNT;i++){
int index = 0, num_add_attr = 0;
if(attr_value[i] == ""){
//no attribute here -> nothing to do; only append a '\t' for displaying
while(num_add_attr <= num_add_attr_total){
part_attributes[num_parts + num_add_attr++] += "\t";
}
continue;
}
int pos = strchr(attr_value[i], ':', index);
if( (attr_value[PROVIDER_COUNT] == PROTOTYPE) ){ //check the part for prototype status
prototype_multi = 2;
} else {
prototype_multi = 1;
}
while( pos > -1){ ///there is another number
if(num_add_attr_total < num_add_attr){
for(int j=0;j<i;j++) part_attributes[num_parts + num_add_attr] += "\t";
}
substr = strsub(attr_value[i],index,pos-index);
index = pos+1;
pos = strchr(substr,'*');
if (pos == -1){
part_amount[num_parts + num_add_attr] = prototype_multi;
} else {
//there is already an multiple part --> get the amount and multiply it
int amount = strtol(strsub(substr,pos+1));
part_amount[num_parts + num_add_attr] = amount*prototype_multi;
}
part_attributes[num_parts + num_add_attr] += strsub(substr,0,pos) + "\t";
part_name[num_parts + num_add_attr] = part_name[num_parts]; ///get the corresponding part
//index = pos + 1;
pos = strchr(attr_value[i], ':', index);
num_add_attr++;
}
if(num_add_attr_total < num_add_attr){ ///this tabs are needed to dispay it properly in the list
for(int j=0;j<i;j++) part_attributes[num_parts + num_add_attr] += "\t";
num_add_attr_total = num_add_attr;
}
substr = strsub(attr_value[i],index);
pos = strchr(substr,'*');
if(pos == -1){
part_amount[num_parts + num_add_attr] = prototype_multi;
} else {
int amount = strtol(strsub(substr,pos+1));
part_amount[num_parts + num_add_attr] = amount*prototype_multi;
}
part_attributes[num_parts + num_add_attr] += strsub(substr,0,pos) + "\t";
part_name[num_parts + num_add_attr] = part_name[num_parts]; ///get the corresponding part
while(num_add_attr < num_add_attr_total){ ///this tabs are needed to dispay it properly in the list
num_add_attr++;
part_attributes[num_parts + num_add_attr] += "\t";
}
}
num_parts += num_add_attr_total + 1;
} //if(part.device.package)
}
}
if(update_cmd){
update_cmd = "CHANGE DISPLAY OFF;" + update_cmd + " run bom_TURAG " + ARG_NOUPDATE + ";";
//if( dlgMessageBox(update_cmd, "+OK", "-Abort") == 1) { exit(1); }
exit(update_cmd);
}
} //updateCollectPartData()
void GenerateList(void){
int index[];
int ind1, ind2, amount = 0;
string qty;
sort(num_parts, index, part_value, part_device, part_headline, part_package, part_attributes, part_name);
row = 0;
list_rows[row] = "Menge\tWert\tBauelement\tPackage\t";
for(int i=0;i<PROVIDER_COUNT;i++){
list_rows[row] += PROVIDER_NAMES[i] + "\t";
}
list_rows[row++] += "Beschreibung\tBauteile";
///accumulate the parts and get the amount if there is more than one part with the same properties
for(int i1 = 0, i2 = 1; i2<=num_parts; i2++){
int is_prototype = 0;
ind1 = index[i1]; //first part with same properties
ind2 = index[i2]; //the other(last) part with same properties
if(i1 == (i2-1)){
amount = part_amount[ind1];
}
if( (i2 != num_parts) && (part_value[ind1] == part_value[ind2]) && (part_package[ind1] == part_package[ind2]) && (part_device[ind1] == part_device[ind2]) && (part_attributes[ind1] == part_attributes[ind2])){
amount += part_amount[ind2];
continue;
}
sprintf(qty, "%d", (amount)); ///calculate quantity of same parts
amount = 0;
list_rows[row] = qty + "\t" + part_value[ind1] + "\t" + part_device[ind1] + "\t" + part_package[ind1] + "\t" + part_attributes[ind1] + part_headline[ind1] + "\t";
///list the part names
do{
list_rows[row] += part_name[index[i1]];
if(i1 < (i2-1)) list_rows[row] += ",";
}while(++i1<i2);
row++;
}
}
string MakeTextOutput(void){
string out = "", line, split[];
int i, width[], headers;
headers = strsplit(split,list_rows[0],'\t');
///get the maximum width for each column
for(i=0;list_rows[i];i++){
strsplit(split,list_rows[i],'\t');
for(int j=0;j<headers;j++){
width[j] = max(width[j], strlen(split[j]));
}
}
///print the rows
for(i=0;i<row;i++){
line = "";
int n = strsplit(split,list_rows[i],'\t');
if(i == 0){
headers = n;
} else {
n = headers; /// for the Rows with missing cells
}
for(int j=0;j<n;j++){
while(strlen(split[j]) <= width[j] ){ ///add spaces --> every row in every column the same width
split[j] += " ";
}
line += split[j] + "|";
}
if( i == 0 ){ ///the '-------' below the heading
int len = strlen(line);
line += "\n";
for(int j=0;j<=len;j++){
line += "-";
}
}
out += line + "\n";
}
return out;
}
string MakeFarnellOutput(void){ ///Farnell Syntax: 'number, quantity'
string out = "Bestellnummer,Menge\n", split[];
int farnell_index, i, j;
strsplit(split, list_rows[0], '\t');
for(i=0;list_rows[i];i++){ ///get the index of the Farnell-number
if (split[i] == "FARNELL"){
farnell_index = i;
break;
}
}
for(i=1;i<row;i++){
strsplit(split, list_rows[i], '\t');
if(split[farnell_index] != ""){
if( strtol(split[0]) ) out += split[farnell_index] + "," + split[0] + "\n"; ///split[0] is the quantity; make only an output, when there is any needed part
}
}
return out;
}
string MakeReicheltOutput(void){///Reichelt-Syntax: 'number;quantity'
string out = "", split[];
int reichelt_index, i, j;
strsplit(split, list_rows[0], '\t');
for(i=0;list_rows[i];i++){ ///get the index of the Reichelt-number
if (split[i] == "REICHELT"){
reichelt_index = i;
break;
}
}
for(i=1;i<row;i++){
strsplit(split, list_rows[i], '\t');
if(split[reichelt_index] != ""){
if( strtol(split[0]) ) out += split[reichelt_index] + ";" + split[0] + "\n";///split[0] is the quantity; make only an output, when there is any needed part
}
}
return out;
}
string MakeDigikeyOutput(void){///Digikey-Syntax: 'quantity,number'
string out = "", split[];
int digikey_index, i, j;
strsplit(split, list_rows[0], '\t');
for(i=0;list_rows[i];i++){ ///get the index of the Digikey-number
if (split[i] == "DIGIKEY"){
digikey_index = i;
break;
}
}
for(i=1;i<row;i++){
strsplit(split, list_rows[i], '\t');
if(split[digikey_index] != ""){
if( strtol(split[0]) ) out += split[0] + "," + split[digikey_index] + "\n";///split[0] is the quantity; make only an output, when there is any needed part
}
}
return out;
}
string MakeExcelOutput(void){
string out = "", line, split[];
int i, width[], headers;
headers = strsplit(split,list_rows[0],'\t');
///print the rows
for(i=0;i<row;i++){
line = "";
int n = strsplit(split,list_rows[i],'\t');
if(i == 0){
headers = n;
} else {
n = headers; /// for the Rows with missing cells
}
for(int j=0;j<n;j++){
line += split[j] + "\t";
}
out += line + "\n";
}
return out;
}
string MakeOutput(void){ ///Choose the Output-Format
switch(output_format){
case output_text: return MakeTextOutput(); break;
case output_farnell: return MakeFarnellOutput(); break;
case output_reichelt: return MakeReicheltOutput(); break;
case output_DigiKey: return MakeDigikeyOutput(); break;
case output_Excel: return MakeExcelOutput(); break;
}
return "";
}
void SaveData(void){
string file_name;
schematic(schem) file_name = filesetext(schem.name,""); ///filename is the name of the schematic; file will be stored in the folder of schematic
switch(output_format){
case output_farnell: file_name += "_farnell"; break;
case output_reichelt: file_name += "_reichelt"; break;
case output_DigiKey: file_name += "_digikey"; break;
case output_Excel: file_name += "_excel"; break;
}
file_name += ".txt";
string path = dlgFileSave("Teileliste speichern", file_name ); ///Open save-Dialog
if (path){ ///do not save if the path is empty
fileerror();
string s[];
if (!fileglob (s, path) || dlgMessageBox ("!Datei existiert - überschreiben?", "+&Ja", "-&Nein") == 0){ ///check, whether the file already exists and ask for overwriting
output (path, "wt"){ ///open the file
printf ("%s", MakeOutput()); ///write to the file
}
}
if (fileerror()){ ///there was an error while writing the file
dlgMessageBox(":Unable to save file");
return;
}
}
}
void ViewList(void){
dlgDialog("Voransicht"){ ///The window
dlgVBoxLayout{ ///box to stack it vertically
string s = MakeOutput();
s = "<pre>" + s + "</pre>";
dlgTextView(s); ///Text box
dlgHBoxLayout{ ///box for buttons (stack it horizontally)
dlgStretch(1); ///stretch: the buttons should be in the middle
dlgPushButton("+&Speichern...") SaveData();
dlgPushButton("+Schließen") dlgReject();
dlgStretch(1); ///stretch: the buttons should be in the middle
}
}
};
}
/// ~~~BEGIN of the ULP ~~~~~~
if (!schematic) ///this ULP only works in Schematicss
{
dlgMessageBox (":Die Bauteilliste kann nur innerhalb eines Schaltplanes erstellt werden.");
exit (1);
}
run_update = 1;
//check for parameters
for(int i=1; i<argc; i++){ //argv[0] is the path of this ULP
if( argv[i] == ARG_NOUPDATE){
run_update = 0;
}
if( argv[i] == ARG_ABS_OCPATH ){
//user provided an absolute path for order codes (or at least he should)
++i;
oc_path = argv[i];
int idx = strchr(oc_path, '\\');
while(idx >= 0){
oc_path[idx] = '/';
idx = strchr(oc_path, '\\');
}
oc_path += "/";
}
if( argv[i] == ARG_ABS_BLACKLISTPATH){
//user provided an absolute path for the blacklist-file (or at least he should)
++i;
bl_path = argv[i];
int idx = strchr(bl_path, '\\');
while(idx >= 0){
bl_path[idx] = '/';
idx = strchr(bl_path, '\\');
}
}
}
/// check for empty pathes
if(oc_path == ""){
oc_path = get_pwd() + ORDER_CODE_RELPATH;
}
if(bl_path == ""){
bl_path = get_pwd() + BLACKLIST_RELPATH + "Blacklist.txt";;
}
if(run_update){
collectFilePartData();
}
updateCollectPartData();
GenerateList();
//string str; sprintf(str, "parts: %d",num_parts); dlgMessageBox(str);
dlgDialog("Teileliste"){ ///Main Dialog
int selected = -2, sort_col = 2, format;
string head = ""; ///empty, because it will be generated in 'GenerateList()' as the row[0]
dlgVBoxLayout { ///Box to stack it vertically
dlgListView (head, list_rows, selected);//, sort_col); ///List
dlgHBoxLayout{ ///Box for the output-format
dlgGroup("Ausgabe-Format"){
dlgRadioButton("&Text", output_format);
dlgRadioButton("&Farnell-Bestellliste", output_format);
dlgRadioButton("&Reichelt-Bestellliste", output_format);
dlgRadioButton("&DigiKey-Bestellliste", output_format);
dlgRadioButton("Bestelliste für &Excel-Import", output_format);
}
dlgStretch(1);
}
dlgHBoxLayout{ ///box to stack the buttons horizontally
//dlgStretch(1);
dlgPushButton("&Voransicht") ViewList();
dlgPushButton("+&Speichern...") SaveData();
dlgPushButton("S&chließen") dlgReject();
dlgStretch(1);
}
}
};