From c32c642ba551d36dcbe8bd104bb3e8a505eddd6b Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 26 Apr 2019 11:59:16 +0200 Subject: [PATCH] Fixed highlighting matching configuration if a material is empty --- .../Models/ExtruderConfigurationModel.py | 19 ++++++++++++++++++- .../Models/PrinterConfigurationModel.py | 18 +++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/cura/PrinterOutput/Models/ExtruderConfigurationModel.py b/cura/PrinterOutput/Models/ExtruderConfigurationModel.py index a291888bfd..5b4cb5d6f5 100644 --- a/cura/PrinterOutput/Models/ExtruderConfigurationModel.py +++ b/cura/PrinterOutput/Models/ExtruderConfigurationModel.py @@ -62,7 +62,24 @@ class ExtruderConfigurationModel(QObject): return " ".join(message_chunks) def __eq__(self, other) -> bool: - return hash(self) == hash(other) + if not isinstance(other, ExtruderConfigurationModel): + return False + + if self._position != other.position: + return False + # Empty materials should be ignored for comparison + if self.activeMaterial is not None and other.activeMaterial is not None: + if self.activeMaterial.guid != other.activeMaterial.guid: + if self.activeMaterial.guid != "" and other.activeMaterial.guid != "": + return False + else: + # At this point there is no material, so it doesn't matter what the hotend is. + return True + + if self.hotendID != other.hotendID: + return False + + return True # Calculating a hash function using the position of the extruder, the material GUID and the hotend id to check if is # unique within a set diff --git a/cura/PrinterOutput/Models/PrinterConfigurationModel.py b/cura/PrinterOutput/Models/PrinterConfigurationModel.py index 876e4e02bd..47b9532080 100644 --- a/cura/PrinterOutput/Models/PrinterConfigurationModel.py +++ b/cura/PrinterOutput/Models/PrinterConfigurationModel.py @@ -71,7 +71,23 @@ class PrinterConfigurationModel(QObject): return "\n".join(message_chunks) def __eq__(self, other): - return hash(self) == hash(other) + if not isinstance(other, PrinterConfigurationModel): + return False + + if self.printerType != other.printerType: + return False + + if self.buildplateConfiguration != other.buildplateConfiguration: + return False + + if len(self.extruderConfigurations) != len(other.extruderConfigurations): + return False + + for self_extruder, other_extruder in zip(sorted(self._extruder_configurations, key=lambda x: x.position), sorted(other.extruderConfigurations, key=lambda x: x.position)): + if self_extruder != other_extruder: + return False + + return True ## The hash function is used to compare and create unique sets. The configuration is unique if the configuration # of the extruders is unique (the order of the extruders matters), and the type and buildplate is the same.