45#include <wx/filename.h>
63 std::placeholders::_1 ) );
101 const std::map<std::string, UTF8>* aProperties,
106 std::unique_ptr<BOARD> board( aAppendToMe ? aAppendToMe :
new BOARD() );
118 parser.
Parse( aFileName );
120 catch(
const std::exception& e )
122 THROW_IO_ERROR( wxString::Format(
"Error parsing PADS binary file: %s", e.what() ) );
154 return board.release();
162 std::vector<PADS_IO::LAYER_INFO> padsLayerInfos =
m_parser->GetLayerInfos();
188 for(
const auto& padsInfo : padsLayerInfos )
191 info.padsLayerNum = padsInfo.number;
192 info.name = padsInfo.name;
196 info.type = convertLayerType( padsInfo.layer_type );
200 if( padsInfo.number == 1 )
202 else if( padsInfo.number ==
m_parser->GetParameters().layer_count )
211 info.required = padsInfo.required;
215 std::vector<INPUT_LAYER_DESC> inputDescs =
221 int copperLayerCount =
m_parser->GetParameters().layer_count;
223 if( copperLayerCount < 1 )
224 copperLayerCount = 2;
226 m_loadBoard->SetCopperLayerCount( copperLayerCount );
239 const auto& boardOutlines =
m_parser->GetBoardOutlines();
241 if( !boardOutlines.empty() )
243 double minX = std::numeric_limits<double>::max();
244 double maxX = std::numeric_limits<double>::lowest();
245 double minY = std::numeric_limits<double>::max();
246 double maxY = std::numeric_limits<double>::lowest();
248 for(
const auto& outline : boardOutlines )
250 for(
const auto& pt : outline.points )
252 minX = std::min( minX, pt.x );
253 maxX = std::max( maxX, pt.x );
254 minY = std::min( minY, pt.y );
255 maxY = std::max( maxY, pt.y );
259 if( minX < maxX && minY < maxY )
271 const auto& nets =
m_parser->GetNets();
273 for(
const auto& padsNet : nets )
280 const auto& decals =
m_parser->GetPartDecals();
281 const auto& parts =
m_parser->GetParts();
283 for(
const auto& padsPart : parts )
290 path.push_back( symbolUuid );
293 std::string decalName = padsPart.decal;
297 if( !decalName.empty() )
303 footprint->
SetValue( padsPart.decal );
312 if( padsPart.bottom_layer )
322 const auto& pts = polyline.points;
327 for(
size_t i = 0; i < pts.size() - 1; ++i )
346 if( polyline.closed && pts.size() > 2 )
351 bool needsClosing = (
std::abs( pLast.
x - pFirst.
x ) > 0.001
373 const auto& routes =
m_parser->GetRoutes();
374 std::set<std::pair<int, int>> placedThroughVias;
376 for(
const auto& route : routes )
380 if( !route.net_name.empty() )
389 for(
const auto& track_def : route.tracks )
391 if( track_def.points.size() < 2 )
400 if( route.net_name.empty() && track_def.layer == 0 )
409 _(
"Skipping track on non-copper layer %d" ), track_def.layer ),
417 int track_width =
scaleSize( track_def.width );
419 if( track_width <= 0 )
422 for(
size_t i = 0; i < track_def.points.size() - 1; ++i )
430 if( ( start -
end ).EuclideanNorm() < 1000 )
469 for(
const auto& via_def : route.vias )
474 if( placedThroughVias.count( std::make_pair( pos.
x, pos.
y ) ) )
477 placedThroughVias.insert( std::make_pair( pos.
x, pos.
y ) );
484 via->SetPosition( pos );
497 const auto& texts =
m_parser->GetTexts();
499 for(
const auto& pads_text : texts )
508 _(
"Text on unmapped layer %d assigned to Comments layer" ),
516 text->SetText( pads_text.content );
518 int scaledSize =
scaleSize( pads_text.height );
525 if( pads_text.width > 0 )
529 text->SetTextAngle( textAngle );
535 text->SetPosition( pos + textShift );
537 if( pads_text.hjust ==
"LEFT" )
539 else if( pads_text.hjust ==
"RIGHT" )
544 if( pads_text.vjust ==
"UP" )
546 else if( pads_text.vjust ==
"DOWN" )
551 text->SetKeepUpright(
false );
552 text->SetLayer( textLayer );
560 const auto& pours =
m_parser->GetPours();
561 const auto& params =
m_parser->GetParameters();
565 for(
const auto& pour_def : pours )
567 if( pour_def.priority > maxPriority )
568 maxPriority = pour_def.priority;
571 for(
const auto& pour_def : pours )
580 _(
"Skipping pour on unmapped layer %d" ), pour_def.layer ),
592 for(
const auto& pt : pour_def.points )
603 if( pour_def.is_cutout )
611 zone->
SetZoneName( wxString::Format( wxT(
"Cutout_%s" ), pour_def.owner_pour ) );
621 int kicadPriority = maxPriority - pour_def.priority + 1;
641 size_t trackCount = 0;
652 m_reporter->Report( wxString::Format(
_(
"Imported %zu footprints, %d nets, %zu tracks,"
653 " %zu vias, %zu zones" ),
656 trackCount, viaCount,
663 const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector )
665 std::map<wxString, PCB_LAYER_ID> layerMap;
668 layerMap[layer.Name] = layer.AutoMapLayer;
684 long long originNm =
static_cast<long long>( std::round( origin *
m_scaleFactor ) );
685 long long valNm =
static_cast<long long>( std::round( aVal *
m_scaleFactor ) );
688 return static_cast<int>( valNm - originNm );
690 return static_cast<int>( originNm - valNm );
698 if(
info.padsLayerNum == aPadsLayer )
715 if( aNetName.empty() )
724 static_cast<int>(
m_loadBoard->GetNetCount() ) + 1 );
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
void SetStart(const VECTOR2I &aStart)
void SetShape(SHAPE_T aShape)
void SetEnd(const VECTOR2I &aEnd)
void SetWidth(int aWidth)
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 SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
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 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.