2013-01-13 16:55:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009-2013 Lorenzo Mercantonio
|
2017-03-02 22:53:49 +00:00
|
|
|
* Copyright (C) 2014-2017 Cirilo Bernardo
|
2018-01-24 13:22:43 +00:00
|
|
|
* Copyright (C) 2018 Jean-Pierre Charras jp.charras at wanadoo.fr
|
2022-01-13 13:45:48 +00:00
|
|
|
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-01-13 16:55:07 +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.
|
2013-01-13 16:55:07 +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.
|
2013-01-13 16:55:07 +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/>.
|
2013-01-13 16:55:07 +00:00
|
|
|
*/
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
#include <exception>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iomanip>
|
2010-11-27 13:09:18 +00:00
|
|
|
#include <vector>
|
2016-09-17 06:14:49 +00:00
|
|
|
#include <wx/dir.h>
|
2021-06-06 12:41:16 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2022-08-30 13:15:54 +00:00
|
|
|
#include <wx/wfstream.h>
|
|
|
|
#include <wx/zstream.h>
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
#include "3d_cache/3d_cache.h"
|
|
|
|
#include "3d_cache/3d_info.h"
|
2020-11-12 20:19:22 +00:00
|
|
|
#include "board.h"
|
2021-06-06 19:03:10 +00:00
|
|
|
#include "board_design_settings.h"
|
2022-09-26 03:40:25 +00:00
|
|
|
#include <fp_lib_table.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include "footprint.h"
|
2021-06-06 19:03:10 +00:00
|
|
|
#include "pad.h"
|
2020-10-04 23:34:59 +00:00
|
|
|
#include "pcb_text.h"
|
2021-06-11 21:07:02 +00:00
|
|
|
#include "pcb_track.h"
|
2023-09-28 03:15:54 +00:00
|
|
|
#include <project_pcb.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/arraydim.h>
|
2020-01-15 23:32:05 +00:00
|
|
|
#include <filename_resolver.h>
|
2016-09-17 06:14:49 +00:00
|
|
|
#include "plugins/3dapi/ifsg_all.h"
|
2017-03-02 22:53:49 +00:00
|
|
|
#include "streamwrapper.h"
|
2016-09-17 06:14:49 +00:00
|
|
|
#include "vrml_layer.h"
|
2018-01-29 20:58:58 +00:00
|
|
|
#include "pcb_edit_frame.h"
|
2021-01-10 19:28:15 +00:00
|
|
|
|
2018-03-05 20:54:10 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2019-05-16 13:46:54 +00:00
|
|
|
#include <geometry/geometry_utils.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
#include <exporter_vrml.h>
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
EXPORTER_VRML::EXPORTER_VRML( BOARD* aBoard )
|
|
|
|
{
|
|
|
|
pcb_exporter = new EXPORTER_PCB_VRML( aBoard );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EXPORTER_VRML::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 )
|
|
|
|
{
|
|
|
|
return pcb_exporter->ExportVRML_File( aProject, aMessages,
|
|
|
|
aFullFileName, aMMtoWRMLunit,
|
2024-03-04 15:05:53 +00:00
|
|
|
aIncludeUnspecified, aIncludeDNP,
|
2022-06-28 16:57:15 +00:00
|
|
|
aExport3DFiles, aUseRelativePaths,
|
|
|
|
a3D_Subdir, aXRef, aYRef );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EXPORTER_VRML::~EXPORTER_VRML()
|
|
|
|
{
|
|
|
|
delete pcb_exporter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-04 09:21:35 +00:00
|
|
|
// The max error (in mm) to approximate arcs to segments:
|
|
|
|
#define ERR_APPROX_MAX_MM 0.005
|
|
|
|
|
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
CUSTOM_COLORS_LIST EXPORTER_PCB_VRML::m_SilkscreenColors;
|
|
|
|
CUSTOM_COLORS_LIST EXPORTER_PCB_VRML::m_MaskColors;
|
|
|
|
CUSTOM_COLORS_LIST EXPORTER_PCB_VRML::m_PasteColors;
|
|
|
|
CUSTOM_COLORS_LIST EXPORTER_PCB_VRML::m_FinishColors;
|
|
|
|
CUSTOM_COLORS_LIST EXPORTER_PCB_VRML::m_BoardColors;
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
KIGFX::COLOR4D EXPORTER_PCB_VRML::m_DefaultSilkscreen;
|
|
|
|
KIGFX::COLOR4D EXPORTER_PCB_VRML::m_DefaultSolderMask;
|
|
|
|
KIGFX::COLOR4D EXPORTER_PCB_VRML::m_DefaultSolderPaste;
|
|
|
|
KIGFX::COLOR4D EXPORTER_PCB_VRML::m_DefaultSurfaceFinish;
|
|
|
|
KIGFX::COLOR4D EXPORTER_PCB_VRML::m_DefaultBoardBody;
|
2022-05-19 22:53:42 +00:00
|
|
|
|
|
|
|
static bool g_ColorsLoaded = false;
|
|
|
|
|
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
EXPORTER_PCB_VRML::EXPORTER_PCB_VRML( BOARD* aBoard ) :
|
2021-07-19 23:56:05 +00:00
|
|
|
m_OutputPCB( nullptr )
|
2021-03-16 19:15:34 +00:00
|
|
|
{
|
2022-06-28 16:57:15 +00:00
|
|
|
m_board = aBoard;
|
2021-03-17 13:26:26 +00:00
|
|
|
m_ReuseDef = true;
|
|
|
|
m_precision = 6;
|
|
|
|
m_WorldScale = 1.0;
|
2021-03-19 13:48:04 +00:00
|
|
|
m_Cache3Dmodels = nullptr;
|
|
|
|
m_UseInlineModelsInBrdfile = false;
|
|
|
|
m_UseRelPathIn3DModelFilename = false;
|
2022-09-16 22:56:24 +00:00
|
|
|
m_BoardToVrmlScale = pcbIUScale.MM_PER_IU;
|
2021-03-17 13:26:26 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
for( int ii = 0; ii < VRML_COLOR_LAST; ++ii )
|
|
|
|
m_sgmaterial[ii] = nullptr;
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
for( unsigned i = 0; i < arrayDim( m_layer_z ); ++i )
|
|
|
|
m_layer_z[i] = 0;
|
|
|
|
|
|
|
|
// this default only makes sense if the output is in mm
|
2022-09-16 11:33:56 +00:00
|
|
|
m_brd_thickness = pcbIUScale.IUTomm( m_board->GetDesignSettings().GetBoardThickness() );
|
2022-05-19 22:53:42 +00:00
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
// TODO: figure out a way to share all these stackup color definitions...
|
|
|
|
initStaticColorList();
|
2022-05-19 22:53:42 +00:00
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
COLOR4D topSilk = m_DefaultSilkscreen;
|
|
|
|
COLOR4D botSilk = m_DefaultSilkscreen;
|
|
|
|
COLOR4D topMask = m_DefaultSolderMask;
|
|
|
|
COLOR4D botMask = m_DefaultSolderMask;
|
|
|
|
COLOR4D paste = m_DefaultSolderPaste;
|
|
|
|
COLOR4D finish = m_DefaultSurfaceFinish;
|
2022-05-19 22:53:42 +00:00
|
|
|
COLOR4D boardBody( 0, 0, 0, 0 );
|
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
const BOARD_STACKUP& stackup = m_board->GetDesignSettings().GetStackupDescriptor();
|
2022-05-19 22:53:42 +00:00
|
|
|
|
|
|
|
auto findColor =
|
|
|
|
[]( const wxString& aColorName, const CUSTOM_COLORS_LIST& aColorSet )
|
|
|
|
{
|
|
|
|
if( aColorName.StartsWith( wxT( "#" ) ) )
|
|
|
|
{
|
|
|
|
return KIGFX::COLOR4D( aColorName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( const CUSTOM_COLOR_ITEM& color : aColorSet )
|
|
|
|
{
|
|
|
|
if( color.m_ColorName == aColorName )
|
|
|
|
return color.m_Color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return KIGFX::COLOR4D();
|
|
|
|
};
|
|
|
|
|
|
|
|
for( const BOARD_STACKUP_ITEM* stackupItem : stackup.GetList() )
|
|
|
|
{
|
|
|
|
wxString colorName = stackupItem->GetColor();
|
|
|
|
|
|
|
|
switch( stackupItem->GetType() )
|
|
|
|
{
|
|
|
|
case BS_ITEM_TYPE_SILKSCREEN:
|
|
|
|
if( stackupItem->GetBrdLayerId() == F_SilkS )
|
2022-06-28 16:57:15 +00:00
|
|
|
topSilk = findColor( colorName, m_SilkscreenColors );
|
2022-05-19 22:53:42 +00:00
|
|
|
else
|
2022-06-28 16:57:15 +00:00
|
|
|
botSilk = findColor( colorName, m_SilkscreenColors );
|
2022-05-19 22:53:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BS_ITEM_TYPE_SOLDERMASK:
|
|
|
|
if( stackupItem->GetBrdLayerId() == F_Mask )
|
2022-06-28 16:57:15 +00:00
|
|
|
topMask = findColor( colorName, m_MaskColors );
|
2022-05-19 22:53:42 +00:00
|
|
|
else
|
2022-06-28 16:57:15 +00:00
|
|
|
botMask = findColor( colorName, m_MaskColors );
|
2022-05-19 22:53:42 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BS_ITEM_TYPE_DIELECTRIC:
|
|
|
|
{
|
2022-06-28 16:57:15 +00:00
|
|
|
KIGFX::COLOR4D layerColor = findColor( colorName, m_BoardColors );
|
2022-05-19 22:53:42 +00:00
|
|
|
|
|
|
|
if( boardBody == COLOR4D( 0, 0, 0, 0 ) )
|
|
|
|
boardBody = layerColor;
|
|
|
|
else
|
|
|
|
boardBody = boardBody.Mix( layerColor, 1.0 - layerColor.a );
|
|
|
|
|
|
|
|
boardBody.a += ( 1.0 - boardBody.a ) * layerColor.a / 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( boardBody == COLOR4D( 0, 0, 0, 0 ) )
|
2022-06-28 16:57:15 +00:00
|
|
|
boardBody = m_DefaultBoardBody;
|
2022-05-19 22:53:42 +00:00
|
|
|
|
|
|
|
const wxString& finishName = stackup.m_FinishType;
|
|
|
|
|
|
|
|
if( finishName.EndsWith( wxT( "OSP" ) ) )
|
|
|
|
{
|
2022-06-28 16:57:15 +00:00
|
|
|
finish = findColor( wxT( "Copper" ), m_FinishColors );
|
2022-05-19 22:53:42 +00:00
|
|
|
}
|
|
|
|
else if( finishName.EndsWith( wxT( "IG" ) )
|
|
|
|
|| finishName.EndsWith( wxT( "gold" ) ) )
|
|
|
|
{
|
2022-06-28 16:57:15 +00:00
|
|
|
finish = findColor( wxT( "Gold" ), m_FinishColors );
|
2022-05-19 22:53:42 +00:00
|
|
|
}
|
|
|
|
else if( finishName.StartsWith( wxT( "HAL" ) )
|
|
|
|
|| finishName.StartsWith( wxT( "HASL" ) )
|
|
|
|
|| finishName.EndsWith( wxT( "tin" ) )
|
|
|
|
|| finishName.EndsWith( wxT( "nickel" ) ) )
|
|
|
|
{
|
2022-06-28 16:57:15 +00:00
|
|
|
finish = findColor( wxT( "Tin" ), m_FinishColors );
|
2022-05-19 22:53:42 +00:00
|
|
|
}
|
|
|
|
else if( finishName.EndsWith( wxT( "silver" ) ) )
|
|
|
|
{
|
2022-06-28 16:57:15 +00:00
|
|
|
finish = findColor( wxT( "Silver" ), m_FinishColors );
|
2022-05-19 22:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto toVRMLColor =
|
|
|
|
[]( const COLOR4D& aColor, double aSpecular, double aAmbient, double aShiny )
|
|
|
|
{
|
|
|
|
COLOR4D diff = aColor;
|
|
|
|
COLOR4D spec = aColor.Brightened( aSpecular );
|
|
|
|
|
|
|
|
return VRML_COLOR( diff.r, diff.g, diff.b,
|
|
|
|
spec.r, spec.g, spec.b,
|
|
|
|
aAmbient, 1.0 - aColor.a, aShiny );
|
|
|
|
};
|
|
|
|
|
|
|
|
vrml_colors_list[VRML_COLOR_TOP_SILK] = toVRMLColor( topSilk, 0.1, 0.7, 0.02 );
|
|
|
|
vrml_colors_list[VRML_COLOR_BOT_SILK] = toVRMLColor( botSilk, 0.1, 0.7, 0.02 );
|
|
|
|
vrml_colors_list[VRML_COLOR_TOP_SOLDMASK] = toVRMLColor( topMask, 0.3, 0.8, 0.30 );
|
|
|
|
vrml_colors_list[VRML_COLOR_BOT_SOLDMASK] = toVRMLColor( botMask, 0.3, 0.8, 0.30 );
|
|
|
|
vrml_colors_list[VRML_COLOR_PASTE] = toVRMLColor( paste, 0.6, 0.7, 0.70 );
|
|
|
|
vrml_colors_list[VRML_COLOR_COPPER] = toVRMLColor( finish, 0.6, 0.7, 0.90 );
|
|
|
|
vrml_colors_list[VRML_COLOR_PCB] = toVRMLColor( boardBody, 0.1, 0.7, 0.01 );
|
2021-03-16 19:15:34 +00:00
|
|
|
|
|
|
|
SetOffset( 0.0, 0.0 );
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
EXPORTER_PCB_VRML::~EXPORTER_PCB_VRML()
|
2021-03-16 19:15:34 +00:00
|
|
|
{
|
|
|
|
// destroy any unassociated material appearances
|
|
|
|
for( int j = 0; j < VRML_COLOR_LAST; ++j )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
if( m_sgmaterial[j] && nullptr == S3D::GetSGNodeParent( m_sgmaterial[j] ) )
|
2021-03-18 12:28:24 +00:00
|
|
|
S3D::DestroyNode( m_sgmaterial[j] );
|
2021-03-16 19:15:34 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
m_sgmaterial[j] = nullptr;
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
if( !m_components.empty() )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
IFSG_TRANSFORM tmp( false );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
for( auto i : m_components )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
tmp.Attach( i );
|
2021-07-19 23:56:05 +00:00
|
|
|
tmp.SetParent( nullptr );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
m_components.clear();
|
|
|
|
m_OutputPCB.Destroy();
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
2021-03-16 19:15:34 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
void EXPORTER_PCB_VRML::initStaticColorList()
|
|
|
|
{
|
|
|
|
// Initialize the list of colors used in VRML export, but only once.
|
Fix typos in pcbnew sub-directory
Found via `codespell -q 3 -S *.po,./thirdparty,./Documentation/changelogs -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,ba,busses,dout,einstance,leaded,modul,ontext,ot,overide,serie,te,,tesselate,tesselator,tht`
2022-06-29 20:21:10 +00:00
|
|
|
// (The list is static)
|
2022-06-28 16:57:15 +00:00
|
|
|
if( g_ColorsLoaded )
|
|
|
|
return;
|
|
|
|
|
|
|
|
#define ADD_COLOR( list, r, g, b, a, name ) \
|
|
|
|
list.emplace_back( r/255.0, g/255.0, b/255.0, a, name )
|
|
|
|
|
|
|
|
ADD_COLOR( m_SilkscreenColors, 245, 245, 245, 1.0, _HKI( "Not specified" ) ); // White
|
|
|
|
ADD_COLOR( m_SilkscreenColors, 20, 51, 36, 1.0, wxT( "Green" ) );
|
|
|
|
ADD_COLOR( m_SilkscreenColors, 181, 19, 21, 1.0, wxT( "Red" ) );
|
|
|
|
ADD_COLOR( m_SilkscreenColors, 2, 59, 162, 1.0, wxT( "Blue" ) );
|
|
|
|
ADD_COLOR( m_SilkscreenColors, 11, 11, 11, 1.0, wxT( "Black" ) );
|
|
|
|
ADD_COLOR( m_SilkscreenColors, 245, 245, 245, 1.0, wxT( "White" ) );
|
|
|
|
ADD_COLOR( m_SilkscreenColors, 32, 2, 53, 1.0, wxT( "Purple" ) );
|
|
|
|
ADD_COLOR( m_SilkscreenColors, 194, 195, 0, 1.0, wxT( "Yellow" ) );
|
|
|
|
|
|
|
|
ADD_COLOR( m_MaskColors, 20, 51, 36, 0.83, _HKI( "Not specified" ) ); // Green
|
|
|
|
ADD_COLOR( m_MaskColors, 20, 51, 36, 0.83, wxT( "Green" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 91, 168, 12, 0.83, wxT( "Light Green" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 13, 104, 11, 0.83, wxT( "Saturated Green" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 181, 19, 21, 0.83, wxT( "Red" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 210, 40, 14, 0.83, wxT( "Light Red" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 239, 53, 41, 0.83, wxT( "Red/Orange" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 2, 59, 162, 0.83, wxT( "Blue" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 54, 79, 116, 0.83, wxT( "Light Blue 1" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 61, 85, 130, 0.83, wxT( "Light Blue 2" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 21, 70, 80, 0.83, wxT( "Green/Blue" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 11, 11, 11, 0.83, wxT( "Black" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 245, 245, 245, 0.83, wxT( "White" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 32, 2, 53, 0.83, wxT( "Purple" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 119, 31, 91, 0.83, wxT( "Light Purple" ) );
|
|
|
|
ADD_COLOR( m_MaskColors, 194, 195, 0, 0.83, wxT( "Yellow" ) );
|
|
|
|
|
|
|
|
ADD_COLOR( m_PasteColors, 128, 128, 128, 1.0, wxT( "Grey" ) );
|
|
|
|
ADD_COLOR( m_PasteColors, 90, 90, 90, 1.0, wxT( "Dark Grey" ) );
|
|
|
|
ADD_COLOR( m_PasteColors, 213, 213, 213, 1.0, wxT( "Silver" ) );
|
|
|
|
|
|
|
|
ADD_COLOR( m_FinishColors, 184, 115, 50, 1.0, wxT( "Copper" ) );
|
|
|
|
ADD_COLOR( m_FinishColors, 178, 156, 0, 1.0, wxT( "Gold" ) );
|
|
|
|
ADD_COLOR( m_FinishColors, 213, 213, 213, 1.0, wxT( "Silver" ) );
|
|
|
|
ADD_COLOR( m_FinishColors, 160, 160, 160, 1.0, wxT( "Tin" ) );
|
|
|
|
|
|
|
|
ADD_COLOR( m_BoardColors, 51, 43, 22, 0.83, wxT( "FR4 natural, dark" ) );
|
|
|
|
ADD_COLOR( m_BoardColors, 109, 116, 75, 0.83, wxT( "FR4 natural" ) );
|
|
|
|
ADD_COLOR( m_BoardColors, 252, 252, 250, 0.90, wxT( "PTFE natural" ) );
|
|
|
|
ADD_COLOR( m_BoardColors, 205, 130, 0, 0.68, wxT( "Polyimide" ) );
|
|
|
|
ADD_COLOR( m_BoardColors, 92, 17, 6, 0.90, wxT( "Phenolic natural" ) );
|
|
|
|
ADD_COLOR( m_BoardColors, 146, 99, 47, 0.83, wxT( "Brown 1" ) );
|
|
|
|
ADD_COLOR( m_BoardColors, 160, 123, 54, 0.83, wxT( "Brown 2" ) );
|
|
|
|
ADD_COLOR( m_BoardColors, 146, 99, 47, 0.83, wxT( "Brown 3" ) );
|
|
|
|
ADD_COLOR( m_BoardColors, 213, 213, 213, 1.0, wxT( "Aluminum" ) );
|
|
|
|
|
|
|
|
m_DefaultSilkscreen = COLOR4D( 0.94, 0.94, 0.94, 1.0 );
|
|
|
|
m_DefaultSolderMask = COLOR4D( 0.08, 0.20, 0.14, 0.83 );
|
|
|
|
m_DefaultSolderPaste = COLOR4D( 0.50, 0.50, 0.50, 1.0 );
|
|
|
|
m_DefaultSurfaceFinish = COLOR4D( 0.75, 0.61, 0.23, 1.0 );
|
|
|
|
m_DefaultBoardBody = COLOR4D( 0.43, 0.45, 0.30, 0.90 );
|
|
|
|
#undef ADD_COLOR
|
|
|
|
|
|
|
|
g_ColorsLoaded = true;
|
|
|
|
}
|
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
bool EXPORTER_PCB_VRML::SetScale( double aWorldScale )
|
2021-03-16 19:15:34 +00:00
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
// set the scaling of the VRML world
|
2021-03-16 19:15:34 +00:00
|
|
|
if( aWorldScale < 0.001 || aWorldScale > 10.0 )
|
|
|
|
throw( std::runtime_error( "WorldScale out of range (valid range is 0.001 to 10.0)" ) );
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
m_OutputPCB.SetScale( aWorldScale * 2.54 );
|
2021-03-17 13:26:26 +00:00
|
|
|
m_WorldScale = aWorldScale * 2.54;
|
2014-06-08 10:35:42 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
void EXPORTER_PCB_VRML::SetOffset( double aXoff, double aYoff )
|
2021-03-16 19:15:34 +00:00
|
|
|
{
|
|
|
|
m_tx = aXoff;
|
|
|
|
m_ty = -aYoff;
|
|
|
|
|
|
|
|
m_holes.SetVertexOffsets( aXoff, aYoff );
|
2021-03-18 12:28:24 +00:00
|
|
|
m_3D_board.SetVertexOffsets( aXoff, aYoff );
|
2021-03-16 19:15:34 +00:00
|
|
|
m_top_copper.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_bot_copper.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_top_silk.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_bot_silk.SetVertexOffsets( aXoff, aYoff );
|
2021-03-18 13:40:36 +00:00
|
|
|
m_top_paste.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_bot_paste.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_top_soldermask.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
m_bot_soldermask.SetVertexOffsets( aXoff, aYoff );
|
2021-03-16 19:15:34 +00:00
|
|
|
m_plated_holes.SetVertexOffsets( aXoff, aYoff );
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-10-17 23:28:12 +00:00
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
bool EXPORTER_PCB_VRML::GetLayer3D( int layer, VRML_LAYER** vlayer )
|
2010-11-27 13:09:18 +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.
|
2014-01-06 20:14:24 +00:00
|
|
|
switch( layer )
|
|
|
|
{
|
2022-05-19 22:53:42 +00:00
|
|
|
case B_Cu: *vlayer = &m_bot_copper; return true;
|
|
|
|
case F_Cu: *vlayer = &m_top_copper; return true;
|
|
|
|
case B_SilkS: *vlayer = &m_bot_silk; return true;
|
|
|
|
case F_SilkS: *vlayer = &m_top_silk; return true;
|
2021-03-18 13:40:36 +00:00
|
|
|
case B_Mask: *vlayer = &m_bot_soldermask; return true;
|
|
|
|
case F_Mask: *vlayer = &m_top_soldermask; return true;
|
2022-05-19 22:53:42 +00:00
|
|
|
case B_Paste: *vlayer = &m_bot_paste; return true;
|
|
|
|
case F_Paste: *vlayer = &m_top_paste; return true;
|
|
|
|
default: return false;
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
void EXPORTER_PCB_VRML::ExportVrmlSolderMask()
|
2021-03-16 19:15:34 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
SHAPE_POLY_SET holes, outlines = m_pcbOutlines;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
// holes is the solder mask opening.
|
|
|
|
// the actual shape is the negative shape of mask opening.
|
2021-03-20 10:13:18 +00:00
|
|
|
PCB_LAYER_ID pcb_layer = F_Mask;
|
2021-03-18 13:40:36 +00:00
|
|
|
VRML_LAYER* vrmllayer = &m_top_soldermask;
|
|
|
|
|
|
|
|
for( int lcnt = 0; lcnt < 2; lcnt++ )
|
|
|
|
{
|
|
|
|
holes.RemoveAllContours();
|
|
|
|
outlines.RemoveAllContours();
|
|
|
|
outlines = m_pcbOutlines;
|
2022-06-28 16:57:15 +00:00
|
|
|
m_board->ConvertBrdLayerToPolygonalContours( pcb_layer, holes );
|
2021-03-18 13:40:36 +00:00
|
|
|
|
2022-04-04 10:25:35 +00:00
|
|
|
outlines.BooleanSubtract( holes, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
outlines.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2021-03-20 10:13:18 +00:00
|
|
|
ExportVrmlPolygonSet( vrmllayer, outlines );
|
2021-03-18 13:40:36 +00:00
|
|
|
|
2021-03-20 10:13:18 +00:00
|
|
|
pcb_layer = B_Mask;
|
2021-03-18 13:40:36 +00:00
|
|
|
vrmllayer = &m_bot_soldermask;
|
|
|
|
}
|
2021-03-16 19:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
void EXPORTER_PCB_VRML::ExportStandardLayers()
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET outlines;
|
|
|
|
|
|
|
|
PCB_LAYER_ID pcb_layer[] =
|
|
|
|
{
|
|
|
|
F_Cu, B_Cu, F_SilkS, B_SilkS, F_Paste, B_Paste
|
|
|
|
};
|
|
|
|
|
|
|
|
VRML_LAYER* vrmllayer[] =
|
|
|
|
{
|
|
|
|
&m_top_copper, &m_bot_copper, &m_top_silk, &m_bot_silk, &m_top_paste, &m_bot_paste,
|
|
|
|
nullptr // Sentinel
|
|
|
|
};
|
|
|
|
|
|
|
|
for( int lcnt = 0; ; lcnt++ )
|
|
|
|
{
|
|
|
|
if( vrmllayer[lcnt] == nullptr )
|
|
|
|
break;
|
|
|
|
|
|
|
|
outlines.RemoveAllContours();
|
2022-06-28 16:57:15 +00:00
|
|
|
m_board->ConvertBrdLayerToPolygonalContours( pcb_layer[lcnt], outlines );
|
2023-04-18 15:46:59 +00:00
|
|
|
outlines.BooleanIntersection( m_pcbOutlines, SHAPE_POLY_SET::PM_FAST );
|
2022-04-04 10:25:35 +00:00
|
|
|
outlines.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2021-03-20 12:39:16 +00:00
|
|
|
|
|
|
|
ExportVrmlPolygonSet( vrmllayer[lcnt], outlines );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
void EXPORTER_PCB_VRML::write_triangle_bag( std::ostream& aOut_file, const VRML_COLOR& aColor,
|
2021-07-19 23:56:05 +00:00
|
|
|
VRML_LAYER* aLayer, bool aPlane, bool aTop,
|
|
|
|
double aTop_z, double aBottom_z )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
// A lot of nodes are not required, but blender sometimes chokes without them.
|
2010-11-27 13:09:18 +00:00
|
|
|
static const char* shape_boiler[] =
|
|
|
|
{
|
|
|
|
"Transform {\n",
|
|
|
|
" children [\n",
|
|
|
|
" Group {\n",
|
|
|
|
" children [\n",
|
|
|
|
" Shape {\n",
|
|
|
|
" appearance Appearance {\n",
|
|
|
|
" material Material {\n",
|
2014-01-06 20:14:24 +00:00
|
|
|
0, // Material marker
|
2010-11-27 13:09:18 +00:00
|
|
|
" }\n",
|
|
|
|
" }\n",
|
|
|
|
" geometry IndexedFaceSet {\n",
|
2012-06-19 19:25:41 +00:00
|
|
|
" solid TRUE\n",
|
2010-11-27 13:09:18 +00:00
|
|
|
" coord Coordinate {\n",
|
|
|
|
" point [\n",
|
2014-01-06 20:14:24 +00:00
|
|
|
0, // Coordinates marker
|
2010-11-27 13:09:18 +00:00
|
|
|
" ]\n",
|
|
|
|
" }\n",
|
|
|
|
" coordIndex [\n",
|
2014-01-06 20:14:24 +00:00
|
|
|
0, // Index marker
|
2010-11-27 13:09:18 +00:00
|
|
|
" ]\n",
|
|
|
|
" }\n",
|
|
|
|
" }\n",
|
|
|
|
" ]\n",
|
|
|
|
" }\n",
|
|
|
|
" ]\n",
|
|
|
|
"}\n",
|
2014-01-06 20:14:24 +00:00
|
|
|
0 // End marker
|
2010-11-27 13:09:18 +00:00
|
|
|
};
|
2013-03-28 16:51:22 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
int marker_found = 0, lineno = 0;
|
|
|
|
|
|
|
|
while( marker_found < 4 )
|
|
|
|
{
|
|
|
|
if( shape_boiler[lineno] )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2016-10-20 11:20:49 +00:00
|
|
|
aOut_file << shape_boiler[lineno];
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
marker_found++;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
switch( marker_found )
|
|
|
|
{
|
2014-01-06 20:14:24 +00:00
|
|
|
case 1: // Material marker
|
2020-12-20 18:23:50 +00:00
|
|
|
{
|
|
|
|
std::streamsize lastPrecision = aOut_file.precision();
|
2016-10-20 11:20:49 +00:00
|
|
|
aOut_file << " diffuseColor " << std::setprecision(3);
|
|
|
|
aOut_file << aColor.diffuse_red << " ";
|
|
|
|
aOut_file << aColor.diffuse_grn << " ";
|
|
|
|
aOut_file << aColor.diffuse_blu << "\n";
|
|
|
|
|
|
|
|
aOut_file << " specularColor ";
|
|
|
|
aOut_file << aColor.spec_red << " ";
|
|
|
|
aOut_file << aColor.spec_grn << " ";
|
|
|
|
aOut_file << aColor.spec_blu << "\n";
|
|
|
|
|
|
|
|
aOut_file << " emissiveColor ";
|
|
|
|
aOut_file << aColor.emit_red << " ";
|
|
|
|
aOut_file << aColor.emit_grn << " ";
|
|
|
|
aOut_file << aColor.emit_blu << "\n";
|
|
|
|
|
|
|
|
aOut_file << " ambientIntensity " << aColor.ambient << "\n";
|
|
|
|
aOut_file << " transparency " << aColor.transp << "\n";
|
|
|
|
aOut_file << " shininess " << aColor.shiny << "\n";
|
2020-12-20 18:23:50 +00:00
|
|
|
aOut_file.precision( lastPrecision );
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-10-20 11:20:49 +00:00
|
|
|
if( aPlane )
|
2021-03-17 13:26:26 +00:00
|
|
|
aLayer->WriteVertices( aTop_z, aOut_file, m_precision );
|
2014-01-06 20:14:24 +00:00
|
|
|
else
|
2021-03-17 13:26:26 +00:00
|
|
|
aLayer->Write3DVertices( aTop_z, aBottom_z, aOut_file, m_precision );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-10-20 11:20:49 +00:00
|
|
|
aOut_file << "\n";
|
2014-01-06 20:14:24 +00:00
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
case 3:
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-10-20 11:20:49 +00:00
|
|
|
if( aPlane )
|
|
|
|
aLayer->WriteIndices( aTop, aOut_file );
|
2014-01-06 20:14:24 +00:00
|
|
|
else
|
2016-10-20 11:20:49 +00:00
|
|
|
aLayer->Write3DIndices( aOut_file );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-10-20 11:20:49 +00:00
|
|
|
aOut_file << "\n";
|
2014-01-06 20:14:24 +00:00
|
|
|
break;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
lineno++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
void EXPORTER_PCB_VRML::writeLayers( const char* aFileName, OSTREAM* aOutputFile )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
|
|
|
// VRML_LAYER board;
|
2021-03-18 12:28:24 +00:00
|
|
|
m_3D_board.Tesselate( &m_holes );
|
2021-03-17 13:26:26 +00:00
|
|
|
double brdz = m_brd_thickness / 2.0
|
2022-09-16 11:33:56 +00:00
|
|
|
- ( pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) ) * m_BoardToVrmlScale;
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_PCB ),
|
2021-03-18 12:28:24 +00:00
|
|
|
&m_3D_board, false, false, brdz, -brdz );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-18 12:28:24 +00:00
|
|
|
create_vrml_shell( m_OutputPCB, VRML_COLOR_PCB, &m_3D_board, brdz, -brdz );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-12-30 11:39:41 +00:00
|
|
|
// VRML_LAYER m_top_copper;
|
2021-03-17 13:26:26 +00:00
|
|
|
m_top_copper.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_COPPER ),
|
|
|
|
&m_top_copper, true, true, GetLayerZ( F_Cu ), 0 );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_COPPER, &m_top_copper,
|
|
|
|
GetLayerZ( F_Cu ), true );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
// VRML_LAYER m_top_paste;
|
|
|
|
m_top_paste.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_PASTE ),
|
|
|
|
&m_top_paste, true, true,
|
2022-09-16 11:33:56 +00:00
|
|
|
GetLayerZ( F_Cu ) + pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) *
|
2021-07-19 23:56:05 +00:00
|
|
|
m_BoardToVrmlScale,
|
2016-09-17 06:14:49 +00:00
|
|
|
0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_PASTE, &m_top_paste,
|
2022-09-16 11:33:56 +00:00
|
|
|
GetLayerZ( F_Cu ) + pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) *
|
2021-07-19 23:56:05 +00:00
|
|
|
m_BoardToVrmlScale,
|
2021-03-18 13:40:36 +00:00
|
|
|
true );
|
|
|
|
}
|
|
|
|
|
|
|
|
// VRML_LAYER m_top_soldermask;
|
|
|
|
m_top_soldermask.Tesselate( &m_holes );
|
|
|
|
|
|
|
|
if( m_UseInlineModelsInBrdfile )
|
|
|
|
{
|
2022-05-19 22:53:42 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_TOP_SOLDMASK ),
|
2021-03-18 13:40:36 +00:00
|
|
|
&m_top_soldermask, true, true,
|
2022-09-16 11:33:56 +00:00
|
|
|
GetLayerZ( F_Cu ) + pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) *
|
2021-07-19 23:56:05 +00:00
|
|
|
m_BoardToVrmlScale,
|
2021-03-18 13:40:36 +00:00
|
|
|
0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-19 22:53:42 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_TOP_SOLDMASK, &m_top_soldermask,
|
2022-09-16 11:33:56 +00:00
|
|
|
GetLayerZ( F_Cu ) + pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) *
|
2021-07-19 23:56:05 +00:00
|
|
|
m_BoardToVrmlScale,
|
2016-09-17 06:14:49 +00:00
|
|
|
true );
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-12-30 11:39:41 +00:00
|
|
|
// VRML_LAYER m_bot_copper;
|
2021-03-17 13:26:26 +00:00
|
|
|
m_bot_copper.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_COPPER ),
|
|
|
|
&m_bot_copper, true, false, GetLayerZ( B_Cu ), 0 );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_COPPER, &m_bot_copper,
|
|
|
|
GetLayerZ( B_Cu ), false );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-18 13:40:36 +00:00
|
|
|
// VRML_LAYER m_bot_paste;
|
|
|
|
m_bot_paste.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_PASTE ),
|
|
|
|
&m_bot_paste, true, false,
|
2021-03-17 13:26:26 +00:00
|
|
|
GetLayerZ( B_Cu )
|
2022-09-16 11:33:56 +00:00
|
|
|
- pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) * m_BoardToVrmlScale,
|
2016-09-17 06:14:49 +00:00
|
|
|
0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_PASTE, &m_bot_paste,
|
2022-09-16 11:33:56 +00:00
|
|
|
GetLayerZ( B_Cu ) - pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) *
|
2021-07-19 23:56:05 +00:00
|
|
|
m_BoardToVrmlScale,
|
2021-03-18 13:40:36 +00:00
|
|
|
false );
|
|
|
|
}
|
|
|
|
|
|
|
|
// VRML_LAYER m_bot_mask:
|
|
|
|
m_bot_soldermask.Tesselate( &m_holes );
|
|
|
|
|
|
|
|
if( m_UseInlineModelsInBrdfile )
|
|
|
|
{
|
2022-05-19 22:53:42 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_BOT_SOLDMASK ),
|
2021-03-18 13:40:36 +00:00
|
|
|
&m_bot_soldermask, true, false,
|
2022-09-16 11:33:56 +00:00
|
|
|
GetLayerZ( B_Cu ) - pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) *
|
2021-07-19 23:56:05 +00:00
|
|
|
m_BoardToVrmlScale,
|
2021-03-18 13:40:36 +00:00
|
|
|
0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-19 22:53:42 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_BOT_SOLDMASK, &m_bot_soldermask,
|
2022-09-16 11:33:56 +00:00
|
|
|
GetLayerZ( B_Cu ) - pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) *
|
2021-07-19 23:56:05 +00:00
|
|
|
m_BoardToVrmlScale,
|
2016-09-17 06:14:49 +00:00
|
|
|
false );
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2014-06-16 12:02:15 +00:00
|
|
|
// VRML_LAYER PTH;
|
2021-07-19 23:56:05 +00:00
|
|
|
m_plated_holes.Tesselate( nullptr, true );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_PASTE ),
|
2021-03-17 13:26:26 +00:00
|
|
|
&m_plated_holes, false, false,
|
2022-09-16 11:33:56 +00:00
|
|
|
GetLayerZ( F_Cu ) + pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) *
|
2021-07-19 23:56:05 +00:00
|
|
|
m_BoardToVrmlScale,
|
2022-09-16 11:33:56 +00:00
|
|
|
GetLayerZ( B_Cu ) - pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) *
|
2021-07-19 23:56:05 +00:00
|
|
|
m_BoardToVrmlScale );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-18 13:40:36 +00:00
|
|
|
create_vrml_shell( m_OutputPCB, VRML_COLOR_PASTE, &m_plated_holes,
|
2022-09-16 11:33:56 +00:00
|
|
|
GetLayerZ( F_Cu ) + pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) *
|
2021-07-19 23:56:05 +00:00
|
|
|
m_BoardToVrmlScale,
|
2022-09-16 11:33:56 +00:00
|
|
|
GetLayerZ( B_Cu ) - pcbIUScale.mmToIU( ART_OFFSET / 2.0 ) *
|
2021-07-19 23:56:05 +00:00
|
|
|
m_BoardToVrmlScale );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-06-16 12:02:15 +00:00
|
|
|
|
2016-12-30 11:39:41 +00:00
|
|
|
// VRML_LAYER m_top_silk;
|
2021-03-17 13:26:26 +00:00
|
|
|
m_top_silk.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2022-05-19 22:53:42 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_TOP_SILK ), &m_top_silk,
|
2021-03-17 13:26:26 +00:00
|
|
|
true, true, GetLayerZ( F_SilkS ), 0 );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-19 22:53:42 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_TOP_SILK, &m_top_silk,
|
2021-03-17 13:26:26 +00:00
|
|
|
GetLayerZ( F_SilkS ), true );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2016-12-30 11:39:41 +00:00
|
|
|
// VRML_LAYER m_bot_silk;
|
2021-03-17 13:26:26 +00:00
|
|
|
m_bot_silk.Tesselate( &m_holes );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2022-05-19 22:53:42 +00:00
|
|
|
write_triangle_bag( *aOutputFile, GetColor( VRML_COLOR_BOT_SILK ), &m_bot_silk,
|
2021-03-17 13:26:26 +00:00
|
|
|
true, false, GetLayerZ( B_SilkS ), 0 );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-19 22:53:42 +00:00
|
|
|
create_vrml_plane( m_OutputPCB, VRML_COLOR_BOT_SILK, &m_bot_silk,
|
2021-03-17 13:26:26 +00:00
|
|
|
GetLayerZ( B_SilkS ), false );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( !m_UseInlineModelsInBrdfile )
|
|
|
|
S3D::WriteVRML( aFileName, true, m_OutputPCB.GetRawPtr(), true, true );
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
void EXPORTER_PCB_VRML::ComputeLayer3D_Zpos()
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2022-06-28 16:57:15 +00:00
|
|
|
int copper_layers = m_board->GetCopperLayerCount();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
|
|
|
// We call it 'layer' thickness, but it's the whole board thickness!
|
2022-06-28 16:57:15 +00:00
|
|
|
m_brd_thickness = m_board->GetDesignSettings().GetBoardThickness() * m_BoardToVrmlScale;
|
2021-03-16 19:15:34 +00:00
|
|
|
double half_thickness = m_brd_thickness / 2;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Compute each layer's Z value, more or less like the 3d view
|
2014-06-24 16:17:18 +00:00
|
|
|
for( LSEQ seq = LSET::AllCuMask().Seq(); seq; ++seq )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2024-04-13 19:14:39 +00:00
|
|
|
int i = static_cast<int>( *seq );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
if( i < copper_layers )
|
2021-03-16 19:15:34 +00:00
|
|
|
SetLayerZ( i, half_thickness - m_brd_thickness * i / (copper_layers - 1) );
|
2010-11-27 13:09:18 +00:00
|
|
|
else
|
2021-03-16 19:15:34 +00:00
|
|
|
SetLayerZ( i, - half_thickness ); // bottom layer
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
// To avoid rounding interference, we apply an epsilon to each successive layer
|
2022-09-16 11:33:56 +00:00
|
|
|
double epsilon_z = pcbIUScale.mmToIU( ART_OFFSET ) * m_BoardToVrmlScale;
|
2021-03-18 13:40:36 +00:00
|
|
|
SetLayerZ( B_Paste, -half_thickness - epsilon_z );
|
|
|
|
SetLayerZ( B_Adhes, -half_thickness - epsilon_z );
|
|
|
|
SetLayerZ( B_SilkS, -half_thickness - epsilon_z * 3 );
|
|
|
|
SetLayerZ( B_Mask, -half_thickness - epsilon_z * 2 );
|
|
|
|
SetLayerZ( F_Mask, half_thickness + epsilon_z * 2 );
|
|
|
|
SetLayerZ( F_SilkS, half_thickness + epsilon_z * 3 );
|
|
|
|
SetLayerZ( F_Adhes, half_thickness + epsilon_z );
|
|
|
|
SetLayerZ( F_Paste, half_thickness + epsilon_z );
|
2021-03-16 19:15:34 +00:00
|
|
|
SetLayerZ( Dwgs_User, half_thickness + epsilon_z * 5 );
|
|
|
|
SetLayerZ( Cmts_User, half_thickness + epsilon_z * 6 );
|
|
|
|
SetLayerZ( Eco1_User, half_thickness + epsilon_z * 7 );
|
|
|
|
SetLayerZ( Eco2_User, half_thickness + epsilon_z * 8 );
|
|
|
|
SetLayerZ( Edge_Cuts, 0 );
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-20 10:13:18 +00:00
|
|
|
void EXPORTER_PCB_VRML::ExportVrmlPolygonSet( VRML_LAYER* aVlayer, const SHAPE_POLY_SET& aOutlines )
|
2021-03-18 13:40:36 +00:00
|
|
|
{
|
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.
|
2021-03-18 13:40:36 +00:00
|
|
|
for( int icnt = 0; icnt < aOutlines.OutlineCount(); icnt++ )
|
|
|
|
{
|
|
|
|
const SHAPE_LINE_CHAIN& outline = aOutlines.COutline( icnt );
|
|
|
|
|
|
|
|
int seg = aVlayer->NewContour();
|
|
|
|
|
|
|
|
for( int jj = 0; jj < outline.PointCount(); jj++ )
|
|
|
|
{
|
|
|
|
if( !aVlayer->AddVertex( seg, outline.CPoint( jj ).x * m_BoardToVrmlScale,
|
|
|
|
-outline.CPoint( jj ).y * m_BoardToVrmlScale ) )
|
|
|
|
throw( std::runtime_error( aVlayer->GetError() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
aVlayer->EnsureWinding( seg, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
void EXPORTER_PCB_VRML::ExportVrmlBoard()
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2022-06-28 16:57:15 +00:00
|
|
|
if( !m_board->GetBoardPolygonOutlines( m_pcbOutlines ) )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2020-11-20 13:55:10 +00:00
|
|
|
wxLogWarning( _( "Board outline is malformed. Run DRC for a full analysis." ) );
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int seg;
|
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
for( int cnt = 0; cnt < m_pcbOutlines.OutlineCount(); cnt++ )
|
2015-07-14 20:23:13 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
const SHAPE_LINE_CHAIN& outline = m_pcbOutlines.COutline( cnt );
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
seg = m_3D_board.NewContour();
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int j = 0; j < outline.PointCount(); j++ )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2021-03-18 12:28:24 +00:00
|
|
|
m_3D_board.AddVertex( seg, (double)outline.CPoint(j).x * m_BoardToVrmlScale,
|
2021-07-19 23:56:05 +00:00
|
|
|
-((double)outline.CPoint(j).y * m_BoardToVrmlScale ) );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
m_3D_board.EnsureWinding( seg, false );
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
// Generate board holes from outlines:
|
|
|
|
for( int ii = 0; ii < m_pcbOutlines.HoleCount( cnt ); ii++ )
|
2017-03-22 09:58:14 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
const SHAPE_LINE_CHAIN& hole = m_pcbOutlines.Hole( cnt, ii );
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
seg = m_holes.NewContour();
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2017-03-22 09:58:14 +00:00
|
|
|
if( seg < 0 )
|
|
|
|
{
|
2020-11-20 13:55:10 +00:00
|
|
|
wxLogError( _( "VRML Export Failed: Could not add holes to contours." ) );
|
2017-03-22 09:58:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2017-03-22 09:58:14 +00:00
|
|
|
for( int j = 0; j < hole.PointCount(); j++ )
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
m_holes.AddVertex( seg, (double) hole.CPoint(j).x * m_BoardToVrmlScale,
|
2021-07-19 23:56:05 +00:00
|
|
|
-( (double) hole.CPoint(j).y * m_BoardToVrmlScale ) );
|
2017-03-22 09:58:14 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
m_holes.EnsureWinding( seg, true );
|
2017-03-22 09:58:14 +00:00
|
|
|
}
|
2014-01-06 20:14:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
void EXPORTER_PCB_VRML::ExportVrmlViaHoles()
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2020-08-31 16:29:13 +00:00
|
|
|
PCB_LAYER_ID top_layer, bottom_layer;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2021-03-20 12:39:16 +00:00
|
|
|
if( track->Type() != PCB_VIA_T )
|
|
|
|
continue;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
|
2014-02-15 07:39:06 +00:00
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
via->LayerPair( &top_layer, &bottom_layer );
|
2021-01-10 19:28:15 +00:00
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
// do not render a buried via
|
|
|
|
if( top_layer != F_Cu && bottom_layer != B_Cu )
|
2021-07-25 01:25:25 +00:00
|
|
|
continue;
|
2021-01-10 19:28:15 +00:00
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
// Export all via holes to m_holes
|
|
|
|
double hole_radius = via->GetDrillValue() * m_BoardToVrmlScale / 2.0;
|
2021-01-10 19:28:15 +00:00
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
if( hole_radius <= 0 )
|
|
|
|
continue;
|
2021-01-10 19:28:15 +00:00
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
double x = via->GetStart().x * m_BoardToVrmlScale;
|
|
|
|
double y = via->GetStart().y * m_BoardToVrmlScale;
|
2020-08-22 21:17:23 +00:00
|
|
|
|
2021-03-20 17:16:25 +00:00
|
|
|
// Set the optimal number of segments to approximate a circle.
|
|
|
|
// SetArcParams needs a count max, and the minimal and maximal length
|
|
|
|
// of segments
|
2022-04-04 09:21:35 +00:00
|
|
|
double max_error = ERR_APPROX_MAX_MM;
|
|
|
|
|
|
|
|
if( m_UseInlineModelsInBrdfile )
|
|
|
|
max_error /= 2.54; // The board is exported with a size reduced by 2.54
|
|
|
|
|
2022-09-16 11:33:56 +00:00
|
|
|
int nsides = GetArcToSegmentCount( via->GetDrillValue(), pcbIUScale.mmToIU( max_error ),
|
2022-01-14 15:34:41 +00:00
|
|
|
FULL_CIRCLE );
|
2022-04-04 09:21:35 +00:00
|
|
|
|
2021-03-20 17:16:25 +00:00
|
|
|
double minSegLength = M_PI * 2.0 * hole_radius / nsides;
|
|
|
|
double maxSegLength = minSegLength*2.0;
|
|
|
|
|
|
|
|
m_holes.SetArcParams( nsides*2, minSegLength, maxSegLength );
|
2022-04-04 12:42:29 +00:00
|
|
|
m_plated_holes.SetArcParams( nsides*2, minSegLength, maxSegLength );
|
2021-03-20 17:16:25 +00:00
|
|
|
|
|
|
|
m_holes.AddCircle( x, -y, hole_radius, true, true );
|
|
|
|
m_plated_holes.AddCircle( x, -y, hole_radius, true, false );
|
|
|
|
|
|
|
|
m_holes.ResetArcParams();
|
|
|
|
m_plated_holes.ResetArcParams();
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
void EXPORTER_PCB_VRML::ExportVrmlPadHole( PAD* aPad )
|
2014-01-06 20:14:24 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
double hole_drill_w = (double) aPad->GetDrillSize().x * m_BoardToVrmlScale / 2.0;
|
|
|
|
double hole_drill_h = (double) aPad->GetDrillSize().y * m_BoardToVrmlScale / 2.0;
|
2014-10-17 23:28:12 +00:00
|
|
|
double hole_drill = std::min( hole_drill_w, hole_drill_h );
|
2021-03-17 13:26:26 +00:00
|
|
|
double hole_x = aPad->GetPosition().x * m_BoardToVrmlScale;
|
|
|
|
double hole_y = aPad->GetPosition().y * m_BoardToVrmlScale;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export the hole on the edge layer
|
2010-11-27 13:09:18 +00:00
|
|
|
if( hole_drill > 0 )
|
|
|
|
{
|
2022-04-04 09:21:35 +00:00
|
|
|
double max_error = ERR_APPROX_MAX_MM;
|
|
|
|
|
|
|
|
if( m_UseInlineModelsInBrdfile )
|
|
|
|
max_error /= 2.54; // The board is exported with a size reduced by 2.54
|
|
|
|
|
2022-09-16 11:33:56 +00:00
|
|
|
int nsides = GetArcToSegmentCount( hole_drill, pcbIUScale.mmToIU( max_error ),
|
2022-01-14 15:34:41 +00:00
|
|
|
FULL_CIRCLE );
|
2021-03-20 17:16:25 +00:00
|
|
|
double minSegLength = M_PI * hole_drill / nsides;
|
|
|
|
double maxSegLength = minSegLength*2.0;
|
|
|
|
|
|
|
|
m_holes.SetArcParams( nsides*2, minSegLength, maxSegLength );
|
2022-04-04 12:42:29 +00:00
|
|
|
m_plated_holes.SetArcParams( nsides*2, minSegLength, maxSegLength );
|
2021-03-20 17:16:25 +00:00
|
|
|
|
2014-06-16 12:02:15 +00:00
|
|
|
bool pth = false;
|
|
|
|
|
2021-05-01 14:46:50 +00:00
|
|
|
if( ( aPad->GetAttribute() != PAD_ATTRIB::NPTH ) )
|
2014-06-16 12:02:15 +00:00
|
|
|
pth = true;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// Oblong hole (slot)
|
2014-06-16 12:02:15 +00:00
|
|
|
|
|
|
|
if( pth )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0 + PLATE_OFFSET,
|
2022-01-13 13:45:48 +00:00
|
|
|
hole_drill_h * 2.0 + PLATE_OFFSET,
|
|
|
|
aPad->GetOrientation().AsDegrees(), true, true );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-16 19:15:34 +00:00
|
|
|
m_plated_holes.AddSlot( hole_x, -hole_y,
|
2022-01-13 13:45:48 +00:00
|
|
|
hole_drill_w * 2.0, hole_drill_h * 2.0,
|
|
|
|
aPad->GetOrientation().AsDegrees(), true, false );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0, hole_drill_h * 2.0,
|
2022-01-13 13:45:48 +00:00
|
|
|
aPad->GetOrientation().AsDegrees(), true, false );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Drill a round hole
|
2014-06-16 12:02:15 +00:00
|
|
|
if( pth )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_holes.AddCircle( hole_x, -hole_y, hole_drill + PLATE_OFFSET, true, true );
|
|
|
|
m_plated_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
2014-06-16 12:02:15 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
2021-03-20 17:16:25 +00:00
|
|
|
|
|
|
|
m_holes.ResetArcParams();
|
|
|
|
m_plated_holes.ResetArcParams();
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// From axis/rot to quaternion
|
2010-11-27 13:09:18 +00:00
|
|
|
static void build_quat( double x, double y, double z, double a, double q[4] )
|
|
|
|
{
|
|
|
|
double sina = sin( a / 2 );
|
|
|
|
|
|
|
|
q[0] = x * sina;
|
|
|
|
q[1] = y * sina;
|
|
|
|
q[2] = z * sina;
|
|
|
|
q[3] = cos( a / 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// From quaternion to axis/rot
|
2010-11-27 13:09:18 +00:00
|
|
|
static void from_quat( double q[4], double rot[4] )
|
|
|
|
{
|
|
|
|
rot[3] = acos( q[3] ) * 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-27 13:09:18 +00:00
|
|
|
for( int i = 0; i < 3; i++ )
|
|
|
|
rot[i] = q[i] / sin( rot[3] / 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Quaternion composition
|
2010-11-27 13:09:18 +00:00
|
|
|
static void compose_quat( double q1[4], double q2[4], double qr[4] )
|
|
|
|
{
|
|
|
|
double tmp[4];
|
|
|
|
|
2014-01-06 20:14:24 +00:00
|
|
|
tmp[0] = q2[3] * q1[0] + q2[0] * q1[3] + q2[1] * q1[2] - q2[2] * q1[1];
|
|
|
|
tmp[1] = q2[3] * q1[1] + q2[1] * q1[3] + q2[2] * q1[0] - q2[0] * q1[2];
|
|
|
|
tmp[2] = q2[3] * q1[2] + q2[2] * q1[3] + q2[0] * q1[1] - q2[1] * q1[0];
|
|
|
|
tmp[3] = q2[3] * q1[3] - q2[0] * q1[0] - q2[1] * q1[1] - q2[2] * q1[2];
|
|
|
|
|
|
|
|
qr[0] = tmp[0];
|
|
|
|
qr[1] = tmp[1];
|
|
|
|
qr[2] = tmp[2];
|
|
|
|
qr[3] = tmp[3];
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-30 21:28:46 +00:00
|
|
|
void EXPORTER_PCB_VRML::ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream* aOutputFile )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2021-09-09 16:05:04 +00:00
|
|
|
// Note: if m_UseInlineModelsInBrdfile is false, the 3D footprint shape is copied to
|
|
|
|
// the vrml board file, and aOutputFile is not used (can be nullptr)
|
|
|
|
// if m_UseInlineModelsInBrdfile is true, the 3D footprint shape is copied to
|
|
|
|
// aOutputFile (with the suitable rotation/translation/scale transform, and the vrml board
|
|
|
|
// file contains only the filename of 3D shapes to add to the full vrml scene
|
|
|
|
wxCHECK( aFootprint, /* void */ );
|
2021-06-30 21:28:46 +00:00
|
|
|
|
2022-09-26 03:40:25 +00:00
|
|
|
wxString libraryName = aFootprint->GetFPID().GetLibNickname();
|
|
|
|
wxString footprintBasePath = wxEmptyString;
|
|
|
|
|
|
|
|
if( m_board->GetProject() )
|
|
|
|
{
|
2022-10-15 08:27:00 +00:00
|
|
|
const FP_LIB_TABLE_ROW* fpRow = nullptr;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2023-09-28 03:15:54 +00:00
|
|
|
fpRow = PROJECT_PCB::PcbFootprintLibs( m_board->GetProject() )->FindRow( libraryName, false );
|
2022-10-15 08:27:00 +00:00
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
// Not found: do nothing
|
|
|
|
}
|
2022-09-26 03:40:25 +00:00
|
|
|
|
|
|
|
if( fpRow )
|
|
|
|
footprintBasePath = fpRow->GetFullURI( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
// Export pad holes
|
2020-11-13 01:33:30 +00:00
|
|
|
for( PAD* pad : aFootprint->Pads() )
|
2021-03-18 18:53:36 +00:00
|
|
|
ExportVrmlPadHole( pad );
|
|
|
|
|
2024-03-04 15:05:53 +00:00
|
|
|
if( !m_includeUnspecified
|
|
|
|
&& ( !( aFootprint->GetAttributes() & ( FP_THROUGH_HOLE | FP_SMD ) ) ) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_includeDNP && aFootprint->IsDNP() )
|
|
|
|
return;
|
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
bool isFlipped = aFootprint->GetLayer() == B_Cu;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Export the object VRML model(s)
|
2020-11-13 01:33:30 +00:00
|
|
|
auto sM = aFootprint->Models().begin();
|
|
|
|
auto eM = aFootprint->Models().end();
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
while( sM != eM )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2021-09-19 12:07:36 +00:00
|
|
|
if( !sM->m_Show )
|
|
|
|
{
|
|
|
|
++sM;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-09-26 03:40:25 +00:00
|
|
|
SGNODE* mod3d = (SGNODE*) m_Cache3Dmodels->Load( sM->m_Filename, footprintBasePath );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( nullptr == mod3d )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
++sM;
|
2010-11-27 13:09:18 +00:00
|
|
|
continue;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
/* Calculate 3D shape rotation:
|
|
|
|
* this is the rotation parameters, with an additional 180 deg rotation
|
|
|
|
* for footprints that are flipped
|
|
|
|
* When flipped, axis rotation is the horizontal axis (X axis)
|
|
|
|
*/
|
|
|
|
double rotx = -sM->m_Rotation.x;
|
|
|
|
double roty = -sM->m_Rotation.y;
|
|
|
|
double rotz = -sM->m_Rotation.z;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
if( isFlipped )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2016-09-17 06:14:49 +00:00
|
|
|
rotx += 180.0;
|
|
|
|
roty = -roty;
|
|
|
|
rotz = -rotz;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do some quaternion munching
|
|
|
|
double q1[4], q2[4], rot[4];
|
|
|
|
build_quat( 1, 0, 0, DEG2RAD( rotx ), q1 );
|
|
|
|
build_quat( 0, 1, 0, DEG2RAD( roty ), q2 );
|
|
|
|
compose_quat( q1, q2, q1 );
|
|
|
|
build_quat( 0, 0, 1, DEG2RAD( rotz ), q2 );
|
|
|
|
compose_quat( q1, q2, q1 );
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Note here aFootprint->GetOrientation() is in 0.1 degrees, so footprint rotation
|
|
|
|
// has to be converted to radians
|
2022-01-13 17:27:36 +00:00
|
|
|
build_quat( 0, 0, 1, aFootprint->GetOrientation().AsRadians(), q2 );
|
2016-09-17 06:14:49 +00:00
|
|
|
compose_quat( q1, q2, q1 );
|
|
|
|
from_quat( q1, rot );
|
|
|
|
|
2022-09-16 23:25:07 +00:00
|
|
|
double offsetFactor = 1000.0f * pcbIUScale.IU_PER_MILS / 25.4f;
|
2017-11-08 09:56:57 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// adjust 3D shape local offset position
|
2017-11-08 09:56:57 +00:00
|
|
|
// they are given in mm, so they are converted in board IU.
|
|
|
|
double offsetx = sM->m_Offset.x * offsetFactor;
|
|
|
|
double offsety = sM->m_Offset.y * offsetFactor;
|
|
|
|
double offsetz = sM->m_Offset.z * offsetFactor;
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
if( isFlipped )
|
|
|
|
offsetz = -offsetz;
|
2021-07-19 23:56:05 +00:00
|
|
|
else
|
|
|
|
offsety = -offsety; // In normal mode, Y axis is reversed in Pcbnew.
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
RotatePoint( &offsetx, &offsety, aFootprint->GetOrientation() );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
SGPOINT trans;
|
2021-03-17 13:26:26 +00:00
|
|
|
trans.x = ( offsetx + aFootprint->GetPosition().x ) * m_BoardToVrmlScale + m_tx;
|
|
|
|
trans.y = -( offsety + aFootprint->GetPosition().y) * m_BoardToVrmlScale - m_ty;
|
|
|
|
trans.z = (offsetz * m_BoardToVrmlScale ) + GetLayerZ( aFootprint->GetLayer() );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-09-09 16:05:04 +00:00
|
|
|
wxCHECK( aOutputFile, /* void */ );
|
|
|
|
|
|
|
|
int old_precision = aOutputFile->precision();
|
|
|
|
aOutputFile->precision( m_precision );
|
|
|
|
|
2022-09-26 02:54:08 +00:00
|
|
|
wxFileName srcFile =
|
|
|
|
m_Cache3Dmodels->GetResolver()->ResolvePath( sM->m_Filename, wxEmptyString );
|
2016-09-17 06:14:49 +00:00
|
|
|
wxFileName dstFile;
|
2021-03-17 13:26:26 +00:00
|
|
|
dstFile.SetPath( m_Subdir3DFpModels );
|
2016-09-17 06:14:49 +00:00
|
|
|
dstFile.SetName( srcFile.GetName() );
|
2022-02-05 02:06:25 +00:00
|
|
|
dstFile.SetExt( wxT( "wrl" ) );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// copy the file if necessary
|
|
|
|
wxDateTime srcModTime = srcFile.GetModificationTime();
|
|
|
|
wxDateTime destModTime = srcModTime;
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
destModTime.SetToCurrent();
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
if( dstFile.FileExists() )
|
|
|
|
destModTime = dstFile.GetModificationTime();
|
|
|
|
|
|
|
|
if( srcModTime != destModTime )
|
|
|
|
{
|
|
|
|
wxString fileExt = srcFile.GetExt();
|
|
|
|
fileExt.LowerCase();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// copy VRML models and use the scenegraph library to
|
|
|
|
// translate other model types
|
2022-02-05 02:06:25 +00:00
|
|
|
if( fileExt == wxT( "wrl" ) )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
if( !wxCopyFile( srcFile.GetFullPath(), dstFile.GetFullPath() ) )
|
2022-08-30 13:15:54 +00:00
|
|
|
{
|
|
|
|
++sM;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( fileExt == wxT( "wrz" ) )
|
|
|
|
{
|
|
|
|
wxFileInputStream input_file_stream( srcFile.GetFullPath() );
|
|
|
|
if( !input_file_stream.IsOk() || input_file_stream.GetSize() == wxInvalidSize )
|
|
|
|
{
|
|
|
|
++sM;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxZlibInputStream zlib_input_stream( input_file_stream, wxZLIB_GZIP );
|
|
|
|
wxFFileOutputStream output_file_stream( dstFile.GetFullPath() );
|
|
|
|
if( !zlib_input_stream.IsOk() || !output_file_stream.IsOk() )
|
|
|
|
{
|
|
|
|
output_file_stream.Close();
|
|
|
|
++sM;
|
2016-09-17 06:14:49 +00:00
|
|
|
continue;
|
2022-08-30 13:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
output_file_stream.Write( zlib_input_stream );
|
|
|
|
output_file_stream.Close();
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-30 21:28:46 +00:00
|
|
|
if( !S3D::WriteVRML( dstFile.GetFullPath().ToUTF8(), true, mod3d, m_ReuseDef,
|
|
|
|
true ) )
|
2022-08-30 13:15:54 +00:00
|
|
|
{
|
|
|
|
++sM;
|
2014-10-17 23:28:12 +00:00
|
|
|
continue;
|
2022-08-30 13:15:54 +00:00
|
|
|
}
|
2014-10-17 23:28:12 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << "Transform {\n";
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
// only write a rotation if it is >= 0.1 deg
|
|
|
|
if( std::abs( rot[3] ) > 0.0001745 )
|
2014-10-17 23:28:12 +00:00
|
|
|
{
|
2021-09-09 14:08:51 +00:00
|
|
|
(*aOutputFile) << " rotation ";
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n";
|
2014-10-17 23:28:12 +00:00
|
|
|
}
|
2011-01-15 20:21:46 +00:00
|
|
|
|
2021-09-09 14:08:51 +00:00
|
|
|
(*aOutputFile) << " translation ";
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << trans.x << " ";
|
|
|
|
(*aOutputFile) << trans.y << " ";
|
|
|
|
(*aOutputFile) << trans.z << "\n";
|
2011-01-19 10:34:56 +00:00
|
|
|
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << " scale ";
|
|
|
|
(*aOutputFile) << sM->m_Scale.x << " ";
|
|
|
|
(*aOutputFile) << sM->m_Scale.y << " ";
|
|
|
|
(*aOutputFile) << sM->m_Scale.z << "\n";
|
2011-01-15 20:21:46 +00:00
|
|
|
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << " children [\n Inline {\n url \"";
|
2013-01-12 10:35:08 +00:00
|
|
|
|
2021-03-17 13:26:26 +00:00
|
|
|
if( m_UseRelPathIn3DModelFilename )
|
2014-10-17 23:28:12 +00:00
|
|
|
{
|
2016-09-17 06:14:49 +00:00
|
|
|
wxFileName tmp = dstFile;
|
2022-02-05 02:06:25 +00:00
|
|
|
tmp.SetExt( wxT( "" ) );
|
|
|
|
tmp.SetName( wxT( "" ) );
|
2014-10-17 23:28:12 +00:00
|
|
|
tmp.RemoveLastDir();
|
2016-09-17 06:14:49 +00:00
|
|
|
dstFile.MakeRelativeTo( tmp.GetPath() );
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
2014-10-17 23:28:12 +00:00
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
wxString fn = dstFile.GetFullPath();
|
2022-02-05 02:06:25 +00:00
|
|
|
fn.Replace( wxT( "\\" ), wxT( "/" ) );
|
2017-03-02 22:53:49 +00:00
|
|
|
(*aOutputFile) << TO_UTF8( fn ) << "\"\n } ]\n";
|
|
|
|
(*aOutputFile) << " }\n";
|
2021-09-09 16:05:04 +00:00
|
|
|
|
|
|
|
aOutputFile->precision( old_precision );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
IFSG_TRANSFORM* modelShape = new IFSG_TRANSFORM( m_OutputPCB.GetRawPtr() );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
// only write a rotation if it is >= 0.1 deg
|
|
|
|
if( std::abs( rot[3] ) > 0.0001745 )
|
|
|
|
modelShape->SetRotation( SGVECTOR( rot[0], rot[1], rot[2] ), rot[3] );
|
|
|
|
|
|
|
|
modelShape->SetTranslation( trans );
|
|
|
|
modelShape->SetScale( SGPOINT( sM->m_Scale.x, sM->m_Scale.y, sM->m_Scale.z ) );
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( nullptr == S3D::GetSGNodeParent( mod3d ) )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-16 19:15:34 +00:00
|
|
|
m_components.push_back( mod3d );
|
2016-09-17 06:14:49 +00:00
|
|
|
modelShape->AddChildNode( mod3d );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
modelShape->AddRefNode( mod3d );
|
|
|
|
}
|
|
|
|
|
2013-03-27 18:34:23 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
++sM;
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
|
|
|
|
bool EXPORTER_PCB_VRML::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 )
|
2010-11-27 13:09:18 +00:00
|
|
|
{
|
2022-06-28 16:57:15 +00:00
|
|
|
if( aProject == nullptr )
|
|
|
|
{
|
|
|
|
if( aMessages )
|
|
|
|
*aMessages = _( "No project when exporting the VRML file");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
SetScale( aMMtoWRMLunit );
|
|
|
|
m_UseInlineModelsInBrdfile = aExport3DFiles;
|
2023-08-25 00:24:51 +00:00
|
|
|
|
|
|
|
wxFileName subdir( a3D_Subdir, wxT( "" ) );
|
|
|
|
// convert the subdir path to a absolute full one with the output file as the cwd
|
|
|
|
m_Subdir3DFpModels = subdir.GetAbsolutePath( wxFileName( aFullFileName ).GetPath() );
|
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
m_UseRelPathIn3DModelFilename = aUseRelativePaths;
|
2024-03-04 15:05:53 +00:00
|
|
|
m_includeUnspecified = aIncludeUnspecified;
|
|
|
|
m_includeDNP = aIncludeDNP;
|
2023-09-28 03:15:54 +00:00
|
|
|
m_Cache3Dmodels = PROJECT_PCB::Get3DCacheManager( aProject );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2022-04-04 09:21:35 +00:00
|
|
|
// When 3D models are separate files, for historical reasons the VRML unit
|
|
|
|
// is expected to be 0.1 inch (2.54mm) instead of 1mm, so we adjust the m_BoardToVrmlScale
|
|
|
|
// to match the VRML scale of these external files.
|
|
|
|
// Otherwise we use 1mm as VRML unit
|
2022-06-28 16:57:15 +00:00
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-10-10 23:54:32 +00:00
|
|
|
{
|
2022-09-16 22:56:24 +00:00
|
|
|
m_BoardToVrmlScale = pcbIUScale.MM_PER_IU / 2.54;
|
2022-06-28 16:57:15 +00:00
|
|
|
SetOffset( -aXRef / 2.54, aYRef / 2.54 );
|
2016-10-10 23:54:32 +00:00
|
|
|
}
|
2016-09-17 06:14:49 +00:00
|
|
|
else
|
2016-10-10 23:54:32 +00:00
|
|
|
{
|
2022-09-16 22:56:24 +00:00
|
|
|
m_BoardToVrmlScale = pcbIUScale.MM_PER_IU;
|
2022-06-28 16:57:15 +00:00
|
|
|
SetOffset( -aXRef, aYRef );
|
2016-10-10 23:54:32 +00:00
|
|
|
}
|
2014-02-03 21:39:42 +00:00
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
bool success = true;
|
|
|
|
|
2016-09-17 06:14:49 +00:00
|
|
|
try
|
|
|
|
{
|
2014-06-08 10:35:42 +00:00
|
|
|
// Preliminary computation: the z value for each layer
|
2022-06-28 16:57:15 +00:00
|
|
|
ComputeLayer3D_Zpos();
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2014-06-08 10:35:42 +00:00
|
|
|
// board edges and cutouts
|
2022-06-28 16:57:15 +00:00
|
|
|
ExportVrmlBoard();
|
2021-03-16 19:15:34 +00:00
|
|
|
|
2021-03-20 12:39:16 +00:00
|
|
|
// Draw solder mask layer (negative layer)
|
2022-06-28 16:57:15 +00:00
|
|
|
ExportVrmlSolderMask();
|
|
|
|
ExportVrmlViaHoles();
|
|
|
|
ExportStandardLayers();
|
|
|
|
|
|
|
|
if( m_UseInlineModelsInBrdfile )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
// Copy fp 3D models in a folder, and link these files in
|
|
|
|
// the board .vrml file
|
2022-06-28 16:57:15 +00:00
|
|
|
ExportFp3DModelsAsLinkedFile( aFullFileName );
|
2017-03-02 22:53:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-17 13:26:26 +00:00
|
|
|
// merge footprints in the .vrml board file
|
2022-06-28 16:57:15 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
|
|
|
ExportVrmlFootprint( footprint, nullptr );
|
2017-03-02 22:53:49 +00:00
|
|
|
|
|
|
|
// write out the board and all layers
|
2022-06-28 16:57:15 +00:00
|
|
|
writeLayers( TO_UTF8( aFullFileName ), nullptr );
|
2017-03-02 22:53:49 +00:00
|
|
|
}
|
2014-06-08 10:35:42 +00:00
|
|
|
}
|
|
|
|
catch( const std::exception& e )
|
|
|
|
{
|
2022-06-28 16:57:15 +00:00
|
|
|
if( aMessages )
|
2023-09-09 04:10:57 +00:00
|
|
|
*aMessages << _( "VRML Export Failed:\n" ) << From_UTF8( e.what() );
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
success = false;
|
2014-06-08 10:35:42 +00:00
|
|
|
}
|
2010-11-27 13:09:18 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
return success;
|
2010-11-27 13:09:18 +00:00
|
|
|
}
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2022-06-28 16:57:15 +00:00
|
|
|
bool PCB_EDIT_FRAME::ExportVRML_File( 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 )
|
|
|
|
{
|
|
|
|
bool success;
|
|
|
|
wxString msgs;
|
|
|
|
EXPORTER_VRML model3d( GetBoard() );
|
|
|
|
|
|
|
|
success = model3d.ExportVRML_File( &Prj(), &msgs, aFullFileName, aMMtoWRMLunit,
|
2024-03-04 15:05:53 +00:00
|
|
|
aIncludeUnspecified, aIncludeDNP,
|
2022-06-28 16:57:15 +00:00
|
|
|
aExport3DFiles, aUseRelativePaths,
|
|
|
|
a3D_Subdir, aXRef, aYRef );
|
|
|
|
|
|
|
|
if( !msgs.IsEmpty() )
|
|
|
|
wxMessageBox( msgs );
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
void EXPORTER_PCB_VRML::ExportFp3DModelsAsLinkedFile( const wxString& aFullFileName )
|
2021-03-17 13:26:26 +00:00
|
|
|
{
|
|
|
|
// check if the 3D Subdir exists - create if not
|
2023-08-25 00:24:51 +00:00
|
|
|
if( !wxDir::Exists( m_Subdir3DFpModels ) )
|
2021-03-17 13:26:26 +00:00
|
|
|
{
|
2023-08-25 00:24:51 +00:00
|
|
|
if( !wxDir::Make( m_Subdir3DFpModels ) )
|
2021-03-17 13:26:26 +00:00
|
|
|
throw( std::runtime_error( "Could not create 3D model subdirectory" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
OPEN_OSTREAM( output_file, TO_UTF8( aFullFileName ) );
|
|
|
|
|
|
|
|
if( output_file.fail() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "Could not open file '" << TO_UTF8( aFullFileName ) << "'";
|
|
|
|
throw( std::runtime_error( ostr.str().c_str() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
output_file.imbue( std::locale::classic() );
|
|
|
|
|
|
|
|
// Begin with the usual VRML boilerplate
|
|
|
|
wxString fn = aFullFileName;
|
2022-02-05 02:06:25 +00:00
|
|
|
fn.Replace( wxT( "\\" ) , wxT( "/" ) );
|
2021-03-17 13:26:26 +00:00
|
|
|
output_file << "#VRML V2.0 utf8\n";
|
|
|
|
output_file << "WorldInfo {\n";
|
|
|
|
output_file << " title \"" << TO_UTF8( fn ) << " - Generated by Pcbnew\"\n";
|
|
|
|
output_file << "}\n";
|
|
|
|
output_file << "Transform {\n";
|
|
|
|
output_file << " scale " << std::setprecision( m_precision );
|
|
|
|
output_file << m_WorldScale << " ";
|
|
|
|
output_file << m_WorldScale << " ";
|
|
|
|
output_file << m_WorldScale << "\n";
|
|
|
|
output_file << " children [\n";
|
|
|
|
|
|
|
|
// Export footprints
|
2022-06-28 16:57:15 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2021-03-18 13:40:36 +00:00
|
|
|
ExportVrmlFootprint( footprint, &output_file );
|
2021-03-17 13:26:26 +00:00
|
|
|
|
|
|
|
// write out the board and all layers
|
2021-03-18 13:40:36 +00:00
|
|
|
writeLayers( TO_UTF8( aFullFileName ), &output_file );
|
2021-03-17 13:26:26 +00:00
|
|
|
|
|
|
|
// Close the outer 'transform' node
|
|
|
|
output_file << "]\n}\n";
|
|
|
|
|
|
|
|
CLOSE_STREAM( output_file );
|
|
|
|
}
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
SGNODE* EXPORTER_PCB_VRML::getSGColor( VRML_COLOR_INDEX colorIdx )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
if( colorIdx == -1 )
|
|
|
|
colorIdx = VRML_COLOR_PCB;
|
|
|
|
else if( colorIdx == VRML_COLOR_LAST )
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
if( m_sgmaterial[colorIdx] )
|
|
|
|
return m_sgmaterial[colorIdx];
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
IFSG_APPEARANCE vcolor( (SGNODE*) nullptr );
|
2021-03-17 13:26:26 +00:00
|
|
|
VRML_COLOR* cp = &vrml_colors_list[colorIdx];
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
vcolor.SetSpecular( cp->spec_red, cp->spec_grn, cp->spec_blu );
|
|
|
|
vcolor.SetDiffuse( cp->diffuse_red, cp->diffuse_grn, cp->diffuse_blu );
|
|
|
|
vcolor.SetShininess( cp->shiny );
|
|
|
|
// NOTE: XXX - replace with a better equation; using this definition
|
|
|
|
// of ambient will not yield the best results
|
|
|
|
vcolor.SetAmbient( cp->ambient, cp->ambient, cp->ambient );
|
|
|
|
vcolor.SetTransparency( cp->transp );
|
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
m_sgmaterial[colorIdx] = vcolor.GetRawPtr();
|
2016-09-17 06:14:49 +00:00
|
|
|
|
2021-03-18 12:28:24 +00:00
|
|
|
return m_sgmaterial[colorIdx];
|
2017-11-02 20:41:29 +00:00
|
|
|
}
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
void EXPORTER_PCB_VRML::create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
|
2021-07-19 23:56:05 +00:00
|
|
|
VRML_LAYER* layer, double top_z, bool aTopPlane )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
std::vector< double > vertices;
|
|
|
|
std::vector< int > idxPlane;
|
|
|
|
|
2019-08-02 20:12:53 +00:00
|
|
|
if( !( *layer ).Get2DTriangles( vertices, idxPlane, top_z, aTopPlane ) )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-02 20:12:53 +00:00
|
|
|
if( ( idxPlane.size() % 3 ) )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle "
|
|
|
|
"list)" ) );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< SGPOINT > vlist;
|
|
|
|
size_t nvert = vertices.size() / 3;
|
|
|
|
size_t j = 0;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < nvert; ++i, j+= 3 )
|
2019-12-05 15:41:21 +00:00
|
|
|
vlist.emplace_back( vertices[j], vertices[j+1], vertices[j+2] );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
// create the intermediate scenegraph
|
|
|
|
IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline
|
2021-07-19 23:56:05 +00:00
|
|
|
IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals
|
2016-09-17 06:14:49 +00:00
|
|
|
IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes
|
|
|
|
IFSG_COORDS cp( face ); // coordinates for all faces
|
|
|
|
cp.SetCoordsList( nvert, &vlist[0] );
|
|
|
|
IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only
|
|
|
|
coordIdx.SetIndices( idxPlane.size(), &idxPlane[0] );
|
|
|
|
IFSG_NORMALS norms( face ); // normals for the top and bottom planes
|
|
|
|
|
|
|
|
// set the normals
|
|
|
|
if( aTopPlane )
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < nvert; ++i )
|
|
|
|
norms.AddNormal( 0.0, 0.0, 1.0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < nvert; ++i )
|
|
|
|
norms.AddNormal( 0.0, 0.0, -1.0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// assign a color from the palette
|
|
|
|
SGNODE* modelColor = getSGColor( colorID );
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( nullptr != modelColor )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
if( nullptr == S3D::GetSGNodeParent( modelColor ) )
|
2016-09-17 06:14:49 +00:00
|
|
|
shape.AddChildNode( modelColor );
|
|
|
|
else
|
|
|
|
shape.AddRefNode( modelColor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 18:53:36 +00:00
|
|
|
void EXPORTER_PCB_VRML::create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID,
|
2021-07-19 23:56:05 +00:00
|
|
|
VRML_LAYER* layer, double top_z, double bottom_z )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
std::vector< double > vertices;
|
|
|
|
std::vector< int > idxPlane;
|
|
|
|
std::vector< int > idxSide;
|
|
|
|
|
|
|
|
if( top_z < bottom_z )
|
|
|
|
{
|
|
|
|
double tmp = top_z;
|
|
|
|
top_z = bottom_z;
|
|
|
|
bottom_z = tmp;
|
|
|
|
}
|
|
|
|
|
2019-08-01 03:02:11 +00:00
|
|
|
if( !( *layer ).Get3DTriangles( vertices, idxPlane, idxSide, top_z, bottom_z )
|
|
|
|
|| idxPlane.empty() || idxSide.empty() )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) )
|
|
|
|
{
|
2020-08-18 14:17:16 +00:00
|
|
|
throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a "
|
|
|
|
"triangle list)" ) );
|
2016-09-17 06:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< SGPOINT > vlist;
|
|
|
|
size_t nvert = vertices.size() / 3;
|
|
|
|
size_t j = 0;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < nvert; ++i, j+= 3 )
|
2019-12-05 15:41:21 +00:00
|
|
|
vlist.emplace_back( vertices[j], vertices[j+1], vertices[j+2] );
|
2016-09-17 06:14:49 +00:00
|
|
|
|
|
|
|
// create the intermediate scenegraph
|
|
|
|
IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline
|
2021-07-19 23:56:05 +00:00
|
|
|
IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals
|
2016-09-17 06:14:49 +00:00
|
|
|
IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes
|
|
|
|
IFSG_COORDS cp( face ); // coordinates for all faces
|
|
|
|
cp.SetCoordsList( nvert, &vlist[0] );
|
|
|
|
IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only
|
|
|
|
coordIdx.SetIndices( idxPlane.size(), &idxPlane[0] );
|
|
|
|
IFSG_NORMALS norms( face ); // normals for the top and bottom planes
|
|
|
|
|
|
|
|
// number of TOP (and bottom) vertices
|
|
|
|
j = nvert / 2;
|
|
|
|
|
|
|
|
// set the TOP normals
|
|
|
|
for( size_t i = 0; i < j; ++i )
|
|
|
|
norms.AddNormal( 0.0, 0.0, 1.0 );
|
|
|
|
|
|
|
|
// set the BOTTOM normals
|
|
|
|
for( size_t i = 0; i < j; ++i )
|
|
|
|
norms.AddNormal( 0.0, 0.0, -1.0 );
|
|
|
|
|
|
|
|
// assign a color from the palette
|
|
|
|
SGNODE* modelColor = getSGColor( colorID );
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( nullptr != modelColor )
|
2016-09-17 06:14:49 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
if( nullptr == S3D::GetSGNodeParent( modelColor ) )
|
2016-09-17 06:14:49 +00:00
|
|
|
shape.AddChildNode( modelColor );
|
|
|
|
else
|
|
|
|
shape.AddRefNode( modelColor );
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a second shape describing the vertical walls of the extrusion
|
|
|
|
// using per-vertex-per-face-normals
|
|
|
|
shape.NewNode( tx0 );
|
|
|
|
shape.AddRefNode( modelColor ); // set the color to be the same as the top/bottom
|
|
|
|
face.NewNode( shape );
|
|
|
|
cp.NewNode( face ); // new vertex list
|
|
|
|
norms.NewNode( face ); // new normals list
|
|
|
|
coordIdx.NewNode( face ); // new index list
|
|
|
|
|
|
|
|
// populate the new per-face vertex list and its indices and normals
|
|
|
|
std::vector< int >::iterator sI = idxSide.begin();
|
|
|
|
std::vector< int >::iterator eI = idxSide.end();
|
|
|
|
|
|
|
|
size_t sidx = 0; // index to the new coord set
|
|
|
|
SGPOINT p1, p2, p3;
|
|
|
|
SGVECTOR vnorm;
|
|
|
|
|
|
|
|
while( sI != eI )
|
|
|
|
{
|
|
|
|
p1 = vlist[*sI];
|
|
|
|
cp.AddCoord( p1 );
|
|
|
|
++sI;
|
|
|
|
|
|
|
|
p2 = vlist[*sI];
|
|
|
|
cp.AddCoord( p2 );
|
|
|
|
++sI;
|
|
|
|
|
|
|
|
p3 = vlist[*sI];
|
|
|
|
cp.AddCoord( p3 );
|
|
|
|
++sI;
|
|
|
|
|
|
|
|
vnorm.SetVector( S3D::CalcTriNorm( p1, p2, p3 ) );
|
|
|
|
norms.AddNormal( vnorm );
|
|
|
|
norms.AddNormal( vnorm );
|
|
|
|
norms.AddNormal( vnorm );
|
|
|
|
|
|
|
|
coordIdx.AddIndex( (int)sidx );
|
|
|
|
++sidx;
|
|
|
|
coordIdx.AddIndex( (int)sidx );
|
|
|
|
++sidx;
|
|
|
|
coordIdx.AddIndex( (int)sidx );
|
|
|
|
++sidx;
|
|
|
|
}
|
|
|
|
}
|