#pragma once #include #include #include #include #include #include #include #include "tinyxml.h" #include "ReadXML.h" using namespace std; void init_readxml() { wire_node.clear(); wire_pairs.clear(); mp.clear(); wiremap.clear(); pinidmap.clear(); pinmap.clear(); cnt = 0; } void producePin(TiXmlElement *pin) { pinidmap[pin->Attribute("id")] = pin->Attribute("name"); } 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; } } 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 if (0 != strcmp(pEle->Value(), strNodeName)) { TiXmlElement *res = GetNodePointerByName(pEle, strNodeName); if (res != NULL) return res; } else return pEle; } return NULL; } TiXmlElement *GetNextNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName) { // if equal root node then return 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; } return NULL; } void produceConnector(TiXmlElement *pcon) { Connector con; 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); connectorNum++; con.ID = connectorNum; con.coord.type = 3; con.coord.ref = connectorNum; connectors[connectorNum] = con; 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"); pinmap[id] = Pin(name, id, con.coord); break; } } break; } } 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); } } } 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; } Wire wire; wire.sn = sn; wire.en = en; wire.name = pwire->Attribute("name"); if (pwire->Attribute("outsidediameter") != NULL) { wire.diameter = atof(pwire->Attribute("outsidediameter")); } else if (pwire->Attribute("wirecsa") != NULL) { wire.diameter = atof(pwire->Attribute("wirecsa")) * 2; } 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 = make_pair(sn.coord, en.coord); pair pr = make_pair(en.coord, sn.coord); if (wire_node.find(p) != wire_node.end()) { Bund bd = wire_node[p]; bd.wirelist.push_back(wire); bd.d.push_back(wire.diameter); wire_node[p] = bd; } else if (wire_node.find(pr) != wire_node.end()) { Bund bd = wire_node[pr]; bd.wirelist.push_back(wire); bd.d.push_back(wire.diameter); wire_node[pr] = bd; } else { Bund bd; bd.start = sn.coord; bd.goal = en.coord; bd.wirelist.push_back(wire); bd.d.push_back(wire.diameter); wire_node[p] = bd; } } void produce(TiXmlElement *pEle) { if (strcmp(pEle->Value(), "wire") == 0) produceWire(pEle); else produceConnector(pEle); return; } void ProduceNodePointerByName(TiXmlElement *pRootEle, const char *strNodeName) { // if equal root node then return if (0 == strcmp(strNodeName, pRootEle->Value())) { produce(pRootEle); return; } TiXmlElement *pEle = pRootEle; for (pEle = pRootEle->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement()) { // recursive find sub node return node pointer if (0 != strcmp(pEle->Value(), strNodeName)) { ProduceNodePointerByName(pEle, strNodeName); } else { produce(pEle); } } return; } void readxml(const string xml, const string connectorFile) { init_readxml(); ifstream infile; infile.open(connectorFile); // XXXX??csv??¡¤?? string s; while (getline(infile, s)) { // cout< fields; // ???????????????? string field; while (getline(sin, field, ',')) // ?????????sin?§Ö????????field??????§µ???????????? { fields.push_back(field); // ???????????????????????fields?? } // cout<LoadFile())) return; // pDoc->Print(); // ??????????Persons?? // cout<<"connectivity"<RootElement(); TiXmlElement *connectivity = GetNodePointerByName(RootElement, "connectivity"); // cout<<(connectivity->Value())<Attribute("id")==NULL)<, Bund>::iterator it = wire_node.begin(); it != wire_node.end(); it++) { wire_pairs.push_back(it->second); } 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<