2013-02-26 11:25:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-05-02 14:15:24 +00:00
|
|
|
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-02-26 11:25:30 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
/**
|
|
|
|
* @file dialog_set_grid.cpp
|
|
|
|
* @brief Manage user grid.
|
|
|
|
*/
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_set_grid_base.h>
|
2015-04-30 08:46:06 +00:00
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
#include <base_units.h>
|
|
|
|
#include <convert_to_biu.h>
|
|
|
|
#include <common.h>
|
|
|
|
|
2018-01-29 15:39:40 +00:00
|
|
|
#include <pcb_base_frame.h>
|
2016-05-02 14:15:24 +00:00
|
|
|
#include <class_drawpanel.h>
|
2015-04-10 23:43:15 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
2016-05-02 14:15:24 +00:00
|
|
|
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2017-02-21 12:42:08 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
2016-05-02 14:15:24 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
|
|
|
|
#include <limits.h>
|
2008-12-05 16:03:05 +00:00
|
|
|
|
2015-06-28 14:11:57 +00:00
|
|
|
// Max values for grid size
|
2018-02-15 15:40:40 +00:00
|
|
|
static const double MAX_GRID_SIZE = 1000.0 * IU_PER_MM;
|
2016-05-02 14:15:24 +00:00
|
|
|
static const double MIN_GRID_SIZE = 0.001 * IU_PER_MM;
|
2015-06-28 14:11:57 +00:00
|
|
|
|
|
|
|
// Min/Max value for grid offset
|
2016-05-02 14:15:24 +00:00
|
|
|
static const double MAX_GRID_OFFSET = INT_MAX / 2.0;
|
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
|
|
|
{
|
2016-07-14 14:25:35 +00:00
|
|
|
PCB_BASE_FRAME* m_parent;
|
|
|
|
wxArrayString m_fast_grid_opts;
|
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
public:
|
2013-07-09 05:48:26 +00:00
|
|
|
/// This has no dependencies on calling wxFrame derivative, such as PCB_BASE_FRAME.
|
2016-05-02 14:15:24 +00:00
|
|
|
DIALOG_SET_GRID( PCB_BASE_FRAME* aParent, const wxArrayString& aGridChoices );
|
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
bool TransferDataFromWindow() override;
|
|
|
|
bool TransferDataToWindow() override;
|
2010-07-14 13:24:36 +00:00
|
|
|
|
|
|
|
private:
|
2016-09-24 18:53:15 +00:00
|
|
|
void OnResetGridOrgClick( wxCommandEvent& event ) override;
|
2016-09-25 17:06:49 +00:00
|
|
|
void OnInitDlg( wxInitDialogEvent& event ) override
|
2016-07-14 14:25:35 +00:00
|
|
|
{
|
|
|
|
// Call the default wxDialog handler of a wxInitDialogEvent
|
|
|
|
TransferDataToWindow();
|
2009-02-07 20:11:09 +00:00
|
|
|
|
2016-07-14 14:25:35 +00:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
FinishDialogSettings();
|
|
|
|
}
|
2013-06-05 14:24:03 +00:00
|
|
|
|
2018-02-24 11:24:00 +00:00
|
|
|
void setGridSize( const wxPoint& grid );
|
|
|
|
bool getGridSize( wxPoint& aGrisSize );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
void setGridOrigin( const wxPoint& grid );
|
2015-06-28 14:11:57 +00:00
|
|
|
bool getGridOrigin( wxPoint& aGridOrigin );
|
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
|
|
|
|
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
DIALOG_SET_GRID::DIALOG_SET_GRID( PCB_BASE_FRAME* aParent, const wxArrayString& aGridChoices ):
|
|
|
|
DIALOG_SET_GRID_BASE( aParent ),
|
|
|
|
m_parent( aParent ),
|
|
|
|
m_fast_grid_opts( aGridChoices )
|
2013-07-09 05:48:26 +00:00
|
|
|
{
|
2016-07-14 14:25:35 +00:00
|
|
|
m_sdbSizerOK->SetDefault(); // set OK button as default response to 'Enter' key
|
2011-09-09 11:02:03 +00:00
|
|
|
|
2018-02-15 15:12:10 +00:00
|
|
|
m_TextPosXUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
|
|
|
|
m_TextPosYUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2018-02-15 15:12:10 +00:00
|
|
|
m_TextSizeXUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
|
|
|
|
m_TextSizeYUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
bool DIALOG_SET_GRID::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
// Validate new settings
|
|
|
|
wxPoint gridOrigin;
|
2017-07-10 13:16:57 +00:00
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
if( !getGridOrigin( gridOrigin ) )
|
|
|
|
{
|
|
|
|
wxMessageBox( wxString::Format( _( "Incorrect grid origin "
|
|
|
|
"(coordinates must be >= %.3f mm and <= %.3f mm)" ),
|
|
|
|
-MAX_GRID_OFFSET/IU_PER_MM, MAX_GRID_OFFSET/IU_PER_MM ) );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-24 11:24:00 +00:00
|
|
|
wxPoint gridSize;
|
2018-02-15 15:12:10 +00:00
|
|
|
|
|
|
|
if( !getGridSize( gridSize ) )
|
|
|
|
{
|
|
|
|
wxMessageBox( wxString::Format( _( "Incorrect grid size "
|
|
|
|
"(size must be >= %.3f mm and <= %.3f mm)" ),
|
|
|
|
MIN_GRID_SIZE/IU_PER_MM, MAX_GRID_SIZE/IU_PER_MM ) );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
int fastGrid1, fastGrid2;
|
|
|
|
getGridForFastSwitching( fastGrid1, fastGrid2 );
|
|
|
|
|
|
|
|
// Apply the new settings
|
|
|
|
|
|
|
|
// Because grid origin is saved in board, show as modified
|
|
|
|
m_parent->OnModify();
|
|
|
|
m_parent->SetGridOrigin( gridOrigin );
|
|
|
|
m_parent->m_UserGridSize = gridSize;
|
|
|
|
m_parent->m_FastGrid1 = fastGrid1;
|
|
|
|
m_parent->m_FastGrid2 = fastGrid2;
|
|
|
|
|
|
|
|
// User grid
|
|
|
|
BASE_SCREEN* screen = m_parent->GetScreen();
|
2018-02-24 11:24:00 +00:00
|
|
|
screen->AddGrid( gridSize, EDA_UNITS_T::UNSCALED_UNITS, ID_POPUP_GRID_USER );
|
2016-05-02 14:15:24 +00:00
|
|
|
|
|
|
|
// If the user grid is the current option, recall SetGrid()
|
|
|
|
// to force new values put in list as current grid value
|
|
|
|
if( screen->GetGridCmdId() == ID_POPUP_GRID_USER )
|
|
|
|
screen->SetGrid( ID_POPUP_GRID_USER );
|
|
|
|
|
|
|
|
// Notify GAL
|
|
|
|
TOOL_MANAGER* mgr = m_parent->GetToolManager();
|
|
|
|
|
|
|
|
if( mgr && m_parent->IsGalCanvasActive() )
|
|
|
|
{
|
|
|
|
mgr->RunAction( "common.Control.gridPreset", true,
|
|
|
|
screen->GetGridCmdId() - ID_POPUP_GRID_LEVEL_1000 );
|
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
TOOL_EVENT gridOriginUpdate = ACTIONS::gridSetOrigin.MakeEvent();
|
2016-05-02 14:15:24 +00:00
|
|
|
gridOriginUpdate.SetParameter( new VECTOR2D( gridOrigin ) );
|
|
|
|
mgr->ProcessEvent( gridOriginUpdate );
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxDialog::TransferDataFromWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_SET_GRID::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
setGridSize( m_parent->m_UserGridSize );
|
|
|
|
setGridOrigin( m_parent->GetGridOrigin() );
|
|
|
|
setGridForFastSwitching( m_fast_grid_opts, m_parent->m_FastGrid1, m_parent->m_FastGrid2 );
|
|
|
|
|
|
|
|
return wxDialog::TransferDataToWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-24 11:24:00 +00:00
|
|
|
void DIALOG_SET_GRID::setGridSize( const wxPoint& 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
|
|
|
|
2018-02-15 15:12:10 +00:00
|
|
|
msg.Printf( wxT( "%.10g" ), To_User_Unit( g_UserUnit, grid.x ) );
|
2010-07-13 10:42:32 +00:00
|
|
|
m_OptGridSizeX->SetValue( msg );
|
2013-06-05 14:24:03 +00:00
|
|
|
|
2018-02-15 15:12:10 +00:00
|
|
|
msg.Printf( wxT( "%.10g" ), To_User_Unit( g_UserUnit, 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
|
|
|
|
2018-02-24 11:24:00 +00:00
|
|
|
bool DIALOG_SET_GRID::getGridSize( wxPoint& aGridSize )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-02-15 15:12:10 +00:00
|
|
|
double x, y;
|
2015-06-28 14:11:57 +00:00
|
|
|
|
2018-02-15 15:12:10 +00:00
|
|
|
const wxString& x_str = m_OptGridSizeX->GetValue();
|
|
|
|
|
|
|
|
if( !x_str.ToDouble( &x ) )
|
2015-06-28 14:11:57 +00:00
|
|
|
return false;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-02-15 15:12:10 +00:00
|
|
|
x = DoubleValueFromString( g_UserUnit, x_str );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-02-15 15:12:10 +00:00
|
|
|
// Some error checking here is a good thing.
|
|
|
|
if( x < MIN_GRID_SIZE || x > MAX_GRID_SIZE )
|
2015-06-28 14:11:57 +00:00
|
|
|
return false;
|
2018-02-15 15:12:10 +00:00
|
|
|
|
|
|
|
const wxString& y_str = m_OptGridSizeY->GetValue();
|
|
|
|
|
|
|
|
if( !y_str.ToDouble( &y ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
y = DoubleValueFromString( g_UserUnit, y_str );
|
|
|
|
|
|
|
|
// Some error checking here is a good thing.
|
|
|
|
if( y < MIN_GRID_SIZE || y > MAX_GRID_SIZE )
|
|
|
|
return false;
|
|
|
|
|
2018-02-24 11:24:00 +00:00
|
|
|
aGridSize.x = KiROUND( x );
|
|
|
|
aGridSize.y = KiROUND( y );
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2015-06-28 14:11:57 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2015-06-28 14:11:57 +00:00
|
|
|
bool DIALOG_SET_GRID::getGridOrigin( wxPoint& aGridOrigin )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-05-02 14:15:24 +00:00
|
|
|
double x, y;
|
|
|
|
|
|
|
|
const wxString& x_str = m_GridOriginXCtrl->GetValue();
|
2015-06-28 14:11:57 +00:00
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
if( !x_str.ToDouble( &x ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
x = DoubleValueFromString( g_UserUnit, x_str );
|
2015-06-28 14:11:57 +00:00
|
|
|
|
|
|
|
// Some error checking here is a good thing.
|
2016-05-02 14:15:24 +00:00
|
|
|
if( x < -MAX_GRID_OFFSET || x > MAX_GRID_OFFSET )
|
2015-06-28 14:11:57 +00:00
|
|
|
return false;
|
2009-11-20 14:55:20 +00:00
|
|
|
|
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
const wxString& y_str = m_GridOriginYCtrl->GetValue();
|
|
|
|
|
|
|
|
if( !y_str.ToDouble( &y ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
y = DoubleValueFromString( g_UserUnit, y_str );
|
2015-06-28 14:11:57 +00:00
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
if( y < -MAX_GRID_OFFSET || y > MAX_GRID_OFFSET )
|
2015-06-28 14:11:57 +00:00
|
|
|
return false;
|
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
|
|
|
|
aGridOrigin.x = KiROUND( x );
|
|
|
|
aGridOrigin.y = KiROUND( y );
|
2015-06-28 14:11:57 +00:00
|
|
|
|
|
|
|
return true;
|
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
|
|
|
|
2015-04-10 23:43:15 +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
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
void DIALOG_SET_GRID::OnResetGridOrgClick( wxCommandEvent& event )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2016-05-02 14:15:24 +00:00
|
|
|
setGridOrigin( wxPoint( 0, 0 ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2013-07-09 05:48:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool PCB_BASE_FRAME::InvokeDialogGrid()
|
|
|
|
{
|
2016-05-02 14:15:24 +00:00
|
|
|
DIALOG_SET_GRID dlg( this, m_gridSelectBox->GetStrings() );
|
|
|
|
return dlg.ShowModal();
|
2013-07-09 05:48:26 +00:00
|
|
|
}
|