-
Notifications
You must be signed in to change notification settings - Fork 8
/
lithophane_utils.py
60 lines (41 loc) · 1.36 KB
/
lithophane_utils.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
import FreeCAD, FreeCADGui
import itertools, Mesh
def recomputeView():
FreeCAD.ActiveDocument.recompute()
FreeCADGui.updateGui()
FreeCADGui.activeDocument().activeView().viewAxonometric()
FreeCADGui.SendMsgToActiveView("ViewFit")
def findSelectedImage():
selection = FreeCADGui.Selection.getSelection()
if len(selection) != 1:
return None
selectedObject = selection[0]
if selectedObject.Proxy is None:
return None
#if not isinstance(selectedObject.Proxy, LithophaneImage):
# return None
return selection[0].Proxy
def findSelectedMesh():
selection = FreeCADGui.Selection.getSelection()
if len(selection) != 1:
return None
selectedObject = selection[0]
if not hasattr(selectedObject, 'Mesh'):
return None
return selection[0].Mesh
def vectorAtGround(vector):
return FreeCAD.Vector(vector.x, vector.y, 0)
def toChunks(iterable, chunksize):
"""
Splits the iterable into evenly sized chunks. The last chunk can be smaller when iterable contains not enough elements
"""
i = iter(iterable)
while True:
wrapped_chunk = [list(itertools.islice(i, int(chunksize)))]
if not wrapped_chunk[0]:
break
yield wrapped_chunk.pop()
def vectorToTuple(vector):
return (vector.x, vector.y, vector.z)
def tupleToVector(t):
return FreeCAD.Vector(t[0], t[1], t[2])