File: dialog_dielectric_list_manager.cpp

package info (click to toggle)
kicad 9.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 770,320 kB
  • sloc: cpp: 961,692; ansic: 121,001; xml: 66,428; python: 18,387; sh: 1,010; awk: 301; asm: 292; makefile: 227; javascript: 167; perl: 10
file content (159 lines) | stat: -rw-r--r-- 4,939 bytes parent folder | download | duplicates (4)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
 *
 * 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.org/licenses/>.
 */

#include "dialog_dielectric_list_manager.h"
#include <wx/msgdlg.h>

DIALOG_DIELECTRIC_MATERIAL::DIALOG_DIELECTRIC_MATERIAL( wxWindow* aParent,
                                                        DIELECTRIC_SUBSTRATE_LIST& aMaterialList ) :
        DIALOG_DIELECTRIC_MATERIAL_BASE( aParent ),
        m_materialList( aMaterialList )
{
    initMaterialList();
    SetupStandardButtons();
}

DIALOG_DIELECTRIC_MATERIAL::~DIALOG_DIELECTRIC_MATERIAL()
{
}


bool DIALOG_DIELECTRIC_MATERIAL::TransferDataFromWindow()
{
    // Validate double values from wxTextCtrl
    double dummy;

    if( !m_tcEpsilonR->GetValue().ToDouble( &dummy ) || dummy < 0.0 )
    {
        wxMessageBox( _( "Incorrect value for Epsilon R" ) );
        return false;
    }

    if( !m_tcLossTg->GetValue().ToDouble( &dummy ) || dummy < 0.0 )
    {
        wxMessageBox( _( "Incorrect value for Loss Tangent" ) );
        return false;
    }

    return true;
}


bool DIALOG_DIELECTRIC_MATERIAL::TransferDataToWindow()
{
    // Init m_tcEpsilonR and m_tcLossTg to a dummy (default) value
    DIELECTRIC_SUBSTRATE dummy;
    dummy.m_EpsilonR = 1.0;
    dummy.m_LossTangent = 0.0;

    m_tcEpsilonR->SetValue( dummy.FormatEpsilonR() );
    m_tcLossTg->SetValue( dummy.FormatLossTangent() );

    return true;
}


DIELECTRIC_SUBSTRATE DIALOG_DIELECTRIC_MATERIAL::GetSelectedSubstrate()
{
    DIELECTRIC_SUBSTRATE substrate;
    double               tmp;

    // return the selected/created substrate. A empty substrate can be returned
    substrate.m_Name = m_tcMaterial->GetValue();

    m_tcEpsilonR->GetValue().ToDouble( &tmp );
    substrate.m_EpsilonR = tmp;

    m_tcLossTg->GetValue().ToDouble( &tmp );
    substrate.m_LossTangent = tmp;

    return substrate;
}


void DIALOG_DIELECTRIC_MATERIAL::initMaterialList()
{
    m_lcMaterials->AppendColumn( _( "Material" ) );
    m_lcMaterials->AppendColumn( _( "Epsilon R" ) );
    m_lcMaterials->AppendColumn( _( "Loss Tan" ) );

    m_lcMaterials->SetColumnWidth( 0, m_lcMaterials->GetColumnWidth( 1 ) * 3 / 2 );

    // Fills m_lcMaterials with available materials
    // The first item is expected a not specified material
    // Other names are proper nouns, and are not translated
    for( int idx = 0; idx < m_materialList.GetCount(); ++idx )
    {
        DIELECTRIC_SUBSTRATE* item = m_materialList.GetSubstrate( idx );

        long tmp = m_lcMaterials->InsertItem( idx, idx == 0 ? wxGetTranslation( item->m_Name )
                                                            : item->m_Name );

        m_lcMaterials->SetItemData( tmp, idx );
        m_lcMaterials->SetItem( tmp, 1, item->FormatEpsilonR() );
        m_lcMaterials->SetItem( tmp, 2, item->FormatLossTangent() );
    }
}


void DIALOG_DIELECTRIC_MATERIAL::onListItemSelected( wxListEvent& event )
{
    int idx = event.GetIndex();

    if( idx < 0 )
        return;

    if( idx == 0 )
        m_tcMaterial->SetValue( wxGetTranslation( m_materialList.GetSubstrate( 0 )->m_Name ) );
    else
        m_tcMaterial->SetValue( m_materialList.GetSubstrate( idx )->m_Name );

    m_tcEpsilonR->SetValue( m_materialList.GetSubstrate( idx )->FormatEpsilonR() );
    m_tcLossTg->SetValue( m_materialList.GetSubstrate( idx )->FormatLossTangent() );
}


void DIALOG_DIELECTRIC_MATERIAL::onListKeyDown( wxListEvent& event )
{
    int idx = event.GetIndex();

    switch( event.GetKeyCode() )
    {
    case WXK_DELETE:
        if( idx >= 0 )
        {
            m_lcMaterials->DeleteItem( idx );
            m_materialList.DeleteSubstrate( idx );

            // Get the new material information for the next item in the list
            // (or last if the deleted item was the last item)
            int next = ( idx < m_materialList.GetCount() ) ? idx : idx - 1;

            m_lcMaterials->SetItemState( next, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
            m_lcMaterials->SetItemState( next, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED );
            m_lcMaterials->EnsureVisible( next );
        }

        break;

    default:
        event.Skip();
    }
}