Skip to content

Commit

Permalink
Correcting a bug when opening the visualizer
Browse files Browse the repository at this point in the history
Correcting a bug when opening the visualization tool withtout a file or
a directory.
  • Loading branch information
rsachetto committed Oct 24, 2023
1 parent 5eefc3e commit 167ada0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 39 deletions.
39 changes: 21 additions & 18 deletions src/gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,8 @@ static void handle_keyboard_input(struct gui_shared_info *gui_config, struct gui
if(tmp) {
gui_config->input = strdup(tmp);
reset(gui_config, gui_state, true);
free(gui_config->error_message);
gui_config->error_message = strdup("Loading Mesh...");
free(gui_config->message);
gui_config->message = strdup("Loading Mesh...");

} else {
gui_config->input = NULL;
Expand Down Expand Up @@ -633,8 +633,8 @@ static void handle_keyboard_input(struct gui_shared_info *gui_config, struct gui

if(tmp) {
reset(gui_config, gui_state, true);
free(gui_config->error_message);
gui_config->error_message = strdup("Loading Mesh...");
free(gui_config->message);
gui_config->message = strdup("Loading Mesh...");
}
return;
}
Expand Down Expand Up @@ -822,7 +822,7 @@ void init_and_open_gui_window(struct gui_shared_info *gui_config) {
gui_state->mesh_info_box.lines = NULL;
configure_info_boxes_sizes(gui_state, help_box_lines, slice_help_box_lines, edit_help_box_lines, end_info_box_lines, box_w, text_offset);

Vector2 error_message_width;
Vector2 message_width;
struct mesh_info *mesh_info = new_mesh_info();
bool end_info_box_strings_configured = false;

Expand Down Expand Up @@ -989,16 +989,16 @@ void init_and_open_gui_window(struct gui_shared_info *gui_config) {
float spacing = gui_state->font_spacing_big;
static Color c = RED;

error_message_width = MeasureTextEx(gui_state->font, "Slicing Mesh...", gui_state->font_size_big, spacing);
int posx = GetScreenWidth() / 2 - (int)error_message_width.x / 2;
message_width = MeasureTextEx(gui_state->font, "Slicing Mesh...", gui_state->font_size_big, spacing);
int posx = GetScreenWidth() / 2 - (int)message_width.x / 2;
int posy = GetScreenHeight() / 2 - 50;

int rec_width = (int)(error_message_width.x) + 50;
int rec_height = (int)(error_message_width.y) + 2;
int rec_width = (int)(message_width.x) + 50;
int rec_height = (int)(message_width.y) + 2;

DrawRectangle(posx, posy, rec_width, rec_height, c);

DrawTextEx(gui_state->font, "Slicing Mesh...", (Vector2){(float)posx + ((float)rec_width - error_message_width.x) / 2, (float)posy},
DrawTextEx(gui_state->font, "Slicing Mesh...", (Vector2){(float)posx + ((float)rec_width - message_width.x) / 2, (float)posy},
gui_state->font_size_big, gui_state->font_spacing_big, BLACK);

}
Expand Down Expand Up @@ -1085,28 +1085,31 @@ void init_and_open_gui_window(struct gui_shared_info *gui_config) {
float spacing = gui_state->font_spacing_big;
static Color c = RED;

if(!gui_config->error_message) {
gui_config->error_message = strdup("Loading Mesh...");
if(!gui_config->message) {
gui_config->message = strdup("Loading Mesh...");
c = WHITE;
}

error_message_width = MeasureTextEx(gui_state->font, gui_config->error_message, gui_state->font_size_big, spacing);
int posx = GetScreenWidth() / 2 - (int)error_message_width.x / 2;
message_width = MeasureTextEx(gui_state->font, gui_config->message, gui_state->font_size_big, spacing);
int posx = GetScreenWidth() / 2 - (int)message_width.x / 2;
int posy = GetScreenHeight() / 2 - 50;

int rec_width = (int)(error_message_width.x) + 50;
int rec_height = (int)(error_message_width.y) + 2;
int rec_width = (int)(message_width.x) + 50;
int rec_height = (int)(message_width.y) + 2;

int rec_bar_w = (int)Remap((float) gui_config->progress, 0, (float) gui_config->file_size, 0, (float) rec_width);

DrawRectangle(posx, posy, rec_bar_w, rec_height, c);
DrawRectangleLines(posx, posy, rec_width, rec_height, BLACK);

// This should not happen... but it does....
if(gui_config->error_message) {
DrawTextEx(gui_state->font, gui_config->error_message, (Vector2){(float)posx + ((float)rec_width - error_message_width.x) / 2, (float)posy},
if(gui_config->message) {
DrawTextEx(gui_state->font, gui_config->message, (Vector2){(float)posx + ((float)rec_width - message_width.x) / 2, (float)posy},
gui_state->font_size_big, gui_state->font_spacing_big, BLACK);

gui_state->handle_keyboard_input = true;
}

}

// Draw FPS
Expand Down
2 changes: 1 addition & 1 deletion src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct gui_shared_info {
bool loaded;
} grid_info;

char *error_message;
char *message;
bool int_scale;
float ui_scale;

Expand Down
2 changes: 1 addition & 1 deletion src/main_simulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static void init_gui_config_for_simulation(const struct user_options *options, s
gui_config->restart = false;

gui_config->draw_type = DRAW_SIMULATION;
gui_config->error_message = NULL;
gui_config->message = NULL;
gui_config->grid_info.loaded = false;
gui_config->int_scale = false;
gui_config->ui_scale = 0.0;
Expand Down
38 changes: 19 additions & 19 deletions src/main_visualizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ static void read_and_render_activation_map(struct gui_shared_info *gui_config, c

if(!gui_config->grid_info.vtk_grid) {
snprintf(error, MAX_ERROR_SIZE, "%s is not an activation map", input_file);
if(gui_config->error_message) {
free(gui_config->error_message);
if(gui_config->message) {
free(gui_config->message);
}
gui_config->error_message = strdup(error);
gui_config->message = strdup(error);
omp_unset_lock(&gui_config->draw_lock);
return;
}
Expand All @@ -49,11 +49,11 @@ static void calc_vm_bounds(struct gui_shared_info *gui_config, const struct simu
char error[MAX_ERROR_SIZE];
snprintf(error, MAX_ERROR_SIZE, "Calculating Vm bounds!");

if(gui_config->error_message) {
free(gui_config->error_message);
if(gui_config->message) {
free(gui_config->message);
}

gui_config->error_message = strdup(error);
gui_config->message = strdup(error);
static struct vtk_unstructured_grid *tmp_grid = NULL;
static bool en_tmp_loaded = false;

Expand Down Expand Up @@ -128,11 +128,11 @@ static int read_and_render_files(struct visualization_options *options, struct g
if(!input_info.exists) {
snprintf(error, MAX_ERROR_SIZE,
"Invalid path or pvd file provided! Press 'o' to open an directory or 'f' to open a simulation file (pvd, vtu, vtk, acm or alg)!");
if(gui_config->error_message) {
free(gui_config->error_message);
if(gui_config->message) {
free(gui_config->message);
}

gui_config->error_message = strdup(error);
gui_config->message = strdup(error);
gui_config->input = NULL;
options->input = NULL;
return SIMULATION_FINISHED;
Expand Down Expand Up @@ -193,9 +193,9 @@ static int read_and_render_files(struct visualization_options *options, struct g
if(!num_files) {
snprintf(error, MAX_ERROR_SIZE, "No simulations file found in %s", simulation_files->base_dir);

if(gui_config->error_message)
free(gui_config->error_message);
gui_config->error_message = strdup(error);
if(gui_config->message)
free(gui_config->message);
gui_config->message = strdup(error);

sdsfree(simulation_files->base_dir);
free(simulation_files);
Expand All @@ -219,9 +219,9 @@ static int read_and_render_files(struct visualization_options *options, struct g
if(!input_info.exists) {
snprintf(error, MAX_ERROR_SIZE, "Geometry file %s not found", geometry_file);

if(gui_config->error_message)
free(gui_config->error_message);
gui_config->error_message = strdup(error);
if(gui_config->message)
free(gui_config->message);
gui_config->message = strdup(error);

sdsfree(simulation_files->base_dir);
free(simulation_files);
Expand Down Expand Up @@ -366,11 +366,11 @@ static int read_and_render_files(struct visualization_options *options, struct g
if(!gui_config->grid_info.vtk_grid) {
snprintf(error, MAX_ERROR_SIZE, "Decoder not available for file %s", current_file_name);

if(gui_config->error_message) {
free(gui_config->error_message);
if(gui_config->message) {
free(gui_config->message);
}

gui_config->error_message = strdup(error);
gui_config->message = strdup(error);
gui_config->grid_info.loaded = false;
gui_config->paused = true;
} else {
Expand Down Expand Up @@ -456,7 +456,7 @@ static void init_gui_config_for_visualization(const struct visualization_options
gui_config->dt = options->dt;
gui_config->draw_type = DRAW_FILE;
gui_config->grid_info.file_name = NULL;
gui_config->error_message = NULL;
gui_config->message = NULL;
gui_config->int_scale = false;
}
}
Expand Down

0 comments on commit 167ada0

Please sign in to comment.