237 lines
6.3 KiB
C++
237 lines
6.3 KiB
C++
|
#include "PointInterpreter.h"
|
|||
|
#include "Constants.h"
|
|||
|
#include <regex>
|
|||
|
#include <stdexcept>
|
|||
|
#include <sstream>
|
|||
|
#include "Geometry_M.h"
|
|||
|
#include "Common/tangible_string_helper.h"
|
|||
|
#include "DataManager/Infrastructure.Interface/Arithmetics/ChangeFSPos.h"
|
|||
|
|
|||
|
void PointInterpreter::ExecuteCommand(std::vector<std::string> &commandLines, std::vector<Point3D_M> &pLoc)
|
|||
|
{
|
|||
|
std::string cmdTmp = "";
|
|||
|
std::vector<std::string> lineName = StringHelper::split(commandLines[0], std::vector<std::string>{SPACE});
|
|||
|
std::string name = "";
|
|||
|
std::string nameStr = "";
|
|||
|
std::vector<std::string> pName;
|
|||
|
std::string lastName = "";
|
|||
|
Point3D_M point;
|
|||
|
if (lineName.size() == 1) // 未指定名称
|
|||
|
{
|
|||
|
lastName = "P";
|
|||
|
}
|
|||
|
else // 指定了名称
|
|||
|
{
|
|||
|
for (int i = 1; i < lineName.size(); i++)
|
|||
|
{
|
|||
|
lastName = lineName[i];
|
|||
|
if (ParseInputName(point, name, lastName) == false)
|
|||
|
{
|
|||
|
throw std::runtime_error("命令执行失败\n Error: 重复命名,不能覆盖原名称对象.\n 位置:行 " + commandLines[0] + "\n 后续命令未执行"); // 解决命名重复的问题
|
|||
|
}
|
|||
|
pName.push_back(name);
|
|||
|
}
|
|||
|
}
|
|||
|
std::vector<std::string> line_1 = StringHelper::GetWords(commandLines[1]);
|
|||
|
if (line_1[0] == "LOC")
|
|||
|
{
|
|||
|
// 参数行 LOC
|
|||
|
std::vector<std::string> lineLoc = StringHelper::GetWords(commandLines[1]);
|
|||
|
if (StringHelper::toUpper(lineLoc[0]) != "LOC")
|
|||
|
{
|
|||
|
commandLines.erase(commandLines.begin());
|
|||
|
throw std::runtime_error("命令格式错误,缺少LOC关键字行");
|
|||
|
}
|
|||
|
// 生成真实名称
|
|||
|
if (lineName.size() < lineLoc.size())
|
|||
|
{
|
|||
|
// 补足不够的名称
|
|||
|
int baseNum = 1;
|
|||
|
for (int ip = lineName.size(); ip < lineLoc.size(); ip++)
|
|||
|
{
|
|||
|
name = ParseNameByPre(lastName, baseNum);
|
|||
|
pName.push_back(name);
|
|||
|
baseNum++;
|
|||
|
}
|
|||
|
}
|
|||
|
commandLines.erase(commandLines.begin());
|
|||
|
// 生成真实坐标点
|
|||
|
|
|||
|
for (int ip = 1; ip < lineLoc.size(); ip++)
|
|||
|
{
|
|||
|
// 20161108 by czb,在ParsePointLoc函数中,tp的name等属性会发生变化
|
|||
|
if (ParsePointLoc(point, lineLoc[ip], true) == false)
|
|||
|
{
|
|||
|
throw std::runtime_error("ParsePointLoc fail");
|
|||
|
}
|
|||
|
point.m_Name = QString::fromStdString(pName[ip - 1]);
|
|||
|
pLoc.push_back(point);
|
|||
|
}
|
|||
|
|
|||
|
commandLines.erase(commandLines.begin());
|
|||
|
|
|||
|
nameStr = "POINT";
|
|||
|
std::string locStr = "LOC";
|
|||
|
for (int ip = 0; ip < pName.size(); ip++)
|
|||
|
{
|
|||
|
std::string cmd;
|
|||
|
cmd+=(LINE_SPLITTER + nameStr + " " + pName[ip]);
|
|||
|
cmd+=(LINE_SPLITTER + locStr + " " + lineLoc[ip + 1]);
|
|||
|
pLoc[ip].m_Command = QString::fromStdString(cmd);
|
|||
|
Add2ModelOrInteractWithIdtf(&pLoc[ip]);
|
|||
|
cmdTmp += cmd;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else if (line_1[0] == "X" || line_1[0] == "Y" || line_1[0] == "Z")
|
|||
|
{
|
|||
|
commandLines.erase(commandLines.begin());
|
|||
|
// 参数行 X Y Z
|
|||
|
std::vector<std::string> lineP = StringHelper::GetWords(commandLines[0]);
|
|||
|
if (lineP.size() != 2)
|
|||
|
{
|
|||
|
throw std::runtime_error("命令格式错误");
|
|||
|
}
|
|||
|
std::vector<std::string> lineLoc = StringHelper::GetWords(commandLines[1]);
|
|||
|
double xPos = 0, yPos = 0, zPos = 0;
|
|||
|
|
|||
|
if (StringHelper::toUpper(lineP[0]) == "X")
|
|||
|
{
|
|||
|
xPos = GetX(lineP[1]);
|
|||
|
commandLines.erase(commandLines.begin());
|
|||
|
if (StringHelper::toUpper(lineLoc[0]) != "YZ")
|
|||
|
{
|
|||
|
throw std::runtime_error("命令格式错误,缺少YZ关键字行");
|
|||
|
}
|
|||
|
}
|
|||
|
else if (StringHelper::toUpper(lineP[0]) == "Y")
|
|||
|
{
|
|||
|
yPos = std::stod(lineP[1]);
|
|||
|
commandLines.erase(commandLines.begin());
|
|||
|
if (StringHelper::toUpper(lineLoc[0]) != "XZ")
|
|||
|
{
|
|||
|
throw std::runtime_error("命令格式错误,缺少XZ关键字行");
|
|||
|
}
|
|||
|
}
|
|||
|
else if (StringHelper::toUpper(lineP[0]) == "Z")
|
|||
|
{
|
|||
|
zPos = std::stod(lineP[1]);
|
|||
|
commandLines.erase(commandLines.begin());
|
|||
|
if (StringHelper::toUpper(lineLoc[0]) != "XY")
|
|||
|
{
|
|||
|
commandLines.erase(commandLines.begin());
|
|||
|
throw std::runtime_error("命令格式错误,缺少XY关键字行");
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
throw std::runtime_error("命令格式错误,缺少X/Y/Z关键字行");
|
|||
|
}
|
|||
|
|
|||
|
// 生成真实名称
|
|||
|
if (lineName.size() < lineLoc.size())
|
|||
|
{
|
|||
|
// 补足不够的名称
|
|||
|
int baseNum = 1;
|
|||
|
for (int ip = lineName.size(); ip < lineLoc.size(); ip++)
|
|||
|
{
|
|||
|
name = ParseNameByPre(lastName, baseNum);
|
|||
|
pName.push_back(name);
|
|||
|
baseNum++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 生成真实坐标点
|
|||
|
for (int ip = 1; ip < lineLoc.size(); ip++)
|
|||
|
{
|
|||
|
double v1 = 0, v2 = 0;
|
|||
|
if (ParsePoint2D(lineLoc[ip], lineP[0], v1, v2) == false)
|
|||
|
{
|
|||
|
throw std::runtime_error("ParsePoint2D fail");
|
|||
|
}
|
|||
|
if (StringHelper::toUpper(lineP[0]) == "X")
|
|||
|
{
|
|||
|
point.m_X = xPos;
|
|||
|
point.m_Y = v1;
|
|||
|
point.m_Z = v2;
|
|||
|
point.m_ProjDir = 1;
|
|||
|
}
|
|||
|
else if (StringHelper::toUpper(lineP[0]) == "Y")
|
|||
|
{
|
|||
|
point.m_X = v1;
|
|||
|
point.m_Y = yPos;
|
|||
|
point.m_Z = v2;
|
|||
|
point.m_ProjDir = 2;
|
|||
|
}
|
|||
|
else if (StringHelper::toUpper(lineP[0]) == "Z")
|
|||
|
{
|
|||
|
point.m_X = v1;
|
|||
|
point.m_Y = v2;
|
|||
|
point.m_Z = zPos;
|
|||
|
point.m_ProjDir = 3;
|
|||
|
}
|
|||
|
point.m_Name = QString::fromStdString(pName[ip - 1]);
|
|||
|
pLoc.push_back(point);
|
|||
|
}
|
|||
|
commandLines.erase(commandLines.begin());
|
|||
|
nameStr = "POINT";
|
|||
|
std::string locStr = StringHelper::toUpper(lineLoc[0]);
|
|||
|
for (int ip = 0; ip < pName.size(); ip++)
|
|||
|
{
|
|||
|
std::string cmd;
|
|||
|
cmd+=(LINE_SPLITTER + nameStr + " " + pName[ip]);
|
|||
|
cmd+=(LINE_SPLITTER + StringHelper::toUpper(lineP[0]) + " " + lineP[1]);
|
|||
|
cmd+=(LINE_SPLITTER + locStr + " " + lineLoc[ip + 1]); // cqr-20180420-3 双引号中间少了一个空格,导致命令解析出错
|
|||
|
Add2ModelOrInteractWithIdtf(&pLoc[ip]);
|
|||
|
point.m_Command = QString::fromStdString(cmd);
|
|||
|
cmdTmp += cmd;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
throw std::runtime_error("命令格式错误,缺少X/Y/Z关键字行");
|
|||
|
}
|
|||
|
|
|||
|
cmd.clear();
|
|||
|
cmd.append(cmdTmp);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
bool PointInterpreter::ParsePoint2D(const std::string &loc, const std::string &dir, double &v1, double &v2)
|
|||
|
{
|
|||
|
if (StringHelper::startsWith(loc,"(") && StringHelper::endsWith(loc,")"))
|
|||
|
{
|
|||
|
// 坐标形式
|
|||
|
std::string temp = loc.substr(1, loc.length() - 2);
|
|||
|
std::vector<std::string> cds = StringHelper::split(temp, std::vector<std::string>{SPACE});
|
|||
|
if (cds.size() != 2)
|
|||
|
{
|
|||
|
throw std::runtime_error("坐标有误!");
|
|||
|
}
|
|||
|
std::string cd1 = cds[0];
|
|||
|
std::string cd2 = cds[1];
|
|||
|
if (dir == "X")
|
|||
|
{
|
|||
|
v1 = std::stod(cd1);
|
|||
|
v2 = std::stod(cd2);
|
|||
|
}
|
|||
|
else if (dir == "Y")
|
|||
|
{
|
|||
|
v1 = GetX(cd1);
|
|||
|
v2 = std::stod(cd2);
|
|||
|
}
|
|||
|
else if (dir == "Z")
|
|||
|
{
|
|||
|
v1 = GetX(cd1);
|
|||
|
v2 = std::stod(cd2);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
|