KiCad PCB EDA Suite
Loading...
Searching...
No Matches
unit_selector.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) 2011-2014 Jean-Pierre Charras
5 * Copyright The 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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
25
26#include "unit_selector.h"
27#include "units_scales.h"
28
29UNIT_SELECTOR_LEN::UNIT_SELECTOR_LEN( wxWindow *parent, wxWindowID id,
30 const wxPoint& pos, const wxSize& size,
31 const wxArrayString& choices, long style ) :
32 UNIT_SELECTOR( parent, id, pos, size, choices, style )
33{
34 Append( _( "mm" ) );
35 Append( _( "um" ) );
36 Append( _( "cm" ) );
37 Append( _( "mil" ) );
38 Append( _( "inch" ) );
39}
40
41
46{
47 switch( GetCurrentSelection() )
48 {
49 case 0: return UNIT_MM; break;
50 case 1: return UNIT_MICRON; break;
51 case 2: return UNIT_CM; break;
52 case 3: return UNIT_MIL; break;
53 case 4: return UNIT_INCH; break;
54 }
55
56 return 1.0;
57}
58
59
60UNIT_SELECTOR_THICKNESS::UNIT_SELECTOR_THICKNESS( wxWindow *parent, wxWindowID id,
61 const wxPoint& pos, const wxSize& size,
62 const wxArrayString& choices, long style )
63 : UNIT_SELECTOR( parent, id, pos, size, choices, style )
64{
65 Append( wxT( "mm" ) );
66 Append( wxT( "µm" ) );
67 Append( wxT( "cm" ) );
68 Append( wxT( "mil" ) );
69 Append( wxT( "inch" ) );
70 Append( wxT( "oz/ft²" ) );
71}
72
73
74/*
75 * Function GetUnitScale
76 * return the scaling factor to convert users units
77 * to normalized units (meter) including copper oz/ft^2
78 */
80{
81 switch( GetCurrentSelection() )
82 {
83 case 0: return UNIT_MM; break;
84 case 1: return UNIT_MICRON; break;
85 case 2: return UNIT_CM; break;
86 case 3: return UNIT_MIL; break;
87 case 4: return UNIT_INCH; break;
88 case 5: return UNIT_OZSQFT; break;
89 }
90 return 1.0;
91}
92
93
94UNIT_SELECTOR_FREQUENCY::UNIT_SELECTOR_FREQUENCY( wxWindow *parent, wxWindowID id,
95 const wxPoint& pos, const wxSize& size,
96 const wxArrayString& choices, long style ):
97 UNIT_SELECTOR( parent, id, pos, size, choices, style )
98{
99 Append( _( "GHz" ) );
100 Append( _( "MHz" ) );
101 Append( _( "kHz" ) );
102 Append( _( "Hz" ) );
103}
104
105/*
106 * Function GetUnitScale
107 * return the scaling factor to convert users units
108 * to normalized units (herz )
109 */
111{
112 switch( GetCurrentSelection() )
113 {
114 case 0: return UNIT_GHZ;
115 case 1: return UNIT_MHZ;
116 case 2: return UNIT_KHZ;
117 case 3: return 1.0;
118 }
119 return 1.0;
120}
121
122
123UNIT_SELECTOR_ANGLE::UNIT_SELECTOR_ANGLE( wxWindow *parent, wxWindowID id,
124 const wxPoint& pos, const wxSize& size,
125 const wxArrayString& choices, long style ) :
126 UNIT_SELECTOR( parent, id, pos, size, choices, style )
127{
128 Append( _( "rad" ) );
129 Append( _( "deg" ) );
130}
131
132/*
133 * Function GetUnitScale
134 * return the scaling factor to convert users units
135 * to normalized units ( radian )
136 */
138{
139 switch( GetCurrentSelection() )
140 {
141 case 0: return UNIT_RADIAN; break;
142 case 1: return UNIT_DEGREE; break;
143 }
144 return 1.0;
145}
146
147
148UNIT_SELECTOR_RESISTOR::UNIT_SELECTOR_RESISTOR( wxWindow *parent, wxWindowID id,
149 const wxPoint& pos, const wxSize& size,
150 const wxArrayString& choices, long style )
151 : UNIT_SELECTOR( parent, id, pos, size, choices, style )
152{
153 Append( wxT( "Ω" ) );
154 Append( wxT( "kΩ" ) );
155}
156
157
158/*
159 * Function GetUnitScale
160 * return the scaling factor to convert users units
161 * to normalized units ( ohm )
162 */
164{
165 switch( GetCurrentSelection() )
166 {
167 case 0: return UNIT_OHM; break;
168 case 1: return UNIT_KOHM; break;
169 }
170 return 1.0;
171}
172
173
175 const wxPoint& pos, const wxSize& size,
176 const wxArrayString& choices, long style )
177 : UNIT_SELECTOR( parent, id, pos, size, choices, style )
178{
179 Append( wxT( "Ω/m" ) );
180 Append( wxT( "Ω/km" ) );
181 Append( wxT( "Ω/ft" ) );
182 Append( wxT( "Ω/1000ft" ) );
183}
184
185
186/*
187 * Function GetUnitScale
188 * return the scaling factor to convert users units
189 * to normalized units ( ohm )
190 */
192{
193 switch( GetCurrentSelection() )
194 {
195 case 0: return UNIT_OHM_PER_METER; break;
196 case 1: return UNIT_OHM_PER_KILOMETER; break;
197 case 2: return UNIT_OHM_PER_FEET; break;
198 case 3: return UNIT_OHM_PER_1000FEET; break;
199 }
200 return 1.0;
201}
202
203
205 const wxPoint& pos, const wxSize& size,
206 const wxArrayString& choices, long style ) :
207 UNIT_SELECTOR( parent, id, pos, size, choices, style )
208{
209 Append( _( "cm" ) );
210 Append( _( "m" ) );
211 Append( _( "km" ) );
212 Append( _( "inch" ) );
213 Append( _( "feet" ) );
214}
215
216/*
217 * Function GetUnitScale
218 * return the scaling factor to convert users units
219 * to normalized units ( m )
220 */
222{
223 switch( GetCurrentSelection() )
224 {
225 case 0: return UNIT_CM; break;
226 case 1: return UNIT_M; break;
227 case 2: return UNIT_KM; break;
228 case 3: return UNIT_INCH; break;
229 case 4: return UNIT_FEET; break;
230 }
231 return 1.0;
232}
233
234/*
235 * Function GetUnitScale
236 * return the scaling factor to convert users units
237 * to normalized units ( V )
238 */
240{
241 switch( GetCurrentSelection() )
242 {
243 case 0: return UNIT_MILLIVOLT; break;
244 case 1: return UNIT_VOLT; break;
245 }
246 return 1.0;
247}
248
249UNIT_SELECTOR_VOLTAGE::UNIT_SELECTOR_VOLTAGE( wxWindow* parent, wxWindowID id, const wxPoint& pos,
250 const wxSize& size, const wxArrayString& choices,
251 long style ) :
252 UNIT_SELECTOR( parent, id, pos, size, choices, style )
253{
254 Append( _( "mV" ) );
255 Append( _( "V" ) );
256}
257
258/*
259 * Function GetUnitScale
260 * return the scaling factor to convert users units
261 * to normalized units ( W )
262 */
264{
265 switch( GetCurrentSelection() )
266 {
267 case 0: return UNIT_MILLIWATT; break;
268 case 1: return UNIT_WATT; break;
269 }
270 return 1.0;
271}
272
273UNIT_SELECTOR_POWER::UNIT_SELECTOR_POWER( wxWindow* parent, wxWindowID id, const wxPoint& pos,
274 const wxSize& size, const wxArrayString& choices,
275 long style ) :
276 UNIT_SELECTOR( parent, id, pos, size, choices, style )
277{
278 Append( _( "mW" ) );
279 Append( _( "W" ) );
280}
281
282UNIT_SELECTOR_SPEED::UNIT_SELECTOR_SPEED( wxWindow* parent, wxWindowID id, const wxPoint& pos,
283 const wxSize& size, const wxArrayString& choices,
284 long style ) :
285 UNIT_SELECTOR( parent, id, pos, size, choices, style )
286{
287 Append( _( "m/s" ) );
288 Append( _( "ft/s" ) );
289 Append( _( "km/h" ) );
290 Append( _( "mi/h" ) );
291}
292
293/*
294 * Function GetUnitScale
295 * return the scaling factor to convert users units
296 * to normalized units (meter per second)
297 */
299{
300 switch( GetCurrentSelection() )
301 {
302 case 0: return UNIT_METER_PER_SECOND; break;
303 case 1: return UNIT_FEET_PER_SECOND; break;
304 case 2: return UNIT_KILOMETER_PER_HOUR; break;
305 case 3: return UNIT_MILES_PER_HOUR; break;
306 }
307 return 1.0;
308}
309
310UNIT_SELECTOR_TIME::UNIT_SELECTOR_TIME( wxWindow* parent, wxWindowID id, const wxPoint& pos,
311 const wxSize& size, const wxArrayString& choices,
312 long style ) :
313 UNIT_SELECTOR( parent, id, pos, size, choices, style )
314{
315 Append( _( "ns" ) );
316 Append( _( "ps" ) );
317}
318
319/*
320 * Function GetUnitScale
321 * return the scaling factor to convert users units
322 * to normalized units (second)
323 */
325{
326 switch( GetCurrentSelection() )
327 {
328 case 0: return UNIT_NSECOND; break;
329 case 1: return UNIT_PSECOND; break;
330 }
331 return 1.0;
332}
UNIT_SELECTOR_ANGLE(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
double GetUnitScale() override
UNIT_SELECTOR_FREQUENCY(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
double GetUnitScale() override
double GetUnitScale() override
UNIT_SELECTOR_LEN_CABLE(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
UNIT_SELECTOR_LEN(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
double GetUnitScale() override
Return the scaling factor to convert users units to normalized units (meter).
UNIT_SELECTOR_LINEAR_RESISTANCE(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
double GetUnitScale() override
UNIT_SELECTOR_POWER(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
UNIT_SELECTOR_RESISTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
double GetUnitScale() override
double GetUnitScale() override
UNIT_SELECTOR_SPEED(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
UNIT_SELECTOR_THICKNESS(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
double GetUnitScale() override
UNIT_SELECTOR_TIME(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
double GetUnitScale() override
double GetUnitScale() override
UNIT_SELECTOR_VOLTAGE(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
UNIT_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
#define _(s)
#define UNIT_DEGREE
#define UNIT_RADIAN
#define UNIT_OZSQFT
#define UNIT_MILES_PER_HOUR
#define UNIT_NSECOND
#define UNIT_METER_PER_SECOND
#define UNIT_OHM_PER_METER
#define UNIT_PSECOND
#define UNIT_KOHM
#define UNIT_GHZ
#define UNIT_MICRON
#define UNIT_KILOMETER_PER_HOUR
#define UNIT_FEET_PER_SECOND
#define UNIT_WATT
#define UNIT_MHZ
#define UNIT_OHM
#define UNIT_MM
#define UNIT_OHM_PER_FEET
#define UNIT_MILLIVOLT
#define UNIT_KHZ
#define UNIT_MIL
#define UNIT_VOLT
#define UNIT_INCH
#define UNIT_OHM_PER_1000FEET
#define UNIT_FEET
#define UNIT_MILLIWATT
#define UNIT_OHM_PER_KILOMETER
#define UNIT_CM
#define UNIT_KM
a wxChoiceBox to select units in Pcb_Calculator