KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eda_units.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <eda_units.h>
25#include <fmt/core.h>
26#include <math/util.h> // for KiROUND
27#include <macros.h>
28#include <charconv>
29#include <wx/translation.h>
30
31
32static void removeTrailingZeros( wxString& aText )
33{
34 int len = aText.length();
35 int removeLast = 0;
36
37 while( --len > 0 && aText[len] == '0' )
38 removeLast++;
39
40 if( len >= 0 && ( aText[len] == '.' || aText[len] == ',' ) )
41 removeLast++;
42
43 aText = aText.RemoveLast( removeLast );
44}
45
46
48{
49 switch( aUnit )
50 {
51 case EDA_UNITS::INCH:
52 case EDA_UNITS::MILS:
53 return true;
54
55 default:
56 return false;
57 }
58}
59
60
62{
63 switch( aUnit )
64 {
65 case EDA_UNITS::UM:
66 case EDA_UNITS::MM:
67 case EDA_UNITS::CM:
68 return true;
69
70 default:
71 return false;
72 }
73}
74
75
76int EDA_UNIT_UTILS::Mm2mils( double aVal )
77{
78 return KiROUND( aVal * 1000. / 25.4 );
79}
80
81
82int EDA_UNIT_UTILS::Mils2mm( double aVal )
83{
84 return KiROUND( aVal * 25.4 / 1000. );
85}
86
87
88bool EDA_UNIT_UTILS::FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits )
89{
90 wxString buf( aTextValue.Strip( wxString::both ) );
91 unsigned brk_point = 0;
92
93 while( brk_point < buf.Len() )
94 {
95 wxChar c = buf[brk_point];
96
97 if( !( ( c >= '0' && c <= '9' ) || ( c == '.' ) || ( c == ',' ) || ( c == '-' )
98 || ( c == '+' ) ) )
99 break;
100
101 ++brk_point;
102 }
103
104 // Check the unit designator (2 ch significant)
105 wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
106
107 //check for um, μm (µ is MICRO SIGN) and µm (µ is GREEK SMALL LETTER MU) for micrometre
108 if( unit == wxT( "um" ) || unit == wxT( "\u00B5m" ) || unit == wxT( "\u03BCm" ) )
109 aUnits = EDA_UNITS::UM;
110 else if( unit == wxT( "mm" ) )
111 aUnits = EDA_UNITS::MM;
112 if( unit == wxT( "cm" ) )
113 aUnits = EDA_UNITS::CM;
114 else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) // "mils" or "thou"
115 aUnits = EDA_UNITS::MILS;
116 else if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
117 aUnits = EDA_UNITS::INCH;
118 else if( unit == wxT( "de" ) || unit == wxT( "ra" ) ) // "deg" or "rad"
119 aUnits = EDA_UNITS::DEGREES;
120 else if( unit == wxT("fs" ) )
121 aUnits = EDA_UNITS::FS;
122 else if( unit == wxT( "ps" ) )
123 {
124 wxString timeUnit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 5 ).Lower() );
125
126 if( timeUnit == wxT( "ps" ) )
127 aUnits = EDA_UNITS::PS;
128 else if( timeUnit == wxT( "ps/in" ) )
129 aUnits = EDA_UNITS::PS_PER_INCH;
130 else if( timeUnit == wxT( "ps/cm" ) )
131 aUnits = EDA_UNITS::PS_PER_CM;
132 else if( timeUnit == wxT( "ps/mm" ) )
133 aUnits = EDA_UNITS::PS_PER_MM;
134 else
135 return false;
136 }
137 else
138 return false;
139
140 return true;
141}
142
143
145{
146 wxString label;
147
148 switch( aUnits )
149 {
150 case EDA_UNITS::UM: label = wxT( " \u00B5m" ); break; //00B5 for µ
151 case EDA_UNITS::MM: label = wxT( " mm" ); break;
152 case EDA_UNITS::CM: label = wxT( " cm" ); break;
153 case EDA_UNITS::DEGREES: label = wxT( "°" ); break;
154 case EDA_UNITS::MILS: label = wxT( " mils" ); break;
155 case EDA_UNITS::INCH: label = wxT( " in" ); break;
156 case EDA_UNITS::PERCENT: label = wxT( "%" ); break;
157 case EDA_UNITS::FS: label = wxT( " fs" ); break;
158 case EDA_UNITS::PS: label = wxT( " ps" ); break;
159 case EDA_UNITS::PS_PER_INCH: label = wxT( " ps/in" ); break;
160 case EDA_UNITS::PS_PER_CM: label = wxT( " ps/cm"); break;
161 case EDA_UNITS::PS_PER_MM: label = wxT( " ps/mm"); break;
162 case EDA_UNITS::UNSCALED: break;
163 default: UNIMPLEMENTED_FOR( wxS( "Unknown units" ) ); break;
164 }
165
166 switch( aType )
167 {
168 case EDA_DATA_TYPE::VOLUME: label += wxT( "³" ); break;
169 case EDA_DATA_TYPE::AREA: label += wxT( "²" ); break;
170 case EDA_DATA_TYPE::DISTANCE: break;
171 case EDA_DATA_TYPE::TIME: break;
172 case EDA_DATA_TYPE::LENGTH_DELAY: break;
173 default: UNIMPLEMENTED_FOR( wxS( "Unknown measurement" ) ); break;
174 }
175
176 return label;
177}
178
179
181{
182 return GetText( aUnits, aType ).Trim( false );
183}
184
185
186std::string EDA_UNIT_UTILS::FormatAngle( const EDA_ANGLE& aAngle )
187{
188 std::string temp = fmt::format( "{:.10g}", aAngle.AsDegrees() );
189
190 return temp;
191}
192
193
194std::string EDA_UNIT_UTILS::FormatInternalUnits( const EDA_IU_SCALE& aIuScale, int aValue )
195{
196 std::string buf;
197 double engUnits = aValue;
198
199 engUnits /= aIuScale.IU_PER_MM;
200
201 if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
202 {
203 buf = fmt::format( "{:.10f}", engUnits );
204
205 // remove trailing zeros
206 while( !buf.empty() && buf[buf.size() - 1] == '0' )
207 {
208 buf.pop_back();
209 }
210
211 // if the value was really small
212 // we may have just stripped all the zeros after the decimal
213 if( buf[buf.size() - 1] == '.' )
214 {
215 buf.pop_back();
216 }
217 }
218 else
219 {
220 buf = fmt::format( "{:.10g}", engUnits );
221 }
222
223 return buf;
224}
225
226
228 const VECTOR2I& aPoint )
229{
230 return FormatInternalUnits( aIuScale, aPoint.x ) + " "
231 + FormatInternalUnits( aIuScale, aPoint.y );
232}
233
234
235#if 0 // No support for std::from_chars on MacOS yet
236
237bool EDA_UNIT_UTILS::ParseInternalUnits( const std::string& aInput, const EDA_IU_SCALE& aIuScale,
238 int& aOut )
239{
240 double value;
241
242 if( std::from_chars( aInput.data(), aInput.data() + aInput.size(), value ).ec != std::errc() )
243 return false;
244
245 aOut = value * aIuScale.IU_PER_MM;
246 return true;
247}
248
249
250bool EDA_UNIT_UTILS::ParseInternalUnits( const std::string& aInput, const EDA_IU_SCALE& aIuScale,
251 VECTOR2I& aOut )
252{
253 size_t pos = aInput.find( ' ' );
254
255 if( pos == std::string::npos )
256 return false;
257
258 std::string first = aInput.substr( 0, pos );
259 std::string second = aInput.substr( pos + 1 );
260
261 VECTOR2I vec;
262
263 if( !ParseInternalUnits( first, aIuScale, vec.x ) )
264 return false;
265
266 if( !ParseInternalUnits( second, aIuScale, vec.y ) )
267 return false;
268
269 aOut = vec;
270
271 return true;
272}
273
274#endif
275
276
277#define IU_TO_MM( x, scale ) ( x / scale.IU_PER_MM )
278#define IU_TO_IN( x, scale ) ( x / scale.IU_PER_MILS / 1000 )
279#define IU_TO_MILS( x, scale ) ( x / scale.IU_PER_MILS )
280#define IU_TO_PS( x, scale ) ( x / scale.IU_PER_PS )
281#define IU_TO_PS_PER_MM( x, scale ) ( x / scale.IU_PER_PS_PER_MM )
282#define MM_TO_IU( x, scale ) ( x * scale.IU_PER_MM )
283#define IN_TO_IU( x, scale ) ( x * scale.IU_PER_MILS * 1000 )
284#define MILS_TO_IU( x, scale ) ( x * scale.IU_PER_MILS )
285#define PS_TO_IU( x, scale ) ( x * scale.IU_PER_PS )
286#define PS_PER_MM_TO_IU( x, scale ) ( x * scale.IU_PER_PS_PER_MM )
287
288
290 double aValue )
291{
292 switch( aUnit )
293 {
294 case EDA_UNITS::UM: return IU_TO_MM( aValue, aIuScale ) * 1000;
295 case EDA_UNITS::MM: return IU_TO_MM( aValue, aIuScale );
296 case EDA_UNITS::CM: return IU_TO_MM( aValue, aIuScale ) / 10;
297 case EDA_UNITS::MILS: return IU_TO_MILS( aValue, aIuScale );
298 case EDA_UNITS::INCH: return IU_TO_IN( aValue, aIuScale );
299 case EDA_UNITS::DEGREES: return aValue;
300 case EDA_UNITS::FS: return IU_TO_PS( aValue, aIuScale ) * 1000.0;
301 case EDA_UNITS::PS: return IU_TO_PS( aValue, aIuScale );
302 case EDA_UNITS::PS_PER_INCH: return IU_TO_PS_PER_MM( aValue, aIuScale ) * 25.4;
303 case EDA_UNITS::PS_PER_CM: return IU_TO_PS_PER_MM( aValue, aIuScale ) * 10;
304 case EDA_UNITS::PS_PER_MM: return IU_TO_PS_PER_MM( aValue, aIuScale );
305 default: return aValue;
306 }
307}
308
309
311 double aValue, bool aAddUnitsText,
312 EDA_DATA_TYPE aType )
313{
314 double value_to_print = aValue;
315 bool is_eeschema = ( aIuScale.IU_PER_MM == SCH_IU_PER_MM );
316
317 switch( aType )
318 {
320 value_to_print = ToUserUnit( aIuScale, aUnits, value_to_print );
322
324 value_to_print = ToUserUnit( aIuScale, aUnits, value_to_print );
326
328 value_to_print = ToUserUnit( aIuScale, aUnits, value_to_print );
329 break;
330
332 break;
333
335 value_to_print = ToUserUnit( aIuScale, aUnits, value_to_print );
336 break;
337
339 value_to_print = ToUserUnit( aIuScale, aUnits, value_to_print );
340 break;
341 }
342
343 const wxChar* format = nullptr;
344
345 switch( aUnits )
346 {
347
348 case EDA_UNITS::MILS: format = is_eeschema ? wxT( "%.3f" ) : wxT( "%.5f" ); break;
349 case EDA_UNITS::INCH: format = is_eeschema ? wxT( "%.6f" ) : wxT( "%.8f" ); break;
350 case EDA_UNITS::DEGREES: format = wxT( "%.4f" ); break;
351 case EDA_UNITS::PS_PER_INCH: format = wxT( "%.4f" ); break;
352 case EDA_UNITS::PS_PER_CM: format = wxT( "%.3f" ); break;
353 case EDA_UNITS::PS_PER_MM: format = wxT( "%.3f" ); break;
354 default: format = wxT( "%.10f" ); break;
355 }
356
357 wxString text;
358 text.Printf( format, value_to_print );
360
361 if( value_to_print != 0.0 && ( text == wxS( "0" ) || text == wxS( "-0" ) ) )
362 {
363 text.Printf( wxS( "%.10f" ), value_to_print );
365 }
366
367 if( aAddUnitsText )
368 text << EDA_UNIT_UTILS::GetText( aUnits, aType );
369
370 return text;
371}
372
373
374
375// A lower-precision (for readability) version of StringFromValue()
377 int aValue,
378 bool aAddUnitLabel,
379 EDA_DATA_TYPE aType )
380{
381 return MessageTextFromValue( aIuScale, aUnits, double( aValue ), aAddUnitLabel, aType );
382}
383
384
385// A lower-precision (for readability) version of StringFromValue()
387 long long int aValue,
388 bool aAddUnitLabel,
389 EDA_DATA_TYPE aType )
390{
391 return MessageTextFromValue( aIuScale, aUnits, double( aValue ), aAddUnitLabel, aType );
392}
393
394
395wxString EDA_UNIT_UTILS::UI::MessageTextFromValue( EDA_ANGLE aValue, bool aAddUnitLabel )
396{
397 if( aAddUnitLabel )
398 return wxString::Format( wxT( "%.1f°" ), aValue.AsDegrees() );
399 else
400 return wxString::Format( wxT( "%.1f" ), aValue.AsDegrees() );
401}
402
403
404// A lower-precision (for readability) version of StringFromValue()
406 double aValue, bool aAddUnitsText,
407 EDA_DATA_TYPE aType )
408{
409 wxString text;
410 const wxChar* format;
411 double value = aValue;
412 bool is_eeschema = ( aIuScale.IU_PER_MM == SCH_IU_PER_MM );
413
414 switch( aType )
415 {
417 value = ToUserUnit( aIuScale, aUnits, value );
418 // Fall through to continue computation
420
422 value = ToUserUnit( aIuScale, aUnits, value );
423 // Fall through to continue computation
425
427 value = ToUserUnit( aIuScale, aUnits, value );
428 break;
429
431 break;
432
434 value = ToUserUnit( aIuScale, aUnits, value );
435 break;
436
438 value = ToUserUnit( aIuScale, aUnits, value );
439 break;
440 }
441
442 switch( aUnits )
443 {
444 default:
445 case EDA_UNITS::UM: format = is_eeschema ? wxT( "%.0f" ) : wxT( "%.1f" ); break;
446 case EDA_UNITS::MM: format = is_eeschema ? wxT( "%.2f" ) : wxT( "%.4f" ); break;
447 case EDA_UNITS::CM: format = is_eeschema ? wxT( "%.3f" ) : wxT( "%.5f" ); break;
448 case EDA_UNITS::MILS: format = is_eeschema ? wxT( "%.0f" ) : wxT( "%.2f" ); break;
449 case EDA_UNITS::INCH: format = is_eeschema ? wxT( "%.3f" ) : wxT( "%.4f" ); break;
450 case EDA_UNITS::DEGREES: format = wxT( "%.3f" ); break;
451 case EDA_UNITS::UNSCALED: format = wxT( "%.0f" ); break;
452 case EDA_UNITS::FS: format = wxT( "%.4f" ); break;
453 case EDA_UNITS::PS: format = wxT( "%.2f" ); break;
454 case EDA_UNITS::PS_PER_INCH: format = wxT( "%.2f" ); break;
455 case EDA_UNITS::PS_PER_CM: format = wxT( "%.2f" ); break;
456 case EDA_UNITS::PS_PER_MM: format = wxT( "%.2f" ); break;
457 }
458
459 text.Printf( format, value );
460
461 if( aAddUnitsText )
462 text += EDA_UNIT_UTILS::GetText( aUnits, aType );
463
464 return text;
465}
466
467
469 EDA_UNITS aUnits,
470 const MINOPTMAX<int>& aValue )
471{
472 wxString msg;
473
474 if( aValue.HasMin() && aValue.Min() > 0 )
475 {
476 msg += _( "min" ) + wxS( " " ) + MessageTextFromValue( aIuScale, aUnits, aValue.Min() );
477 }
478
479 if( aValue.HasOpt() )
480 {
481 if( !msg.IsEmpty() )
482 msg += wxS( "; " );
483
484 msg += _( "opt" ) + wxS( " " ) + MessageTextFromValue( aIuScale, aUnits, aValue.Opt() );
485 }
486
487 if( aValue.HasMax() )
488 {
489 if( !msg.IsEmpty() )
490 msg += wxS( "; " );
491
492 msg += _( "max" ) + wxS( " " ) + MessageTextFromValue( aIuScale, aUnits, aValue.Max() );
493 }
494
495 return msg;
496};
497
498
500 double aValue )
501{
502 switch( aUnits )
503 {
504 case EDA_UNITS::UM: return MM_TO_IU( aValue / 1000.0, aIuScale );
505 case EDA_UNITS::MM: return MM_TO_IU( aValue, aIuScale );
506 case EDA_UNITS::CM: return MM_TO_IU( aValue * 10, aIuScale );
507 case EDA_UNITS::MILS: return MILS_TO_IU( aValue, aIuScale );
508 case EDA_UNITS::INCH: return IN_TO_IU( aValue, aIuScale );
509 case EDA_UNITS::FS: return PS_TO_IU( aValue / 1000.0, aIuScale );
510 case EDA_UNITS::PS: return PS_TO_IU( aValue, aIuScale );
511 case EDA_UNITS::PS_PER_INCH: return PS_PER_MM_TO_IU( aValue / 25.4, aIuScale );
512 case EDA_UNITS::PS_PER_CM: return PS_PER_MM_TO_IU( aValue / 10, aIuScale );
513 case EDA_UNITS::PS_PER_MM: return PS_PER_MM_TO_IU( aValue, aIuScale );
514 default:
517 case EDA_UNITS::PERCENT: return aValue;
518 }
519}
520
521
522double EDA_UNIT_UTILS::UI::DoubleValueFromString( const wxString& aTextValue )
523{
524 double dtmp = 0;
525
526 // Acquire the 'right' decimal point separator
527 const struct lconv* lc = localeconv();
528
529 wxChar decimal_point = lc->decimal_point[0];
530 wxString buf( aTextValue.Strip( wxString::both ) );
531
532 // Convert any entered decimal point separators to the 'right' one
533 buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
534 buf.Replace( wxT( "," ), wxString( decimal_point, 1 ) );
535
536 // Find the end of the numeric part
537 unsigned brk_point = 0;
538
539 while( brk_point < buf.Len() )
540 {
541 wxChar ch = buf[brk_point];
542
543 if( !( ( ch >= '0' && ch <= '9' ) || ( ch == decimal_point ) || ( ch == '-' )
544 || ( ch == '+' ) ) )
545 {
546 break;
547 }
548
549 ++brk_point;
550 }
551
552 // Extract the numeric part
553 buf.Left( brk_point ).ToDouble( &dtmp );
554
555 return dtmp;
556}
557
558
560 const wxString& aTextValue, EDA_DATA_TYPE aType )
561{
562 double dtmp = 0;
563
564 // Acquire the 'right' decimal point separator
565 const struct lconv* lc = localeconv();
566
567 wxChar decimal_point = lc->decimal_point[0];
568 wxString buf( aTextValue.Strip( wxString::both ) );
569
570 // Convert any entered decimal point separators to the 'right' one
571 buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
572 buf.Replace( wxT( "," ), wxString( decimal_point, 1 ) );
573
574 // Find the end of the numeric part
575 unsigned brk_point = 0;
576
577 while( brk_point < buf.Len() )
578 {
579 wxChar ch = buf[brk_point];
580
581 if( !( (ch >= '0' && ch <= '9') || (ch == decimal_point) || (ch == '-') || (ch == '+') ) )
582 break;
583
584 ++brk_point;
585 }
586
587 // Extract the numeric part
588 buf.Left( brk_point ).ToDouble( &dtmp );
589
590 // Check the optional unit designator (2 ch significant)
591 wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
592
593 if( aUnits == EDA_UNITS::UM
594 || aUnits == EDA_UNITS::MM
595 || aUnits == EDA_UNITS::CM
596 || aUnits == EDA_UNITS::MILS
597 || aUnits == EDA_UNITS::INCH )
598 {
599 //check for um, μm (µ is MICRO SIGN) and µm (µ is GREEK SMALL LETTER MU) for micrometre
600 if( unit == wxT( "um" ) || unit == wxT( "\u00B5m" ) || unit == wxT( "\u03BCm" ) )
601 {
602 aUnits = EDA_UNITS::UM;
603 }
604 else if( unit == wxT( "mm" ) )
605 {
606 aUnits = EDA_UNITS::MM;
607 }
608 else if( unit == wxT( "cm" ) )
609 {
610 aUnits = EDA_UNITS::CM;
611 }
612 else if( unit == wxT( "mi" ) || unit == wxT( "th" ) )
613 {
614 aUnits = EDA_UNITS::MILS;
615 }
616 else if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
617 {
618 aUnits = EDA_UNITS::INCH;
619 }
620 else if( unit == wxT( "oz" ) ) // 1 oz = 1.37 mils
621 {
622 aUnits = EDA_UNITS::MILS;
623 dtmp *= 1.37;
624 }
625 }
626 else if( aUnits == EDA_UNITS::DEGREES )
627 {
628 if( unit == wxT( "ra" ) ) // Radians
629 dtmp *= 180.0f / M_PI;
630 }
631 else if( aUnits == EDA_UNITS::FS || aUnits == EDA_UNITS::PS || aUnits == EDA_UNITS::PS_PER_INCH
632 || aUnits == EDA_UNITS::PS_PER_CM || aUnits == EDA_UNITS::PS_PER_MM )
633
634 {
635 wxString timeUnit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 5 ).Lower() );
636
637 if( timeUnit == wxT( "fs" ) )
638 aUnits = EDA_UNITS::FS;
639 if( timeUnit == wxT( "ps" ) )
640 aUnits = EDA_UNITS::PS;
641 else if( timeUnit == wxT( "ps/in" ) )
642 aUnits = EDA_UNITS::PS_PER_INCH;
643 else if( timeUnit == wxT( "ps/cm" ) )
644 aUnits = EDA_UNITS::PS_PER_CM;
645 else if( timeUnit == wxT( "ps/mm" ) )
646 aUnits = EDA_UNITS::PS_PER_MM;
647 }
648
649 switch( aType )
650 {
652 dtmp = FromUserUnit( aIuScale, aUnits, dtmp );
654
656 dtmp = FromUserUnit( aIuScale, aUnits, dtmp );
658
660 dtmp = FromUserUnit( aIuScale, aUnits, dtmp );
661 break;
662
664 break;
665
667 dtmp = FromUserUnit( aIuScale, aUnits, dtmp );
668 break;
669
671 dtmp = FromUserUnit( aIuScale, aUnits, dtmp );
672 break;
673 }
674
675 return dtmp;
676}
677
678
679long long int EDA_UNIT_UTILS::UI::ValueFromString( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
680 const wxString& aTextValue, EDA_DATA_TYPE aType )
681{
682 double value = DoubleValueFromString( aIuScale, aUnits, aTextValue, aType );
683
684 return KiROUND<double, long long int>( value );
685}
686
687
688long long int EDA_UNIT_UTILS::UI::ValueFromString( const wxString& aTextValue )
689{
690 double value = DoubleValueFromString( aTextValue );
691
692 return KiROUND<double, long long int>( value );
693}
constexpr double SCH_IU_PER_MM
Schematic internal units 1=100nm.
Definition: base_units.h:72
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
double AsDegrees() const
Definition: eda_angle.h:116
T Min() const
Definition: minoptmax.h:33
bool HasMax() const
Definition: minoptmax.h:38
bool HasMin() const
Definition: minoptmax.h:37
T Max() const
Definition: minoptmax.h:34
T Opt() const
Definition: minoptmax.h:35
bool HasOpt() const
Definition: minoptmax.h:39
#define _(s)
#define IU_TO_IN(x, scale)
Definition: eda_units.cpp:278
#define IU_TO_PS_PER_MM(x, scale)
Definition: eda_units.cpp:281
#define IN_TO_IU(x, scale)
Definition: eda_units.cpp:283
#define IU_TO_MILS(x, scale)
Definition: eda_units.cpp:279
#define IU_TO_PS(x, scale)
Definition: eda_units.cpp:280
#define MM_TO_IU(x, scale)
Definition: eda_units.cpp:282
#define PS_TO_IU(x, scale)
Definition: eda_units.cpp:285
#define PS_PER_MM_TO_IU(x, scale)
Definition: eda_units.cpp:286
#define IU_TO_MM(x, scale)
Definition: eda_units.cpp:277
#define MILS_TO_IU(x, scale)
Definition: eda_units.cpp:284
static void removeTrailingZeros(wxString &aText)
Definition: eda_units.cpp:32
EDA_DATA_TYPE
The type of unit.
Definition: eda_units.h:38
EDA_UNITS
Definition: eda_units.h:48
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:96
KICOMMON_API wxString MessageTextFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A helper to convert the double length aValue to a string in inches, millimeters, or unscaled units.
Definition: eda_units.cpp:405
KICOMMON_API double FromUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Return in internal units the value aValue given in a real unit such as "in", "mm",...
Definition: eda_units.cpp:499
KICOMMON_API long long int ValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue in aUnits to internal units used by the application.
Definition: eda_units.cpp:679
KICOMMON_API wxString StringFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Return the string from aValue according to aUnits (inch, mm ...) for display.
Definition: eda_units.cpp:310
KICOMMON_API wxString MessageTextFromMinOptMax(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const MINOPTMAX< int > &aValue)
Definition: eda_units.cpp:468
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue to a double.
Definition: eda_units.cpp:559
KICOMMON_API double ToUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Convert aValue in internal units to the appropriate user units defined by aUnit.
Definition: eda_units.cpp:289
KICOMMON_API wxString GetText(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
Definition: eda_units.cpp:144
KICOMMON_API bool FetchUnitsFromString(const wxString &aTextValue, EDA_UNITS &aUnits)
Write any unit info found in the string to aUnits.
Definition: eda_units.cpp:88
KICOMMON_API bool IsImperialUnit(EDA_UNITS aUnit)
Definition: eda_units.cpp:47
KICOMMON_API bool IsMetricUnit(EDA_UNITS aUnit)
Definition: eda_units.cpp:61
KICOMMON_API wxString GetLabel(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
Definition: eda_units.cpp:180
KICOMMON_API int Mm2mils(double aVal)
Convert mm to mils.
Definition: eda_units.cpp:76
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
Definition: eda_units.cpp:194
KICOMMON_API std::string FormatAngle(const EDA_ANGLE &aAngle)
Convert aAngle from board units to a string appropriate for writing to file.
Definition: eda_units.cpp:186
KICOMMON_API int Mils2mm(double aVal)
Convert mils to mm.
Definition: eda_units.cpp:82
const double IU_PER_MM
Definition: base_units.h:76