34#include <idf_parser.h>
50#define LINE_WIDTH (pcbIUScale.mmToIU( 0.1 ))
62 double scale = aIDFBoard.GetUserScale();
64 std::list< IDF_SEGMENT* > lines;
65 IDF_OUTLINE* outline =
nullptr;
73 aIDFBoard.GetUserOffset( offX, offY );
94 IDF_SEGMENT* seg =
new IDF_SEGMENT( sp, ep );
97 lines.push_back( seg );
112 IDF_POINT corners[4];
113 corners[0] = IDF_POINT(
left, top );
114 corners[1] = IDF_POINT(
right, top );
115 corners[2] = IDF_POINT(
right, bottom );
116 corners[3] = IDF_POINT(
left, bottom );
118 lines.push_back(
new IDF_SEGMENT( corners[0], corners[1] ) );
119 lines.push_back(
new IDF_SEGMENT( corners[1], corners[2] ) );
120 lines.push_back(
new IDF_SEGMENT( corners[2], corners[3] ) );
121 lines.push_back(
new IDF_SEGMENT( corners[3], corners[0] ) );
137 lines.push_back( seg );
154 IDF_SEGMENT* seg =
new IDF_SEGMENT( sp, ep, 360.0,
true );
157 lines.push_back( seg );
177 outline =
new IDF_OUTLINE;
178 IDF3::GetOutline( lines, *outline );
180 if( outline->empty() )
183 aIDFBoard.AddBoardOutline( outline );
187 while( !lines.empty() )
190 outline =
new IDF_OUTLINE;
192 IDF3::GetOutline( lines, *outline );
194 if( outline->empty() )
200 aIDFBoard.AddBoardOutline( outline );
209 while( !lines.empty() )
211 delete lines.front();
218 outline =
new IDF_OUTLINE;
251 outline->push(
new IDF_SEGMENT( p1, p2 ) );
253 for(
int i = 1; i < 4; ++i )
260 outline->push(
new IDF_SEGMENT( p1, p2 ) );
263 aIDFBoard.AddBoardOutline( outline );
273 bool aIncludeUnspecified,
bool aIncludeDNP )
279 wxString footprintBasePath = wxEmptyString;
295 footprintBasePath = fpRow->
GetFullURI(
true );
298 if( crefdes.empty() || !crefdes.compare(
"~" ) )
304 if( cvalue.empty() || !cvalue.compare(
"~" ) )
307 crefdes =
"NOREFDES";
320 double scale = aIDFBoard.GetUserScale();
321 IDF3::KEY_PLATING kplate;
327 aIDFBoard.GetUserOffset( dx, dy );
329 for(
auto pad : aFootprint->
Pads() )
331 drill = (double)
pad->GetDrillSize().x *
scale;
332 x =
pad->GetPosition().x *
scale + dx;
333 y = -
pad->GetPosition().y *
scale + dy;
347 if( tstr.empty() || !tstr.compare(
"0" ) || !tstr.compare(
"~" )
348 || ( kplate == IDF3::NPTH )
363 && (
pad->GetDrillSize().x !=
pad->GetDrillSize().y ) )
369 double dlength =
pad->GetDrillSize().y *
scale;
374 double angle =
pad->GetOrientation().AsDegrees();
382 if( dlength < drill )
384 std::swap( drill, dlength );
395 aIDFBoard.AddSlot( drill, dlength, angle, x, y );
399 IDF_DRILL_DATA *dp =
new IDF_DRILL_DATA( drill, x, y, kplate, crefdes,
400 pintype, IDF3::ECAD );
402 if( !aIDFBoard.AddDrill( dp ) )
406 std::ostringstream ostr;
407 ostr << __FILE__ <<
":" << __LINE__ <<
":" << __FUNCTION__;
408 ostr <<
"(): could not add drill";
410 throw std::runtime_error( ostr.str() );
419 if( aFootprint->
IsDNP() && !aIncludeDNP )
425 IDF3_COMPONENT* comp =
nullptr;
427 auto sM = aFootprint->
Models().begin();
428 auto eM = aFootprint->
Models().end();
441 idfExt = idfFile.GetExt();
443 if( idfExt.Cmp( wxT(
"idf" ) ) && idfExt.Cmp( wxT(
"IDF" ) ) )
457 if( refdes.empty() || !refdes.compare(
"~" ) )
458 refdes = aIDFBoard.GetNewRefDes();
461 IDF3_COMP_OUTLINE* outline;
463 outline = aIDFBoard.GetComponentOutline( idfFile.GetFullPath() );
466 throw( std::runtime_error( aIDFBoard.GetError() ) );
469 double locx = sM->m_Offset.x;
470 double locy = sM->m_Offset.y;
471 double locz = sM->m_Offset.z;
472 double lrot = sM->m_Rotation.z;
474 bool top = ( aFootprint->
GetLayer() ==
B_Cu ) ?
false :
true;
492 while( rotz >= 360.0 ) rotz -= 360.0;
495 while( rotz <= -360.0 ) rotz += 360.0;
498 if( comp ==
nullptr )
499 comp = aIDFBoard.FindComponent( refdes );
501 if( comp ==
nullptr )
503 comp =
new IDF3_COMPONENT( &aIDFBoard );
505 if( comp ==
nullptr )
506 throw( std::runtime_error( aIDFBoard.GetError() ) );
508 comp->SetRefDes( refdes );
514 rotz, IDF3::LYR_TOP );
520 rotz, IDF3::LYR_BOTTOM );
523 comp->SetPlacement( IDF3::PS_ECAD );
525 aIDFBoard.AddComponent( comp );
529 double refX, refY, refA;
530 IDF3::IDF_LAYER side;
532 if( ! comp->GetPosition( refX, refY, refA, side ) )
539 rotz, IDF3::LYR_TOP );
545 rotz, IDF3::LYR_BOTTOM );
548 comp->SetPlacement( IDF3::PS_ECAD );
564 if( ( top && side == IDF3::LYR_BOTTOM ) || ( !top && side == IDF3::LYR_TOP )
565 || ( refA > 0.0001 ) || ( refX > 0.0001 ) )
567 comp->GetPosition( refX, refY, refA, side );
569 std::ostringstream ostr;
570 ostr <<
"* " << __FILE__ <<
":" << __LINE__ <<
":" << __FUNCTION__ <<
"():\n";
571 ostr <<
"* conflicting Reference Designator '" << refdes <<
"'\n";
573 ostr <<
" vs. " << refX <<
"\n";
575 ostr <<
" vs. " << refY <<
"\n";
576 ostr <<
"* angle: " << rotz;
577 ostr <<
" vs. " << refA <<
"\n";
580 ostr <<
"* TOP vs. ";
582 ostr <<
"* BOTTOM vs. ";
584 if( side == IDF3::LYR_TOP )
589 throw( std::runtime_error( ostr.str() ) );
595 IDF3_COMP_OUTLINE_DATA* data =
new IDF3_COMP_OUTLINE_DATA( comp, outline );
597 data->SetOffsets( locx, locy, locz, lrot );
598 comp->AddOutlineData( data );
609 bool aUseThou,
double aXRef,
double aYRef,
610 bool aIncludeUnspecified,
bool aIncludeDNP )
612 IDF3_BOARD idfBoard( IDF3::CAD_ELEC );
621 IDF3::IDF_UNIT idfUnit;
625 idfUnit = IDF3::UNIT_THOU;
626 idfBoard.SetUserPrecision( 1 );
630 idfUnit = IDF3::UNIT_MM;
631 idfBoard.SetUserPrecision( 5 );
636 idfBoard.SetUserScale(
scale );
638 idfBoard.SetBoardName(
TO_UTF8( brdName.GetFullName() ) );
639 idfBoard.SetBoardVersion( 0 );
640 idfBoard.SetLibraryVersion( 0 );
642 std::ostringstream ostr;
644 idfBoard.SetIDFSource( ostr.str() );
649 idfBoard.SetUserOffset( -aXRef, aYRef );
658 if( !idfBoard.WriteFile( aFullFileName, idfUnit,
false ) )
661 msg <<
_(
"IDF Export Failed:\n" ) <<
From_UTF8( idfBoard.GetError().c_str() );
670 msg <<
_(
"IDF Export Failed:\n" ) << ioe.
What();
675 catch(
const std::exception& e )
678 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....
const FOOTPRINTS & Footprints() const
const wxString & GetFileName() const
PROJECT * GetProject() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
const DRAWINGS & Drawings() const
constexpr const Vec & GetOrigin() const
constexpr const SizeVec & 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, const EMBEDDED_FILES *aFiles)
Determines the full path of the given file name.
Hold a record identifying a library accessed by the appropriate footprint library #PLUGIN object in t...
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, bool aIncludeUnspecified, bool aIncludeDNP)
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.
static FP_LIB_TABLE * PcbFootprintLibs(PROJECT *aProject)
Return the table of footprint libraries without Kiway.
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
FILENAME_RESOLVER * GetResolver() noexcept
@ ARC
use RECTANGLE instead of RECT to avoid collision in a Windows header
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 FILENAME_RESOLVER * resolver
static void idf_export_footprint(BOARD *aPcb, FOOTPRINT *aFootprint, IDF3_BOARD &aIDFBoard, bool aIncludeUnspecified, bool aIncludeDNP)
Retrieve information from all board footprints, adds drill holes to the DRILLED_HOLES or BOARD_OUTLIN...
This file contains miscellaneous commonly used macros and functions.
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
wxString From_UTF8(const char *cstring)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
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_SHAPE_T
class PCB_SHAPE, a segment not on copper layers