diff --git a/src/xmlsql.cpp b/src/xmlsql.cpp index 16de24f..a002805 100644 --- a/src/xmlsql.cpp +++ b/src/xmlsql.cpp @@ -5,424 +5,449 @@ #include "Astar.h" #include "Geometry.h" #include "Intersection.h" -#include -#include +#include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace std; +map pmp, clipName; -map pmp,clipName; - -struct Readexcel{ - vectorslist; - TiXmlElement* GetNodePointerByName(TiXmlElement* pRootEle, const char* strNodeName) +struct Readexcel +{ + vector slist; + TiXmlElement *GetNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName) { // if equal root node then return if (0 == strcmp(strNodeName, pRootEle->Value())) { return pRootEle; } - TiXmlElement* pEle = pRootEle; - for (pEle = pRootEle->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement()) - { - // recursive find sub node return node pointer + TiXmlElement *pEle = pRootEle; + for (pEle = pRootEle->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement()) + { + // recursive find sub node return node pointer if (0 != strcmp(pEle->Value(), strNodeName)) { - TiXmlElement* res=GetNodePointerByName(pEle,strNodeName); - if(res!=NULL)return res; + TiXmlElement *res = GetNodePointerByName(pEle, strNodeName); + if (res != NULL) + return res; } - else return pEle; - } + else + return pEle; + } return NULL; } - vector read(string xml){ + vector read(string xml) + { slist.clear(); - TiXmlDocument* pDoc = new TiXmlDocument(); + TiXmlDocument *pDoc = new TiXmlDocument(); pDoc->LoadFile(xml.c_str()); - + TiXmlElement *RootElement = pDoc->RootElement(); - - TiXmlElement * row=GetNodePointerByName(RootElement, "Row"); - - TiXmlElement* pEle; - - for (pEle =row; pEle; pEle = pEle->NextSiblingElement()) - { - // recursive find sub node return node pointer - - TiXmlElement* cell; + + TiXmlElement *row = GetNodePointerByName(RootElement, "Row"); + + TiXmlElement *pEle; + + for (pEle = row; pEle; pEle = pEle->NextSiblingElement()) + { + // recursive find sub node return node pointer + + TiXmlElement *cell; string s[7]; - int i=0; - for (cell =pEle->FirstChildElement(); cell; cell = cell->NextSiblingElement()){ - - //cout<<(cell->FirstChildElement()->GetText())<FirstChildElement()->GetText(); + int i = 0; + for (cell = pEle->FirstChildElement(); cell; cell = cell->NextSiblingElement()) + { + + // cout<<(cell->FirstChildElement()->GetText())<FirstChildElement()->GetText(); i++; } slist.push_back(s[0]); - slist.push_back(s[1]+" "+s[2]+" "+s[3]); - slist.push_back(s[4]+" "+s[5]+" "+s[6]); - } - + slist.push_back(s[1] + " " + s[2] + " " + s[3]); + slist.push_back(s[4] + " " + s[5] + " " + s[6]); + } return slist; } -}rexcel; - -//读取卡箍点 -void read_points(string filename,Astar * pastar){ - //cout<<"read "<sl=rexcel.read(filename); - //cout<<"------"< sl = rexcel.read(filename); + // cout<<"------"<>p1.x>>p1.y>>p1.z; - sin2>>p2.x>>p2.y>>p2.z; - //p1.print("p"); - pmp[p1]=s1; - pmp[p2]=s2; - clipName[p1]=s0; - - clipSet.addclip(p1,p2,s0,2); + string s1 = sl[i + 1], s2 = sl[i + 2], s0 = sl[i]; + // cout<> p1.x >> p1.y >> p1.z; + sin2 >> p2.x >> p2.y >> p2.z; + // p1.print("p"); + pmp[p1] = s1; + pmp[p2] = s2; + clipName[p1] = s0; + + clipSet.addclip(p1, p2, s0, 2); pastar->add_clip(clipSet.c[clipSet.clipnum]); - //cout<<"--"<(number) != number) + { + throw invalid_argument("Invalid input string for conversion to unsigned int."); + } // 检查转换是否成功,以及值是否在 unsigned int 的范围内 + return static_cast(number); // 转换为 unsigned int 并返回 } -unsigned int extractAndConvert(const string& str) { - size_t pos = str.find("/"); // 查找 "//" 的位置 - if (pos == std::string::npos) { - throw invalid_argument("No '/' found in the string."); - } - string numberStr = str.substr(0, pos); // 截取 "//" 之前的部分 - char* endptr; - long number = strtol(numberStr.c_str(), &endptr, 10); // 使用 strtol 将字符串转换为 long,并检查转换是否成功 - if (endptr == numberStr.c_str() || *endptr != '\0' || number < 0 || static_cast(number) != number) { - throw invalid_argument("Invalid input string for conversion to unsigned int."); - } // 检查转换是否成功,以及值是否在 unsigned int 的范围内 - return static_cast(number); // 转换为 unsigned int 并返回 -} - - -bool read_OBJ(const string& filename,vector& vertices,vector& indices) +bool read_OBJ(const string &filename, vector &vertices, vector &indices) { - ifstream file(filename.c_str()); - if (!file.is_open()) { - return false; - } - string line; - while (getline(file, line)) { - // 忽略空行和注释行 - if (line.empty() || line.at(0) == '#') { - continue; - } - //std::cout<> token && token == "v") {// 解析顶点 - float x, y, z; - iss >> x >> y >> z; - //std::cout<<"v:"<> v1_s >> v2_s >> v3_s)) { - // 处理非三角形面或其他错误情况 - continue; - } - try { - v1=extractAndConvert(v1_s)-1; - } catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; - } - try { - v2=extractAndConvert(v2_s)-1; - } catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; - } - try { - v3=extractAndConvert(v3_s)-1; - } catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; - } - //std::cout<<"f:"<> token && token == "v") + { // 解析顶点 + float x, y, z; + iss >> x >> y >> z; + // std::cout<<"v:"<> v1_s >> v2_s >> v3_s)) + { + // 处理非三角形面或其他错误情况 + continue; + } + try + { + v1 = extractAndConvert(v1_s) - 1; + } + catch (const std::exception &e) + { + std::cerr << "Error: " << e.what() << std::endl; + } + try + { + v2 = extractAndConvert(v2_s) - 1; + } + catch (const std::exception &e) + { + std::cerr << "Error: " << e.what() << std::endl; + } + try + { + v3 = extractAndConvert(v3_s) - 1; + } + catch (const std::exception &e) + { + std::cerr << "Error: " << e.what() << std::endl; + } + // std::cout<<"f:"<"; + string endfilename = "end" + resultfile; + // oendpoint.open(endfilename.c_str(),ios::out); + + readxml(xml, connectorFile); + + cout << "wire_pairs num: " << wire_pairs.size() << endl; + + for (int i = 0; i < wire_pairs.size(); i++) + { + // if(i!=6)continue; + Bund &bd = wire_pairs[i]; + // oendpoint<"; } - cout<& files) { - //文件句柄 +void getAllFiles(string path, vector &files) +{ + // 文件句柄 long long hFile = 0; - //文件信息 - struct _finddata_t fileinfo; - string p; - if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) { - do { - if ((fileinfo.attrib & _A_SUBDIR)) { //比较文件类型是否是文件夹 - if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) { + // 文件信息 + struct _finddata_t fileinfo; + string p; + if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) + { + do + { + if ((fileinfo.attrib & _A_SUBDIR)) + { // 比较文件类型是否是文件夹 + if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) + { files.push_back(p.assign(path).append("\\").append(fileinfo.name)); - //递归搜索 + // 递归搜索 getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files); } } - else { + else + { files.push_back(p.assign(path).append("\\").append(fileinfo.name)); } - } while (_findnext(hFile, &fileinfo) == 0); //寻找下一个,成功返回0,否则-1 + } while (_findnext(hFile, &fileinfo) == 0); // 寻找下一个,成功返回0,否则-1 _findclose(hFile); } } -//初始化各个结构体 -inline void init(){ +// 初始化各个结构体 +inline void init() +{ kdtree.build(); - cout<<"kdtree build Finish"<>mode; mode = argv[1]; - - if(mode=="generateCATIA"){ - //该模式为基本模式,使用它来生成通道模型 - string clipDoc,xmlDoc,connectorFile,stlFileName,outputFileName; - cin>>clipDoc>>xmlDoc>>connectorFile>>stlFileName>>outputFileName; + + if (mode == "generateCATIA") + { + // 该模式为基本模式,使用它来生成通道模型 + string clipDoc, xmlDoc, connectorFile, stlFileName, outputFileName; + cin >> clipDoc >> xmlDoc >> connectorFile >> stlFileName >> outputFileName; vector clipFileNames; - getAllFiles(clipDoc,clipFileNames); - for(int i=0;i filenames; - getAllFiles(xmlDoc,filenames); - for(int i=0;i>clipDoc>>stlFileName>>outputFileName; - cout<<"mode = createChannel"<> clipDoc >> stlFileName >> outputFileName; + cout << "mode = createChannel" << endl; vector clipFileNames; - getAllFiles(clipDoc,clipFileNames); - for(int i=0;i>clipDoc>>xmlDoc>>connectorFile>>OBJDoc>>outputFileName; clipDoc = argv[2]; xmlDoc = argv[3]; connectorFile = argv[4]; OBJDoc = argv[5]; outputFileName = argv[6]; - + vector OBJFilenames; - getAllFiles(OBJDoc,OBJFilenames); - cout<<"OBJfilename.size()"< clipFileNames; - getAllFiles(clipDoc,clipFileNames); - for(int i=0;i filenames; - getAllFiles(xmlDoc,filenames); + getAllFiles(xmlDoc, filenames); - cout<<"filename.size()"<