/** Add specified item to the grid view */ void AddItem(TSharedPtr<FWorldTileModel> LevelModel) { auto NewNode = SNew(SWorldTileItem) .InWorldModel(WorldModel) .InItemModel(LevelModel) .InThumbnailCollection(ThumbnailCollection); AddGraphNode(NewNode); }
void CPlanarGraph::AddGraphNodes(int numOfNodes, int parent /* = -1 */) { int current = parent; for ( int i=0; i<numOfNodes; i++ ) { CGraphNode node; std::ostringstream os; os << GetNumOfNodes(); std::string name = "node" + os.str(); node.SetName(name); AddGraphNode(node); int curId = GetNumOfNodes() - 1; if ( current >= 0 ) { AddGraphEdge(CGraphEdge(current, curId)); } current = curId; } }
bool CPlanarGraph::LoadGraphFromXML(const char* fileName, bool flagDetectFaces /* = true */, bool flagIgnoreIndiv /* = true */) { // Clear the current graph... ClearGraph(); TiXmlDocument doc; bool loadFlag = doc.LoadFile(fileName); if ( loadFlag == false ) { std::cout << "Failed to load graph from " << fileName << "!\n"; return loadFlag; } //doc.Print(); TiXmlNode* xmlRoot = 0; xmlRoot = doc.RootElement(); assert( xmlRoot ); TiXmlNode* xmlNode = xmlRoot->FirstChild(); while ( xmlNode != 0 ) { if ( strcmp(xmlNode->Value(), "Node") == 0 ) { // Parse a node... CGraphNode graphNode; float px, py; int rx = xmlNode->ToElement()->QueryFloatAttribute("px", &px); int ry = xmlNode->ToElement()->QueryFloatAttribute("py", &py); if ( rx != TIXML_SUCCESS || ry != TIXML_SUCCESS ) { graphNode.RandomlyInitPos(); } else { graphNode.SetPos(px, py); } int type; int r = xmlNode->ToElement()->QueryIntAttribute("type", &type); if ( r == TIXML_SUCCESS ) { graphNode.SetType(type); } int boundary; int rb = xmlNode->ToElement()->QueryIntAttribute("boundary", &boundary); if ( rb == TIXML_SUCCESS ) { graphNode.SetBoundaryType(boundary); } int fixed; int rf = xmlNode->ToElement()->QueryIntAttribute("fix", &fixed); if ( rf == TIXML_SUCCESS && fixed != 0 ) { graphNode.SetFlagFixed(true); } const char* str = xmlNode->ToElement()->Attribute("name"); if ( *str != '\0' ) { graphNode.SetName(str); } AddGraphNode(graphNode); } else if ( strcmp(xmlNode->Value(), "Edge") == 0 ) { // Parse an edge... int idx0 = -1; int idx1 = -1; int r0 = xmlNode->ToElement()->QueryIntAttribute("node0", &idx0); int r1 = xmlNode->ToElement()->QueryIntAttribute("node1", &idx1); if ( r0 != TIXML_SUCCESS ) { const char* str = xmlNode->ToElement()->Attribute("name0"); idx0 = FindNodeAccordingToName(str); } if ( r1 != TIXML_SUCCESS ) { const char* str = xmlNode->ToElement()->Attribute("name1"); idx1 = FindNodeAccordingToName(str); } if ( idx0 >= 0 && idx1 >= 0 ) { CGraphEdge graphEdge(idx0, idx1); AddGraphEdge(graphEdge); } } // Move to the next sibling... xmlNode = xmlNode->NextSibling(); } SetNodeNeighbors(); if ( flagIgnoreIndiv == true ) { RemoveIndividualNodes(); } if ( flagDetectFaces == false ) { return loadFlag; } //PrintGraph(); // Step 1: Detect faces of the planar graph... DetectFaces(); return loadFlag; }