2013-02-26 11:25:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-02-03 09:09:53 +00:00
|
|
|
* Copyright (C) 1992-2018 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 <common.h>
|
2018-02-03 09:09:53 +00:00
|
|
|
#include <widgets/unit_binder.h>
|
2018-08-26 17:57:28 +00:00
|
|
|
#include <hotkeys.h>
|
2018-11-17 00:33:20 +00:00
|
|
|
#include <pcb_base_edit_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>
|
|
|
|
|
2015-06-28 14:11:57 +00:00
|
|
|
// Max values for grid size
|
2018-02-03 09:09:53 +00:00
|
|
|
static const int MAX_GRID_SIZE = KiROUND( 1000.0 * IU_PER_MM );
|
|
|
|
static const int MIN_GRID_SIZE = KiROUND( 0.001 * IU_PER_MM );
|
2015-06-28 14:11:57 +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
|
|
|
{
|
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;
|
2009-02-07 20:11:09 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
UNIT_BINDER m_gridOriginX;
|
|
|
|
UNIT_BINDER m_gridOriginY;
|
|
|
|
UNIT_BINDER m_userGridX;
|
|
|
|
UNIT_BINDER m_userGridY;
|
2013-07-09 05:48:26 +00:00
|
|
|
};
|
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 ),
|
2018-02-03 09:09:53 +00:00
|
|
|
m_fast_grid_opts( aGridChoices ),
|
|
|
|
m_gridOriginX( aParent, m_staticTextGridPosX, m_GridOriginXCtrl, m_TextPosXUnits ),
|
|
|
|
m_gridOriginY( aParent, m_staticTextGridPosY, m_GridOriginYCtrl, m_TextPosYUnits ),
|
2018-11-29 18:59:38 +00:00
|
|
|
m_userGridX( aParent, m_staticTextSizeX, m_OptGridSizeX, m_TextSizeXUnits ),
|
|
|
|
m_userGridY( aParent, m_staticTextSizeY, m_OptGridSizeY, m_TextSizeYUnits )
|
2013-07-09 05:48:26 +00:00
|
|
|
{
|
2018-02-03 09:09:53 +00:00
|
|
|
m_comboBoxGrid1->Append( m_fast_grid_opts );
|
|
|
|
m_comboBoxGrid2->Append( m_fast_grid_opts );
|
2011-09-09 11:02:03 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
m_sdbSizerOK->SetDefault(); // set OK button as default response to 'Enter' key
|
2018-03-06 05:33:04 +00:00
|
|
|
SetInitialFocus( m_GridOriginXCtrl );
|
2018-02-02 15:44:53 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
Layout();
|
2010-07-13 10:42:32 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
FinishDialogSettings();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
bool DIALOG_SET_GRID::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
// Validate new settings
|
2018-11-29 18:59:38 +00:00
|
|
|
if( !m_userGridX.Validate( MIN_GRID_SIZE, MAX_GRID_SIZE ) )
|
2018-02-03 09:09:53 +00:00
|
|
|
return false;
|
2017-07-10 13:16:57 +00:00
|
|
|
|
2018-11-29 18:59:38 +00:00
|
|
|
if( !m_userGridY.Validate( MIN_GRID_SIZE, MAX_GRID_SIZE ) )
|
2018-02-15 15:12:10 +00:00
|
|
|
return false;
|
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
// Apply the new settings
|
|
|
|
|
2018-02-02 15:44:53 +00:00
|
|
|
// Because grid origin is saved in board, show as modified
|
2016-05-02 14:15:24 +00:00
|
|
|
m_parent->OnModify();
|
2018-02-03 09:09:53 +00:00
|
|
|
m_parent->SetGridOrigin( wxPoint( m_gridOriginX.GetValue(), m_gridOriginY.GetValue() ) );
|
|
|
|
m_parent->m_UserGridSize = wxPoint( m_userGridX.GetValue(), m_userGridY.GetValue() );
|
2018-02-02 15:44:53 +00:00
|
|
|
m_parent->m_FastGrid1 = m_comboBoxGrid1->GetSelection();
|
|
|
|
m_parent->m_FastGrid2 = m_comboBoxGrid2->GetSelection();
|
2016-05-02 14:15:24 +00:00
|
|
|
|
|
|
|
// User grid
|
|
|
|
BASE_SCREEN* screen = m_parent->GetScreen();
|
2018-02-03 09:09:53 +00:00
|
|
|
screen->AddGrid( m_parent->m_UserGridSize, 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();
|
2018-02-03 09:09:53 +00:00
|
|
|
gridOriginUpdate.SetParameter( new VECTOR2D( m_parent->GetGridOrigin() ) );
|
2016-05-02 14:15:24 +00:00
|
|
|
mgr->ProcessEvent( gridOriginUpdate );
|
|
|
|
}
|
|
|
|
|
2018-11-23 23:33:02 +00:00
|
|
|
m_parent->UpdateGridSelectBox();
|
|
|
|
|
2016-05-02 14:15:24 +00:00
|
|
|
return wxDialog::TransferDataFromWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_SET_GRID::TransferDataToWindow()
|
|
|
|
{
|
2018-02-03 09:09:53 +00:00
|
|
|
m_userGridX.SetValue( m_parent->m_UserGridSize.x );
|
|
|
|
m_userGridY.SetValue( m_parent->m_UserGridSize.y );
|
2016-05-02 14:15:24 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
m_gridOriginX.SetValue( m_parent->GetGridOrigin().x );
|
|
|
|
m_gridOriginY.SetValue( m_parent->GetGridOrigin().y );
|
2016-05-02 14:15:24 +00:00
|
|
|
|
2018-02-02 15:44:53 +00:00
|
|
|
m_comboBoxGrid1->SetSelection( m_parent->m_FastGrid1 );
|
|
|
|
m_comboBoxGrid2->SetSelection( m_parent->m_FastGrid2 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-26 17:57:28 +00:00
|
|
|
int hk1 = m_parent->GetHotKeyDescription( HK_SWITCH_GRID_TO_FASTGRID1 )->m_KeyCode;
|
|
|
|
int hk2 = m_parent->GetHotKeyDescription( HK_SWITCH_GRID_TO_FASTGRID2 )->m_KeyCode;
|
|
|
|
m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
|
|
|
|
m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
|
|
|
|
|
2018-02-02 15:44:53 +00:00
|
|
|
return wxDialog::TransferDataToWindow();
|
2010-07-13 10:42:32 +00:00
|
|
|
}
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2007-06-05 12:10:51 +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
|
|
|
{
|
2018-02-03 09:09:53 +00:00
|
|
|
m_gridOriginX.SetValue( 0 );
|
|
|
|
m_gridOriginY.SetValue( 0 );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2013-07-09 05:48:26 +00:00
|
|
|
|
|
|
|
|
2018-11-17 00:33:20 +00:00
|
|
|
bool PCB_BASE_EDIT_FRAME::InvokeDialogGrid()
|
2013-07-09 05:48:26 +00:00
|
|
|
{
|
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
|
|
|
}
|
2018-11-17 00:33:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
void PCB_BASE_EDIT_FRAME::OnGridSettings( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
InvokeDialogGrid();
|
|
|
|
}
|