TiXmlDocument* pXMLSchedulers = new TiXmlDocument( "Schedulers.xml" );
TiXmlDocument* pXMLFlowGraph = new TiXmlDocument( "FlowGraph.xml" );
map <string, pair<string,string> > connectionPointMap;
if ( pXMLSchedulers->LoadFile( TIXML_ENCODING_UTF8 ))
{
TiXmlNode* pSchedulers = pXMLSchedulers->FirstChild("Schedulers");
if (pSchedulers)
{
TiXmlElement flowGraph("FlowGraph");
flowGraph.SetAttribute("CompactMode","1");
TiXmlNode *pFlowGraph = pXMLFlowGraph->InsertEndChild(flowGraph);
TiXmlNode* pPages = pSchedulers->FirstChild("Pages");
while (pPages != NULL)
{
TiXmlNode *pPagesClone = pPages->Clone();
pFlowGraph->LinkEndChild(pPagesClone);
TiXmlNode *pPage = pPagesClone->FirstChild("Page");
while (pPage)
{
TiXmlNode *pNode = pPage->FirstChild("Node");
while (pNode)
{
string idNode = Util::Convert("%ld",pNode);
TiXmlElement *pNodeElement = pNode->ToElement();
pNodeElement->SetAttribute("Id",idNode.c_str());
// don't know how to calc real size.
pNodeElement->SetAttribute("UserSize","200, 200");
TiXmlNode *pConnectionPoint = pNode->FirstChild("ConnectionPoint");
uint index = 0;
while (pConnectionPoint)
{
TiXmlElement* pConnectionPointElement = pConnectionPoint->ToElement();
// Create name attribute
CString newPointName;
newPointName.Format(_T("%ld"), Timer().Start());
pConnectionPointElement->SetAttribute("Name",newPointName);
// Memorize Id to reconnect
string idConnectionPoint = pConnectionPointElement->Attribute("Id");
connectionPointMap[idConnectionPoint]=make_pair(idNode,Util::Convert("%d",index));
pConnectionPointElement->RemoveAttribute("Id");
pConnectionPoint = pConnectionPoint->NextSibling("ConnectionPoint");
index++;
}
pNode = pNode->NextSibling("Node");
}
TiXmlNode *pConnection = pPage->FirstChild("Connection");
while (pConnection)
{
TiXmlElement *pConnectionElement = pConnection->ToElement();
string input = pConnectionElement->Attribute("Input");
string output = pConnectionElement->Attribute("Output");
if (connectionPointMap.find(input) == connectionPointMap.end() || connectionPointMap.find(output) == connectionPointMap.end())
{
assert(false);
continue;
}
pConnectionElement->SetAttribute("InputNode",connectionPointMap[input].first.c_str());
pConnectionElement->SetAttribute("InputPointIndex",connectionPointMap[input].second.c_str());
pConnectionElement->SetAttribute("OutputNode",connectionPointMap[output].first.c_str());
pConnectionElement->SetAttribute("OutputPointIndex",connectionPointMap[output].second.c_str());
pConnectionElement->RemoveAttribute("Input");
pConnectionElement->RemoveAttribute("Output");
pConnection = pConnection->NextSibling("Connection");
}
pPage = pPage->NextSibling("Page");
}
pPages = pPages->NextSibling("Pages");
}
}
}
bool ret = pXMLFlowGraph->SaveFile();
delete pXMLSchedulers;
delete pXMLFlowGraph;