1
# **************************************************************************
2
# Copyright (c) 2024 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
# This file is part of FreeCAD. *
6
# FreeCAD is free software: you can redistribute it and/or modify it *
7
# under the terms of the GNU Lesser General Public License as *
8
# published by the Free Software Foundation, either version 2.1 of the *
9
# License, or (at your option) any later version. *
11
# FreeCAD is distributed in the hope that it will be useful, but *
12
# WITHOUT ANY WARRANTY; without even the implied warranty of *
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14
# Lesser General Public License for more details. *
16
# You should have received a copy of the GNU Lesser General Public *
17
# License along with FreeCAD. If not, see *
18
# <https://www.gnu.org/licenses/>. *
20
# **************************************************************************
30
class ExportImportTest(unittest.TestCase):
32
TempPath = tempfile.gettempdir()
33
self.fileName = TempPath + os.sep + "ColorPerFaceTest.step"
34
self.doc = App.newDocument()
37
App.closeDocument(self.doc.Name)
39
def testSaveLoadStepFile(self):
41
Create a STEP file with color per face
43
part = self.doc.addObject("App::Part", "Part")
44
box = part.newObject("Part::Box", "Box")
47
box.ViewObject.DiffuseColor = [
56
ImportGui.export([part], self.fileName)
58
self.doc.clearDocument()
59
ImportGui.insert(name=self.fileName, docName=self.doc.Name, merge=False, useLinkGroup=True)
61
part_features = list(filter(lambda x: x.isDerivedFrom("Part::Feature"), self.doc.Objects))
62
self.assertEqual(len(part_features), 1)
63
feature = part_features[0]
65
self.assertEqual(len(feature.ViewObject.DiffuseColor), 6)
66
self.assertEqual(feature.ViewObject.DiffuseColor[0], (1.0, 0.0, 0.0, 0.0))
67
self.assertEqual(feature.ViewObject.DiffuseColor[1], (1.0, 0.0, 0.0, 0.0))
68
self.assertEqual(feature.ViewObject.DiffuseColor[2], (1.0, 0.0, 0.0, 0.0))
69
self.assertEqual(feature.ViewObject.DiffuseColor[3], (1.0, 0.0, 0.0, 0.0))
70
self.assertEqual(feature.ViewObject.DiffuseColor[4], (1.0, 1.0, 0.0, 0.0))
71
self.assertEqual(feature.ViewObject.DiffuseColor[5], (1.0, 1.0, 0.0, 0.0))
73
sa = coin.SoSearchAction()
74
sa.setType(coin.SoMaterialBinding.getClassTypeId())
75
# We need an easier way to access nodes of a display mode
76
sa.setInterest(coin.SoSearchAction.ALL)
77
sa.apply(feature.ViewObject.RootNode)
80
bind = paths.get(2).getTail()
81
self.assertEqual(bind.value.getValue(), bind.PER_PART)
83
sa = coin.SoSearchAction()
84
sa.setType(coin.SoMaterial.getClassTypeId())
85
# We need an easier way to access nodes of a display mode
86
sa.setInterest(coin.SoSearchAction.ALL)
87
sa.apply(feature.ViewObject.RootNode)
90
mat = paths.get(2).getTail()
91
self.assertEqual(mat.diffuseColor.getNum(), 6)