summaryrefslogtreecommitdiff
path: root/MainWindow.cpp
diff options
context:
space:
mode:
authorDaniel Jones <admin@danieljon.es>2020-06-24 21:24:22 +0930
committerDaniel Jones <admin@danieljon.es>2020-06-24 21:24:22 +0930
commit91aff1783d364f3f2c814a90ec292cb89d5deb88 (patch)
tree464d2c2adcf8977c1e3a355783194a50fca7d136 /MainWindow.cpp
parent19c61272bde25dbf1991bcb3ad31d173cda92df2 (diff)
downloadfoxlogicgates-91aff1783d364f3f2c814a90ec292cb89d5deb88.tar.gz
foxlogicgates-91aff1783d364f3f2c814a90ec292cb89d5deb88.zip
functionality: implemented deleting selected gate with the delete key.
Diffstat (limited to 'MainWindow.cpp')
-rw-r--r--MainWindow.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/MainWindow.cpp b/MainWindow.cpp
index 23ca61c..8b22243 100644
--- a/MainWindow.cpp
+++ b/MainWindow.cpp
@@ -604,6 +604,7 @@ MainWindow::on_key_release(FXObject *sender, FXSelector sel, void *ptr)
{
if (selected_input.gate != nullptr)
{
+ /* delete link */
switch (selected_input.input)
{
case 1:
@@ -622,8 +623,59 @@ MainWindow::on_key_release(FXObject *sender, FXSelector sel, void *ptr)
selected_input.input = -1;
draw();
}
+ else if (selected_gate)
+ {
+ /* delete gate and all associations */
+ /*
+ * 2 inputs
+ * x outputs
+ *
+ * inputs:
+ * if input1/2 != null:
+ * call their remove_gate_id with this gate id
+ * update that gate
+ * outputs:
+ * iterate through ouputs
+ * call remove_input_gate with this gate id
+ * update that gate
+ */
+ Gate *gate;
+ /* delete inputs */
+ if (selected_gate->get_input_gate1())
+ {
+ selected_gate->get_input_gate1()->remove_output_gate_id(selected_gate->get_id());
+ update_gate_state(selected_gate->get_input_gate1());
+ }
+ if (selected_gate->get_input_gate2())
+ {
+ selected_gate->get_input_gate2()->remove_output_gate_id(selected_gate->get_id());
+ update_gate_state(selected_gate->get_input_gate2());
+ }
+
+ /* delete outputs */
+ for(auto g = selected_gate->get_output_gates()->begin(); g != selected_gate->get_output_gates()->end(); ++g)
+ {
+ gate = find_gate_by_id((*g));
+ if (!gate)
+ continue;
+ gate->remove_input_gate(selected_gate->get_id());
+ update_gate_state(gate);
+ }
+ int pos = 0;
+ for (auto g = gates.begin(); g != gates.end(); ++g)
+ {
+ gate = (*g).get();
+ if (gate->get_id() == selected_gate->get_id())
+ {
+ gates.erase(gates.begin() + pos);
+ break;
+ }
+ pos++;
+ }
+ }
break;
}
+
default:
this->onKeyPress(sender, sel, ptr);
break;