29#include <wx/translation.h>
34 constexpr double int_limit = ( std::numeric_limits<int>::max() - 10 ) / 2.54;
37 *aOutOfRange = !( aValue >= -int_limit && aValue <= int_limit );
39 int32_t iu =
KiROUND( std::clamp( aValue, -int_limit, int_limit ) * 2.54 );
44 return KiROUND( (
double) iu / 10.0 ) * 10;
51 const std::map<wxString, wxString>::const_iterator& value = aProps.find( aKey );
52 return value == aProps.end() ? aDefault : wxAtoi( value->second );
57 const wxString& aKey,
double aDefault )
59 const std::map<wxString, wxString>::const_iterator& value = aProps.find( aKey );
61 if( value == aProps.end() )
65 std::istringstream istr( (
const char*) value->second.mb_str() );
66 istr.imbue( std::locale::classic() );
77 const std::map<wxString, wxString>::const_iterator& value = aProps.find( aKey );
79 if( value == aProps.end() )
82 return value->second ==
"T" || value->second ==
"TRUE";
87 const wxString& aKey,
const wxString& aDefault,
93 const wxString& value =
ReadString( aProps, aKey, aDefault );
97 if( !value.EndsWith(
"mil", &prefix ) )
99 wxLogTrace(
"ALTIUM", wxT(
"Unit '%s' does not end with 'mil'." ), value );
103 prefix.StartsWith(
"+", &prefix );
107 if( !prefix.ToCDouble( &mils ) )
109 wxLogTrace(
"ALTIUM", wxT(
"Cannot convert '%s' to double." ), prefix );
118 const wxString& aKey,
const wxString& aDefault )
120 const auto& utf8Value = aProps.find( wxString(
"%UTF8%" ) + aKey );
122 if( utf8Value != aProps.end() )
123 return utf8Value->second;
125 const auto& value = aProps.find( aKey );
127 if( value != aProps.end() )
128 return value->second;
135 const wxString& aKey,
const wxString& aDefault )
137 const auto& unicodeFlag = aProps.find( wxS(
"UNICODE" ) );
139 if( unicodeFlag != aProps.end() && unicodeFlag->second.Contains( wxS(
"EXISTS" ) ) )
141 const auto& unicodeValue = aProps.find( wxString(
"UNICODE__" ) + aKey );
143 if( unicodeValue != aProps.end() )
145 wxArrayString arr = wxSplit( unicodeValue->second,
',',
'\0' );
148 for( wxString part : arr )
149 out += wxString(
wchar_t( wxAtoi( part ) ) );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)
static int32_t ConvertToKicadUnit(const double aValue, bool *aOutOfRange=nullptr)
Convert a value in Altium's internal unit (0.1 uinch) to KiCad IU, clamped to the representable range...
static bool ReadBool(const std::map< wxString, wxString > &aProps, const wxString &aKey, bool aDefault)
static wxString ReadUnicodeString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
static wxString ReadString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
static int32_t ReadKicadUnit(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault, bool *aOutOfRange=nullptr)
static double ReadDouble(const std::map< wxString, wxString > &aProps, const wxString &aKey, double aDefault)