-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.py
374 lines (295 loc) · 10.7 KB
/
gui.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
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.widget import Widget
from KCanvasHelper import *
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.lang import Builder
from kivy.core.window import Window
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import random
import _thread
import sys
from kivy.config import Config
Config.set('graphics', 'position', 'custom')
Config.set('graphics', 'left', 10)
Config.set('graphics', 'top', 10)
class RootLayout(BoxLayout):
def yyySomething(self):
pass
def setWindowSize():
Window.size = (200,550)
setWindowSize()
#class gui:
class gui(App):
def on_zUp(self):
print('on_zUp')
z = self.getZShow()
for zz in self.parser.zLayers:
if zz > z:
z = zz
break
self.rl.ids.s_sh_hLayer.value = z
self.plotFromNewThread()
def on_zDown(self):
print('on_zDown')
z = self.getZShow()
zn = z
for zz in self.parser.zLayers:
if zz < z:
zn = zz
elif zz == z or zz > z:
break
self.rl.ids.s_sh_hLayer.value = zn
self.plotFromNewThread()
def on_plot(self):
print("on_plot")
self.plotFromNewThread()
def on_hLayerChange(self,obj):
print("on_plot")
self.plotFromNewThread()
def on_hLayerMove(self,obj):
self.rl.ids.l_zSlider.text = str(self.getZShow())
def plotFromNewThread(self):
try:
if self.plotRunning:
self.plot( self.inFile, self.dVal )
except:
i = _thread.start_new_thread( self.plot, (self.inFile, self.dVal, ) )
self.plotRunning = True
def build(self):
Builder.load_file('layoutMain.kv')
self.pltInit = False
self.title = "Print Mill Post Process - PMPP"
self.rl = RootLayout()
'''
self.kc = KCanvasHelper()
self.bl = BoxLayout( orientation = 'vertical' )
self.blControls = BoxLayout(
orientation = 'vertical'
)
self.bl.add_widget( self.blControls )
btLoadFile = Button(
text = "Load file",
on_release = self.on_loadFile
)
self.blControls.add_widget(btLoadFile)
self.l_layersCount = Label(text="l_layersCount")
self.blControls.add_widget( self.l_layersCount )
self.w = Widget()
self.bl.add_widget( self.w )
self.kc.dClear( self.w.canvas )
#tests
if 0:
imgT = '/home/yoyo/Apps/icons/ico_firma_256_256.png'
self.kc.dImage( self.w.canvas, 10, 50, imgT)
self.kc.dImage( self.w.canvas, 10, 200, imgT, (32,32))
self.kc.dRectangle( self.w.canvas,
10,50,5,5, (255,0,0)
)
self.kc.dLine( self.w.canvas, 0,0, 10,50, 2, (0,255,0) )
return self.bl
'''
k = self.parser.zLayers
print("k",k)
self.rl.ids.s_sh_hLayer.min = min(k)
self.rl.ids.s_sh_hLayer.value = min(k)
self.rl.ids.s_sh_hLayer.max = max(k)
self.plotRunningProcess = False
self.plotFromNewThread()
d = self.dVal
self.rl.ids.lAddInf.text = '''
Stock at bottom left:
{} x {} x {}[mm]
'''.format(
d['bottomLeft'][0], d['bottomLeft'][1], d['bottomLeft'][2],
)
setWindowSize()
return self.rl
def setParser(self, parser, inFile, dVal):
self.parser = parser
self.inFile = inFile
self.dVal = dVal
def getZShow(self):
zShow = -1.0
sv = self.rl.ids.s_sh_hLayer.value
#print("show layer on slider ",sv)
for z in self.parser.zLayers:
if sv >= z:
zShow = z
else:
break
#print(" so from slider show:",zShow)
return zShow
def plotLine(self, ax, paths,
label_=None,
color_=None,
lineWidth_=1.0,
linestyle_='-'
):
if color_ == None:
color_ = ( random.random(), random.random(), random.random() )
addedLabel = False
showAllLayers = self.rl.ids.cb_sh_allLayer.active
zShow = self.getZShow()
#print("paths",len(paths))
for i,path in enumerate(paths):
xs = []
ys = []
zs = []
#print("")
for ii,l4 in enumerate(path):
try:
if showAllLayers == True or ( showAllLayers == False and zShow == l4['Z'] ):
if l4['X'] and l4['Y'] and l4['Z']:
xs.append(l4['X'])
ys.append(l4['Y'])
zs.append(l4['Z'])
#if showAllLayers == False:
# print(self.parser.V4lToStr(l4)," -> ",l4['orgLine'])
elif showAllLayers == False and zShow != l4['Z']:
#print("zShow {} and l4 is {}".format(zShow,l4['Z']))
break
except:
pass
if addedLabel == False and label_ != None:
ax.plot(xs, ys, zs,
color=color_,
linewidth=lineWidth_,
label=label_,
linestyle=linestyle_
)
addedLabel = True
else:
ax.plot(xs, ys, zs,
color=color_,
linewidth=lineWidth_,
linestyle=linestyle_
)
def plot(self, filePath, dVal):
print("gui.plot")
if self.plotRunningProcess == True:
print(" in running ....")
return 0
else:
self.plotRunningProcess = True
self.layers= {
'foam' : 0,
'outer': 1,
'offsets90': 0,
'offset': 1,
}
self.rl.ids.l_zSlider.text = "{}mm".format(self.getZShow())
for c in self.layers.keys():
#print(c)
active = self.rl.ids["cb_sh_%sLayer"%c].active
#print("checkt ?",active)
self.layers[c] = 1 if active else 0
#fig = plt.figure()
#ax = fig.add_subplot(projection='3d')
if self.pltInit == False:
self.fig = plt.figure("Print Mill Post Process - PMPP [{}]".format(filePath))
self.ax = self.fig.add_subplot(
2 if self.rl.ids.cb_sh_volume.active else 1,
1,1,
projection='3d')
self.pltInit = True
fig = self.fig
ax = self.ax
#ax.axis('equal') # list of float or {‘on’, ‘off’, ‘equal’, ‘tight’, ‘scaled’, ‘normal’, ‘auto’, ‘image’, ‘square’}
#ax.set_proj_type('persp')
ax.set_aspect(aspect='equal')
ax.autoscale_view()
#ax.set_title('Print Mill Post Process - PMPP')
ax.grid(True)
else:
ax = self.ax
fig = self.fig
ax.clear()
# 0,0,0 axis to show x,y,z
scaleSize = 10.0
ax.plot([0,scaleSize], [0,0], [0,0],
color = 'r',
linewidth=2.0
)
ax.plot([0,0],[0,scaleSize],[0,0],
color = 'g',
linewidth=2.0
)
ax.plot([0,0],[0,0],[0,scaleSize],
color = 'b',
linewidth=2.0
)
if self.layers['foam']:
self.plotLine( ax, self.parser.allWorkPathsV4l,
"all foam",
color_ = (0.1, 0.68, 0.5),
lineWidth_=0.38
)
if self.layers['outer']:
self.plotLine( ax, self.parser.outerWallV4l,
"outer foam",
color_ = (0.5,0.5,1.0),
linestyle_="--"
)
if self.layers['offsets90']:
self.plotLine( ax, self.parser.offsets90LinesV4l,
"offsets 90' lines",
color_ = (1.0,0,0),
lineWidth_= 0.7
)
if self.layers['offset']:
self.plotLine( ax, self.parser.offsetsLinesV4l,
"mill path tool D:{}[mm]".format(dVal['mill']['toolD']),
color_ = (0.75,0.5,0.0),
lineWidth_= 0.7
)
if self.rl.ids.cb_sh_volume.active:
print("volume graph !")
showAllLayers = self.rl.ids.cb_sh_allLayer.active
zShow = self.getZShow()
flow = []
xs = []
xBase = 0.0
volTotal = 0.0
for path in self.parser.allWorkPathsV4l:
for p in path[:-1]:
if showAllLayers == True or ( showAllLayers == False and zShow == p['Z'] ):
xs.append(xBase)
flow.append(p['EFlow'])
xBase+= p['dist']
try:
abcea = self.axE
except:
self.axE = self.fig.add_subplot(
3,1,3)
self.axE.clear()
self.axE.plot(xs,flow)
self.axE.autoscale_view()
self.axE.grid(True)
self.axE.set_ylabel("E flow")
self.axE.set_xlabel("path in mm")
if 1:
thismanager = plt.get_current_fig_manager()
thismanager.window.wm_geometry("+300+0")
ax.legend()
self.plotRunningProcess = False
plt.show()
#fig.canvas.draw()
#fig.canvas.flush_events()
#plt.pause(0.1)
else:
plt.savefig('/tmp/plt.png')
self.kc.dImage(
self.w.canvas,
0,
0,
'/tmp/plt.png'
)
def killPlt(self):
plt.close()
def on_loadFile(self,a):
print("on_loadFile")
self.plot()