- added the ability to compress the FlatCAM project on save with LZMA compression. There is a setting in Edit -> Preferences -> Compression Level between 0 and 9. 9 level yields best compression at the price of RAM usage and time spent.

- made FlatCAM able to load old type (uncompressed) FlatCAM projects
This commit is contained in:
Marius Stanciu
2019-02-19 01:22:17 +02:00
committed by Marius S
parent c22d6766f4
commit 7f65cf628d
3 changed files with 71 additions and 32 deletions

View File

@@ -14,6 +14,7 @@ import os
import random import random
import logging import logging
import simplejson as json import simplejson as json
import lzma
import re import re
import os import os
@@ -312,6 +313,7 @@ class App(QtCore.QObject):
"global_project_at_startup": self.general_defaults_form.general_app_group.project_startup_cb, "global_project_at_startup": self.general_defaults_form.general_app_group.project_startup_cb,
"global_project_autohide": self.general_defaults_form.general_app_group.project_autohide_cb, "global_project_autohide": self.general_defaults_form.general_app_group.project_autohide_cb,
"global_advanced": self.general_defaults_form.general_app_group.advanced_cb, "global_advanced": self.general_defaults_form.general_app_group.advanced_cb,
"global_compression_level": self.general_defaults_form.general_app_group.compress_combo,
"global_gridx": self.general_defaults_form.general_gui_group.gridx_entry, "global_gridx": self.general_defaults_form.general_gui_group.gridx_entry,
"global_gridy": self.general_defaults_form.general_gui_group.gridy_entry, "global_gridy": self.general_defaults_form.general_gui_group.gridy_entry,
@@ -547,6 +549,7 @@ class App(QtCore.QObject):
"global_shell_shape": [500, 300], # Shape of the shell in pixels. "global_shell_shape": [500, 300], # Shape of the shell in pixels.
"global_shell_at_startup": False, # Show the shell at startup. "global_shell_at_startup": False, # Show the shell at startup.
"global_recent_limit": 10, # Max. items in recent list. "global_recent_limit": 10, # Max. items in recent list.
"global_compression_level": 3,
"fit_key": 'V', "fit_key": 'V',
"zoom_out_key": '-', "zoom_out_key": '-',
"zoom_in_key": '=', "zoom_in_key": '=',
@@ -6222,7 +6225,7 @@ class App(QtCore.QObject):
""" """
App.log.debug("Opening project: " + filename) App.log.debug("Opening project: " + filename)
# Open and parse # Open and parse an uncompressed Project file
try: try:
f = open(filename, 'r') f = open(filename, 'r')
except IOError: except IOError:
@@ -6236,7 +6239,16 @@ class App(QtCore.QObject):
App.log.error("Failed to parse project file: %s" % filename) App.log.error("Failed to parse project file: %s" % filename)
self.inform.emit("[ERROR_NOTCL] Failed to parse project file: %s" % filename) self.inform.emit("[ERROR_NOTCL] Failed to parse project file: %s" % filename)
f.close() f.close()
return
# Open and parse a compressed Project file
try:
with lzma.open(filename) as f:
file_content = f.read().decode('utf-8')
d = json.loads(file_content, object_hook=dict2obj)
except IOError:
App.log.error("Failed to open project file: %s" % filename)
self.inform.emit("[ERROR_NOTCL] Failed to open project file: %s" % filename)
return
self.file_opened.emit("project", filename) self.file_opened.emit("project", filename)
@@ -6958,37 +6970,42 @@ The normal flow when working in FlatCAM is the following:</span></p>
"options": self.options, "options": self.options,
"version": self.version} "version": self.version}
with lzma.open(filename, "w", preset=int(self.defaults['global_compression_level'])) as f:
g = json.dumps(d, default=to_dict, indent=2, sort_keys=True).encode('utf-8')
# # Write
f.write(g)
self.inform.emit("[success] Project saved to: %s" % filename)
# Open file # Open file
try: # try:
f = open(filename, 'w') # f = open(filename, 'w')
except IOError: # except IOError:
App.log.error("[ERROR] Failed to open file for saving: %s", filename) # App.log.error("[ERROR] Failed to open file for saving: %s", filename)
return # return
#
# Write # # Write
json.dump(d, f, default=to_dict, indent=2, sort_keys=True) # json.dump(d, f, default=to_dict, indent=2, sort_keys=True)
f.close() # f.close()
#
# verification of the saved project # # verification of the saved project
# Open and parse # # Open and parse
try: # try:
saved_f = open(filename, 'r') # saved_f = open(filename, 'r')
except IOError: # except IOError:
self.inform.emit("[ERROR_NOTCL] Failed to verify project file: %s. Retry to save it." % filename) # self.inform.emit("[ERROR_NOTCL] Failed to verify project file: %s. Retry to save it." % filename)
return # return
#
try: # try:
saved_d = json.load(saved_f, object_hook=dict2obj) # saved_d = json.load(saved_f, object_hook=dict2obj)
except: # except:
self.inform.emit("[ERROR_NOTCL] Failed to parse saved project file: %s. Retry to save it." % filename) # self.inform.emit("[ERROR_NOTCL] Failed to parse saved project file: %s. Retry to save it." % filename)
f.close() # f.close()
return # return
saved_f.close() # saved_f.close()
#
if 'version' in saved_d: # if 'version' in saved_d:
self.inform.emit("[success] Project saved to: %s" % filename) # self.inform.emit("[success] Project saved to: %s" % filename)
else: # else:
self.inform.emit("[ERROR_NOTCL] Failed to save project file: %s. Retry to save it." % filename) # self.inform.emit("[ERROR_NOTCL] Failed to save project file: %s. Retry to save it." % filename)
def on_options_app2project(self): def on_options_app2project(self):
""" """

View File

@@ -3129,6 +3129,23 @@ class GeneralAppPrefGroupUI(OptionsGroupUI):
hlay.addWidget(self.advanced_cb) hlay.addWidget(self.advanced_cb)
hlay.addStretch() hlay.addStretch()
hlay1 = QtWidgets.QHBoxLayout()
self.layout.addLayout(hlay1)
# Project LZMA Comppression Level
self.compress_combo = FCComboBox()
self.compress_label = QtWidgets.QLabel('Compress Level:')
self.compress_label.setToolTip(
"The level of compression used when saving\n"
"a FlatCAM project. Higher value means better compression\n"
"but require more RAM and time."
)
# self.advanced_cb.setLayoutDirection(QtCore.Qt.RightToLeft)
self.compress_combo.addItems([str(i) for i in range(10)])
hlay1.addWidget(self.compress_label)
hlay1.addWidget(self.compress_combo)
self.form_box_2 = QtWidgets.QFormLayout() self.form_box_2 = QtWidgets.QFormLayout()
self.layout.addLayout(self.form_box_2) self.layout.addLayout(self.form_box_2)

View File

@@ -9,6 +9,11 @@ CAD program, and create G-Code for Isolation routing.
================================================= =================================================
19.02.2019
- added the ability to compress the FlatCAM project on save with LZMA compression. There is a setting in Edit -> Preferences -> Compression Level between 0 and 9. 9 level yields best compression at the price of RAM usage and time spent.
- made FlatCAM able to load old type (uncompressed) FlatCAM projects
18.02.2019 18.02.2019
- added protections again wrong values for the Buffer and Paint Tool in Geometry Editor - added protections again wrong values for the Buffer and Paint Tool in Geometry Editor