-
Notifications
You must be signed in to change notification settings - Fork 17
/
Tracker.py
94 lines (74 loc) · 2.52 KB
/
Tracker.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 -*-
#-------------------------------------------------
#-- animation workbench tracker
#--
#-- microelly 2015
#--
#-- GNU Lesser General Public License (LGPL)
#-------------------------------------------------
import FreeCAD,PySide,os,FreeCADGui
from PySide import QtCore, QtGui, QtSvg
from PySide.QtGui import *
import Part
#----------
import math,os
import FreeCAD, Animation, PySide
from Animation import say,sayErr,sayexc
from EditWidget import EditNoDialWidget
__vers__='0.3 30.11.2015'
__dir__ = os.path.dirname(__file__)
def createTracker(name="MyTracker",src=None,filename="/tmp/tracker"):
obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython",name)
obj.addProperty("App::PropertyString","filename","Base","").filename=filename
obj.addProperty("App::PropertyLink","src","Base","").src=src
obj.addProperty("App::PropertyFloat","time","Base","").time=0
_Tracker(obj)
_ViewProviderTracker(obj.ViewObject)
return obj
class _Tracker(Animation._Actor):
''' track the time/placement of src to filename '''
def update(self):
try:
self.path
except:
self.path=[]
if (self.obj2.src.time==0):
f = open(self.obj2.filename + "_out.txt",'w')
else:
f = open(self.obj2.filename + "_out.txt",'a')
f.write("# " + str(self.obj2.src.time) +" " +str(self.obj2.src.Placement)+'\n') # python will convert \n to os.linesep
b=self.obj2.src.Placement.Base
r=self.obj2.src.Placement.Rotation.Axis
a=self.obj2.src.Placement.Rotation.Angle
l=' '.join(str(k) for k in [self.obj2.src.time,b.x,b.y,b.z,r.x,r.y,r.z,a])
f.write(l +"\n")
f.close()
self.path.append(self.obj2.src.Placement.Base)
class _ViewProviderTracker(Animation._ViewProviderActor):
def getIcon(self):
return __dir__ +'/icons/icon2.svg'
def attach(self,vobj):
self.emenu=[["Show Path",self.showpath]]
self.cmenu=[]
say("attach " + str(vobj.Object.Label))
self.Object = vobj.Object
self.obj2=self.Object
self.Object.Proxy.Lock=False
self.Object.Proxy.Changed=False
return
def edit(self):
self.dialog=EditNoDialWidget(self,self.emenu)
self.dialog.show()
def showVersion(self):
cl=self.Object.Proxy.__class__.__name__
PySide.QtGui.QMessageBox.information(None, "About ", "Animation" + cl +" Node\nVersion " + __vers__ )
def showpath(self):
''' path as Part.polygon '''
FreeCAD.s=self
points=self.Object.Proxy.path
for p in self.Object.Proxy.path:
say(str(p))
pp=Part.makePolygon(points)
Part.show(pp)
FreeCAD.ActiveDocument.recompute()
return FreeCAD.activeDocument().ActiveObject