69 PCB_IO( wxS(
"Protel Autotrax" ) )
85static bool readFile(
const wxString& aFileName, wxString& aOut,
size_t aLimit = 0 )
87 std::ifstream file( aFileName.fn_str(), std::ios::binary );
97 file.read( raw.data(), aLimit );
98 raw.resize(
static_cast<size_t>( file.gcount() ) );
102 std::ostringstream ss;
107 aOut = wxString::FromUTF8( raw.data(), raw.size() );
109 if( aOut.IsEmpty() && !raw.empty() )
110 aOut = wxString::From8BitData( raw.data(), raw.size() );
125 if( !
readFile( aFileName, contents, 4096 ) )
133 const std::map<std::string, UTF8>* aProperties,
PROJECT* aProject )
140 std::unique_ptr<BOARD> boardDeleter( aAppendToMe ?
nullptr :
m_board );
146 m_board->SetFileName( aFileName );
150 if( !
readFile( aFileName, contents ) )
151 THROW_IO_ERROR( wxString::Format(
_(
"Could not read file '%s'." ), aFileName ) );
158 if( !parser.
Parse( contents, data ) )
159 THROW_IO_ERROR( wxString::Format(
_(
"'%s' is not a valid Protel Autotrax file." ), aFileName ) );
163 boardDeleter.release();
195 if( aNetName.IsEmpty() )
198 auto it =
m_nets.find( aNetName );
207 m_nets[aNetName] = existing;
227 aFootprint->
Add( aItem );
249 case 1:
return { { 90.0, 90.0 } };
250 case 2:
return { { 0.0, 90.0 } };
251 case 4:
return { { 270.0, 90.0 } };
252 case 8:
return { { 180.0, 90.0 } };
253 case 3:
return { { 0.0, 180.0 } };
254 case 6:
return { { 270.0, 180.0 } };
255 case 12:
return { { 180.0, 180.0 } };
256 case 9:
return { { 90.0, 180.0 } };
257 case 14:
return { { 180.0, 270.0 } };
258 case 13:
return { { 90.0, 270.0 } };
259 case 11:
return { { 0.0, 270.0 } };
260 case 7:
return { { 270.0, 270.0 } };
261 case 5:
return { { 270.0, 90.0 }, { 90.0, 90.0 } };
262 case 10:
return { { 180.0, 90.0 }, { 0.0, 90.0 } };
263 default:
return { { 0.0, 360.0 } };
306 int width = std::max( 1,
toIU( aArc.
width ) );
311 auto pointAt = [&](
double aDeg )
313 double rad = aDeg *
M_PI / 180.0;
323 if( span.deltaDeg >= 360.0 )
332 shape->
SetArcGeometry( pointAt( span.startDeg ), pointAt( span.startDeg + span.deltaDeg / 2.0 ),
333 pointAt( span.startDeg + span.deltaDeg ) );
343 int drill = std::max( 1,
toIU( aVia.
drill ) );
344 int diameter = std::max( drill + 2,
toIU( aVia.
diameter ) );
364 via->SetDrill( drill );
394 bool standalone =
false;
444 pad->SetLayerSet( smdMask );
464 int minX = std::min( p1.
x, p2.
x );
465 int maxX = std::max( p1.
x, p2.
x );
466 int minY = std::min( p1.
y, p2.
y );
467 int maxY = std::max( p1.
y, p2.
y );
509 text->SetLayer( layer );
512 int height = std::max( 1,
toIU( aText.
height ) );
514 text->SetTextThickness( std::max( 1,
toIU( aText.
width ) ) );
521 text->SetMirrored(
true );
532 if( !aComp.
refdes.IsEmpty() )
535 if( !aComp.
value.IsEmpty() )
538 if( !aComp.
name.IsEmpty() )
544 for(
const ARC& a : aComp.
arcs )
547 for(
const VIA& v : aComp.
vias )
577 double maxYmils = 0.0;
579 auto noteLayer = [&](
int aLayer )
595 auto scan = [&](
const auto& aContainer )
597 for(
const TRACK& t : aContainer.tracks )
599 noteLayer( t.
layer );
600 maxYmils = std::max( { maxYmils, t.
y1, t.
y2 } );
603 for(
const ARC& a : aContainer.arcs )
605 noteLayer( a.
layer );
609 for(
const VIA& v : aContainer.vias )
610 maxYmils = std::max( maxYmils, v.
y );
614 noteLayer( p.
layer );
615 maxYmils = std::max( maxYmils, p.
y );
618 for(
const FILL& f : aContainer.fills )
620 noteLayer( f.
layer );
621 maxYmils = std::max( { maxYmils, f.
y1, f.
y2 } );
624 for(
const TEXT& s : aContainer.texts )
625 maxYmils = std::max( maxYmils, s.
y );
633 m_board->SetCopperLayerCount( 2 + innerNeeded );
643 for(
const ARC& a : aData.
arcs )
646 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)
void SetStart(const VECTOR2I &aStart)
void SetShape(SHAPE_T aShape)
void SetEnd(const VECTOR2I &aEnd)
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
void SetWidth(int aWidth)
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()
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
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
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
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 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 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.
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_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:
@ 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