51#define LINE_WIDTH (pcbIUScale.mmToIU( 0.1 ))
75 std::list<IDF_SEGMENT*>& aLines )
86 sp.
x = aGraphic->
GetStart().
x * aScale + aOffX;
87 sp.
y = -aGraphic->
GetStart().
y * aScale + aOffY;
88 ep.
x = aGraphic->
GetEnd().
x * aScale + aOffX;
89 ep.
y = -aGraphic->
GetEnd().
y * aScale + aOffY;
103 double bottom = -aGraphic->
GetEnd().
y * aScale + aOffY;
112 aLines.push_back(
new IDF_SEGMENT( corners[0], corners[1] ) );
113 aLines.push_back(
new IDF_SEGMENT( corners[1], corners[2] ) );
114 aLines.push_back(
new IDF_SEGMENT( corners[2], corners[3] ) );
115 aLines.push_back(
new IDF_SEGMENT( corners[3], corners[0] ) );
126 ep.
x = aGraphic->
GetStart().
x * aScale + aOffX;
127 ep.
y = -aGraphic->
GetStart().
y * aScale + aOffY;
145 aLines.push_back(
new IDF_SEGMENT( sp, ep, 360.0,
true ) );
162 for(
int jj = 0; jj <
chain.PointCount(); ++jj )
170 sp.
x = start.
x * aScale + aOffX;
171 sp.
y = -start.
y * aScale + aOffY;
172 ep.
x =
end.x * aScale + aOffX;
173 ep.
y = -
end.y * aScale + aOffY;
187 for(
size_t ii = 1; ii < pts.size(); ++ii )
189 if( pts[ii - 1] == pts[ii] )
192 sp.
x = pts[ii - 1].x * aScale + aOffX;
193 sp.
y = -pts[ii - 1].y * aScale + aOffY;
194 ep.
x = pts[ii].x * aScale + aOffX;
195 ep.
y = -pts[ii].y * aScale + aOffY;
215 std::list< IDF_SEGMENT* > lines;
246 if( outline->
empty() )
253 while( !lines.empty() )
260 if( outline->
empty() )
278 while( !lines.empty() )
280 delete lines.front();
322 for(
int i = 1; i < 4; ++i )
343 SFVEC3F( aRotation.
x, aRotation.
y, aRotation.
z ),
345 const SFVEC3F zRow( modelMatrix[0].z, modelMatrix[1].z, modelMatrix[2].z );
349 for(
unsigned int meshIdx = 0; meshIdx < aModel.
m_MeshesSize; ++meshIdx )
356 for(
unsigned int vtx = 0; vtx < mesh.
m_VertexSize; ++vtx )
359 ret = std::max( ret, glm::dot( zRow, pos ) );
370 wxString footprintBasePath = wxEmptyString;
374 std::optional<LIBRARY_TABLE_ROW*> fpRow =
388 auto sM = aFootprint->
Models().begin();
389 auto eM = aFootprint->
Models().end();
401 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
403 embeddedFilesStack.push_back(
m_board->GetEmbeddedFiles() );
405 idfFile.Assign(
m_resolver->ResolvePath( sM->m_Filename, footprintBasePath, std::move( embeddedFilesStack ) ) );
406 idfExt = idfFile.GetExt();
408 if( idfExt.Cmp( wxT(
"idf" ) ) && idfExt.Cmp( wxT(
"IDF" ) ) )
422 if( refdes.empty() || !refdes.compare(
"~" ) )
432 m_reporter->Report( wxString::Format(
"Error exporting footprint %s model %s",
441 double locx = sM->m_Offset.x;
442 double locy = sM->m_Offset.y;
443 double locz = sM->m_Offset.z;
444 double lrot = sM->m_Rotation.z;
464 while( rotz >= 360.0 ) rotz -= 360.0;
467 while( rotz <= -360.0 ) rotz += 360.0;
470 if(
comp ==
nullptr )
473 if(
comp ==
nullptr )
477 comp->SetRefDes( refdes );
498 double refX, refY, refA;
501 if( !
comp->GetPosition( refX, refY, refA, side ) )
534 || ( refA > 0.0001 ) || ( refX > 0.0001 ) )
539 wxString::Format(
"Error exporting footprint %s: duplicate reference designator",
553 comp->AddOutlineData( data );
559 m_reporter->Report( wxString::Format(
_(
"Exported IDF model for footprint %s" ), aFootprint->
GetReference() ),
563 return comp !=
nullptr;
576 m_reporter->Report( wxString::Format(
_(
"Could not generate extruded body for %s" ),
593 if(
chain.PointCount() < 3 )
597 m_reporter->Report( wxString::Format(
_(
"Could not generate extruded body for %s" ),
608 std::list<IDF_SEGMENT*> lines;
610 for(
int ii = 0; ii <
chain.PointCount(); ++ii )
627 while( !lines.empty() )
629 delete lines.front();
637 field = &aFootprint->
Value();
646 m_reporter->Report( wxString::Format(
_(
"Could not generate extruded body for %s" ),
660 if( idfOutline->
empty() )
686 m_reporter->Report( wxString::Format(
_(
"Could not generate extruded body for %s" ),
709 wxString footprintBasePath = wxEmptyString;
721 if( !fpModel.m_Show || fpModel.m_Filename.empty() )
724 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
726 embeddedFilesStack.push_back(
m_board->GetEmbeddedFiles() );
728 wxString modelPath =
m_resolver->ResolvePath( fpModel.m_Filename, footprintBasePath,
729 std::move( embeddedFilesStack ) );
731 if( modelPath.empty() )
740 fpModel.m_Scale ).value_or( 0 ) ) );
759 if( crefdes.empty() || !crefdes.compare(
"~" ) )
765 if( cvalue.empty() || !cvalue.compare(
"~" ) )
768 crefdes =
"NOREFDES";
784 std::list<IDF_SEGMENT*> cutoutLines;
795 while( !cutoutLines.empty() )
800 if( cutout->
empty() )
811 for(
auto pad : aFootprint->
Pads() )
813 drill = (double)
pad->GetDrillSize().x *
scale;
814 x =
pad->GetPosition().x *
scale + dx;
815 y = -
pad->GetPosition().y *
scale + dy;
829 if( tstr.empty() || !tstr.compare(
"0" ) || !tstr.compare(
"~" )
845 && (
pad->GetDrillSize().x !=
pad->GetDrillSize().y ) )
851 double dlength =
pad->GetDrillSize().y *
scale;
856 double angle =
pad->GetOrientation().AsDegrees();
864 if( dlength < drill )
866 std::swap( drill, dlength );
877 aIDFBoard.
AddSlot( drill, dlength, angle, x, y );
890 m_reporter->Report( wxString::Format(
"Error exporting footprint %s: %s",
892 _(
"could not add drill for pad" ) ),
906 int standoffHeight = 0;
931 if( height == 0 &&
m_settings->m_calculateHeightFromModels )
938 body = &generatedBody;
947 if( refdes.empty() || !refdes.compare(
"~" ) )
954 if(
comp ==
nullptr )
957 comp->SetRefDes( refdes );
966 double refX, refY, refA;
969 if( !
comp->GetPosition( refX, refY, refA, side ) )
990 || ( refA > 0.0001 ) || ( refX > 0.0001 ) )
992 comp->GetPosition( refX, refY, refA, side );
997 wxString::Format(
"Error exporting footprint %s: duplicate reference designator",
1011 data->
SetOffsets( 0.0, 0.0, standoffHeight * unitScale, 0.0 );
1012 comp->AddOutlineData( data );
1016 m_reporter->Report( wxString::Format(
_(
"Exported extruded body for footprint %s" ),
1086 wxFileName brdName =
m_board->GetFileName();
1094 std::ostringstream ostr;
1124 catch(
const std::exception& e )
1134 wxFileName brdname( aFullFileName );
1135 wxFileName libname( aFullFileName );
1140 m_settings->AddOutput( brdname.GetFullPath() );
1141 m_settings->AddOutput( libname.GetFullPath() );
1145 m_reporter->Report( wxString::Format(
_(
"Wrote IDF board file to %s" ), brdname.GetFullPath() ),
1147 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.
A 3D body attached to a footprint (or, later, placed on a board).
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