From eeddfcbec22178b5aa18a6e01dd32f2f68749daf Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 26 Oct 2013 09:03:06 +0200 Subject: [PATCH] Pcbnew, dxf import: Add dialog to choose the board import layer, and the position of dxf coordinates origin --- pcbnew/CMakeLists.txt | 1 + pcbnew/import_dxf/dialog_dxf_import.cpp | 159 +++- pcbnew/import_dxf/dialog_dxf_import.fbp | 741 +++++++++++++++++++ pcbnew/import_dxf/dialog_dxf_import_base.cpp | 83 +++ pcbnew/import_dxf/dialog_dxf_import_base.h | 67 ++ pcbnew/import_dxf/dxf2brd_items.cpp | 2 +- pcbnew/import_dxf/dxf2brd_items.h | 2 + 7 files changed, 1042 insertions(+), 13 deletions(-) create mode 100644 pcbnew/import_dxf/dialog_dxf_import.fbp create mode 100644 pcbnew/import_dxf/dialog_dxf_import_base.cpp create mode 100644 pcbnew/import_dxf/dialog_dxf_import_base.h diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 972542c886..41cefc0b66 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -117,6 +117,7 @@ set( PCBNEW_DIALOGS ) set( PCBNEW_IMPORT_DXF + import_dxf/dialog_dxf_import_base.cpp import_dxf/dialog_dxf_import.cpp import_dxf/dxf2brd_items.cpp ) diff --git a/pcbnew/import_dxf/dialog_dxf_import.cpp b/pcbnew/import_dxf/dialog_dxf_import.cpp index ee24139604..4a93aa056a 100644 --- a/pcbnew/import_dxf/dialog_dxf_import.cpp +++ b/pcbnew/import_dxf/dialog_dxf_import.cpp @@ -1,10 +1,99 @@ +/** + * @file dialog_dxf_import.cpp + * @brief Dialog to import a dxf file on a given board layer. + */ + +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 + */ + #include #include #include +#include +#include -bool InvokeDXFDialogImport( PCB_EDIT_FRAME* aCaller ) +class DIALOG_DXF_IMPORT : public DIALOG_DXF_IMPORT_BASE { - wxFileDialog dlg( aCaller, +private: + PCB_EDIT_FRAME * m_parent; + static wxString m_dxfFilename; + static int m_offsetSelection; + static LAYER_NUM m_layer; + +public: + + DIALOG_DXF_IMPORT( PCB_EDIT_FRAME* aParent ); + ~DIALOG_DXF_IMPORT(); + +private: + // Virtual event handlers + void OnCancelClick( wxCommandEvent& event ) { event.Skip(); } + void OnOKClick( wxCommandEvent& event ); + void OnBrowseDxfFiles( wxCommandEvent& event ); +}; + +// Static members of DIALOG_DXF_IMPORT, to remember +// the user's choices during the session +wxString DIALOG_DXF_IMPORT::m_dxfFilename; +int DIALOG_DXF_IMPORT::m_offsetSelection = 4; +LAYER_NUM DIALOG_DXF_IMPORT::m_layer = DRAW_N; + + +DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT( PCB_EDIT_FRAME* aParent ) + : DIALOG_DXF_IMPORT_BASE( aParent ) +{ + m_parent = aParent; + m_textCtrlFileName->SetValue( m_dxfFilename ); + m_rbOffsetOption->SetSelection( m_offsetSelection ); + + // Configure the layers list selector + m_SelLayerBox->SetLayersHotkeys( false ); // Do not display hotkeys + m_SelLayerBox->SetLayerMask( ALL_CU_LAYERS ); // Do not use copper layers + m_SelLayerBox->SetBoardFrame( m_parent ); + m_SelLayerBox->Resync(); + if( m_SelLayerBox->SetLayerSelection( m_layer ) < 0 ) + { + m_layer = DRAW_N; + m_SelLayerBox->SetLayerSelection( m_layer ); + } + + GetSizer()->Fit( this ); + GetSizer()->SetSizeHints( this ); + Centre(); +} + + +DIALOG_DXF_IMPORT::~DIALOG_DXF_IMPORT() +{ + m_offsetSelection = m_rbOffsetOption->GetSelection(); + m_layer = m_SelLayerBox->GetLayerSelection(); +} + + +void DIALOG_DXF_IMPORT::OnBrowseDxfFiles( wxCommandEvent& event ) +{ + wxFileDialog dlg( m_parent, wxT( "Open File" ), wxEmptyString, wxEmptyString, wxT( "dxf Files (*.dxf)|*.dxf|*.DXF" ), @@ -13,17 +102,63 @@ bool InvokeDXFDialogImport( PCB_EDIT_FRAME* aCaller ) wxString fileName = dlg.GetPath(); - if( !fileName.IsEmpty() ) - { - BOARD * brd = aCaller->GetBoard(); - DXF2BRD_CONVERTER dxf_importer; + if( fileName.IsEmpty() ) + return; - // Set coordinates offset for import (offset is given in mm) - double offsetY = - aCaller->GetPageSizeIU().y * MM_PER_IU; - dxf_importer.SetOffset( 0.0, offsetY ); - dxf_importer.SetBrdLayer( DRAW_N ); - dxf_importer.ImportDxfFile( fileName, brd ); + m_dxfFilename = fileName; + m_textCtrlFileName->SetValue( fileName ); +} + +void DIALOG_DXF_IMPORT::OnOKClick( wxCommandEvent& event ) +{ + m_dxfFilename = m_textCtrlFileName->GetValue(); + + if( m_dxfFilename.IsEmpty() ) + return; + + double offsetX = 0; + double offsetY = 0; + + m_offsetSelection = m_rbOffsetOption->GetSelection(); + switch( m_offsetSelection ) + { + case 0: + break; + + case 1: + offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU / 2; + break; + + case 2: + offsetX = m_parent->GetPageSizeIU().x * MM_PER_IU / 2; + offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU / 2; + break; + + case 3: + offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU; + break; } - return true; + BOARD * brd = m_parent->GetBoard(); + DXF2BRD_CONVERTER dxf_importer; + + // Set coordinates offset for import (offset is given in mm) + dxf_importer.SetOffset( offsetX, offsetY ); + m_layer = m_SelLayerBox->GetLayerSelection(); + dxf_importer.SetBrdLayer( m_layer ); + dxf_importer.ImportDxfFile( m_dxfFilename, brd ); + + EndModal( wxID_OK ); +} + + +bool InvokeDXFDialogImport( PCB_EDIT_FRAME* aCaller ) +{ + DIALOG_DXF_IMPORT dlg( aCaller ); + bool success = dlg.ShowModal() == wxID_OK; + + if( success ) + aCaller->OnModify(); + + return success; } diff --git a/pcbnew/import_dxf/dialog_dxf_import.fbp b/pcbnew/import_dxf/dialog_dxf_import.fbp new file mode 100644 index 0000000000..e68140be0f --- /dev/null +++ b/pcbnew/import_dxf/dialog_dxf_import.fbp @@ -0,0 +1,741 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_dxf_import_base + 1000 + none + 1 + dialog_dxf_import + + . + + 1 + 1 + 1 + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + DIALOG_DXF_IMPORT_BASE + + 356,273 + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h + Import DXF file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bSizerMain + wxVERTICAL + none + + 5 + wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Filename: + + 0 + + + 0 + + 1 + m_staticText37 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND|wxBOTTOM + 0 + + + bSizerFile + wxHORIZONTAL + none + + 5 + wxRIGHT|wxLEFT + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + 300,-1 + 1 + m_textCtrlFileName + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Browse + + 0 + + + 0 + + 1 + m_buttonBrowse + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnBrowseDxfFiles + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + "Right top corner" "Middle" "Centered on page" "Right bottom corner" + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Origin of DXF Coordinates + 1 + + 0 + + + 0 + + 1 + m_rbOffsetOption + 1 + + + protected + 1 + + Resizable + 3 + 1 + + wxRA_SPECIFY_COLS + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Board layer for import: + + 0 + + + 0 + + 1 + m_staticTextBrdlayer + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_SelLayerBox + 1 + + + protected + 1 + + Resizable + -1 + 1 + + + PCB_LAYER_BOX_SELECTOR; class_pcb_layer_box_selector.h + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_staticline8 + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALIGN_RIGHT + 0 + + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbSizer1 + protected + + OnCancelClick + + + + OnOKClick + + + + + + + + diff --git a/pcbnew/import_dxf/dialog_dxf_import_base.cpp b/pcbnew/import_dxf/dialog_dxf_import_base.cpp new file mode 100644 index 0000000000..03e80e26a6 --- /dev/null +++ b/pcbnew/import_dxf/dialog_dxf_import_base.cpp @@ -0,0 +1,83 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Oct 8 2012) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "class_pcb_layer_box_selector.h" + +#include "dialog_dxf_import_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_DXF_IMPORT_BASE::DIALOG_DXF_IMPORT_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bSizerMain; + bSizerMain = new wxBoxSizer( wxVERTICAL ); + + m_staticText37 = new wxStaticText( this, wxID_ANY, _("Filename:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText37->Wrap( -1 ); + bSizerMain->Add( m_staticText37, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + + wxBoxSizer* bSizerFile; + bSizerFile = new wxBoxSizer( wxHORIZONTAL ); + + m_textCtrlFileName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_textCtrlFileName->SetMinSize( wxSize( 300,-1 ) ); + + bSizerFile->Add( m_textCtrlFileName, 1, wxRIGHT|wxLEFT, 5 ); + + m_buttonBrowse = new wxButton( this, wxID_ANY, _("Browse"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerFile->Add( m_buttonBrowse, 0, wxRIGHT|wxLEFT, 5 ); + + + bSizerMain->Add( bSizerFile, 0, wxEXPAND|wxBOTTOM, 5 ); + + wxString m_rbOffsetOptionChoices[] = { _("Right top corner"), _("Middle"), _("Centered on page"), _("Right bottom corner") }; + int m_rbOffsetOptionNChoices = sizeof( m_rbOffsetOptionChoices ) / sizeof( wxString ); + m_rbOffsetOption = new wxRadioBox( this, wxID_ANY, _("Origin of DXF Coordinates"), wxDefaultPosition, wxDefaultSize, m_rbOffsetOptionNChoices, m_rbOffsetOptionChoices, 1, wxRA_SPECIFY_COLS ); + m_rbOffsetOption->SetSelection( 3 ); + bSizerMain->Add( m_rbOffsetOption, 0, wxALL|wxEXPAND, 5 ); + + m_staticTextBrdlayer = new wxStaticText( this, wxID_ANY, _("Board layer for import:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextBrdlayer->Wrap( -1 ); + bSizerMain->Add( m_staticTextBrdlayer, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + + m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); + bSizerMain->Add( m_SelLayerBox, 0, wxALL|wxEXPAND, 5 ); + + m_staticline8 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + bSizerMain->Add( m_staticline8, 0, wxEXPAND | wxALL, 5 ); + + m_sdbSizer1 = new wxStdDialogButtonSizer(); + m_sdbSizer1OK = new wxButton( this, wxID_OK ); + m_sdbSizer1->AddButton( m_sdbSizer1OK ); + m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL ); + m_sdbSizer1->AddButton( m_sdbSizer1Cancel ); + m_sdbSizer1->Realize(); + + bSizerMain->Add( m_sdbSizer1, 0, wxALIGN_RIGHT, 5 ); + + + this->SetSizer( bSizerMain ); + this->Layout(); + + this->Centre( wxBOTH ); + + // Connect Events + m_buttonBrowse->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DXF_IMPORT_BASE::OnBrowseDxfFiles ), NULL, this ); + m_sdbSizer1Cancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DXF_IMPORT_BASE::OnCancelClick ), NULL, this ); + m_sdbSizer1OK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DXF_IMPORT_BASE::OnOKClick ), NULL, this ); +} + +DIALOG_DXF_IMPORT_BASE::~DIALOG_DXF_IMPORT_BASE() +{ + // Disconnect Events + m_buttonBrowse->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DXF_IMPORT_BASE::OnBrowseDxfFiles ), NULL, this ); + m_sdbSizer1Cancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DXF_IMPORT_BASE::OnCancelClick ), NULL, this ); + m_sdbSizer1OK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DXF_IMPORT_BASE::OnOKClick ), NULL, this ); + +} diff --git a/pcbnew/import_dxf/dialog_dxf_import_base.h b/pcbnew/import_dxf/dialog_dxf_import_base.h new file mode 100644 index 0000000000..b0e47c0982 --- /dev/null +++ b/pcbnew/import_dxf/dialog_dxf_import_base.h @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Oct 8 2012) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __DIALOG_DXF_IMPORT_BASE_H__ +#define __DIALOG_DXF_IMPORT_BASE_H__ + +#include +#include +#include +class DIALOG_SHIM; +class PCB_LAYER_BOX_SELECTOR; + +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_DXF_IMPORT_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_DXF_IMPORT_BASE : public DIALOG_SHIM +{ + private: + + protected: + wxStaticText* m_staticText37; + wxTextCtrl* m_textCtrlFileName; + wxButton* m_buttonBrowse; + wxRadioBox* m_rbOffsetOption; + wxStaticText* m_staticTextBrdlayer; + PCB_LAYER_BOX_SELECTOR* m_SelLayerBox; + wxStaticLine* m_staticline8; + wxStdDialogButtonSizer* m_sdbSizer1; + wxButton* m_sdbSizer1OK; + wxButton* m_sdbSizer1Cancel; + + // Virtual event handlers, overide them in your derived class + virtual void OnBrowseDxfFiles( wxCommandEvent& event ) { event.Skip(); } + virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); } + virtual void OnOKClick( wxCommandEvent& event ) { event.Skip(); } + + + public: + + DIALOG_DXF_IMPORT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Import DXF file"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 356,273 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~DIALOG_DXF_IMPORT_BASE(); + +}; + +#endif //__DIALOG_DXF_IMPORT_BASE_H__ diff --git a/pcbnew/import_dxf/dxf2brd_items.cpp b/pcbnew/import_dxf/dxf2brd_items.cpp index 5d48bb8e2d..1b8b7df0c8 100644 --- a/pcbnew/import_dxf/dxf2brd_items.cpp +++ b/pcbnew/import_dxf/dxf2brd_items.cpp @@ -72,7 +72,7 @@ int DXF2BRD_CONVERTER::mapX( double aDxfCoordX ) int DXF2BRD_CONVERTER::mapY( double aDxfCoordY ) { - return Millimeter2iu( -m_yOffset - (aDxfCoordY * m_Dfx2mm) ); + return Millimeter2iu( m_yOffset - (aDxfCoordY * m_Dfx2mm) ); } diff --git a/pcbnew/import_dxf/dxf2brd_items.h b/pcbnew/import_dxf/dxf2brd_items.h index 158c34f2ab..c2316aa326 100644 --- a/pcbnew/import_dxf/dxf2brd_items.h +++ b/pcbnew/import_dxf/dxf2brd_items.h @@ -46,6 +46,8 @@ private: double m_yOffset; // Y coord offset for conversion (in mm) double m_defaultThickness; // default line thickness for conversion (in dxf units) double m_Dfx2mm; // The scale factor to convert DXF units to mm + // Seems DRW_Interface always converts DXF coordinates in mm + // (to be confirmed) int m_brdLayer; // The board layer to place imported dfx items int m_version; std::string m_codePage;