COMPASSi/trunk/code/projects/DataManager/Logic/Logic.DataManagement/Interpreters/HullObjInterpreter.cpp

1553 lines
62 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "HullObjInterpreter.h"
#include "CurveInterpreter.h"
#include "Constants.h"
#include "DataManager.h"
#include <algorithm>
#include <stdexcept>
#include <cmath> // For mathematical operations like std::abs and std::sqrt
#include <limits> // For std::numeric_limits
#include <regex>
#include "DataManagerGlobal.h"
#include "Common/tangible_string_helper.h"
#include "PathUtil.h"
HullObjectInterpreter::HullObjectInterpreter()
{
}
void HullObjectInterpreter::ExecuteCommand(std::vector<std::string> &commandLines, IModel &o,DataManager* pdata)
{
std::string firstWord = StringHelper::toUpper(StringHelper::FirstWord(commandLines[0]));
// if (firstWord == "MDECKSURF")
// {
// // o = new MainDeckSurf();
// }
// else if (firstWord == "SHELLSURF")
// {
// // o = new ShellSurf();
// }
// else if (firstWord == "HULL")
// {
// Hull_M* pHull = dynamic_cast<Hull_M*>(&o);
// }
// else if (firstWord == "DECKSURF")
// {
// // o = new DeckSurf();
// }
// else if (firstWord == "BOUNDSURF")
// {
// // o = new BoundSurf();
// }
// else if (firstWord == "SUBDIVSURF")
// {
// // o = new SubdivSurf();
// }
// else if (firstWord == "OPENCARGOREGION")
// {
// // o = new OpenCargoRegion();
// }
// else if (firstWord == "SPACE")
// {
// // o = new Space();
// // Space *sp = dynamic_cast<Space *>(o);
// // if (sp)
// // {
// // sp->isUnit = false;
// // }
// }
// else if (firstWord == "SPACEUNIT")
// {
// // o = new Space();
// // Space *sp_Unit = dynamic_cast<Space *>(o);
// // if (sp_Unit)
// // {
// // sp_Unit->isUnit = true;
// // }
// }
// else if (firstWord == "APPENDAGE")
// {
// // o = new Appendage();
// }
// else
// {
// // 默认情况
// }
// 名称行
std::string name;
std::string cmdName = commandLines[0];
if (!ParseName(o, name, cmdName))
{
throw std::runtime_error("命令执行失败\n Error: 重复命名,不能覆盖原名称对象.\n 位置:行 " + commandLines[0] + "\n 后续命令未执行"); // 解决命名重复的问题
}
LineDone(commandLines);
if (commandLines.empty())
{
throw std::runtime_error("MissingParameterException: Missing parameters.");
}
std::vector<std::string> linePara1st = StringHelper::GetWords(commandLines[0]);
// if ((o is MainDeckSurf || o is ShellSurf || o is DeckSurf || o is BoundSurf || o is SubdivSurf || o is OpenCargoRegion /* || o is Hull*/) && linePara1st[0].ToUpper() == "THR")
// {
// if (linePara1st.size() < 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter count.");
// }
// if (o is OpenCargoRegion && linePara1st.Length > 2)
// {
// throw std::runtime_error("开敞客货区仅可来自一个几何面")
// }
// o.Src = new int[ModelData.ARRAY_SIZE_NORMAL];
// for (int i = 1; i < linePara1st.Length; i++)
// {
// int sid = Global.RootWorkItem.Services.Get<IDataManager>().GetObjectIDByName<Surface>(linePara1st[i]);
// if (sid == -1)
// {
// throw std::runtime_error("InputObjectTypeErrorException: Invalid object type.");
// }
// o.Src[i - 1] = sid;
// }
// LineDone(commandLines);
// o.Name = name;
// Add2ModelOrInteractWithIdtf(o);
// }
//else
if (firstWord == "HULL")
{
Hull_M* pHull = dynamic_cast<Hull_M*>(&o);
if (linePara1st.size() < 2)
throw std::runtime_error("ErrorParameterException: Invalid parameter count.");
string cmd = StringHelper::toUpper(linePara1st[0]);
if (cmd == "THR")
{
pHull->m_Type = 1;
} // 20170801 修改关键字 by czb面围拢
else if (cmd == "BOOL")
{
pHull->m_Type = 2;
} // 20170801 新增 by czb体组合原为“THR”
else
{
throw std::runtime_error("ErrorParameterException: Invalid parameter.");
}
pHull->m_Src.resize(ModelData::ARRAY_SIZE_NORMAL);
// 面围拢
if (pHull->m_Type == 1)
{
for (int i = 1; i < linePara1st.size(); i++)
{
int sid = -1;
string sname = StringHelper::toUpper(linePara1st[i]);
sid = DataManager::GetObjectIDByName(sname);
if (sid == -1)
throw std::runtime_error("InputObjectTypeErrorException: Invalid object type.");
pHull->m_Src[i - 1] = sid;
}
}
// 体组合
else if (pHull->m_Type == 2)
{
pHull->m_SolidAddMode.resize(ModelData::ARRAY_SIZE_NORMAL);
for (int i = 1; i < linePara1st.size(); i++)
{
int sid = -1;
string sname = StringHelper::toUpper(linePara1st[i]);
int stype = ParseBoolSymbolFromName(sname);
// 20170801 修改 by czb
sid = DataManager::GetObjectIDByName(sname);
if (sid == -1)
throw std::runtime_error("InputObjectTypeErrorException: Invalid object type.");
pHull->m_Src[i - 1] = sid;
pHull->m_SolidAddMode[i - 1] = stype;
}
}
LineDone(commandLines);
pHull->m_Name = QString::fromStdString(name);
Add2ModelOrInteractWithIdtf(pHull);
}
// else if (o is DeckSurf)
// {
// // 平台面
// DeckSurf m = new DeckSurf();
// m.Name = name;
// m.GenType = 1;
// // 参数行-Z
// if (linePara1st[0].ToUpper() != "Z" || linePara1st.Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// m.Z = double.Parse(linePara1st[1]);
// LineDone(commandLines);
// // 参数行-X
// if (commandLines.Count == 0)
// {
// throw std::runtime_error("MissingParameterException: Missing parameters.");
// }
// string[] lineParaX = commandLines[0].GetWords(Constants.SquareBrackets);
// if (lineParaX[0].ToUpper() != "X" || lineParaX.Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// string x = lineParaX[1].Replace(Constants.SquareBrackets[0], "").Replace(Constants.SquareBrackets[1], "");
// if (x.GetWords().Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// m.X1 = GetX(x.GetWords()[0]);
// m.X2 = GetX(x.GetWords()[1]);
// LineDone(commandLines);
// // 参数行-Y
// if (commandLines.Count == 0)
// {
// throw std::runtime_error("MissingParameterException: Missing parameters.");
// }
// string[] lineParaY = commandLines[0].GetWords(Constants.SquareBrackets);
// if (lineParaY[0].ToUpper() != "Y" || lineParaY.Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// string y = lineParaY[1].Replace(Constants.SquareBrackets[0], "").Replace(Constants.SquareBrackets[1], "");
// if (y.GetWords().Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// m.Y1 = double.Parse(y.GetWords()[0]);
// m.Y2 = double.Parse(y.GetWords()[1]);
// LineDone(commandLines);
// Add2ModelOrInteractWithIdtf(m);
// }
// else if (o is BoundSurf)
// {
// // 上建外围面
// BoundSurf m = new BoundSurf();
// m.Name = name;
// m.GenType = 1;
// // 参数行-X或Y
// if (linePara1st[0].ToUpper() == "X")
// {
// if (linePara1st.Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// m.Dir = 0;
// m.X1 = GetX(linePara1st[1]);
// LineDone(commandLines);
// // 参数行-Y
// if (commandLines.Count == 0)
// {
// throw std::runtime_error("MissingParameterException: Missing parameters.");
// }
// string[] lineParaXY = commandLines[0].GetWords(Constants.SquareBrackets);
// if (lineParaXY[0].ToUpper() != "Y" || lineParaXY.Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// string xyz = lineParaXY[1].Replace(Constants.SquareBrackets[0], "").Replace(Constants.SquareBrackets[1], "");
// if (xyz.GetWords().Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// m.Y1 = double.Parse(xyz.GetWords()[0]);
// m.Y2 = double.Parse(xyz.GetWords()[1]);
// LineDone(commandLines);
// }
// else if (linePara1st[0].ToUpper() == "Y")
// {
// if (linePara1st.Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// m.Dir = 1;
// m.Y1 = double.Parse(linePara1st[1]);
// LineDone(commandLines);
// // 参数行-X
// if (commandLines.Count == 0)
// {
// throw std::runtime_error("MissingParameterException: Missing parameters.");
// }
// string[] lineParaYX = commandLines[0].GetWords(Constants.SquareBrackets);
// if (lineParaYX[0].ToUpper() != "X" || lineParaYX.Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// string xyz = lineParaYX[1].Replace(Constants.SquareBrackets[0], "").Replace(Constants.SquareBrackets[1], "");
// if (xyz.GetWords().Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// m.X1 = GetX(xyz.GetWords()[0]);
// m.X2 = GetX(xyz.GetWords()[1]);
// LineDone(commandLines);
// }
// else
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// // 参数行-Z
// if (commandLines.Count == 0)
// {
// throw std::runtime_error("MissingParameterException: Missing parameters.");
// }
// string[] lineParaZ = commandLines[0].GetWords(Constants.SquareBrackets);
// if (lineParaZ[0].ToUpper() != "Z" || lineParaZ.Length != 2)
// {
// throw new ErrorParameterException();
// }
// string z = lineParaZ[1].Replace(Constants.SquareBrackets[0], "").Replace(Constants.SquareBrackets[1], "");
// if (z.GetWords().Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// m.Z1 = double.Parse(z.GetWords()[0]);
// m.Z2 = double.Parse(z.GetWords()[1]);
// LineDone(commandLines);
// Add2ModelOrInteractWithIdtf(m);
// }
// else if (o is SubdivSurf)
// {
// // 分舱面
// SubdivSurf m = new SubdivSurf();
// m.Name = name;
// m.GenType = 1;
// // 参数行-X或Y
// if (linePara1st[0].ToUpper() == "X")
// {
// if (linePara1st.Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// m.Dir = 0;
// m.XY = GetX(linePara1st[1]);
// LineDone(commandLines);
// }
// else if (linePara1st[0].ToUpper() == "Y")
// {
// if (linePara1st.Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// m.Dir = 1;
// m.XY = double.Parse(linePara1st[1]);
// LineDone(commandLines);
// }
// else
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// // 参数行-Y/X
// if (commandLines.Count == 0)
// {
// throw std::runtime_error("MissingParameterException: Missing parameters.");
// }
// string[] lineParaLMTXY = commandLines[0].GetWords(Constants.SquareBrackets);
// if (m.Dir == 0 && lineParaLMTXY[0].ToUpper() == "Y" || m.Dir == 1 && lineParaLMTXY[0].ToUpper() == "X")
// {
// }
// else
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// if (lineParaLMTXY.Length == 2 && lineParaLMTXY[1].Contains(Constants.SquareBrackets[0]) || lineParaLMTXY.Length == 3)
// {
// }
// else
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// if (lineParaLMTXY.Length == 2)
// {
// string[] cord = lineParaLMTXY[1].Replace(Constants.SquareBrackets[0], "").Replace(Constants.SquareBrackets[1], "").GetWords();
// if (cord.Length != 2)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// if (m.Dir == 0)
// {
// m.Y1 = double.Parse(cord[0]);
// m.Y2 = double.Parse(cord[1]);
// }
// else
// {
// m.X1 = double.Parse(cord[0]);
// m.X2 = double.Parse(cord[1]);
// }
// m.BndType = 0;
// }
// else if (lineParaLMTXY.Length == 3)
// {
// int id1 = GetHullSurf(lineParaLMTXY[1]);
// int id2 = GetHullSurf(lineParaLMTXY[2]);
// if (m.Dir == 0)
// {
// m.RefY1 = id1;
// m.RefY2 = id2;
// }
// else
// {
// m.RefX1 = id1;
// m.RefX2 = id2;
// }
// m.BndType = 1;
// }
// LineDone(commandLines);
// // 参数行-Z
// if (commandLines.Count == 0)
// {
// throw std::runtime_error("MissingParameterException: Missing parameters.");
// }
// string[] lineParaLMTZ = commandLines[0].GetWords(Constants.SquareBrackets);
// if (lineParaLMTZ[0].ToUpper() != "Z")
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// if (lineParaLMTZ.Length == 2 && lineParaLMTZ[1].Contains(Constants.SquareBrackets[0]) && m.BndType == 0 || lineParaLMTZ.Length == 3 && m.BndType == 1)
// {
// }
// else
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// if (lineParaLMTZ.Length == 2)
// {
// string[] cord = lineParaLMTZ[1].Replace(Constants.SquareBrackets[0], "").Replace(Constants.SquareBrackets[1], "").GetWords();
// if (cord.Length != 2)
// {
// throw new ErrorParameterException();
// }
// m.Z1 = double.Parse(cord[0]);
// m.Z2 = double.Parse(cord[1]);
// }
// else if (lineParaLMTZ.Length == 3)
// {
// int id1 = GetHullSurf(lineParaLMTZ[1]);
// int id2 = GetHullSurf(lineParaLMTZ[2]);
// m.RefZ1 = id1;
// m.RefZ2 = id2;
// }
// LineDone(commandLines);
// //// 参数行-LMT
// // if (commandLines.Count == 0)
// //{
// // throw new MissingParameterException();
// // }
// // string[] lineParaLMT = commandLines[0].GetWords();
// // if (lineParaLMT[0].ToUpper() != "LMT")
// //{
// // throw new ErrorParameterException();
// // }
// // m.Src = new int[ModelData.ARRAY_SIZE_NORMAL];
// // if (lineParaLMT.Length > 1)
// //{
// // for (int i = 1; i < lineParaLMT.Length; i++)
// // {
// // if (lineParaLMT[i].ToUpper() == "MDECKSURF" || lineParaLMT[i].ToUpper() == "SHELLSURF")
// // {
// // continue;
// // }
// // int sid = Global.RootWorkItem.Services.Get<IDataManager>().GetObjectIDByName<DeckSurf>(lineParaLMT[i]);
// // if (sid == -1)
// // {
// // sid = Global.RootWorkItem.Services.Get<IDataManager>().GetObjectIDByName<BoundSurf>(lineParaLMT[i]);
// // if (sid == -1)
// // {
// // sid = Global.RootWorkItem.Services.Get<IDataManager>().GetObjectIDByName<SubdivSurf>(lineParaLMT[i]);
// // if (sid == -1)
// // {
// // throw new ObjectNotFoundException(lineParaLMT[i]);
// // }
// // }
// // }
// // m.Src[i - 1] = sid;
// // }
// // }
// // LineDone(commandLines);
// // 参数行-CORR
// if (commandLines.Count != 0)
// {
// string[] linecorr = commandLines[0].GetWords();
// if (linecorr[0].ToUpper() == "CORR")
// {
// if (linecorr.Length != 6)
// {
// throw std::runtime_error("ErrorParameterException: Invalid parameter.");
// }
// m.Corrugated = 1;
// m.CorDir = int.Parse(linecorr[1]);
// m.S = double.Parse(linecorr[2]);
// m.A = double.Parse(linecorr[3]);
// m.D = double.Parse(linecorr[4]);
// m.F = double.Parse(linecorr[5]);
// LineDone(commandLines);
// }
// }
// Add2ModelOrInteractWithIdtf(m);
// }
else if (firstWord == "SPACEUNIT" || firstWord == "SPACE")
{
Space_M* pSpace = dynamic_cast<Space_M*>(&o);
pSpace->m_Name = QString::fromStdString(name);
if(firstWord == "SPACEUNIT")
{
pSpace->m_IsUnit = true;
}
else
{
pSpace->m_IsUnit = false;
}
std::vector<std::string> linePara = StringHelper::GetWords(commandLines[0]);
if (linePara.size() < 2)
{
throw std::runtime_error("ErrorParameterException: Invalid parameter.");
}
// int XFlag = 0; //用于标记是否为独立单元体如果是则X位置可以允许输入1个值
// int LPointsFlag = 0;//用于标记是否为独立单元体,如果是,则可以允许输入空值
// 参数行-THR
string cmd = StringHelper::toUpper(linePara[0]);
if (cmd == "X")
{
pSpace->m_GenType = 1;
pSpace->m_Type = 0;
}
else if (cmd == "BOOL")
{
pSpace->m_GenType = 0;
pSpace->m_Type = 1;
} // 20170801 修改关键字 by czb体组合原为“THR”
else if (cmd == "THR")
{
pSpace->m_GenType = 2;
pSpace->m_Type = 2;
} // 20170801 新增 by czb面围拢
else
{
throw std::runtime_error("ErrorParameterException: Invalid parameter.");
}
if (pSpace->m_Type == 1) // 体组合
{
int cnt = 0;
pSpace->m_Src.resize(ModelData::ARRAY_SIZE_NORMAL);
pSpace->m_SolidAddMode.resize(ModelData::ARRAY_SIZE_NORMAL);
for (int i = 1; i < linePara.size(); i++)
{
string solidname = linePara[i];
int solidandtype = ParseBoolSymbolFromName(solidname);
// 20170801 修改 by czb
int sid = DataManager::GetObjectIDByName(solidname);
if (sid == -1)
throw std::runtime_error("InputObjectTypeErrorException: Invalid object type.");
pSpace->m_Src[cnt + i - 1] = sid;
pSpace->m_SolidAddMode[cnt + i - 1] = solidandtype;
}
LineDone(commandLines);
}
else if (pSpace->m_Type == 2) // 面围拢20170801 新增 by czb
{
pSpace->m_Src.resize(ModelData::ARRAY_SIZE_NORMAL);
pSpace->m_SolidAddMode.resize(ModelData::ARRAY_SIZE_NORMAL);
for (int i = 1; i < linePara.size(); i++)
{
int sid = -1;
string sname = StringHelper::toUpper(linePara[i]);
sid = DataManager::GetObjectIDByName(sname);
if (sid == -1)
throw std::runtime_error("InputObjectTypeErrorException: Invalid object type.");
pSpace->m_Src[i - 1] = sid;
}
LineDone(commandLines);
}
// else // if (linePara[0].ToUpper() == "X") // XUEFENG DELETE 202012
else if (linePara.size() <= 3) // XUEFENG ADDED 202012
{
pSpace->m_Src.resize(ModelData::ARRAY_SIZE_NORMAL);
pSpace->m_SolidAddMode.resize(ModelData::ARRAY_SIZE_NORMAL);
pSpace->LCharacterPoints.resize(ModelData::ARRAY_SIZE_NORMAL);
pSpace->FCharacterPoints.resize(ModelData::ARRAY_SIZE_NORMAL);
// 考虑输入肋位号的情况
// X向范围x1x2可以是x+或x-,表示船首和船尾
if (StringHelper::toUpper(linePara[0]) == "X-")
{
pSpace->m_X1 = -500;
}
else if ( StringHelper::toUpper(linePara[1]) == "X+")
throw std::runtime_error("X 后端位置有误");
else
pSpace->m_X1 = GetX(linePara[1]);
if (linePara.size() > 2)
{
if (StringHelper::toUpper(linePara[2]) == "X+")
{
pSpace->m_X2 = 500;
}
else if ( StringHelper::toUpper(linePara[2]) == "X-")
throw std::runtime_error("X前端位置有误");
else
pSpace->m_X2 = GetX(linePara[2]);
if ((pSpace->m_X1 > pSpace->m_X2) || (pSpace->m_X1 == pSpace->m_X2))
throw std::runtime_error("X范围有误前端位置不能大于等于后端位置");
}
else
throw std::runtime_error("X位置必须输入前后端位置");
// XFlag = 1; //标记X位置只有一个值
LineDone(commandLines);
// 可输入0个特征点对于01个特征点进行转换传给舱室生成模块
//
if (commandLines.size() > 0)
{
linePara = StringHelper::GetWords(commandLines[0]);
if (StringHelper::toUpper(linePara[0]) == "FPOINTS")
{
int LCount = 0, FCount = 0;
double dSpec;
for (int i = 1; i < linePara.size(); i++)
{
// 判断括号
if (linePara[i].find("(") == std::string::npos)
{
throw std::runtime_error("特征点缺少括号()");
}
std::vector<std::string> s = StringHelper::GetWords(
StringHelper::replace(StringHelper::replace(linePara[i], "(", ""), ")", ""));
for (int k =0 ; k < s.size(); k++)
{
dSpec = convertSpecToDigital(s[k]);
if (dSpec < -1000)
throw std::runtime_error("特征点坐标为非数字。");
else
{
pSpace->LCharacterPoints[2 * (i - 1) + k] = dSpec;
LCount++;
}
}
}
pSpace->LCharacterPoints[LCount] = 1000;
LineDone(commandLines);
if (!commandLines.empty())
{
linePara = StringHelper::GetWords(commandLines[0]);
} // else throw new ErrorSyntaxException("缺少尾特征点定义。");
if (StringHelper::toUpper(linePara[0]) == "APOINTS")
{
if (linePara.size() > 1)
{
for (size_t i = 1; i < linePara.size(); i++)
{
// 判断括号
if (linePara[i].find("(") == std::string::npos)
{
throw std::runtime_error("特征点缺少括号()");
}
std::vector<std::string> s = StringHelper::GetWords(
StringHelper::replace(StringHelper::replace(linePara[i], "(", ""), ")", ""));
for (int k =0 ; k < s.size(); k++)
{
dSpec = convertSpecToDigital(s[k]);
if (dSpec < -1000)
throw std::runtime_error("特征点坐标为非数字。");
else
{
pSpace->FCharacterPoints[2 * (i - 1) + k] = dSpec;
FCount++;
}
}
}
pSpace->FCharacterPoints[FCount] = 1000;
LineDone(commandLines);
}
else
{
// 如果没有首特征点,则把尾特征点的定义复制到首特征点
FCount = LCount;
for (int j = 0; j <= LCount; j++)
{
pSpace->FCharacterPoints[j] = pSpace->LCharacterPoints[j];
}
LineDone(commandLines);
}
}
else
{
// throw new ErrorSyntaxException("特征点定义必须成对出现缺少APOINTS定义。");
// 如果没有首特征点,则把尾特征点的定义复制到首特征点
FCount = LCount;
for (int j = 0; j <= LCount; j++)
{
pSpace->FCharacterPoints[j] = pSpace->LCharacterPoints[j];
}
}
if (FCount == 0 && LCount != 0)
{
FCount = LCount;
for (int j = 0; j <= LCount; j++)
{
pSpace->FCharacterPoints[j] = pSpace->LCharacterPoints[j];
}
}
if (FCount != 0 && LCount == 0)
{
LCount = FCount;
for (int j = 0; j <= LCount; j++)
{
pSpace->LCharacterPoints[j] = pSpace->FCharacterPoints[j];
}
}
// 对特征点的个数,对应情况进行判断
if (FCount != LCount)
throw std::runtime_error("特征点个数不一致。");
else
{
if (FCount == 0) // 0个特征点
{
pSpace->LCharacterPoints[0] = pSpace->FCharacterPoints[0] = convertSpecToDigital("y-");
pSpace->LCharacterPoints[1] = pSpace->FCharacterPoints[1] = convertSpecToDigital("z+");
pSpace->LCharacterPoints[2] = pSpace->FCharacterPoints[2] = convertSpecToDigital("y+");
pSpace->LCharacterPoints[3] = pSpace->FCharacterPoints[3] = convertSpecToDigital("z-");
pSpace->FCharacterPoints[4] = pSpace->LCharacterPoints[4] = 1000;
FCount = LCount = 4;
}
else if (FCount / 2 == 1) // 1个特征点,经武汉陈博士提出修改 15/10/14
{
if ((pSpace->LCharacterPoints[0] == 777) || (pSpace->LCharacterPoints[0] == -777))
{
pSpace->LCharacterPoints[2] = pSpace->LCharacterPoints[1];
pSpace->FCharacterPoints[2] = pSpace->FCharacterPoints[1];
pSpace->LCharacterPoints[1] = pSpace->FCharacterPoints[1] = convertSpecToDigital("z+");
pSpace->LCharacterPoints[3] = pSpace->FCharacterPoints[3] = convertSpecToDigital("z-");
}
else if ((pSpace->LCharacterPoints[0] == 888) || (pSpace->LCharacterPoints[0] == -888))
{
pSpace->LCharacterPoints[3] = pSpace->LCharacterPoints[1];
pSpace->FCharacterPoints[3] = pSpace->FCharacterPoints[1];
pSpace->LCharacterPoints[1] = pSpace->LCharacterPoints[0];
pSpace->FCharacterPoints[1] = pSpace->FCharacterPoints[0];
pSpace->LCharacterPoints[0] = pSpace->FCharacterPoints[0] = convertSpecToDigital("y+");
pSpace->LCharacterPoints[2] = pSpace->FCharacterPoints[2] = convertSpecToDigital("y-");
}
else
{
throw std::runtime_error("一个特征点时输入格式有误。");
}
pSpace->FCharacterPoints[4] = pSpace->LCharacterPoints[4] = 1000;
}
for (int i = 0; i < FCount * 2; i++)
{
bool l = pSpace->LCharacterPoints[i] == 777 || pSpace->LCharacterPoints[i] == -777 || pSpace->LCharacterPoints[i] == 888 || pSpace->LCharacterPoints[i] == -888 || pSpace->LCharacterPoints[i] == 999 || pSpace->LCharacterPoints[i] == -999;
bool f = pSpace->FCharacterPoints[i] == 777 || pSpace->FCharacterPoints[i] == -777 || pSpace->FCharacterPoints[i] == 888 || pSpace->FCharacterPoints[i] == -888 || pSpace->FCharacterPoints[i] == 999 || pSpace->FCharacterPoints[i] == -999;
if (!l && !f)
{
continue;
}
if (pSpace->LCharacterPoints[i] != pSpace->FCharacterPoints[i])
{
throw std::runtime_error("首尾特征点不一一对应。");
}
// if (!(((pSpace->LCharacterPoints[i] == 777) && (pSpace->FCharacterPoints[i] == 777))
// || ((pSpace->LCharacterPoints[i] == -777) && (pSpace->FCharacterPoints[i] == -777))
// || ((pSpace->LCharacterPoints[i] == 888) && (pSpace->FCharacterPoints[i] == 888))
// || ((pSpace->LCharacterPoints[i] == -888) && (pSpace->FCharacterPoints[i] == -888))
// || ((pSpace->LCharacterPoints[i] == 999) && (pSpace->FCharacterPoints[i] == 999))
// || ((pSpace->LCharacterPoints[i] == -999) && (pSpace->FCharacterPoints[i] == -999))))
// throw new ErrorSyntaxException("首尾特征点不一一对应。");
}
}
}
else if ((StringHelper::toUpper(linePara[0]) == "APOINTS"))
{
int FCount = 0, LCount = 0;
double dSpec;
// XUEFENG ADDED 20211007
// XUEFENG MODIFIED 20211020
if (linePara.size() <= 2)
{
std::vector<std::string> s = StringHelper::GetWords(
StringHelper::replace(StringHelper::replace(linePara[1], "(", ""), ")", ""));
if (StringHelper::toUpper(s[0]) != "Y+" && StringHelper::toUpper(s[0]) != "Y-" &&
StringHelper::toUpper(s[0]) != "Z+" && StringHelper::toUpper(s[0]) != "Z-")
{
throw std::runtime_error("一个特征点应以“Y或Z”开头");
}
}
// END MODIFIED
// END ADDED
for (size_t i = 1; i < linePara.size(); i++)
{
// 判断括号
if (linePara[i].find("(") == std::string::npos)
{
throw std::runtime_error("特征点缺少括号()");
}
std::vector<std::string> s = StringHelper::GetWords(
StringHelper::replace(StringHelper::replace(linePara[i], "(", ""), ")", ""));
for (int k =0 ; k < s.size(); k++)
{
dSpec = convertSpecToDigital(s[k]);
if (dSpec < -1000)
throw std::runtime_error("特征点坐标为非数字。");
else
{
pSpace->FCharacterPoints[2 * (i - 1) + k] = dSpec;
FCount++;
}
}
}
pSpace->FCharacterPoints[FCount] = 1000;
LineDone(commandLines);
if (commandLines.size() > 0)
{
linePara = StringHelper::GetWords(commandLines[0]);
} // else throw new ErrorSyntaxException("缺少尾特征点定义。");
if (StringHelper::toUpper(linePara[0]) == "FPOINTS")
{
if (linePara.size() > 1)
{
for (size_t i = 1; i < linePara.size(); i++)
{
// 判断括号
if (linePara[i].find("(") == std::string::npos)
{
throw std::runtime_error("特征点缺少括号()");
}
std::vector<std::string> s = StringHelper::GetWords(
StringHelper::replace(StringHelper::replace(linePara[i], "(", ""), ")", ""));
for (int k =0 ; k < s.size(); k++)
{
dSpec = convertSpecToDigital(s[k]);
if (dSpec < -1000)
throw std::runtime_error("特征点坐标为非数字。");
else
{
pSpace->LCharacterPoints[2 * (i - 1) + k] = dSpec;
LCount++;
}
}
}
pSpace->LCharacterPoints[LCount] = 1000;
LineDone(commandLines);
}
else
{
// 如果没有首特征点,则把尾特征点的定义复制到首特征点
LCount = FCount;
for (int j = 0; j <= FCount; j++)
{
pSpace->LCharacterPoints[j] = pSpace->FCharacterPoints[j];
}
LineDone(commandLines);
}
}
else
{
// throw new ErrorSyntaxException("特征点定义必须成对出现缺少FPOINTS定义。");
// 如果没有首特征点,则把尾特征点的定义复制到首特征点
LCount = FCount;
for (int j = 0; j <= FCount; j++)
{
pSpace->LCharacterPoints[j] = pSpace->FCharacterPoints[j];
}
}
if (LCount == 0 && FCount != 0)
{
LCount = FCount;
for (int j = 0; j <= FCount; j++)
{
pSpace->LCharacterPoints[j] = pSpace->FCharacterPoints[j];
}
}
if (LCount != 0 && FCount == 0)
{
FCount = LCount;
for (int j = 0; j <= FCount; j++)
{
pSpace->FCharacterPoints[j] = pSpace->LCharacterPoints[j];
}
}
// 对特征点的个数,对应情况进行判断
if (LCount != FCount)
throw std::runtime_error("特征点个数不一致。");
else
{
if (LCount == 0) // 0个特征点
{
pSpace->FCharacterPoints[0] = pSpace->LCharacterPoints[0] = convertSpecToDigital("y-");
pSpace->FCharacterPoints[1] = pSpace->LCharacterPoints[1] = convertSpecToDigital("z+");
pSpace->FCharacterPoints[2] = pSpace->LCharacterPoints[2] = convertSpecToDigital("y+");
pSpace->FCharacterPoints[3] = pSpace->LCharacterPoints[3] = convertSpecToDigital("z-");
pSpace->LCharacterPoints[4] = pSpace->FCharacterPoints[4] = 1000;
LCount = FCount = 4;
}
else if (LCount / 2 == 1) // 1个特征点,经武汉陈博士提出修改 15/10/14
{
if ((pSpace->FCharacterPoints[0] == 777) || (pSpace->FCharacterPoints[0] == -777))
{
pSpace->FCharacterPoints[2] = pSpace->FCharacterPoints[1];
pSpace->LCharacterPoints[2] = pSpace->LCharacterPoints[1];
pSpace->FCharacterPoints[1] = pSpace->LCharacterPoints[1] = convertSpecToDigital("z+");
pSpace->FCharacterPoints[3] = pSpace->LCharacterPoints[3] = convertSpecToDigital("z-");
}
else if ((pSpace->FCharacterPoints[0] == 888) || (pSpace->FCharacterPoints[0] == -888))
{
pSpace->FCharacterPoints[3] = pSpace->FCharacterPoints[1];
pSpace->LCharacterPoints[3] = pSpace->LCharacterPoints[1];
pSpace->FCharacterPoints[1] = pSpace->FCharacterPoints[0];
pSpace->LCharacterPoints[1] = pSpace->LCharacterPoints[0];
pSpace->FCharacterPoints[0] = pSpace->LCharacterPoints[0] = convertSpecToDigital("y+");
pSpace->FCharacterPoints[2] = pSpace->LCharacterPoints[2] = convertSpecToDigital("y-");
}
else
{
throw std::runtime_error("一个特征点时输入格式有误。");
}
pSpace->LCharacterPoints[4] = pSpace->FCharacterPoints[4] = 1000;
}
for (int i = 0; i < LCount * 2; i++)
{
bool l = pSpace->FCharacterPoints[i] == 777 || pSpace->FCharacterPoints[i] == -777 || pSpace->FCharacterPoints[i] == 888 || pSpace->FCharacterPoints[i] == -888 || pSpace->FCharacterPoints[i] == 999 || pSpace->FCharacterPoints[i] == -999;
bool f = pSpace->LCharacterPoints[i] == 777 || pSpace->LCharacterPoints[i] == -777 || pSpace->LCharacterPoints[i] == 888 || pSpace->LCharacterPoints[i] == -888 || pSpace->LCharacterPoints[i] == 999 || pSpace->LCharacterPoints[i] == -999;
if (!l && !f)
{
continue;
}
if (pSpace->FCharacterPoints[i] != pSpace->LCharacterPoints[i])
{
throw std::runtime_error("首尾特征点不一一对应。");
}
// if (!(((pSpace->FCharacterPoints[i] == 777) && (pSpace->LCharacterPoints[i] == 777))
// || ((pSpace->FCharacterPoints[i] == -777) && (pSpace->LCharacterPoints[i] == -777))
// || ((pSpace->FCharacterPoints[i] == 888) && (pSpace->LCharacterPoints[i] == 888))
// || ((pSpace->FCharacterPoints[i] == -888) && (pSpace->LCharacterPoints[i] == -888))
// || ((pSpace->FCharacterPoints[i] == 999) && (pSpace->LCharacterPoints[i] == 999))
// || ((pSpace->FCharacterPoints[i] == -999) && (pSpace->LCharacterPoints[i] == -999))))
// throw new ErrorSyntaxException("首尾特征点不一一对应。");
}
}
}
else
{
// 0个特征点
pSpace->LCharacterPoints[0] = pSpace->FCharacterPoints[0] = convertSpecToDigital("y-");
pSpace->LCharacterPoints[1] = pSpace->FCharacterPoints[1] = convertSpecToDigital("z+");
pSpace->LCharacterPoints[2] = pSpace->FCharacterPoints[2] = convertSpecToDigital("y+");
pSpace->LCharacterPoints[3] = pSpace->FCharacterPoints[3] = convertSpecToDigital("z-");
pSpace->FCharacterPoints[4] = pSpace->LCharacterPoints[4] = 1000;
}
}
else
{
// 0个特征点
pSpace->LCharacterPoints[0] = pSpace->FCharacterPoints[0] = convertSpecToDigital("y-");
pSpace->LCharacterPoints[1] = pSpace->FCharacterPoints[1] = convertSpecToDigital("z+");
pSpace->LCharacterPoints[2] = pSpace->FCharacterPoints[2] = convertSpecToDigital("y+");
pSpace->LCharacterPoints[3] = pSpace->FCharacterPoints[3] = convertSpecToDigital("z-");
pSpace->FCharacterPoints[4] = pSpace->LCharacterPoints[4] = 1000;
}
// 判断是否存在特殊点或重复点 by yangchen 20170104
bool flag = false; // 是否存在特殊点
bool bRepeat = false; // 是否有重复特征点
std::vector<Point2D> fPoints;
std::vector<Point2D> lPoints;
int Count = 0; // 特征点个数
while (pSpace->FCharacterPoints[Count] != 1000)
{
if (!bRepeat)
{
Point2D fPt;
Point2D lPt;
fPt.x = pSpace->FCharacterPoints[Count];
fPt.y = pSpace->FCharacterPoints[Count + 1];
lPt.x = pSpace->LCharacterPoints[Count];
lPt.y = pSpace->LCharacterPoints[Count + 1];
auto itF = std::find(fPoints.begin(), fPoints.end(), lPt);
int repeatIndex = (itF != fPoints.end()) ? std::distance(fPoints.begin(), itF) : -1;
if (repeatIndex > -1 && repeatIndex != fPoints.size() - 1) // 20170601 by czb相邻特征点不视为重复点 //(fPoints.Contains(fPt) )
{
bRepeat = true;
}
else
{
fPoints.push_back(fPt);
}
auto itL = std::find(lPoints.begin(), lPoints.end(), lPt);
repeatIndex = (itL != lPoints.end()) ? std::distance(lPoints.begin(), itL) : -1;
if (repeatIndex > -1 && repeatIndex != lPoints.size() - 1) // 20170601 by czb相邻特征点不视为重复点 //(lPoints.Contains(lPt))
{
bRepeat = true;
}
else
{
lPoints.push_back(lPt);
}
}
if (convertDigitalToSpec(pSpace->FCharacterPoints[Count]) != "")
{
flag = true;
}
if (convertDigitalToSpec(pSpace->FCharacterPoints[Count + 1]) != "")
{
flag = true;
}
Count += 2;
}
if (bRepeat)
throw std::runtime_error("端面特征点重复。");
if (Count > 4 && !flag) // 点个数大于2且不包含特殊点
{
pSpace->LCharacterPoints[Count] = pSpace->LCharacterPoints[0];
pSpace->FCharacterPoints[Count] = pSpace->FCharacterPoints[0];
Count++;
pSpace->LCharacterPoints[Count] = pSpace->LCharacterPoints[1];
pSpace->FCharacterPoints[Count] = pSpace->FCharacterPoints[1];
Count++;
pSpace->LCharacterPoints[Count] = 1000;
pSpace->FCharacterPoints[Count] = 1000;
}
string hullName = "";
if (commandLines.size() > 0)
{
linePara = StringHelper::GetWords(commandLines[0]);
if (StringHelper::toUpper(linePara[0]) == "FROM")
{
if (linePara.size() > 2)
{
throw std::runtime_error("不支持多个主船体!");
}
if (linePara.size() == 2)
{
hullName = linePara[1];
}
else
{
hullName = "HULL_1";
}
// XUEFENG ADDED 202012
if (StringHelper::startsWith(hullName,"0"))
{
hullName = hullName;
}
// END ADDED
else if (!StringHelper::startsWith(hullName,"HULL_"))
{
hullName = "HULL_" + hullName;
}
LineDone(commandLines);
}
else // 缺省from
{
hullName = "HULL_1";
}
}
else // 缺省from
{
hullName = "HULL_1";
}
// XUEFENG ADDED 202012
if (hullName == "0")
{
pSpace->m_HullID = -99999;
}
// END ADDED
else
{
if (pdata->getModelData().getHulls().size()==0)
{
throw std::runtime_error("没有主船体,请创建主船体!");
}
int sid = DataManager::GetObjectIDByName(hullName);
if (sid < 0)
{
throw std::runtime_error("不存在主船体" + hullName + "");
}
pSpace->m_HullID = sid;
}
}
// XUEFENG ADDED 202012
// 多端面
else if (linePara.size() > 3)
{
int numSection = linePara.size() - 1;
pSpace->m_NumSections = numSection;
pSpace->m_Src.resize(ModelData::ARRAY_SIZE_NORMAL);
pSpace->m_SolidAddMode.resize(ModelData::ARRAY_SIZE_NORMAL);
pSpace->LCharacterPoints.resize(ModelData::ARRAY_SIZE_NORMAL);
pSpace->FCharacterPoints.resize(ModelData::ARRAY_SIZE_NORMAL);
// pSpace.SectionX = new double[numSection];
// pSpace.ALLCharacterPoints = new double[ModelData.ARRAY_SIZE_NORMAL];
// 考虑输入肋位号的情况
// X向范围x1x2x3 ...... 可以是x+或x-,表示船首和船尾
if ( StringHelper::toUpper(linePara[1]) == "X-")
{
// pSpace.SectionX[0] = -500;
pSpace->LCharacterPoints[0] = -500;
}
else if (StringHelper::toUpper(linePara[1]) =="X+")
throw std::runtime_error("X 后端位置有误");
else
// pSpace.SectionX[0] = GetX(linePara[1]);
pSpace->LCharacterPoints[0] = GetX(linePara[1]);
for (int i = 2; i < linePara.size(); i++)
{
if (StringHelper::toUpper(linePara[i])== "X+")
{
// pSpace.SectionX[i-1] = 500;
pSpace->LCharacterPoints[i - 1] = 500;
}
else if (StringHelper::toUpper(linePara[i]) == "X-")
throw std::runtime_error("X前端位置有误");
else
// pSpace.SectionX[i-1] = GetX(linePara[i]);
pSpace->LCharacterPoints[i - 1] = GetX(linePara[i]);
// if ((pSpace.SectionX[i-2] > pSpace.SectionX[i - 1]) || (pSpace.SectionX[i-1] == pSpace.SectionX[i-2]))
if ((pSpace->LCharacterPoints[i - 2] > pSpace->LCharacterPoints[i - 1]) || (pSpace->LCharacterPoints[i - 1] == pSpace->LCharacterPoints[i - 2]))
throw std::runtime_error("X范围有误前端位置不能大于等于后端位置");
}
LineDone(commandLines);
// 可输入numSection x N个特征点
//
if (commandLines.size() > 0)
{
linePara = StringHelper::GetWords(commandLines[0]);
if (StringHelper::toUpper(linePara[0]) == "ALLPOINTS") /*|| (linePara[0].ToUpper() == "ISCAL")*/
{
int LCount = 0;
double dSpec;
for (int i = 1; i < linePara.size(); i++)
{
// 判断括号
if (linePara[i].find("(") == std::string::npos)
{
throw std::runtime_error("特征点缺少括号()");
}
std::vector<std::string> s = StringHelper::GetWords(
StringHelper::replace(StringHelper::replace(linePara[i], "(", ""), ")", ""));
for (int k = 0; k < s.size(); k++)
{
dSpec = convertSpecToDigital(s[k]);
if (dSpec < -1000)
throw std::runtime_error("特征点坐标为非数字。");
else
{
// pSpace.ALLCharacterPoints[2 * (i - 1) + k] = dSpec;
pSpace->FCharacterPoints[2 * (i - 1) + k] = dSpec;
LCount++;
}
}
}
// pSpace.ALLCharacterPoints[LCount] = 1000;
pSpace->FCharacterPoints[LCount] = 1000;
LineDone(commandLines);
}
}
// FROM
string hullName = "";
if (commandLines.size() > 0)
{
linePara = StringHelper::GetWords(commandLines[0]);
if (StringHelper::toUpper(linePara[0]) == "FROM")
{
if (linePara.size() > 2)
{
throw std::runtime_error("不支持多个主船体!");
}
if (linePara.size() == 2)
{
hullName = linePara[1];
}
else
{
hullName = "HULL_1";
}
// XUEFENG ADDED 202012
if (StringHelper::startsWith(hullName,"0"))
{
hullName = hullName;
}
// END ADDED
else if (!StringHelper::startsWith(StringHelper::toUpper(hullName),"HULL_"))
{
hullName = "HULL_" + hullName;
}
LineDone(commandLines);
}
else // 缺省from
{
hullName = "HULL_1";
}
}
else // 缺省from
{
hullName = "HULL_1";
}
// XUEFENG ADDED 202012
if (hullName == "0")
{
pSpace->m_HullID = -99999;
}
// END ADDED
else
{
if (pdata->getModelData().getHulls().size()==0)
{
throw std::runtime_error("没有主船体,请创建主船体!");
}
int sid = DataManager::GetObjectIDByName(hullName);
if (sid < 0)
{
throw std::runtime_error("不存在主船体" + hullName + "");
}
pSpace->m_HullID = sid;
}
}
// END ADDED
Add2ModelOrInteractWithIdtf(pSpace);
}
else if (firstWord == "APPENDAGE")
{
// 附体
Appendage_M* pAppendage = dynamic_cast<Appendage_M*>(&o);
pAppendage->m_Name = QString::fromStdString(name);
// 参数行-THR
std::vector<std::string> linePara = StringHelper::GetWords(commandLines[0]);
if (linePara.size() < 2)
{
throw std::runtime_error("附体命令行参数错误!");
}
std::string cmd = StringHelper::toUpper(linePara[0]);
if (cmd == "BOOL")
{
pAppendage->m_Type = 1;
} // 20170801 修改关键字 by czb体组合原为“THR”
else if (cmd == "THR")
{
pAppendage->m_Type = 2;
} // 20170801 新增 by czb面围拢
else
{
throw std::runtime_error("附体命令行参数错误!");
}
if (pAppendage->m_Type == 1) // 体组合
{
pAppendage->m_Src.resize(ModelData::ARRAY_SIZE_NORMAL);
pAppendage->m_SolidAddMode.resize(ModelData::ARRAY_SIZE_NORMAL);
for (int i = 1; i < linePara.size(); i++)
{
string solidname = linePara[i];
int solidandtype = ParseBoolSymbolFromName(solidname);
// 20170801 修改 by czb
int sid = DataManager::GetObjectIDByName(solidname);
if (sid == -1)
throw std::runtime_error("对象" + solidname + "不存在!");
pAppendage->m_Src[i - 1] = sid;
pAppendage->m_SolidAddMode[i - 1] = solidandtype;
}
LineDone(commandLines);
}
else if (pAppendage->m_Type == 2) // 面围拢
{
pAppendage->m_Src.resize(ModelData::ARRAY_SIZE_NORMAL);
pAppendage->m_SolidAddMode.resize(ModelData::ARRAY_SIZE_NORMAL);
for (int i = 1; i < linePara.size(); i++)
{
int sid = -1;
string sname = StringHelper::toUpper(linePara[i]);
sid = DataManager::GetObjectIDByName(sname);
if (sid == -1)
throw std::runtime_error("对象" + sname + "不存在!");
pAppendage->m_Src[i - 1] = sid;
}
LineDone(commandLines);
}
Add2ModelOrInteractWithIdtf(pAppendage);
}
}
double HullObjectInterpreter::convertSpecToDigital(const std::string& strSpec, int flag )
{
double dSpec = 0;
std::string upperSpec = StringHelper::toUpper(strSpec); // 使用你已有的 toupper 函数
if (upperSpec == "Y+") {
dSpec = (flag == 0) ? 777 : 666;
}
else if (upperSpec == "Y-") {
dSpec = (flag == 0) ? -777 : -666;
}
else if (upperSpec == "Z+") {
dSpec = (flag == 0) ? 888 : 666;
}
else if (upperSpec == "Z-") {
dSpec = (flag == 0) ? -888 : -666;
}
else if (upperSpec == "P+") {
dSpec = 999;
}
else if (upperSpec == "P-") {
dSpec = -999;
}
else {
try {
dSpec = std::stod(strSpec); // 直接解析原始 strSpec保持逻辑一致
}
catch (...) {
dSpec = -10001;
}
}
return dSpec;
}
std::string HullObjectInterpreter::convertDigitalToSpec(double dSpec, int flag)
{
std::string strSpec;
// by yangchen 20170105
int kk = 0;
// 尝试将 double 转换为 int与 C# 的 int.TryParse 等效)
kk = static_cast<int>(dSpec);
if (static_cast<double>(kk) != dSpec) {
return "";
}
switch (kk)
{
case 666:
strSpec = (flag == 0) ? "y+" : "z+";
break;
case -666:
strSpec = (flag == 0) ? "y-" : "z-";
break;
case 777:
strSpec = "y+";
break;
case -777:
strSpec = "y-";
break;
case 888:
strSpec = "z+";
break;
case -888:
strSpec = "z-";
break;
case 999:
strSpec = "p+";
break;
case -999:
strSpec = "p-";
break;
default:
strSpec = "";
break;
}
return strSpec;
}
PropertyInterpreter::PropertyInterpreter()
{
}
void PropertyInterpreter::ExecuteCommand(std::vector<std::string> commandLines, std::vector<int>& ids,int& iValue)
{
std::vector<std::string> lineName = StringHelper::GetWords(commandLines[0]);
if(lineName.size() < 2)
{
return;
}
for (auto name :lineName)
{
int obj_id = DataManager::GetObjectIDByName(name);
if(obj_id < 0)
{
continue;
}
ids.emplace_back(obj_id);
}
LineDone(commandLines);
std::vector<std::string> linePara1 = StringHelper::GetWords(commandLines[0]);
if(linePara1.size() < 1)
{
return;
}
std::string upperWords = StringHelper::toUpper(linePara1[0]);
if(upperWords == "VISIBLE")
{
if(linePara1.size() != 2)
{
return;
}
iValue = std::stoi(linePara1[1]);
}
LineDone(commandLines);
}
RegenCommandInterpreter::RegenCommandInterpreter()
{
}
void RegenCommandInterpreter::ExecuteCommand(std::vector<std::string> commandLines,QString& strLog)
{
if (commandLines.size() == 0)
{
return;
}
std::vector<std::string> line = StringHelper::GetWords(commandLines[0]);
LineDone(commandLines);
std::vector<int> idList;
if (line.size() == 1)
{
//所有图元
idList = DataManager::GetAllObject();
}
else
{
for (int i = 1; i < line.size(); i++)
{
int id = DataManager::GetObjectIDByName(line[i]);
if (id == -1)
{
continue;
}
idList.emplace_back(id);
}
}
if (idList.size() < 1)
{
return;
}
//idList = mng.SortIDByDepend(idList);//根据依赖关系排序
//分类(几何,主甲板-外板-船壳,舱室-附体) by yangchen 20170104
std::vector<int> geomList;//几何
std::vector<int> hullList;//甲板-外板-船壳
std::vector<int> spaceList;//舱室-附体
for(int id : idList)
{
int type = id / 1000000;
if (type < 4)
{
geomList.emplace_back(id);
}
if (type == 10 || type == 11 || type == 18)
{
hullList.emplace_back(id);
}
if (type == 16 || type == 17)
{
spaceList.emplace_back(id);
}
}
geomList = DataManager::sortListByDependent(geomList);//根据依赖关系排序
hullList = DataManager::sortListByDependent(hullList);//根据依赖关系排序
spaceList = DataManager::sortListByDependent(spaceList);//根据依赖关系排序
idList.clear();
idList.insert(idList.end(),geomList.begin(),geomList.end());
idList.insert(idList.end(),hullList.begin(),hullList.end());
idList.insert(idList.end(),spaceList.begin(),spaceList.end());
QString s = "图元对应命令:" + PathUtil::getEndMark();
QString names = "";
for (int id : idList)
{
IModel * pO = DataManager::GetObjectByID(id);
if(!pO)
{
continue;
}
names += " " + pO->GetName();
s += pO->GetCommand() + PathUtil::getEndMark();
}
strLog = "";
strLog +="REGENCMD" + names + PathUtil::getEndMark();
strLog += s+ PathUtil::getEndMark();;
}