-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcbmodel.py
executable file
·3892 lines (3454 loc) · 167 KB
/
cbmodel.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
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
"""
Description
-----------
cbmodel simulates building a Crossbeams model.
Author
------
Charles Sharman
License
-------
Distributed under the GNU GENERAL PUBLIC LICENSE Version 3. View
LICENSE for details.
Revision History
----------------
10/25/05: Began
10/25/05 - 11/19/09: Many undocumented modifications
version 0.1 changes to 5/31/10
- Added detail option
- Added some Blender-compatible keys
- Made edit a RMB event
- Allowed multiple selections (and deletions)
- Added more Blender-compatible keys
- Removed 'total'/'part' distinction
- Converted from tk to gtk
- Added manual.pdf and called this version 0.1
- Added MMB pan/orbit
version 0.2 changes to 6/1/10
- Made project_directory relative
- Allowed for missing icons
- Fixed resize
version 0.3 changes to 6/24/10
- Added border select
- Fixed no more valid ports code
- Added Options->Add Pieces
version 0.4 changes to 7/22/10
- Added grab, duplicate, rotate mode
- Updated to new (v0.4) save format
- Added Mass feature
- Spruced up menus
- Made rotate work around mouse origin
version 0.5 changes to 12/18/10
- Fixed overlapping ports error
- Changed redraw to a gtk-expose event
- Added ends_visible option
- Added render ability (detail == 2) (caused selection display change)
- Added status line
- Made 1-ended icons more viewable
- Added mirror mode
version 0.6 changes to 7/11/11
- fixed Ends Visible redisplay bug
- added registry with .sticksrc
- Made individual detail==1 pieces be a CallList
- Removed ends_visible option
- Moved color setting to module level
- Put more keyboard options in menu
- Diverted most key calls to menu accelerators
- Made installation more official with distutils
- Minor bug fixes
version 0.7 changes to 7/18/11
- Added configure option to gears and wheels
- Fixed gllist memory leak for detail1
- Improved .png output
- Fixed line draw errors after/in Detail - Line mode
version 0.8 changes to 9/12/11
- Added Window menu to size/color for modelling or instructions
- Added part_outline in base_pieces (for white on white)
- Switched from numarray to numpy
- removed join2s from pieces.
- Made registery update project_dir on save
- Added -p option to print_keys
- Added instruction mode
- Sped-up render with .raw format
- Fixed move straight1m2 port bug
- Made render mode an option to setup.py (use --render)
- Made share directory lookup automated according to setup.py
- Used mailcap for pdf viewer
- Fixed rotate/mirror center bug
version 0.9 changes to 5/5/12
- Changed len1 to 43.2
- Added -gear option
- Scaled grab/duplicate moves to 0.25*len1
- Added stiffen option to joinrots
- Added import option
- Redid base_pieces.write_move to avoid hanging nodes
- Changed file extension to .cbm, name to cbmodel, .sticksrc to .cbmodelrc
- Many instruction appearance changes
- Shuffled the menu items
version 0.91 changes to 5/21/13
- Made redraw the default (rather than draw) to avoid blurring on expose
- Changed len1 to 44.8 and subsequent dimensions
- Altered colors
- Added name aliases
- Fixed a bug in instruction mode submodel
- Fixed labelling of joinrot and wheels
- Added combination parameter to base_pieces to allow combinations of pieces
- Added indirect rendering option for off-screen PS_SCALE
- Added more piece color options
- Sped-up base_pieces.write_move
- Added pose option
- Looked at storing connectivity as the model goes, but it made the
code more complex in many places, and didn't speed up anything but
pose. remove_piece is clever and simply takes the inverted ends
removed. Skipped.
version 1.00 changes to 07/09/14
- Made ps_scale an option to allow faster instruction rendering
- Simplified instruction piece names
- Added piece center option
- Added undo/redo
- Added tooltips and removed menu descriptions from the manual
- Replaced the Select menu with the Edit menu
- Removed detail=0 from pieces
- Reintroduced self.redisplay for faster drawing on expose
- Added chirality to detail==1 joints to reflect actual pieces
- Added instruction helps
- Changed instruction color scheme
- Moved document images into doc_images
- Added non-NumPad run-time option
- Improved documentation
- Improved comments
- Migrated from double- to single-buffered opengl. Screen redraws
were so slow, the user needed visual feedback about the refresh
rate. Additionally, OSX had trouble with ReadPixels from the BACK
buffer.
- Added the Navigation with Numpad or Alphas options
- Added OSX compatibility
version 1.01 changes to 12/29/14
- Connection added to helps, front page
- Fixed load bug on models with no instructions
- Fixed TypeError in fuzzy_frame call for later PIL versions
version 1.02 changes to 3/10/15
- Changed warning for 10+
- Made some errors more clear with popups
version 1.03 changes to 01/30/16
- Added team builds
- Made screen updates conventional
- Bug fixes
Conventions
-----------
A part is a piece in a module. *
A piece is anything that can be added to a module. *
* Unfortunately, this wasn't followed too strictly
Helps
-----
- The python-gtkglext documentation is terrible. Use the c-code
documentation: /usr/share/doc/libgtkglext1-doc/html/index.html.
- check /usr/share/doc/python-gtkglext1/examples for examples.
- check /var/lib/python-support/python2.5/gtk-2.0/gtk/gtkgl for
specific gtkglext code.
- check /usr/share/doc/python-gtk2-doc/examples for pygtk examples.
- reportlab drawImage had bugs (required import PIL.Image instead of
import Image, required reportab.lib.utils.ImageReader, and im.fp).
Used drawInlineImage instead; shouldn't harm instructions.
To Do
-----
- Consider making the detail==1 pieces .raw also and remove GLE
- Consider transparency instead of grey for unplaced instruction pieces
"""
import sys
if '-h' in sys.argv or '--help' in sys.argv:
print """
Usage: cbmodel
Run the Crossbeams Modeller
Optional arguments
-h, --help display this help and exit
-i, --indirect force indirect (software-driven, not graphics-card driven)
drawing
-p, --printkeys print the key code as a key is pressed
-a, --alpha use alpha-numeric (non-numpad) keys for navigation
"""
sys.exit()
import os
import time
import math
import copy
import ConfigParser
from OpenGL.GL import *
from OpenGL.GLE import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import pygtk, gtk, gtk.gtkgl, pango, cairo, pangocairo
import numpy as np
import PIL.Image as Image
# Global Variables
try:
bundled_directory = sys._MEIPASS # Needed for OSX bundles
except:
bundled_directory = './'
share_directory = os.path.normpath(os.path.join(os.path.dirname(__file__), '../share/cbmodel/'))
if not os.path.exists(share_directory):
if os.path.exists(bundled_directory):
share_directory = bundled_directory
else:
share_directory = './'
doc_directory = os.path.normpath(os.path.join(share_directory, '../doc/cbmodel/'))
if not os.path.exists(doc_directory):
if os.path.exists(bundled_directory):
doc_directory = bundled_directory
else:
doc_directory = './'
os.chdir(bundled_directory)
if os.path.exists(os.path.join(share_directory, 'ogl_drawings/')):
max_detail = 2
else:
max_detail = 1
sys.path.append(share_directory)
# Now that the path is right, we can import the rest
import base_pieces
import pieces
import vector_math
import instructions
version = '1.03' # Change also in setup.py, cbmodel.tex
piece_aliases = [('anglep5xp5', 'angle1x1', '1x1'),
('angle1xp5', 'angle2x1', '2x1'),
('angle1x1', 'angle2x2', '2x2'),
('angle1p5x1p5', 'angle3x3', '3x3'),
('angle2x1', 'angle4x2', '4x2'),
('angle2x2', 'angle4x4', '4x4'),
('arc1x1', 'arc2x2', '2x2'),
('arc1p5x1p5', 'arc3x3', '3x3'),
('arc2x1', 'arc4x2', '4x2'),
('arc2x2', 'arc4x4', '4x4'),
('gear_axle1s', 'axle_g1', 'g1'),
('gear_axle2s', 'axle_g2', 'g2'),
('gear1', 'gear1', '1'),
('gear3s', 'gear3s', '3s'),
('gear3l', 'gear3l', '3l'),
('gear_bevel', 'gear_b', 'b'),
('gear_rack', 'rack', 'rack'),
('gear_rack_spur', 'gear_r', 'r'),
('join1', 'join1', '1'),
('join2', 'join2', '2'),
('join2flat', 'join2f', '2f'),
('join3', 'join3', '3'),
('join3flat', 'join3f', '3f'),
('join4', 'join4', '4'),
('join4flat', 'join4f', '4f'),
('join5', 'join5', '5'),
('join6', 'join6', '6'),
('joinrot11', 'rotate2s', '2s'),
('joinrot12', 'rotate3fd', '3fd'),
('joinrot21', 'rotate3s', '3s'),
('joinrot22', 'rotate4d', '4d'),
('joinrot2flat1', 'rotate3fs', '3fs'),
('joinrot2flat2', 'rotate4fd', '4fd'),
('joinrot3flat1', 'rotate4s', '4s'),
('joinrot3flat2', 'rotate5d', '5d'),
('joinrot4flat1', 'rotate5s', '5s'),
('joinrot4flat2', 'rotate6d', '6d'),
('pivotm1', 'couple2s', '2s'),
('pivot', 'couple22', '22'),
('pivot111', 'couple222', '222'),
('pivot00', 'couple11', '11'),
('pivot01', 'couple12', '12'),
('pivot0m1', 'couple1s', '1s'),
('pivotm1m1', 'coupless', 'ss'),
('pivot0', 'couple211', '211'),
('pivot0_', 'couple1', '1'),
('straightp5', 'straight1', '1'),
('straight1m1', 'axle_s', 's'),
('straight1', 'straight2', '2'),
('straight1p5', 'straight3', '3'),
('straight2', 'straight4', '4'),
('wheel_axle1s1w', 'axle_w1', 'w1'),
('wheel_axle2s2w', 'axle_w2', 'w2'),
('wheel_axle1s3w', 'axle_w3', 'w3'),
('wheelp5', 'wheel1', '1'),
('wheel1', 'wheel2', '2'),
('coupler', 'couple', 'couple'),
('stiffen', 'stiff', 'stiff')]
class MainScreen(object):
"""
Does everything for screen display and interaction with the module
"""
key_table = {'toggle_port()': 'p',
'toggle_port(-1)': '<Shift>p',
'flip_port()': 'f',
'flip_port(-1)': '<Shift>f',
'connect_part()': 'c',
'query_selection()': 'q',
'grab()': 'g',
'duplicate()': '<Shift>d',
'rotate()': 'r',
'mirror()': '<Control>m',
'border_select()': 'b',
'select_all()': 'a',
'delete_part()': 'x',
'delete_frame()': 'x',
'undo()': '<Control>z',
'redo()': '<Control>y',
'write_file()': 'F2',
'read_file()': 'F1',
'solid()': 'z',
'render()': 'F12',
'redraw_screen()': 'KP_Page_Up',
'orbitup()': 'KP_Up',
'panup()': 'KP_8',
'orbitdown()': 'KP_Down',
'pandown()': 'KP_2',
'orbitleft()': 'KP_Left',
'panleft()': 'KP_4',
'orbitright()': 'KP_Right',
'panright()': 'KP_6',
'rotateccw()': 'KP_Divide',
'rotatecw()': 'KP_Multiply',
'zoomin()': 'KP_Add',
'zoomin(0.25)': '<Primary>KP_Add',
'zoomout()': 'KP_Subtract',
'zoomout(0.25)': '<Primary>KP_Subtract',
'viewstandard("top")': 'KP_Home',
'viewstandard("bottom")': 'KP_7',
'viewstandard("front")': 'KP_End',
'viewstandard("back")': 'KP_1',
'viewstandard("right")': 'KP_Page_Down',
'viewstandard("left")': 'KP_3',
'toggle_frame()': 'Right',
'toggle_frame(None, -1)': 'Left',
'quit()': '<Control>q'}
numpad = {'redraw_screen()': 'KP_Page_Up',
'orbitup()': 'KP_Up',
'panup()': 'KP_8',
'orbitdown()': 'KP_Down',
'pandown()': 'KP_2',
'orbitleft()': 'KP_Left',
'panleft()': 'KP_4',
'orbitright()': 'KP_Right',
'panright()': 'KP_6',
'rotateccw()': 'KP_Divide',
'rotatecw()': 'KP_Multiply',
'zoomin()': 'KP_Add',
'zoomin(0.25)': '<Primary>KP_Add',
'zoomout()': 'KP_Subtract',
'zoomout(0.25)': '<Primary>KP_Subtract',
'viewstandard("top")': 'KP_Home',
'viewstandard("bottom")': 'KP_7',
'viewstandard("front")': 'KP_End',
'viewstandard("back")': 'KP_1',
'viewstandard("right")': 'KP_Page_Down',
'viewstandard("left")': 'KP_3'}
nonumpad = {'redraw_screen()': 'o',
'orbitup()': 'i',
'panup()': '<Shift>i',
'orbitdown()': 'comma',
'pandown()': '<Shift>less',
'orbitleft()': 'j',
'panleft()': '<Shift>j',
'orbitright()': 'l',
'panright()': '<Shift>l',
'rotateccw()': '8',
'rotatecw()': '9',
'zoomin()': '<Shift>plus',
'zoomin(0.25)': '<Shift><Control>plus',
'zoomout()': 'minus',
'zoomout(0.25)': '<Control>minus',
'viewstandard("top")': 'u',
'viewstandard("bottom")': '<Shift>u',
'viewstandard("front")': 'm',
'viewstandard("back")': '<Shift>m',
'viewstandard("right")': 'period',
'viewstandard("left")': '<Shift>greater'}
# Colors
#SCREEN_COLOR = ((0.0, 0.0, 0.0), (1.0, 0.25, 0.25)) # BG, FG
#PRINT_COLOR = ((1.0, 1.0, 1.0), (0.75, 0.0, 0.0)) # BG, FG
#SCREEN_COLOR = ((0.0, 0.0, 0.0), (0.871, 0.504, 0.055)) # BG, FG
#PRINT_COLOR = ((1.0, 1.0, 1.0), (0.871, 0.504, 0.055)) # BG, FG
#SCREEN_COLOR = ((0.0, 0.0, 0.0), (0.875, 0.549, 0.098)) # BG, FG
#PRINT_COLOR = ((1.0, 1.0, 1.0), (0.875, 0.549, 0.098)) # BG, FG
SCREEN_COLOR = ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0), (1.0, 0.8, 0.0)) # BG, FG, Highlights
#PRINT_COVER_COLOR = ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0), (1.0, 0.8, 0.0)) # BG, FG, Highlights
PRINT_COVER_COLOR = ((1.0, 1.0, 1.0), (0.0, 0.0, 0.0), (1.0, 0.8, 0.0)) # BG, FG, Highlights
#PRINT_BODY_COLOR = ((0.828, 0.879, 0.938), (0.875, 0.549, 0.098)) # BG, FG
PRINT_BODY_COLOR = ((1.0, 1.0, 1.0), (0.0, 0.0, 0.0), (1.0, 0.8, 0.0)) # BG, FG, Highlights
PIECE_COLORS = {'total': (1.0, 1.0, 1.0),
'straight': (1.0, 1.0, 1.0),
'angle': (1.0, 1.0, 1.0),
'arc': (1.0, 1.0, 1.0),
'part': (0.0, 1.0, 0.0),
'edit': (0.45, 0.675, 0.9),
'outline': (0.0, 0.0, 0.0),
'newpart': (0.45, 0.675, 0.9),
'futurepart': (0.33, 0.33, 0.33),
'tire': (0.33, 0.33, 0.33),
'wheel': (1.0, 1.0, 1.0),
'clip': (1.0, 1.0, 1.0),
'gear': (1.0, 1.0, 1.0),
'shaft': (0.5, 0.5, 0.5),
'region0': (1.0, 0.5, 0.5),
'region1': (0.5, 1.0, 0.5),
'region2': (0.5, 0.5, 1.0),
'region3': (0.8, 0.8, 0.4),
'region4': (0.8, 0.4, 0.8),
'region5': (0.4, 0.8, 0.8)}
# Sizes/Scales
SCREEN_SCALE = 100
PS_SCALE = 3.0 # Print to Screen Scale DPI = PS_SCALE*SCREEN_SCALE
IMAGE_SCALE = 300/(PS_SCALE*SCREEN_SCALE) # Image to Print Scale
PAPER_SIZE = (8.5, 11.0) # inches
#PAPER_SIZE = (9.06, 11.0) # scaled for 8.5x14 booklet printouts
MARGIN_SIZE = 0.125 # inches
SEP_SIZE = 0.05 # Internal separation between frames
FRAME_MARGIN_SIZE = 0.075 # inches
COVER_SIZE = (PAPER_SIZE[0]-2*MARGIN_SIZE, PAPER_SIZE[1]-2*MARGIN_SIZE)
FRAME_SIZE = ((PAPER_SIZE[0]-2*MARGIN_SIZE-SEP_SIZE)/2, (PAPER_SIZE[1]-2*MARGIN_SIZE-SEP_SIZE)/2)
# Cursors
REGULAR_CURSOR = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
WAIT_CURSOR = gtk.gdk.Cursor(gtk.gdk.WATCH)
def __init__(self, print_keys = 0, rendering = 'direct', use_numpad = 1):
global max_detail
self.print_keys = print_keys
self.rendering = rendering
if not use_numpad:
for key in self.nonumpad:
self.key_table[key] = self.nonumpad[key]
pieces.init(share_directory)
self.background_color = self.SCREEN_COLOR[0]
self.annotate_color = self.SCREEN_COLOR[1]
self.highlight_color = self.SCREEN_COLOR[2]
base_pieces.colors = self.PIECE_COLORS
pieces.colors = self.PIECE_COLORS
self.last_time = 0
self.mode = 'normal'
self.redisplay = 'redraw'
self.current_filename = ''
self.project_directory = os.path.join(os.getcwd())
self.annotate = instructions.Annotate(self, share_directory)
self.morbit = math.pi/12.0
self.SCR = (900, 900)
self.start_pixperunit = 10.0
#self.pixperunit = self.start_pixperunit
self.set_pixperunit(self.start_pixperunit)
# self.mpan initialized in opengl_reshape
# Front view start
self.start_vcenter = np.array([0.0, 0.0, 0.0])
self.start_vout = np.array([0.0, 0.0, 1.0])
self.start_vup = np.array([0.0, 1.0, 0.0])
self.lowerleft = (20.0, 20.0)
# Do aliases
self.piece_list = filter(lambda x: type(eval('pieces.' + x)) == type(pieces.stick) and issubclass(eval('pieces.' + x), pieces.stick), dir(pieces))
self.piece_list.remove('stick')
self.piece_list.remove('axle')
self.name2alias = {}
self.alias2name = {}
self.name2simple = {}
for name in self.piece_list:
self.name2alias[name] = name
self.alias2name[name] = name
self.name2simple[name] = name
for name, alias, simple in piece_aliases:
self.name2alias[name] = alias
self.alias2name[alias] = name
self.name2simple[name] = simple
pieces.aliases = self.name2alias
local_alias = map(lambda x: (self.name2alias[x], x), self.piece_list)
local_alias.sort()
self.piece_list = map(lambda x: x[1], local_alias)
self.total = base_pieces.module()
self.last_joint = 'join2'
self.last_stick = 'straight1'
self.current_piece = self.piece_list.index(self.last_stick)
self.name = self.validate_part(self.piece_list[self.current_piece])
self.creationmode = 'modelling'
self.image_type = 'screen'
self.omit_logo = 0
self.ps_scale = 1 # start in draft mode
self.draw_center = 0 # don't show a box at piece centers
# Main
config_name = self.config_name()
if config_name:
config = ConfigParser.RawConfigParser()
config.read(self.config_name())
if config.has_section('Keys'):
options = dict(config.items('Keys'))
for key in options:
self.key_table[key] = options[key]
if config.has_option('State', 'project_directory'):
try_dir = config.get('State', 'project_directory')
if os.path.exists(try_dir):
self.project_directory = try_dir
else:
print 'Warning: Couldn\'t find directory ' + try_dir
self.vcenter = self.start_vcenter
self.vout = self.start_vout
self.vup = self.start_vup
gtk.window_set_default_icon_from_file(os.path.join(share_directory, 'symbol.png'))
#print gtk.window_get_default_icon_list()
self.win = gtk.Window()
#self.win.set_geometry_hints(None, min_width = 200, min_height = 200)
self.win.set_default_size(850, 600)
self.update_title()
#if not sys.platform.startswith('win'):
# self.win.set_resize_mode(gtk.RESIZE_IMMEDIATE)
self.win.set_reallocate_redraws(True)
self.win.connect('destroy', self.quit)
self.win.connect('key_press_event', self.opengl_keypress) # Needed for a few stubborn keycodes that aren't exactly recognized correctly
self.win.show()
# Vertical Container
vbox1 = gtk.VBox()
self.win.add(vbox1)
vbox1.show()
# Menu Space
accel_group = gtk.AccelGroup()
self.win.add_accel_group(accel_group)
self.modelling_only_items = []
self.instructions_only_items = []
self.group_only_items = []
menubar = gtk.MenuBar()
vbox1.pack_start(menubar, False)
menubar.show()
file_container = gtk.Menu()
file_new = gtk.ImageMenuItem(gtk.STOCK_NEW)
file_new.set_tooltip_text('Erases the current model and starts a new model')
file_new.connect('activate', self.clear_all)
file_container.append(file_new)
file_open = gtk.ImageMenuItem(gtk.STOCK_OPEN)
file_open.set_tooltip_text('Erases the current model and opens a previously saved model')
file_open.connect('activate', self.read_file)
keyval, keymod = self.key_lookup('read_file()')
file_open.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
file_container.append(file_open)
file_save = gtk.ImageMenuItem(gtk.STOCK_SAVE)
file_save.set_tooltip_text('Save the current model')
file_save.connect('activate', lambda x: self.write_file(None, False))
keyval, keymod = self.key_lookup('write_file()')
file_save.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
file_container.append(file_save)
file_saveas = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS)
file_saveas.set_tooltip_text('Save the current model with a different name')
file_saveas.connect('activate', self.write_file)
file_container.append(file_saveas)
file_container.append(gtk.SeparatorMenuItem())
file_savepng = gtk.ImageMenuItem('Save Snapshot')
file_savepng.set_tooltip_text('Save a snapshot of the editing window in .png format.')
file_savepng.set_image(gtk.image_new_from_stock(gtk.STOCK_SAVE, gtk.ICON_SIZE_MENU))
file_savepng.connect('activate', self.write_png)
file_container.append(file_savepng)
file_savecsv = gtk.ImageMenuItem('Save Inventory')
file_savecsv.set_tooltip_text('Save a list of pieces and quantities as a .csv file')
file_savecsv.set_image(gtk.image_new_from_stock(gtk.STOCK_SAVE, gtk.ICON_SIZE_MENU))
file_savecsv.connect('activate', self.write_csv)
file_container.append(file_savecsv)
file_container.append(gtk.SeparatorMenuItem())
file_merge = gtk.ImageMenuItem('Merge')
file_merge.set_tooltip_text('Merge a model from another file with the current model')
file_merge.set_image(gtk.image_new_from_stock(gtk.STOCK_INDENT, gtk.ICON_SIZE_MENU))
file_merge.connect('activate', self.merge_file)
self.modelling_only_items.append(file_merge)
file_container.append(file_merge)
file_container.append(gtk.SeparatorMenuItem())
file_quit = gtk.ImageMenuItem(gtk.STOCK_QUIT)
file_quit.set_tooltip_text('Quit the program')
file_quit.connect('activate', self.quit)
keyval, keymod = self.key_lookup('quit()')
file_quit.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
file_container.append(file_quit)
file_menu = gtk.MenuItem('_File')
file_menu.set_submenu(file_container)
file_menu.show()
menubar.append(file_menu)
edit_container = gtk.Menu()
edit_undo = gtk.ImageMenuItem(gtk.STOCK_UNDO)
edit_undo.set_tooltip_text('Undo the last model operation')
edit_undo.connect('activate', self.undo)
keyval, keymod = self.key_lookup('undo()')
edit_undo.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
self.modelling_only_items.append(edit_undo)
edit_container.append(edit_undo)
edit_redo = gtk.ImageMenuItem(gtk.STOCK_REDO)
edit_redo.set_tooltip_text('Redo the last model operation')
edit_redo.connect('activate', self.redo)
keyval, keymod = self.key_lookup('redo()')
edit_redo.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
self.modelling_only_items.append(edit_redo)
edit_container.append(edit_redo)
edit_container.append(gtk.SeparatorMenuItem())
edit_select_all = gtk.MenuItem('Select/Deselect All')
edit_select_all.set_tooltip_text('Select all pieces when none are selected or deselect all pieces when some are selected')
edit_select_all.connect('activate', self.select_all)
keyval, keymod = self.key_lookup('select_all()')
edit_select_all.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
edit_container.append(edit_select_all)
edit_select_border = gtk.MenuItem('Border Select')
edit_select_border.set_tooltip_text('Select all pieces within a rectangular box')
edit_select_border.connect('activate', self.border_select)
keyval, keymod = self.key_lookup('border_select()')
edit_select_border.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
edit_container.append(edit_select_border)
edit_select_type = gtk.MenuItem('Select by Type')
edit_select_type.set_tooltip_text('Select all pieces of the piece type currently being placed')
edit_select_type.connect('activate', self.type_select)
self.modelling_only_items.append(edit_select_type)
edit_container.append(edit_select_type)
edit_select_set_fixed = gtk.MenuItem('Selected to Fixed')
edit_select_set_fixed.set_tooltip_text('Make the selected region the fixed region')
edit_select_set_fixed.connect('activate', self.set_fixed_region)
self.instructions_only_items.append(edit_select_set_fixed)
edit_select_set_fixed.set_sensitive(False)
edit_container.append(edit_select_set_fixed)
edit_select_hide_selected = gtk.MenuItem('Hide Selected')
edit_select_hide_selected.set_tooltip_text('Hide the selected parts')
edit_select_hide_selected.connect('activate', self.hide_selected)
self.instructions_only_items.append(edit_select_hide_selected)
edit_select_hide_selected.set_sensitive(False)
edit_container.append(edit_select_hide_selected)
edit_select_unhide = gtk.MenuItem('Unhide')
edit_select_unhide.set_tooltip_text('Unhide all hidden parts')
edit_select_unhide.connect('activate', self.unhide)
self.instructions_only_items.append(edit_select_unhide)
edit_select_unhide.set_sensitive(False)
edit_container.append(edit_select_unhide)
edit_container.append(gtk.SeparatorMenuItem())
edit_query = gtk.MenuItem('Query')
edit_query.set_tooltip_text('Pop-up a piece query window on the currently selected piece')
edit_query.connect('activate', self.query_selection)
keyval, keymod = self.key_lookup('query_selection()')
edit_query.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
self.modelling_only_items.append(edit_query)
edit_container.append(edit_query)
edit_grab = gtk.MenuItem('Grab')
edit_grab.set_tooltip_text('Move the selected pieces')
edit_grab.connect('activate', self.grab)
keyval, keymod = self.key_lookup('grab()')
edit_grab.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
self.modelling_only_items.append(edit_grab)
edit_container.append(edit_grab)
edit_duplicate = gtk.MenuItem('Duplicate')
edit_duplicate.set_tooltip_text('Duplicate the selected pieces')
edit_duplicate.connect('activate', self.duplicate)
keyval, keymod = self.key_lookup('duplicate()')
edit_duplicate.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
self.modelling_only_items.append(edit_duplicate)
edit_container.append(edit_duplicate)
edit_rotate = gtk.MenuItem('Rotate')
edit_rotate.set_tooltip_text('Rotate the selected pieces')
edit_rotate.connect('activate', self.rotate)
keyval, keymod = self.key_lookup('rotate()')
edit_rotate.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
#self.modelling_only_items.append(edit_rotate)
edit_container.append(edit_rotate)
edit_mirror = gtk.MenuItem('Mirror')
edit_mirror.set_tooltip_text('Mirror the selected pieces')
edit_mirror.connect('activate', self.mirror)
keyval, keymod = self.key_lookup('mirror()')
edit_mirror.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
self.modelling_only_items.append(edit_mirror)
edit_container.append(edit_mirror)
edit_delete = gtk.MenuItem('Delete')
edit_delete.set_tooltip_text('Delete the selected pieces')
edit_delete.connect('activate', self.delete_part)
keyval, keymod = self.key_lookup('delete_part()')
edit_delete.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
self.modelling_only_items.append(edit_delete)
edit_container.append(edit_delete)
edit_fix = gtk.MenuItem('Fix')
edit_fix.set_tooltip_text('Attempts to fix a corrupt model')
edit_fix.connect('activate', self.fix_model)
self.modelling_only_items.append(edit_fix)
edit_container.append(edit_fix)
edit_menu = gtk.MenuItem('_Edit')
edit_menu.set_submenu(edit_container)
edit_menu.show()
menubar.append(edit_menu)
view_container = gtk.Menu()
view_inventory = gtk.MenuItem('Inventory')
view_inventory.set_tooltip_text('Lists the pieces used in the model')
view_inventory.connect('activate', self.view_inventory)
view_container.append(view_inventory)
view_dimensions = gtk.MenuItem('Dimensions')
view_dimensions.set_tooltip_text('Bounds the model in a 3D box and reports the box distances')
view_dimensions.connect('activate', self.view_dimensions)
view_container.append(view_dimensions)
view_mass = gtk.MenuItem('Mass')
view_mass.set_tooltip_text('Reports the model\'s mass')
view_mass.connect('activate', self.view_mass)
view_container.append(view_mass)
view_price = gtk.MenuItem('Price')
view_price.set_tooltip_text('Reports the model\'s price')
view_price.connect('activate', self.view_price)
view_container.append(view_price)
view_page_count = gtk.MenuItem('Pages')
view_page_count.set_tooltip_text('Reports the number of instruction set pages including front and back cover')
view_page_count.connect('activate', self.view_page_count)
view_container.append(view_page_count)
view_container.append(gtk.SeparatorMenuItem())
view_side = gtk.MenuItem('Side')
view_side_container = gtk.Menu()
view_side.set_submenu(view_side_container)
view_container.append(view_side)
view_front = gtk.MenuItem('Front')
view_front.set_tooltip_text('Views the front of the model')
view_front.connect('activate', self.viewstandard, 'front')
keyval, keymod = self.key_lookup('viewstandard("front")')
view_front.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_side_container.append(view_front)
view_top = gtk.MenuItem('Top')
view_top.set_tooltip_text('Views the top of the model')
view_top.connect('activate', self.viewstandard, 'top')
keyval, keymod = self.key_lookup('viewstandard("top")')
view_top.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_side_container.append(view_top)
view_right = gtk.MenuItem('Right')
view_right.set_tooltip_text('Views the right side of the model')
view_right.connect('activate', self.viewstandard, 'right')
keyval, keymod = self.key_lookup('viewstandard("right")')
view_right.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_side_container.append(view_right)
view_back = gtk.MenuItem('Back')
view_back.set_tooltip_text('Views the back of the model')
view_back.connect('activate', self.viewstandard, 'back')
keyval, keymod = self.key_lookup('viewstandard("back")')
view_back.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_side_container.append(view_back)
view_bottom = gtk.MenuItem('Bottom')
view_bottom.set_tooltip_text('Views the bottom of the model')
view_bottom.connect('activate', self.viewstandard, 'bottom')
keyval, keymod = self.key_lookup('viewstandard("bottom")')
view_bottom.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_side_container.append(view_bottom)
view_left = gtk.MenuItem('Left')
view_left.set_tooltip_text('Views the left side of the model')
view_left.connect('activate', self.viewstandard, 'left')
keyval, keymod = self.key_lookup('viewstandard("left")')
view_left.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_side_container.append(view_left)
view_orbit = gtk.MenuItem('Orbit')
view_orbit_container = gtk.Menu()
view_orbit.set_submenu(view_orbit_container)
view_container.append(view_orbit)
view_orbitup = gtk.MenuItem('Up')
view_orbitup.set_tooltip_text('Orbits the observer 15 degrees up')
view_orbitup.connect('activate', self.orbitup)
keyval, keymod = self.key_lookup('orbitup()')
view_orbitup.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_orbit_container.append(view_orbitup)
view_orbitdown = gtk.MenuItem('Down')
view_orbitdown.set_tooltip_text('Orbits the observer 15 degrees down')
view_orbitdown.connect('activate', self.orbitdown)
keyval, keymod = self.key_lookup('orbitdown()')
view_orbitdown.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_orbit_container.append(view_orbitdown)
view_orbitleft = gtk.MenuItem('Left')
view_orbitleft.set_tooltip_text('Orbits the observer 15 degrees to the left')
view_orbitleft.connect('activate', self.orbitleft)
keyval, keymod = self.key_lookup('orbitleft()')
view_orbitleft.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_orbit_container.append(view_orbitleft)
view_orbitright = gtk.MenuItem('Right')
view_orbitright.set_tooltip_text('Orbits the observer 15 degrees to the right')
view_orbitright.connect('activate', self.orbitright)
keyval, keymod = self.key_lookup('orbitright()')
view_orbitright.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_orbit_container.append(view_orbitright)
view_orbitccw = gtk.MenuItem('CCW')
view_orbitccw.set_tooltip_text('Orbits the observer 15 degrees counter-clockwise')
view_orbitccw.connect('activate', self.rotateccw)
keyval, keymod = self.key_lookup('rotateccw()')
view_orbitccw.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_orbit_container.append(view_orbitccw)
view_orbitcw = gtk.MenuItem('CW')
view_orbitcw.set_tooltip_text('Orbits the observer 15 degrees clockwise')
view_orbitcw.connect('activate', self.rotatecw)
keyval, keymod = self.key_lookup('rotatecw()')
view_orbitcw.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_orbit_container.append(view_orbitcw)
view_pan = gtk.MenuItem('Pan')
view_pan_container = gtk.Menu()
view_pan.set_submenu(view_pan_container)
view_container.append(view_pan)
view_panup = gtk.MenuItem('Up')
view_panup.set_tooltip_text('Pans the observer up')
view_panup.connect('activate', self.panup)
keyval, keymod = self.key_lookup('panup()')
view_panup.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_pan_container.append(view_panup)
view_pandown = gtk.MenuItem('Down')
view_pandown.set_tooltip_text('Pans the observer down')
view_pandown.connect('activate', self.pandown)
keyval, keymod = self.key_lookup('pandown()')
view_pandown.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_pan_container.append(view_pandown)
view_panleft = gtk.MenuItem('Left')
view_panleft.set_tooltip_text('Pans the observer left')
view_panleft.connect('activate', self.panleft)
keyval, keymod = self.key_lookup('panleft()')
view_panleft.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_pan_container.append(view_panleft)
view_panright = gtk.MenuItem('Right')
view_panright.set_tooltip_text('Pans the observer right')
view_panright.connect('activate', self.panright)
keyval, keymod = self.key_lookup('panright()')
view_panright.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_pan_container.append(view_panright)
view_zoom = gtk.MenuItem('Zoom')
view_zoom_container = gtk.Menu()
view_zoom.set_submenu(view_zoom_container)
view_container.append(view_zoom)
view_zoomin = gtk.MenuItem('In')
view_zoomin.set_tooltip_text('Zooms in toward the model')
view_zoomin.connect('activate', self.zoomin)
keyval, keymod = self.key_lookup('zoomin()')
view_zoomin.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_zoom_container.append(view_zoomin)
view_zoomout = gtk.MenuItem('Out')
view_zoomout.set_tooltip_text('Zooms away from the model')
view_zoomout.connect('activate', self.zoomout)
keyval, keymod = self.key_lookup('zoomout()')
view_zoomout.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
view_zoom_container.append(view_zoomout)
view_menu = gtk.MenuItem('_View')
view_menu.set_submenu(view_container)
view_menu.show()
menubar.append(view_menu)
part_container = gtk.Menu()
self.part_add_pieces = gtk.CheckMenuItem('Add Pieces')
self.part_add_pieces.set_tooltip_text('Automatically places the next piece in green')
self.part_add_pieces.set_active(True)
self.modelling_only_items.append(self.part_add_pieces)
part_container.append(self.part_add_pieces)
part_container.append(gtk.SeparatorMenuItem())
part_next_port = gtk.MenuItem('Next Port')
part_next_port.set_tooltip_text('Connect the next piece port to the model at the current model port')
part_next_port.connect('activate', self.toggle_port)
keyval, keymod = self.key_lookup('toggle_port()')
part_next_port.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
part_container.append(part_next_port)
part_previous_port = gtk.MenuItem('Previous Port')
part_previous_port.set_tooltip_text('Connect the previous piece port to the model at the current model port')
part_previous_port.connect('activate', self.toggle_port, -1)
keyval, keymod = self.key_lookup('toggle_port(-1)')
part_previous_port.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
part_container.append(part_previous_port)
part_next_flip = gtk.MenuItem('Flip 90')
part_next_flip.set_tooltip_text('Rotate the piece 90 degrees about the current model port')
part_next_flip.connect('activate', self.flip_port)
keyval, keymod = self.key_lookup('flip_port()')
part_next_flip.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
part_container.append(part_next_flip)
part_previous_flip = gtk.MenuItem('Flip -90')
part_previous_flip.set_tooltip_text('Rotate the piece -90 degrees about the current model port')
part_previous_flip.connect('activate', self.flip_port, -1)
keyval, keymod = self.key_lookup('flip_port(-1)')
part_previous_flip.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
part_container.append(part_previous_flip)
part_connect = gtk.MenuItem('Connect')
part_connect.set_tooltip_text('Connect the piece to the model')
part_connect.connect('activate', self.connect_part)
keyval, keymod = self.key_lookup('connect_part()')
part_connect.add_accelerator('activate', accel_group, keyval, keymod, gtk.ACCEL_VISIBLE)
part_container.append(part_connect)
self.part_menu = gtk.MenuItem('_Piece')
self.part_menu.set_submenu(part_container)
self.part_menu.show()
menubar.append(self.part_menu)
instructions_container = gtk.Menu()
self.instructions_show_mirror = gtk.CheckMenuItem('Show Mirror')
self.instructions_show_mirror.set_tooltip_text('Show the mirror icon, showing new pieces are mirrored from old ones')
self.instructions_show_mirror.set_active(False)
self.instructions_show_mirror.connect('activate', self.show_mirror)
instructions_container.append(self.instructions_show_mirror)
self.instructions_show_magnify = gtk.CheckMenuItem('Show Cross Hair')
self.instructions_show_magnify.set_tooltip_text('Show the cross hair icon, which shows the piece the next frame will be centered on')
self.instructions_show_magnify.set_active(False)
self.instructions_show_magnify.connect('activate', self.show_magnify)
instructions_container.append(self.instructions_show_magnify)
instructions_container.append(gtk.SeparatorMenuItem())
instructions_new = gtk.ImageMenuItem(gtk.STOCK_NEW)
instructions_new.set_tooltip_text('Erase all instructions and start new instructions')
instructions_new.connect('activate', self.clear_instructions)
instructions_container.append(instructions_new)
instructions_copy2group = gtk.MenuItem('Copy to Group')
instructions_copy2group.set_tooltip_text('Erase all group instructions and copy individual instructions to group instructions.')
instructions_copy2group.connect('activate', self.copy2group)
self.group_only_items.append(instructions_copy2group)
instructions_container.append(instructions_copy2group)
self.instructions_hold_pose = gtk.CheckMenuItem('Hold Pose')
self.instructions_hold_pose.set_tooltip_text('Hold the cover pose through all instruction steps')
self.instructions_hold_pose.set_active(False)
self.instructions_hold_pose.connect('toggled', self.hold_pose)
instructions_container.append(self.instructions_hold_pose)