FreeCAD

Форк
0
/
TestImportGui.py 
91 строка · 4.0 Кб
1
# **************************************************************************
2
#   Copyright (c) 2024 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
#                                                                         *
4
#   This file is part of FreeCAD.                                         *
5
#                                                                         *
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.                       *
10
#                                                                         *
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.                       *
15
#                                                                         *
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/>.                                      *
19
#                                                                         *
20
# **************************************************************************
21

22
import os
23
import tempfile
24
import unittest
25
import FreeCAD as App
26
import ImportGui
27
from pivy import coin
28

29

30
class ExportImportTest(unittest.TestCase):
31
    def setUp(self):
32
        TempPath = tempfile.gettempdir()
33
        self.fileName = TempPath + os.sep + "ColorPerFaceTest.step"
34
        self.doc = App.newDocument()
35

36
    def tearDown(self):
37
        App.closeDocument(self.doc.Name)
38

39
    def testSaveLoadStepFile(self):
40
        """
41
        Create a STEP file with color per face
42
        """
43
        part = self.doc.addObject("App::Part", "Part")
44
        box = part.newObject("Part::Box", "Box")
45
        self.doc.recompute()
46

47
        box.ViewObject.DiffuseColor = [
48
            (1.0, 0.0, 0.0, 0.0),
49
            (1.0, 0.0, 0.0, 0.0),
50
            (1.0, 0.0, 0.0, 0.0),
51
            (1.0, 0.0, 0.0, 0.0),
52
            (1.0, 1.0, 0.0, 0.0),
53
            (1.0, 1.0, 0.0, 0.0),
54
        ]
55

56
        ImportGui.export([part], self.fileName)
57

58
        self.doc.clearDocument()
59
        ImportGui.insert(name=self.fileName, docName=self.doc.Name, merge=False, useLinkGroup=True)
60

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]
64

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))
72

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)
78
        paths = sa.getPaths()
79

80
        bind = paths.get(2).getTail()
81
        self.assertEqual(bind.value.getValue(), bind.PER_PART)
82

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)
88
        paths = sa.getPaths()
89

90
        mat = paths.get(2).getTail()
91
        self.assertEqual(mat.diffuseColor.getNum(), 6)
92

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.