Commit 6a9ed328 authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew, dxf import: Add dialog to choose the board import layer, and the...

Pcbnew, dxf import: Add dialog to choose the board import layer, and the position of dxf coordinates origin
parent 7e3551d3
...@@ -117,6 +117,7 @@ set( PCBNEW_DIALOGS ...@@ -117,6 +117,7 @@ set( PCBNEW_DIALOGS
) )
set( PCBNEW_IMPORT_DXF set( PCBNEW_IMPORT_DXF
import_dxf/dialog_dxf_import_base.cpp
import_dxf/dialog_dxf_import.cpp import_dxf/dialog_dxf_import.cpp
import_dxf/dxf2brd_items.cpp import_dxf/dxf2brd_items.cpp
) )
......
/**
* @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 <dxf2brd_items.h> #include <dxf2brd_items.h>
#include <wxPcbStruct.h> #include <wxPcbStruct.h>
#include <convert_from_iu.h> #include <convert_from_iu.h>
#include <dialog_dxf_import_base.h>
#include <class_pcb_layer_box_selector.h>
bool InvokeDXFDialogImport( PCB_EDIT_FRAME* aCaller ) class DIALOG_DXF_IMPORT : public DIALOG_DXF_IMPORT_BASE
{
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( aCaller, wxFileDialog dlg( m_parent,
wxT( "Open File" ), wxT( "Open File" ),
wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString,
wxT( "dxf Files (*.dxf)|*.dxf|*.DXF" ), wxT( "dxf Files (*.dxf)|*.dxf|*.DXF" ),
...@@ -13,17 +102,63 @@ bool InvokeDXFDialogImport( PCB_EDIT_FRAME* aCaller ) ...@@ -13,17 +102,63 @@ bool InvokeDXFDialogImport( PCB_EDIT_FRAME* aCaller )
wxString fileName = dlg.GetPath(); wxString fileName = dlg.GetPath();
if( !fileName.IsEmpty() ) if( fileName.IsEmpty() )
return;
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 )
{ {
BOARD * brd = aCaller->GetBoard(); 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;
}
BOARD * brd = m_parent->GetBoard();
DXF2BRD_CONVERTER dxf_importer; DXF2BRD_CONVERTER dxf_importer;
// Set coordinates offset for import (offset is given in mm) // Set coordinates offset for import (offset is given in mm)
double offsetY = - aCaller->GetPageSizeIU().y * MM_PER_IU; dxf_importer.SetOffset( offsetX, offsetY );
dxf_importer.SetOffset( 0.0, offsetY ); m_layer = m_SelLayerBox->GetLayerSelection();
dxf_importer.SetBrdLayer( DRAW_N ); dxf_importer.SetBrdLayer( m_layer );
dxf_importer.ImportDxfFile( fileName, brd ); 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 true; return success;
} }
This diff is collapsed.
///////////////////////////////////////////////////////////////////////////
// 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 );
}
///////////////////////////////////////////////////////////////////////////
// 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 <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
class DIALOG_SHIM;
class PCB_LAYER_BOX_SELECTOR;
#include "dialog_shim.h"
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/textctrl.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/radiobox.h>
#include <wx/bmpcbox.h>
#include <wx/statline.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// 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__
...@@ -72,7 +72,7 @@ int DXF2BRD_CONVERTER::mapX( double aDxfCoordX ) ...@@ -72,7 +72,7 @@ int DXF2BRD_CONVERTER::mapX( double aDxfCoordX )
int DXF2BRD_CONVERTER::mapY( double aDxfCoordY ) int DXF2BRD_CONVERTER::mapY( double aDxfCoordY )
{ {
return Millimeter2iu( -m_yOffset - (aDxfCoordY * m_Dfx2mm) ); return Millimeter2iu( m_yOffset - (aDxfCoordY * m_Dfx2mm) );
} }
......
...@@ -46,6 +46,8 @@ private: ...@@ -46,6 +46,8 @@ private:
double m_yOffset; // Y coord offset for conversion (in mm) double m_yOffset; // Y coord offset for conversion (in mm)
double m_defaultThickness; // default line thickness for conversion (in dxf units) double m_defaultThickness; // default line thickness for conversion (in dxf units)
double m_Dfx2mm; // The scale factor to convert DXF units to mm 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_brdLayer; // The board layer to place imported dfx items
int m_version; int m_version;
std::string m_codePage; std::string m_codePage;
......
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