-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.py
716 lines (605 loc) · 37.8 KB
/
draw.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
5#!/usr/bin/env python
# -*- coding: utf-8
import wx
import wx.lib.agw.floatspin as FS
from wx.glcanvas import GLCanvas
from wx.glcanvas import GLContext
from pysymoro import robot
from symorodraw import objects
import canvas
import data
from numpy import *
from numpy.linalg import norm
import OpenGL.GL as gl
import OpenGL.GLU as glu
import OpenGL.GLUT as glut
from objects import Frame, SuperRevoluteJoint, SuperPrismaticJoint, Point
# This class represents the main window of the program. It creates the elemetns of the program and fill all panels and sizers.
# New elements can be added by adding the entry into the "widget" dictionary in data.py file. In case of the callback it has to be created in this class
# If element is already use in the program, it should be automaticaly implemented
# It carries out the simple operations and sent the inital signals to the main program to begin mulit-click operations.
class MainFrame(wx.Frame):
'''Create Main Window of the program'''
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.data = data.data()
self.buttons = {}
self.sizers = {}
self.static_sizers = {}
self.canvas = {}
self.panels = {}
self.grids = {}
self.check_boxes = {}
self.texts = {}
self.spins = {}
self.menu_bars = {}
self.menus = {}
self.menu_items = {}
self.mouse = wx.MouseEvent()
self.create_menu()
self.create_ui()
self.Show()
i = [key for key in self.data.GetList() if self.data.CheckKey(key, 'active')]
for widget in i:
key = self.data.GetWidget(widget)
if not key['active']:
if self.data.GetValue(key['parent'],'w_type')=='sizer':
self.sizers[key['parent']].Hide(key['position'])
elif self.data.GetValue(key['parent'],'w_type')=='static_sizer':
self.static_sizers[key['parent']].Hide(key['position'])
def create_menu(self):
for key in self.data.GetTypedList('w_type','menu_bar'):
self.CreateMenuElements('MENU_BAR')
self.AppendMenuElements('MENU_BAR')
self.SetMenus()
# Initalization of elements
def CreateMenuElements(self, key):
if self.data.GetValue(key,'w_type')=='menu_bar':
self.menu_bars[key] = wx.MenuBar()
elif self.data.GetValue(key,'w_type')=='menu':
self.menus[key] = wx.Menu()
elif self.data.GetValue(key,'w_type')=='menu_item':
menu_item = self.data.GetWidget(key)
if self.data.CheckKey(key,'id'):
menu_id = menu_item['id']
else:
menu_id = wx.ID_ANY
self.menu_items[key]= wx.MenuItem(self.menus[menu_item['parent']], id=menu_id, text=menu_item['label'])
if self.data.CheckKey(key,'callback'):
self.Bind(wx.EVT_MENU, getattr(self, menu_item['callback']), self.menu_items[key])
else:
self.Bind(wx.EVT_MENU, None, self.menu_items[key])
my_list = self.data.GetTypedList('parent',key)
for name in my_list:
self.CreateMenuElements(name)
# Filling the menu
def AppendMenuElements(self, key):
my_list = self.data.SortPosition(key)
for name in my_list:
self.AppendMenuElements(name)
if self.data.GetValue(name,'w_type')=='menu':
menu = self.data.GetWidget(name)
if self.data.CheckKey(name,'w_type'):
if menu['submenu']:
self.menus[key].AppendSubMenu(self.menus[name], text=menu['label'])
else:
self.menu_bars[key].Append(self.menus[name], title=menu['label'])
elif self.data.GetValue(name,'w_type')=='menu_item':
menu_item = self.data.GetWidget(name)
self.menus[key].AppendItem(self.menu_items[name])
elif self.data.GetValue(name,'w_type') == 'menu_separator':
self.menus[key].AppendSeparator()
def SetMenus(self):
my_list = self.data.GetTypedList('w_type','menu_bar')
for name in my_list:
self.SetMenuBar(self.menu_bars[name])
# Create UI
def create_ui(self):
self.CreateElements('MAIN')
self.FillSizers('MAIN')
self.SetSizerAndFit(self.sizers['MAIN'])
def CreateElements(self, key):
my_type = self.data.GetValue(key,'w_type')
if my_type == 'static_text':
self.CreateText(key)
elif my_type == 'canvas':
self.CreateCanvas(key)
elif my_type == 'panel':
self.CreatePanel(key)
elif my_type == 'sizer':
self.CreateSizer(key)
elif my_type == 'button':
self.CreateButton(key)
elif my_type == 'grid':
self.CreateGrid(key)
elif my_type == 'static_sizer':
self.CreateStaticSizer(key)
elif my_type == 'check_box':
self.CreateCheckBox(key)
elif my_type == 'float_spin':
self.CreateFloatSpin(key)
my_list = self.data.GetTypedList('parent',key)
for name in my_list:
self.CreateElements(name)
def FillSizers(self, key):
if not self.data.GetValue(key, 'w_type') == 'grid':
my_list = self.data.SortPosition(key)
else:
my_list = self.data.GetTypedList('parent',key)
for name in my_list:
self.FillSizers(name)
if self.data.GetValue(name,'w_type') == 'button':
self.FillButton(name)
if self.data.GetValue(name,'w_type') == 'static_sizer':
self.FillStaticSizer(name)
if self.data.GetValue(name,'w_type') == 'sizer':
self.FillSizer(name)
if self.data.GetValue(name,'w_type') == 'canvas':
self.FillCanvas(name)
if self.data.GetValue(name,'w_type') == 'panel':
self.FillPanel(name)
if self.data.GetValue(name,'w_type') == 'grid':
self.FillGrid(name)
if self.data.GetValue(name,'w_type') == 'static_text':
self.FillStaticText(name)
if self.data.GetValue(name,'w_type') == 'check_box':
self.FillCheckBox(name)
if self.data.GetValue(name,'w_type') == 'float_spin':
self.FillFloatSpin(name)
# Creators of specific type of elements
def CreateText(self, key):
text = self.data.GetWidget(key)
if not self.data.CheckKey(key, 'size'):
text['size']=(70, -1)
self.texts[key] = wx.StaticText(parent=self.panels[text['panel']], size=text['size'], label=text['label'])
def CreateCanvas(self, key):
self.canvas[key] = canvas.myGLCanvas(self)
def CreatePanel(self, key):
self.panels[key] = wx.Panel(self)
def CreateGrid(self, key):
grid = self.data.GetWidget(key)
self.grids[key]= wx.GridBagSizer(hgap=grid['horizontal'], vgap=grid['vertical'])
def CreateButton(self, key):
button = self.data.GetWidget(key)
self.buttons[key] = wx.Button(parent=self.panels[button['panel']], label=button['label'])
self.buttons[key].Bind(wx.EVT_BUTTON, getattr(self, button['callback']) )
def CreateCheckBox(self, key):
check_box = self.data.GetWidget(key)
self.check_boxes[key] = wx.CheckBox(parent=self.panels[check_box['panel']], label=check_box['label'])
self.check_boxes[key].Bind(wx.EVT_CHECKBOX,getattr(self, check_box['callback']))
def CreateSizer(self, key):
sizer = self.data.GetWidget(key)
if not self.data.CheckKey(key, 'orientation'):
sizer['orientation'] = wx.HORIZONTAL
self.sizers[key] = wx.BoxSizer(sizer['orientation'])
def CreateStaticSizer(self, key):
sizer = self.data.GetWidget(key)
if not self.data.CheckKey(key, 'id'):
sizer['id'] = wx.ID_ANY
if not self.data.CheckKey(key, 'orientation'):
sizer['orientation'] = wx.HORIZONTAL
if self.data.CheckKey(key, 'label'):
self.static_sizers[key] = wx.StaticBoxSizer(wx.StaticBox(parent=self.panels[sizer['panel']], id=sizer['id'], label=self.data.GetValue(key,'label')
), orient=sizer['orientation'])
else:
self.static_sizers[key] = wx.StaticBoxSizer(wx.StaticBox(parent=self.panels[sizer['panel']], id=sizer['id'],), orient=sizer['orientation'])
def CreateFloatSpin(self, key):
spin = self.data.GetWidget(key)
if not self.data.CheckKey(key, 'size'):
sizer['size'] = (70,-1)
if not self.data.CheckKey(key, 'increment'):
sizer['increment'] = 0.5
if not self.data.CheckKey(key, 'min_val'):
sizer['size'] = None
if not self.data.CheckKey(key, 'max_val'):
sizer['increment'] = None
self.spins[key]=(FS.FloatSpin(self.panels[spin['panel']], size=spin['size'],
increment=spin['increment'], min_val=spin['min_val'], max_val=spin['max_val']))
self.spins[key].Bind(FS.EVT_FLOATSPIN, getattr(self, spin['callback']) )
self.spins[key].SetDigits(2)
# Specific to the type filling operations
def FillButton(self, key):
button = self.data.GetWidget(key)
if self.data.GetValue(button['parent'],'w_type') =='grid':
self.grids[button['parent']].Add(self.buttons[key], pos=( button['vertical'],button['horizontal']))
else:
if not self.data.CheckKey(key,'proportion'):
button['proportion'] = 0
if not self.data.CheckKey(key,'border'):
button['border'] = 1
if not self.data.CheckKey(key,'flag'):
button['flag'] = wx.EXPAND
if self.data.GetValue(button['parent'],'w_type') == 'static_sizer':
self.static_sizers[button['parent']].Add(self.buttons[key], proportion=button['proportion'], flag=button['flag'], border=button['border'])
elif self.data.GetValue(button['parent'],'w_type') == 'sizer':
self.sizers[button['parent']].Add(self.buttons[key], proportion=button['proportion'], flag=button['flag'], border=button['border'])
def FillCheckBox(self, key):
check_box = self.data.GetWidget(key)
if self.data.GetValue(check_box['parent'],'w_type') =='grid':
self.grids[check_box['parent']].Add(self.check_boxes[key], pos=( check_box['vertical'],check_box['horizontal']))
else:
if not self.data.CheckKey(key,'proportion'):
check_box['proportion'] = 0
if not self.data.CheckKey(key,'border'):
check_box['border'] = 1
if not self.data.CheckKey(key,'flag'):
check_box['flag'] = wx.EXPAND
if self.data.GetValue(check_box['parent'],'w_type') == 'static_sizer':
self.static_sizers[check_box['parent']].Add(self.check_boxes[key], proportion=check_box['proportion'], flag=check_box['flag'], border=check_box['border'])
elif self.data.GetValue(check_box['parent'],'w_type') == 'sizer':
self.sizers[check_box['parent']].Add(self.check_boxes[key], proportion=check_box['proportion'], flag=check_box['flag'], border=check_box['border'])
def FillStaticSizer(self, key):
sizer = self.data.GetWidget(key)
if self.data.GetValue(sizer['parent'],'w_type') =='panel':
self.panels[sizer['parent']].SetSizerAndFit(self.static_sizers[key])
elif self.data.GetValue(sizer['parent'],'w_type') =='grid':
self.grids[sizer['parent']].Add(self.static_sizers[key], pos=( sizer['vertical'],sizer['horizontal']))
elif self.data.GetValue(sizer['parent'],'w_type') =='sizer':
if not self.data.CheckKey(key,'proportion'):
sizer['proportion'] = 0
if not self.data.CheckKey(key,'border'):
sizer['border'] = 0
if not self.data.CheckKey(key,'flag'):
sizer['flag'] = wx.EXPAND
self.sizers[sizer['parent']].Add(self.static_sizers[key], proportion=sizer['proportion'], flag=sizer['flag'], border=sizer['border'])
def FillSizer(self, key):
sizer = self.data.GetWidget(key)
if self.data.GetValue(sizer['parent'],'w_type') =='panel':
self.panels[sizer['parent']].SetSizerAndFit(self.sizers[key])
elif self.data.GetValue(sizer['parent'],'w_type') =='grid':
self.grids[sizer['parent']].Add(self.sizers[key], pos=( sizer['vertical'],sizer['horizontal']))
else:
if not self.data.CheckKey(key,'proportion'):
sizer['proportion'] = 0
if not self.data.CheckKey(key,'border'):
sizer['border'] = 0
if not self.data.CheckKey(key,'flag'):
sizer['flag'] = wx.EXPAND
if self.data.GetValue(sizer['parent'],'w_type') =='sizer':
self.sizers[sizer['parent']].Add(self.static[key], proportion=sizer['proportion'], flag=sizer['flag'], border=sizer['border'])
elif self.data.GetValue(sizer['parent'],'w_type') =='static_sizer':
self.static_sizers[sizer['parent']].Add(self.sizers[key], proportion=sizer['proportion'], flag=sizer['flag'], border=sizer['border'])
def FillCanvas(self, key):
canvas = self.data.GetWidget(key)
if not self.data.CheckKey(key,'proportion'):
canvas['proportion'] = 0
if not self.data.CheckKey(key,'border'):
canvas['border'] = 8
if not self.data.CheckKey(key,'flag'):
canvas['flag'] = wx.EXPAND| wx.ALL
self.sizers[canvas['parent']].Add(self.canvas[key], proportion=canvas['proportion'], flag=canvas['flag'], border=canvas['border'])
def FillPanel(self, key):
panel = self.data.GetWidget(key)
if not self.data.CheckKey(key,'proportion'):
panel['proportion'] = 0
if not self.data.CheckKey(key,'border'):
panel['border'] = 1
if not self.data.CheckKey(key,'flag'):
panel['flag'] = wx.EXPAND
self.sizers[panel['parent']].Add(self.panels[key], proportion=panel['proportion'], flag=panel['flag'], border=panel['border'])
def FillGrid(self, key):
grid = self.data.GetWidget(key)
if not self.data.CheckKey(key,'proportion'):
grid['proportion'] = 0
if not self.data.CheckKey(key,'border'):
grid['border'] = 0
if not self.data.CheckKey(key,'flag'):
grid['flag'] = wx.ALL
if self.data.GetValue(grid['parent'],'w_type')=='sizer':
self.sizers[grid['parent']].Add(self.grids[key], proportion=grid['proportion'], flag=grid['flag'], border=grid['border'])
elif self.data.GetValue(grid['parent'],'w_type')=='static_sizer':
self.static_sizers[grid['parent']].Add(self.grids[key], proportion=grid['proportion'], flag=grid['flag'], border=grid['border'])
def FillStaticText(self, key):
text = self.data.GetWidget(key)
if self.data.GetValue(text['parent'],'w_type')=='grid':
self.grids[text['parent']].Add(self.texts[key],(self.data.GetValue(key,'horizontal'),self.data.GetValue(key,'vertical')))
else:
if not self.data.CheckKey(key,'proportion'):
text['proportion'] = 0
if not self.data.CheckKey(key,'border'):
text['border'] = 0
if not self.data.CheckKey(key,'flag'):
text['flag'] = wx.ALIGN_LEFT
if self.data.GetValue(text['parent'],'w_type')=='sizer':
self.sizers[text['parent']].Add(self.texts[key], proportion=text['proportion'], flag=text['flag'], border=text['border'])
elif self.data.GetValue(text['parent'],'w_type')=='static_sizer':
self.static_sizers[text['parent']].Add(self.texts[key], proportion=text['proportion'], flag=text['flag'], border=text['border'])
def FillFloatSpin(self, key):
spin = self.data.GetWidget(key)
if self.data.GetValue(spin['parent'],'w_type')=='grid':
self.grids[spin['parent']].Add(self.spins[key],(self.data.GetValue(key,'horizontal'),self.data.GetValue(key,'vertical')))
else:
if not self.data.CheckKey(key,'proportion'):
spin['proportion'] = 0
if not self.data.CheckKey(key,'border'):
spin['border'] = 0
if not self.data.CheckKey(key,'flag'):
spin['flag'] = wx.ALIGN_LEFT
if self.data.GetValue(spin['parent'],'w_type')=='sizer':
self.sizers[spin['parent']].Add(self.spins[key], proportion=spin['proportion'], flag=spin['flag'], border=spin['border'])
elif self.data.GetValue(spin['parent'],'w_type')=='static_sizer':
self.static_sizers[spin['parent']].Add(self.spins[key], proportion=spin['proportion'], flag=spin['flag'], border=spin['border'])
# Callbacks
# Planes
def OnPlane1(self, event):
del self.canvas['CANVAS'].plane[:]
self.Init('PLANE1')
def OnPlane2(self, event):
del self.canvas['CANVAS'].plane[:]
self.Init('PLANE2')
def OnPlane3(self, event):
del self.canvas['CANVAS'].plane[:]
self.Init('PLANE3')
# Export
def OnExport(self, event):
self.Export()
# Subfunction to the OnExport callback
def Export(self):
export = wx.TextEntryDialog(None, 'Give the name of the robot', style=wx.SYSTEM_MENU|wx.OK|wx.CANCEL)
if export.ShowModal()==wx.ID_OK:
name = export.GetValue()
if name:
self.canvas['CANVAS'].Export(export.GetValue())
else:
msg = wx.MessageDialog (None, 'Cannot export, please give the name of the robot.', style=wx.OK|wx.CENTRE)
if msg.ShowModal()==wx.ID_OK:
self.Export()
def OnRefPoint(self, event):
self.Init('REF_POINT')
self.data.FlagReset('PICK')
# Camera, views
def OnTop(self, event):
self.SetCamera([0,1,0],[0,0,-1])
def OnFront(self, event):
self.SetCamera([0,0,1],[0,1,0])
def OnRight(self, event):
self.SetCamera([1,0,0],[0,1,0])
def OnBottom(self, event):
self.SetCamera([0,-1,0],[0,0,1])
def OnBack(self, event):
self.SetCamera([0,0,-1],[0,1,0])
def OnLeft(self, event):
self.SetCamera([-1,0,0],[0,1,0])
# Subfunction to the camera callbacks
def SetCamera(self, up, eye):
self.canvas['CANVAS'].up = up
self.canvas['CANVAS'].cam = add(multiply(eye,norm(self.canvas['CANVAS'].u)),self.canvas['CANVAS'].cen)
self.canvas['CANVAS'].CameraTransformation()
# Create Joints
def OnRevolute(self, event):
if self.data.FlagGet('MODE'):
msg = wx.MessageDialog (None, 'Cannot add an element, switch to the structure mode.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
self.Init('REVOLUTE')
self.data.FlagReset('PICK')
def OnPrismatic(self, event):
if self.data.FlagGet('MODE'):
msg = wx.MessageDialog (None, 'Cannot add an element, switch to the structure mode.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
self.Init('PRISMATIC')
self.data.FlagReset('PICK')
def OnFixed(self, event):
if self.data.FlagGet('MODE'):
msg = wx.MessageDialog (None, 'Cannot add an element, switch to the structure mode.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
self.Init('FIXED')
self.data.FlagReset('PICK')
# PANEL_SIDE elements
def OnDelete(self, event):
if self.data.FlagGet('MODE'):
msg = wx.MessageDialog (None, 'Cannot remove an element, switch to the structure mode.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
self.Init('DELETE')
def OnAddAncestor(self, event):
if self.data.FlagGet('MODE'):
msg = wx.MessageDialog (None, 'Cannot add an element, switch to the structure mode.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
self.Init('ADD_ANC')
def OnRemoveAncestor(self, event):
if self.data.FlagGet('MODE'):
msg = wx.MessageDialog (None, 'Cannot add an element, switch to the structure mode.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
self.Init('REM_ANC')
def OnDefineD_H(self,event):
self.DefineD_H()
if self.canvas['CANVAS'].structure:
self.UpdateValues()
self.data.FlagSet('MODE',1)
# Subfunction to the Defining parameters callbacks
def DefineD_H(self):
self.canvas['CANVAS'].structure, self.canvas['CANVAS'].branches = self.canvas['CANVAS'].DefineStructure()
if self.canvas['CANVAS'].structure and self.canvas['CANVAS'].branches:
next_branch = [[self.canvas['CANVAS'].branches[self.canvas['CANVAS'].structure[0]][1:],
transpose(self.canvas['CANVAS'].elements[self.canvas['CANVAS'].structure[4][0]-1].T),
self.canvas['CANVAS'].structure[4][0]]]
while next_branch:
new_branch = self.canvas['CANVAS'].GetParameters(next_branch[0][0],next_branch[0][1],next_branch[0][2])
self.canvas['CANVAS'].SetParameters(next_branch[0][0])
next_branch += self.canvas['CANVAS'].GetTransforms(next_branch[0][0],next_branch[0][1], new_branch)
del next_branch[0]
self.data.FlagSet('PARAMETERS',1)
def OnStructure(self,event):
self.canvas['CANVAS'].SaveConfiguration()
self.data.FlagReset('MODE')
def OnCheckParameters(self, event):
if self.data.FlagGet('PARAMETERS')==3:
msg = wx.MessageDialog (None, 'Structure has been changed, cannot come back to the previous configuration.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
elif self.data.FlagGet('PARAMETERS')==2:
self.canvas['CANVAS'].LoadConfiguration()
self.UpdateValues()
if self.canvas['CANVAS'].structure:
self.data.FlagSet('MODE',1)
def OnConfiguration(self, event):
if not self.data.FlagGet('PARAMETERS') or self.data.FlagGet('PARAMETERS') == 3:
self.DefineD_H()
self.data.FlagSet('PARAMETERS',2)
self.canvas['CANVAS'].SaveConfiguration()
self.canvas['CANVAS'].SetConfiguration()
self.UpdateValues()
if self.canvas['CANVAS'].structure:
self.data.FlagSet('MODE',1)
def UpdateValues(self):
if not self.data.FlagGet('ACTIVE_JOINT') == -2:
joint = self.canvas['CANVAS'].elements[self.data.FlagGet('ACTIVE_JOINT')-1]
else:
joint = self.canvas['CANVAS'].globFrame
self.spins['ON_R'].SetValue(joint.r)
self.spins['ON_THETA'].SetValue(joint.theta)
self.spins['ON_D'].SetValue(joint.d)
self.spins['ON_ALPHA'].SetValue(joint.alpha)
self.spins['ON_B'].SetValue(joint.b)
self.spins['ON_GAMMA'].SetValue(joint.gamma)
self.spins['VAR_ON_THETA'].SetValue(joint.theta)
self.spins['VAR_ON_R'].SetValue(joint.r)
def OnCut(self, event):
self.canvas['CANVAS'].elements[self.data.FlagGet('ACTIVE_JOINT')-1].cut_joint = event.EventObject.GetValue()
def OnActive(self, event):
self.canvas['CANVAS'].elements[self.data.FlagGet('ACTIVE_JOINT')-1].active = event.EventObject.GetValue()
def OnChangeZAxis(self, event):
self.canvas['CANVAS'].elements[self.data.FlagGet('ACTIVE_JOINT')-1].T[0:3,0:3] = self.canvas['CANVAS'].EulerTransformation(pi,[1,0,0]).dot(self.canvas['CANVAS'].elements[
self.data.FlagGet('ACTIVE_JOINT')-1].T[0:3,0:3])
# Parameters
def OnAlpha(self, event):
self.canvas['CANVAS'].elements[self.data.FlagGet('ACTIVE_JOINT')-1].alpha = event.EventObject.GetValue()
self.canvas['CANVAS'].OnDraw()
self.canvas['CANVAS'].Redraw()
def OnTheta(self, event):
self.canvas['CANVAS'].elements[self.data.FlagGet('ACTIVE_JOINT')-1].theta = event.EventObject.GetValue()
self.canvas['CANVAS'].OnDraw()
self.canvas['CANVAS'].Redraw()
def OnGamma(self, event):
self.canvas['CANVAS'].elements[self.data.FlagGet('ACTIVE_JOINT')-1].gamma = event.EventObject.GetValue()
self.canvas['CANVAS'].OnDraw()
self.canvas['CANVAS'].Redraw()
def OnD(self, event):
self.canvas['CANVAS'].elements[self.data.FlagGet('ACTIVE_JOINT')-1].d = event.EventObject.GetValue()
self.canvas['CANVAS'].OnDraw()
self.canvas['CANVAS'].Redraw()
def OnB(self, event):
self.canvas['CANVAS'].elements[self.data.FlagGet('ACTIVE_JOINT')-1].b = event.EventObject.GetValue()
self.canvas['CANVAS'].OnDraw()
self.canvas['CANVAS'].Redraw()
def OnR(self, event):
self.canvas['CANVAS'].elements[self.data.FlagGet('ACTIVE_JOINT')-1].r = event.EventObject.GetValue()
self.canvas['CANVAS'].OnDraw()
self.canvas['CANVAS'].Redraw()
#Constraints
def OnParallel(self, event):
if self.data.FlagGet('MODE'):
msg = wx.MessageDialog (None, 'Cannot add an element, switch to the structure mode.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
del self.canvas['CANVAS'].plane[:]
self.Init('PARALLEL')
def OnPerpendicular(self, event):
if self.data.FlagGet('MODE'):
msg = wx.MessageDialog (None, 'Cannot add an element, switch to the structure mode.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
del self.canvas['CANVAS'].plane[:]
self.Init('PERPENDICULAR')
def OnPlanePerpendicular(self, event):
if self.data.FlagGet('MODE'):
msg = wx.MessageDialog (None, 'Cannot add an element, switch to the structure mode.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
del self.canvas['CANVAS'].plane[:]
self.Init('PLANE_PERPENDICULAR')
def OnAtDistance(self, event):
if self.data.FlagGet('MODE'):
msg = wx.MessageDialog (None, 'Cannot add an element, switch to the structure mode.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
del self.canvas['CANVAS'].plane[:]
self.Init('AT_DISTANCE')
def OnAtAngle(self,event):
if self.data.FlagGet('MODE'):
msg = wx.MessageDialog (None, 'Cannot add an element, switch to the structure mode.', style=wx.OK|wx.CENTRE)
msg.ShowModal()
return
del self.canvas['CANVAS'].plane[:]
self.Init('AT_ANGLE')
# Function initaliazing the flag
def Init(self, f_id):
if not self.data.FlagGet(f_id):
self.data.FlagsChange('joint')
self.data.FlagsChange('ref')
self.data.FlagsChange('plane')
self.data.FlagsChange('button')
self.data.FlagsChange('constraints')
self.data.FlagIncrement(f_id)
# Activating and the deactivating picked elements
def ActiveJoint(self,joint_id):
if not joint_id == -2:
joint = self.canvas['CANVAS'].elements[joint_id-1]
else:
joint = self.canvas['CANVAS'].globFrame
for key in self.data.GetTypedList('parent','PANEL_JOINT_SIZER'):
if not key == 'ON_ANCESTORS':
self.sizers['PANEL_JOINT_SIZER'].Show(self.data.GetValue(key,'position'))
if not joint.param or joint.virtual_joint:
for key in self.data.GetTypedList('parent','ON_PARAMETERS'):
self.sizers['ON_PARAMETERS'].Hide(self.data.GetValue(key,'position'))
self.static_sizers['ON_VARIABLES'].Hide(self.data.GetValue('ON_VAR_S_R','position'))
self.static_sizers['ON_VARIABLES'].Hide(self.data.GetValue('ON_VAR_S_THETA','position'))
else:
if isinstance(joint,SuperRevoluteJoint):
self.static_sizers['ON_VARIABLES'].Show(self.data.GetValue('ON_VAR_S_THETA','position'))
self.static_sizers['ON_PARAMETERS'].Hide(self.data.GetValue('ON_PARAM_S_THETA','position'))
self.static_sizers['ON_VARIABLES'].Hide(self.data.GetValue('ON_VAR_S_R','position'))
self.static_sizers['ON_PARAMETERS'].Show(self.data.GetValue('ON_PARAM_S_R','position'))
elif isinstance(joint,SuperPrismaticJoint):
self.static_sizers['ON_VARIABLES'].Hide(self.data.GetValue('ON_VAR_S_THETA','position'))
self.static_sizers['ON_PARAMETERS'].Show(self.data.GetValue('ON_PARAM_S_THETA','position'))
self.static_sizers['ON_VARIABLES'].Show(self.data.GetValue('ON_VAR_S_R','position'))
self.static_sizers['ON_PARAMETERS'].Hide(self.data.GetValue('ON_PARAM_S_R','position'))
else:
self.static_sizers['ON_VARIABLES'].Hide(self.data.GetValue('ON_VAR_S_THETA','position'))
self.static_sizers['ON_PARAMETERS'].Show(self.data.GetValue('ON_PARAM_S_THETA','position'))
self.static_sizers['ON_VARIABLES'].Hide(self.data.GetValue('ON_VAR_S_R','position'))
self.static_sizers['ON_PARAMETERS'].Show(self.data.GetValue('ON_PARAM_S_R','position'))
if joint.param == 4:
self.static_sizers['ON_PARAMETERS'].Hide(self.data.GetValue('ON_PARAM_S_B','position'))
self.static_sizers['ON_PARAMETERS'].Hide(self.data.GetValue('ON_PARAM_S_GAMMA','position'))
self.static_sizers['ON_PARAMETERS'].Show(self.data.GetValue('ON_PARAM_S_ALPHA','position'))
self.static_sizers['ON_PARAMETERS'].Show(self.data.GetValue('ON_PARAM_S_D','position'))
elif joint.param == 6:
self.static_sizers['ON_PARAMETERS'].Show(self.data.GetValue('ON_PARAM_S_B','position'))
self.static_sizers['ON_PARAMETERS'].Show(self.data.GetValue('ON_PARAM_S_GAMMA','position'))
self.static_sizers['ON_PARAMETERS'].Show(self.data.GetValue('ON_PARAM_S_ALPHA','position'))
self.static_sizers['ON_PARAMETERS'].Show(self.data.GetValue('ON_PARAM_S_D','position'))
self.check_boxes['ON_ACTIVE'].SetValue(joint.active)
self.check_boxes['ON_CUT_JOINT'].SetValue(joint.cut_joint)
self.data.FlagSet('ACTIVE_JOINT',joint_id)
self.UpdateValues()
def ActiveLink(self, link_id):
self.sizers['PANEL_JOINT_SIZER'].Show(self.data.GetValue('ON_ANCESTORS','position'))
self.data.FlagSet('ACTIVE_LINK',link_id)
def Deactive(self):
for key in self.data.GetTypedList('parent','PANEL_JOINT_SIZER'):
self.sizers['PANEL_JOINT_SIZER'].Hide(self.data.GetValue(key,'position'))
self.static_sizers['ON_VARIABLES'].Hide(self.data.GetValue('ON_VAR_S_R','position'))
self.static_sizers['ON_VARIABLES'].Hide(self.data.GetValue('ON_VAR_S_THETA','position'))
self.data.FlagReset('ACTIVE_JOINT')
self.data.FlagReset('ACTIVE_LINK')
# Initalization of the program
if __name__ == '__main__':
app = wx.App(redirect = False)
style = wx.DEFAULT_FRAME_STYLE^wx.MAXIMIZE_BOX^wx.RESIZE_BORDER
frame = MainFrame(
parent = None,
id = wx.ID_ANY,
title = 'Draw_me',
size = (-1, -1),
style = style
)
app.MainLoop()
app.Destroy()