34#include <idf_parser.h>
49#define LINE_WIDTH (pcbIUScale.mmToIU( 0.1 ))
61 double scale = aIDFBoard.GetUserScale();
63 std::list< IDF_SEGMENT* > lines;
64 IDF_OUTLINE* outline =
nullptr;
72 aIDFBoard.GetUserOffset( offX, offY );
93 IDF_SEGMENT* seg =
new IDF_SEGMENT( sp, ep );
96 lines.push_back( seg );
111 IDF_POINT corners[4];
112 corners[0] = IDF_POINT(
left, top );
113 corners[1] = IDF_POINT(
right, top );
114 corners[2] = IDF_POINT(
right, bottom );
115 corners[3] = IDF_POINT(
left, bottom );
117 lines.push_back(
new IDF_SEGMENT( corners[0], corners[1] ) );
118 lines.push_back(
new IDF_SEGMENT( corners[1], corners[2] ) );
119 lines.push_back(
new IDF_SEGMENT( corners[2], corners[3] ) );
120 lines.push_back(
new IDF_SEGMENT( corners[3], corners[0] ) );
136 lines.push_back( seg );
153 IDF_SEGMENT* seg =
new IDF_SEGMENT( sp, ep, 360.0,
true );
156 lines.push_back( seg );
176 outline =
new IDF_OUTLINE;
177 IDF3::GetOutline( lines, *outline );
179 if( outline->empty() )
182 aIDFBoard.AddBoardOutline( outline );
186 while( !lines.empty() )
189 outline =
new IDF_OUTLINE;
191 IDF3::GetOutline( lines, *outline );
193 if( outline->empty() )
199 aIDFBoard.AddBoardOutline( outline );
208 while( !lines.empty() )
210 delete lines.front();
217 outline =
new IDF_OUTLINE;
250 outline->push(
new IDF_SEGMENT( p1, p2 ) );
252 for(
int i = 1; i < 4; ++i )
259 outline->push(
new IDF_SEGMENT( p1, p2 ) );
262 aIDFBoard.AddBoardOutline( outline );
277 wxString footprintBasePath = wxEmptyString;
293 footprintBasePath = fpRow->
GetFullURI(
true );
296 if( crefdes.empty() || !crefdes.compare(
"~" ) )
302 if( cvalue.empty() || !cvalue.compare(
"~" ) )
305 crefdes =
"NOREFDES";
318 double scale = aIDFBoard.GetUserScale();
319 IDF3::KEY_PLATING kplate;
325 aIDFBoard.GetUserOffset( dx, dy );
327 for(
auto pad : aFootprint->
Pads() )
329 drill = (double)
pad->GetDrillSize().x *
scale;
330 x =
pad->GetPosition().x *
scale + dx;
331 y = -
pad->GetPosition().y *
scale + dy;
345 if( tstr.empty() || !tstr.compare(
"0" ) || !tstr.compare(
"~" )
346 || ( kplate == IDF3::NPTH )
361 && (
pad->GetDrillSize().x !=
pad->GetDrillSize().y ) )
367 double dlength =
pad->GetDrillSize().y *
scale;
372 double angle =
pad->GetOrientation().AsDegrees();
380 if( dlength < drill )
382 std::swap( drill, dlength );
393 aIDFBoard.AddSlot( drill, dlength, angle, x, y );
397 IDF_DRILL_DATA *dp =
new IDF_DRILL_DATA( drill, x, y, kplate, crefdes,
398 pintype, IDF3::ECAD );
400 if( !aIDFBoard.AddDrill( dp ) )
404 std::ostringstream ostr;
405 ostr << __FILE__ <<
":" << __LINE__ <<
":" << __FUNCTION__;
406 ostr <<
"(): could not add drill";
408 throw std::runtime_error( ostr.str() );
417 IDF3_COMPONENT* comp =
nullptr;
419 auto sM = aFootprint->
Models().begin();
420 auto eM = aFootprint->
Models().end();
433 idfExt = idfFile.GetExt();
435 if( idfExt.Cmp( wxT(
"idf" ) ) && idfExt.Cmp( wxT(
"IDF" ) ) )
449 if( refdes.empty() || !refdes.compare(
"~" ) )
450 refdes = aIDFBoard.GetNewRefDes();
453 IDF3_COMP_OUTLINE* outline;
455 outline = aIDFBoard.GetComponentOutline( idfFile.GetFullPath() );
458 throw( std::runtime_error( aIDFBoard.GetError() ) );
461 double locx = sM->m_Offset.x * 25.4;
462 double locy = sM->m_Offset.y * 25.4;
463 double locz = sM->m_Offset.z * 25.4;
464 double lrot = sM->m_Rotation.z;
466 bool top = ( aFootprint->
GetLayer() ==
B_Cu ) ?
false :
true;
484 while( rotz >= 360.0 ) rotz -= 360.0;
487 while( rotz <= -360.0 ) rotz += 360.0;
490 if( comp ==
nullptr )
491 comp = aIDFBoard.FindComponent( refdes );
493 if( comp ==
nullptr )
495 comp =
new IDF3_COMPONENT( &aIDFBoard );
497 if( comp ==
nullptr )
498 throw( std::runtime_error( aIDFBoard.GetError() ) );
500 comp->SetRefDes( refdes );
506 rotz, IDF3::LYR_TOP );
512 rotz, IDF3::LYR_BOTTOM );
515 comp->SetPlacement( IDF3::PS_ECAD );
517 aIDFBoard.AddComponent( comp );
521 double refX, refY, refA;
522 IDF3::IDF_LAYER side;
524 if( ! comp->GetPosition( refX, refY, refA, side ) )
531 rotz, IDF3::LYR_TOP );
537 rotz, IDF3::LYR_BOTTOM );
540 comp->SetPlacement( IDF3::PS_ECAD );
556 if( ( top && side == IDF3::LYR_BOTTOM ) || ( !top && side == IDF3::LYR_TOP )
557 || ( refA > 0.0001 ) || ( refX > 0.0001 ) )
559 comp->GetPosition( refX, refY, refA, side );
561 std::ostringstream ostr;
562 ostr <<
"* " << __FILE__ <<
":" << __LINE__ <<
":" << __FUNCTION__ <<
"():\n";
563 ostr <<
"* conflicting Reference Designator '" << refdes <<
"'\n";
565 ostr <<
" vs. " << refX <<
"\n";
567 ostr <<
" vs. " << refY <<
"\n";
568 ostr <<
"* angle: " << rotz;
569 ostr <<
" vs. " << refA <<
"\n";
572 ostr <<
"* TOP vs. ";
574 ostr <<
"* BOTTOM vs. ";
576 if( side == IDF3::LYR_TOP )
581 throw( std::runtime_error( ostr.str() ) );
587 IDF3_COMP_OUTLINE_DATA* data =
new IDF3_COMP_OUTLINE_DATA( comp, outline );
589 data->SetOffsets( locx, locy, locz, lrot );
590 comp->AddOutlineData( data );
601 bool aUseThou,
double aXRef,
double aYRef )
603 IDF3_BOARD idfBoard( IDF3::CAD_ELEC );
608 resolver =
Prj().Get3DCacheManager()->GetResolver();
612 IDF3::IDF_UNIT idfUnit;
616 idfUnit = IDF3::UNIT_THOU;
617 idfBoard.SetUserPrecision( 1 );
621 idfUnit = IDF3::UNIT_MM;
622 idfBoard.SetUserPrecision( 5 );
627 idfBoard.SetUserScale(
scale );
629 idfBoard.SetBoardName(
TO_UTF8( brdName.GetFullName() ) );
630 idfBoard.SetBoardVersion( 0 );
631 idfBoard.SetLibraryVersion( 0 );
633 std::ostringstream ostr;
635 idfBoard.SetIDFSource( ostr.str() );
640 idfBoard.SetUserOffset( -aXRef, aYRef );
649 if( !idfBoard.WriteFile( aFullFileName, idfUnit,
false ) )
652 msg <<
_(
"IDF Export Failed:\n" ) <<
FROM_UTF8( idfBoard.GetError().c_str() );
661 msg <<
_(
"IDF Export Failed:\n" ) << ioe.
What();
666 catch(
const std::exception& e )
669 msg <<
_(
"IDF Export Failed:\n" ) <<
FROM_UTF8( e.what() );
constexpr EDA_IU_SCALE pcbIUScale
wxString GetBuildVersion()
Get the full KiCad version string.
int GetBoardThickness() const
The full thickness of the board including copper and masks.
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.
const BOX2I GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
FOOTPRINTS & Footprints()
const wxString & GetFileName() const
PROJECT * GetProject() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
const Vec & GetOrigin() const
const Vec & GetSize() const
EDA_ANGLE GetArcAngle() const
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Provide an extensible class to resolve 3D model paths.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath)
Determines the full path of the given file name.
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fall back table frag...
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()
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
bool Export_IDF3(BOARD *aPcb, const wxString &aFullFileName, bool aUseThou, double aXRef, double aYRef)
Create an IDF3 compliant BOARD (*.emn) and LIBRARY (*.emp) file.
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
static void idf_export_outline(BOARD *aPcb, IDF3_BOARD &aIDFBoard)
Retrieve line segment information from the edge layer and compiles the data into a form which can be ...
static void idf_export_footprint(BOARD *aPcb, FOOTPRINT *aFootprint, IDF3_BOARD &aIDFBoard)
Retrieve information from all board footprints, adds drill holes to the DRILLED_HOLES or BOARD_OUTLIN...
static FILENAME_RESOLVER * resolver
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.
@ NPTH
like PAD_PTH, but not plated
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers