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 hole or slot (must be in final position)
85 bool AddPadHole( const PAD* aPad, const VECTOR2D& aOrigin );
86
87 // add a pad shape (must be in final position)
88 bool AddPadShape( const PAD* aPad, const VECTOR2D& aOrigin, bool aVia );
89
90 // add a via shape
91 bool AddViaShape( const PCB_VIA* aVia, const VECTOR2D& aOrigin );
92
93 // add a track segment shape (do not use it for track arcs)
94 bool AddTrackSegment( const PCB_TRACK* aTrack, const VECTOR2D& aOrigin );
95
96 // add a set of polygons (must be in final position) on top or bottom of the board as copper
97 bool AddCopperPolygonShapes( const SHAPE_POLY_SET* aPolyShapes, PCB_LAYER_ID aLayer,
98 const VECTOR2D& aOrigin, bool aTrack );
99
100 // add a component at the given position and orientation
101 bool AddComponent( const std::string& aFileName, const std::string& aRefDes, bool aBottom,
102 VECTOR2D aPosition, double aRotation, VECTOR3D aOffset,
103 VECTOR3D aOrientation, VECTOR3D aScale, bool aSubstituteModels = true );
104
105 void SetBoardColor( double r, double g, double b );
106 void SetCopperColor( double r, double g, double b );
107
108 void SetEnabledLayers( const LSET& aLayers );
109
110 void SetFuseShapes( bool aValue );
111
112 void SetStackup( const BOARD_STACKUP& aStackup );
113
114 void SetNetFilter( const wxString& aFilter );
115
116 // Set the max distance (in mm) to consider 2 points have the same coordinates
117 // and can be merged
119
120 void SetMaxError( int aMaxError ) { m_maxError = aMaxError; }
121
122 // create the PCB model using the current outlines and drill holes
123 bool CreatePCB( SHAPE_POLY_SET& aOutline, VECTOR2D aOrigin, bool aPushBoardBody );
124
134 bool MakeShapes( std::vector<TopoDS_Shape>& aShapes, const SHAPE_POLY_SET& aPolySet,
135 bool aConvertToArcs, double aThickness, double aZposition,
136 const VECTOR2D& aOrigin );
137
148 bool MakeShapeAsCylinder( TopoDS_Shape& aShape, const SHAPE_LINE_CHAIN& aChain,
149 double aThickness, double aZposition, const VECTOR2D& aOrigin );
150
163 bool MakeShapeAsThickSegment( TopoDS_Shape& aShape,
164 VECTOR2D aStartPoint, VECTOR2D aEndPoint,
165 double aWidth, double aThickness, double aZposition,
166 const VECTOR2D& aOrigin );
167
168#ifdef SUPPORTS_IGES
169 // write the assembly model in IGES format
170 bool WriteIGES( const wxString& aFileName );
171#endif
172
173 // write the assembly model in STEP format
174 bool WriteSTEP( const wxString& aFileName, bool aOptimize );
175
176 // write the assembly in BREP format
177 bool WriteBREP( const wxString& aFileName );
178
179 // write the assembly in XAO format with pad faces as groups
180 bool WriteXAO( const wxString& aFileName );
181
196 bool WriteGLTF( const wxString& aFileName );
197
198private:
202 bool isBoardOutlineValid();
203
204 void getLayerZPlacement( const PCB_LAYER_ID aLayer, double& aZPos, double& aThickness );
205
206 void getBoardBodyZPlacement( double& aZPos, double& aThickness );
207
220 bool getModelLabel( const std::string& aFileNameUTF8, VECTOR3D aScale, TDF_Label& aLabel,
221 bool aSubstituteModels, wxString* aErrorMessage = nullptr );
222
223 bool getModelLocation( bool aBottom, VECTOR2D aPosition, double aRotation, VECTOR3D aOffset,
224 VECTOR3D aOrientation, TopLoc_Location& aLocation );
225
226 bool readIGES( Handle( TDocStd_Document )& m_doc, const char* fname );
227 bool readSTEP( Handle( TDocStd_Document )& m_doc, const char* fname );
228
229 TDF_Label transferModel( Handle( TDocStd_Document )& source, Handle( TDocStd_Document ) & dest,
230 VECTOR3D aScale );
231
232 Handle( XCAFApp_Application ) m_app;
233 Handle( TDocStd_Document ) m_doc;
234 Handle( XCAFDoc_ShapeTool ) m_assy;
235 TDF_Label m_assy_label;
236 bool m_hasPCB; // set true if CreatePCB() has been invoked
237 bool m_fuseShapes; // fuse geometry together
238 int m_platingThickness; // plating thickness for TH pads/vias
239 std::vector<TDF_Label> m_pcb_labels; // labels for the PCB model (one by main outline)
240 MODEL_MAP m_models; // map of file names to model labels
241 int m_components; // number of successfully loaded components;
242 double m_precision; // model (length unit) numeric precision
243 double m_angleprec; // angle numeric precision
244 double m_boardColor[3]; // board body, RGB values
245 double m_copperColor[3]; // copper, RGB values
246 BOARD_STACKUP m_stackup; // board stackup
247 LSET m_enabledLayers; // a set of layers enabled for export
248 wxString m_netFilter; // remove nets not matching this wildcard
249
250 double m_minx; // leftmost curve point
251 double m_mergeOCCMaxDist; // minimum distance (mm) below which two
252 // points are considered coincident by OCC
253
254 // Holes in copper and main outlines
255 std::vector<TopoDS_Shape> m_copperCutouts;
256 std::vector<TopoDS_Shape> m_boardCutouts;
257
258 // Main outlines (more than one board)
259 std::vector<TopoDS_Shape> m_board_outlines;
260 std::vector<TopoDS_Shape> m_board_copper_zones;
261 std::vector<TopoDS_Shape> m_board_copper_tracks;
262 std::vector<TopoDS_Shape> m_board_copper_pads;
263 std::vector<TopoDS_Shape> m_board_copper_fused;
264
265 // Data for pads
266 std::map<wxString, std::pair<gp_Pnt, TopoDS_Shape>> m_pad_points;
267
269 wxString m_pcbName;
270
272};
273
274#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:59
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 SetCopperColor(double r, double g, double b)
bool isBoardOutlineValid()
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)
Convert a SHAPE_LINE_CHAIN containing only one 360 deg arc to a TopoDS_Shape ( vertical cylinder) it ...
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)
double m_boardColor[3]
wxString m_pcbName
Name of the PCB, which will most likely be the file name of the path.
std::vector< TopoDS_Shape > m_boardCutouts
void getBoardBodyZPlacement(double &aZPos, double &aThickness)
std::vector< TopoDS_Shape > m_board_copper_fused
TDF_Label m_assy_label
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
bool AddPadHole(const PAD *aPad, const VECTOR2D &aOrigin)
double m_mergeOCCMaxDist
std::vector< TDF_Label > m_pcb_labels
bool MakeShapeAsCylinder(TopoDS_Shape &aShape, const SHAPE_LINE_CHAIN &aChain, double aThickness, double aZposition, const VECTOR2D &aOrigin)
Convert a SHAPE_LINE_CHAIN containing only one 360 deg arc to a TopoDS_Shape ( vertical cylinder) it ...
void getLayerZPlacement(const PCB_LAYER_ID aLayer, double &aZPos, double &aThickness)
std::vector< TopoDS_Shape > m_board_outlines
bool readIGES(Handle(TDocStd_Document)&m_doc, const char *fname)
void SetBoardColor(double r, double g, double b)
bool AddViaShape(const PCB_VIA *aVia, const VECTOR2D &aOrigin)
void SetEnabledLayers(const LSET &aLayers)
bool readSTEP(Handle(TDocStd_Document)&m_doc, const char *fname)
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]
std::vector< TopoDS_Shape > m_board_copper_tracks
void SetStackup(const BOARD_STACKUP &aStackup)
void SetNetFilter(const wxString &aFilter)
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)
bool getModelLabel(const std::string &aFileNameUTF8, VECTOR3D aScale, TDF_Label &aLabel, bool aSubstituteModels, wxString *aErrorMessage=nullptr)
Load a 3D model data.
bool WriteSTEP(const wxString &aFileName, bool aOptimize)
std::vector< TopoDS_Shape > m_copperCutouts
std::vector< TopoDS_Shape > m_board_copper_pads
std::vector< TopoDS_Shape > m_board_copper_zones
std::map< wxString, std::pair< gp_Pnt, TopoDS_Shape > > m_pad_points
MODEL_MAP m_models
bool AddTrackSegment(const PCB_TRACK *aTrack, const VECTOR2D &aOrigin)
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 AddCopperPolygonShapes(const SHAPE_POLY_SET *aPolyShapes, PCB_LAYER_ID aLayer, const VECTOR2D &aOrigin, bool aTrack)
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)