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
79{
80public:
81 STEP_PCB_MODEL( const wxString& aPcbName );
82 virtual ~STEP_PCB_MODEL();
83
84 // add a pad shape (must be in final position)
85 bool AddPadShape( const PAD* aPad, const VECTOR2D& aOrigin, bool aVia );
86
87 // add a pad hole or slot (must be in final position)
88 bool AddHole( const SHAPE_SEGMENT& aShape, int aPlatingThickness, PCB_LAYER_ID aLayerTop,
89 PCB_LAYER_ID aLayerBot, bool aVia, const VECTOR2D& aOrigin );
90
91 // add a plated hole shape (without the hole)
92 bool AddBarrel( const SHAPE_SEGMENT& aShape, PCB_LAYER_ID aLayerTop, PCB_LAYER_ID aLayerBot,
93 bool aVia, const VECTOR2D& aOrigin );
94
95 // add a set of polygons (must be in final position)
96 bool AddPolygonShapes( const SHAPE_POLY_SET* aPolyShapes, PCB_LAYER_ID aLayer,
97 const VECTOR2D& aOrigin );
98
99 // add a component at the given position and orientation
100 bool AddComponent( const std::string& aFileName, const std::string& aRefDes, bool aBottom,
101 VECTOR2D aPosition, double aRotation, VECTOR3D aOffset,
102 VECTOR3D aOrientation, VECTOR3D aScale, bool aSubstituteModels = true );
103
104 void SetCopperColor( double r, double g, double b );
105 void SetPadColor( double r, double g, double b );
106
107 void SetEnabledLayers( const LSET& aLayers );
108 void SetFuseShapes( bool aValue );
109 void SetSimplifyShapes( bool aValue );
110 void SetAddVisMaterials( bool aValue );
111 void SetStackup( const BOARD_STACKUP& aStackup );
112 void SetNetFilter( const wxString& aFilter );
113
114 // Set the max distance (in mm) to consider 2 points have the same coordinates
115 // and can be merged
117
118 void SetMaxError( int aMaxError ) { m_maxError = aMaxError; }
119
120 // create the PCB model using the current outlines and drill holes
121 bool CreatePCB( SHAPE_POLY_SET& aOutline, VECTOR2D aOrigin, bool aPushBoardBody );
122
132 bool MakeShapes( std::vector<TopoDS_Shape>& aShapes, const SHAPE_POLY_SET& aPolySet,
133 bool aConvertToArcs, double aThickness, double aZposition,
134 const VECTOR2D& aOrigin );
135
147 bool MakeShapeAsThickSegment( TopoDS_Shape& aShape,
148 VECTOR2D aStartPoint, VECTOR2D aEndPoint,
149 double aWidth, double aThickness, double aZposition,
150 const VECTOR2D& aOrigin );
151
152#ifdef SUPPORTS_IGES
153 // write the assembly model in IGES format
154 bool WriteIGES( const wxString& aFileName );
155#endif
156
157 // write the assembly model in STEP format
158 bool WriteSTEP( const wxString& aFileName, bool aOptimize );
159
160 // write the assembly in BREP format
161 bool WriteBREP( const wxString& aFileName );
162
163 // write the assembly in XAO format with pad faces as groups
164 bool WriteXAO( const wxString& aFileName );
165
180 bool WriteGLTF( const wxString& aFileName );
181
182private:
186 bool isBoardOutlineValid();
187
188 void getLayerZPlacement( const PCB_LAYER_ID aLayer, double& aZPos, double& aThickness );
189
190 void getCopperLayerZPlacement( const PCB_LAYER_ID aLayer, double& aZPos, double& aThickness );
191
192 void getBoardBodyZPlacement( double& aZPos, double& aThickness );
193
206 bool getModelLabel( const std::string& aFileNameUTF8, VECTOR3D aScale, TDF_Label& aLabel,
207 bool aSubstituteModels, wxString* aErrorMessage = nullptr );
208
209 bool getModelLocation( bool aBottom, VECTOR2D aPosition, double aRotation, VECTOR3D aOffset,
210 VECTOR3D aOrientation, TopLoc_Location& aLocation );
211
212 bool readIGES( Handle( TDocStd_Document ) & aDoc, const char* aFname );
213 bool readSTEP( Handle( TDocStd_Document ) & aDoc, const char* aFname );
214 bool readVRML( Handle( TDocStd_Document ) & aDoc, const char* aFname );
215
216 TDF_Label transferModel( Handle( TDocStd_Document )& source, Handle( TDocStd_Document ) & dest,
217 VECTOR3D aScale );
218
219 Handle( XCAFApp_Application ) m_app;
220 Handle( TDocStd_Document ) m_doc;
221 Handle( XCAFDoc_ShapeTool ) m_assy;
222 TDF_Label m_assy_label;
223 bool m_hasPCB; // set true if CreatePCB() has been invoked
224 bool m_simplifyShapes; // convert parts of outlines to arcs where possible
225 bool m_fuseShapes; // fuse geometry together
226 std::vector<TDF_Label> m_pcb_labels; // labels for the PCB model (one by main outline)
227 MODEL_MAP m_models; // map of file names to model labels
228 int m_components; // number of successfully loaded components;
229 double m_precision; // model (length unit) numeric precision
230 double m_angleprec; // angle numeric precision
231 double m_copperColor[3]; // copper, RGB values
232 double m_padColor[3]; // pads, RGB values
233 BOARD_STACKUP m_stackup; // board stackup
234 LSET m_enabledLayers; // a set of layers enabled for export
235 wxString m_netFilter; // remove nets not matching this wildcard
236
237 double m_minx; // leftmost curve point
238 double m_mergeOCCMaxDist; // minimum distance (mm) below which two
239 // points are considered coincident by OCC
240
241 // Holes in copper and main outlines
242 std::vector<TopoDS_Shape> m_copperCutouts;
243 std::vector<TopoDS_Shape> m_boardCutouts;
244
245 // Main outlines (more than one board)
246 std::vector<TopoDS_Shape> m_board_outlines;
247 std::vector<TopoDS_Shape> m_board_copper;
248 std::vector<TopoDS_Shape> m_board_copper_pads;
249 std::vector<TopoDS_Shape> m_board_copper_vias;
250 std::vector<TopoDS_Shape> m_board_copper_fused;
251 std::vector<TopoDS_Shape> m_board_silkscreen;
252 std::vector<TopoDS_Shape> m_board_soldermask;
253
254 // Data for pads
255 std::map<wxString, std::pair<gp_Pnt, TopoDS_Shape>> m_pad_points;
256
258 wxString m_pcbName;
259
261};
262
263#endif // OCE_VIS_OCE_UTILS_H
Manage layers needed to make a physical board.
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
Definition: pad.h:53
Represent a set of closed polygons.
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.
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 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]
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
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
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)