Add refresh command
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Thu, 19 Dec 2024 08:49:16 +0000 (09:49 +0100)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Thu, 19 Dec 2024 08:52:31 +0000 (09:52 +0100)
This command refreshes the schema window with new states of mosfets (and
nodes in future).

inc/FET_sim.h
src/colors.c
src/main.c

index e7215a4c254a72254cb47a40b379c4d2db2393d1..82356140fcc2165c34016dd7f891d00d992dbbe8 100644 (file)
@@ -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
index d7be7eb32f9c9c4fff245a51da59df3cb1c24997..24c1722e68a5825ea0db8aa565f6146cacbdd680 100644 (file)
@@ -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);
+}
index 0aeb31ac229c27aca27f021bffcdd1ab068eb995..e6cf3fe339cd5f19d3650e5e707074170989487a 100644 (file)
@@ -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)