|
@@ -129,17 +129,12 @@ class VersionUpgrade30to31(VersionUpgrade):
|
|
|
if parser.has_option("values", "machine_nozzle_size"):
|
|
|
machine_nozzle_size = parser["values"]["machine_nozzle_size"]
|
|
|
|
|
|
- machine_extruder_count = '1' # by default it is 1 and the value cannot be stored in the global stack
|
|
|
- if parser.has_option("values", "machine_extruder_count"):
|
|
|
- machine_extruder_count = parser["values"]["machine_extruder_count"]
|
|
|
+ definition_name = parser["general"]["name"]
|
|
|
+ machine_extruders = self._getSingleExtrusionMachineExtruders(definition_name)
|
|
|
|
|
|
- if machine_extruder_count == '1':
|
|
|
- definition_name = parser["general"]["name"]
|
|
|
- machine_extruders = self._getSingleExtrusionMachineExtruders(definition_name)
|
|
|
-
|
|
|
- # For single extruder machine we need only first extruder
|
|
|
- if len(machine_extruders) !=0:
|
|
|
- self._updateSingleExtruderDefinitionFile(machine_extruders, machine_nozzle_size)
|
|
|
+ #For single extuder machine we nee only first extruder
|
|
|
+ if len(machine_extruders) !=0:
|
|
|
+ if self._updateSingleExtuderDefinitionFile(machine_extruders, machine_nozzle_size):
|
|
|
parser.remove_option("values", "machine_nozzle_size")
|
|
|
|
|
|
# Update version numbers
|
|
@@ -224,9 +219,9 @@ class VersionUpgrade30to31(VersionUpgrade):
|
|
|
|
|
|
machine_instances_dir = Resources.getPath(CuraApplication.ResourceTypes.MachineStack)
|
|
|
|
|
|
- machine_instance_id = None
|
|
|
+ machine_instances = []
|
|
|
|
|
|
- # Find machine instances
|
|
|
+ #Find all machine instances
|
|
|
for item in os.listdir(machine_instances_dir):
|
|
|
file_path = os.path.join(machine_instances_dir, item)
|
|
|
if not os.path.isfile(file_path):
|
|
@@ -247,51 +242,57 @@ class VersionUpgrade30to31(VersionUpgrade):
|
|
|
if not parser.has_option("general", "id"):
|
|
|
continue
|
|
|
|
|
|
- id = parser["general"]["id"]
|
|
|
- if id + "_settings" != definition_name:
|
|
|
+ machine_instances.append(parser)
|
|
|
+
|
|
|
+ #Find for extruders
|
|
|
+ extruders_instances_dir = Resources.getPath(CuraApplication.ResourceTypes.ExtruderStack)
|
|
|
+ #"machine",[extruders]
|
|
|
+ extruder_instances_per_machine = {}
|
|
|
+
|
|
|
+ #Find all custom extruders for founded machines
|
|
|
+ for item in os.listdir(extruders_instances_dir):
|
|
|
+ file_path = os.path.join(extruders_instances_dir, item)
|
|
|
+ if not os.path.isfile(file_path):
|
|
|
continue
|
|
|
- else:
|
|
|
- machine_instance_id = id
|
|
|
- break
|
|
|
|
|
|
- if machine_instance_id is not None:
|
|
|
+ parser = configparser.ConfigParser(interpolation=None)
|
|
|
+ try:
|
|
|
+ parser.read([file_path])
|
|
|
+ except:
|
|
|
+ # skip, it is not a valid stack file
|
|
|
+ continue
|
|
|
|
|
|
- extruders_instances_dir = Resources.getPath(CuraApplication.ResourceTypes.ExtruderStack)
|
|
|
- #"machine",[extruders]
|
|
|
- extruder_instances = []
|
|
|
+ if not parser.has_option("metadata", "type"):
|
|
|
+ continue
|
|
|
+ if "extruder_train" != parser["metadata"]["type"]:
|
|
|
+ continue
|
|
|
|
|
|
- # Find all custom extruders for found machines
|
|
|
- for item in os.listdir(extruders_instances_dir):
|
|
|
- file_path = os.path.join(extruders_instances_dir, item)
|
|
|
- if not os.path.isfile(file_path):
|
|
|
- continue
|
|
|
+ if not parser.has_option("metadata", "machine"):
|
|
|
+ continue
|
|
|
+ if not parser.has_option("metadata", "position"):
|
|
|
+ continue
|
|
|
|
|
|
- parser = configparser.ConfigParser(interpolation=None)
|
|
|
- try:
|
|
|
- parser.read([file_path])
|
|
|
- except:
|
|
|
- # skip, it is not a valid stack file
|
|
|
- continue
|
|
|
|
|
|
- if not parser.has_option("metadata", "type"):
|
|
|
- continue
|
|
|
- if "extruder_train" != parser["metadata"]["type"]:
|
|
|
- continue
|
|
|
+ for machine_instace in machine_instances:
|
|
|
|
|
|
- if not parser.has_option("metadata", "machine"):
|
|
|
- continue
|
|
|
- if not parser.has_option("metadata", "position"):
|
|
|
+ machine_id = machine_instace["general"]["id"]
|
|
|
+ if machine_id != parser["metadata"]["machine"]:
|
|
|
continue
|
|
|
|
|
|
- if machine_instance_id != parser["metadata"]["machine"]:
|
|
|
+ if machine_id + "_settings" != definition_name:
|
|
|
continue
|
|
|
|
|
|
- extruder_instances.append(parser)
|
|
|
+ if extruder_instances_per_machine.get(machine_id) is None:
|
|
|
+ extruder_instances_per_machine.update({machine_id:[]})
|
|
|
+
|
|
|
+ extruder_instances_per_machine.get(machine_id).append(parser)
|
|
|
+ #the extruder can be related only to one machine
|
|
|
+ break
|
|
|
|
|
|
- return extruder_instances
|
|
|
+ return extruder_instances_per_machine
|
|
|
|
|
|
- # Find extruder definition at index 0 and update its values
|
|
|
- def _updateSingleExtruderDefinitionFile(self, extruder_instances_per_machine, machine_nozzle_size):
|
|
|
+ #Find extruder defition at index 0 and update its values
|
|
|
+ def _updateSingleExtuderDefinitionFile(self, extruder_instances_per_machine, machine_nozzle_size):
|
|
|
|
|
|
defintion_instances_dir = Resources.getPath(CuraApplication.ResourceTypes.DefinitionChangesContainer)
|
|
|
|
|
@@ -311,15 +312,19 @@ class VersionUpgrade30to31(VersionUpgrade):
|
|
|
continue
|
|
|
name = parser["general"]["name"]
|
|
|
custom_extruder_at_0_position = None
|
|
|
- for extruder_instance in extruder_instances_per_machine:
|
|
|
+ for machine_extruders in extruder_instances_per_machine:
|
|
|
+ for extruder_instance in extruder_instances_per_machine[machine_extruders]:
|
|
|
|
|
|
- definition_position = extruder_instance["metadata"]["position"]
|
|
|
+ if extruder_instance["general"]["id"] + "_settings" == name:
|
|
|
+ defition_position = extruder_instance["metadata"]["position"]
|
|
|
|
|
|
- if definition_position == "0":
|
|
|
- custom_extruder_at_0_position = extruder_instance
|
|
|
+ if defition_position == "0":
|
|
|
+ custom_extruder_at_0_position = extruder_instance
|
|
|
+ break
|
|
|
+ if custom_extruder_at_0_position is not None:
|
|
|
break
|
|
|
|
|
|
- # If not null, then parsed file is for first extuder and then can be updated. I need to update only
|
|
|
+ #If not null, then parsed file is for first extuder and then can be updated. I need to update only
|
|
|
# first, because this update for single extuder machine
|
|
|
if custom_extruder_at_0_position is not None:
|
|
|
|
|
@@ -369,4 +374,4 @@ class VersionUpgrade30to31(VersionUpgrade):
|
|
|
quality_changes_dir = Resources.getPath(CuraApplication.ResourceTypes.QualityInstanceContainer)
|
|
|
|
|
|
with open(os.path.join(quality_changes_dir, extruder_quality_changes_filename), "w") as f:
|
|
|
- f.write(extruder_quality_changes_output.getvalue())
|
|
|
+ f.write(extruder_quality_changes_output.getvalue())
|