KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_dielectric_list_manager.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2009-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU 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.org/licenses/>.
19 */
20
22#include <wx/msgdlg.h>
23
25 DIELECTRIC_SUBSTRATE_LIST& aMaterialList ) :
27 m_materialList( aMaterialList )
28{
31}
32
34{
35}
36
37
39{
40 // Validate double values from wxTextCtrl
41 double dummy;
42
43 if( !m_tcEpsilonR->GetValue().ToDouble( &dummy ) || dummy < 0.0 )
44 {
45 wxMessageBox( _( "Incorrect value for Epsilon R" ) );
46 return false;
47 }
48
49 if( !m_tcLossTg->GetValue().ToDouble( &dummy ) || dummy < 0.0 )
50 {
51 wxMessageBox( _( "Incorrect value for Loss Tangent" ) );
52 return false;
53 }
54
55 return true;
56}
57
58
60{
61 // Init m_tcEpsilonR and m_tcLossTg to a dummy (default) value
63 dummy.m_EpsilonR = 1.0;
64 dummy.m_LossTangent = 0.0;
65
66 m_tcEpsilonR->SetValue( dummy.FormatEpsilonR() );
67 m_tcLossTg->SetValue( dummy.FormatLossTangent() );
68
69 return true;
70}
71
72
74{
75 DIELECTRIC_SUBSTRATE substrate;
76 double tmp;
77
78 // return the selected/created substrate. A empty substrate can be returned
79 substrate.m_Name = m_tcMaterial->GetValue();
80
81 m_tcEpsilonR->GetValue().ToDouble( &tmp );
82 substrate.m_EpsilonR = tmp;
83
84 m_tcLossTg->GetValue().ToDouble( &tmp );
85 substrate.m_LossTangent = tmp;
86
87 return substrate;
88}
89
90
92{
93 m_lcMaterials->AppendColumn( _( "Material" ) );
94 m_lcMaterials->AppendColumn( _( "Epsilon R" ) );
95 m_lcMaterials->AppendColumn( _( "Loss Tan" ) );
96
97 m_lcMaterials->SetColumnWidth( 0, m_lcMaterials->GetColumnWidth( 1 ) * 3 / 2 );
98
99 // Fills m_lcMaterials with available materials
100 // The first item is expected a not specified material
101 // Other names are proper nouns, and are not translated
102 for( int idx = 0; idx < m_materialList.GetCount(); ++idx )
103 {
105
106 long tmp = m_lcMaterials->InsertItem( idx, idx == 0 ? wxGetTranslation( item->m_Name )
107 : item->m_Name );
108
109 m_lcMaterials->SetItemData( tmp, idx );
110 m_lcMaterials->SetItem( tmp, 1, item->FormatEpsilonR() );
111 m_lcMaterials->SetItem( tmp, 2, item->FormatLossTangent() );
112 }
113}
114
115
117{
118 int idx = event.GetIndex();
119
120 if( idx < 0 )
121 return;
122
123 if( idx == 0 )
124 m_tcMaterial->SetValue( wxGetTranslation( m_materialList.GetSubstrate( 0 )->m_Name ) );
125 else
126 m_tcMaterial->SetValue( m_materialList.GetSubstrate( idx )->m_Name );
127
130}
131
132
134{
135 int idx = event.GetIndex();
136
137 switch( event.GetKeyCode() )
138 {
139 case WXK_DELETE:
140 if( idx >= 0 )
141 {
142 m_lcMaterials->DeleteItem( idx );
144
145 // Get the new material information for the next item in the list
146 // (or last if the deleted item was the last item)
147 int next = ( idx < m_materialList.GetCount() ) ? idx : idx - 1;
148
149 m_lcMaterials->SetItemState( next, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
150 m_lcMaterials->SetItemState( next, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED );
151 m_lcMaterials->EnsureVisible( next );
152 }
153
154 break;
155
156 default:
157 event.Skip();
158 }
159}
Class DIALOG_DIELECTRIC_MATERIAL_BASE.
void onListItemSelected(wxListEvent &event) override
void onListKeyDown(wxListEvent &event) override
DIALOG_DIELECTRIC_MATERIAL(wxWindow *aParent, DIELECTRIC_SUBSTRATE_LIST &aMaterialList)
DIELECTRIC_SUBSTRATE_LIST & m_materialList
The list of available materials.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void DeleteSubstrate(int aIdx)
Delete the specified item in the substrate list.
DIELECTRIC_SUBSTRATE * GetSubstrate(int aIdx)
#define _(s)
CITER next(CITER it)
Definition: ptree.cpp:126
std::vector< FAB_LAYER_COLOR > dummy