diff --git a/main.py b/main.py index 8a0ea26..0514b93 100644 --- a/main.py +++ b/main.py @@ -59,6 +59,24 @@ def excepthook(exc_type, exc_value, exc_tb): style_sheet = getStyleSheet() app.setStyleSheet(style_sheet) + def splanes_update(project_path, cntrl): + # update splanes in settings because we might have different versions + if hasattr(sett().slicing, "splanes_file"): + # we have kinda old settings which point to separate file with planes + # load planes as it is, but remove this parameter and save settings + # TODO: we can remove this condition after one release + + # try to open figures file + figpath = pathlib.Path(project_path, sett().slicing.splanes_file) + if os.path.isfile(figpath): + cntrl.load_planes_from_file(figpath) + else: + cntrl.load_planes([]) + + del sett().slicing.splanes_file + + cntrl.save_settings("vip") + def open_project(project_path: str): load_settings(str(pathlib.Path(project_path, "settings.yaml"))) @@ -77,26 +95,7 @@ def open_project(project_path: str): if os.path.isfile(stlpath): cntrl.load_stl(stlpath) - if hasattr(sett().slicing, "splanes_file"): - # we have kinda old settings which point to separate file with planes - # load planes as it is, but remove this parameter and save settings - # TODO: we can remove this condition after one release - - # try to open figures file - figpath = pathlib.Path(project_path, sett().slicing.splanes_file) - if os.path.isfile(figpath): - cntrl.load_planes_from_file(figpath) - else: - cntrl.load_planes([]) - - del sett().slicing.splanes_file - - cntrl.save_settings("vip") - else: - # load splanes from settings - cntrl.load_planes( - [read_plane(figure.description) for figure in sett().figures] - ) + splanes_update(project_path, cntrl) window.showMaximized() window.show() @@ -114,6 +113,9 @@ def create_project(project_path: str): model = MainModel() cntrl = MainController(window, model) + + splanes_update(project_path, cntrl) + window.showMaximized() window.show() entry_window.close() diff --git a/settings.yaml b/settings.yaml index 41a343d..58e57a5 100644 --- a/settings.yaml +++ b/settings.yaml @@ -106,7 +106,7 @@ slicing: originz: 0.0 overlapping_infill_percentage: 100.0 overlapping_infill_lid_percentage: 60.0 - planes_contact_with_nozzle: '' + planes_contact_with_nozzle: "" print_speed: 50 print_speed_layer1: 50 print_speed_wall: 50 @@ -158,3 +158,7 @@ supports: uninterrupted_print: enabled: false cut_distance: 0.0 +figures: + - description: plane X0.00 Y0.00 Z0.00 T0.00 R0.00 + index: 0 + settings: {} diff --git a/src/client.py b/src/client.py index 7347389..5d9c913 100644 --- a/src/client.py +++ b/src/client.py @@ -18,7 +18,7 @@ def get_file_chunks(filename): def prepare_bug(filename, error_description): with open("auth.yaml", "r") as file: - auth_data = yaml.safe_load(file) + auth_data = yaml.full_load(file) req = srv_bug_pb2.AddBugRequest( info=srv_bug_pb2.BugInfo( diff --git a/src/controller.py b/src/controller.py index 194b4f1..0331900 100644 --- a/src/controller.py +++ b/src/controller.py @@ -763,12 +763,14 @@ def save_settings_file(self): def save_project_files(self, save_path=""): if save_path == "": self.save_settings("vip", PathBuilder.settings_file()) - shutil.copy2(PathBuilder.stl_model_temp(), PathBuilder.stl_model()) + if os.path.isfile(PathBuilder.stl_model_temp()): + shutil.copy2(PathBuilder.stl_model_temp(), PathBuilder.stl_model()) else: self.save_settings("vip", path.join(save_path, "settings.yaml")) - shutil.copy2( - PathBuilder.stl_model_temp(), path.join(save_path, "model.stl") - ) + if os.path.isfile(PathBuilder.stl_model_temp()): + shutil.copy2( + PathBuilder.stl_model_temp(), path.join(save_path, "model.stl") + ) def save_project(self): try: diff --git a/src/settings.py b/src/settings.py index 9ef5eb6..d14c6a4 100644 --- a/src/settings.py +++ b/src/settings.py @@ -102,6 +102,10 @@ def compare_project_file(filename): def compare_files(file1_path, file2_path): + # if either of the files does not exist, return False + if not os.path.exists(file1_path) or not os.path.exists(file2_path): + return True + try: with open(file1_path, "rb") as file1: data1 = file1.read() @@ -268,7 +272,7 @@ def save_splanes_to_file(splanes, filename): def get_version(settings_filename): try: with open(settings_filename, "r") as settings_file: - settings = yaml.safe_load(settings_file) + settings = yaml.full_load(settings_file) version = settings["common"]["version"] return version @@ -280,7 +284,7 @@ def get_version(settings_filename): def set_version(settings_filename, version): try: with open(settings_filename, "r") as settings_file: - settings = yaml.safe_load(settings_file) + settings = yaml.full_load(settings_file) settings["common"]["version"] = version @@ -293,10 +297,10 @@ def set_version(settings_filename, version): def paths_transfer_in_settings(initial_settings_filename, final_settings_filename): with open(initial_settings_filename, "r") as settings_file: - initial_settings = yaml.safe_load(settings_file) + initial_settings = yaml.load(settings_file) with open(final_settings_filename, "r") as settings_file: - final_settings = yaml.safe_load(settings_file) + final_settings = yaml.load(settings_file) compare_settings(initial_settings, final_settings)