File size: 2,770 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | # SPDX-License-Identifier: LGPL-2.1-or-later
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.ShapeAppearance[0].DiffuseColor = (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
"""
"""
This test isn't currently valid as it draws from the hard coded default material.
The preference editor doesn't allow for setting transparencies. The default value
of 0 corresponds to a fully transparent color, which is not desirable. It changes
the transparency when loading to 1.0
"""
self._pg.SetUnsigned("DefaultShapeColor", 0xFF000000) # red
obj = self._doc.addObject("Part::Box")
self.assertEqual(
obj.ViewObject.ShapeAppearance[0].DiffuseColor,
(1.0, 0.0, 0.0, 1.0),
"default shape color was not set correctly",
)
self.assertEqual(
obj.ViewObject.ShapeMaterial.DiffuseColor,
(1.0, 0.0, 0.0, 1.0),
"default material 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))
|