summaryrefslogtreecommitdiffstats
path: root/Project/ControlElementContainer.cpp
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2017-09-04 20:05:30 -0300
committerGitHub <noreply@github.com>2017-09-04 20:05:30 -0300
commit926af7f34aaf5aebdbac0cbc550ed75647874258 (patch)
tree4df26f8c631aeeeed6e5c9e8aab87c4c663bd30f /Project/ControlElementContainer.cpp
parent17d1dd82ec065eff08546ef1fd2a188ce77471b2 (diff)
parent6f3421c4150e49af026432a2a2be0171d741ad03 (diff)
downloadPSP.git-926af7f34aaf5aebdbac0cbc550ed75647874258.tar.gz
PSP.git-926af7f34aaf5aebdbac0cbc550ed75647874258.tar.xz
PSP.git-926af7f34aaf5aebdbac0cbc550ed75647874258.zip
Merge pull request #33 from Thales1330/wip/electromechanical-calc
Wip electromechanical calc
Diffstat (limited to 'Project/ControlElementContainer.cpp')
-rw-r--r--Project/ControlElementContainer.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/Project/ControlElementContainer.cpp b/Project/ControlElementContainer.cpp
index e461529..edfe684 100644
--- a/Project/ControlElementContainer.cpp
+++ b/Project/ControlElementContainer.cpp
@@ -50,6 +50,88 @@ void ControlElementContainer::ClearContainer()
void ControlElementContainer::FillContainer(std::vector<ControlElement*> controlElementList,
std::vector<ConnectionLine*> connectionLineList)
{
+ ClearContainer();
m_ctrlElementsList = controlElementList;
m_cLineList = connectionLineList;
+
+ for(auto it = controlElementList.begin(), itEnd = controlElementList.end(); it != itEnd; ++it) {
+ if(Constant* constant = dynamic_cast<Constant*>(*it)) {
+ m_constantList.push_back(constant);
+ } else if(Exponential* exponential = dynamic_cast<Exponential*>(*it)) {
+ m_exponentialList.push_back(exponential);
+ } else if(Gain* gain = dynamic_cast<Gain*>(*it)) {
+ m_gainList.push_back(gain);
+ } else if(IOControl* ioControl = dynamic_cast<IOControl*>(*it)) {
+ m_ioControlList.push_back(ioControl);
+ } else if(Limiter* limiter = dynamic_cast<Limiter*>(*it)) {
+ m_limiterList.push_back(limiter);
+ } else if(Multiplier* multiplier = dynamic_cast<Multiplier*>(*it)) {
+ m_multiplierList.push_back(multiplier);
+ } else if(RateLimiter* rateLimiter = dynamic_cast<RateLimiter*>(*it)) {
+ m_rateLimiterList.push_back(rateLimiter);
+ } else if(Sum* sum = dynamic_cast<Sum*>(*it)) {
+ m_sumList.push_back(sum);
+ } else if(TransferFunction* tf = dynamic_cast<TransferFunction*>(*it)) {
+ m_tfList.push_back(tf);
+ }
+ }
+}
+
+void ControlElementContainer::GetContainerCopy(std::vector<ControlElement*>& controlElementList,
+ std::vector<ConnectionLine*>& 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<ConnectionLine*>((*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<ControlElement*>(oldElement->GetCopy());
+ controlElementList.push_back(copy);
+ // Copy nodes.
+ std::vector<Node*> nodeList = copy->GetNodeList();
+ std::vector<Node*> 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<ConnectionLine*>(*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);
+ }
+ }
+ }
+ }
}