Advertisement
Korotkodul

logic_main.cpp1

Mar 16th, 2025 (edited)
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.58 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.  
  13.  
  14.  
  15. int main ()
  16. try
  17. {
  18.     int win_w = 600;
  19.     int win_h = 400;
  20.     Graph_lib::Point lt{ Graph_lib::x_max()/2 - win_w/2, Graph_lib::y_max()/2 - win_h/2 };
  21.     Simple_window win{ lt, win_w  , win_h * 1.5, "Scheme of Logic Elements" };
  22.    
  23.     using namespace Logic;
  24.  
  25.     Source A0;
  26.     Source A1;
  27.     Source A2;
  28.     Source A3;
  29.     Source B0;
  30.     Source B1;
  31.     Source B2;
  32.     Source B3;
  33.  
  34.     // Заменим And на Xor
  35.     Xor xor0;
  36.     Xor xor1;
  37.     Xor xor2;
  38.     Xor xor3;
  39.  
  40.     // Подключение источников к XOR
  41.     A0 >> xor0;
  42.     B0 >> xor0;
  43.     A1 >> xor1;
  44.     B1 >> xor1;
  45.     A2 >> xor2;
  46.     B2 >> xor2;
  47.     A3 >> xor3;
  48.     B3 >> xor3;
  49.  
  50.     // Объединение XOR
  51.     Or nor{ Out_state::inverted };
  52.  
  53.     xor0 >> nor;
  54.     xor1 >> nor;
  55.     xor2 >> nor;
  56.     xor3 >> nor;
  57.  
  58.     // Создание схемы
  59.     SchemeShape scheme{ Graph_lib::Point{5, 5}, win_w - 80, win_h - 10 };
  60.     win.attach(scheme);
  61.  
  62.     auto column_x = [] (double c) -> int
  63.     {
  64.         return int(30 + 100 * c);
  65.     };
  66.  
  67.     auto line_y = [] (double l) -> int
  68.     {
  69.         return int(40 + 75 * l);
  70.     };
  71.  
  72.     // Создание отображений для источников
  73.     SourceShape A0_shape{ scheme, A0, "A0", Graph_lib::Point{ column_x(0), line_y(0) } };
  74.     SourceShape B0_shape{ scheme, B0, "B0", Graph_lib::Point{ column_x(0), line_y(1) } };
  75.     SourceShape A1_shape{ scheme, A1, "A1", Graph_lib::Point{ column_x(0), line_y(2) } };
  76.     SourceShape B1_shape{ scheme, B1, "B1", Graph_lib::Point{ column_x(0), line_y(3) } };
  77.     SourceShape A2_shape{ scheme, A2, "A2", Graph_lib::Point{ column_x(0), line_y(4) } };
  78.     SourceShape B2_shape{ scheme, B2, "B2", Graph_lib::Point{ column_x(0), line_y(5) } };
  79.     SourceShape A3_shape{ scheme, A3, "A3", Graph_lib::Point{ column_x(0), line_y(6) } };
  80.     SourceShape B3_shape{ scheme, B3, "B3", Graph_lib::Point{ column_x(0), line_y(7) } };
  81.  
  82.     Graph_lib::Text TA0{ Graph_lib::Point{ column_x(0) + 10, line_y(0) + 20}, "-1" };
  83.     Graph_lib::Text TB0{ Graph_lib::Point{ column_x(0) + 10, line_y(1) + 20}, "-1" };
  84.     Graph_lib::Text TA1{ Graph_lib::Point{ column_x(0) + 10, line_y(2) + 20}, "-1" };
  85.     Graph_lib::Text TB1{ Graph_lib::Point{ column_x(0) + 10, line_y(3) + 20}, "-1" };
  86.     Graph_lib::Text TA2{ Graph_lib::Point{ column_x(0) + 10, line_y(4) + 20}, "-1" };
  87.     Graph_lib::Text TB2{ Graph_lib::Point{ column_x(0) + 10, line_y(5) + 20}, "-1" };
  88.     Graph_lib::Text TA3{ Graph_lib::Point{ column_x(0) + 10, line_y(6) + 20}, "-1" };
  89.     Graph_lib::Text TB3{ Graph_lib::Point{ column_x(0) + 10, line_y(7) + 20}, "-1" };
  90.  
  91.     TA0.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  92.     TA0.set_font_size(20);  // Увеличиваем размер шрифта
  93.     TA1.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  94.     TA1.set_font_size(20);  // Увеличиваем размер шрифта
  95.     TA2.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  96.     TA2.set_font_size(20);  // Увеличиваем размер шрифта
  97.     TA3.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  98.     TA3.set_font_size(20);  // Увеличиваем размер шрифта
  99.     TB0.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  100.     TB0.set_font_size(20);  // Увеличиваем размер шрифта
  101.     TB1.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  102.     TB1.set_font_size(20);  // Увеличиваем размер шрифта
  103.     TB2.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  104.     TB2.set_font_size(20);  // Увеличиваем размер шрифта
  105.     TB3.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  106.     TB3.set_font_size(20);  // Увеличиваем размер шрифта
  107.  
  108.     win.attach(TA0);
  109.     win.attach(TA1);
  110.     win.attach(TB0);
  111.     win.attach(TB1);
  112.     win.attach(TA2);
  113.     win.attach(TA3);
  114.     win.attach(TB2);
  115.     win.attach(TB3);
  116.  
  117.     // Заменим AndShape на XorShape
  118.     XorShape xor0_shape{ scheme, xor0, "xor0", Graph_lib::Point{ column_x(1), line_y(1) } };
  119.     XorShape xor1_shape{ scheme, xor1, "xor1", Graph_lib::Point{ column_x(1), line_y(3) } };
  120.     XorShape xor2_shape{ scheme, xor2, "xor2", Graph_lib::Point{ column_x(1), line_y(5) } };
  121.     XorShape xor3_shape{ scheme, xor3, "xor3", Graph_lib::Point{ column_x(1), line_y(7) } };
  122.  
  123.     Graph_lib::Text Txor0{ Graph_lib::Point{ column_x(1) + 10, line_y(1) + 20}, "-1" };
  124.     Graph_lib::Text Txor1{ Graph_lib::Point{ column_x(1) + 10, line_y(3) + 20}, "-1" };
  125.     Graph_lib::Text Txor2{ Graph_lib::Point{ column_x(1) + 10, line_y(5) + 20}, "-1" };
  126.     Graph_lib::Text Txor3{ Graph_lib::Point{ column_x(1) + 10, line_y(7) + 20}, "-1" };
  127.  
  128.     Txor0.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  129.     Txor0.set_font_size(20);  // Увеличиваем размер шрифта
  130.     Txor1.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  131.     Txor1.set_font_size(20);  // Увеличиваем размер шрифта
  132.     Txor2.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  133.     Txor2.set_font_size(20);  // Увеличиваем размер шрифта
  134.     Txor3.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  135.     Txor3.set_font_size(20);  // Увеличиваем размер шрифта
  136.  
  137.     win.attach(Txor0);
  138.     win.attach(Txor1);
  139.     win.attach(Txor2);
  140.     win.attach(Txor3);
  141.  
  142.  
  143.     // Создание отображения для объединения XOR
  144.     OrShape nor_shape{ scheme, nor, "nor", Graph_lib::Point{ column_x(2), line_y(4) } };
  145.     Graph_lib::Text Tnor{ Graph_lib::Point{ column_x(2) + 12, line_y(4) + 19 }, "-1" };
  146.     Tnor.set_font(Graph_lib::Font::helvetica_bold);  // Жирный шрифт
  147.     Tnor.set_font_size(20);  // Увеличиваем размер шрифта
  148.     win.attach(Tnor);
  149.  
  150.     // Обновляем соединения схемы
  151.     scheme.update_connections();
  152.  
  153.     // Ожидание нажатия кнопки
  154.     win.wait_for_button();
  155.  
  156.     return 0;
  157. }
  158. catch (std::exception& e)
  159. {
  160.     std::cerr << e.what() << std::endl;
  161.     return 1;
  162. }
  163. catch (...)
  164. {
  165.     std::cerr <<"Oops, something went wrong..."<< std::endl;
  166.     return 2;
  167. }
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement