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