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>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxBasePcbFrame.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>
|
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:
|
|
|
|
DIALOG_SET_GRID( wxWindow* parent, const wxPoint& pos );
|
2013-06-05 14:24:03 +00:00
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
void SetGridSize( const wxRealPoint& grid );
|
|
|
|
wxRealPoint GetGridSize();
|
|
|
|
void SetGridUnits( int units );
|
|
|
|
int GetGridUnits();
|
|
|
|
void SetGridOrigin( const wxPoint& grid );
|
|
|
|
wxPoint GetGridOrigin();
|
2011-09-09 11:02:03 +00:00
|
|
|
void SetGridForFastSwitching( wxArrayString aGrids, int aGrid1, int aGrid2 );
|
|
|
|
void GetGridForFastSwitching( int& aGrid1, int& aGrid2 );
|
2010-07-14 13:24:36 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void OnResetGridOrgClick( wxCommandEvent& event );
|
|
|
|
void OnCancelClick( wxCommandEvent& event );
|
|
|
|
void OnOkClick( wxCommandEvent& event );
|
2010-07-13 10:42:32 +00:00
|
|
|
};
|
2009-02-07 20:11:09 +00:00
|
|
|
|
2013-06-05 14:24:03 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_BASE_FRAME::InstallGridFrame( const wxPoint& pos )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-07-13 10:42:32 +00:00
|
|
|
DIALOG_SET_GRID dlg( this, pos );
|
2008-12-05 16:03:05 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
dlg.SetGridUnits( m_UserGridUnit );
|
2010-07-13 10:42:32 +00:00
|
|
|
dlg.SetGridSize( m_UserGridSize );
|
|
|
|
dlg.SetGridOrigin( GetScreen()->m_GridOrigin );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-14 20:03:15 +00:00
|
|
|
if( m_gridSelectBox )
|
|
|
|
dlg.SetGridForFastSwitching( m_gridSelectBox->GetStrings(), m_FastGrid1, m_FastGrid2 );
|
2011-09-09 11:02:03 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2009-04-05 20:49:15 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
m_UserGridSize = dlg.GetGridSize();
|
2011-09-06 19:42:46 +00:00
|
|
|
m_UserGridUnit = (EDA_UNITS_T) dlg.GetGridUnits();
|
2010-07-14 13:24:36 +00:00
|
|
|
GetScreen()->m_GridOrigin = dlg.GetGridOrigin();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
GetScreen()->AddGrid( m_UserGridSize, m_UserGridUnit, ID_POPUP_GRID_USER );
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2011-09-09 11:02:03 +00:00
|
|
|
dlg.GetGridForFastSwitching( m_FastGrid1, m_FastGrid2 );
|
|
|
|
|
2010-02-12 12:52:26 +00:00
|
|
|
// 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 );
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
DIALOG_SET_GRID::DIALOG_SET_GRID( wxWindow* parent, const wxPoint& pos ) :
|
|
|
|
DIALOG_SET_GRID_BASE( parent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-07-13 10:42:32 +00:00
|
|
|
m_TextPosXUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
|
|
|
|
m_TextPosYUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
|
|
|
|
|
2011-03-14 15:17:18 +00:00
|
|
|
m_sdbSizer1OK->SetDefault();
|
2010-07-13 10:42:32 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
2010-07-14 13:24:36 +00:00
|
|
|
Centre();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2010-07-13 10:42:32 +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
|
|
|
|
2010-07-13 10:42:32 +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
|
|
|
|
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
/* TODO: Some error checking here would be a good thing. */
|
|
|
|
m_OptGridSizeX->GetValue().ToDouble( &grid.x );
|
|
|
|
m_OptGridSizeY->GetValue().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
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
void DIALOG_SET_GRID::SetGridUnits( int units )
|
2008-12-05 16:03:05 +00:00
|
|
|
{
|
2010-07-13 10:42:32 +00:00
|
|
|
if( units != INCHES )
|
|
|
|
m_UnitGrid->SetSelection( 1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
int DIALOG_SET_GRID::GetGridUnits()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-07-13 10:42:32 +00:00
|
|
|
return m_UnitGrid->GetSelection();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
|
2010-07-13 10:42:32 +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
|
|
|
|
2010-07-13 10:42:32 +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
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
void DIALOG_SET_GRID::SetGridOrigin( const wxPoint& grid )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2010-07-14 13:24:36 +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
|
|
|
|
2011-09-09 11:02:03 +00:00
|
|
|
void DIALOG_SET_GRID::SetGridForFastSwitching( wxArrayString aGrids, int aGrid1, int aGrid2 )
|
|
|
|
{
|
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
|
|
|
|
2011-09-09 11:02:03 +00:00
|
|
|
void DIALOG_SET_GRID::GetGridForFastSwitching( int& aGrid1, int& aGrid2 )
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2010-07-14 13:24:36 +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
|
|
|
{
|
2010-07-14 13:24:36 +00:00
|
|
|
EndModal( wxID_OK );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|