2013-01-13 17:55:07 +01:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009-2013 Lorenzo Mercantonio
|
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras jp.charras at wanadoo.fr
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2013-01-13 17:55:07 +01: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
|
|
|
|
*/
|
2021-03-17 14:26:26 +01:00
|
|
|
/**
|
|
|
|
* @file dialog_export_vrml.cpp
|
|
|
|
*/
|
|
|
|
|
2017-08-02 13:30:57 -04:00
|
|
|
#include <wx/dir.h>
|
|
|
|
|
2022-08-27 13:23:43 -04:00
|
|
|
#include <base_units.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-01-12 17:18:08 +00:00
|
|
|
#include <confirm.h>
|
2021-09-14 23:45:14 +01:00
|
|
|
#include <kiface_base.h>
|
2020-01-12 17:18:08 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-01-12 20:44:19 -05:00
|
|
|
#include <pcbnew_settings.h>
|
2025-05-23 22:38:59 +01:00
|
|
|
#include <tools/board_editor_control.h>
|
2020-05-31 17:42:04 -04:00
|
|
|
#include <project/project_file.h> // LAST_PATH_TYPE
|
2024-04-27 22:57:24 +03:00
|
|
|
#include <wx/msgdlg.h>
|
2013-01-13 17:55:07 +01:00
|
|
|
|
2024-09-07 19:57:19 -04:00
|
|
|
#include <dialog_export_vrml.h>
|
2013-01-13 17:55:07 +01:00
|
|
|
|
|
|
|
|
2024-09-07 19:57:19 -04:00
|
|
|
DIALOG_EXPORT_VRML::DIALOG_EXPORT_VRML( PCB_EDIT_FRAME* aEditFrame ) :
|
|
|
|
DIALOG_EXPORT_VRML_BASE( aEditFrame ),
|
|
|
|
m_editFrame( aEditFrame )
|
2013-01-13 17:55:07 +01:00
|
|
|
{
|
2024-09-07 19:57:19 -04:00
|
|
|
m_filePicker->SetFocus();
|
|
|
|
|
|
|
|
PCBNEW_SETTINGS* cfg = m_editFrame->GetPcbNewSettings();
|
|
|
|
|
|
|
|
m_unitsOpt = cfg->m_ExportVrml.units;
|
|
|
|
m_noUnspecified = cfg->m_ExportVrml.no_unspecified;
|
|
|
|
m_noDNP = cfg->m_ExportVrml.no_dnp;
|
|
|
|
m_copy3DFilesOpt = cfg->m_ExportVrml.copy_3d_models;
|
|
|
|
m_useRelativePathsOpt = cfg->m_ExportVrml.use_relative_paths;
|
|
|
|
m_RefUnits = cfg->m_ExportVrml.ref_units;
|
|
|
|
m_XRef = cfg->m_ExportVrml.ref_x;
|
|
|
|
m_YRef = cfg->m_ExportVrml.ref_y;
|
|
|
|
m_originMode = cfg->m_ExportVrml.origin_mode;
|
|
|
|
|
|
|
|
|
|
|
|
m_rbCoordOrigin->SetSelection( m_originMode );
|
|
|
|
m_rbSelectUnits->SetSelection( m_unitsOpt );
|
|
|
|
m_cbRemoveUnspecified->SetValue( m_noUnspecified );
|
|
|
|
m_cbRemoveDNP->SetValue( m_noDNP );
|
|
|
|
m_cbCopyFiles->SetValue( m_copy3DFilesOpt );
|
|
|
|
m_cbUseRelativePaths->SetValue( m_useRelativePathsOpt );
|
|
|
|
m_VRML_RefUnitChoice->SetSelection( m_RefUnits );
|
|
|
|
wxString tmpStr;
|
|
|
|
tmpStr << m_XRef;
|
|
|
|
m_VRML_Xref->SetValue( tmpStr );
|
|
|
|
tmpStr = wxT( "" );
|
|
|
|
tmpStr << m_YRef;
|
|
|
|
m_VRML_Yref->SetValue( tmpStr );
|
|
|
|
|
|
|
|
SetupStandardButtons();
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
finishDialogSettings();
|
|
|
|
}
|
2021-03-17 14:26:26 +01:00
|
|
|
|
2015-08-13 15:13:34 +02:00
|
|
|
|
2024-09-07 19:57:19 -04:00
|
|
|
DIALOG_EXPORT_VRML::~DIALOG_EXPORT_VRML()
|
|
|
|
{
|
|
|
|
m_unitsOpt = GetUnits();
|
|
|
|
m_noUnspecified = GetNoUnspecifiedOption();
|
|
|
|
m_noDNP = GetNoDNPOption();
|
|
|
|
m_copy3DFilesOpt = GetCopyFilesOption();
|
2015-08-13 15:13:34 +02:00
|
|
|
|
2024-09-07 19:57:19 -04:00
|
|
|
PCBNEW_SETTINGS* cfg = nullptr;
|
2013-01-13 17:55:07 +01:00
|
|
|
|
2024-09-07 19:57:19 -04:00
|
|
|
try
|
2024-03-04 10:05:53 -05:00
|
|
|
{
|
2024-09-07 19:57:19 -04:00
|
|
|
cfg = m_editFrame->GetPcbNewSettings();
|
2024-03-04 10:05:53 -05:00
|
|
|
}
|
2024-09-07 19:57:19 -04:00
|
|
|
catch( const std::runtime_error& e )
|
2024-03-04 10:05:53 -05:00
|
|
|
{
|
2024-09-07 19:57:19 -04:00
|
|
|
wxFAIL_MSG( e.what() );
|
2024-03-04 10:05:53 -05:00
|
|
|
}
|
|
|
|
|
2024-09-07 19:57:19 -04:00
|
|
|
if( cfg )
|
2013-01-13 17:55:07 +01:00
|
|
|
{
|
2024-09-07 19:57:19 -04:00
|
|
|
cfg->m_ExportVrml.units = m_unitsOpt;
|
|
|
|
cfg->m_ExportVrml.no_unspecified = m_noUnspecified;
|
|
|
|
cfg->m_ExportVrml.no_dnp = m_noDNP;
|
|
|
|
cfg->m_ExportVrml.copy_3d_models = m_copy3DFilesOpt;
|
|
|
|
cfg->m_ExportVrml.use_relative_paths = m_useRelativePathsOpt;
|
|
|
|
cfg->m_ExportVrml.ref_units = m_VRML_RefUnitChoice->GetSelection();
|
|
|
|
cfg->m_ExportVrml.origin_mode = m_rbCoordOrigin->GetSelection();
|
2014-10-17 19:28:12 -04:00
|
|
|
|
2024-09-07 19:57:19 -04:00
|
|
|
double val = 0.0;
|
|
|
|
m_VRML_Xref->GetValue().ToDouble( &val );
|
|
|
|
cfg->m_ExportVrml.ref_x = val;
|
2014-10-17 19:28:12 -04:00
|
|
|
|
2024-09-07 19:57:19 -04:00
|
|
|
m_VRML_Yref->GetValue().ToDouble( &val );
|
|
|
|
cfg->m_ExportVrml.ref_y = val;
|
2013-01-13 17:55:07 +01:00
|
|
|
}
|
2024-09-07 19:57:19 -04:00
|
|
|
}
|
2013-01-13 17:55:07 +01:00
|
|
|
|
|
|
|
|
2024-09-07 19:57:19 -04:00
|
|
|
bool DIALOG_EXPORT_VRML::TransferDataFromWindow()
|
2017-08-02 13:30:57 -04:00
|
|
|
{
|
|
|
|
wxFileName fn = m_filePicker->GetPath();
|
|
|
|
|
|
|
|
if( fn.Exists() )
|
|
|
|
{
|
2018-03-07 20:32:30 -08:00
|
|
|
if( wxMessageBox( _( "Are you sure you want to overwrite the existing file?" ),
|
2017-08-02 13:30:57 -04:00
|
|
|
_( "Warning" ), wxYES_NO | wxCENTER | wxICON_QUESTION, this ) == wxNO )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-07 19:57:19 -04:00
|
|
|
double DIALOG_EXPORT_VRML::GetXRef()
|
|
|
|
{
|
|
|
|
return EDA_UNIT_UTILS::UI::DoubleValueFromString( m_VRML_Xref->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double DIALOG_EXPORT_VRML::GetYRef()
|
|
|
|
{
|
|
|
|
return EDA_UNIT_UTILS::UI::DoubleValueFromString( m_VRML_Yref->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-05-23 22:38:59 +01:00
|
|
|
int BOARD_EDITOR_CONTROL::ExportVRML( const TOOL_EVENT& aEvent )
|
2013-01-13 17:55:07 +01:00
|
|
|
{
|
2015-10-04 19:07:20 +02:00
|
|
|
// These variables are static to keep info during the session.
|
2015-09-12 12:57:38 -04:00
|
|
|
static wxString subDirFor3Dshapes;
|
2014-10-17 19:28:12 -04:00
|
|
|
|
2025-05-23 22:38:59 +01:00
|
|
|
BOARD* board = m_frame->GetBoard();
|
|
|
|
|
2019-08-02 21:03:03 -06:00
|
|
|
// Build default output file name
|
2025-05-23 22:38:59 +01:00
|
|
|
wxString path = m_frame->GetLastPath( LAST_PATH_VRML );
|
2019-08-02 21:03:03 -06:00
|
|
|
|
|
|
|
if( path.IsEmpty() )
|
2015-10-04 19:07:20 +02:00
|
|
|
{
|
2025-05-23 22:38:59 +01:00
|
|
|
wxFileName brdFile = board->GetFileName();
|
2022-02-04 22:44:59 +00:00
|
|
|
brdFile.SetExt( wxT( "wrl" ) );
|
2019-08-02 21:03:03 -06:00
|
|
|
path = brdFile.GetFullPath();
|
2015-10-04 19:07:20 +02:00
|
|
|
}
|
2014-10-17 19:28:12 -04:00
|
|
|
|
|
|
|
if( subDirFor3Dshapes.IsEmpty() )
|
|
|
|
subDirFor3Dshapes = wxT( "shapes3D" );
|
2013-01-13 17:55:07 +01:00
|
|
|
|
|
|
|
// The general VRML scale factor
|
|
|
|
// Assuming the VRML default unit is the mm
|
2015-08-06 19:13:02 -04:00
|
|
|
// this is the mm to VRML scaling factor for mm, 0.1 inch, and inch
|
2015-08-13 15:13:34 +02:00
|
|
|
double scaleList[4] = { 1.0, 0.001, 10.0/25.4, 1.0/25.4 };
|
2013-01-13 17:55:07 +01:00
|
|
|
|
2025-05-23 22:38:59 +01:00
|
|
|
DIALOG_EXPORT_VRML dlg( m_frame );
|
2019-08-02 21:03:03 -06:00
|
|
|
dlg.FilePicker()->SetPath( path );
|
2013-01-13 17:55:07 +01:00
|
|
|
dlg.SetSubdir( subDirFor3Dshapes );
|
|
|
|
|
2015-12-27 18:33:15 +01:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2025-05-23 22:38:59 +01:00
|
|
|
return 0;
|
2015-12-27 18:33:15 +01:00
|
|
|
|
2015-08-13 15:13:34 +02:00
|
|
|
double aXRef = dlg.GetXRef();
|
|
|
|
double aYRef = dlg.GetYRef();
|
|
|
|
|
|
|
|
if( dlg.GetRefUnitsChoice() == 1 )
|
|
|
|
{
|
|
|
|
// selected reference unit is in inches
|
|
|
|
aXRef *= 25.4;
|
|
|
|
aYRef *= 25.4;
|
|
|
|
}
|
|
|
|
|
2021-03-17 14:26:26 +01:00
|
|
|
if( dlg.GetOriginChoice() == 1 )
|
|
|
|
{
|
|
|
|
// Origin = board center:
|
2025-05-23 22:38:59 +01:00
|
|
|
BOX2I bbox = board->ComputeBoundingBox( true );
|
2023-08-24 20:24:51 -04:00
|
|
|
aXRef = pcbIUScale.IUTomm( bbox.GetCenter().x );
|
|
|
|
aYRef = pcbIUScale.IUTomm( bbox.GetCenter().y );
|
2021-03-17 14:26:26 +01:00
|
|
|
}
|
|
|
|
|
2014-10-17 19:28:12 -04:00
|
|
|
double scale = scaleList[dlg.GetUnits()]; // final scale export
|
2024-03-04 10:05:53 -05:00
|
|
|
bool includeUnspecified = !dlg.GetNoUnspecifiedOption();
|
|
|
|
bool includeDNP = !dlg.GetNoDNPOption();
|
2014-10-17 19:28:12 -04:00
|
|
|
bool export3DFiles = dlg.GetCopyFilesOption();
|
2014-11-17 14:55:26 +01:00
|
|
|
bool useRelativePaths = dlg.GetUseRelativePathsOption();
|
2013-01-13 17:55:07 +01:00
|
|
|
|
2019-08-02 21:03:03 -06:00
|
|
|
path = dlg.FilePicker()->GetPath();
|
2025-05-23 22:38:59 +01:00
|
|
|
m_frame->SetLastPath( LAST_PATH_VRML, path );
|
2019-08-02 21:03:03 -06:00
|
|
|
wxFileName modelPath = path;
|
|
|
|
|
2015-10-04 19:07:20 +02:00
|
|
|
wxBusyCursor dummy;
|
2013-01-13 17:55:07 +01:00
|
|
|
|
2015-10-04 19:07:20 +02:00
|
|
|
subDirFor3Dshapes = dlg.GetSubdir3Dshapes();
|
|
|
|
modelPath.AppendDir( subDirFor3Dshapes );
|
2014-10-17 19:28:12 -04:00
|
|
|
|
|
|
|
if( export3DFiles && !modelPath.DirExists() )
|
|
|
|
{
|
2020-01-12 17:18:08 +00:00
|
|
|
if( !modelPath.Mkdir() )
|
|
|
|
{
|
2025-05-23 22:38:59 +01:00
|
|
|
DisplayErrorMessage( m_frame, wxString::Format( _( "Failed to create folder '%s'." ),
|
|
|
|
modelPath.GetPath() ) );
|
|
|
|
return 0;
|
2020-01-12 17:18:08 +00:00
|
|
|
}
|
2014-10-17 19:28:12 -04:00
|
|
|
}
|
2013-01-13 17:55:07 +01:00
|
|
|
|
2025-05-23 22:38:59 +01:00
|
|
|
if( !m_frame->ExportVRML_File( path, scale, includeUnspecified, includeDNP, export3DFiles,
|
|
|
|
useRelativePaths, modelPath.GetPath(), aXRef, aYRef ) )
|
2013-01-13 17:55:07 +01:00
|
|
|
{
|
2025-05-23 22:38:59 +01:00
|
|
|
DisplayErrorMessage( m_frame, wxString::Format( _( "Failed to create file '%s'." ),
|
|
|
|
path ) );
|
2013-01-13 17:55:07 +01:00
|
|
|
}
|
2025-05-23 22:38:59 +01:00
|
|
|
|
|
|
|
return 0;
|
2024-09-11 09:53:26 -04:00
|
|
|
}
|