29#include <wx/translation.h>
34 constexpr double int_limit = ( std::numeric_limits<int>::max() - 10 ) / 2.54;
36 int32_t iu =
KiROUND( std::clamp( aValue, -int_limit, int_limit ) * 2.54 );
41 return KiROUND( (
double) iu / 10.0 ) * 10;
48 const std::map<wxString, wxString>::const_iterator& value = aProps.find( aKey );
49 return value == aProps.end() ? aDefault : wxAtoi( value->second );
54 const wxString& aKey,
double aDefault )
56 const std::map<wxString, wxString>::const_iterator& value = aProps.find( aKey );
58 if( value == aProps.end() )
62 std::istringstream istr( (
const char*) value->second.mb_str() );
63 istr.imbue( std::locale::classic() );
74 const std::map<wxString, wxString>::const_iterator& value = aProps.find( aKey );
76 if( value == aProps.end() )
79 return value->second ==
"T" || value->second ==
"TRUE";
84 const wxString& aKey,
const wxString& aDefault )
86 const wxString& value =
ReadString( aProps, aKey, aDefault );
90 if( !value.EndsWith(
"mil", &prefix ) )
92 wxLogTrace(
"ALTIUM", wxT(
"Unit '%s' does not end with 'mil'." ), value );
96 prefix.StartsWith(
"+", &prefix );
100 if( !prefix.ToCDouble( &mils ) )
102 wxLogTrace(
"ALTIUM", wxT(
"Cannot convert '%s' to double." ), prefix );
111 const wxString& aKey,
const wxString& aDefault )
113 const auto& utf8Value = aProps.find( wxString(
"%UTF8%" ) + aKey );
115 if( utf8Value != aProps.end() )
116 return utf8Value->second;
118 const auto& value = aProps.find( aKey );
120 if( value != aProps.end() )
121 return value->second;
128 const wxString& aKey,
const wxString& aDefault )
130 const auto& unicodeFlag = aProps.find( wxS(
"UNICODE" ) );
132 if( unicodeFlag != aProps.end() && unicodeFlag->second.Contains( wxS(
"EXISTS" ) ) )
134 const auto& unicodeValue = aProps.find( wxString(
"UNICODE__" ) + aKey );
136 if( unicodeValue != aProps.end() )
138 wxArrayString arr = wxSplit( unicodeValue->second,
',',
'\0' );
141 for( wxString part : arr )
142 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 ReadKicadUnit(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
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 double ReadDouble(const std::map< wxString, wxString > &aProps, const wxString &aKey, double aDefault)
static int32_t ConvertToKicadUnit(const double aValue)