#include "DataLoader.hpp" #include "CsvLoader.hpp" #include "MatLoader.hpp" #include "Mf4Loader.hpp" #include "Utf8Util.hpp" #include namespace jdi { namespace { /** @brief 取小写扩展名(含点)。 */ std::wstring ExtensionOf(const std::wstring& filePath) { const std::size_t dot = filePath.find_last_of(L'.'); if (dot == std::wstring::npos) { return std::wstring(); } return ToLowerAscii(filePath.substr(dot)); } } // namespace bool IsSupportedSignalFile(const std::wstring& filePath) { const std::wstring extension = ExtensionOf(filePath); return extension == L".csv" || extension == L".txt" || extension == L".mf4" || extension == L".mdf" || extension == L".dat" || extension == L".mat"; } const wchar_t* SignalFileDialogFilter() { // GetOpenFileNameW 要求:每个过滤器一对「说明\0通配符\0」,最后以空字符串结束。 return L"测量数据文件 (*.csv;*.txt;*.mf4;*.mdf;*.dat;*.mat)\0*.csv;*.txt;*.mf4;*.mdf;*.dat;*.mat\0" L"CSV 文本 (*.csv;*.txt)\0*.csv;*.txt\0" L"ASAM MDF v4 (*.mf4;*.mdf)\0*.mf4;*.mdf\0" L"MATLAB 数据 (*.mat)\0*.mat\0" L"全部文件 (*.*)\0*.*\0"; } bool LoadSignalSourceGroups(const std::wstring& filePath, std::vector& groups, std::wstring& error, const LoadProgress& progress) { error.clear(); groups.clear(); const std::wstring extension = ExtensionOf(filePath); if (extension == L".mat") { return LoadMatSourceGroups(filePath, groups, error, progress); } LoadedSourceGroup group; if (!LoadSignalSource(filePath, group.source, error, progress)) { return false; } groups.push_back(std::move(group)); return true; } bool LoadSignalSource(const std::wstring& filePath, LoadedSource& source, std::wstring& error, const LoadProgress& progress) { const std::wstring extension = ExtensionOf(filePath); if (extension == L".mf4" || extension == L".mdf") { return LoadMf4Source(filePath, source, error, progress); } // 其余(含未知扩展名)一律按 CSV 文本尝试解析:文本格式的容错性最好, // 而未知扩展名在「打开文件」对话框里也只能由用户显式指定。 return LoadCsvSource(filePath, source, error, progress); } } // namespace jdi