2016-09-02 10:08:40 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
2024-02-01 21:29:03 +00:00
|
|
|
* Copyright (C) 2021-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-09-02 10:08:40 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OCE_VIS_OCE_UTILS_H
|
|
|
|
#define OCE_VIS_OCE_UTILS_H
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2024-04-22 00:39:43 +00:00
|
|
|
#include <Standard_Handle.hxx>
|
|
|
|
#include <TDF_Label.hxx>
|
2016-09-02 10:08:40 +00:00
|
|
|
#include <TopoDS_Shape.hxx>
|
|
|
|
|
2022-10-08 22:00:05 +00:00
|
|
|
#include <math/vector2d.h>
|
|
|
|
#include <math/vector3.h>
|
|
|
|
#include <geometry/shape_poly_set.h>
|
2024-04-22 00:39:43 +00:00
|
|
|
#include <board_stackup_manager/board_stackup.h>
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2023-03-02 18:38:19 +00:00
|
|
|
/**
|
|
|
|
* Default distance between points to treat them as separate ones (mm)
|
2023-03-06 10:47:29 +00:00
|
|
|
* 0.001 mm or less is a reasonable value. A too large value creates issues by
|
2023-03-02 18:38:19 +00:00
|
|
|
* merging points that should be different.
|
2023-03-06 10:47:29 +00:00
|
|
|
* Remember we are a 3D space, so a thin shape can be broken if 2 points
|
2023-03-02 18:38:19 +00:00
|
|
|
* are merged (in X, Y, Z coords) when they should not.
|
|
|
|
* round shapes converted to polygon can also be not good with a to large value
|
|
|
|
*/
|
|
|
|
static constexpr double OCC_MAX_DISTANCE_TO_MERGE_POINTS = 0.001;
|
|
|
|
|
|
|
|
// default PCB thickness in mm
|
|
|
|
static constexpr double BOARD_THICKNESS_DEFAULT_MM = 1.6;
|
|
|
|
|
|
|
|
// minimum PCB thickness in mm (10 microns assumes a very thin polyimide film)
|
2023-03-06 10:47:29 +00:00
|
|
|
// must be > OCC_MAX_DISTANCE_TO_MERGE_POINTS
|
2023-03-02 18:38:19 +00:00
|
|
|
static constexpr double BOARD_THICKNESS_MIN_MM = 0.01;
|
|
|
|
|
|
|
|
// default copper thickness in mm
|
2023-03-06 10:47:29 +00:00
|
|
|
// must be > OCC_MAX_DISTANCE_TO_MERGE_POINTS
|
2023-03-02 18:38:19 +00:00
|
|
|
static constexpr double COPPER_THICKNESS_DEFAULT_MM = 0.035;
|
|
|
|
|
|
|
|
// Max error to approximate an arc by segments (in mm)
|
|
|
|
static constexpr double ARC_TO_SEGMENT_MAX_ERROR_MM = 0.005;
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2022-10-08 22:00:05 +00:00
|
|
|
class PAD;
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2024-04-22 00:39:43 +00:00
|
|
|
class TDocStd_Document;
|
|
|
|
class XCAFApp_Application;
|
|
|
|
class XCAFDoc_ShapeTool;
|
|
|
|
|
2022-10-08 22:00:05 +00:00
|
|
|
typedef std::pair< std::string, TDF_Label > MODEL_DATUM;
|
|
|
|
typedef std::map< std::string, TDF_Label > MODEL_MAP;
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2022-10-08 22:00:05 +00:00
|
|
|
extern void ReportMessage( const wxString& aMessage );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2022-10-08 22:00:05 +00:00
|
|
|
class STEP_PCB_MODEL
|
2021-07-29 11:10:58 +00:00
|
|
|
{
|
2016-09-02 10:08:40 +00:00
|
|
|
public:
|
2022-10-08 22:00:05 +00:00
|
|
|
STEP_PCB_MODEL( const wxString& aPcbName );
|
|
|
|
virtual ~STEP_PCB_MODEL();
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2023-08-27 17:37:28 +00:00
|
|
|
// add a pad shape (must be in final position)
|
2024-04-25 12:34:49 +00:00
|
|
|
bool AddPadShape( const PAD* aPad, const VECTOR2D& aOrigin, bool aVia );
|
2023-03-02 18:38:19 +00:00
|
|
|
|
2024-05-19 01:28:43 +00:00
|
|
|
// add a pad hole or slot (must be in final position)
|
|
|
|
bool AddHole( const SHAPE_SEGMENT& aShape, int aPlatingThickness, PCB_LAYER_ID aLayerTop,
|
|
|
|
PCB_LAYER_ID aLayerBot, bool aVia, const VECTOR2D& aOrigin );
|
2023-08-27 17:37:28 +00:00
|
|
|
|
2024-05-19 01:28:43 +00:00
|
|
|
// add a plated hole shape (without the hole)
|
|
|
|
bool AddBarrel( const SHAPE_SEGMENT& aShape, PCB_LAYER_ID aLayerTop, PCB_LAYER_ID aLayerBot,
|
|
|
|
bool aVia, const VECTOR2D& aOrigin );
|
2023-08-27 17:37:28 +00:00
|
|
|
|
2024-05-19 01:28:43 +00:00
|
|
|
// add a set of polygons (must be in final position)
|
|
|
|
bool AddPolygonShapes( const SHAPE_POLY_SET* aPolyShapes, PCB_LAYER_ID aLayer,
|
|
|
|
const VECTOR2D& aOrigin );
|
2023-03-02 18:38:19 +00:00
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
// add a component at the given position and orientation
|
2022-10-08 22:00:05 +00:00
|
|
|
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 );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2023-03-06 10:47:29 +00:00
|
|
|
void SetCopperColor( double r, double g, double b );
|
2024-05-19 01:28:43 +00:00
|
|
|
void SetPadColor( double r, double g, double b );
|
2022-05-09 20:02:33 +00:00
|
|
|
|
2024-04-22 00:39:43 +00:00
|
|
|
void SetEnabledLayers( const LSET& aLayers );
|
2024-04-19 00:42:41 +00:00
|
|
|
void SetFuseShapes( bool aValue );
|
2024-05-19 01:28:43 +00:00
|
|
|
void SetSimplifyShapes( bool aValue );
|
|
|
|
void SetAddVisMaterials( bool aValue );
|
2024-04-22 00:39:43 +00:00
|
|
|
void SetStackup( const BOARD_STACKUP& aStackup );
|
2024-04-24 15:28:44 +00:00
|
|
|
void SetNetFilter( const wxString& aFilter );
|
|
|
|
|
2023-03-02 18:38:19 +00:00
|
|
|
// Set the max distance (in mm) to consider 2 points have the same coordinates
|
|
|
|
// and can be merged
|
|
|
|
void OCCSetMergeMaxDistance( double aDistance = OCC_MAX_DISTANCE_TO_MERGE_POINTS );
|
2018-06-19 08:14:10 +00:00
|
|
|
|
2022-10-08 22:00:05 +00:00
|
|
|
void SetMaxError( int aMaxError ) { m_maxError = aMaxError; }
|
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
// create the PCB model using the current outlines and drill holes
|
2024-04-22 00:39:43 +00:00
|
|
|
bool CreatePCB( SHAPE_POLY_SET& aOutline, VECTOR2D aOrigin, bool aPushBoardBody );
|
2022-10-08 22:00:05 +00:00
|
|
|
|
2023-05-16 11:39:16 +00:00
|
|
|
/**
|
2024-05-19 01:28:43 +00:00
|
|
|
* Convert a SHAPE_POLY_SET to TopoDS_Shape's (polygonal vertical prisms, or flat faces)
|
2023-08-24 00:47:51 +00:00
|
|
|
* @param aShapes is the TopoDS_Shape list to append to
|
|
|
|
* @param aPolySet is a polygon set
|
2024-04-23 16:25:17 +00:00
|
|
|
* @param aConvertToArcs set to approximate with arcs
|
2024-05-19 01:28:43 +00:00
|
|
|
* @param aThickness is the height of the created prism, or 0.0: flat face pointing up, -0.0: down.
|
2023-05-16 11:39:16 +00:00
|
|
|
* @param aOrigin is the origin of the coordinates
|
|
|
|
* @return true if success
|
|
|
|
*/
|
2023-08-24 00:47:51 +00:00
|
|
|
bool MakeShapes( std::vector<TopoDS_Shape>& aShapes, const SHAPE_POLY_SET& aPolySet,
|
2024-04-23 16:25:17 +00:00
|
|
|
bool aConvertToArcs, double aThickness, double aZposition,
|
|
|
|
const VECTOR2D& aOrigin );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2023-05-16 11:39:16 +00:00
|
|
|
/**
|
2024-05-19 01:28:43 +00:00
|
|
|
* Make a segment shape based on start and end point. If they're too close, make a cylinder.
|
|
|
|
* It is a specialized version of MakeShape()
|
2023-08-23 16:11:43 +00:00
|
|
|
* @param aShape is the TopoDS_Shape to initialize (must be empty)
|
|
|
|
* @param aStartPoint is the start point of the segment
|
|
|
|
* @param aEndPoint is the end point of the segment
|
|
|
|
* @param aWidth is the width of the segment
|
2024-05-19 01:28:43 +00:00
|
|
|
* @param aThickness is the height of the created segment, or 0.0: flat face pointing up, -0.0: down.
|
2023-08-23 16:11:43 +00:00
|
|
|
* @param aOrigin is the origin of the coordinates
|
|
|
|
* @return true if success
|
|
|
|
*/
|
|
|
|
bool MakeShapeAsThickSegment( TopoDS_Shape& aShape,
|
|
|
|
VECTOR2D aStartPoint, VECTOR2D aEndPoint,
|
|
|
|
double aWidth, double aThickness, double aZposition,
|
|
|
|
const VECTOR2D& aOrigin );
|
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
#ifdef SUPPORTS_IGES
|
|
|
|
// write the assembly model in IGES format
|
2018-09-20 09:05:52 +00:00
|
|
|
bool WriteIGES( const wxString& aFileName );
|
2016-09-02 10:08:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// write the assembly model in STEP format
|
2023-11-19 12:21:25 +00:00
|
|
|
bool WriteSTEP( const wxString& aFileName, bool aOptimize );
|
2021-07-29 11:10:58 +00:00
|
|
|
|
2024-04-17 14:31:07 +00:00
|
|
|
// write the assembly in BREP format
|
|
|
|
bool WriteBREP( const wxString& aFileName );
|
|
|
|
|
2024-04-25 22:53:39 +00:00
|
|
|
// write the assembly in XAO format with pad faces as groups
|
|
|
|
bool WriteXAO( const wxString& aFileName );
|
|
|
|
|
2023-08-19 15:40:45 +00:00
|
|
|
/**
|
|
|
|
* Write the assembly in binary GLTF Format
|
|
|
|
*
|
|
|
|
* We only support binary GLTF because GLTF is weird
|
|
|
|
* Officially, binary GLTF is actually json+binary in one file
|
|
|
|
* If we elected non-binary output with opecascade, it will generate
|
|
|
|
* that one file as two separate files, one containing json that references the binary
|
|
|
|
* Which is actually more annoying to deal with (to do the temp file rename, since we dont
|
|
|
|
* control the binary name) and silly when you can just have the one file.
|
|
|
|
*
|
|
|
|
* @param aFileName Output file path
|
|
|
|
*
|
|
|
|
* @return true if the write succeeded without error
|
|
|
|
*/
|
|
|
|
bool WriteGLTF( const wxString& aFileName );
|
|
|
|
|
2021-07-29 11:10:58 +00:00
|
|
|
private:
|
2022-11-15 15:37:00 +00:00
|
|
|
/**
|
|
|
|
* @return true if the board(s) outline is valid. False otherwise
|
|
|
|
*/
|
|
|
|
bool isBoardOutlineValid();
|
|
|
|
|
2024-04-22 00:39:43 +00:00
|
|
|
void getLayerZPlacement( const PCB_LAYER_ID aLayer, double& aZPos, double& aThickness );
|
|
|
|
|
2024-05-17 15:19:44 +00:00
|
|
|
void getCopperLayerZPlacement( const PCB_LAYER_ID aLayer, double& aZPos, double& aThickness );
|
|
|
|
|
2024-04-22 00:39:43 +00:00
|
|
|
void getBoardBodyZPlacement( double& aZPos, double& aThickness );
|
2022-11-15 15:37:00 +00:00
|
|
|
|
2021-07-29 11:10:58 +00:00
|
|
|
/**
|
|
|
|
* Load a 3D model data.
|
|
|
|
*
|
2021-08-27 12:34:49 +00:00
|
|
|
* @param aFileNameUTF8 is the filename encoded UTF8 (different formats allowed)
|
|
|
|
* but for WRML files a model data can be loaded instead of the vrml data,
|
|
|
|
* not suitable in a step file.
|
2021-07-29 11:10:58 +00:00
|
|
|
* @param aScale is the X,Y,Z scaling factors.
|
|
|
|
* @param aLabel is the TDF_Label to store the data.
|
|
|
|
* @param aSubstituteModels = true to allows data substitution, false to disallow.
|
|
|
|
* @param aErrorMessage (can be nullptr) is an error message to be displayed on error.
|
|
|
|
* @return true if successfully loaded, false on error.
|
|
|
|
*/
|
2022-10-08 22:00:05 +00:00
|
|
|
bool getModelLabel( const std::string& aFileNameUTF8, VECTOR3D aScale, TDF_Label& aLabel,
|
2021-07-29 11:10:58 +00:00
|
|
|
bool aSubstituteModels, wxString* aErrorMessage = nullptr );
|
|
|
|
|
2022-10-08 22:00:05 +00:00
|
|
|
bool getModelLocation( bool aBottom, VECTOR2D aPosition, double aRotation, VECTOR3D aOffset,
|
|
|
|
VECTOR3D aOrientation, TopLoc_Location& aLocation );
|
2021-07-29 11:10:58 +00:00
|
|
|
|
2024-05-16 18:57:44 +00:00
|
|
|
bool readIGES( Handle( TDocStd_Document ) & aDoc, const char* aFname );
|
|
|
|
bool readSTEP( Handle( TDocStd_Document ) & aDoc, const char* aFname );
|
|
|
|
bool readVRML( Handle( TDocStd_Document ) & aDoc, const char* aFname );
|
2021-07-29 11:10:58 +00:00
|
|
|
|
2022-10-08 22:00:05 +00:00
|
|
|
TDF_Label transferModel( Handle( TDocStd_Document )& source, Handle( TDocStd_Document ) & dest,
|
|
|
|
VECTOR3D aScale );
|
2021-07-29 11:10:58 +00:00
|
|
|
|
|
|
|
Handle( XCAFApp_Application ) m_app;
|
|
|
|
Handle( TDocStd_Document ) m_doc;
|
|
|
|
Handle( XCAFDoc_ShapeTool ) m_assy;
|
|
|
|
TDF_Label m_assy_label;
|
2023-03-02 18:38:19 +00:00
|
|
|
bool m_hasPCB; // set true if CreatePCB() has been invoked
|
2024-05-19 01:28:43 +00:00
|
|
|
bool m_simplifyShapes; // convert parts of outlines to arcs where possible
|
2024-04-19 00:42:41 +00:00
|
|
|
bool m_fuseShapes; // fuse geometry together
|
2023-03-02 18:38:19 +00:00
|
|
|
std::vector<TDF_Label> m_pcb_labels; // labels for the PCB model (one by main outline)
|
|
|
|
MODEL_MAP m_models; // map of file names to model labels
|
|
|
|
int m_components; // number of successfully loaded components;
|
|
|
|
double m_precision; // model (length unit) numeric precision
|
|
|
|
double m_angleprec; // angle numeric precision
|
2023-03-06 10:47:29 +00:00
|
|
|
double m_copperColor[3]; // copper, RGB values
|
2024-05-19 01:28:43 +00:00
|
|
|
double m_padColor[3]; // pads, RGB values
|
2024-04-22 00:39:43 +00:00
|
|
|
BOARD_STACKUP m_stackup; // board stackup
|
|
|
|
LSET m_enabledLayers; // a set of layers enabled for export
|
2024-04-24 15:28:44 +00:00
|
|
|
wxString m_netFilter; // remove nets not matching this wildcard
|
2023-03-02 18:38:19 +00:00
|
|
|
|
|
|
|
double m_minx; // leftmost curve point
|
|
|
|
double m_mergeOCCMaxDist; // minimum distance (mm) below which two
|
|
|
|
// points are considered coincident by OCC
|
|
|
|
|
2024-02-01 21:29:03 +00:00
|
|
|
// Holes in copper and main outlines
|
|
|
|
std::vector<TopoDS_Shape> m_copperCutouts;
|
|
|
|
std::vector<TopoDS_Shape> m_boardCutouts;
|
2022-07-06 21:32:52 +00:00
|
|
|
|
2023-03-02 18:38:19 +00:00
|
|
|
// Main outlines (more than one board)
|
2023-08-21 02:10:43 +00:00
|
|
|
std::vector<TopoDS_Shape> m_board_outlines;
|
2024-05-19 01:28:43 +00:00
|
|
|
std::vector<TopoDS_Shape> m_board_copper;
|
2023-08-21 02:10:43 +00:00
|
|
|
std::vector<TopoDS_Shape> m_board_copper_pads;
|
2024-05-19 01:28:43 +00:00
|
|
|
std::vector<TopoDS_Shape> m_board_copper_vias;
|
2024-04-19 00:42:41 +00:00
|
|
|
std::vector<TopoDS_Shape> m_board_copper_fused;
|
2024-05-19 01:28:43 +00:00
|
|
|
std::vector<TopoDS_Shape> m_board_silkscreen;
|
|
|
|
std::vector<TopoDS_Shape> m_board_soldermask;
|
2023-03-02 18:38:19 +00:00
|
|
|
|
2024-04-25 22:53:39 +00:00
|
|
|
// Data for pads
|
|
|
|
std::map<wxString, std::pair<gp_Pnt, TopoDS_Shape>> m_pad_points;
|
|
|
|
|
2022-07-06 21:32:52 +00:00
|
|
|
/// Name of the PCB, which will most likely be the file name of the path.
|
|
|
|
wxString m_pcbName;
|
2022-10-08 22:00:05 +00:00
|
|
|
|
|
|
|
int m_maxError;
|
2016-09-02 10:08:40 +00:00
|
|
|
};
|
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
#endif // OCE_VIS_OCE_UTILS_H
|