Advertisement
Korotkodul

logic1

Mar 16th, 2025
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.02 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 * 1.5, "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.   and0 >> nor;
  65.   and1 >> nor;
  66.   and2 >> nor;
  67.   and3 >> nor;
  68.  
  69.   //
  70.   /*src2 >> ~and1;
  71.   src4 >> ~and1 >> or2 >> and5 >> and7;
  72.   src3 >> ~and2 >> or2;
  73.   src5 >> ~and2;
  74.  
  75.   src6 >> and5;
  76.   src6 >> and6;
  77.  
  78.   src7 >> and7;
  79.   src7 >> and8;
  80.  
  81.   src4 >>  and3;
  82.   src2 >> ~and3 >> or3 >> ~and5;
  83.   src5 >>  and4 >> or3;
  84.   src3 >> ~and4;
  85.   src1 >> ~or1 >> or3 >> and6 >> and8;
  86.   src1 >> ~or1;*/
  87.  
  88.   //
  89.   SchemeShape scheme{ Graph_lib::Point{5, 5}, win_w - 80, win_h - 10 };
  90.  
  91.   win.attach(scheme);
  92.  
  93.   auto column_x = [] (double c) -> int
  94.   {
  95.     return int(30 + 100 * c);
  96.   };
  97.  
  98.   auto line_y = [] (double l) -> int
  99.   {
  100.     return int(40 + 75 * l);
  101.   };
  102.   SourceShape A0_shape{ scheme, A0, "A0", Graph_lib::Point{ column_x(0), line_y(0) } };
  103.   SourceShape B0_shape{ scheme, B0, "B0", Graph_lib::Point{ column_x(0), line_y(1) } };
  104.  
  105.   SourceShape A1_shape{ scheme, A1, "A1", Graph_lib::Point{ column_x(0), line_y(2) } };
  106.   SourceShape B1_shape{ scheme, B1, "B1", Graph_lib::Point{ column_x(0), line_y(3) } };
  107.  
  108.   SourceShape A2_shape{ scheme, A2, "A2", Graph_lib::Point{ column_x(0), line_y(4) } };
  109.   SourceShape B2_shape{ scheme, B2, "B2", Graph_lib::Point{ column_x(0), line_y(5) } };
  110.  
  111.   SourceShape A3_shape{ scheme, A3, "A3", Graph_lib::Point{ column_x(0), line_y(6) } };
  112.   SourceShape B3_shape{ scheme, B3, "B3", Graph_lib::Point{ column_x(0), line_y(7) } };
  113.  
  114.    AndShape and0_shape{ scheme, and0, "and0", Graph_lib::Point{ column_x(1), line_y(1) } };
  115.    AndShape and1_shape{ scheme, and1, "and1", Graph_lib::Point{ column_x(1), line_y(3) } };
  116.    AndShape and2_shape{ scheme, and2, "and2", Graph_lib::Point{ column_x(1), line_y(5) } };
  117.    AndShape and3_shape{ scheme, and3, "and3", Graph_lib::Point{ column_x(1), line_y(7) } };
  118.  
  119.    OrShape nor_shape{ scheme, nor, "nor", Graph_lib::Point{ column_x(2), line_y(4) } };
  120.  
  121.   /*SourceShape src_shape1{ scheme, src1, "src1", Graph_lib::Point{ column_x(0), line_y(4) } };
  122.   SourceShape src_shape2{ scheme, src2, "src2", Graph_lib::Point{ column_x(0), line_y(0) } };
  123.   SourceShape src_shape3{ scheme, src3, "src3", Graph_lib::Point{ column_x(0), line_y(1) } };
  124.   SourceShape src_shape4{ scheme, src4, "src4", Graph_lib::Point{ column_x(0), line_y(2) } };
  125.   SourceShape src_shape5{ scheme, src5, "src5", Graph_lib::Point{ column_x(0), line_y(3) } };
  126.   SourceShape src_shape6{ scheme, src6, "src6", Graph_lib::Point{ column_x(2), line_y(2) } };
  127.   SourceShape src_shape7{ scheme, src7, "src7", Graph_lib::Point{ column_x(3), line_y(2) + 5 } };
  128.  
  129.   AndShape and_shape1{ scheme, and1, "and1", Graph_lib::Point{ column_x(1), line_y(0) + 5 } };
  130.   AndShape and_shape2{ scheme, and2, "and2", Graph_lib::Point{ column_x(1), line_y(1) + 5 } };
  131.   AndShape and_shape3{ scheme, and3, "and3", Graph_lib::Point{ column_x(1), line_y(2) + 5 } };
  132.   AndShape and_shape4{ scheme, and4, "and4", Graph_lib::Point{ column_x(1), line_y(3) + 5 } };
  133.   AndShape and_shape5{ scheme, and5, "and5", Graph_lib::Point{ column_x(3), line_y(1) + 6 }, DEFAULT_WIDTH, DEFAULT_HEIGHT + DEFAULT_HEIGHT / 3 };
  134.   AndShape and_shape6{ scheme, and6, "and6", Graph_lib::Point{ column_x(3), line_y(3) } };
  135.   AndShape and_shape7{ scheme, and7, "and7", Graph_lib::Point{ column_x(4), line_y(1) + 17 } };
  136.   AndShape and_shape8{ scheme, and8, "and8", Graph_lib::Point{ column_x(4), line_y(3) - 5 } };
  137.  
  138.   OrShape or_shape1{ scheme, or1, "or1", Graph_lib::Point{ column_x(1), line_y(4) } };
  139.   OrShape or_shape2{ scheme, or2, "or2", Graph_lib::Point{ column_x(2), line_y(1) } };
  140.   OrShape or_shape3{ scheme, or3, "or3", Graph_lib::Point{ column_x(2), line_y(3) }, DEFAULT_WIDTH, DEFAULT_HEIGHT + DEFAULT_HEIGHT / 3  };
  141. */
  142.   scheme.update_connections();
  143.  
  144.   win.wait_for_button();
  145.  
  146.   /*src1 = true;
  147.   src6 = true;
  148.   src7 = true;
  149.  
  150.   win.wait_for_button();
  151.  
  152.   src4 = true;
  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