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.
|
|
|
|
*
|
2015-04-10 23:43:15 +00:00
|
|
|
* Copyright (C) 1992-2015 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
|
|
|
|
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>
|
2015-06-28 14:11:57 +00:00
|
|
|
#include <macros.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>
|
2015-04-30 08:46:06 +00:00
|
|
|
|
2015-04-10 23:43:15 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
#include <class_draw_panel_gal.h>
|
2015-04-30 08:46:06 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2015-06-30 12:08:03 +00:00
|
|
|
#include <tools/common_actions.h>
|
2008-12-05 16:03:05 +00:00
|
|
|
|
2015-06-28 14:11:57 +00:00
|
|
|
// Max values for grid size
|
|
|
|
#define MAX_GRID_SIZE ( 50.0 * IU_PER_MM )
|
|
|
|
#define MIN_GRID_SIZE ( 0.001 * IU_PER_MM )
|
|
|
|
|
|
|
|
// Min/Max value for grid offset
|
2015-07-02 07:28:54 +00:00
|
|
|
#define MAX_GRID_OFFSET double(INT_MAX/2)
|
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 );
|
2015-06-28 14:11:57 +00:00
|
|
|
bool getGridSize( wxRealPoint& 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
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-06-28 14:11:57 +00:00
|
|
|
bool DIALOG_SET_GRID::getGridSize( wxRealPoint& aGrisSize )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-07-13 10:42:32 +00:00
|
|
|
wxRealPoint grid;
|
2015-06-28 14:11:57 +00:00
|
|
|
m_callers_grid_units = getGridUnits();
|
|
|
|
double grid_unit_to_iu = m_callers_grid_units == INCHES ? IU_PER_MILS*1000 : IU_PER_MM;
|
|
|
|
|
|
|
|
wxString val = m_OptGridSizeX->GetValue();
|
|
|
|
|
|
|
|
double tmp;
|
|
|
|
|
|
|
|
if( !val.ToDouble( &tmp ) ||
|
|
|
|
tmp*grid_unit_to_iu < MIN_GRID_SIZE || tmp*grid_unit_to_iu > MAX_GRID_SIZE )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aGrisSize.x = tmp;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-06-28 14:11:57 +00:00
|
|
|
val = m_OptGridSizeY->GetValue();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-06-28 14:11:57 +00:00
|
|
|
if( !val.ToDouble( &tmp ) ||
|
|
|
|
tmp*grid_unit_to_iu < MIN_GRID_SIZE || tmp*grid_unit_to_iu > MAX_GRID_SIZE )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aGrisSize.y = tmp;
|
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
|
|
|
{
|
2015-06-28 14:11:57 +00:00
|
|
|
double tmp;
|
|
|
|
|
|
|
|
tmp = DoubleValueFromString( g_UserUnit, m_GridOriginXCtrl->GetValue() );
|
|
|
|
|
|
|
|
// Some error checking here is a good thing.
|
|
|
|
if( tmp < -MAX_GRID_OFFSET || tmp > MAX_GRID_OFFSET )
|
|
|
|
return false;
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2015-06-28 14:11:57 +00:00
|
|
|
aGridOrigin.x = KiROUND( tmp );
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2015-06-28 14:11:57 +00:00
|
|
|
tmp = DoubleValueFromString( g_UserUnit, m_GridOriginYCtrl->GetValue() );
|
|
|
|
|
|
|
|
if( tmp < -MAX_GRID_OFFSET || tmp > MAX_GRID_OFFSET )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
aGridOrigin.y = KiROUND( tmp );
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
{
|
2015-06-28 14:11:57 +00:00
|
|
|
bool success = getGridSize( m_callers_user_size );
|
|
|
|
|
|
|
|
if( !success )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
success = getGridOrigin( m_callers_origin );
|
|
|
|
|
|
|
|
if( !success )
|
|
|
|
{
|
2015-06-30 16:31:48 +00:00
|
|
|
wxMessageBox( wxString::Format( _( "Incorrect grid origin (coordinates must be >= %.3f mm and <= %.3f mm)" ),
|
2015-06-28 14:11:57 +00:00
|
|
|
-MAX_GRID_OFFSET/IU_PER_MM, MAX_GRID_OFFSET/IU_PER_MM ) );
|
|
|
|
return;
|
|
|
|
}
|
2013-07-09 05:48:26 +00:00
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2014-04-19 18:47:20 +00:00
|
|
|
if( GetGridOrigin() != grid_origin && IsType( FRAME_PCB ) )
|
2013-08-03 16:16:57 +00:00
|
|
|
OnModify(); // because grid origin is saved in board, show as modified
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
SetGridOrigin( grid_origin );
|
|
|
|
|
2015-04-10 23:43:15 +00:00
|
|
|
BASE_SCREEN* screen = GetScreen();
|
|
|
|
|
|
|
|
screen->AddGrid( m_UserGridSize, m_UserGridUnit, ID_POPUP_GRID_USER );
|
2013-07-09 05:48:26 +00:00
|
|
|
|
|
|
|
// If the user grid is the current option, recall SetGrid()
|
|
|
|
// to force new values put in list as current grid value
|
2015-05-12 09:05:36 +00:00
|
|
|
if( screen->GetGridCmdId() == ID_POPUP_GRID_USER )
|
2015-04-10 23:43:15 +00:00
|
|
|
screen->SetGrid( ID_POPUP_GRID_USER );
|
|
|
|
|
2015-04-30 08:46:06 +00:00
|
|
|
// Notify GAL
|
|
|
|
TOOL_MANAGER* mgr = GetToolManager();
|
|
|
|
|
|
|
|
if( mgr && IsGalCanvasActive() )
|
2015-06-30 12:08:03 +00:00
|
|
|
{
|
2015-04-30 08:46:06 +00:00
|
|
|
mgr->RunAction( "common.Control.gridPreset", true,
|
2015-06-28 14:11:57 +00:00
|
|
|
screen->GetGridCmdId() - ID_POPUP_GRID_LEVEL_1000 );
|
2013-07-09 05:48:26 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
TOOL_EVENT gridOriginUpdate = COMMON_ACTIONS::gridSetOrigin.MakeEvent();
|
|
|
|
gridOriginUpdate.SetParameter( new VECTOR2D( grid_origin ) );
|
|
|
|
mgr->ProcessEvent( gridOriginUpdate );
|
|
|
|
}
|
|
|
|
|
2013-07-09 05:48:26 +00:00
|
|
|
m_canvas->Refresh();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|