From: Lukáš Jiřiště Date: Sat, 29 Mar 2025 20:50:47 +0000 (+0100) Subject: Make setting node possible in schema mode X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=a5d4540f1b7fb30bcbe8fa667e5bf9a4b5f65462;p=FET_sim.git Make setting node possible in schema mode --- 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); }