diff --git a/src/build123d/geometry.py b/src/build123d/geometry.py index 0b634696..dd8cb08d 100644 --- a/src/build123d/geometry.py +++ b/src/build123d/geometry.py @@ -77,7 +77,7 @@ # properties used to store mass calculation result from OCP.GProp import GProp_GProps -from OCP.Quantity import Quantity_ColorRGBA +from OCP.Quantity import Quantity_Color, Quantity_ColorRGBA from OCP.TopLoc import TopLoc_Location from OCP.TopoDS import TopoDS_Face, TopoDS_Shape @@ -959,7 +959,13 @@ def __deepcopy__(self, _memo) -> Color: def __str__(self) -> str: """Generate string""" - return f"Color: {str(self.to_tuple())}" + quantity_color_enum = self.wrapped.GetRGB().Name() + quantity_color_str = Quantity_Color.StringName_s(quantity_color_enum) + return f"Color: {str(self.to_tuple())} ~ {quantity_color_str}" + + def __repr__(self) -> str: + """Color repr""" + return f"Color{str(self.to_tuple())}" class Location: diff --git a/tests/test_direct_api.py b/tests/test_direct_api.py index b2a73be7..f3e4891c 100644 --- a/tests/test_direct_api.py +++ b/tests/test_direct_api.py @@ -744,6 +744,11 @@ def test_copy(self): self.assertAlmostEqual(c_copy.to_tuple()[2], 0.3, 5) self.assertAlmostEqual(c_copy.to_tuple()[3], 0.4, 5) + def test_str_repr(self): + c = Color(1, 0, 0) + self.assertEqual(str(c), "Color: (1.0, 0.0, 0.0, 1.0) ~ RED") + self.assertEqual(repr(c), "Color(1.0, 0.0, 0.0, 1.0)") + class TestCompound(DirectApiTestCase): def test_make_text(self):