------------------------------------------------------------------------------
| 590 | |
| 591 | //------------------------------------------------------------------------------ |
| 592 | std::vector<int> vtkDataAssembly::AddNodes(const std::vector<std::string>& names, int parent) |
| 593 | { |
| 594 | auto& internals = (*this->Internals); |
| 595 | auto pnode = internals.FindNode(parent); |
| 596 | if (!pnode) |
| 597 | { |
| 598 | vtkErrorMacro("Parent node with id=" << parent << " not found."); |
| 599 | return std::vector<int>{}; |
| 600 | } |
| 601 | |
| 602 | // validate names first to avoid partial additions. |
| 603 | for (const auto& name : names) |
| 604 | { |
| 605 | if (!vtkDataAssembly::IsNodeNameValid(name.c_str())) |
| 606 | { |
| 607 | vtkErrorMacro("Invalid name specified '" << name << "'."); |
| 608 | return std::vector<int>{}; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | std::vector<int> ids; |
| 613 | for (const auto& name : names) |
| 614 | { |
| 615 | auto child = ++internals.MaxUniqueId; |
| 616 | auto cnode = pnode.append_child(name.c_str()); |
| 617 | cnode.append_attribute("id") = child; |
| 618 | internals.NodeMap[child] = cnode; |
| 619 | ids.push_back(child); |
| 620 | } |
| 621 | if (!ids.empty()) |
| 622 | { |
| 623 | this->Modified(); |
| 624 | } |
| 625 | return ids; |
| 626 | } |
| 627 | |
| 628 | //------------------------------------------------------------------------------ |
| 629 | bool vtkDataAssembly::RemoveNode(int id) |