KiCad PCB EDA Suite
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 (C) 2004-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 
26 #include "unit_selector.h"
27 #include "units_scales.h"
28 
29 UNIT_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 
42 /*
43  * Function GetUnitScale
44  * return the scaling factor to convert users units
45  * to normalized units (meter)
46  */
48 {
49  switch( GetCurrentSelection() )
50  {
51  case 0: return UNIT_MM; break;
52  case 1: return UNIT_MICRON; break;
53  case 2: return UNIT_CM; break;
54  case 3: return UNIT_MIL; break;
55  case 4: return UNIT_INCH; break;
56  }
57  return 1.0;
58 }
59 
60 
61 UNIT_SELECTOR_THICKNESS::UNIT_SELECTOR_THICKNESS( wxWindow *parent, wxWindowID id,
62  const wxPoint& pos, const wxSize& size,
63  const wxArrayString& choices, long style )
64  : UNIT_SELECTOR( parent, id, pos, size, choices, style )
65 {
66  Append( wxT( "mm" ) );
67  Append( wxT( "µm" ) );
68  Append( wxT( "cm" ) );
69  Append( wxT( "mil" ) );
70  Append( wxT( "inch" ) );
71  Append( wxT( "oz/ft²" ) );
72 }
73 
74 
75 /*
76  * Function GetUnitScale
77  * return the scaling factor to convert users units
78  * to normalized units (meter) including copper oz/ft^2
79  */
81 {
82  switch( GetCurrentSelection() )
83  {
84  case 0: return UNIT_MM; break;
85  case 1: return UNIT_MICRON; break;
86  case 2: return UNIT_CM; break;
87  case 3: return UNIT_MIL; break;
88  case 4: return UNIT_INCH; break;
89  case 5: return UNIT_OZSQFT; break;
90  }
91  return 1.0;
92 }
93 
94 
95 UNIT_SELECTOR_FREQUENCY::UNIT_SELECTOR_FREQUENCY( wxWindow *parent, wxWindowID id,
96  const wxPoint& pos, const wxSize& size,
97  const wxArrayString& choices, long style ):
98  UNIT_SELECTOR( parent, id, pos, size, choices, style )
99 {
100  Append( _( "GHz" ) );
101  Append( _( "MHz" ) );
102  Append( _( "kHz" ) );
103  Append( _( "Hz" ) );
104 }
105 
106 /*
107  * Function GetUnitScale
108  * return the scaling factor to convert users units
109  * to normalized units (herz )
110  */
112 {
113  switch( GetCurrentSelection() )
114  {
115  case 0: return UNIT_GHZ;
116  case 1: return UNIT_MHZ;
117  case 2: return UNIT_KHZ;
118  case 3: return 1.0;
119  }
120  return 1.0;
121 }
122 
123 
124 UNIT_SELECTOR_ANGLE::UNIT_SELECTOR_ANGLE( wxWindow *parent, wxWindowID id,
125  const wxPoint& pos, const wxSize& size,
126  const wxArrayString& choices, long style ) :
127  UNIT_SELECTOR( parent, id, pos, size, choices, style )
128 {
129  Append( _( "rad" ) );
130  Append( _( "deg" ) );
131 }
132 
133 /*
134  * Function GetUnitScale
135  * return the scaling factor to convert users units
136  * to normalized units ( radian )
137  */
139 {
140  switch( GetCurrentSelection() )
141  {
142  case 0: return UNIT_RADIAN; break;
143  case 1: return UNIT_DEGREE; break;
144  }
145  return 1.0;
146 }
147 
148 
149 UNIT_SELECTOR_RESISTOR::UNIT_SELECTOR_RESISTOR( wxWindow *parent, wxWindowID id,
150  const wxPoint& pos, const wxSize& size,
151  const wxArrayString& choices, long style )
152  : UNIT_SELECTOR( parent, id, pos, size, choices, style )
153 {
154  Append( wxT( "Ω" ) );
155  Append( wxT( "kΩ" ) );
156 }
157 
158 
159 /*
160  * Function GetUnitScale
161  * return the scaling factor to convert users units
162  * to normalized units ( ohm )
163  */
165 {
166  switch( GetCurrentSelection() )
167  {
168  case 0: return UNIT_OHM; break;
169  case 1: return UNIT_KOHM; break;
170  }
171  return 1.0;
172 }
173 
UNIT_SELECTOR_ANGLE(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
#define UNIT_OZSQFT
Definition: units_scales.h:36
#define UNIT_OHM
Definition: units_scales.h:45
double GetUnitScale() override
Function GetUnitScale.
#define UNIT_INCH
Definition: units_scales.h:34
UNIT_SELECTOR_FREQUENCY(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
double GetUnitScale() override
Function GetUnitScale.
#define UNIT_CM
Definition: units_scales.h:32
#define UNIT_KOHM
Definition: units_scales.h:46
double GetUnitScale() override
Function GetUnitScale.
#define UNIT_RADIAN
Definition: units_scales.h:43
double GetUnitScale() override
Function GetUnitScale.
#define _(s)
#define UNIT_GHZ
Definition: units_scales.h:38
UNIT_SELECTOR_LEN(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
#define UNIT_MICRON
Definition: units_scales.h:33
#define UNIT_MHZ
Definition: units_scales.h:39
UNIT_SELECTOR_RESISTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
#define UNIT_DEGREE
Definition: units_scales.h:42
double GetUnitScale() override
Function GetUnitScale.
UNIT_SELECTOR_THICKNESS(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0)
#define UNIT_KHZ
Definition: units_scales.h:40
#define UNIT_MIL
Definition: units_scales.h:35
#define UNIT_MM
Definition: units_scales.h:31