-
Notifications
You must be signed in to change notification settings - Fork 5
/
Face.py
93 lines (82 loc) · 3.05 KB
/
Face.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# coding=UTF-8
import FreeCAD
import Part
from DocumentObject import DocumentObject
class SMFace(DocumentObject):
"""
A face is defined by a set of points.
All edges of the face are created if not already exists.
The face is stored as a sorted list of edges
It also have a layer it belongs to
"""
pytype = "SMFace"
def __init__(self,layer,points):
DocumentObject.__init__(self)
FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Face",self,self)
self.addProperty("App::PropertyLinkList","Edges","Base","End point")
#self.addProperty("App::PropertyLink","Layer","Base", "The layer this point is in")
#self.Layer=layer.getobj()
layer.registerFace(self)
edges = self.getOrCreateEdges(points)
if not edges:
raise UnimplementedError, "Cannot add a face by noncircular edgeset"
self.Edges = map(lambda x: x.getobj(), edges)
self.createGeometry()
def getEdges(self):
return map(lambda x: x.Proxy, self.Edges)
def getOrCreateEdges(self,points):
mesh = self.getParentByType('SMesh')
layer = self.getParentByType('SMLayer')
fp=points[0]
#FreeCAD.Console.PrintMessage('p0=%s\n'%fp.Label)
lastp=fp
edges=[]
for p in points[1:]:
#FreeCAD.Console.PrintMessage('p =%s\n'%p.Label)
edges.append(mesh.getOrCreateEdge(lastp,p,layer.Label))
lastp = p
#FreeCAD.Console.PrintMessage('lp=%s\n'%p.Label)
edges.append(mesh.getOrCreateEdge(lastp,fp,layer.Label))
return edges
def getPoints(self):
points=[]
edges = self.getEdges()
if not edges:
return []
for e in edges:
points.append(e.Start.Proxy)
points.append(edges[-1].End.Proxy)
return points
def isOnPoints(self,points):
myps=self.getPoints()
if len(points) != len(self.getPoints()):
return False
for i in range(len(points)):
if myps[i] != points[i]:
return False
return True
def fromfef(self,data):
# FIXME: it needs to be converted to this framework
if data:
data=data.strip().split(' ')
numpoints=int(data[0])
self.points=[]
#print data
for i in range(numpoints):
self.points.append(ship.points[int(data[i+1])])
#print i
self.layer=ship.layers[int(data[i+2])]
self.selected=int(data[i+3])
if points:
self.points+=points
if layer:
self.layer=layer
self.plane=Plane(face=self)
def createGeometry(self):
fp = self
plm = fp.Placement
ps = self.getPoints()
pvs = map(lambda x: x.Coordinates, ps)
shape = Part.makePolygon(pvs)
fp.Shape = Part.Face(shape)
fp.Placement = plm