Commit 431ed318 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Pcbnew VRML export improvements.

* Improve VRML export dialog lay out.
* Make the OK button the default action in the export dialog.
* Make 3D model export work correctly and avoid redundant file copies.
* Fix embedded path separators in wrl files on windows.
* Fix absolute model file path creation in wrl files.
* Clean up VRML export code.
parent 40468bff
...@@ -934,12 +934,15 @@ public: ...@@ -934,12 +934,15 @@ public:
* @param aMMtoWRMLunit = the VRML scaling factor: * @param aMMtoWRMLunit = the VRML scaling factor:
* 1.0 to export in mm. 0.001 for meters * 1.0 to export in mm. 0.001 for meters
* @param aExport3DFiles = true to copy 3D shapes in the subir a3D_Subdir * @param aExport3DFiles = true to copy 3D shapes in the subir a3D_Subdir
* @param a3D_Subdir = sub directory where 3D shapes files are copied * @param aUseRelativePaths set to true to use relative paths instead of absolute paths
* used only when aExport3DFiles == true * in the board VRML file URLs.
* @param a3D_Subdir = sub directory where 3D shapes files are copied. This is only used
* when aExport3DFiles == true
* @return true if Ok. * @return true if Ok.
*/ */
bool ExportVRML_File( const wxString & aFullFileName, double aMMtoWRMLunit, bool ExportVRML_File( const wxString & aFullFileName, double aMMtoWRMLunit,
bool aExport3DFiles, const wxString & a3D_Subdir ); bool aExport3DFiles, bool aUseRelativePaths,
const wxString & a3D_Subdir );
/** /**
* Function ExportToIDF3 * Function ExportToIDF3
......
...@@ -38,19 +38,19 @@ ...@@ -38,19 +38,19 @@
*/ */
#include <dialog_export_vrml_base.h> // the wxFormBuilder header file #include <dialog_export_vrml_base.h> // the wxFormBuilder header file
#define OPTKEY_OUTPUT_UNIT wxT("VrmlExportUnit" ) #define OPTKEY_OUTPUT_UNIT wxT( "VrmlExportUnit" )
#define OPTKEY_3DFILES_OPT wxT("VrmlExport3DShapeFilesOpt" ) #define OPTKEY_3DFILES_OPT wxT( "VrmlExportCopyFiles" )
#define OPTKEY_USE_ABS_PATHS wxT( "VrmlUseRelativePaths" )
class DIALOG_EXPORT_3DFILE : public DIALOG_EXPORT_3DFILE_BASE class DIALOG_EXPORT_3DFILE : public DIALOG_EXPORT_3DFILE_BASE
{ {
private: private:
PCB_EDIT_FRAME* m_parent; PCB_EDIT_FRAME* m_parent;
wxConfigBase* m_config; wxConfigBase* m_config;
int m_unitsOpt; // to remember last option int m_unitsOpt; // Remember last units option
int m_3DFilesOpt; // to remember last option bool m_copy3DFilesOpt; // Remember last copy model files option
bool m_useRelativePathsOpt; // Remember last use absolut paths option
void OnCancelClick( wxCommandEvent& event ){ EndModal( wxID_CANCEL ); }
void OnOkClick( wxCommandEvent& event ){ EndModal( wxID_OK ); }
public: public:
DIALOG_EXPORT_3DFILE( PCB_EDIT_FRAME* parent ) : DIALOG_EXPORT_3DFILE( PCB_EDIT_FRAME* parent ) :
...@@ -58,30 +58,42 @@ public: ...@@ -58,30 +58,42 @@ public:
{ {
m_parent = parent; m_parent = parent;
m_config = Kiface().KifaceSettings(); m_config = Kiface().KifaceSettings();
SetFocus(); m_filePicker->SetFocus();
m_config->Read( OPTKEY_OUTPUT_UNIT, &m_unitsOpt ); m_config->Read( OPTKEY_OUTPUT_UNIT, &m_unitsOpt );
m_config->Read( OPTKEY_3DFILES_OPT, &m_3DFilesOpt ); m_config->Read( OPTKEY_3DFILES_OPT, &m_copy3DFilesOpt );
m_rbSelectUnits->SetSelection(m_unitsOpt); m_config->Read( OPTKEY_USE_ABS_PATHS, &m_useRelativePathsOpt );
m_rb3DFilesOption->SetSelection(m_3DFilesOpt); m_rbSelectUnits->SetSelection( m_unitsOpt );
m_cbCopyFiles->SetValue( m_copy3DFilesOpt );
m_cbUseAbsolutePaths->SetValue( m_useRelativePathsOpt );
wxButton* okButton = (wxButton*) FindWindowByLabel( wxT( "OK" ) );
if( okButton )
SetDefaultItem( okButton );
GetSizer()->SetSizeHints( this ); GetSizer()->SetSizeHints( this );
Centre(); Centre();
Connect( ID_USE_ABS_PATH, wxEVT_UPDATE_UI,
wxUpdateUIEventHandler( DIALOG_EXPORT_3DFILE::OnUpdateUseAbsolutPath ) );
} }
~DIALOG_EXPORT_3DFILE() ~DIALOG_EXPORT_3DFILE()
{ {
m_unitsOpt = GetUnits( ); m_unitsOpt = GetUnits();
m_3DFilesOpt = Get3DFilesOption( ); m_copy3DFilesOpt = GetCopyFilesOption();
m_config->Write( OPTKEY_OUTPUT_UNIT, m_unitsOpt ); m_config->Write( OPTKEY_OUTPUT_UNIT, m_unitsOpt );
m_config->Write( OPTKEY_3DFILES_OPT, m_3DFilesOpt ); m_config->Write( OPTKEY_3DFILES_OPT, m_copy3DFilesOpt );
m_config->Write( OPTKEY_USE_ABS_PATHS, m_useRelativePathsOpt );
}; };
void SetSubdir( const wxString & aDir ) void SetSubdir( const wxString & aDir )
{ {
m_SubdirNameCtrl->SetValue( aDir); m_SubdirNameCtrl->SetValue( aDir );
} }
wxString GetSubdir( ) wxString GetSubdir()
{ {
return m_SubdirNameCtrl->GetValue( ); return m_SubdirNameCtrl->GetValue();
} }
wxFilePickerCtrl* FilePicker() wxFilePickerCtrl* FilePicker()
...@@ -89,26 +101,43 @@ public: ...@@ -89,26 +101,43 @@ public:
return m_filePicker; return m_filePicker;
} }
int GetUnits( ) int GetUnits()
{ {
return m_unitsOpt = m_rbSelectUnits->GetSelection(); return m_unitsOpt = m_rbSelectUnits->GetSelection();
} }
int Get3DFilesOption( ) bool GetCopyFilesOption()
{ {
return m_3DFilesOpt = m_rb3DFilesOption->GetSelection(); return m_copy3DFilesOpt = m_cbCopyFiles->GetValue();
}
bool GetUseAbsolutePathsOption()
{
return m_useRelativePathsOpt = m_cbUseAbsolutePaths->GetValue();
}
void OnUpdateUseAbsolutPath( wxUpdateUIEvent& event )
{
// Making path relative or absolute has no meaning when VRML files are not copied.
event.Enable( m_cbCopyFiles->GetValue() );
} }
}; };
/**
* Function OnExportVRML
* will export the current BOARD to a VRML file.
*/
void PCB_EDIT_FRAME::OnExportVRML( wxCommandEvent& event ) void PCB_EDIT_FRAME::OnExportVRML( wxCommandEvent& event )
{ {
wxFileName fn; wxFileName fn;
static wxString subDirFor3Dshapes = wxT("shapes3D"); wxString projectPath;
if( !wxGetEnv( wxT( "KIPRJMOD" ), &projectPath ) )
projectPath = wxFileName::GetCwd();
static wxString subDirFor3Dshapes;
if( subDirFor3Dshapes.IsEmpty() )
{
subDirFor3Dshapes = wxT( "shapes3D" );
}
// The general VRML scale factor // The general VRML scale factor
// Assuming the VRML default unit is the mm // Assuming the VRML default unit is the mm
...@@ -116,9 +145,8 @@ void PCB_EDIT_FRAME::OnExportVRML( wxCommandEvent& event ) ...@@ -116,9 +145,8 @@ void PCB_EDIT_FRAME::OnExportVRML( wxCommandEvent& event )
double scaleList[3] = { 1.0/25.4, 1, 0.001 }; double scaleList[3] = { 1.0/25.4, 1, 0.001 };
// Build default file name // Build default file name
wxString ext = wxT( "wrl" );
fn = GetBoard()->GetFileName(); fn = GetBoard()->GetFileName();
fn.SetExt( ext ); fn.SetExt( wxT( "wrl" ) );
DIALOG_EXPORT_3DFILE dlg( this ); DIALOG_EXPORT_3DFILE dlg( this );
dlg.FilePicker()->SetPath( fn.GetFullPath() ); dlg.FilePicker()->SetPath( fn.GetFullPath() );
...@@ -127,18 +155,26 @@ void PCB_EDIT_FRAME::OnExportVRML( wxCommandEvent& event ) ...@@ -127,18 +155,26 @@ void PCB_EDIT_FRAME::OnExportVRML( wxCommandEvent& event )
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )
return; return;
double scale = scaleList[dlg.GetUnits( )]; // final scale export double scale = scaleList[dlg.GetUnits()]; // final scale export
bool export3DFiles = dlg.Get3DFilesOption( ) == 0; bool export3DFiles = dlg.GetCopyFilesOption();
bool useRelativePaths = dlg.GetUseAbsolutePathsOption();
wxString fullFilename = dlg.FilePicker()->GetPath();
wxFileName modelPath = fullFilename;
wxBusyCursor dummy; wxBusyCursor dummy;
wxString fullFilename = dlg.FilePicker()->GetPath(); modelPath.AppendDir( dlg.GetSubdir() );
subDirFor3Dshapes = dlg.GetSubdir(); subDirFor3Dshapes = dlg.GetSubdir();
if( export3DFiles && !wxDirExists( subDirFor3Dshapes ) ) wxLogDebug( wxT( "Exporting enabled=%d to %s." ),
wxMkdir( subDirFor3Dshapes ); export3DFiles, GetChars( subDirFor3Dshapes ) );
if( export3DFiles && !modelPath.DirExists() )
{
modelPath.Mkdir();
}
if( ! ExportVRML_File( fullFilename, scale, export3DFiles, subDirFor3Dshapes ) ) if( !ExportVRML_File( fullFilename, scale, export3DFiles, useRelativePaths,
modelPath.GetPath() ) )
{ {
wxString msg = _( "Unable to create " ) + fullFilename; wxString msg = _( "Unable to create " ) + fullFilename;
wxMessageBox( msg ); wxMessageBox( msg );
......
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 8 2012) // C++ code generated with wxFormBuilder (version Nov 6 2013)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
...@@ -19,15 +19,14 @@ DIALOG_EXPORT_3DFILE_BASE::DIALOG_EXPORT_3DFILE_BASE( wxWindow* parent, wxWindow ...@@ -19,15 +19,14 @@ DIALOG_EXPORT_3DFILE_BASE::DIALOG_EXPORT_3DFILE_BASE( wxWindow* parent, wxWindow
wxBoxSizer* bUpperSizer; wxBoxSizer* bUpperSizer;
bUpperSizer = new wxBoxSizer( wxVERTICAL ); bUpperSizer = new wxBoxSizer( wxVERTICAL );
bUpperSizer->SetMinSize( wxSize( 450,-1 ) ); m_staticText1 = new wxStaticText( this, wxID_ANY, _("File Name:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText1 = new wxStaticText( this, wxID_ANY, _("Vrml main file filename:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText1->Wrap( -1 ); m_staticText1->Wrap( -1 );
bUpperSizer->Add( m_staticText1, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); bUpperSizer->Add( m_staticText1, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_filePicker = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, _("Save VRML Board File"), wxT("*.wrl"), wxDefaultPosition, wxDefaultSize, wxFLP_SAVE|wxFLP_USE_TEXTCTRL ); m_filePicker = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, _("Save VRML Board File"), wxT("*.wrl"), wxDefaultPosition, wxDefaultSize, wxFLP_SAVE|wxFLP_USE_TEXTCTRL );
bUpperSizer->Add( m_filePicker, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); bUpperSizer->Add( m_filePicker, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
m_staticText3 = new wxStaticText( this, wxID_ANY, _("Vrml 3D footprints shapes subdir:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText3 = new wxStaticText( this, wxID_ANY, _("Footprint 3D model path:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText3->Wrap( -1 ); m_staticText3->Wrap( -1 );
bUpperSizer->Add( m_staticText3, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); bUpperSizer->Add( m_staticText3, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
...@@ -36,25 +35,33 @@ DIALOG_EXPORT_3DFILE_BASE::DIALOG_EXPORT_3DFILE_BASE( wxWindow* parent, wxWindow ...@@ -36,25 +35,33 @@ DIALOG_EXPORT_3DFILE_BASE::DIALOG_EXPORT_3DFILE_BASE( wxWindow* parent, wxWindow
bUpperSizer->Add( m_SubdirNameCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); bUpperSizer->Add( m_SubdirNameCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
bSizer1->Add( bUpperSizer, 0, wxEXPAND, 5 ); bSizer1->Add( bUpperSizer, 0, wxALL|wxEXPAND, 5 );
wxBoxSizer* bLowerSizer; wxBoxSizer* bLowerSizer;
bLowerSizer = new wxBoxSizer( wxHORIZONTAL ); bLowerSizer = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxVERTICAL );
m_cbCopyFiles = new wxCheckBox( this, wxID_ANY, _("Copy 3D model files to 3D model path"), wxDefaultPosition, wxDefaultSize, 0 );
m_cbCopyFiles->SetValue(true);
bSizer4->Add( m_cbCopyFiles, 0, wxALL, 5 );
m_cbUseAbsolutePaths = new wxCheckBox( this, ID_USE_ABS_PATH, _("Use absolute paths to model files in board VRML file"), wxDefaultPosition, wxDefaultSize, 0 );
m_cbUseAbsolutePaths->SetValue(true);
bSizer4->Add( m_cbUseAbsolutePaths, 0, wxALL, 5 );
bLowerSizer->Add( bSizer4, 3, wxEXPAND, 5 );
wxString m_rbSelectUnitsChoices[] = { _("Inch"), _("mm"), _("Meter") }; wxString m_rbSelectUnitsChoices[] = { _("Inch"), _("mm"), _("Meter") };
int m_rbSelectUnitsNChoices = sizeof( m_rbSelectUnitsChoices ) / sizeof( wxString ); int m_rbSelectUnitsNChoices = sizeof( m_rbSelectUnitsChoices ) / sizeof( wxString );
m_rbSelectUnits = new wxRadioBox( this, wxID_ANY, _("Units:"), wxDefaultPosition, wxDefaultSize, m_rbSelectUnitsNChoices, m_rbSelectUnitsChoices, 1, wxRA_SPECIFY_COLS ); m_rbSelectUnits = new wxRadioBox( this, wxID_ANY, _("Units:"), wxDefaultPosition, wxDefaultSize, m_rbSelectUnitsNChoices, m_rbSelectUnitsChoices, 1, wxRA_SPECIFY_COLS );
m_rbSelectUnits->SetSelection( 0 ); m_rbSelectUnits->SetSelection( 0 );
bLowerSizer->Add( m_rbSelectUnits, 1, wxALL|wxEXPAND, 5 ); bLowerSizer->Add( m_rbSelectUnits, 1, wxALL|wxEXPAND, 5 );
wxString m_rb3DFilesOptionChoices[] = { _("Copy 3D Shapes Files in Subdir"), _("Use Absolute Path in Vrml File ") };
int m_rb3DFilesOptionNChoices = sizeof( m_rb3DFilesOptionChoices ) / sizeof( wxString );
m_rb3DFilesOption = new wxRadioBox( this, wxID_ANY, _("3D Shapes Files Option:"), wxDefaultPosition, wxDefaultSize, m_rb3DFilesOptionNChoices, m_rb3DFilesOptionChoices, 1, wxRA_SPECIFY_COLS );
m_rb3DFilesOption->SetSelection( 1 );
bLowerSizer->Add( m_rb3DFilesOption, 1, wxALL|wxEXPAND, 5 );
bSizer1->Add( bLowerSizer, 1, wxEXPAND, 5 ); bSizer1->Add( bLowerSizer, 1, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 );
m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizer1->Add( m_staticline1, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 ); bSizer1->Add( m_staticline1, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 );
...@@ -71,6 +78,7 @@ DIALOG_EXPORT_3DFILE_BASE::DIALOG_EXPORT_3DFILE_BASE( wxWindow* parent, wxWindow ...@@ -71,6 +78,7 @@ DIALOG_EXPORT_3DFILE_BASE::DIALOG_EXPORT_3DFILE_BASE( wxWindow* parent, wxWindow
this->SetSizer( bSizer1 ); this->SetSizer( bSizer1 );
this->Layout(); this->Layout();
bSizer1->Fit( this );
// Connect Events // Connect Events
m_sdbSizer1Cancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXPORT_3DFILE_BASE::OnCancelClick ), NULL, this ); m_sdbSizer1Cancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXPORT_3DFILE_BASE::OnCancelClick ), NULL, this );
......
This diff is collapsed.
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 8 2012) // C++ code generated with wxFormBuilder (version Nov 6 2013)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
...@@ -23,6 +23,7 @@ class DIALOG_SHIM; ...@@ -23,6 +23,7 @@ class DIALOG_SHIM;
#include <wx/filepicker.h> #include <wx/filepicker.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/checkbox.h>
#include <wx/radiobox.h> #include <wx/radiobox.h>
#include <wx/statline.h> #include <wx/statline.h>
#include <wx/button.h> #include <wx/button.h>
...@@ -38,12 +39,18 @@ class DIALOG_EXPORT_3DFILE_BASE : public DIALOG_SHIM ...@@ -38,12 +39,18 @@ class DIALOG_EXPORT_3DFILE_BASE : public DIALOG_SHIM
private: private:
protected: protected:
enum
{
ID_USE_ABS_PATH = 1000
};
wxStaticText* m_staticText1; wxStaticText* m_staticText1;
wxFilePickerCtrl* m_filePicker; wxFilePickerCtrl* m_filePicker;
wxStaticText* m_staticText3; wxStaticText* m_staticText3;
wxTextCtrl* m_SubdirNameCtrl; wxTextCtrl* m_SubdirNameCtrl;
wxCheckBox* m_cbCopyFiles;
wxCheckBox* m_cbUseAbsolutePaths;
wxRadioBox* m_rbSelectUnits; wxRadioBox* m_rbSelectUnits;
wxRadioBox* m_rb3DFilesOption;
wxStaticLine* m_staticline1; wxStaticLine* m_staticline1;
wxStdDialogButtonSizer* m_sdbSizer1; wxStdDialogButtonSizer* m_sdbSizer1;
wxButton* m_sdbSizer1OK; wxButton* m_sdbSizer1OK;
...@@ -56,7 +63,7 @@ class DIALOG_EXPORT_3DFILE_BASE : public DIALOG_SHIM ...@@ -56,7 +63,7 @@ class DIALOG_EXPORT_3DFILE_BASE : public DIALOG_SHIM
public: public:
DIALOG_EXPORT_3DFILE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Vrml Board Export Options:"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 370,252 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); DIALOG_EXPORT_3DFILE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("VRML Export Options"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_EXPORT_3DFILE_BASE(); ~DIALOG_EXPORT_3DFILE_BASE();
}; };
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment