forked from VyacheslavKlipov/PlacementTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommon.py
103 lines (89 loc) · 3.41 KB
/
Common.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
93
94
95
96
97
98
99
100
101
102
103
import FreeCAD,FreeCADGui
import inspect, os.path
filename = inspect.getframeinfo(inspect.currentframe()).filename
path = os.path.dirname(os.path.abspath(filename))
#FreeCAD.Console.PrintMessage(path)
ICONPATH = path+'/Resources/icons/'
#ICONPATH = FreeCAD.getUserAppDataDir()+'Mod/PlacementTools/Resources/icons/'
def getParent(obj):
for a in obj.InList:
for b in a.ViewObject.claimChildren():
if b == obj:
# FreeCAD.Console.PrintMessage('|')
return a
return obj
def upperObject(obj):
# FreeCAD.Console.PrintMessage('[upperObject]')
par=getParent(obj)
if par!=obj:
#obj.InList.__len__()>0:
#FreeCAD.Console.PrintMessage('[yes]')
#FreeCAD.Console.PrintMessage(obj.Label)
return upperObject(par)
#return upperObject(obj.InList[obj.InList.__len__()-1])
else:
#FreeCAD.Console.PrintMessage('[no]')
#FreeCAD.Console.PrintMessage(obj.Label)
#FreeCAD.Console.PrintMessage('\n')
return obj
def GetSelectedUpperObjectsNew():
upperobjs=[]
objs=FreeCADGui.Selection.getSelection()
for obj in objs:
upperobjs.append(upperObject(obj))
return upperobjs
def GetSelectedUpperObjects():
upperobjs=[]
objs=FreeCADGui.Selection.getSelection()
for obj in objs:
upperobjs.append(upperObject(obj))
return upperobjs
def getMax(v1,v2):
if v1>v2:
return v1
else:
return v2
def getMin(v1,v2):
if v1<v2:
return v1
else:
return v2
def GetObjectBoundBox(obj):
if not (hasattr(obj,'Shape')) and obj.TypeId=='App::Part':
bb=FreeCAD.BoundBox()
for subobj in obj.OutList:
if subobj.TypeId=='App::Part':
bb2=GetObjectBoundBox(subobj)
else:
if subobj.TypeId!='App::Origin':
bb2=subobj.Shape.BoundBox
else:
bb2=FreeCAD.BoundBox()
bb.XMax=getMax(bb.XMax,bb2.XMax)
bb.YMax=getMax(bb.YMax,bb2.YMax)
bb.ZMax=getMax(bb.ZMax,bb2.ZMax)
bb.XMin=getMin(bb.XMin,bb2.XMin)
bb.YMin=getMin(bb.YMin,bb2.YMin)
bb.ZMin=getMin(bb.ZMin,bb2.ZMin)
p=[]
p.append(obj.Placement.multiply(FreeCAD.Placement(FreeCAD.Vector(bb.XMin,bb.YMin,bb.ZMin),obj.Placement.Rotation)))
p.append(obj.Placement.multiply(FreeCAD.Placement(FreeCAD.Vector(bb.XMax,bb.YMin,bb.ZMin),obj.Placement.Rotation)))
p.append(obj.Placement.multiply(FreeCAD.Placement(FreeCAD.Vector(bb.XMax,bb.YMax,bb.ZMin),obj.Placement.Rotation)))
p.append(obj.Placement.multiply(FreeCAD.Placement(FreeCAD.Vector(bb.XMin,bb.YMax,bb.ZMin),obj.Placement.Rotation)))
p.append(obj.Placement.multiply(FreeCAD.Placement(FreeCAD.Vector(bb.XMin,bb.YMin,bb.ZMax),obj.Placement.Rotation)))
p.append(obj.Placement.multiply(FreeCAD.Placement(FreeCAD.Vector(bb.XMax,bb.YMin,bb.ZMax),obj.Placement.Rotation)))
p.append(obj.Placement.multiply(FreeCAD.Placement(FreeCAD.Vector(bb.XMax,bb.YMax,bb.ZMax),obj.Placement.Rotation)))
p.append(obj.Placement.multiply(FreeCAD.Placement(FreeCAD.Vector(bb.XMin,bb.YMax,bb.ZMax),obj.Placement.Rotation)))
bb=FreeCAD.BoundBox()
for pp in p:
bb.XMax=getMax(bb.XMax,pp.Base.x)
bb.YMax=getMax(bb.YMax,pp.Base.y)
bb.ZMax=getMax(bb.ZMax,pp.Base.z)
bb.XMin=getMin(bb.XMin,pp.Base.x)
bb.YMin=getMin(bb.YMin,pp.Base.y)
bb.ZMin=getMin(bb.ZMin,pp.Base.z)
return bb
else:
return obj.Shape.BoundBox
# v=App.Vector(b.Shape.BoundBox.XMax,b.Shape.BoundBox.YMax,b.Shape.BoundBox.ZMax)
#App.ActiveDocument.Part.Placement.multiply( App.Placement(v,App.ActiveDocument.Part.Placement.Rotation))