FreeCAD

Форк
0
/
colorcodeshapes.py 
113 строк · 4.5 Кб
1
#***************************************************************************
2
#*   Copyright (c) 2012 Sebastian Hoogen <github@sebastianhoogen.de>       *
3
#*                                                                         *
4
#*   This program is free software; you can redistribute it and/or modify  *
5
#*   it under the terms of the GNU Lesser General Public License (LGPL)    *
6
#*   as published by the Free Software Foundation; either version 2 of     *
7
#*   the License, or (at your option) any later version.                   *
8
#*   for detail see the LICENCE text file.                                 *
9
#*                                                                         *
10
#*   This program is distributed in the hope that it will be useful,       *
11
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
#*   GNU Library General Public License for more details.                  *
14
#*                                                                         *
15
#*   You should have received a copy of the GNU Library General Public     *
16
#*   License along with this program; if not, write to the Free Software   *
17
#*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
18
#*   USA                                                                   *
19
#*                                                                         *
20
#***************************************************************************
21

22
__title__ = "FreeCAD OpenSCAD Workbench - 2D helper functions"
23
__author__ = "Sebastian Hoogen"
24
__url__ = ["https://www.freecad.org"]
25

26
'''
27
This Script includes python functions to find out the most basic shape type
28
in a compound and to change the color of shapes according to their shape type
29
'''
30

31

32
def shapedict(shapelst):
33
    return dict([(shape.hashCode(),shape) for shape in shapelst])
34

35

36
def shapeset(shapelst):
37
    return set([shape.hashCode() for shape in shapelst])
38

39

40
def mostbasiccompound(comp):
41
    '''searches for the most basic shape in a Compound'''
42
    solids = shapeset(comp.Solids)
43
    shells = shapeset(comp.Shells)
44
    faces = shapeset(comp.Faces)
45
    wires = shapeset(comp.Wires)
46
    edges = shapeset(comp.Edges)
47
    vertexes = shapeset(comp.Vertexes)
48
    #FreeCAD.Console.PrintMessage('%s\n' % (str((len(solids),len(shells),len(faces),len(wires),len(edges),len(vertexes)))))
49
    for shape in comp.Solids:
50
        shells -= shapeset(shape.Shells)
51
        faces -= shapeset(shape.Faces)
52
        wires -= shapeset(shape.Wires)
53
        edges -= shapeset(shape.Edges)
54
        vertexes -= shapeset(shape.Vertexes)
55
    for shape in comp.Shells:
56
        faces -= shapeset(shape.Faces)
57
        wires -= shapeset(shape.Wires)
58
        edges -= shapeset(shape.Edges)
59
        vertexes -= shapeset(shape.Vertexes)
60
    for shape in comp.Faces:
61
        wires -= shapeset(shape.Wires)
62
        edges -= shapeset(shape.Edges)
63
        vertexes -= shapeset(shape.Vertexes)
64
    for shape in comp.Wires:
65
        edges -= shapeset(shape.Edges)
66
        vertexes -= shapeset(shape.Vertexes)
67
    for shape in comp.Edges:
68
        vertexes -= shapeset(shape.Vertexes)
69
    #FreeCAD.Console.PrintMessage('%s\n' % (str((len(solids),len(shells),len(faces),len(wires),len(edges),len(vertexes)))))
70
    #return len(solids),len(shells),len(faces),len(wires),len(edges),len(vertexes)
71
    if vertexes:
72
        return "Vertex"
73
    elif edges:
74
        return "Edge"
75
    elif wires:
76
        return "Wire"
77
    elif faces:
78
        return "Face"
79
    elif shells:
80
        return "Shell"
81
    elif solids:
82
        return "Solid"
83

84
def colorcodeshapes(objs):
85
    shapecolors = {
86
        "Compound":(0.3,0.3,0.4),
87
        "CompSolid":(0.1,0.5,0.0),
88
        "Solid":(0.0,0.8,0.0),
89
        "Shell":(0.8,0.0,0.0),
90
        "Face":(0.6,0.6,0.0),
91
        "Wire":(0.1,0.1,0.1),
92
        "Edge":(1.0,1.0,1.0),
93
        "Vertex":(8.0,8.0,8.0),
94
        "Shape":(0.0,0.0,1.0),
95
        None:(0.0,0.0,0.0)}
96

97
    for obj in objs:
98
        if hasattr(obj, 'Shape'):
99
            try:
100
                if obj.Shape.isNull():
101
                    continue
102
                if not obj.Shape.isValid():
103
                    color = (1.0,0.4,0.4)
104
                else:
105
                    st=obj.Shape.ShapeType
106
                    if st in ["Compound", "CompSolid"]:
107
                        st = mostbasiccompound(obj.Shape)
108
                    color = shapecolors[st]
109
                obj.ViewObject.ShapeColor = color
110
            except Exception:
111
                raise
112

113
#colorcodeshapes(App.ActiveDocument.Objects)
114

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

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

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

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