Mod: Show regressions in shape colouring

This PR demonstrates the known regressions of the recently merged material branch:
* Changing the transparency after setting color per face will reset them
* The result of boolean operations or compound doesn't inherit the colour of its input objects
* If colour is set per face to a boolean operaton object then saving and restoring the file causes weird rendering behaviour
  because material binding is set to PER_PART but only a single colour is defined
* If a shape inside a part container has set colour per face then saving and restoring as STEP file causes weird rendering
behaviour for the same reason
* Shape binder or datum objects don't show the correct default shape colour
This commit is contained in:
wmayer
2024-04-09 20:32:32 +02:00
committed by wwmayer
parent cc96f2718e
commit 3a34fe080a
5 changed files with 299 additions and 0 deletions

View File

@@ -253,3 +253,87 @@ class PartDesignTransformed(unittest.TestCase):
# def tearDown(self):
# #closing doc
# FreeCAD.closeDocument("SketchGuiTest")
class TestShapeBinder(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("PartDesignTestShapeBinder")
def testDefaultColor(self):
"""
A shape binder uses a different default color than a Part feature.
This color must still be set after its creation.
"""
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Box = self.Doc.addObject('PartDesign::AdditiveBox','Box')
self.Body.addObject(self.Box)
self.Doc.recompute()
binder = self.Doc.addObject('PartDesign::ShapeBinder','ShapeBinder')
binder.Support = [(self.Box, 'Face1')]
grp = App.ParamGet("User parameter:BaseApp/Preferences/Mod/PartDesign")
packed_color = grp.GetUnsigned("DefaultDatumColor", 0xFFD70099)
r, g, b, a = binder.ViewObject.ShapeColor
color = int(r * 255.0 + 0.5) << 24 | int(g * 255.0 + 0.5) << 16 | int(b * 255.0 + 0.5) << 8 | int(a * 255.0 + 0.5)
self.assertEqual(packed_color, color)
def tearDown(self):
FreeCAD.closeDocument(self.Doc.Name)
class TestSubShapeBinder(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("PartDesignTestSubShapeBinder")
def tearDown(self):
FreeCAD.closeDocument(self.Doc.Name)
def testDefaultColor(self):
"""
A sub-shape binder uses a different default color than a Part feature.
This color must still be set after its creation.
"""
body = self.Doc.addObject('PartDesign::Body','Body')
box = self.Doc.addObject('PartDesign::AdditiveBox','Box')
body.addObject(box)
self.Doc.recompute()
binder = body.newObject('PartDesign::SubShapeBinder','Binder')
binder.Support = [(box, ("Face1"))]
grp = App.ParamGet("User parameter:BaseApp/Preferences/Mod/PartDesign")
packed_color = grp.GetUnsigned("DefaultDatumColor", 0xFFD70099)
r, g, b, a = binder.ViewObject.ShapeColor
color = int(r * 255.0 + 0.5) << 24 | int(g * 255.0 + 0.5) << 16 | int(b * 255.0 + 0.5) << 8 | int(a * 255.0 + 0.5)
self.assertEqual(packed_color, color)
class TestDatumPlane(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("PartDesignTestDatumPlane")
def tearDown(self):
FreeCAD.closeDocument(self.Doc.Name)
def testDefaultColor(self):
"""
A datum object uses a different default color than a Part feature.
This color must still be set after its creation.
"""
body = self.Doc.addObject('PartDesign::Body','Body')
box = self.Doc.addObject('PartDesign::AdditiveBox','Box')
body.addObject(box)
self.Doc.recompute()
datum = body.newObject('PartDesign::Plane','DatumPlane')
datum.AttachmentSupport = [(box, 'Face6')]
datum.MapMode = 'FlatFace'
self.Doc.recompute()
grp = App.ParamGet("User parameter:BaseApp/Preferences/Mod/PartDesign")
packed_color = grp.GetUnsigned("DefaultDatumColor", 0xFFD70099)
r, g, b, a = datum.ViewObject.ShapeColor
color = int(r * 255.0 + 0.5) << 24 | int(g * 255.0 + 0.5) << 16 | int(b * 255.0 + 0.5) << 8 | int(a * 255.0 + 0.5)
self.assertEqual(packed_color, color)