1
#***************************************************************************
2
#* Copyright (c) 2012 Sebastian Hoogen <github@sebastianhoogen.de> *
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. *
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. *
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 *
20
#***************************************************************************
22
__title__ = "FreeCAD OpenSCAD Workbench - 2D helper functions"
23
__author__ = "Sebastian Hoogen"
24
__url__ = ["https://www.freecad.org"]
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
32
def shapedict(shapelst):
33
return dict([(shape.hashCode(),shape) for shape in shapelst])
36
def shapeset(shapelst):
37
return set([shape.hashCode() for shape in shapelst])
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)
84
def colorcodeshapes(objs):
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),
93
"Vertex":(8.0,8.0,8.0),
94
"Shape":(0.0,0.0,1.0),
98
if hasattr(obj, 'Shape'):
100
if obj.Shape.isNull():
102
if not obj.Shape.isValid():
103
color = (1.0,0.4,0.4)
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
113
#colorcodeshapes(App.ActiveDocument.Objects)