Advertisement
Korotkodul

N2

Mar 16th, 2025 (edited)
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.86 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. int main ()
  14. try
  15. {
  16.   int win_w = 600;
  17.   int win_h = 400;
  18.   Graph_lib::Point lt{ Graph_lib::x_max()/2 - win_w/2, Graph_lib::y_max()/2 - win_h/2 };
  19.   Simple_window win{ lt, win_w, win_h, "Scheme of Logic Elements" };
  20.   //win.wait_for_button();
  21.  
  22.   using namespace Logic;
  23.  
  24.   //
  25.   /*Source src1;
  26.   Source src2;
  27.   Source src3;
  28.   Source src4;
  29.   Source src5;
  30.   Source src6;
  31.   Source src7;*/
  32.  
  33.   Source A0;
  34.   Source A1;
  35.   Source A2;
  36.   Source A3;
  37.   Source B0;
  38.   Source B1;
  39.   Source B2;
  40.   Source B3;
  41.  
  42.   And and0;
  43.   And and1;
  44.   And and2;
  45.   And and3;
  46.   //And and6;
  47.   //And and7{ Out_state::inverted };
  48.   //And and8{ Out_state::inverted };
  49.  
  50.   //Or or1;
  51.   //Or or2;
  52.   //Or or3;
  53.   Or nor{ Out_state::inverted };
  54.  
  55.   A0 >> and0;
  56.   B0 >> and0;
  57.   A1 >> and1;
  58.   B1 >> and1;
  59.   A2 >> and2;
  60.   B2 >> and2;
  61.   A3 >> and3;
  62.   B3 >> and3;
  63.  
  64.   //
  65.   /*src2 >> ~and1;
  66.   src4 >> ~and1 >> or2 >> and5 >> and7;
  67.   src3 >> ~and2 >> or2;
  68.   src5 >> ~and2;
  69.  
  70.   src6 >> and5;
  71.   src6 >> and6;
  72.  
  73.   src7 >> and7;
  74.   src7 >> and8;
  75.  
  76.   src4 >>  and3;
  77.   src2 >> ~and3 >> or3 >> ~and5;
  78.   src5 >>  and4 >> or3;
  79.   src3 >> ~and4;
  80.   src1 >> ~or1 >> or3 >> and6 >> and8;
  81.   src1 >> ~or1;*/
  82.  
  83.   //
  84.   SchemeShape scheme{ Graph_lib::Point{5, 5}, win_w - 80, win_h - 10 };
  85.  
  86.   win.attach(scheme);
  87.  
  88.   auto column_x = [] (double c) -> int
  89.   {
  90.     return int(30 + 100 * c);
  91.   };
  92.  
  93.   auto line_y = [] (double l) -> int
  94.   {
  95.     return int(40 + 75 * l);
  96.   };
  97.   SourceShape A0_shape{ scheme, A0, "A0", Graph_lib::Point{ column_x(0), line_y(0) } };
  98.   SourceShape B0_shape{ scheme, B0, "B0", Graph_lib::Point{ column_x(0), line_y(1) } };
  99.  
  100.   SourceShape A1_shape{ scheme, A1, "A1", Graph_lib::Point{ column_x(0), line_y(2) } };
  101.   SourceShape B1_shape{ scheme, B1, "B1", Graph_lib::Point{ column_x(0), line_y(3) } };
  102.  
  103.   SourceShape A2_shape{ scheme, A2, "A2", Graph_lib::Point{ column_x(0), line_y(4) } };
  104.   SourceShape B2_shape{ scheme, B2, "B2", Graph_lib::Point{ column_x(0), line_y(5) } };
  105.  
  106.   SourceShape A3_shape{ scheme, A3, "A3", Graph_lib::Point{ column_x(0), line_y(6) } };
  107.   SourceShape B3_shape{ scheme, B3, "B3", Graph_lib::Point{ column_x(0), line_y(7) } };
  108.  
  109.    AndShape and0_shape{ scheme, and0, "and0", Graph_lib::Point{ column_x(1), line_y(1) } };
  110.    AndShape and1_shape{ scheme, and1, "and1", Graph_lib::Point{ column_x(1), line_y(3) } };
  111.    AndShape and2_shape{ scheme, and2, "and2", Graph_lib::Point{ column_x(1), line_y(5) } };
  112.    AndShape and3_shape{ scheme, and3, "and3", Graph_lib::Point{ column_x(1), line_y(7) } };
  113.  
  114.   /*SourceShape src_shape1{ scheme, src1, "src1", Graph_lib::Point{ column_x(0), line_y(4) } };
  115.   SourceShape src_shape2{ scheme, src2, "src2", Graph_lib::Point{ column_x(0), line_y(0) } };
  116.   SourceShape src_shape3{ scheme, src3, "src3", Graph_lib::Point{ column_x(0), line_y(1) } };
  117.   SourceShape src_shape4{ scheme, src4, "src4", Graph_lib::Point{ column_x(0), line_y(2) } };
  118.   SourceShape src_shape5{ scheme, src5, "src5", Graph_lib::Point{ column_x(0), line_y(3) } };
  119.   SourceShape src_shape6{ scheme, src6, "src6", Graph_lib::Point{ column_x(2), line_y(2) } };
  120.   SourceShape src_shape7{ scheme, src7, "src7", Graph_lib::Point{ column_x(3), line_y(2) + 5 } };
  121.  
  122.   AndShape and_shape1{ scheme, and1, "and1", Graph_lib::Point{ column_x(1), line_y(0) + 5 } };
  123.   AndShape and_shape2{ scheme, and2, "and2", Graph_lib::Point{ column_x(1), line_y(1) + 5 } };
  124.   AndShape and_shape3{ scheme, and3, "and3", Graph_lib::Point{ column_x(1), line_y(2) + 5 } };
  125.   AndShape and_shape4{ scheme, and4, "and4", Graph_lib::Point{ column_x(1), line_y(3) + 5 } };
  126.   AndShape and_shape5{ scheme, and5, "and5", Graph_lib::Point{ column_x(3), line_y(1) + 6 }, DEFAULT_WIDTH, DEFAULT_HEIGHT + DEFAULT_HEIGHT / 3 };
  127.   AndShape and_shape6{ scheme, and6, "and6", Graph_lib::Point{ column_x(3), line_y(3) } };
  128.   AndShape and_shape7{ scheme, and7, "and7", Graph_lib::Point{ column_x(4), line_y(1) + 17 } };
  129.   AndShape and_shape8{ scheme, and8, "and8", Graph_lib::Point{ column_x(4), line_y(3) - 5 } };
  130.  
  131.   OrShape or_shape1{ scheme, or1, "or1", Graph_lib::Point{ column_x(1), line_y(4) } };
  132.   OrShape or_shape2{ scheme, or2, "or2", Graph_lib::Point{ column_x(2), line_y(1) } };
  133.   OrShape or_shape3{ scheme, or3, "or3", Graph_lib::Point{ column_x(2), line_y(3) }, DEFAULT_WIDTH, DEFAULT_HEIGHT + DEFAULT_HEIGHT / 3  };
  134. */
  135.   scheme.update_connections();
  136.  
  137.   win.wait_for_button();
  138.  
  139.   /*src1 = true;
  140.   src6 = true;
  141.   src7 = true;
  142.  
  143.   win.wait_for_button();
  144.  
  145.   src4 = true;
  146.  
  147.   win.wait_for_button();
  148.   */
  149.   return 0;
  150. }
  151. catch (std::exception& e)
  152. {
  153.   std::cerr << e.what() << std::endl;
  154.   return 1;
  155. }
  156. catch (...)
  157. {
  158.   std::cerr <<"Oops, something went wrong..."<< std::endl;
  159.   return 2;
  160. }
  161.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement