diff --git a/.github/workflows/build-linux.yaml b/.github/workflows/build-linux.yaml index f170cd5..740421d 100644 --- a/.github/workflows/build-linux.yaml +++ b/.github/workflows/build-linux.yaml @@ -34,7 +34,7 @@ jobs: # cache: "pip" - name: Install dependencies run: | - python3 -m pip install --upgrade pip setuptools wheel flake8 pyinstaller + python3 -m pip install --upgrade pip setuptools wheel flake8 pyinstaller==5.13.0 python3 -m pip install -r linux-req.txt - name: Lint with flake8 run: | @@ -47,6 +47,7 @@ jobs: run: | mv settings.yaml dist/settings.yaml mv icon.png dist/icon.png + mv icons/ dist/icons/ - name: Upload artifact uses: actions/upload-artifact@v2 with: diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ab20321..86e2132 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -43,6 +43,7 @@ jobs: run: | mv settings.yaml dist/settings.yaml mv icon.png dist/icon.png + mv icons/ dist/icons/ - name: Upload artifact uses: actions/upload-artifact@v2 with: diff --git a/icons/redo.png b/icons/redo.png new file mode 100644 index 0000000..2aebf0e Binary files /dev/null and b/icons/redo.png differ diff --git a/icons/undo.png b/icons/undo.png new file mode 100644 index 0000000..6bc5ed4 Binary files /dev/null and b/icons/undo.png differ diff --git a/main.py b/main.py index 8a0ea26..c50f4e0 100644 --- a/main.py +++ b/main.py @@ -59,24 +59,8 @@ def excepthook(exc_type, exc_value, exc_tb): style_sheet = getStyleSheet() app.setStyleSheet(style_sheet) - def open_project(project_path: str): - load_settings(str(pathlib.Path(project_path, "settings.yaml"))) - - # update project_path in settings, because it originally might be in another place - sett().project_path = project_path - create_temporary_project_files() - - window = MainWindow() - window.close_signal.connect(entry_window.show) - - model = MainModel() - cntrl = MainController(window, model) - - # try to open stl file - stlpath = pathlib.Path(project_path, sett().slicing.stl_file) - if os.path.isfile(stlpath): - cntrl.load_stl(stlpath) - + 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 @@ -98,6 +82,26 @@ def open_project(project_path: str): [read_plane(figure.description) for figure in sett().figures] ) + def open_project(project_path: str): + load_settings(str(pathlib.Path(project_path, "settings.yaml"))) + + # update project_path in settings, because it originally might be in another place + sett().project_path = project_path + create_temporary_project_files() + + window = MainWindow() + window.close_signal.connect(entry_window.show) + + model = MainModel() + cntrl = MainController(window, model) + + # try to open stl file + stlpath = pathlib.Path(project_path, sett().slicing.stl_file) + if os.path.isfile(stlpath): + cntrl.load_stl(stlpath) + + splanes_update(project_path, cntrl) + window.showMaximized() window.show() cntrl.reset_settings() @@ -114,6 +118,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/main.spec b/main.spec index 419689e..815de0f 100644 --- a/main.spec +++ b/main.spec @@ -7,7 +7,7 @@ block_cipher = None a = Analysis(['main.py'], binaries=[], datas=[('src', 'src/'), ('settings.yaml', 'lib/')], - hiddenimports=['vtkmodules', 'vtkmodules.all', 'vtkmodules.qt.QVTKRenderWindowInteractor', 'vtkmodules.util', 'vtkmodules.util.numpy_support', 'yaml', 'numpy', 'numpy-stl'], + hiddenimports=['vtkmodules', 'vtkmodules.all', 'vtkmodules.qt.QVTKRenderWindowInteractor', 'vtkmodules.util', 'vtkmodules.util.numpy_support', 'yaml', 'numpy', 'pkg_resources.extern'], hookspath=[], hooksconfig={}, runtime_hooks=[], 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/InteractorAroundActivePlane.py b/src/InteractorAroundActivePlane.py index a95268f..595c90a 100644 --- a/src/InteractorAroundActivePlane.py +++ b/src/InteractorAroundActivePlane.py @@ -115,6 +115,7 @@ def leftBtnPress(self, obj, event, view=None): normal = actor.GetTriangleNormal(triangle_id) actor.RotateByVector(-normal) view.model_centering() + view.save_current_movement() def middleBtnPress(self, obj, event): if event == "MouseWheelForwardEvent": 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 39fc795..0331900 100644 --- a/src/controller.py +++ b/src/controller.py @@ -125,6 +125,8 @@ def _connect_signals(self): self.view.picture_slider.valueChanged.connect(self.change_layer_view) self.view.move_button.clicked.connect(self.move_model) self.view.place_button.clicked.connect(self.place_model) + self.view.cancel_action.clicked.connect(partial(self.view.shift_state, True)) + self.view.return_action.clicked.connect(partial(self.view.shift_state, False)) self.view.load_model_button.clicked.connect(self.open_file) self.view.slice3a_button.clicked.connect(partial(self.slice_stl, "3axes")) self.view.slice_vip_button.clicked.connect(partial(self.slice_stl, "vip")) @@ -204,7 +206,7 @@ def create_printer(self): save_settings() # update label with printer path - self.view.printer_path_edit.setText(os.path.basename(printer_path)) + self.view.setts.edit("printer_path").setText(os.path.basename(printer_path)) # update path in calibration model try: @@ -243,7 +245,7 @@ def choose_printer_path(self): save_settings() # update label with printer path - self.view.printer_path_edit.setText(os.path.basename(printer_path)) + self.view.setts.edit("printer_path").setText(os.path.basename(printer_path)) # update path in calibration model try: @@ -709,7 +711,6 @@ def save_settings(self, slicing_type, filename=""): s.slicing.rotationz, ) = tf.GetOrientation() s.slicing.scalex, s.slicing.scaley, s.slicing.scalez = tf.GetScale() - s.slicing.angle = float(self.view.colorize_angle_value.text()) s.slicing.slicing_type = slicing_type m = vtkMatrix4x4() @@ -762,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: @@ -887,15 +890,9 @@ def display_settings(self): self.view.supports_number_of_bottom_layers_value.setText( str(s.supports.bottoms_depth) ) - self.view.supports_bottom_thickness_value.setText( - str(round(s.slicing.layer_height * s.supports.bottoms_depth, 2)) - ) self.view.supports_number_of_lid_layers_value.setText( str(int(s.supports.lids_depth)) ) - self.view.supports_lid_thickness_value.setText( - str(round(s.slicing.layer_height * s.supports.lids_depth, 2)) - ) self.view.colorize_angle_value.setText(str(s.slicing.angle)) def colorize_model(self): diff --git a/src/figure_editor.py b/src/figure_editor.py index 8d570e0..1ce9e85 100644 --- a/src/figure_editor.py +++ b/src/figure_editor.py @@ -279,7 +279,7 @@ def params(self): class StlMovePanel(QWidget): - def __init__(self, methods, captions): + def __init__(self, viev, methods, captions): super().__init__() self.setEnabled(False) @@ -302,6 +302,7 @@ def __init__(self, methods, captions): gridLayout.addWidget(btn_neg, row, 1) edit = QLineEdit() + edit.installEventFilter(viev) edit.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) edit.setMinimumWidth(20) gridLayout.addWidget(edit, row, 2) diff --git a/src/gui_utils.py b/src/gui_utils.py index 49c13ed..2a6dfc8 100644 --- a/src/gui_utils.py +++ b/src/gui_utils.py @@ -717,6 +717,7 @@ def setTransform(self): self.view.stlActor.SetUserTransform(self.tf) self.view.updateTransform() self.view.reload_scene() + self.view.save_current_movement() def set(self, text, axis): try: diff --git a/src/locales.py b/src/locales.py index c06a950..46bbd0a 100644 --- a/src/locales.py +++ b/src/locales.py @@ -144,6 +144,7 @@ class Locale: WarningPathNotClosed = "When cutting the model, not closed areas were found! Check that the shapes are positioned correctly" RemoveFirstPlaneError = "First figure cannot be removed" + CannotDropHere = "Figure cannot be dropped here" def __init__(self, **entries): self.__dict__.update(entries) @@ -295,6 +296,7 @@ def __init__(self, **entries): M10CutDistance="Дистанция отреза филамента, мм:", RemoveFirstPlaneError="Первая фигура не может быть убрана", WarningPathNotClosed="При разрезании модели были обнаружены незамкнутые участки! Проверьте корректность расположения фигур", + CannotDropHere="Фигура не может быть перенесена сюда", ), } diff --git a/src/settings.py b/src/settings.py index 2f2a2e3..d14c6a4 100644 --- a/src/settings.py +++ b/src/settings.py @@ -89,6 +89,9 @@ def compare_figures(settings): if current_figures[i]["description"] != figures_from_settings[i].description: return False + if current_figures[i]["settings"] != figures_from_settings[i].settings: + return False + return True @@ -99,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() @@ -265,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 @@ -277,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 @@ -290,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) @@ -319,16 +326,21 @@ def __init__(self, d): else: setattr(self, a, Settings(b) if isinstance(b, dict) else b) + def __repr__(self): + return str(self.__dict__) + def __eq__(self, other): if not isinstance(other, Settings): return False ignore_attributes = [ "splanes_file", + "figures", "print_time", "consumption_material", "planes_contact_with_nozzle", ] + # try to compare attributes from left to right for attr in self.__dict__: if attr in ignore_attributes: continue @@ -336,6 +348,16 @@ def __eq__(self, other): return False if getattr(self, attr) != getattr(other, attr): return False + + # try to compare attributes from right to left + for attr in other.__dict__: + if attr in ignore_attributes: + continue + if not hasattr(self, attr): + return False + if getattr(self, attr) != getattr(other, attr): + return False + return True @@ -370,9 +392,22 @@ def settings_file_default(): def settings_file_old(): return path.join(PathBuilder.project_path(), "settings_old.yaml") + @staticmethod + def get_cmd_with_path(cmd): + temp_settings = prepare_temp_settings(sett()) + encoded_temp_settings = base64.b64encode(temp_settings.encode("utf-8")).decode( + "utf-8" + ) + return ( + cmd + + f'"{PathBuilder.settings_file_temp()}"' + + " --data=" + + f"{encoded_temp_settings}" + ) + @staticmethod def colorizer_cmd(): - return sett().colorizer.cmd + f'"{PathBuilder.settings_file()}"' + return PathBuilder.get_cmd_with_path(sett().colorizer.cmd) @staticmethod def colorizer_stl(): @@ -384,16 +419,7 @@ def colorizer_result(): @staticmethod def slicing_cmd(): - temp_settings = prepare_temp_settings(sett()) - encoded_temp_settings = base64.b64encode(temp_settings.encode("utf-8")).decode( - "utf-8" - ) - return ( - sett().slicing.cmd - + f'"{PathBuilder.settings_file_temp()}"' - + " --data=" - + f"{encoded_temp_settings}" - ) + return PathBuilder.get_cmd_with_path(sett().slicing.cmd) @staticmethod def gcodevis_file(): diff --git a/src/settings_widget.py b/src/settings_widget.py index d557568..51e7079 100644 --- a/src/settings_widget.py +++ b/src/settings_widget.py @@ -68,6 +68,7 @@ class SettingsWidget(QWidget): "support_priority_zoffset", "support_number_of_bottom_layers", "support_number_of_lid_layers", + "critical_angle", ] # extra parameters are only used for a small widget with parameters for each figure specifically @@ -337,952 +338,928 @@ def with_sett(self, name: str): return self # we match the given name with each setting and add it to the layout - match name: - case "printer_path": - # self.ensure_sett("hardware.printer_path") - - printer_basename = "" - try: - printer_basename = path.basename(self.sett().hardware.printer_dir) - if self.sett().hardware.printer_dir == "" or not path.isdir( - self.sett().hardware.printer_dir - ): - # empty directory - raise ValueError("Choose default printer") - - logging.info( - f"hardware printer path is {self.sett().hardware.printer_dir}" - ) - except ValueError: - # set default path to printer config - self.sett().hardware.printer_dir = path.join( - APP_PATH, "data", "printers", "default" - ) - logging.info( - f"hardware printer path is default: {self.sett().hardware.printer_dir}" - ) - printer_basename = path.basename(self.sett().hardware.printer_dir) - - printer_path_edit = ClickableLineEdit(printer_basename) - printer_path_edit.setReadOnly(True) - - printer_add_btn = QPushButton("+") - printer_add_btn.setToolTip(self.locale.AddNewPrinter) - - label = QLabel(self.locale.PrinterName) - self.panel.addWidget(label, self.next_row, 1) - self.panel.addWidget(printer_add_btn, self.cur_row, 2) - self.panel.addWidget(printer_path_edit, self.cur_row, 3, 1, 3) - - self.__elements[name] = { - "label": label, - "edit": printer_path_edit, - "add_btn": printer_add_btn, - } - case "uninterrupted_print": - self.ensure_sett("uninterrupted_print.enabled") - - uninterrupted_print = QLabel(self.locale.UninterruptedPrint) - uninterrupted_print_box = QCheckBox() - if sett().uninterrupted_print.enabled: - uninterrupted_print_box.setCheckState(QtCore.Qt.Checked) - self.panel.addWidget( - QLabel(self.locale.UninterruptedPrint), self.next_row, 1 + if name == "printer_path": + # self.ensure_sett("hardware.printer_path") + + printer_basename = "" + try: + printer_basename = path.basename(self.sett().hardware.printer_dir) + if self.sett().hardware.printer_dir == "" or not path.isdir( + self.sett().hardware.printer_dir + ): + # empty directory + raise ValueError("Choose default printer") + + logging.info( + f"hardware printer path is {self.sett().hardware.printer_dir}" ) - self.panel.addWidget( - uninterrupted_print_box, self.cur_row, 2, 1, self.col2_cells + except ValueError: + # set default path to printer config + self.sett().hardware.printer_dir = path.join( + APP_PATH, "data", "printers", "default" ) - - # on check on this box, we should restrict fill type to zigzag only - def on_uninterrupted_print_change(): - self.sett().uninterrupted_print.enabled = ( - uninterrupted_print_box.isChecked() - ) - - isUninterrupted = uninterrupted_print_box.isChecked() - - self.values("filling_type").setEnabled(not isUninterrupted) - self.checkbox("retraction_on").setEnabled(not isUninterrupted) - self.edit("retraction_distance").setEnabled(not isUninterrupted) - self.edit("retraction_speed").setEnabled(not isUninterrupted) - self.edit("retraction_compensation").setEnabled(not isUninterrupted) - - if isUninterrupted: - zigzag_idx = locales.getLocaleByLang( - "en" - ).FillingTypeValues.index("ZigZag") - self.values("filling_type").setCurrentIndex(zigzag_idx) - self.checkbox("retraction_on").setChecked(False) - - uninterrupted_print_box.stateChanged.connect( - on_uninterrupted_print_change + logging.info( + f"hardware printer path is default: {self.sett().hardware.printer_dir}" ) + printer_basename = path.basename(self.sett().hardware.printer_dir) + + printer_path_edit = ClickableLineEdit(printer_basename) + printer_path_edit.setReadOnly(True) + + printer_add_btn = QPushButton("+") + printer_add_btn.setToolTip(self.locale.AddNewPrinter) + + label = QLabel(self.locale.PrinterName) + self.panel.addWidget(label, self.next_row, 1) + self.panel.addWidget(printer_add_btn, self.cur_row, 2) + self.panel.addWidget(printer_path_edit, self.cur_row, 3, 1, 3) + + self.__elements[name] = { + "label": label, + "edit": printer_path_edit, + "add_btn": printer_add_btn, + } + elif name == "uninterrupted_print": + self.ensure_sett("uninterrupted_print.enabled") + + uninterrupted_print = QLabel(self.locale.UninterruptedPrint) + uninterrupted_print_box = QCheckBox() + if sett().uninterrupted_print.enabled: + uninterrupted_print_box.setCheckState(QtCore.Qt.Checked) + self.panel.addWidget( + QLabel(self.locale.UninterruptedPrint), self.next_row, 1 + ) + self.panel.addWidget( + uninterrupted_print_box, self.cur_row, 2, 1, self.col2_cells + ) - self.__elements[name] = { - "label": uninterrupted_print, - "checkbox": uninterrupted_print_box, - } - - case "m10_cut_distance": - self.ensure_sett("uninterrupted_print.cut_distance") - - m10_cut_distance = QLabel(self.locale.M10CutDistance) - m10_cut_distance_value = QLineEdit() - m10_cut_distance_value.setText( - str(sett().uninterrupted_print.cut_distance) + # on check on this box, we should restrict fill type to zigzag only + def on_uninterrupted_print_change(): + self.sett().uninterrupted_print.enabled = ( + uninterrupted_print_box.isChecked() ) - m10_cut_distance_value.setValidator(self.doubleValidator) - self.panel.addWidget(m10_cut_distance, self.next_row, 1) - self.panel.addWidget( - m10_cut_distance_value, self.cur_row, 2, 1, self.col2_cells - ) - - def on_change(): - sett().uninterrupted_print.cut_distance = self.__smart_float( - m10_cut_distance_value.text() - ) - m10_cut_distance_value.textChanged.connect(on_change) + isUninterrupted = uninterrupted_print_box.isChecked() - self.__elements[name] = { - "label": m10_cut_distance, - "edit": m10_cut_distance_value, - } + self.values("filling_type").setEnabled(not isUninterrupted) + self.checkbox("retraction_on").setEnabled(not isUninterrupted) + self.edit("retraction_distance").setEnabled(not isUninterrupted) + self.edit("retraction_speed").setEnabled(not isUninterrupted) + self.edit("retraction_compensation").setEnabled(not isUninterrupted) - case "line_width": - self.ensure_sett("slicing.line_width") + if isUninterrupted: + zigzag_idx = locales.getLocaleByLang("en").FillingTypeValues.index( + "ZigZag" + ) + self.values("filling_type").setCurrentIndex(zigzag_idx) + self.checkbox("retraction_on").setChecked(False) + + uninterrupted_print_box.stateChanged.connect(on_uninterrupted_print_change) + + self.__elements[name] = { + "label": uninterrupted_print, + "checkbox": uninterrupted_print_box, + } + + elif name == "m10_cut_distance": + self.ensure_sett("uninterrupted_print.cut_distance") + + m10_cut_distance = QLabel(self.locale.M10CutDistance) + m10_cut_distance_value = QLineEdit() + m10_cut_distance_value.setText(str(sett().uninterrupted_print.cut_distance)) + m10_cut_distance_value.setValidator(self.doubleValidator) + self.panel.addWidget(m10_cut_distance, self.next_row, 1) + self.panel.addWidget( + m10_cut_distance_value, self.cur_row, 2, 1, self.col2_cells + ) - line_width = QLabel(self.locale.LineWidth) - line_width_value = QLineEdit() - line_width_value.setText(str(self.sett().slicing.line_width)) - line_width_value.setValidator(self.doubleValidator) - line_width_value.textChanged.connect(self.__update_wall_thickness) - self.panel.addWidget(line_width, self.next_row, 1) - self.panel.addWidget( - line_width_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + sett().uninterrupted_print.cut_distance = self.__smart_float( + m10_cut_distance_value.text() ) - def on_change(): - self.sett().slicing.line_width = self.__smart_float( - line_width_value.text() - ) + m10_cut_distance_value.textChanged.connect(on_change) - line_width_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": m10_cut_distance, + "edit": m10_cut_distance_value, + } - self.__elements[name] = { - "label": line_width, - "edit": line_width_value, - } + elif name == "line_width": + self.ensure_sett("slicing.line_width") - case "layer_height": - self.ensure_sett("slicing.layer_height") + line_width = QLabel(self.locale.LineWidth) + line_width_value = QLineEdit() + line_width_value.setText(str(self.sett().slicing.line_width)) + line_width_value.setValidator(self.doubleValidator) + line_width_value.textChanged.connect(self.__update_wall_thickness) + self.panel.addWidget(line_width, self.next_row, 1) + self.panel.addWidget(line_width_value, self.cur_row, 2, 1, self.col2_cells) - layer_height = QLabel(self.locale.LayerHeight) - layer_height_value = QLineEdit() - layer_height_value.setText(str(self.sett().slicing.layer_height)) - layer_height_value.setValidator(self.doubleValidator) - layer_height_value.textChanged.connect(self.__change_layer_height) - self.panel.addWidget(layer_height, self.next_row, 1) - self.panel.addWidget( - layer_height_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.line_width = self.__smart_float( + line_width_value.text() ) - def on_change(): - self.sett().slicing.layer_height = self.__smart_float( - layer_height_value.text() - ) + line_width_value.textChanged.connect(on_change) - layer_height_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": line_width, + "edit": line_width_value, + } - self.__elements[name] = { - "label": layer_height, - "edit": layer_height_value, - } + elif name == "layer_height": + self.ensure_sett("slicing.layer_height") - case "number_wall_lines": - self.ensure_sett("slicing.wall_thickness") + layer_height = QLabel(self.locale.LayerHeight) + layer_height_value = QLineEdit() + layer_height_value.setText(str(self.sett().slicing.layer_height)) + layer_height_value.setValidator(self.doubleValidator) + layer_height_value.textChanged.connect(self.__change_layer_height) + self.panel.addWidget(layer_height, self.next_row, 1) + self.panel.addWidget( + layer_height_value, self.cur_row, 2, 1, self.col2_cells + ) - number_wall_lines_label = QLabel(self.locale.NumberWallLines) - if self.sett().slicing.line_width > 0: - number_wall_lines_value = int( - self.sett().slicing.wall_thickness - / self.sett().slicing.line_width - ) - else: - number_wall_lines_value = 0 + def on_change(): + self.sett().slicing.layer_height = self.__smart_float( + layer_height_value.text() + ) - number_wall_lines_value = LineEdit(str(number_wall_lines_value)) - number_wall_lines_value.setValidator(self.intValidator) + layer_height_value.textChanged.connect(on_change) - number_wall_lines_value.textChanged.connect( - self.__update_wall_thickness - ) + self.__elements[name] = { + "label": layer_height, + "edit": layer_height_value, + } - self.panel.addWidget(number_wall_lines_label, self.next_row, 1) - self.panel.addWidget(number_wall_lines_value, self.cur_row, 2) + elif name == "number_wall_lines": + self.ensure_sett("slicing.wall_thickness") - wall_thickness_label = QLabel(self.locale.WallThickness) - wall_thickness_value = LineEdit(str(self.sett().slicing.wall_thickness)) - wall_thickness_value.setReadOnly(True) - millimeter_label = QLabel(self.locale.Millimeter) - self.panel.addWidget(wall_thickness_label, self.cur_row, 3) - self.panel.addWidget(wall_thickness_value, self.cur_row, 4) - self.panel.addWidget(millimeter_label, self.cur_row, 5) + number_wall_lines_label = QLabel(self.locale.NumberWallLines) + if self.sett().slicing.line_width > 0: + number_wall_lines_value = int( + self.sett().slicing.wall_thickness / self.sett().slicing.line_width + ) + else: + number_wall_lines_value = 0 - def on_change(): - self.sett().slicing.wall_thickness = self.__smart_float( - wall_thickness_value.text() - ) + number_wall_lines_value = LineEdit(str(number_wall_lines_value)) + number_wall_lines_value.setValidator(self.intValidator) - number_wall_lines_value.textChanged.connect(on_change) + number_wall_lines_value.textChanged.connect(self.__update_wall_thickness) - self.__elements[name] = { - "label": number_wall_lines_label, - "edit": number_wall_lines_value, - "wall_thickness_label": wall_thickness_label, - "wall_thickness_value": wall_thickness_value, - } + self.panel.addWidget(number_wall_lines_label, self.next_row, 1) + self.panel.addWidget(number_wall_lines_value, self.cur_row, 2) - case "number_of_bottom_layers": - self.ensure_sett("slicing.bottoms_depth") + wall_thickness_label = QLabel(self.locale.WallThickness) + wall_thickness_value = LineEdit(str(self.sett().slicing.wall_thickness)) + wall_thickness_value.setReadOnly(True) + millimeter_label = QLabel(self.locale.Millimeter) + self.panel.addWidget(wall_thickness_label, self.cur_row, 3) + self.panel.addWidget(wall_thickness_value, self.cur_row, 4) + self.panel.addWidget(millimeter_label, self.cur_row, 5) - number_of_bottom_layers_label = QLabel(self.locale.NumberOfBottomLayers) - number_of_bottom_layers_value = LineEdit( - str(self.sett().slicing.bottoms_depth) - ) - number_of_bottom_layers_value.setValidator(self.intValidator) - number_of_bottom_layers_value.textChanged.connect( - self.__update_bottom_thickness + def on_change(): + self.sett().slicing.wall_thickness = self.__smart_float( + wall_thickness_value.text() ) - self.panel.addWidget(number_of_bottom_layers_label, self.next_row, 1) - self.panel.addWidget(number_of_bottom_layers_value, self.cur_row, 2) - - bottom_thickness_label = QLabel(self.locale.BottomThickness) - bottom_thickness_value = LineEdit( - str( - round( - self.sett().slicing.bottoms_depth - * self.sett().slicing.layer_height, - 2, - ), - ) - ) - bottom_thickness_value.setReadOnly(True) - millimeter_label = QLabel(self.locale.Millimeter) + number_wall_lines_value.textChanged.connect(on_change) - self.panel.addWidget(bottom_thickness_label, self.cur_row, 3) - self.panel.addWidget(bottom_thickness_value, self.cur_row, 4) - self.panel.addWidget(millimeter_label, self.cur_row, 5) + self.__elements[name] = { + "label": number_wall_lines_label, + "edit": number_wall_lines_value, + "wall_thickness_label": wall_thickness_label, + "wall_thickness_value": wall_thickness_value, + } - def on_change(): - self.sett().slicing.bottoms_depth = self.__smart_float( - bottom_thickness_value.text() - ) + elif name == "number_of_bottom_layers": + self.ensure_sett("slicing.bottoms_depth") - number_of_bottom_layers_value.textChanged.connect(on_change) + number_of_bottom_layers_label = QLabel(self.locale.NumberOfBottomLayers) + number_of_bottom_layers_value = LineEdit( + str(self.sett().slicing.bottoms_depth) + ) + number_of_bottom_layers_value.setValidator(self.intValidator) + number_of_bottom_layers_value.textChanged.connect( + self.__update_bottom_thickness + ) - self.__elements[name] = { - "label": number_of_bottom_layers_label, - "edit": number_of_bottom_layers_value, - "bottom_thickness_label": bottom_thickness_label, - "bottom_thickness_value": bottom_thickness_value, - } + self.panel.addWidget(number_of_bottom_layers_label, self.next_row, 1) + self.panel.addWidget(number_of_bottom_layers_value, self.cur_row, 2) + + bottom_thickness_label = QLabel(self.locale.BottomThickness) + bottom_thickness_value = LineEdit( + str( + round( + self.sett().slicing.bottoms_depth + * self.sett().slicing.layer_height, + 2, + ), + ) + ) + bottom_thickness_value.setReadOnly(True) + millimeter_label = QLabel(self.locale.Millimeter) - case "number_of_lids_layers": - self.ensure_sett("slicing.lids_depth") + self.panel.addWidget(bottom_thickness_label, self.cur_row, 3) + self.panel.addWidget(bottom_thickness_value, self.cur_row, 4) + self.panel.addWidget(millimeter_label, self.cur_row, 5) - number_of_lids_layers_label = QLabel(self.locale.NumberOfLidLayers) - number_of_lids_layers_value = LineEdit( - str(self.sett().slicing.lids_depth) - ) - number_of_lids_layers_value.setValidator(self.intValidator) - number_of_lids_layers_value.textChanged.connect( - self.__update_lid_thickness + def on_change(): + self.sett().slicing.bottoms_depth = self.__smart_float( + number_of_bottom_layers_value.text() ) - self.panel.addWidget(number_of_lids_layers_label, self.next_row, 1) - self.panel.addWidget(number_of_lids_layers_value, self.cur_row, 2) - - lid_thickness_label = QLabel(self.locale.LidsThickness) - lid_thickness_value = LineEdit( - str( - round( - self.sett().slicing.lids_depth - * self.sett().slicing.layer_height, - 2, - ), - ) + number_of_bottom_layers_value.textChanged.connect(on_change) + + self.__elements[name] = { + "label": number_of_bottom_layers_label, + "edit": number_of_bottom_layers_value, + "bottom_thickness_label": bottom_thickness_label, + "bottom_thickness_value": bottom_thickness_value, + } + + elif name == "number_of_lids_layers": + self.ensure_sett("slicing.lids_depth") + + number_of_lids_layers_label = QLabel(self.locale.NumberOfLidLayers) + number_of_lids_layers_value = LineEdit(str(self.sett().slicing.lids_depth)) + number_of_lids_layers_value.setValidator(self.intValidator) + number_of_lids_layers_value.textChanged.connect(self.__update_lid_thickness) + + self.panel.addWidget(number_of_lids_layers_label, self.next_row, 1) + self.panel.addWidget(number_of_lids_layers_value, self.cur_row, 2) + + lid_thickness_label = QLabel(self.locale.LidsThickness) + lid_thickness_value = LineEdit( + str( + round( + self.sett().slicing.lids_depth + * self.sett().slicing.layer_height, + 2, + ), ) - lid_thickness_value.setReadOnly(True) - millimeter_label = QLabel(self.locale.Millimeter) + ) + lid_thickness_value.setReadOnly(True) + millimeter_label = QLabel(self.locale.Millimeter) - self.panel.addWidget(lid_thickness_label, self.cur_row, 3) - self.panel.addWidget(lid_thickness_value, self.cur_row, 4) - self.panel.addWidget(millimeter_label, self.cur_row, 5) + self.panel.addWidget(lid_thickness_label, self.cur_row, 3) + self.panel.addWidget(lid_thickness_value, self.cur_row, 4) + self.panel.addWidget(millimeter_label, self.cur_row, 5) - def on_change(): - self.sett().slicing.lids_depth = self.__smart_float( - lid_thickness_value.text() - ) + def on_change(): + self.sett().slicing.lids_depth = self.__smart_float( + number_of_lids_layers_value.text() + ) - number_of_lids_layers_value.textChanged.connect(on_change) + number_of_lids_layers_value.textChanged.connect(on_change) - self.__elements[name] = { - "label": number_of_lids_layers_label, - "edit": number_of_lids_layers_value, - "lid_thickness_label": lid_thickness_label, - "lid_thickness_value": lid_thickness_value, - } + self.__elements[name] = { + "label": number_of_lids_layers_label, + "edit": number_of_lids_layers_value, + "lid_thickness_label": lid_thickness_label, + "lid_thickness_value": lid_thickness_value, + } - case "extruder_temp": - self.ensure_sett("slicing.extruder_temperature") + elif name == "extruder_temp": + self.ensure_sett("slicing.extruder_temperature") - extruder_temp_label = QLabel(self.locale.ExtruderTemp) - extruder_temp_value = LineEdit( - str(self.sett().slicing.extruder_temperature) - ) - extruder_temp_value.setValidator(self.intValidator) - self.panel.addWidget(extruder_temp_label, self.next_row, 1) - self.panel.addWidget( - extruder_temp_value, self.cur_row, 2, 1, self.col2_cells + extruder_temp_label = QLabel(self.locale.ExtruderTemp) + extruder_temp_value = LineEdit( + str(self.sett().slicing.extruder_temperature) + ) + extruder_temp_value.setValidator(self.intValidator) + self.panel.addWidget(extruder_temp_label, self.next_row, 1) + self.panel.addWidget( + extruder_temp_value, self.cur_row, 2, 1, self.col2_cells + ) + + def on_change(): + self.sett().slicing.extruder_temperature = self.__smart_float( + extruder_temp_value.text() ) - def on_change(): - self.sett().slicing.extruder_temperature = self.__smart_float( - extruder_temp_value.text() - ) + extruder_temp_value.textChanged.connect(on_change) - extruder_temp_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": extruder_temp_label, + "edit": extruder_temp_value, + } - self.__elements[name] = { - "label": extruder_temp_label, - "edit": extruder_temp_value, - } + elif name == "bed_temp": + self.ensure_sett("slicing.bed_temperature") - case "bed_temp": - self.ensure_sett("slicing.bed_temperature") + bed_temp_label = QLabel(self.locale.BedTemp) + bed_temp_value = LineEdit(str(self.sett().slicing.bed_temperature)) + bed_temp_value.setValidator(self.intValidator) + self.panel.addWidget(bed_temp_label, self.next_row, 1) + self.panel.addWidget(bed_temp_value, self.cur_row, 2, 1, self.col2_cells) - bed_temp_label = QLabel(self.locale.BedTemp) - bed_temp_value = LineEdit(str(self.sett().slicing.bed_temperature)) - bed_temp_value.setValidator(self.intValidator) - self.panel.addWidget(bed_temp_label, self.next_row, 1) - self.panel.addWidget( - bed_temp_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.bed_temperature = self.__smart_float( + bed_temp_value.text() ) - def on_change(): - self.sett().slicing.bed_temperature = self.__smart_float( - bed_temp_value.text() - ) + bed_temp_value.textChanged.connect(on_change) - bed_temp_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": bed_temp_label, + "edit": bed_temp_value, + } - self.__elements[name] = { - "label": bed_temp_label, - "edit": bed_temp_value, - } + elif name == "skirt_line_count": + self.ensure_sett("slicing.skirt_line_count") - case "skirt_line_count": - self.ensure_sett("slicing.skirt_line_count") + skirt_line_count_label = QLabel(self.locale.SkirtLineCount) + skirt_line_count_value = LineEdit(str(self.sett().slicing.skirt_line_count)) + skirt_line_count_value.setValidator(self.intValidator) + self.panel.addWidget(skirt_line_count_label, self.next_row, 1) + self.panel.addWidget( + skirt_line_count_value, self.cur_row, 2, 1, self.col2_cells + ) - skirt_line_count_label = QLabel(self.locale.SkirtLineCount) - skirt_line_count_value = LineEdit( - str(self.sett().slicing.skirt_line_count) - ) - skirt_line_count_value.setValidator(self.intValidator) - self.panel.addWidget(skirt_line_count_label, self.next_row, 1) - self.panel.addWidget( - skirt_line_count_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.skirt_line_count = self.__smart_float( + skirt_line_count_value.text() ) - def on_change(): - self.sett().slicing.skirt_line_count = self.__smart_float( - skirt_line_count_value.text() - ) + skirt_line_count_value.textChanged.connect(on_change) - skirt_line_count_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": skirt_line_count_label, + "edit": skirt_line_count_value, + } - self.__elements[name] = { - "label": skirt_line_count_label, - "edit": skirt_line_count_value, - } + elif name == "fan_speed": + self.ensure_sett("slicing.fan_speed") - case "fan_speed": - self.ensure_sett("slicing.fan_speed") + fan_speed_label = QLabel(self.locale.FanSpeed) + fan_speed_value = LineEdit(str(self.sett().slicing.fan_speed)) + fan_speed_value.setValidator(self.intValidator) + self.panel.addWidget(fan_speed_label, self.next_row, 1) + self.panel.addWidget(fan_speed_value, self.cur_row, 2, 1, self.col2_cells) - fan_speed_label = QLabel(self.locale.FanSpeed) - fan_speed_value = LineEdit(str(self.sett().slicing.fan_speed)) - fan_speed_value.setValidator(self.intValidator) - self.panel.addWidget(fan_speed_label, self.next_row, 1) - self.panel.addWidget( - fan_speed_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.fan_speed = self.__smart_float( + fan_speed_value.text() ) - def on_change(): - self.sett().slicing.fan_speed = self.__smart_float( - fan_speed_value.text() - ) + fan_speed_value.textChanged.connect(on_change) - fan_speed_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": fan_speed_label, + "edit": fan_speed_value, + } - self.__elements[name] = { - "label": fan_speed_label, - "edit": fan_speed_value, - } + elif name == "fan_off_layer1": + self.ensure_sett("slicing.fan_off_layer1") - case "fan_off_layer1": - self.ensure_sett("slicing.fan_off_layer1") + fan_off_layer1_label = QLabel(self.locale.FanOffLayer1) + fan_off_layer1_box = QCheckBox() + if self.sett().slicing.fan_off_layer1: + fan_off_layer1_box.setCheckState(QtCore.Qt.Checked) + self.panel.addWidget(fan_off_layer1_label, self.next_row, 1) + self.panel.addWidget( + fan_off_layer1_box, self.cur_row, 2, 1, self.col2_cells + ) - fan_off_layer1_label = QLabel(self.locale.FanOffLayer1) - fan_off_layer1_box = QCheckBox() - if self.sett().slicing.fan_off_layer1: - fan_off_layer1_box.setCheckState(QtCore.Qt.Checked) - self.panel.addWidget(fan_off_layer1_label, self.next_row, 1) - self.panel.addWidget( - fan_off_layer1_box, self.cur_row, 2, 1, self.col2_cells - ) + def on_change(): + self.sett().slicing.fan_off_layer1 = fan_off_layer1_box.isChecked() - def on_change(): - self.sett().slicing.fan_off_layer1 = fan_off_layer1_box.isChecked() + fan_off_layer1_box.stateChanged.connect(on_change) - fan_off_layer1_box.stateChanged.connect(on_change) + self.__elements[name] = { + "label": fan_off_layer1_label, + "checkbox": fan_off_layer1_box, + } - self.__elements[name] = { - "label": fan_off_layer1_label, - "checkbox": fan_off_layer1_box, - } + elif name == "print_speed": + self.ensure_sett("slicing.print_speed") - case "print_speed": - self.ensure_sett("slicing.print_speed") + print_speed_label = QLabel(self.locale.PrintSpeed) + print_speed_value = LineEdit(str(self.sett().slicing.print_speed)) + print_speed_value.setValidator(self.intValidator) + self.panel.addWidget(print_speed_label, self.next_row, 1) + self.panel.addWidget(print_speed_value, self.cur_row, 2, 1, self.col2_cells) - print_speed_label = QLabel(self.locale.PrintSpeed) - print_speed_value = LineEdit(str(self.sett().slicing.print_speed)) - print_speed_value.setValidator(self.intValidator) - self.panel.addWidget(print_speed_label, self.next_row, 1) - self.panel.addWidget( - print_speed_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.print_speed = self.__smart_float( + print_speed_value.text() ) - def on_change(): - self.sett().slicing.print_speed = self.__smart_float( - print_speed_value.text() - ) + print_speed_value.textChanged.connect(on_change) - print_speed_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": print_speed_label, + "edit": print_speed_value, + } - self.__elements[name] = { - "label": print_speed_label, - "edit": print_speed_value, - } + elif name == "print_speed_layer1": + self.ensure_sett("slicing.print_speed_layer1") - case "print_speed_layer1": - self.ensure_sett("slicing.print_speed_layer1") + print_speed_layer1_label = QLabel(self.locale.PrintSpeedLayer1) + print_speed_layer1_value = LineEdit( + str(self.sett().slicing.print_speed_layer1) + ) + print_speed_layer1_value.setValidator(self.intValidator) + self.panel.addWidget(print_speed_layer1_label, self.next_row, 1) + self.panel.addWidget( + print_speed_layer1_value, self.cur_row, 2, 1, self.col2_cells + ) - print_speed_layer1_label = QLabel(self.locale.PrintSpeedLayer1) - print_speed_layer1_value = LineEdit( - str(self.sett().slicing.print_speed_layer1) - ) - print_speed_layer1_value.setValidator(self.intValidator) - self.panel.addWidget(print_speed_layer1_label, self.next_row, 1) - self.panel.addWidget( - print_speed_layer1_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.print_speed_layer1 = self.__smart_float( + print_speed_layer1_value.text() ) - def on_change(): - self.sett().slicing.print_speed_layer1 = self.__smart_float( - print_speed_layer1_value.text() - ) + print_speed_layer1_value.textChanged.connect(on_change) - print_speed_layer1_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": print_speed_layer1_label, + "edit": print_speed_layer1_value, + } - self.__elements[name] = { - "label": print_speed_layer1_label, - "edit": print_speed_layer1_value, - } + elif name == "print_speed_wall": + self.ensure_sett("slicing.print_speed_wall") - case "print_speed_wall": - self.ensure_sett("slicing.print_speed_wall") + print_speed_wall_label = QLabel(self.locale.PrintSpeedWall) + print_speed_wall_value = LineEdit(str(self.sett().slicing.print_speed_wall)) + print_speed_wall_value.setValidator(self.intValidator) + self.panel.addWidget(print_speed_wall_label, self.next_row, 1) + self.panel.addWidget( + print_speed_wall_value, self.cur_row, 2, 1, self.col2_cells + ) - print_speed_wall_label = QLabel(self.locale.PrintSpeedWall) - print_speed_wall_value = LineEdit( - str(self.sett().slicing.print_speed_wall) + def on_change(): + self.sett().slicing.print_speed_wall = self.__smart_float( + print_speed_wall_value.text() ) - print_speed_wall_value.setValidator(self.intValidator) - self.panel.addWidget(print_speed_wall_label, self.next_row, 1) - self.panel.addWidget( - print_speed_wall_value, self.cur_row, 2, 1, self.col2_cells - ) - - def on_change(): - self.sett().slicing.print_speed_wall = self.__smart_float( - print_speed_wall_value.text() - ) - print_speed_wall_value.textChanged.connect(on_change) + print_speed_wall_value.textChanged.connect(on_change) - self.__elements[name] = { - "label": print_speed_wall_label, - "edit": print_speed_wall_value, - } + self.__elements[name] = { + "label": print_speed_wall_label, + "edit": print_speed_wall_value, + } - case "filling_type": - self.ensure_sett("slicing.filling_type") + elif name == "filling_type": + self.ensure_sett("slicing.filling_type") - filling_type_label = QLabel(self.locale.FillingType) - filling_type_values = QComboBox() - filling_type_values.addItems(self.locale.FillingTypeValues) - filling_type_values.setCurrentIndex( - locales.getLocaleByLang("en").FillingTypeValues.index( - self.sett().slicing.filling_type - ) - ) - self.panel.addWidget(filling_type_label, self.next_row, 1) - self.panel.addWidget( - filling_type_values, self.cur_row, 2, 1, self.col2_cells + filling_type_label = QLabel(self.locale.FillingType) + filling_type_values = QComboBox() + filling_type_values.addItems(self.locale.FillingTypeValues) + filling_type_values.setCurrentIndex( + locales.getLocaleByLang("en").FillingTypeValues.index( + self.sett().slicing.filling_type ) + ) + self.panel.addWidget(filling_type_label, self.next_row, 1) + self.panel.addWidget( + filling_type_values, self.cur_row, 2, 1, self.col2_cells + ) + + def on_change(): + self.sett().slicing.filling_type = locales.getLocaleByLang( + "en" + ).FillingTypeValues[filling_type_values.currentIndex()] - def on_change(): - self.sett().slicing.filling_type = locales.getLocaleByLang( - "en" - ).FillingTypeValues[filling_type_values.currentIndex()] + filling_type_values.currentIndexChanged.connect(on_change) - filling_type_values.currentIndexChanged.connect(on_change) + self.__elements[name] = { + "label": filling_type_label, + "values": filling_type_values, + "setting": "slicing.filling_type", + } - self.__elements[name] = { - "label": filling_type_label, - "values": filling_type_values, - "setting": "slicing.filling_type", - } + elif name == "fill_density": + self.ensure_sett("slicing.fill_density") - case "fill_density": - self.ensure_sett("slicing.fill_density") + fill_density_label = QLabel(self.locale.FillDensity) + fill_density_value = LineEdit(str(self.sett().slicing.fill_density)) + fill_density_value.setValidator(self.intValidator) + self.panel.addWidget(fill_density_label, self.next_row, 1) + self.panel.addWidget( + fill_density_value, self.cur_row, 2, 1, self.col2_cells + ) - fill_density_label = QLabel(self.locale.FillDensity) - fill_density_value = LineEdit(str(self.sett().slicing.fill_density)) - fill_density_value.setValidator(self.intValidator) - self.panel.addWidget(fill_density_label, self.next_row, 1) - self.panel.addWidget( - fill_density_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.fill_density = self.__smart_float( + fill_density_value.text() ) - def on_change(): - self.sett().slicing.fill_density = self.__smart_float( - fill_density_value.text() - ) + fill_density_value.textChanged.connect(on_change) - fill_density_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": fill_density_label, + "edit": fill_density_value, + "setting": "slicing.fill_density", + } - self.__elements[name] = { - "label": fill_density_label, - "edit": fill_density_value, - "setting": "slicing.fill_density", - } + elif name == "overlap_infill": + self.ensure_sett("slicing.overlapping_infill_percentage") - case "overlap_infill": - self.ensure_sett("slicing.overlapping_infill_percentage") + overlap_infill_label = QLabel(self.locale.OverlappingInfillPercentage) + overlap_infill_value = LineEdit( + str(self.sett().slicing.overlapping_infill_percentage) + ) + overlap_infill_value.setValidator(self.intValidator) + self.panel.addWidget(overlap_infill_label, self.next_row, 1) + self.panel.addWidget( + overlap_infill_value, self.cur_row, 2, 1, self.col2_cells + ) - overlap_infill_label = QLabel(self.locale.OverlappingInfillPercentage) - overlap_infill_value = LineEdit( - str(self.sett().slicing.overlapping_infill_percentage) - ) - overlap_infill_value.setValidator(self.intValidator) - self.panel.addWidget(overlap_infill_label, self.next_row, 1) - self.panel.addWidget( - overlap_infill_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.overlapping_infill_percentage = self.__smart_float( + overlap_infill_value.text() ) - def on_change(): - self.sett().slicing.overlapping_infill_percentage = ( - self.__smart_float(overlap_infill_value.text()) - ) + overlap_infill_value.textChanged.connect(on_change) - overlap_infill_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": overlap_infill_label, + "edit": overlap_infill_value, + } - self.__elements[name] = { - "label": overlap_infill_label, - "edit": overlap_infill_value, - } + elif name == "retraction_on": + self.ensure_sett("slicing.retraction_on") - case "retraction_on": - self.ensure_sett("slicing.retraction_on") + retraction_on_label = QLabel(self.locale.Retraction) + retraction_on_box = QCheckBox() + if self.sett().slicing.retraction_on: + retraction_on_box.setCheckState(QtCore.Qt.Checked) + self.panel.addWidget(retraction_on_label, self.next_row, 1) + self.panel.addWidget(retraction_on_box, self.cur_row, 2, 1, self.col2_cells) - retraction_on_label = QLabel(self.locale.Retraction) - retraction_on_box = QCheckBox() - if self.sett().slicing.retraction_on: - retraction_on_box.setCheckState(QtCore.Qt.Checked) - self.panel.addWidget(retraction_on_label, self.next_row, 1) - self.panel.addWidget( - retraction_on_box, self.cur_row, 2, 1, self.col2_cells - ) + def on_change(): + self.sett().slicing.retraction_on = retraction_on_box.isChecked() - def on_change(): - self.sett().slicing.retraction_on = retraction_on_box.isChecked() + retraction_on_box.stateChanged.connect(on_change) - retraction_on_box.stateChanged.connect(on_change) + self.__elements[name] = { + "label": retraction_on_label, + "checkbox": retraction_on_box, + } - self.__elements[name] = { - "label": retraction_on_label, - "checkbox": retraction_on_box, - } + elif name == "retraction_distance": + self.ensure_sett("slicing.retraction_distance") - case "retraction_distance": - self.ensure_sett("slicing.retraction_distance") + retraction_distance_label = QLabel(self.locale.RetractionDistance) + retraction_distance_value = LineEdit( + str(self.sett().slicing.retraction_distance) + ) + retraction_distance_value.setValidator(self.doubleValidator) + self.panel.addWidget(retraction_distance_label, self.next_row, 1) + self.panel.addWidget( + retraction_distance_value, self.cur_row, 2, 1, self.col2_cells + ) - retraction_distance_label = QLabel(self.locale.RetractionDistance) - retraction_distance_value = LineEdit( - str(self.sett().slicing.retraction_distance) - ) - retraction_distance_value.setValidator(self.doubleValidator) - self.panel.addWidget(retraction_distance_label, self.next_row, 1) - self.panel.addWidget( - retraction_distance_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.retraction_distance = self.__smart_float( + retraction_distance_value.text() ) - def on_change(): - self.sett().slicing.retraction_distance = self.__smart_float( - retraction_distance_value.text() - ) + retraction_distance_value.textChanged.connect(on_change) - retraction_distance_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": retraction_distance_label, + "edit": retraction_distance_value, + } - self.__elements[name] = { - "label": retraction_distance_label, - "edit": retraction_distance_value, - } + elif name == "retraction_speed": + self.ensure_sett("slicing.retraction_speed") - case "retraction_speed": - self.ensure_sett("slicing.retraction_speed") + retraction_speed_label = QLabel(self.locale.RetractionSpeed) + retraction_speed_value = LineEdit(str(self.sett().slicing.retraction_speed)) + retraction_speed_value.setValidator(self.intValidator) + self.panel.addWidget(retraction_speed_label, self.next_row, 1) + self.panel.addWidget( + retraction_speed_value, self.cur_row, 2, 1, self.col2_cells + ) - retraction_speed_label = QLabel(self.locale.RetractionSpeed) - retraction_speed_value = LineEdit( - str(self.sett().slicing.retraction_speed) - ) - retraction_speed_value.setValidator(self.intValidator) - self.panel.addWidget(retraction_speed_label, self.next_row, 1) - self.panel.addWidget( - retraction_speed_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.retraction_speed = self.__smart_float( + retraction_speed_value.text() ) - def on_change(): - self.sett().slicing.retraction_speed = self.__smart_float( - retraction_speed_value.text() - ) + retraction_speed_value.textChanged.connect(on_change) - retraction_speed_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": retraction_speed_label, + "edit": retraction_speed_value, + } - self.__elements[name] = { - "label": retraction_speed_label, - "edit": retraction_speed_value, - } + elif name == "retraction_compensation": + self.ensure_sett("slicing.retract_compensation_amount") - case "retraction_compensation": - self.ensure_sett("slicing.retract_compensation_amount") + retraction_compensation_label = QLabel( + self.locale.RetractCompensationAmount + ) + retraction_compensation_value = LineEdit( + str(self.sett().slicing.retract_compensation_amount) + ) + retraction_compensation_value.setValidator(self.doubleValidator) + self.panel.addWidget(retraction_compensation_label, self.next_row, 1) + self.panel.addWidget( + retraction_compensation_value, self.cur_row, 2, 1, self.col2_cells + ) - retraction_compensation_label = QLabel( - self.locale.RetractCompensationAmount - ) - retraction_compensation_value = LineEdit( - str(self.sett().slicing.retract_compensation_amount) - ) - retraction_compensation_value.setValidator(self.doubleValidator) - self.panel.addWidget(retraction_compensation_label, self.next_row, 1) - self.panel.addWidget( - retraction_compensation_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.retract_compensation_amount = self.__smart_float( + retraction_compensation_value.text() ) - def on_change(): - self.sett().slicing.retract_compensation_amount = ( - self.__smart_float(retraction_compensation_value.text()) - ) + retraction_compensation_value.textChanged.connect(on_change) - retraction_compensation_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": retraction_compensation_label, + "edit": retraction_compensation_value, + } - self.__elements[name] = { - "label": retraction_compensation_label, - "edit": retraction_compensation_value, - } + elif name == "material_shrinkage": + self.ensure_sett("slicing.material_shrinkage") - case "material_shrinkage": - self.ensure_sett("slicing.material_shrinkage") + material_shrinkage_label = QLabel(self.locale.MaterialShrinkage) + material_shrinkage_value = LineEdit( + str(self.sett().slicing.material_shrinkage) + ) + material_shrinkage_value.setValidator(self.doublePercentValidator) + self.panel.addWidget(material_shrinkage_label, self.next_row, 1) + self.panel.addWidget( + material_shrinkage_value, self.cur_row, 2, 1, self.col2_cells + ) - material_shrinkage_label = QLabel(self.locale.MaterialShrinkage) - material_shrinkage_value = LineEdit( - str(self.sett().slicing.material_shrinkage) - ) - material_shrinkage_value.setValidator(self.doublePercentValidator) - self.panel.addWidget(material_shrinkage_label, self.next_row, 1) - self.panel.addWidget( - material_shrinkage_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().slicing.material_shrinkage = self.__smart_float( + material_shrinkage_value.text() ) - def on_change(): - self.sett().slicing.material_shrinkage = self.__smart_float( - material_shrinkage_value.text() - ) + material_shrinkage_value.textChanged.connect(on_change) - material_shrinkage_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": material_shrinkage_label, + "edit": material_shrinkage_value, + } - self.__elements[name] = { - "label": material_shrinkage_label, - "edit": material_shrinkage_value, - } + elif name == "supports_on": + self.ensure_sett("supports.enabled") + # supports_label = QLabel(self.locale.SupportsSettings) - case "supports_on": - self.ensure_sett("supports.enabled") - # supports_label = QLabel(self.locale.SupportsSettings) + # supports on + supports_on_label = QLabel(self.locale.SupportsOn) + supports_on_box = QCheckBox() + if self.sett().supports.enabled: + supports_on_box.setCheckState(QtCore.Qt.Checked) - # supports on - supports_on_label = QLabel(self.locale.SupportsOn) - supports_on_box = QCheckBox() - if self.sett().supports.enabled: - supports_on_box.setCheckState(QtCore.Qt.Checked) + # self.panel.addWidget(supports_label, self.next_row, 1) - # self.panel.addWidget(supports_label, self.next_row, 1) + self.panel.addWidget(supports_on_label, self.next_row, 1) + self.panel.addWidget(supports_on_box, self.cur_row, 2, 1, self.col2_cells) - self.panel.addWidget(supports_on_label, self.next_row, 1) - self.panel.addWidget( - supports_on_box, self.cur_row, 2, 1, self.col2_cells - ) + def on_change(): + self.sett().supports.enabled = supports_on_box.isChecked() - def on_change(): - self.sett().supports.enabled = supports_on_box.isChecked() + supports_on_box.stateChanged.connect(on_change) - supports_on_box.stateChanged.connect(on_change) + self.__elements[name] = { + # "group_label": supports_label, + "label": supports_on_label, + "checkbox": supports_on_box, + } - self.__elements[name] = { - # "group_label": supports_label, - "label": supports_on_label, - "checkbox": supports_on_box, - } + elif name == "support_density": + self.ensure_sett("supports.fill_density") - case "support_density": - self.ensure_sett("supports.fill_density") + support_density_label = QLabel(self.locale.SupportDensity) + support_density_value = LineEdit(str(self.sett().supports.fill_density)) + support_density_value.setValidator(self.intValidator) + self.panel.addWidget(support_density_label, self.next_row, 1) + self.panel.addWidget( + support_density_value, self.cur_row, 2, 1, self.col2_cells + ) - support_density_label = QLabel(self.locale.SupportDensity) - support_density_value = LineEdit(str(self.sett().supports.fill_density)) - support_density_value.setValidator(self.intValidator) - self.panel.addWidget(support_density_label, self.next_row, 1) - self.panel.addWidget( - support_density_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().supports.fill_density = self.__smart_float( + support_density_value.text() ) - def on_change(): - self.sett().supports.fill_density = self.__smart_float( - support_density_value.text() - ) - - support_density_value.textChanged.connect(on_change) + support_density_value.textChanged.connect(on_change) - self.__elements[name] = { - "label": support_density_label, - "edit": support_density_value, - } + self.__elements[name] = { + "label": support_density_label, + "edit": support_density_value, + } - case "support_fill_type": - self.ensure_sett("supports.fill_type") + elif name == "support_fill_type": + self.ensure_sett("supports.fill_type") - support_fill_type_label = QLabel(self.locale.FillingType) - support_fill_type_values = QComboBox() - support_fill_type_values.addItems(self.locale.FillingTypeValues) - support_fill_type_values.setCurrentIndex( - locales.getLocaleByLang("en").FillingTypeValues.index( - self.sett().supports.fill_type - ) - ) - self.panel.addWidget(support_fill_type_label, self.next_row, 1) - self.panel.addWidget( - support_fill_type_values, self.cur_row, 2, 1, self.col2_cells + support_fill_type_label = QLabel(self.locale.FillingType) + support_fill_type_values = QComboBox() + support_fill_type_values.addItems(self.locale.FillingTypeValues) + support_fill_type_values.setCurrentIndex( + locales.getLocaleByLang("en").FillingTypeValues.index( + self.sett().supports.fill_type ) + ) + self.panel.addWidget(support_fill_type_label, self.next_row, 1) + self.panel.addWidget( + support_fill_type_values, self.cur_row, 2, 1, self.col2_cells + ) + + def on_change(): + self.sett().supports.fill_type = locales.getLocaleByLang( + "en" + ).FillingTypeValues[support_fill_type_values.currentIndex()] - def on_change(): - self.sett().supports.fill_type = locales.getLocaleByLang( - "en" - ).FillingTypeValues[support_fill_type_values.currentIndex()] + support_fill_type_values.currentIndexChanged.connect(on_change) - support_fill_type_values.currentIndexChanged.connect(on_change) + self.__elements[name] = { + "label": support_fill_type_label, + "values": support_fill_type_values, + } - self.__elements[name] = { - "label": support_fill_type_label, - "values": support_fill_type_values, - } + elif name == "support_xy_offset": + self.ensure_sett("supports.xy_offset") - case "support_xy_offset": - self.ensure_sett("supports.xy_offset") + support_xy_offset_label = QLabel(self.locale.SupportXYOffset) + support_xy_offset_value = LineEdit(str(self.sett().supports.xy_offset)) + support_xy_offset_value.setValidator(self.doubleValidator) + self.panel.addWidget(support_xy_offset_label, self.next_row, 1) + self.panel.addWidget( + support_xy_offset_value, self.cur_row, 2, 1, self.col2_cells + ) - support_xy_offset_label = QLabel(self.locale.SupportXYOffset) - support_xy_offset_value = LineEdit(str(self.sett().supports.xy_offset)) - support_xy_offset_value.setValidator(self.intValidator) - self.panel.addWidget(support_xy_offset_label, self.next_row, 1) - self.panel.addWidget( - support_xy_offset_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().supports.xy_offset = self.__smart_float( + support_xy_offset_value.text() ) - def on_change(): - self.sett().supports.xy_offset = self.__smart_float( - support_xy_offset_value.text() - ) + support_xy_offset_value.textChanged.connect(on_change) - support_xy_offset_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": support_xy_offset_label, + "edit": support_xy_offset_value, + } - self.__elements[name] = { - "label": support_xy_offset_label, - "edit": support_xy_offset_value, - } + elif name == "support_z_offset": + self.ensure_sett("supports.z_offset_layers") - case "support_z_offset": - self.ensure_sett("supports.z_offset_layers") + support_z_offset_label = QLabel(self.locale.SupportZOffsetLayers) + support_z_offset_value = LineEdit(str(self.sett().supports.z_offset_layers)) + support_z_offset_value.setValidator(self.intValidator) + self.panel.addWidget(support_z_offset_label, self.next_row, 1) + self.panel.addWidget( + support_z_offset_value, self.cur_row, 2, 1, self.col2_cells + ) - support_z_offset_label = QLabel(self.locale.SupportZOffsetLayers) - support_z_offset_value = LineEdit( - str(self.sett().supports.z_offset_layers) - ) - support_z_offset_value.setValidator(self.intValidator) - self.panel.addWidget(support_z_offset_label, self.next_row, 1) - self.panel.addWidget( - support_z_offset_value, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().supports.z_offset_layers = self.__smart_float( + support_z_offset_value.text() ) - def on_change(): - self.sett().supports.z_offset_layers = self.__smart_float( - support_z_offset_value.text() - ) + support_z_offset_value.textChanged.connect(on_change) - support_z_offset_value.textChanged.connect(on_change) + self.__elements[name] = { + "label": support_z_offset_label, + "edit": support_z_offset_value, + } - self.__elements[name] = { - "label": support_z_offset_label, - "edit": support_z_offset_value, - } + elif name == "support_priority_zoffset": + self.ensure_sett("supports.priority_z_offset") - case "support_priority_zoffset": - self.ensure_sett("supports.priority_z_offset") + support_priority_zoffset_label = QLabel(self.locale.SupportPriorityZOffset) + support_priorityz_offset_box = QCheckBox() + if self.sett().supports.priority_z_offset: + support_priorityz_offset_box.setCheckState(QtCore.Qt.Checked) - support_priority_zoffset_label = QLabel( - self.locale.SupportPriorityZOffset - ) - support_priorityz_offset_box = QCheckBox() - if self.sett().supports.priority_z_offset: - support_priorityz_offset_box.setCheckState(QtCore.Qt.Checked) + self.panel.addWidget(support_priority_zoffset_label, self.next_row, 1) + self.panel.addWidget( + support_priorityz_offset_box, self.cur_row, 2, 1, self.col2_cells + ) - self.panel.addWidget(support_priority_zoffset_label, self.next_row, 1) - self.panel.addWidget( - support_priorityz_offset_box, self.cur_row, 2, 1, self.col2_cells + def on_change(): + self.sett().supports.priority_z_offset = ( + support_priorityz_offset_box.isChecked() ) - def on_change(): - self.sett().supports.priority_z_offset = ( - support_priorityz_offset_box.isChecked() - ) - - support_priorityz_offset_box.stateChanged.connect(on_change) + support_priorityz_offset_box.stateChanged.connect(on_change) - self.__elements[name] = { - "label": support_priority_zoffset_label, - "checkbox": support_priorityz_offset_box, - } + self.__elements[name] = { + "label": support_priority_zoffset_label, + "checkbox": support_priorityz_offset_box, + } - case "support_number_of_bottom_layers": - self.ensure_sett("supports.bottoms_depth") + elif name == "support_number_of_bottom_layers": + self.ensure_sett("supports.bottoms_depth") - support_number_of_bottom_layers_label = QLabel( - self.locale.NumberOfBottomLayers - ) - support_number_of_bottom_layers_value = LineEdit( - str(self.sett().supports.bottoms_depth) - ) - support_number_of_bottom_layers_value.setValidator(self.intValidator) - support_number_of_bottom_layers_value.textChanged.connect( - self.__update_supports_bottom_thickness - ) - self.panel.addWidget( - support_number_of_bottom_layers_label, self.next_row, 1 - ) - self.panel.addWidget( - support_number_of_bottom_layers_value, self.cur_row, 2 + support_number_of_bottom_layers_label = QLabel( + self.locale.NumberOfBottomLayers + ) + support_number_of_bottom_layers_value = LineEdit( + str(self.sett().supports.bottoms_depth) + ) + support_number_of_bottom_layers_value.setValidator(self.intValidator) + support_number_of_bottom_layers_value.textChanged.connect( + self.__update_supports_bottom_thickness + ) + self.panel.addWidget( + support_number_of_bottom_layers_label, self.next_row, 1 + ) + self.panel.addWidget(support_number_of_bottom_layers_value, self.cur_row, 2) + + bottom_thickness_label = QLabel(self.locale.BottomThickness) + bottom_thickness_value = LineEdit( + str( + round( + self.sett().supports.bottoms_depth + * self.sett().slicing.layer_height, + 2, + ), ) + ) + bottom_thickness_value.setReadOnly(True) + millimeter_label = QLabel(self.locale.Millimeter) - bottom_thickness_label = QLabel(self.locale.BottomThickness) - bottom_thickness_value = LineEdit( - str( - round( - self.sett().supports.bottoms_depth - * self.sett().slicing.layer_height, - 2, - ), - ) + self.panel.addWidget(bottom_thickness_label, self.cur_row, 3) + self.panel.addWidget(bottom_thickness_value, self.cur_row, 4) + self.panel.addWidget(millimeter_label, self.cur_row, 5) + + def on_change(): + self.sett().supports.bottoms_depth = self.__smart_float( + support_number_of_bottom_layers_value.text() ) - bottom_thickness_value.setReadOnly(True) - millimeter_label = QLabel(self.locale.Millimeter) - self.panel.addWidget(bottom_thickness_label, self.cur_row, 3) - self.panel.addWidget(bottom_thickness_value, self.cur_row, 4) - self.panel.addWidget(millimeter_label, self.cur_row, 5) + support_number_of_bottom_layers_value.textChanged.connect(on_change) - def on_change(): - self.sett().supports.bottoms_depth = self.__smart_float( - bottom_thickness_value.text() - ) + self.__elements[name] = { + "label": support_number_of_bottom_layers_label, + "edit": support_number_of_bottom_layers_value, + "bottom_thickness_label": bottom_thickness_label, + "bottom_thickness_value": bottom_thickness_value, + } - support_number_of_bottom_layers_value.textChanged.connect(on_change) + elif name == "support_number_of_lid_layers": + self.ensure_sett("supports.lids_depth") - self.__elements[name] = { - "label": support_number_of_bottom_layers_label, - "edit": support_number_of_bottom_layers_value, - "bottom_thickness_label": bottom_thickness_label, - "bottom_thickness_value": bottom_thickness_value, - } + support_number_of_lid_layers_label = QLabel(self.locale.NumberOfLidLayers) + support_number_of_lid_layers_value = LineEdit( + str(self.sett().supports.lids_depth) + ) + support_number_of_lid_layers_value.setValidator(self.intValidator) + support_number_of_lid_layers_value.textChanged.connect( + self.__update_supports_lid_thickness + ) + self.panel.addWidget(support_number_of_lid_layers_label, self.next_row, 1) + self.panel.addWidget(support_number_of_lid_layers_value, self.cur_row, 2) + + lid_thickness_label = QLabel(self.locale.LidsThickness) + lid_thickness_value = LineEdit( + str( + round( + self.sett().supports.lids_depth + * self.sett().slicing.layer_height, + 2, + ), + ) + ) + lid_thickness_value.setReadOnly(True) + millimeter_label = QLabel(self.locale.Millimeter) - case "support_number_of_lid_layers": - self.ensure_sett("supports.lids_depth") + self.panel.addWidget(lid_thickness_label, self.cur_row, 3) + self.panel.addWidget(lid_thickness_value, self.cur_row, 4) + self.panel.addWidget(millimeter_label, self.cur_row, 5) - support_number_of_lid_layers_label = QLabel( - self.locale.NumberOfLidLayers - ) - support_number_of_lid_layers_value = LineEdit( - str(self.sett().supports.lids_depth) - ) - support_number_of_lid_layers_value.setValidator(self.intValidator) - support_number_of_lid_layers_value.textChanged.connect( - self.__update_supports_lid_thickness - ) - self.panel.addWidget( - support_number_of_lid_layers_label, self.next_row, 1 - ) - self.panel.addWidget( - support_number_of_lid_layers_value, self.cur_row, 2 + def on_change(): + self.sett().supports.lids_depth = self.__smart_float( + support_number_of_lid_layers_value.text() ) - lid_thickness_label = QLabel(self.locale.LidsThickness) - lid_thickness_value = LineEdit( - str( - round( - self.sett().supports.lids_depth - * self.sett().slicing.layer_height, - 2, - ), - ) - ) - lid_thickness_value.setReadOnly(True) - millimeter_label = QLabel(self.locale.Millimeter) + support_number_of_lid_layers_value.textChanged.connect(on_change) - self.panel.addWidget(lid_thickness_label, self.cur_row, 3) - self.panel.addWidget(lid_thickness_value, self.cur_row, 4) - self.panel.addWidget(millimeter_label, self.cur_row, 5) + self.__elements[name] = { + "label": support_number_of_lid_layers_label, + "edit": support_number_of_lid_layers_value, + "lid_thickness_label": lid_thickness_label, + "lid_thickness_value": lid_thickness_value, + } + elif name == "critical_angle": + self.ensure_sett("slicing.angle") - def on_change(): - self.sett().supports.lids_depth = self.__smart_float( - lid_thickness_value.text() - ) + angle_label = QLabel(self.locale.CriticalWallOverhangAngle) + angle_value = LineEdit(str(self.sett().slicing.angle)) + angle_value.setValidator(self.doubleValidator) + self.panel.addWidget(angle_label, self.next_row, 1) + self.panel.addWidget(angle_value, self.cur_row, 2, 1, self.col2_cells) + + def on_change(): + self.sett().slicing.angle = self.__smart_float(angle_value.text()) - support_number_of_lid_layers_value.textChanged.connect(on_change) + angle_value.textChanged.connect(on_change) - self.__elements[name] = { - "label": support_number_of_lid_layers_label, - "edit": support_number_of_lid_layers_value, - "lid_thickness_label": lid_thickness_label, - "lid_thickness_value": lid_thickness_value, - } + self.__elements[name] = { + "label": angle_label, + "edit": angle_value, + } # add row index for element self.__elements[name]["row_idx"] = self.cur_row diff --git a/src/window.py b/src/window.py index 683cd7c..9e71d72 100644 --- a/src/window.py +++ b/src/window.py @@ -3,6 +3,7 @@ import vtk, src from PyQt5 import QtCore from PyQt5 import QtGui +from PyQt5.QtCore import Qt, QEvent from PyQt5.QtCore import Qt from PyQt5.QtWidgets import ( QMainWindow, @@ -29,7 +30,7 @@ from src import locales, gui_utils, interactor_style from src.InteractorAroundActivePlane import InteractionAroundActivePlane -from src.gui_utils import plane_tf, Plane, Cone +from src.gui_utils import plane_tf, Plane, Cone, showErrorDialog from src.settings import ( sett, get_color, @@ -70,10 +71,28 @@ def __init__(self, parent=None): self.setDropIndicatorShown(True) self.setAcceptDrops(True) - def dragMoveEvent(self, event): + def dragEnterEvent(self, e: QtGui.QDragEnterEvent) -> None: + # we cannot start dragging the first row + item = self.selectedItems()[0] + idx = self.indexFromItem(item) + if idx.row() == 0: + e.ignore() + return + + return super().dragEnterEvent(e) + + def dragMoveEvent(self, event: QtGui.QDragMoveEvent) -> None: self.itemIsMoving = True super().dragMoveEvent(event) + def dropEvent(self, event): + # we cannot drop on the first row + if self.indexAt(event.pos()).row() == 0: + showErrorDialog(locales.getLocale().CannotDropHere) + return + + super().dropEvent(event) + class MainWindow(QMainWindow): from src.figure_editor import FigureEditor @@ -149,6 +168,22 @@ def __init__(self, parent=None): self.place_button.setFixedWidth(240) page_layout.addWidget(self.place_button, 1, 2) + self.cancel_action = QPushButton(self) + self.cancel_action.setIcon(QtGui.QIcon("icons/undo.png")) + self.cancel_action.setIconSize(QtCore.QSize(20, 20)) + self.cancel_action.setToolTip("Undo") + self.cancel_action.setCheckable(False) + self.cancel_action.setFixedWidth(30) + page_layout.addWidget(self.cancel_action, 1, 4) + + self.return_action = QPushButton(self) + self.return_action.setIcon(QtGui.QIcon("icons/redo.png")) + self.return_action.setIconSize(QtCore.QSize(20, 20)) + self.return_action.setToolTip("Redo") + self.return_action.setCheckable(False) + self.return_action.setFixedWidth(30) + page_layout.addWidget(self.return_action, 1, 5) + page_layout.addWidget(self.init_stl_move_panel(), 2, 0, 1, 5) page_layout.setColumnStretch(0, 0) page_layout.setRowStretch(0, 0) @@ -222,6 +257,7 @@ def projectChangeDialog(self): def init3d_widget(self): widget3d = QVTKRenderWindowInteractor(self) + widget3d.installEventFilter(self) self.render = vtk.vtkRenderer() self.render.SetBackground(get_color("white")) @@ -303,11 +339,12 @@ def add_legend(self): self.legend.GetPositionCoordinate().SetValue(0, 0) self.legend.GetPosition2Coordinate().SetCoordinateSystemToDisplay() self.legend.GetPosition2Coordinate().SetValue(290, 3 * 30) - self.legend.SetEntry(0, hackData, "rotate - left mouse button", [1, 1, 1]) - self.legend.SetEntry( - 1, hackData, "move - middle mouse button (or shift+left)", [1, 1, 1] - ) - self.legend.SetEntry(2, hackData, "scale - right mouse button", [1, 1, 1]) + + legend_color = [192, 192, 192] + self.legend.SetEntry(0, hackData, "rotate - left mouse button", legend_color) + self.legend.SetEntry(1, hackData, "move - right mouse button", legend_color) + self.legend.SetEntry(2, hackData, "scale - mouse wheel", legend_color) + self.render.AddActor(self.legend) def init_right_panel(self): @@ -402,20 +439,7 @@ def get_cur_row(): self.save_gcode_button = QPushButton(self.locale.SaveGCode) buttons_layout.addWidget(self.save_gcode_button, get_cur_row(), 3) - - self.critical_wall_overhang_angle_label = QLabel( - self.locale.CriticalWallOverhangAngle - ) - buttons_layout.addWidget( - self.critical_wall_overhang_angle_label, get_next_row(), 1, 1, 2 - ) buttons_layout.setColumnMinimumWidth(1, 230) - self.colorize_angle_value = LineEdit(str(sett().slicing.angle)) - self.colorize_angle_value.setValidator(doubleValidator) - buttons_layout.addWidget(self.colorize_angle_value, get_cur_row(), 2, 1, 1) - - self.color_model_button = QPushButton(self.locale.ColorModel) - buttons_layout.addWidget(self.color_model_button, get_cur_row(), 3) self.slice_vip_button = QPushButton(self.locale.SliceVip) buttons_layout.addWidget(self.slice_vip_button, get_next_row(), 1, 1, 2) @@ -472,6 +496,9 @@ def init_figure_panel(self): self.remove_plane_button = QPushButton(self.locale.DeletePlane) bottom_layout.addWidget(self.remove_plane_button, 3, 2) + self.color_model_button = QPushButton(self.locale.ColorModel) + bottom_layout.addWidget(self.color_model_button, 3, 3) + self.edit_figure_button = QPushButton(self.locale.EditFigure) bottom_layout.addWidget(self.edit_figure_button, 4, 2) @@ -531,6 +558,7 @@ def scaleSet(self): return scalePos, scaleNeg, scaleSet self.stl_move_panel = StlMovePanel( + self, { (0, "X"): translate(1, 0, 0), (0, "Y"): translate(0, 1, 0), @@ -664,6 +692,31 @@ def change_layer_view( # self.rotateAnyPlane(self.planesActors[i], self.planes[i], currRotation) return new_slider_value + def eventFilter(self, obj, event): + if event.type() == QEvent.KeyPress: + if not self.keyPressProcessing(event): + return super().eventFilter(obj, event) + return True + return super().eventFilter(obj, event) + + def keyPressEvent(self, event): + if not self.keyPressProcessing(event): + super().keyPressEvent(event) + + def keyPressProcessing(self, event): + if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_S: + self.save_project_action.trigger() + return True + + if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_Z: + self.shift_state() + return True + elif event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_Y: + self.shift_state(False) + return True + + return False + def move_stl2(self): if self.move_button.isChecked(): self.state_moving() @@ -700,7 +753,11 @@ def TransformActor(obj, event): self.stlActor.lastMove = origin self.model_centering_box.setChecked(False) + def EndTransform(obj, event): + self.save_current_movement() + self.boxWidget.AddObserver("InteractionEvent", TransformActor) + self.boxWidget.AddObserver("EndInteractionEvent", EndTransform) else: self.boxWidget.SetEnabled(True) # self.interactor.GetInteractorStyle().SetCurrentStyleToTrackballActor() @@ -721,6 +778,52 @@ def TransformActor(obj, event): # self.interactor.GetInteractorStyle().SetCurrentStyleToTrackballCamera() self.reload_scene() + def save_current_movement(self): + movements = self.stlActor.movements_array + current_index = self.stlActor.current_movement_index + + movements = [movement for movement in movements if movement[0] <= current_index] + + movement = self.copyTransform(self.stlActor.GetUserTransform()) + movements.append((current_index + 1, movement)) + + max_movements = 100 + if len(movements) > max_movements: + movements.pop(0) + + self.stlActor.movements_array = movements + self.stlActor.current_movement_index = len(movements) - 1 + + # We move on to the nearest state of movement of the model. + # If cancel=True, go back. If cancel=False, move forward. + def shift_state(self, cancel=True): + current_index = self.stlActor.current_movement_index + movements = self.stlActor.movements_array + + if cancel: + current_index -= 1 + else: + current_index += 1 + + if (current_index > len(movements) - 1) or (current_index < 0): + return False + + transform = movements[current_index][1] + + self.stlActor.SetUserTransform(transform) + if not self.boxWidget is None: + self.boxWidget.SetTransform(transform) + + self.updateTransform() + self.reload_scene() + + self.stlActor.current_movement_index = current_index + + def copyTransform(self, transform): + new_transform = vtk.vtkTransform() + new_transform.SetMatrix(transform.GetMatrix()) + return new_transform + def updateTransform(self): tf = self.stlActor.GetUserTransform() x, y, z = tf.GetPosition() @@ -753,6 +856,10 @@ def load_stl(self, stl_actor): self.clear_scene() self.boxWidget = None self.stlActor = stl_actor + self.stlActor.movements_array = [ + (0, self.copyTransform(self.stlActor.GetUserTransform())) + ] + self.stlActor.current_movement_index = 0 self.stlActor.addUserTransformUpdateCallback(self.stl_move_panel.update) # self.actor_interactor_style.setStlActor(self.stlActor) self.updateTransform() @@ -962,6 +1069,8 @@ def state_nothing(self): self.hide_checkbox.setChecked(False) self.bottom_panel.setEnabled(False) self.stl_move_panel.setEnabled(False) + self.cancel_action.setEnabled(False) + self.return_action.setEnabled(False) self.state = NothingState def state_gcode(self, layers_count): @@ -985,6 +1094,8 @@ def state_gcode(self, layers_count): self.hide_checkbox.setChecked(True) self.bottom_panel.setEnabled(False) self.stl_move_panel.setEnabled(False) + self.cancel_action.setEnabled(False) + self.return_action.setEnabled(False) self.state = GCodeState def state_stl(self): @@ -1007,6 +1118,8 @@ def state_stl(self): self.hide_checkbox.setChecked(False) self.bottom_panel.setEnabled(True) self.stl_move_panel.setEnabled(False) + self.cancel_action.setEnabled(True) + self.return_action.setEnabled(True) self.state = StlState def state_moving(self): @@ -1020,7 +1133,7 @@ def state_moving(self): self.picture_slider.setEnabled(False) self.picture_slider.setSliderPosition(0) self.move_button.setEnabled(True) - self.place_button.setEnabled(True) + self.place_button.setEnabled(False) self.load_model_button.setEnabled(False) self.slice3a_button.setEnabled(False) self.color_model_button.setEnabled(False) @@ -1029,6 +1142,8 @@ def state_moving(self): # self.hide_checkbox.setChecked(False) self.bottom_panel.setEnabled(False) self.stl_move_panel.setEnabled(True) + self.cancel_action.setEnabled(True) + self.return_action.setEnabled(True) self.state = MovingState def state_both(self, layers_count): @@ -1043,7 +1158,7 @@ def state_both(self, layers_count): self.picture_slider.setMaximum(layers_count) self.picture_slider.setSliderPosition(layers_count) self.move_button.setEnabled(True) - self.place_button.setEnabled(True) + self.place_button.setEnabled(False) self.load_model_button.setEnabled(True) self.slice3a_button.setEnabled(True) self.color_model_button.setEnabled(True) @@ -1052,6 +1167,8 @@ def state_both(self, layers_count): self.hide_checkbox.setChecked(True) self.bottom_panel.setEnabled(True) self.stl_move_panel.setEnabled(False) + self.cancel_action.setEnabled(True) + self.return_action.setEnabled(True) self.state = BothState def reset_colorize(self):