65 PCB_IO( wxS(
"Protel Autotrax" ) )
81static bool readFile(
const wxString& aFileName, wxString& aOut,
size_t aLimit = 0 )
83 std::ifstream file( aFileName.fn_str(), std::ios::binary );
93 file.read( raw.data(), aLimit );
94 raw.resize(
static_cast<size_t>( file.gcount() ) );
98 std::ostringstream ss;
103 aOut = wxString::FromUTF8( raw.data(), raw.size() );
105 if( aOut.IsEmpty() && !raw.empty() )
106 aOut = wxString::From8BitData( raw.data(), raw.size() );
121 if( !
readFile( aFileName, contents, 4096 ) )
129 const std::map<std::string, UTF8>* aProperties,
PROJECT* aProject )
139 if( !
readFile( aFileName, contents ) )
147 if( !parser.
Parse( contents, data ) )
148 THROW_IO_ERRORF(
_(
"'%s' is not a valid Protel Autotrax file." ), aFileName );
181 if( aNetName.IsEmpty() )
184 auto it =
m_nets.find( aNetName );
193 m_nets[aNetName] = existing;
213 aFootprint->
Add( aItem );
235 case 1:
return { { 90.0, 90.0 } };
236 case 2:
return { { 0.0, 90.0 } };
237 case 4:
return { { 270.0, 90.0 } };
238 case 8:
return { { 180.0, 90.0 } };
239 case 3:
return { { 0.0, 180.0 } };
240 case 6:
return { { 270.0, 180.0 } };
241 case 12:
return { { 180.0, 180.0 } };
242 case 9:
return { { 90.0, 180.0 } };
243 case 14:
return { { 180.0, 270.0 } };
244 case 13:
return { { 90.0, 270.0 } };
245 case 11:
return { { 0.0, 270.0 } };
246 case 7:
return { { 270.0, 270.0 } };
247 case 5:
return { { 270.0, 90.0 }, { 90.0, 90.0 } };
248 case 10:
return { { 180.0, 90.0 }, { 0.0, 90.0 } };
249 default:
return { { 0.0, 360.0 } };
292 int width = std::max( 1,
toIU( aArc.
width ) );
297 auto pointAt = [&](
double aDeg )
299 double rad = aDeg *
M_PI / 180.0;
309 if( span.deltaDeg >= 360.0 )
318 shape->
SetArcGeometry( pointAt( span.startDeg ), pointAt( span.startDeg + span.deltaDeg / 2.0 ),
319 pointAt( span.startDeg + span.deltaDeg ) );
329 int drill = std::max( 1,
toIU( aVia.
drill ) );
330 int diameter = std::max( drill + 2,
toIU( aVia.
diameter ) );
351 via->SetDrill( drill );
381 bool standalone =
false;
432 pad->SetLayerSet( smdMask );
452 int minX = std::min( p1.
x, p2.
x );
453 int maxX = std::max( p1.
x, p2.
x );
454 int minY = std::min( p1.
y, p2.
y );
455 int maxY = std::max( p1.
y, p2.
y );
497 text->SetLayer( layer );
500 int height = std::max( 1,
toIU( aText.
height ) );
502 text->SetTextThickness( std::max( 1,
toIU( aText.
width ) ) );
509 text->SetMirrored(
true );
520 if( !aComp.
refdes.IsEmpty() )
523 if( !aComp.
value.IsEmpty() )
526 if( !aComp.
name.IsEmpty() )
532 for(
const ARC& a : aComp.
arcs )
535 for(
const VIA& v : aComp.
vias )
565 double maxYmils = 0.0;
567 auto noteLayer = [&](
int aLayer )
583 auto scan = [&](
const auto& aContainer )
585 for(
const TRACK& t : aContainer.tracks )
587 noteLayer( t.
layer );
588 maxYmils = std::max( { maxYmils, t.
y1, t.
y2 } );
591 for(
const ARC& a : aContainer.arcs )
593 noteLayer( a.
layer );
597 for(
const VIA& v : aContainer.vias )
598 maxYmils = std::max( maxYmils, v.
y );
602 noteLayer( p.
layer );
603 maxYmils = std::max( maxYmils, p.
y );
606 for(
const FILL& f : aContainer.fills )
608 noteLayer( f.
layer );
609 maxYmils = std::max( { maxYmils, f.
y1, f.
y2 } );
612 for(
const TEXT& s : aContainer.texts )
613 maxYmils = std::max( maxYmils, s.
y );
621 m_board->SetCopperLayerCount( 2 + innerNeeded );
631 for(
const ARC& a : aData.
arcs )
634 for(
const VIA& v : aData.
vias )
Line-oriented parser for Protel Autotrax / Easytrax PCB files.
static bool Sniff(const wxString &aContents)
Cheap content sniff: the first non-blank, non-comment line is the magic header "PCB FILE 4" (Autotrax...
bool Parse(const wxString &aContents, AUTOTRAX::BOARD_DATA &aBoard)
Parse aContents into aBoard.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
void SetCenter(const VECTOR2I &aCenter)
virtual void SetFilled(bool aFlag)
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
A logical library item identifier and consists of various portions much like a URI.
LSET is a set of PCB_LAYER_IDs.
LSET & FlipStandardLayers(int aCopperLayersCount=0)
Flip the layers in this set.
Handle the data for a net.
static REPORTER & GetInstance()
@ NORMAL
Shape is the same on all layers.
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
static LSET PTHMask()
layer set for a through hole pad
static LSET SMDMask()
layer set for a SMD pad on Front layer
void buildComponent(const AUTOTRAX::COMPONENT &aComp)
NETINFO_ITEM * getNet(const wxString &aNetName)
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
std::map< wxString, NETINFO_ITEM * > m_nets
static int toIU(double aMils)
Convert a mil value to KiCad internal units (nm).
void buildBoard(const AUTOTRAX::BOARD_DATA &aData)
BOARD_ITEM * parentOf(FOOTPRINT *aFootprint) const
Parent for a primitive: the owning footprint, or the board for free items.
void addItem(BOARD_ITEM *aItem, FOOTPRINT *aFootprint)
Attach an item to its footprint, or append it to the board.
int m_maxY
board Y extent in IU, used to flip the Y axis
~PCB_IO_AUTOTRAX() override
VECTOR2I toBoard(double aX, double aY) const
Convert an Autotrax point (mils, Y-down) to a board point (nm, Y-up).
void emitTrack(const AUTOTRAX::TRACK &aTrack, FOOTPRINT *aFootprint)
void emitFill(const AUTOTRAX::FILL &aFill, FOOTPRINT *aFootprint)
void emitPad(const AUTOTRAX::PAD &aPad, FOOTPRINT *aFootprint)
void emitArc(const AUTOTRAX::ARC &aArc, FOOTPRINT *aFootprint)
bool mapLayer(int aLayer, PCB_LAYER_ID &aResult) const
Map an Autotrax layer number to a KiCad layer.
void loadBoard(const wxString &aFileName, BOARD &aBoard, bool aIsNewLoad, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Parse aFileName into aBoard.
void emitText(const AUTOTRAX::TEXT &aText, FOOTPRINT *aFootprint)
void emitVia(const AUTOTRAX::VIA &aVia, FOOTPRINT *aFootprint)
BOARD * m_board
The board BOARD being worked on, no ownership here.
virtual bool CanReadBoard(const wxString &aFileName) const
Checks if this PCB_IO can read the specified board file.
PCB_IO(const wxString &aName)
const std::map< std::string, UTF8 > * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
void SetWidth(int aWidth) override
void SetShape(SHAPE_T aShape) override
void SetEnd(const VECTOR2I &aEnd) override
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
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.
A pure virtual class used to derive REPORTER objects from.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
Handle a list of polygons defining a copper zone.
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetAssignedPriority(unsigned aPriority)
void SetOutline(SHAPE_POLY_SET *aOutline)
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
#define THROW_IO_ERRORF(msg,...)
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
static std::vector< ARC_SPAN > arcSpansFromSegments(int aSegments)
Translate an Autotrax arc quadrant bitmask into the arc spans it represents.
static bool readFile(const wxString &aFileName, wxString &aOut, size_t aLimit=0)
Read a file into aOut.
One arc as a (start angle, signed sweep) pair in the file's native Y-down frame.
Free or component arc (FA / CA).
int segments
quadrant bitmask; 15 = full circle
Everything parsed out of an Autotrax/Easytrax file, before any KiCad object is created.
std::vector< COMPONENT > components
std::vector< NET_NODE > netNodes
std::vector< TRACK > tracks
std::vector< TEXT > texts
std::vector< FILL > fills
A placed component (COMP .. ENDCOMP) holding its own primitives.
std::vector< TRACK > tracks
std::vector< FILL > fills
std::vector< TEXT > texts
Free or component rectangular fill (FF / CF), Autotrax's only pour.
One refdes -> net membership row collected from the NETDEF section.
Free or component pad/pin (FP / CP).
int shape
1 round, 2 rect, 3 octagon, 4 round-rect
Free or component string (FS / CS).
int direction
0..3, multiplied by 90 degrees
Free or component track segment (FT / CT). All coordinates are in mils.
Free or component via (FV / CV).
IbisParser parser & reporter
VECTOR2< int32_t > VECTOR2I