Pcbnew: add user position option to DXF import dialog.

* Dialog UI policy fixes and layout improvement provided by Wayne Stambaugh.
This commit is contained in:
Cirilo Bernardo 2015-08-27 14:10:28 -04:00 committed by Wayne Stambaugh
parent 51a6d389fb
commit adddfd22a3
5 changed files with 1111 additions and 379 deletions

View File

@ -7,7 +7,7 @@
* 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.
* Copyright (C) 1992-2015 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
@ -28,7 +28,6 @@
*/
#include <dialog_dxf_import.h>
//#include <pgm_base.h>
#include <kiface_i.h>
#include <convert_from_iu.h>
#include <class_pcb_layer_box_selector.h>
@ -43,11 +42,15 @@
#define DXF_IMPORT_LAYER_OPTION_KEY wxT("DxfImportBrdLayer")
#define DXF_IMPORT_COORD_ORIGIN_KEY wxT("DxfImportCoordOrigin")
#define DXF_IMPORT_LAST_FILE_KEY wxT("DxfImportLastFile")
#define DXF_IMPORT_GRID_UNITS_KEY wxT("DxfImportGridUnits")
#define DXF_IMPORT_GRID_OFFSET_X_KEY wxT("DxfImportGridOffsetX")
#define DXF_IMPORT_GRID_OFFSET_Y_KEY wxT("DxfImportGridOffsetY")
// 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;
int DIALOG_DXF_IMPORT::m_offsetSelection = 0;
LAYER_NUM DIALOG_DXF_IMPORT::m_layer = Dwgs_User;
@ -56,14 +59,28 @@ DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT( PCB_BASE_FRAME* aParent )
{
m_parent = aParent;
m_config = Kiface().KifaceSettings();
m_PCBGridUnits = 0;
m_PCBGridOffsetX = 0.0;
m_PCBGridOffsetY = 0.0;
if( m_config )
{
m_layer = m_config->Read( DXF_IMPORT_LAYER_OPTION_KEY, (long)Dwgs_User );
m_offsetSelection = m_config->Read( DXF_IMPORT_COORD_ORIGIN_KEY, 3 );
m_offsetSelection = m_config->Read( DXF_IMPORT_COORD_ORIGIN_KEY, (long)0 );
m_dxfFilename = m_config->Read( DXF_IMPORT_LAST_FILE_KEY, wxEmptyString );
m_config->Read( DXF_IMPORT_GRID_UNITS_KEY, &m_PCBGridUnits, 0 );
m_config->Read( DXF_IMPORT_GRID_OFFSET_X_KEY, &m_PCBGridOffsetX, 0.0 );
m_config->Read( DXF_IMPORT_GRID_OFFSET_Y_KEY, &m_PCBGridOffsetY, 0.0 );
}
m_DXFPCBGridUnits->SetSelection( m_PCBGridUnits );
wxString tmpStr;
tmpStr << m_PCBGridOffsetX;
m_DXFPCBXCoord->SetValue( tmpStr );
tmpStr = wxT( "" );
tmpStr << m_PCBGridOffsetY;
m_DXFPCBYCoord->SetValue( tmpStr );
m_textCtrlFileName->SetValue( m_dxfFilename );
m_rbOffsetOption->SetSelection( m_offsetSelection );
@ -79,6 +96,7 @@ DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT( PCB_BASE_FRAME* aParent )
m_SelLayerBox->SetLayerSelection( m_layer );
}
m_sdbSizer1OK->SetDefault();
GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this );
Centre();
@ -95,6 +113,10 @@ DIALOG_DXF_IMPORT::~DIALOG_DXF_IMPORT()
m_config->Write( DXF_IMPORT_LAYER_OPTION_KEY, (long)m_layer );
m_config->Write( DXF_IMPORT_COORD_ORIGIN_KEY, m_offsetSelection );
m_config->Write( DXF_IMPORT_LAST_FILE_KEY, m_dxfFilename );
m_config->Write( DXF_IMPORT_GRID_UNITS_KEY, GetPCBGridUnits() );
m_config->Write( DXF_IMPORT_GRID_OFFSET_X_KEY, m_DXFPCBXCoord->GetValue() );
m_config->Write( DXF_IMPORT_GRID_OFFSET_Y_KEY, m_DXFPCBYCoord->GetValue() );
}
}
@ -110,10 +132,11 @@ void DIALOG_DXF_IMPORT::OnBrowseDxfFiles( wxCommandEvent& event )
path = fn.GetPath();
filename = fn.GetFullName();
}
wxFileDialog dlg( m_parent,
wxT( "Open File" ),
_( "Open File" ),
path, filename,
wxT( "dxf Files (*.dxf)|*.dxf" ),
wxT( "DXF Files (*.dxf)|*.dxf" ),
wxFD_OPEN|wxFD_FILE_MUST_EXIST );
if( dlg.ShowModal() != wxID_OK )
@ -140,23 +163,34 @@ void DIALOG_DXF_IMPORT::OnOKClick( wxCommandEvent& event )
double offsetY = 0;
m_offsetSelection = m_rbOffsetOption->GetSelection();
switch( m_offsetSelection )
{
case 0:
break;
case 0:
offsetX = m_parent->GetPageSizeIU().x * MM_PER_IU / 2;
offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU / 2;
break;
case 1:
offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU / 2;
break;
case 1:
break;
case 2:
offsetX = m_parent->GetPageSizeIU().x * MM_PER_IU / 2;
offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU / 2;
break;
case 2:
offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU / 2;
break;
case 3:
offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU;
break;
case 3:
offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU;
break;
case 4:
GetPCBGridOffsets( offsetX, offsetY );
if( GetPCBGridUnits() )
{
offsetX *= 25.4;
offsetY *= 25.4;
}
break;
}
// Set coordinates offset for import (offset is given in mm)
@ -215,6 +249,7 @@ bool InvokeDXFDialogModuleImport( PCB_BASE_FRAME* aCaller, MODULE* aModule )
aCaller->OnModify();
std::list<BOARD_ITEM*>::const_iterator it, itEnd;
for( it = list.begin(), itEnd = list.end(); it != itEnd; ++it )
{
BOARD_ITEM* item = *it;
@ -253,3 +288,26 @@ bool InvokeDXFDialogModuleImport( PCB_BASE_FRAME* aCaller, MODULE* aModule )
return success;
}
void DIALOG_DXF_IMPORT::OriginOptionOnUpdateUI( wxUpdateUIEvent& event )
{
bool enable = m_rbOffsetOption->GetSelection() == 4;
m_DXFPCBGridUnits->Enable( enable );
m_DXFPCBXCoord->Enable( enable );
m_DXFPCBYCoord->Enable( enable );
}
int DIALOG_DXF_IMPORT::GetPCBGridUnits( void )
{
return m_DXFPCBGridUnits->GetSelection();
}
void DIALOG_DXF_IMPORT::GetPCBGridOffsets( double &aXOffset, double &aYOffset )
{
aXOffset = DoubleValueFromString( UNSCALED_UNITS, m_DXFPCBXCoord->GetValue() );
aYOffset = DoubleValueFromString( UNSCALED_UNITS, m_DXFPCBYCoord->GetValue() );
return;
}

File diff suppressed because it is too large Load Diff

View File

@ -46,6 +46,9 @@ private:
PCB_BASE_FRAME* m_parent;
wxConfigBase* m_config; // Current config
DXF2BRD_CONVERTER m_dxfImporter;
int m_PCBGridUnits;
double m_PCBGridOffsetX;
double m_PCBGridOffsetY;
static wxString m_dxfFilename;
static int m_offsetSelection;
@ -55,4 +58,7 @@ private:
void OnCancelClick( wxCommandEvent& event ) { event.Skip(); }
void OnOKClick( wxCommandEvent& event );
void OnBrowseDxfFiles( wxCommandEvent& event );
void OriginOptionOnUpdateUI( wxUpdateUIEvent& event );
int GetPCBGridUnits( void );
void GetPCBGridOffsets( double &aXOffset, double &aYOffset );
};

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 8 2012)
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -18,39 +18,107 @@ DIALOG_DXF_IMPORT_BASE::DIALOG_DXF_IMPORT_BASE( wxWindow* parent, wxWindowID id,
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_staticText37 = new wxStaticText( this, wxID_ANY, _("File:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText37->Wrap( -1 );
bSizerFile->Add( m_staticText37, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
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 );
bSizerFile->Add( m_textCtrlFileName, 1, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP, 5 );
m_buttonBrowse = new wxButton( this, wxID_ANY, _("Browse"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerFile->Add( m_buttonBrowse, 0, wxRIGHT|wxLEFT, 5 );
bSizerFile->Add( m_buttonBrowse, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP, 5 );
bSizerMain->Add( bSizerFile, 0, wxEXPAND|wxBOTTOM, 5 );
bSizerMain->Add( bSizerFile, 0, wxALL|wxEXPAND, 5 );
wxString m_rbOffsetOptionChoices[] = { _("Right top corner"), _("Middle"), _("Centered on page"), _("Right bottom corner") };
wxBoxSizer* bSizer3;
bSizer3 = new wxBoxSizer( wxHORIZONTAL );
wxString m_rbOffsetOptionChoices[] = { _("Center of page"), _("Upper left corner of page"), _("Center left side of page"), _("Lower left corner of page"), _("User defined position") };
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_rbOffsetOption = new wxRadioBox( this, wxID_ORIGIN_SELECT, _("Place DXF origin (0,0) point:"), wxDefaultPosition, wxDefaultSize, m_rbOffsetOptionNChoices, m_rbOffsetOptionChoices, 1, wxRA_SPECIFY_COLS );
m_rbOffsetOption->SetSelection( 0 );
bSizer3->Add( m_rbOffsetOption, 0, wxALL|wxEXPAND, 5 );
m_staticTextBrdlayer = new wxStaticText( this, wxID_ANY, _("Board layer for import:"), wxDefaultPosition, wxDefaultSize, 0 );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bSizer6;
bSizer6 = new wxBoxSizer( wxHORIZONTAL );
m_staticText4 = new wxStaticText( this, wxID_ANY, _("X Position:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText4->Wrap( -1 );
bSizer6->Add( m_staticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_DXFPCBXCoord = new wxTextCtrl( this, wxID_ANY, _("0.0"), wxDefaultPosition, wxDefaultSize, 0 );
m_DXFPCBXCoord->SetMaxLength( 10 );
m_DXFPCBXCoord->SetToolTip( _("DXF origin on PCB Grid, X Coordinate") );
bSizer6->Add( m_DXFPCBXCoord, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
bSizer4->Add( bSizer6, 1, wxEXPAND, 5 );
wxBoxSizer* bSizer7;
bSizer7 = new wxBoxSizer( wxHORIZONTAL );
m_staticText5 = new wxStaticText( this, wxID_ANY, _("Y Position:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText5->Wrap( -1 );
bSizer7->Add( m_staticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_DXFPCBYCoord = new wxTextCtrl( this, wxID_ANY, _("0.0"), wxDefaultPosition, wxDefaultSize, 0 );
m_DXFPCBYCoord->SetMaxLength( 10 );
m_DXFPCBYCoord->SetToolTip( _("DXF origin on PCB Grid, Y Coordinate") );
bSizer7->Add( m_DXFPCBYCoord, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
bSizer4->Add( bSizer7, 1, wxEXPAND, 5 );
wxBoxSizer* bSizer5;
bSizer5 = new wxBoxSizer( wxHORIZONTAL );
m_staticText3 = new wxStaticText( this, wxID_ANY, _("Units:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText3->Wrap( -1 );
bSizer5->Add( m_staticText3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
wxString m_DXFPCBGridUnitsChoices[] = { _("mm"), _("inch") };
int m_DXFPCBGridUnitsNChoices = sizeof( m_DXFPCBGridUnitsChoices ) / sizeof( wxString );
m_DXFPCBGridUnits = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_DXFPCBGridUnitsNChoices, m_DXFPCBGridUnitsChoices, 0 );
m_DXFPCBGridUnits->SetSelection( 0 );
m_DXFPCBGridUnits->SetToolTip( _("Select PCB grid units") );
bSizer5->Add( m_DXFPCBGridUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
bSizer4->Add( bSizer5, 1, wxEXPAND, 5 );
bSizer3->Add( bSizer4, 1, 0, 5 );
bSizerMain->Add( bSizer3, 1, wxALL|wxEXPAND, 5 );
wxBoxSizer* bSizer8;
bSizer8 = new wxBoxSizer( wxHORIZONTAL );
m_staticTextBrdlayer = new wxStaticText( this, wxID_ANY, _("Layer:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextBrdlayer->Wrap( -1 );
bSizerMain->Add( m_staticTextBrdlayer, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
bSizer8->Add( m_staticTextBrdlayer, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxTOP, 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 );
bSizer8->Add( m_SelLayerBox, 1, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 5 );
bSizerMain->Add( bSizer8, 0, wxALL|wxEXPAND, 5 );
m_staticline8 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizerMain->Add( m_staticline8, 0, wxEXPAND | wxALL, 5 );
bSizerMain->Add( m_staticline8, 0, wxALL|wxEXPAND, 5 );
m_sdbSizer1 = new wxStdDialogButtonSizer();
m_sdbSizer1OK = new wxButton( this, wxID_OK );
@ -59,16 +127,18 @@ DIALOG_DXF_IMPORT_BASE::DIALOG_DXF_IMPORT_BASE( wxWindow* parent, wxWindowID id,
m_sdbSizer1->AddButton( m_sdbSizer1Cancel );
m_sdbSizer1->Realize();
bSizerMain->Add( m_sdbSizer1, 0, wxALIGN_RIGHT, 5 );
bSizerMain->Add( m_sdbSizer1, 0, wxALIGN_RIGHT|wxBOTTOM|wxLEFT|wxRIGHT, 5 );
this->SetSizer( bSizerMain );
this->Layout();
bSizerMain->Fit( this );
this->Centre( wxBOTH );
// Connect Events
m_buttonBrowse->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DXF_IMPORT_BASE::OnBrowseDxfFiles ), NULL, this );
m_rbOffsetOption->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_DXF_IMPORT_BASE::OriginOptionOnUpdateUI ), 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 );
}
@ -77,6 +147,7 @@ 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_rbOffsetOption->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_DXF_IMPORT_BASE::OriginOptionOnUpdateUI ), 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 );

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 8 2012)
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
@ -25,12 +25,15 @@ class PCB_LAYER_BOX_SELECTOR;
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/radiobox.h>
#include <wx/valtext.h>
#include <wx/choice.h>
#include <wx/bmpcbox.h>
#include <wx/statline.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
#define wxID_ORIGIN_SELECT 1000
///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_DXF_IMPORT_BASE
@ -44,6 +47,12 @@ class DIALOG_DXF_IMPORT_BASE : public DIALOG_SHIM
wxTextCtrl* m_textCtrlFileName;
wxButton* m_buttonBrowse;
wxRadioBox* m_rbOffsetOption;
wxStaticText* m_staticText4;
wxTextCtrl* m_DXFPCBXCoord;
wxStaticText* m_staticText5;
wxTextCtrl* m_DXFPCBYCoord;
wxStaticText* m_staticText3;
wxChoice* m_DXFPCBGridUnits;
wxStaticText* m_staticTextBrdlayer;
PCB_LAYER_BOX_SELECTOR* m_SelLayerBox;
wxStaticLine* m_staticline8;
@ -53,13 +62,14 @@ class DIALOG_DXF_IMPORT_BASE : public DIALOG_SHIM
// Virtual event handlers, overide them in your derived class
virtual void OnBrowseDxfFiles( wxCommandEvent& event ) { event.Skip(); }
virtual void OriginOptionOnUpdateUI( wxUpdateUIEvent& 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( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Import DXF File"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_DXF_IMPORT_BASE();
};