summaryrefslogtreecommitdiffstats
path: root/Project
diff options
context:
space:
mode:
authorThales1330 <thaleslima.ufu@gmail.com>2017-03-04 17:14:52 -0300
committerThales1330 <thaleslima.ufu@gmail.com>2017-03-04 17:14:52 -0300
commitd11da00a993f1eeae6a1be50839ac72740e4e27b (patch)
treeda8c3327dbd077c37b3f5a0c0a5ac3ddffd14baa /Project
parent4ddc7be64451db873e49169e951532ce8893e359 (diff)
downloadPSP.git-d11da00a993f1eeae6a1be50839ac72740e4e27b.tar.gz
PSP.git-d11da00a993f1eeae6a1be50839ac72740e4e27b.tar.xz
PSP.git-d11da00a993f1eeae6a1be50839ac72740e4e27b.zip
Delete element implemented
Diffstat (limited to 'Project')
-rw-r--r--Project/ConnectionLine.cpp92
-rw-r--r--Project/ConnectionLine.h16
-rw-r--r--Project/ControlEditor.cpp76
-rw-r--r--Project/ControlEditor.h1
-rw-r--r--Project/ControlElement.cpp6
-rw-r--r--Project/ControlElement.h7
-rw-r--r--Project/Project.mk2
-rw-r--r--Project/TransferFunction.cpp15
8 files changed, 172 insertions, 43 deletions
diff --git a/Project/ConnectionLine.cpp b/Project/ConnectionLine.cpp
index 3cd6547..fefe144 100644
--- a/Project/ConnectionLine.cpp
+++ b/Project/ConnectionLine.cpp
@@ -9,6 +9,7 @@ ConnectionLine::ConnectionLine(Node* firstNode)
m_pointList.push_back(pt);
}
m_nodeList.push_back(firstNode);
+ firstNode->SetConnected();
}
ConnectionLine::~ConnectionLine() {}
@@ -46,44 +47,50 @@ bool ConnectionLine::Intersects(wxRect2DDouble rect) const
void ConnectionLine::UpdatePoints()
{
- bool hasOneNode = true;
- wxPoint2DDouble pt1 = m_nodeList[0]->GetPosition();
- wxPoint2DDouble pt2;
- if(m_nodeList.size() == 1)
- pt2 = m_tmpSndPt;
- else {
- pt2 = m_nodeList[1]->GetPosition();
- hasOneNode = false;
- }
- 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(hasOneNode)
- m_pointList[4] = pt2;
- else {
- if(m_nodeList[1]->GetAngle() == 0.0)
- m_pointList[4] = m_pointList[5] + wxPoint2DDouble(-10, 0);
- else if(m_nodeList[1]->GetAngle() == 90.0)
- m_pointList[4] = m_pointList[5] + wxPoint2DDouble(0, -10);
- else if(m_nodeList[1]->GetAngle() == 180.0)
- m_pointList[4] = m_pointList[5] + wxPoint2DDouble(10, 0);
- else if(m_nodeList[1]->GetAngle() == 270.0)
- m_pointList[4] = m_pointList[5] + wxPoint2DDouble(0, 10);
- }
+ if(m_type == ELEMENT_ELEMENT) {
+ bool hasOneNode = true;
+ wxPoint2DDouble pt1 = m_nodeList[0]->GetPosition();
+ wxPoint2DDouble pt2;
+ if(m_nodeList.size() == 1)
+ pt2 = m_tmpSndPt;
+ else {
+ pt2 = m_nodeList[1]->GetPosition();
+ hasOneNode = false;
+ }
+ 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[3] = m_pointList[4] + wxPoint2DDouble(0.0, midPt.m_y - m_pointList[4].m_y);
+ m_pointList[2] = m_pointList[1] + wxPoint2DDouble(0.0, midPt.m_y - m_pointList[1].m_y);
+
+ m_pointList[5] = pt2;
+ if(hasOneNode)
+ m_pointList[4] = pt2;
+ else {
+ if(m_nodeList[1]->GetAngle() == 0.0)
+ m_pointList[4] = m_pointList[5] + wxPoint2DDouble(-10, 0);
+ else if(m_nodeList[1]->GetAngle() == 90.0)
+ m_pointList[4] = m_pointList[5] + wxPoint2DDouble(0, -10);
+ else if(m_nodeList[1]->GetAngle() == 180.0)
+ m_pointList[4] = m_pointList[5] + wxPoint2DDouble(10, 0);
+ else if(m_nodeList[1]->GetAngle() == 270.0)
+ 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);
+ } else if(m_type == ELEMENT_LINE) {
+ wxPoint2DDouble pt1 = m_nodeList[0]->GetPosition();
+ wxPoint2DDouble pt2 = m_parentLine->GetMidPoint();
+ //CONTINUE...
+ }
}
bool ConnectionLine::AppendNode(Node* node, ControlElement* parent)
@@ -98,6 +105,7 @@ bool ConnectionLine::AppendNode(Node* node, ControlElement* parent)
}
m_nodeList.push_back(node);
+ node->SetConnected();
return true;
}
@@ -112,3 +120,13 @@ void ConnectionLine::StartMove(wxPoint2DDouble position)
m_moveStartPtY = position.m_y;
m_moveStartOffset = m_lineOffset;
}
+
+wxPoint2DDouble ConnectionLine::GetMidPoint() const { return ((m_pointList[2] + m_pointList[3]) / 2.0); }
+
+void ConnectionLine::SetParentLine(ConnectionLine* parent)
+{
+ if(parent) {
+ m_type = ELEMENT_LINE;
+ m_parentLine = parent;
+ }
+}
diff --git a/Project/ConnectionLine.h b/Project/ConnectionLine.h
index cc7b51e..b39fe15 100644
--- a/Project/ConnectionLine.h
+++ b/Project/ConnectionLine.h
@@ -6,6 +6,10 @@
class ConnectionLine : public ControlElement
{
public:
+ enum ConnectionLineType {
+ ELEMENT_ELEMENT = 0,
+ ELEMENT_LINE
+ };
ConnectionLine(Node* firstNode);
~ConnectionLine();
@@ -16,13 +20,23 @@ public:
virtual void Move(wxPoint2DDouble position);
virtual bool AppendNode(Node* node, ControlElement* parent);
virtual void UpdatePoints();
- virtual void SetTemporarySecondPoint(wxPoint2DDouble point) { m_tmpSndPt = point; };
+ virtual void SetTemporarySecondPoint(wxPoint2DDouble point) { m_tmpSndPt = point; }
+ virtual wxPoint2DDouble GetMidPoint() const;
+
+ virtual ConnectionLineType GetType() const { return m_type; }
+ virtual void SetType(ConnectionLineType newType) { m_type = newType; }
+
+ virtual ConnectionLine* GetParentLine() const { return m_parentLine; }
+ virtual void SetParentLine(ConnectionLine* parent);
protected:
double m_lineOffset = 0.0;
double m_moveStartPtY = 0.0;
double m_moveStartOffset = 0.0;
wxPoint2DDouble m_tmpSndPt;
+
+ ConnectionLineType m_type = ELEMENT_ELEMENT;
+ ConnectionLine* m_parentLine = NULL;
};
#endif // CONNECTIONLINE_H
diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp
index bfc81ad..84a2650 100644
--- a/Project/ControlEditor.cpp
+++ b/Project/ControlEditor.cpp
@@ -278,6 +278,11 @@ void ControlEditor::OnDoubleClick(wxMouseEvent& event)
Element* element = *it;
if(element->Contains(m_camera->ScreenToWorld(clickPoint))) {
element->ShowForm(this, element);
+ auto childList = element->GetChildList();
+ for(auto itC = childList.begin(), itEndC = childList.end(); itC != itEndC; ++itC) {
+ ConnectionLine* line = static_cast<ConnectionLine*>(*itC);
+ line->UpdatePoints();
+ }
redraw = true;
}
}
@@ -398,13 +403,20 @@ void ControlEditor::OnLeftClickUp(wxMouseEvent& event)
if(m_mode == MODE_INSERT_LINE && !foundNode) {
ConnectionLine* line = *(m_connectionList.end() - 1);
+ // 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 associated child from parents.
auto parentList = line->GetParentList();
for(auto it = parentList.begin(), itEnd = parentList.end(); it != itEnd; ++it) {
Element* element = *it;
element->RemoveChild(line);
}
- delete line;
m_connectionList.pop_back();
+ if(line) delete line;
m_mode = MODE_EDIT;
} else if(m_mode != MODE_INSERT) {
m_mode = MODE_EDIT;
@@ -551,6 +563,10 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event)
char key = event.GetUnicodeKey();
if(key != WXK_NONE) {
switch(key) {
+ case WXK_DELETE: // Delete selected elements.
+ {
+ DeleteSelectedElements();
+ } break;
case 'R': // Rotate the selected elements.
{
RotateSelectedElements(event.GetModifiers() != wxMOD_SHIFT);
@@ -574,3 +590,61 @@ void ControlEditor::RotateSelectedElements(bool clockwise)
}
Redraw();
}
+
+void ControlEditor::DeleteSelectedElements()
+{
+ for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) {
+ Element* element = *it;
+ if(element->IsSelected()) {
+ // Remove child/parent.
+ auto childList = element->GetChildList();
+ for(auto itC = childList.begin(), itEnd = childList.end(); itC != itEnd; ++itC) {
+ // The child is always a connection line.
+ ConnectionLine* child = static_cast<ConnectionLine*>(*itC);
+ // Delete the connection line.
+ 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;
+ break;
+ }
+ }
+ }
+ m_elementList.erase(it--);
+ if(element) delete element;
+ }
+ }
+
+ 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;
+ }
+ }
+ Redraw();
+}
diff --git a/Project/ControlEditor.h b/Project/ControlEditor.h
index d4e99b7..73c2c62 100644
--- a/Project/ControlEditor.h
+++ b/Project/ControlEditor.h
@@ -65,6 +65,7 @@ public:
virtual void AddElement(ControlElementButtonID id);
virtual void Redraw() { m_glCanvas->Refresh(); }
virtual void RotateSelectedElements(bool clockwise);
+ virtual void DeleteSelectedElements();
protected:
virtual void OnKeyDown(wxKeyEvent& event);
diff --git a/Project/ControlElement.cpp b/Project/ControlElement.cpp
index a1f2fc1..cc7ba20 100644
--- a/Project/ControlElement.cpp
+++ b/Project/ControlElement.cpp
@@ -77,6 +77,12 @@ void Node::Rotate(bool clockwise)
if(m_angle != 0.0) RotateTriPt(m_angle);
}
+bool Node::Contains(wxPoint2DDouble position) const
+{
+ if(m_connected) return false;
+ return m_rect.Contains(position);
+}
+
ControlElement::ControlElement()
: Element()
{
diff --git a/Project/ControlElement.h b/Project/ControlElement.h
index dedcc80..2a516aa 100644
--- a/Project/ControlElement.h
+++ b/Project/ControlElement.h
@@ -32,11 +32,16 @@ public:
void StartMove(wxPoint2DDouble position);
void Move(wxPoint2DDouble position);
- bool Contains(wxPoint2DDouble position) const { return m_rect.Contains(position); }
+ bool Contains(wxPoint2DDouble position) const;
+
+ bool IsConnected() const { return m_connected; }
+ void SetConnected(bool connected = true) { m_connected = connected; }
protected:
wxRect2DDouble m_rect;
NodeType m_nodeType;
+
+ bool m_connected = false;
wxPoint2DDouble m_moveStartPt;
wxPoint2DDouble m_movePos;
diff --git a/Project/Project.mk b/Project/Project.mk
index 06bb923..78d0569 100644
--- a/Project/Project.mk
+++ b/Project/Project.mk
@@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=Thales
-Date :=03/03/2017
+Date :=04/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/TransferFunction.cpp b/Project/TransferFunction.cpp
index 34d082c..00e8fa2 100644
--- a/Project/TransferFunction.cpp
+++ b/Project/TransferFunction.cpp
@@ -191,8 +191,19 @@ void TransferFunction::UpdateTFText()
GetTFString(num, den);
SetText(num, den);
if(m_nodeList.size() == 2) {
- m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0));
- m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0));
+ if(m_angle == 0.0) {
+ m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0));
+ m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0));
+ } else if(m_angle == 90.0) {
+ m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, -m_height / 2));
+ m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2));
+ } else if(m_angle == 180.0) {
+ m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0));
+ m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0));
+ } else if(m_angle == 270.0) {
+ m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2));
+ m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(0, -m_height / 2));
+ }
}
}