41#include <wx/filename.h>
59 std::placeholders::_1 ) );
97 const std::map<std::string, UTF8>* aProperties,
102 std::unique_ptr<BOARD> board( aAppendToMe ? aAppendToMe :
new BOARD() );
114 parser.
Parse( aFileName );
116 catch(
const std::exception& e )
118 THROW_IO_ERROR( wxString::Format(
"Error parsing PADS binary file: %s", e.what() ) );
150 return board.release();
158 std::vector<PADS_IO::LAYER_INFO> padsLayerInfos =
m_parser->GetLayerInfos();
184 for(
const auto& padsInfo : padsLayerInfos )
187 info.padsLayerNum = padsInfo.number;
188 info.name = padsInfo.name;
192 info.type = convertLayerType( padsInfo.layer_type );
196 if( padsInfo.number == 1 )
198 else if( padsInfo.number ==
m_parser->GetParameters().layer_count )
207 info.required = padsInfo.required;
211 std::vector<INPUT_LAYER_DESC> inputDescs =
217 int copperLayerCount =
m_parser->GetParameters().layer_count;
219 if( copperLayerCount < 1 )
220 copperLayerCount = 2;
222 m_loadBoard->SetCopperLayerCount( copperLayerCount );
235 const auto& boardOutlines =
m_parser->GetBoardOutlines();
237 if( !boardOutlines.empty() )
239 double minX = std::numeric_limits<double>::max();
240 double maxX = std::numeric_limits<double>::lowest();
241 double minY = std::numeric_limits<double>::max();
242 double maxY = std::numeric_limits<double>::lowest();
244 for(
const auto& outline : boardOutlines )
246 for(
const auto& pt : outline.points )
248 minX = std::min( minX, pt.x );
249 maxX = std::max( maxX, pt.x );
250 minY = std::min( minY, pt.y );
251 maxY = std::max( maxY, pt.y );
255 if( minX < maxX && minY < maxY )
267 const auto& nets =
m_parser->GetNets();
269 for(
const auto& padsNet : nets )
276 const auto& decals =
m_parser->GetPartDecals();
277 const auto& parts =
m_parser->GetParts();
279 for(
const auto& padsPart : parts )
286 path.push_back( symbolUuid );
289 std::string decalName = padsPart.decal;
293 if( !decalName.empty() )
299 footprint->
SetValue( padsPart.decal );
308 if( padsPart.bottom_layer )
318 const auto& pts = polyline.points;
323 for(
size_t i = 0; i < pts.size() - 1; ++i )
342 if( polyline.closed && pts.size() > 2 )
347 bool needsClosing = (
std::abs( pLast.
x - pFirst.
x ) > 0.001
369 const auto& routes =
m_parser->GetRoutes();
370 std::set<std::pair<int, int>> placedThroughVias;
372 for(
const auto& route : routes )
376 if( !route.net_name.empty() )
385 for(
const auto& track_def : route.tracks )
387 if( track_def.points.size() < 2 )
396 if( route.net_name.empty() && track_def.layer == 0 )
405 _(
"Skipping track on non-copper layer %d" ), track_def.layer ),
413 int track_width =
scaleSize( track_def.width );
415 if( track_width <= 0 )
418 for(
size_t i = 0; i < track_def.points.size() - 1; ++i )
426 if( ( start -
end ).EuclideanNorm() < 1000 )
465 for(
const auto& via_def : route.vias )
470 if( placedThroughVias.count( std::make_pair( pos.
x, pos.
y ) ) )
473 placedThroughVias.insert( std::make_pair( pos.
x, pos.
y ) );
480 via->SetPosition( pos );
493 const auto& texts =
m_parser->GetTexts();
495 for(
const auto& pads_text : texts )
504 _(
"Text on unmapped layer %d assigned to Comments layer" ),
512 text->SetText( pads_text.content );
514 int scaledSize =
scaleSize( pads_text.height );
521 if( pads_text.width > 0 )
525 text->SetTextAngle( textAngle );
531 text->SetPosition( pos + textShift );
533 if( pads_text.hjust ==
"LEFT" )
535 else if( pads_text.hjust ==
"RIGHT" )
540 if( pads_text.vjust ==
"UP" )
542 else if( pads_text.vjust ==
"DOWN" )
547 text->SetKeepUpright(
false );
548 text->SetLayer( textLayer );
556 const auto& pours =
m_parser->GetPours();
557 const auto& params =
m_parser->GetParameters();
561 for(
const auto& pour_def : pours )
563 if( pour_def.priority > maxPriority )
564 maxPriority = pour_def.priority;
567 for(
const auto& pour_def : pours )
576 _(
"Skipping pour on unmapped layer %d" ), pour_def.layer ),
588 for(
const auto& pt : pour_def.points )
599 if( pour_def.is_cutout )
607 zone->
SetZoneName( wxString::Format( wxT(
"Cutout_%s" ), pour_def.owner_pour ) );
617 int kicadPriority = maxPriority - pour_def.priority + 1;
637 size_t trackCount = 0;
648 m_reporter->Report( wxString::Format(
_(
"Imported %zu footprints, %d nets, %zu tracks,"
649 " %zu vias, %zu zones" ),
652 trackCount, viaCount,
659 const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector )
661 std::map<wxString, PCB_LAYER_ID> layerMap;
664 layerMap[layer.Name] = layer.AutoMapLayer;
680 long long originNm =
static_cast<long long>( std::round( origin *
m_scaleFactor ) );
681 long long valNm =
static_cast<long long>( std::round( aVal *
m_scaleFactor ) );
684 return static_cast<int>( valNm - originNm );
686 return static_cast<int>( originNm - valNm );
694 if(
info.padsLayerNum == aPadsLayer )
711 if( aNetName.empty() )
720 static_cast<int>(
m_loadBoard->GetNetCount() ) + 1 );
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
virtual void RegisterCallback(LAYER_MAPPING_HANDLER aLayerMappingHandler)
Register a different handler to be called when mapping of input layers to KiCad layers occurs.
LAYER_MAPPING_HANDLER m_layer_mapping_handler
Callback to get layer mapping.
A logical library item identifier and consists of various portions much like a URI.
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Handle the data for a net.
Parser for PADS binary PCB file format (.pcb).
static bool IsBinaryPadsFile(const wxString &aFileName)
Check if a file appears to be a PADS binary PCB file.
void Parse(const wxString &aFileName)
Maps PADS layer numbers and names to KiCad layer IDs.
Converts PADS file format units to KiCad internal units (nanometers).
static constexpr double BASIC_TO_NM
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
const IO_FILE_DESC GetBoardFileDesc() const override
Returns board file description for the PCB_IO.
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties, PROJECT *aProject) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
~PCB_IO_PADS_BINARY() override
int scaleSize(double aVal) const
const IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
const PADS_IO::BINARY_PARSER * m_parser
PCB_LAYER_ID getMappedLayer(int aPadsLayer) const
PADS_UNIT_CONVERTER m_unitConverter
void ensureNet(const std::string &aNetName)
int scaleCoord(double aVal, bool aIsX) const
std::vector< PADS_LAYER_INFO > m_layerInfos
PADS_LAYER_MAPPER m_layerMapper
std::map< wxString, PCB_LAYER_ID > m_layerMap
std::map< std::string, std::string > m_pinToNetMap
std::map< wxString, PCB_LAYER_ID > DefaultLayerMappingCallback(const std::vector< INPUT_LAYER_DESC > &aInputLayerDescriptionVector)
virtual bool CanReadBoard(const wxString &aFileName) const
Checks if this PCB_IO can read the specified board file.
PCB_IO(const wxString &aName)
void SetWidth(int aWidth) override
void SetShape(SHAPE_T aShape) override
void SetEnd(const VECTOR2I &aEnd) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
void SetEnd(const VECTOR2I &aEnd)
void SetStart(const VECTOR2I &aStart)
virtual void SetWidth(int aWidth)
Container for project specific data.
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
Handle a list of polygons defining a copper zone.
void SetDoNotAllowPads(bool aEnable)
void SetMinThickness(int aMinThickness)
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
SHAPE_POLY_SET * Outline()
void SetIsRuleArea(bool aEnable)
void SetDoNotAllowTracks(bool aEnable)
void SetDoNotAllowVias(bool aEnable)
void SetNet(NETINFO_ITEM *aNetInfo) override
Override that drops aNetInfo when this zone is in copper-thieving fill mode.
void SetThermalReliefGap(int aThermalReliefGap)
void SetDoNotAllowFootprints(bool aEnable)
void SetDoNotAllowZoneFills(bool aEnable)
void SetAssignedPriority(unsigned aPriority)
void SetPadConnection(ZONE_CONNECTION aPadConnection)
void SetZoneName(const wxString &aName)
int GetNumCorners(void) const
Access to m_Poly parameters.
double m_PadsPcbTextWidthScale
PADS text width scale factor for PCB imports.
double m_PadsPcbTextHeightScale
PADS text height scale factor for PCB imports.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
@ LEFT_RIGHT
Flip left to right (around the Y axis)
wxString ConvertInvertedNetName(const std::string &aNetName)
Convert a PADS net name to KiCad format, handling inverted signal notation.
KIID GenerateDeterministicUuid(const std::string &aIdentifier)
Generate a deterministic KIID from a PADS component identifier.
PADS_LAYER_FUNCTION
Layer types from PADS LAYER_TYPE field.
@ ASSEMBLY
Assembly drawing.
@ ROUTING
Copper routing layer.
@ PASTE_MASK
Solder paste mask.
@ MIXED
Mixed signal/plane.
@ DOCUMENTATION
Documentation layer.
@ SILK_SCREEN
Silkscreen/legend.
@ PLANE
Power/ground plane.
@ SOLDER_MASK
Solder mask.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Common utilities and types for parsing PADS file formats.
PADS_LAYER_TYPE
PADS layer types.
Container that describes file type info.
wxString m_Description
Description shown in the file picker dialog.
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
A point that may be either a line endpoint or an arc segment.
ARC arc
Arc parameters (only valid when is_arc is true)
bool is_arc
True if this segment is an arc, false for line.
double y
Endpoint Y coordinate.
double x
Endpoint X coordinate.
double cx
Center X coordinate.
double delta_angle
Arc sweep angle in degrees (positive = CCW)
double cy
Center Y coordinate.
A polyline that may contain arc segments.
Information about a single PADS layer.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
VECTOR2< int32_t > VECTOR2I
@ THERMAL
Use thermal relief for pads.