2011-09-23 13:57:12 +00:00
|
|
|
/**
|
2013-06-05 14:24:03 +00:00
|
|
|
* @file dialog_set_grid.cpp
|
2011-09-23 13:57:12 +00:00
|
|
|
* @brief Manage user grid.
|
|
|
|
*/
|
2013-02-26 11:25:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2013-07-09 05:48:26 +00:00
|
|
|
#include <macros.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <common.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <pcbnew_id.h>
|
|
|
|
#include <dialog_set_grid_base.h>
|
2013-07-09 05:48:26 +00:00
|
|
|
#include <invoke_pcb_dialog.h>
|
2008-12-05 16:03:05 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
class DIALOG_SET_GRID : public DIALOG_SET_GRID_BASE
|
2010-07-13 10:42:32 +00:00
|
|
|
{
|
2010-07-14 13:24:36 +00:00
|
|
|
public:
|
2013-06-05 14:24:03 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
/// This has no dependencies on calling wxFrame derivative, such as PCB_BASE_FRAME.
|
|
|
|
DIALOG_SET_GRID( wxFrame* aCaller, EDA_UNITS_T* aGridUnits, EDA_UNITS_T aBoardUnits,
|
|
|
|
wxRealPoint* aUserSize, wxPoint* aOrigin,
|
|
|
|
int* aFastGrid1, int* aFastGrid2, const wxArrayString& aGridChoices );
|
2010-07-14 13:24:36 +00:00
|
|
|
|
|
|
|
private:
|
2013-07-09 05:48:26 +00:00
|
|
|
void OnResetGridOrgClick( wxCommandEvent& event );
|
|
|
|
void OnCancelClick( wxCommandEvent& event );
|
|
|
|
void OnOkClick( wxCommandEvent& event );
|
2009-02-07 20:11:09 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
EDA_UNITS_T& m_callers_grid_units;
|
|
|
|
EDA_UNITS_T m_callers_board_units;
|
|
|
|
wxRealPoint& m_callers_user_size;
|
|
|
|
wxPoint& m_callers_origin;
|
|
|
|
int& m_callers_fast_grid1;
|
|
|
|
int& m_callers_fast_grid2;
|
2013-06-05 14:24:03 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
void setGridUnits( EDA_UNITS_T units );
|
|
|
|
EDA_UNITS_T getGridUnits();
|
2008-12-05 16:03:05 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
void setGridSize( const wxRealPoint& grid );
|
|
|
|
wxRealPoint getGridSize();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
void setGridOrigin( const wxPoint& grid );
|
|
|
|
wxPoint getGridOrigin();
|
2011-09-09 11:02:03 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
void setGridForFastSwitching( const wxArrayString& aGrids, int aGrid1, int aGrid2 );
|
|
|
|
void getGridForFastSwitching( int& aGrid1, int& aGrid2 );
|
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
DIALOG_SET_GRID::DIALOG_SET_GRID( wxFrame* aCaller, EDA_UNITS_T* aGridUnits, EDA_UNITS_T aBoardUnits,
|
|
|
|
wxRealPoint* aUserSize, wxPoint* aOrigin, int* aFastGrid1, int* aFastGrid2, const wxArrayString& aGridChoices ):
|
|
|
|
DIALOG_SET_GRID_BASE( aCaller ),
|
|
|
|
m_callers_grid_units( *aGridUnits ),
|
|
|
|
m_callers_board_units( aBoardUnits ),
|
|
|
|
m_callers_user_size( *aUserSize ),
|
|
|
|
m_callers_origin( *aOrigin ),
|
|
|
|
m_callers_fast_grid1( *aFastGrid1 ),
|
|
|
|
m_callers_fast_grid2( *aFastGrid2 )
|
|
|
|
{
|
|
|
|
m_TextPosXUnits->SetLabel( GetUnitsLabel( m_callers_board_units ) );
|
|
|
|
m_TextPosYUnits->SetLabel( GetUnitsLabel( m_callers_board_units ) );
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
m_sdbSizer1OK->SetDefault(); // set OK button as default response to 'Enter' key
|
2011-09-09 11:02:03 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
setGridUnits( m_callers_grid_units );
|
|
|
|
setGridSize( m_callers_user_size );
|
|
|
|
setGridOrigin( m_callers_origin );
|
|
|
|
setGridForFastSwitching( aGridChoices, m_callers_fast_grid1, m_callers_fast_grid2 );
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Fit();
|
|
|
|
Centre();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
void DIALOG_SET_GRID::setGridUnits( EDA_UNITS_T aUnits )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-07-09 05:48:26 +00:00
|
|
|
m_UnitGrid->SetSelection( aUnits != INCHES );
|
|
|
|
}
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
|
|
|
|
EDA_UNITS_T DIALOG_SET_GRID::getGridUnits()
|
|
|
|
{
|
|
|
|
return m_UnitGrid->GetSelection() == 0 ? INCHES : MILLIMETRES;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
void DIALOG_SET_GRID::setGridSize( const wxRealPoint& grid )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-07-13 10:42:32 +00:00
|
|
|
wxString msg;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-06-05 14:24:03 +00:00
|
|
|
msg.Printf( wxT( "%.10g" ), grid.x );
|
2010-07-13 10:42:32 +00:00
|
|
|
m_OptGridSizeX->SetValue( msg );
|
2013-06-05 14:24:03 +00:00
|
|
|
|
|
|
|
msg.Printf( wxT( "%.10g" ), grid.y );
|
2010-07-13 10:42:32 +00:00
|
|
|
m_OptGridSizeY->SetValue( msg );
|
|
|
|
}
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
wxRealPoint DIALOG_SET_GRID::getGridSize()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-07-13 10:42:32 +00:00
|
|
|
wxRealPoint grid;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
// @todo: Some error checking here would be a good thing.
|
|
|
|
wxString x = m_OptGridSizeX->GetValue();
|
|
|
|
wxString y = m_OptGridSizeY->GetValue();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
x.ToDouble( &grid.x );
|
|
|
|
y.ToDouble( &grid.y );
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
return grid;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
wxPoint DIALOG_SET_GRID::getGridOrigin()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-07-13 10:42:32 +00:00
|
|
|
wxPoint grid;
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
// @todo Some error checking here would be a good thing.
|
2012-04-16 17:39:32 +00:00
|
|
|
grid.x = ReturnValueFromTextCtrl( *m_GridOriginXCtrl );
|
|
|
|
grid.y = ReturnValueFromTextCtrl( *m_GridOriginYCtrl );
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
return grid;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
void DIALOG_SET_GRID::setGridOrigin( const wxPoint& grid )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2012-04-13 18:51:24 +00:00
|
|
|
PutValueInLocalUnits( *m_GridOriginXCtrl, grid.x );
|
|
|
|
PutValueInLocalUnits( *m_GridOriginYCtrl, grid.y );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
2013-06-05 14:24:03 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
void DIALOG_SET_GRID::setGridForFastSwitching( const wxArrayString& aGrids, int aGrid1, int aGrid2 )
|
2011-09-09 11:02:03 +00:00
|
|
|
{
|
2013-02-26 11:25:30 +00:00
|
|
|
m_comboBoxGrid1->Append( aGrids );
|
|
|
|
m_comboBoxGrid2->Append( aGrids );
|
2011-09-09 11:02:03 +00:00
|
|
|
|
|
|
|
m_comboBoxGrid1->SetSelection( aGrid1 );
|
|
|
|
m_comboBoxGrid2->SetSelection( aGrid2 );
|
|
|
|
}
|
|
|
|
|
2013-06-05 14:24:03 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
void DIALOG_SET_GRID::getGridForFastSwitching( int& aGrid1, int& aGrid2 )
|
2011-09-09 11:02:03 +00:00
|
|
|
{
|
|
|
|
aGrid1 = m_comboBoxGrid1->GetSelection();
|
|
|
|
aGrid2 = m_comboBoxGrid2->GetSelection();
|
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
void DIALOG_SET_GRID::OnResetGridOrgClick( wxCommandEvent& event )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2013-07-09 05:48:26 +00:00
|
|
|
setGridOrigin( wxPoint( 0, 0 ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
void DIALOG_SET_GRID::OnCancelClick( wxCommandEvent& event )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-07-14 13:24:36 +00:00
|
|
|
EndModal( wxID_CANCEL );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
|
|
|
|
void DIALOG_SET_GRID::OnOkClick( wxCommandEvent& event )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2013-07-09 05:48:26 +00:00
|
|
|
m_callers_grid_units = getGridUnits();
|
|
|
|
m_callers_user_size = getGridSize();
|
|
|
|
m_callers_origin = getGridOrigin();
|
|
|
|
|
|
|
|
getGridForFastSwitching( m_callers_fast_grid1, m_callers_fast_grid2 );
|
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
EndModal( wxID_OK );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2013-07-09 05:48:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxBasePcbFrame.h>
|
|
|
|
|
|
|
|
bool PCB_BASE_FRAME::InvokeDialogGrid()
|
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
wxPoint grid_origin = GetGridOrigin();
|
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
DIALOG_SET_GRID dlg( this, &m_UserGridUnit, g_UserUnit, &m_UserGridSize,
|
2013-08-03 05:15:23 +00:00
|
|
|
&grid_origin, &m_FastGrid1, &m_FastGrid2,
|
2013-07-09 05:48:26 +00:00
|
|
|
m_gridSelectBox->GetStrings() );
|
|
|
|
|
|
|
|
int ret = dlg.ShowModal();
|
|
|
|
|
|
|
|
if( ret == wxID_OK )
|
|
|
|
{
|
2013-08-03 16:16:57 +00:00
|
|
|
if( GetGridOrigin() != grid_origin && IsType( PCB_FRAME_TYPE ) )
|
|
|
|
OnModify(); // because grid origin is saved in board, show as modified
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
SetGridOrigin( grid_origin );
|
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
GetScreen()->AddGrid( m_UserGridSize, m_UserGridUnit, ID_POPUP_GRID_USER );
|
|
|
|
|
|
|
|
// If the user grid is the current option, recall SetGrid()
|
|
|
|
// to force new values put in list as current grid value
|
|
|
|
if( GetScreen()->GetGridId() == ID_POPUP_GRID_USER )
|
|
|
|
GetScreen()->SetGrid( ID_POPUP_GRID_USER );
|
|
|
|
|
|
|
|
m_canvas->Refresh();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|