2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file set_grid.cpp
|
|
|
|
* @brief Manage user grid.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "wxBasePcbFrame.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "pcbnew.h"
|
2009-09-22 12:27:57 +00:00
|
|
|
#include "pcbnew_id.h"
|
2010-07-13 10:42:32 +00:00
|
|
|
#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:
|
|
|
|
int m_internalUnits;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DIALOG_SET_GRID( wxWindow* parent, const wxPoint& pos );
|
|
|
|
~DIALOG_SET_GRID() { }
|
|
|
|
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
|
|
|
|
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-13 10:42:32 +00:00
|
|
|
dlg.m_internalUnits = m_InternalUnits;
|
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-09-09 11:02:03 +00:00
|
|
|
if( m_SelGridBox )
|
|
|
|
dlg.SetGridForFastSwitching( m_SelGridBox->GetStrings(), m_FastGrid1, m_FastGrid2 );
|
|
|
|
|
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
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
DrawPanel->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-14 13:24:36 +00:00
|
|
|
SetFocus();
|
|
|
|
|
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
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
msg.Printf( wxT( "%.4f" ), grid.x );
|
|
|
|
m_OptGridSizeX->SetValue( msg );
|
|
|
|
msg.Printf( wxT( "%.4f" ), grid.y );
|
|
|
|
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. */
|
2010-07-14 13:24:36 +00:00
|
|
|
grid.x = ReturnValueFromTextCtrl( *m_GridOriginXCtrl, m_internalUnits );
|
|
|
|
grid.y = ReturnValueFromTextCtrl( *m_GridOriginYCtrl, m_internalUnits );
|
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
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
PutValueInLocalUnits( *m_GridOriginXCtrl, grid.x, m_internalUnits );
|
|
|
|
PutValueInLocalUnits( *m_GridOriginYCtrl, grid.y, m_internalUnits );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
2011-09-09 11:02:03 +00:00
|
|
|
void DIALOG_SET_GRID::SetGridForFastSwitching( wxArrayString aGrids, int aGrid1, int aGrid2 )
|
|
|
|
{
|
|
|
|
for( wxArrayString::iterator i = aGrids.begin(); i != aGrids.end(); i++ )
|
|
|
|
{
|
|
|
|
m_comboBoxGrid1->Append( *i );
|
|
|
|
m_comboBoxGrid2->Append( *i );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_comboBoxGrid1->SetSelection( aGrid1 );
|
|
|
|
m_comboBoxGrid2->SetSelection( aGrid2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
/*************************************************************************/
|
2010-07-14 13:24:36 +00:00
|
|
|
void DIALOG_SET_GRID::OnOkClick( wxCommandEvent& event )
|
2010-07-13 10:42:32 +00:00
|
|
|
/*************************************************************************/
|
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
|
|
|
}
|