Skip to content

Commit

Permalink
IMPROVEMENT: re-compute derived parameters because the fc_parameters …
Browse files Browse the repository at this point in the history
…values might have changed

Also remove some dependencies
  • Loading branch information
amilcarlucas committed May 11, 2024
1 parent 00b5de4 commit a02e578
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion MethodicConfigurator/frontend_tkinter_parameter_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def __create_parameter_area_widgets(self):
self.annotate_params_into_files = tk.BooleanVar(value=False)

# Create a Scrollable parameter editor table
self.parameter_editor_table = ParameterEditorTable(self.root, self.local_filesystem, self.flight_controller)
self.parameter_editor_table = ParameterEditorTable(self.root, self.local_filesystem)
self.repopulate_parameter_table(self.current_file)
self.parameter_editor_table.pack(side="top", fill="both", expand=True)

Expand Down
35 changes: 22 additions & 13 deletions MethodicConfigurator/frontend_tkinter_parameter_editor_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,35 @@ class ParameterEditorTable(ScrollFrame):
This class inherits from ScrollFrame and is responsible for creating,
managing, and updating the table that displays parameters for editing.
"""
def __init__(self, root, local_filesystem, flight_controller):
def __init__(self, root, local_filesystem):
super().__init__(root)
self.root = root
self.local_filesystem = local_filesystem
self.flight_controller = flight_controller
self.background_color = root.cget("background")
self.current_file = None
self.write_checkbutton_var = {}
self.at_least_one_param_edited = False

# Prepare a dictionary that maps variable names to their values
variables = {}
# These variables are used by the forced_parameters and derived_parameters in *_configuration_steps.json files
self.variables = {}
if hasattr(self.local_filesystem, 'vehicle_components') and self.local_filesystem.vehicle_components and \
'Components' in self.local_filesystem.vehicle_components:
variables['vehicle_components'] = self.local_filesystem.vehicle_components['Components']
self.variables['vehicle_components'] = self.local_filesystem.vehicle_components['Components']
if hasattr(self.local_filesystem, 'doc_dict') and self.local_filesystem.doc_dict:
variables['doc_dict'] = self.local_filesystem.doc_dict
if self.flight_controller and hasattr(self.flight_controller, 'fc_parameters') and \
self.flight_controller.fc_parameters:
variables['fc_parameters'] = self.flight_controller.fc_parameters
self.variables['doc_dict'] = self.local_filesystem.doc_dict

self.compute_forced_and_derived_parameters()

def compute_forced_and_derived_parameters(self):
if self.local_filesystem.configuration_steps:
for filename, file_info in self.local_filesystem.configuration_steps.items():
error_msg = self.local_filesystem.compute_parameters(filename, file_info, 'forced', variables)
error_msg = self.local_filesystem.compute_parameters(filename, file_info, 'forced', self.variables)
if error_msg:
messagebox.showerror("Error in forced parameters", error_msg)
error_msg = self.local_filesystem.compute_parameters(filename, file_info, 'derived', variables)
if error_msg:
messagebox.showerror("Error in derived parameters", error_msg)

#error_msg = self.local_filesystem.compute_parameters(filename, file_info, 'derived', self.variables)
#if error_msg:
# messagebox.showerror("Error in derived parameters", error_msg)

def repopulate(self, selected_file: str, different_params: dict, fc_parameters: dict, show_only_differences: bool):
for widget in self.view_port.winfo_children():
Expand All @@ -88,6 +88,15 @@ def repopulate(self, selected_file: str, different_params: dict, fc_parameters:

self.write_checkbutton_var = {}

# re-compute derived parameters because the fc_parameters values might have changed
if self.local_filesystem.configuration_steps:
self.variables['fc_parameters'] = fc_parameters
error_msg = self.local_filesystem.compute_parameters(selected_file,
self.local_filesystem.configuration_steps[selected_file],
'derived', self.variables)
if error_msg:
messagebox.showerror("Error in derived parameters", error_msg)

if show_only_differences:
self.__update_table(different_params, fc_parameters)
else:
Expand Down

0 comments on commit a02e578

Please sign in to comment.