summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThales1330 <thaleslima.ufu@gmail.com>2017-03-09 15:09:43 -0300
committerThales1330 <thaleslima.ufu@gmail.com>2017-03-09 15:09:43 -0300
commit21ebf63bb59357000f9bb44acde176d4ff169c01 (patch)
tree2e3603bb0640b089d81844c5d37a8f6b5ce8da33
parenta1890bd024e0baea393480810709f43208825b9a (diff)
downloadPSP.git-21ebf63bb59357000f9bb44acde176d4ff169c01.tar.gz
PSP.git-21ebf63bb59357000f9bb44acde176d4ff169c01.tar.xz
PSP.git-21ebf63bb59357000f9bb44acde176d4ff169c01.zip
Sum implemented
-rw-r--r--Project/ConnectionLine.cpp14
-rw-r--r--Project/ConnectionLine.h1
-rw-r--r--Project/ControlEditor.cpp15
-rw-r--r--Project/ControlEditor.h1
-rw-r--r--Project/Project.mk2
-rw-r--r--Project/Sum.cpp119
-rw-r--r--Project/Sum.h3
-rw-r--r--Project/SumForm.cpp18
8 files changed, 150 insertions, 23 deletions
diff --git a/Project/ConnectionLine.cpp b/Project/ConnectionLine.cpp
index ecbec1d..8a232fe 100644
--- a/Project/ConnectionLine.cpp
+++ b/Project/ConnectionLine.cpp
@@ -27,7 +27,7 @@ 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);
@@ -95,7 +95,7 @@ void ConnectionLine::UpdatePoints()
wxPoint2DDouble pt1 = m_nodeList[0]->GetPosition();
wxPoint2DDouble pt2 = m_parentLine->GetMidPoint();
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);
@@ -157,7 +157,7 @@ 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;
@@ -172,3 +172,11 @@ std::vector<ConnectionLine*> ConnectionLine::GetLineChildList() const
}
return childList;
}
+
+void ConnectionLine::RemoveParent(Element* parent)
+{
+ for(auto it = m_parentList.begin(); it != m_parentList.end(); ++it) {
+ Element* element = *it;
+ if(element == parent) m_parentList.erase(it--);
+ }
+}
diff --git a/Project/ConnectionLine.h b/Project/ConnectionLine.h
index 350c5d9..bb2dbcd 100644
--- a/Project/ConnectionLine.h
+++ b/Project/ConnectionLine.h
@@ -16,6 +16,7 @@ public:
virtual void Draw(wxPoint2DDouble translation, double scale) const;
virtual bool Contains(wxPoint2DDouble position) const;
virtual bool Intersects(wxRect2DDouble rect) const;
+ virtual void RemoveParent(Element* parent);
virtual void StartMove(wxPoint2DDouble position);
virtual void Move(wxPoint2DDouble position);
virtual bool AppendNode(Node* node, ControlElement* parent);
diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp
index 3638a42..3b6f8a5 100644
--- a/Project/ControlEditor.cpp
+++ b/Project/ControlEditor.cpp
@@ -103,7 +103,7 @@ ControlEditor::ControlEditor(wxWindow* parent)
m_glContext = new wxGLContext(m_glCanvas);
m_camera = new Camera();
m_selectionRect = wxRect2DDouble(0, 0, 0, 0);
- //m_camera->SetScale(1.2);
+ // m_camera->SetScale(1.2);
}
ControlEditor::~ControlEditor()
{
@@ -282,6 +282,7 @@ void ControlEditor::OnDoubleClick(wxMouseEvent& event)
Element* element = *it;
if(element->Contains(m_camera->ScreenToWorld(clickPoint))) {
element->ShowForm(this, element);
+ CheckConnections();
auto childList = element->GetChildList();
for(auto itC = childList.begin(), itEndC = childList.end(); itC != itEndC; ++itC) {
ConnectionLine* line = static_cast<ConnectionLine*>(*itC);
@@ -668,3 +669,15 @@ std::vector<ConnectionLine*>::iterator ControlEditor::DeleteLineFromList(std::ve
if(cLine) delete cLine;
return it;
}
+
+void ControlEditor::CheckConnections()
+{
+ for(auto it = m_connectionList.begin(); it != m_connectionList.end(); ++it) {
+ ConnectionLine* cLine = *it;
+ if(cLine->GetType() == ConnectionLine::ELEMENT_ELEMENT) {
+ if(cLine->GetParentList().size() < 2){
+ it = DeleteLineFromList(it);
+ }
+ }
+ }
+}
diff --git a/Project/ControlEditor.h b/Project/ControlEditor.h
index fd74d55..c9f47f8 100644
--- a/Project/ControlEditor.h
+++ b/Project/ControlEditor.h
@@ -68,6 +68,7 @@ public:
virtual void Redraw() { m_glCanvas->Refresh(); }
virtual void RotateSelectedElements(bool clockwise);
virtual void DeleteSelectedElements();
+ virtual void CheckConnections();
protected:
virtual void OnKeyDown(wxKeyEvent& event);
diff --git a/Project/Project.mk b/Project/Project.mk
index 3cf1d99..284769d 100644
--- a/Project/Project.mk
+++ b/Project/Project.mk
@@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=Thales
-Date :=08/03/2017
+Date :=09/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
diff --git a/Project/Sum.cpp b/Project/Sum.cpp
index 4d4303f..d814bbe 100644
--- a/Project/Sum.cpp
+++ b/Project/Sum.cpp
@@ -39,26 +39,53 @@ void Sum::Draw(wxPoint2DDouble translation, double scale) const
// Plot signals.
glLineWidth(2.0);
+ wxPoint2DDouble signalOffset[4];
+ wxPoint2DDouble sigmaOffset;
+ if(m_angle == 0.0) {
+ signalOffset[0] = wxPoint2DDouble(6, 0);
+ signalOffset[1] = wxPoint2DDouble(12, 0);
+ signalOffset[2] = wxPoint2DDouble(9, -3);
+ signalOffset[3] = wxPoint2DDouble(9, 3);
+ sigmaOffset = wxPoint2DDouble(6, 0);
+ } else if(m_angle == 90.0) {
+ signalOffset[0] = wxPoint2DDouble(-3, 9);
+ signalOffset[1] = wxPoint2DDouble(3, 9);
+ signalOffset[2] = wxPoint2DDouble(0, 6);
+ signalOffset[3] = wxPoint2DDouble(0, 12);
+ sigmaOffset = wxPoint2DDouble(0, 6);
+ } else if(m_angle == 180.0) {
+ signalOffset[0] = wxPoint2DDouble(-6, 0);
+ signalOffset[1] = wxPoint2DDouble(-12, 0);
+ signalOffset[2] = wxPoint2DDouble(-9, -3);
+ signalOffset[3] = wxPoint2DDouble(-9, 3);
+ sigmaOffset = wxPoint2DDouble(-6, 0);
+ } else if(m_angle == 270.0) {
+ signalOffset[0] = wxPoint2DDouble(-3, -9);
+ signalOffset[1] = wxPoint2DDouble(3, -9);
+ signalOffset[2] = wxPoint2DDouble(0, -6);
+ signalOffset[3] = wxPoint2DDouble(0, -12);
+ sigmaOffset = wxPoint2DDouble(0, -6);
+ }
for(int i = 0; i < (int)m_nodeList.size() - 1; ++i) {
std::vector<wxPoint2DDouble> hLine;
- hLine.push_back(m_nodeList[i]->GetPosition() + wxPoint2DDouble(6, 0));
- hLine.push_back(m_nodeList[i]->GetPosition() + wxPoint2DDouble(12, 0));
+ hLine.push_back(m_nodeList[i]->GetPosition() + signalOffset[0]);
+ hLine.push_back(m_nodeList[i]->GetPosition() + signalOffset[1]);
DrawLine(hLine);
if(m_signalList[i] == SIGNAL_POSITIVE) {
std::vector<wxPoint2DDouble> vLine;
- vLine.push_back(m_nodeList[i]->GetPosition() + wxPoint2DDouble(9, -3));
- vLine.push_back(m_nodeList[i]->GetPosition() + wxPoint2DDouble(9, 3));
+ vLine.push_back(m_nodeList[i]->GetPosition() + signalOffset[2]);
+ vLine.push_back(m_nodeList[i]->GetPosition() + signalOffset[3]);
DrawLine(vLine);
}
}
// Plot sigma.
std::vector<wxPoint2DDouble> sigma;
- sigma.push_back(m_position + wxPoint2DDouble(10, 9));
- sigma.push_back(m_position + wxPoint2DDouble(0, 9));
- sigma.push_back(m_position + wxPoint2DDouble(6, 0));
- sigma.push_back(m_position + wxPoint2DDouble(0, -9));
- sigma.push_back(m_position + wxPoint2DDouble(10, -9));
+ sigma.push_back(m_position + wxPoint2DDouble(4, 9) + sigmaOffset);
+ sigma.push_back(m_position + wxPoint2DDouble(-6, 9) + sigmaOffset);
+ sigma.push_back(m_position + wxPoint2DDouble(0, 0) + sigmaOffset);
+ sigma.push_back(m_position + wxPoint2DDouble(-6, -9) + sigmaOffset);
+ sigma.push_back(m_position + wxPoint2DDouble(4, -9) + sigmaOffset);
glColor4d(0.0, 0.3, 1.0, 1.0);
DrawLine(sigma);
@@ -79,10 +106,78 @@ bool Sum::ShowForm(wxWindow* parent, Element* element)
void Sum::UpdatePoints()
{
- m_height = 18.0 * (m_nodeList.size() - 1);
+ if(m_angle == 0.0 || m_angle == 180.0) {
+ m_height = 18.0 * (m_nodeList.size() - 1);
+ m_width = 36.0;
+ } else {
+ m_width = 18.0 * (m_nodeList.size() - 1);
+ m_height = 42.0;
+ }
+
for(int i = 0; i < (int)m_nodeList.size() - 1; ++i) {
- m_nodeList[i]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 9 + 18 * i - m_height / 2));
- m_nodeList[i]->StartMove(m_position);
+ if(m_angle == 0.0)
+ m_nodeList[i]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 9 + 18 * i - m_height / 2));
+ else if(m_angle == 90.0)
+ m_nodeList[i]->SetPosition(m_position + wxPoint2DDouble(m_width / 2 - 9 - 18 * i, -m_height / 2));
+ else if(m_angle == 180.0)
+ m_nodeList[i]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, m_height / 2 - 9 - 18 * i));
+ else if(m_angle == 270.0)
+ m_nodeList[i]->SetPosition(m_position + wxPoint2DDouble(9 + 18 * i - m_width / 2, m_height / 2));
}
+ if(m_angle == 0.0)
+ m_nodeList[m_nodeList.size() - 1]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0));
+ else if(m_angle == 90.0)
+ m_nodeList[m_nodeList.size() - 1]->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2));
+ else if(m_angle == 180.0)
+ m_nodeList[m_nodeList.size() - 1]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0));
+ else if(m_angle == 270.0)
+ m_nodeList[m_nodeList.size() - 1]->SetPosition(m_position + wxPoint2DDouble(0, -m_height / 2));
+
SetPosition(m_position); // Update rect.
}
+
+void Sum::AddInNode()
+{
+ Node* newNode = new Node(wxPoint2DDouble(0, 0), Node::NODE_IN, m_borderSize);
+ m_nodeList.insert(m_nodeList.end() - 1, newNode);
+}
+
+void Sum::RemoveInNode()
+{
+ Node* nodeToRemove = *(m_nodeList.end() - 2);
+ bool foundChild = false;
+ for(auto it = m_childList.begin(), itEnd = m_childList.end(); it != itEnd; ++it) {
+ ControlElement* child = static_cast<ControlElement*>(*it);
+ auto childNodeList = child->GetNodeList();
+ for(auto itN = childNodeList.begin(), itEndN = childNodeList.end(); itN != itEndN; ++itN) {
+ Node* node = *itN;
+ if(node == nodeToRemove) {
+ child->RemoveParent(this);
+ RemoveChild(child);
+ foundChild = true;
+ break;
+ }
+ }
+ if(foundChild) break;
+ }
+ m_nodeList.erase(m_nodeList.end() - 2);
+}
+
+void Sum::Rotate(bool clockwise)
+{
+ if(clockwise)
+ m_angle += 90.0;
+ else
+ m_angle -= 90.0;
+ if(m_angle >= 360.0)
+ m_angle = 0.0;
+ else if(m_angle < 0)
+ m_angle = 270.0;
+
+ UpdatePoints();
+
+ for(auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) {
+ Node* node = *it;
+ node->Rotate(clockwise);
+ }
+}
diff --git a/Project/Sum.h b/Project/Sum.h
index 4b12653..30bfb4e 100644
--- a/Project/Sum.h
+++ b/Project/Sum.h
@@ -16,11 +16,14 @@ public:
virtual bool Contains(wxPoint2DDouble position) const { return m_rect.Contains(position); }
virtual bool Intersects(wxRect2DDouble rect) const { return m_rect.Intersects(rect); }
virtual bool ShowForm(wxWindow* parent, Element* element);
+ virtual void Rotate(bool clockwise = true);
virtual std::vector<Signal> GetSignalList() const { return m_signalList; }
virtual void SetSignalList(std::vector<Signal> signalList) { m_signalList = signalList; }
virtual void UpdatePoints();
+ void AddInNode();
+ void RemoveInNode();
protected:
std::vector<Signal> m_signalList;
diff --git a/Project/SumForm.cpp b/Project/SumForm.cpp
index 4742eaa..2bb7c67 100644
--- a/Project/SumForm.cpp
+++ b/Project/SumForm.cpp
@@ -37,7 +37,11 @@ bool SumForm::ValidateData()
for(int i = 0; i < (int)m_textCtrlSigns->GetValue().length(); ++i) {
if(m_textCtrlSigns->GetValue()[i] != ' ') signalStr += m_textCtrlSigns->GetValue()[i];
}
- if(signalStr.size() < 2) return false;
+ if(signalStr.size() < 2){
+ wxMessageDialog msg(this, _("You must assign at least two signals."), _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
+ msg.ShowModal();
+ return false;
+ }
std::vector<Sum::Signal> signalList;
for(int i = 0; i < (int)signalStr.length(); ++i) {
@@ -49,6 +53,8 @@ bool SumForm::ValidateData()
signalList.push_back(Sum::SIGNAL_NEGATIVE);
} break;
default: {
+ wxMessageDialog msg(this, _("Value entered incorrectly in the field \"Signs\"."), _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
+ msg.ShowModal();
return false;
}
}
@@ -57,14 +63,14 @@ bool SumForm::ValidateData()
int diff = (int)signalList.size() - (int)m_sum->GetSignalList().size();
if(diff < 0) {
-
+ diff = std::abs(diff);
+ for(int i = 0; i < diff; ++i) {
+ m_sum->RemoveInNode();
+ }
} else if(diff > 0) {
- auto nodeList = m_sum->GetNodeList();
for(int i = 0; i < diff; ++i) {
- Node* newNode = new Node();
- nodeList.insert(nodeList.end() - 1, newNode);
+ m_sum->AddInNode();
}
- m_sum->SetNodeList(nodeList);
}
m_sum->SetSignalList(signalList);
m_sum->UpdatePoints();