You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
275 lines
6.4 KiB
275 lines
6.4 KiB
9 months ago
|
#pragma once
|
||
|
|
||
10 months ago
|
#include <string>
|
||
|
#include <map>
|
||
10 months ago
|
#include <iomanip>
|
||
10 months ago
|
#include <vector>
|
||
|
#include <cmath>
|
||
|
#include <fstream>
|
||
|
#include <sstream>
|
||
10 months ago
|
|
||
9 months ago
|
#include "tinyxml.h"
|
||
|
#include "ReadXML.h"
|
||
10 months ago
|
|
||
9 months ago
|
using namespace std;
|
||
10 months ago
|
|
||
10 months ago
|
void init_readxml()
|
||
|
{
|
||
10 months ago
|
wire_node.clear();
|
||
|
wire_pairs.clear();
|
||
|
mp.clear();
|
||
|
wiremap.clear();
|
||
|
pinidmap.clear();
|
||
|
pinmap.clear();
|
||
10 months ago
|
cnt = 0;
|
||
10 months ago
|
}
|
||
|
|
||
10 months ago
|
void producePin(TiXmlElement *pin)
|
||
|
{
|
||
|
pinidmap[pin->Attribute("id")] = pin->Attribute("name");
|
||
10 months ago
|
}
|
||
10 months ago
|
string safegave(TiXmlElement *pEle, const char *t)
|
||
|
{
|
||
|
if (pEle->Attribute(t) == NULL)
|
||
|
return ini;
|
||
|
else
|
||
|
{
|
||
|
string v = pEle->Attribute(t);
|
||
|
if (v == "")
|
||
|
return ini;
|
||
|
else
|
||
|
return v;
|
||
10 months ago
|
}
|
||
|
}
|
||
|
|
||
10 months ago
|
TiXmlElement *GetNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName)
|
||
10 months ago
|
{
|
||
|
// if equal root node then return
|
||
|
if (0 == strcmp(strNodeName, pRootEle->Value()))
|
||
|
{
|
||
|
return pRootEle;
|
||
|
}
|
||
10 months ago
|
|
||
|
TiXmlElement *pEle = pRootEle;
|
||
|
for (pEle = pRootEle->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement())
|
||
|
{
|
||
|
// recursive find sub node return node pointer
|
||
10 months ago
|
if (0 != strcmp(pEle->Value(), strNodeName))
|
||
|
{
|
||
10 months ago
|
TiXmlElement *res = GetNodePointerByName(pEle, strNodeName);
|
||
|
if (res != NULL)
|
||
|
return res;
|
||
10 months ago
|
}
|
||
10 months ago
|
else
|
||
|
return pEle;
|
||
|
}
|
||
|
|
||
10 months ago
|
return NULL;
|
||
|
}
|
||
10 months ago
|
TiXmlElement *GetNextNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName)
|
||
10 months ago
|
{
|
||
|
// if equal root node then return
|
||
10 months ago
|
TiXmlElement *pEle;
|
||
|
for (pEle = pRootEle->NextSiblingElement(); pEle; pEle = pEle->NextSiblingElement())
|
||
|
{
|
||
|
// recursive find sub node return node pointer
|
||
|
if (0 == strcmp(pEle->Value(), strNodeName))
|
||
|
return pEle;
|
||
|
}
|
||
10 months ago
|
return NULL;
|
||
|
}
|
||
10 months ago
|
void produceConnector(TiXmlElement *pcon)
|
||
|
{
|
||
10 months ago
|
Connector con;
|
||
10 months ago
|
con.id = pcon->Attribute("id");
|
||
|
con.name = pcon->Attribute("name");
|
||
|
con.partnumber = pcon->Attribute("partnumber");
|
||
|
con.coord = mp[con.name];
|
||
|
con.dir = P(0, 0, 0);
|
||
10 months ago
|
connectorNum++;
|
||
10 months ago
|
con.ID = connectorNum;
|
||
|
con.coord.type = 3;
|
||
|
con.coord.ref = connectorNum;
|
||
10 months ago
|
|
||
10 months ago
|
connectors[connectorNum] = con;
|
||
10 months ago
|
|
||
10 months ago
|
TiXmlElement *pEle;
|
||
|
TiXmlElement *p;
|
||
|
for (pEle = pcon->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement())
|
||
|
{
|
||
|
if (strcmp(pEle->Value(), "backshell") == 0)
|
||
|
{
|
||
|
for (p = pEle->FirstChildElement(); p; p = p->NextSiblingElement())
|
||
|
{
|
||
|
if (strcmp(p->Value(), "termination") == 0)
|
||
|
{
|
||
|
string id = p->Attribute("id");
|
||
|
string name = p->Attribute("name");
|
||
10 months ago
|
|
||
10 months ago
|
pinmap[id] = Pin(name, id, con.coord);
|
||
10 months ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
10 months ago
|
for (pEle = pcon->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement())
|
||
|
{
|
||
|
if (strcmp(pEle->Value(), "pin") == 0)
|
||
|
{
|
||
|
string id = pEle->Attribute("id");
|
||
|
string name = pEle->Attribute("name");
|
||
|
pinmap[id] = Pin(name, id, con.coord);
|
||
10 months ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
10 months ago
|
void produceWire(TiXmlElement *pwire)
|
||
|
{
|
||
|
Pin sn, en;
|
||
|
TiXmlElement *pconnection = GetNodePointerByName(pwire, "connection");
|
||
|
if (pconnection != NULL)
|
||
|
{
|
||
|
sn = pinmap[pconnection->Attribute("pinref")];
|
||
|
TiXmlElement *pconnection2 = GetNextNodePointerByName(pconnection, "connection");
|
||
|
if (pconnection2 != NULL)
|
||
|
en = pinmap[pconnection2->Attribute("pinref")];
|
||
|
else
|
||
|
en = sn;
|
||
10 months ago
|
}
|
||
|
Wire wire;
|
||
10 months ago
|
wire.sn = sn;
|
||
|
wire.en = en;
|
||
|
wire.name = pwire->Attribute("name");
|
||
|
if (pwire->Attribute("outsidediameter") != NULL)
|
||
|
{
|
||
|
wire.diameter = atof(pwire->Attribute("outsidediameter"));
|
||
10 months ago
|
}
|
||
10 months ago
|
else if (pwire->Attribute("wirecsa") != NULL)
|
||
|
{
|
||
|
wire.diameter = atof(pwire->Attribute("wirecsa")) * 2;
|
||
10 months ago
|
}
|
||
10 months ago
|
else
|
||
|
wire.diameter = 0.4;
|
||
|
wiremap[wire.name] = wire;
|
||
|
if (sn.coord == P(0, 0, 0) || en.coord == P(0, 0, 0) || sn.coord == en.coord)
|
||
|
return;
|
||
|
|
||
|
pair<P, P> p = make_pair(sn.coord, en.coord);
|
||
|
pair<P, P> pr = make_pair(en.coord, sn.coord);
|
||
|
if (wire_node.find(p) != wire_node.end())
|
||
|
{
|
||
|
Bund bd = wire_node[p];
|
||
10 months ago
|
bd.wirelist.push_back(wire);
|
||
|
bd.d.push_back(wire.diameter);
|
||
10 months ago
|
wire_node[p] = bd;
|
||
10 months ago
|
}
|
||
10 months ago
|
else if (wire_node.find(pr) != wire_node.end())
|
||
|
{
|
||
|
Bund bd = wire_node[pr];
|
||
10 months ago
|
bd.wirelist.push_back(wire);
|
||
|
bd.d.push_back(wire.diameter);
|
||
10 months ago
|
wire_node[pr] = bd;
|
||
10 months ago
|
}
|
||
10 months ago
|
else
|
||
|
{
|
||
10 months ago
|
Bund bd;
|
||
10 months ago
|
bd.start = sn.coord;
|
||
|
bd.goal = en.coord;
|
||
10 months ago
|
bd.wirelist.push_back(wire);
|
||
|
bd.d.push_back(wire.diameter);
|
||
10 months ago
|
wire_node[p] = bd;
|
||
10 months ago
|
}
|
||
|
}
|
||
10 months ago
|
void produce(TiXmlElement *pEle)
|
||
|
{
|
||
|
if (strcmp(pEle->Value(), "wire") == 0)
|
||
|
produceWire(pEle);
|
||
|
else
|
||
|
produceConnector(pEle);
|
||
10 months ago
|
return;
|
||
|
}
|
||
10 months ago
|
void ProduceNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName)
|
||
10 months ago
|
{
|
||
|
// if equal root node then return
|
||
|
if (0 == strcmp(strNodeName, pRootEle->Value()))
|
||
|
{
|
||
|
produce(pRootEle);
|
||
|
return;
|
||
|
}
|
||
10 months ago
|
|
||
|
TiXmlElement *pEle = pRootEle;
|
||
|
for (pEle = pRootEle->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement())
|
||
|
{
|
||
|
// recursive find sub node return node pointer
|
||
10 months ago
|
if (0 != strcmp(pEle->Value(), strNodeName))
|
||
|
{
|
||
10 months ago
|
ProduceNodePointerByName(pEle, strNodeName);
|
||
10 months ago
|
}
|
||
10 months ago
|
else
|
||
|
{
|
||
10 months ago
|
produce(pEle);
|
||
|
}
|
||
10 months ago
|
}
|
||
|
|
||
10 months ago
|
return;
|
||
|
}
|
||
9 months ago
|
void readxml(const string xml, const string connectorFile)
|
||
10 months ago
|
{
|
||
10 months ago
|
init_readxml();
|
||
|
ifstream infile;
|
||
9 months ago
|
infile.open(connectorFile); // XXXX??csv??��??
|
||
10 months ago
|
|
||
10 months ago
|
string s;
|
||
10 months ago
|
|
||
10 months ago
|
while (getline(infile, s))
|
||
|
{
|
||
|
// cout<<s<<endl;
|
||
9 months ago
|
istringstream sin(s); // ???????????line???????????istringstream??
|
||
|
vector<string> fields; // ????????????????
|
||
10 months ago
|
string field;
|
||
9 months ago
|
while (getline(sin, field, ',')) // ?????????sin?��????????field??????��????????????
|
||
10 months ago
|
{
|
||
9 months ago
|
fields.push_back(field); // ???????????????????????fields??
|
||
10 months ago
|
}
|
||
|
// cout<<fields[0]<<endl;
|
||
|
// cout<<"read_xml getline"<<endl;
|
||
|
// cout<<fields[0]<<" "<<fields[1]<<" "<<fields[2]<<" "<<fields[3]<<endl;
|
||
|
mp[fields[0]] = P(atof(fields[1].c_str()), atof(fields[2].c_str()), atof(fields[3].c_str()));
|
||
10 months ago
|
}
|
||
|
|
||
9 months ago
|
TiXmlDocument *pDoc = new TiXmlDocument(xml.c_str());
|
||
10 months ago
|
if (!(pDoc->LoadFile()))
|
||
|
return;
|
||
|
// pDoc->Print();
|
||
9 months ago
|
// ??????????Persons??
|
||
10 months ago
|
|
||
10 months ago
|
// cout<<"connectivity"<<endl<<endl;
|
||
10 months ago
|
TiXmlElement *RootElement = pDoc->RootElement();
|
||
10 months ago
|
TiXmlElement *connectivity = GetNodePointerByName(RootElement, "connectivity");
|
||
|
// cout<<(connectivity->Value())<<endl;
|
||
|
// cout<<(connectivity->Attribute("id")==NULL)<<endl;
|
||
|
ProduceNodePointerByName(connectivity, "connector");
|
||
|
ProduceNodePointerByName(connectivity, "splice");
|
||
|
ProduceNodePointerByName(connectivity, "wire");
|
||
|
for (map<pair<P, P>, Bund>::iterator it = wire_node.begin(); it != wire_node.end(); it++)
|
||
|
{
|
||
10 months ago
|
wire_pairs.push_back(it->second);
|
||
|
}
|
||
10 months ago
|
for (int i = 0; i < wire_pairs.size(); i++)
|
||
|
{
|
||
|
Bund &bd = wire_pairs[i];
|
||
|
for (int j = 0; j < bd.d.size(); j++)
|
||
|
{
|
||
|
bd.dia += (bd.d[j]) * (bd.d[j]);
|
||
|
// cout<<bd.d[j]<<" ";
|
||
10 months ago
|
}
|
||
10 months ago
|
bd.dia = sqrt(bd.dia);
|
||
|
for (int j = 0; j < bd.wirelist.size(); j++)
|
||
|
{
|
||
|
Wire &wire = bd.wirelist[j];
|
||
10 months ago
|
bd.wirenamelist.push_back(wire.name);
|
||
|
}
|
||
|
}
|
||
10 months ago
|
cout << "read xml Finish" << endl;
|
||
10 months ago
|
}
|