Advertisement
Korotkodul

logic_main.cpp

Mar 16th, 2025
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <exception>
  4.  
  5. #include <Graph_lib/Graph.h>
  6. #include <Graph_lib/Window.h>
  7. #include <Graph_lib/Simple_window.h>
  8.  
  9. #include "logic.h"
  10. #include "logic_shapes.h"
  11.  
  12. int main ()
  13. try
  14. {
  15.     int win_w = 600;
  16.     int win_h = 400;
  17.     Graph_lib::Point lt{ Graph_lib::x_max()/2 - win_w/2, Graph_lib::y_max()/2 - win_h/2 };
  18.     Simple_window win{ lt, win_w  , win_h * 1.5, "Scheme of Logic Elements" };
  19.    
  20.     using namespace Logic;
  21.  
  22.     Source A0;
  23.     Source A1;
  24.     Source A2;
  25.     Source A3;
  26.     Source B0;
  27.     Source B1;
  28.     Source B2;
  29.     Source B3;
  30.  
  31.     // Заменим And на Xor
  32.     Xor xor0;
  33.     Xor xor1;
  34.     Xor xor2;
  35.     Xor xor3;
  36.  
  37.     // Подключение источников к XOR
  38.     A0 >> xor0;
  39.     B0 >> xor0;
  40.     A1 >> xor1;
  41.     B1 >> xor1;
  42.     A2 >> xor2;
  43.     B2 >> xor2;
  44.     A3 >> xor3;
  45.     B3 >> xor3;
  46.  
  47.     // Объединение XOR
  48.     Or nor{ Out_state::inverted };
  49.  
  50.     xor0 >> nor;
  51.     xor1 >> nor;
  52.     xor2 >> nor;
  53.     xor3 >> nor;
  54.  
  55.     // Создание схемы
  56.     SchemeShape scheme{ Graph_lib::Point{5, 5}, win_w - 80, win_h - 10 };
  57.     win.attach(scheme);
  58.  
  59.     auto column_x = [] (double c) -> int
  60.     {
  61.         return int(30 + 100 * c);
  62.     };
  63.  
  64.     auto line_y = [] (double l) -> int
  65.     {
  66.         return int(40 + 75 * l);
  67.     };
  68.  
  69.     // Создание отображений для источников
  70.     SourceShape A0_shape{ scheme, A0, "A0", Graph_lib::Point{ column_x(0), line_y(0) } };
  71.     SourceShape B0_shape{ scheme, B0, "B0", Graph_lib::Point{ column_x(0), line_y(1) } };
  72.     SourceShape A1_shape{ scheme, A1, "A1", Graph_lib::Point{ column_x(0), line_y(2) } };
  73.     SourceShape B1_shape{ scheme, B1, "B1", Graph_lib::Point{ column_x(0), line_y(3) } };
  74.     SourceShape A2_shape{ scheme, A2, "A2", Graph_lib::Point{ column_x(0), line_y(4) } };
  75.     SourceShape B2_shape{ scheme, B2, "B2", Graph_lib::Point{ column_x(0), line_y(5) } };
  76.     SourceShape A3_shape{ scheme, A3, "A3", Graph_lib::Point{ column_x(0), line_y(6) } };
  77.     SourceShape B3_shape{ scheme, B3, "B3", Graph_lib::Point{ column_x(0), line_y(7) } };
  78.  
  79.     // Заменим AndShape на XorShape
  80.     XorShape xor0_shape{ scheme, xor0, "xor0", Graph_lib::Point{ column_x(1), line_y(1) } };
  81.     XorShape xor1_shape{ scheme, xor1, "xor1", Graph_lib::Point{ column_x(1), line_y(3) } };
  82.     XorShape xor2_shape{ scheme, xor2, "xor2", Graph_lib::Point{ column_x(1), line_y(5) } };
  83.     XorShape xor3_shape{ scheme, xor3, "xor3", Graph_lib::Point{ column_x(1), line_y(7) } };
  84.  
  85.     // Создание отображения для объединения XOR
  86.     OrShape nor_shape{ scheme, nor, "nor", Graph_lib::Point{ column_x(2), line_y(4) } };
  87.  
  88.     // Обновляем соединения схемы
  89.     scheme.update_connections();
  90.  
  91.     // Ожидание нажатия кнопки
  92.     win.wait_for_button();
  93.  
  94.     return 0;
  95. }
  96. catch (std::exception& e)
  97. {
  98.     std::cerr << e.what() << std::endl;
  99.     return 1;
  100. }
  101. catch (...)
  102. {
  103.     std::cerr <<"Oops, something went wrong..."<< std::endl;
  104.     return 2;
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement