| 293 | } |
| 294 | |
| 295 | void FlattenBuildingParts(HierarchyLinker::Node::Ptrs & trees) |
| 296 | { |
| 297 | for (auto & tree : trees) |
| 298 | { |
| 299 | CHECK(!tree->HasParent(), ()); |
| 300 | |
| 301 | std::vector<std::pair<hierarchy::HierarchyLinker::Node::Ptr, hierarchy::HierarchyLinker::Node::Ptr>> |
| 302 | buildingPartsTrees; |
| 303 | |
| 304 | static auto const & buildingPartChecker = ftypes::IsBuildingPartChecker::Instance(); |
| 305 | std::function<void(hierarchy::HierarchyLinker::Node::Ptr const &)> visit; |
| 306 | visit = [&](auto const & n) |
| 307 | { |
| 308 | if (buildingPartChecker(n->GetData().GetTypes())) |
| 309 | { |
| 310 | CHECK(n->HasParent(), ()); |
| 311 | auto building = n->GetParent(); |
| 312 | buildingPartsTrees.emplace_back(building, n); |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | CHECK(!buildingPartChecker(n->GetData().GetTypes()), ()); |
| 317 | for (auto const & ch : n->GetChildren()) |
| 318 | visit(ch); |
| 319 | }; |
| 320 | |
| 321 | visit(tree); |
| 322 | |
| 323 | for (auto const & buildingAndParts : buildingPartsTrees) |
| 324 | { |
| 325 | Unlink(buildingAndParts.second, buildingAndParts.first); |
| 326 | tree_node::PostOrderVisit(buildingAndParts.second, [&](auto const & buildingPartNode) |
| 327 | { |
| 328 | CHECK(buildingPartChecker(buildingPartNode->GetData().GetTypes()), ()); |
| 329 | buildingPartNode->RemoveChildren(); |
| 330 | tree_node::Link(buildingPartNode, buildingAndParts.first); |
| 331 | }); |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | } // namespace hierarchy |
| 336 | } // namespace generator |