-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathDiagram.py
More file actions
337 lines (267 loc) · 9.02 KB
/
Diagram.py
File metadata and controls
337 lines (267 loc) · 9.02 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# -*- coding: utf-8 -*-
#-------------------------------------------------
#-- Animation workbench
#--
#-- microelly 2015
#--
#-- GNU Lesser General Public License (LGPL)
#-------------------------------------------------
from say import *
import math
from EditWidget import EditWidget
__vers__= '0.2'
__dir__ = os.path.dirname(__file__)
def _creategraphs(obj):
obj.Proxy.data={}
obj.Proxy.data2={}
obj.Proxy.data3={}
obj.Proxy.data4={}
obj.Proxy.data5={}
obj.Proxy.data6={}
obj.Proxy.data7={}
obj.Proxy.data8={}
obj.Proxy.data9={}
if obj.trafo!='' and obj.graph == None:
w=Part.makeSphere(0.1)
Part.show(w)
obj.graph=FreeCAD.activeDocument().ActiveObject
obj.graph.ViewObject.LineColor=(1.0,0.0,.0)
obj.graph.Label="Graph 1 "
if obj.trafo2!='' and obj.graph2 == None:
w=Part.makeSphere(0.1)
Part.show(w)
obj.graph2=FreeCAD.activeDocument().ActiveObject
obj.graph2.ViewObject.LineColor=(.0,1.0,.0)
obj.graph2.Label="Graph 2 "
if obj.trafo3!='' and obj.graph3 == None:
w=Part.makeSphere(0.1)
Part.show(w)
obj.graph3=FreeCAD.activeDocument().ActiveObject
obj.graph3.ViewObject.LineColor=(.0,.0,1.0)
obj.graph3.Label="Graph 3 "
if obj.trafo4!='' and obj.graph4 == None:
w=Part.makeSphere(0.1)
Part.show(w)
obj.graph4=FreeCAD.activeDocument().ActiveObject
obj.graph4.ViewObject.LineColor=(1.0,1.0,.0)
obj.graph4.Label="Graph 4 "
if obj.trafo5!='' and obj.graph5 == None:
w=Part.makeSphere(0.1)
Part.show(w)
obj.graph5=FreeCAD.activeDocument().ActiveObject
obj.graph5.ViewObject.LineColor=(1.0,.0,1.0)
obj.graph5.Label="Graph 5 "
if obj.trafo6!='' and obj.graph6 == None:
w=Part.makeSphere(0.1)
Part.show(w)
obj.graph6=FreeCAD.activeDocument().ActiveObject
obj.graph6.ViewObject.LineColor=(.0,1.0,1.0)
obj.graph6.Label="Graph 6 "
if obj.trafo7!='' and obj.graph6 == None:
w=Part.makeSphere(0.1)
Part.show(w)
obj.graph7=FreeCAD.activeDocument().ActiveObject
obj.graph7.ViewObject.LineColor=(.0,1.0,1.0)
obj.graph7.Label="Graph 7 "
if obj.trafo8!='' and obj.graph8 == None:
w=Part.makeSphere(0.1)
Part.show(w)
obj.graph8=FreeCAD.activeDocument().ActiveObject
obj.graph8.ViewObject.LineColor=(.0,1.0,1.0)
obj.graph8.Label="Graph 8 "
if obj.trafo9!='' and obj.graph9 == None:
w=Part.makeSphere(0.1)
Part.show(w)
obj.graph9=FreeCAD.activeDocument().ActiveObject
obj.graph9.ViewObject.LineColor=(.0,1.0,1.0)
obj.graph9.Label="Graph 9 "
def createDiagram(name='My_Diagram',trafo='',trafo2='',trafo3='',trafo4='',trafo5='',trafo6=''):
obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython",name)
obj.addProperty("App::PropertyLink","source","Base","")
obj.addProperty("App::PropertyLink","source2","Base","")
obj.addProperty("App::PropertyLink","source3","Base","")
obj.addProperty("App::PropertyLink","source4","Base","")
obj.addProperty("App::PropertyPlacement","graphPlacement","Base","")
obj.addProperty("App::PropertyLink","graph","Base","")
obj.addProperty("App::PropertyLink","graph2","Base","")
obj.addProperty("App::PropertyLink","graph3","Base","")
obj.addProperty("App::PropertyLink","graph4","Base","")
obj.addProperty("App::PropertyLink","graph5","Base","")
obj.addProperty("App::PropertyLink","graph6","Base","")
obj.addProperty("App::PropertyLink","graph7","Base","")
obj.addProperty("App::PropertyLink","graph8","Base","")
obj.addProperty("App::PropertyLink","graph9","Base","")
obj.addProperty("App::PropertyFloat","out","Results","")
obj.addProperty("App::PropertyFloat","out2","Results","")
obj.addProperty("App::PropertyFloat","out3","Results","")
obj.addProperty("App::PropertyFloat","out4","Results","")
obj.addProperty("App::PropertyFloat","out5","Results","")
obj.addProperty("App::PropertyFloat","out6","Results","")
obj.addProperty("App::PropertyFloat","out7","Results","")
obj.addProperty("App::PropertyFloat","out8","Results","")
obj.addProperty("App::PropertyFloat","out9","Results","")
obj.addProperty("App::PropertyFloat","time","Base","")
obj.time=0
obj.addProperty("App::PropertyString","timeExpression","Functions","")
obj.addProperty("App::PropertyString","trafo","Functions","")
obj.addProperty("App::PropertyString","trafo2","Functions","")
obj.addProperty("App::PropertyString","trafo3","Functions","")
obj.addProperty("App::PropertyString","trafo4","Functions","")
obj.addProperty("App::PropertyString","trafo5","Functions","")
obj.addProperty("App::PropertyString","trafo6","Functions","")
obj.addProperty("App::PropertyString","trafo7","Functions","")
obj.addProperty("App::PropertyString","trafo8","Functions","")
obj.addProperty("App::PropertyString","trafo9","Functions","")
obj.trafo=trafo
obj.trafo2=trafo2
obj.trafo3=trafo3
obj.trafo4=trafo4
obj.trafo5=trafo5
obj.trafo6=trafo6
obj.addProperty("App::PropertyFloat","a","FunctionParameter","")
obj.addProperty("App::PropertyFloat","b","FunctionParameter","")
obj.addProperty("App::PropertyFloat","c","FunctionParameter","")
obj.addProperty("App::PropertyFloat","d","FunctionParameter","")
obj.a=200
obj.b=0.5
obj.c=50
_Diagram(obj)
_ViewProviderDiagram(obj.ViewObject)
obj.Proxy.updater=True
_creategraphs(obj)
return obj
class _Diagram(Animation._Actor):
def update(self):
time=self.obj2.time
try:
say("update time=" + str(time) + ", "+ self.obj2.Label)
except:
say("update (ohne Label)")
time=self.obj2.time
a=self.obj2.a
b=self.obj2.b
c=self.obj2.c
d=self.obj2.d
source=self.obj2.source
source2=self.obj2.source2
source3=self.obj2.source3
source4=self.obj2.source4
if self.obj2.timeExpression!="":
say(["eval time Expression",time])
time=eval(self.obj2.timeExpression)
say(["time== ",time,self.obj2.timeExpression])
out=0
out1=0
out2=0
out3=0
out4=0
out5=0
out6=0
out7=0
out8=0
out9=0
if self.obj2.trafo: out=eval(self.obj2.trafo)
if self.obj2.trafo2: out2=eval(self.obj2.trafo2)
if self.obj2.trafo3: out3=eval(self.obj2.trafo3)
if self.obj2.trafo4: out4=eval(self.obj2.trafo4)
if self.obj2.trafo5: out5=eval(self.obj2.trafo5)
if self.obj2.trafo6: out6=eval(self.obj2.trafo6)
if self.obj2.trafo7: out7=eval(self.obj2.trafo7)
if self.obj2.trafo8: out8=eval(self.obj2.trafo8)
if self.obj2.trafo9: out9=eval(self.obj2.trafo9)
# say([time,out,out2,out3,out4])
self.obj2.out=out
self.obj2.out2=out2
self.obj2.out3=out3
self.obj2.out4=out4
self.obj2.out5=out5
self.obj2.out6=out6
self.obj2.out7=out7
self.obj2.out8=out8
self.obj2.out9=out9
if self.obj2.trafo:
self.register(time,self.data,out,self.obj2.graph)
if self.obj2.trafo2:
self.register(time,self.data2,out2,self.obj2.graph2)
if self.obj2.trafo3:
self.register(time,self.data3,out3,self.obj2.graph3)
if self.obj2.trafo4:
self.register(time,self.data4,out4,self.obj2.graph4)
if self.obj2.trafo5:
self.register(time,self.data5,out5,self.obj2.graph5)
if self.obj2.trafo6:
self.register(time,self.data6,out6,self.obj2.graph6)
if self.obj2.trafo7:
self.register(time,self.data7,out7,self.obj2.graph7)
if self.obj2.trafo8:
self.register(time,self.data8,out8,self.obj2.graph8)
if self.obj2.trafo9:
self.register(time,self.data9,out9,self.obj2.graph9)
def register(self,time,data,out,graph):
data[time]=out
ts=data.keys()
ts.sort()
pl=[]
# say("points")
for t in ts:
pl.append((t,data[t],1))
# say(pl)
if len(pl)>1:
w=Part.makePolygon(pl)
else:
w=Part.makeSphere(0.1)
try:
graph.Shape=w
graph.Placement=self.obj2.graphPlacement
except:
pass
def step(self,now):
self.obj2.time=float(now)/100
def onChanged(self,obj,prop):
if prop in ['trafo','trafo2','trafo3','trafo4','trafo5','trafo6','trafo7','trafo8','trafo9']:
_creategraphs(obj)
class _ViewProviderDiagram(Animation._ViewProviderActor):
def attach(self,vobj):
vobj.Proxy = self
self.Object = vobj.Object
self.obj2=self.Object
self.Object.Proxy.Lock=False
self.Object.Proxy.Changed=False
_creategraphs(self.Object)
icon='/icons/diagram.png'
self.iconpath = __dir__ + icon
self.vers=__vers__
return
def doubleClicked(self,vobj):
return
def setupContextMenu(self, obj, menu):
return
if __name__ == '__main__':
from Diagram import *
App.setActiveDocument("Unnamed")
App.ActiveDocument=App.getDocument("Unnamed")
Gui.ActiveDocument=Gui.getDocument("Unnamed")
import Animation
Animation.createManager()
App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.addObject("Part::Cone","Cone")
import Placer
s1=Placer.createPlacer("B1")
s1.target=App.ActiveDocument.Box001
s2=Placer.createPlacer("B2")
s2.target=App.ActiveDocument.Box002
s2.y="10"
s3=Placer.createPlacer("B3")
s3.target=App.ActiveDocument.Box003
s3.y="20"
import Diagram
c=Diagram.createDiagram("dia","0.200*time","0.2*(0.01*time-0.5)**2","10+time+1","-10*time")
c.source=s1
c.trafo="source.Placement.Rotation.Angle*100"
c.timeExpression="source.time*10000"
c.graphPlacement.Base.z=10
m=App.ActiveDocument.My_Manager
m.addObject(c)