From 1158ce068e3b5b391604270bf10c52d0d2f7f4db Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Tue, 16 May 2017 19:07:49 -0300 Subject: Sync generator control fixed --- Project/ControlElementContainer.cpp | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'Project/ControlElementContainer.cpp') diff --git a/Project/ControlElementContainer.cpp b/Project/ControlElementContainer.cpp index f8accdc..edfe684 100644 --- a/Project/ControlElementContainer.cpp +++ b/Project/ControlElementContainer.cpp @@ -76,3 +76,62 @@ void ControlElementContainer::FillContainer(std::vector control } } } + +void ControlElementContainer::GetContainerCopy(std::vector& controlElementList, + std::vector& connectionLineList) +{ + controlElementList.clear(); + connectionLineList.clear(); + + // Copy connection lines + for(auto it = m_cLineList.begin(), itEnd = m_cLineList.end(); it != itEnd; ++it) { + ConnectionLine* copy = static_cast((*it)->GetCopy()); + connectionLineList.push_back(copy); + } + + // Copy elements (exept connection line). + int nodeID = 0; + for(auto it = m_ctrlElementsList.begin(), itEnd = m_ctrlElementsList.end(); it != itEnd; ++it) { + Element* oldElement = *it; + ControlElement* copy = static_cast(oldElement->GetCopy()); + controlElementList.push_back(copy); + // Copy nodes. + std::vector nodeList = copy->GetNodeList(); + std::vector nodeListCopy; + for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { + Node* node = *itN; + node->SetID(nodeID); + Node* copyNode = new Node(); + *copyNode = *node; + nodeListCopy.push_back(copyNode); + nodeID++; + } + copy->SetNodeList(nodeListCopy); + + // Replace children to copies. + auto childList = copy->GetChildList(); + for(auto itC = childList.begin(), itEndC = childList.end(); itC != itEndC; ++itC) { + ConnectionLine* child = static_cast(*itC); + // Replace child's parent to copy. + for(auto itCL = connectionLineList.begin(), itEndCL = connectionLineList.end(); itCL != itEndCL; ++itCL) { + ConnectionLine* copyLine = *itCL; + if(copyLine->GetID() == child->GetID()) { + // Replace node. + nodeList = child->GetNodeList(); + for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { + Node* node = *itN; + for(auto itCN = nodeListCopy.begin(), itEndCN = nodeListCopy.end(); itCN != itEndCN; ++itCN) { + Node* nodeCopy = *itCN; + if(node->GetID() == nodeCopy->GetID()) { + copyLine->ReplaceNode(node, nodeCopy); + break; + } + } + } + copyLine->ReplaceParent(oldElement, copy); + copy->ReplaceChild(child, copyLine); + } + } + } + } +} -- cgit