Prepare structures for graphics
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Wed, 18 Dec 2024 14:53:21 +0000 (15:53 +0100)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Wed, 18 Dec 2024 14:53:21 +0000 (15:53 +0100)
inc/FET_sim.h
src/build_helper.c
src/c_addfet.c

index 602be8cc9c223465109b01f46f97be93d5597a42..a3f108cc93676668279fa61ce97d068ada9af750 100644 (file)
@@ -34,6 +34,28 @@ typedef enum e_type
 
 typedef unsigned long t_id;
 
+typedef enum e_orientation
+{
+       UP,
+       RIGHT,
+       DOWN,
+       LEFT,
+}      t_orientation;
+
+typedef chtype t_symbol;
+
+typedef struct s_position
+{
+       long    x;
+       long    y;
+}                      t_position;
+
+typedef struct s_node_segment
+{
+       t_position      position;
+       t_symbol        symbol;
+}                              t_node_segment;
+
 typedef struct s_node
 {
        t_id    id;
@@ -41,17 +63,20 @@ typedef struct s_node
        t_state state;
        t_state set_state;
        t_vec   connected;
+       t_vec   segments;
 }                      t_node;
 
 typedef struct s_mosfet
 {
-       t_id    id;
-       int             is_opened;
-       t_type  type;
-       t_node  *gate;
-       t_node  *source;
-       t_node  *drain;
-}                      t_mosfet;
+       t_id                    id;
+       int                             is_opened;
+       t_type                  type;
+       t_node                  *gate;
+       t_node                  *source;
+       t_node                  *drain;
+       t_position              position;
+       t_orientation   orientation;
+}                                      t_mosfet;
 
 typedef enum e_command
 {
@@ -107,7 +132,7 @@ typedef struct s_windows
 }                      t_windows;
 
 t_node         *add_node(t_vec *nodes, t_state set_state);
-t_mosfet       *add_mosfet(t_vec *mosfets, t_type type);
+t_mosfet       *add_mosfet(t_vec *mosfets, t_type type, t_position pos, t_orientation orient);
 t_node         *get_node_by_id(t_vec *nodes, t_id id);
 t_mosfet       *get_mosfet_by_id(t_vec *mosfets, t_id id);
 void           bind_fet_node(t_mosfet *mosfet, t_node *node, t_terminal terminal);
index 37189d8a47c393a1a6f09db442bec94668019e48..dc28f925a7db1afe8afcb1fe05f03a173ab670c0 100644 (file)
@@ -125,11 +125,12 @@ t_node    *add_node(t_vec *nodes, t_state set_state)
        node.state = set_state;
        node.set_state = set_state;
        ft_vec_init(&node.connected, sizeof(t_mosfet *));
+       ft_vec_init(&node.segments, sizeof(t_node_segment));
        ft_vec_append(nodes, &node);
        return (ft_vec_access(nodes, nodes->size - 1));
 }
 
-t_mosfet       *add_mosfet(t_vec *mosfets, t_type type)
+t_mosfet       *add_mosfet(t_vec *mosfets, t_type type, t_position pos, t_orientation orient)
 {
        t_mosfet        mosfet;
 
@@ -139,6 +140,8 @@ t_mosfet    *add_mosfet(t_vec *mosfets, t_type type)
        mosfet.gate = NULL;
        mosfet.drain = NULL;
        mosfet.source = NULL;
+       mosfet.position = pos;
+       mosfet.orientation = orient;
        ft_vec_append(mosfets, &mosfet);
        return (ft_vec_access(mosfets, mosfets->size - 1));
 }
index 47cf85dd3094ebd8356b29de6b5c2cbc664a79b7..729e7555ef61017d1e27fcd333c63e1847dc1737 100644 (file)
@@ -19,7 +19,7 @@ int   c_addfet(WINDOW *command_win, t_input input, t_vec *mosfets)
        }
        while (num > 0)
        {
-               mosfet = add_mosfet(mosfets, input.argv[0].val.type);
+               mosfet = add_mosfet(mosfets, input.argv[0].val.type, (t_position){.x = -2, .y = -2}, LEFT);
                if (!mosfet)
                        return (0);
                wprintw(command_win, "%lu ", mosfet->id);