From: Lukáš Jiřiště Date: Sat, 29 Mar 2025 21:14:40 +0000 (+0100) Subject: Add switch in reverse order to schema mode X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=fdeb97233061d0a30105ef01394a39298b500aa8;p=FET_sim.git Add switch in reverse order to schema mode --- diff --git a/src/schema_mode.c b/src/schema_mode.c index 7e4d738..4b3f85e 100644 --- a/src/schema_mode.c +++ b/src/schema_mode.c @@ -321,7 +321,7 @@ 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) +void schema_switch_node(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos) { t_node *chosen_node; @@ -338,6 +338,23 @@ void schema_switch_mode(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_ return ; } +void schema_reverse_switch_node(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 == off) + chosen_node->set_state = unknown; + 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 schema_next(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos) { if (sim_step(nodes, mosfets)) @@ -365,7 +382,9 @@ int handle_key_press(int ch, WINDOW *schematics_win, t_vec *nodes, t_vec *mosfet 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); + schema_switch_node(schematics_win, nodes, mosfets, pos); + else if (ch == 'S') + schema_reverse_switch_node(schematics_win, nodes, mosfets, pos); else if (ch == 'n') schema_next(schematics_win, nodes, mosfets, pos); return (0);