50#define LINE_WIDTH (pcbIUScale.mmToIU( 0.1 ))
74 std::list<IDF_SEGMENT*>& aLines )
85 sp.
x = aGraphic->
GetStart().
x * aScale + aOffX;
86 sp.
y = -aGraphic->
GetStart().
y * aScale + aOffY;
87 ep.
x = aGraphic->
GetEnd().
x * aScale + aOffX;
88 ep.
y = -aGraphic->
GetEnd().
y * aScale + aOffY;
102 double bottom = -aGraphic->
GetEnd().
y * aScale + aOffY;
111 aLines.push_back(
new IDF_SEGMENT( corners[0], corners[1] ) );
112 aLines.push_back(
new IDF_SEGMENT( corners[1], corners[2] ) );
113 aLines.push_back(
new IDF_SEGMENT( corners[2], corners[3] ) );
114 aLines.push_back(
new IDF_SEGMENT( corners[3], corners[0] ) );
125 ep.
x = aGraphic->
GetStart().
x * aScale + aOffX;
126 ep.
y = -aGraphic->
GetStart().
y * aScale + aOffY;
144 aLines.push_back(
new IDF_SEGMENT( sp, ep, 360.0,
true ) );
161 for(
int jj = 0; jj <
chain.PointCount(); ++jj )
169 sp.
x = start.
x * aScale + aOffX;
170 sp.
y = -start.
y * aScale + aOffY;
171 ep.
x =
end.x * aScale + aOffX;
172 ep.
y = -
end.y * aScale + aOffY;
186 for(
size_t ii = 1; ii < pts.size(); ++ii )
188 if( pts[ii - 1] == pts[ii] )
191 sp.
x = pts[ii - 1].x * aScale + aOffX;
192 sp.
y = -pts[ii - 1].y * aScale + aOffY;
193 ep.
x = pts[ii].x * aScale + aOffX;
194 ep.
y = -pts[ii].y * aScale + aOffY;
214 std::list< IDF_SEGMENT* > lines;
245 if( outline->
empty() )
252 while( !lines.empty() )
259 if( outline->
empty() )
277 while( !lines.empty() )
279 delete lines.front();
321 for(
int i = 1; i < 4; ++i )
342 SFVEC3F( aRotation.
x, aRotation.
y, aRotation.
z ),
344 const SFVEC3F zRow( modelMatrix[0].z, modelMatrix[1].z, modelMatrix[2].z );
348 for(
unsigned int meshIdx = 0; meshIdx < aModel.
m_MeshesSize; ++meshIdx )
355 for(
unsigned int vtx = 0; vtx < mesh.
m_VertexSize; ++vtx )
358 ret = std::max( ret, glm::dot( zRow, pos ) );
369 wxString footprintBasePath = wxEmptyString;
373 std::optional<LIBRARY_TABLE_ROW*> fpRow =
387 auto sM = aFootprint->
Models().begin();
388 auto eM = aFootprint->
Models().end();
400 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
402 embeddedFilesStack.push_back(
m_board->GetEmbeddedFiles() );
404 idfFile.Assign(
m_resolver->ResolvePath( sM->m_Filename, footprintBasePath, std::move( embeddedFilesStack ) ) );
405 idfExt = idfFile.GetExt();
407 if( idfExt.Cmp( wxT(
"idf" ) ) && idfExt.Cmp( wxT(
"IDF" ) ) )
421 if( refdes.empty() || !refdes.compare(
"~" ) )
431 m_reporter->Report( wxString::Format(
"Error exporting footprint %s model %s",
440 double locx = sM->m_Offset.x;
441 double locy = sM->m_Offset.y;
442 double locz = sM->m_Offset.z;
443 double lrot = sM->m_Rotation.z;
463 while( rotz >= 360.0 ) rotz -= 360.0;
466 while( rotz <= -360.0 ) rotz += 360.0;
469 if(
comp ==
nullptr )
472 if(
comp ==
nullptr )
476 comp->SetRefDes( refdes );
497 double refX, refY, refA;
500 if( !
comp->GetPosition( refX, refY, refA, side ) )
533 || ( refA > 0.0001 ) || ( refX > 0.0001 ) )
538 wxString::Format(
"Error exporting footprint %s: duplicate reference designator",
552 comp->AddOutlineData( data );
558 m_reporter->Report( wxString::Format(
_(
"Exported IDF model for footprint %s" ), aFootprint->
GetReference() ),
562 return comp !=
nullptr;
575 m_reporter->Report( wxString::Format(
_(
"Could not generate extruded body for %s" ),
592 if(
chain.PointCount() < 3 )
596 m_reporter->Report( wxString::Format(
_(
"Could not generate extruded body for %s" ),
607 std::list<IDF_SEGMENT*> lines;
609 for(
int ii = 0; ii <
chain.PointCount(); ++ii )
626 while( !lines.empty() )
628 delete lines.front();
636 field = &aFootprint->
Value();
645 m_reporter->Report( wxString::Format(
_(
"Could not generate extruded body for %s" ),
659 if( idfOutline->
empty() )
685 m_reporter->Report( wxString::Format(
_(
"Could not generate extruded body for %s" ),
708 wxString footprintBasePath = wxEmptyString;
720 if( !fpModel.m_Show || fpModel.m_Filename.empty() )
723 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
725 embeddedFilesStack.push_back(
m_board->GetEmbeddedFiles() );
727 wxString modelPath =
m_resolver->ResolvePath( fpModel.m_Filename, footprintBasePath,
728 std::move( embeddedFilesStack ) );
730 if( modelPath.empty() )
739 fpModel.m_Scale ).value_or( 0 ) ) );
758 if( crefdes.empty() || !crefdes.compare(
"~" ) )
764 if( cvalue.empty() || !cvalue.compare(
"~" ) )
767 crefdes =
"NOREFDES";
783 std::list<IDF_SEGMENT*> cutoutLines;
794 while( !cutoutLines.empty() )
799 if( cutout->
empty() )
810 for(
auto pad : aFootprint->
Pads() )
812 drill = (double)
pad->GetDrillSize().x *
scale;
813 x =
pad->GetPosition().x *
scale + dx;
814 y = -
pad->GetPosition().y *
scale + dy;
828 if( tstr.empty() || !tstr.compare(
"0" ) || !tstr.compare(
"~" )
844 && (
pad->GetDrillSize().x !=
pad->GetDrillSize().y ) )
850 double dlength =
pad->GetDrillSize().y *
scale;
855 double angle =
pad->GetOrientation().AsDegrees();
863 if( dlength < drill )
865 std::swap( drill, dlength );
876 aIDFBoard.
AddSlot( drill, dlength, angle, x, y );
889 m_reporter->Report( wxString::Format(
"Error exporting footprint %s: %s",
891 _(
"could not add drill for pad" ) ),
905 int standoffHeight = 0;
917 if( extruded->m_height <= 0 )
920 standoffHeight = extruded->m_standoff;
932 body = &generatedBody;
941 if( refdes.empty() || !refdes.compare(
"~" ) )
948 if(
comp ==
nullptr )
951 comp->SetRefDes( refdes );
960 double refX, refY, refA;
963 if( !
comp->GetPosition( refX, refY, refA, side ) )
984 || ( refA > 0.0001 ) || ( refX > 0.0001 ) )
986 comp->GetPosition( refX, refY, refA, side );
991 wxString::Format(
"Error exporting footprint %s: duplicate reference designator",
1005 data->
SetOffsets( 0.0, 0.0, standoffHeight * unitScale, 0.0 );
1006 comp->AddOutlineData( data );
1010 m_reporter->Report( wxString::Format(
_(
"Exported extruded body for footprint %s" ),
1080 wxFileName brdName =
m_board->GetFileName();
1088 std::ostringstream ostr;
1118 catch(
const std::exception& e )
1128 wxFileName brdname( aFullFileName );
1129 wxFileName libname( aFullFileName );
1134 m_settings->AddOutput( brdname.GetFullPath() );
1135 m_settings->AddOutput( libname.GetFullPath() );
1139 m_reporter->Report( wxString::Format(
_(
"Wrote IDF board file to %s" ), brdname.GetFullPath() ),
1141 m_reporter->Report( wxString::Format(
_(
"Wrote IDF library file to %s" ), libname.GetFullPath() ),
glm::mat4 CalcModelMatrix(const SFVEC3F &aOffset, const SFVEC3F &aRotation, const SFVEC3F &aScale)
Build the model-to-footprint transform used by rendering and picking.
Defines math related functions.
void ApplyExtrusionTransform(SHAPE_POLY_SET &aOutline, const EXTRUDED_3D_BODY *aBody, const VECTOR2I &aFpPos)
Apply 2D extrusion transforms (rotation, scale, offset) to an outline.
bool GetExtrusionOutline(const FOOTPRINT *aFootprint, SHAPE_POLY_SET &aOutline, PCB_LAYER_ID aLayerOverride)
Get the extrusion outline polygon for a footprint in board coordinates.
constexpr EDA_IU_SCALE pcbIUScale
wxString GetBuildVersion()
Get the full KiCad version string.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
bool AddOutline(IDF_OUTLINE *aOutline)
Add the specified outline to this object.
virtual bool SetThickness(double aThickness)
Set the thickness or height of the outline (mm).
size_t OutlinesSize(void)
virtual bool SetUnit(IDF3::IDF_UNIT aUnit)
Function SetUnit sets the native unit of the outline; except for component outlines this must be the ...
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 DRAWINGS & Drawings() const
constexpr Vec Centre() const
constexpr const Vec & GetOrigin() const
constexpr const SizeVec & GetSize() const
EDA_ANGLE GetArcAngle() const
SHAPE_POLY_SET & GetPolyShape()
void RebuildBezierToSegmentsPointsList(int aMaxError)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
const std::vector< VECTOR2I > & GetBezierPoints() const
bool IsPolyShapeValid() const
Provide an extensible class to resolve 3D model paths.
void GetUserOffset(double &aXoff, double &aYoff)
bool WriteFile(const wxString &aFullFileName, IDF3::IDF_UNIT aUnits, REPORTER *aReporter=nullptr)
bool SetBoardThickness(double aBoardThickness)
bool SetLibraryVersion(int aVersion)
IDF3_COMP_OUTLINE * GetComponentOutline(const wxString &aFullFileName)
const std::string & GetNewRefDes(void)
double GetUserScale(void) const
void SetUserOffset(double aXoff, double aYoff)
const std::string & GetError(void)
void SetIDFSource(const std::string &aIDFSource)
IDF3_COMPONENT * FindComponent(const std::string &aRefDes)
IDF_DRILL_DATA * AddDrill(IDF_DRILL_DATA *aDrilledHole)
bool AddComponent(IDF3_COMPONENT *aComponent)
bool SetUserScale(double aScaleFactor)
void SetBoardName(const std::string &aBoardName)
bool SetUserPrecision(int aPrecision)
bool AddSlot(double aWidth, double aLength, double aOrientation, double aX, double aY)
bool SetBoardVersion(int aVersion)
bool AddBoardOutline(IDF_OUTLINE *aOutline)
bool SetOffsets(double aXoff, double aYoff, double aZoff, double aAngleOff)
Set the position and orientation of this outline item in relation to its parent.
A component's outline as stored in an IDF library file.
bool SetComponentClass(IDF3::COMP_TYPE aCompClass)
Set the type of component outline (.ELECTRICAL or .MECHANICAL).
JOB_EXPORT_PCB_IDF * m_settings
VECTOR2D getOrigin() const
IDF3_COMP_OUTLINE * createOutlineFromExtrudedBody(const FOOTPRINT *aFootprint, IDF3_BOARD &aIDFBoard, const EXTRUDED_3D_BODY &aBody) const
Generates an IDF component outline from a footprint extruded 3D body, if possible.
FILENAME_RESOLVER * m_resolver
bool Export(const wxString &aFullFileName) const
Generate IDFv3 compliant board (*.emn) and library (*.emp) files for aPcb.
void exportFootprint(FOOTPRINT *aFootprint, IDF3_BOARD &aIDFBoard) const
Exports the given footprint to an in-progress IDF file.
int getMaxModelHeight(FOOTPRINT *aFootprint) const
Returns the largest extent in Z of the footprint's visible 3D models, in IU.
bool exportFootprintIdfModels(FOOTPRINT *aFootprint, IDF3_BOARD &aIDFBoard) const
Exports any explicit IDF models attached to a footprint to an in-progress IDF file.
IDF_EXPORTER(BOARD *aBoard, FILENAME_RESOLVER *aResolver, JOB_EXPORT_PCB_IDF *aSettings, REPORTER *aReporter=nullptr)
std::unique_ptr< JOB_EXPORT_PCB_IDF > m_defaultSettings
A segment and winding information for an IDF outline.
void Clear()
Clear the internal list of outline segments.
bool push(IDF_SEGMENT *item)
Add a segment to the internal segment list.
A point as used by the various IDF related classes.
A segment as used in IDFv3 outlines.
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()
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
Cache for storing the 3D shapes.
S3DMODEL * GetModel(const wxString &aModelFileName, const wxString &aBasePath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack)
Attempt to load the scene data for a model and to translate it into an S3D_MODEL structure for displa...
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
int OutlineCount() const
Return the number of outlines in the set.
void Move(const VECTOR2I &aVector) override
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
@ RECTANGLE
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 void idf_append_shape(PCB_SHAPE *aGraphic, double aScale, double aOffX, double aOffY, std::list< IDF_SEGMENT * > &aLines)
Convert a single Edge_Cuts graphic into IDF segments and append them to aLines.
static std::optional< double > getModelHeight(const S3DMODEL &aModel, const VECTOR3D &aRotation, const VECTOR3D &aScale)
Returns the largest board Z value, in mm, of the given model.
static const std::string IdfV3LibraryFileExtension
static const std::string IdfV3BoardFileExtension
static wxString From_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
This file contains miscellaneous commonly used macros and functions.
KEY_PLATING
The plating condition of a hole.
IDF_UNIT
The native unit of the board and of component outlines.
IDF_LAYER
The various IDF layer classes and groupings.
void GetOutline(std::list< IDF_SEGMENT * > &aLines, IDF_OUTLINE &aOutline)
Take contiguous elements from 'aLines' and stuffs them into 'aOutline'; elements put into the outline...
COMP_TYPE
Whether a component is a mechanical or electrical part.
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Store the a model based on meshes and materials.
unsigned int m_MeshesSize
Number of meshes in the array.
SMESH * m_Meshes
The meshes list of this model.
Per-vertex normal/color/texcoors structure.
unsigned int m_VertexSize
Number of vertex in the arrays.
SFVEC3F * m_Positions
Vertex position array.
KIBIS top(path, &reporter)
const SHAPE_LINE_CHAIN chain
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
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
VECTOR3< double > VECTOR3D