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