KiCad PCB EDA Suite
legacy_plugin.cpp
Go to the documentation of this file.
1 
2 /*
3  * This program source code file is part of KiCad, a free EDA CAD application.
4  *
5  * Copyright (C) 2007-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2019 Jean-Pierre Charras, jp.charras@wanadoo.fr
7  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 /*
28  This implements loading and saving a BOARD, behind the PLUGIN interface.
29 
30  The definitions:
31 
32  *) a Board Internal Unit (BIU) is a unit of length that is used only internally
33  to PCBNEW, and is nanometers when this work is done, but deci-mils until done.
34 
35  The philosophies:
36 
37  *) BIUs should be typed as such to distinguish them from ints. This is mostly
38  for human readability, and having the type nearby in the source supports this readability.
39  *) Do not assume that BIUs will always be int, doing a sscanf() into a BIU
40  does not make sense in case the size of the BIU changes.
41  *) variables are put onto the stack in an automatic, even when it might look
42  more efficient to do otherwise. This is so we can seem them with a debugger.
43  *) Global variables should not be touched from within a PLUGIN, since it will eventually
44  be in a DLL/DSO. This includes window information too. The PLUGIN API knows
45  nothing of wxFrame or globals and all error reporting must be done by throwing
46  an exception.
47  *) No wxWindowing calls are made in here, since the UI resides higher up than in here,
48  and is going to process a bucket of detailed information thrown from down here
49  in the form of an exception if an error happens.
50  *) Much of what we do in this source file is for human readability, not performance.
51  Simply avoiding strtok() more often than the old code washes out performance losses.
52  Remember strncmp() will bail as soon as a mismatch happens, not going all the way
53  to end of string unless a full match.
54  *) angles are in the process of migrating to doubles, and 'int' if used, is
55  only shortterm, and along with this a change, and transition from from
56  "tenths of degrees" to simply "degrees" in the double (which has no problem
57  representing any portion of a degree).
58 */
59 
60 
61 #include <cerrno>
62 #include <cmath>
63 #include <cstdio>
64 #include <cstring>
65 #include <legacy_plugin.h> // implement this here
66 #include <wx/ffile.h>
67 #include <wx/string.h>
68 
69 #include <kicad_string.h>
70 #include <macros.h>
71 #include <properties.h>
72 #include <zones.h>
73 
74 #include <class_board.h>
75 #include <class_module.h>
76 #include <class_track.h>
77 #include <class_pcb_text.h>
78 #include <class_zone.h>
79 #include <class_dimension.h>
80 #include <class_drawsegment.h>
81 #include <class_pcb_target.h>
82 #include <class_edge_mod.h>
83 #include <3d_cache/3d_info.h>
84 #include <pcb_plot_params.h>
85 #include <pcb_plot_params_parser.h>
86 #include <convert_to_biu.h>
87 #include <trigo.h>
88 #include <build_version.h>
89 #include <confirm.h>
90 #include <math/util.h> // for KiROUND
91 
93 
94 
95 #define VERSION_ERROR_FORMAT _( "File \"%s\" is format version: %d.\nI only support format version <= %d.\nPlease upgrade Pcbnew to load this file." )
96 #define UNKNOWN_GRAPHIC_FORMAT _( "unknown graphic type: %d")
97 #define UNKNOWN_PAD_FORMAT _( "unknown pad type: %d")
98 #define UNKNOWN_PAD_ATTRIBUTE _( "unknown pad attribute: %d" )
99 
100 
101 typedef unsigned LEG_MASK;
102 
103 #define FIRST_LAYER 0
104 #define FIRST_COPPER_LAYER 0
105 #define LAYER_N_BACK 0
106 #define LAYER_N_2 1
107 #define LAYER_N_3 2
108 #define LAYER_N_4 3
109 #define LAYER_N_5 4
110 #define LAYER_N_6 5
111 #define LAYER_N_7 6
112 #define LAYER_N_8 7
113 #define LAYER_N_9 8
114 #define LAYER_N_10 9
115 #define LAYER_N_11 10
116 #define LAYER_N_12 11
117 #define LAYER_N_13 12
118 #define LAYER_N_14 13
119 #define LAYER_N_15 14
120 #define LAYER_N_FRONT 15
121 #define LAST_COPPER_LAYER LAYER_N_FRONT
122 
123 #define FIRST_NON_COPPER_LAYER 16
124 #define ADHESIVE_N_BACK 16
125 #define ADHESIVE_N_FRONT 17
126 #define SOLDERPASTE_N_BACK 18
127 #define SOLDERPASTE_N_FRONT 19
128 #define SILKSCREEN_N_BACK 20
129 #define SILKSCREEN_N_FRONT 21
130 #define SOLDERMASK_N_BACK 22
131 #define SOLDERMASK_N_FRONT 23
132 #define DRAW_N 24
133 #define COMMENT_N 25
134 #define ECO1_N 26
135 #define ECO2_N 27
136 #define EDGE_N 28
137 #define LAST_NON_COPPER_LAYER 28
138 
139 // Masks to identify a layer by a bit map
140 typedef unsigned LAYER_MSK;
141 #define LAYER_BACK (1 << LAYER_N_BACK)
142 #define LAYER_2 (1 << LAYER_N_2)
143 #define LAYER_3 (1 << LAYER_N_3)
144 #define LAYER_4 (1 << LAYER_N_4)
145 #define LAYER_5 (1 << LAYER_N_5)
146 #define LAYER_6 (1 << LAYER_N_6)
147 #define LAYER_7 (1 << LAYER_N_7)
148 #define LAYER_8 (1 << LAYER_N_8)
149 #define LAYER_9 (1 << LAYER_N_9)
150 #define LAYER_10 (1 << LAYER_N_10)
151 #define LAYER_11 (1 << LAYER_N_11)
152 #define LAYER_12 (1 << LAYER_N_12)
153 #define LAYER_13 (1 << LAYER_N_13)
154 #define LAYER_14 (1 << LAYER_N_14)
155 #define LAYER_15 (1 << LAYER_N_15)
156 #define LAYER_FRONT (1 << LAYER_N_FRONT)
157 #define ADHESIVE_LAYER_BACK (1 << ADHESIVE_N_BACK)
158 #define ADHESIVE_LAYER_FRONT (1 << ADHESIVE_N_FRONT)
159 #define SOLDERPASTE_LAYER_BACK (1 << SOLDERPASTE_N_BACK)
160 #define SOLDERPASTE_LAYER_FRONT (1 << SOLDERPASTE_N_FRONT)
161 #define SILKSCREEN_LAYER_BACK (1 << SILKSCREEN_N_BACK)
162 #define SILKSCREEN_LAYER_FRONT (1 << SILKSCREEN_N_FRONT)
163 #define SOLDERMASK_LAYER_BACK (1 << SOLDERMASK_N_BACK)
164 #define SOLDERMASK_LAYER_FRONT (1 << SOLDERMASK_N_FRONT)
165 #define DRAW_LAYER (1 << DRAW_N)
166 #define COMMENT_LAYER (1 << COMMENT_N)
167 #define ECO1_LAYER (1 << ECO1_N)
168 #define ECO2_LAYER (1 << ECO2_N)
169 #define EDGE_LAYER (1 << EDGE_N)
170 
171 // Helpful global layer masks:
172 // ALL_AUX_LAYERS layers are technical layers, ALL_NO_CU_LAYERS has user
173 // and edge layers too!
174 #define ALL_NO_CU_LAYERS 0x1FFF0000
175 #define ALL_CU_LAYERS 0x0000FFFF
176 #define FRONT_TECH_LAYERS (SILKSCREEN_LAYER_FRONT | SOLDERMASK_LAYER_FRONT \
177  | ADHESIVE_LAYER_FRONT | SOLDERPASTE_LAYER_FRONT)
178 #define BACK_TECH_LAYERS (SILKSCREEN_LAYER_BACK | SOLDERMASK_LAYER_BACK \
179  | ADHESIVE_LAYER_BACK | SOLDERPASTE_LAYER_BACK)
180 #define ALL_TECH_LAYERS (FRONT_TECH_LAYERS | BACK_TECH_LAYERS)
181 #define BACK_LAYERS (LAYER_BACK | BACK_TECH_LAYERS)
182 #define FRONT_LAYERS (LAYER_FRONT | FRONT_TECH_LAYERS)
183 
184 #define ALL_USER_LAYERS (DRAW_LAYER | COMMENT_LAYER | ECO1_LAYER | ECO2_LAYER )
185 
186 #define NO_LAYERS 0x00000000
187 
188 
189 // Old internal units definition (UI = decimil)
190 #define PCB_LEGACY_INTERNAL_UNIT 10000
191 
193 #define SZ( x ) (sizeof(x)-1)
194 
195 
196 static const char delims[] = " \t\r\n";
197 
198 
199 static bool inline isSpace( int c ) { return strchr( delims, c ) != 0; }
200 
201 #define MASK(x) (1<<(x))
202 
203 //-----<BOARD Load Functions>---------------------------------------------------
204 
206 #define TESTLINE( x ) ( !strncasecmp( line, x, SZ( x ) ) && isSpace( line[SZ( x )] ) )
207 
209 #define TESTSUBSTR( x ) ( !strncasecmp( line, x, SZ( x ) ) )
210 
211 
212 #if 1
213 #define READLINE( rdr ) rdr->ReadLine()
214 
215 #else
216 static inline char* ReadLine( LINE_READER* rdr, const char* caller )
220 {
221  char* ret = rdr->ReadLine();
222 
223  const char* line = rdr->Line();
224  printf( "%-6u %s: %s", rdr->LineNumber(), caller, line );
225 
226 #if 0 // trap
227  if( !strcmp( "loadSETUP", caller ) && !strcmp( "$EndSETUP\n", line ) )
228  {
229  int breakhere = 1;
230  }
231 #endif
232 
233  return ret;
234 }
235 #define READLINE( rdr ) ReadLine( rdr, __FUNCTION__ )
236 #endif
237 
238 
239 
240 using std::unique_ptr;
241 
242 
243 static EDA_TEXT_HJUSTIFY_T horizJustify( const char* horizontal )
244 {
245  if( !strcmp( "L", horizontal ) )
246  return GR_TEXT_HJUSTIFY_LEFT;
247  if( !strcmp( "R", horizontal ) )
248  return GR_TEXT_HJUSTIFY_RIGHT;
250 }
251 
252 static EDA_TEXT_VJUSTIFY_T vertJustify( const char* vertical )
253 {
254  if( !strcmp( "T", vertical ) )
255  return GR_TEXT_VJUSTIFY_TOP;
256  if( !strcmp( "B", vertical ) )
259 }
260 
261 
263 inline int layerMaskCountSet( LEG_MASK aMask )
264 {
265  int count = 0;
266 
267  for( int i = 0; aMask; ++i, aMask >>= 1 )
268  {
269  if( aMask & 1 )
270  ++count;
271  }
272 
273  return count;
274 }
275 
276 
277 // return true if aLegacyLayerNum is a valid copper layer legacy id, therefore
278 // top, bottom or inner activated layer
279 inline bool is_leg_copperlayer_valid( int aCu_Count, LAYER_NUM aLegacyLayerNum )
280 {
281  return ( aLegacyLayerNum == LAYER_N_FRONT ) || ( aLegacyLayerNum < aCu_Count );
282 }
283 
284 
286 {
287  int newid;
288  unsigned old = aLayerNum;
289 
290  // this is a speed critical function, be careful.
291 
292  if( unsigned( old ) <= unsigned( LAYER_N_FRONT ) )
293  {
294  // In .brd files, the layers are numbered from back to front
295  // (the opposite of the .kicad_pcb files)
296  if( old == LAYER_N_FRONT )
297  newid = F_Cu;
298  else if( old == LAYER_N_BACK )
299  newid = B_Cu;
300  else
301  {
302  newid = cu_count - 1 - old;
303  wxASSERT( newid >= 0 );
304  // This is of course incorrect, but at least it avoid crashing pcbnew:
305  if( newid < 0 )
306  newid = 0;
307  }
308  }
309  else
310  {
311  switch( old )
312  {
313  case ADHESIVE_N_BACK: newid = B_Adhes; break;
314  case ADHESIVE_N_FRONT: newid = F_Adhes; break;
315  case SOLDERPASTE_N_BACK: newid = B_Paste; break;
316  case SOLDERPASTE_N_FRONT: newid = F_Paste; break;
317  case SILKSCREEN_N_BACK: newid = B_SilkS; break;
318  case SILKSCREEN_N_FRONT: newid = F_SilkS; break;
319  case SOLDERMASK_N_BACK: newid = B_Mask; break;
320  case SOLDERMASK_N_FRONT: newid = F_Mask; break;
321  case DRAW_N: newid = Dwgs_User; break;
322  case COMMENT_N: newid = Cmts_User; break;
323  case ECO1_N: newid = Eco1_User; break;
324  case ECO2_N: newid = Eco2_User; break;
325  case EDGE_N: newid = Edge_Cuts; break;
326  default:
327 // wxASSERT( 0 );
328  // Remap all illegal non copper layers to comment layer
329  newid = Cmts_User;
330  }
331  }
332 
333  return PCB_LAYER_ID( newid );
334 }
335 
336 
337 LSET LEGACY_PLUGIN::leg_mask2new( int cu_count, unsigned aMask )
338 {
339  LSET ret;
340 
341  if( ( aMask & ALL_CU_LAYERS ) == ALL_CU_LAYERS )
342  {
343  ret = LSET::AllCuMask();
344 
345  aMask &= ~ALL_CU_LAYERS;
346  }
347 
348  for( int i=0; aMask; ++i, aMask >>= 1 )
349  {
350  if( aMask & 1 )
351  ret.set( leg_layer2new( cu_count, i ) );
352  }
353 
354  return ret;
355 }
356 
357 
365 static inline int intParse( const char* next, const char** out = NULL )
366 {
367  // please just compile this and be quiet, hide casting ugliness:
368  return (int) strtol( next, (char**) out, 10 );
369 }
370 
375 static inline LAYER_NUM layerParse( const char* next, const char** out = NULL )
376 {
377  return intParse( next, out );
378 }
379 
387 static inline long hexParse( const char* next, const char** out = NULL )
388 {
389  // please just compile this and be quiet, hide casting ugliness:
390  return strtol( next, (char**) out, 16 );
391 }
392 
393 
394 BOARD* LEGACY_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe,
395  const PROPERTIES* aProperties )
396 {
397  LOCALE_IO toggle; // toggles on, then off, the C locale.
398 
399  init( aProperties );
400 
401  m_board = aAppendToMe ? aAppendToMe : new BOARD();
402 
403  // Give the filename to the board if it's new
404  if( !aAppendToMe )
405  m_board->SetFileName( aFileName );
406 
407  // delete on exception, iff I own m_board, according to aAppendToMe
408  unique_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
409 
410  FILE_LINE_READER reader( aFileName );
411 
412  m_reader = &reader; // member function accessibility
413 
414  checkVersion();
415 
416  loadAllSections( bool( aAppendToMe ) );
417 
418  deleter.release();
419  return m_board;
420 }
421 
422 
423 void LEGACY_PLUGIN::loadAllSections( bool doAppend )
424 {
425  // $GENERAL section is first
426 
427  // $SHEETDESCR section is next
428 
429  // $SETUP section is next
430 
431  // Then follows $EQUIPOT and all the rest
432  char* line;
433 
434  while( ( line = READLINE( m_reader ) ) != NULL )
435  {
436  // put the more frequent ones at the top, but realize TRACKs are loaded as a group
437 
438  if( TESTLINE( "$MODULE" ) )
439  {
440  unique_ptr<MODULE> module( new MODULE( m_board ) );
441 
442  LIB_ID fpid;
443  std::string fpName = StrPurge( line + SZ( "$MODULE" ) );
444 
445  // The footprint names in legacy libraries can contain the '/' and ':'
446  // characters which will cause the FPID parser to choke.
447  ReplaceIllegalFileNameChars( &fpName );
448 
449  if( !fpName.empty() )
450  fpid.Parse( fpName, LIB_ID::ID_PCB, true );
451 
452  module->SetFPID( fpid );
453 
454  loadMODULE( module.get() );
455  m_board->Add( module.release(), ADD_MODE::APPEND );
456  }
457 
458  else if( TESTLINE( "$DRAWSEGMENT" ) )
459  {
460  loadPCB_LINE();
461  }
462 
463  else if( TESTLINE( "$EQUIPOT" ) )
464  {
466  }
467 
468  else if( TESTLINE( "$TEXTPCB" ) )
469  {
470  loadPCB_TEXT();
471  }
472 
473  else if( TESTLINE( "$TRACK" ) )
474  {
476  }
477 
478  else if( TESTLINE( "$NCLASS" ) )
479  {
480  loadNETCLASS();
481  }
482 
483  else if( TESTLINE( "$CZONE_OUTLINE" ) )
484  {
486  }
487 
488  else if( TESTLINE( "$COTATION" ) )
489  {
490  loadDIMENSION();
491  }
492 
493  else if( TESTLINE( "$PCB_TARGET" ) || TESTLINE( "$MIREPCB" ) )
494  {
495  loadPCB_TARGET();
496  }
497 
498  else if( TESTLINE( "$ZONE" ) )
499  {
500  // No longer supported; discard segment fills
502  }
503 
504  else if( TESTLINE( "$GENERAL" ) )
505  {
506  loadGENERAL();
507  }
508 
509  else if( TESTLINE( "$SHEETDESCR" ) )
510  {
511  loadSHEET();
512  }
513 
514  else if( TESTLINE( "$SETUP" ) )
515  {
516  if( !doAppend )
517  {
518  loadSETUP();
519  }
520  else
521  {
522  while( ( line = READLINE( m_reader ) ) != NULL )
523  {
524  // gobble until $EndSetup
525  if( TESTLINE( "$EndSETUP" ) )
526  break;
527  }
528  }
529  }
530 
531  else if( TESTLINE( "$EndBOARD" ) )
532  return; // preferred exit
533  }
534 
535  THROW_IO_ERROR( "Missing '$EndBOARD'" );
536 }
537 
538 
540 {
541  // Read first line and TEST if it is a PCB file format header like this:
542  // "PCBNEW-BOARD Version 1 ...."
543 
544  m_reader->ReadLine();
545 
546  char* line = m_reader->Line();
547 
548  if( !TESTLINE( "PCBNEW-BOARD" ) )
549  {
550  THROW_IO_ERROR( "Unknown file type" );
551  }
552 
553  int ver = 1; // if sccanf fails
554  sscanf( line, "PCBNEW-BOARD Version %d", &ver );
555 
556 #if !defined(DEBUG)
557  if( ver > LEGACY_BOARD_FILE_VERSION )
558  {
559  // "File \"%s\" is format version: %d.\nI only support format version <= %d.\nPlease upgrade Pcbnew to load this file."
561  m_reader->GetSource().GetData(), ver, LEGACY_BOARD_FILE_VERSION );
563  }
564 #endif
565 
568 }
569 
570 
572 {
573  char* line;
574  char* saveptr;
575  bool saw_LayerCount = false;
576 
577  while( ( line = READLINE( m_reader ) ) != NULL )
578  {
579  const char* data;
580 
581  if( TESTLINE( "Units" ) )
582  {
583  // what are the engineering units of the lengths in the BOARD?
584  data = strtok_r( line + SZ("Units"), delims, &saveptr );
585 
586  if( !strcmp( data, "mm" ) )
587  {
588  diskToBiu = IU_PER_MM;
589  }
590  }
591 
592  else if( TESTLINE( "LayerCount" ) )
593  {
594  int tmp = intParse( line + SZ( "LayerCount" ) );
596 
597  // This has to be set early so that leg_layer2new() works OK, and
598  // that means before parsing "EnabledLayers" and "VisibleLayers".
599  m_cu_count = tmp;
600 
601  saw_LayerCount = true;
602  }
603 
604  else if( TESTLINE( "EnabledLayers" ) )
605  {
606  if( !saw_LayerCount )
607  THROW_IO_ERROR( "Missing '$GENERAL's LayerCount" );
608 
609  LEG_MASK enabledLayers = hexParse( line + SZ( "EnabledLayers" ) );
610 
611  LSET new_mask = leg_mask2new( m_cu_count, enabledLayers );
612 
613  //DBG( printf( "EnabledLayers: %s\n", new_mask.FmtHex().c_str() );)
614 
615  m_board->SetEnabledLayers( new_mask );
616 
617  // layer visibility equals layer usage, unless overridden later via "VisibleLayers"
618  // Must call SetEnabledLayers() before calling SetVisibleLayers().
619  m_board->SetVisibleLayers( new_mask );
620  }
621 
622  else if( TESTLINE( "VisibleLayers" ) )
623  {
624  if( !saw_LayerCount )
625  THROW_IO_ERROR( "Missing '$GENERAL's LayerCount" );
626 
627  LEG_MASK visibleLayers = hexParse( line + SZ( "VisibleLayers" ) );
628 
629  LSET new_mask = leg_mask2new( m_cu_count, visibleLayers );
630 
631  m_board->SetVisibleLayers( new_mask );
632  }
633 
634  else if( TESTLINE( "Ly" ) ) // Old format for Layer count
635  {
636  if( !saw_LayerCount )
637  {
638  LEG_MASK layer_mask = hexParse( line + SZ( "Ly" ) );
639 
640  m_cu_count = layerMaskCountSet( layer_mask & ALL_CU_LAYERS );
641 
643 
644  saw_LayerCount = true;
645  }
646  }
647 
648  else if( TESTLINE( "BoardThickness" ) )
649  {
650  BIU thickn = biuParse( line + SZ( "BoardThickness" ) );
652  }
653 
654  else if( TESTLINE( "NoConn" ) )
655  {
656  // ignore
657  intParse( line + SZ( "NoConn" ) );
658  }
659 
660  else if( TESTLINE( "Di" ) )
661  {
662  biuParse( line + SZ( "Di" ), &data );
663  biuParse( data, &data );
664  biuParse( data, &data );
665  biuParse( data );
666  }
667 
668  else if( TESTLINE( "Nnets" ) )
669  {
670  m_netCodes.resize( intParse( line + SZ( "Nnets" ) ) );
671  }
672 
673  else if( TESTLINE( "Nn" ) ) // id "Nnets" for old .brd files
674  {
675  m_netCodes.resize( intParse( line + SZ( "Nn" ) ) );
676  }
677 
678  else if( TESTLINE( "$EndGENERAL" ) )
679  return; // preferred exit
680  }
681 
682  THROW_IO_ERROR( "Missing '$EndGENERAL'" );
683 }
684 
685 
687 {
688  char buf[260];
689  TITLE_BLOCK tb;
690  char* line;
691  char* data;
692 
693  while( ( line = READLINE( m_reader ) ) != NULL )
694  {
695  if( TESTLINE( "Sheet" ) )
696  {
697  // e.g. "Sheet A3 16535 11700"
698  // width and height are in 1/1000th of an inch, always
699  PAGE_INFO page;
700  char* sname = strtok_r( line + SZ( "Sheet" ), delims, &data );
701 
702  if( sname )
703  {
704  wxString wname = FROM_UTF8( sname );
705 
706  if( !page.SetType( wname ) )
707  {
708  m_error.Printf( _( "Unknown sheet type \"%s\" on line:%d" ),
709  wname.GetData(),
710  m_reader->LineNumber() );
712  }
713 
714  char* width = strtok_r( NULL, delims, &data );
715  char* height = strtok_r( NULL, delims, &data );
716  char* orient = strtok_r( NULL, delims, &data );
717 
718  // only parse the width and height if page size is custom ("User")
719  if( wname == PAGE_INFO::Custom )
720  {
721  if( width && height )
722  {
723  // legacy disk file describes paper in mils
724  // (1/1000th of an inch)
725  int w = intParse( width );
726  int h = intParse( height );
727 
728  page.SetWidthMils( w );
729  page.SetHeightMils( h );
730  }
731  }
732 
733  if( orient && !strcmp( orient, "portrait" ) )
734  {
735  page.SetPortrait( true );
736  }
737 
738  m_board->SetPageSettings( page );
739  }
740  }
741 
742  else if( TESTLINE( "Title" ) )
743  {
744  ReadDelimitedText( buf, line, sizeof(buf) );
745  tb.SetTitle( FROM_UTF8( buf ) );
746  }
747 
748  else if( TESTLINE( "Date" ) )
749  {
750  ReadDelimitedText( buf, line, sizeof(buf) );
751  tb.SetDate( FROM_UTF8( buf ) );
752  }
753 
754  else if( TESTLINE( "Rev" ) )
755  {
756  ReadDelimitedText( buf, line, sizeof(buf) );
757  tb.SetRevision( FROM_UTF8( buf ) );
758  }
759 
760  else if( TESTLINE( "Comp" ) )
761  {
762  ReadDelimitedText( buf, line, sizeof(buf) );
763  tb.SetCompany( FROM_UTF8( buf ) );
764  }
765 
766  else if( TESTLINE( "Comment1" ) )
767  {
768  ReadDelimitedText( buf, line, sizeof(buf) );
769  tb.SetComment( 0, FROM_UTF8( buf ) );
770  }
771 
772  else if( TESTLINE( "Comment2" ) )
773  {
774  ReadDelimitedText( buf, line, sizeof(buf) );
775  tb.SetComment( 1, FROM_UTF8( buf ) );
776  }
777 
778  else if( TESTLINE( "Comment3" ) )
779  {
780  ReadDelimitedText( buf, line, sizeof(buf) );
781  tb.SetComment( 2, FROM_UTF8( buf ) );
782  }
783 
784  else if( TESTLINE( "Comment4" ) )
785  {
786  ReadDelimitedText( buf, line, sizeof(buf) );
787  tb.SetComment( 3, FROM_UTF8( buf ) );
788  }
789 
790  else if( TESTLINE( "Comment5" ) )
791  {
792  ReadDelimitedText( buf, line, sizeof(buf) );
793  tb.SetComment( 4, FROM_UTF8( buf ) );
794  }
795 
796  else if( TESTLINE( "Comment6" ) )
797  {
798  ReadDelimitedText( buf, line, sizeof(buf) );
799  tb.SetComment( 5, FROM_UTF8( buf ) );
800  }
801 
802  else if( TESTLINE( "Comment7" ) )
803  {
804  ReadDelimitedText( buf, line, sizeof(buf) );
805  tb.SetComment( 6, FROM_UTF8( buf ) );
806  }
807 
808  else if( TESTLINE( "Comment8" ) )
809  {
810  ReadDelimitedText( buf, line, sizeof(buf) );
811  tb.SetComment( 7, FROM_UTF8( buf ) );
812  }
813 
814  else if( TESTLINE( "Comment9" ) )
815  {
816  ReadDelimitedText( buf, line, sizeof(buf) );
817  tb.SetComment( 8, FROM_UTF8( buf ) );
818  }
819 
820  else if( TESTLINE( "$EndSHEETDESCR" ) )
821  {
822  m_board->SetTitleBlock( tb );
823  return; // preferred exit
824  }
825  }
826 
827  THROW_IO_ERROR( "Missing '$EndSHEETDESCR'" );
828 }
829 
830 
832 {
833  NETCLASSPTR netclass_default = m_board->GetDesignSettings().GetDefault();
834  // TODO Orson: is it really necessary to first operate on a copy and then apply it?
835  // would not it be better to use reference here and apply all the changes instantly?
838  char* line;
839  char* saveptr;
840 
841  while( ( line = READLINE( m_reader ) ) != NULL )
842  {
843  const char* data;
844 
845  if( TESTLINE( "PcbPlotParams" ) )
846  {
847  PCB_PLOT_PARAMS plot_opts;
848 
849  PCB_PLOT_PARAMS_PARSER parser( line + SZ( "PcbPlotParams" ), m_reader->GetSource() );
850 
851  plot_opts.Parse( &parser );
852 
853  m_board->SetPlotOptions( plot_opts );
854  }
855 
856  else if( TESTLINE( "AuxiliaryAxisOrg" ) )
857  {
858  BIU gx = biuParse( line + SZ( "AuxiliaryAxisOrg" ), &data );
859  BIU gy = biuParse( data );
860 
861  // m_board->SetAuxOrigin( wxPoint( gx, gy ) ); gets overwritten by SetDesignSettings() below
862  bds.m_AuxOrigin = wxPoint( gx, gy );
863  }
864 
865  /* Done from $General above's "LayerCount"
866  else if( TESTLINE( "Layers" ) )
867  {
868  int tmp = intParse( line + SZ( "Layers" ) );
869  m_board->SetCopperLayerCount( tmp );
870 
871  m_cu_count = tmp;
872  }
873  */
874 
875  else if( TESTSUBSTR( "Layer[" ) )
876  {
877  // eg: "Layer[n] <a_Layer_name_with_no_spaces> <LAYER_T>"
878 
879  LAYER_NUM layer_num = layerParse( line + SZ( "Layer[" ), &data );
880  PCB_LAYER_ID layer_id = leg_layer2new( m_cu_count, layer_num );
881 
882  /*
883  switch( layer_num )
884  {
885  case LAYER_N_BACK:
886  layer_id = B_Cu;
887  break;
888 
889  case LAYER_N_FRONT:
890  layer_id = F_Cu;
891  break;
892 
893  default:
894  layer_id = PCB_LAYER_ID( layer_num );
895  }
896  */
897 
898  data = strtok_r( (char*) data+1, delims, &saveptr ); // +1 for ']'
899 
900  if( data )
901  {
902  wxString layerName = FROM_UTF8( data );
903  m_board->SetLayerName( layer_id, layerName );
904 
905  data = strtok_r( NULL, delims, &saveptr );
906 
907  if( data ) // optional in old board files
908  {
909  LAYER_T type = LAYER::ParseType( data );
910  m_board->SetLayerType( layer_id, type );
911  }
912  }
913  }
914 
915  else if( TESTLINE( "TrackWidth" ) )
916  {
917  BIU tmp = biuParse( line + SZ( "TrackWidth" ) );
918  netclass_default->SetTrackWidth( tmp );
919  }
920 
921  else if( TESTLINE( "TrackWidthList" ) )
922  {
923  BIU tmp = biuParse( line + SZ( "TrackWidthList" ) );
924  bds.m_TrackWidthList.push_back( tmp );
925  }
926 
927  else if( TESTLINE( "TrackClearence" ) )
928  {
929  BIU tmp = biuParse( line + SZ( "TrackClearence" ) );
930  netclass_default->SetClearance( tmp );
931  }
932 
933  else if( TESTLINE( "TrackMinWidth" ) )
934  {
935  BIU tmp = biuParse( line + SZ( "TrackMinWidth" ) );
936  bds.m_TrackMinWidth = tmp;
937  }
938 
939  else if( TESTLINE( "ZoneClearence" ) )
940  {
941  BIU tmp = biuParse( line + SZ( "ZoneClearence" ) );
942  zs.m_ZoneClearance = tmp;
943  }
944 
945  else if( TESTLINE( "Zone_45_Only" ) )
946  {
947  bool tmp = (bool) intParse( line + SZ( "Zone_45_Only" ) );
948  zs.m_Zone_45_Only = tmp;
949  }
950 
951  else if( TESTLINE( "DrawSegmWidth" ) )
952  {
953  BIU tmp = biuParse( line + SZ( "DrawSegmWidth" ) );
954  bds.m_LineThickness[ LAYER_CLASS_COPPER ] = tmp;
955  }
956 
957  else if( TESTLINE( "EdgeSegmWidth" ) )
958  {
959  BIU tmp = biuParse( line + SZ( "EdgeSegmWidth" ) );
960  bds.m_LineThickness[ LAYER_CLASS_EDGES ] = tmp;
961  }
962 
963  else if( TESTLINE( "ViaMinSize" ) )
964  {
965  BIU tmp = biuParse( line + SZ( "ViaMinSize" ) );
966  bds.m_ViasMinSize = tmp;
967  }
968 
969  else if( TESTLINE( "MicroViaMinSize" ) )
970  {
971  BIU tmp = biuParse( line + SZ( "MicroViaMinSize" ) );
972  bds.m_MicroViasMinSize = tmp;
973  }
974 
975  else if( TESTLINE( "ViaSizeList" ) )
976  {
977  // e.g. "ViaSizeList DIAMETER [DRILL]"
978 
979  BIU drill = 0;
980  BIU diameter = biuParse( line + SZ( "ViaSizeList" ), &data );
981 
982  data = strtok_r( (char*) data, delims, (char**) &data );
983  if( data ) // DRILL may not be present ?
984  drill = biuParse( data );
985 
986  bds.m_ViasDimensionsList.emplace_back( diameter,
987  drill );
988  }
989 
990  else if( TESTLINE( "ViaSize" ) )
991  {
992  BIU tmp = biuParse( line + SZ( "ViaSize" ) );
993  netclass_default->SetViaDiameter( tmp );
994  }
995 
996  else if( TESTLINE( "ViaDrill" ) )
997  {
998  BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
999  netclass_default->SetViaDrill( tmp );
1000  }
1001 
1002  else if( TESTLINE( "ViaMinDrill" ) )
1003  {
1004  BIU tmp = biuParse( line + SZ( "ViaMinDrill" ) );
1005  bds.m_ViasMinDrill = tmp;
1006  }
1007 
1008  else if( TESTLINE( "MicroViaSize" ) )
1009  {
1010  BIU tmp = biuParse( line + SZ( "MicroViaSize" ) );
1011  netclass_default->SetuViaDiameter( tmp );
1012  }
1013 
1014  else if( TESTLINE( "MicroViaDrill" ) )
1015  {
1016  BIU tmp = biuParse( line + SZ( "MicroViaDrill" ) );
1017  netclass_default->SetuViaDrill( tmp );
1018  }
1019 
1020  else if( TESTLINE( "MicroViaMinDrill" ) )
1021  {
1022  BIU tmp = biuParse( line + SZ( "MicroViaMinDrill" ) );
1023  bds.m_MicroViasMinDrill = tmp;
1024  }
1025 
1026  else if( TESTLINE( "MicroViasAllowed" ) )
1027  {
1028  int tmp = intParse( line + SZ( "MicroViasAllowed" ) );
1029  bds.m_MicroViasAllowed = tmp;
1030  }
1031 
1032  else if( TESTLINE( "TextPcbWidth" ) )
1033  {
1034  BIU tmp = biuParse( line + SZ( "TextPcbWidth" ) );
1035  bds.m_TextThickness[ LAYER_CLASS_COPPER ] = tmp;
1036  }
1037 
1038  else if( TESTLINE( "TextPcbSize" ) )
1039  {
1040  BIU x = biuParse( line + SZ( "TextPcbSize" ), &data );
1041  BIU y = biuParse( data );
1042 
1043  bds.m_TextSize[ LAYER_CLASS_COPPER ] = wxSize( x, y );
1044  }
1045 
1046  else if( TESTLINE( "EdgeModWidth" ) )
1047  {
1048  BIU tmp = biuParse( line + SZ( "EdgeModWidth" ) );
1049  bds.m_LineThickness[ LAYER_CLASS_SILK ] = tmp;
1050  bds.m_LineThickness[ LAYER_CLASS_OTHERS ] = tmp;
1051  }
1052 
1053  else if( TESTLINE( "TextModWidth" ) )
1054  {
1055  BIU tmp = biuParse( line + SZ( "TextModWidth" ) );
1056  bds.m_TextThickness[ LAYER_CLASS_SILK ] = tmp;
1057  bds.m_TextThickness[ LAYER_CLASS_OTHERS ] = tmp;
1058  }
1059 
1060  else if( TESTLINE( "TextModSize" ) )
1061  {
1062  BIU x = biuParse( line + SZ( "TextModSize" ), &data );
1063  BIU y = biuParse( data );
1064 
1065  bds.m_TextSize[ LAYER_CLASS_SILK ] = wxSize( x, y );
1066  bds.m_TextSize[ LAYER_CLASS_OTHERS ] = wxSize( x, y );
1067  }
1068 
1069  else if( TESTLINE( "PadSize" ) )
1070  {
1071  BIU x = biuParse( line + SZ( "PadSize" ), &data );
1072  BIU y = biuParse( data );
1073 
1074  bds.m_Pad_Master.SetSize( wxSize( x, y ) );
1075  }
1076 
1077  else if( TESTLINE( "PadDrill" ) )
1078  {
1079  BIU tmp = biuParse( line + SZ( "PadDrill" ) );
1080  bds.m_Pad_Master.SetDrillSize( wxSize( tmp, tmp ) );
1081  }
1082 
1083  else if( TESTLINE( "Pad2MaskClearance" ) )
1084  {
1085  BIU tmp = biuParse( line + SZ( "Pad2MaskClearance" ) );
1086  bds.m_SolderMaskMargin = tmp;
1087  }
1088 
1089  else if( TESTLINE( "SolderMaskMinWidth" ) )
1090  {
1091  BIU tmp = biuParse( line + SZ( "SolderMaskMinWidth" ) );
1092  bds.m_SolderMaskMinWidth = tmp;
1093  }
1094 
1095  else if( TESTLINE( "Pad2PasteClearance" ) )
1096  {
1097  BIU tmp = biuParse( line + SZ( "Pad2PasteClearance" ) );
1098  bds.m_SolderPasteMargin = tmp;
1099  }
1100 
1101  else if( TESTLINE( "Pad2PasteClearanceRatio" ) )
1102  {
1103  double ratio = atof( line + SZ( "Pad2PasteClearanceRatio" ) );
1104  bds.m_SolderPasteMarginRatio = ratio;
1105  }
1106 
1107  else if( TESTLINE( "GridOrigin" ) )
1108  {
1109  BIU x = biuParse( line + SZ( "GridOrigin" ), &data );
1110  BIU y = biuParse( data );
1111 
1112  // m_board->SetGridOrigin( wxPoint( x, y ) ); gets overwritten by SetDesignSettings() below
1113  bds.m_GridOrigin = wxPoint( x, y );
1114  }
1115 
1116  else if( TESTLINE( "VisibleElements" ) )
1117  {
1118  int visibleElements = hexParse( line + SZ( "VisibleElements" ) );
1119  bds.SetVisibleElements( visibleElements );
1120  }
1121 
1122  else if( TESTLINE( "$EndSETUP" ) )
1123  {
1124  m_board->SetDesignSettings( bds );
1125  m_board->SetZoneSettings( zs );
1126 
1127  // Very old *.brd file does not have NETCLASSes
1128  // "TrackWidth", "ViaSize", "ViaDrill", "ViaMinSize", and "TrackClearence" were
1129  // defined in SETUP; these values are put into the default NETCLASS until later board
1130  // load code should override them. *.brd files which have been saved with knowledge
1131  // of NETCLASSes will override these defaults, very old boards (before 2009) will not
1132  // and use the setup values.
1133  // However these values should be the same as default NETCLASS.
1134 
1135  return; // preferred exit
1136  }
1137  }
1138 
1139  /*
1140  * Ensure tracks and vias sizes lists are ok:
1141  * Sort lists by by increasing value and remove duplicates
1142  * (the first value is not tested, because it is the netclass value)
1143  */
1144  BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
1145  sort( designSettings.m_ViasDimensionsList.begin() + 1, designSettings.m_ViasDimensionsList.end() );
1146  sort( designSettings.m_TrackWidthList.begin() + 1, designSettings.m_TrackWidthList.end() );
1147 
1148  for( unsigned ii = 1; ii < designSettings.m_ViasDimensionsList.size() - 1; ii++ )
1149  {
1150  if( designSettings.m_ViasDimensionsList[ii] == designSettings.m_ViasDimensionsList[ii + 1] )
1151  {
1152  designSettings.m_ViasDimensionsList.erase( designSettings.m_ViasDimensionsList.begin() + ii );
1153  ii--;
1154  }
1155  }
1156 
1157  for( unsigned ii = 1; ii < designSettings.m_TrackWidthList.size() - 1; ii++ )
1158  {
1159  if( designSettings.m_TrackWidthList[ii] == designSettings.m_TrackWidthList[ii + 1] )
1160  {
1161  designSettings.m_TrackWidthList.erase( designSettings.m_TrackWidthList.begin() + ii );
1162  ii--;
1163  }
1164  }
1165 }
1166 
1167 
1169 {
1170  char* line;
1171 
1172  while( ( line = READLINE( m_reader ) ) != NULL )
1173  {
1174  const char* data;
1175 
1176  // most frequently encountered ones at the top
1177 
1178  if( TESTSUBSTR( "D" ) && strchr( "SCAP", line[1] ) ) // read a drawing item, e.g. "DS"
1179  {
1180  loadMODULE_EDGE( aModule );
1181  }
1182 
1183  else if( TESTLINE( "$PAD" ) )
1184  {
1185  loadPAD( aModule );
1186  }
1187 
1188  // Read a footprint text description (ref, value, or drawing)
1189  else if( TESTSUBSTR( "T" ) )
1190  {
1191  // e.g. "T1 6940 -16220 350 300 900 60 M I 20 N "CFCARD"\r\n"
1192  int tnum = intParse( line + SZ( "T" ) );
1193 
1194  TEXTE_MODULE* textm = nullptr;
1195 
1196  switch( tnum )
1197  {
1199  textm = &aModule->Reference();
1200  break;
1201 
1203  textm = &aModule->Value();
1204  break;
1205 
1206  // All other fields greater than 1.
1207  default:
1208  textm = new TEXTE_MODULE( aModule );
1209  aModule->Add( textm );
1210  }
1211 
1212  loadMODULE_TEXT( textm );
1213  }
1214 
1215  else if( TESTLINE( "Po" ) )
1216  {
1217  // e.g. "Po 19120 39260 900 0 4E823D06 68183921-93a5-49ac-91b0-49d05a0e1647 ~~\r\n"
1218  BIU pos_x = biuParse( line + SZ( "Po" ), &data );
1219  BIU pos_y = biuParse( data, &data );
1220  int orient = intParse( data, &data );
1221  LAYER_NUM layer_num = layerParse( data, &data );
1222  PCB_LAYER_ID layer_id = leg_layer2new( m_cu_count, layer_num );
1223  long edittime = hexParse( data, &data );
1224  char* uuid = strtok_r( (char*) data, delims, (char**) &data );
1225 
1226  data = strtok_r( (char*) data+1, delims, (char**) &data );
1227 
1228  // data is now a two character long string
1229  // Note: some old files do not have this field
1230  if( data && data[0] == 'F' )
1231  aModule->SetLocked( true );
1232 
1233  if( data && data[1] == 'P' )
1234  aModule->SetIsPlaced( true );
1235 
1236  aModule->SetPosition( wxPoint( pos_x, pos_y ) );
1237  aModule->SetLayer( layer_id );
1238  aModule->SetOrientation( orient );
1239  const_cast<KIID&>( aModule->m_Uuid ) = KIID( uuid );
1240  aModule->SetLastEditTime( edittime );
1241  }
1242 
1243  /* footprint name set earlier, immediately after MODULE construction
1244  else if( TESTLINE( "Li" ) ) // Library name of footprint
1245  {
1246  // There can be whitespace in the footprint name on some old libraries.
1247  // Grab everything after "Li" up to end of line:
1248  //aModule->SetFPID( FROM_UTF8( StrPurge( line + SZ( "Li" ) ) ) );
1249  }
1250  */
1251 
1252  else if( TESTLINE( "Sc" ) ) // timestamp
1253  {
1254  char* uuid = strtok_r( (char*) line + SZ( "Sc" ), delims, (char**) &data );
1255  const_cast<KIID&>( aModule->m_Uuid ) = KIID( uuid );
1256  }
1257 
1258  else if( TESTLINE( "Op" ) ) // (Op)tions for auto placement
1259  {
1260  int itmp1 = hexParse( line + SZ( "Op" ), &data );
1261  int itmp2 = hexParse( data );
1262 
1263  int cntRot180 = itmp2 & 0x0F;
1264  if( cntRot180 > 10 )
1265  cntRot180 = 10;
1266 
1267  aModule->SetPlacementCost180( cntRot180 );
1268 
1269  int cntRot90 = itmp1 & 0x0F;
1270  if( cntRot90 > 10 )
1271  cntRot90 = 0;
1272 
1273  itmp1 = (itmp1 >> 4) & 0x0F;
1274  if( itmp1 > 10 )
1275  itmp1 = 0;
1276 
1277  aModule->SetPlacementCost90( (itmp1 << 4) | cntRot90 );
1278  }
1279 
1280  else if( TESTLINE( "At" ) ) // (At)tributes of module
1281  {
1282  int attrs = MOD_DEFAULT;
1283 
1284  data = line + SZ( "At" );
1285 
1286  if( strstr( data, "SMD" ) )
1287  attrs |= MOD_CMS;
1288 
1289  if( strstr( data, "VIRTUAL" ) )
1290  attrs |= MOD_VIRTUAL;
1291 
1292  aModule->SetAttributes( attrs );
1293  }
1294 
1295  else if( TESTLINE( "AR" ) ) // Alternate Reference
1296  {
1297  // e.g. "AR /68183921-93a5-49ac-e164-49d05a0e1647/93a549d0-49d0-e164-91b0-49d05a0e1647"
1298  data = strtok_r( line + SZ( "AR" ), delims, (char**) &data );
1299 
1300  if( data )
1301  aModule->SetPath( KIID_PATH( FROM_UTF8( data ) ) );
1302  }
1303 
1304  else if( TESTLINE( "$SHAPE3D" ) )
1305  {
1306  load3D( aModule );
1307  }
1308 
1309  else if( TESTLINE( "Cd" ) )
1310  {
1311  // e.g. "Cd Double rangee de contacts 2 x 4 pins\r\n"
1312  aModule->SetDescription( FROM_UTF8( StrPurge( line + SZ( "Cd" ) ) ) );
1313  }
1314 
1315  else if( TESTLINE( "Kw" ) ) // Key words
1316  {
1317  aModule->SetKeywords( FROM_UTF8( StrPurge( line + SZ( "Kw" ) ) ) );
1318  }
1319 
1320  else if( TESTLINE( ".SolderPasteRatio" ) )
1321  {
1322  double tmp = atof( line + SZ( ".SolderPasteRatio" ) );
1323  // Due to a bug in dialog editor in Modedit, fixed in BZR version 3565
1324  // this parameter can be broken.
1325  // It should be >= -50% (no solder paste) and <= 0% (full area of the pad)
1326 
1327  if( tmp < -0.50 )
1328  tmp = -0.50;
1329  if( tmp > 0.0 )
1330  tmp = 0.0;
1331  aModule->SetLocalSolderPasteMarginRatio( tmp );
1332  }
1333 
1334  else if( TESTLINE( ".SolderPaste" ) )
1335  {
1336  BIU tmp = biuParse( line + SZ( ".SolderPaste" ) );
1337  aModule->SetLocalSolderPasteMargin( tmp );
1338  }
1339 
1340  else if( TESTLINE( ".SolderMask" ) )
1341  {
1342  BIU tmp = biuParse( line + SZ( ".SolderMask" ) );
1343  aModule->SetLocalSolderMaskMargin( tmp );
1344  }
1345 
1346  else if( TESTLINE( ".LocalClearance" ) )
1347  {
1348  BIU tmp = biuParse( line + SZ( ".LocalClearance" ) );
1349  aModule->SetLocalClearance( tmp );
1350  }
1351 
1352  else if( TESTLINE( ".ZoneConnection" ) )
1353  {
1354  int tmp = intParse( line + SZ( ".ZoneConnection" ) );
1355  aModule->SetZoneConnection( (ZONE_CONNECTION) tmp );
1356  }
1357 
1358  else if( TESTLINE( ".ThermalWidth" ) )
1359  {
1360  BIU tmp = biuParse( line + SZ( ".ThermalWidth" ) );
1361  aModule->SetThermalWidth( tmp );
1362  }
1363 
1364  else if( TESTLINE( ".ThermalGap" ) )
1365  {
1366  BIU tmp = biuParse( line + SZ( ".ThermalGap" ) );
1367  aModule->SetThermalGap( tmp );
1368  }
1369 
1370  else if( TESTLINE( "$EndMODULE" ) )
1371  {
1372  aModule->CalculateBoundingBox();
1373 
1374  return; // preferred exit
1375  }
1376  }
1377 
1378  wxString msg = wxString::Format(
1379  _( "Missing '$EndMODULE' for MODULE \"%s\"" ),
1380  GetChars( aModule->GetFPID().GetLibItemName() ) );
1381 
1382  THROW_IO_ERROR( msg );
1383 }
1384 
1385 
1387 {
1388  unique_ptr<D_PAD> pad( new D_PAD( aModule ) );
1389  char* line;
1390  char* saveptr;
1391 
1392  while( ( line = READLINE( m_reader ) ) != NULL )
1393  {
1394  const char* data;
1395 
1396  if( TESTLINE( "Sh" ) ) // (Sh)ape and padname
1397  {
1398  // e.g. "Sh "A2" C 520 520 0 0 900"
1399  // or "Sh "1" R 157 1378 0 0 900"
1400 
1401  // mypadname is LATIN1/CRYLIC for BOARD_FORMAT_VERSION 1,
1402  // but for BOARD_FORMAT_VERSION 2, it is UTF8 from disk.
1403  // So we have to go through two code paths. Moving forward
1404  // padnames will be in UTF8 on disk, as are all KiCad strings on disk.
1405  char mypadname[50];
1406 
1407  data = line + SZ( "Sh" ) + 1; // +1 skips trailing whitespace
1408 
1409  data = data + ReadDelimitedText( mypadname, data, sizeof(mypadname) ) + 1; // +1 trailing whitespace
1410 
1411  while( isSpace( *data ) )
1412  ++data;
1413 
1414  unsigned char padchar = (unsigned char) *data++;
1415  int padshape;
1416 
1417  BIU size_x = biuParse( data, &data );
1418  BIU size_y = biuParse( data, &data );
1419  BIU delta_x = biuParse( data, &data );
1420  BIU delta_y = biuParse( data, &data );
1421  double orient = degParse( data );
1422 
1423  switch( padchar )
1424  {
1425  case 'C': padshape = PAD_SHAPE_CIRCLE; break;
1426  case 'R': padshape = PAD_SHAPE_RECT; break;
1427  case 'O': padshape = PAD_SHAPE_OVAL; break;
1428  case 'T': padshape = PAD_SHAPE_TRAPEZOID; break;
1429  default:
1430  m_error.Printf( _( "Unknown padshape '%c=0x%02x' on line: %d of footprint: \"%s\"" ),
1431  padchar,
1432  padchar,
1433  m_reader->LineNumber(),
1434  GetChars( aModule->GetFPID().GetLibItemName() )
1435  );
1437  }
1438 
1439  // go through a wxString to establish a universal character set properly
1440  wxString padname;
1441 
1442  if( m_loading_format_version == 1 )
1443  {
1444  // add 8 bit bytes, file format 1 was KiCad font type byte,
1445  // simply promote those 8 bit bytes up into UNICODE. (subset of LATIN1)
1446  const unsigned char* cp = (unsigned char*) mypadname;
1447  while( *cp )
1448  {
1449  padname += *cp++; // unsigned, ls 8 bits only
1450  }
1451  }
1452  else
1453  {
1454  // version 2, which is UTF8.
1455  padname = FROM_UTF8( mypadname );
1456  }
1457  // chances are both were ASCII, but why take chances?
1458 
1459  pad->SetName( padname );
1460  pad->SetShape( PAD_SHAPE_T( padshape ) );
1461  pad->SetSize( wxSize( size_x, size_y ) );
1462  pad->SetDelta( wxSize( delta_x, delta_y ) );
1463  pad->SetOrientation( orient );
1464  }
1465 
1466  else if( TESTLINE( "Dr" ) ) // (Dr)ill
1467  {
1468  // e.g. "Dr 350 0 0" or "Dr 0 0 0 O 0 0"
1469  BIU drill_x = biuParse( line + SZ( "Dr" ), &data );
1470  BIU drill_y = drill_x;
1471  BIU offs_x = biuParse( data, &data );
1472  BIU offs_y = biuParse( data, &data );
1473 
1475 
1476  data = strtok_r( (char*) data, delims, &saveptr );
1477  if( data ) // optional shape
1478  {
1479  if( data[0] == 'O' )
1480  {
1481  drShape = PAD_DRILL_SHAPE_OBLONG;
1482 
1483  data = strtok_r( NULL, delims, &saveptr );
1484  drill_x = biuParse( data );
1485 
1486  data = strtok_r( NULL, delims, &saveptr );
1487  drill_y = biuParse( data );
1488  }
1489  }
1490 
1491  pad->SetDrillShape( drShape );
1492  pad->SetOffset( wxPoint( offs_x, offs_y ) );
1493  pad->SetDrillSize( wxSize( drill_x, drill_y ) );
1494  }
1495 
1496  else if( TESTLINE( "At" ) ) // (At)tribute
1497  {
1498  // e.g. "At SMD N 00888000"
1499  // sscanf( PtLine, "%s %s %X", BufLine, BufCar, &m_layerMask );
1500 
1501  PAD_ATTR_T attribute;
1502 
1503  data = strtok_r( line + SZ( "At" ), delims, (char**) &data );
1504 
1505  if( !strcmp( data, "SMD" ) )
1506  attribute = PAD_ATTRIB_SMD;
1507  else if( !strcmp( data, "CONN" ) )
1508  attribute = PAD_ATTRIB_CONN;
1509  else if( !strcmp( data, "HOLE" ) )
1510  attribute = PAD_ATTRIB_HOLE_NOT_PLATED;
1511  else
1512  attribute = PAD_ATTRIB_STANDARD;
1513 
1514  strtok_r( NULL, delims, (char**) &data ); // skip BufCar
1515  strtok_r( NULL, delims, (char**) &data );
1516 
1517  LEG_MASK layer_mask = hexParse( data );
1518 
1519  pad->SetLayerSet( leg_mask2new( m_cu_count, layer_mask ) );
1520  pad->SetAttribute( attribute );
1521  }
1522 
1523  else if( TESTLINE( "Ne" ) ) // (Ne)tname
1524  {
1525  // e.g. "Ne 461 "V5.0"
1526 
1527  char buf[1024]; // can be fairly long
1528  int netcode = intParse( line + SZ( "Ne" ), &data );
1529 
1530  // Store the new code mapping
1531  pad->SetNetCode( getNetCode( netcode ) );
1532 
1533  // read Netname
1534  ReadDelimitedText( buf, data, sizeof(buf) );
1535 
1536  if( m_board )
1537  wxASSERT( m_board->FindNet( getNetCode( netcode ) )->GetNetname()
1538  == FROM_UTF8( StrPurge( buf ) ) );
1539  }
1540 
1541  else if( TESTLINE( "Po" ) ) // (Po)sition
1542  {
1543  // e.g. "Po 500 -500"
1544  wxPoint pos;
1545 
1546  pos.x = biuParse( line + SZ( "Po" ), &data );
1547  pos.y = biuParse( data );
1548 
1549  pad->SetPos0( pos );
1550  // pad->SetPosition( pos ); set at function return
1551  }
1552 
1553  else if( TESTLINE( "Le" ) )
1554  {
1555  BIU tmp = biuParse( line + SZ( "Le" ) );
1556  pad->SetPadToDieLength( tmp );
1557  }
1558 
1559  else if( TESTLINE( ".SolderMask" ) )
1560  {
1561  BIU tmp = biuParse( line + SZ( ".SolderMask" ) );
1562  pad->SetLocalSolderMaskMargin( tmp );
1563  }
1564 
1565  else if( TESTLINE( ".SolderPasteRatio" ) )
1566  {
1567  double tmp = atof( line + SZ( ".SolderPasteRatio" ) );
1568  pad->SetLocalSolderPasteMarginRatio( tmp );
1569  }
1570 
1571  else if( TESTLINE( ".SolderPaste" ) )
1572  {
1573  BIU tmp = biuParse( line + SZ( ".SolderPaste" ) );
1574  pad->SetLocalSolderPasteMargin( tmp );
1575  }
1576 
1577  else if( TESTLINE( ".LocalClearance" ) )
1578  {
1579  BIU tmp = biuParse( line + SZ( ".LocalClearance" ) );
1580  pad->SetLocalClearance( tmp );
1581  }
1582 
1583  else if( TESTLINE( ".ZoneConnection" ) )
1584  {
1585  int tmp = intParse( line + SZ( ".ZoneConnection" ) );
1586  pad->SetZoneConnection( (ZONE_CONNECTION) tmp );
1587  }
1588 
1589  else if( TESTLINE( ".ThermalWidth" ) )
1590  {
1591  BIU tmp = biuParse( line + SZ( ".ThermalWidth" ) );
1592  pad->SetThermalWidth( tmp );
1593  }
1594 
1595  else if( TESTLINE( ".ThermalGap" ) )
1596  {
1597  BIU tmp = biuParse( line + SZ( ".ThermalGap" ) );
1598  pad->SetThermalGap( tmp );
1599  }
1600 
1601  else if( TESTLINE( "$EndPAD" ) )
1602  {
1603  // pad's "Position" is not relative to the module's,
1604  // whereas Pos0 is relative to the module's but is the unrotated coordinate.
1605 
1606  wxPoint padpos = pad->GetPos0();
1607 
1608  RotatePoint( &padpos, aModule->GetOrientation() );
1609 
1610  pad->SetPosition( padpos + aModule->GetPosition() );
1611 
1612  aModule->Add( pad.release() );
1613  return; // preferred exit
1614  }
1615  }
1616 
1617  THROW_IO_ERROR( "Missing '$EndPAD'" );
1618 }
1619 
1620 
1622 {
1623  STROKE_T shape;
1624  char* line = m_reader->Line(); // obtain current (old) line
1625 
1626  switch( line[1] )
1627  {
1628  case 'S': shape = S_SEGMENT; break;
1629  case 'C': shape = S_CIRCLE; break;
1630  case 'A': shape = S_ARC; break;
1631  case 'P': shape = S_POLYGON; break;
1632  default:
1633  m_error.Printf( _( "Unknown EDGE_MODULE type:'%c=0x%02x' on line:%d of footprint:\"%s\"" ),
1634  (unsigned char) line[1],
1635  (unsigned char) line[1],
1636  m_reader->LineNumber(),
1637  GetChars( aModule->GetFPID().GetLibItemName() )
1638  );
1640  }
1641 
1642  unique_ptr<EDGE_MODULE> dwg( new EDGE_MODULE( aModule, shape ) ); // a drawing
1643 
1644  const char* data;
1645 
1646  // common to all cases, and we have to check their values uniformly at end
1647  BIU width = 1;
1649 
1650  switch( shape )
1651  {
1652  case S_ARC:
1653  {
1654  BIU start0_x = biuParse( line + SZ( "DA" ), &data );
1655  BIU start0_y = biuParse( data, &data );
1656  BIU end0_x = biuParse( data, &data );
1657  BIU end0_y = biuParse( data, &data );
1658  double angle = degParse( data, &data );
1659 
1660  width = biuParse( data, &data );
1661  layer = layerParse( data );
1662 
1663  dwg->SetAngle( angle );
1664  dwg->m_Start0 = wxPoint( start0_x, start0_y );
1665  dwg->m_End0 = wxPoint( end0_x, end0_y );
1666  }
1667  break;
1668 
1669  case S_SEGMENT:
1670  case S_CIRCLE:
1671  {
1672  // e.g. "DS -7874 -10630 7874 -10630 50 20\r\n"
1673  BIU start0_x = biuParse( line + SZ( "DS" ), &data );
1674  BIU start0_y = biuParse( data, &data );
1675  BIU end0_x = biuParse( data, &data );
1676  BIU end0_y = biuParse( data, &data );
1677 
1678  width = biuParse( data, &data );
1679  layer = layerParse( data );
1680 
1681  dwg->m_Start0 = wxPoint( start0_x, start0_y );
1682  dwg->m_End0 = wxPoint( end0_x, end0_y );
1683  }
1684  break;
1685 
1686  case S_POLYGON:
1687  {
1688  // e.g. "DP %d %d %d %d %d %d %d\n"
1689  BIU start0_x = biuParse( line + SZ( "DP" ), &data );
1690  BIU start0_y = biuParse( data, &data );
1691  BIU end0_x = biuParse( data, &data );
1692  BIU end0_y = biuParse( data, &data );
1693  int ptCount = intParse( data, &data );
1694 
1695  width = biuParse( data, &data );
1696  layer = layerParse( data );
1697 
1698  dwg->m_Start0 = wxPoint( start0_x, start0_y );
1699  dwg->m_End0 = wxPoint( end0_x, end0_y );
1700 
1701  std::vector<wxPoint> pts;
1702  pts.reserve( ptCount );
1703 
1704  for( int ii = 0; ii<ptCount; ++ii )
1705  {
1706  if( ( line = READLINE( m_reader ) ) == NULL )
1707  {
1708  THROW_IO_ERROR( "S_POLGON point count mismatch." );
1709  }
1710 
1711  // e.g. "Dl 23 44\n"
1712 
1713  if( !TESTLINE( "Dl" ) )
1714  {
1715  THROW_IO_ERROR( "Missing Dl point def" );
1716  }
1717 
1718  BIU x = biuParse( line + SZ( "Dl" ), &data );
1719  BIU y = biuParse( data );
1720 
1721  pts.emplace_back( x, y );
1722  }
1723 
1724  dwg->SetPolyPoints( pts );
1725  }
1726  break;
1727 
1728  default:
1729  // first switch code above prevents us from getting here.
1730  break;
1731  }
1732 
1733  // Check for a reasonable layer:
1734  // m_Layer must be >= FIRST_NON_COPPER_LAYER, but because microwave footprints
1735  // can use the copper layers m_Layer < FIRST_NON_COPPER_LAYER is allowed.
1736  // @todo: changes use of EDGE_MODULE these footprints and allows only
1737  // m_Layer >= FIRST_NON_COPPER_LAYER
1738  if( layer < FIRST_LAYER || layer > LAST_NON_COPPER_LAYER )
1739  layer = SILKSCREEN_N_FRONT;
1740 
1741  dwg->SetWidth( width );
1742  dwg->SetLayer( leg_layer2new( m_cu_count, layer ) );
1743 
1744  EDGE_MODULE* em = dwg.release();
1745 
1746  aModule->Add( em );
1747 
1748  // this had been done at the MODULE level before, presumably because the
1749  // EDGE_MODULE needs to be already added to a module before this function will work.
1750  em->SetDrawCoord();
1751 }
1752 
1753 
1755 {
1756  const char* data;
1757  const char* txt_end;
1758  const char* line = m_reader->Line(); // current (old) line
1759 
1760  // sscanf( line + 1, "%d %d %d %d %d %d %d %s %s %d %s",
1761  // &type, &m_Pos0.x, &m_Pos0.y, &m_Size.y, &m_Size.x,
1762  // &m_Orient, &m_Thickness, BufCar1, BufCar2, &layer, BufCar3 ) >= 10 )
1763 
1764  // e.g. "T1 6940 -16220 350 300 900 60 M I 20 N "CFCARD"\r\n"
1765  // or T1 0 500 600 400 900 80 M V 20 N"74LS245"
1766  // ouch, the last example has no space between N and "74LS245" !
1767  // that is an older version.
1768 
1769  int type = intParse( line+1, &data );
1770  BIU pos0_x = biuParse( data, &data );
1771  BIU pos0_y = biuParse( data, &data );
1772  BIU size0_y = biuParse( data, &data );
1773  BIU size0_x = biuParse( data, &data );
1774  double orient = degParse( data, &data );
1775  BIU thickn = biuParse( data, &data );
1776 
1777  // read the quoted text before the first call to strtok() which introduces
1778  // NULs into the string and chops it into mutliple C strings, something
1779  // ReadDelimitedText() cannot traverse.
1780 
1781  // convert the "quoted, escaped, UTF8, text" to a wxString, find it by skipping
1782  // as far forward as needed until the first double quote.
1783  txt_end = data + ReadDelimitedText( &m_field, data );
1784 
1785  aText->SetText( m_field );
1786 
1787  // after switching to strtok, there's no easy coming back because of the
1788  // embedded nul(s?) placed to the right of the current field.
1789  // (that's the reason why strtok was deprecated...)
1790  char* mirror = strtok_r( (char*) data, delims, (char**) &data );
1791  char* hide = strtok_r( NULL, delims, (char**) &data );
1792  char* tmp = strtok_r( NULL, delims, (char**) &data );
1793 
1794  LAYER_NUM layer_num = tmp ? layerParse( tmp ) : SILKSCREEN_N_FRONT;
1795 
1796  char* italic = strtok_r( NULL, delims, (char**) &data );
1797 
1798  char* hjust = strtok_r( (char*) txt_end, delims, (char**) &data );
1799  char* vjust = strtok_r( NULL, delims, (char**) &data );
1800 
1802  && type != TEXTE_MODULE::TEXT_is_VALUE )
1804 
1805  aText->SetType( static_cast<TEXTE_MODULE::TEXT_TYPE>( type ) );
1806 
1807  aText->SetPos0( wxPoint( pos0_x, pos0_y ) );
1808  aText->SetTextSize( wxSize( size0_x, size0_y ) );
1809 
1810  orient -= ( static_cast<MODULE*>( aText->GetParent() ) )->GetOrientation();
1811 
1812  aText->SetTextAngle( orient );
1813 
1814  // Set a reasonable width:
1815  if( thickn < 1 )
1816  thickn = 1;
1817 
1818  /* this is better left to the dialogs UIs
1819  aText->SetThickness( Clamp_Text_PenSize( thickn, aText->GetSize() ) );
1820  */
1821 
1822  aText->SetThickness( thickn );
1823 
1824  aText->SetMirrored( mirror && *mirror == 'M' );
1825 
1826  aText->SetVisible( !(hide && *hide == 'I') );
1827 
1828  aText->SetItalic( italic && *italic == 'I' );
1829 
1830  if( hjust )
1831  aText->SetHorizJustify( horizJustify( hjust ) );
1832 
1833  if( vjust )
1834  aText->SetVertJustify( vertJustify( vjust ) );
1835 
1836  // A protection against mal formed (or edited by hand) files:
1837  if( layer_num < FIRST_LAYER )
1838  layer_num = FIRST_LAYER;
1839  else if( layer_num > LAST_NON_COPPER_LAYER )
1840  layer_num = LAST_NON_COPPER_LAYER;
1841  else if( layer_num == LAYER_N_BACK )
1842  layer_num = SILKSCREEN_N_BACK;
1843  else if( layer_num == LAYER_N_FRONT )
1844  layer_num = SILKSCREEN_N_FRONT;
1845  else if( layer_num < LAYER_N_FRONT ) // this case is a internal layer
1846  layer_num = SILKSCREEN_N_FRONT;
1847 
1848  aText->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
1849 
1850  // Calculate the actual position.
1851  aText->SetDrawCoord();
1852 }
1853 
1854 
1856 {
1857  MODULE_3D_SETTINGS t3D;
1858 
1859  char* line;
1860  while( ( line = READLINE( m_reader ) ) != NULL )
1861  {
1862  if( TESTLINE( "Na" ) ) // Shape File Name
1863  {
1864  char buf[512];
1865  ReadDelimitedText( buf, line + SZ( "Na" ), sizeof(buf) );
1866  t3D.m_Filename = buf;
1867  }
1868 
1869  else if( TESTLINE( "Sc" ) ) // Scale
1870  {
1871  sscanf( line + SZ( "Sc" ), "%lf %lf %lf\n",
1872  &t3D.m_Scale.x,
1873  &t3D.m_Scale.y,
1874  &t3D.m_Scale.z );
1875  }
1876 
1877  else if( TESTLINE( "Of" ) ) // Offset
1878  {
1879  sscanf( line + SZ( "Of" ), "%lf %lf %lf\n",
1880  &t3D.m_Offset.x,
1881  &t3D.m_Offset.y,
1882  &t3D.m_Offset.z );
1883  }
1884 
1885  else if( TESTLINE( "Ro" ) ) // Rotation
1886  {
1887  sscanf( line + SZ( "Ro" ), "%lf %lf %lf\n",
1888  &t3D.m_Rotation.x,
1889  &t3D.m_Rotation.y,
1890  &t3D.m_Rotation.z );
1891  }
1892 
1893  else if( TESTLINE( "$EndSHAPE3D" ) )
1894  {
1895  aModule->Models().push_back( t3D );
1896  return; // preferred exit
1897  }
1898  }
1899 
1900  THROW_IO_ERROR( "Missing '$EndSHAPE3D'" );
1901 }
1902 
1903 
1905 {
1906  /* example:
1907  $DRAWSEGMENT
1908  Po 0 57500 -1000 57500 0 150
1909  De 24 0 900 0 0
1910  $EndDRAWSEGMENT
1911  */
1912 
1913  unique_ptr<DRAWSEGMENT> dseg( new DRAWSEGMENT( m_board ) );
1914 
1915  char* line;
1916  char* saveptr;
1917 
1918  while( ( line = READLINE( m_reader ) ) != NULL )
1919  {
1920  const char* data;
1921 
1922  if( TESTLINE( "Po" ) )
1923  {
1924  int shape = intParse( line + SZ( "Po" ), &data );
1925  BIU start_x = biuParse( data, &data );
1926  BIU start_y = biuParse( data, &data );
1927  BIU end_x = biuParse( data, &data );
1928  BIU end_y = biuParse( data, &data );
1929  BIU width = biuParse( data );
1930 
1931  if( width < 0 )
1932  width = 0;
1933 
1934  dseg->SetShape( STROKE_T( shape ) );
1935  dseg->SetWidth( width );
1936  dseg->SetStart( wxPoint( start_x, start_y ) );
1937  dseg->SetEnd( wxPoint( end_x, end_y ) );
1938  }
1939 
1940  else if( TESTLINE( "De" ) )
1941  {
1942  BIU x = 0;
1943  BIU y;
1944 
1945  data = strtok_r( line + SZ( "De" ), delims, &saveptr );
1946  for( int i = 0; data; ++i, data = strtok_r( NULL, delims, &saveptr ) )
1947  {
1948  switch( i )
1949  {
1950  case 0:
1951  LAYER_NUM layer;
1952  layer = layerParse( data );
1953 
1954  if( layer < FIRST_NON_COPPER_LAYER )
1955  layer = FIRST_NON_COPPER_LAYER;
1956 
1957  else if( layer > LAST_NON_COPPER_LAYER )
1958  layer = LAST_NON_COPPER_LAYER;
1959 
1960  dseg->SetLayer( leg_layer2new( m_cu_count, layer ) );
1961  break;
1962  case 1:
1963  int mtype;
1964  mtype = intParse( data );
1965  dseg->SetType( mtype ); // m_Type
1966  break;
1967  case 2:
1968  double angle;
1969  angle = degParse( data );
1970  dseg->SetAngle( angle ); // m_Angle
1971  break;
1972  case 3:
1973  const_cast<KIID&>( dseg->m_Uuid ) = KIID( data );
1974  break;
1975  case 4:
1976  STATUS_FLAGS state;
1977  state = static_cast<STATUS_FLAGS>( hexParse( data ) );
1978  dseg->SetState( state, true );
1979  break;
1980 
1981  // Bezier Control Points
1982  case 5:
1983  x = biuParse( data );
1984  break;
1985  case 6:
1986  y = biuParse( data );
1987  dseg->SetBezControl1( wxPoint( x, y ) );
1988  break;
1989 
1990  case 7:
1991  x = biuParse( data );
1992  break;
1993  case 8:
1994  y = biuParse( data );
1995  dseg->SetBezControl2( wxPoint( x, y ) );
1996  break;
1997 
1998  default:
1999  break;
2000  }
2001  }
2002  }
2003 
2004  else if( TESTLINE( "$EndDRAWSEGMENT" ) )
2005  {
2006  m_board->Add( dseg.release(), ADD_MODE::APPEND );
2007  return; // preferred exit
2008  }
2009  }
2010 
2011  THROW_IO_ERROR( "Missing '$EndDRAWSEGMENT'" );
2012 }
2013 
2015 {
2016  /* a net description is something like
2017  * $EQUIPOT
2018  * Na 5 "/BIT1"
2019  * St ~
2020  * $EndEQUIPOT
2021  */
2022 
2023  char buf[1024];
2024 
2025  NETINFO_ITEM* net = NULL;
2026  char* line;
2027  int netCode = 0;
2028 
2029  while( ( line = READLINE( m_reader ) ) != NULL )
2030  {
2031  const char* data;
2032 
2033  if( TESTLINE( "Na" ) )
2034  {
2035  // e.g. "Na 58 "/cpu.sch/PAD7"\r\n"
2036 
2037  netCode = intParse( line + SZ( "Na" ), &data );
2038 
2039  ReadDelimitedText( buf, data, sizeof(buf) );
2040 
2041  if( net == NULL )
2042  net = new NETINFO_ITEM( m_board, FROM_UTF8( buf ), netCode );
2043  else
2044  {
2045  THROW_IO_ERROR( "Two net definitions in '$EQUIPOT' block" );
2046  }
2047  }
2048 
2049  else if( TESTLINE( "$EndEQUIPOT" ) )
2050  {
2051  // net 0 should be already in list, so store this net
2052  // if it is not the net 0, or if the net 0 does not exists.
2053  if( net && ( net->GetNet() > 0 || m_board->FindNet( 0 ) == NULL ) )
2054  {
2055  m_board->Add( net );
2056 
2057  // Be sure we have room to store the net in m_netCodes
2058  if( (int)m_netCodes.size() <= netCode )
2059  m_netCodes.resize( netCode+1 );
2060 
2061  m_netCodes[netCode] = net->GetNet();
2062  net = NULL;
2063  }
2064  else
2065  {
2066  delete net;
2067  net = NULL; // Avoid double deletion.
2068  }
2069 
2070  return; // preferred exit
2071  }
2072  }
2073 
2074  // If we are here, there is an error.
2075  delete net;
2076  THROW_IO_ERROR( "Missing '$EndEQUIPOT'" );
2077 }
2078 
2079 
2081 {
2082  /* examples:
2083  For a single line text:
2084  ----------------------
2085  $TEXTPCB
2086  Te "Text example"
2087  Po 66750 53450 600 800 150 0
2088  De 24 1 0 Italic
2089  $EndTEXTPCB
2090 
2091  For a multi line text:
2092  ---------------------
2093  $TEXTPCB
2094  Te "Text example"
2095  Nl "Line 2"
2096  Po 66750 53450 600 800 150 0
2097  De 24 1 0 Italic
2098  $EndTEXTPCB
2099  Nl "line nn" is a line added to the current text
2100  */
2101 
2102  char text[1024];
2103 
2104  // maybe someday a constructor that takes all this data in one call?
2105  TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
2106  m_board->Add( pcbtxt, ADD_MODE::APPEND );
2107 
2108  char* line;
2109 
2110  while( ( line = READLINE( m_reader ) ) != NULL )
2111  {
2112  const char* data;
2113 
2114  if( TESTLINE( "Te" ) ) // Text line (or first line for multi line texts)
2115  {
2116  ReadDelimitedText( text, line + SZ( "Te" ), sizeof(text) );
2117  pcbtxt->SetText( FROM_UTF8( text ) );
2118  }
2119 
2120  else if( TESTLINE( "nl" ) ) // next line of the current text
2121  {
2122  ReadDelimitedText( text, line + SZ( "nl" ), sizeof(text) );
2123  pcbtxt->SetText( pcbtxt->GetText() + wxChar( '\n' ) + FROM_UTF8( text ) );
2124  }
2125 
2126  else if( TESTLINE( "Po" ) )
2127  {
2128  wxSize size;
2129 
2130  BIU pos_x = biuParse( line + SZ( "Po" ), &data );
2131  BIU pos_y = biuParse( data, &data );
2132  size.x = biuParse( data, &data );
2133  size.y = biuParse( data, &data );
2134  BIU thickn = biuParse( data, &data );
2135  double angle = degParse( data );
2136 
2137  pcbtxt->SetTextSize( size );
2138 
2139  pcbtxt->SetThickness( thickn );
2140  pcbtxt->SetTextAngle( angle );
2141 
2142  pcbtxt->SetTextPos( wxPoint( pos_x, pos_y ) );
2143  }
2144 
2145  else if( TESTLINE( "De" ) )
2146  {
2147  // e.g. "De 21 1 68183921-93a5-49ac-91b0-49d05a0e1647 Normal C\r\n"
2148  LAYER_NUM layer_num = layerParse( line + SZ( "De" ), &data );
2149  int notMirrored = intParse( data, &data );
2150  char* uuid = strtok_r( (char*) data, delims, (char**) &data );
2151  char* style = strtok_r( NULL, delims, (char**) &data );
2152  char* hJustify = strtok_r( NULL, delims, (char**) &data );
2153  char* vJustify = strtok_r( NULL, delims, (char**) &data );
2154 
2155  pcbtxt->SetMirrored( !notMirrored );
2156  const_cast<KIID&>( pcbtxt->m_Uuid ) = KIID( uuid );
2157  pcbtxt->SetItalic( !strcmp( style, "Italic" ) );
2158 
2159  if( hJustify )
2160  pcbtxt->SetHorizJustify( horizJustify( hJustify ) );
2161  else
2162  {
2163  // boom, somebody changed a constructor, I was relying on this:
2164  wxASSERT( pcbtxt->GetHorizJustify() == GR_TEXT_HJUSTIFY_CENTER );
2165  }
2166 
2167  if( vJustify )
2168  pcbtxt->SetVertJustify( vertJustify( vJustify ) );
2169 
2170  if( layer_num < FIRST_COPPER_LAYER )
2171  layer_num = FIRST_COPPER_LAYER;
2172  else if( layer_num > LAST_NON_COPPER_LAYER )
2173  layer_num = LAST_NON_COPPER_LAYER;
2174 
2175  if( layer_num >= FIRST_NON_COPPER_LAYER ||
2176  is_leg_copperlayer_valid( m_cu_count, layer_num ) )
2177  pcbtxt->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
2178  else // not perfect, but putting this text on front layer is a workaround
2179  pcbtxt->SetLayer( F_Cu );
2180  }
2181 
2182  else if( TESTLINE( "$EndTEXTPCB" ) )
2183  {
2184  return; // preferred exit
2185  }
2186  }
2187 
2188  THROW_IO_ERROR( "Missing '$EndTEXTPCB'" );
2189 }
2190 
2191 
2192 void LEGACY_PLUGIN::loadTrackList( int aStructType )
2193 {
2194  char* line;
2195 
2196  while( ( line = READLINE( m_reader ) ) != NULL )
2197  {
2198  // read two lines per loop iteration, each loop is one TRACK or VIA
2199  // example first line:
2200  // e.g. "Po 0 23994 28800 24400 28800 150 -1" for a track
2201  // e.g. "Po 3 21086 17586 21086 17586 180 -1" for a via (uses sames start and end)
2202  const char* data;
2203 
2204  if( line[0] == '$' ) // $EndTRACK
2205  return; // preferred exit
2206 
2207  assert( TESTLINE( "Po" ) );
2208 
2209  VIATYPE viatype = static_cast<VIATYPE>( intParse( line + SZ( "Po" ), &data ) );
2210  BIU start_x = biuParse( data, &data );
2211  BIU start_y = biuParse( data, &data );
2212  BIU end_x = biuParse( data, &data );
2213  BIU end_y = biuParse( data, &data );
2214  BIU width = biuParse( data, &data );
2215 
2216  // optional 7th drill parameter (must be optional in an old format?)
2217  data = strtok_r( (char*) data, delims, (char**) &data );
2218 
2219  BIU drill = data ? biuParse( data ) : -1; // SetDefault() if < 0
2220 
2221  // Read the 2nd line to determine the exact type, one of:
2222  // PCB_TRACE_T, PCB_VIA_T, or PCB_SEGZONE_T. The type field in 2nd line
2223  // differentiates between PCB_TRACE_T and PCB_VIA_T. With virtual
2224  // functions in use, it is critical to instantiate the PCB_VIA_T
2225  // exactly.
2226  READLINE( m_reader );
2227 
2228  line = m_reader->Line();
2229 
2230  // example second line:
2231  // "De 0 0 463 0 800000\r\n"
2232 
2233 #if 1
2234  assert( TESTLINE( "De" ) );
2235 #else
2236  if( !TESTLINE( "De" ) )
2237  {
2238  // mandatory 2nd line is missing
2239  THROW_IO_ERROR( "Missing 2nd line of a TRACK def" );
2240  }
2241 #endif
2242 
2243  int makeType;
2244 
2245  // parse the 2nd line to determine the type of object
2246  // e.g. "De 15 1 7 68183921-93a5-49ac-91b0-49d05a0e1647 0" for a via
2247  LAYER_NUM layer_num = layerParse( line + SZ( "De" ), &data );
2248  int type = intParse( data, &data );
2249  int net_code = intParse( data, &data );
2250  char* uuid = strtok_r( (char*) data, delims, (char**) &data );
2251  int flags_int = intParse( data, (const char**) &data );
2252 
2253  STATUS_FLAGS flags = static_cast<STATUS_FLAGS>( flags_int );
2254 
2255  if( aStructType == PCB_TRACE_T )
2256  {
2257  makeType = ( type == 1 ) ? PCB_VIA_T : PCB_TRACE_T;
2258  }
2259  else if (aStructType == NOT_USED )
2260  {
2261  continue;
2262  }
2263  else
2264  {
2265  wxFAIL_MSG( "Segment type unknown" );
2266  continue;
2267  }
2268 
2269  TRACK* newTrack;
2270 
2271  switch( makeType )
2272  {
2273  default:
2274  case PCB_TRACE_T: newTrack = new TRACK( m_board ); break;
2275  case PCB_VIA_T: newTrack = new VIA( m_board ); break;
2276  }
2277 
2278  const_cast<KIID&>( newTrack->m_Uuid ) = KIID( uuid );
2279  newTrack->SetPosition( wxPoint( start_x, start_y ) );
2280  newTrack->SetEnd( wxPoint( end_x, end_y ) );
2281 
2282  newTrack->SetWidth( width );
2283 
2284  if( makeType == PCB_VIA_T ) // Ensure layers are OK when possible:
2285  {
2286  VIA *via = static_cast<VIA*>( newTrack );
2287  via->SetViaType( viatype );
2288 
2289  if( drill < 0 )
2290  via->SetDrillDefault();
2291  else
2292  via->SetDrill( drill );
2293 
2294  if( via->GetViaType() == VIATYPE::THROUGH )
2295  via->SetLayerPair( F_Cu, B_Cu );
2296  else
2297  {
2298  PCB_LAYER_ID back = leg_layer2new( m_cu_count, (layer_num >> 4) & 0xf );
2299  PCB_LAYER_ID front = leg_layer2new( m_cu_count, layer_num & 0xf );
2300 
2301  if( is_leg_copperlayer_valid( m_cu_count, back ) &&
2303  via->SetLayerPair( front, back );
2304  else
2305  {
2306  delete via;
2307  newTrack = NULL;
2308  }
2309  }
2310  }
2311  else
2312  {
2313  // A few legacy boards can have tracks on non existent layers, because
2314  // reducing the number of layers does not remove tracks on removed layers
2315  // If happens, skip them
2316  if( is_leg_copperlayer_valid( m_cu_count, layer_num ) )
2317  newTrack->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
2318  else
2319  {
2320  delete newTrack;
2321  newTrack = NULL;
2322  }
2323  }
2324 
2325  if( newTrack )
2326  {
2327  newTrack->SetNetCode( getNetCode( net_code ) );
2328  newTrack->SetState( flags, true );
2329 
2330  m_board->Add( newTrack );
2331  }
2332  }
2333 
2334  THROW_IO_ERROR( "Missing '$EndTRACK'" );
2335 }
2336 
2337 
2339 {
2340  char buf[1024];
2341  wxString netname;
2342  char* line;
2343 
2344  // create an empty NETCLASS without a name, but do not add it to the BOARD
2345  // yet since that would bypass duplicate netclass name checking within the BOARD.
2346  // store it temporarily in an unique_ptr until successfully inserted into the BOARD
2347  // just before returning.
2348  NETCLASSPTR nc = std::make_shared<NETCLASS>( wxEmptyString );
2349 
2350  while( ( line = READLINE( m_reader ) ) != NULL )
2351  {
2352  if( TESTLINE( "AddNet" ) ) // most frequent type of line
2353  {
2354  // e.g. "AddNet "V3.3D"\n"
2355  ReadDelimitedText( buf, line + SZ( "AddNet" ), sizeof(buf) );
2356  netname = FROM_UTF8( buf );
2357  nc->Add( netname );
2358  }
2359 
2360  else if( TESTLINE( "Clearance" ) )
2361  {
2362  BIU tmp = biuParse( line + SZ( "Clearance" ) );
2363  nc->SetClearance( tmp );
2364  }
2365 
2366  else if( TESTLINE( "TrackWidth" ) )
2367  {
2368  BIU tmp = biuParse( line + SZ( "TrackWidth" ) );
2369  nc->SetTrackWidth( tmp );
2370  }
2371 
2372  else if( TESTLINE( "ViaDia" ) )
2373  {
2374  BIU tmp = biuParse( line + SZ( "ViaDia" ) );
2375  nc->SetViaDiameter( tmp );
2376  }
2377 
2378  else if( TESTLINE( "ViaDrill" ) )
2379  {
2380  BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
2381  nc->SetViaDrill( tmp );
2382  }
2383 
2384  else if( TESTLINE( "uViaDia" ) )
2385  {
2386  BIU tmp = biuParse( line + SZ( "uViaDia" ) );
2387  nc->SetuViaDiameter( tmp );
2388  }
2389 
2390  else if( TESTLINE( "uViaDrill" ) )
2391  {
2392  BIU tmp = biuParse( line + SZ( "uViaDrill" ) );
2393  nc->SetuViaDrill( tmp );
2394  }
2395 
2396  else if( TESTLINE( "Name" ) )
2397  {
2398  ReadDelimitedText( buf, line + SZ( "Name" ), sizeof(buf) );
2399  nc->SetName( FROM_UTF8( buf ) );
2400  }
2401 
2402  else if( TESTLINE( "Desc" ) )
2403  {
2404  ReadDelimitedText( buf, line + SZ( "Desc" ), sizeof(buf) );
2405  nc->SetDescription( FROM_UTF8( buf ) );
2406  }
2407 
2408  else if( TESTLINE( "$EndNCLASS" ) )
2409  {
2410  if( !m_board->GetDesignSettings().m_NetClasses.Add( nc ) )
2411  {
2412  // Must have been a name conflict, this is a bad board file.
2413  // User may have done a hand edit to the file.
2414 
2415  // unique_ptr will delete nc on this code path
2416 
2417  m_error.Printf( _( "duplicate NETCLASS name \"%s\"" ), nc->GetName().GetData() );
2419  }
2420 
2421  return; // preferred exit
2422  }
2423  }
2424 
2425  THROW_IO_ERROR( "Missing '$EndNCLASS'" );
2426 }
2427 
2428 
2430 {
2431  unique_ptr<ZONE_CONTAINER> zc( new ZONE_CONTAINER( m_board ) );
2432 
2434  bool endContour = false;
2435  int holeIndex = -1; // -1 is the main outline; holeIndex >= 0 = hole index
2436  char buf[1024];
2437  char* line;
2438 
2439  while( ( line = READLINE( m_reader ) ) != NULL )
2440  {
2441  const char* data;
2442 
2443  if( TESTLINE( "ZCorner" ) ) // new corner of the zone outlines found
2444  {
2445  // e.g. "ZCorner 25650 49500 0"
2446  BIU x = biuParse( line + SZ( "ZCorner" ), &data );
2447  BIU y = biuParse( data, &data );
2448 
2449  if( endContour )
2450  {
2451  // the previous corner was the last corner of a contour.
2452  // so this corner is the first of a new hole
2453  endContour = false;
2454  zc->NewHole();
2455  holeIndex++;
2456  }
2457 
2458  zc->AppendCorner( wxPoint( x, y ), holeIndex );
2459 
2460  // Is this corner the end of current contour?
2461  // the next corner (if any) will be stored in a new contour (a hole)
2462  // intParse( data )returns 0 = usual corner, 1 = last corner of the current contour:
2463  endContour = intParse( data );
2464  }
2465 
2466  else if( TESTLINE( "ZInfo" ) ) // general info found
2467  {
2468  // e.g. 'ZInfo 68183921-93a5-49ac-91b0-49d05a0e1647 310 "COMMON"'
2469  char* uuid = strtok_r( (char*) line + SZ( "ZInfo" ), delims, (char**) &data );
2470  int netcode = intParse( data, &data );
2471 
2472  if( ReadDelimitedText( buf, data, sizeof(buf) ) > (int) sizeof(buf) )
2473  THROW_IO_ERROR( "ZInfo netname too long" );
2474 
2475  const_cast<KIID&>( zc->m_Uuid ) = KIID( uuid );
2476  // Init the net code only, not the netname, to be sure
2477  // the zone net name is the name read in file.
2478  // (When mismatch, the user will be prompted in DRC, to fix the actual name)
2479  zc->BOARD_CONNECTED_ITEM::SetNetCode( getNetCode( netcode ) );
2480  }
2481 
2482  else if( TESTLINE( "ZLayer" ) ) // layer found
2483  {
2484  LAYER_NUM layer_num = layerParse( line + SZ( "ZLayer" ) );
2485  zc->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
2486  }
2487 
2488  else if( TESTLINE( "ZAux" ) ) // aux info found
2489  {
2490  // e.g. "ZAux 7 E"
2491  int ignore = intParse( line + SZ( "ZAux" ), &data );
2492  char* hopt = strtok_r( (char*) data, delims, (char**) &data );
2493 
2494  if( !hopt )
2495  {
2496  m_error.Printf( _( "Bad ZAux for CZONE_CONTAINER \"%s\"" ),
2497  zc->GetNetname().GetData() );
2499  }
2500 
2501  switch( *hopt ) // upper case required
2502  {
2503  case 'N': outline_hatch = ZONE_HATCH_STYLE::NO_HATCH; break;
2504  case 'E': outline_hatch = ZONE_HATCH_STYLE::DIAGONAL_EDGE; break;
2505  case 'F': outline_hatch = ZONE_HATCH_STYLE::DIAGONAL_FULL; break;
2506  default:
2507  m_error.Printf( _( "Bad ZAux for CZONE_CONTAINER \"%s\"" ),
2508  zc->GetNetname().GetData() );
2510  }
2511 
2512  (void) ignore;
2513 
2514  // Set hatch mode later, after reading corner outline data
2515  }
2516 
2517  else if( TESTLINE( "ZSmoothing" ) )
2518  {
2519  // e.g. "ZSmoothing 0 0"
2520  int smoothing = intParse( line + SZ( "ZSmoothing" ), &data );
2521  BIU cornerRadius = biuParse( data );
2522 
2523  if( smoothing >= ZONE_SETTINGS::SMOOTHING_LAST || smoothing < 0 )
2524  {
2525  m_error.Printf( _( "Bad ZSmoothing for CZONE_CONTAINER \"%s\"" ),
2526  zc->GetNetname().GetData() );
2528  }
2529 
2530  zc->SetCornerSmoothingType( smoothing );
2531  zc->SetCornerRadius( cornerRadius );
2532  }
2533 
2534  else if( TESTLINE( "ZKeepout" ) )
2535  {
2536  char* token;
2537  zc->SetIsKeepout( true );
2538  // e.g. "ZKeepout tracks N vias N pads Y"
2539  token = strtok_r( line + SZ( "ZKeepout" ), delims, (char**) &data );
2540 
2541  while( token )
2542  {
2543  if( !strcmp( token, "tracks" ) )
2544  {
2545  token = strtok_r( NULL, delims, (char**) &data );
2546  zc->SetDoNotAllowTracks( token && *token == 'N' );
2547  }
2548  else if( !strcmp( token, "vias" ) )
2549  {
2550  token = strtok_r( NULL, delims, (char**) &data );
2551  zc->SetDoNotAllowVias( token && *token == 'N' );
2552  }
2553  else if( !strcmp( token, "copperpour" ) )
2554  {
2555  token = strtok_r( NULL, delims, (char**) &data );
2556  zc->SetDoNotAllowCopperPour( token && *token == 'N' );
2557  }
2558 
2559  token = strtok_r( NULL, delims, (char**) &data );
2560  }
2561  }
2562 
2563  else if( TESTLINE( "ZOptions" ) )
2564  {
2565  // e.g. "ZOptions 0 32 F 200 200"
2566  int fillmode = intParse( line + SZ( "ZOptions" ), &data );
2567  static_cast<void>( intParse( data, &data ) ); // Ignored
2568  char fillstate = data[1]; // here e.g. " F"
2569  BIU thermalReliefGap = biuParse( data += 2 , &data ); // +=2 for " F"
2570  BIU thermalReliefCopperBridge = biuParse( data );
2571 
2572  if( fillmode)
2573  {
2574  // SEGMENT fill mode no longer supported. Make sure user is OK with converting them.
2576  {
2577  KIDIALOG dlg( nullptr,
2578  _( "The legacy segment fill mode is no longer supported.\n"
2579  "Convert zones to polygon fills?"),
2580  _( "Legacy Zone Warning" ),
2581  wxYES_NO | wxICON_WARNING );
2582 
2583  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
2584 
2585  if( dlg.ShowModal() == wxID_NO )
2586  THROW_IO_ERROR( wxT( "CANCEL" ) );
2587 
2588  m_showLegacyZoneWarning = false;
2589  }
2590 
2591  // User OK'd; switch to polygon mode
2592  zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
2593  m_board->SetModified();
2594  }
2595  else
2596  zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
2597 
2598  zc->SetIsFilled( fillstate == 'S' );
2599  zc->SetThermalReliefGap( thermalReliefGap );
2600  zc->SetThermalReliefCopperBridge( thermalReliefCopperBridge );
2601  }
2602 
2603  else if( TESTLINE( "ZClearance" ) ) // Clearance and pad options info found
2604  {
2605  // e.g. "ZClearance 40 I"
2606  BIU clearance = biuParse( line + SZ( "ZClearance" ), &data );
2607  char* padoption = strtok_r( (char*) data, delims, (char**) &data ); // data: " I"
2608 
2609  ZONE_CONNECTION popt;
2610  switch( *padoption )
2611  {
2612  case 'I': popt = ZONE_CONNECTION::FULL; break;
2613  case 'T': popt = ZONE_CONNECTION::THERMAL; break;
2614  case 'H': popt = ZONE_CONNECTION::THT_THERMAL; break;
2615  case 'X': popt = ZONE_CONNECTION::NONE; break;
2616  default:
2617  m_error.Printf( _( "Bad ZClearance padoption for CZONE_CONTAINER \"%s\"" ),
2618  zc->GetNetname().GetData() );
2620  }
2621 
2622  zc->SetZoneClearance( clearance );
2623  zc->SetPadConnection( popt );
2624  }
2625 
2626  else if( TESTLINE( "ZMinThickness" ) )
2627  {
2628  BIU thickness = biuParse( line + SZ( "ZMinThickness" ) );
2629  zc->SetMinThickness( thickness );
2630  }
2631 
2632  else if( TESTLINE( "ZPriority" ) )
2633  {
2634  int priority = intParse( line + SZ( "ZPriority" ) );
2635  zc->SetPriority( priority );
2636  }
2637 
2638  else if( TESTLINE( "$POLYSCORNERS" ) )
2639  {
2640  // Read the PolysList (polygons that are the solid areas in the filled zone)
2641  SHAPE_POLY_SET polysList;
2642 
2643  bool makeNewOutline = true;
2644 
2645  while( ( line = READLINE( m_reader ) ) != NULL )
2646  {
2647  if( TESTLINE( "$endPOLYSCORNERS" ) )
2648  break;
2649 
2650  // e.g. "39610 43440 0 0"
2651  BIU x = biuParse( line, &data );
2652  BIU y = biuParse( data, &data );
2653 
2654  if( makeNewOutline )
2655  polysList.NewOutline();
2656 
2657  polysList.Append( x, y );
2658 
2659  bool end_contour = intParse( data, &data ); // end_countour was a bool when file saved, so '0' or '1' here
2660  intParse( data ); // skip corner utility flag
2661 
2662  makeNewOutline = end_contour;
2663  }
2664 
2665  zc->SetFilledPolysList( polysList );
2666  }
2667 
2668  else if( TESTLINE( "$FILLSEGMENTS" ) )
2669  {
2670  while( ( line = READLINE( m_reader ) ) != NULL )
2671  {
2672  if( TESTLINE( "$endFILLSEGMENTS" ) )
2673  break;
2674 
2675  // e.g. ""%d %d %d %d\n"
2676  BIU sx = biuParse( line, &data );
2677  BIU sy = biuParse( data, &data );
2678  BIU ex = biuParse( data, &data );
2679  BIU ey = biuParse( data );
2680 
2681  zc->FillSegments().push_back( SEG( VECTOR2I( sx, sy ), VECTOR2I( ex, ey ) ) );
2682  }
2683  }
2684 
2685  else if( TESTLINE( "$endCZONE_OUTLINE" ) )
2686  {
2687  // Ensure keepout does not have a net
2688  // (which have no sense for a keepout zone)
2689  if( zc->GetIsKeepout() )
2690  zc->SetNetCode( NETINFO_LIST::UNCONNECTED );
2691 
2692  // should always occur, but who knows, a zone without two corners
2693  // is no zone at all, it's a spot?
2694 
2695  if( zc->GetNumCorners() > 2 )
2696  {
2697  if( !zc->IsOnCopperLayer() )
2698  {
2699  zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
2700  zc->SetNetCode( NETINFO_LIST::UNCONNECTED );
2701  }
2702 
2703  // Hatch here, after outlines corners are read
2704  // Set hatch here, after outlines corners are read
2705  zc->SetHatch( outline_hatch, ZONE_CONTAINER::GetDefaultHatchPitch(),
2706  true );
2707 
2708  m_board->Add( zc.release() );
2709  }
2710 
2711  return; // preferred exit
2712  }
2713  }
2714 
2715  THROW_IO_ERROR( "Missing '$endCZONE_OUTLINE'" );
2716 }
2717 
2718 
2720 {
2721  unique_ptr<DIMENSION> dim( new DIMENSION( m_board ) );
2722 
2723  char* line;
2724 
2725  while( ( line = READLINE( m_reader ) ) != NULL )
2726  {
2727  const char* data;
2728 
2729  if( TESTLINE( "$endCOTATION" ) )
2730  {
2731  m_board->Add( dim.release(), ADD_MODE::APPEND );
2732  return; // preferred exit
2733  }
2734 
2735  else if( TESTLINE( "Va" ) )
2736  {
2737  BIU value = biuParse( line + SZ( "Va" ) );
2738  dim->SetValue( value );
2739  }
2740 
2741  else if( TESTLINE( "Ge" ) )
2742  {
2743  // e.g. "Ge 1 21 68183921-93a5-49ac-91b0-49d05a0e1647\r\n"
2744  int shape = intParse( line + SZ( "De" ), (const char**) &data );
2745  LAYER_NUM layer_num = layerParse( data, &data );
2746  char* uuid = strtok_r( (char*) data, delims, (char**) &data );
2747 
2748  dim->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
2749  const_cast<KIID&>( dim->m_Uuid ) = KIID( uuid );
2750  dim->SetShape( shape );
2751  }
2752 
2753  else if( TESTLINE( "Te" ) )
2754  {
2755  char buf[2048];
2756 
2757  ReadDelimitedText( buf, line + SZ( "Te" ), sizeof(buf) );
2758  dim->SetText( FROM_UTF8( buf ) );
2759  }
2760 
2761  else if( TESTLINE( "Po" ) )
2762  {
2763  BIU pos_x = biuParse( line + SZ( "Po" ), &data );
2764  BIU pos_y = biuParse( data, &data );
2765  BIU width = biuParse( data, &data );
2766  BIU height = biuParse( data, &data );
2767  BIU thickn = biuParse( data, &data );
2768  double orient = degParse( data, &data );
2769  char* mirror = strtok_r( (char*) data, delims, (char**) &data );
2770 
2771  // This sets both DIMENSION's position and internal m_Text's.
2772  // @todo: But why do we even know about internal m_Text?
2773  dim->SetPosition( wxPoint( pos_x, pos_y ) );
2774  dim->SetTextSize( wxSize( width, height ) );
2775 
2776  dim->Text().SetMirrored( mirror && *mirror == '0' );
2777  dim->Text().SetThickness( thickn );
2778  dim->Text().SetTextAngle( orient );
2779  }
2780 
2781  else if( TESTLINE( "Sb" ) )
2782  {
2783  int ignore = biuParse( line + SZ( "Sb" ), &data );
2784  BIU crossBarOx = biuParse( data, &data );
2785  BIU crossBarOy = biuParse( data, &data );
2786  BIU crossBarFx = biuParse( data, &data );
2787  BIU crossBarFy = biuParse( data, &data );
2788  BIU width = biuParse( data );
2789 
2790  dim->m_crossBarO.x = crossBarOx;
2791  dim->m_crossBarO.y = crossBarOy;
2792  dim->m_crossBarF.x = crossBarFx;
2793  dim->m_crossBarF.y = crossBarFy;
2794  dim->SetWidth( width );
2795  (void) ignore;
2796  }
2797 
2798  else if( TESTLINE( "Sd" ) )
2799  {
2800  int ignore = intParse( line + SZ( "Sd" ), &data );
2801  BIU featureLineDOx = biuParse( data, &data );
2802  BIU featureLineDOy = biuParse( data, &data );
2803  BIU featureLineDFx = biuParse( data, &data );
2804  BIU featureLineDFy = biuParse( data );
2805 
2806  dim->m_featureLineDO.x = featureLineDOx;
2807  dim->m_featureLineDO.y = featureLineDOy;
2808  dim->m_featureLineDF.x = featureLineDFx;
2809  dim->m_featureLineDF.y = featureLineDFy;
2810  (void) ignore;
2811  }
2812 
2813  else if( TESTLINE( "Sg" ) )
2814  {
2815  int ignore = intParse( line + SZ( "Sg" ), &data );
2816  BIU featureLineGOx = biuParse( data, &data );
2817  BIU featureLineGOy = biuParse( data, &data );
2818  BIU featureLineGFx = biuParse( data, &data );
2819  BIU featureLineGFy = biuParse( data );
2820 
2821  dim->m_featureLineGO.x = featureLineGOx;
2822  dim->m_featureLineGO.y = featureLineGOy;
2823  dim->m_featureLineGF.x = featureLineGFx;
2824  dim->m_featureLineGF.y = featureLineGFy;
2825  (void) ignore;
2826  }
2827 
2828  else if( TESTLINE( "S1" ) )
2829  {
2830  int ignore = intParse( line + SZ( "S1" ), &data );
2831  biuParse( data, &data ); // skipping excessive data
2832  biuParse( data, &data ); // skipping excessive data
2833  BIU arrowD1Fx = biuParse( data, &data );
2834  BIU arrowD1Fy = biuParse( data );
2835 
2836  dim->m_arrowD1F.x = arrowD1Fx;
2837  dim->m_arrowD1F.y = arrowD1Fy;
2838  (void) ignore;
2839  }
2840 
2841  else if( TESTLINE( "S2" ) )
2842  {
2843  int ignore = intParse( line + SZ( "S2" ), &data );
2844  biuParse( data, &data ); // skipping excessive data
2845  biuParse( data, &data ); // skipping excessive data
2846  BIU arrowD2Fx = biuParse( data, &data );
2847  BIU arrowD2Fy = biuParse( data, &data );
2848 
2849  dim->m_arrowD2F.x = arrowD2Fx;
2850  dim->m_arrowD2F.y = arrowD2Fy;
2851  (void) ignore;
2852  }
2853 
2854  else if( TESTLINE( "S3" ) )
2855  {
2856  int ignore = intParse( line + SZ( "S3" ), &data );
2857  biuParse( data, &data ); // skipping excessive data
2858  biuParse( data, &data ); // skipping excessive data
2859  BIU arrowG1Fx = biuParse( data, &data );
2860  BIU arrowG1Fy = biuParse( data, &data );
2861 
2862  dim->m_arrowG1F.x = arrowG1Fx;
2863  dim->m_arrowG1F.y = arrowG1Fy;
2864  (void) ignore;
2865  }
2866 
2867  else if( TESTLINE( "S4" ) )
2868  {
2869  int ignore = intParse( line + SZ( "S4" ), &data );
2870  biuParse( data, &data ); // skipping excessive data
2871  biuParse( data, &data ); // skipping excessive data
2872  BIU arrowG2Fx = biuParse( data, &data );
2873  BIU arrowG2Fy = biuParse( data, &data );
2874 
2875  dim->m_arrowG2F.x = arrowG2Fx;
2876  dim->m_arrowG2F.y = arrowG2Fy;
2877  (void) ignore;
2878  }
2879  }
2880 
2881  THROW_IO_ERROR( "Missing '$endCOTATION'" );
2882 }
2883 
2884 
2886 {
2887  char* line;
2888 
2889  while( ( line = READLINE( m_reader ) ) != NULL )
2890  {
2891  const char* data;
2892 
2893  if( TESTLINE( "$EndPCB_TARGET" ) || TESTLINE( "$EndMIREPCB" ) )
2894  {
2895  return; // preferred exit
2896  }
2897 
2898  else if( TESTLINE( "Po" ) )
2899  {
2900  int shape = intParse( line + SZ( "Po" ), &data );
2901  LAYER_NUM layer_num = layerParse( data, &data );
2902  BIU pos_x = biuParse( data, &data );
2903  BIU pos_y = biuParse( data, &data );
2904  BIU size = biuParse( data, &data );
2905  BIU width = biuParse( data, &data );
2906  char* uuid = strtok_r( (char*) data, delims, (char**) &data );
2907 
2908  if( layer_num < FIRST_NON_COPPER_LAYER )
2909  layer_num = FIRST_NON_COPPER_LAYER;
2910 
2911  else if( layer_num > LAST_NON_COPPER_LAYER )
2912  layer_num = LAST_NON_COPPER_LAYER;
2913 
2914  PCB_TARGET* t = new PCB_TARGET( m_board, shape, leg_layer2new( m_cu_count, layer_num ),
2915  wxPoint( pos_x, pos_y ), size, width );
2916  m_board->Add( t, ADD_MODE::APPEND );
2917 
2918  const_cast<KIID&>( t->m_Uuid ) = KIID( uuid );
2919  }
2920  }
2921 
2922  THROW_IO_ERROR( "Missing '$EndDIMENSION'" );
2923 }
2924 
2925 
2926 BIU LEGACY_PLUGIN::biuParse( const char* aValue, const char** nptrptr )
2927 {
2928  char* nptr;
2929 
2930  errno = 0;
2931 
2932  double fval = strtod( aValue, &nptr );
2933 
2934  if( errno )
2935  {
2936  m_error.Printf( _( "invalid float number in file: \"%s\"\nline: %d, offset: %d" ),
2937  m_reader->GetSource().GetData(),
2938  m_reader->LineNumber(), aValue - m_reader->Line() + 1 );
2939 
2941  }
2942 
2943  if( aValue == nptr )
2944  {
2945  m_error.Printf( _( "missing float number in file: \"%s\"\nline: %d, offset: %d" ),
2946  m_reader->GetSource().GetData(),
2947  m_reader->LineNumber(), aValue - m_reader->Line() + 1 );
2948 
2950  }
2951 
2952  if( nptrptr )
2953  *nptrptr = nptr;
2954 
2955  fval *= diskToBiu;
2956 
2957  // fval is up into the whole number realm here, and should be bounded
2958  // within INT_MIN to INT_MAX since BIU's are nanometers.
2959  return KiROUND( fval );
2960 }
2961 
2962 
2963 double LEGACY_PLUGIN::degParse( const char* aValue, const char** nptrptr )
2964 {
2965  char* nptr;
2966 
2967  errno = 0;
2968 
2969  double fval = strtod( aValue, &nptr );
2970 
2971  if( errno )
2972  {
2973  m_error.Printf( _( "invalid float number in file: \"%s\"\nline: %d, offset: %d" ),
2974  m_reader->GetSource().GetData(), m_reader->LineNumber(), aValue - m_reader->Line() + 1 );
2975 
2977  }
2978 
2979  if( aValue == nptr )
2980  {
2981  m_error.Printf( _( "missing float number in file: \"%s\"\nline: %d, offset: %d" ),
2982  m_reader->GetSource().GetData(), m_reader->LineNumber(), aValue - m_reader->Line() + 1 );
2983 
2985  }
2986 
2987  if( nptrptr )
2988  *nptrptr = nptr;
2989 
2990  return fval;
2991 }
2992 
2993 
2994 void LEGACY_PLUGIN::init( const PROPERTIES* aProperties )
2995 {
2997  m_cu_count = 16;
2998  m_board = NULL;
2999  m_showLegacyZoneWarning = true;
3000  m_props = aProperties;
3001 
3002  // conversion factor for saving RAM BIUs to KICAD legacy file format.
3003  biuToDisk = 1.0/IU_PER_MM; // BIUs are nanometers & file is mm
3004 
3005  // Conversion factor for loading KICAD legacy file format into BIUs in RAM
3006  // Start by assuming the *.brd file is in deci-mils.
3007  // If we see "Units mm" in the $GENERAL section, set diskToBiu to 1000000.0
3008  // then, during the file loading process, to start a conversion from
3009  // mm to nanometers. The deci-mil legacy files have no such "Units" marker
3010  // so we must assume the file is in deci-mils until told otherwise.
3011 
3012  diskToBiu = IU_PER_MILS / 10; // BIUs are nanometers
3013 }
3014 
3015 
3016 void LEGACY_PLUGIN::SaveModule3D( const MODULE* me ) const
3017 {
3018  auto sM = me->Models().begin();
3019  auto eM = me->Models().end();
3020 
3021  while( sM != eM )
3022  {
3023  if( sM->m_Filename.empty() )
3024  {
3025  ++sM;
3026  continue;
3027  }
3028 
3029  fprintf( m_fp, "$SHAPE3D\n" );
3030 
3031  fprintf( m_fp, "Na %s\n", EscapedUTF8( sM->m_Filename ).c_str() );
3032 
3033  fprintf(m_fp,
3034 #if defined(DEBUG)
3035  // use old formats for testing, just to verify compatibility
3036  // using "diff", then switch to more concise form for release builds.
3037  "Sc %lf %lf %lf\n",
3038 #else
3039  "Sc %.10g %.10g %.10g\n",
3040 #endif
3041  sM->m_Scale.x,
3042  sM->m_Scale.y,
3043  sM->m_Scale.z );
3044 
3045  fprintf(m_fp,
3046 #if defined(DEBUG)
3047  "Of %lf %lf %lf\n",
3048 #else
3049  "Of %.10g %.10g %.10g\n",
3050 #endif
3051  sM->m_Offset.x,
3052  sM->m_Offset.y,
3053  sM->m_Offset.z );
3054 
3055  fprintf(m_fp,
3056 #if defined(DEBUG)
3057  "Ro %lf %lf %lf\n",
3058 #else
3059  "Ro %.10g %.10g %.10g\n",
3060 #endif
3061  sM->m_Rotation.x,
3062  sM->m_Rotation.y,
3063  sM->m_Rotation.z );
3064 
3065  fprintf( m_fp, "$EndSHAPE3D\n" );
3066 
3067  ++sM;
3068  }
3069 }
3070 
3071 
3072 //-----<FOOTPRINT LIBRARY FUNCTIONS>--------------------------------------------
3073 
3074 /*
3075 
3076  The legacy file format is being obsoleted and this code will have a short
3077  lifetime, so it only needs to be good enough for a short duration of time.
3078  Caching all the MODULEs is a bit memory intensive, but it is a considerably
3079  faster way of fulfilling the API contract. Otherwise, without the cache, you
3080  would have to re-read the file when searching for any MODULE, and this would
3081  be very problematic filling a FOOTPRINT_LIST via this PLUGIN API. If memory
3082  becomes a concern, consider the cache lifetime policy, which determines the
3083  time that a LP_CACHE is in RAM. Note PLUGIN lifetime also plays a role in
3084  cache lifetime.
3085 
3086 */
3087 
3088 
3089 #include <boost/ptr_container/ptr_map.hpp>
3090 #include <wx/filename.h>
3091 
3092 typedef boost::ptr_map< std::string, MODULE > MODULE_MAP;
3093 typedef MODULE_MAP::iterator MODULE_ITER;
3094 typedef MODULE_MAP::const_iterator MODULE_CITER;
3095 
3096 
3103 struct LP_CACHE
3104 {
3105  LEGACY_PLUGIN* m_owner; // my owner, I need its LEGACY_PLUGIN::loadMODULE()
3106  wxString m_lib_path;
3107  MODULE_MAP m_modules; // map or tuple of footprint_name vs. MODULE*
3109 
3110  bool m_cache_dirty; // Stored separately because it's expensive to check
3111  // m_cache_timestamp against all the files.
3112  long long m_cache_timestamp; // A hash of the timestamps for all the footprint
3113  // files.
3114 
3115  LP_CACHE( LEGACY_PLUGIN* aOwner, const wxString& aLibraryPath );
3116 
3117  // Most all functions in this class throw IO_ERROR exceptions. There are no
3118  // error codes nor user interface calls from here, nor in any PLUGIN.
3119  // Catch these exceptions higher up please.
3120 
3121  void Load();
3122 
3123  void ReadAndVerifyHeader( LINE_READER* aReader );
3124 
3125  void SkipIndex( LINE_READER* aReader );
3126 
3127  void LoadModules( LINE_READER* aReader );
3128 
3129  bool IsModified();
3130  static long long GetTimestamp( const wxString& aLibPath );
3131 };
3132 
3133 
3134 LP_CACHE::LP_CACHE( LEGACY_PLUGIN* aOwner, const wxString& aLibraryPath ) :
3135  m_owner( aOwner ),
3136  m_lib_path( aLibraryPath ),
3137  m_writable( true ),
3138  m_cache_dirty( true ),
3139  m_cache_timestamp( 0 )
3140 {
3141 }
3142 
3143 
3145 {
3147 
3148  return m_cache_dirty;
3149 }
3150 
3151 
3152 long long LP_CACHE::GetTimestamp( const wxString& aLibPath )
3153 {
3154  return wxFileName( aLibPath ).GetModificationTime().GetValue().GetValue();
3155 }
3156 
3157 
3159 {
3160  m_cache_dirty = false;
3161 
3162  FILE_LINE_READER reader( m_lib_path );
3163 
3164  ReadAndVerifyHeader( &reader );
3165  SkipIndex( &reader );
3166  LoadModules( &reader );
3167 
3168  // Remember the file modification time of library file when the
3169  // cache snapshot was made, so that in a networked environment we will
3170  // reload the cache as needed.
3172 }
3173 
3174 
3176 {
3177  char* line = aReader->ReadLine();
3178  char* data;
3179 
3180  if( !line )
3181  THROW_IO_ERROR( wxString::Format( _( "File '%s' is empty." ), m_lib_path ) );
3182 
3183  if( !TESTLINE( "PCBNEW-LibModule-V1" ) )
3184  THROW_IO_ERROR( wxString::Format( _( "File '%s' is not a legacy library." ), m_lib_path ) );
3185 
3186  while( ( line = aReader->ReadLine() ) != NULL )
3187  {
3188  if( TESTLINE( "Units" ) )
3189  {
3190  const char* units = strtok_r( line + SZ( "Units" ), delims, &data );
3191 
3192  if( !strcmp( units, "mm" ) )
3193  m_owner->diskToBiu = IU_PER_MM;
3194 
3195  }
3196  else if( TESTLINE( "$INDEX" ) )
3197  return;
3198  }
3199 }
3200 
3201 
3203 {
3204  // Some broken INDEX sections have more than one section, due to prior bugs.
3205  // So we must read the next line after $EndINDEX tag,
3206  // to see if this is not a new $INDEX tag.
3207  bool exit = false;
3208  char* line = aReader->Line();
3209 
3210  do
3211  {
3212  if( TESTLINE( "$INDEX" ) )
3213  {
3214  exit = false;
3215 
3216  while( ( line = aReader->ReadLine() ) != NULL )
3217  {
3218  if( TESTLINE( "$EndINDEX" ) )
3219  {
3220  exit = true;
3221  break;
3222  }
3223  }
3224  }
3225  else if( exit )
3226  break;
3227  } while( ( line = aReader->ReadLine() ) != NULL );
3228 }
3229 
3230 
3232 {
3233  m_owner->SetReader( aReader );
3234 
3235  char* line = aReader->Line();
3236 
3237  do
3238  {
3239  // test first for the $MODULE, even before reading because of INDEX bug.
3240  if( TESTLINE( "$MODULE" ) )
3241  {
3242  unique_ptr<MODULE> module( new MODULE( m_owner->m_board ) );
3243 
3244  std::string footprintName = StrPurge( line + SZ( "$MODULE" ) );
3245 
3246  // The footprint names in legacy libraries can contain the '/' and ':'
3247  // characters which will cause the LIB_ID parser to choke.
3248  ReplaceIllegalFileNameChars( &footprintName );
3249 
3250  // set the footprint name first thing, so exceptions can use name.
3251  module->SetFPID( LIB_ID( wxEmptyString, footprintName ) );
3252 
3253  m_owner->loadMODULE( module.get() );
3254 
3255  MODULE* m = module.release(); // exceptions after this are not expected.
3256 
3257  // Not sure why this is asserting on debug builds. The debugger shows the
3258  // strings are the same. If it's not really needed maybe it can be removed.
3259 // wxASSERT( footprintName == m->GetFPID().GetLibItemName() );
3260 
3261  /*
3262 
3263  There was a bug in old legacy library management code
3264  (pre-LEGACY_PLUGIN) which was introducing duplicate footprint names
3265  in legacy libraries without notification. To best recover from such
3266  bad libraries, and use them to their fullest, there are a few
3267  strategies that could be used. (Note: footprints must have unique
3268  names to be accepted into this cache.) The strategy used here is to
3269  append a differentiating version counter to the end of the name as:
3270  _v2, _v3, etc.
3271 
3272  */
3273 
3274  MODULE_CITER it = m_modules.find( footprintName );
3275 
3276  if( it == m_modules.end() ) // footprintName is not present in cache yet.
3277  {
3278  std::pair<MODULE_ITER, bool> r = m_modules.insert( footprintName, m );
3279 
3280  wxASSERT_MSG( r.second, wxT( "error doing cache insert using guaranteed unique name" ) );
3281  (void) r;
3282  }
3283 
3284  // Bad library has a duplicate of this footprintName, generate a
3285  // unique footprint name and load it anyway.
3286  else
3287  {
3288  bool nameOK = false;
3289  int version = 2;
3290  char buf[48];
3291 
3292  while( !nameOK )
3293  {
3294  std::string newName = footprintName;
3295 
3296  newName += "_v";
3297  sprintf( buf, "%d", version++ );
3298  newName += buf;
3299 
3300  it = m_modules.find( newName );
3301 
3302  if( it == m_modules.end() )
3303  {
3304  nameOK = true;
3305 
3306  m->SetFPID( LIB_ID( wxEmptyString, newName ) );
3307  std::pair<MODULE_ITER, bool> r = m_modules.insert( newName, m );
3308 
3309  wxASSERT_MSG( r.second, wxT( "error doing cache insert using guaranteed unique name" ) );
3310  (void) r;
3311  }
3312  }
3313  }
3314  }
3315 
3316  } while( ( line = aReader->ReadLine() ) != NULL );
3317 }
3318 
3319 
3320 long long LEGACY_PLUGIN::GetLibraryTimestamp( const wxString& aLibraryPath ) const
3321 {
3322  return LP_CACHE::GetTimestamp( aLibraryPath );
3323 }
3324 
3325 
3326 void LEGACY_PLUGIN::cacheLib( const wxString& aLibraryPath )
3327 {
3328  if( !m_cache || m_cache->m_lib_path != aLibraryPath || m_cache->IsModified() )
3329  {
3330  // a spectacular episode in memory management:
3331  delete m_cache;
3332  m_cache = new LP_CACHE( this, aLibraryPath );
3333  m_cache->Load();
3334  }
3335 }
3336 
3337 
3338 void LEGACY_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
3339  bool aBestEfforts, const PROPERTIES* aProperties )
3340 {
3341  LOCALE_IO toggle; // toggles on, then off, the C locale.
3342  wxString errorMsg;
3343 
3344  init( aProperties );
3345 
3346  try
3347  {
3348  cacheLib( aLibPath );
3349  }
3350  catch( const IO_ERROR& ioe )
3351  {
3352  errorMsg = ioe.What();
3353  }
3354 
3355  // Some of the files may have been parsed correctly so we want to add the valid files to
3356  // the library.
3357 
3358  for( MODULE_CITER it = m_cache->m_modules.begin(); it != m_cache->m_modules.end(); ++it )
3359  aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
3360 
3361  if( !errorMsg.IsEmpty() && !aBestEfforts )
3362  THROW_IO_ERROR( errorMsg );
3363 }
3364 
3365 
3366 MODULE* LEGACY_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
3367  const wxString& aFootprintName, const PROPERTIES* aProperties )
3368 {
3369  LOCALE_IO toggle; // toggles on, then off, the C locale.
3370 
3371  init( aProperties );
3372 
3373  cacheLib( aLibraryPath );
3374 
3375  const MODULE_MAP& mods = m_cache->m_modules;
3376 
3377  MODULE_CITER it = mods.find( TO_UTF8( aFootprintName ) );
3378 
3379  if( it == mods.end() )
3380  {
3381  /*
3382  THROW_IO_ERROR( wxString::Format( _( "No \"%s\" footprint in library \"%s\"" ),
3383  aFootprintName.GetData(), aLibraryPath.GetData() ) );
3384  */
3385 
3386  return NULL;
3387  }
3388 
3389  // Return copy of already loaded MODULE
3390  return (MODULE*) it->second->Duplicate();
3391 }
3392 
3393 
3394 bool LEGACY_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
3395 {
3396  wxFileName fn = aLibraryPath;
3397 
3398  if( !fn.FileExists() )
3399  return false;
3400 
3401  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
3402  // we don't want that. we want bare metal portability with no UI here.
3403  if( wxRemove( aLibraryPath ) )
3404  {
3406  _( "library \"%s\" cannot be deleted" ),
3407  aLibraryPath.GetData() ) );
3408  }
3409 
3410  if( m_cache && m_cache->m_lib_path == aLibraryPath )
3411  {
3412  delete m_cache;
3413  m_cache = 0;
3414  }
3415 
3416  return true;
3417 }
3418 
3419 
3420 bool LEGACY_PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
3421 {
3422 #if 0 // no support for 32 Cu layers in legacy format
3423  return false;
3424 #else
3425  LOCALE_IO toggle;
3426 
3427  init( NULL );
3428 
3429  cacheLib( aLibraryPath );
3430 
3431  return m_cache->m_writable;
3432 #endif
3433 }
3434 
3435 
3437  m_cu_count( 16 ), // for FootprintLoad()
3438  m_board( nullptr ),
3439  m_props( nullptr ),
3440  m_reader( nullptr ),
3441  m_fp( nullptr ),
3442  m_cache( nullptr ),
3443  m_mapping( new NETINFO_MAPPING() )
3444 {
3445  init( NULL );
3446 }
3447 
3448 
3450 {
3451  delete m_cache;
3452  delete m_mapping;
3453 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:172
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
CITER next(CITER it)
Definition: ptree.cpp:130
void SetPlacementCost90(int aCost)
Definition: class_module.h:556
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
int m_SolderMaskMargin
Solder mask margin.
ZONE_CONNECTION
How pads are covered by copper in zone.
Definition: zones.h:41
void SetFileFormatVersionAtLoad(int aVersion)
Definition: class_board.h:272
void SetModified()
Definition: base_struct.cpp:94
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
double GetOrientation() const
Definition: class_module.h:215
#define SILKSCREEN_N_BACK
void SetTextAngle(double aAngle)
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:81
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
TEXTE_MODULE & Reference()
Definition: class_module.h:477
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox
Definition: confirm.cpp:53
void SetThermalGap(int aGap)
Definition: class_module.h:256
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:44
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
unsigned LAYER_MSK
wxPoint m_GridOrigin
origin for grid offsets
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
TEXTE_PCB class definition.
void cacheLib(const wxString &aLibraryPath)
we only cache one footprint library for now, this determines which one.
MODULE_MAP::const_iterator MODULE_CITER
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
Definition: string.cpp:310
void SetLocalClearance(int aClearance)
Definition: class_module.h:235
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:66
int m_SolderPasteMargin
Solder paste margin absolute value.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:202
PAD_ATTR_T
Enum PAD_ATTR_T is the set of pad shapes, used with D_PAD::{Set,Get}Attribute() The double name is fo...
Definition: pad_shapes.h:59
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:44
LP_CACHE(LEGACY_PLUGIN *aOwner, const wxString &aLibraryPath)
void loadMODULE_TEXT(TEXTE_MODULE *aText)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPlacementCost180(int aCost)
Definition: class_module.h:553
This file is part of the common library.
PCB_PLOT_PARAMS_PARSER is the parser class for PCB_PLOT_PARAMS.
bool m_showLegacyZoneWarning
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:107
std::vector< int > m_TrackWidthList
static int intParse(const char *next, const char **out=NULL)
Function intParse parses an ASCII integer string with possible leading whitespace into an integer and...
void SetRevision(const wxString &aRevision)
Definition: title_block.h:84
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: class_board.h:534
#define LAYER_N_BACK
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
LEGACY_PLUGIN * m_owner
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: class_board.h:528
the 3d code uses this value
Definition: typeinfo.h:80
void SetItalic(bool isItalic)
Definition: eda_text.h:163
polygon (not yet used for tracks, but could be in microwave apps)
boost::ptr_map< std::string, MODULE > MODULE_MAP
#define COMMENT_N
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:62
#define EDGE_N
#define ADHESIVE_N_FRONT
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:231
static const char delims[]
void SetVisible(bool aVisible)
Definition: eda_text.h:169
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
Definition: page_info.cpp:117
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:74
void SetCopperLayerCount(int aCount)
static LAYER_NUM layerParse(const char *next, const char **out=NULL)
Function layerParse Like intParse but returns a LAYER_NUM.
void loadMODULE(MODULE *aModule)
friend struct LP_CACHE
Definition: legacy_plugin.h:67
void SkipIndex(LINE_READER *aReader)
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL) override
Function Load loads information from some input file format that this PLUGIN implementation knows abo...
bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Function FootprintLibDelete deletes an existing footprint library and returns true,...
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.
Definition: string.cpp:680
void SetDate(const wxString &aDate)
Function SetDate sets the date field, and defaults to the current time and date.
Definition: title_block.h:74
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:512
bool IsModified()
usual segment : line with rounded ends
const LIB_ID & GetFPID() const
Definition: class_module.h:219
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:78
#define READLINE(rdr)
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:305
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
static PCB_LAYER_ID leg_layer2new(int cu_count, LAYER_NUM aLayerNum)
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Function SetLayerType changes the type of the layer given by aLayer.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
#define SOLDERMASK_N_FRONT
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
wxString m_field
reused to stuff MODULE fields.
PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
void SetBoardThickness(int aThickness)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
defines the basic data associated with a single 3D model.
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
PAD_DRILL_SHAPE_T
Enum PAD_DRILL_SHAPE_T is the set of pad drill shapes, used with D_PAD::{Set,Get}DrillShape()
Definition: pad_shapes.h:47
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: class_module.h:241
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
int m_loading_format_version
which BOARD_FORMAT_VERSION am I Load()ing?
#define ECO2_N
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
static int GetDefaultHatchPitch()
Function GetDefaultHatchPitchMils.
PAD_SHAPE_T
Enum PAD_SHAPE_T is the set of pad shapes, used with D_PAD::{Set,Get}Shape()
Definition: pad_shapes.h:31
#define SOLDERMASK_N_BACK
void SetReader(LINE_READER *aReader)
Definitions for tracks, vias and zones.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
VECTOR3D m_Offset
3D model offset (mm)
Definition: class_module.h:99
#define ADHESIVE_N_BACK
FILE * m_fp
no ownership here.
This file contains miscellaneous commonly used macros and functions.
void load3D(MODULE *aModule)
void SetWidth(int aWidth)
Definition: class_track.h:104
bool m_cache_dirty
double biuToDisk
convert from BIUs to disk engineering units with this scale factor
LP_CACHE assists only for the footprint portion of the PLUGIN API, and only for the LEGACY_PLUGIN,...
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:249
#define SILKSCREEN_N_FRONT
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
wxSize m_TextSize[LAYER_CLASS_COUNT]
BIU biuParse(const char *aValue, const char **nptrptr=NULL)
Function biuParse parses an ASCII decimal floating point value and scales it into a BIU according to ...
std::vector< int > m_netCodes
net codes mapping for boards being loaded
DIMENSION class definition.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: common.h:65
PCB_LAYER_ID
A quick note on layer IDs:
LINE_READER * m_reader
no ownership here.
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
int m_TextThickness[LAYER_CLASS_COUNT]
static EDA_TEXT_HJUSTIFY_T horizJustify(const char *horizontal)
bool is_leg_copperlayer_valid(int aCu_Count, LAYER_NUM aLegacyLayerNum)
LSET is a set of PCB_LAYER_IDs.
pads are covered by copper
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:183
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:111
void SetComment(int aIdx, const wxString &aComment)
Definition: title_block.h:104
#define NULL
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
SHAPE_POLY_SET.
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:476
void SetVisibleLayers(LSET aLayerMask)
Function SetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
LEGACY_PLUGIN is a PLUGIN derivation which could possibly be put into a DLL/DSO.
Definition: legacy_plugin.h:65
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
void loadMODULE_EDGE(MODULE *aModule)
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:187
Arcs (with rounded ends)
LAYER_T
Enum LAYER_T gives the allowed types of layers, same as Specctra DSN spec.
Definition: class_board.h:68
void LoadModules(LINE_READER *aReader)
VIATYPE
Definition: class_track.h:62
void SetLastEditTime(timestamp_t aTime)
Definition: class_module.h:347
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
void SetCompany(const wxString &aCompany)
Definition: title_block.h:94
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:232
unsigned STATUS_FLAGS
Definition: base_struct.h:159
void SetThermalWidth(int aWidth)
Definition: class_module.h:253
void SetSize(const wxSize &aSize)
Definition: class_pad.h:299
int m_ZoneClearance
Minimal clearance value.
Definition: zone_settings.h:74
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
#define ECO1_N
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Sets net using a net code.
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aDesignSettings)
Function SetDesignSettings.
Definition: class_board.h:522
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_Layer contains the top layer, the other layer is in m_BottomLayer.
#define ALL_CU_LAYERS
#define THROW_IO_ERROR(msg)
unsigned LEG_MASK
void SetIsPlaced(bool isPlaced)
Definition: class_module.h:320
LEGACY_PLUGIN::BIU BIU
void SetFileName(const wxString &aFileName)
Definition: class_board.h:216
void SetPosition(const wxPoint &aPos) override
void SetPlotOptions(const PCB_PLOT_PARAMS &aOptions)
Definition: class_board.h:531
double diskToBiu
convert from disk engineering units to BIUs with this scale factor
static LAYER_T ParseType(const char *aType)
Function ParseType converts a string to a LAYER_T.
void SetTitle(const wxString &aTitle)
Definition: title_block.h:60
PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board.
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:63
int NewOutline()
Creates a new empty polygon in the set and returns its index
BOARD * m_board
which BOARD, no ownership here
void SetType(TEXT_TYPE aType)
int m_LineThickness[LAYER_CLASS_COUNT]
#define TESTSUBSTR(x)
C sub-string compare test for a specific length of characters.
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:253
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_module.h:232
void SetPos0(const wxPoint &aPos)
void SetDrillDefault()
Function SetDrillDefault sets the drill value for vias to the default value UNDEFINED_DRILL_DIAMETER.
Definition: class_track.h:452
void SetZoneSettings(const ZONE_SETTINGS &aSettings)
Set the zone settings for this container.
void loadAllSections(bool doAppend)
Thermal relief only for THT pads.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
wxString m_Filename
The 3D shape filename in 3D library.
Definition: class_module.h:100
default
Definition: class_module.h:73
static bool isSpace(int c)
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:58
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:51
const KIID m_Uuid
Definition: base_struct.h:169
void loadZONE_CONTAINER()
Definition: seg.h:39
double degParse(const char *aValue, const char **nptrptr=NULL)
Function degParse parses an ASCII decimal floating point value which is certainly an angle.
Use thermal relief for pads.
bool Add(const NETCLASSPTR &aNetclass)
Function Add takes aNetclass and puts it into this NETCLASSES container.
Definition: netclass.cpp:99
#define LAYER_N_FRONT
const ZONE_SETTINGS & GetZoneSettings() const
Fetch the zone settings for this container.
static LSET leg_mask2new(int cu_count, unsigned aMask)
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_module.h:238
MODULE_MAP::const_iterator MODULE_CITER
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:205
long long m_cache_timestamp
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
#define FIRST_LAYER
void SetState(int type, int state)
Definition: base_struct.h:246
void SetLocked(bool isLocked) override
Function SetLocked sets the MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: class_module.h:311
ZONE_HATCH_STYLE
Zone hatch styles.
Definition: zone_settings.h:45
Class to handle a graphic segment.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
NETCLASSPTR GetDefault() const
Function GetDefault.
VECTOR3D m_Rotation
3D model rotation (degrees)
Definition: class_module.h:98
#define VERSION_ERROR_FORMAT
static EDA_TEXT_VJUSTIFY_T vertJustify(const char *vertical)
int GetNet() const
Function GetNet.
Definition: netinfo.h:224
int layerMaskCountSet(LEG_MASK aMask)
Count the number of set layers in the mask.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:186
#define _(s)
Definition: 3d_actions.cpp:33
wxString m_lib_path
void SetOrientation(double newangle)
Virtual component: when created by copper shapes on board (Like edge card connectors,...
Definition: class_module.h:76
wxString m_error
for throwing exceptions
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:101
#define LAST_NON_COPPER_LAYER
void SetZoneConnection(ZONE_CONNECTION aType)
Definition: class_module.h:243
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
static long hexParse(const char *next, const char **out=NULL)
Function hexParse parses an ASCII hex integer string with possible leading whitespace into a long int...
#define SOLDERPASTE_N_FRONT
#define DRAW_N
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:239
void SetDrawCoord()
Set absolute coordinates.
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
char * strtok_r(char *str, const char *delim, char **nextp)
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:431
static long long GetTimestamp(const wxString &aLibPath)
void SetVisibleElements(int aMask)
Function SetVisibleElements changes the bit-mask of visible element categories.
VIATYPE GetViaType() const
Definition: class_track.h:416
#define IU_PER_MILS
Definition: plotter.cpp:137
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:61
VECTOR3D m_Scale
3D model scaling factor (dimensionless)
Definition: class_module.h:97
Pads are not covered.
std::vector< VIA_DIMENSION > m_ViasDimensionsList
#define FIRST_COPPER_LAYER
int ShowModal() override
Definition: confirm.cpp:95
void SetKeywords(const wxString &aKeywords)
Definition: class_module.h:226
PCB_TARGET class definition.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
void SetPath(const KIID_PATH &aPath)
Definition: class_module.h:229
void SetTextAngle(double aAngle)
void SaveModule3D(const MODULE *aModule) const
Module description (excepted pads)
bool m_MicroViasAllowed
true to allow micro vias
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
Definition: string.cpp:155
double m_SolderPasteMarginRatio
Solder pask margin ratio value of pad size The final margin is the sum of these 2 values.
EDGE_MODULE class definition.
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
void loadPAD(MODULE *aModule)
void Parse(PCB_PLOT_PARAMS_PARSER *aParser)
#define SZ(x)
Get the length of a string constant, at compile time.
MODULE_MAP::iterator MODULE_ITER
BOARD_ITEM_CONTAINER * GetParent() const
void ReadAndVerifyHeader(LINE_READER *aReader)
void SetViaType(VIATYPE aViaType)
Definition: class_track.h:421
int getNetCode(int aNetCode)
Converts net code using the mapping table if available, otherwise returns unchanged net code
void SetPortrait(bool aIsPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
Definition: page_info.cpp:182
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:462
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
const wxPoint GetPosition() const override
Definition: class_module.h:210
void SetFPID(const LIB_ID &aFPID)
Definition: class_module.h:220
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
#define TESTLINE(x)
C string compare test for a specific length of characters.
void loadTrackList(int aStructType)
Function loadTrackList reads a list of segments (Tracks and Vias, or Segzones)
void SetEnabledLayers(LSET aLayerMask)
Function SetEnabledLayers is a proxy function that calls the correspondent function in m_BoardSetting...
wxPoint m_AuxOrigin
origin for plot exports
DIMENSION.
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty nets are stored with consecutive integers as net codes
MODULE_MAP m_modules
LP_CACHE * m_cache
#define SOLDERPASTE_N_BACK
#define FIRST_NON_COPPER_LAYER
void SetThickness(int aNewThickness)
Set the pen width.
Definition: eda_text.h:143
int m_SolderMaskMinWidth
Solder mask min width.
void SetAttributes(int aAttributes)
Definition: class_module.h:260
MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void SetDescription(const wxString &aDoc)
Definition: class_module.h:223