38 #include <idf_parser.h> 41 #include <wx/msgdlg.h> 48 #define PCBNEW // needed to define the right value of Millimeter2iu(x) 54 #define LINE_WIDTH (Millimeter2iu( 0.1 )) 66 double scale = aIDFBoard.GetUserScale();
71 std::list< IDF_SEGMENT* > lines;
72 IDF_OUTLINE* outline =
nullptr;
80 aIDFBoard.GetUserOffset( offX, offY );
101 IDF_SEGMENT* seg =
new IDF_SEGMENT( sp, ep );
104 lines.push_back( seg );
116 double bottom = graphic->
GetEnd().y *
scale + offY;
119 IDF_POINT corners[4];
120 corners[0] = IDF_POINT(
left, top );
121 corners[1] = IDF_POINT(
right, top );
122 corners[2] = IDF_POINT(
right, bottom );
123 corners[3] = IDF_POINT(
left, bottom );
125 lines.push_back(
new IDF_SEGMENT( corners[0], corners[1] ) );
126 lines.push_back(
new IDF_SEGMENT( corners[1], corners[2] ) );
127 lines.push_back(
new IDF_SEGMENT( corners[2], corners[3] ) );
128 lines.push_back(
new IDF_SEGMENT( corners[3], corners[0] ) );
141 IDF_SEGMENT* seg =
new IDF_SEGMENT( sp, ep, -graphic->
GetArcAngle() / 10.0, true );
144 lines.push_back( seg );
161 IDF_SEGMENT* seg =
new IDF_SEGMENT( sp, ep, 360.0,
true );
164 lines.push_back( seg );
184 outline =
new IDF_OUTLINE;
185 IDF3::GetOutline( lines, *outline );
187 if( outline->empty() )
190 aIDFBoard.AddBoardOutline( outline );
194 while( !lines.empty() )
197 outline =
new IDF_OUTLINE;
199 IDF3::GetOutline( lines, *outline );
201 if( outline->empty() )
207 aIDFBoard.AddBoardOutline( outline );
216 while( !lines.empty() )
218 delete lines.front();
225 outline =
new IDF_OUTLINE;
258 outline->push(
new IDF_SEGMENT( p1, p2 ) );
260 for(
int i = 1; i < 4; ++i )
267 outline->push(
new IDF_SEGMENT( p1, p2 ) );
270 aIDFBoard.AddBoardOutline( outline );
284 if( crefdes.empty() || !crefdes.compare(
"~" ) )
290 if( cvalue.empty() || !cvalue.compare(
"~" ) )
293 crefdes =
"NOREFDES";
306 double scale = aIDFBoard.GetUserScale();
307 IDF3::KEY_PLATING kplate;
313 aIDFBoard.GetUserOffset( dx, dy );
315 for(
auto pad : aFootprint->
Pads() )
317 drill = (double)
pad->GetDrillSize().x *
scale;
318 x =
pad->GetPosition().x *
scale + dx;
319 y = -
pad->GetPosition().y *
scale + dy;
333 if( tstr.empty() || !tstr.compare(
"0" ) || !tstr.compare(
"~" )
334 || ( kplate == IDF3::NPTH )
349 && (
pad->GetDrillSize().x !=
pad->GetDrillSize().y ) )
355 double dlength =
pad->GetDrillSize().y *
scale;
360 double angle =
pad->GetOrientation() / 10.0;
368 if( dlength < drill )
370 std::swap( drill, dlength );
381 aIDFBoard.AddSlot( drill, dlength,
angle, x, y );
385 IDF_DRILL_DATA *dp =
new IDF_DRILL_DATA( drill, x, y, kplate, crefdes,
386 pintype, IDF3::ECAD );
388 if( !aIDFBoard.AddDrill( dp ) )
392 std::ostringstream ostr;
393 ostr << __FILE__ <<
":" << __LINE__ <<
":" << __FUNCTION__;
394 ostr <<
"(): could not add drill";
396 throw std::runtime_error( ostr.str() );
405 IDF3_COMPONENT* comp =
nullptr;
407 auto sM = aFootprint->
Models().begin();
408 auto eM = aFootprint->
Models().end();
421 idfExt = idfFile.GetExt();
423 if( idfExt.Cmp( wxT(
"idf" ) ) && idfExt.Cmp( wxT(
"IDF" ) ) )
437 if( refdes.empty() || !refdes.compare(
"~" ) )
438 refdes = aIDFBoard.GetNewRefDes();
441 IDF3_COMP_OUTLINE* outline;
443 outline = aIDFBoard.GetComponentOutline( idfFile.GetFullPath() );
446 throw( std::runtime_error( aIDFBoard.GetError() ) );
449 double locx = sM->m_Offset.x * 25.4;
450 double locy = sM->m_Offset.y * 25.4;
451 double locz = sM->m_Offset.z * 25.4;
452 double lrot = sM->m_Rotation.z;
454 bool top = ( aFootprint->
GetLayer() ==
B_Cu ) ?
false :
true;
472 while( rotz >= 360.0 ) rotz -= 360.0;
475 while( rotz <= -360.0 ) rotz += 360.0;
478 if( comp ==
nullptr )
479 comp = aIDFBoard.FindComponent( refdes );
481 if( comp ==
nullptr )
483 comp =
new IDF3_COMPONENT( &aIDFBoard );
485 if( comp ==
nullptr )
486 throw( std::runtime_error( aIDFBoard.GetError() ) );
488 comp->SetRefDes( refdes );
494 rotz, IDF3::LYR_TOP );
500 rotz, IDF3::LYR_BOTTOM );
503 comp->SetPlacement( IDF3::PS_ECAD );
505 aIDFBoard.AddComponent( comp );
509 double refX, refY, refA;
510 IDF3::IDF_LAYER side;
512 if( ! comp->GetPosition( refX, refY, refA, side ) )
519 rotz, IDF3::LYR_TOP );
525 rotz, IDF3::LYR_BOTTOM );
528 comp->SetPlacement( IDF3::PS_ECAD );
544 if( ( top && side == IDF3::LYR_BOTTOM ) || ( !top && side == IDF3::LYR_TOP )
545 || ( refA > 0.0001 ) || ( refX > 0.0001 ) )
547 comp->GetPosition( refX, refY, refA, side );
549 std::ostringstream ostr;
550 ostr <<
"* " << __FILE__ <<
":" << __LINE__ <<
":" << __FUNCTION__ <<
"():\n";
551 ostr <<
"* conflicting Reference Designator '" << refdes <<
"'\n";
553 ostr <<
" vs. " << refX <<
"\n";
555 ostr <<
" vs. " << refY <<
"\n";
556 ostr <<
"* angle: " << rotz;
557 ostr <<
" vs. " << refA <<
"\n";
560 ostr <<
"* TOP vs. ";
562 ostr <<
"* BOTTOM vs. ";
564 if( side == IDF3::LYR_TOP )
569 throw( std::runtime_error( ostr.str() ) );
575 IDF3_COMP_OUTLINE_DATA* data =
new IDF3_COMP_OUTLINE_DATA( comp, outline );
577 data->SetOffsets( locx, locy, locz, lrot );
578 comp->AddOutlineData( data );
589 bool aUseThou,
double aXRef,
double aYRef )
591 IDF3_BOARD idfBoard( IDF3::CAD_ELEC );
596 resolver =
Prj().Get3DCacheManager()->GetResolver();
599 double scale = MM_PER_IU;
600 IDF3::IDF_UNIT idfUnit;
604 idfUnit = IDF3::UNIT_THOU;
605 idfBoard.SetUserPrecision( 1 );
610 idfBoard.SetUserPrecision( 5 );
615 idfBoard.SetUserScale(
scale );
617 idfBoard.SetBoardName(
TO_UTF8( brdName.GetFullName() ) );
618 idfBoard.SetBoardVersion( 0 );
619 idfBoard.SetLibraryVersion( 0 );
621 std::ostringstream ostr;
623 idfBoard.SetIDFSource( ostr.str() );
628 idfBoard.SetUserOffset( -aXRef, aYRef );
637 if( !idfBoard.WriteFile( aFullFileName, idfUnit,
false ) )
640 msg <<
_(
"IDF Export Failed:\n" ) <<
FROM_UTF8( idfBoard.GetError().c_str() );
649 msg <<
_(
"IDF Export Failed:\n" ) << ioe.
What();
654 catch(
const std::exception& e )
657 msg <<
_(
"IDF Export Failed:\n" ) <<
FROM_UTF8( e.what() );
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
const wxPoint & GetStart() const
Return the starting point of the graphic.
const EDA_RECT GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
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 ...
bool Export_IDF3(BOARD *aPcb, const wxString &aFullFileName, bool aUseThou, double aXRef, double aYRef)
Create an IDF3 compliant BOARD (*.emn) and LIBRARY (*.emp) file.
double GetArcAngle() const
int GetBoardThickness() const
void RotatePoint(int *pX, int *pY, double angle)
const wxString & GetFileName() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
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.
like PAD_PTH, but not plated
const wxPoint & GetEnd() const
Return the ending point of the graphic.
virtual const wxString What() const
A composite of Problem() and Where()
wxString GetBuildVersion()
Get the full KiCad version string.
const wxPoint GetOrigin() const
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
FOOTPRINTS & Footprints()
wxPoint GetCenter() const override
This defaults to the center of the bounding box if not overridden.
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...
wxString ResolvePath(const wxString &aFileName)
Determines the full path of the given file name.
Provide an extensible class to resolve 3D model paths.
Information pertinent to a Pcbnew printed circuit board.
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
Handle the component boundary box.
static FILENAME_RESOLVER * resolver
virtual wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
class PCB_SHAPE, a segment not on copper layers
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
const wxSize GetSize() const