diff options
author | Thales1330 <thaleslima.ufu@gmail.com> | 2017-03-06 18:59:37 -0300 |
---|---|---|
committer | Thales1330 <thaleslima.ufu@gmail.com> | 2017-03-06 18:59:37 -0300 |
commit | b3be8e8ef6338bce2106d9c161bf3c7f7f7f9244 (patch) | |
tree | 4fc4811494822647c7a9af397d372af8629ac924 | |
parent | d11da00a993f1eeae6a1be50839ac72740e4e27b (diff) | |
download | PSP.git-b3be8e8ef6338bce2106d9c161bf3c7f7f7f9244.tar.gz PSP.git-b3be8e8ef6338bce2106d9c161bf3c7f7f7f9244.tar.xz PSP.git-b3be8e8ef6338bce2106d9c161bf3c7f7f7f9244.zip |
Connection line fully implemented
Bug on delete a chid line and update points
-rw-r--r-- | Project/ConnectionLine.cpp | 52 | ||||
-rw-r--r-- | Project/ConnectionLine.h | 4 | ||||
-rw-r--r-- | Project/ControlEditor.cpp | 93 | ||||
-rw-r--r-- | Project/ControlEditor.h | 7 | ||||
-rw-r--r-- | Project/Project.mk | 2 |
5 files changed, 110 insertions, 48 deletions
diff --git a/Project/ConnectionLine.cpp b/Project/ConnectionLine.cpp index fefe144..ecbec1d 100644 --- a/Project/ConnectionLine.cpp +++ b/Project/ConnectionLine.cpp @@ -27,6 +27,11 @@ void ConnectionLine::Draw(wxPoint2DDouble translation, double scale) const glLineWidth(1.5); glColor4d(0.0, 0.0, 0.0, 1.0); DrawLine(m_pointList); + + if(m_type == ELEMENT_LINE) { + glColor4d(0.0, 0.0, 0.0, 1.0); + DrawCircle(m_pointList[5], 3, 10, GL_POLYGON); + } } bool ConnectionLine::Contains(wxPoint2DDouble position) const @@ -89,7 +94,32 @@ void ConnectionLine::UpdatePoints() } else if(m_type == ELEMENT_LINE) { wxPoint2DDouble pt1 = m_nodeList[0]->GetPosition(); wxPoint2DDouble pt2 = m_parentLine->GetMidPoint(); - //CONTINUE... + wxPoint2DDouble midPt = (pt1 + pt2) / 2.0 + wxPoint2DDouble(0.0, m_lineOffset); + + m_pointList[0] = pt1; + if(m_nodeList[0]->GetAngle() == 0.0) + m_pointList[1] = m_pointList[0] + wxPoint2DDouble(-10, 0); + else if(m_nodeList[0]->GetAngle() == 90.0) + m_pointList[1] = m_pointList[0] + wxPoint2DDouble(0, -10); + else if(m_nodeList[0]->GetAngle() == 180.0) + m_pointList[1] = m_pointList[0] + wxPoint2DDouble(10, 0); + else if(m_nodeList[0]->GetAngle() == 270.0) + m_pointList[1] = m_pointList[0] + wxPoint2DDouble(0, 10); + + m_pointList[2] = m_pointList[1] + wxPoint2DDouble(0.0, midPt.m_y - m_pointList[1].m_y); + + m_pointList[5] = pt2; + if(m_pointList[2].m_y > pt2.m_y) { + m_pointList[4] = m_pointList[5] + wxPoint2DDouble(0, 10); + } else { + m_pointList[4] = m_pointList[5] + wxPoint2DDouble(0, -10); + } + + m_pointList[3] = m_pointList[4] + wxPoint2DDouble(0.0, midPt.m_y - m_pointList[4].m_y); + } + for(auto it = m_childList.begin(), itEnd = m_childList.end(); it != itEnd; ++it) { + ConnectionLine* child = static_cast<ConnectionLine*>(*it); + child->UpdatePoints(); } } @@ -123,10 +153,22 @@ void ConnectionLine::StartMove(wxPoint2DDouble position) wxPoint2DDouble ConnectionLine::GetMidPoint() const { return ((m_pointList[2] + m_pointList[3]) / 2.0); } -void ConnectionLine::SetParentLine(ConnectionLine* parent) +bool ConnectionLine::SetParentLine(ConnectionLine* parent) +{ + if(m_nodeList[0]->GetNodeType() != Node::NODE_IN) return false; + if(!parent) return false; + + m_type = ELEMENT_LINE; + m_parentLine = parent; + return true; +} + +std::vector<ConnectionLine*> ConnectionLine::GetLineChildList() const { - if(parent) { - m_type = ELEMENT_LINE; - m_parentLine = parent; + std::vector<ConnectionLine*> childList; + for(auto it = m_childList.begin(), itEnd = m_childList.end(); it != itEnd; ++it) { + ConnectionLine* child = static_cast<ConnectionLine*>(*it); + childList.push_back(child); } + return childList; } diff --git a/Project/ConnectionLine.h b/Project/ConnectionLine.h index b39fe15..350c5d9 100644 --- a/Project/ConnectionLine.h +++ b/Project/ConnectionLine.h @@ -27,7 +27,9 @@ public: virtual void SetType(ConnectionLineType newType) { m_type = newType; } virtual ConnectionLine* GetParentLine() const { return m_parentLine; } - virtual void SetParentLine(ConnectionLine* parent); + virtual bool SetParentLine(ConnectionLine* parent); + + virtual std::vector<ConnectionLine*> GetLineChildList() const; protected: double m_lineOffset = 0.0; diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 84a2650..4e04fb1 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -385,16 +385,25 @@ void ControlEditor::OnLeftClickUp(wxMouseEvent& event) } } for(auto it = m_connectionList.begin(), itEnd = m_connectionList.end(); it != itEnd; ++it) { - ConnectionLine* line = *it; - if(m_mode == MODE_SELECTION_RECT) { - if(line->Intersects(m_selectionRect)) { - line->SetSelected(); + ConnectionLine* cLine = *it; + if(m_mode == MODE_INSERT_LINE && !foundNode && it != (itEnd - 1)) { + if(cLine->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { + ConnectionLine* iLine = *(m_connectionList.end() - 1); + cLine->AddChild(iLine); + iLine->SetParentLine(cLine); + iLine->UpdatePoints(); + m_mode = MODE_EDIT; + foundNode = true; + } + } else if(m_mode == MODE_SELECTION_RECT) { + if(cLine->Intersects(m_selectionRect)) { + cLine->SetSelected(); } else if(!event.ControlDown()) { - line->SetSelected(false); + cLine->SetSelected(false); } } else if(!event.ControlDown()) { - if(!line->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { - line->SetSelected(false); + if(!cLine->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { + cLine->SetSelected(false); } } } @@ -402,21 +411,21 @@ void ControlEditor::OnLeftClickUp(wxMouseEvent& event) m_selectionRect = wxRect2DDouble(0, 0, 0, 0); if(m_mode == MODE_INSERT_LINE && !foundNode) { - ConnectionLine* line = *(m_connectionList.end() - 1); + ConnectionLine* cLine = *(m_connectionList.end() - 1); // Free nodes - auto nodeList = line->GetNodeList(); + auto nodeList = cLine->GetNodeList(); for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { Node* node = *itN; node->SetConnected(false); } // Remove the associated child from parents. - auto parentList = line->GetParentList(); + auto parentList = cLine->GetParentList(); for(auto it = parentList.begin(), itEnd = parentList.end(); it != itEnd; ++it) { Element* element = *it; - element->RemoveChild(line); + element->RemoveChild(cLine); } m_connectionList.pop_back(); - if(line) delete line; + if(cLine) delete cLine; m_mode = MODE_EDIT; } else if(m_mode != MODE_INSERT) { m_mode = MODE_EDIT; @@ -605,20 +614,7 @@ void ControlEditor::DeleteSelectedElements() for(auto itCo = m_connectionList.begin(); itCo != m_connectionList.end(); ++itCo) { ConnectionLine* line = *itCo; if(line == child) { - // Free nodes - auto nodeList = line->GetNodeList(); - for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { - Node* node = *itN; - node->SetConnected(false); - } - // Remove the child from parents - auto parentList = line->GetParentList(); - for(auto itP = parentList.begin(), itEndP = parentList.end(); itP != itEndP; ++itP) { - Element* parent = *itP; - parent->RemoveChild(child); - } - m_connectionList.erase(itCo--); - if(line) delete line; + itCo = DeleteLineFromList(itCo); break; } } @@ -631,20 +627,39 @@ void ControlEditor::DeleteSelectedElements() for(auto it = m_connectionList.begin(); it != m_connectionList.end(); ++it) { ConnectionLine* line = *it; if(line->IsSelected()) { - auto parentList = line->GetParentList(); - for(auto itP = parentList.begin(), itEnd = parentList.end(); itP != itEnd; ++itP) { - Element* parent = *itP; - if(parent) parent->RemoveChild(line); - } - // Free nodes - auto nodeList = line->GetNodeList(); - for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { - Node* node = *itN; - node->SetConnected(false); - } - m_connectionList.erase(it--); - if(line) delete line; + it = DeleteLineFromList(it); } } Redraw(); } + +std::vector<ConnectionLine*>::iterator ControlEditor::DeleteLineFromList(std::vector<ConnectionLine*>::iterator& it) +{ + ConnectionLine* cLine = *it; + auto childList = cLine->GetLineChildList(); + for(auto itC = childList.begin(), itEndC = childList.end(); itC != itEndC; ++itC) { + ConnectionLine* child = *itC; + //child->GetParentLine()->RemoveChild(child); Error + for(auto itL = m_connectionList.begin(); itL != m_connectionList.end(); ++itL) { + ConnectionLine* childOnList = *itL; + if(childOnList == child) { + itL = DeleteLineFromList(itL); + } + } + } + wxMessageBox(wxString::Format("%d", (int)cLine->GetChildList().size())); + auto parentList = cLine->GetParentList(); + for(auto itP = parentList.begin(), itEnd = parentList.end(); itP != itEnd; ++itP) { + Element* parent = *itP; + if(parent) parent->RemoveChild(cLine); + } + // Free nodes + auto nodeList = cLine->GetNodeList(); + for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { + Node* node = *itN; + node->SetConnected(false); + } + m_connectionList.erase(it--); + if(cLine) delete cLine; + return it; +} diff --git a/Project/ControlEditor.h b/Project/ControlEditor.h index 73c2c62..8d499fc 100644 --- a/Project/ControlEditor.h +++ b/Project/ControlEditor.h @@ -10,6 +10,7 @@ #include <GL/glu.h> class Camera; +class Element; class ControlElement; class TransferFunction; class ConnectionLine; @@ -83,6 +84,8 @@ protected: void BuildControlElementPanel(); void SetViewport(); + std::vector<ConnectionLine*>::iterator DeleteLineFromList(std::vector<ConnectionLine*>::iterator& it); + wxGLContext* m_glContext = NULL; Camera* m_camera = NULL; @@ -90,10 +93,10 @@ protected: wxRect2DDouble m_selectionRect; wxPoint2DDouble m_startSelRect; - + std::vector<ControlElement*> m_elementList; std::vector<ConnectionLine*> m_connectionList; - + bool m_firstDraw = true; }; #endif // CONTROLEDITOR_H diff --git a/Project/Project.mk b/Project/Project.mk index 78d0569..0518120 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Thales -Date :=04/03/2017 +Date :=06/03/2017 CodeLitePath :="C:/Program Files/CodeLite" LinkerName :=C:/TDM-GCC-64/bin/g++.exe SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC |