Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <exception>
- #include <Graph_lib/Graph.h>
- #include <Graph_lib/Window.h>
- #include <Graph_lib/Simple_window.h>
- #include "logic.h"
- #include "logic_shapes.h"
- int main ()
- try
- {
- int win_w = 600;
- int win_h = 400;
- Graph_lib::Point lt{ Graph_lib::x_max()/2 - win_w/2, Graph_lib::y_max()/2 - win_h/2 };
- Simple_window win{ lt, win_w , win_h * 1.5, "Scheme of Logic Elements" };
- using namespace Logic;
- Source A0;
- Source A1;
- Source A2;
- Source A3;
- Source B0;
- Source B1;
- Source B2;
- Source B3;
- // Заменим And на Xor
- Xor xor0;
- Xor xor1;
- Xor xor2;
- Xor xor3;
- // Подключение источников к XOR
- A0 >> xor0;
- B0 >> xor0;
- A1 >> xor1;
- B1 >> xor1;
- A2 >> xor2;
- B2 >> xor2;
- A3 >> xor3;
- B3 >> xor3;
- // Объединение XOR
- Or nor{ Out_state::inverted };
- xor0 >> nor;
- xor1 >> nor;
- xor2 >> nor;
- xor3 >> nor;
- // Создание схемы
- SchemeShape scheme{ Graph_lib::Point{5, 5}, win_w - 80, win_h - 10 };
- win.attach(scheme);
- auto column_x = [] (double c) -> int
- {
- return int(30 + 100 * c);
- };
- auto line_y = [] (double l) -> int
- {
- return int(40 + 75 * l);
- };
- // Создание отображений для источников
- SourceShape A0_shape{ scheme, A0, "A0", Graph_lib::Point{ column_x(0), line_y(0) } };
- SourceShape B0_shape{ scheme, B0, "B0", Graph_lib::Point{ column_x(0), line_y(1) } };
- SourceShape A1_shape{ scheme, A1, "A1", Graph_lib::Point{ column_x(0), line_y(2) } };
- SourceShape B1_shape{ scheme, B1, "B1", Graph_lib::Point{ column_x(0), line_y(3) } };
- SourceShape A2_shape{ scheme, A2, "A2", Graph_lib::Point{ column_x(0), line_y(4) } };
- SourceShape B2_shape{ scheme, B2, "B2", Graph_lib::Point{ column_x(0), line_y(5) } };
- SourceShape A3_shape{ scheme, A3, "A3", Graph_lib::Point{ column_x(0), line_y(6) } };
- SourceShape B3_shape{ scheme, B3, "B3", Graph_lib::Point{ column_x(0), line_y(7) } };
- // Заменим AndShape на XorShape
- XorShape xor0_shape{ scheme, xor0, "xor0", Graph_lib::Point{ column_x(1), line_y(1) } };
- XorShape xor1_shape{ scheme, xor1, "xor1", Graph_lib::Point{ column_x(1), line_y(3) } };
- XorShape xor2_shape{ scheme, xor2, "xor2", Graph_lib::Point{ column_x(1), line_y(5) } };
- XorShape xor3_shape{ scheme, xor3, "xor3", Graph_lib::Point{ column_x(1), line_y(7) } };
- // Создание отображения для объединения XOR
- OrShape nor_shape{ scheme, nor, "nor", Graph_lib::Point{ column_x(2), line_y(4) } };
- // Обновляем соединения схемы
- scheme.update_connections();
- // Ожидание нажатия кнопки
- win.wait_for_button();
- return 0;
- }
- catch (std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- return 1;
- }
- catch (...)
- {
- std::cerr <<"Oops, something went wrong..."<< std::endl;
- return 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement