File: dialog_track_via_size.cpp

package info (click to toggle)
kicad 5.0.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 234,592 kB
  • sloc: cpp: 505,330; ansic: 57,038; python: 4,886; sh: 879; awk: 294; makefile: 253; xml: 103; perl: 5
file content (109 lines) | stat: -rw-r--r-- 3,156 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * KiRouter - a push-and-(sometimes-)shove PCB router
 *
 * Copyright (C) 2014  CERN
 * Author: Maciej Suminski <maciej.suminski@cern.ch>
 *
 * 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 3 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, see <http://www.gnu.or/licenses/>.
 */

/**
 * Push and Shove router track width and via size dialog.
 */

#include "dialog_track_via_size.h"
#include <base_units.h>
#include <confirm.h>
#include <widgets/text_ctrl_eval.h>
#include <core/optional.h>

#include "board_design_settings.h"

DIALOG_TRACK_VIA_SIZE::DIALOG_TRACK_VIA_SIZE( wxWindow* aParent, BOARD_DESIGN_SETTINGS& aSettings ) :
    DIALOG_TRACK_VIA_SIZE_BASE( aParent ),
    m_trackWidth( aParent, m_trackWidthText, m_trackWidthLabel ),
    m_viaDiameter( aParent, m_viaDiameterText, m_viaDiameterLabel ),
    m_viaDrill( aParent, m_viaDrillText, m_viaDrillLabel ),
    m_settings( aSettings )
{
    m_stdButtonsOK->SetDefault();

    // Now all widgets have the size fixed, call FinishDialogSettings
    FinishDialogSettings();
}


bool DIALOG_TRACK_VIA_SIZE::TransferDataFromWindow()
{
    if( !wxDialog::TransferDataFromWindow() )
        return false;

    if( !check() )
        return false;

    // Store dialog values to the router settings
    m_settings.SetCustomTrackWidth( m_trackWidth.GetValue() );
    m_settings.SetCustomViaSize( m_viaDiameter.GetValue() );
    m_settings.SetCustomViaDrill( m_viaDrill.GetValue() );

    return true;
}


bool DIALOG_TRACK_VIA_SIZE::TransferDataToWindow()
{
    if( !wxDialog::TransferDataToWindow() )
        return false;

    // Load router settings to dialog fields
    m_trackWidth.SetValue( m_settings.GetCustomTrackWidth() );
    m_viaDiameter.SetValue( m_settings.GetCustomViaSize() );
    m_viaDrill.SetValue( m_settings.GetCustomViaDrill() );

    return true;
}


bool DIALOG_TRACK_VIA_SIZE::check()
{
    if( m_trackWidth.GetValue() <= 0 )
    {
        DisplayError( GetParent(), _( "Invalid track width" ) );
        m_trackWidthText->SetFocus();
        return false;
    }

    if( m_viaDiameter.GetValue() <= 0 )
    {
        DisplayError( GetParent(), _( "Invalid via diameter" ) );
        m_viaDiameterText->SetFocus();
        return false;
    }

    if( m_viaDrill.GetValue() <= 0 )
    {
        DisplayError( GetParent(), _( "Invalid via drill size" ) );
        m_viaDrillText->SetFocus();
        return false;
    }

    if( m_viaDrill.GetValue() >= m_viaDiameter.GetValue() )
    {
        DisplayError( GetParent(), _( "Via drill size has to be smaller than via diameter" ) );
        m_viaDrillText->SetFocus();
        return false;
    }

    return true;
}