From 240d1edda4f818fdbf7b319f111b51c17af79d50 Mon Sep 17 00:00:00 2001 From: bdieterm <119257544+bdieterm@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:23:55 +0100 Subject: [PATCH] Part: add color transparency unit tests --- src/Mod/Part/CMakeLists.txt | 1 + src/Mod/Part/TestPartGui.py | 1 + .../Part/parttests/ColorTransparencyTest.py | 58 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/Mod/Part/parttests/ColorTransparencyTest.py diff --git a/src/Mod/Part/CMakeLists.txt b/src/Mod/Part/CMakeLists.txt index b7502d6e77..767b1a43d9 100644 --- a/src/Mod/Part/CMakeLists.txt +++ b/src/Mod/Part/CMakeLists.txt @@ -69,6 +69,7 @@ set(Part_tests parttests/regression_tests.py parttests/TopoShapeListTest.py parttests/ColorPerFaceTest.py + parttests/ColorTransparencyTest.py ) add_custom_target(PartScripts ALL SOURCES diff --git a/src/Mod/Part/TestPartGui.py b/src/Mod/Part/TestPartGui.py index 9527da2fbe..dc207cc831 100644 --- a/src/Mod/Part/TestPartGui.py +++ b/src/Mod/Part/TestPartGui.py @@ -44,6 +44,7 @@ def findDockWidget(name): #--------------------------------------------------------------------------- """ from parttests.ColorPerFaceTest import ColorPerFaceTest +from parttests.ColorTransparencyTest import ColorTransparencyTest #class PartGuiTestCases(unittest.TestCase): diff --git a/src/Mod/Part/parttests/ColorTransparencyTest.py b/src/Mod/Part/parttests/ColorTransparencyTest.py new file mode 100644 index 0000000000..f948bdac8a --- /dev/null +++ b/src/Mod/Part/parttests/ColorTransparencyTest.py @@ -0,0 +1,58 @@ +import unittest + +import FreeCAD as App + + +class ColorTransparencyTest(unittest.TestCase): + + def setUp(self): + self._doc = App.newDocument() + self._pg = App.ParamGet('User parameter:BaseApp/Preferences/View') + self._backup_default_transparency = self._pg.GetInt('DefaultShapeTransparency') + self._backup_default_shapecolor = self._pg.GetUnsigned('DefaultShapeColor') + + + def tearDown(self): + App.closeDocument(self._doc.Name) + self._pg.SetInt('DefaultShapeTransparency', self._backup_default_transparency) + self._pg.SetUnsigned('DefaultShapeColor', self._backup_default_shapecolor) + + + def test_default_shape_transparency(self): + """ + related: https://github.com/FreeCAD/FreeCAD/pull/11866 + related: https://github.com/FreeCAD/FreeCAD/pull/11586 + """ + transparency = 70 + self._pg.SetInt('DefaultShapeTransparency', transparency) + obj = self._doc.addObject('Part::Box') + assert obj.ViewObject.Transparency == transparency + obj.ViewObject.ShapeColor = (0.5, 0.0, 0.0) + + self.assertEqual(obj.ViewObject.Transparency, transparency, + 'transparency was unexpectedly changed to {} when changing the color.'.format( + obj.ViewObject.Transparency)) + + + def test_default_shape_color(self): + """ + related: https://github.com/FreeCAD/FreeCAD/pull/11866 + """ + self._pg.SetUnsigned('DefaultShapeColor', 0xff000000) # red + obj = self._doc.addObject('Part::Box') + + self.assertEqual(obj.ViewObject.ShapeColor, (1.0, 0.0, 0.0, 0.0), + 'default shape color was not set correctly') + + + def test_app_plane_transparency(self): + """ + related: https://github.com/FreeCAD/FreeCAD/pull/12064 + """ + self._pg.SetInt('DefaultShapeTransparency', 70) + obj = self._doc.addObject('App::Origin') + t = self._doc.findObjects('App::Plane')[0].ViewObject.Transparency + + self.assertEqual(t, 0, + 'transparency of App::Plane object is {} instead of 0'.format(t)) +