KiCad PCB EDA Suite
Loading...
Searching...
No Matches
step_pcb_model.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 Cirilo Bernardo <[email protected]>
5 * Copyright (C) 2021-2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef OCE_VIS_OCE_UTILS_H
26#define OCE_VIS_OCE_UTILS_H
27
28#include <list>
29#include <map>
30#include <string>
31#include <utility>
32#include <vector>
33
34#include <Standard_Handle.hxx>
35#include <TDF_Label.hxx>
36#include <TopoDS_Shape.hxx>
37
38#include <math/vector2d.h>
39#include <math/vector3.h>
42
51static constexpr double OCC_MAX_DISTANCE_TO_MERGE_POINTS = 0.001;
52
53// default PCB thickness in mm
54static constexpr double BOARD_THICKNESS_DEFAULT_MM = 1.6;
55
56// minimum PCB thickness in mm (10 microns assumes a very thin polyimide film)
57// must be > OCC_MAX_DISTANCE_TO_MERGE_POINTS
58static constexpr double BOARD_THICKNESS_MIN_MM = 0.01;
59
60// default copper thickness in mm
61// must be > OCC_MAX_DISTANCE_TO_MERGE_POINTS
62static constexpr double COPPER_THICKNESS_DEFAULT_MM = 0.035;
63
64// Max error to approximate an arc by segments (in mm)
65static constexpr double ARC_TO_SEGMENT_MAX_ERROR_MM = 0.005;
66
67class PAD;
68
69class TDocStd_Document;
70class XCAFApp_Application;
71class XCAFDoc_ShapeTool;
72
73typedef std::pair< std::string, TDF_Label > MODEL_DATUM;
74typedef std::map< std::string, TDF_Label > MODEL_MAP;
75
76extern void ReportMessage( const wxString& aMessage );
77
78enum class OUTPUT_FORMAT
79{
88};
89
91{
92public:
93 STEP_PCB_MODEL( const wxString& aPcbName );
94 virtual ~STEP_PCB_MODEL();
95
96 // Update m_outFmt to aVariant, giving the output format variant
97 void SpecializeVariant( OUTPUT_FORMAT aVariant ) { m_outFmt = aVariant; }
98
99 // add a pad shape (must be in final position)
100 bool AddPadShape( const PAD* aPad, const VECTOR2D& aOrigin, bool aVia );
101
102 // add a pad hole or slot (must be in final position)
103 bool AddHole( const SHAPE_SEGMENT& aShape, int aPlatingThickness, PCB_LAYER_ID aLayerTop,
104 PCB_LAYER_ID aLayerBot, bool aVia, const VECTOR2D& aOrigin );
105
106 // add a plated hole shape (without the hole)
107 bool AddBarrel( const SHAPE_SEGMENT& aShape, PCB_LAYER_ID aLayerTop, PCB_LAYER_ID aLayerBot,
108 bool aVia, const VECTOR2D& aOrigin );
109
110 // add a set of polygons (must be in final position)
111 bool AddPolygonShapes( const SHAPE_POLY_SET* aPolyShapes, PCB_LAYER_ID aLayer,
112 const VECTOR2D& aOrigin );
113
114 // add a component at the given position and orientation
115 bool AddComponent( const std::string& aFileName, const std::string& aRefDes, bool aBottom,
116 VECTOR2D aPosition, double aRotation, VECTOR3D aOffset,
117 VECTOR3D aOrientation, VECTOR3D aScale, bool aSubstituteModels = true );
118
119 void SetCopperColor( double r, double g, double b );
120 void SetPadColor( double r, double g, double b );
121
122 void SetEnabledLayers( const LSET& aLayers );
123 void SetFuseShapes( bool aValue );
124 void SetSimplifyShapes( bool aValue );
125 void SetAddVisMaterials( bool aValue );
126 void SetStackup( const BOARD_STACKUP& aStackup );
127 void SetNetFilter( const wxString& aFilter );
128
129 // Set the max distance (in mm) to consider 2 points have the same coordinates
130 // and can be merged
132
133 void SetMaxError( int aMaxError ) { m_maxError = aMaxError; }
134
135 // create the PCB model using the current outlines and drill holes
136 bool CreatePCB( SHAPE_POLY_SET& aOutline, VECTOR2D aOrigin, bool aPushBoardBody );
137
147 bool MakeShapes( std::vector<TopoDS_Shape>& aShapes, const SHAPE_POLY_SET& aPolySet,
148 bool aConvertToArcs, double aThickness, double aZposition,
149 const VECTOR2D& aOrigin );
150
162 bool MakeShapeAsThickSegment( TopoDS_Shape& aShape,
163 VECTOR2D aStartPoint, VECTOR2D aEndPoint,
164 double aWidth, double aThickness, double aZposition,
165 const VECTOR2D& aOrigin );
166
167#ifdef SUPPORTS_IGES
168 // write the assembly model in IGES format
169 bool WriteIGES( const wxString& aFileName );
170#endif
171
172 // write the assembly model in STEP format
173 bool WriteSTEP( const wxString& aFileName, bool aOptimize );
174
175 // write the assembly in BREP format
176 bool WriteBREP( const wxString& aFileName );
177
178 // write the assembly in XAO format with pad faces as groups
179 bool WriteXAO( const wxString& aFileName );
180
195 bool WriteGLTF( const wxString& aFileName );
196
197 // write the assembly in PLY format (mesh)
198 bool WritePLY( const wxString& aFileName );
199
200 // write the assembly in STL format (mesh)
201 bool WriteSTL( const wxString& aFileName );
202
203private:
207 bool isBoardOutlineValid();
208
209 void getLayerZPlacement( const PCB_LAYER_ID aLayer, double& aZPos, double& aThickness );
210
211 void getCopperLayerZPlacement( const PCB_LAYER_ID aLayer, double& aZPos, double& aThickness );
212
213 void getBoardBodyZPlacement( double& aZPos, double& aThickness );
214
227 bool getModelLabel( const std::string& aFileNameUTF8, VECTOR3D aScale, TDF_Label& aLabel,
228 bool aSubstituteModels, wxString* aErrorMessage = nullptr );
229
230 bool getModelLocation( bool aBottom, VECTOR2D aPosition, double aRotation, VECTOR3D aOffset,
231 VECTOR3D aOrientation, TopLoc_Location& aLocation );
232
233 bool readIGES( Handle( TDocStd_Document ) & aDoc, const char* aFname );
234 bool readSTEP( Handle( TDocStd_Document ) & aDoc, const char* aFname );
235 bool readVRML( Handle( TDocStd_Document ) & aDoc, const char* aFname );
236
237 bool performMeshing( Handle( XCAFDoc_ShapeTool ) & aShapeTool );
238
239 TDF_Label transferModel( Handle( TDocStd_Document )& source, Handle( TDocStd_Document ) & dest,
240 VECTOR3D aScale );
241
242 Handle( XCAFApp_Application ) m_app;
243 Handle( TDocStd_Document ) m_doc;
244 Handle( XCAFDoc_ShapeTool ) m_assy;
245 TDF_Label m_assy_label;
246 bool m_hasPCB; // set true if CreatePCB() has been invoked
247 bool m_simplifyShapes; // convert parts of outlines to arcs where possible
248 bool m_fuseShapes; // fuse geometry together
249 std::vector<TDF_Label> m_pcb_labels; // labels for the PCB model (one by main outline)
250 MODEL_MAP m_models; // map of file names to model labels
251 int m_components; // number of successfully loaded components;
252 double m_precision; // model (length unit) numeric precision
253 double m_angleprec; // angle numeric precision
254 double m_copperColor[3]; // copper, RGB values
255 double m_padColor[3]; // pads, RGB values
256 BOARD_STACKUP m_stackup; // board stackup
257 LSET m_enabledLayers; // a set of layers enabled for export
258 wxString m_netFilter; // remove nets not matching this wildcard
259
260 double m_minx; // leftmost curve point
261 double m_mergeOCCMaxDist; // minimum distance (mm) below which two
262 // points are considered coincident by OCC
263
264 // Holes in copper and main outlines
265 std::vector<TopoDS_Shape> m_copperCutouts;
266 std::vector<TopoDS_Shape> m_boardCutouts;
267
268 // Main outlines (more than one board)
269 std::vector<TopoDS_Shape> m_board_outlines;
270 std::vector<TopoDS_Shape> m_board_copper;
271 std::vector<TopoDS_Shape> m_board_copper_pads;
272 std::vector<TopoDS_Shape> m_board_copper_vias;
273 std::vector<TopoDS_Shape> m_board_copper_fused;
274 std::vector<TopoDS_Shape> m_board_silkscreen;
275 std::vector<TopoDS_Shape> m_board_soldermask;
276
277 // Data for pads
278 std::map<wxString, std::pair<gp_Pnt, TopoDS_Shape>> m_pad_points;
279
281 wxString m_pcbName;
282
284
287};
288
289#endif // OCE_VIS_OCE_UTILS_H
Manage layers needed to make a physical board.
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
Definition: pad.h:54
Represent a set of closed polygons.
OUTPUT_FORMAT m_outFmt
The current output format for created file.
void SetCopperColor(double r, double g, double b)
std::vector< TopoDS_Shape > m_board_silkscreen
wxString m_netFilter
bool CreatePCB(SHAPE_POLY_SET &aOutline, VECTOR2D aOrigin, bool aPushBoardBody)
bool MakeShapeAsThickSegment(TopoDS_Shape &aShape, VECTOR2D aStartPoint, VECTOR2D aEndPoint, double aWidth, double aThickness, double aZposition, const VECTOR2D &aOrigin)
Make a segment shape based on start and end point.
bool WritePLY(const wxString &aFileName)
std::vector< TopoDS_Shape > m_board_copper_vias
bool AddComponent(const std::string &aFileName, const std::string &aRefDes, bool aBottom, VECTOR2D aPosition, double aRotation, VECTOR3D aOffset, VECTOR3D aOrientation, VECTOR3D aScale, bool aSubstituteModels=true)
wxString m_pcbName
Name of the PCB, which will most likely be the file name of the path.
std::vector< TopoDS_Shape > m_boardCutouts
std::vector< TopoDS_Shape > m_board_soldermask
void getBoardBodyZPlacement(double &aZPos, double &aThickness)
std::vector< TopoDS_Shape > m_board_copper_fused
TDF_Label m_assy_label
std::vector< TopoDS_Shape > m_board_copper
void SetFuseShapes(bool aValue)
bool WriteXAO(const wxString &aFileName)
bool WriteGLTF(const wxString &aFileName)
Write the assembly in binary GLTF Format.
Handle(XCAFDoc_ShapeTool) m_assy
double m_mergeOCCMaxDist
std::vector< TDF_Label > m_pcb_labels
bool AddHole(const SHAPE_SEGMENT &aShape, int aPlatingThickness, PCB_LAYER_ID aLayerTop, PCB_LAYER_ID aLayerBot, bool aVia, const VECTOR2D &aOrigin)
void getLayerZPlacement(const PCB_LAYER_ID aLayer, double &aZPos, double &aThickness)
bool AddBarrel(const SHAPE_SEGMENT &aShape, PCB_LAYER_ID aLayerTop, PCB_LAYER_ID aLayerBot, bool aVia, const VECTOR2D &aOrigin)
std::vector< TopoDS_Shape > m_board_outlines
void SetSimplifyShapes(bool aValue)
bool readVRML(Handle(TDocStd_Document) &aDoc, const char *aFname)
void SetPadColor(double r, double g, double b)
void SetEnabledLayers(const LSET &aLayers)
bool performMeshing(Handle(XCAFDoc_ShapeTool) &aShapeTool)
bool readSTEP(Handle(TDocStd_Document) &aDoc, const char *aFname)
Handle(TDocStd_Document) m_doc
Handle(XCAFApp_Application) m_app
void SetMaxError(int aMaxError)
bool getModelLocation(bool aBottom, VECTOR2D aPosition, double aRotation, VECTOR3D aOffset, VECTOR3D aOrientation, TopLoc_Location &aLocation)
virtual ~STEP_PCB_MODEL()
double m_copperColor[3]
bool WriteSTL(const wxString &aFileName)
void SetStackup(const BOARD_STACKUP &aStackup)
void SetNetFilter(const wxString &aFilter)
double m_padColor[3]
bool AddPadShape(const PAD *aPad, const VECTOR2D &aOrigin, bool aVia)
bool MakeShapes(std::vector< TopoDS_Shape > &aShapes, const SHAPE_POLY_SET &aPolySet, bool aConvertToArcs, double aThickness, double aZposition, const VECTOR2D &aOrigin)
Convert a SHAPE_POLY_SET to TopoDS_Shape's (polygonal vertical prisms, or flat faces)
bool getModelLabel(const std::string &aFileNameUTF8, VECTOR3D aScale, TDF_Label &aLabel, bool aSubstituteModels, wxString *aErrorMessage=nullptr)
Load a 3D model data.
bool readIGES(Handle(TDocStd_Document) &aDoc, const char *aFname)
bool AddPolygonShapes(const SHAPE_POLY_SET *aPolyShapes, PCB_LAYER_ID aLayer, const VECTOR2D &aOrigin)
bool WriteSTEP(const wxString &aFileName, bool aOptimize)
std::vector< TopoDS_Shape > m_copperCutouts
void SpecializeVariant(OUTPUT_FORMAT aVariant)
std::vector< TopoDS_Shape > m_board_copper_pads
std::map< wxString, std::pair< gp_Pnt, TopoDS_Shape > > m_pad_points
MODEL_MAP m_models
void SetAddVisMaterials(bool aValue)
void getCopperLayerZPlacement(const PCB_LAYER_ID aLayer, double &aZPos, double &aThickness)
TDF_Label transferModel(Handle(TDocStd_Document)&source, Handle(TDocStd_Document) &dest, VECTOR3D aScale)
void OCCSetMergeMaxDistance(double aDistance=OCC_MAX_DISTANCE_TO_MERGE_POINTS)
BOARD_STACKUP m_stackup
bool WriteBREP(const wxString &aFileName)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
static constexpr double COPPER_THICKNESS_DEFAULT_MM
OUTPUT_FORMAT
static constexpr double OCC_MAX_DISTANCE_TO_MERGE_POINTS
Default distance between points to treat them as separate ones (mm) 0.001 mm or less is a reasonable ...
std::map< std::string, TDF_Label > MODEL_MAP
static constexpr double BOARD_THICKNESS_DEFAULT_MM
std::pair< std::string, TDF_Label > MODEL_DATUM
static constexpr double ARC_TO_SEGMENT_MAX_ERROR_MM
static constexpr double BOARD_THICKNESS_MIN_MM
void ReportMessage(const wxString &aMessage)