Skip to content

Commit

Permalink
fix: change yaml load and default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjonok committed Jul 10, 2024
1 parent c1837eb commit 0b307c3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
42 changes: 22 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")))

Expand All @@ -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()
Expand All @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: {}
2 changes: 1 addition & 1 deletion src/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 6 additions & 4 deletions src/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)

Expand Down

0 comments on commit 0b307c3

Please sign in to comment.