diff options
-rw-r--r-- | Gate.cpp | 67 | ||||
-rw-r--r-- | Gate.h | 9 | ||||
-rw-r--r-- | MainWindow.cpp | 40 | ||||
-rw-r--r-- | MainWindow.h | 9 |
4 files changed, 119 insertions, 6 deletions
@@ -22,7 +22,7 @@ Gate::Gate(GATE_TYPE type, int x, int y, int width, int height) this->gate_type = type; this->input_gate1 = nullptr; this->input_gate2 = nullptr; - this->output_gate = nullptr; + //this->output_gate = nullptr; this->id = Gate::gate_id_counter++; // increment counter after assigning this->x = x; this->y = y; @@ -56,7 +56,6 @@ void Gate::update_state() break; } - case AND: { if (!input_gate1 || !input_gate2) {this->output_state = false; return; } @@ -117,3 +116,67 @@ void Gate::update_state() break; } } +std::string +Gate::get_output_type_text() +{ + std::string out; + switch (this->gate_type) + { + case INPUT: + { + return "INPUT"; + } + + case OUTPUT: + { + return "OUTPUT"; + } + + case AND: + { + return "AND"; + } + + + case OR: + { + return "OR"; + } + + + case NOT: + { + return "NOT"; + } + + + case NAND: + { + return "NAND"; + } + + + case NOR: + { + return "NOR"; + } + + + case XOR: + { + return "XOR"; + } + + + case XNOR: + { + return "XNOR"; + } + + default: + return "?"; + } + +} + + @@ -16,6 +16,8 @@ #ifndef GATE_H #define GATE_H +#include <string> + class Gate { public: @@ -45,13 +47,14 @@ class Gate GATE_TYPE get_gate_type() { return this->gate_type; }; Gate *get_input_gate1() { return this->input_gate1; }; Gate *get_input_gate2() { return this->input_gate2; }; - Gate *get_output_gate() { return this->output_gate; }; + //Gate *get_output_gate() { return this->output_gate; }; + std::string get_output_type_text(); void set_x(int x) { this->x = x; }; void set_y(int y) { this->y = y; }; void set_state(bool state) { this->output_state = state; }; void set_input_gate1(Gate *gate) { this->input_gate1 = gate; }; void set_input_gate2(Gate *gate) { this->input_gate2 = gate; }; - void set_output_gate(Gate *gate) { this->output_gate = gate; }; + //void set_output_gate(Gate *gate) { this->output_gate = gate; }; void update_state(); private: @@ -66,7 +69,7 @@ class Gate /* inputs/outputs */ Gate *input_gate1; Gate *input_gate2; - Gate *output_gate; + //Gate *output_gate; /* states */ bool output_state = false; diff --git a/MainWindow.cpp b/MainWindow.cpp index ccd1b12..91fd4a4 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -111,6 +111,27 @@ MainWindow::create_ui() new FXButton(toolsFrame, "XOR", XOR_icon, this, MainWindow::ID_BUTTON_XOR, BUTTON_NORMAL|LAYOUT_FILL_X); new FXButton(toolsFrame, "XNOR", XNOR_icon, this, MainWindow::ID_BUTTON_XNOR, BUTTON_NORMAL|LAYOUT_FILL_X); new FXButton(toolsFrame, "NOT", NOT_icon, this, MainWindow::ID_BUTTON_NOT, BUTTON_NORMAL|LAYOUT_FILL_X); + + optionsFrame = new FXVerticalFrame(contents, FRAME_SUNKEN|LAYOUT_FILL_Y|LAYOUT_TOP, 0, 0, 0, 0, 10, 10, 10, 10); + new FXLabel(optionsFrame, "Options", NULL, JUSTIFY_CENTER_X|LAYOUT_FILL_X); + new FXHorizontalSeparator(optionsFrame, SEPARATOR_RIDGE|LAYOUT_FILL_X); + + input1_frame = new FXHorizontalFrame(optionsFrame, LAYOUT_SIDE_TOP); + input2_frame = new FXHorizontalFrame(optionsFrame, LAYOUT_SIDE_TOP); + output_state_frame = new FXHorizontalFrame(optionsFrame, LAYOUT_SIDE_TOP); + + + new FXLabel(input1_frame, "Input 1: ", NULL, JUSTIFY_CENTER_X); + input_1_details = new FXLabel(input1_frame, "", NULL, JUSTIFY_CENTER_X); + input_1_details->setText("(None)"); + + new FXLabel(input2_frame, "Input 2: ", NULL, JUSTIFY_CENTER_X); + input_2_details = new FXLabel(input2_frame, "", NULL, JUSTIFY_CENTER_X); + input_2_details->setText("(None)"); + + new FXLabel(output_state_frame, "Output state: ", NULL, JUSTIFY_CENTER_X); + output_details = new FXLabel(output_state_frame, "", NULL, JUSTIFY_CENTER_X); + output_details->setText("(None)"); } void @@ -278,6 +299,20 @@ MainWindow::draw() } + /* update options panel */ + if (selected_gate) + { + input_1_details->setText((selected_gate->get_input_gate1() ? selected_gate->get_input_gate1()->get_output_type_text().c_str() : "(None)")); + input_2_details->setText((selected_gate->get_input_gate2() ? selected_gate->get_input_gate2()->get_output_type_text().c_str() : "(None)")); + output_details->setText(selected_gate->get_output_state() ? "ON" : "OFF"); + } + else + { + input_1_details->setText("(None)"); + input_2_details->setText("(None)"); + output_details->setText("(None)"); + } + FXDCWindow dc_canvas(canvas); dc_canvas.drawImage(canvas_image, 0, 0); } @@ -356,6 +391,7 @@ MainWindow::on_left_mouse_down(FXObject*, FXSelector, void *ptr) { dragging_link = true; } + gate->update_state(); } else { @@ -407,7 +443,8 @@ MainWindow::on_left_mouse_up(FXObject*, FXSelector, void *ptr) gate->set_input_gate1(selected_gate); } } - selected_gate->set_output_gate(gate); + //selected_gate->set_output_gate(gate); + gate->update_state(); } dragging_link = false; } @@ -428,6 +465,7 @@ MainWindow::on_right_mouse_down(FXObject*, FXSelector, void *ptr) gate->set_state(!gate->get_output_state()); } } + gate->update_state(); draw(); return 1; diff --git a/MainWindow.h b/MainWindow.h index 4a2362d..d150325 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -89,12 +89,21 @@ class MainWindow : public FXMainWindow FXHorizontalFrame *contents; FXVerticalFrame *canvasFrame; FXVerticalFrame *toolsFrame; + FXVerticalFrame *optionsFrame; FXScrollWindow *scroll_area; FXScrollWindow *toolbox_scroll_area; FXCanvas *canvas; FXBMPImage *canvas_image; FXApp *app; + FXHorizontalFrame *input1_frame; + FXHorizontalFrame *input2_frame; + FXHorizontalFrame *output_state_frame; + + FXLabel *input_1_details; + FXLabel *input_2_details; + FXLabel *output_details; + /* icons */ FXGIFIcon *INPUT_icon; FXGIFIcon *OUTPUT_icon; |