CURA-4870 Reuse the filter in findContainerStacks to find specific

printers.
Allow to show configurations with empty material or variant.
This commit is contained in:
Diego Prado Gesto 2018-03-13 15:54:00 +01:00
parent 2bf6d071d1
commit 180139090a
2 changed files with 11 additions and 15 deletions

View file

@ -37,13 +37,18 @@ class ExtruderConfigurationModel(QObject):
## This method is intended to indicate whether the configuration is valid or not. ## This method is intended to indicate whether the configuration is valid or not.
# The method checks if the mandatory fields are or not set # The method checks if the mandatory fields are or not set
# At this moment is always valid since we allow to have empty material and variants.
def isValid(self): def isValid(self):
return self._material is not None and self._hotend_id is not None and self.material.guid is not None return True
def __str__(self): def __str__(self):
if not self.isValid(): message_chunks = []
return "No information" message_chunks.append("Position: " + str(self._position))
return "Position: " + str(self._position) + " - Material: " + self._material.type + " - HotendID: " + self._hotend_id message_chunks.append("-")
message_chunks.append("Material: " + self.material.type if self.material else "empty")
message_chunks.append("-")
message_chunks.append("HotendID: " + self.hotendID if self.hotendID else "empty")
return " ".join(message_chunks)
def __eq__(self, other): def __eq__(self, other):
return hash(self) == hash(other) return hash(self) == hash(other)

View file

@ -361,19 +361,10 @@ class MachineManager(QObject):
# \param metadata_filter \type{dict} list of metadata keys and values used for filtering # \param metadata_filter \type{dict} list of metadata keys and values used for filtering
@staticmethod @staticmethod
def getMachine(definition_id: str, metadata_filter: Dict[str, str] = None) -> Optional["GlobalStack"]: def getMachine(definition_id: str, metadata_filter: Dict[str, str] = None) -> Optional["GlobalStack"]:
machines = ContainerRegistry.getInstance().findContainerStacks(type = "machine") machines = ContainerRegistry.getInstance().findContainerStacks(type = "machine", **metadata_filter)
for machine in machines: for machine in machines:
if machine.definition.getId() == definition_id: if machine.definition.getId() == definition_id:
if metadata_filter: return machine
pass_all_filters = True
for key in metadata_filter:
if machine.getMetaDataEntry(key) != metadata_filter[key]:
pass_all_filters = False
break
if pass_all_filters:
return machine
else:
return machine
return None return None
@pyqtSlot(str, str) @pyqtSlot(str, str)