99#define FIRST_COPPER_LAYER 0
100#define LAYER_N_BACK 0
115#define LAYER_N_FRONT 15
116#define LAST_COPPER_LAYER LAYER_N_FRONT
118#define FIRST_NON_COPPER_LAYER 16
119#define ADHESIVE_N_BACK 16
120#define ADHESIVE_N_FRONT 17
121#define SOLDERPASTE_N_BACK 18
122#define SOLDERPASTE_N_FRONT 19
123#define SILKSCREEN_N_BACK 20
124#define SILKSCREEN_N_FRONT 21
125#define SOLDERMASK_N_BACK 22
126#define SOLDERMASK_N_FRONT 23
132#define LAST_NON_COPPER_LAYER 28
136#define LAYER_BACK (1 << LAYER_N_BACK)
137#define LAYER_2 (1 << LAYER_N_2)
138#define LAYER_3 (1 << LAYER_N_3)
139#define LAYER_4 (1 << LAYER_N_4)
140#define LAYER_5 (1 << LAYER_N_5)
141#define LAYER_6 (1 << LAYER_N_6)
142#define LAYER_7 (1 << LAYER_N_7)
143#define LAYER_8 (1 << LAYER_N_8)
144#define LAYER_9 (1 << LAYER_N_9)
145#define LAYER_10 (1 << LAYER_N_10)
146#define LAYER_11 (1 << LAYER_N_11)
147#define LAYER_12 (1 << LAYER_N_12)
148#define LAYER_13 (1 << LAYER_N_13)
149#define LAYER_14 (1 << LAYER_N_14)
150#define LAYER_15 (1 << LAYER_N_15)
151#define LAYER_FRONT (1 << LAYER_N_FRONT)
152#define ADHESIVE_LAYER_BACK (1 << ADHESIVE_N_BACK)
153#define ADHESIVE_LAYER_FRONT (1 << ADHESIVE_N_FRONT)
154#define SOLDERPASTE_LAYER_BACK (1 << SOLDERPASTE_N_BACK)
155#define SOLDERPASTE_LAYER_FRONT (1 << SOLDERPASTE_N_FRONT)
156#define SILKSCREEN_LAYER_BACK (1 << SILKSCREEN_N_BACK)
157#define SILKSCREEN_LAYER_FRONT (1 << SILKSCREEN_N_FRONT)
158#define SOLDERMASK_LAYER_BACK (1 << SOLDERMASK_N_BACK)
159#define SOLDERMASK_LAYER_FRONT (1 << SOLDERMASK_N_FRONT)
160#define DRAW_LAYER (1 << DRAW_N)
161#define COMMENT_LAYER (1 << COMMENT_N)
162#define ECO1_LAYER (1 << ECO1_N)
163#define ECO2_LAYER (1 << ECO2_N)
164#define EDGE_LAYER (1 << EDGE_N)
169#define ALL_NO_CU_LAYERS 0x1FFF0000
170#define ALL_CU_LAYERS 0x0000FFFF
171#define FRONT_TECH_LAYERS (SILKSCREEN_LAYER_FRONT | SOLDERMASK_LAYER_FRONT \
172 | ADHESIVE_LAYER_FRONT | SOLDERPASTE_LAYER_FRONT)
173#define BACK_TECH_LAYERS (SILKSCREEN_LAYER_BACK | SOLDERMASK_LAYER_BACK \
174 | ADHESIVE_LAYER_BACK | SOLDERPASTE_LAYER_BACK)
175#define ALL_TECH_LAYERS (FRONT_TECH_LAYERS | BACK_TECH_LAYERS)
176#define BACK_LAYERS (LAYER_BACK | BACK_TECH_LAYERS)
177#define FRONT_LAYERS (LAYER_FRONT | FRONT_TECH_LAYERS)
179#define ALL_USER_LAYERS (DRAW_LAYER | COMMENT_LAYER | ECO1_LAYER | ECO2_LAYER )
181#define NO_LAYERS 0x00000000
185#define PCB_LEGACY_INTERNAL_UNIT 10000
188#define SZ( x ) (sizeof(x)-1)
194static bool inline isSpace(
int c ) {
return strchr(
delims, c ) !=
nullptr; }
196#define MASK(x) (1<<(x))
201 const unsigned PROGRESS_DELTA = 250;
224#define TESTLINE( x ) ( !strncasecmp( line, x, SZ( x ) ) && isSpace( line[SZ( x )] ) )
227#define TESTSUBSTR( x ) ( !strncasecmp( line, x, SZ( x ) ) )
231#define READLINE( rdr ) rdr->ReadLine()
237static inline char* ReadLine(
LINE_READER* rdr,
const char* caller )
241 const char* line = rdr->
Line();
244 if( !strcmp(
"loadSETUP", caller ) && !strcmp(
"$EndSETUP\n", line ) )
252#define READLINE( rdr ) ReadLine( rdr, __FUNCTION__ )
258 if( !strcmp(
"L", horizontal ) )
261 if( !strcmp(
"R", horizontal ) )
269 if( !strcmp(
"T", vertical ) )
272 if( !strcmp(
"B", vertical ) )
284 for(
int i = 0; aMask; ++i, aMask >>= 1 )
298 return aLegacyLayerNum ==
LAYER_N_FRONT || aLegacyLayerNum < aCu_Count;
305 unsigned old = aLayerNum;
323 newid = cu_count - 1 - old;
324 wxASSERT( newid >= 0 );
366 aMask &= ~ALL_CU_LAYERS;
369 for(
int i=0; aMask; ++i, aMask >>= 1 )
385static inline int intParse(
const char*
next,
const char** out =
nullptr )
388 return (
int) strtol(
next, (
char**) out, 10 );
398static inline long hexParse(
const char*
next,
const char** out =
nullptr )
401 return strtol(
next, (
char**) out, 16 );
413 std::unique_ptr<BOARD> boardDeleter;
421 boardDeleter = std::make_unique<BOARD>();
478 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>(
m_board );
481 std::string fpName =
StrPurge( line +
SZ(
"$MODULE" ) );
487 if( !fpName.empty() )
488 fpid.
Parse( fpName,
true );
490 footprint->SetFPID( fpid );
495 else if(
TESTLINE(
"$DRAWSEGMENT" ) )
515 else if(
TESTLINE(
"$CZONE_OUTLINE" ) )
536 else if(
TESTLINE(
"$SHEETDESCR" ) )
581 sscanf( line,
"PCBNEW-BOARD Version %d", &ver );
584 if( ver > LEGACY_BOARD_FILE_VERSION )
586 m_error.Printf(
_(
"File '%s' has an unrecognized version: %d." ),
602 bool saw_LayerCount =
false;
613 if( !strcmp( data,
"mm" ) )
620 int tmp =
intParse( line +
SZ(
"LayerCount" ) );
628 saw_LayerCount =
true;
630 else if(
TESTLINE(
"EnabledLayers" ) )
632 if( !saw_LayerCount )
647 else if(
TESTLINE(
"VisibleLayers" ) )
653 if( !saw_LayerCount )
665 if( !saw_LayerCount )
672 saw_LayerCount =
true;
675 else if(
TESTLINE(
"BoardThickness" ) )
700 else if(
TESTLINE(
"$EndGENERAL" ) )
732 m_error.Printf(
_(
"Unknown sheet type '%s' on line: %d." ),
745 if( width && height )
757 if( orient && !strcmp( orient,
"portrait" ) )
830 else if(
TESTLINE(
"$EndSHEETDESCR" ) )
845 std::shared_ptr<NETCLASS> defaultNetclass = bds.
m_NetSettings->m_DefaultNetClass;
861 plot_opts.
Parse( &parser );
866 else if(
TESTLINE(
"AuxiliaryAxisOrg" ) )
877 int layer_num =
intParse( line +
SZ(
"Layer[" ), &data );
899 defaultNetclass->SetTrackWidth( tmp );
901 else if(
TESTLINE(
"TrackWidthList" ) )
906 else if(
TESTLINE(
"TrackClearence" ) )
909 defaultNetclass->SetClearance( tmp );
911 else if(
TESTLINE(
"TrackMinWidth" ) )
916 else if(
TESTLINE(
"ZoneClearence" ) )
921 else if(
TESTLINE(
"Zone_45_Only" ) )
925 else if(
TESTLINE(
"DrawSegmWidth" ) )
930 else if(
TESTLINE(
"EdgeSegmWidth" ) )
940 else if(
TESTLINE(
"MicroViaMinSize" ) )
945 else if(
TESTLINE(
"ViaSizeList" ) )
950 BIU diameter =
biuParse( line +
SZ(
"ViaSizeList" ), &data );
961 defaultNetclass->SetViaDiameter( tmp );
966 defaultNetclass->SetViaDrill( tmp );
968 else if(
TESTLINE(
"ViaMinDrill" ) )
973 else if(
TESTLINE(
"MicroViaSize" ) )
976 defaultNetclass->SetuViaDiameter( tmp );
978 else if(
TESTLINE(
"MicroViaDrill" ) )
981 defaultNetclass->SetuViaDrill( tmp );
983 else if(
TESTLINE(
"MicroViaMinDrill" ) )
988 else if(
TESTLINE(
"MicroViasAllowed" ) )
992 else if(
TESTLINE(
"TextPcbWidth" ) )
997 else if(
TESTLINE(
"TextPcbSize" ) )
1004 else if(
TESTLINE(
"EdgeModWidth" ) )
1010 else if(
TESTLINE(
"TextModWidth" ) )
1016 else if(
TESTLINE(
"TextModSize" ) )
1036 else if(
TESTLINE(
"Pad2MaskClearance" ) )
1041 else if(
TESTLINE(
"SolderMaskMinWidth" ) )
1046 else if(
TESTLINE(
"Pad2PasteClearance" ) )
1051 else if(
TESTLINE(
"Pad2PasteClearanceRatio" ) )
1053 double ratio = atof( line +
SZ(
"Pad2PasteClearanceRatio" ) );
1057 else if(
TESTLINE(
"GridOrigin" ) )
1064 else if(
TESTLINE(
"VisibleElements" ) )
1070 int visibleElements =
hexParse( line +
SZ(
"VisibleElements" ) );
1076 for(
size_t i = 0; i < visibles.size(); i++ )
1077 visibles.
set( i, visibleElements & ( 1u << i ) );
1117 for(
unsigned ii = 1; ii < designSettings.
m_TrackWidthList.size() - 1; ii++ )
1138 if(
TESTSUBSTR(
"D" ) && strchr(
"SCAP", line[1] ) )
1176 int orient =
intParse( data, &data );
1177 int layer_num =
intParse( data, &data );
1180 [[maybe_unused]]
long edittime =
hexParse( data, &data );
1188 if( data && data[0] ==
'F' )
1191 if( data && data[1] ==
'P' )
1201 char* uuid =
strtok_r( (
char*) line +
SZ(
"Sc" ),
delims, (
char**) &data );
1213 data = line +
SZ(
"At" );
1215 if( strstr( data,
"SMD" ) )
1217 else if( strstr( data,
"VIRTUAL" ) )
1245 else if(
TESTLINE(
".SolderPasteRatio" ) )
1247 double tmp = atof( line +
SZ(
".SolderPasteRatio" ) );
1261 else if(
TESTLINE(
".SolderPaste" ) )
1266 else if(
TESTLINE(
".SolderMask" ) )
1271 else if(
TESTLINE(
".LocalClearance" ) )
1276 else if(
TESTLINE(
".ZoneConnection" ) )
1278 int tmp =
intParse( line +
SZ(
".ZoneConnection" ) );
1281 else if(
TESTLINE(
".ThermalWidth" ) )
1286 else if(
TESTLINE(
".ThermalGap" ) )
1291 else if(
TESTLINE(
"$EndMODULE" ) )
1305 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( aFootprint );
1321 char mypadnumber[50];
1323 data = line +
SZ(
"Sh" ) + 1;
1326 data = data +
ReadDelimitedText( mypadnumber, data,
sizeof( mypadnumber ) ) + 1;
1331 unsigned char padchar = (
unsigned char) *data++;
1347 m_error.Printf(
_(
"Unknown padshape '%c=0x%02x' on line: %d of footprint: '%s'." ),
1360 const unsigned char* cp = (
unsigned char*) mypadnumber;
1373 pad->SetNumber( padNumber );
1377 pad->SetOrientation( orient );
1383 BIU drill_y = drill_x;
1393 if( data[0] ==
'O' )
1405 pad->SetDrillShape( drShape );
1407 pad->SetDrillSize(
VECTOR2I( drill_x, drill_y ) );
1418 if( !strcmp( data,
"SMD" ) )
1420 else if( !strcmp( data,
"CONN" ) )
1422 else if( !strcmp( data,
"HOLE" ) )
1433 pad->SetAttribute( attribute );
1440 int netcode =
intParse( line +
SZ(
"Ne" ), &data );
1462 pad->SetPos0( pos );
1468 pad->SetPadToDieLength( tmp );
1470 else if(
TESTLINE(
".SolderMask" ) )
1473 pad->SetLocalSolderMaskMargin( tmp );
1475 else if(
TESTLINE(
".SolderPasteRatio" ) )
1477 double tmp = atof( line +
SZ(
".SolderPasteRatio" ) );
1478 pad->SetLocalSolderPasteMarginRatio( tmp );
1480 else if(
TESTLINE(
".SolderPaste" ) )
1483 pad->SetLocalSolderPasteMargin( tmp );
1485 else if(
TESTLINE(
".LocalClearance" ) )
1488 pad->SetLocalClearance( tmp );
1490 else if(
TESTLINE(
".ZoneConnection" ) )
1492 int tmp =
intParse( line +
SZ(
".ZoneConnection" ) );
1495 else if(
TESTLINE(
".ThermalWidth" ) )
1498 pad->SetThermalSpokeWidth( tmp );
1500 else if(
TESTLINE(
".ThermalGap" ) )
1503 pad->SetThermalGap( tmp );
1516 if(
pad->GetSizeX() > 0 &&
pad->GetSizeY() > 0 )
1518 aFootprint->
Add(
pad.release() );
1522 wxLogError(
_(
"Invalid zero-sized pad ignored in\nfile: %s" ),
1546 m_error.Printf(
_(
"Unknown FP_SHAPE type:'%c=0x%02x' on line %d of footprint '%s'." ),
1552 std::unique_ptr<FP_SHAPE> dwg = std::make_unique<FP_SHAPE>( aFootprint, shape );
1573 dwg->SetCenter0(
VECTOR2I( center0_x, center0_y ) );
1574 dwg->SetStart0(
VECTOR2I( start0_x, start0_y ) );
1575 dwg->SetArcAngleAndEnd0(
angle,
true );
1591 dwg->SetStart0(
VECTOR2I( start0_x, start0_y ) );
1592 dwg->SetEnd0(
VECTOR2I( end0_x, end0_y ) );
1603 int ptCount =
intParse( data, &data );
1608 dwg->SetStart0(
VECTOR2I( start0_x, start0_y ) );
1609 dwg->SetEnd0(
VECTOR2I( end0_x, end0_y ) );
1611 std::vector<VECTOR2I> pts;
1612 pts.reserve( ptCount );
1614 for(
int ii = 0; ii < ptCount; ++ii )
1631 pts.emplace_back( x, y );
1634 dwg->SetPolyPoints( pts );
1654 aFootprint->
Add( fpShape );
1665 const char* txt_end;
1673 int type =
intParse( line+1, &data );
1688 m_field.Replace( wxT(
"%V" ), wxT(
"${VALUE}" ) );
1689 m_field.Replace( wxT(
"%R" ), wxT(
"${REFERENCE}" ) );
1704 char* hjust =
strtok_r( (
char*) txt_end,
delims, (
char**) &data );
1723 aText->
SetVisible( !(hide && *hide ==
'I') );
1725 aText->
SetItalic( italic && *italic ==
'I' );
1781 else if(
TESTLINE(
"$EndSHAPE3D" ) )
1783 aFootprint->
Models().push_back( t3D );
1801 std::unique_ptr<PCB_SHAPE> dseg = std::make_unique<PCB_SHAPE>(
m_board );
1812 int shape =
intParse( line +
SZ(
"Po" ), &data );
1822 dseg->SetShape(
static_cast<SHAPE_T>( shape ) );
1823 dseg->SetFilled(
false );
1828 dseg->SetCenter(
VECTOR2I( start_x, start_y ) );
1829 dseg->SetStart(
VECTOR2I( end_x, end_y ) );
1833 dseg->SetStart(
VECTOR2I( start_x, start_y ) );
1834 dseg->SetEnd(
VECTOR2I( end_x, end_y ) );
1844 for(
int i = 0; data; ++i, data =
strtok_r(
nullptr,
delims, &saveptr ) )
1868 dseg->SetArcAngleAndEnd(
angle );
1873 const_cast<KIID&
>( dseg->m_Uuid ) =
KIID( data );
1879 dseg->SetState( state,
true );
1888 dseg->SetBezierC1(
VECTOR2I( x, y ) );
1895 dseg->SetBezierC2(
VECTOR2I( x, y ) );
1903 else if(
TESTLINE(
"$EndDRAWSEGMENT" ) )
1936 netCode =
intParse( line +
SZ(
"Na" ), &data );
1940 if( net ==
nullptr )
1947 THROW_IO_ERROR( wxT(
"Two net definitions in '$EQUIPOT' block" ) );
1950 else if(
TESTLINE(
"$EndEQUIPOT" ) )
2046 int layer_num =
intParse( line +
SZ(
"De" ), &data );
2047 int notMirrored =
intParse( data, &data );
2055 pcbtxt->
SetItalic( !strcmp( style,
"Italic" ) );
2081 else if(
TESTLINE(
"$EndTEXTPCB" ) )
2105 if( line[0] ==
'$' )
2148 int layer_num =
intParse( line +
SZ(
"De" ), &data );
2149 int type =
intParse( data, &data );
2150 int net_code =
intParse( data, &data );
2152 int flags_int =
intParse( data, (
const char**) &data );
2166 wxFAIL_MSG( wxT(
"Segment type unknown" ) );
2188 via->SetViaType( viatype );
2191 via->SetDrillDefault();
2193 via->SetDrill( drill );
2207 via->SetLayerPair( front, back );
2255 std::shared_ptr<NETCLASS> nc = std::make_shared<NETCLASS>( wxEmptyString );
2267 std::make_unique<EDA_COMBINED_MATCHER>( netname,
CTX_NETCLASS ),
2274 nc->SetClearance( tmp );
2276 else if(
TESTLINE(
"TrackWidth" ) )
2279 nc->SetTrackWidth( tmp );
2284 nc->SetViaDiameter( tmp );
2289 nc->SetViaDrill( tmp );
2294 nc->SetuViaDiameter( tmp );
2299 nc->SetuViaDrill( tmp );
2311 else if(
TESTLINE(
"$EndNCLASS" ) )
2320 m_error.Printf(
_(
"Duplicate NETCLASS name '%s'." ), nc->GetName() );
2338 std::unique_ptr<ZONE> zc = std::make_unique<ZONE>(
m_board );
2341 bool endContour =
false;
2365 zc->AppendCorner(
VECTOR2I( x, y ), holeIndex );
2375 char* uuid =
strtok_r( (
char*) line +
SZ(
"ZInfo" ),
delims, (
char**) &data );
2376 int netcode =
intParse( data, &data );
2381 const_cast<KIID&
>( zc->m_Uuid ) =
KIID( uuid );
2386 zc->BOARD_CONNECTED_ITEM::SetNetCode(
getNetCode( netcode ) );
2390 int layer_num =
intParse( line +
SZ(
"ZLayer" ) );
2401 m_error.Printf(
_(
"Bad ZAux for CZONE_CONTAINER \"%s\"" ),
2402 zc->GetNetname().GetData() );
2412 m_error.Printf(
_(
"Bad ZAux for CZONE_CONTAINER \"%s\"" ),
2413 zc->GetNetname().GetData() );
2419 else if(
TESTLINE(
"ZSmoothing" ) )
2422 int smoothing =
intParse( line +
SZ(
"ZSmoothing" ), &data );
2427 m_error.Printf(
_(
"Bad ZSmoothing for CZONE_CONTAINER \"%s\"" ),
2428 zc->GetNetname().GetData() );
2432 zc->SetCornerSmoothingType( smoothing );
2433 zc->SetCornerRadius( cornerRadius );
2438 zc->SetIsRuleArea(
true );
2439 zc->SetDoNotAllowPads(
false );
2440 zc->SetDoNotAllowFootprints(
false );
2447 if( !strcmp( token,
"tracks" ) )
2450 zc->SetDoNotAllowTracks( token && *token ==
'N' );
2452 else if( !strcmp( token,
"vias" ) )
2455 zc->SetDoNotAllowVias( token && *token ==
'N' );
2457 else if( !strcmp( token,
"copperpour" ) )
2460 zc->SetDoNotAllowCopperPour( token && *token ==
'N' );
2469 int fillmode =
intParse( line +
SZ(
"ZOptions" ), &data );
2471 char fillstate = data[1];
2472 BIU thermalReliefGap =
biuParse( data += 2 , &data );
2482 _(
"The legacy segment fill mode is no longer supported.\n"
2483 "Convert zones to smoothed polygon fills?" ),
2484 _(
"Legacy Zone Warning" ),
2485 wxYES_NO | wxICON_WARNING );
2504 zc->SetIsFilled( fillstate ==
'S' );
2505 zc->SetThermalReliefGap( thermalReliefGap );
2506 zc->SetThermalReliefSpokeWidth( thermalReliefCopperBridge );
2508 else if(
TESTLINE(
"ZClearance" ) )
2511 BIU clearance =
biuParse( line +
SZ(
"ZClearance" ), &data );
2512 char* padoption =
strtok_r( (
char*) data,
delims, (
char**) &data );
2515 switch( *padoption )
2522 m_error.Printf(
_(
"Bad ZClearance padoption for CZONE_CONTAINER \"%s\"" ),
2523 zc->GetNetname().GetData() );
2527 zc->SetLocalClearance( clearance );
2528 zc->SetPadConnection( popt );
2530 else if(
TESTLINE(
"ZMinThickness" ) )
2533 zc->SetMinThickness( thickness );
2537 int priority =
intParse( line +
SZ(
"ZPriority" ) );
2538 zc->SetAssignedPriority( priority );
2540 else if(
TESTLINE(
"$POLYSCORNERS" ) )
2545 bool makeNewOutline =
true;
2549 if(
TESTLINE(
"$endPOLYSCORNERS" ) )
2556 if( makeNewOutline )
2559 polysList.
Append( x, y );
2562 bool end_contour =
intParse( data, &data );
2565 makeNewOutline = end_contour;
2568 zc->SetFilledPolysList( zc->GetLayer(), polysList );
2570 else if(
TESTLINE(
"$FILLSEGMENTS" ) )
2574 if(
TESTLINE(
"$endFILLSEGMENTS" ) )
2584 else if(
TESTLINE(
"$endCZONE_OUTLINE" ) )
2588 if( zc->GetIsRuleArea() )
2594 if( zc->GetNumCorners() > 2 )
2596 if( !zc->IsOnCopperLayer() )
2619 std::unique_ptr<PCB_DIM_ALIGNED> dim = std::make_unique<PCB_DIM_ALIGNED>(
m_board,
2632 dim->UpdateHeight( crossBarF, crossBarO );
2647 int shape =
intParse( line +
SZ(
"De" ), (
const char**) &data );
2648 int layer_num =
intParse( data, &data );
2652 const_cast<KIID&
>( dim->m_Uuid ) =
KIID( uuid );
2662 dim->SetOverrideText(
FROM_UTF8( buf ) );
2663 dim->SetOverrideTextEnabled(
true );
2665 dim->SetAutoUnits();
2677 dim->SetTextPos(
VECTOR2I( pos_x, pos_y ) );
2678 dim->SetTextSize(
VECTOR2I( width, height ) );
2679 dim->SetMirrored( mirror && *mirror ==
'0' );
2680 dim->SetTextThickness( thickn );
2681 dim->SetTextAngle( orient );
2692 dim->SetLineThickness( width );
2693 crossBarO =
VECTOR2I( crossBarOx, crossBarOy );
2694 crossBarF =
VECTOR2I( crossBarFx, crossBarFy );
2705 dim->SetStart(
VECTOR2I( featureLineDOx, featureLineDOy ) );
2716 dim->SetEnd(
VECTOR2I( featureLineGOx, featureLineGOy ) );
2770 int shape =
intParse( line +
SZ(
"Po" ), &data );
2771 int layer_num =
intParse( data, &data );
2784 VECTOR2I( pos_x, pos_y ), size, width );
2801 double fval = strtod( aValue, &nptr );
2805 m_error.Printf(
_(
"Invalid floating point number in file: '%s'\nline: %d, offset: %d" ),
2813 if( aValue == nptr )
2815 m_error.Printf(
_(
"Missing floating point number in file: '%s'\nline: %d, offset: %d" ),
2840 double fval = strtod( aValue, &nptr );
2844 m_error.Printf(
_(
"Invalid floating point number in file: '%s'\nline: %d, offset: %d" ),
2852 if( aValue == nptr )
2854 m_error.Printf(
_(
"Missing floating point number in file: '%s'\nline: %d, offset: %d" ),
2908#include <boost/ptr_container/ptr_map.hpp>
2909#include <wx/filename.h>
2935 static long long GetTimestamp(
const wxString& aLibPath );
2951 m_lib_path( aLibraryPath ),
2953 m_cache_dirty( true ),
2954 m_cache_timestamp( 0 )
2969 return wxFileName( aLibPath ).GetModificationTime().GetValue().GetValue();
2998 if( !
TESTLINE(
"PCBNEW-LibModule-V1" ) )
3001 while( ( line = aReader->
ReadLine() ) !=
nullptr )
3007 if( !strcmp( units,
"mm" ) )
3025 char* line = aReader->
Line();
3033 while( ( line = aReader->
ReadLine() ) !=
nullptr )
3046 }
while( ( line = aReader->
ReadLine() ) !=
nullptr );
3054 char* line = aReader->
Line();
3061 std::unique_ptr<FOOTPRINT> fp_ptr = std::make_unique<FOOTPRINT>(
m_owner->
m_board );
3063 std::string footprintName =
StrPurge( line +
SZ(
"$MODULE" ) );
3070 fp_ptr->SetFPID(
LIB_ID( wxEmptyString, footprintName ) );
3092 FOOTPRINT_MAP::const_iterator it =
m_footprints.find( footprintName );
3098 wxFAIL_MSG( wxT(
"error doing cache insert using guaranteed unique name" ) );
3105 bool nameOK =
false;
3111 std::string newName = footprintName;
3114 snprintf( buf,
sizeof(buf),
"%d", version++ );
3127 wxFAIL_MSG( wxT(
"error doing cache insert using guaranteed unique "
3135 }
while( ( line = aReader->
ReadLine() ) !=
nullptr );
3163 init( aProperties );
3171 errorMsg = ioe.
What();
3178 aFootprintNames.Add(
FROM_UTF8( footprint.first.c_str() ) );
3180 if( !errorMsg.IsEmpty() && !aBestEfforts )
3186 const wxString& aFootprintName,
bool aKeepUUID,
3191 init( aProperties );
3196 FOOTPRINT_MAP::const_iterator it = footprints.find(
TO_UTF8( aFootprintName ) );
3198 if( it == footprints.end() )
3205 copy->SetParent(
nullptr );
3213 wxFileName fn = aLibraryPath;
3215 if( !fn.FileExists() )
3220 if( wxRemove( aLibraryPath ) )
3223 aLibraryPath.GetData() ) );
3256 m_progressReporter( nullptr ),
3257 m_lastProgressLine( 0 ),
3259 m_reader( nullptr ),
constexpr EDA_IU_SCALE pcbIUScale
LAYER_T
The allowed types of layers, same as Specctra DSN spec.
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
void SetGridOrigin(const VECTOR2I &aOrigin)
std::unique_ptr< PAD > m_Pad_Master
void SetAuxOrigin(const VECTOR2I &aOrigin)
int m_SolderMaskExpansion
int m_TextThickness[LAYER_CLASS_COUNT]
std::vector< int > m_TrackWidthList
int m_LineThickness[LAYER_CLASS_COUNT]
void SetBoardThickness(int aThickness)
double m_SolderPasteMarginRatio
VECTOR2I m_TextSize[LAYER_CLASS_COUNT]
std::vector< VIA_DIMENSION > m_ViasDimensionsList
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
BOARD_ITEM_CONTAINER * GetParentFootprint() const
Information pertinent to a Pcbnew printed circuit board.
void SetPlotOptions(const PCB_PLOT_PARAMS &aOptions)
bool m_LegacyDesignSettingsLoaded
True if the legacy board design settings were loaded from a file.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
void SetZoneSettings(const ZONE_SETTINGS &aSettings) override
Set the zone settings for this container.
void SetFileName(const wxString &aFileName)
const ZONE_SETTINGS & GetZoneSettings() const override
Fetch the zone settings for this container.
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
void SetPageSettings(const PAGE_INFO &aPageSettings)
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
void SetCopperLayerCount(int aCount)
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Change the type of the layer given by aLayer.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
void SetVisibleElements(const GAL_SET &aMask)
A proxy function that calls the correspondent function in m_BoardSettings.
void SetFileFormatVersionAtLoad(int aVersion)
void SetState(EDA_ITEM_FLAGS type, bool state)
virtual const wxString & GetText() const
Return the string associated with the text object.
void SetTextPos(const VECTOR2I &aPoint)
void SetMirrored(bool isMirrored)
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
GR_TEXT_H_ALIGN_T GetHorizJustify() const
virtual void SetVisible(bool aVisible)
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
void SetTextSize(const VECTOR2I &aNewSize)
virtual void SetText(const wxString &aText)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
void SetItalic(bool aItalic)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
A LINE_READER that reads from an open file.
void Rewind()
Rewind the file and resets the line number back to zero.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
VECTOR3D m_Offset
3D model offset (mm)
VECTOR3D m_Rotation
3D model rotation (degrees)
VECTOR3D m_Scale
3D model scaling factor (dimensionless)
wxString m_Filename
The 3D shape filename in 3D library.
virtual void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
void SetType(TEXT_TYPE aType)
void SetDrawCoord()
Set relative coordinates.
TEXT_TYPE
Footprint text type: there must be only one (and only one) for each of the reference value texts in o...
void SetPos0(const VECTOR2I &aPos)
Helper for storing and iterating over GAL_LAYER_IDs.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
A PLUGIN derivation which could possibly be put into a DLL/DSO.
unsigned m_lastProgressLine
int m_loading_format_version
which BOARD_FORMAT_VERSION am I Load()ing?
int getNetCode(int aNetCode)
BIU biuParse(const char *aValue, const char **nptrptr=nullptr)
Parse an ASCII decimal floating point value and scales it into a BIU according to the current value o...
static LSET leg_mask2new(int cu_count, unsigned aMask)
void loadFP_SHAPE(FOOTPRINT *aFootprint)
void init(const STRING_UTF8_MAP *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
double diskToBiu
convert from disk engineering units to BIUs with this scale factor
void loadTrackList(int aStructType)
Read a list of segments (Tracks and Vias, or Segzones)
bool m_showLegacySegmentZoneWarning
wxString m_field
reused to stuff FOOTPRINT fields.
static PCB_LAYER_ID leg_layer2new(int cu_count, int aLayerNum)
PROGRESS_REPORTER * m_progressReporter
may be NULL, no ownership
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
Load information from some input file format that this PLUGIN implementation knows about into either ...
double biuToDisk
convert from BIUs to disk engineering units with this scale factor
unsigned m_lineCount
for progress reporting
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const STRING_UTF8_MAP *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
void loadFOOTPRINT(FOOTPRINT *aFootprint)
void loadPAD(FOOTPRINT *aFootprint)
void checkpoint()
Converts net code using the mapping table if available, otherwise returns unchanged net code.
void loadAllSections(bool doAppend)
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
bool FootprintLibDelete(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete an existing footprint library and returns true, or if library does not exist returns false,...
void load3D(FOOTPRINT *aFootprint)
EDA_ANGLE degParse(const char *aValue, const char **nptrptr=nullptr)
Parse an ASCII decimal floating point value which is certainly an angle in tenths of a degree.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
void loadZONE_CONTAINER()
wxString m_error
for throwing exceptions
std::vector< int > m_netCodes
net codes mapping for boards being loaded
const STRING_UTF8_MAP * m_props
passed via Save() or Load(), no ownership,
void loadMODULE_TEXT(FP_TEXT *aText)
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const STRING_UTF8_MAP *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
LINE_READER * m_reader
no ownership here.
void SetReader(LINE_READER *aReader)
void cacheLib(const wxString &aLibraryPath)
we only cache one footprint library for now, this determines which one.
BOARD * m_board
which BOARD, no ownership here
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
const UTF8 & GetLibItemName() const
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
char * Line() const
Return a pointer to the last line that was read in.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
LSET is a set of PCB_LAYER_IDs.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Handle the data for a net.
static const int UNCONNECTED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetWidthMils(int aWidthInMils)
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
static const wxChar Custom[]
"User" defined page type
void SetHeightMils(int aHeightInMils)
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
The parser for PCB_PLOT_PARAMS.
Parameters and options when plotting/printing a board.
void Parse(PCB_PLOT_PARAMS_PARSER *aParser)
void SetWidth(int aWidth)
void SetEnd(const VECTOR2I &aEnd)
void SetPosition(const VECTOR2I &aPos) override
A progress reporter interface for use in multi-threaded environments.
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
Container for project specific data.
Represent a set of closed polygons.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...
int NewOutline()
Creates a new hole in a given outline.
A name/value tuple with unique names and optional values.
Simple container to manage line stroke parameters.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
void SetRevision(const wxString &aRevision)
void SetComment(int aIdx, const wxString &aComment)
void SetTitle(const wxString &aTitle)
void SetCompany(const wxString &aCompany)
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
ZONE_SETTINGS handles zones parameters.
static int GetDefaultHatchPitch()
This file is part of the common library.
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
std::uint32_t EDA_ITEM_FLAGS
void ignore_unused(const T &)
#define THROW_IO_ERROR(msg)
PCB_LAYER_ID
A quick note on layer IDs:
static GR_TEXT_V_ALIGN_T vertJustify(const char *vertical)
static int intParse(const char *next, const char **out=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
#define SILKSCREEN_N_BACK
#define SZ(x)
Get the length of a string constant, at compile time.
static const char delims[]
#define TESTSUBSTR(x)
C sub-string compare test for a specific length of characters.
#define LAST_NON_COPPER_LAYER
#define SOLDERMASK_N_FRONT
#define SOLDERMASK_N_BACK
bool is_leg_copperlayer_valid(int aCu_Count, int aLegacyLayerNum)
#define SOLDERPASTE_N_BACK
int layerMaskCountSet(LEG_MASK aMask)
Count the number of set layers in the mask.
static long hexParse(const char *next, const char **out=nullptr)
Parse an ASCII hex integer string with possible leading whitespace into a long integer and updates th...
#define SOLDERPASTE_N_FRONT
static GR_TEXT_H_ALIGN_T horizJustify(const char *horizontal)
#define SILKSCREEN_N_FRONT
#define TESTLINE(x)
C string compare test for a specific length of characters.
boost::ptr_map< std::string, FOOTPRINT > FOOTPRINT_MAP
#define FIRST_NON_COPPER_LAYER
static bool isSpace(int c)
#define FIRST_COPPER_LAYER
This file contains miscellaneous commonly used macros and functions.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
PAD_ATTRIB
The set of pad shapes, used with PAD::{Set,Get}Attribute().
@ NPTH
like PAD_PTH, but not plated
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
@ CONN
Like smd, does not appear on the solder paste layer (default)
PAD_DRILL_SHAPE_T
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
int ReadDelimitedText(wxString *aDest, const char *aSource)
Copy bytes from aSource delimited string segment to aDest wxString.
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
char * strtok_r(char *str, const char *delim, char **nextp)
static LAYER_T ParseType(const char *aType)
Convert a string to a LAYER_T.
The footprint portion of the PLUGIN API, and only for the LEGACY_PLUGIN, so therefore is private to t...
LP_CACHE(LEGACY_PLUGIN *aOwner, const wxString &aLibraryPath)
void ReadAndVerifyHeader(LINE_READER *aReader)
long long m_cache_timestamp
void LoadModules(LINE_READER *aReader)
FOOTPRINT_MAP m_footprints
static long long GetTimestamp(const wxString &aLibPath)
void SkipIndex(LINE_READER *aReader)
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ NOT_USED
the 3d code uses this value
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
ZONE_BORDER_DISPLAY_STYLE
Zone border styles.
ZONE_CONNECTION
How pads are covered by copper in zone.
@ THERMAL
Use thermal relief for pads.
@ THT_THERMAL
Thermal relief only for THT pads.
@ NONE
Pads are not covered.
@ FULL
pads are covered by copper