26 #include <compoundfilereader.h> 30 #include <wx/translation.h> 35 const CFB::CompoundFileReader& aReader,
const char* aStreamName )
37 const CFB::COMPOUND_FILE_ENTRY* ret =
nullptr;
38 aReader.EnumFiles( aReader.GetRootEntry(), -1,
39 [&](
const CFB::COMPOUND_FILE_ENTRY* aEntry,
const CFB::utf16string& aU16dir,
41 if( aReader.IsStream( aEntry ) )
43 std::string
name = UTF16ToUTF8( aEntry->name );
44 if( aU16dir.length() > 0 )
46 std::string dir = UTF16ToUTF8( aU16dir.c_str() );
47 if( strncmp( aStreamName, dir.c_str(), dir.length() ) == 0
48 && aStreamName[dir.length()] ==
'\\' 49 && strcmp( aStreamName + dir.length() + 1,
name.c_str() ) == 0 )
56 if( strcmp( aStreamName,
name.c_str() ) == 0 )
68 const CFB::CompoundFileReader& aReader,
const CFB::COMPOUND_FILE_ENTRY* aEntry )
71 m_size = static_cast<size_t>( aEntry->size );
83 std::map<wxString, wxString>
kv;
85 uint32_t length = Read<uint32_t>();
94 if(
m_pos[length - 1] !=
'\0' )
96 wxLogError(
"For Altium import, we assumes a null byte at the end of a list of properties. " 97 "Because this is missing, imported data might be malformed or missing." );
102 std::string str = std::string(
m_pos, length - 1 );
105 std::size_t token_end = 0;
106 while( token_end < str.size() && token_end != std::string::npos )
108 std::size_t token_start = str.find(
'|', token_end );
109 std::size_t token_equal = str.find(
'=', token_start );
110 token_end = str.find(
'|', token_equal );
112 std::string keyS = str.substr( token_start + 1, token_equal - token_start - 1 );
113 std::string valueS = str.substr( token_equal + 1, token_end - token_equal - 1 );
117 wxString key( keyS.c_str(), wxConvISO8859_1 );
118 wxString value( valueS.c_str(), wxConvISO8859_1 );
121 kv.insert( { key.Trim().MakeUpper(), value.Trim() } );
128 const std::map<wxString, wxString>& aProperties,
const wxString& aKey,
int aDefault )
130 const std::map<wxString, wxString>::const_iterator& value = aProperties.find( aKey );
131 return value == aProperties.end() ? aDefault : wxAtoi( value->second );
135 const std::map<wxString, wxString>& aProperties,
const wxString& aKey,
double aDefault )
137 const std::map<wxString, wxString>::const_iterator& value = aProperties.find( aKey );
138 if( value == aProperties.end() )
144 std::istringstream istr( (
const char*) value->second.mb_str() );
145 istr.imbue( std::locale::classic() );
153 const std::map<wxString, wxString>& aProperties,
const wxString& aKey,
bool aDefault )
155 const std::map<wxString, wxString>::const_iterator& value = aProperties.find( aKey );
156 if( value == aProperties.end() )
159 return value->second ==
"T" || value->second ==
"TRUE";
163 const wxString& aKey,
const wxString& aDefault )
168 if( !value.EndsWith(
"mil", &prefix ) )
175 if( !prefix.ToCDouble( &mils ) )
177 wxLogError(
wxString::Format(
"Cannot convert '%s' into double", prefix ) );
185 const wxString& aKey,
const wxString& aDefault )
187 const std::map<wxString, wxString>::const_iterator& value = aProperties.find( aKey );
188 return value == aProperties.end() ? aDefault : value->second;
static int PropertiesReadInt(const std::map< wxString, wxString > &aProperties, const wxString &aKey, int aDefault)
size_t GetRemainingBytes() const
static bool PropertiesReadBool(const std::map< wxString, wxString > &aProperties, const wxString &aKey, bool aDefault)
static int32_t PropertiesReadKicadUnit(const std::map< wxString, wxString > &aProperties, const wxString &aKey, const wxString &aDefault)
static int32_t ConvertToKicadUnit(const double aValue)
const CFB::COMPOUND_FILE_ENTRY * FindStream(const CFB::CompoundFileReader &aReader, const char *aStreamName)
std::map< wxString, wxString > ReadProperties()
static double PropertiesReadDouble(const std::map< wxString, wxString > &aProperties, const wxString &aKey, double aDefault)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
ALTIUM_PARSER(const CFB::CompoundFileReader &aReader, const CFB::COMPOUND_FILE_ENTRY *aEntry)
static wxString PropertiesReadString(const std::map< wxString, wxString > &aProperties, const wxString &aKey, const wxString &aDefault)
std::unique_ptr< char[]> m_content