Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/settings loading #173

Merged
merged 2 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

logging.basicConfig(
filename="interface.log",
filemode="a+",
filemode="w+",
level=logging.INFO,
format="%(asctime)s %(message)s",
)
Expand Down Expand Up @@ -89,6 +89,8 @@ def open_project(project_path: str):
sett().project_path = project_path
create_temporary_project_files()

logging.debug(f"after we opened project, settings are: {sett()}")

window = MainWindow()
window.close_signal.connect(entry_window.show)

Expand Down
1 change: 1 addition & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ supports:
fill_density: 5
bottoms_depth: 0
lids_depth: 0
create_walls: true
uninterrupted_print:
enabled: false
cut_distance: 0.0
Expand Down
32 changes: 32 additions & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import pathlib
import base64
import logging

import yaml
import vtk
Expand Down Expand Up @@ -61,15 +62,23 @@ def copy_project_files(project_path: str):


def project_change_check():
logging.debug("Checking project change")
save_settings("vip")
saved_settings = Settings(
read_settings(str(pathlib.Path(sett().project_path, "settings.yaml")))
)
logging.debug("Saved settings:")
logging.debug(saved_settings)
logging.debug("Current settings:")
logging.debug(sett())
if sett() != saved_settings:
logging.debug("Saved settings do not match current settings.")
return False
if not compare_project_file("model.stl"):
logging.debug("Saved model.stl does not match current model.stl.")
return False
if not compare_figures(saved_settings):
logging.debug("Saved figures do not match current figures.")
return False

return True
Expand All @@ -83,13 +92,16 @@ def compare_figures(settings):
figures_from_settings = []

if len(current_figures) != len(figures_from_settings):
logging.debug("Number of figures does not match")
return False

for i in range(len(current_figures)):
if current_figures[i]["description"] != figures_from_settings[i].description:
logging.debug(f"Description of figure {i} does not match")
return False

if current_figures[i]["settings"] != figures_from_settings[i].settings:
logging.debug(f"Settings of figure {i} does not match")
return False

return True
Expand Down Expand Up @@ -209,6 +221,7 @@ def load_settings(filename=""):

data = read_settings(filename)
if data != None:
logging.debug("Settings loaded")
_sett = Settings(data)

# check if the format is similar
Expand All @@ -235,6 +248,18 @@ def read_settings(filename=""):

with open(filename) as f:
data = yaml.safe_load(f)

# right now let's check that some fields are just None,
# just because they were not found in the new template
def check_children(obj):
for key, value in obj.items():
if isinstance(value, dict):
check_children(value)
elif value is None:
logging.debug(f"Value of {key} is None")

check_children(data)

return data

return None
Expand Down Expand Up @@ -344,24 +369,31 @@ def __eq__(self, other):
"print_time",
"consumption_material",
"planes_contact_with_nozzle",
# for some reason this is temporary field that is not being updated well
"stl_file",
"printer_dir",
]

# try to compare attributes from left to right
for attr in self.__dict__:
if attr in ignore_attributes:
continue
if not hasattr(other, attr):
logging.debug(f"Attribute {attr} not found in other")
return False
if getattr(self, attr) != getattr(other, attr):
logging.debug(f"Attribute {attr} does not match")
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):
logging.debug(f"Attribute {attr} not found in self")
return False
if getattr(self, attr) != getattr(other, attr):
logging.debug(f"Attribute {attr} does not match")
return False

return True
Expand Down
17 changes: 12 additions & 5 deletions src/settings_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)

from src import locales
from src.settings import sett, APP_PATH, Settings
from src.settings import sett, APP_PATH, Settings, read_settings
from src.qt_utils import ClickableLineEdit, LineEdit

import os.path as path
Expand Down Expand Up @@ -61,7 +61,7 @@ class SettingsWidget(QWidget):
"material_shrinkage",
"flow_rate", # Коэффициент потока расплава
"pressure_advance_on",
"pressure_advance_rate",
"pressure_advance",
"random_layer_start",
"is_wall_outside_in",
# TODO: add separate dummy setting to mark the beginning of supports settings
Expand Down Expand Up @@ -92,6 +92,9 @@ def __init__(self, parent=None, settings_provider: callable = None):

self.sett = settings_provider

# TODO: Load the bundled settings
self.bundled_settings = Settings(read_settings(filename=None))

self.panel = QGridLayout()
self.panel.setSpacing(5)
self.panel.setColumnStretch(1, 1)
Expand Down Expand Up @@ -340,7 +343,11 @@ def ensure_sett(self, name: str):
"""
attrs = name.split(".")

global_top = sett()
# TODO: right here global top should be something different,
# I suppose inside this widget we should load kinda
# global settings object with the original bundled data
# global_top = sett()
global_top = self.bundled_settings
top_level = self.sett()
for idx, attr in enumerate(attrs):
if not hasattr(top_level, attr):
Expand Down Expand Up @@ -1160,8 +1167,8 @@ def on_change():
"checkbox": pressure_advance_on_box,
}

elif name == "pressure_advance_rate":
self.ensure_sett("slicing.pressure_advance_rate")
elif name == "pressure_advance":
self.ensure_sett("slicing.pressure_advance")

pressure_advance_label = QLabel(self.locale.PressureAdvanceValue)
pressure_advance_value = LineEdit(str(self.sett().slicing.pressure_advance))
Expand Down
7 changes: 7 additions & 0 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@ def get_cur_row():

self.setts = SettingsWidget(settings_provider=sett).with_all()

# check if there is some stuff going on with loaded and missed settings
logging.debug("Loaded settings after settings widget: %s", sett())

# and when some of these parameters are null, we are actually better
# just take their defalts from the bundled settings yaml config
# this way these mismatched settings will be fixed

scroll = QScrollArea()
scroll.setWidget(self.setts)
scroll.setWidgetResizable(True)
Expand Down