From: Lukáš Jiřiště Date: Thu, 19 Dec 2024 08:49:16 +0000 (+0100) Subject: Add refresh command X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=0ac04d404f053f517908cb58986c348c3c031f8e;p=FET_sim.git Add refresh command This command refreshes the schema window with new states of mosfets (and nodes in future). --- diff --git a/inc/FET_sim.h b/inc/FET_sim.h index e7215a4..8235614 100644 --- a/inc/FET_sim.h +++ b/inc/FET_sim.h @@ -89,6 +89,7 @@ typedef enum e_command bind, help, connect, + refresh_schema, switch_to_schema, exitsim, } t_command; @@ -177,6 +178,6 @@ int c_draw(WINDOW *command_win, t_input input, t_vec *mosfets); int c_help(WINDOW *command_win, t_input input); int c_next(t_input input, t_vec *nodes, t_vec *mosfets); int c_setnode(WINDOW *command_win, t_input input, t_vec *nodes); - +int refresh_schema_win(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets); int schema_mode(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets); #endif //FET_SIM_H diff --git a/src/colors.c b/src/colors.c index d7be7eb..24c1722 100644 --- a/src/colors.c +++ b/src/colors.c @@ -182,3 +182,20 @@ void draw_single(WINDOW *command_win, const t_mosfet *mosfet) draw_bottom(command_win, mosfet); return ; } + +int refresh_schema_win(WINDOW *schematics_win, __attribute__((unused)) t_vec *nodes, t_vec *mosfets) +{ + size_t i; + const t_mosfet *mosfet; + + werase(schematics_win); + i = 0; + while (i < mosfets->size) + { + mosfet = ft_vec_caccess(mosfets, i); + schema_draw_mosfet(schematics_win, mosfet); + ++i; + } + wrefresh(schematics_win); + return (1); +} diff --git a/src/main.c b/src/main.c index 0aeb31a..e6cf3fe 100644 --- a/src/main.c +++ b/src/main.c @@ -44,6 +44,8 @@ int parse_command(const char *str, t_command *cmd) { if (!ft_strcmp(str, "n") || !ft_strcmp(str, "next")) *cmd = next; + else if (!ft_strcmp(str, "r") || !ft_strcmp(str, "refresh")) + *cmd = refresh_schema; else if (!ft_strcmp(str, "d") || !ft_strcmp(str, "draw")) *cmd = draw; else if (!ft_strcmp(str, "s") || !ft_strcmp(str, "set") || !ft_strcmp(str, "setnode")) @@ -131,7 +133,7 @@ int has_correct_argc(t_input input) return (0); if (c == connect && argc != 4) return (0); - if (c == switch_to_schema && argc > 0) + if ((c == switch_to_schema || c == refresh_schema) && argc > 0) return (0); return (1); } @@ -241,6 +243,8 @@ int process_input(t_windows *windows, t_vec *nodes, t_vec *mosfets) res = c_connect(windows->command_win, input, nodes, mosfets); else if (input.command == help) res = c_help(windows->command_win, input); + else if(input.command == refresh_schema) + res = refresh_schema_win(windows->schematics_win, nodes, mosfets); else if (input.command == switch_to_schema) res = schema_mode(windows->schematics_win, nodes, mosfets); else if (input.command == exitsim)