KiCad PCB EDA Suite
Loading...
Searching...
No Matches
idf_outlines.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2014-2017 Cirilo Bernardo
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <iostream>
22#include <iomanip>
23#include <sstream>
24#include <cmath>
25#include <utility>
26
27#include <io/idf/idf_helpers.h>
28#include <io/idf/idf_outlines.h>
29#include <io/idf/idf_parser.h>
30
31#include "string_utils.h"
32
33using namespace IDF3;
34using namespace std;
35
36
37static std::string GetOutlineTypeString( IDF3::OUTLINE_TYPE aOutlineType )
38{
39 switch( aOutlineType )
40 {
42 return ".BOARD_OUTLINE";
43
45 return ".OTHER_OUTLINE";
46
48 return ".PLACEMENT_OUTLINE";
49
51 return ".ROUTE_OUTLINE";
52
54 return ".PLACE_KEEPOUT";
55
57 return ".ROUTE_KEEPOUT";
58
60 return ".VIA_KEEPOUT";
61
63 return ".PLACE_REGION";
64
66 return "COMPONENT OUTLINE";
67
68 default:
69 break;
70 }
71
72 std::ostringstream ostr;
73 ostr << "[INVALID OUTLINE TYPE VALUE]:" << static_cast<int>( aOutlineType );
74
75 return ostr.str();
76}
77
78
79#ifndef DISABLE_IDF_OWNERSHIP
80static bool CheckOwnership( int aSourceLine, const char* aSourceFunc,
81 IDF3_BOARD* aParent, IDF3::KEY_OWNER aOwnerCAD,
82 IDF3::OUTLINE_TYPE aOutlineType, std::string& aErrorString )
83{
84 if( aParent == nullptr )
85 {
86 ostringstream ostr;
87 ostr << "* " << __FILE__ << ":" << aSourceLine << ":" << aSourceFunc << "():\n";
88 ostr << "* BUG: outline's parent not set; cannot enforce ownership rules\n";
89 ostr << "* outline type: " << GetOutlineTypeString( aOutlineType );
90 aErrorString = ostr.str();
91
92 return false;
93 }
94
95 // note: component outlines have no owner so we don't care about
96 // who modifies them
97 if( aOwnerCAD == KEY_OWNER::UNOWNED || aOutlineType == IDF3::OUTLINE_TYPE::OTLN_COMPONENT )
98 return true;
99
100 IDF3::CAD_TYPE parentCAD = aParent->GetCadType();
101
102 if( aOwnerCAD == KEY_OWNER::MCAD && parentCAD == CAD_TYPE::CAD_MECH )
103 return true;
104
105 if( aOwnerCAD == KEY_OWNER::ECAD && parentCAD == CAD_TYPE::CAD_ELEC )
106 return true;
107
108 do
109 {
110 ostringstream ostr;
111 ostr << __FILE__ << ":" << aSourceLine << ":" << aSourceFunc << "():\n";
112 ostr << "* ownership violation; CAD type is ";
113
114 if( parentCAD == CAD_TYPE::CAD_MECH )
115 ostr << "MCAD ";
116 else
117 ostr << "ECAD ";
118
119 ostr << "while outline owner is " << GetOwnerString( aOwnerCAD ) << "\n";
120 ostr << "* outline type: " << GetOutlineTypeString( aOutlineType );
121 aErrorString = ostr.str();
122
123 } while( 0 );
124
125 return false;
126}
127#endif
128
129
139
140
145
146
151
152
153void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aIdfVersion )
154{
155 // reads the outline data from a file
156 double x, y, ang;
157 double dLoc = 1e-5; // distances are equal when closer than 0.1 micron
158 bool comment = false;
159 bool quoted = false;
160 bool closed = false;
161 int idx = 0;
162 int loopidx = -1;
163 int tmp = 0;
164 int npts = 0;
165 std::string iline;
166 std::string entry;
167 std::stringstream tstr;
168 IDF_OUTLINE* op = nullptr;
169 IDF_SEGMENT* sp = nullptr;
170 IDF_POINT prePt;
171 IDF_POINT curPt;
172 std::streampos pos;
173
174 // destroy any existing outline data
176
177 while( aBoardFile.good() )
178 {
179 if( !FetchIDFLine( aBoardFile, iline, comment, pos ) )
180 continue;
181
182 idx = 0;
183 GetIDFString( iline, entry, quoted, idx );
184
185 if( quoted )
186 {
187 ostringstream ostr;
188
189 ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " <<
191 ostr << " is quoted\n";
192 ostr << "* line: '" << iline << "'";
193
194 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
195 }
196
197 // check for the end of the section
198 if( entry.size() >= 5 && CompareToken( ".END_", entry.substr( 0, 5 ) ) )
199 {
200 // rewind to the start of the last line; the routine invoking
201 // this is responsible for checking that the current '.END_ ...'
202 // matches the section header.
203 if( aBoardFile.eof() )
204 aBoardFile.clear();
205
206 aBoardFile.seekg( pos );
207
208 if( outlines.size() > 0 )
209 {
210 if( npts > 0 && !closed )
211 {
212 ostringstream ostr;
213 ostr << "invalid outline (not closed)\n";
214 ostr << "* file position: " << pos;
215
216 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
217 }
218
219 // verify winding
220 if( !single )
221 {
222 if( !outlines.front()->IsCCW() )
223 {
224 ERROR_IDF << "invalid IDF3 file (BOARD_OUTLINE)\n";
225 cerr << "* WARNING: first outline is not in CCW order\n";
226 return;
227 }
228
229 if( outlines.size() > 1 && outlines.back()->IsCCW() &&
230 !outlines.back()->IsCircle() )
231 {
232 ERROR_IDF << "invalid IDF3 file (BOARD_OUTLINE)\n";
233 cerr << "* WARNING: final cutout does not have points in CW order\n";
234 cerr << "* file position: " << pos << "\n";
235 return;
236 }
237 }
238 }
239
240 return;
241 }
242
243 tstr.clear();
244 tstr << entry;
245
246 tstr >> tmp;
247
248 if( tstr.fail() )
249 {
250 if( outlineType == OUTLINE_TYPE::OTLN_COMPONENT && CompareToken( "PROP", entry ) )
251 {
252 aBoardFile.seekg( pos );
253 return;
254 }
255
256 do
257 {
258 ostringstream ostr;
259
260 ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " <<
262 ostr << " is not numeric\n";
263 ostr << "* line: '" << iline << "'\n";
264 ostr << "* file position: " << pos;
265
266 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
267
268 } while( 0 );
269 }
270
271 if( tmp != loopidx )
272 {
273 // index change
274 if( npts > 0 && !closed )
275 {
276 ostringstream ostr;
277 ostr << "invalid outline ( outline # " << loopidx << " not closed)\n";
278 ostr << "* file position: " << pos;
279
280 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
281 }
282
283 if( tmp < 0 )
284 {
285 ostringstream ostr;
286
287 ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " <<
289 ostr << " is invalid\n";
290 ostr << "* line: '" << iline << "'\n";
291 ostr << "* file position: " << pos;
292
293 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
294 }
295
296 if( loopidx == -1 )
297 {
298 // first outline
299 if( single )
300 {
301 // outline may have a Loop Index of 0 or 1
302 if( tmp == 0 || tmp == 1 )
303 {
304 try
305 {
306 op = new IDF_OUTLINE;
307 }
308 catch( std::bad_alloc& )
309 {
311 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
312 "memory allocation failed" ) );
313 }
314
315 outlines.push_back( op );
316 loopidx = tmp;
317 }
318 else
319 {
320 ostringstream ostr;
321
322 ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " <<
324 ostr << " is invalid (must be 0 or 1)\n";
325 ostr << "* line: '" << iline << "'\n";
326 ostr << "* file position: " << pos;
327
328 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
329 }
330 }
331 else
332 {
333 // outline *MUST* have a Loop Index of 0
334 if( tmp != 0 )
335 {
336 ostringstream ostr;
337
338 ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " <<
340 ostr << " is invalid (must be 0)\n";
341 ostr << "* line: '" << iline << "'\n";
342 ostr << "* file position: " << pos;
343
344 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
345 }
346
347 try
348 {
349 op = new IDF_OUTLINE;
350 }
351 catch( std::bad_alloc& )
352 {
354 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
355 "memory allocation failed" ) );
356 }
357
358 outlines.push_back( op );
359 loopidx = tmp;
360 }
361 }
362 else
363 {
364 // outline for cutout
365 if( single )
366 {
367 ostringstream ostr;
368
369 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType );
370 ostr << " section may only have one outline\n";
371 ostr << "* line: '" << iline << "'\n";
372 ostr << "* file position: " << pos;
373
374 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
375 }
376
377 if( tmp - loopidx != 1 )
378 {
379 ostringstream ostr;
380
381 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType );
382 ostr << " section must have cutouts in numeric order from 1 onwards\n";
383 ostr << "* line: '" << iline << "'\n";
384 ostr << "* file position: " << pos;
385
386 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
387 }
388
389 // verify winding of previous outline
390 if( ( loopidx == 0 && !op->IsCCW() )
391 || ( loopidx > 0 && op->IsCCW() && !op->IsCircle() ) )
392 {
393 ostringstream ostr;
394
395 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
396 ostr << "* violation of loop point order rules by Loop Index " << loopidx <<
397 "\n";
398 ostr << "* line: '" << iline << "'\n";
399 ostr << "* file position: " << pos;
400
401 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
402 }
403
404 try
405 {
406 op = new IDF_OUTLINE;
407 }
408 catch( std::bad_alloc& )
409 {
411 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
412 "memory allocation failed" ) );
413 }
414
415 outlines.push_back( op );
416 loopidx = tmp;
417 }
418 // end of index change code
419 npts = 0;
420 closed = false;
421 }
422
423 if( op == nullptr )
424 {
425 ostringstream ostr;
426
427 ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " <<
429 ostr << " is invalid\n";
430 ostr << "* line: '" << iline << "'\n";
431 ostr << "* file position: " << pos;
432
433 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
434 }
435
436 if( !GetIDFString( iline, entry, quoted, idx ) )
437 {
438 ostringstream ostr;
439
440 ostr << "\n* invalid outline: RECORD 3, FIELD 2 of ";
441 ostr << GetOutlineTypeString( outlineType ) << " does not exist\n";
442 ostr << "* line: '" << iline << "'\n";
443 ostr << "* file position: " << pos;
444
445 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
446 }
447
448 if( quoted )
449 {
450 ostringstream ostr;
451
452 ostr << "\n* invalid outline: RECORD 3, FIELD 2 of ";
453 ostr << GetOutlineTypeString( outlineType ) << " must not be in quotes\n";
454 ostr << "* line: '" << iline << "'\n";
455 ostr << "* file position: " << pos;
456
457 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
458 }
459
460 tstr.clear();
461 tstr << entry;
462
463 tstr >> x;
464
465 if( tstr.fail() )
466 {
467 ostringstream ostr;
468
469 ostr << "\n* invalid outline: RECORD 3, FIELD 2 of ";
470 ostr << GetOutlineTypeString( outlineType ) << " is an invalid X value\n";
471 ostr << "* line: '" << iline << "'\n";
472 ostr << "* file position: " << pos;
473
474 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
475 }
476
477 if( !GetIDFString( iline, entry, quoted, idx ) )
478 {
479 ostringstream ostr;
480
481 ostr << "\n* invalid outline: RECORD 3, FIELD 3 of ";
482 ostr << GetOutlineTypeString( outlineType ) << " does not exist\n";
483 ostr << "* line: '" << iline << "'\n";
484 ostr << "* file position: " << pos;
485
486 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
487 }
488
489 if( quoted )
490 {
491 ostringstream ostr;
492
493 ostr << "\n* invalid outline: RECORD 3, FIELD 3 of ";
494 ostr << GetOutlineTypeString( outlineType ) << " must not be in quotes\n";
495 ostr << "* line: '" << iline << "'\n";
496 ostr << "* file position: " << pos;
497
498 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
499 }
500
501 tstr.clear();
502 tstr << entry;
503
504 tstr >> y;
505
506 if( tstr.fail() )
507 {
508 ostringstream ostr;
509
510 ostr << "\n* invalid outline: RECORD 3, FIELD 3 of ";
511 ostr << GetOutlineTypeString( outlineType ) << " is an invalid Y value\n";
512 ostr << "* line: '" << iline << "'\n";
513 ostr << "* file position: " << pos;
514
515 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
516 }
517
518 if( !GetIDFString( iline, entry, quoted, idx ) )
519 {
520 ostringstream ostr;
521
522 ostr << "\n* invalid outline: RECORD 3, FIELD 4 of ";
523 ostr << GetOutlineTypeString( outlineType ) << " does not exist\n";
524 ostr << "* line: '" << iline << "'\n";
525 ostr << "* file position: " << pos;
526
527 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
528 }
529
530 if( quoted )
531 {
532 ostringstream ostr;
533
534 ostr << "\n* invalid outline: RECORD 3, FIELD 4 of ";
535 ostr << GetOutlineTypeString( outlineType ) << " must not be in quotes\n";
536 ostr << "* line: '" << iline << "'\n";
537 ostr << "* file position: " << pos;
538
539 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
540 }
541
542 tstr.clear();
543 tstr << entry;
544
545 tstr >> ang;
546
547 if( tstr.fail() )
548 {
549 ostringstream ostr;
550
551 ostr << "\n* invalid outline: RECORD 3, FIELD 4 of ";
552 ostr << GetOutlineTypeString( outlineType ) << " is not a valid angle\n";
553 ostr << "* line: '" << iline << "'\n";
554 ostr << "* file position: " << pos;
555
556 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
557 }
558
559 // the line was successfully read; convert to mm if necessary
561 {
562 x *= IDF_THOU_TO_MM;
563 y *= IDF_THOU_TO_MM;
564 }
565 else if( ( aIdfVersion == IDF_VERSION::IDF_V2 ) && ( unit == IDF_UNIT::UNIT_TNM ) )
566 {
567 x *= IDF_TNM_TO_MM;
568 y *= IDF_TNM_TO_MM;
569 }
570 else if( unit != IDF_UNIT::UNIT_MM )
571 {
572 ostringstream ostr;
573 ostr << "\n* BUG: invalid UNIT type: " << static_cast<int>( unit );
574
575 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
576 }
577
578 if( npts++ == 0 )
579 {
580 // first point
581 prePt.x = x;
582 prePt.y = y;
583
584 // ensure that the first point is not an arc specification
585 if( ang < -MIN_ANG || ang > MIN_ANG )
586 {
587 ostringstream ostr;
588
589 ostr << "\n* invalid outline: RECORD 3 of ";
590 ostr << GetOutlineTypeString( outlineType ) << "\n";
591 ostr << "* violation: first point of an outline has a non-zero angle\n";
592 ostr << "* line: '" << iline << "'\n";
593 ostr << "* file position: " << pos;
594
595 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
596 }
597 }
598 else
599 {
600 // Nth point
601 if( closed )
602 {
603 ostringstream ostr;
604
605 ostr << "\n* invalid outline: RECORD 3 of ";
606 ostr << GetOutlineTypeString( outlineType ) << "\n";
607 ostr << "* violation: adding a segment to a closed outline\n";
608 ostr << "* line: '" << iline << "'\n";
609 ostr << "* file position: " << pos;
610
611 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
612 }
613
614 curPt.x = x;
615 curPt.y = y;
616
617 try
618 {
619 if( ang > -MIN_ANG && ang < MIN_ANG )
620 {
621 sp = new IDF_SEGMENT( prePt, curPt );
622 }
623 else
624 {
625 sp = new IDF_SEGMENT( prePt, curPt, ang, false );
626 }
627 }
628 catch( std::bad_alloc& )
629 {
631 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
632 "memory allocation failed" ) );
633 }
634
635 if( sp->IsCircle() )
636 {
637 // this is a circle; the loop is closed
638 if( op->size() != 0 )
639 {
640 delete sp;
641
642 ostringstream ostr;
643
644 ostr << "\n* invalid outline: RECORD 3 of ";
645 ostr << GetOutlineTypeString( outlineType ) << "\n";
646 ostr << "* violation: adding a circle to a non-empty outline\n";
647 ostr << "* line: '" << iline << "'\n";
648 ostr << "* file position: " << pos;
649
650 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
651 }
652
653 closed = true;
654 }
655 else if( op->size() != 0 )
656 {
657 if( curPt.Matches( op->front()->startPoint, dLoc ) )
658 closed = true;
659 }
660
661 op->push( sp );
662 prePt.x = x;
663 prePt.y = y;
664 }
665 }
666
667 // NOTE:
668 // 1. ideally we would ensure that there are no arcs with a radius of 0
669
670 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
671 "problems reading file (premature end of outline)" ) );
672
673 return;
674}
675
676
677bool BOARD_OUTLINE::writeComments( std::ostream& aBoardFile )
678{
679 if( comments.empty() )
680 return true;
681
682 list< string >::const_iterator itS = comments.begin();
683 list< string >::const_iterator itE = comments.end();
684
685 while( itS != itE )
686 {
687 aBoardFile << "# " << *itS << "\n";
688 ++itS;
689 }
690
691 return !aBoardFile.fail();
692}
693
694
695bool BOARD_OUTLINE::writeOwner( std::ostream& aBoardFile )
696{
697 switch( owner )
698 {
699 case KEY_OWNER::ECAD:
700 aBoardFile << "ECAD\n";
701 break;
702
703 case KEY_OWNER::MCAD:
704 aBoardFile << "MCAD\n";
705 break;
706
707 default:
708 aBoardFile << "UNOWNED\n";
709 break;
710 }
711
712 return !aBoardFile.fail();
713}
714
715
716void BOARD_OUTLINE::writeOutline( std::ostream& aBoardFile, IDF_OUTLINE* aOutline, size_t aIndex )
717{
718 std::list<IDF_SEGMENT*>::iterator bo;
719 std::list<IDF_SEGMENT*>::iterator eo;
720
721 if( !aOutline )
722 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
723 "\n* BUG: nullptr outline pointer" ) );
724
725 if( aOutline->size() == 1 )
726 {
727 if( !aOutline->front()->IsCircle() )
728 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
729 "bad outline (single segment item, not circle)" ) );
730
731 if( single )
732 aIndex = 0;
733
734 // NOTE: a circle always has an angle of 360, never -360,
735 // otherwise SolidWorks chokes on the file.
737 {
738 aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5)
739 << aOutline->front()->startPoint.x << " "
740 << aOutline->front()->startPoint.y << " 0\n";
741
742 aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5)
743 << aOutline->front()->endPoint.x << " "
744 << aOutline->front()->endPoint.y << " 360\n";
745 }
746 else
747 {
748 aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1)
749 << (aOutline->front()->startPoint.x / IDF_THOU_TO_MM) << " "
750 << (aOutline->front()->startPoint.y / IDF_THOU_TO_MM) << " 0\n";
751
752 aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1)
753 << (aOutline->front()->endPoint.x / IDF_THOU_TO_MM) << " "
754 << (aOutline->front()->endPoint.y / IDF_THOU_TO_MM) << " 360\n";
755 }
756
757 return;
758 }
759
760 if( single )
761 {
762 // only indices 0 (CCW) and 1 (CW) are valid; set the index according to
763 // the outline's winding
764 if( aOutline->IsCCW() )
765 aIndex = 0;
766 else
767 aIndex = 1;
768 }
769
770
771 // check if we must reverse things
772 if( ( aOutline->IsCCW() && ( aIndex > 0 ) ) || ( ( !aOutline->IsCCW() ) && ( aIndex == 0 ) ) )
773 {
774 eo = aOutline->begin();
775 bo = aOutline->end();
776 --bo;
777
778 // ensure that the very last point is the same as the very first point
779 if( aOutline->size() > 1 )
780 {
781 std::list<IDF_SEGMENT*>::iterator to = eo;
782 ++to;
783 (*to)->startPoint = (*eo)->endPoint;
784 }
785
786 // for the first item we write out both points
788 {
789 if( aOutline->front()->angle < MIN_ANG && aOutline->front()->angle > -MIN_ANG )
790 {
791 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
792 << aOutline->front()->endPoint.x << " " << aOutline->front()->endPoint.y
793 << " 0\n";
794
795 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
796 << aOutline->front()->startPoint.x << " "
797 << aOutline->front()->startPoint.y << " 0\n";
798 }
799 else
800 {
801 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
802 << aOutline->front()->endPoint.x << " " << aOutline->front()->endPoint.y
803 << " 0\n";
804
805 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
806 << aOutline->front()->startPoint.x << " "
807 << aOutline->front()->startPoint.y << " " << setprecision( 3 )
808 << -aOutline->front()->angle << "\n";
809 }
810 }
811 else
812 {
813 if( aOutline->front()->angle < MIN_ANG && aOutline->front()->angle > -MIN_ANG )
814 {
815 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
816 << ( aOutline->front()->endPoint.x / IDF_THOU_TO_MM ) << " "
817 << ( aOutline->front()->endPoint.y / IDF_THOU_TO_MM ) << " 0\n";
818
819 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
820 << ( aOutline->front()->startPoint.x / IDF_THOU_TO_MM ) << " "
821 << ( aOutline->front()->startPoint.y / IDF_THOU_TO_MM ) << " 0\n";
822 }
823 else
824 {
825 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
826 << ( aOutline->front()->endPoint.x / IDF_THOU_TO_MM ) << " "
827 << ( aOutline->front()->endPoint.y / IDF_THOU_TO_MM ) << " 0\n";
828
829 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
830 << ( aOutline->front()->startPoint.x / IDF_THOU_TO_MM ) << " "
831 << ( aOutline->front()->startPoint.y / IDF_THOU_TO_MM ) << " "
832 << setprecision( 3 ) << -aOutline->front()->angle << "\n";
833 }
834 }
835
836 // for all other segments we only write out the start point
837 while( bo != eo )
838 {
840 {
841 if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG )
842 {
843 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
844 << ( *bo )->startPoint.x << " " << ( *bo )->startPoint.y << " 0\n";
845 }
846 else
847 {
848 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
849 << ( *bo )->startPoint.x << " " << ( *bo )->startPoint.y << " "
850 << setprecision( 3 ) << -( *bo )->angle << "\n";
851 }
852 }
853 else
854 {
855 if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG )
856 {
857 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
858 << ( ( *bo )->startPoint.x / IDF_THOU_TO_MM ) << " "
859 << ( ( *bo )->startPoint.y / IDF_THOU_TO_MM ) << " 0\n";
860 }
861 else
862 {
863 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
864 << ( ( *bo )->startPoint.x / IDF_THOU_TO_MM ) << " "
865 << ( ( *bo )->startPoint.y / IDF_THOU_TO_MM ) << " "
866 << setprecision( 3 ) << -( *bo )->angle << "\n";
867 }
868 }
869
870 --bo;
871 }
872 }
873 else
874 {
875 // ensure that the very last point is the same as the very first point
876 if( aOutline->size() > 1 )
877 aOutline->back()-> endPoint = aOutline->front()->startPoint;
878
879 bo = aOutline->begin();
880 eo = aOutline->end();
881
882 // for the first item we write out both points
884 {
885 if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG )
886 {
887 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
888 << ( *bo )->startPoint.x << " " << ( *bo )->startPoint.y << " 0\n";
889
890 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
891 << ( *bo )->endPoint.x << " " << ( *bo )->endPoint.y << " 0\n";
892 }
893 else
894 {
895 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
896 << ( *bo )->startPoint.x << " " << ( *bo )->startPoint.y << " 0\n";
897
898 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
899 << ( *bo )->endPoint.x << " " << ( *bo )->endPoint.y << " "
900 << setprecision( 3 ) << ( *bo )->angle << "\n";
901 }
902 }
903 else
904 {
905 if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG )
906 {
907 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
908 << ( ( *bo )->startPoint.x / IDF_THOU_TO_MM ) << " "
909 << ( ( *bo )->startPoint.y / IDF_THOU_TO_MM ) << " 0\n";
910
911 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
912 << ( ( *bo )->endPoint.x / IDF_THOU_TO_MM ) << " "
913 << ( ( *bo )->endPoint.y / IDF_THOU_TO_MM ) << " 0\n";
914 }
915 else
916 {
917 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
918 << ( ( *bo )->startPoint.x / IDF_THOU_TO_MM ) << " "
919 << ( ( *bo )->startPoint.y / IDF_THOU_TO_MM ) << " 0\n";
920
921 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
922 << ( ( *bo )->endPoint.x / IDF_THOU_TO_MM ) << " "
923 << ( ( *bo )->endPoint.y / IDF_THOU_TO_MM ) << " " << setprecision( 3 )
924 << ( *bo )->angle << "\n";
925 }
926 }
927
928 ++bo;
929
930 // for all other segments we only write out the last point
931 while( bo != eo )
932 {
934 {
935 if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG )
936 {
937 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
938 << ( *bo )->endPoint.x << " " << ( *bo )->endPoint.y << " 0\n";
939 }
940 else
941 {
942 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 )
943 << ( *bo )->endPoint.x << " " << ( *bo )->endPoint.y << " "
944 << setprecision( 3 ) << ( *bo )->angle << "\n";
945 }
946 }
947 else
948 {
949 if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG )
950 {
951 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
952 << ( ( *bo )->endPoint.x / IDF_THOU_TO_MM ) << " "
953 << ( ( *bo )->endPoint.y / IDF_THOU_TO_MM ) << " 0\n";
954 }
955 else
956 {
957 aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 )
958 << ( ( *bo )->endPoint.x / IDF_THOU_TO_MM ) << " "
959 << ( ( *bo )->endPoint.y / IDF_THOU_TO_MM ) << " "
960 << setprecision( 3 ) << ( *bo )->angle << "\n";
961 }
962 }
963
964 ++bo;
965 }
966 }
967}
968
969
970void BOARD_OUTLINE::writeOutlines( std::ostream& aBoardFile )
971{
972 if( outlines.empty() )
973 return;
974
975 int idx = 0;
976 std::list< IDF_OUTLINE* >::iterator itS = outlines.begin();
977 std::list< IDF_OUTLINE* >::iterator itE = outlines.end();
978
979 while( itS != itE )
980 {
981 writeOutline( aBoardFile, *itS, idx++ );
982 ++itS;
983 }
984}
985
986
988{
989 // note: although IDF_UNIT::UNIT_TNM is accepted here without reservation,
990 // this can only affect data being read from a file.
991 if( aUnit != IDF_UNIT::UNIT_MM && aUnit != IDF_UNIT::UNIT_THOU && aUnit != IDF_UNIT::UNIT_TNM )
992 {
993 ostringstream ostr;
994 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
995 ostr << "* BUG: invalid IDF UNIT: " << static_cast<int>( aUnit ) << "\n";
996 ostr << "* outline type: " << GetOutlineTypeString( outlineType );
997 errormsg = ostr.str();
998
999 return false;
1000 }
1001
1002 unit = aUnit;
1003 return true;
1004}
1005
1006
1008{
1009 return unit;
1010}
1011
1012
1013bool BOARD_OUTLINE::setThickness( double aThickness )
1014{
1015 if( aThickness < 0.0 )
1016 {
1017 ostringstream ostr;
1018 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
1019 ostr << "* BUG: aThickness < 0.0\n";
1020 ostr << "* outline type: " << GetOutlineTypeString( outlineType );
1021 errormsg = ostr.str();
1022
1023 return false;
1024 }
1025
1026 thickness = aThickness;
1027 return true;
1028}
1029
1030
1031bool BOARD_OUTLINE::SetThickness( double aThickness )
1032{
1033#ifndef DISABLE_IDF_OWNERSHIP
1034 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
1035 return false;
1036#endif
1037
1038 return setThickness( aThickness );
1039}
1040
1041
1043{
1044 return thickness;
1045}
1046
1047void BOARD_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHeader,
1048 IDF3::IDF_VERSION aIdfVersion )
1049{
1050 // BOARD_OUTLINE (PANEL_OUTLINE)
1051 // .BOARD_OUTLINE [OWNER]
1052 // [thickness]
1053 // [outlines]
1054
1055 // check RECORD 1
1056 std::string token;
1057 bool quoted = false;
1058 int idx = 0;
1059 std::streampos pos;
1060
1061 pos = aBoardFile.tellg();
1062
1063 if( !GetIDFString( aHeader, token, quoted, idx ) )
1064 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
1065 "invalid invocation: blank header line" ) );
1066
1067 if( quoted )
1068 {
1069 ostringstream ostr;
1070
1071 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1072 ostr << "* violation: section names may not be in quotes\n";
1073 ostr << "* line: '" << aHeader << "'\n";
1074 ostr << "* file position: " << pos;
1075
1076 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1077 }
1078
1079 if( !CompareToken( ".BOARD_OUTLINE", token ) )
1080 {
1081 ostringstream ostr;
1082
1083 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1084 ostr << "* violation: not a board outline\n";
1085 ostr << "* line: '" << aHeader << "'\n";
1086 ostr << "* file position: " << pos;
1087
1088 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1089 }
1090
1091 if( !GetIDFString( aHeader, token, quoted, idx ) )
1092 {
1093 if( aIdfVersion > IDF_VERSION::IDF_V2 )
1094 ERROR_IDF << "no OWNER; setting to UNOWNED\n";
1095
1097 }
1098 else
1099 {
1100 if( !ParseOwner( token, owner ) )
1101 {
1102 ERROR_IDF << "invalid OWNER (reverting to UNOWNED): " << token << "\n";
1104 }
1105 }
1106
1107 // check RECORD 2
1108 std::string iline;
1109 bool comment = false;
1110 while( aBoardFile.good() && !FetchIDFLine( aBoardFile, iline, comment, pos ) );
1111
1112 if( ( !aBoardFile.good() && !aBoardFile.eof() ) || iline.empty() )
1113 {
1114 ostringstream ostr;
1115
1116 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1117 ostr << "* violation: premature end\n";
1118 ostr << "* file position: " << pos;
1119
1120 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1121 }
1122
1123 idx = 0;
1124
1125 if( comment )
1126 {
1127 ostringstream ostr;
1128
1129 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1130 ostr << "* violation: comment within .BOARD_OUTLINE section\n";
1131 ostr << "* line: '" << iline << "'\n";
1132 ostr << "* file position: " << pos;
1133
1134 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1135 }
1136
1137 if( !GetIDFString( iline, token, quoted, idx ) )
1138 {
1139 ostringstream ostr;
1140
1141 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1142 ostr << "* violation: no thickness specified\n";
1143 ostr << "* file position: " << pos;
1144
1145 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1146 }
1147
1148 std::stringstream teststr;
1149 teststr << token;
1150
1151 teststr >> thickness;
1152
1153 if( teststr.fail() )
1154 {
1155 ostringstream ostr;
1156
1157 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1158 ostr << "* violation: invalid RECORD 2 (thickness)\n";
1159 ostr << "* line: '" << iline << "'\n";
1160 ostr << "* file position: " << pos;
1161
1162 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1163 }
1164
1165 if( unit == IDF_UNIT::UNIT_THOU )
1166 {
1168 }
1169 else if( ( aIdfVersion == IDF_VERSION::IDF_V2 ) && ( unit == IDF_UNIT::UNIT_TNM ) )
1170 {
1172 }
1173 else if( unit != IDF_UNIT::UNIT_MM )
1174 {
1175 ostringstream ostr;
1176 ostr << "\n* BUG: invalid UNIT type: " << static_cast<int>( unit );
1177
1178 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1179 }
1180
1181 // for some unknown reason IDF allows 0 or negative thickness, but this
1182 // is a problem so we fix it here
1183 if( thickness <= 0.0 )
1184 {
1185 if( thickness == 0.0 )
1186 {
1187 ERROR_IDF << "\n* WARNING: setting board thickness to default 1.6mm (";
1188 cerr << thickness << ")\n";
1189 thickness = 1.6;
1190 }
1191 else
1192 {
1194 ERROR_IDF << "\n* WARNING: setting board thickness to positive number (";
1195 cerr << thickness << ")\n";
1196 }
1197 }
1198
1199 // read RECORD 3 values
1200 readOutlines( aBoardFile, aIdfVersion );
1201
1202 // check RECORD 4
1203 while( aBoardFile.good() && !FetchIDFLine( aBoardFile, iline, comment, pos ) );
1204
1205 if( ( !aBoardFile.good() && aBoardFile.eof() ) || iline.empty() )
1206 {
1207 ostringstream ostr;
1208
1209 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1210 ostr << "* violation: premature end\n";
1211 ostr << "* file position: " << pos;
1212
1213 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1214 }
1215
1216 idx = 0;
1217
1218 if( comment )
1219 {
1220 ostringstream ostr;
1221
1222 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1223 ostr << "* violation: comment within section\n";
1224 ostr << "* line: '" << iline << "'\n";
1225 ostr << "* file position: " << pos;
1226
1227 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1228 }
1229
1230 if( !CompareToken( ".END_BOARD_OUTLINE", iline ) )
1231 {
1232 ostringstream ostr;
1233
1234 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1235 ostr << "* violation: no .END_BOARD_OUTLINE found\n";
1236 ostr << "* file position: " << pos;
1237
1238 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1239 }
1240}
1241
1242
1243void BOARD_OUTLINE::writeData( std::ostream& aBoardFile )
1244{
1245 writeComments( aBoardFile );
1246
1247 // note: a BOARD_OUTLINE section is required, even if it is empty
1248 aBoardFile << ".BOARD_OUTLINE ";
1249
1250 writeOwner( aBoardFile );
1251
1252 if( unit != IDF_UNIT::UNIT_THOU )
1253 aBoardFile << setiosflags( ios::fixed ) << setprecision( 5 ) << thickness << "\n";
1254 else
1255 aBoardFile << setiosflags( ios::fixed ) << setprecision( 1 )
1256 << ( thickness / IDF_THOU_TO_MM ) << "\n";
1257
1258 writeOutlines( aBoardFile );
1259
1260 aBoardFile << ".END_BOARD_OUTLINE\n\n";
1261}
1262
1264{
1265 comments.clear();
1266 clearOutlines();
1267
1269 return;
1270}
1271
1272
1274{
1275#ifndef DISABLE_IDF_OWNERSHIP
1276 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
1277 return false;
1278#endif
1279
1280 clear();
1281
1282 return true;
1283}
1284
1285
1287{
1288 parent = aParent;
1289}
1290
1291
1293{
1294 return parent;
1295}
1296
1297
1299{
1300 std::list< IDF_OUTLINE* >::iterator itS = outlines.begin();
1301 std::list< IDF_OUTLINE* >::iterator itE = outlines.end();
1302
1303 try
1304 {
1305 while( itS != itE )
1306 {
1307 if( *itS == aOutline )
1308 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
1309 "duplicate outline pointer" ) );
1310
1311 ++itS;
1312 }
1313
1314 outlines.push_back( aOutline );
1315
1316 }
1317 catch( const std::exception& e )
1318 {
1319 errormsg = e.what();
1320
1321 return false;
1322 }
1323
1324 return true;
1325}
1326
1327
1329{
1330#ifndef DISABLE_IDF_OWNERSHIP
1331 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
1332 return false;
1333#endif
1334
1335 return addOutline( aOutline );
1336}
1337
1338
1340{
1341 std::list< IDF_OUTLINE* >::iterator itS = outlines.begin();
1342 std::list< IDF_OUTLINE* >::iterator itE = outlines.end();
1343
1344 if( !aOutline )
1345 {
1346 ostringstream ostr;
1347 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
1348 ostr << "* BUG: nullptr aOutline pointer\n";
1349 ostr << "* outline type: " << GetOutlineTypeString( outlineType );
1350 errormsg = ostr.str();
1351
1352 return false;
1353 }
1354
1355 if( outlines.empty() )
1356 {
1357 errormsg.clear();
1358 return false;
1359 }
1360
1361 // if there are more than 1 outlines it makes no sense to delete
1362 // the first outline (board outline) since that would have the
1363 // undesirable effect of substituting a cutout outline as the board outline
1364 if( aOutline == outlines.front() )
1365 {
1366 if( outlines.size() > 1 )
1367 {
1368 ostringstream ostr;
1369 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
1370 ostr << "* BUG: attempting to delete first outline in list\n";
1371 ostr << "* outline type: " << GetOutlineTypeString( outlineType );
1372 errormsg = ostr.str();
1373
1374 return false;
1375 }
1376
1377 outlines.clear();
1378 return true;
1379 }
1380
1381 while( itS != itE )
1382 {
1383 if( *itS == aOutline )
1384 {
1385 outlines.erase( itS );
1386 return true;
1387 }
1388
1389 ++itS;
1390 }
1391
1392 errormsg.clear();
1393 return false;
1394}
1395
1396
1397bool BOARD_OUTLINE::DelOutline( size_t aIndex )
1398{
1399 std::list< IDF_OUTLINE* >::iterator itS = outlines.begin();
1400
1401 if( outlines.empty() )
1402 {
1403 errormsg.clear();
1404 return false;
1405 }
1406
1407 if( aIndex >= outlines.size() )
1408 {
1409 ostringstream ostr;
1410 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
1411 ostr << "* BUG: index out of bounds (" << aIndex << " / " << outlines.size() << ")\n";
1412 ostr << "* outline type: " << GetOutlineTypeString( outlineType );
1413 errormsg = ostr.str();
1414
1415 return false;
1416 }
1417
1418 if( aIndex == 0 )
1419 {
1420 // if there are more than 1 outlines it makes no sense to delete
1421 // the first outline (board outline) since that would have the
1422 // undesirable effect of substituting a cutout outline as the board outline
1423 if( outlines.size() > 1 )
1424 {
1425 ostringstream ostr;
1426 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
1427 ostr << "* BUG: attempting to delete first outline in list\n";
1428 ostr << "* outline type: " << GetOutlineTypeString( outlineType );
1429 errormsg = ostr.str();
1430
1431 return false;
1432 }
1433
1434 delete *itS;
1435 outlines.clear();
1436
1437 return true;
1438 }
1439
1440 for( ; aIndex > 0; --aIndex )
1441 ++itS;
1442
1443 delete *itS;
1444 outlines.erase( itS );
1445
1446 return true;
1447}
1448
1449
1450const std::list<IDF_OUTLINE*>* BOARD_OUTLINE::GetOutlines( void )
1451{
1452 return &outlines;
1453}
1454
1455
1457{
1458 return outlines.size();
1459}
1460
1461
1463{
1464 if( aIndex >= outlines.size() )
1465 {
1466 ostringstream ostr;
1467 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
1468 ostr << "* aIndex (" << aIndex << ") is out of range (" << outlines.size() << ")";
1469 errormsg = ostr.str();
1470
1471 return nullptr;
1472 }
1473
1474 std::list< IDF_OUTLINE* >::iterator itS = outlines.begin();
1475
1476 for( ; aIndex > 0; --aIndex )
1477 ++itS;
1478
1479 return *itS;
1480}
1481
1482
1484{
1485 return owner;
1486}
1487
1488
1490{
1491#ifndef DISABLE_IDF_OWNERSHIP
1492 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
1493 return false;
1494#endif
1495
1496 owner = aOwner;
1497 return true;
1498}
1499
1500
1502{
1503 return single;
1504}
1505
1506
1508{
1509 std::list< IDF_OUTLINE* >::iterator itS = outlines.begin();
1510 std::list< IDF_OUTLINE* >::iterator itE = outlines.end();
1511
1512 while( itS != itE )
1513 {
1514 delete *itS;
1515 ++itS;
1516 }
1517
1518 outlines.clear();
1519}
1520
1521
1522void BOARD_OUTLINE::AddComment( const std::string& aComment )
1523{
1524 if( aComment.empty() )
1525 return;
1526
1527 comments.push_back( aComment );
1528}
1529
1530
1532{
1533 return comments.size();
1534}
1535
1536
1537std::list< std::string >* BOARD_OUTLINE::GetComments( void )
1538{
1539 return &comments;
1540}
1541
1542
1543const std::string* BOARD_OUTLINE::GetComment( size_t aIndex )
1544{
1545 if( aIndex >= comments.size() )
1546 return nullptr;
1547
1548 std::list< std::string >::iterator itS = comments.begin();
1549
1550 for( ; aIndex > 0; --aIndex )
1551 ++itS;
1552
1553 return &(*itS);
1554}
1555
1556
1557bool BOARD_OUTLINE::DeleteComment( size_t aIndex )
1558{
1559 if( aIndex >= comments.size() )
1560 return false;
1561
1562 std::list< std::string >::iterator itS = comments.begin();
1563
1564 for( ; aIndex > 0; --aIndex )
1565 ++itS;
1566
1567 comments.erase( itS );
1568 return true;
1569}
1570
1571
1573{
1574 comments.clear();
1575}
1576
1577
1585
1586
1587bool OTHER_OUTLINE::SetOutlineIdentifier( const std::string& aUniqueID )
1588{
1589#ifndef DISABLE_IDF_OWNERSHIP
1590 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
1591 return false;
1592#endif
1593
1594 uniqueID = aUniqueID;
1595
1596 return true;
1597}
1598
1599
1600const std::string& OTHER_OUTLINE::GetOutlineIdentifier( void )
1601{
1602 return uniqueID;
1603}
1604
1605
1607{
1608#ifndef DISABLE_IDF_OWNERSHIP
1609 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
1610 return false;
1611#endif
1612
1613 switch( aSide )
1614 {
1615 case IDF_LAYER::LYR_TOP:
1617 side = aSide;
1618 break;
1619
1620 default:
1621 do
1622 {
1623 ostringstream ostr;
1624 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
1625 ostr << "* BUG: invalid side (" << static_cast<int>( aSide ) << "); must be one of TOP/BOTTOM\n";
1626 ostr << "* outline type: " << GetOutlineTypeString( outlineType );
1627 errormsg = ostr.str();
1628 } while( 0 );
1629
1631 return false;
1632
1633 break;
1634 }
1635
1636 return true;
1637}
1638
1639
1641{
1642 return side;
1643}
1644
1645
1646void OTHER_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHeader,
1647 IDF3::IDF_VERSION aIdfVersion )
1648{
1649 // OTHER_OUTLINE/VIA_KEEPOUT
1650 // .OTHER_OUTLINE [OWNER]
1651 // [outline identifier] [thickness] [board side: Top/Bot] {not present in VA\IA KEEPOUT}
1652 // [outline]
1653
1654 // check RECORD 1
1655 std::string token;
1656 bool quoted = false;
1657 int idx = 0;
1658 std::streampos pos = aBoardFile.tellg();
1659
1660 if( !GetIDFString( aHeader, token, quoted, idx ) )
1661 {
1662 ostringstream ostr;
1663 ostr << "\n* BUG: invalid invocation: blank header line\n";
1664
1665 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1666 }
1667
1668 if( quoted )
1669 {
1670 ostringstream ostr;
1671
1672 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1673 ostr << "* violation: section names must not be in quotes\n";
1674 ostr << "* line: '" << aHeader << "'\n";
1675 ostr << "* file position: " << pos;
1676
1677 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1678 }
1679
1681 {
1682 if( !CompareToken( ".OTHER_OUTLINE", token ) )
1683 {
1684 ostringstream ostr;
1685
1686 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1687 ostr << "* BUG: not an .OTHER outline\n";
1688
1689 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1690 }
1691 }
1692 else
1693 {
1694 if( !CompareToken( ".VIA_KEEPOUT", token ) )
1695 {
1696 ostringstream ostr;
1697
1698 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1699 ostr << "* BUG: not a .VIA_KEEPOUT outline\n";
1700
1701 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1702 }
1703 }
1704
1705 if( !GetIDFString( aHeader, token, quoted, idx ) )
1706 {
1707 if( aIdfVersion > IDF_VERSION::IDF_V2 )
1708 ERROR_IDF << "no OWNER; setting to UNOWNED\n";
1709
1711 }
1712 else
1713 {
1714 if( !ParseOwner( token, owner ) )
1715 {
1716 ERROR_IDF << "invalid OWNER (reverting to UNOWNED): " << token << "\n";
1718 }
1719 }
1720
1721 std::string iline;
1722 bool comment = false;
1723
1725 {
1726 // check RECORD 2
1727 // [outline identifier] [thickness] [board side: Top/Bot]
1728 while( aBoardFile.good() && !FetchIDFLine( aBoardFile, iline, comment, pos ) );
1729
1730 if( ( !aBoardFile.good() && aBoardFile.eof() ) || iline.empty() )
1731 {
1732 ostringstream ostr;
1733
1734 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1735 ostr << "* violation: premature end\n";
1736 ostr << "* file position: " << pos;
1737
1738 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1739 }
1740
1741 idx = 0;
1742 if( comment )
1743 {
1744 ostringstream ostr;
1745
1746 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1747 ostr << "* violation: comment within .OTHER_OUTLINE section\n";
1748 ostr << "* line: '" << iline << "'\n";
1749 ostr << "* file position: " << pos;
1750
1751 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1752 }
1753
1754 if( !GetIDFString( iline, token, quoted, idx ) )
1755 {
1756 ostringstream ostr;
1757
1758 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1759 ostr << "* violation: no outline identifier\n";
1760 ostr << "* line: '" << iline << "'\n";
1761 ostr << "* file position: " << pos;
1762
1763 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1764 }
1765
1766 uniqueID = token;
1767
1768 if( !GetIDFString( iline, token, quoted, idx ) )
1769 {
1770 ostringstream ostr;
1771
1772 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1773 ostr << "* violation: no thickness\n";
1774 ostr << "* line: '" << iline << "'\n";
1775 ostr << "* file position: " << pos;
1776
1777 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1778 }
1779
1780 std::stringstream teststr;
1781 teststr << token;
1782
1783 teststr >> thickness;
1784
1785 if( teststr.fail() )
1786 {
1787 ostringstream ostr;
1788
1789 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1790 ostr << "* violation: invalid thickness\n";
1791 ostr << "* line: '" << iline << "'\n";
1792 ostr << "* file position: " << pos;
1793
1794 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1795 }
1796
1797 if( unit == IDF_UNIT::UNIT_THOU )
1798 {
1800 }
1801 else if( ( aIdfVersion == IDF_VERSION::IDF_V2 ) && ( unit == IDF_UNIT::UNIT_TNM ) )
1802 {
1804 }
1805 else if( unit != IDF_UNIT::UNIT_MM )
1806 {
1807 ostringstream ostr;
1808 ostr << "\n* BUG: invalid UNIT type: " << static_cast<int>( unit );
1809
1810 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1811 }
1812
1813 if( aIdfVersion == IDF_VERSION::IDF_V2 )
1814 {
1816 }
1817 else
1818 {
1819 if( !GetIDFString( iline, token, quoted, idx ) )
1820 {
1821 ostringstream ostr;
1822
1823 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1824 ostr << "* violation: no board side\n";
1825 ostr << "* line: '" << iline << "'\n";
1826 ostr << "* file position: " << pos;
1827
1828 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1829 }
1830
1831 if( !ParseIDFLayer( token, side ) || ( side != IDF_LAYER::LYR_TOP && side != IDF_LAYER::LYR_BOTTOM ) )
1832 {
1833 ostringstream ostr;
1834
1835 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1836 ostr << "* violation: invalid side (must be TOP or BOTTOM only)\n";
1837 ostr << "* line: '" << iline << "'\n";
1838 ostr << "* file position: " << pos;
1839
1840 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1841 }
1842 }
1843
1844 }
1845
1846 // read RECORD 3 values
1847 readOutlines( aBoardFile, aIdfVersion );
1848
1849 // check RECORD 4
1850 while( aBoardFile.good() && !FetchIDFLine( aBoardFile, iline, comment, pos ) );
1851
1852 if( ( !aBoardFile.good() && aBoardFile.eof() ) || iline.empty() )
1853 {
1854 ostringstream ostr;
1855
1856 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1857 ostr << "* violation: premature end\n";
1858 ostr << "* file position: " << pos;
1859
1860 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1861 }
1862
1863 idx = 0;
1864
1865 if( comment )
1866 {
1867 ostringstream ostr;
1868
1869 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1870 ostr << "* violation: comment within section\n";
1871 ostr << "* line: '" << iline << "'\n";
1872 ostr << "* file position: " << pos;
1873
1874 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1875 }
1876
1878 {
1879 if( !CompareToken( ".END_OTHER_OUTLINE", iline ) )
1880 {
1881 ostringstream ostr;
1882
1883 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1884 ostr << "* violation: no .END_OTHER_OUTLINE found\n";
1885 ostr << "* file position: " << pos;
1886
1887 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1888 }
1889 }
1890 else
1891 {
1892 if( !CompareToken( ".END_VIA_KEEPOUT", iline ) )
1893 {
1894 ostringstream ostr;
1895
1896 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
1897 ostr << "* violation: no .END_VIA_KEEPOUT found\n";
1898 ostr << "* file position: " << pos;
1899
1900 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1901 }
1902 }
1903}
1904
1905
1906void OTHER_OUTLINE::writeData( std::ostream& aBoardFile )
1907{
1908 // this section is optional; do not write if not required
1909 if( outlines.empty() )
1910 return;
1911
1912 writeComments( aBoardFile );
1913
1914 // write RECORD 1
1916 aBoardFile << ".OTHER_OUTLINE ";
1917 else
1918 aBoardFile << ".VIA_KEEPOUT ";
1919
1920 writeOwner( aBoardFile );
1921
1922 // write RECORD 2
1924 {
1925 aBoardFile << "\"" << EscapeString( uniqueID, CTX_QUOTED_STR ) << "\" ";
1926
1927 if( unit != IDF_UNIT::UNIT_THOU )
1928 aBoardFile << setiosflags( ios::fixed ) << setprecision( 5 ) << thickness << " ";
1929 else
1930 aBoardFile << setiosflags( ios::fixed ) << setprecision( 1 )
1931 << ( thickness / IDF_THOU_TO_MM ) << " ";
1932
1933 switch( side )
1934 {
1935 case IDF_LAYER::LYR_TOP:
1937 WriteLayersText( aBoardFile, side );
1938 break;
1939
1940 default:
1941 do
1942 {
1943 ostringstream ostr;
1944 ostr << "\n* invalid OTHER_OUTLINE side (neither top nor bottom): ";
1945 ostr << static_cast<int>( side );
1946 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
1947 } while( 0 );
1948
1949 break;
1950 }
1951 }
1952
1953 // write RECORD 3
1954 writeOutlines( aBoardFile );
1955
1956 // write RECORD 4
1958 aBoardFile << ".END_OTHER_OUTLINE\n\n";
1959 else
1960 aBoardFile << ".END_VIA_KEEPOUT\n\n";
1961}
1962
1963
1965{
1966#ifndef DISABLE_IDF_OWNERSHIP
1967 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
1968 return false;
1969#endif
1970
1971 clear();
1973 uniqueID.clear();
1974
1975 return true;
1976}
1977
1978
1986
1987
1989{
1990#ifndef DISABLE_IDF_OWNERSHIP
1991 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
1992 return false;
1993#endif
1994
1995 layers = aLayer;
1996
1997 return true;
1998}
1999
2000
2002{
2003 return layers;
2004}
2005
2006
2007void ROUTE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHeader,
2008 IDF3::IDF_VERSION aIdfVersion )
2009{
2010 // ROUTE_OUTLINE (or ROUTE_KEEPOUT)
2011 // .ROUTE_OUTLINE [OWNER]
2012 // [layers]
2013 // [outline]
2014
2015 // check RECORD 1
2016 std::string token;
2017 bool quoted = false;
2018 int idx = 0;
2019 std::streampos pos = aBoardFile.tellg();
2020
2021 if( !GetIDFString( aHeader, token, quoted, idx ) )
2022 {
2023 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
2024 "\n* BUG: invalid invocation; blank header line" ) );
2025 }
2026
2027 if( quoted )
2028 {
2029 ostringstream ostr;
2030
2031 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2032 ostr << "* violation: section names must not be in quotes\n";
2033 ostr << "* line: '" << aHeader << "'\n";
2034 ostr << "* file position: " << pos;
2035
2036 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2037 }
2038
2040 {
2041 if( !CompareToken( ".ROUTE_OUTLINE", token ) )
2042 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
2043 "\n* BUG: not a ROUTE outline" ) );
2044 }
2045 else
2046 {
2047 if( !CompareToken( ".ROUTE_KEEPOUT", token ) )
2048 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
2049 "\n* BUG: not a ROUTE KEEPOUT outline" ) );
2050 }
2051
2052 if( !GetIDFString( aHeader, token, quoted, idx ) )
2053 {
2054 if( aIdfVersion > IDF_VERSION::IDF_V2 )
2055 ERROR_IDF << "no OWNER; setting to UNOWNED\n";
2056
2058 }
2059 else
2060 {
2061 if( !ParseOwner( token, owner ) )
2062 {
2063 ERROR_IDF << "invalid OWNER (reverting to UNOWNED): " << token << "\n";
2065 }
2066 }
2067
2068 // check RECORD 2
2069 // [layers: TOP, BOTTOM, BOTH, INNER, ALL]
2070 std::string iline;
2071 bool comment = false;
2072
2074 {
2075 while( aBoardFile.good() && !FetchIDFLine( aBoardFile, iline, comment, pos ) );
2076
2077 if( !aBoardFile.good() )
2078 {
2079 ostringstream ostr;
2080
2081 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2082 ostr << "* violation: premature end\n";
2083 ostr << "* file position: " << pos;
2084
2085 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2086 }
2087
2088 idx = 0;
2089
2090 if( comment )
2091 {
2092 ostringstream ostr;
2093
2094 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2095 ostr << "* violation: comment within a section\n";
2096 ostr << "* line: '" << iline << "'\n";
2097 ostr << "* file position: " << pos;
2098
2099 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2100 }
2101
2102 if( !GetIDFString( iline, token, quoted, idx ) )
2103 {
2104 ostringstream ostr;
2105
2106 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2107 ostr << "* violation: no layers specification\n";
2108 ostr << "* line: '" << iline << "'\n";
2109 ostr << "* file position: " << pos;
2110
2111 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2112 }
2113
2114 if( quoted )
2115 {
2116 ostringstream ostr;
2117
2118 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2119 ostr << "* violation: layers specification must not be in quotes\n";
2120 ostr << "* line: '" << iline << "'\n";
2121 ostr << "* file position: " << pos;
2122
2123 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2124 }
2125
2126 if( !ParseIDFLayer( token, layers ) )
2127 {
2128 ostringstream ostr;
2129
2130 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2131 ostr << "* violation: invalid layers specification\n";
2132 ostr << "* line: '" << iline << "'\n";
2133 ostr << "* file position: " << pos;
2134
2135 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2136 }
2137
2138 if( aIdfVersion == IDF_VERSION::IDF_V2 )
2139 {
2141 {
2142 ostringstream ostr;
2143
2144 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2145 ostr << "* violation: IDFv2 allows only TOP/BOTTOM/BOTH; layer was '";
2146 ostr << token << "'\n";
2147 ostr << "* line: '" << iline << "'\n";
2148 ostr << "* file position: " << pos;
2149
2150 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2151 }
2152 }
2153 }
2154 else
2155 {
2157 }
2158
2159 // read RECORD 3 values
2160 readOutlines( aBoardFile, aIdfVersion );
2161
2162 // check RECORD 4
2163 while( aBoardFile.good() && !FetchIDFLine( aBoardFile, iline, comment, pos ) );
2164
2165 if( ( !aBoardFile.good() && aBoardFile.eof() ) || iline.empty() )
2166 {
2167 ostringstream ostr;
2168
2169 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2170 ostr << "* violation: premature end\n";
2171 ostr << "* file position: " << pos;
2172
2173 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2174 }
2175
2176 idx = 0;
2177
2178 if( comment )
2179 {
2180 ostringstream ostr;
2181
2182 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2183 ostr << "* violation: comment within section\n";
2184 ostr << "* line: '" << iline << "'\n";
2185 ostr << "* file position: " << pos;
2186
2187 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2188 }
2189
2191 {
2192 if( !CompareToken( ".END_ROUTE_OUTLINE", iline ) )
2193 {
2194 ostringstream ostr;
2195
2196 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2197 ostr << "* violation: no .END_ROUTE_OUTLINE found\n";
2198 ostr << "* file position: " << pos;
2199
2200 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2201 }
2202 }
2203 else
2204 {
2205 if( !CompareToken( ".END_ROUTE_KEEPOUT", iline ) )
2206 {
2207 ostringstream ostr;
2208
2209 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2210 ostr << "* violation: no .END_ROUTE_KEEPOUT found\n";
2211 ostr << "* file position: " << pos;
2212
2213 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2214 }
2215 }
2216}
2217
2218
2219void ROUTE_OUTLINE::writeData( std::ostream& aBoardFile )
2220{
2221 // this section is optional; do not write if not required
2222 if( outlines.empty() )
2223 return;
2224
2226 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
2227 "layer not specified" ) );
2228
2229 writeComments( aBoardFile );
2230
2231 // write RECORD 1
2233 aBoardFile << ".ROUTE_OUTLINE ";
2234 else
2235 aBoardFile << ".ROUTE_KEEPOUT ";
2236
2237 writeOwner( aBoardFile );
2238
2239 // write RECORD 2
2240 WriteLayersText( aBoardFile, layers );
2241 aBoardFile << "\n";
2242
2243 // write RECORD 3
2244 writeOutlines( aBoardFile );
2245
2246 // write RECORD 4
2248 aBoardFile << ".END_ROUTE_OUTLINE\n\n";
2249 else
2250 aBoardFile << ".END_ROUTE_KEEPOUT\n\n";
2251}
2252
2253
2255{
2256#ifndef DISABLE_IDF_OWNERSHIP
2257 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
2258 return false;
2259#endif
2260
2261 clear();
2263
2264 return true;
2265}
2266
2267
2269{
2270 setParent( aParent );
2272 single = true;
2273 thickness = -1.0;
2275}
2276
2277
2279{
2280#ifndef DISABLE_IDF_OWNERSHIP
2281 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
2282 return false;
2283#endif
2284
2285 switch( aSide )
2286 {
2287 case IDF_LAYER::LYR_TOP:
2290 side = aSide;
2291 break;
2292
2293 default:
2294 do
2295 {
2297 ostringstream ostr;
2298 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
2299 ostr << "* BUG: invalid layer (" << static_cast<int>( aSide ) << "): must be one of TOP/BOTTOM/BOTH\n";
2300 ostr << "* outline type: " << GetOutlineTypeString( outlineType );
2301 errormsg = ostr.str();
2302
2303 return false;
2304 } while( 0 );
2305
2306 break;
2307 }
2308
2309 return true;
2310}
2311
2312
2314{
2315 return side;
2316}
2317
2318
2319bool PLACE_OUTLINE::SetMaxHeight( double aHeight )
2320{
2321#ifndef DISABLE_IDF_OWNERSHIP
2322 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
2323 return false;
2324#endif
2325
2326 if( aHeight < 0.0 )
2327 {
2328 thickness = 0.0;
2329
2330 do
2331 {
2332 ostringstream ostr;
2333 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
2334 ostr << "* BUG: invalid height (" << aHeight << "): must be >= 0.0";
2335 ostr << "* outline type: " << GetOutlineTypeString( outlineType );
2336 errormsg = ostr.str();
2337
2338 return false;
2339 } while( 0 );
2340 }
2341
2342 thickness = aHeight;
2343 return true;
2344}
2345
2346
2348{
2349 return thickness;
2350}
2351
2352
2353void PLACE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHeader,
2354 IDF3::IDF_VERSION aIdfVersion )
2355{
2356 // PLACE_OUTLINE/KEEPOUT
2357 // .PLACE_OUTLINE [OWNER]
2358 // [board side: Top/Bot/Both] [height]
2359 // [outline]
2360
2361 // check RECORD 1
2362 std::string token;
2363 bool quoted = false;
2364 int idx = 0;
2365 std::streampos pos = aBoardFile.tellg();
2366
2367 if( !GetIDFString( aHeader, token, quoted, idx ) )
2368 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
2369 "\n* BUG: invalid invocation: blank header line\n" ) );
2370
2371 if( quoted )
2372 {
2373 ostringstream ostr;
2374
2375 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2376 ostr << "* violation: section name must not be in quotes\n";
2377 ostr << "* line: '" << aHeader << "'\n";
2378 ostr << "* file position: " << pos;
2379
2380 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2381 }
2382
2384 {
2385 if( !CompareToken( ".PLACE_OUTLINE", token ) )
2386 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
2387 "\n* BUG: not a .PLACE_OUTLINE" ) );
2388 }
2389 else
2390 {
2391 if( !CompareToken( ".PLACE_KEEPOUT", token ) )
2392 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
2393 "\n* BUG: not a .PLACE_KEEPOUT" ) );
2394 }
2395
2396 if( !GetIDFString( aHeader, token, quoted, idx ) )
2397 {
2398 if( aIdfVersion > IDF_VERSION::IDF_V2 )
2399 ERROR_IDF << "no OWNER; setting to UNOWNED\n";
2400
2402 }
2403 else
2404 {
2405 if( !ParseOwner( token, owner ) )
2406 {
2407 ERROR_IDF << "invalid OWNER (reverting to UNOWNED): " << token << "\n";
2409 }
2410 }
2411
2412 // check RECORD 2
2413 // [board side: Top/Bot/Both] [height]
2414 std::string iline;
2415 bool comment = false;
2416
2418 {
2419 while( aBoardFile.good() && !FetchIDFLine( aBoardFile, iline, comment, pos ) );
2420
2421 if( !aBoardFile.good() )
2422 {
2423 ostringstream ostr;
2424
2425 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2426 ostr << "* violation: premature end\n";
2427 ostr << "* file position: " << pos;
2428
2429 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2430 }
2431
2432 idx = 0;
2433
2434 if( comment )
2435 {
2436 ostringstream ostr;
2437
2438 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2439 ostr << "* violation: comment within the section\n";
2440 ostr << "* line: '" << iline << "'\n";
2441 ostr << "* file position: " << pos;
2442
2443 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2444 }
2445
2446 if( !GetIDFString( iline, token, quoted, idx ) )
2447 {
2448 ostringstream ostr;
2449
2450 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2451 ostr << "* violation: no board side information\n";
2452 ostr << "* line: '" << iline << "'\n";
2453 ostr << "* file position: " << pos;
2454
2455 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2456 }
2457
2458 if( !ParseIDFLayer( token, side ) ||
2460 {
2461 ostringstream ostr;
2462
2463 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2464 ostr << "* violation: invalid board side: must be one of TOP/BOTTOM/BOTH\n";
2465 ostr << "* line: '" << iline << "'\n";
2466 ostr << "* file position: " << pos;
2467
2468 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2469 }
2470
2471 if( GetIDFString( iline, token, quoted, idx ) )
2472 {
2473 std::stringstream teststr;
2474 teststr << token;
2475
2476 teststr >> thickness;
2477
2478 if( teststr.fail() )
2479 {
2480 ostringstream ostr;
2481
2482 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2483 ostr << "* violation: invalid height\n";
2484 ostr << "* line: '" << iline << "'\n";
2485 ostr << "* file position: " << pos;
2486
2487 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2488 }
2489
2490 if( thickness < 0.0 )
2491 {
2492 ostringstream ostr;
2493
2494 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2495 ostr << "* violation: thickness < 0\n";
2496 ostr << "* line: '" << iline << "'\n";
2497 ostr << "* file position: " << pos;
2498
2499 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2500 }
2501
2502 if( unit == IDF_UNIT::UNIT_THOU )
2503 {
2505 }
2506 else if( ( aIdfVersion == IDF_VERSION::IDF_V2 ) && ( unit == IDF_UNIT::UNIT_TNM ) )
2507 {
2509 }
2510 else if( unit != IDF_UNIT::UNIT_MM )
2511 {
2512 ostringstream ostr;
2513 ostr << "\n* BUG: invalid UNIT type: " << static_cast<int>( unit );
2514
2515 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2516 }
2517
2518 if( thickness < 0.0 )
2519 thickness = 0.0;
2520 }
2521 else
2522 {
2523 // for OUTLINE_TYPE::OTLN_PLACE, thickness may be omitted, but is required for OUTLINE_TYPE::OTLN_PLACE_KEEPOUT
2525 {
2526 ostringstream ostr;
2527
2528 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2529 ostr << "* violation: missing thickness\n";
2530 ostr << "* line: '" << iline << "'\n";
2531 ostr << "* file position: " << pos;
2532
2533 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2534 }
2535
2536 thickness = -1.0;
2537 }
2538 }
2539 else
2540 {
2542 thickness = 0.0;
2543 }
2544
2545 // read RECORD 3 values
2546 readOutlines( aBoardFile, aIdfVersion );
2547
2548 // check RECORD 4
2549 while( aBoardFile.good() && !FetchIDFLine( aBoardFile, iline, comment, pos ) );
2550
2551 if( ( !aBoardFile.good() && aBoardFile.eof() ) || iline.empty() )
2552 {
2553 ostringstream ostr;
2554
2555 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2556 ostr << "* violation: premature end\n";
2557 ostr << "* file position: " << pos;
2558
2559 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2560 }
2561
2562 idx = 0;
2563
2564 if( comment )
2565 {
2566 ostringstream ostr;
2567
2568 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2569 ostr << "* violation: comment within section\n";
2570 ostr << "* line: '" << iline << "'\n";
2571 ostr << "* file position: " << pos;
2572
2573 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2574 }
2575
2577 {
2578 if( !GetIDFString( iline, token, quoted, idx )
2579 || !CompareToken( ".END_PLACE_OUTLINE", token ) )
2580 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
2581 "invalid .PLACE_OUTLINE section: no .END_PLACE_OUTLINE found" ) );
2582 }
2583 else
2584 {
2585 if( !GetIDFString( iline, token, quoted, idx )
2586 || !CompareToken( ".END_PLACE_KEEPOUT", token ) )
2587 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
2588 "invalid .PLACE_KEEPOUT section: no .END_PLACE_KEEPOUT found" ) );
2589 }
2590}
2591
2592
2593void PLACE_OUTLINE::writeData( std::ostream& aBoardFile )
2594{
2595 // this section is optional; do not write if not required
2596 if( outlines.empty() )
2597 return;
2598
2599 writeComments( aBoardFile );
2600
2601 // write RECORD 1
2603 aBoardFile << ".PLACE_OUTLINE ";
2604 else
2605 aBoardFile << ".PLACE_KEEPOUT ";
2606
2607 writeOwner( aBoardFile );
2608
2609 // write RECORD 2
2610 switch( side )
2611 {
2612 case IDF_LAYER::LYR_TOP:
2615 WriteLayersText( aBoardFile, side );
2616 break;
2617
2618 default:
2619 do
2620 {
2621 ostringstream ostr;
2622 ostr << "\n* invalid PLACE_OUTLINE/KEEPOUT side (";
2623 ostr << static_cast<int>( side ) << "); must be one of TOP/BOTTOM/BOTH";
2624 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2625 } while( 0 );
2626
2627 break;
2628 }
2629
2630 // thickness is optional for OUTLINE_TYPE::OTLN_PLACE, but mandatory for OUTLINE_TYPE::OTLN_PLACE_KEEPOUT
2632 {
2633 aBoardFile << "\n";
2634 }
2635 else
2636 {
2637 aBoardFile << " ";
2638
2639 if( unit != IDF_UNIT::UNIT_THOU )
2640 aBoardFile << setiosflags( ios::fixed ) << setprecision( 5 ) << thickness << "\n";
2641 else
2642 aBoardFile << setiosflags( ios::fixed ) << setprecision( 1 )
2643 << ( thickness / IDF_THOU_TO_MM ) << "\n";
2644 }
2645
2646 // write RECORD 3
2647 writeOutlines( aBoardFile );
2648
2649 // write RECORD 4
2651 aBoardFile << ".END_PLACE_OUTLINE\n\n";
2652 else
2653 aBoardFile << ".END_PLACE_KEEPOUT\n\n";
2654
2655 return;
2656}
2657
2658
2660{
2661#ifndef DISABLE_IDF_OWNERSHIP
2662 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
2663 return false;
2664#endif
2665
2666 clear();
2667 thickness = 0.0;
2669
2670 return true;
2671}
2672
2673
2680
2681
2688
2689
2696
2697
2699{
2700 setParent( aParent );
2702 thickness = 0.0;
2704 single = true;
2705 return;
2706}
2707
2708
2710{
2711#ifndef DISABLE_IDF_OWNERSHIP
2712 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
2713 return false;
2714#endif
2715
2716 switch( aSide )
2717 {
2718 case IDF_LAYER::LYR_TOP:
2721 side = aSide;
2722 break;
2723
2724 default:
2725 do
2726 {
2727 ostringstream ostr;
2728 ostr << "invalid side (" << static_cast<int>( aSide ) << "); must be one of TOP/BOTTOM/BOTH\n";
2729 ostr << "* outline type: " << GetOutlineTypeString( outlineType );
2730 errormsg = ostr.str();
2731
2732 return false;
2733 } while( 0 );
2734
2735 break;
2736 }
2737
2738 return true;
2739}
2740
2741
2743{
2744 return side;
2745}
2746
2747
2748bool GROUP_OUTLINE::SetGroupName( std::string aGroupName )
2749{
2750#ifndef DISABLE_IDF_OWNERSHIP
2751 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
2752 return false;
2753#endif
2754
2755 groupName = std::move( aGroupName );
2756
2757 return true;
2758}
2759
2760
2761const std::string& GROUP_OUTLINE::GetGroupName( void )
2762{
2763 return groupName;
2764}
2765
2766
2767void GROUP_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHeader,
2768 IDF3::IDF_VERSION aIdfVersion )
2769{
2770 // Placement Group
2771 // .PLACE_REGION [OWNER]
2772 // [side: Top/Bot/Both ] [component group name]
2773 // [outline]
2774
2775 // check RECORD 1
2776 std::string token;
2777 bool quoted = false;
2778 int idx = 0;
2779 std::streampos pos = aBoardFile.tellg();
2780
2781 if( !GetIDFString( aHeader, token, quoted, idx ) )
2782 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
2783 "\n* BUG: invalid invocation: blank header line" ) );
2784
2785 if( quoted )
2786 {
2787 ostringstream ostr;
2788
2789 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2790 ostr << "* violation: section name must not be in quotes\n";
2791 ostr << "* line: '" << aHeader << "'\n";
2792 ostr << "* file position: " << pos;
2793
2794 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2795 }
2796
2797 if( !CompareToken( ".PLACE_REGION", token ) )
2798 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "\n* BUG: not a .PLACE_REGION" ) );
2799
2800 if( !GetIDFString( aHeader, token, quoted, idx ) )
2801 {
2802 if( aIdfVersion > IDF_VERSION::IDF_V2 )
2803 ERROR_IDF << "no OWNER; setting to UNOWNED\n";
2804
2806 }
2807 else
2808 {
2809 if( !ParseOwner( token, owner ) )
2810 {
2811 ERROR_IDF << "invalid OWNER (reverting to UNOWNED): " << token << "\n";
2813 }
2814 }
2815
2816 std::string iline;
2817 bool comment = false;
2818
2819 // check RECORD 2
2820 // [side: Top/Bot/Both ] [component group name]
2821 while( aBoardFile.good() && !FetchIDFLine( aBoardFile, iline, comment, pos ) );
2822
2823 if( !aBoardFile.good() )
2824 {
2825 ostringstream ostr;
2826
2827 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2828 ostr << "* violation: premature end\n";
2829 ostr << "* file position: " << pos;
2830
2831 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2832 }
2833
2834 idx = 0;
2835
2836 if( comment )
2837 {
2838 ostringstream ostr;
2839
2840 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2841 ostr << "* violation: comment within section\n";
2842 ostr << "* line: '" << iline << "'\n";
2843 ostr << "* file position: " << pos;
2844
2845 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2846 }
2847
2848 if( !GetIDFString( iline, token, quoted, idx ) )
2849 {
2850 ostringstream ostr;
2851
2852 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2853 ostr << "* violation: no board side specified\n";
2854 ostr << "* line: '" << iline << "'\n";
2855 ostr << "* file position: " << pos;
2856
2857 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2858 }
2859
2860 if( !ParseIDFLayer( token, side ) ||
2862 {
2863 ostringstream ostr;
2864
2865 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2866 ostr << "* violation: invalid board side, must be one of TOP/BOTTOM/BOTH\n";
2867 ostr << "* line: '" << iline << "'\n";
2868 ostr << "* file position: " << pos;
2869
2870 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2871 }
2872
2873 if( !GetIDFString( iline, token, quoted, idx ) )
2874 {
2875 ostringstream ostr;
2876
2877 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2878 ostr << "* violation: no outline identifier\n";
2879 ostr << "* line: '" << iline << "'\n";
2880 ostr << "* file position: " << pos;
2881
2882 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2883 }
2884
2885 groupName = token;
2886
2887 // read RECORD 3 values
2888 readOutlines( aBoardFile, aIdfVersion );
2889
2890 // check RECORD 4
2891 while( aBoardFile.good() && !FetchIDFLine( aBoardFile, iline, comment, pos ) );
2892
2893 if( ( !aBoardFile.good() && aBoardFile.eof() ) || iline.empty() )
2894 {
2895 ostringstream ostr;
2896
2897 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2898 ostr << "* violation: premature end\n";
2899 ostr << "* file position: " << pos;
2900
2901 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2902 }
2903
2904 idx = 0;
2905
2906 if( comment )
2907 {
2908 ostringstream ostr;
2909
2910 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
2911 ostr << "* violation: comment within section\n";
2912 ostr << "* line: '" << iline << "'\n";
2913 ostr << "* file position: " << pos;
2914
2915 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2916 }
2917
2918 if( !GetIDFString( iline, token, quoted, idx ) || !CompareToken( ".END_PLACE_REGION", token ) )
2919 {
2920 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
2921 "\n* invalid .PLACE_REGION section: no .END_PLACE_REGION found" ) );
2922 }
2923}
2924
2925
2926void GROUP_OUTLINE::writeData( std::ostream& aBoardFile )
2927{
2928 // this section is optional; do not write if not required
2929 if( outlines.empty() )
2930 return;
2931
2932 writeComments( aBoardFile );
2933
2934 // write RECORD 1
2935 aBoardFile << ".PLACE_REGION ";
2936
2937 writeOwner( aBoardFile );
2938
2939 // write RECORD 2
2940 switch( side )
2941 {
2942 case IDF_LAYER::LYR_TOP:
2945 WriteLayersText( aBoardFile, side );
2946 break;
2947
2948 default:
2949 do
2950 {
2951 ostringstream ostr;
2952 ostr << "\n* invalid PLACE_REGION side (must be TOP/BOTTOM/BOTH): ";
2953 ostr << static_cast<int>( side );
2954
2955 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
2956 } while( 0 );
2957
2958 break;
2959 }
2960
2961 aBoardFile << " \"" << EscapeString( groupName, CTX_QUOTED_STR ) << "\"\n";
2962
2963 // write RECORD 3
2964 writeOutlines( aBoardFile );
2965
2966 // write RECORD 4
2967 aBoardFile << ".END_PLACE_REGION\n\n";
2968}
2969
2970
2972{
2973#ifndef DISABLE_IDF_OWNERSHIP
2974 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
2975 return false;
2976#endif
2977
2978 clear();
2979 thickness = 0.0;
2981 groupName.clear();
2982
2983 return true;
2984}
2985
2986
2988{
2989 setParent( aParent );
2990 single = true;
2993 refNum = 0;
2994 return;
2995}
2996
2997
2998void IDF3_COMP_OUTLINE::readProperties( std::istream& aLibFile )
2999{
3000 bool quoted = false;
3001 bool comment = false;
3002 std::string iline;
3003 std::string token;
3004 std::streampos pos;
3005 std::string pname; // property name
3006 std::string pval; // property value
3007 int idx = 0;
3008
3009 while( aLibFile.good() )
3010 {
3011 if( !FetchIDFLine( aLibFile, iline, comment, pos ) )
3012 continue;
3013
3014 idx = 0;
3015
3016 if( comment )
3017 {
3018 ostringstream ostr;
3019
3020 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3021 ostr << "* violation: comment within section\n";
3022 ostr << "* line: '" << iline << "'\n";
3023 ostr << "* file position: " << pos;
3024
3025 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3026 }
3027
3028 if( !GetIDFString( iline, token, quoted, idx ) )
3029 {
3030 ostringstream ostr;
3031
3032 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3033 ostr << "* violation: bad property section (no PROP)\n";
3034 ostr << "* line: '" << iline << "'\n";
3035 ostr << "* file position: " << pos;
3036
3037 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3038 }
3039
3040 if( quoted )
3041 {
3042 ostringstream ostr;
3043
3044 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3045 ostr << "* violation: PROP or .END must not be quoted\n";
3046 ostr << "* line: '" << iline << "'\n";
3047 ostr << "* file position: " << pos;
3048
3049 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3050 }
3051
3052 if( token.size() >= 5 && CompareToken( ".END_", token.substr( 0, 5 ) ) )
3053 {
3054 if(aLibFile.eof())
3055 aLibFile.clear();
3056
3057 aLibFile.seekg( pos );
3058 return;
3059 }
3060
3061 if( !CompareToken( "PROP", token ) )
3062 {
3063 ostringstream ostr;
3064
3065 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3066 ostr << "* violation: expecting PROP or .END_ELECTRICAL\n";
3067 ostr << "* line: '" << iline << "'\n";
3068 ostr << "* file position: " << pos;
3069
3070 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3071 }
3072
3073 if( !GetIDFString( iline, token, quoted, idx ) )
3074 {
3075 ostringstream ostr;
3076
3077 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3078 ostr << "* violation: no PROP name\n";
3079 ostr << "* line: '" << iline << "'\n";
3080 ostr << "* file position: " << pos;
3081
3082 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3083 }
3084
3085 pname = token;
3086
3087 if( !GetIDFString( iline, token, quoted, idx ) )
3088 {
3089 ostringstream ostr;
3090
3091 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3092 ostr << "* violation: no PROP value\n";
3093 ostr << "* line: '" << iline << "'\n";
3094 ostr << "* file position: " << pos;
3095
3096 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3097 }
3098
3099 pval = token;
3100
3101 if( props.insert( pair< string, string >(pname, pval) ).second == false )
3102 {
3103 ostringstream ostr;
3104
3105 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3106 ostr << "* violation: duplicate property name \"" << EscapeString( pname, CTX_QUOTED_STR ) << "\"\n";
3107 ostr << "* line: '" << iline << "'\n";
3108 ostr << "* file position: " << pos;
3109
3110 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3111 }
3112 }
3113}
3114
3115
3116bool IDF3_COMP_OUTLINE::writeProperties( std::ostream& aLibFile )
3117{
3118 if( props.empty() )
3119 return true;
3120
3121 std::map< std::string, std::string >::const_iterator itS = props.begin();
3122 std::map< std::string, std::string >::const_iterator itE = props.end();
3123
3124 while( itS != itE )
3125 {
3126 aLibFile << "PROP " << "\"" << EscapeString( itS->first, CTX_QUOTED_STR ) << "\" \""
3127 << EscapeString( itS->second, CTX_QUOTED_STR ) << "\"\n";
3128 ++itS;
3129 }
3130
3131 return !aLibFile.fail();
3132}
3133
3134
3135void IDF3_COMP_OUTLINE::readData( std::istream& aLibFile, const std::string& aHeader,
3136 IDF3::IDF_VERSION aIdfVersion )
3137{
3138 // .ELECTRICAL/.MECHANICAL
3139 // [GEOM] [PART] [UNIT] [HEIGHT]
3140 // [outline]
3141 // [PROP] [prop name] [prop value]
3142 // check RECORD 1
3143 std::string token;
3144 bool quoted = false;
3145 int idx = 0;
3146 std::streampos pos = aLibFile.tellg();
3147
3148 if( !GetIDFString( aHeader, token, quoted, idx ) )
3149 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__,
3150 "\n* BUG: invalid invocation: blank header line" ) );
3151
3152 if( quoted )
3153 {
3154 ostringstream ostr;
3155
3156 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3157 ostr << "* violation: section name must not be in quotes\n";
3158 ostr << "* line: '" << aHeader << "'\n";
3159 ostr << "* file position: " << pos;
3160
3161 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3162 }
3163
3164 if( CompareToken( ".ELECTRICAL", token ) )
3165 {
3167 }
3168 else if( CompareToken( ".MECHANICAL", token ) )
3169 {
3171 }
3172 else
3173 {
3174 ostringstream ostr;
3175
3176 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3177 ostr << "* violation: expecting .ELECTRICAL or .MECHANICAL header\n";
3178 ostr << "* line: '" << aHeader << "'\n";
3179 ostr << "* file position: " << pos;
3180
3181 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3182 }
3183
3184 // check RECORD 2
3185 // [GEOM] [PART] [UNIT] [HEIGHT]
3186 std::string iline;
3187 bool comment = false;
3188
3189 while( aLibFile.good() && !FetchIDFLine( aLibFile, iline, comment, pos ) );
3190
3191 if( !aLibFile.good() )
3192 {
3193 ostringstream ostr;
3194
3195 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3196 ostr << "* violation: premature end\n";
3197 ostr << "* file position: " << pos;
3198
3199 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3200 }
3201
3202 idx = 0;
3203
3204 if( comment )
3205 {
3206 ostringstream ostr;
3207
3208 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3209 ostr << "* violation: comment within section\n";
3210 ostr << "* line: '" << iline << "'\n";
3211 ostr << "* file position: " << pos;
3212
3213 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3214 }
3215
3216 if( !GetIDFString( iline, token, quoted, idx ) )
3217 {
3218 ostringstream ostr;
3219
3220 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3221 ostr << "* violation: no GEOMETRY NAME\n";
3222 ostr << "* line: '" << iline << "'\n";
3223 ostr << "* file position: " << pos;
3224
3225 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3226 }
3227
3228 geometry = token;
3229
3230 if( !GetIDFString( iline, token, quoted, idx ) )
3231 {
3232 ostringstream ostr;
3233
3234 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3235 ostr << "* violation: no PART NAME\n";
3236 ostr << "* line: '" << iline << "'\n";
3237 ostr << "* file position: " << pos;
3238
3239 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3240 }
3241
3242 part = token;
3243
3244 if( part.empty() && geometry.empty() )
3245 {
3246 ostringstream ostr;
3247
3248 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3249 ostr << "* violation: both GEOMETRY and PART names are empty\n";
3250 ostr << "* line: '" << iline << "'\n";
3251 ostr << "* file position: " << pos;
3252
3253 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3254 }
3255
3256 if( !GetIDFString( iline, token, quoted, idx ) )
3257 {
3258 ostringstream ostr;
3259
3260 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3261 ostr << "* violation: no UNIT type\n";
3262 ostr << "* line: '" << iline << "'\n";
3263 ostr << "* file position: " << pos;
3264
3265 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3266 }
3267
3268 if( CompareToken( "MM", token ) )
3269 {
3271 }
3272 else if( CompareToken( "THOU", token ) )
3273 {
3275 }
3276 else if( aIdfVersion == IDF_VERSION::IDF_V2 && !CompareToken( "TNM", token ) )
3277 {
3279 }
3280 else
3281 {
3282 ostringstream ostr;
3283
3284 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3285 ostr << "* violation: invalid UNIT '" << token << "': must be one of MM or THOU\n";
3286 ostr << "* line: '" << iline << "'\n";
3287 ostr << "* file position: " << pos;
3288
3289 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3290 }
3291
3292 if( !GetIDFString( iline, token, quoted, idx ) )
3293 {
3294 ostringstream ostr;
3295
3296 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3297 ostr << "* violation: no height specified\n";
3298 ostr << "* line: '" << iline << "'\n";
3299 ostr << "* file position: " << pos;
3300
3301 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3302 }
3303
3304 std::istringstream teststr;
3305 teststr.str( token );
3306
3307 teststr >> thickness;
3308 if( teststr.fail() )
3309 {
3310 ostringstream ostr;
3311
3312 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3313 ostr << "* violation: invalid height '" << token << "'\n";
3314 ostr << "* line: '" << iline << "'\n";
3315 ostr << "* file position: " << pos;
3316
3317 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3318 }
3319
3320 if( unit == IDF_UNIT::UNIT_THOU )
3321 {
3323 }
3324 else if( ( aIdfVersion == IDF_VERSION::IDF_V2 ) && ( unit == IDF_UNIT::UNIT_TNM ) )
3325 {
3327 }
3328 else if( unit != IDF_UNIT::UNIT_MM )
3329 {
3330 ostringstream ostr;
3331 ostr << "\n* BUG: invalid UNIT type: " << static_cast<int>( unit );
3332
3333 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3334 }
3335
3336 // read RECORD 3 values
3337 readOutlines( aLibFile, aIdfVersion );
3338
3339 if( compType == COMP_TYPE::COMP_ELEC && aIdfVersion > IDF_VERSION::IDF_V2 )
3340 readProperties( aLibFile );
3341
3342 // check RECORD 4
3343 while( aLibFile.good() && !FetchIDFLine( aLibFile, iline, comment, pos ) );
3344
3345 if( ( !aLibFile.good() && aLibFile.eof() ) && iline.empty() )
3346 {
3347 ostringstream ostr;
3348
3349 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3350 ostr << "* violation: premature end\n";
3351 ostr << "* file position: " << pos;
3352
3353 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3354 }
3355
3356 idx = 0;
3357
3358 if( comment )
3359 {
3360 ostringstream ostr;
3361
3362 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3363 ostr << "* violation: comment within section\n";
3364 ostr << "* line: '" << iline << "'\n";
3365 ostr << "* file position: " << pos;
3366
3367 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3368 }
3369
3371 {
3372 if( !CompareToken( ".END_ELECTRICAL", iline ) )
3373 {
3374 ostringstream ostr;
3375
3376 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3377 ostr << "* violation: no .END_ELECTRICAL found\n";
3378 ostr << "* line: '" << iline << "'\n";
3379 ostr << "* file position: " << pos;
3380
3381 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3382 }
3383 }
3384 else
3385 {
3386 if( !CompareToken( ".END_MECHANICAL", iline ) )
3387 {
3388 ostringstream ostr;
3389
3390 ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n";
3391 ostr << "* violation: no .END_MECHANICAL found\n";
3392 ostr << "* line: '" << iline << "'\n";
3393 ostr << "* file position: " << pos;
3394
3395 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3396 }
3397 }
3398}
3399
3400
3401void IDF3_COMP_OUTLINE::writeData( std::ostream& aLibFile )
3402{
3403 if( refNum == 0 )
3404 return; // nothing to do
3405
3407 {
3408 ostringstream ostr;
3409 ostr << "\n* component type not set or invalid: " << static_cast<int>( compType );
3410
3411 throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) );
3412 }
3413
3414 writeComments( aLibFile );
3415
3416 // note: the outline section is required, even if it is empty
3418 aLibFile << ".ELECTRICAL\n";
3419 else
3420 aLibFile << ".MECHANICAL\n";
3421
3422 // RECORD 2
3423 // [GEOM] [PART] [UNIT] [HEIGHT]
3424 aLibFile << "\"" << EscapeString( geometry, CTX_QUOTED_STR ) << "\" \""
3425 << EscapeString( part, CTX_QUOTED_STR ) << "\" ";
3426
3427 if( unit != IDF_UNIT::UNIT_THOU )
3428 {
3429 aLibFile << "MM " << setiosflags( ios::fixed ) << setprecision( 5 ) << thickness << "\n";
3430 }
3431 else
3432 {
3433 aLibFile << "THOU " << setiosflags( ios::fixed ) << setprecision( 1 )
3434 << ( thickness / IDF_THOU_TO_MM ) << "\n";
3435 }
3436
3437 writeOutlines( aLibFile );
3438
3440 {
3441 writeProperties( aLibFile );
3442 aLibFile << ".END_ELECTRICAL\n\n";
3443 }
3444 else
3445 {
3446 aLibFile << ".END_MECHANICAL\n\n";
3447 }
3448}
3449
3450
3452{
3453#ifndef DISABLE_IDF_OWNERSHIP
3454 if( !CheckOwnership( __LINE__, __FUNCTION__, parent, owner, outlineType, errormsg ) )
3455 return false;
3456#endif
3457
3458 clear();
3459 uid.clear();
3460 geometry.clear();
3461 part.clear();
3463 refNum = 0;
3464 props.clear();
3465
3466 return true;
3467}
3468
3469
3471{
3472 switch( aCompClass )
3473 {
3476 compType = aCompClass;
3477 break;
3478
3479 default:
3480 do
3481 {
3482 ostringstream ostr;
3483 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
3484 ostr << "* BUG: invalid component class (must be ELECTRICAL or MECHANICAL): ";
3485 ostr << static_cast<int>( aCompClass ) << "\n";
3486 errormsg = ostr.str();
3487
3488 return false;
3489 } while( 0 );
3490
3491 break;
3492 }
3493
3494 return true;
3495}
3496
3497
3502
3503
3504void IDF3_COMP_OUTLINE::SetGeomName( const std::string& aGeomName )
3505{
3506 geometry = aGeomName;
3507 uid.clear();
3508}
3509
3510
3511const std::string& IDF3_COMP_OUTLINE::GetGeomName( void )
3512{
3513 return geometry;
3514}
3515
3516
3517void IDF3_COMP_OUTLINE::SetPartName( const std::string& aPartName )
3518{
3519 part = aPartName;
3520 uid.clear();
3521}
3522
3523
3524const std::string& IDF3_COMP_OUTLINE::GetPartName( void )
3525{
3526 return part;
3527}
3528
3529
3530const std::string& IDF3_COMP_OUTLINE::GetUID( void )
3531{
3532 if( !uid.empty() )
3533 return uid;
3534
3535 if( geometry.empty() && part.empty() )
3536 return uid;
3537
3538 uid = geometry + "_" + part;
3539
3540 return uid;
3541}
3542
3543
3545{
3546 return ++refNum;
3547}
3548
3549
3551{
3552 if( refNum == 0 )
3553 {
3554 ostringstream ostr;
3555 ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n";
3556 ostr << "* BUG: decrementing refNum beyond 0";
3557 errormsg = ostr.str();
3558
3559 return -1;
3560 }
3561
3562 --refNum;
3563 return refNum;
3564}
3565
3566
3567bool IDF3_COMP_OUTLINE::CreateDefaultOutline( const std::string& aGeom, const std::string& aPart )
3568{
3569 Clear();
3570
3571 if( aGeom.empty() && aPart.empty() )
3572 {
3573 geometry = "NOGEOM";
3574 part = "NOPART";
3575 uid = "NOGEOM_NOPART";
3576 }
3577 else
3578 {
3579 geometry = aGeom;
3580 part = aPart;
3581 uid = aGeom + "_" + aPart;
3582 }
3583
3585 thickness = 5.0;
3587
3588 // Create a star shape 5mm high with points on 5 and 3 mm circles
3589 double a, da;
3590 da = M_PI / 5.0;
3591 a = da / 2.0;
3592
3593 IDF_POINT p1, p2;
3594 IDF_SEGMENT* sp;
3595 IDF_OUTLINE* ol;
3596
3597 p1.x = 1.5 * cos( a );
3598 p1.y = 1.5 * sin( a );
3599
3600 try
3601 {
3602 ol = new IDF_OUTLINE;
3603 }
3604 catch( std::bad_alloc& )
3605 {
3606 return false;
3607 }
3608
3609 for( int i = 0; i < 10; ++i )
3610 {
3611 if( i & 1 )
3612 {
3613 p2.x = 2.5 * cos( a );
3614 p2.y = 2.5 * sin( a );
3615 }
3616 else
3617 {
3618 p2.x = 1.5 * cos( a );
3619 p2.y = 1.5 * sin( a );
3620 }
3621
3622 try
3623 {
3624 sp = new IDF_SEGMENT( p1, p2 );
3625 }
3626 catch( std::bad_alloc& )
3627 {
3628 Clear();
3629 return false;
3630 }
3631
3632 ol->push( sp );
3633 a += da;
3634 p1 = p2;
3635 }
3636
3637 a = da / 2.0;
3638 p2.x = 1.5 * cos( a );
3639 p2.y = 1.5 * sin( a );
3640
3641 try
3642 {
3643 sp = new IDF_SEGMENT( p1, p2 );
3644 }
3645 catch( std::bad_alloc& )
3646 {
3647 Clear();
3648 return false;
3649 }
3650
3651 ol->push( sp );
3652 outlines.push_back( ol );
3653
3654 return true;
3655}
void ClearComments(void)
Deletes all comments.
virtual bool Clear(void)
Free memory and reinitializes all internal data except for the parent pointer.
bool addOutline(IDF_OUTLINE *aOutline)
std::string errormsg
bool AddOutline(IDF_OUTLINE *aOutline)
Add the specified outline to this object.
virtual bool setThickness(double aThickness)
virtual void clear(void)
friend class IDF3_BOARD
virtual ~BOARD_OUTLINE()
IDF3::KEY_OWNER GetOwner(void)
IDF_OUTLINE * GetOutline(size_t aIndex)
Return a pointer to the outline as specified by aIndex.
IDF3::IDF_UNIT unit
bool DeleteComment(size_t aIndex)
Deletes a comment based on the given index.
bool writeComments(std::ostream &aBoardFile)
virtual void readData(std::istream &aBoardFile, const std::string &aHeader, IDF3::IDF_VERSION aIdfVersion)
Read data from a .BOARD_OUTLINE section.
const std::string * GetComment(size_t aIndex)
void writeOutlines(std::ostream &aBoardFile)
IDF3::OUTLINE_TYPE outlineType
bool IsSingle(void)
std::list< std::string > * GetComments(void)
bool writeOwner(std::ostream &aBoardFile)
void clearOutlines(void)
IDF3::KEY_OWNER owner
virtual bool SetThickness(double aThickness)
Set the thickness or height of the outline (mm).
virtual double GetThickness(void)
bool DelOutline(IDF_OUTLINE *aOutline)
Remove the given outline, subject to IDF ownership rules, if it is owned by this object.
const std::list< IDF_OUTLINE * > * GetOutlines(void)
Return outlines list.
IDF3_BOARD * parent
virtual void writeData(std::ostream &aBoardFile)
Write the comments and .BOARD_OUTLINE section to an IDFv3 file.
void readOutlines(std::istream &aBoardFile, IDF3::IDF_VERSION aIdfVersion)
bool SetOwner(IDF3::KEY_OWNER aOwner)
Set the ownership status of the outline subject to IDF ownership rules.
std::list< std::string > comments
IDF3_BOARD * GetParent(void)
size_t OutlinesSize(void)
void writeOutline(std::ostream &aBoardFile, IDF_OUTLINE *aOutline, size_t aIndex)
size_t CommentsSize(void)
IDF3::OUTLINE_TYPE GetOutlineType(void)
void setParent(IDF3_BOARD *aParent)
Set the parent IDF_BOARD object.
virtual bool SetUnit(IDF3::IDF_UNIT aUnit)
Function SetUnit sets the native unit of the outline; except for component outlines this must be the ...
std::list< IDF_OUTLINE * > outlines
void AddComment(const std::string &aComment)
Add a comment to the outline data.
virtual IDF3::IDF_UNIT GetUnit(void)
Return the native unit type of the outline.
virtual bool SetGroupName(std::string aGroupName)
Set the name of the group, subject to IDF ownership rules.
friend class IDF3_BOARD
IDF3::IDF_LAYER side
virtual bool Clear(void) override
Delete internal data, subject to IDF ownership rules.
virtual void writeData(std::ostream &aBoardFile) override
Write the data to a .PLACE_REGION section of an IDFv3 file.
virtual void readData(std::istream &aBoardFile, const std::string &aHeader, IDF3::IDF_VERSION aIdfVersion) override
Read GROUP_OUTLINE data from an open IDFv3 file.
virtual IDF3::IDF_LAYER GetSide(void)
std::string groupName
virtual const std::string & GetGroupName(void)
Return a reference to the (non-unique) group name.
GROUP_OUTLINE(IDF3_BOARD *aParent)
virtual bool SetSide(IDF3::IDF_LAYER aSide)
Set the side which this outline applies to (TOP, BOTTOM, BOTH).
IDF3::CAD_TYPE GetCadType(void)
Definition idf_parser.h:425
void SetPartName(const std::string &aPartName)
Set the Part Name (Part Number, IDFv3 spec) of the component outline.
void readProperties(std::istream &aLibFile)
const std::string & GetUID(void)
friend class IDF3_BOARD
virtual void writeData(std::ostream &aLibFile) override
Write comments and component outline data to an IDFv3 Library file.
virtual void readData(std::istream &aLibFile, const std::string &aHeader, IDF3::IDF_VERSION aIdfVersion) override
Read a component outline from an open IDFv3 file.
IDF3::COMP_TYPE GetComponentClass(void)
std::map< std::string, std::string > props
IDF3_COMP_OUTLINE(IDF3_BOARD *aParent)
virtual bool Clear(void) override
Delete internal outline data.
IDF3::COMP_TYPE compType
bool CreateDefaultOutline(const std::string &aGeom, const std::string &aPart)
Create a default outline with the given Geometry and Part names.
int decrementRef(void)
Decrement the internal reference counter to keep track of the number of components referring to this ...
void SetGeomName(const std::string &aGeomName)
Set the Geometry Name (Package Name, IDFv3 spec) of the component outline.
std::string geometry
bool SetComponentClass(IDF3::COMP_TYPE aCompClass)
Set the type of component outline (.ELECTRICAL or .MECHANICAL).
bool writeProperties(std::ostream &aLibFile)
const std::string & GetGeomName(void)
int incrementRef(void)
Increment the internal reference counter to keep track of the number of components referring to this ...
const std::string & GetPartName(void)
Return the Part Name (Part Number) of the component outline.
A segment and winding information for an IDF outline.
Definition idf_common.h:551
std::list< IDF_SEGMENT * >::iterator end()
Definition idf_common.h:623
std::list< IDF_SEGMENT * >::iterator begin()
Definition idf_common.h:615
size_t size()
Definition idf_common.h:583
IDF_SEGMENT *& back()
Definition idf_common.h:607
IDF_SEGMENT *& front()
Definition idf_common.h:599
bool push(IDF_SEGMENT *item)
Add a segment to the internal segment list.
A point as used by the various IDF related classes.
Definition idf_common.h:426
bool Matches(const IDF_POINT &aPoint, double aRadius=1e-5) const
Return true if the given coordinate point is within the given radius of the point.
double x
Definition idf_common.h:457
double y
Definition idf_common.h:458
A segment as used in IDFv3 outlines.
Definition idf_common.h:468
IDF_POINT endPoint
end point coordinates in mm
Definition idf_common.h:537
IDF_POINT startPoint
starting point coordinates in mm
Definition idf_common.h:536
double angle
included angle (degrees) according to IDFv3 specification
Definition idf_common.h:541
friend class IDF3_BOARD
virtual void readData(std::istream &aBoardFile, const std::string &aHeader, IDF3::IDF_VERSION aIdfVersion) override
Read an OTHER_OUTLINE data from an IDFv3 file.
IDF3::IDF_LAYER side
std::string uniqueID
virtual bool Clear(void) override
Function Clear deletes internal data except for the parent object.
virtual bool SetOutlineIdentifier(const std::string &aUniqueID)
Function SetOutlineIdentifier sets the Outline Identifier string of this OTHER_OUTLINE object as per ...
virtual const std::string & GetOutlineIdentifier(void)
Function GetOutlineIdentifier returns the object's Outline Identifier.
virtual void writeData(std::ostream &aBoardFile) override
Write the OTHER_OUTLINE data to an open IDFv3 file.
virtual bool SetSide(IDF3::IDF_LAYER aSide)
Function SetSide sets the side which this outline is applicable to (TOP, BOTTOM).
OTHER_OUTLINE(IDF3_BOARD *aParent)
virtual IDF3::IDF_LAYER GetSide(void)
Function GetSide returns the side which this outline is applicable to.
PLACE_KO_OUTLINE(IDF3_BOARD *aParent)
friend class IDF3_BOARD
virtual double GetMaxHeight(void)
Function GetMaxHeight returns the maximum allowable height for a component in this region.
IDF3::IDF_LAYER side
virtual bool SetMaxHeight(double aHeight)
Function SetMaxHeight sets the maximum height of a component within this outline.
virtual bool SetSide(IDF3::IDF_LAYER aSide)
Function SetSide sets the side (TOP, BOTTOM, BOTH) which this outline applies to.
virtual IDF3::IDF_LAYER GetSide(void)
Function GetSide returns the side which this outline is applicable to.
virtual void writeData(std::ostream &aBoardFile) override
Write the PLACE_OUTLINE data to an open IDFv3 file.
virtual bool Clear(void) override
Function Clear deletes all internal data.
virtual void readData(std::istream &aBoardFile, const std::string &aHeader, IDF3::IDF_VERSION aIdfVersion) override
Read PLACE_OUTLINE data from an open IDFv3 file.
PLACE_OUTLINE(IDF3_BOARD *aParent)
ROUTE_KO_OUTLINE(IDF3_BOARD *aParent)
friend class IDF3_BOARD
virtual void writeData(std::ostream &aBoardFile) override
Write the ROUTE_OUTLINE data to an open IDFv3 file.
virtual bool Clear(void) override
Function Clear deletes internal data except for the parent object.
virtual bool SetLayers(IDF3::IDF_LAYER aLayer)
Function SetLayers sets the layer or group of layers this outline is applicable to.
ROUTE_OUTLINE(IDF3_BOARD *aParent)
IDF3::IDF_LAYER layers
virtual void readData(std::istream &aBoardFile, const std::string &aHeader, IDF3::IDF_VERSION aIdfVersion) override
Read ROUTE_OUTLINE data from an IDFv3 file.
virtual IDF3::IDF_LAYER GetLayers(void)
Function GetLayers returns the layer or group of layers which this outline is applicable to.
VIA_KO_OUTLINE(IDF3_BOARD *aParent)
#define MIN_ANG
Definition idf_common.h:35
#define IDF_THOU_TO_MM
Definition idf_helpers.h:37
#define IDF_TNM_TO_MM
Definition idf_helpers.h:39
#define ERROR_IDF
Definition idf_helpers.h:29
static bool CheckOwnership(int aSourceLine, const char *aSourceFunc, IDF3_BOARD *aParent, IDF3::KEY_OWNER aOwnerCAD, IDF3::OUTLINE_TYPE aOutlineType, std::string &aErrorString)
static std::string GetOutlineTypeString(IDF3::OUTLINE_TYPE aOutlineType)
bool ParseIDFLayer(const std::string &aToken, IDF3::IDF_LAYER &aLayer)
Parse an input string for a valid IDF layer specification.
bool GetIDFString(const std::string &aLine, std::string &aIDFString, bool &hasQuotes, int &aIndex)
Parse a line retrieved via FetchIDFLine() and returns the first IDF string found from the starting po...
CAD_TYPE
The class of CAD program which is opening or modifying a file.
Definition idf_common.h:127
std::string GetOwnerString(IDF3::KEY_OWNER aOwner)
bool FetchIDFLine(std::istream &aModel, std::string &aLine, bool &isComment, std::streampos &aFilePos)
Retrieve a single line from an IDF file and performs minimal processing.
OUTLINE_TYPE
The class of outline.
Definition idf_common.h:150
IDF_VERSION
The supported IDF versions (3.0 and 2.0 ONLY).
Definition idf_common.h:76
IDF_UNIT
The native unit of the board and of component outlines.
Definition idf_common.h:177
bool CompareToken(const char *aTokenString, const std::string &aInputString)
Perform a case-insensitive comparison of a token string and an input string.
IDF_LAYER
The various IDF layer classes and groupings.
Definition idf_common.h:137
KEY_OWNER
The type of CAD which has ownership an object.
Definition idf_common.h:85
bool WriteLayersText(std::ostream &aBoardFile, IDF3::IDF_LAYER aLayer)
Write out text corresponding to the given IDF Layer type.
COMP_TYPE
Whether a component is a mechanical or electrical part.
Definition idf_common.h:167
bool ParseOwner(const std::string &aToken, IDF3::KEY_OWNER &aOwner)
Parse the input string for a valid IDF Owner type.
STL namespace.
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_QUOTED_STR
#define M_PI