You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.8 KiB
C++
82 lines
1.8 KiB
C++
#include "stdafx.h"
|
|
#include "StreamingTsvStream.h"
|
|
#include "SigmaView.h"
|
|
#include <vector>
|
|
|
|
StreamingTsvStream::StreamingTsvStream(CSigmaView* pView, int importType)
|
|
: m_pView(pView)
|
|
, m_importType(importType)
|
|
{
|
|
if (m_importType == TableImport_Curves && m_pView != nullptr)
|
|
{
|
|
m_curveImporter = std::make_unique<CurveStreamImporter>(m_pView);
|
|
}
|
|
|
|
m_parser.SetCallback([this](int lineIndex, const std::vector<std::string>& fields)
|
|
{
|
|
OnParsedLine(lineIndex, fields);
|
|
});
|
|
}
|
|
|
|
void StreamingTsvStream::Write(const void* data, size_t size)
|
|
{
|
|
m_parser.Feed(data, size);
|
|
}
|
|
|
|
void StreamingTsvStream::Complete()
|
|
{
|
|
m_parser.End();
|
|
if (m_curveImporter)
|
|
m_curveImporter->End();
|
|
}
|
|
|
|
std::vector<CString> StreamingTsvStream::FieldsToCString(const std::vector<std::string>& fields)
|
|
{
|
|
std::vector<CString> out;
|
|
out.reserve(fields.size());
|
|
for (const auto& f : fields)
|
|
{
|
|
out.emplace_back(f.c_str());
|
|
}
|
|
return out;
|
|
}
|
|
|
|
void StreamingTsvStream::OnParsedLine(int lineIndex, const std::vector<std::string>& fields)
|
|
{
|
|
std::vector<CString> row = FieldsToCString(fields);
|
|
if (row.empty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (lineIndex == 0)
|
|
{
|
|
BuildColumnIndexMapFromHeaders(row, m_columnIndexMap);
|
|
if (GetRowValue(row, m_columnIndexMap, _T("X")).IsEmpty() || GetRowValue(row, m_columnIndexMap, _T("Y")).IsEmpty())
|
|
return; // 缺 X/Y 列,后续行也会被跳过
|
|
m_headersReady = true;
|
|
return;
|
|
}
|
|
|
|
if (!m_headersReady || m_pView == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
switch (m_importType)
|
|
{
|
|
case TableImport_Points:
|
|
ImportPointRow(m_pView, m_columnIndexMap, row);
|
|
break;
|
|
case TableImport_XyzPoints:
|
|
ImportXyzPointRow(m_pView, m_columnIndexMap, row);
|
|
break;
|
|
case TableImport_Curves:
|
|
if (m_curveImporter)
|
|
m_curveImporter->OnRow(m_columnIndexMap, row);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|