~metacollin/kicad/osx_distribution

« back to all changes in this revision

Viewing changes to utils/idftools/idf_cylinder.cpp

  • Committer: jean-pierre charras
  • Author(s): Cirilo Bernardo
  • Date: 2014-02-05 09:27:21 UTC
  • mto: This revision was merged to the branch mainline in revision 4660.
  • Revision ID: jp.charras@wanadoo.fr-20140205092721-l33hnnhoqogdaajq
Apply IDF tools patch from Cirilo Bernardo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This program source code file is part of KiCad, a free EDA CAD application.
 
3
 *
 
4
 * Copyright (C) 2014  Cirilo Bernardo
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; either version 2
 
9
 * of the License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, you may find one here:
 
18
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 
19
 * or you may search the http://www.gnu.org website for the version 2 license,
 
20
 * or you may write to the Free Software Foundation, Inc.,
 
21
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
22
 */
 
23
 
 
24
/*
 
25
 *  This program creates an outline for a horizontal or vertically
 
26
 *  oriented axial or radial leaded cylinder with dimensions based
 
27
 *  on the user's input.
 
28
 */
 
29
 
 
30
#include <iostream>
 
31
#include <fstream>
 
32
#include <string>
 
33
#include <sstream>
 
34
#include <cmath>
 
35
#include <cstdio>
 
36
#include <list>
 
37
#include <utility>
 
38
#include <clocale>
 
39
 
 
40
using namespace std;
 
41
 
 
42
void make_vcyl( bool inch, bool axial, double dia, double length,
 
43
                double z, double wireDia );
 
44
 
 
45
void make_hcyl( bool inch, bool axial, double dia, double length,
 
46
                double z, double wireDia );
 
47
 
 
48
void writeAxialCyl( FILE* fp, bool inch, double dia, double length, double wireDia, double pitch );
 
49
 
 
50
void writeRadialCyl( FILE* fp, bool inch, double dia, double length, double wireDia,
 
51
                     double pitch, double lead );
 
52
 
 
53
int main( int argc, char **argv )
 
54
{
 
55
    // IDF implicitly requires the C locale
 
56
    setlocale( LC_ALL, "C" );
 
57
 
 
58
    if( argc == 1 )
 
59
    {
 
60
        cout << "idfcyl: This program generates an outline for a cylindrical component.\n";
 
61
        cout << "        The cylinder may be horizontal or vertical.\n";
 
62
        cout << "        A horizontal cylinder may have wires at one or both ends.\n";
 
63
        cout << "        A vertical cylinder may have at most one wire which may be\n";
 
64
        cout << "        placed on the left or right side.\n\n";
 
65
        cout << "Input:\n";
 
66
        cout << "        Unit: mm, in (millimeters or inches)\n";
 
67
        cout << "        Orientation: V (vertical)\n";
 
68
        cout << "        Lead type: X, R (axial, radial)\n";
 
69
        cout << "        Diameter of body\n";
 
70
        cout << "        Length of body\n";
 
71
        cout << "        Board offset\n";
 
72
        cout << "        *   Wire diameter\n";
 
73
        cout << "        *   Pitch\n";
 
74
        cout << "        **  Wire side: L, R (left, right)\n";
 
75
        cout << "        *** Lead length\n";
 
76
        cout << "        File name (must end in *.idf)\n\n";
 
77
        cout << "        NOTES:\n";
 
78
        cout << "            *   only required for horizontal orientation or\n";
 
79
        cout << "                vertical orientation with axial leads\n\n";
 
80
        cout << "            **  only required for vertical orientation with axial leads\n\n";
 
81
        cout << "            *** only required for horizontal orientation with radial leads\n\n";
 
82
    }
 
83
 
 
84
    char orientation = '\0';
 
85
    bool inch  = false; // default mm
 
86
    double dia = 0.0;
 
87
    double length = 0.0;
 
88
    double extraZ = 0.0;
 
89
    double wireDia = 0.0;
 
90
    bool axial = false;
 
91
 
 
92
    stringstream tstr;
 
93
    string line;
 
94
 
 
95
    line.clear();
 
96
    while( line.compare( "mm" ) && line.compare( "in" ) )
 
97
    {
 
98
        cout << "* Units (mm,in): ";
 
99
        line.clear();
 
100
        std::getline( cin, line );
 
101
    }
 
102
 
 
103
    if( line.compare( "mm" ) )
 
104
        inch = true;
 
105
 
 
106
    line.clear();
 
107
    while( line.compare( "H" ) && line.compare( "h" )
 
108
        && line.compare( "V" ) && line.compare( "v" ) )
 
109
    {
 
110
        cout << "* Orientation (H,V): ";
 
111
        line.clear();
 
112
        std::getline( cin, line );
 
113
    }
 
114
 
 
115
    if( line.compare( "H" ) && line.compare( "h" ) )
 
116
        orientation = 'v';
 
117
    else
 
118
        orientation = 'h';
 
119
 
 
120
    bool ok = false;
 
121
 
 
122
    while( !ok )
 
123
    {
 
124
        cout << "* Axial or Radial (X,R): ";
 
125
 
 
126
        line.clear();
 
127
        std::getline( cin, line );
 
128
 
 
129
        if( !line.compare( "x" ) || !line.compare( "X" ) )
 
130
        {
 
131
            axial = true;
 
132
            ok = true;
 
133
        }
 
134
        else if( !line.compare( "r" ) || !line.compare( "R" ) )
 
135
        {
 
136
            axial = false;
 
137
            ok = true;
 
138
        }
 
139
    }
 
140
 
 
141
    // cylinder dimensions
 
142
    ok = false;
 
143
    while( !ok )
 
144
    {
 
145
        cout << "* Diameter: ";
 
146
 
 
147
        line.clear();
 
148
        std::getline( cin, line );
 
149
 
 
150
        tstr.clear();
 
151
        tstr.str( line );
 
152
        if( (tstr >> dia) && dia > 0.0 )
 
153
            ok = true;
 
154
    }
 
155
 
 
156
    ok = false;
 
157
    while( !ok )
 
158
    {
 
159
        cout << "* Length: ";
 
160
 
 
161
        line.clear();
 
162
        std::getline( cin, line );
 
163
 
 
164
        tstr.clear();
 
165
        tstr.str( line );
 
166
        if( (tstr >> length) && length > 0.0 )
 
167
            ok = true;
 
168
    }
 
169
 
 
170
    ok = false;
 
171
    while( !ok )
 
172
    {
 
173
        cout << "* Board offset: ";
 
174
 
 
175
        line.clear();
 
176
        std::getline( cin, line );
 
177
 
 
178
        tstr.clear();
 
179
        tstr.str( line );
 
180
        if( (tstr >> extraZ) && extraZ > 0.0 )
 
181
            ok = true;
 
182
    }
 
183
 
 
184
    ok = false;
 
185
    while( ( axial || orientation == 'h' ) && !ok )
 
186
    {
 
187
        cout << "* Wire diameter: ";
 
188
 
 
189
        line.clear();
 
190
        std::getline( cin, line );
 
191
 
 
192
        tstr.clear();
 
193
        tstr.str( line );
 
194
        if( (tstr >> wireDia) && wireDia > 0.0 )
 
195
        {
 
196
            if( wireDia < dia )
 
197
                ok = true;
 
198
            else
 
199
                cout << "* WARNING: wire diameter must be < cylinder diameter\n";
 
200
        }
 
201
    }
 
202
 
 
203
    switch( orientation )
 
204
    {
 
205
        case 'v':
 
206
            make_vcyl( inch, axial, dia, length, extraZ, wireDia );
 
207
            break;
 
208
        case 'h':
 
209
            make_hcyl( inch, axial, dia, length, extraZ, wireDia );
 
210
            break;
 
211
        default:
 
212
            break;
 
213
    }
 
214
 
 
215
    setlocale( LC_ALL, "" );
 
216
    return 0;
 
217
}
 
218
 
 
219
 
 
220
void make_vcyl( bool inch, bool axial, double dia, double length,
 
221
                double z, double wireDia )
 
222
{
 
223
    bool ok = false;
 
224
    bool left = false;
 
225
    stringstream tstr;
 
226
    string line;
 
227
 
 
228
    double pitch = 0.0;
 
229
 
 
230
    while( axial && !ok )
 
231
    {
 
232
        cout << "* Pitch: ";
 
233
 
 
234
        line.clear();
 
235
        std::getline( cin, line );
 
236
 
 
237
        tstr.clear();
 
238
        tstr.str( line );
 
239
        if( (tstr >> pitch) && pitch > 0.0 )
 
240
        {
 
241
            if( (pitch - wireDia) <= (dia / 2.0) )
 
242
            {
 
243
                cout << "* WARNING: Pitch must be > dia/2 + wireDia\n";
 
244
            }
 
245
            else
 
246
            {
 
247
                ok = true;
 
248
            }
 
249
        }
 
250
    }
 
251
 
 
252
    ok = false;
 
253
    while( axial && !ok )
 
254
    {
 
255
        cout << "* Pin side (L,R): ";
 
256
 
 
257
        line.clear();
 
258
        std::getline( cin, line );
 
259
 
 
260
        if( !line.compare( "l" ) || !line.compare( "L" ) )
 
261
        {
 
262
            left = true;
 
263
            ok   = true;
 
264
        }
 
265
        else if( !line.compare( "r" ) || !line.compare( "R" ) )
 
266
            ok = true;
 
267
    }
 
268
 
 
269
    line.clear();
 
270
    while( line.empty() || line.find( ".idf" ) == string::npos )
 
271
    {
 
272
        cout << "* File name (*.idf): ";
 
273
 
 
274
        line.clear();
 
275
        std::getline( cin, line );
 
276
    }
 
277
 
 
278
    FILE* fp = fopen( line.c_str(), "w" );
 
279
 
 
280
    if( !fp )
 
281
    {
 
282
        cerr << "Could not open output file: " << line << "\n";
 
283
        return;
 
284
    }
 
285
 
 
286
    fprintf( fp, "# cylindrical outline, vertical, " );
 
287
 
 
288
    if( !axial )
 
289
        fprintf( fp, "radial leads\n" );
 
290
    else
 
291
        fprintf( fp, "axial lead on %s\n", left ? "left" : "right" );
 
292
 
 
293
    fprintf( fp, "# file: \"%s\"\n", line.c_str() );
 
294
 
 
295
    if( inch )
 
296
    {
 
297
        fprintf( fp, "# dia: %d THOU\n", (int) (dia * 1000) );
 
298
        fprintf( fp, "# length: %d THOU\n", (int) (length * 1000) );
 
299
        fprintf( fp, "# board offset: %d THOU\n", (int) (z * 1000) );
 
300
 
 
301
        if( axial )
 
302
        {
 
303
            fprintf( fp, "# wire dia: %d THOU\n", (int) (wireDia * 1000) );
 
304
            fprintf( fp, "# pitch: %d THOU\n", (int) (pitch * 1000) );
 
305
        }
 
306
    }
 
307
    else
 
308
    {
 
309
        fprintf( fp, "# dia: %.3f mm\n", dia );
 
310
        fprintf( fp, "# length: %.3f mm\n", length );
 
311
        fprintf( fp, "# board offset: %.3f mm\n", z );
 
312
 
 
313
        if( axial )
 
314
        {
 
315
            fprintf( fp, "# wire dia: %.3f mm\n", wireDia );
 
316
            fprintf( fp, "# pitch: %.3f mm\n", pitch );
 
317
        }
 
318
    }
 
319
 
 
320
    fprintf( fp, ".ELECTRICAL\n" );
 
321
 
 
322
    if( !axial )
 
323
    {
 
324
        fprintf( fp, "\"CYLV_%s_RAD\" \"D%.3f_H%.3f_Z%.3f\" ", inch ? "IN" : "MM",
 
325
            dia, length, z );
 
326
    }
 
327
    else
 
328
    {
 
329
        fprintf( fp, "\"CYLV_%s_AX%s\" \"D%.3f_H%.3f_Z%.3f_WD%.3f_P%.3f\" ", inch ? "IN" : "MM",
 
330
                 left ? "L" : "R", dia, length, z, wireDia, pitch );
 
331
    }
 
332
 
 
333
    if( inch )
 
334
        fprintf( fp, "THOU %d\n", (int) ((length + z) * 1000) );
 
335
    else
 
336
        fprintf( fp, "MM %.3f\n", length + z );
 
337
 
 
338
    if( !axial )
 
339
    {
 
340
        fprintf( fp, "0 0 0 0\n" );
 
341
 
 
342
        if( inch )
 
343
            fprintf( fp, "0 %d 0 360\n", (int) (dia * 1000) );
 
344
        else
 
345
            fprintf( fp, "0 %.3f 0 360\n", dia );
 
346
 
 
347
        fprintf( fp, ".END_ELECTRICAL\n" );
 
348
        fclose( fp );
 
349
        return;
 
350
    }
 
351
 
 
352
    double px[4], py[4];
 
353
 
 
354
    // points are:
 
355
    // [0] = upper point on cylinder perimeter
 
356
    // [1] = lower point on cylinder perimeter
 
357
    // [2] = point beneath wire center
 
358
    // [3] = point above wire center
 
359
 
 
360
    if( inch )
 
361
    {
 
362
        dia     *= 1000.0;
 
363
        pitch   *= 1000.0;
 
364
        wireDia *= 1000.0;
 
365
    }
 
366
 
 
367
    double ang = asin( wireDia / dia );
 
368
    px[0] = dia * cos( ang ) / 2.0 - pitch / 2.0;
 
369
    px[1] = px[0];
 
370
    px[2] = pitch / 2.0;
 
371
    px[3] = px[2];
 
372
 
 
373
    py[0] = wireDia / 2.0;
 
374
    py[1] = -py[0];
 
375
    py[2] = py[1];
 
376
    py[3] = py[0];
 
377
 
 
378
    char li = '0';
 
379
 
 
380
    double fullAng = 360.0;
 
381
 
 
382
    if( left )
 
383
    {
 
384
        li = '1';
 
385
        fullAng = -360.0;
 
386
        for( int i = 0; i < 4; ++i ) px[i] = -px[i];
 
387
    }
 
388
 
 
389
 
 
390
    if( inch )
 
391
    {
 
392
        fprintf( fp, "%c %d %d 0\n", li, (int) px[0], (int) py[0] );
 
393
        fprintf( fp, "%c %d %d %.3f\n", li, (int) px[1], (int) py[1],
 
394
                 fullAng * ( 1 - ang / M_PI ) );
 
395
        fprintf( fp, "%c %d %d 0\n", li, (int) px[2], (int) py[2] );
 
396
        fprintf( fp, "%c %d %d %s\n", li, (int) px[3], (int) py[3],
 
397
                 left ? "-180" : "180" );
 
398
        fprintf( fp, "%c %d %d 0\n", li, (int) px[0], (int) py[0] );
 
399
    }
 
400
    else
 
401
    {
 
402
        fprintf( fp, "%c %.3f %.3f 0\n", li, px[0], py[0] );
 
403
        fprintf( fp, "%c %.3f %.3f %.3f\n", li, px[1], py[1], fullAng * ( 1 - ang / M_PI ) );
 
404
        fprintf( fp, "%c %.3f %.3f 0\n", li, px[2], py[2] );
 
405
        fprintf( fp, "%c %.3f %.3f %s\n", li, px[3], py[3],
 
406
                 left ? "-180" : "180" );
 
407
        fprintf( fp, "%c %.3f %.3f 0\n", li, px[0], py[0] );
 
408
    }
 
409
 
 
410
    fprintf( fp, ".END_ELECTRICAL\n" );
 
411
    fclose( fp );
 
412
    return;
 
413
}
 
414
 
 
415
 
 
416
void make_hcyl( bool inch, bool axial, double dia, double length,
 
417
                double z, double wireDia )
 
418
{
 
419
    bool ok = false;
 
420
    stringstream tstr;
 
421
    string line;
 
422
 
 
423
    double pitch = 0.0;
 
424
    double lead  = 0.0; // lead length for radial leads
 
425
 
 
426
    ok = false;
 
427
    while( !ok )
 
428
    {
 
429
        if( axial )
 
430
            cout << "* Axial pitch: ";
 
431
        else
 
432
            cout << "* Radial pitch: ";
 
433
 
 
434
        line.clear();
 
435
        std::getline( cin, line );
 
436
 
 
437
        tstr.clear();
 
438
        tstr.str( line );
 
439
        if( (tstr >> pitch) && pitch > 0.0 )
 
440
        {
 
441
            if( axial )
 
442
            {
 
443
                if( (pitch - wireDia) <= length )
 
444
                {
 
445
                    cout << "* WARNING: Axial pitch must be > length + wireDia\n";
 
446
                }
 
447
                else
 
448
                {
 
449
                    ok = true;
 
450
                }
 
451
            }
 
452
            else
 
453
            {
 
454
                if( (pitch + wireDia) >= dia )
 
455
                {
 
456
                    cout << "* WARNING: Radial pitch must be < dia - wireDia\n";
 
457
                }
 
458
                else if( pitch <= wireDia )
 
459
                {
 
460
                    cout << "* WARNING: Radial pitch must be > wireDia\n";
 
461
                }
 
462
                else
 
463
                {
 
464
                    ok = true;
 
465
                }
 
466
            }
 
467
        }
 
468
    }
 
469
 
 
470
    ok = false;
 
471
    while( !axial && !ok )
 
472
    {
 
473
        cout << "* Lead length: ";
 
474
 
 
475
        line.clear();
 
476
        std::getline( cin, line );
 
477
 
 
478
        tstr.clear();
 
479
        tstr.str( line );
 
480
        if( (tstr >> lead) && lead > 0.0 )
 
481
        {
 
482
            if( lead < wireDia )
 
483
                cout << "* WARNING: lead length must be >= wireDia\n";
 
484
            else
 
485
                ok = true;
 
486
        }
 
487
    }
 
488
 
 
489
    line.clear();
 
490
    while( line.empty() || line.find( ".idf" ) == string::npos )
 
491
    {
 
492
        cout << "* File name (*.idf): ";
 
493
 
 
494
        line.clear();
 
495
        std::getline( cin, line );
 
496
    }
 
497
 
 
498
    FILE* fp = fopen( line.c_str(), "w" );
 
499
 
 
500
    if( !fp )
 
501
    {
 
502
        cerr << "Could not open output file: " << line << "\n";
 
503
        return;
 
504
    }
 
505
 
 
506
    fprintf( fp, "# cylindrical outline, horiz., " );
 
507
 
 
508
    fprintf( fp, "%s pins\n", axial ? "axial" : "radial" );
 
509
 
 
510
    fprintf( fp, "# file: \"%s\"\n", line.c_str() );
 
511
 
 
512
    if( inch )
 
513
    {
 
514
        fprintf( fp, "# dia: %d THOU\n", (int) (dia * 1000) );
 
515
        fprintf( fp, "# length: %d THOU\n", (int) (length * 1000) );
 
516
        fprintf( fp, "# extra height: %d THOU\n", (int) (z * 1000) );
 
517
        fprintf( fp, "# wire dia: %d THOU\n", (int) (wireDia * 1000) );
 
518
        fprintf( fp, "# pitch: %d THOU\n", (int) (pitch * 1000) );
 
519
        if( !axial )
 
520
            fprintf( fp, "# lead: %d THOU\n", (int) (lead * 1000) );
 
521
    }
 
522
    else
 
523
    {
 
524
        fprintf( fp, "# dia: %.3f mm\n", dia );
 
525
        fprintf( fp, "# length: %.3f mm\n", length );
 
526
        fprintf( fp, "# extra height: %.3f mm\n", z );
 
527
        fprintf( fp, "# wire dia: %.3f mm\n", wireDia );
 
528
        fprintf( fp, "# pitch: %.3f mm\n", pitch );
 
529
        if( !axial )
 
530
            fprintf( fp, "# lead: %.3f mm\n", lead );
 
531
    }
 
532
 
 
533
    fprintf( fp, ".ELECTRICAL\n" );
 
534
 
 
535
    if( axial )
 
536
    {
 
537
        fprintf( fp, "\"CYLH_%s_AXI\" \"D%.3f_H%.3f_Z%.3f_WD%.3f_P%.3f\" ",
 
538
                 inch ? "IN" : "MM", dia, length, z, wireDia, pitch );
 
539
    }
 
540
    else
 
541
    {
 
542
        fprintf( fp, "\"CYLH_%s_RAD\" \"D%.3f_H%.3f_Z%.3f_WD%.3f_P%.3f_L%.3f\" ",
 
543
                 inch ? "IN" : "MM", dia, length, z, wireDia, pitch, lead );
 
544
    }
 
545
 
 
546
    if( inch )
 
547
    {
 
548
        fprintf( fp, "THOU %d\n", (int) ((dia + z) * 1000) );
 
549
        dia *= 1000.0;
 
550
        length *= 1000.0;
 
551
        wireDia *= 1000.0;
 
552
        pitch *= 1000.0;
 
553
        if( !axial )
 
554
            lead *= 1000.0;
 
555
    }
 
556
    else
 
557
    {
 
558
        fprintf( fp, "MM %.3f\n", dia + z );
 
559
    }
 
560
 
 
561
    if( axial )
 
562
        writeAxialCyl( fp, inch, dia, length, wireDia, pitch );
 
563
    else
 
564
        writeRadialCyl( fp, inch, dia, length, wireDia, pitch, lead );
 
565
 
 
566
    fprintf( fp, ".END_ELECTRICAL\n" );
 
567
    fclose( fp );
 
568
    return;
 
569
    return;
 
570
}
 
571
 
 
572
void writeAxialCyl( FILE* fp, bool inch, double dia, double length,
 
573
                   double wireDia, double pitch )
 
574
{
 
575
    double x1, y1;
 
576
    double x2, y2;
 
577
 
 
578
    x1 = -length / 2.0;
 
579
    x2 = -pitch / 2.0;
 
580
    y1 = dia / 2.0;
 
581
    y2 = wireDia / 2.0;
 
582
 
 
583
    if( inch )
 
584
    {
 
585
        fprintf( fp, "0 %d %d 0\n", (int) x1, (int) y1 );
 
586
        fprintf( fp, "0 %d %d 0\n", (int) x1, (int) y2 );
 
587
        fprintf( fp, "0 %d %d 0\n", (int) x2, (int) y2 );
 
588
        fprintf( fp, "0 %d %d 180\n", (int) x2, (int) -y2 );
 
589
        fprintf( fp, "0 %d %d 0\n", (int) x1, (int) -y2 );
 
590
        fprintf( fp, "0 %d %d 0\n", (int) x1, (int) -y1 );
 
591
        fprintf( fp, "0 %d %d 0\n", (int) -x1, (int) -y1 );
 
592
        fprintf( fp, "0 %d %d 0\n", (int) -x1, (int) -y2 );
 
593
        fprintf( fp, "0 %d %d 0\n", (int) -x2, (int) -y2 );
 
594
        fprintf( fp, "0 %d %d 180\n", (int) -x2, (int) y2 );
 
595
        fprintf( fp, "0 %d %d 0\n", (int) -x1, (int) y2 );
 
596
        fprintf( fp, "0 %d %d 0\n", (int) -x1, (int) y1 );
 
597
        fprintf( fp, "0 %d %d 0\n", (int) x1, (int) y1 );
 
598
    }
 
599
    else
 
600
    {
 
601
        fprintf( fp, "0 %.3f %.3f 0\n", x1, y1 );
 
602
        fprintf( fp, "0 %.3f %.3f 0\n", x1, y2 );
 
603
        fprintf( fp, "0 %.3f %.3f 0\n", x2, y2 );
 
604
        fprintf( fp, "0 %.3f %.3f 180\n", x2, -y2 );
 
605
        fprintf( fp, "0 %.3f %.3f 0\n", x1, -y2 );
 
606
        fprintf( fp, "0 %.3f %.3f 0\n", x1, -y1 );
 
607
        fprintf( fp, "0 %.3f %.3f 0\n", -x1, -y1 );
 
608
        fprintf( fp, "0 %.3f %.3f 0\n", -x1, -y2 );
 
609
        fprintf( fp, "0 %.3f %.3f 0\n", -x2, -y2 );
 
610
        fprintf( fp, "0 %.3f %.3f 180\n", -x2, y2 );
 
611
        fprintf( fp, "0 %.3f %.3f 0\n", -x1, y2 );
 
612
        fprintf( fp, "0 %.3f %.3f 0\n", -x1, y1 );
 
613
        fprintf( fp, "0 %.3f %.3f 0\n", x1, y1 );
 
614
    }
 
615
 
 
616
    return;
 
617
}
 
618
 
 
619
void writeRadialCyl( FILE* fp, bool inch, double dia, double length,
 
620
                    double wireDia, double pitch, double lead )
 
621
{
 
622
    double x1, y1;
 
623
    double x2, y2;
 
624
    double x3;
 
625
 
 
626
    // center is between the mounting holes
 
627
    // which are on a horizontal line
 
628
    y1 = lead + length;
 
629
    y2 = lead;
 
630
    x1 = dia / 2.0;
 
631
    x2 = ( pitch + wireDia ) /2.0;
 
632
    x3 = x2 - wireDia;
 
633
 
 
634
    if( inch )
 
635
    {
 
636
        fprintf( fp, "0 %d %d 0\n", (int) -x1, (int) y1 );
 
637
        fprintf( fp, "0 %d %d 0\n", (int) -x1, (int) y2 );
 
638
        fprintf( fp, "0 %d %d 0\n", (int) -x2, (int) y2 );
 
639
        fprintf( fp, "0 %d 0 0\n", (int) -x2 );
 
640
        fprintf( fp, "0 %d 0 180\n", (int) -x3 );
 
641
        fprintf( fp, "0 %d %d 0\n", (int) -x3, (int) y2 );
 
642
        fprintf( fp, "0 %d %d 0\n", (int) x3, (int) y2 );
 
643
        fprintf( fp, "0 %d 0 0\n", (int) x3 );
 
644
        fprintf( fp, "0 %d 0 180\n", (int) x2 );
 
645
        fprintf( fp, "0 %d %d 0\n", (int) x2, (int) y2 );
 
646
        fprintf( fp, "0 %d %d 0\n", (int) x1, (int) y2 );
 
647
        fprintf( fp, "0 %d %d 0\n", (int) x1, (int) y1 );
 
648
        fprintf( fp, "0 %d %d 0\n", (int) -x1, (int) y1 );
 
649
    }
 
650
    else
 
651
    {
 
652
        fprintf( fp, "0 %.3f %.3f 0\n", -x1, y1 );
 
653
        fprintf( fp, "0 %.3f %.3f 0\n", -x1, y2 );
 
654
        fprintf( fp, "0 %.3f %.3f 0\n", -x2, y2 );
 
655
        fprintf( fp, "0 %.3f 0 0\n", -x2 );
 
656
        fprintf( fp, "0 %.3f 0 180\n", -x3 );
 
657
        fprintf( fp, "0 %.3f %.3f 0\n", -x3, y2 );
 
658
        fprintf( fp, "0 %.3f %.3f 0\n", x3, y2 );
 
659
        fprintf( fp, "0 %.3f 0 0\n", x3 );
 
660
        fprintf( fp, "0 %.3f 0 180\n", x2 );
 
661
        fprintf( fp, "0 %.3f %.3f 0\n", x2, y2 );
 
662
        fprintf( fp, "0 %.3f %.3f 0\n", x1, y2 );
 
663
        fprintf( fp, "0 %.3f %.3f 0\n", x1, y1 );
 
664
        fprintf( fp, "0 %.3f %.3f 0\n", -x1, y1 );
 
665
    }
 
666
 
 
667
    return;
 
668
}