1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
22  */
23 
24 
25 #include <pcb_edit_frame.h>
26 #include <board_design_settings.h>
27 #include <dialogs/dialog_text_entry.h>
28 #include <panel_setup_mask_and_paste.h>
29 #include <wx/treebook.h>
30 
31 
PANEL_SETUP_MASK_AND_PASTE(PAGED_DIALOG * aParent,PCB_EDIT_FRAME * aFrame)32 PANEL_SETUP_MASK_AND_PASTE::PANEL_SETUP_MASK_AND_PASTE( PAGED_DIALOG* aParent,
33                                                         PCB_EDIT_FRAME* aFrame ) :
34         PANEL_SETUP_MASK_AND_PASTE_BASE( aParent->GetTreebook() ),
35         m_maskMargin( aFrame, m_maskMarginLabel, m_maskMarginCtrl, m_maskMarginUnits ),
36         m_maskMinWidth( aFrame, m_maskMinWidthLabel, m_maskMinWidthCtrl, m_maskMinWidthUnits ),
37         m_pasteMargin( aFrame, m_pasteMarginLabel, m_pasteMarginCtrl, m_pasteMarginUnits ),
38         m_pasteMarginRatio( aFrame, m_pasteMarginRatioLabel, m_pasteMarginRatioCtrl,
39                             m_pasteMarginRatioUnits )
40 {
41     m_Frame = aFrame;
42     m_BrdSettings = &m_Frame->GetBoard()->GetDesignSettings();
43 
44     m_staticTextInfoPaste->SetFont( KIUI::GetInfoFont( this ).Italic() );
45 
46     m_pasteMargin.SetNegativeZero();
47 
48     m_pasteMarginRatio.SetUnits( EDA_UNITS::PERCENT );
49     m_pasteMarginRatio.SetNegativeZero();
50 }
51 
52 
TransferDataToWindow()53 bool PANEL_SETUP_MASK_AND_PASTE::TransferDataToWindow()
54 {
55     m_maskMargin.SetValue( m_BrdSettings->m_SolderMaskMargin );
56     m_maskMinWidth.SetValue( m_BrdSettings->m_SolderMaskMinWidth );
57     m_pasteMargin.SetValue( m_BrdSettings->m_SolderPasteMargin );
58     m_pasteMarginRatio.SetDoubleValue( m_BrdSettings->m_SolderPasteMarginRatio * 100.0 );
59 
60     return true;
61 }
62 
63 
TransferDataFromWindow()64 bool PANEL_SETUP_MASK_AND_PASTE::TransferDataFromWindow()
65 {
66     // These are all stored in project file, not board, so no need for OnModify()
67     m_BrdSettings->m_SolderMaskMargin = m_maskMargin.GetValue();
68     m_BrdSettings->m_SolderMaskMinWidth = m_maskMinWidth.GetValue();
69     m_BrdSettings->m_SolderPasteMargin = m_pasteMargin.GetValue();
70     m_BrdSettings->m_SolderPasteMarginRatio = m_pasteMarginRatio.GetDoubleValue() / 100.0;
71 
72     return true;
73 }
74 
75 
ImportSettingsFrom(BOARD * aBoard)76 void PANEL_SETUP_MASK_AND_PASTE::ImportSettingsFrom( BOARD* aBoard )
77 {
78     BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
79 
80     m_BrdSettings = &aBoard->GetDesignSettings();
81     TransferDataToWindow();
82 
83     m_BrdSettings = savedSettings;
84 }
85