2021-03-16 19:15:34 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-05-19 22:53:42 +00:00
|
|
|
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-03-16 19:15:34 +00:00
|
|
|
*
|
2022-06-28 16:57:15 +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 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2021-03-16 19:15:34 +00:00
|
|
|
*
|
2022-06-28 16:57:15 +00:00
|
|
|
* 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.
|
2021-03-16 19:15:34 +00:00
|
|
|
*
|
2022-06-28 16:57:15 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2021-03-16 19:15:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-05-19 22:53:42 +00:00
|
|
|
#include <dialogs/dialog_color_picker.h>
|
2022-06-28 16:57:15 +00:00
|
|
|
#include <export_vrml.h>
|
2022-05-19 22:53:42 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
// offset for art layers, mm (silk, paste, etc)
|
|
|
|
#define ART_OFFSET 0.025
|
|
|
|
// offset for plating
|
|
|
|
#define PLATE_OFFSET 0.005
|
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
class PROJECT;
|
2021-03-16 19:15:34 +00:00
|
|
|
|
|
|
|
enum VRML_COLOR_INDEX
|
|
|
|
{
|
|
|
|
VRML_COLOR_NONE = -1,
|
|
|
|
VRML_COLOR_PCB = 0,
|
|
|
|
VRML_COLOR_COPPER,
|
2022-05-19 22:53:42 +00:00
|
|
|
VRML_COLOR_TOP_SOLDMASK,
|
|
|
|
VRML_COLOR_BOT_SOLDMASK,
|
2021-03-18 13:40:36 +00:00
|
|
|
VRML_COLOR_PASTE,
|
2022-05-19 22:53:42 +00:00
|
|
|
VRML_COLOR_TOP_SILK,
|
|
|
|
VRML_COLOR_BOT_SILK,
|
2021-03-18 13:40:36 +00:00
|
|
|
VRML_COLOR_LAST // Sentinel
|
2021-03-16 19:15:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct VRML_COLOR
|
|
|
|
{
|
|
|
|
float diffuse_red;
|
|
|
|
float diffuse_grn;
|
|
|
|
float diffuse_blu;
|
|
|
|
|
|
|
|
float spec_red;
|
|
|
|
float spec_grn;
|
|
|
|
float spec_blu;
|
|
|
|
|
|
|
|
float emit_red;
|
|
|
|
float emit_grn;
|
|
|
|
float emit_blu;
|
|
|
|
|
|
|
|
float ambient;
|
|
|
|
float transp;
|
|
|
|
float shiny;
|
|
|
|
|
|
|
|
VRML_COLOR()
|
|
|
|
{
|
|
|
|
// default green
|
|
|
|
diffuse_red = 0.13f;
|
|
|
|
diffuse_grn = 0.81f;
|
|
|
|
diffuse_blu = 0.22f;
|
|
|
|
spec_red = 0.01f;
|
|
|
|
spec_grn = 0.08f;
|
|
|
|
spec_blu = 0.02f;
|
|
|
|
emit_red = 0.0f;
|
|
|
|
emit_grn = 0.0f;
|
|
|
|
emit_blu = 0.0f;
|
|
|
|
|
|
|
|
ambient = 0.8f;
|
|
|
|
transp = 0.0f;
|
|
|
|
shiny = 0.02f;
|
|
|
|
}
|
|
|
|
|
|
|
|
VRML_COLOR( float dr, float dg, float db,
|
|
|
|
float sr, float sg, float sb,
|
|
|
|
float am, float tr, float sh )
|
|
|
|
{
|
|
|
|
diffuse_red = dr;
|
|
|
|
diffuse_grn = dg;
|
|
|
|
diffuse_blu = db;
|
|
|
|
spec_red = sr;
|
|
|
|
spec_grn = sg;
|
|
|
|
spec_blu = sb;
|
2022-05-19 22:53:42 +00:00
|
|
|
emit_red = 0.0f;
|
|
|
|
emit_grn = 0.0f;
|
|
|
|
emit_blu = 0.0f;
|
2021-03-16 19:15:34 +00:00
|
|
|
|
|
|
|
ambient = am;
|
|
|
|
transp = tr;
|
|
|
|
shiny = sh;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Handle the board and its board items to convert them to a VRML representation:
|
2021-03-18 18:53:36 +00:00
|
|
|
class EXPORTER_PCB_VRML
|
2021-03-16 19:15:34 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-06-28 16:57:15 +00:00
|
|
|
EXPORTER_PCB_VRML( BOARD* aBoard );
|
2021-03-18 18:53:36 +00:00
|
|
|
~EXPORTER_PCB_VRML();
|
2021-03-16 19:15:34 +00:00
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
/**
|
|
|
|
* Export a VRML file image of the board.
|
|
|
|
* @param aProject is the current project (cannot be null)
|
|
|
|
* @param aMessages will contain error message(s)
|
|
|
|
* @param aFullFileName the full filename of the file to create
|
|
|
|
* @param aMMtoWRMLunit the VRML scaling factor: 1.0 to export in mm. 0.001 for meters
|
|
|
|
* @param aExport3DFiles true to copy 3D shapes in the subir a3D_Subdir
|
|
|
|
* @param aUseRelativePaths set to true to use relative paths instead of absolute paths
|
|
|
|
* in the board VRML file URLs.
|
|
|
|
* @param a3D_Subdir sub directory where 3D shapes files are copied. This is only used
|
|
|
|
* when aExport3DFiles == true.
|
|
|
|
* @param aXRef X value of PCB (0,0) reference point.
|
|
|
|
* @param aYRef Y value of PCB (0,0) reference point.
|
|
|
|
* @return true if Ok.
|
|
|
|
*/
|
|
|
|
bool ExportVRML_File( PROJECT* aProject, wxString *aMessages,
|
|
|
|
const wxString& aFullFileName, double aMMtoWRMLunit,
|
2024-03-04 15:05:53 +00:00
|
|
|
bool aIncludeUnspecified, bool aIncludeDNP,
|
2022-06-28 16:57:15 +00:00
|
|
|
bool aExport3DFiles, bool aUseRelativePaths,
|
|
|
|
const wxString& a3D_Subdir,
|
|
|
|
double aXRef, double aYRef );
|
|
|
|
|
|
|
|
private:
|
2021-03-16 19:15:34 +00:00
|
|
|
VRML_COLOR& GetColor( VRML_COLOR_INDEX aIndex )
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
return vrml_colors_list[aIndex];
|
2021-03-16 19:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetOffset( double aXoff, double aYoff );
|
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
double GetLayerZ( int aLayer )
|
2021-03-16 19:15:34 +00:00
|
|
|
{
|
|
|
|
if( unsigned( aLayer ) >= arrayDim( m_layer_z ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return m_layer_z[ aLayer ];
|
|
|
|
}
|
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
void SetLayerZ( int aLayer, double aValue )
|
2021-03-16 19:15:34 +00:00
|
|
|
{
|
|
|
|
m_layer_z[aLayer] = aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the scaling of the VRML world
|
|
|
|
bool SetScale( double aWorldScale );
|
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
// Initialize the list of colors used in VRML export.
|
|
|
|
void initStaticColorList();
|
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
// Build and export the solder mask layer, that is a negative layer
|
2021-03-18 13:40:36 +00:00
|
|
|
void ExportVrmlSolderMask();
|
2021-03-16 19:15:34 +00:00
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
// Build and export the 4 layers F_Cu, B_Cu, F_SilkS, B_SilkS
|
|
|
|
void ExportStandardLayers();
|
2021-03-16 19:15:34 +00:00
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
void ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream* aOutputFile );
|
2021-03-16 19:15:34 +00:00
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
// Build and exports the board outlines (board body)
|
|
|
|
void ExportVrmlBoard();
|
2021-03-16 19:15:34 +00:00
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
// Export all via holes
|
|
|
|
void ExportVrmlViaHoles();
|
2021-03-17 13:26:26 +00:00
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
void ExportFp3DModelsAsLinkedFile( const wxString& aFullFileName );
|
2021-03-17 13:26:26 +00:00
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
void ExportVrmlPadHole( PAD* aPad );
|
2021-03-16 19:15:34 +00:00
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
// Export a set of polygons without holes.
|
2021-03-20 10:13:18 +00:00
|
|
|
// Polygons in SHAPE_POLY_SET must be without hole, i.e. holes must be linked
|
|
|
|
// previously to their main outline.
|
|
|
|
void ExportVrmlPolygonSet( VRML_LAYER* aVlayer, const SHAPE_POLY_SET& aOutlines );
|
2021-03-18 13:40:36 +00:00
|
|
|
|
|
|
|
void writeLayers( const char* aFileName, OSTREAM* aOutputFile );
|
2021-03-17 13:26:26 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
// select the VRML layer object to draw on
|
|
|
|
// return true if a layer has been selected.
|
2021-07-21 23:14:56 +00:00
|
|
|
bool GetLayer3D( int layer, VRML_LAYER** vlayer );
|
2021-03-16 19:15:34 +00:00
|
|
|
|
|
|
|
// Build the Z position of 3D layers
|
2021-03-18 13:40:36 +00:00
|
|
|
void ComputeLayer3D_Zpos();
|
2021-03-16 19:15:34 +00:00
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
void write_triangle_bag( std::ostream& aOut_file, const VRML_COLOR& aColor, VRML_LAYER* aLayer,
|
|
|
|
bool aPlane, bool aTop, double aTop_z, double aBottom_z );
|
2021-03-17 13:26:26 +00:00
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER* layer,
|
|
|
|
double top_z, double bottom_z );
|
2021-03-17 13:26:26 +00:00
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, VRML_LAYER* layer,
|
|
|
|
double aHeight, bool aTopPlane );
|
2021-03-17 13:26:26 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
SGNODE* getSGColor( VRML_COLOR_INDEX colorIdx );
|
2021-06-04 17:44:22 +00:00
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
static CUSTOM_COLORS_LIST m_SilkscreenColors;
|
|
|
|
static CUSTOM_COLORS_LIST m_MaskColors;
|
|
|
|
static CUSTOM_COLORS_LIST m_PasteColors;
|
|
|
|
static CUSTOM_COLORS_LIST m_FinishColors;
|
|
|
|
static CUSTOM_COLORS_LIST m_BoardColors;
|
|
|
|
|
|
|
|
static KIGFX::COLOR4D m_DefaultBackgroundTop;
|
|
|
|
static KIGFX::COLOR4D m_DefaultBackgroundBot;
|
|
|
|
static KIGFX::COLOR4D m_DefaultSilkscreen;
|
|
|
|
static KIGFX::COLOR4D m_DefaultSolderMask;
|
|
|
|
static KIGFX::COLOR4D m_DefaultSolderPaste;
|
|
|
|
static KIGFX::COLOR4D m_DefaultSurfaceFinish;
|
|
|
|
static KIGFX::COLOR4D m_DefaultBoardBody;
|
2022-05-19 22:53:42 +00:00
|
|
|
|
|
|
|
IFSG_TRANSFORM m_OutputPCB;
|
|
|
|
VRML_LAYER m_holes;
|
|
|
|
VRML_LAYER m_3D_board;
|
|
|
|
VRML_LAYER m_top_copper;
|
|
|
|
VRML_LAYER m_bot_copper;
|
|
|
|
VRML_LAYER m_top_silk;
|
|
|
|
VRML_LAYER m_bot_silk;
|
|
|
|
VRML_LAYER m_top_soldermask;
|
|
|
|
VRML_LAYER m_bot_soldermask;
|
|
|
|
VRML_LAYER m_top_paste;
|
|
|
|
VRML_LAYER m_bot_paste;
|
|
|
|
VRML_LAYER m_plated_holes;
|
|
|
|
|
|
|
|
std::list<SGNODE*> m_components;
|
|
|
|
S3D_CACHE* m_Cache3Dmodels;
|
2021-06-04 17:44:22 +00:00
|
|
|
|
|
|
|
/* true to use VRML inline{} syntax for footprint 3D models, like:
|
|
|
|
* Inline { url "F:/tmp/pic_programmer/shapes3D/DIP-18_W7.62mm_Socket.wrl" }
|
|
|
|
* false to merge VRML 3D modules in the .wrl board file
|
|
|
|
*/
|
2022-05-19 22:53:42 +00:00
|
|
|
bool m_UseInlineModelsInBrdfile;
|
2021-06-04 17:44:22 +00:00
|
|
|
|
|
|
|
// 3D subdirectory to copy footprint vrml 3D models when not merged in board file
|
|
|
|
wxString m_Subdir3DFpModels;
|
|
|
|
|
|
|
|
// true to use relative paths in VRML inline{} for footprint 3D models
|
|
|
|
// used only if m_UseInlineModelsInBrdfile = true
|
2022-05-19 22:53:42 +00:00
|
|
|
bool m_UseRelPathIn3DModelFilename;
|
2021-06-04 17:44:22 +00:00
|
|
|
|
|
|
|
// true to reuse component definitions
|
2022-05-19 22:53:42 +00:00
|
|
|
bool m_ReuseDef;
|
2021-06-04 17:44:22 +00:00
|
|
|
|
2024-03-04 15:05:53 +00:00
|
|
|
// true if unspecified components should be included
|
|
|
|
bool m_includeUnspecified;
|
|
|
|
|
|
|
|
// true if DNP components should be included
|
|
|
|
bool m_includeDNP;
|
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
// scaling from 0.1 inch to desired VRML unit
|
2022-05-19 22:53:42 +00:00
|
|
|
double m_WorldScale = 1.0;
|
2021-06-04 17:44:22 +00:00
|
|
|
|
|
|
|
// scaling from mm to desired VRML world scale
|
2022-05-19 22:53:42 +00:00
|
|
|
double m_BoardToVrmlScale;
|
2021-06-04 17:44:22 +00:00
|
|
|
|
2022-05-19 22:53:42 +00:00
|
|
|
double m_tx; // global translation along X
|
|
|
|
double m_ty; // global translation along Y
|
2021-06-04 17:44:22 +00:00
|
|
|
|
2022-05-19 22:53:42 +00:00
|
|
|
double m_brd_thickness; // depth of the PCB
|
2021-06-04 17:44:22 +00:00
|
|
|
|
|
|
|
private:
|
2022-06-28 16:57:15 +00:00
|
|
|
BOARD* m_board;
|
2021-06-04 17:44:22 +00:00
|
|
|
VRML_COLOR vrml_colors_list[VRML_COLOR_LAST];
|
|
|
|
double m_layer_z[PCB_LAYER_ID_COUNT];
|
|
|
|
SHAPE_POLY_SET m_pcbOutlines; // stores the board main outlines
|
|
|
|
|
|
|
|
int m_precision; // precision factor when exporting fp shapes
|
|
|
|
// to separate files
|
|
|
|
SGNODE* m_sgmaterial[VRML_COLOR_LAST];
|
2021-03-16 19:15:34 +00:00
|
|
|
};
|