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.
kev/Drawer/Module/GeoSigmaDraw/TableDataImporter.h

68 lines
2.5 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#include "stdafx.h"
class CSigmaView;
class CXy;
#include "TsvParser.h"
#include <map>
#include <vector>
/**
* @brief 表格数据导入类型(与流式 API 的 importType 对应)
*/
enum TableImportType
{
TableImport_Points = 1, // 普通点井点X,Y 必需Z, 名称, 图层 可选
TableImport_XyzPoints = 2, // XYZ 散点X,Y 必需Z, 图层 可选
TableImport_Curves = 3 // 曲线X,Y 必需Z, L, 名称, 图层 可选
};
/**
* @brief 从已解析的表格数据导入普通点(井点)
* @return 导入数量,失败返回 -1
*/
int ImportTableAsPoints(CSigmaView* pView, const TsvParser::TableData& tableData);
/**
* @brief 从已解析的表格数据导入 XYZ 散点
* @return 导入数量,失败返回 -1
*/
int ImportTableAsXyzPoints(CSigmaView* pView, const TsvParser::TableData& tableData);
/**
* @brief 从已解析的表格数据导入曲线
* @return 导入曲线条数,失败返回 -1
*/
int ImportTableAsCurves(CSigmaView* pView, const TsvParser::TableData& tableData);
// ---------------------------------------------------------------------------
// 流式按行导入(真流式:每行解析完即导入,不攒整表)
// ---------------------------------------------------------------------------
void BuildColumnIndexMapFromHeaders(const std::vector<CString>& headers, std::map<CString, int>& outMap);
CString GetRowValue(const std::vector<CString>& row, const std::map<CString, int>& columnIndexMap, const CString& columnName);
double GetRowDoubleValue(const std::vector<CString>& row, const std::map<CString, int>& columnIndexMap, const CString& columnName, double defaultValue = 0.0);
bool ImportPointRow(CSigmaView* pView, const std::map<CString, int>& columnIndexMap, const std::vector<CString>& row);
bool ImportXyzPointRow(CSigmaView* pView, const std::map<CString, int>& columnIndexMap, const std::vector<CString>& row);
/** 曲线流式导入:有状态,每行 OnRow结束时 End() 提交最后一条曲线 */
class CurveStreamImporter
{
public:
explicit CurveStreamImporter(CSigmaView* pView);
void OnRow(const std::map<CString, int>& columnIndexMap, const std::vector<CString>& row);
void End();
int GetImportCount() const { return m_importCount; }
private:
void FlushCurrentCurve();
CSigmaView* m_pView = nullptr;
CXy* m_pXy = nullptr;
CString m_currentLayer;
CString m_currentName;
std::vector<double> m_curX, m_curY, m_curZ, m_curL;
CString m_curName;
int m_importCount = 0;
};