1 /*
2  * KiRouter - a push-and-(sometimes-)shove PCB router
3  *
4  * Copyright (C) 2014  CERN
5  * Author: Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program.  If not, see <http://www.gnu.or/licenses/>.
19  */
20 
21 /**
22  * Push and Shove router track width and via size dialog.
23  */
24 
25 #include "dialog_track_via_size.h"
26 #include <base_units.h>
27 #include <confirm.h>
28 #include <widgets/text_ctrl_eval.h>
29 #include <core/optional.h>
30 #include <eda_draw_frame.h>
31 
32 #include "board_design_settings.h"
33 
34 const int minSize = (int)( 0.01 * IU_PER_MM );
35 
DIALOG_TRACK_VIA_SIZE(EDA_DRAW_FRAME * aParent,BOARD_DESIGN_SETTINGS & aSettings)36 DIALOG_TRACK_VIA_SIZE::DIALOG_TRACK_VIA_SIZE( EDA_DRAW_FRAME* aParent,
37                                               BOARD_DESIGN_SETTINGS& aSettings ) :
38     DIALOG_TRACK_VIA_SIZE_BASE( aParent ),
39     m_trackWidth( aParent, m_trackWidthLabel, m_trackWidthText, m_trackWidthUnits, minSize ),
40     m_viaDiameter( aParent, m_viaDiameterLabel, m_viaDiameterText, m_viaDiameterUnits, minSize ),
41     m_viaDrill( aParent, m_viaDrillLabel, m_viaDrillText, m_viaDrillUnits, minSize ),
42     m_settings( aSettings )
43 {
44     m_stdButtonsOK->SetDefault();
45 
46     // Now all widgets have the size fixed, call FinishDialogSettings
47     finishDialogSettings();
48 }
49 
50 
TransferDataFromWindow()51 bool DIALOG_TRACK_VIA_SIZE::TransferDataFromWindow()
52 {
53     if( !wxDialog::TransferDataFromWindow() )
54         return false;
55 
56     if( m_viaDrill.GetValue() >= m_viaDiameter.GetValue() )
57     {
58         DisplayError( GetParent(), _( "Via drill size must be smaller than via diameter" ) );
59         m_viaDrillText->SetFocus();
60         return false;
61     }
62 
63     // Store dialog values to the router settings
64     m_settings.SetCustomTrackWidth( m_trackWidth.GetValue() );
65     m_settings.SetCustomViaSize( m_viaDiameter.GetValue() );
66     m_settings.SetCustomViaDrill( m_viaDrill.GetValue() );
67 
68     return true;
69 }
70 
71 
TransferDataToWindow()72 bool DIALOG_TRACK_VIA_SIZE::TransferDataToWindow()
73 {
74     if( !wxDialog::TransferDataToWindow() )
75         return false;
76 
77     // Load router settings to dialog fields
78     m_trackWidth.SetValue( m_settings.GetCustomTrackWidth() );
79     m_viaDiameter.SetValue( m_settings.GetCustomViaSize() );
80     m_viaDrill.SetValue( m_settings.GetCustomViaDrill() );
81 
82     return true;
83 }
84 
85