35#include <idf_parser.h>
49#define LINE_WIDTH (pcbIUScale.mmToIU( 0.1 ))
61 double scale = aIDFBoard.GetUserScale();
66 std::list< IDF_SEGMENT* > lines;
67 IDF_OUTLINE* outline =
nullptr;
75 aIDFBoard.GetUserOffset( offX, offY );
96 IDF_SEGMENT* seg =
new IDF_SEGMENT( sp, ep );
99 lines.push_back( seg );
114 IDF_POINT corners[4];
115 corners[0] = IDF_POINT(
left, top );
116 corners[1] = IDF_POINT(
right, top );
117 corners[2] = IDF_POINT(
right, bottom );
118 corners[3] = IDF_POINT(
left, bottom );
120 lines.push_back(
new IDF_SEGMENT( corners[0], corners[1] ) );
121 lines.push_back(
new IDF_SEGMENT( corners[1], corners[2] ) );
122 lines.push_back(
new IDF_SEGMENT( corners[2], corners[3] ) );
123 lines.push_back(
new IDF_SEGMENT( corners[3], corners[0] ) );
139 lines.push_back( seg );
156 IDF_SEGMENT* seg =
new IDF_SEGMENT( sp, ep, 360.0,
true );
159 lines.push_back( seg );
179 outline =
new IDF_OUTLINE;
180 IDF3::GetOutline( lines, *outline );
182 if( outline->empty() )
185 aIDFBoard.AddBoardOutline( outline );
189 while( !lines.empty() )
192 outline =
new IDF_OUTLINE;
194 IDF3::GetOutline( lines, *outline );
196 if( outline->empty() )
202 aIDFBoard.AddBoardOutline( outline );
211 while( !lines.empty() )
213 delete lines.front();
220 outline =
new IDF_OUTLINE;
253 outline->push(
new IDF_SEGMENT( p1, p2 ) );
255 for(
int i = 1; i < 4; ++i )
262 outline->push(
new IDF_SEGMENT( p1, p2 ) );
265 aIDFBoard.AddBoardOutline( outline );
280 wxString footprintBasePath = wxEmptyString;
296 footprintBasePath = fpRow->
GetFullURI(
true );
299 if( crefdes.empty() || !crefdes.compare(
"~" ) )
305 if( cvalue.empty() || !cvalue.compare(
"~" ) )
308 crefdes =
"NOREFDES";
321 double scale = aIDFBoard.GetUserScale();
322 IDF3::KEY_PLATING kplate;
328 aIDFBoard.GetUserOffset( dx, dy );
330 for(
auto pad : aFootprint->
Pads() )
332 drill = (double)
pad->GetDrillSize().x *
scale;
333 x =
pad->GetPosition().x *
scale + dx;
334 y = -
pad->GetPosition().y *
scale + dy;
348 if( tstr.empty() || !tstr.compare(
"0" ) || !tstr.compare(
"~" )
349 || ( kplate == IDF3::NPTH )
364 && (
pad->GetDrillSize().x !=
pad->GetDrillSize().y ) )
370 double dlength =
pad->GetDrillSize().y *
scale;
375 double angle =
pad->GetOrientation().AsDegrees();
383 if( dlength < drill )
385 std::swap( drill, dlength );
396 aIDFBoard.AddSlot( drill, dlength,
angle, x, y );
400 IDF_DRILL_DATA *dp =
new IDF_DRILL_DATA( drill, x, y, kplate, crefdes,
401 pintype, IDF3::ECAD );
403 if( !aIDFBoard.AddDrill( dp ) )
407 std::ostringstream ostr;
408 ostr << __FILE__ <<
":" << __LINE__ <<
":" << __FUNCTION__;
409 ostr <<
"(): could not add drill";
411 throw std::runtime_error( ostr.str() );
420 IDF3_COMPONENT* comp =
nullptr;
422 auto sM = aFootprint->
Models().begin();
423 auto eM = aFootprint->
Models().end();
436 idfExt = idfFile.GetExt();
438 if( idfExt.Cmp( wxT(
"idf" ) ) && idfExt.Cmp( wxT(
"IDF" ) ) )
452 if( refdes.empty() || !refdes.compare(
"~" ) )
453 refdes = aIDFBoard.GetNewRefDes();
456 IDF3_COMP_OUTLINE* outline;
458 outline = aIDFBoard.GetComponentOutline( idfFile.GetFullPath() );
461 throw( std::runtime_error( aIDFBoard.GetError() ) );
464 double locx = sM->m_Offset.x * 25.4;
465 double locy = sM->m_Offset.y * 25.4;
466 double locz = sM->m_Offset.z * 25.4;
467 double lrot = sM->m_Rotation.z;
469 bool top = ( aFootprint->
GetLayer() ==
B_Cu ) ?
false :
true;
487 while( rotz >= 360.0 ) rotz -= 360.0;
490 while( rotz <= -360.0 ) rotz += 360.0;
493 if( comp ==
nullptr )
494 comp = aIDFBoard.FindComponent( refdes );
496 if( comp ==
nullptr )
498 comp =
new IDF3_COMPONENT( &aIDFBoard );
500 if( comp ==
nullptr )
501 throw( std::runtime_error( aIDFBoard.GetError() ) );
503 comp->SetRefDes( refdes );
509 rotz, IDF3::LYR_TOP );
515 rotz, IDF3::LYR_BOTTOM );
518 comp->SetPlacement( IDF3::PS_ECAD );
520 aIDFBoard.AddComponent( comp );
524 double refX, refY, refA;
525 IDF3::IDF_LAYER side;
527 if( ! comp->GetPosition( refX, refY, refA, side ) )
534 rotz, IDF3::LYR_TOP );
540 rotz, IDF3::LYR_BOTTOM );
543 comp->SetPlacement( IDF3::PS_ECAD );
559 if( ( top && side == IDF3::LYR_BOTTOM ) || ( !top && side == IDF3::LYR_TOP )
560 || ( refA > 0.0001 ) || ( refX > 0.0001 ) )
562 comp->GetPosition( refX, refY, refA, side );
564 std::ostringstream ostr;
565 ostr <<
"* " << __FILE__ <<
":" << __LINE__ <<
":" << __FUNCTION__ <<
"():\n";
566 ostr <<
"* conflicting Reference Designator '" << refdes <<
"'\n";
568 ostr <<
" vs. " << refX <<
"\n";
570 ostr <<
" vs. " << refY <<
"\n";
571 ostr <<
"* angle: " << rotz;
572 ostr <<
" vs. " << refA <<
"\n";
575 ostr <<
"* TOP vs. ";
577 ostr <<
"* BOTTOM vs. ";
579 if( side == IDF3::LYR_TOP )
584 throw( std::runtime_error( ostr.str() ) );
590 IDF3_COMP_OUTLINE_DATA* data =
new IDF3_COMP_OUTLINE_DATA( comp, outline );
592 data->SetOffsets( locx, locy, locz, lrot );
593 comp->AddOutlineData( data );
604 bool aUseThou,
double aXRef,
double aYRef )
606 IDF3_BOARD idfBoard( IDF3::CAD_ELEC );
611 resolver =
Prj().Get3DCacheManager()->GetResolver();
615 IDF3::IDF_UNIT idfUnit;
619 idfUnit = IDF3::UNIT_THOU;
620 idfBoard.SetUserPrecision( 1 );
625 idfBoard.SetUserPrecision( 5 );
630 idfBoard.SetUserScale(
scale );
632 idfBoard.SetBoardName(
TO_UTF8( brdName.GetFullName() ) );
633 idfBoard.SetBoardVersion( 0 );
634 idfBoard.SetLibraryVersion( 0 );
636 std::ostringstream ostr;
638 idfBoard.SetIDFSource( ostr.str() );
643 idfBoard.SetUserOffset( -aXRef, aYRef );
652 if( !idfBoard.WriteFile( aFullFileName, idfUnit,
false ) )
655 msg <<
_(
"IDF Export Failed:\n" ) <<
FROM_UTF8( idfBoard.GetError().c_str() );
664 msg <<
_(
"IDF Export Failed:\n" ) << ioe.
What();
669 catch(
const std::exception& e )
672 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...
virtual wxString GetShownText(int aDepth=0, bool aAllowExtraText=true) const override
Return the string actually shown after processing of the base text.
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()
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
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.
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.
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
@ 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