From a5d4540f1b7fb30bcbe8fa667e5bf9a4b5f65462 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Ji=C5=99i=C5=A1t=C4=9B?= Date: Sat, 29 Mar 2025 21:50:47 +0100 Subject: [PATCH] Make setting node possible in schema mode --- src/main.c | 6 +++--- src/schema_mode.c | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 7ed93d6..384797d 100644 --- a/src/main.c +++ b/src/main.c @@ -96,10 +96,10 @@ int parse_terminal(const char *str, t_terminal *term) int parse_state(const char *str, t_state *state) { - if(!ft_strcmp(str, "on")) - *state = on; - else if (!ft_strcmp(str, "off")) + if (!ft_strcmp(str, "off")) *state = off; + else if (!ft_strcmp(str, "on")) + *state = on; else if (!ft_strcmp(str, "pd") || !ft_strcmp(str, "pull_down")) *state = pull_down; else if (!ft_strcmp(str, "pu") || !ft_strcmp(str, "pull_up")) diff --git a/src/schema_mode.c b/src/schema_mode.c index 644b25c..fb66c2d 100644 --- a/src/schema_mode.c +++ b/src/schema_mode.c @@ -321,6 +321,23 @@ void schema_user_draw_node(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, return ; } +void schema_switch_mode(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos) +{ + t_node *chosen_node; + + chosen_node = find_node_at_pos(nodes, pos); + if (!chosen_node) + return ; + if (chosen_node->set_state == unknown) + chosen_node->set_state = off; + else + ++chosen_node->set_state; + update_nodes(nodes, mosfets); + refresh_schema_win(schematics_win, nodes, mosfets); + wmove(schematics_win, pos.y, pos.x); + return ; +} + int handle_key_press(int ch, WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets) { t_position pos; @@ -338,6 +355,8 @@ int handle_key_press(int ch, WINDOW *schematics_win, t_vec *nodes, t_vec *mosfet schema_add_mosfet(schematics_win, nodes, mosfets, pos); else if (ch == 'c') schema_user_draw_node(schematics_win, nodes, mosfets, pos); + else if (ch == 's') + schema_switch_mode(schematics_win, nodes, mosfets, pos); return (0); } -- 2.30.2