-
Notifications
You must be signed in to change notification settings - Fork 0
/
classEditor.py
executable file
·9243 lines (8429 loc) · 286 KB
/
classEditor.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/env python
# -*- coding: utf-8 -*-
# Copyright 2007 Philippe LAWRENCE
#
# This file is part of pyBar.
# pyBar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# pyBar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyBar; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
import sys
import pango
import xml.etree.ElementTree as ET
from function import *
import gobject
from time import sleep
import Const
import classDialog
import classProfilManager
import classPrefs
#import classRdm
import copy
import file_tools
import function
def Rotation(a, x, y):
"""x, y étant les coordonnées d'un point dans un repère 1, retourne les coordonnées du point dans le repère 2 obtenu par rotation d'angle a"""
x1 = x*math.cos(a) + y*math.sin(a)
y1 = -x*math.sin(a) + y*math.cos(a)
return x1, y1
class MyError(Exception):
"""Surcharge de la classe d'erreur"""
#def __init__(self, value):
# self.value = value
def __str__(self):
return repr(self.value)
class CMenuNode1(object):
"""Classe pour les menus contextuels d'un noeud d'arc"""
ui = '''<ui>
<popup>
<!-- <menuitem action="0" />
<menuitem action="1" />
<separator/> -->
<menuitem action="Rel" name="rel"/>
<menuitem action="Clear" name="clear"/>
</popup>
</ui>'''
def __init__(self, Main, node, event):
ui =CMenuNode1.ui
arcs = Main.data_editor.get_arcs()
uimanager = gtk.UIManager()
uimanager.add_ui_from_string(ui)
accelgroup = uimanager.get_accel_group()
Main.w2.add_accel_group(accelgroup)
actiongroup = gtk.ActionGroup('settings')
if node.arc in arcs:
id = uimanager.new_merge_id()
uimanager.add_ui(id, '/popup', '0', '0', gtk.UI_MANAGER_MENUITEM, False)
id = uimanager.new_merge_id()
uimanager.add_ui(id, '/popup', '1', '1', gtk.UI_MANAGER_MENUITEM, False)
id = uimanager.new_merge_id()
uimanager.add_ui(id, '/popup/clear', 'separator',
None, gtk.UI_MANAGER_SEPARATOR, False)
actiongroup.add_radio_actions([
('0', None, 'Position relative à la corde', None, None, 0),
('1', None, 'Position relative à l\'arc', None, None, 1)
], node.pos_on_curve, node.update_type_coor, (Main, node))
uimanager.insert_action_group(actiongroup)
actiongroup.add_toggle_actions([
('Rel', None, 'Relaxer', None, None, node._update_relax, node.rel)
], Main)
actiongroup.add_actions([
('Clear', None, 'Supprimer', None, None, node.on_delete)
], (Main, node.id))
popup_menu = uimanager.get_widget('/popup')
popup_menu.popup(None, None, None, event.button, event.time)
class CMenuNode2(object):
"""Classe pour les menus contextuels d'un noeud simple"""
ui = '''<ui>
<popup>
<menuitem action="Clear" />
</popup>
</ui>'''
def __init__(self, Main, node, event):
ui =CMenuNode2.ui
uimanager = gtk.UIManager()
uimanager.add_ui_from_string(ui)
accelgroup = uimanager.get_accel_group()
Main.w2.add_accel_group(accelgroup)
actiongroup = gtk.ActionGroup('settings')
actiongroup.add_actions([
('Clear', None, 'Supprimer', None, None, node.on_delete)
], (Main, node.id))
uimanager.insert_action_group(actiongroup)
popup_menu = uimanager.get_widget('/popup')
popup_menu.popup(None, None, None, event.button, event.time)
class CMenuS(object):
"""Classe pour les menus contextuels d'une section"""
ui = '''<ui>
<popup>
<menuitem action="Name"/>
<menuitem action="H"/>
<menuitem action="V"/>
<menuitem action="Clear" />
</popup>
</ui>'''
def __init__(self, Main, S, event):
ui =CMenuS.ui
uimanager = gtk.UIManager()
uimanager.add_ui_from_string(ui)
accelgroup = uimanager.get_accel_group()
Main.w2.add_accel_group(accelgroup)
actiongroup = gtk.ActionGroup('settings')
try:
S.profil
tag0 = 1
except AttributeError:
tag0 = 0
try:
S.h
tag1 = 1
except AttributeError:
tag1 = 0
try:
S.v
tag2 = 1
except AttributeError:
tag2 = 0
actiongroup.add_toggle_actions([
('Name', None, 'Définir le nom', None, None, S.on_add_name, tag0),
('H', None, 'Définir la hauteur', None, None, S.on_add_h, tag1),
('V', None, 'Définir la distance v', None, None, S.on_add_v, tag2)
], Main)
actiongroup.add_actions([
('Clear', None, 'Supprimer', None, None, S.on_delete)
], (Main, S.id))
uimanager.insert_action_group(actiongroup)
popup_menu = uimanager.get_widget('/popup')
popup_menu.popup(None, None, None, event.button, event.time)
class CMenuMat(object):
"""Classe pour les menus contextuels d'un matériau"""
ui = '''<ui>
<popup>
<menuitem action="Name"/>
<menuitem action="MV"/>
<menuitem action="Alpha"/>
<menuitem action="Clear" />
</popup>
</ui>'''
def __init__(self, Main, Mat, event):
ui =CMenuMat.ui
uimanager = gtk.UIManager()
uimanager.add_ui_from_string(ui)
accelgroup = uimanager.get_accel_group()
Main.w2.add_accel_group(accelgroup)
actiongroup = gtk.ActionGroup('settings')
try:
Mat.profil
tag0 = 1
except AttributeError:
tag0 = 0
try:
Mat.m
tag1 = 1
except AttributeError:
tag1 = 0
try:
Mat.a
tag2 = 1
except AttributeError:
tag2 = 0
actiongroup.add_toggle_actions([
('Name', None, 'Définir le nom', None, None, Mat.on_add_name, tag0),
('MV', None, 'Définir la masse volumique', None, None, Mat.on_add_mv, tag1),
('Alpha', None, 'Définir le coefficient de dilatation', None, None, Mat.on_add_alpha, tag2)
], Main)
actiongroup.add_actions([
('Clear', None, 'Supprimer', None, None, Mat.on_delete)
], (Main, Mat.id))
uimanager.insert_action_group(actiongroup)
popup_menu = uimanager.get_widget('/popup')
popup_menu.popup(None, None, None, event.button, event.time)
class CMenuEmpty(object):
"""Classe pour les menus contextuels en dehors d'un item"""
ui = '''<ui>
<popup>
<!-- <menuitem action="Copy" />
<menuitem action="Paste" /> -->
<menuitem action="Clear" />
</popup>
</ui>'''
def __init__(self, Main, event):
ui =CMenuEmpty.ui
uimanager = gtk.UIManager()
uimanager.add_ui_from_string(ui)
accelgroup = uimanager.get_accel_group()
Main.w2.add_accel_group(accelgroup)
actiongroup = gtk.ActionGroup('settings')
n_page = Main.book.get_current_page()
is_sensitive = False
if n_page == 1:
nodes = Main.data_editor.nodes
for node in nodes:
checkbutton = node.hbox.get_children()[1]
if checkbutton.get_active():
is_sensitive = True
break
f = Main.remove_nodes
elif n_page == 2:
nodes = Main.data_editor.barres
for node in nodes:
checkbutton = node.hbox.get_children()[1]
if checkbutton.get_active():
is_sensitive = True
break
f = Main.remove_barres
elif n_page == 4:
nodes = Main.data_editor.sections
for node in nodes:
checkbutton = node.hbox.get_children()[0]
if checkbutton.get_active():
is_sensitive = True
break
f = Main.remove_sections
elif n_page == 5:
nodes = Main.data_editor.materials
for node in nodes:
checkbutton = node.hbox.get_children()[0]
if checkbutton.get_active():
is_sensitive = True
break
f = Main.remove_materials
elif n_page == 6:
case_page = Main.charbook.get_current_page()
page = Main.charbook.get_nth_page(case_page)
vbox = page.get_children()[0].get_children()[0]
childs = vbox.get_children()
case = Main.data_editor.cases[case_page]
for i, hbox in enumerate(childs):
char = case.chars[i]
if char.get_is_selected():
is_sensitive = True
break
f = Main.remove_chars
action = gtk.Action("Clear", "Supprimer", None, None)
actiongroup.add_action(action)
action.set_sensitive(is_sensitive)
action.connect('activate', f)
uimanager.insert_action_group(actiongroup)
popup_menu = uimanager.get_widget('/popup')
popup_menu.popup(None, None, None, event.button, event.time)
class CMenuNode3(object):
"""Classe pour les menus contextuels d'une barre simple"""
ui = '''<ui>
<popup>
<menuitem action="R0"/>
<menuitem action="R1"/>
<menuitem action="Clear" name="clear"/>
</popup>
</ui>'''
def __init__(self, Main, b, event):
ui =CMenuNode3.ui
uimanager = gtk.UIManager()
uimanager.add_ui_from_string(ui)
accelgroup = uimanager.get_accel_group()
Main.w2.add_accel_group(accelgroup)
actiongroup = gtk.ActionGroup('settings')
actiongroup.add_toggle_actions([
('R0', None, 'Relaxer l\'origine', None, None, b._update_relax, b.R0),
('R1', None, 'Relaxer l\'extrémité', None, None, b._update_relax, b.R1)
], Main)
if isinstance(b, Barre):
if b.R0 and b.R1:
is_sensitive = True
else:
is_sensitive = False
id = uimanager.new_merge_id()
uimanager.add_ui(id, '/popup', 'N+', 'N+', gtk.UI_MANAGER_MENUITEM, False)
id = uimanager.new_merge_id()
uimanager.add_ui(id, '/popup', 'N-', 'N-', gtk.UI_MANAGER_MENUITEM, False)
id = uimanager.new_merge_id()
uimanager.add_ui(id, '/popup/clear', 'separator',
None, gtk.UI_MANAGER_SEPARATOR, False)
action = gtk.ToggleAction("N+", 'Traction seulement', None, None)
action.set_sensitive(is_sensitive)
action.set_active(b.mode == 1 and True or False)
action.connect('activate', b.set_one_way, Main, "N+")
actiongroup.add_action(action)
action = gtk.ToggleAction("N-", 'Compression seulement', None, None)
action.set_sensitive(is_sensitive)
action.set_active(b.mode == -1 and True or False)
action.connect('activate', b.set_one_way, Main, "N-")
actiongroup.add_action(action)
#actiongroup.add_toggle_actions([
# ('N+', None, 'Traction seulement', None, None, b._update_relax, 0),
# ('N-', None, 'Compression seulement', None, None, b._update_relax, 0)
# ], Main)
actiongroup.add_actions([
('Clear', None, 'Supprimer', None, None, b.on_delete)
], (Main, b.id))
uimanager.insert_action_group(actiongroup)
popup_menu = uimanager.get_widget('/popup')
Main.cm_popup = True
popup_menu.popup(None, None, None, event.button, event.time)
popup_menu.connect("event", Main.popup_event)
class CMenuChar1(object):
"""Classe pour les menus contextuels du chargement sur un arc"""
ui = '''<ui>
<popup>
<menuitem action="0" />
<menuitem action="1" />
<menuitem action="2" />
<menuitem action="Unif" />
<menuitem action="Start" />
<menuitem action="End" />
<menuitem action="Copy" />
<menuitem action="Clear" />
</popup>
</ui>'''
def __init__(self, Main, char, event):
ui =CMenuChar1.ui
uimanager = gtk.UIManager()
uimanager.add_ui_from_string(ui)
accelgroup = uimanager.get_accel_group()
Main.w2.add_accel_group(accelgroup)
actiongroup = gtk.ActionGroup('settings')
actiongroup.add_radio_actions([
('0', None, 'Linéique', None, None, 0),
('1', None, 'Projetée', None, None, 1),
('2', None, 'Radiale', None, None, 2)
], char.proj, char.update_arc_type, Main)
uimanager.insert_action_group(actiongroup)
start = not char.d['x1'] == 0.
end = not char.d['x2'] == 1.
actiongroup.add_toggle_actions([
('Unif', None, 'Charge uniforme', None, None, char.update_unif, char.unif),
('Start', None, 'Ajouter un point de départ', None, None, char.add_start_point, start),
('End', None, 'Ajouter un point de fin', None, None, char.add_end_point, end)
], Main)
actiongroup.add_actions([
('Copy', None, 'Copier', None, None, char.copy_char),
('Clear', None, 'Supprimer', None, None, char.on_delete),
], Main)
popup_menu = uimanager.get_widget('/popup')
popup_menu.popup(None, None, None, event.button, event.time)
class CMenuChar2(object):
"""Classe pour les menus contextuels du chargement sur une barre"""
ui = '''<ui>
<popup>
<menuitem action="Copy" />
<menuitem action="Clear" />
</popup>
</ui>'''
def __init__(self, Main, Char, event):
ui =CMenuChar2.ui
uimanager = gtk.UIManager()
uimanager.add_ui_from_string(ui)
accelgroup = uimanager.get_accel_group()
Main.w2.add_accel_group(accelgroup)
actiongroup = gtk.ActionGroup('settings')
page = Main.charbook.get_nth_page(Main.charbook.get_current_page())
n_page = Main.charbook.get_current_page()
vbox = page.get_children()[0].get_children()[0]
childs = vbox.get_children()
case = Main.data_editor.cases[n_page]
is_sensitive = True
#for i, hbox in enumerate(childs):
# char = case.chars[i]
# if char.get_is_selected():
# is_sensitive = True
# break
action = gtk.Action("Copy", "Copier", None, None)
actiongroup.add_action(action)
action.set_sensitive(is_sensitive)
action.connect('activate', Char.copy_char, Main)
action = gtk.Action("Clear", "Supprimer", None, None)
actiongroup.add_action(action)
action.set_sensitive(is_sensitive)
action.connect('activate', Char.on_delete, Main)
uimanager.insert_action_group(actiongroup)
popup_menu = uimanager.get_widget('/popup')
popup_menu.popup(None, None, None, event.button, event.time)
class AbstractNode(object):
"""Classe abstraite pour les noeuds"""
class_counter = 0
def update_preceding_combo(self, old, new):
"""Actualise le combo des noeuds précédents - Ne fait rien"""
pass
def fill_preceding_node(self, combobox, li):
"""Remplit le combo des noeuds avec des nouvelles valeurs - Ne fait rien"""
pass
def update_arc_name(self, barres, old_name, new_name):
"""Actualise le combo du nom de l'arc pour un noeud - Ne fait rien"""
pass
def set_xml(self, parent):
"""Crée les attributs nécessaires à la structure xml pour un noeud - Ne fait rien"""
pass
def update_tooltip_L(self, unit_L, unit_F=None):
"""Actualise les tooltips des longueurs suite à un changement d'unité pour un noeud - Ne fait rien"""
pass
def add_combo_item(self, elem):
"""Ajoute un arc dans le combo des arcs - Ne fait rien"""
pass
def remove_combo_items(self, barres):
"""Supprime des arcs dans le combo des arcs - Ne fait rien"""
pass
# non utilisé
def on_copy(self, widget, Main):
"""Action de copier l'élement - finir"""
Main.set_is_changed()
def on_delete(self, widget, *args):
"""Action de suppression d'un noeud depuis le CM"""
Main, node_id = args
box = Main.data_box['noeud']
nodes = Main.data_editor.nodes
are_deleted = []
old_nodes = Main.data_editor.get_all_nodes()
for i, node in enumerate(nodes):
if not node.id == node_id:
continue
box.remove(node.hbox.get_parent())
are_deleted.append(node.name)
del(nodes[i])
Main.set_is_changed(True)
Main.data_editor.size_changed = True
break
Main._fill_preceding_node(i)
# modification de la page contenant des combobox avec des noeuds
Main._remove_liaison2(are_deleted)
Main._remove_nodes_combo(old_nodes, are_deleted)
Main._remove_combo_char_items(are_deleted)
class ArcNode(AbstractNode):
"""Classe pour un noeud d'arc"""
def __init__(self, data):
self.id = AbstractNode.class_counter
AbstractNode.class_counter += 1
content = data['d']
self.name = data['id']
self.arc = data['name']
d = data['d']
try:
self.d = float(d) # compris entre 0 et 1
except ValueError:
self.d = None
try:
pos_on_curve = data['pos_on_curve']
if pos_on_curve == 'true':
self.pos_on_curve = 1
else:
self.pos_on_curve = 0
except KeyError:
self.pos_on_curve = 1
if 'rel' in data:
if data["rel"] == 1:
self.rel = True
elif data["rel"] == "0":
self.rel = False
else:
self.rel = False
else:
self.rel = False
self.x = None
self.y = None
def set_content_from_widgets(self, relative_node=None):
"""Modifie les attributs à partir de la lecture des widgets pour un noeud d'arc"""
widgets = self.hbox.get_children()
self.arc = widgets[3].get_active_text()
entry = widgets[4]
try:
self.d = float(entry.get_text().replace(',', '.'))
if self.d <= 0 or self.d >= 1:
raise ValueError
except ValueError:
self.d = None
#self.rel = widgets[5].get_active()
def set_xml(self, parent):
"""Crée les attributs nécessaires à la structure xml pour un noeud d'arc"""
if self.arc is None:
return
node = ET.SubElement(parent, "arc", {"id": self.name})
d = self.d
if self.d is None:
d = ""
node.set("d", str(d))
if self.arc is False:
return
node.set("name", self.arc)
node.set("r", self.rel and "1" or "0")
node.set("pos_on_curve", self.pos_on_curve and "true" or "false")
try:
l = self.l
node.set("liaison", ",".join(l))
except AttributeError:
pass
try:
dep = self.dep
dep = ",".join(dep)
node.set("dep", dep)
except AttributeError:
pass
return node
def update_arc_name(self, barres, old_name, new_name):
"""Actualise le combo du nom de l'arc pour un noeud d'arc"""
widgets = self.hbox.get_children()
if self.arc == old_name:
self.arc = new_name
combobox = widgets[3]
function.change_elem_combo(combobox, old_name, new_name, False)
def update_coors(self, modified_nodes, data_editor):
"""Actualise les coordonnées du noeud d'arc"""
self.set_coors_label(data_editor)
return self.name
def set_coors_label(self, data_editor):
"""Raffraichit l'affichage des coordonnées dans une ligne de noeud d'arc"""
#print "set_coors_label", self.name
widgets = self.hbox.get_children()
label = widgets[5]
try:
if self.arc == False or self.arc is None:
raise MyError
arc = data_editor.get_barre(self.arc)
resu = arc.get_coors(data_editor, self.d)
if resu is None:
raise MyError
x, y = resu
except MyError:
label.set_text("%s = (-,-)" % self.name)
self.x = None
self.y = None
return
label.set_text("%s = (%s,%s)" % (self.name, function.PrintValue(x),
function.PrintValue(y)))
self.x = x
self.y = y
def update_numeric_L(self, factor):
"""Actualise les valeurs numériques après changement unité de longueur pour un noeud ArcNode"""
pass
def add_hbox(self, Main):
"""Crée la hbox pour un noeud d'arc pour la page des noeuds"""
eventbox = gtk.EventBox()
hbox = gtk.HBox(False, 0)
image = gtk.Image()
file1 = self.get_img_file()
image.set_from_file("glade/%s" % file1)
hbox.pack_start(image, False, False, 0)
button = gtk.CheckButton()
button.set_tooltip_text('Sélectionner')
hbox.pack_start(button, False, False, 0)
entry = gtk.Entry()
entry.set_size_request(80, 30)
entry.set_text(self.name)
entry.set_tooltip_text("Nom")
entry.connect("changed", self.update_node_name, Main, self.id)
hbox.pack_start(entry, False, False, 0)
combobox = gtk.combo_box_new_text()
combobox.set_size_request(90, 30)
arcs = Main.data_editor.get_arcs2()
function.fill_elem_combo(combobox, arcs, self.arc)
id1 = combobox.connect('changed', self.update_arc, Main)
combobox.set_tooltip_text('Choix de l\'arc')
hbox.pack_start(combobox, False, False, 0)
entry = gtk.Entry()
entry.set_size_request(80, 30)
d = self.d
if self.d is None:
d = ""
entry.set_text(str(d))
entry.set_tooltip_text("Position relative entre 0 et 1")
id2 = entry.connect('changed', Main.update_nodes, self)
hbox.pack_start(entry, False, False, 0)
label = gtk.Label()
hbox.pack_start(label, False, False, 20)
self.hbox = hbox
self.set_coors_label(Main.data_editor)
eventbox.add(hbox)
eventbox.show_all()
eventbox.connect("event", self.onCMenu, Main)
self.ids = (id1, id2)
return eventbox
def get_img_file(self):
"""Retourne le nom du fichier en fonction des relaxations"""
if self.rel == 0:
return "noeud2_0.png"
return "noeud2_1.png"
def _update_relax(self, widget, Main):
"""Modification de la relaxation du noeud d'arc"""
self.rel = widget.get_active()
file1 = self.get_img_file()
widgets = self.hbox.get_children()
image = widgets[0]
image.set_from_file("glade/%s" % file1)
Main.set_is_changed(True)
def update_arc(self, widget, Main):
"""Mise à jour de l'arc de rattachement d'un noeud d'arc"""
tag = self.arc
self.arc = widget.get_active_text()
ed = Main.data_editor
barres = ed.barres
if tag is False: # ajout du noeud dans les combo des barres
for barre in barres:
barre.add_node_combo(ed, self)
else:
defined = []
for barre in barres:
widgets = barre.hbox.get_children()
combo1 = widgets[3]
combo2 = widgets[4]
model = combo1.get_model()
nodes = [i[0] for i in model]
if self.arc in defined:
if not self.name in nodes:
barre.add_node_combo(ed, self, force=True)
#print "Ajout de %s dans %s" % (self.name, barre.name)
else:
if self.name in nodes:
#print "suppression de %s dans %s" % (self.name, barre.name)
barre.remove_nodes_combo([self.name])
defined.append(barre.name)
self.set_coors_label(Main.data_editor)
Main.set_is_changed(True)
def update_node_name(self, widget, Main, id):
"""Mise à jour du nom d'un noeud pour un noeud d'arc"""
new = widget.get_text()
old = self.name
if new == old:
return None
self.name = new
Main.set_is_changed(True)
# actualise les combobox des noeuds précédents
nodes = Main.data_editor.nodes
#node_names = Main.data_editor.get_all_nodes()
n = 0
for node in nodes:
if node.id == id:
break
n += 1
#n = node_names.index(new)
next_nodes = nodes[n+1:]
self._update_preceding_node(next_nodes, old, new)
# modification de la page des barres
Main._update_node_list(self, n)
# actualise les instances Nodes
self.set_content_from_widgets()
self.set_coors_label(Main.data_editor)
def _update_preceding_node(self, nodes, old, new):
"""Actualise le combo des noeuds relatifs pour tous les noeuds donnés"""
for node in nodes:
node.update_preceding_combo(old, new)
def add_combo_item(self, elem):
"""Ajoute un arc dans le combo des arcs"""
combo = self.hbox.get_children()[3]
combo.append_text(elem)
def remove_combo_items(self, deleted):
"""Supprime des arcs dans le combo des noeuds d'arcs"""
combo = self.hbox.get_children()[3]
model = combo.get_model()
nodes = [i[0] for i in model]
indices = []
for node in deleted:
if node in nodes:
indices.append(nodes.index(node))
for pos in reversed(indices):
combo.remove_text(pos)
def onCMenu(self, widget, event, Main):
"""Affiche le menu contextuel d'un noeud d'arc"""
if event.type == gtk.gdk.ENTER_NOTIFY:
Main.set_hover(widget)
elif event.type == gtk.gdk.MOTION_NOTIFY:
return True
elif event.type == gtk.gdk.BUTTON_PRESS:
if event.button == 3:
CMenuNode1(Main, self, event)
return True # bloque la propagation du signal
return False
def update_type_coor(self, action, current, *args):
"""Choisi le type de coordonnées (par rapport à la corde ou sur l'arc)"""
#print "update_type_coor", action.get_current_value()
Main, node = args
node.pos_on_curve = action.get_current_value()
Main.set_is_changed(True)
class Node(AbstractNode):
"""Classe contenant pour un noeud simple"""
def __init__(self, name, content):
self.id = AbstractNode.class_counter
AbstractNode.class_counter += 1
self.name = name
self.arc = None # None si sans objet (segment), False si pas encore défini
self.x = None
self.y = None
self.set_content_from_string(content)
def set_content_from_string(self, content):
"""Crée les attribut de l'instance en fonction de la chaine de caractère"""
self.rel = None
if content.find("<") > 0:
self.pol = True
else:
self.pol = False
if content[0] == "@":
pos = content.find(",")
self.rel = content[1:pos]
content = content[pos+1:]
string = ","
if self.pol:
string = "<"
self.s_x, self.s_y = content.split(string)
def set_content_from_widgets(self, relative_node=None):
"""Modifie les attributs à partir de la lecture des widgets pour un noeud simple"""
widgets = self.hbox.get_children()
entry = widgets[2]
node_name = entry.get_text()
if relative_node is None:
combobox = widgets[3]
relative_node = combobox.get_active_text()
if relative_node == "":
relative_node = None
self.rel = relative_node
entry = widgets[4]
self.s_x = entry.get_text().replace(',', '.')
entry = widgets[5]
self.s_y = entry.get_text().replace(',', '.')
self.pol = [False, True][widgets[6].get_active()]
def set_xml(self, parent):
"""Crée les attributs nécessaires à la structure xml pour un noeud simple"""
node = ET.SubElement(parent, "node", {"id": self.name})
string = ''
if not self.rel is None:
string += "@%s," % self.rel
string += "%s" % self.s_x
if self.pol:
string += "<"
else:
string += ","
string += "%s" % self.s_y
node.set("d", string)
try:
l = self.l # !! liaison
node.set("liaison", ",".join(l))
except AttributeError:
pass
try:
dep = self.dep
dep = ",".join(dep)
node.set("dep", dep)
except AttributeError:
pass
return node
def update_preceding_combo(self, old, new):
"""Actualise le combo des noeuds précédents pour un noeud simple"""
combobox = self.hbox.get_children()[3]
function.change_elem_combo(combobox, old, new)
if self.rel == old:
self.rel = new
def fill_preceding_node(self, combobox, li):
"""Remplit le combo des noeuds avec des nouvelles valeurs"""
function.fill_elem_combo(combobox, li)
def update_coors(self, modified_nodes, data_editor):
"""Actualise les coordonnées du noeud simple"""
combobox = self.hbox.get_children()[3]
relative_node = combobox.get_active_text()
if relative_node is None or not relative_node in modified_nodes:
return None # pas de noeud relatif ou noeud different de celui modifié
self.set_coors_label(data_editor)
return self.name
def set_coors_label(self, data_editor):
"""Raffraichit l'affichage des coordonnées dans une ligne de noeud simple"""
widgets = self.hbox.get_children()
nodes = data_editor.nodes
coors = function.Str2NodeCoors2(self, nodes)
label = widgets[7]
if coors:
label.set_text("%s = (%s,%s)" % (self.name, function.PrintValue(coors[0]),
function.PrintValue(coors[1])))
self.x = coors[0]
self.y = coors[1]
else:
label.set_text("%s = (-,-)" % self.name)
try:
self.x = None
self.y = None
except AttributeError:
pass
def update_numeric_L(self, factor):
"""Actualise les valeurs numériques dans les champs de type entry après changement unité de longueur pour un noeud Node"""
widgets = self.hbox.get_children()
is_pol = [False, True][widgets[6].get_active()]
entry = widgets[4]
entry.handler_block(self.ids[1])
try:
val = float(entry.get_text())
val = val*factor
entry.set_text(str(val))
except ValueError:
pass
entry.handler_unblock(self.ids[1])
entry = widgets[5]
entry.handler_block(self.ids[2])
if not is_pol:
try:
val = float(entry.get_text())
val = val*factor
entry.set_text(str(val))
except ValueError:
pass
entry.handler_unblock(self.ids[2])
self.set_content_from_widgets(self.rel)
def add_hbox(self, Main):
"""Crée la hbox d'un noeud simple de la page des noeuds"""
node_name = self.name
units = Main.data_editor.get_units()
unit_L = function.return_key(units['L'], Main.data_editor.unit_conv['L'])
#unit_F = function.return_key(units['F'], Main.data_editor.unit_conv['F'])
eventbox = gtk.EventBox()
hbox = gtk.HBox(False, 0)
image = gtk.Image()
image.set_from_file("glade/noeud1.png")
hbox.pack_start(image, False, False, 0)
button = gtk.CheckButton()
button.set_tooltip_text('Sélectionner')
hbox.pack_start(button, False, False, 0)
entry = gtk.Entry()
entry.set_size_request(80, 30)
entry.set_text(node_name)
entry.set_tooltip_text("Nom")
entry.connect("changed", self.update_node_name, Main, self.id)
hbox.pack_start(entry, False, False, 0)
combobox = gtk.combo_box_new_text()
combobox.set_size_request(60, 30)
pos = Main.data_editor.nodes.index(self)
nodes = Main.data_editor.nodes[0:pos]
li = ['']
for val in nodes:
li.append(val.name)
if self.rel is None:
rel = ''
else:
rel = self.rel
function.fill_elem_combo(combobox, li, rel)
if pos == 0:
combobox.set_sensitive(False)
combobox.set_tooltip_text("Définir le noeud par rapport à un noeud précédent")
id1 = combobox.connect('changed', Main.update_nodes, self)
hbox.pack_start(combobox, False, False, 0)
entry = gtk.Entry()
entry.set_size_request(90, 30)
entry.set_text(self.s_x)
id2 = entry.connect('changed', Main.update_nodes, self)
hbox.pack_start(entry, False, False, 0)
entry = gtk.Entry()
entry.set_size_request(90, 30)
entry.set_text(self.s_y)
id3 = entry.connect('changed', Main.update_nodes, self)
hbox.pack_start(entry, False, False, 0)
self.ids = (id1, id2, id3)
button = gtk.CheckButton("Polaire")
if self.pol:
button.set_active(True)
button.connect('clicked', self.update_node2, Main)
hbox.pack_start(button, False, False, 0)
label = gtk.Label()
hbox.pack_start(label, False, False, 20)
self.hbox = hbox
self.set_coors_label(Main.data_editor)
self.update_tooltip_L(unit_L)
eventbox.add(hbox)
eventbox.show_all()
eventbox.connect("event", self.onCMenu, Main)
return eventbox
def update_tooltip_L(self, unit_L):
"""Actualise les tooltips des longueurs suite à un changement d'unité pour un noeud simple"""
widgets = self.hbox.get_children()
is_pol = [False, True][widgets[6].get_active()]
entry1 = widgets[4]
entry2 = widgets[5]
if is_pol:
string1 = 'Distance en %s' % unit_L
string2 = 'Angle en degré'
else:
string1 = 'Coordonnée suivant X en %s' % unit_L
string2 = 'Coordonnée suivant Y en %s' % unit_L
entry1.set_tooltip_text(string1)
entry2.set_tooltip_text(string2)
def update_node2(self, widget, Main):
"""Changement du type de coordonnées polaire ou cartésienne.
Actualise les tooltip pour un noeud donné"""
self.pol = [False, True][widget.get_active()]
units = Main.data_editor.get_units()
unit_L = function.return_key(units['L'], Main.data_editor.unit_conv['L'])
unit_F = function.return_key(units['F'], Main.data_editor.unit_conv['F'])
self.update_tooltip_L(unit_L)
Main.set_is_changed(True)
def update_node_name(self, widget, Main, id):
"""Mise à jour du nom d'un noeud pour un noeud simple"""
new = widget.get_text()
old = self.name
if new == old:
return None
self.name = new
Main.set_is_changed(True)