KiCad PCB EDA Suite
kicad_plugin.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2012 CERN
5  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <fctsys.h>
26 #include <kicad_string.h>
27 #include <common.h>
28 #include <build_version.h> // LEGACY_BOARD_FILE_VERSION
29 #include <macros.h>
31 #include <base_units.h>
32 #include <trace_helpers.h>
33 #include <class_board.h>
34 #include <class_module.h>
35 #include <class_pcb_text.h>
36 #include <class_dimension.h>
37 #include <class_track.h>
38 #include <class_zone.h>
39 #include <class_drawsegment.h>
40 #include <class_pcb_target.h>
41 #include <class_edge_mod.h>
42 #include <pcb_plot_params.h>
43 #include <zones.h>
44 #include <kicad_plugin.h>
45 #include <pcb_parser.h>
46 #include <pcbnew_settings.h>
47 #include <wx/dir.h>
48 #include <wx/filename.h>
49 #include <wx/wfstream.h>
50 #include <boost/ptr_container/ptr_map.hpp>
51 #include <memory.h>
53 #include <convert_basic_shapes_to_polygon.h> // for enum RECT_CHAMFER_POSITIONS definition
54 #include <kiface_i.h>
55 
56 #include <advanced_config.h> // for pad pin function and pad property feature management
57 
58 using namespace PCB_KEYS_T;
59 
60 
62 void filterNetClass( const BOARD& aBoard, NETCLASS& aNetClass )
63 {
64  auto connectivity = aBoard.GetConnectivity();
65 
66  for( NETCLASS::iterator it = aNetClass.begin(); it != aNetClass.end(); )
67  {
68  NETINFO_ITEM* netinfo = aBoard.FindNet( *it );
69 
70  if( netinfo && connectivity->GetNodeCount( netinfo->GetNet() ) <= 0 ) // hopefully there are no nets with negative
71  aNetClass.Remove( it++ ); // node count, but you never know..
72  else
73  ++it;
74  }
75 }
76 
87 {
89  std::unique_ptr<MODULE> m_module;
90 
91 public:
92  FP_CACHE_ITEM( MODULE* aModule, const WX_FILENAME& aFileName );
93 
94  const WX_FILENAME& GetFileName() const { return m_filename; }
95  const MODULE* GetModule() const { return m_module.get(); }
96 };
97 
98 
99 FP_CACHE_ITEM::FP_CACHE_ITEM( MODULE* aModule, const WX_FILENAME& aFileName ) :
100  m_filename( aFileName ),
101  m_module( aModule )
102 { }
103 
104 
105 typedef boost::ptr_map< wxString, FP_CACHE_ITEM > MODULE_MAP;
106 typedef MODULE_MAP::iterator MODULE_ITER;
107 typedef MODULE_MAP::const_iterator MODULE_CITER;
108 
109 
110 class FP_CACHE
111 {
112  PCB_IO* m_owner; // Plugin object that owns the cache.
113  wxFileName m_lib_path; // The path of the library.
114  wxString m_lib_raw_path; // For quick comparisons.
115  MODULE_MAP m_modules; // Map of footprint file name per MODULE*.
116 
117  bool m_cache_dirty; // Stored separately because it's expensive to check
118  // m_cache_timestamp against all the files.
119  long long m_cache_timestamp; // A hash of the timestamps for all the footprint
120  // files.
121 
122 public:
123  FP_CACHE( PCB_IO* aOwner, const wxString& aLibraryPath );
124 
125  wxString GetPath() const { return m_lib_raw_path; }
126  bool IsWritable() const { return m_lib_path.IsOk() && m_lib_path.IsDirWritable(); }
127  bool Exists() const { return m_lib_path.IsOk() && m_lib_path.DirExists(); }
129 
130  // Most all functions in this class throw IO_ERROR exceptions. There are no
131  // error codes nor user interface calls from here, nor in any PLUGIN.
132  // Catch these exceptions higher up please.
133 
140  void Save( MODULE* aModule = NULL );
141 
142  void Load();
143 
144  void Remove( const wxString& aFootprintName );
145 
152  static long long GetTimestamp( const wxString& aLibPath );
153 
158  bool IsModified();
159 
172  bool IsPath( const wxString& aPath ) const;
173 };
174 
175 
176 FP_CACHE::FP_CACHE( PCB_IO* aOwner, const wxString& aLibraryPath )
177 {
178  m_owner = aOwner;
179  m_lib_raw_path = aLibraryPath;
180  m_lib_path.SetPath( aLibraryPath );
181  m_cache_timestamp = 0;
182  m_cache_dirty = true;
183 }
184 
185 
186 void FP_CACHE::Save( MODULE* aModule )
187 {
188  m_cache_timestamp = 0;
189 
190  if( !m_lib_path.DirExists() && !m_lib_path.Mkdir() )
191  {
192  THROW_IO_ERROR( wxString::Format( _( "Cannot create footprint library path \"%s\"" ),
193  m_lib_raw_path ) );
194  }
195 
196  if( !m_lib_path.IsDirWritable() )
197  {
198  THROW_IO_ERROR( wxString::Format( _( "Footprint library path \"%s\" is read only" ),
199  m_lib_raw_path ) );
200  }
201 
202  for( MODULE_ITER it = m_modules.begin(); it != m_modules.end(); ++it )
203  {
204  if( aModule && aModule != it->second->GetModule() )
205  continue;
206 
207  WX_FILENAME fn = it->second->GetFileName();
208 
209  wxString tempFileName =
210 #ifdef USE_TMP_FILE
211  wxFileName::CreateTempFileName( fn.GetPath() );
212 #else
213  fn.GetFullPath();
214 #endif
215  // Allow file output stream to go out of scope to close the file stream before
216  // renaming the file.
217  {
218  wxLogTrace( traceKicadPcbPlugin, wxT( "Creating temporary library file %s" ),
219  GetChars( tempFileName ) );
220 
221  FILE_OUTPUTFORMATTER formatter( tempFileName );
222 
223  m_owner->SetOutputFormatter( &formatter );
224  m_owner->Format( (BOARD_ITEM*) it->second->GetModule() );
225  }
226 
227 #ifdef USE_TMP_FILE
228  wxRemove( fn.GetFullPath() ); // it is not an error if this does not exist
229 
230  // Even on linux you can see an _intermittent_ error when calling wxRename(),
231  // and it is fully inexplicable. See if this dodges the error.
232  wxMilliSleep( 250L );
233 
234  if( !wxRenameFile( tempFileName, fn.GetFullPath() ) )
235  {
236  wxString msg = wxString::Format(
237  _( "Cannot rename temporary file \"%s\" to footprint library file \"%s\"" ),
238  GetChars( tempFileName ),
239  GetChars( fn.GetFullPath() )
240  );
241  THROW_IO_ERROR( msg );
242  }
243 #endif
245  }
246 
247  m_cache_timestamp += m_lib_path.GetModificationTime().GetValue().GetValue();
248 
249  // If we've saved the full cache, we clear the dirty flag.
250  if( !aModule )
251  m_cache_dirty = false;
252 }
253 
254 
256 {
257  m_cache_dirty = false;
258  m_cache_timestamp = 0;
259 
260  wxDir dir( m_lib_raw_path );
261 
262  if( !dir.IsOpened() )
263  {
264  wxString msg = wxString::Format( _( "Footprint library path '%s' does not exist "
265  "(or is not a directory)." ),
266  m_lib_raw_path );
267  THROW_IO_ERROR( msg );
268  }
269 
270  wxString fullName;
271  wxString fileSpec = wxT( "*." ) + KiCadFootprintFileExtension;
272 
273  // wxFileName construction is egregiously slow. Construct it once and just swap out
274  // the filename thereafter.
275  WX_FILENAME fn( m_lib_raw_path, wxT( "dummyName" ) );
276 
277  if( dir.GetFirst( &fullName, fileSpec ) )
278  {
279  wxString cacheError;
280 
281  do
282  {
283  fn.SetFullName( fullName );
284 
285  // Queue I/O errors so only files that fail to parse don't get loaded.
286  try
287  {
288  FILE_LINE_READER reader( fn.GetFullPath() );
289 
290  m_owner->m_parser->SetLineReader( &reader );
291 
292  MODULE* footprint = (MODULE*) m_owner->m_parser->Parse();
293  wxString fpName = fn.GetName();
294 
295  footprint->SetFPID( LIB_ID( wxEmptyString, fpName ) );
296  m_modules.insert( fpName, new FP_CACHE_ITEM( footprint, fn ) );
297 
299  }
300  catch( const IO_ERROR& ioe )
301  {
302  if( !cacheError.IsEmpty() )
303  cacheError += "\n\n";
304 
305  cacheError += ioe.What();
306  }
307  } while( dir.GetNext( &fullName ) );
308 
309  if( !cacheError.IsEmpty() )
310  THROW_IO_ERROR( cacheError );
311  }
312 }
313 
314 
315 void FP_CACHE::Remove( const wxString& aFootprintName )
316 {
317  MODULE_CITER it = m_modules.find( aFootprintName );
318 
319  if( it == m_modules.end() )
320  {
321  wxString msg = wxString::Format( _( "library \"%s\" has no footprint \"%s\" to delete" ),
323  aFootprintName );
324  THROW_IO_ERROR( msg );
325  }
326 
327  // Remove the module from the cache and delete the module file from the library.
328  wxString fullPath = it->second->GetFileName().GetFullPath();
329  m_modules.erase( aFootprintName );
330  wxRemoveFile( fullPath );
331 }
332 
333 
334 bool FP_CACHE::IsPath( const wxString& aPath ) const
335 {
336  return aPath == m_lib_raw_path;
337 }
338 
339 
341 {
343 
344  return m_cache_dirty;
345 }
346 
347 
348 long long FP_CACHE::GetTimestamp( const wxString& aLibPath )
349 {
350  wxString fileSpec = wxT( "*." ) + KiCadFootprintFileExtension;
351 
352  return TimestampDir( aLibPath, fileSpec );
353 }
354 
355 
356 void PCB_IO::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties )
357 {
358  LOCALE_IO toggle; // toggles on, then off, the C locale.
359 
360  init( aProperties );
361 
362  m_board = aBoard; // after init()
363 
364  // Prepare net mapping that assures that net codes saved in a file are consecutive integers
365  m_mapping->SetBoard( aBoard );
366 
367  FILE_OUTPUTFORMATTER formatter( aFileName );
368 
369  m_out = &formatter; // no ownership
370 
371  m_out->Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n", SEXPR_BOARD_FILE_VERSION,
372  formatter.Quotew( GetBuildVersion() ).c_str() );
373 
374  Format( aBoard, 1 );
375 
376  m_out->Print( 0, ")\n" );
377 }
378 
379 
380 BOARD_ITEM* PCB_IO::Parse( const wxString& aClipboardSourceInput )
381 {
382  std::string input = TO_UTF8( aClipboardSourceInput );
383 
384  STRING_LINE_READER reader( input, wxT( "clipboard" ) );
385 
386  m_parser->SetLineReader( &reader );
387 
388  try
389  {
390  return m_parser->Parse();
391  }
392  catch( const PARSE_ERROR& parse_error )
393  {
394  if( m_parser->IsTooRecent() )
395  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
396  else
397  throw;
398  }
399 }
400 
401 
402 void PCB_IO::Format( BOARD_ITEM* aItem, int aNestLevel ) const
403 {
404  LOCALE_IO toggle; // public API function, perform anything convenient for caller
405 
406  switch( aItem->Type() )
407  {
408  case PCB_T:
409  format( static_cast<BOARD*>( aItem ), aNestLevel );
410  break;
411 
412  case PCB_DIMENSION_T:
413  format( static_cast<DIMENSION*>( aItem ), aNestLevel );
414  break;
415 
416  case PCB_LINE_T:
417  format( static_cast<DRAWSEGMENT*>( aItem ), aNestLevel );
418  break;
419 
420  case PCB_MODULE_EDGE_T:
421  format( static_cast<EDGE_MODULE*>( aItem ), aNestLevel );
422  break;
423 
424  case PCB_TARGET_T:
425  format( static_cast<PCB_TARGET*>( aItem ), aNestLevel );
426  break;
427 
428  case PCB_MODULE_T:
429  format( static_cast<MODULE*>( aItem ), aNestLevel );
430  break;
431 
432  case PCB_PAD_T:
433  format( static_cast<D_PAD*>( aItem ), aNestLevel );
434  break;
435 
436  case PCB_TEXT_T:
437  format( static_cast<TEXTE_PCB*>( aItem ), aNestLevel );
438  break;
439 
440  case PCB_MODULE_TEXT_T:
441  format( static_cast<TEXTE_MODULE*>( aItem ), aNestLevel );
442  break;
443 
444  case PCB_TRACE_T:
445  case PCB_ARC_T:
446  case PCB_VIA_T:
447  format( static_cast<TRACK*>( aItem ), aNestLevel );
448  break;
449 
451  case PCB_ZONE_AREA_T:
452  format( static_cast<ZONE_CONTAINER*>( aItem ), aNestLevel );
453  break;
454 
455  default:
456  wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
457  }
458 }
459 
460 
461 void PCB_IO::formatLayer( const BOARD_ITEM* aItem ) const
462 {
463  if( m_ctl & CTL_STD_LAYER_NAMES )
464  {
465  PCB_LAYER_ID layer = aItem->GetLayer();
466 
467  // English layer names should never need quoting.
468  m_out->Print( 0, " (layer %s)", TO_UTF8( BOARD::GetStandardLayerName( layer ) ) );
469  }
470  else
471  m_out->Print( 0, " (layer %s)", m_out->Quotew( aItem->GetLayerName() ).c_str() );
472 }
473 
474 
475 void PCB_IO::formatSetup( BOARD* aBoard, int aNestLevel ) const
476 {
477  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
478 
479  // Setup
480  m_out->Print( aNestLevel, "(setup\n" );
481 
482  // Save the board physical stackup structure
484 
485  if( aBoard->GetDesignSettings().m_HasStackup )
486  stackup.FormatBoardStackup( m_out,aBoard, aNestLevel+1 );
487 
488  // Save current default track width, for compatibility with older Pcbnew version;
489  m_out->Print( aNestLevel+1, "(last_trace_width %s)\n",
490  FormatInternalUnits( dsnSettings.GetCurrentTrackWidth() ).c_str() );
491 
492  // Save custom track widths list (the first is not saved here: it's the netclass value)
493  for( unsigned ii = 1; ii < dsnSettings.m_TrackWidthList.size(); ii++ )
494  {
495  m_out->Print( aNestLevel+1, "(user_trace_width %s)\n",
496  FormatInternalUnits( dsnSettings.m_TrackWidthList[ii] ).c_str() );
497  }
498 
499  m_out->Print( aNestLevel+1, "(trace_clearance %s)\n",
500  FormatInternalUnits( dsnSettings.GetDefault()->GetClearance() ).c_str() );
501 
502  // ZONE_SETTINGS
503  m_out->Print( aNestLevel+1, "(zone_clearance %s)\n",
504  FormatInternalUnits( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() );
505  m_out->Print( aNestLevel+1, "(zone_45_only %s)\n",
506  aBoard->GetZoneSettings().m_Zone_45_Only ? "yes" : "no" );
507 
508  m_out->Print( aNestLevel+1, "(trace_min %s)\n",
509  FormatInternalUnits( dsnSettings.m_TrackMinWidth ).c_str() );
510 
511  // Save current default via size, for compatibility with older Pcbnew version;
512  m_out->Print( aNestLevel+1, "(via_size %s)\n",
513  FormatInternalUnits( dsnSettings.GetDefault()->GetViaDiameter() ).c_str() );
514  m_out->Print( aNestLevel+1, "(via_drill %s)\n",
515  FormatInternalUnits( dsnSettings.GetDefault()->GetViaDrill() ).c_str() );
516  m_out->Print( aNestLevel+1, "(via_min_size %s)\n",
517  FormatInternalUnits( dsnSettings.m_ViasMinSize ).c_str() );
518  m_out->Print( aNestLevel+1, "(via_min_drill %s)\n",
519  FormatInternalUnits( dsnSettings.m_ViasMinDrill ).c_str() );
520 
521  // Save custom via dimensions list (the first is not saved here: it's the netclass value)
522  for( unsigned ii = 1; ii < dsnSettings.m_ViasDimensionsList.size(); ii++ )
523  m_out->Print( aNestLevel+1, "(user_via %s %s)\n",
524  FormatInternalUnits( dsnSettings.m_ViasDimensionsList[ii].m_Diameter ).c_str(),
525  FormatInternalUnits( dsnSettings.m_ViasDimensionsList[ii].m_Drill ).c_str() );
526 
527  // Save custom diff-pair dimensions (the first is not saved here: it's the netclass value)
528  for( unsigned ii = 1; ii < dsnSettings.m_DiffPairDimensionsList.size(); ii++ )
529  {
530  m_out->Print( aNestLevel+1, "(user_diff_pair %s %s %s)\n",
531  FormatInternalUnits( dsnSettings.m_DiffPairDimensionsList[ii].m_Width ).c_str(),
532  FormatInternalUnits( dsnSettings.m_DiffPairDimensionsList[ii].m_Gap ).c_str(),
533  FormatInternalUnits( dsnSettings.m_DiffPairDimensionsList[ii].m_ViaGap ).c_str() );
534  }
535 
536  // for old versions compatibility:
537  if( dsnSettings.m_BlindBuriedViaAllowed )
538  m_out->Print( aNestLevel+1, "(blind_buried_vias_allowed yes)\n" );
539 
540  m_out->Print( aNestLevel+1, "(uvia_size %s)\n",
541  FormatInternalUnits( dsnSettings.GetDefault()->GetuViaDiameter() ).c_str() );
542  m_out->Print( aNestLevel+1, "(uvia_drill %s)\n",
543  FormatInternalUnits( dsnSettings.GetDefault()->GetuViaDrill() ).c_str() );
544  m_out->Print( aNestLevel+1, "(uvias_allowed %s)\n",
545  ( dsnSettings.m_MicroViasAllowed ) ? "yes" : "no" );
546  m_out->Print( aNestLevel+1, "(uvia_min_size %s)\n",
547  FormatInternalUnits( dsnSettings.m_MicroViasMinSize ).c_str() );
548  m_out->Print( aNestLevel+1, "(uvia_min_drill %s)\n",
549  FormatInternalUnits( dsnSettings.m_MicroViasMinDrill ).c_str() );
550 
551  m_out->Print( aNestLevel+1, "(max_error %s)\n",
552  FormatInternalUnits( dsnSettings.m_MaxError ).c_str() );
553 
554  // Store this option only if it is not the legacy option:
555  if( dsnSettings.m_ZoneUseNoOutlineInFill )
556  m_out->Print( aNestLevel+1, "(filled_areas_thickness no)\n" );
557 
558  formatDefaults( dsnSettings, aNestLevel+1 );
559 
560  m_out->Print( aNestLevel+1, "(pad_size %s %s)\n",
561  FormatInternalUnits( dsnSettings.m_Pad_Master.GetSize().x ).c_str(),
562  FormatInternalUnits( dsnSettings.m_Pad_Master.GetSize().y ).c_str() );
563  m_out->Print( aNestLevel+1, "(pad_drill %s)\n",
564  FormatInternalUnits( dsnSettings.m_Pad_Master.GetDrillSize().x ).c_str() );
565 
566  m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
567  FormatInternalUnits( dsnSettings.m_SolderMaskMargin ).c_str() );
568 
569  if( dsnSettings.m_SolderMaskMinWidth )
570  m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
571  FormatInternalUnits( dsnSettings.m_SolderMaskMinWidth ).c_str() );
572 
573  if( dsnSettings.m_SolderPasteMargin != 0 )
574  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
575  FormatInternalUnits( dsnSettings.m_SolderPasteMargin ).c_str() );
576 
577  if( dsnSettings.m_SolderPasteMarginRatio != 0 )
578  m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
579  Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
580 
581  m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
582  FormatInternalUnits( aBoard->GetAuxOrigin().x ).c_str(),
583  FormatInternalUnits( aBoard->GetAuxOrigin().y ).c_str() );
584 
585  if( aBoard->GetGridOrigin().x || aBoard->GetGridOrigin().y )
586  m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
587  FormatInternalUnits( aBoard->GetGridOrigin().x ).c_str(),
588  FormatInternalUnits( aBoard->GetGridOrigin().y ).c_str() );
589 
590  m_out->Print( aNestLevel+1, "(visible_elements %X)\n",
591  dsnSettings.GetVisibleElements() );
592 
593  aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
594 
595  m_out->Print( aNestLevel, ")\n\n" );
596 }
597 
598 
599 void PCB_IO::formatDefaults( const BOARD_DESIGN_SETTINGS& aSettings, int aNestLevel ) const
600 {
601  m_out->Print( aNestLevel, "(defaults\n" );
602 
603  m_out->Print( aNestLevel+1, "(edge_clearance %s)\n",
604  FormatInternalUnits( aSettings.m_CopperEdgeClearance ).c_str() );
605 
606  m_out->Print( aNestLevel+1, "(edge_cuts_line_width %s)\n",
607  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_EDGES ] ).c_str() );
608 
609  m_out->Print( aNestLevel+1, "(courtyard_line_width %s)\n",
611 
612  m_out->Print( aNestLevel+1, "(copper_line_width %s)\n",
613  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_COPPER ] ).c_str() );
614  m_out->Print( aNestLevel+1, "(copper_text_dims (size %s %s) (thickness %s)%s%s)\n",
615  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_COPPER ].x ).c_str(),
616  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_COPPER ].y ).c_str(),
618  aSettings.m_TextItalic[ LAYER_CLASS_COPPER ] ? " italic" : "",
619  aSettings.m_TextUpright[ LAYER_CLASS_COPPER ] ? " keep_upright" : "" );
620 
621  m_out->Print( aNestLevel+1, "(silk_line_width %s)\n",
622  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_SILK ] ).c_str() );
623  m_out->Print( aNestLevel+1, "(silk_text_dims (size %s %s) (thickness %s)%s%s)\n",
624  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_SILK ].x ).c_str(),
625  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_SILK ].y ).c_str(),
626  FormatInternalUnits( aSettings.m_TextThickness[ LAYER_CLASS_SILK ] ).c_str(),
627  aSettings.m_TextItalic[ LAYER_CLASS_SILK ] ? " italic" : "",
628  aSettings.m_TextUpright[ LAYER_CLASS_SILK ] ? " keep_upright" : "" );
629 
630  m_out->Print( aNestLevel+1, "(other_layers_line_width %s)\n",
631  FormatInternalUnits( aSettings.m_LineThickness[ LAYER_CLASS_OTHERS ] ).c_str() );
632  m_out->Print( aNestLevel+1, "(other_layers_text_dims (size %s %s) (thickness %s)%s%s)\n",
633  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_OTHERS ].x ).c_str(),
634  FormatInternalUnits( aSettings.m_TextSize[ LAYER_CLASS_OTHERS ].y ).c_str(),
636  aSettings.m_TextItalic[ LAYER_CLASS_OTHERS ] ? " italic" : "",
637  aSettings.m_TextUpright[ LAYER_CLASS_OTHERS ] ? " keep_upright" : "" );
638 
639  m_out->Print( aNestLevel+1, "(dimension_units %d)\n", aSettings.m_DimensionUnits );
640  m_out->Print( aNestLevel+1, "(dimension_precision %d)\n", aSettings.m_DimensionPrecision );
641 
642  m_out->Print( aNestLevel, ")\n" );
643 }
644 
645 
646 void PCB_IO::formatGeneral( BOARD* aBoard, int aNestLevel ) const
647 {
648  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
649 
650  m_out->Print( 0, "\n" );
651  m_out->Print( aNestLevel, "(general\n" );
652  // Write Bounding box info
653  m_out->Print( aNestLevel+1, "(thickness %s)\n",
654  FormatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() );
655 
656  m_out->Print( aNestLevel+1, "(drawings %u)\n", (unsigned)aBoard->Drawings().size() );
657  m_out->Print( aNestLevel + 1, "(tracks %u)\n", (unsigned)aBoard->Tracks().size() );
658  m_out->Print( aNestLevel + 1, "(modules %u)\n", (unsigned)aBoard->Modules().size() );
659  m_out->Print( aNestLevel+1, "(nets %d)\n", m_mapping->GetSize() );
660  m_out->Print( aNestLevel, ")\n\n" );
661 
662  aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
663  aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
664 }
665 
666 
667 void PCB_IO::formatBoardLayers( BOARD* aBoard, int aNestLevel ) const
668 {
669  m_out->Print( aNestLevel, "(layers\n" );
670 
671  // Save only the used copper layers from front to back.
672  LSET visible_layers = aBoard->GetVisibleLayers();
673 
674  for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
675  {
676  PCB_LAYER_ID layer = *cu;
677 
678  m_out->Print( aNestLevel+1, "(%d %s %s", layer,
679  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
680  LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
681 
682  if( !visible_layers[layer] )
683  m_out->Print( 0, " hide" );
684 
685  m_out->Print( 0, ")\n" );
686  }
687 
688  // Save used non-copper layers in the order they are defined.
689  // desired sequence for non Cu BOARD layers.
690  static const PCB_LAYER_ID non_cu[] =
691  {
692  B_Adhes, // 32
693  F_Adhes,
694  B_Paste,
695  F_Paste,
696  B_SilkS,
697  F_SilkS,
698  B_Mask,
699  F_Mask,
700  Dwgs_User,
701  Cmts_User,
702  Eco1_User,
703  Eco2_User,
704  Edge_Cuts,
705  Margin,
706  B_CrtYd,
707  F_CrtYd,
708  B_Fab,
709  F_Fab
710  };
711 
712  for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
713  {
714  PCB_LAYER_ID layer = *seq;
715 
716  m_out->Print( aNestLevel+1, "(%d %s user", layer,
717  m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
718 
719  if( !visible_layers[layer] )
720  m_out->Print( 0, " hide" );
721 
722  m_out->Print( 0, ")\n" );
723  }
724 
725  m_out->Print( aNestLevel, ")\n\n" );
726 }
727 
728 
729 void PCB_IO::formatNetInformation( BOARD* aBoard, int aNestLevel ) const
730 {
731  const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
732  for( NETINFO_ITEM* net : *m_mapping )
733  {
734  m_out->Print( aNestLevel, "(net %d %s)\n",
735  m_mapping->Translate( net->GetNet() ),
736  m_out->Quotew( net->GetNetname() ).c_str() );
737  }
738 
739  m_out->Print( 0, "\n" );
740 
741  // Save the default net class first.
742  NETCLASS defaultNC = *dsnSettings.GetDefault();
743  filterNetClass( *aBoard, defaultNC ); // Remove empty nets (from a copy of a netclass)
744  defaultNC.Format( m_out, aNestLevel, m_ctl );
745 
746  // Save the rest of the net classes alphabetically.
747  for( const auto& it : dsnSettings.m_NetClasses )
748  {
749  NETCLASS netclass = *it.second;
750  filterNetClass( *aBoard, netclass ); // Remove empty nets (from a copy of a netclass)
751  netclass.Format( m_out, aNestLevel, m_ctl );
752  }
753 }
754 
755 
756 void PCB_IO::formatHeader( BOARD* aBoard, int aNestLevel ) const
757 {
758  formatGeneral( aBoard, aNestLevel );
759  // Layers list.
760  formatBoardLayers( aBoard, aNestLevel );
761 
762  // Setup
763  formatSetup( aBoard, aNestLevel );
764 
765  // Save net codes and names
766  formatNetInformation( aBoard, aNestLevel );
767 }
768 
769 void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const
770 {
771  formatHeader( aBoard, aNestLevel );
772 
773  // Save the modules.
774  for( auto module : aBoard->Modules() )
775  {
776  Format( module, aNestLevel );
777  m_out->Print( 0, "\n" );
778  }
779 
780  // Save the graphical items on the board (not owned by a module)
781  for( auto item : aBoard->Drawings() )
782  Format( item, aNestLevel );
783 
784  if( aBoard->Drawings().size() )
785  m_out->Print( 0, "\n" );
786 
787  // Do not save MARKER_PCBs, they can be regenerated easily.
788 
789  // Save the tracks and vias.
790  for( auto track : aBoard->Tracks() )
791  Format( track, aNestLevel );
792 
793  if( aBoard->Tracks().size() )
794  m_out->Print( 0, "\n" );
795 
796  // Save the polygon (which are the newer technology) zones.
797  for( int i = 0; i < aBoard->GetAreaCount(); ++i )
798  Format( aBoard->GetArea( i ), aNestLevel );
799 }
800 
801 
802 void PCB_IO::format( DIMENSION* aDimension, int aNestLevel ) const
803 {
804  m_out->Print( aNestLevel, "(dimension %s (width %s)",
805  FormatInternalUnits( aDimension->GetValue() ).c_str(),
806  FormatInternalUnits( aDimension->GetWidth() ).c_str() );
807 
808  formatLayer( aDimension );
809 
810  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aDimension->m_Uuid.AsString() ) );
811 
812  m_out->Print( 0, "\n" );
813 
814  Format( &aDimension->Text(), aNestLevel+1 );
815 
816  m_out->Print( aNestLevel+1, "(feature1 (pts (xy %s %s) (xy %s %s)))\n",
817  FormatInternalUnits( aDimension->m_featureLineDO.x ).c_str(),
818  FormatInternalUnits( aDimension->m_featureLineDO.y ).c_str(),
819  FormatInternalUnits( aDimension->m_featureLineDF.x ).c_str(),
820  FormatInternalUnits( aDimension->m_featureLineDF.y ).c_str() );
821 
822  m_out->Print( aNestLevel+1, "(feature2 (pts (xy %s %s) (xy %s %s)))\n",
823  FormatInternalUnits( aDimension->m_featureLineGO.x ).c_str(),
824  FormatInternalUnits( aDimension->m_featureLineGO.y ).c_str(),
825  FormatInternalUnits( aDimension->m_featureLineGF.x ).c_str(),
826  FormatInternalUnits( aDimension->m_featureLineGF.y ).c_str() );
827 
828  m_out->Print( aNestLevel+1, "(crossbar (pts (xy %s %s) (xy %s %s)))\n",
829  FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
830  FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
831  FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
832  FormatInternalUnits( aDimension->m_crossBarF.y ).c_str() );
833 
834  m_out->Print( aNestLevel+1, "(arrow1a (pts (xy %s %s) (xy %s %s)))\n",
835  FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
836  FormatInternalUnits( aDimension->m_crossBarF.y ).c_str(),
837  FormatInternalUnits( aDimension->m_arrowD1F.x ).c_str(),
838  FormatInternalUnits( aDimension->m_arrowD1F.y ).c_str() );
839 
840  m_out->Print( aNestLevel+1, "(arrow1b (pts (xy %s %s) (xy %s %s)))\n",
841  FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
842  FormatInternalUnits( aDimension->m_crossBarF.y ).c_str(),
843  FormatInternalUnits( aDimension->m_arrowD2F.x ).c_str(),
844  FormatInternalUnits( aDimension->m_arrowD2F.y ).c_str() );
845 
846  m_out->Print( aNestLevel+1, "(arrow2a (pts (xy %s %s) (xy %s %s)))\n",
847  FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
848  FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
849  FormatInternalUnits( aDimension->m_arrowG1F.x ).c_str(),
850  FormatInternalUnits( aDimension->m_arrowG1F.y ).c_str() );
851 
852  m_out->Print( aNestLevel+1, "(arrow2b (pts (xy %s %s) (xy %s %s)))\n",
853  FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
854  FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
855  FormatInternalUnits( aDimension->m_arrowG2F.x ).c_str(),
856  FormatInternalUnits( aDimension->m_arrowG2F.y ).c_str() );
857 
858  m_out->Print( aNestLevel, ")\n" );
859 }
860 
861 
862 void PCB_IO::format( DRAWSEGMENT* aSegment, int aNestLevel ) const
863 {
864  switch( aSegment->GetShape() )
865  {
866  case S_SEGMENT: // Line
867  m_out->Print( aNestLevel, "(gr_line (start %s) (end %s)",
868  FormatInternalUnits( aSegment->GetStart() ).c_str(),
869  FormatInternalUnits( aSegment->GetEnd() ).c_str() );
870 
871  if( aSegment->GetAngle() != 0.0 )
872  m_out->Print( 0, " (angle %s)", FormatAngle( aSegment->GetAngle() ).c_str() );
873 
874  break;
875 
876  case S_CIRCLE: // Circle
877  m_out->Print( aNestLevel, "(gr_circle (center %s) (end %s)",
878  FormatInternalUnits( aSegment->GetStart() ).c_str(),
879  FormatInternalUnits( aSegment->GetEnd() ).c_str() );
880  break;
881 
882  case S_ARC: // Arc
883  m_out->Print( aNestLevel, "(gr_arc (start %s) (end %s) (angle %s)",
884  FormatInternalUnits( aSegment->GetStart() ).c_str(),
885  FormatInternalUnits( aSegment->GetEnd() ).c_str(),
886  FormatAngle( aSegment->GetAngle() ).c_str() );
887  break;
888 
889  case S_POLYGON: // Polygon
890  if( aSegment->IsPolyShapeValid() )
891  {
892  SHAPE_POLY_SET& poly = aSegment->GetPolyShape();
893  SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
894  int pointsCount = outline.PointCount();
895 
896  m_out->Print( aNestLevel, "(gr_poly (pts" );
897 
898  for( int ii = 0; ii < pointsCount; ++ii )
899  {
900  m_out->Print( 0, " (xy %s)", FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
901  }
902 
903  m_out->Print( 0, ")" );
904  }
905  else
906  {
907  wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
908  return;
909  }
910 
911  break;
912 
913  case S_CURVE: // Bezier curve
914  m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
915  FormatInternalUnits( aSegment->GetStart() ).c_str(),
916  FormatInternalUnits( aSegment->GetBezControl1() ).c_str(),
917  FormatInternalUnits( aSegment->GetBezControl2() ).c_str(),
918  FormatInternalUnits( aSegment->GetEnd() ).c_str() );
919  break;
920 
921  default:
922  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
923  return;
924  };
925 
926  formatLayer( aSegment );
927 
928  m_out->Print( 0, " (width %s)", FormatInternalUnits( aSegment->GetWidth() ).c_str() );
929 
930  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aSegment->m_Uuid.AsString() ) );
931 
932  if( aSegment->GetStatus() )
933  m_out->Print( 0, " (status %X)", aSegment->GetStatus() );
934 
935  m_out->Print( 0, ")\n" );
936 }
937 
938 
939 void PCB_IO::format( EDGE_MODULE* aModuleDrawing, int aNestLevel ) const
940 {
941  switch( aModuleDrawing->GetShape() )
942  {
943  case S_SEGMENT: // Line
944  m_out->Print( aNestLevel, "(fp_line (start %s) (end %s)",
945  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
946  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
947  break;
948 
949  case S_CIRCLE: // Circle
950  m_out->Print( aNestLevel, "(fp_circle (center %s) (end %s)",
951  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
952  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
953  break;
954 
955  case S_ARC: // Arc
956  m_out->Print( aNestLevel, "(fp_arc (start %s) (end %s) (angle %s)",
957  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
958  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str(),
959  FormatAngle( aModuleDrawing->GetAngle() ).c_str() );
960  break;
961 
962  case S_POLYGON: // Polygonal segment
963  if( aModuleDrawing->IsPolyShapeValid() )
964  {
965  SHAPE_POLY_SET& poly = aModuleDrawing->GetPolyShape();
966  SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
967  int pointsCount = outline.PointCount();
968 
969  m_out->Print( aNestLevel, "(fp_poly (pts" );
970 
971  for( int ii = 0; ii < pointsCount; ++ii )
972  {
973  int nestLevel = 0;
974 
975  if( ii && !( ii%4 ) ) // newline every 4 pts
976  {
977  nestLevel = aNestLevel + 1;
978  m_out->Print( 0, "\n" );
979  }
980 
981  m_out->Print( nestLevel, "%s(xy %s)",
982  nestLevel ? "" : " ", FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
983  }
984 
985  m_out->Print( 0, ")" );
986  }
987  else
988  {
989  wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
990  return;
991  }
992  break;
993 
994  case S_CURVE: // Bezier curve
995  m_out->Print( aNestLevel, "(fp_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
996  FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
997  FormatInternalUnits( aModuleDrawing->GetBezier0_C1() ).c_str(),
998  FormatInternalUnits( aModuleDrawing->GetBezier0_C2() ).c_str(),
999  FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
1000  break;
1001 
1002  default:
1003  wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
1004  return;
1005  };
1006 
1007  formatLayer( aModuleDrawing );
1008 
1009  m_out->Print( 0, " (width %s)", FormatInternalUnits( aModuleDrawing->GetWidth() ).c_str() );
1010 
1011  m_out->Print( 0, ")\n" );
1012 }
1013 
1014 
1015 void PCB_IO::format( PCB_TARGET* aTarget, int aNestLevel ) const
1016 {
1017  m_out->Print( aNestLevel, "(target %s (at %s) (size %s)",
1018  ( aTarget->GetShape() ) ? "x" : "plus",
1019  FormatInternalUnits( aTarget->GetPosition() ).c_str(),
1020  FormatInternalUnits( aTarget->GetSize() ).c_str() );
1021 
1022  if( aTarget->GetWidth() != 0 )
1023  m_out->Print( 0, " (width %s)", FormatInternalUnits( aTarget->GetWidth() ).c_str() );
1024 
1025  formatLayer( aTarget );
1026 
1027  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aTarget->m_Uuid.AsString() ) );
1028 
1029  m_out->Print( 0, ")\n" );
1030 }
1031 
1032 
1033 void PCB_IO::format( MODULE* aModule, int aNestLevel ) const
1034 {
1035  if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
1036  {
1037  const wxArrayString* initial_comments = aModule->GetInitialComments();
1038 
1039  if( initial_comments )
1040  {
1041  for( unsigned i=0; i<initial_comments->GetCount(); ++i )
1042  m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) );
1043 
1044  m_out->Print( 0, "\n" ); // improve readability?
1045  }
1046  }
1047 
1048  m_out->Print( aNestLevel, "(module %s",
1049  m_out->Quotes( aModule->GetFPID().Format() ).c_str() );
1050 
1051  if( aModule->IsLocked() )
1052  m_out->Print( 0, " locked" );
1053 
1054  if( aModule->IsPlaced() )
1055  m_out->Print( 0, " placed" );
1056 
1057  formatLayer( aModule );
1058 
1059  m_out->Print( 0, " (tedit %lX)", (unsigned long)aModule->GetLastEditTime() );
1060 
1061  if( !( m_ctl & CTL_OMIT_TSTAMPS ) )
1062  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aModule->m_Uuid.AsString() ) );
1063 
1064  m_out->Print( 0, "\n" );
1065 
1066  if( !( m_ctl & CTL_OMIT_AT ) )
1067  {
1068  m_out->Print( aNestLevel+1, "(at %s", FormatInternalUnits( aModule->GetPosition() ).c_str() );
1069 
1070  if( aModule->GetOrientation() != 0.0 )
1071  m_out->Print( 0, " %s", FormatAngle( aModule->GetOrientation() ).c_str() );
1072 
1073  m_out->Print( 0, ")\n" );
1074  }
1075 
1076  if( !aModule->GetDescription().IsEmpty() )
1077  m_out->Print( aNestLevel+1, "(descr %s)\n",
1078  m_out->Quotew( aModule->GetDescription() ).c_str() );
1079 
1080  if( !aModule->GetKeywords().IsEmpty() )
1081  m_out->Print( aNestLevel+1, "(tags %s)\n",
1082  m_out->Quotew( aModule->GetKeywords() ).c_str() );
1083 
1084  if( !( m_ctl & CTL_OMIT_PATH ) && !aModule->GetPath().empty() )
1085  m_out->Print( aNestLevel+1, "(path %s)\n",
1086  m_out->Quotew( aModule->GetPath().AsString() ).c_str() );
1087 
1088  if( aModule->GetPlacementCost90() != 0 )
1089  m_out->Print( aNestLevel+1, "(autoplace_cost90 %d)\n", aModule->GetPlacementCost90() );
1090 
1091  if( aModule->GetPlacementCost180() != 0 )
1092  m_out->Print( aNestLevel+1, "(autoplace_cost180 %d)\n", aModule->GetPlacementCost180() );
1093 
1094  if( aModule->GetLocalSolderMaskMargin() != 0 )
1095  m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n",
1096  FormatInternalUnits( aModule->GetLocalSolderMaskMargin() ).c_str() );
1097 
1098  if( aModule->GetLocalSolderPasteMargin() != 0 )
1099  m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n",
1100  FormatInternalUnits( aModule->GetLocalSolderPasteMargin() ).c_str() );
1101 
1102  if( aModule->GetLocalSolderPasteMarginRatio() != 0 )
1103  m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
1104  Double2Str( aModule->GetLocalSolderPasteMarginRatio() ).c_str() );
1105 
1106  if( aModule->GetLocalClearance() != 0 )
1107  m_out->Print( aNestLevel+1, "(clearance %s)\n",
1108  FormatInternalUnits( aModule->GetLocalClearance() ).c_str() );
1109 
1110  if( aModule->GetZoneConnection() != ZONE_CONNECTION::INHERITED )
1111  m_out->Print( aNestLevel+1, "(zone_connect %d)\n",
1112  static_cast<int>( aModule->GetZoneConnection() ) );
1113 
1114  if( aModule->GetThermalWidth() != 0 )
1115  m_out->Print( aNestLevel+1, "(thermal_width %s)\n",
1116  FormatInternalUnits( aModule->GetThermalWidth() ).c_str() );
1117 
1118  if( aModule->GetThermalGap() != 0 )
1119  m_out->Print( aNestLevel+1, "(thermal_gap %s)\n",
1120  FormatInternalUnits( aModule->GetThermalGap() ).c_str() );
1121 
1122  // Attributes
1123  if( aModule->GetAttributes() != MOD_DEFAULT )
1124  {
1125  m_out->Print( aNestLevel+1, "(attr" );
1126 
1127  if( aModule->GetAttributes() & MOD_CMS )
1128  m_out->Print( 0, " smd" );
1129 
1130  if( aModule->GetAttributes() & MOD_VIRTUAL )
1131  m_out->Print( 0, " virtual" );
1132 
1133  m_out->Print( 0, ")\n" );
1134  }
1135 
1136  Format( (BOARD_ITEM*) &aModule->Reference(), aNestLevel+1 );
1137  Format( (BOARD_ITEM*) &aModule->Value(), aNestLevel+1 );
1138 
1139  // Save drawing elements.
1140  for( auto gr : aModule->GraphicalItems() )
1141  Format( gr, aNestLevel+1 );
1142 
1143  // Save pads.
1144  for( auto pad : aModule->Pads() )
1145  format( pad, aNestLevel+1 );
1146 
1147  // Save zones.
1148  for( auto zone : aModule->Zones() )
1149  format( zone, aNestLevel + 1 );
1150 
1151  // Save 3D info.
1152  auto bs3D = aModule->Models().begin();
1153  auto es3D = aModule->Models().end();
1154 
1155  while( bs3D != es3D )
1156  {
1157  if( !bs3D->m_Filename.IsEmpty() )
1158  {
1159  m_out->Print( aNestLevel+1, "(model %s\n",
1160  m_out->Quotew( bs3D->m_Filename ).c_str() );
1161 
1162  /* Write 3D model offset in mm
1163  * 4.0.x wrote "at" which was actually in inches
1164  * 5.0.x onwards, 3D model offset is written using "offset"
1165  *
1166  * If the offset is all zero, write "at" (fewer file changes)
1167  * Otherwise, write "offset"
1168  */
1169 
1170  wxString offsetTag = "offset";
1171 
1172  if( bs3D->m_Offset.x == 0 &&
1173  bs3D->m_Offset.y == 0 &&
1174  bs3D->m_Offset.z == 0 )
1175  {
1176  offsetTag = "at";
1177  }
1178 
1179  m_out->Print( aNestLevel+2, "(%s (xyz %s %s %s))\n",
1180  offsetTag.ToStdString().c_str(),
1181  Double2Str( bs3D->m_Offset.x ).c_str(),
1182  Double2Str( bs3D->m_Offset.y ).c_str(),
1183  Double2Str( bs3D->m_Offset.z ).c_str() );
1184 
1185  m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
1186  Double2Str( bs3D->m_Scale.x ).c_str(),
1187  Double2Str( bs3D->m_Scale.y ).c_str(),
1188  Double2Str( bs3D->m_Scale.z ).c_str() );
1189 
1190  m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
1191  Double2Str( bs3D->m_Rotation.x ).c_str(),
1192  Double2Str( bs3D->m_Rotation.y ).c_str(),
1193  Double2Str( bs3D->m_Rotation.z ).c_str() );
1194 
1195  m_out->Print( aNestLevel+1, ")\n" );
1196  }
1197  ++bs3D;
1198  }
1199 
1200  m_out->Print( aNestLevel, ")\n" );
1201 }
1202 
1203 
1204 void PCB_IO::formatLayers( LSET aLayerMask, int aNestLevel ) const
1205 {
1206  std::string output;
1207 
1208  if( aNestLevel == 0 )
1209  output += ' ';
1210 
1211  output += "(layers";
1212 
1213  static const LSET cu_all( LSET::AllCuMask() );
1214  static const LSET fr_bk( 2, B_Cu, F_Cu );
1215  static const LSET adhes( 2, B_Adhes, F_Adhes );
1216  static const LSET paste( 2, B_Paste, F_Paste );
1217  static const LSET silks( 2, B_SilkS, F_SilkS );
1218  static const LSET mask( 2, B_Mask, F_Mask );
1219  static const LSET crt_yd(2, B_CrtYd, F_CrtYd );
1220  static const LSET fab( 2, B_Fab, F_Fab );
1221 
1222  LSET cu_mask = cu_all;
1223 
1224  // output copper layers first, then non copper
1225 
1226  if( ( aLayerMask & cu_mask ) == cu_mask )
1227  {
1228  output += " *.Cu";
1229  aLayerMask &= ~cu_all; // clear bits, so they are not output again below
1230  }
1231  else if( ( aLayerMask & cu_mask ) == fr_bk )
1232  {
1233  output += " F&B.Cu";
1234  aLayerMask &= ~fr_bk;
1235  }
1236 
1237  if( ( aLayerMask & adhes ) == adhes )
1238  {
1239  output += " *.Adhes";
1240  aLayerMask &= ~adhes;
1241  }
1242 
1243  if( ( aLayerMask & paste ) == paste )
1244  {
1245  output += " *.Paste";
1246  aLayerMask &= ~paste;
1247  }
1248 
1249  if( ( aLayerMask & silks ) == silks )
1250  {
1251  output += " *.SilkS";
1252  aLayerMask &= ~silks;
1253  }
1254 
1255  if( ( aLayerMask & mask ) == mask )
1256  {
1257  output += " *.Mask";
1258  aLayerMask &= ~mask;
1259  }
1260 
1261  if( ( aLayerMask & crt_yd ) == crt_yd )
1262  {
1263  output += " *.CrtYd";
1264  aLayerMask &= ~crt_yd;
1265  }
1266 
1267  if( ( aLayerMask & fab ) == fab )
1268  {
1269  output += " *.Fab";
1270  aLayerMask &= ~fab;
1271  }
1272 
1273  // output any individual layers not handled in wildcard combos above
1274 
1275  wxString layerName;
1276 
1277  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
1278  {
1279  if( aLayerMask[layer] )
1280  {
1281  if( m_board && !( m_ctl & CTL_STD_LAYER_NAMES ) )
1282  layerName = m_board->GetLayerName( PCB_LAYER_ID( layer ) );
1283 
1284  else // I am being called from FootprintSave()
1285  layerName = BOARD::GetStandardLayerName( PCB_LAYER_ID( layer ) );
1286 
1287  output += ' ';
1288  output += m_out->Quotew( layerName );
1289  }
1290  }
1291 
1292  m_out->Print( aNestLevel, "%s)", output.c_str() );
1293 }
1294 
1295 
1296 void PCB_IO::format( D_PAD* aPad, int aNestLevel ) const
1297 {
1298  const char* shape;
1299 
1300  switch( aPad->GetShape() )
1301  {
1302  case PAD_SHAPE_CIRCLE: shape = "circle"; break;
1303  case PAD_SHAPE_RECT: shape = "rect"; break;
1304  case PAD_SHAPE_OVAL: shape = "oval"; break;
1305  case PAD_SHAPE_TRAPEZOID: shape = "trapezoid"; break;
1307  case PAD_SHAPE_ROUNDRECT: shape = "roundrect"; break;
1308  case PAD_SHAPE_CUSTOM: shape = "custom"; break;
1309 
1310  default:
1311  THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"), aPad->GetShape() ) );
1312  }
1313 
1314  const char* type;
1315 
1316  switch( aPad->GetAttribute() )
1317  {
1318  case PAD_ATTRIB_STANDARD: type = "thru_hole"; break;
1319  case PAD_ATTRIB_SMD: type = "smd"; break;
1320  case PAD_ATTRIB_CONN: type = "connect"; break;
1321  case PAD_ATTRIB_HOLE_NOT_PLATED: type = "np_thru_hole"; break;
1322 
1323  default:
1324  THROW_IO_ERROR( wxString::Format( "unknown pad attribute: %d", aPad->GetAttribute() ) );
1325  }
1326 
1327  const char* property = nullptr;
1328 
1329  switch( aPad->GetProperty() )
1330  {
1331  case PAD_PROP_NONE: break;
1332  case PAD_PROP_BGA: property = "pad_prop_bga"; break;
1333  case PAD_PROP_FIDUCIAL_GLBL: property = "pad_prop_fiducial_glob"; break;
1334  case PAD_PROP_FIDUCIAL_LOCAL: property = "pad_prop_fiducial_loc"; break;
1335  case PAD_PROP_TESTPOINT: property = "pad_prop_testpoint"; break;
1336  case PAD_PROP_HEATSINK: property = "pad_prop_heatsink"; break;
1337  case PAD_PROP_CASTELLATED: property = "pad_prop_castellated"; break;
1338 
1339  default:
1340  THROW_IO_ERROR( wxString::Format( "unknown pad property: %d", aPad->GetProperty() ) );
1341  }
1342 
1343  m_out->Print( aNestLevel, "(pad %s %s %s",
1344  m_out->Quotew( aPad->GetName() ).c_str(),
1345  type, shape );
1346  m_out->Print( 0, " (at %s", FormatInternalUnits( aPad->GetPos0() ).c_str() );
1347 
1348  if( aPad->GetOrientation() != 0.0 )
1349  m_out->Print( 0, " %s", FormatAngle( aPad->GetOrientation() ).c_str() );
1350 
1351  m_out->Print( 0, ")" );
1352  m_out->Print( 0, " (size %s)", FormatInternalUnits( aPad->GetSize() ).c_str() );
1353 
1354  if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) )
1355  m_out->Print( 0, " (rect_delta %s )", FormatInternalUnits( aPad->GetDelta() ).c_str() );
1356 
1357  wxSize sz = aPad->GetDrillSize();
1358  wxPoint shapeoffset = aPad->GetOffset();
1359 
1360  if( (sz.GetWidth() > 0) || (sz.GetHeight() > 0) ||
1361  (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1362  {
1363  m_out->Print( 0, " (drill" );
1364 
1365  if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
1366  m_out->Print( 0, " oval" );
1367 
1368  if( sz.GetWidth() > 0 )
1369  m_out->Print( 0, " %s", FormatInternalUnits( sz.GetWidth() ).c_str() );
1370 
1371  if( sz.GetHeight() > 0 && sz.GetWidth() != sz.GetHeight() )
1372  m_out->Print( 0, " %s", FormatInternalUnits( sz.GetHeight() ).c_str() );
1373 
1374  if( (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1375  m_out->Print( 0, " (offset %s)", FormatInternalUnits( aPad->GetOffset() ).c_str() );
1376 
1377  m_out->Print( 0, ")" );
1378  }
1379 
1380  if( property && ADVANCED_CFG::GetCfg().m_EnableUsePadProperty )
1381  {
1382  // Add pad property, if exists.
1383  m_out->Print( 0, " (property %s)", property );
1384  }
1385 
1386  formatLayers( aPad->GetLayerSet() );
1387 
1388  // Output the radius ratio for rounded and chamfered rect pads
1389  if( aPad->GetShape() == PAD_SHAPE_ROUNDRECT || aPad->GetShape() == PAD_SHAPE_CHAMFERED_RECT)
1390  {
1391  m_out->Print( 0, " (roundrect_rratio %s)",
1392  Double2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
1393  }
1394 
1395  // Output the chamfer corners for chamfered rect pads
1396  if( aPad->GetShape() == PAD_SHAPE_CHAMFERED_RECT)
1397  {
1398  m_out->Print( 0, "\n" );
1399 
1400  m_out->Print( aNestLevel+1, "(chamfer_ratio %s)",
1401  Double2Str( aPad->GetChamferRectRatio() ).c_str() );
1402 
1403  m_out->Print( 0, " (chamfer" );
1404 
1405  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_TOP_LEFT ) )
1406  m_out->Print( 0, " top_left" );
1407 
1408  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_TOP_RIGHT ) )
1409  m_out->Print( 0, " top_right" );
1410 
1411  if( ( aPad->GetChamferPositions() & RECT_CHAMFER_BOTTOM_LEFT ) )
1412  m_out->Print( 0, " bottom_left" );
1413 
1415  m_out->Print( 0, " bottom_right" );
1416 
1417  m_out->Print( 0, ")" );
1418  }
1419 
1420  std::string output;
1421 
1422  // Unconnected pad is default net so don't save it.
1423  if( !( m_ctl & CTL_OMIT_NETS ) && aPad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
1424  StrPrintf( &output, " (net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
1425  m_out->Quotew( aPad->GetNetname() ).c_str() );
1426 
1428  {
1429  // Add pinfunction, if exists.
1430  // Pin function is closely related to nets, so if CTL_OMIT_NETS is set,
1431  // omit also pin function (for instance when saved from library editor)
1432  if( !(m_ctl & CTL_OMIT_NETS) && !aPad->GetPinFunction().IsEmpty() )
1433  StrPrintf( &output, " (pinfunction %s)",
1434  m_out->Quotew( aPad->GetPinFunction() ).c_str() );
1435  }
1436 
1437  if( aPad->GetPadToDieLength() != 0 )
1438  StrPrintf( &output, " (die_length %s)",
1439  FormatInternalUnits( aPad->GetPadToDieLength() ).c_str() );
1440 
1441  if( aPad->GetLocalSolderMaskMargin() != 0 )
1442  StrPrintf( &output, " (solder_mask_margin %s)",
1443  FormatInternalUnits( aPad->GetLocalSolderMaskMargin() ).c_str() );
1444 
1445  if( aPad->GetLocalSolderPasteMargin() != 0 )
1446  StrPrintf( &output, " (solder_paste_margin %s)",
1447  FormatInternalUnits( aPad->GetLocalSolderPasteMargin() ).c_str() );
1448 
1449  if( aPad->GetLocalSolderPasteMarginRatio() != 0 )
1450  StrPrintf( &output, " (solder_paste_margin_ratio %s)",
1451  Double2Str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
1452 
1453  if( aPad->GetLocalClearance() != 0 )
1454  StrPrintf( &output, " (clearance %s)", FormatInternalUnits( aPad->GetLocalClearance() ).c_str() );
1455 
1457  StrPrintf( &output, " (zone_connect %d)", static_cast<int>( aPad->GetZoneConnection() ) );
1458 
1459  if( aPad->GetThermalWidth() != 0 )
1460  StrPrintf( &output, " (thermal_width %s)", FormatInternalUnits( aPad->GetThermalWidth() ).c_str() );
1461 
1462  if( aPad->GetThermalGap() != 0 )
1463  StrPrintf( &output, " (thermal_gap %s)", FormatInternalUnits( aPad->GetThermalGap() ).c_str() );
1464 
1465  if( output.size() )
1466  {
1467  m_out->Print( 0, "\n" );
1468  m_out->Print( aNestLevel+1, "%s", output.c_str()+1 ); // +1 skips 1st space on 1st element
1469  }
1470 
1471  if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
1472  {
1473  m_out->Print( 0, "\n");
1474  m_out->Print( aNestLevel+1, "(options" );
1475 
1477  m_out->Print( 0, " (clearance convexhull)" );
1478  #if 1 // Set to 1 to output the default option
1479  else
1480  m_out->Print( 0, " (clearance outline)" );
1481  #endif
1482 
1483  // Output the anchor pad shape (circle/rect)
1484  if( aPad->GetAnchorPadShape() == PAD_SHAPE_RECT )
1485  shape = "rect";
1486  else
1487  shape = "circle";
1488 
1489  m_out->Print( 0, " (anchor %s)", shape );
1490 
1491  m_out->Print( 0, ")"); // end of (options ...
1492 
1493  // Output graphic primitive of the pad shape
1494  m_out->Print( 0, "\n");
1495  m_out->Print( aNestLevel+1, "(primitives" );
1496 
1497  int nested_level = aNestLevel+2;
1498 
1499  // Output all basic shapes
1500  for( unsigned icnt = 0; icnt < aPad->GetPrimitives().size(); ++icnt )
1501  {
1502  m_out->Print( 0, "\n");
1503 
1504  const PAD_CS_PRIMITIVE& primitive = aPad->GetPrimitives()[icnt];
1505 
1506  switch( primitive.m_Shape )
1507  {
1508  case S_SEGMENT: // usual segment : line with rounded ends
1509  m_out->Print( nested_level, "(gr_line (start %s) (end %s) (width %s))",
1510  FormatInternalUnits( primitive.m_Start ).c_str(),
1511  FormatInternalUnits( primitive.m_End ).c_str(),
1512  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1513  break;
1514 
1515  case S_ARC: // Arc with rounded ends
1516  m_out->Print( nested_level, "(gr_arc (start %s) (end %s) (angle %s) (width %s))",
1517  FormatInternalUnits( primitive.m_Start ).c_str(),
1518  FormatInternalUnits( primitive.m_End ).c_str(),
1519  FormatAngle( primitive.m_ArcAngle ).c_str(),
1520  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1521  break;
1522 
1523  case S_CIRCLE: // ring or circle (circle if width == 0
1524  m_out->Print( nested_level, "(gr_circle (center %s) (end %s %s) (width %s))",
1525  FormatInternalUnits( primitive.m_Start ).c_str(),
1526  FormatInternalUnits( primitive.m_Start.x + primitive.m_Radius ).c_str(),
1527  FormatInternalUnits( primitive.m_Start.y ).c_str(),
1528  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1529  break;
1530 
1531  case S_CURVE: // Bezier Curve
1532  m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s)) (width %s))",
1533  FormatInternalUnits( primitive.m_Start ).c_str(),
1534  FormatInternalUnits( primitive.m_Ctrl1 ).c_str(),
1535  FormatInternalUnits( primitive.m_Ctrl2 ).c_str(),
1536  FormatInternalUnits( primitive.m_End ).c_str(),
1537  FormatInternalUnits( primitive.m_Thickness ).c_str() );
1538  break;
1539 
1540  case S_POLYGON: // polygon
1541  if( primitive.m_Poly.size() < 2 )
1542  break; // Malformed polygon.
1543 
1544  {
1545  m_out->Print( nested_level, "(gr_poly (pts\n");
1546 
1547  // Write the polygon corners coordinates:
1548  const std::vector< wxPoint>& poly = primitive.m_Poly;
1549  int newLine = 0;
1550 
1551  for( unsigned ii = 0; ii < poly.size(); ii++ )
1552  {
1553  if( newLine == 0 )
1554  m_out->Print( nested_level+1, " (xy %s)",
1555  FormatInternalUnits( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
1556  else
1557  m_out->Print( 0, " (xy %s)",
1558  FormatInternalUnits( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
1559 
1560  if( ++newLine > 4 )
1561  {
1562  newLine = 0;
1563  m_out->Print( 0, "\n" );
1564  }
1565  }
1566 
1567  m_out->Print( 0, ") (width %s))", FormatInternalUnits( primitive.m_Thickness ).c_str() );
1568  }
1569  break;
1570 
1571  default:
1572  break;
1573  }
1574  }
1575 
1576  m_out->Print( 0, "\n");
1577  m_out->Print( aNestLevel+1, ")" ); // end of (basic_shapes
1578  }
1579 
1580  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aPad->m_Uuid.AsString() ) );
1581 
1582  m_out->Print( 0, ")\n" );
1583 }
1584 
1585 
1586 void PCB_IO::format( TEXTE_PCB* aText, int aNestLevel ) const
1587 {
1588  m_out->Print( aNestLevel, "(gr_text %s (at %s",
1589  m_out->Quotew( aText->GetText() ).c_str(),
1590  FormatInternalUnits( aText->GetTextPos() ).c_str() );
1591 
1592  if( aText->GetTextAngle() != 0.0 )
1593  m_out->Print( 0, " %s", FormatAngle( aText->GetTextAngle() ).c_str() );
1594 
1595  m_out->Print( 0, ")" );
1596 
1597  formatLayer( aText );
1598 
1599  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aText->m_Uuid.AsString() ) );
1600 
1601  m_out->Print( 0, "\n" );
1602 
1603  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl );
1604 
1605  m_out->Print( aNestLevel, ")\n" );
1606 }
1607 
1608 
1609 void PCB_IO::format( TEXTE_MODULE* aText, int aNestLevel ) const
1610 {
1611  std::string type;
1612 
1613  switch( aText->GetType() )
1614  {
1615  case TEXTE_MODULE::TEXT_is_REFERENCE: type = "reference"; break;
1616  case TEXTE_MODULE::TEXT_is_VALUE: type = "value"; break;
1617  case TEXTE_MODULE::TEXT_is_DIVERS: type = "user";
1618  }
1619 
1620  m_out->Print( aNestLevel, "(fp_text %s %s (at %s",
1621  type.c_str(),
1622  m_out->Quotew( aText->GetText() ).c_str(),
1623  FormatInternalUnits( aText->GetPos0() ).c_str() );
1624 
1625  // Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle,
1626  // but internally the angle is held relative to its parent footprint. parent
1627  // may be NULL when saving a footprint outside a BOARD.
1628  double orient = aText->GetTextAngle();
1629  MODULE* parent = (MODULE*) aText->GetParent();
1630 
1631  if( parent )
1632  {
1633  // GetTextAngle() is always in -360..+360 range because of
1634  // TEXTE_MODULE::SetTextAngle(), but summing that angle with an
1635  // additional board angle could kick sum up >= 360 or <= -360, so to have
1636  // consistent results, normalize again for the BOARD save. A footprint
1637  // save does not use this code path since parent is NULL.
1638 #if 0
1639  // This one could be considered reasonable if you like positive angles
1640  // in your board text.
1641  orient = NormalizeAnglePos( orient + parent->GetOrientation() );
1642 #else
1643  // Choose compatibility for now, even though this is only a 720 degree clamp
1644  // with two possible values for every angle.
1645  orient = NormalizeAngle360Min( orient + parent->GetOrientation() );
1646 #endif
1647  }
1648 
1649  if( orient != 0.0 )
1650  m_out->Print( 0, " %s", FormatAngle( orient ).c_str() );
1651 
1652  if( !aText->IsKeepUpright() )
1653  m_out->Print( 0, " unlocked" );
1654 
1655  m_out->Print( 0, ")" );
1656  formatLayer( aText );
1657 
1658  if( !aText->IsVisible() )
1659  m_out->Print( 0, " hide" );
1660 
1661  m_out->Print( 0, "\n" );
1662 
1663  aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE );
1664 
1665  m_out->Print( aNestLevel, ")\n" );
1666 }
1667 
1668 
1669 void PCB_IO::format( TRACK* aTrack, int aNestLevel ) const
1670 {
1671  if( aTrack->Type() == PCB_VIA_T )
1672  {
1673  PCB_LAYER_ID layer1, layer2;
1674 
1675  const VIA* via = static_cast<const VIA*>( aTrack );
1676  BOARD* board = (BOARD*) via->GetParent();
1677 
1678  wxCHECK_RET( board != 0, wxT( "Via " ) + via->GetSelectMenuText( EDA_UNITS::MILLIMETRES )
1679  + wxT( " has no parent." ) );
1680 
1681  m_out->Print( aNestLevel, "(via" );
1682 
1683  via->LayerPair( &layer1, &layer2 );
1684 
1685  switch( via->GetViaType() )
1686  {
1687  case VIATYPE::THROUGH: // Default shape not saved.
1688  break;
1689 
1690  case VIATYPE::BLIND_BURIED:
1691  m_out->Print( 0, " blind" );
1692  break;
1693 
1694  case VIATYPE::MICROVIA:
1695  m_out->Print( 0, " micro" );
1696  break;
1697 
1698  default:
1699  THROW_IO_ERROR( wxString::Format( _( "unknown via type %d" ), via->GetViaType() ) );
1700  }
1701 
1702  m_out->Print( 0, " (at %s) (size %s)",
1703  FormatInternalUnits( aTrack->GetStart() ).c_str(),
1704  FormatInternalUnits( aTrack->GetWidth() ).c_str() );
1705 
1706  if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER )
1707  m_out->Print( 0, " (drill %s)", FormatInternalUnits( via->GetDrill() ).c_str() );
1708 
1709  m_out->Print( 0, " (layers %s %s)",
1710  m_out->Quotew( m_board->GetLayerName( layer1 ) ).c_str(),
1711  m_out->Quotew( m_board->GetLayerName( layer2 ) ).c_str() );
1712  }
1713  else if( aTrack->Type() == PCB_ARC_T )
1714  {
1715  const ARC* arc = static_cast<const ARC*>( aTrack );
1716 
1717  m_out->Print( aNestLevel, "(arc (start %s) (mid %s) (end %s) (width %s)",
1718  FormatInternalUnits( arc->GetStart() ).c_str(),
1719  FormatInternalUnits( arc->GetMid() ).c_str(),
1720  FormatInternalUnits( arc->GetEnd() ).c_str(),
1721  FormatInternalUnits( arc->GetWidth() ).c_str() );
1722 
1723  m_out->Print( 0, " (layer %s)", m_out->Quotew( aTrack->GetLayerName() ).c_str() );
1724  }
1725  else
1726  {
1727  m_out->Print( aNestLevel, "(segment (start %s) (end %s) (width %s)",
1728  FormatInternalUnits( aTrack->GetStart() ).c_str(), FormatInternalUnits( aTrack->GetEnd() ).c_str(),
1729  FormatInternalUnits( aTrack->GetWidth() ).c_str() );
1730 
1731  m_out->Print( 0, " (layer %s)", m_out->Quotew( aTrack->GetLayerName() ).c_str() );
1732  }
1733 
1734  m_out->Print( 0, " (net %d)", m_mapping->Translate( aTrack->GetNetCode() ) );
1735 
1736  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aTrack->m_Uuid.AsString() ) );
1737 
1738  if( aTrack->GetStatus() != 0 )
1739  m_out->Print( 0, " (status %X)", aTrack->GetStatus() );
1740 
1741  m_out->Print( 0, ")\n" );
1742 }
1743 
1744 
1745 void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const
1746 {
1747  // Save the NET info; For keepout zones, net code and net name are irrelevant
1748  // so be sure a dummy value is stored, just for ZONE_CONTAINER compatibility
1749  // (perhaps netcode and netname should be not stored)
1750  m_out->Print( aNestLevel, "(zone (net %d) (net_name %s)",
1751  aZone->GetIsKeepout() ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
1752  m_out->Quotew( aZone->GetIsKeepout() ? wxT("") : aZone->GetNetname() ).c_str() );
1753 
1754  // If a zone exists on multiple layers, format accordingly
1755  if( aZone->GetLayerSet().count() > 1 )
1756  {
1757  formatLayers( aZone->GetLayerSet() );
1758  }
1759  else
1760  {
1761  formatLayer( aZone );
1762  }
1763 
1764  m_out->Print( 0, " (tstamp %s)", TO_UTF8( aZone->m_Uuid.AsString() ) );
1765 
1766  // Save the outline aux info
1767  std::string hatch;
1768 
1769  switch( aZone->GetHatchStyle() )
1770  {
1771  default:
1773  hatch = "none";
1774  break;
1776  hatch = "edge";
1777  break;
1779  hatch = "full";
1780  break;
1781  }
1782 
1783  m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(),
1784  FormatInternalUnits( aZone->GetHatchPitch() ).c_str() );
1785 
1786  if( aZone->GetPriority() > 0 )
1787  m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetPriority() );
1788 
1789  m_out->Print( aNestLevel+1, "(connect_pads" );
1790 
1791  switch( aZone->GetPadConnection() )
1792  {
1793  default:
1794  case ZONE_CONNECTION::THERMAL: // Default option not saved or loaded.
1795  break;
1796 
1798  m_out->Print( 0, " thru_hole_only" );
1799  break;
1800 
1801  case ZONE_CONNECTION::FULL:
1802  m_out->Print( 0, " yes" );
1803  break;
1804 
1805  case ZONE_CONNECTION::NONE:
1806  m_out->Print( 0, " no" );
1807  break;
1808  }
1809 
1810  m_out->Print( 0, " (clearance %s))\n",
1811  FormatInternalUnits( aZone->GetZoneClearance() ).c_str() );
1812 
1813  m_out->Print( aNestLevel+1, "(min_thickness %s)",
1814  FormatInternalUnits( aZone->GetMinThickness() ).c_str() );
1815 
1816  // write it only if V 6.O version option is not used (i.e. do not write if the
1817  // "legacy" algorithm is used)
1818  if( !aZone->GetFilledPolysUseThickness() )
1819  m_out->Print( 0, " (filled_areas_thickness no)" );
1820 
1821  m_out->Print( 0, "\n" );
1822 
1823  if( aZone->GetIsKeepout() )
1824  {
1825  m_out->Print( aNestLevel+1, "(keepout (tracks %s) (vias %s) (copperpour %s))\n",
1826  aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
1827  aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
1828  aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed" );
1829  }
1830 
1831  m_out->Print( aNestLevel+1, "(fill" );
1832 
1833  // Default is not filled.
1834  if( aZone->IsFilled() )
1835  m_out->Print( 0, " yes" );
1836 
1837  // Default is polygon filled.
1838  if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1839  m_out->Print( 0, " (mode hatch)" );
1840 
1841  m_out->Print( 0, " (thermal_gap %s) (thermal_bridge_width %s)",
1842  FormatInternalUnits( aZone->GetThermalReliefGap() ).c_str(),
1843  FormatInternalUnits( aZone->GetThermalReliefCopperBridge() ).c_str() );
1844 
1846  {
1847  m_out->Print( 0, " (smoothing" );
1848 
1849  switch( aZone->GetCornerSmoothingType() )
1850  {
1852  m_out->Print( 0, " chamfer" );
1853  break;
1854 
1856  m_out->Print( 0, " fillet" );
1857  break;
1858 
1859  default:
1860  THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
1861  aZone->GetCornerSmoothingType() ) );
1862  }
1863  m_out->Print( 0, ")" );
1864 
1865  if( aZone->GetCornerRadius() != 0 )
1866  m_out->Print( 0, " (radius %s)",
1867  FormatInternalUnits( aZone->GetCornerRadius() ).c_str() );
1868  }
1869 
1870  if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
1871  {
1872  m_out->Print( 0, "\n" );
1873  m_out->Print( aNestLevel+2, "(hatch_thickness %s) (hatch_gap %s) (hatch_orientation %s)",
1874  FormatInternalUnits( aZone->GetHatchFillTypeThickness() ).c_str(),
1875  FormatInternalUnits( aZone->GetHatchFillTypeGap() ).c_str(),
1876  Double2Str( aZone->GetHatchFillTypeOrientation() ).c_str() );
1877 
1878  if( aZone->GetHatchFillTypeSmoothingLevel() > 0 )
1879  {
1880  m_out->Print( 0, "\n" );
1881  m_out->Print( aNestLevel+2, "(hatch_smoothing_level %d) (hatch_smoothing_value %s)",
1883  Double2Str( aZone->GetHatchFillTypeSmoothingValue() ).c_str() );
1884  }
1885  }
1886 
1887  m_out->Print( 0, ")\n" );
1888 
1889  int newLine = 0;
1890 
1891  if( aZone->GetNumCorners() )
1892  {
1893  bool new_polygon = true;
1894  bool is_closed = false;
1895 
1896  for( auto iterator = aZone->IterateWithHoles(); iterator; iterator++ )
1897  {
1898  if( new_polygon )
1899  {
1900  newLine = 0;
1901  m_out->Print( aNestLevel+1, "(polygon\n" );
1902  m_out->Print( aNestLevel+2, "(pts\n" );
1903  new_polygon = false;
1904  is_closed = false;
1905  }
1906 
1907  if( newLine == 0 )
1908  m_out->Print( aNestLevel+3, "(xy %s %s)",
1909  FormatInternalUnits( iterator->x ).c_str(), FormatInternalUnits( iterator->y ).c_str() );
1910  else
1911  m_out->Print( 0, " (xy %s %s)",
1912  FormatInternalUnits( iterator->x ).c_str(), FormatInternalUnits( iterator->y ).c_str() );
1913 
1914  if( newLine < 4 )
1915  {
1916  newLine += 1;
1917  }
1918  else
1919  {
1920  newLine = 0;
1921  m_out->Print( 0, "\n" );
1922  }
1923 
1924  if( iterator.IsEndContour() )
1925  {
1926  is_closed = true;
1927 
1928  if( newLine != 0 )
1929  m_out->Print( 0, "\n" );
1930 
1931  m_out->Print( aNestLevel+2, ")\n" );
1932  m_out->Print( aNestLevel+1, ")\n" );
1933  new_polygon = true;
1934  }
1935  }
1936 
1937  if( !is_closed ) // Should not happen, but...
1938  {
1939  if( newLine != 0 )
1940  m_out->Print( 0, "\n" );
1941 
1942  m_out->Print( aNestLevel+2, ")\n" );
1943  m_out->Print( aNestLevel+1, ")\n" );
1944  }
1945  }
1946 
1947  // Save the PolysList (filled areas)
1948  const SHAPE_POLY_SET& fv = aZone->GetFilledPolysList();
1949  newLine = 0;
1950 
1951  if( !fv.IsEmpty() )
1952  {
1953  bool new_polygon = true;
1954  bool is_closed = false;
1955 
1956  for( auto it = fv.CIterate(); it; ++it )
1957  {
1958  if( new_polygon )
1959  {
1960  newLine = 0;
1961  m_out->Print( aNestLevel+1, "(filled_polygon\n" );
1962  m_out->Print( aNestLevel+2, "(pts\n" );
1963  new_polygon = false;
1964  is_closed = false;
1965  }
1966 
1967  if( newLine == 0 )
1968  m_out->Print( aNestLevel+3, "(xy %s %s)",
1969  FormatInternalUnits( it->x ).c_str(), FormatInternalUnits( it->y ).c_str() );
1970  else
1971  m_out->Print( 0, " (xy %s %s)",
1972  FormatInternalUnits( it->x ) .c_str(), FormatInternalUnits( it->y ).c_str() );
1973 
1974  if( newLine < 4 )
1975  {
1976  newLine += 1;
1977  }
1978  else
1979  {
1980  newLine = 0;
1981  m_out->Print( 0, "\n" );
1982  }
1983 
1984  if( it.IsEndContour() )
1985  {
1986  is_closed = true;
1987 
1988  if( newLine != 0 )
1989  m_out->Print( 0, "\n" );
1990 
1991  m_out->Print( aNestLevel+2, ")\n" );
1992  m_out->Print( aNestLevel+1, ")\n" );
1993  new_polygon = true;
1994  }
1995  }
1996 
1997  if( !is_closed ) // Should not happen, but...
1998  m_out->Print( aNestLevel+1, ")\n" );
1999  }
2000 
2001  // Save the filling segments list
2002  const auto& segs = aZone->FillSegments();
2003 
2004  if( segs.size() )
2005  {
2006  m_out->Print( aNestLevel+1, "(fill_segments\n" );
2007 
2008  for( ZONE_SEGMENT_FILL::const_iterator it = segs.begin(); it != segs.end(); ++it )
2009  {
2010  m_out->Print( aNestLevel+2, "(pts (xy %s) (xy %s))\n",
2011  FormatInternalUnits( wxPoint( it->A ) ).c_str(),
2012  FormatInternalUnits( wxPoint( it->B ) ).c_str() );
2013  }
2014 
2015  m_out->Print( aNestLevel+1, ")\n" );
2016  }
2017 
2018  m_out->Print( aNestLevel, ")\n" );
2019 }
2020 
2021 
2022 PCB_IO::PCB_IO( int aControlFlags ) :
2023  m_cache( 0 ),
2024  m_ctl( aControlFlags ),
2025  m_parser( new PCB_PARSER() ),
2026  m_mapping( new NETINFO_MAPPING() )
2027 {
2028  init( 0 );
2029  m_out = &m_sf;
2030 }
2031 
2032 
2034 {
2035  delete m_cache;
2036  delete m_parser;
2037  delete m_mapping;
2038 }
2039 
2040 
2041 BOARD* PCB_IO::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties )
2042 {
2043  FILE_LINE_READER reader( aFileName );
2044 
2045  init( aProperties );
2046 
2047  m_parser->SetLineReader( &reader );
2048  m_parser->SetBoard( aAppendToMe );
2049 
2050  BOARD* board;
2051 
2052  try
2053  {
2054  board = dynamic_cast<BOARD*>( m_parser->Parse() );
2055  }
2056  catch( const FUTURE_FORMAT_ERROR& )
2057  {
2058  // Don't wrap a FUTURE_FORMAT_ERROR in another
2059  throw;
2060  }
2061  catch( const PARSE_ERROR& parse_error )
2062  {
2063  if( m_parser->IsTooRecent() )
2064  throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
2065  else
2066  throw;
2067  }
2068 
2069  if( !board )
2070  {
2071  // The parser loaded something that was valid, but wasn't a board.
2072  THROW_PARSE_ERROR( _( "this file does not contain a PCB" ),
2073  m_parser->CurSource(), m_parser->CurLine(),
2074  m_parser->CurLineNumber(), m_parser->CurOffset() );
2075  }
2076 
2077  // Give the filename to the board if it's new
2078  if( !aAppendToMe )
2079  board->SetFileName( aFileName );
2080 
2081  return board;
2082 }
2083 
2084 
2085 void PCB_IO::init( const PROPERTIES* aProperties )
2086 {
2087  m_board = NULL;
2088  m_reader = NULL;
2090  m_props = aProperties;
2091 }
2092 
2093 
2094 void PCB_IO::validateCache( const wxString& aLibraryPath, bool checkModified )
2095 {
2096  if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
2097  {
2098  // a spectacular episode in memory management:
2099  delete m_cache;
2100  m_cache = new FP_CACHE( this, aLibraryPath );
2101  m_cache->Load();
2102  }
2103 }
2104 
2105 
2106 void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
2107  bool aBestEfforts, const PROPERTIES* aProperties )
2108 {
2109  LOCALE_IO toggle; // toggles on, then off, the C locale.
2110  wxDir dir( aLibPath );
2111  wxString errorMsg;
2112 
2113  init( aProperties );
2114 
2115  try
2116  {
2117  validateCache( aLibPath );
2118  }
2119  catch( const IO_ERROR& ioe )
2120  {
2121  errorMsg = ioe.What();
2122  }
2123 
2124  // Some of the files may have been parsed correctly so we want to add the valid files to
2125  // the library.
2126 
2127  for( MODULE_CITER it = m_cache->GetModules().begin(); it != m_cache->GetModules().end(); ++it )
2128  aFootprintNames.Add( it->first );
2129 
2130  if( !errorMsg.IsEmpty() && !aBestEfforts )
2131  THROW_IO_ERROR( errorMsg );
2132 }
2133 
2134 
2135 const MODULE* PCB_IO::getFootprint( const wxString& aLibraryPath,
2136  const wxString& aFootprintName,
2137  const PROPERTIES* aProperties,
2138  bool checkModified )
2139 {
2140  LOCALE_IO toggle; // toggles on, then off, the C locale.
2141 
2142  init( aProperties );
2143 
2144  try
2145  {
2146  validateCache( aLibraryPath, checkModified );
2147  }
2148  catch( const IO_ERROR& )
2149  {
2150  // do nothing with the error
2151  }
2152 
2153  const MODULE_MAP& mods = m_cache->GetModules();
2154 
2155  MODULE_CITER it = mods.find( aFootprintName );
2156 
2157  if( it == mods.end() )
2158  return nullptr;
2159 
2160  return it->second->GetModule();
2161 }
2162 
2163 
2164 const MODULE* PCB_IO::GetEnumeratedFootprint( const wxString& aLibraryPath,
2165  const wxString& aFootprintName,
2166  const PROPERTIES* aProperties )
2167 {
2168  return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
2169 }
2170 
2171 
2172 bool PCB_IO::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
2173  const PROPERTIES* aProperties )
2174 {
2175  // Note: checking the cache sounds like a good idea, but won't catch files which differ
2176  // only in case.
2177  //
2178  // Since this goes out to the native filesystem, we get platform differences (ie: MSW's
2179  // case-insensitive filesystem) handled "for free".
2180  // Warning: footprint names frequently contain a point. So be careful when initializing
2181  // wxFileName, and use a CTOR with extension specified
2182  wxFileName footprintFile( aLibraryPath, aFootprintName, KiCadFootprintFileExtension );
2183 
2184  return footprintFile.Exists();
2185 }
2186 
2187 
2188 MODULE* PCB_IO::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
2189  const PROPERTIES* aProperties )
2190 {
2191  const MODULE* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
2192  return footprint ? (MODULE*) footprint->Duplicate() : nullptr;
2193 }
2194 
2195 
2196 void PCB_IO::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
2197  const PROPERTIES* aProperties )
2198 {
2199  LOCALE_IO toggle; // toggles on, then off, the C locale.
2200 
2201  init( aProperties );
2202 
2203  // In this public PLUGIN API function, we can safely assume it was
2204  // called for saving into a library path.
2206 
2207  validateCache( aLibraryPath );
2208 
2209  if( !m_cache->IsWritable() )
2210  {
2211  if( !m_cache->Exists() )
2212  {
2213  const wxString msg = wxString::Format( _( "Library \"%s\" does not exist.\n"
2214  "Would you like to create it?"),
2215  GetChars( aLibraryPath ) );
2216 
2217  if( wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES )
2218  return;
2219 
2220  // Save throws its own IO_ERROR on failure, so no need to recreate here
2221  m_cache->Save( NULL );
2222  }
2223  else
2224  {
2225  wxString msg = wxString::Format( _( "Library \"%s\" is read only" ), aLibraryPath );
2226  THROW_IO_ERROR( msg );
2227  }
2228  }
2229 
2230  wxString footprintName = aFootprint->GetFPID().GetLibItemName();
2231 
2232  MODULE_MAP& mods = m_cache->GetModules();
2233 
2234  // Quietly overwrite module and delete module file from path for any by same name.
2235  wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetLibItemName(),
2237 
2238 #ifndef __WINDOWS__
2239  // Write through symlinks, don't replace them
2240  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
2241  {
2242  char buffer[ PATH_MAX + 1 ];
2243  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
2244 
2245  if( pathLen > 0 )
2246  {
2247  buffer[ pathLen ] = '\0';
2248  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
2249  fn.Normalize();
2250  }
2251  }
2252 #endif
2253 
2254  if( !fn.IsOk() )
2255  {
2256  THROW_IO_ERROR( wxString::Format( _( "Footprint file name \"%s\" is not valid." ),
2257  fn.GetFullPath() ) );
2258  }
2259 
2260  if( fn.FileExists() && !fn.IsFileWritable() )
2261  {
2262  THROW_IO_ERROR( wxString::Format( _( "No write permissions to delete file \"%s\"" ),
2263  fn.GetFullPath() ) );
2264  }
2265 
2266  wxString fullPath = fn.GetFullPath();
2267  wxString fullName = fn.GetFullName();
2268  MODULE_CITER it = mods.find( footprintName );
2269 
2270  if( it != mods.end() )
2271  {
2272  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint file '%s'." ), fullPath );
2273  mods.erase( footprintName );
2274  wxRemoveFile( fullPath );
2275  }
2276 
2277  // I need my own copy for the cache
2278  MODULE* module = static_cast<MODULE*>( aFootprint->Duplicate() );
2279 
2280  // It should have no parent, orientation should be zero, and it should be on the front layer.
2281  module->SetParent( nullptr );
2282  module->SetOrientation( 0 );
2283 
2284  if( module->GetLayer() != F_Cu )
2285  {
2286  auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
2287 
2288  if( cfg )
2289  module->Flip( module->GetPosition(), cfg->m_FlipLeftRight );
2290  else
2291  module->Flip( module->GetPosition(), false );
2292  }
2293 
2294  wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath );
2295  mods.insert( footprintName, new FP_CACHE_ITEM( module, WX_FILENAME( fn.GetPath(), fullName ) ) );
2296  m_cache->Save( module );
2297 }
2298 
2299 
2300 void PCB_IO::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
2301  const PROPERTIES* aProperties )
2302 {
2303  LOCALE_IO toggle; // toggles on, then off, the C locale.
2304 
2305  init( aProperties );
2306 
2307  validateCache( aLibraryPath );
2308 
2309  if( !m_cache->IsWritable() )
2310  {
2311  THROW_IO_ERROR( wxString::Format( _( "Library \"%s\" is read only." ),
2312  aLibraryPath.GetData() ) );
2313  }
2314 
2315  m_cache->Remove( aFootprintName );
2316 }
2317 
2318 
2319 
2320 long long PCB_IO::GetLibraryTimestamp( const wxString& aLibraryPath ) const
2321 {
2322  return FP_CACHE::GetTimestamp( aLibraryPath );
2323 }
2324 
2325 
2326 void PCB_IO::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
2327 {
2328  if( wxDir::Exists( aLibraryPath ) )
2329  {
2330  THROW_IO_ERROR( wxString::Format( _( "Cannot overwrite library path \"%s\"." ),
2331  aLibraryPath.GetData() ) );
2332  }
2333 
2334  LOCALE_IO toggle;
2335 
2336  init( aProperties );
2337 
2338  delete m_cache;
2339  m_cache = new FP_CACHE( this, aLibraryPath );
2340  m_cache->Save();
2341 }
2342 
2343 
2344 bool PCB_IO::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
2345 {
2346  wxFileName fn;
2347  fn.SetPath( aLibraryPath );
2348 
2349  // Return if there is no library path to delete.
2350  if( !fn.DirExists() )
2351  return false;
2352 
2353  if( !fn.IsDirWritable() )
2354  {
2355  THROW_IO_ERROR( wxString::Format( _( "User does not have permission to delete directory \"%s\"." ),
2356  aLibraryPath.GetData() ) );
2357  }
2358 
2359  wxDir dir( aLibraryPath );
2360 
2361  if( dir.HasSubDirs() )
2362  {
2363  THROW_IO_ERROR( wxString::Format( _( "Library directory \"%s\" has unexpected sub-directories." ),
2364  aLibraryPath.GetData() ) );
2365  }
2366 
2367  // All the footprint files must be deleted before the directory can be deleted.
2368  if( dir.HasFiles() )
2369  {
2370  unsigned i;
2371  wxFileName tmp;
2372  wxArrayString files;
2373 
2374  wxDir::GetAllFiles( aLibraryPath, &files );
2375 
2376  for( i = 0; i < files.GetCount(); i++ )
2377  {
2378  tmp = files[i];
2379 
2380  if( tmp.GetExt() != KiCadFootprintFileExtension )
2381  {
2382  THROW_IO_ERROR( wxString::Format( _( "Unexpected file \"%s\" was found in library path \"%s\"." ),
2383  files[i].GetData(), aLibraryPath.GetData() ) );
2384  }
2385  }
2386 
2387  for( i = 0; i < files.GetCount(); i++ )
2388  wxRemoveFile( files[i] );
2389  }
2390 
2391  wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library \"%s\"." ),
2392  aLibraryPath.GetData() );
2393 
2394  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2395  // we don't want that. we want bare metal portability with no UI here.
2396  if( !wxRmdir( aLibraryPath ) )
2397  {
2398  THROW_IO_ERROR( wxString::Format( _( "Footprint library \"%s\" cannot be deleted." ),
2399  aLibraryPath.GetData() ) );
2400  }
2401 
2402  // For some reason removing a directory in Windows is not immediately updated. This delay
2403  // prevents an error when attempting to immediately recreate the same directory when over
2404  // writing an existing library.
2405 #ifdef __WINDOWS__
2406  wxMilliSleep( 250L );
2407 #endif
2408 
2409  if( m_cache && !m_cache->IsPath( aLibraryPath ) )
2410  {
2411  delete m_cache;
2412  m_cache = NULL;
2413  }
2414 
2415  return true;
2416 }
2417 
2418 
2419 bool PCB_IO::IsFootprintLibWritable( const wxString& aLibraryPath )
2420 {
2421  LOCALE_IO toggle;
2422 
2423  init( NULL );
2424 
2425  validateCache( aLibraryPath );
2426 
2427  return m_cache->IsWritable();
2428 }
void FormatBoardStackup(OUTPUTFORMATTER *aFormatter, BOARD *aBoard, int aNestLevel) const
Writes the stackup info on board file.
timestamp_t GetLastEditTime() const
Definition: class_module.h:349
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
friend class FP_CACHE
MODULE_MAP::iterator MODULE_ITER
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
int m_SolderMaskMargin
Solder mask margin.
int GetAttributes() const
Definition: class_module.h:259
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
int GetLocalSolderMaskMargin() const
Definition: class_pad.h:461
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
double GetOrientation() const
Definition: class_module.h:215
bool IsFilled() const
Definition: class_zone.h:188
STATUS_FLAGS GetStatus() const
Definition: base_struct.h:254
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
LSEQ CuStack() const
Function CuStack returns a sequence of copper layers in starting from the front/top and extending to ...
Definition: lset.cpp:155
LINE_READER * m_reader
no ownership here.
void formatGeneral(BOARD *aBoard, int aNestLevel=0) const
formats the General section of the file
int GetPlacementCost90() const
Definition: class_module.h:555
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:527
bool IsModified()
Function IsModified Return true if the cache is not up-to-date.
TEXTE_MODULE & Reference()
Definition: class_module.h:477
std::unique_ptr< MODULE > m_module
int GetNetCode() const
Function GetNetCode.
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: class_board.h:530
const MODULE * GetModule() const
Definition: typeinfo.h:85
#define CTL_OMIT_AT
Omit position and rotation.
BOARD_ITEM * Parse(const wxString &aClipboardSourceInput)
const wxPoint & GetPos0() const
Definition: class_pad.h:294
PCB_IO is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
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...
int GetWidth() const
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
int StrPrintf(std::string *aResult, const char *aFormat,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
void formatLayer(const BOARD_ITEM *aItem) const
TEXTE_PCB class definition.
int GetThermalReliefCopperBridge(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:542
no special fabrication property
Definition: pad_shapes.h:78
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:66
int m_SolderPasteMargin
Solder paste margin absolute value.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:202
wxFileName m_lib_path
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
this class manage the layers needed to make a physical board they are solder mask,...
Implementation of conversion functions that require both schematic and board internal units.
wxPoint m_crossBarF
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
std::vector< int > m_TrackWidthList
const std::string KiCadFootprintFileExtension
wxPoint m_arrowD1F
PAD_SHAPE_T GetAnchorPadShape() const
Function GetAnchorPadShape.
Definition: class_pad.h:247
FP_CACHE * m_cache
Footprint library cache.
const wxPoint & GetStart() const
Definition: class_track.h:111
STROKE_T GetShape() const
PCB_PARSER reads a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD...
Definition: pcb_parser.h:69
std::vector< DIFF_PAIR_DIMENSION > m_DiffPairDimensionsList
int GetSize() const
int GetHatchFillTypeThickness() const
Definition: class_zone.h:213
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
const MODULE * GetEnumeratedFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
Function GetEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for m...
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControl=0) const
bool IsVisible() const
Definition: eda_text.h:170
bool IsPlaced() const
Definition: class_module.h:319
void init(const PROPERTIES *aProperties)
a fiducial (usually a smd) for the full board
Definition: pad_shapes.h:80
wxPoint m_Start
angle of an arc, from its starting point, in 0.1 deg
Definition: class_pad.h:98
polygon (not yet used for tracks, but could be in microwave apps)
ZONE_CONNECTION GetZoneConnection() const
Definition: class_module.h:248
bool IsEmpty() const
Returns true if the set is empty (no polygons at all)
int GetPadToDieLength() const
Definition: class_pad.h:459
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:62
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
ZONE_SEGMENT_FILL & FillSegments()
Definition: class_zone.h:262
const WX_FILENAME & GetFileName() const
wxString m_lib_raw_path
PADS & Pads()
Definition: class_module.h:173
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:74
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
double GetTextAngle() const
Definition: eda_text.h:158
bool GetFilledPolysUseThickness() const
Definition: class_zone.h:617
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
double GetHatchFillTypeOrientation() const
Definition: class_zone.h:219
wxString GetName() const
Definition: common.cpp:723
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
void formatNetInformation(BOARD *aBoard, int aNestLevel=0) const
formats the Nets and Netclasses
Smd pad, used in BGA footprints.
Definition: pad_shapes.h:79
wxString AsString() const
Definition: common.cpp:170
double GetHatchFillTypeSmoothingValue() const
Definition: class_zone.h:225
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:512
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
usual segment : line with rounded ends
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:65
const LIB_ID & GetFPID() const
Definition: class_module.h:219
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
wxPoint m_featureLineDF
const KIID_PATH & GetPath() const
Definition: class_module.h:228
DRAWINGS & GraphicalItems()
Definition: class_module.h:183
a pad used as heat sink, usually in SMD footprints
Definition: pad_shapes.h:83
int GetThermalReliefGap(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:533
const wxString & GetPinFunction() const
Definition: class_pad.h:211
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function GetStandardSizes returns the standard page types, such as "A4", "A3", etc.
Definition: page_info.cpp:267
void SetFullName(const wxString &aFileNameAndExtension)
Definition: common.cpp:717
PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
int GetThermalGap() const
Definition: class_pad.cpp:747
int GetLocalSolderMaskMargin() const
Definition: class_module.h:231
int PointCount() const
Function PointCount()
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:377
int GetLocalClearance() const
Definition: class_pad.h:464
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
wxPoint m_Ctrl1
is also the start point of the arc
Definition: class_pad.h:100
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
iterator begin()
Definition: netclass.h:132
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:449
Definitions for tracks, vias and zones.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
This file contains miscellaneous commonly used macros and functions.
int GetChamferPositions() const
has meaning only for chamfered rect pads
Definition: class_pad.h:724
a pad with a castellated through hole
Definition: pad_shapes.h:84
bool GetDoNotAllowVias() const
Definition: class_zone.h:651
static const char * ShowType(LAYER_T aType)
Function ShowType converts a LAYER_T enum to a const char*.
void SetOutputFormatter(OUTPUTFORMATTER *aFormatter)
void SetBoard(const BOARD *aBoard)
Function SetBoard Sets a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:282
long long m_cache_timestamp
wxPoint m_featureLineGO
const wxPoint & GetStart0() const
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_zone.cpp:277
bool IsKeepUpright()
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
wxSize m_TextSize[LAYER_CLASS_COUNT]
DIMENSION class definition.
const VECTOR2I & CPoint(int aIndex) const
Function Point()
MODULE_MAP m_modules
class MODULE, a footprint
Definition: typeinfo.h:89
long long GetTimestamp()
Definition: common.cpp:757
void Remove(const wxString &aFootprintName)
int GetWidth() const
MODULE_MAP::const_iterator MODULE_CITER
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:552
BOARD_STACKUP & GetStackupDescriptor()
PCB_IO(int aControlFlags=CTL_FOR_BOARD)
boost::ptr_map< wxString, FP_CACHE_ITEM > MODULE_MAP
STRINGSET::iterator iterator
Definition: netclass.h:131
PCB_LAYER_ID
A quick note on layer IDs:
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:207
int m_TextThickness[LAYER_CLASS_COUNT]
int m_Radius
thickness of segment or outline For filled S_CIRCLE shape, thickness = 0.
Definition: class_pad.h:96
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:919
void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty.
LSET is a set of PCB_LAYER_IDs.
pads are covered by copper
const std::vector< PAD_CS_PRIMITIVE > & GetPrimitives() const
Accessor to the basic shape list.
Definition: class_pad.h:373
const wxPoint & GetMid() const
Definition: class_track.h:292
void SetBoard(BOARD *aBoard)
Definition: pcb_parser.h:342
unsigned int GetCornerRadius() const
Definition: class_zone.h:615
int GetSize() const
Function GetSize.
Definition: netinfo.h:376
std::vector< wxPoint > m_Poly
Bezier Control point 2.
Definition: class_pad.h:102
int GetLocalClearance() const
Definition: class_module.h:234
#define NULL
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void FootprintSave(const wxString &aLibraryPath, const MODULE *aFootprint, const PROPERTIES *aProperties=NULL) override
Function FootprintSave will write aModule to an existing library located at aLibraryPath.
MODULES & Modules()
Definition: class_board.h:229
iterator end()
Definition: netclass.h:133
wxString GetBuildVersion()
Get the full KiCad version string.
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:218
bool IsPath(const wxString &aPath) const
Function IsPath checks if aPath is the same as the current cache path.
SHAPE_POLY_SET.
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:476
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
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 validateCache(const wxString &aLibraryPath, bool checkModified=true)
ZONE_FILL_MODE GetFillMode() const
Definition: class_zone.h:156
int GetValue() const
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:438
Arcs (with rounded ends)
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
const wxPoint & GetOffset() const
Definition: class_pad.h:309
ZONE_CONNECTION GetZoneConnection() const
Definition: class_pad.cpp:725
int m_loading_format_version
which SEXPR_BOARD_FILE_VERSION should be Load()ed?
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:432
double GetChamferRectRatio() const
has meaning only for chamfered rect pads
Definition: class_pad.h:701
int GetThermalWidth() const
Definition: class_pad.cpp:736
NETCLASS handles a collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:55
Helper class to handle a primitive (basic shape: polygon, segment, circle or arc) to build a custom p...
Definition: class_pad.h:89
TEXT_TYPE GetType() const
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:446
wxPoint m_arrowG1F
bool GetDoNotAllowCopperPour() const
Definition: class_zone.h:650
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:306
wxPoint m_arrowD2F
wxPoint m_arrowG2F
bool m_TextItalic[LAYER_CLASS_COUNT]
Definition of file extensions used in Kicad.
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:450
const wxString & GetName() const
Definition: class_pad.h:203
int m_ZoneClearance
Minimal clearance value.
Definition: zone_settings.h:74
long long TimestampDir(const wxString &aDirPath, const wxString &aFilespec)
A copy of ConvertFileTimeToWx() because wxWidgets left it as a static function private to src/common/...
Definition: common.cpp:916
PCB_IO * m_owner
wxLogTrace helper definitions.
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: ws_painter.cpp:213
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
#define THROW_IO_ERROR(msg)
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
const wxPoint & GetBezier0_C2() const
SHAPE_POLY_SET & GetPolyShape()
void formatSetup(BOARD *aBoard, int aNestLevel=0) const
formats the board setup information
PAD_PROP_T GetProperty() const
Definition: class_pad.h:452
WX_FILENAME m_filename
void SetFileName(const wxString &aFileName)
Definition: class_board.h:216
Bezier Curve.
#define UNDEFINED_DRILL_DIAMETER
Definition: class_track.h:71
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:335
PCB_PARSER * m_parser
ZONE_CONNECTION GetPadConnection(D_PAD *aPad=NULL) const
Definition: class_zone.cpp:879
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
const wxSize & GetDelta() const
Definition: class_pad.h:303
const wxString & GetNetname() const
Function GetNetname.
wxPoint m_End
is also the center of the circle and arc
Definition: class_pad.h:99
#define CTL_OMIT_NETS
Omit pads net names (useless in library)
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:467
#define CTL_OMIT_PATH
Omit component sheet time stamp (useless in library)
FP_CACHE_ITEM is helper class for creating a footprint library cache.
const wxArrayString * GetInitialComments() const
Return the initial comments block or NULL if none, without transfer of ownership.
Definition: class_module.h:660
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:63
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:100
void Save(MODULE *aModule=NULL)
Function Save Save the footprint cache or a single module from it to disk.
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:301
const wxString & GetKeywords() const
Definition: class_module.h:225
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
STROKE_T m_Shape
Definition: class_pad.h:92
ZONE_HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:538
int m_LineThickness[LAYER_CLASS_COUNT]
int GetCornerSmoothingType() const
Definition: class_zone.h:611
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
const MODULE_ZONE_CONTAINERS & Zones() const
Definition: class_module.h:188
UTF8 Format() const
Definition: lib_id.cpp:237
const wxPoint & GetGridOrigin() const
Definition: class_board.h:342
int GetLocalSolderPasteMargin() const
Definition: class_module.h:237
int GetWidth() const
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:649
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:335
Thermal relief only for THT pads.
wxPoint m_Ctrl2
Bezier Control point 1.
Definition: class_pad.h:101
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:101
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
Function FootprintDelete deletes aFootprintName from the library at aLibraryPath.
default
Definition: class_module.h:73
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
wxString GetPath() const
Definition: common.cpp:736
bool m_EnableUsePinFunction
Enable pad pin function handling in pcbnew.
const KIID m_Uuid
Definition: base_struct.h:169
const wxPoint & GetPos0() const
CUST_PAD_SHAPE_IN_ZONE GetCustomShapeInZoneOpt() const
Definition: class_pad.h:253
int m_Thickness
S_SEGMENT, S_ARC, S_CIRCLE, S_POLYGON only (same as DRAWSEGMENT)
Definition: class_pad.h:93
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
int GetPlacementCost180() const
Definition: class_module.h:552
virtual std::string Quotes(const std::string &aWrapee)
Function Quotes checks aWrapee input string for a need to be quoted (e.g.
Definition: richio.cpp:433
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Function GetLayerType returns the type of the copper layer given by aLayer.
void Load()
Use thermal relief for pads.
void formatBoardLayers(BOARD *aBoard, int aNestLevel=0) const
formats the board layer information
wxString GetFullPath() const
Definition: common.cpp:742
const wxString & GetDescription() const
Definition: class_module.h:222
double GetAngle() const
const ZONE_SETTINGS & GetZoneSettings() const
Fetch the zone settings for this container.
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
bool IsWritable() const
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
Definition: pcb_parser.h:360
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:240
MODULE_MAP::const_iterator MODULE_CITER
std::list< MODULE_3D_SETTINGS > & Models()
Definition: class_module.h:205
void Remove(iterator aName)
Function Remove will remove NET name aName from the collection of members.
Definition: netclass.h:143
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
STRING_FORMATTER m_sf
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:100
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
a fiducial (usually a smd) local to the parent footprint
Definition: pad_shapes.h:81
virtual wxString GetClass() const =0
Function GetClass returns the class name.
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:533
A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition: common.h:391
int GetVisibleElements() const
Function GetVisibleElements returns a bit-mask of all the element categories that are visible.
int GetWidth() const
Definition: class_track.h:105
const MODULE * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties, bool checkModified)
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.
int GetNet() const
Function GetNet.
Definition: netinfo.h:224
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
#define _(s)
Definition: 3d_actions.cpp:33
SHAPE_LINE_CHAIN.
bool m_ZoneUseNoOutlineInFill
Option to handle filled polygons in zones: the "legacy" option is using thick outlines around filled ...
void SetOrientation(double newangle)
SHAPE_POLY_SET::ITERATOR IterateWithHoles()
Function IterateWithHoles returns an iterator to visit all points of the zone's main outline with hol...
Definition: class_zone.h:470
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:426
Virtual component: when created by copper shapes on board (Like edge card connectors,...
Definition: class_module.h:76
#define CTL_OMIT_TSTAMPS
Omit component time stamp (useless in library)
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .
Definition: trigo.h:248
TEXTE_PCB & Text()
wxString AsString() const
Definition: common.h:123
#define CTL_STD_LAYER_NAMES
Use English Standard layer names.
const wxSize & GetDrillSize() const
Definition: class_pad.h:306
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
BOARD * m_board
which BOARD, no ownership here
bool FootprintExists(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
Function FootprintExists check for the existence of a footprint.
int GetShape() const
VIATYPE GetViaType() const
Definition: class_track.h:416
void format(BOARD *aBoard, int aNestLevel=0) const
int GetHatchPitch() const
Hatch related methods.
Definition: class_zone.cpp:964
const wxPoint & GetBezControl2() const
The common library.
int GetMinThickness() const
Definition: class_zone.h:204
Pads are not covered.
bool IsPolyShapeValid() const
const wxPoint & GetEnd() const
Definition: class_track.h:108
std::vector< VIA_DIMENSION > m_ViasDimensionsList
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
bool GetDoNotAllowTracks() const
Definition: class_zone.h:652
FP_CACHE_ITEM(MODULE *aModule, const WX_FILENAME &aFileName)
double GetRoundRectRadiusRatio() const
has meaning only for rounded rect pads
Definition: class_pad.h:675
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the net class to aFormatter in s-expression form.
Definition: netclass.cpp:253
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
const wxPoint & GetBezier0_C1() const
wxPoint m_crossBarO
const wxPoint & GetEnd0() const
int GetHatchFillTypeSmoothingLevel() const
Definition: class_zone.h:222
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
PCB_TARGET class definition.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
const wxPoint & GetBezControl1() const
void formatDefaults(const BOARD_DESIGN_SETTINGS &aSettings, int aNestLevel) const
formats the defaults subsection of the board setup
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
Pcbnew s-expression file format parser definition.
void filterNetClass(const BOARD &aBoard, NETCLASS &aNetClass)
Removes empty nets (i.e. with node count equal zero) from net classes
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:172
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:237
FP_CACHE(PCB_IO *aOwner, const wxString &aLibraryPath)
void formatHeader(BOARD *aBoard, int aNestLevel=0) const
writes everything that comes before the board_items, like settings and layers etc
Module description (excepted pads)
bool m_MicroViasAllowed
true to allow micro vias
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:884
bool m_cache_dirty
void formatLayers(LSET aLayerMask, int aNestLevel=0) const
int GetZoneClearance() const
Definition: class_zone.h:194
class ZONE_CONTAINER, managed by a footprint
Definition: typeinfo.h:95
bool m_HasStackup
Set to true if the board has a stackup management.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
#define CTL_OMIT_INITIAL_COMMENTS
omit MODULE initial comments
MODULE_MAP::iterator MODULE_ITER
double m_SolderPasteMarginRatio
Solder pask margin ratio value of pad size The final margin is the sum of these 2 values.
const wxSize & GetSize() const
Definition: class_pad.h:300
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
int GetThermalWidth() const
Definition: class_module.h:254
EDGE_MODULE class definition.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
T NormalizeAngle360Min(T Angle)
Normalize angle to be > -360.0 and < 360.0 Angle equal to -360 or +360 are set to 0.
Definition: trigo.h:237
int GetLocalSolderPasteMargin() const
Definition: class_pad.h:467
bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Function FootprintLibDelete deletes an existing footprint library and returns true,...
BOARD_ITEM_CONTAINER * GetParent() const
STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
#define CTL_OMIT_HIDE
Definition: eda_text.h:39
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
a test point pad
Definition: pad_shapes.h:82
static long long GetTimestamp(const wxString &aLibPath)
Function GetTimestamp Generate a timestamp representing all source files in the cache (including the ...
bool Exists() const
wxPoint m_featureLineDO
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:462
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
int GetHatchFillTypeGap() const
Definition: class_zone.h:216
const wxPoint GetPosition() const override
Definition: class_module.h:210
int GetThermalGap() const
Definition: class_module.h:257
DRAWINGS & Drawings()
Definition: class_board.h:238
void SetFPID(const LIB_ID &aFPID)
Definition: class_module.h:220
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
wxString GetPath() const
DIMENSION.
TRACKS & Tracks()
Definition: class_board.h:220
bool m_TextUpright[LAYER_CLASS_COUNT]
double m_ArcAngle
radius of a circle
Definition: class_pad.h:97
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:523
double GetLocalSolderPasteMarginRatio() const
Definition: class_pad.h:470
MODULE_MAP & GetModules()
virtual void Save(const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL) override
Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows a...
const wxPoint GetPosition() const override
int Translate(int aNetCode) const
Function Translate Translates net number according to the map prepared by Update() function.
BOARD_ITEM * Duplicate() const
Function Duplicate creates a copy of a BOARD_ITEM.
int m_SolderMaskMinWidth
Solder mask min width.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Function GetStandardLayerName returns an "English Standard" name of a PCB layer when given aLayerNumb...
Definition: class_board.h:622
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:571
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
wxPoint m_featureLineGF