From b448040808d3b83f9bcfdb2f48f82f8b152f237e Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 19 Apr 2010 13:38:57 +0200 Subject: [PATCH] Pcbnew: Added VRML export, from the patch sent by Lorenzo Marcantonio ( october 2009, 11) --- common/build_version.cpp | 2 +- pcbnew/dialog_export_3Dfiles_base.cpp | 4 +- pcbnew/dialog_export_3Dfiles_base.fbp | 6 +- pcbnew/dialog_export_3Dfiles_base.h | 2 +- pcbnew/export_vrml.cpp | 128 ++++++++++++++------------ 5 files changed, 76 insertions(+), 66 deletions(-) diff --git a/common/build_version.cpp b/common/build_version.cpp index 1da0f1f8fb..356646a860 100644 --- a/common/build_version.cpp +++ b/common/build_version.cpp @@ -6,7 +6,7 @@ #endif #ifndef KICAD_BUILD_VERSION -#define KICAD_BUILD_VERSION "(2010-04-13 BZR 23xx)" +#define KICAD_BUILD_VERSION "(2010-04-19 BZR 23xx)" #endif #define VERSION_STABILITY "unstable" diff --git a/pcbnew/dialog_export_3Dfiles_base.cpp b/pcbnew/dialog_export_3Dfiles_base.cpp index 0887f95c10..e312d5a42c 100644 --- a/pcbnew/dialog_export_3Dfiles_base.cpp +++ b/pcbnew/dialog_export_3Dfiles_base.cpp @@ -20,14 +20,14 @@ DIALOG_EXPORT_3DFILE_BASE::DIALOG_EXPORT_3DFILE_BASE( wxWindow* parent, wxWindow bUpperSizer = new wxBoxSizer( wxVERTICAL ); bUpperSizer->SetMinSize( wxSize( 450,-1 ) ); - m_staticText1 = new wxStaticText( this, wxID_ANY, _("Wrml main file filename:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText1 = new wxStaticText( this, wxID_ANY, _("Vrml main file filename:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText1->Wrap( -1 ); 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_DEFAULT_STYLE|wxFLP_SAVE ); bUpperSizer->Add( m_filePicker, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); - m_staticText3 = new wxStaticText( this, wxID_ANY, _("Wrml 3D footprints shapes subdir:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText3 = new wxStaticText( this, wxID_ANY, _("Vrml 3D footprints shapes subdir:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText3->Wrap( -1 ); bUpperSizer->Add( m_staticText3, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); diff --git a/pcbnew/dialog_export_3Dfiles_base.fbp b/pcbnew/dialog_export_3Dfiles_base.fbp index ab7b0a744d..f0cf0f5a21 100644 --- a/pcbnew/dialog_export_3Dfiles_base.fbp +++ b/pcbnew/dialog_export_3Dfiles_base.fbp @@ -35,7 +35,7 @@ 370,252 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER - + Vrml Board Export Options: @@ -96,7 +96,7 @@ 0 wxID_ANY - Wrml main file filename: + Vrml main file filename: m_staticText1 @@ -200,7 +200,7 @@ 0 wxID_ANY - Wrml 3D footprints shapes subdir: + Vrml 3D footprints shapes subdir: m_staticText3 diff --git a/pcbnew/dialog_export_3Dfiles_base.h b/pcbnew/dialog_export_3Dfiles_base.h index 25b6f7d90a..cb1f5ce540 100644 --- a/pcbnew/dialog_export_3Dfiles_base.h +++ b/pcbnew/dialog_export_3Dfiles_base.h @@ -51,7 +51,7 @@ class DIALOG_EXPORT_3DFILE_BASE : public wxDialog public: - DIALOG_EXPORT_3DFILE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, 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 Board Export Options:"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 370,252 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_EXPORT_3DFILE_BASE(); }; diff --git a/pcbnew/export_vrml.cpp b/pcbnew/export_vrml.cpp index 365a2baf1b..508ea08d16 100644 --- a/pcbnew/export_vrml.cpp +++ b/pcbnew/export_vrml.cpp @@ -14,6 +14,73 @@ #include + +/* the dialog to create VRML files, derived from DIALOG_EXPORT_3DFILE_BASE, + * created by wxFormBuilder + */ +#include "dialog_export_3Dfiles_base.h" // the wxFormBuilder header file + +#define OPTKEY_OUTPUT_UNIT wxT("VrmlExportUnit" ) +#define OPTKEY_3DFILES_OPT wxT("VrmlExport3DShapeFilesOpt" ) + +class DIALOG_EXPORT_3DFILE : public DIALOG_EXPORT_3DFILE_BASE +{ +private: + WinEDA_PcbFrame* m_parent; + wxConfig* m_config; + int m_unitsOpt; // to remember last option + int m_3DFilesOpt; // to remember last option + virtual void OnCancelClick( wxCommandEvent& event ){ EndModal( wxID_CANCEL ); } + virtual void OnOkClick( wxCommandEvent& event ){ EndModal( wxID_OK ); } + +public: + DIALOG_EXPORT_3DFILE( WinEDA_PcbFrame* parent ) : + DIALOG_EXPORT_3DFILE_BASE( parent ) + { + m_parent = parent; + m_config = wxGetApp().m_EDA_Config; + SetFocus(); + m_config->Read( OPTKEY_OUTPUT_UNIT, &m_unitsOpt ); + m_config->Read( OPTKEY_3DFILES_OPT, &m_3DFilesOpt ); + m_rbSelectUnits->SetSelection(m_unitsOpt); + m_rb3DFilesOption->SetSelection(m_3DFilesOpt); + GetSizer()->SetSizeHints( this ); + Centre(); + } + ~DIALOG_EXPORT_3DFILE() + { + m_unitsOpt = GetUnits( ); + m_3DFilesOpt = Get3DFilesOption( ); + m_config->Write( OPTKEY_OUTPUT_UNIT, m_unitsOpt ); + m_config->Write( OPTKEY_3DFILES_OPT, m_3DFilesOpt ); + }; + + void SetSubdir( const wxString & aDir ) + { + m_SubdirNameCtrl->SetValue( aDir); + } + + wxString GetSubdir( ) + { + return m_SubdirNameCtrl->GetValue( ); + } + + wxFilePickerCtrl* FilePicker() + { + return m_filePicker; + } + + int GetUnits( ) + { + return m_unitsOpt = m_rbSelectUnits->GetSelection(); + } + + int Get3DFilesOption( ) + { + return m_3DFilesOpt = m_rb3DFilesOption->GetSelection(); + } +}; + /* I use this a lot... */ static const double PI2 = M_PI / 2; @@ -1037,63 +1104,6 @@ static void write_and_empty_triangle_bag( FILE* output_file, } -/* the dialog to create VRML files, derived from DIALOG_EXPORT_3DFILE_BASE, - * created by wxFormBuilder - */ -#include "dialog_export_3Dfiles_base.h" // the wxFormBuilder header file - -class DIALOG_EXPORT_3DFILE : public DIALOG_EXPORT_3DFILE_BASE -{ - private: - static int m_UnitsOpt; // to remember last option - static int m_3DFilesOpt; // to remember last option - virtual void OnCancelClick( wxCommandEvent& event ){ EndModal( wxID_CANCEL ); } - virtual void OnOkClick( wxCommandEvent& event ){ EndModal( wxID_OK ); } - - public: - DIALOG_EXPORT_3DFILE( wxWindow* parent ) : - DIALOG_EXPORT_3DFILE_BASE( parent ) - { - SetFocus(); - m_rbSelectUnits->SetSelection(m_UnitsOpt); - m_rb3DFilesOption->SetSelection(m_3DFilesOpt); - GetSizer()->SetSizeHints( this ); - Centre(); - } - ~DIALOG_EXPORT_3DFILE() - { - m_UnitsOpt = GetUnits( ); - m_3DFilesOpt = Get3DFilesOption( ); - }; - - void SetSubdir( const wxString & aDir ) - { - m_SubdirNameCtrl->SetValue( aDir); - } - - wxString GetSubdir( ) - { - return m_SubdirNameCtrl->GetValue( ); - } - - wxFilePickerCtrl* FilePicker() - { - return m_filePicker; - } - - int GetUnits( ) - { - return m_UnitsOpt = m_rbSelectUnits->GetSelection(); - } - - int Get3DFilesOption( ) - { - return m_3DFilesOpt = m_rb3DFilesOption->GetSelection(); - } -}; -int DIALOG_EXPORT_3DFILE::m_UnitsOpt = 0; // to remember last option -int DIALOG_EXPORT_3DFILE::m_3DFilesOpt = 1; // to remember last option - /** * Function OnExportVRML * will export the current BOARD to a VRML file. @@ -1186,8 +1196,8 @@ bool WinEDA_PcbFrame::ExportVRML_File( const wxString & aFullFileName, * more easy for rotations... */ pcb->ComputeBoundaryBox(); - double dx = board_scaling_factor * pcb->m_BoundaryBox.Centre().x; - double dy = board_scaling_factor * pcb->m_BoundaryBox.Centre().y; + double dx = board_scaling_factor * pcb->m_BoundaryBox.Centre().x * aScale; + double dy = board_scaling_factor * pcb->m_BoundaryBox.Centre().y * aScale; fprintf(output_file, " translation %g %g 0.0\n", -dx, dy ); fprintf(output_file, " children [\n" );