5
;# Copyright (C) Jose E. Marchesi
7
;# Time-stamp: "2003-11-11 14:45:16 jemarch"
9
;# This program is free software; you can redistribute it and/or
10
;# modify it under the terms of the GNU General Public License as
11
;# published by the Free Software Foundation; either version 2 of
12
;# the License, or (at your option) any later version.
14
;# This program is distributed in the hope that it will be useful,
15
;# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
;# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
;# GNU General Public License for more details.
19
;# You should have received a copy of the GNU General Public
20
;# License along with this program; if not, write to the Free
21
;# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28
;# Creates the default fonts for Gerwin
30
proc gui_create_fonts {} {
35
;# Default application font
37
[font create -family Helvetica -size 11]
40
;# Fonts for the ER Diagram
41
set gfonts(ercanvas_default) \
42
[font create -family Courier -size 8]
43
set gfonts(ercanvas_titles) \
44
[font create -family Courier -size 11]
45
set gfonts(ercanvas_minilabels) \
46
[font create -family Times -size 8]
51
;# gui_gcanvas_make_zoom CANVAS FACTOR
53
;# Makes a zoom on CANVAS, by FACTOR
54
;# Manages fonts sizes
56
;# CANVAS can be er or td
58
proc gui_gcanvas_make_zoom {what_canvas factor} {
68
;# First of all, scale the canvas itself
69
${gcanvas} scale all 0.0 0.0 $factor $factor
72
set fontfactor [expr ([font actual $gfonts(ercanvas_default) -size] \
75
regsub {([0-9]+)\.[0-9]} $fontfactor "\\1" fontfactor
77
font configure $gfonts(ercanvas_default) \
80
set fontfactor [expr ([font actual $gfonts(ercanvas_titles) -size] \
83
regsub {([0-9]+)\.[0-9]} $fontfactor "\\1" fontfactor
85
font configure $gfonts(ercanvas_titles) \
88
;# Reconfigure all entities and relations dimensions
107
;# Initializes the gerwin widgets, into WIDGET
109
proc gui_init {widget} {
114
global gerwin_version
115
global gerwin_editionarea
118
set gmainframe ${widget}
121
wm title . "Gerwin $gerwin_version"
126
;# Make the mainframe
127
MainFrame ${gmainframe} -separator both \
128
-textvariable gerwin_state -menu [gui_create_mainmenu]
130
${gmainframe} addindicator -text "Tcl Gerwin"
131
${gmainframe} addindicator -text $gerwin_version
133
;# Create the button-area
134
set fbarea [${gmainframe} addtoolbar]
135
gui_create_button_area $fbarea
138
set userframe [${gmainframe} getframe]
141
;# Create the app area
142
gui_create_app_area ${userframe}.apparea
146
;# Create the edition area
147
;# The edition area is a notebook widget, that contain frames.
148
;# The first frame is that one with the project properties
150
;#set gerwin_editionarea ${userframe}.editionarea
151
;#gui_create_edition_area ${userframe}.editionarea
153
;# Launch the bindings
154
;#gui_launch_bindings
156
;#pack ${userframe}.editionarea -side top -fill x
157
pack ${gmainframe} -fill both -expand true
159
;# Now there is not any project opened, so disable all the buttons
160
;# except the one with new-project and the one with load-project
161
gui_no_project_opened
167
;# gui_create_app_area WIDGET
169
;# Create the app area with all the pages
171
proc gui_create_app_area {widget} {
178
set userframe [${gmainframe} getframe]
180
;# Create the apptree
181
;# gui_create_apptree ${userframe}.apptree
183
;# Create the notebook
184
NoteBook ${userframe}.apparea
185
set apparea ${userframe}.apparea
188
;# pack ${apptree} -fill y -side left
191
pack ${apparea} -fill both -expand true -side right
197
;# gui_create_apptree PATH
199
;# Create the apptree at PATH
202
proc gui_create_apptree {path} {
208
;# Create the Tree widget
209
Tree ${path} -showlines true -dragenabled false
211
;##############################
212
;# Create the application nodes
213
;##############################
215
;# Gerwin -> Settings at right
216
gui_apptree_insert 0 root Gerwin
221
;# gui_apptree_insert INDEX PARENT NODE
223
;# Insert NODe into the apptree
225
proc gui_apptree_insert {index parent node} {
230
${apptree} insert $index $parent apptree-{$node} \
231
-text $node -font $gfonts(default) -image [Bitmap::get save]
238
;# gui_app_area_raise_Project_page
240
;# Raises the project page on the app area
242
proc gui_app_area_raise_Project_page {} {
246
${apparea} raise Project
252
;# gui_app_area_destroy_ER_page
254
;# Destroys the app area TD page
256
proc gui_app_area_destroy_ER_page {} {
267
;# gui_app_area_destroy_TD_page
269
;# Destroys the app area TD page
271
proc gui_app_area_destroy_TD_page {} {
281
;# gui_app_area_destroy_Output_page
283
;# Destroys the app area Output page
285
proc gui_app_area_destroy_Output_page {} {
289
${apparea} delete Output
295
;# gui_app_area_destroy_Project_page
297
;# Destroys the app area Project page
299
proc gui_app_area_destroy_Project_page {} {
303
${apparea} delete Project
308
;# gui_app_area_create_Project_page
310
;# Creates the app area Project page, with page information
312
proc gui_app_area_create_Project_page {} {
316
global gerwin_cproject_name
317
global gerwin_cproject_file
318
global gerwin_cproject_author
320
;# Create the new page, if it is not created
321
${apparea} insert 0 Project -text "Project"
322
${apparea} raise Project
324
;# Put here the project attributes
325
set widget [${apparea} getframe Project]
327
TitleFrame ${widget}.editframe -side center -text "Project Properties"
329
set editwidget [${widget}.editframe getframe]
332
frame ${editwidget}.nameline
333
LabelEntry ${editwidget}.nameline.label -label "Project Name:" -labelwidth 16 \
334
-textvariable gerwin_cproject_name \
335
-helptext "Name of the current project" -width 50
338
frame ${editwidget}.fileline
339
LabelEntry ${editwidget}.fileline.label -label "Project File:" -labelwidth 16 \
340
-textvariable gerwin_cproject_file \
341
-helptext "Storage file of the current project" -editable false \
344
Button ${editwidget}.fileline.button -text "select file" \
345
-helptext "Select a file to store the project in" \
346
-command "set tempfile \[gui_select_file_to_save\] ; \
348
if {\$tempfile != {}} then {
349
set gerwin_cproject_file \$tempfile
350
gerwin_save_project_file
356
frame ${editwidget}.authorline
357
LabelEntry ${editwidget}.authorline.label -label "Project Author:" -labelwidth 16 \
358
-textvariable gerwin_cproject_author \
359
-helptext "Author of the current project" -width 50
361
pack ${editwidget}.nameline.label -side left -anchor w
362
pack ${editwidget}.nameline -side top -anchor w
364
pack ${editwidget}.fileline.label -side left -anchor w
365
pack ${editwidget}.fileline.button -side left
366
pack ${editwidget}.fileline -side top -anchor w
368
pack ${editwidget}.authorline.label -side left -anchor w
369
pack ${editwidget}.authorline -side top -anchor w
371
pack ${editwidget} -side left
373
pack ${widget}.editframe -side left -fill both -expand true
375
;# Scale the notebook
376
NoteBook::compute_size ${apparea}
382
;# gui_app_area_raise_ER_page
384
;# Raises the ER page
386
proc gui_app_area_raise_ER_page {} {
395
;# gui_app_area_raise_TD_page
397
;# Raises the TD page
399
proc gui_app_area_raise_TD_page {} {
411
;# gui_app_area_raise_Output_page
413
;# Raises the Output page
415
proc gui_app_area_raise_Output_page {} {
419
${apparea} raise Output
425
;# gui_app_area_create_Domain_page
427
;# Create the app area Domain page, with the Domain Manager
429
proc gui_app_area_create_Domain_page {} {
434
;# Create the new page
435
${apparea} insert 0 Domain -text "Domains and Types"
438
;# Include here the new
444
;# gui_app_area_destroy_Domain_page
446
;# Delete the Domain page from the app area, and destroy its contents
448
proc gui_app_area_destroy_Domain_page {} {
451
global gerwin_domains
454
;# Delete the page and destroy the contents
455
${apparea} delete Domain
457
;# Purge all domains on the system
458
foreach d $gerwin_domains {
463
set gerwin_domains {}
468
;# gui_app_area_create_ER_page
470
;# Create the app area ER page
472
proc gui_app_area_create_ER_page {} {
476
global gerwin_editionarea
479
global gui_button_bbox_elements
480
global gui_button_bbox_tools
481
global gui_button_bbox_print_ER
482
global gui_button_bbox_zoom_ER
485
;# Create the new page
486
${apparea} insert end ER -text "ER Diagram"
488
;# Now, the scrolled canvas and the editionarea into two paned windows
489
set pw [${apparea} getframe ER].pw
490
PanedWindow $pw -side left -weights extra
492
;# Frame for the ER toolbar and scrolled canvas
493
;# Create the toolbar for ER
494
set erframe [${pw} add]
495
frame ${erframe}.toolbar
496
set bbox [ButtonBox ${erframe}.toolbar.tb2 -spacing 0 -padx 1 -pady 1]
497
set gui_button_bbox_elements $bbox
499
$bbox add -text entity \
500
-helptype balloon -helptext "Insert a new entity object" \
502
-command {gerwin_set_state "Inserting entity"}
504
$bbox add -text relation \
505
-helptype balloon -helptext "Insert a new relation object" \
507
-command {gerwin_set_state "Inserting relation begin"}
509
Separator ${erframe}.toolbar.sep2 -orient vertical
512
set bbox [ButtonBox ${erframe}.toolbar.tb3 -spacing 0 -padx 1 -pady 1]
513
set gui_button_bbox_tools $bbox
515
$bbox add -text move \
516
-helptype balloon -helptext "Move an object" \
518
-command {gerwin_set_state "Moving"}
520
$bbox add -text edit \
521
-helptype balloon -helptext "Edit the properties of an object" \
523
-command {gerwin_set_state "Editing"}
525
$bbox add -text delete \
526
-helptype balloon -helptext "Delete an object" \
527
-command {gerwin_set_state "Deleting"} -relief groove
528
;#-image [Bitmap::get cut] -relief groove \
530
Separator ${erframe}.toolbar.sep1 -orient vertical
532
set bbox [ButtonBox ${erframe}.toolbar.tb7 -spacing 0 -padx 1 -pady 1]
533
set gui_button_bbox_print_ER $bbox
535
$bbox add -text "print" -helptype balloon \
536
-helptext "Print the ER diagram" \
537
-relief groove -command gerwin_print_ER
539
# set bbox [ButtonBox ${erframe}.toolbar.tb8 -spacing 0 -padx 1 -pady 1]
540
# set gui_button_bbox_zoom_ER $bbox
542
# $bbox add -text "+" -helptype balloon \
543
# -helptext "Positive zoom" \
544
# -relief groove -command [list gui_gcanvas_make_zoom er 1.1]
545
# $bbox add -text "-" -helptype balloon \
546
# -helptext "Negative zoom" \
547
# -relief groove -command [list gui_gcanvas_make_zoom er 0.9]
550
# Separator ${erframe}.toolbar.sep3 -orient vertical
552
pack ${erframe}.toolbar.tb2 -side left -anchor w
553
pack ${erframe}.toolbar.sep2 -side left -padx 4 -fill y
554
pack ${erframe}.toolbar.tb3 -side left -anchor w
555
pack ${erframe}.toolbar.sep1 -side left -padx 4 -fill y
556
pack ${erframe}.toolbar.tb7 -side left -anchor w
557
# pack ${erframe}.toolbar.sep3 -side left -padx 4 -fill y
558
# pack ${erframe}.toolbar.tb8 -side left -anchor w
560
gui_create_scrolled_canvas [frame ${erframe}.fcanvas] ;#-bg white
561
set gcanvas ${erframe}.fcanvas.canvas
563
pack ${erframe}.toolbar -side top -fill x
564
pack ${erframe}.fcanvas -side top -fill both -expand true
566
;# Set the canvas enter and leave bindings
567
bind ${gcanvas} <Enter> gui_enter_canvas_bind
568
bind ${gcanvas} <Leave> gui_leave_canvas_bind
570
;# Set the canvas dimensions bindings
571
bind . <Key-Right> gui_expand_canvas_to_right
572
bind . <Key-Down> gui_expand_canvas_to_down
573
bind . <Key-Left> gui_shrink_canvas_to_left
574
bind . <Key-Up> gui_shrink_canvas_to_up
576
;# Create the editionarea
577
set gerwin_editionarea [${pw} add].editionarea
578
gui_create_edition_area ${gerwin_editionarea}
582
pack ${gerwin_editionarea} -side bottom -fill x
585
pack ${erframe} -fill both -expand true
586
pack ${pw} -fill both -expand true
588
;# Update the notebook size
589
NoteBook::compute_size ${apparea}
593
;# gui_app_area_create_TD_page
595
;# Create the app area TD page
597
proc gui_app_area_create_TD_page {} {
603
global gui_button_bbox_print_TD
604
global gui_button_bbox_gen_TD
606
;# Create the new page
607
${apparea} insert end TD -text "Table Diagram"
609
set bbutton_frame [frame [${apparea} getframe TD].toolbar]
611
set bbox [ButtonBox ${bbutton_frame}.tb1 -spacing 0 -padx 1 -pady 1]
612
set gui_button_bbox_gen_TD $bbox
614
$bbox add -text "Update" \
615
-helptype balloon -helptext "Generate the table diagram" \
616
-relief groove -command {gen_ER_to_TD}
618
Separator ${bbutton_frame}.sep1 -orient vertical
620
set bbox [ButtonBox ${bbutton_frame}.tb2 -spacing 0 -padx 1 -pady 1]
621
set gui_button_bbox_print_TD $bbox
623
$bbox add -text "print" -helptype balloon \
624
-helptext "Print the Table diagram" \
625
-relief groove -command gerwin_print_TD
627
pack ${bbutton_frame}.tb1 -side left -anchor w
628
pack ${bbutton_frame}.sep1 -side left -padx 4 -fill y
629
pack ${bbutton_frame}.tb2 -side left -anchor w
632
set erframe [frame [${apparea} getframe TD].fcanvas]
633
gui_create_scrolled_canvas ${erframe}
635
set gcanvas_td ${erframe}.canvas
637
;# Set the canvas enter and leave bindings
638
bind ${gcanvas_td} <Enter> {. configure -cursor fleur}
639
bind ${gcanvas_td} <Leave> {. configure -cursor ""}
641
;# Set the bind for marking
642
${gcanvas_td} bind all <Button-1> {gui_mark_td %x %y}
645
pack ${bbutton_frame} -fill x
646
pack ${erframe} -fill both -expand true
651
;# gui_app_area_create_Output_page
653
;# Create the app area Output page
655
proc gui_app_area_create_Output_page {} {
659
global gerwin_output_formats
660
global gerwin_output_active_format
662
global output_pages_widget
665
global gui_button_bbox_gen_output
667
;# Create the new page
668
${apparea} insert end Output -text "Output"
670
;# Create the toolbar
671
set bbutton_frame [frame [${apparea} getframe Output].toolbar]
672
set bbox [ButtonBox ${bbutton_frame}.tb1 -spacing 0 -padx 1 -pady 1]
673
set gui_button_bbox_gen_output $bbox
675
$bbox add -text "Create output" \
676
-helptype balloon -helptext "Generate the selected output format" \
677
-relief groove -command "gen_TD_to_Output \$gerwin_output_active_format"
680
;# Replace it with a ComboBox
681
Label ${bbutton_frame}.label -text "output format: "
682
ComboBox ${bbutton_frame}.formats -values $gerwin_output_formats -expand tab \
684
-modifycmd "set gerwin_output_active_format \[lindex \$gerwin_output_formats \[${bbutton_frame}.formats getvalue\]\]"
687
pack ${bbutton_frame}.label -side left -anchor w
688
pack ${bbutton_frame}.formats -side left
689
pack ${bbutton_frame}.tb1 -side left -anchor w -padx 4
691
;# Now, create the notebook with the several output gtexts
692
set outputs [NoteBook [${apparea} getframe Output].nb]
693
set output_pages_widget $outputs
696
pack ${bbutton_frame} -fill x
697
pack ${outputs} -fill both -expand true
698
;#pack ${erframe} -fill both -expand true
703
;# gui_destroy_output_page FORMAT
705
;# Destroy the FORMAT output page
707
proc gui_destroy_output_page {format} {
710
global output_pages_widget
713
;# First of all, clean output_pages and gtext_output(FORMAT)
714
set index [lsearch $output_pages $format]
715
set output_pages [lreplace $output_pages $index $index]
717
unset gtext_output($format)
719
;# Ok, then destroy the widget
720
${output_pages_widget} delete $format
726
;# gui_create_output_page FORMAT
728
;# Creates a new output page for FORMAT on the output_pages_widget notebook
730
proc gui_create_output_page {format} {
733
global output_pages_widget
735
global gerwin_output_active_format
738
;# First of all, update output_pages
739
lappend output_pages $format
741
;# Second, create the page into the notebook
742
${output_pages_widget} insert end $format -text $format
744
;# Good. Next, create the button bar
745
set toolbar [frame [${output_pages_widget} getframe $format].toolbar]
748
set bbox [ButtonBox ${toolbar}.tb3 -spacing 0 -padx 1 -pady 1]
750
$bbox add -text update \
751
-helptype balloon -helptext "Update this output from the tables" \
753
-command "set ftemp \$gerwin_output_active_format
754
set gerwin_output_active_format $format
755
gen_TD_to_Output $format
756
set gerwin_output_active_format \$ftemp"
758
Separator ${toolbar}.sep3 -orient vertical
760
;# Save and print buttons
761
set bbox [ButtonBox ${toolbar}.tb1 -spacing 0 -padx 1 -pady 1]
763
$bbox add -text save \
764
-helptype balloon -helptext "Save this output to a file" \
766
-command [list gerwin_save_output_file $format]
768
# $bbox add -text print \
769
# -helptype balloon -helptext "Print this output to a printer" \
771
# -command [list gerwin_print_output $format]
774
set bbox [ButtonBox ${toolbar}.tb2 -spacing 0 -padx 1 -pady 1]
776
$bbox add -text close \
777
-helptype balloon -helptext "Close this output page" \
779
-command [list gui_destroy_output_page $format]
782
pack ${toolbar}.tb3 -side left -anchor w
783
pack ${toolbar}.sep3 -side left
784
pack ${toolbar}.tb1 -side left -anchor w
785
pack ${toolbar}.tb2 -side right -anchor w
787
;# Now create the scrolled text
788
set stext [frame [${output_pages_widget} getframe $format].stext]
790
gui_create_scrolled_text ${stext}
793
pack ${toolbar} -side top -fill x
794
pack ${stext} -side top -fill both -expand true
796
;# Finally, raise the page and update gtext_output
797
${output_pages_widget} raise $format
798
set gtext_output($format) ${stext}.text
800
;# Put the background
801
$gtext_output($format) configure -bg white
803
;# Make the text widget not editable
804
$gtext_output($format) configure -state disabled
809
;# gui_enter_canvas_bind
812
proc gui_enter_canvas_bind {} {
817
switch $gerwin_state {
821
. configure -cursor crosshair
824
"Inserting relation begin" {
826
. configure -cursor left_side
830
"Inserting relation end" {
832
. configure -cursor right_side
838
. configure -cursor pirate
844
. configure -cursor fleur
850
. configure -cursor hand1
856
. configure -cursor ""
865
;# gui_leave_canvas_bind
868
proc gui_leave_canvas_bind {} {
870
. configure -cursor ""
877
;# gui_update_font FONT
879
;# Updates the application global font
881
proc gui_update_font {newfont} {
887
. configure -cursor watch
889
;# Update the fonts of all widgets
890
if { $gui_font != $newfont } then {
892
$fontselwidget configure -font $newfont
893
set gui_font $newfont
896
. configure -cursor ""
901
;# gui_create_edition_area WIDGET
903
;# Creates the edition area
905
proc gui_create_edition_area {widget} {
907
;# Create the notebook
916
;# gui_create_mainmenu
918
;# Create the main menu string
920
proc gui_create_mainmenu {} {
927
{command "&Exit Gerwin" {} "exit the application" {Ctrl e} -command gerwin_quit}
931
{command "&New Project" {} "new project" {Ctrl n} -command gerwin_new_project}
932
{command "&Open Project" {} "open a new project" {Ctrl o} -command gerwin_open_project}
933
{command "&Save Project" {} "save the current project" {Ctrl s} -command gerwin_save_project}
934
{command "&Close Project" {} "close the current project" {Ctrl c} -command gerwin_close_project}
944
;# gui_create_button_area WIDGET
946
;# Create the button area widget
949
proc gui_create_button_area {widget} {
951
global gui_button_bbox_project
953
global gerwin_output_formats
956
set bbox [ButtonBox ${widget}.tb1 -spacing 0 -padx 1 -pady 1]
957
set gui_button_bbox_project $bbox
959
$bbox add -text "new" -helptype balloon \
960
-helptext "New project" \
962
-command "gerwin_new_project"
964
$bbox add -text "open" -helptype balloon \
965
-helptext "Open a project" \
967
-command "gerwin_open_project"
969
$bbox add -text "save" -helptype balloon \
970
-helptext "Save the current project" \
972
-command "gerwin_save_project"
975
pack ${widget}.tb1 -side left -anchor w
978
# set bbox [ButtonBox ${widget}.tb5 -spacing 0 -padx 1 -pady 1]
979
# set gui_button_bbox_ssql $bbox
981
# $bbox add -text "save sql" \
982
# -helptype balloon -helptext "Saves the SQL list" \
983
# -relief groove -command {gerwin_save_sql}
988
;# gui_create_scrolled_text FRAME ARGS
990
;# Create a scrolled text widget
992
proc gui_create_scrolled_text {widget args} {
995
;# Create the text widget
996
eval {text ${widget}.text \
997
-xscrollcommand [list ${widget}.xscroll set] \
998
-yscrollcommand [list ${widget}.yscroll set] \
999
-borderwidth 0} $args
1001
;# Create the scroll widgets
1002
scrollbar ${widget}.xscroll -orient horizontal \
1003
-command [list ${widget}.text xview]
1004
scrollbar ${widget}.yscroll -orient vertical \
1005
-command [list ${widget}.text yview]
1008
grid ${widget}.text ${widget}.yscroll -sticky news
1009
grid ${widget}.xscroll -sticky ew
1010
grid rowconfigure ${widget} 0 -weight 1
1011
grid columnconfigure ${widget} 0 -weight 1
1017
;# gui_shrink_canvas_to_left
1020
proc gui_shrink_canvas_to_left {} {
1024
set sarea [${gcanvas} cget -scrollregion]
1026
${gcanvas} configure -scrollregion \
1027
[list [lindex $sarea 0] [lindex $sarea 1] \
1028
[expr [lindex $sarea 2] - 100] [lindex $sarea 3]]
1036
;# gui_expand_canvas_to_right
1039
proc gui_expand_canvas_to_right {} {
1043
set sarea [${gcanvas} cget -scrollregion]
1045
${gcanvas} configure -scrollregion \
1046
[list [lindex $sarea 0] [lindex $sarea 1] \
1047
[expr [lindex $sarea 2] + 100] [lindex $sarea 3]]
1054
;# gui_shrink_canvas_to_up
1057
proc gui_shrink_canvas_to_up {} {
1061
set sarea [${gcanvas} cget -scrollregion]
1063
${gcanvas} configure -scrollregion \
1064
[list [lindex $sarea 0] [lindex $sarea 1] \
1065
[lindex $sarea 2] [expr [lindex $sarea 3] - 100]]
1072
;# gui_expand_canvas_to_down
1075
proc gui_expand_canvas_to_down {} {
1079
set sarea [${gcanvas} cget -scrollregion]
1081
${gcanvas} configure -scrollregion \
1082
[list [lindex $sarea 0] [lindex $sarea 1] \
1083
[lindex $sarea 2] [expr [lindex $sarea 3] + 100]]
1089
;# gui_create_scrolled_canvas FRAME ARGS
1091
;# Create a scrolled canvas widget
1093
proc gui_create_scrolled_canvas { widget args } {
1096
;# Create the canvas widget
1097
eval {canvas ${widget}.canvas \
1098
-xscrollcommand [list ${widget}.xscroll set] \
1099
-yscrollcommand [list ${widget}.yscroll set] \
1100
-highlightthickness 0 \
1101
-borderwidth 0 -bg white} $args
1103
;# Create the scroll widgets
1104
scrollbar ${widget}.xscroll -orient horizontal \
1105
-command [list ${widget}.canvas xview]
1106
scrollbar ${widget}.yscroll -orient vertical \
1107
-command [list ${widget}.canvas yview]
1109
;# Pack the widgets (with grid)
1110
grid ${widget}.canvas ${widget}.yscroll -sticky news
1111
grid ${widget}.xscroll -sticky ew
1112
grid rowconfigure ${widget} 0 -weight 1
1113
grid columnconfigure ${widget} 0 -weight 1
1119
;# gui_change_state TEXT
1121
;# Change the state to TEXT
1122
;# Now this is a nop
1124
proc gui_change_state {text} {
1130
;# gui_yes_no_cancel TEXT
1133
proc gui_yes_no_cancel {text} {
1137
MessageDlg ${gmainframe}.notice -title "I am asking you, dude!" -justify left -icon info \
1138
-message $text -type yesnocancel
1146
;# Notice about something.
1148
proc gui_notice {text} {
1152
MessageDlg ${gmainframe}.notice -title "Notice" -justify left -icon info \
1153
-message $text -type ok
1159
;# Notice a fatal error and exit
1161
proc gui_fatal {text} {
1165
toplevel ${gmainframe}.fatal -bg red
1167
label ${gmainframe}.fatal.label -text "Fatal Error: $text" \
1169
button ${gmainframe}.fatal.button -text "Quit Gerwin" \
1172
pack ${gmainframe}.fatal.label -side top
1173
pack ${gmainframe}.fatal.button -side top
1175
focus ${gmainframe}.fatal
1180
;# gui_project_opened
1182
;# Enables some buttons and canvas and text backgrounds
1184
proc gui_project_opened {} {
1186
global gui_button_bbox_project
1187
global gui_button_bbox_elements
1188
global gui_button_bbox_tools
1189
global gui_button_bbox_gen_TD
1190
global gui_button_bbox_gen_output
1191
global gui_button_bbox_gen_GerwinML
1192
global gui_button_bbox_ssql
1193
global gui_button_bbox_print_ER
1194
global gui_button_bbox_print_TD
1200
;# Enable some buttons
1202
# $gui_button_bbox_project itemconfigure 0 -state active ;# New Project
1203
# $gui_button_bbox_project itemconfigure 1 -state active ;# Open Project
1204
$gui_button_bbox_project itemconfigure 2 -state active ;# Save project
1205
# ;#$gui_button_bbox_project itemconfigure 3 -state active ;# Close project
1207
# $gui_button_bbox_elements itemconfigure 0 -state active ;# Insert entity
1208
# $gui_button_bbox_elements itemconfigure 1 -state active ;# Insert relation
1209
# ;#$gui_button_bbox_elements itemconfigure 2 -state active ;# Insert label
1211
# $gui_button_bbox_tools itemconfigure 0 -state active ;# Move
1212
# $gui_button_bbox_tools itemconfigure 1 -state active ;# Edit properties
1213
# $gui_button_bbox_tools itemconfigure 2 -state active ;# Delete
1215
# $gui_button_bbox_gen_TD itemconfigure 0 -state active ;# Generate tables
1216
# $gui_button_bbox_gen_output itemconfigure 0 -state active ;# Generate Output
1218
# ;#$gui_button_bbox_ssql itemconfigure 0 -state active ;# Save SQL
1220
# $gui_button_bbox_print_ER itemconfigure 0 -state active ;# Print ER
1221
# $gui_button_bbox_print_TD itemconfigure 0 -state active ;# Print TD
1223
# ;# Change some backgrounds
1224
# ${gcanvas} configure -bg white
1225
# ${gcanvas_td} configure -bg white
1228
;# Create the app area pages
1229
;#gui_app_area_create_Domain_page
1230
gui_app_area_create_Project_page
1231
gui_app_area_create_ER_page
1232
gui_app_area_create_TD_page
1233
gui_app_area_create_Output_page
1235
;# Launch the bindings
1238
;# Set the editing state
1239
gerwin_set_state Editing
1245
;# gui_no_project_opened
1247
;# Disables some buttons and the color of some objects
1249
proc gui_no_project_opened {} {
1251
global gui_button_bbox_project
1252
global gui_button_bbox_elements
1253
global gui_button_bbox_tools
1254
global gui_button_bbox_gen_TD
1255
global gui_button_bbox_gen_output
1256
global gui_button_bbox_gen_GerwinML
1257
global gui_button_bbox_ssql
1258
global gui_button_bbox_print_ER
1259
global gui_button_bbox_print_TD
1265
;# Disable some buttons
1267
$gui_button_bbox_project itemconfigure 2 -state disabled ;# Save project
1268
;#$gui_button_bbox_project itemconfigure 3 -state disabled ;# Close project
1270
# $gui_button_bbox_elements itemconfigure 0 -state disabled ;# Insert entity
1271
# $gui_button_bbox_elements itemconfigure 1 -state disabled ;# Insert relation
1272
;#$gui_button_bbox_elements itemconfigure 2 -state disabled ;# Insert label
1274
# $gui_button_bbox_tools itemconfigure 0 -state disabled ;# Move
1275
# $gui_button_bbox_tools itemconfigure 1 -state disabled ;# Edit properties
1276
# $gui_button_bbox_tools itemconfigure 2 -state disabled ;# Delete
1278
# $gui_button_bbox_gen_TD itemconfigure 0 -state disabled ;# Gen TD
1279
# $gui_button_bbox_gen_output itemconfigure 0 -state disabled ;# Gen Output
1281
# ;#$gui_button_bbox_ssql itemconfigure 0 -state disabled
1283
# $gui_button_bbox_print_ER itemconfigure 0 -state disabled ;# Print ER
1284
# $gui_button_bbox_print_TD itemconfigure 0 -state disabled ;# Print TD
1287
# ;# Change the color of the canvas and text widget to grey
1288
# ${gcanvas} configure -bg grey
1289
# ${gcanvas_td} configure -bg grey
1290
;#${gtext_sql} configure -bg grey
1294
;# gui_launch_bindings
1296
;# Launch the bindings of the canvas
1298
proc gui_launch_bindings {} {
1303
set userframe [${gmainframe} getframe]
1305
;# The button-1 (mark) binding
1306
${gcanvas} bind all <Button-1> {gui_mark %x %y}
1311
;# gui_drag XPOS YPOS
1313
;# Event to mouse-drag-1 on the canvas
1315
proc gui_drag {xpos ypos} {
1319
global gerwin_premov_x
1320
global gerwin_premov_y
1321
global gerwin_premov_object
1322
global gerwin_obj_moving
1323
global gerwin_obj_type_moving
1326
global gerwin_relation
1329
;# See if we are really moving
1330
if {$gerwin_state != "Moving"} then {
1334
set userframe [${gmainframe} getframe]
1336
;# Map from view coordinates to canvas coordinates
1337
set xpos [${gcanvas} canvasx $xpos]
1338
set ypos [${gcanvas} canvasy $ypos]
1341
;# Move the current object
1342
set dx [expr $xpos - $gerwin_premov_x]
1343
set dy [expr $ypos - $gerwin_premov_y]
1346
${gcanvas} move $gerwin_premov_object $dx $dy
1349
;# Actualize premov coordinates
1350
set gerwin_premov_x $xpos
1351
set gerwin_premov_y $ypos
1353
;# Actualize the widget coordinates
1354
switch $gerwin_obj_type_moving {
1358
set gm_relation($gerwin_obj_moving,xpos) [lindex [${gcanvas} bbox \
1359
$gm_relation($gerwin_obj_moving,grouptag)] 0]
1360
set gm_relation($gerwin_obj_moving,ypos) [lindex [${gcanvas} bbox \
1361
$gm_relation($gerwin_obj_moving,grouptag)] 1]
1365
if {$gerwin_relation($gerwin_obj_moving,reflexive)} then {
1366
;# It is a reflexive relation
1367
gm_relation_update_links_reflexive $gerwin_obj_moving
1369
;# Non-reflexive relation
1370
gm_relation_update_links $gerwin_obj_moving
1376
set gm_entity($gerwin_obj_moving,xpos) [lindex [${gcanvas} bbox \
1377
$gm_entity($gerwin_obj_moving,grouptag)] 0]
1378
set gm_entity($gerwin_obj_moving,ypos) [lindex [${gcanvas} bbox \
1379
$gm_entity($gerwin_obj_moving,grouptag)] 1]
1381
;# Update all the links
1382
foreach r [gob_entity_get_relations $gerwin_obj_moving] {
1384
if {$gerwin_relation($r,reflexive)} then {
1385
;# Reflexive relation
1386
gm_relation_update_links_reflexive $r
1388
gm_relation_update_links $r
1401
;# gui_drag_td XPOS YPOS
1403
;# Event to mouse-drag-1 on the TD canvas
1405
proc gui_drag_td {xpos ypos} {
1408
global gerwin_premov_x
1409
global gerwin_premov_y
1410
global gerwin_premov_object
1411
global gerwin_obj_moving
1412
global gerwin_obj_type_moving
1417
;# We are always moving here
1418
;# (for now :P) [jemarch]
1420
set userframe [${gmainframe} getframe]
1422
;# Map from view coordinates to canvas coordinates
1423
set xpos [${gcanvas_td} canvasx $xpos]
1424
set ypos [${gcanvas_td} canvasy $ypos]
1426
;# Move the current object
1427
set dx [expr $xpos - $gerwin_premov_x]
1428
set dy [expr $ypos - $gerwin_premov_y]
1430
;# Actualize premov coordinates
1431
set gerwin_premov_x $xpos
1432
set gerwin_premov_y $ypos
1435
${gcanvas_td} move $gerwin_premov_object $dx $dy
1437
;# Actualize the coordinates
1438
switch $gerwin_obj_type_moving {
1441
;# Get the name of the two linked tables
1442
regsub {(.+)-([^-]+)} $gerwin_obj_moving "\\1" rtable
1443
regsub {(.+)-([^-]+)} $gerwin_obj_moving "\\2" table
1445
;# Update the position of the corresponding flkey
1446
gm_flkey_set_xpos $rtable $table [lindex [${gcanvas_td} bbox \
1447
"taggroup-Flkey-$rtable-$table"] 0]
1448
gm_flkey_set_ypos $rtable $table [lindex [${gcanvas_td} bbox \
1449
"taggroup-Flkey-$rtable-$table"] 1]
1451
;# Update the links of the flkey
1454
foreach t [gob_table_get_foreign_keys $table] {
1456
set rtable [lindex $t 1]
1458
;#${gcanvas_td} delete "taggroup-Flkey-$rtable-$table"
1459
${gcanvas_td} delete "taggroup-Flkey-link-$rtable-$table"
1463
;# For each foreign key
1464
foreach t [gob_table_get_foreign_keys $table] {
1466
set nrtable [lindex $t 1]
1467
set rattribute [lindex $t 0]
1469
if {$nrtable == $rtable} then {
1470
lappend rattributes($rtable) $rattribute
1475
gm_draw_link_td $table $rtable $rattributes($rtable)
1484
;# Actualize the table coordinates
1485
set gm_table($gerwin_obj_moving,xpos) [lindex [${gcanvas_td} bbox \
1486
$gm_table($gerwin_obj_moving,grouptag)] 0]
1487
set gm_table($gerwin_obj_moving,ypos) [lindex [${gcanvas_td} bbox \
1488
$gm_table($gerwin_obj_moving,grouptag)] 1]
1490
;# Update the table links
1491
gm_table_update_links $gerwin_obj_moving
1500
;# gui_mark_td XPOS YPOS
1502
;# Evento to mouse-pointer-1 on the td canvas
1504
proc gui_mark_td {xpos ypos} {
1507
global gerwin_tables
1508
global gerwin_premov_x
1509
global gerwin_premov_y
1510
global gerwin_premov_object
1511
global gerwin_obj_moving
1512
global gerwin_obj_type_moving
1516
set userframe [${gmainframe} getframe]
1518
;# Get the coords onto the widget
1519
set xpos [${gcanvas_td} canvasx $xpos]
1520
set ypos [${gcanvas_td} canvasy $ypos]
1522
;# Now, figure out what WGOB we want to delete
1523
set wgob [${gcanvas_td} find closest $xpos $ypos]
1525
;# Get the taggroup from the WGOB
1526
set wgobtags [${gcanvas_td} gettags $wgob]
1527
set index [lsearch -glob $wgobtags "taggroup-*"]
1528
set taggroup [lindex $wgobtags $index]
1530
;# Get the object name
1531
regsub {taggroup-([^-]+)-.+} $taggroup "\\1" gm_type
1533
if {$gm_type == "Flkey"} then {
1535
regsub {taggroup-[^-]+-(.+)} $taggroup "\\1" gm_name
1538
regsub {taggroup-.*-(.+)} $taggroup "\\1" gm_name
1541
set gerwin_obj_type_moving $gm_type
1542
set gerwin_obj_moving $gm_name
1544
set gerwin_premov_x $xpos
1545
set gerwin_premov_y $ypos
1546
set gerwin_premov_object $taggroup
1552
;# gui_mark XPOS YPOS
1554
;# Event to mouse-pointer-1 on the canvas
1556
proc gui_mark {xpos ypos} {
1560
global gerwin_entities
1561
global gerwin_relations
1562
global gerwin_relation
1563
global gerwin_premov_x
1564
global gerwin_premov_y
1565
global gerwin_premov_object
1566
global gerwin_entity_seq
1567
global gerwin_relation_seq
1568
global gerwin_obj_moving
1569
global gerwin_obj_type_moving
1577
set userframe [${gmainframe} getframe]
1579
;# Switch over the actual state
1580
switch $gerwin_state {
1582
"Inserting relation begin" {
1584
;# Get the coords onto the widget
1585
set xpos [${gcanvas} canvasx $xpos]
1586
set ypos [${gcanvas} canvasy $ypos]
1588
;# Figure out what WGOB is the first entity
1589
set wgob [${gcanvas} find closest $xpos $ypos]
1591
;# Get the taggroup tag from the WGOB
1592
set wgobtags [${gcanvas} gettags $wgob]
1593
set index [lsearch -glob $wgobtags "taggroup-*"]
1594
set taggroup [lindex $wgobtags $index]
1596
;# Get the object name and type from the taggroup
1597
regsub {taggroup-([^-]+)-.+} $taggroup "\\1" gm_type
1598
regsub {taggroup-[^-]+-(.+)} $taggroup "\\1" gm_name
1600
;# Do nothing if this is not an entity
1601
if {$gm_type != "Entity"} then {
1607
;# Set the first entity, and then switch to "Inserting relation end" state
1608
set gui_entity1 $gm_name
1610
gerwin_set_state "Inserting relation end"
1612
. configure -cursor right_side
1615
"Inserting relation end" {
1617
;# Get the coords onto the widget
1618
set xpos [${gcanvas} canvasx $xpos]
1619
set ypos [${gcanvas} canvasy $ypos]
1621
;# Figure out what WGOB is the first entity
1622
set wgob [${gcanvas} find closest $xpos $ypos]
1624
;# Get the taggroup tag from the WGOB
1625
set wgobtags [${gcanvas} gettags $wgob]
1626
set index [lsearch -glob $wgobtags "taggroup-*"]
1627
set taggroup [lindex $wgobtags $index]
1629
;# Get the object name and type from the taggroup
1630
regsub {taggroup-([^-]+)-.+} $taggroup "\\1" gm_type
1631
regsub {taggroup-[^-]+-(.+)} $taggroup "\\1" gm_name
1633
if {$gm_type != "Entity"} then {
1635
;# See if we are adding an entity to a n-relation
1636
if {$gm_type == "Relation"} then {
1638
;# If the relation is reflexive, abort inmediatly
1639
if {$gerwin_relation($gm_name,reflexive)} then {
1640
gui_notice "You cannot add a new entity to a reflexive relation!"
1642
;# Goto Editing state
1643
gerwin_set_state "Editing"
1645
. configure -cursor hand1
1649
;# If the entity is already part of the relation, abort inmediatly
1650
if {[lsearch -glob [gob_relation_get_entities $gm_name] "$gui_entity1 *"] != -1} then {
1651
gui_notice "Sorry, $gui_entity1 already have a link to $gm_name"
1653
;# Goto Editing state
1654
gerwin_set_state "Editing"
1656
. configure -cursor hand1
1660
;# Add a link to gui_entity1 to the relation
1661
;# Cardinality is always _/N
1662
gob_relation_add_entity $gm_name $gui_entity1 1 N
1664
;# Add the relation to the entity's relation list
1665
gob_entity_add_relation $gui_entity1 $gm_name
1667
;# Now, all entities have cardinality 1/N
1668
;# The _ is a fake value
1669
foreach e [gob_relation_get_entities $gm_name] {
1672
gob_relation_set_entity_min_card $gm_name $e _
1673
gob_relation_set_entity_max_card $gm_name $e N
1678
;# Actualize the edition page for the relation
1679
;# But only if it visible
1680
if {[lsearch $earea_pages $gm_name] != -1} then {
1681
gui_edition_area_delete_page $gm_name
1682
gui_edit_relation $gm_name
1685
;# Update the links in the screen
1686
gm_relation_update_links $gm_name
1688
;# Goto Editing state
1689
gerwin_set_state "Editing"
1691
. configure -cursor hand1
1697
;# Set the second entity
1698
set gui_entity2 $gm_name
1700
;# Create the new relation
1701
set rname "relation$gerwin_relation_seq"
1702
incr gerwin_relation_seq
1703
gob_create_relation $rname {} {}
1704
gob_relation_add_entity $rname $gui_entity1 1 1
1705
gob_relation_add_entity $rname $gui_entity2 1 1
1707
;# Add the relations to the entities
1708
if {$gui_entity1 == $gui_entity2} then {
1709
;# Reflexive relation
1710
set gerwin_relation($rname,reflexive) 1
1711
gob_entity_add_relation $gui_entity1 $rname
1713
;# Non-reflexive relation
1714
gob_entity_add_relation $gui_entity1 $rname
1715
gob_entity_add_relation $gui_entity2 $rname
1719
;# Find an approximative good starting point
1721
if {$gui_entity1 != $gui_entity2} then {
1722
;# Non reflexive relation
1723
set bbox1 [$gcanvas bbox taggroup-Entity-${gui_entity1}]
1724
set bbox2 [$gcanvas bbox taggroup-Entity-${gui_entity2}]
1727
[lindex $bbox1 0] + \
1728
(([lindex $bbox1 2] - [lindex $bbox1 0]) / 2)]
1731
[lindex $bbox1 1] + \
1732
(([lindex $bbox1 3] - [lindex $bbox1 1]) / 2)]
1735
[lindex $bbox2 0] + \
1736
(([lindex $bbox2 2] - [lindex $bbox2 0]) / 2)]
1739
[lindex $bbox2 1] + \
1740
(([lindex $bbox2 3] - [lindex $bbox2 1]) / 2)]
1743
[expr ($rp1x + (($rp2x - $rp1x) / 2))]
1745
[expr ($rp1y + (($rp2y - $rp1y) / 2))]
1748
;# Reflexive relation
1749
set spx [expr $gm_entity($gui_entity1,xpos) + 100]
1750
set spy [expr $gm_entity($gui_entity1,ypos) - 50]
1754
gm_draw_relation $rname $spx $spy
1756
if {$gui_entity1 == $gui_entity2} then {
1757
;# Reflexive relation
1758
gm_relation_update_links_reflexive $rname
1760
;# No reflexive relation
1761
gm_relation_update_links $rname
1764
;# Goto Editing state
1765
gerwin_set_state "Editing"
1767
. configure -cursor hand1
1770
"Inserting entity" {
1772
;# Get the coords onto the widget
1773
set xpos [${gcanvas} canvasx $xpos]
1774
set ypos [${gcanvas} canvasy $ypos]
1776
;# Create a new entity, with a sequential name and
1777
;# Without any attribute, and with the key empty.
1778
set ename "entity$gerwin_entity_seq"
1779
incr gerwin_entity_seq
1780
gob_create_entity $ename {} {} {}
1783
gm_draw_entity $ename $xpos $ypos
1785
;# Goto Editing state
1786
gerwin_set_state "Editing"
1788
. configure -cursor hand1
1794
;# Get the coords onto the widget
1795
set xpos [${gcanvas} canvasx $xpos]
1796
set ypos [${gcanvas} canvasy $ypos]
1798
;# Now, figure out what WGOB we want to delete
1799
set wgob [${gcanvas} find closest $xpos $ypos]
1802
;# Get the taggroup tag from the WGOB
1803
set wgobtags [${gcanvas} gettags $wgob]
1804
set index [lsearch -glob $wgobtags "taggroup-*"]
1805
set taggroup [lindex $wgobtags $index]
1807
;# Get the object name and type from the taggroup
1808
regsub {taggroup-([^-]+)-.+} $taggroup "\\1" gm_type
1809
regsub {taggroup-[^-]+-(.+)} $taggroup "\\1" gm_name
1811
set gerwin_obj_moving $gm_name
1812
set gerwin_obj_type_moving $gm_type
1814
set gerwin_premov_x $xpos
1815
set gerwin_premov_y $ypos
1816
set gerwin_premov_object $taggroup
1822
;# Get the coords onto the widget
1823
set xpos [${gcanvas} canvasx $xpos]
1824
set ypos [${gcanvas} canvasy $ypos]
1826
;# Now, figure out what WGOB we want to delete
1827
set wgob [${gcanvas} find closest $xpos $ypos]
1830
;# Get the taggroup tag from the WGOB
1831
set wgobtags [${gcanvas} gettags $wgob]
1832
set index [lsearch -glob $wgobtags "taggroup-*"]
1833
set taggroup [lindex $wgobtags $index]
1835
;# Get the object name and type from the taggroup
1836
regsub {taggroup-([^-]+)-.+} $taggroup "\\1" gm_type
1837
regsub {taggroup-[^-]+-(.+)} $taggroup "\\1" gm_name
1839
;# Switch over the type
1844
gui_edit_relation $gm_name
1850
gui_edit_entity $gm_name
1859
;# Get the coords onto the widget
1860
set xpos [${gcanvas} canvasx $xpos]
1861
set ypos [${gcanvas} canvasy $ypos]
1863
;# Now, figure out what WGOB we want to delete
1864
set wgob [${gcanvas} find closest $xpos $ypos]
1867
;# Get the taggroup tag from the WGOB
1868
set wgobtags [${gcanvas} gettags $wgob]
1869
set index [lsearch -glob $wgobtags "taggroup-*"]
1870
set taggroup [lindex $wgobtags $index]
1872
;# Get the object name and type from the taggroup
1873
regsub {taggroup-([^-]+)-.+} $taggroup "\\1" gm_type
1874
regsub {taggroup-[^-]+-(.+)} $taggroup "\\1" gm_name
1876
;# Switch over the type
1880
;# Delete the relation from the canvas
1881
gm_delete_relation $gm_name
1883
;# Delete the relation from all entities that haves that relation registered
1884
foreach e [gob_relation_get_entities $gm_name] {
1886
gob_entity_delete_relation [lindex $e 0] $gm_name
1890
;# Delete relation's links
1891
${gcanvas} delete "taggroup-Link-$gm_name"
1894
gob_delete_relation $gm_name
1896
;# Delete the relation page from the editionarea
1897
gui_edition_area_delete_page $gm_name
1901
;# Delete the entity from the canvas
1902
gm_delete_entity $gm_name
1904
;# Delete all relations with num_entities equal to two
1905
foreach r [gob_entity_get_relations $gm_name] {
1907
if {[gob_relation_get_num_entities $r] == 2} then {
1909
;# Delete the relation from the canvas
1910
gm_delete_relation $r
1912
;# Delete the relation from all entities that haves that relation registered
1913
foreach e [gob_relation_get_entities $r] {
1915
gob_entity_delete_relation [lindex $e 0] $r
1919
;# Delete relation's links
1920
${gcanvas} delete "taggroup-Link-$r"
1923
gob_delete_relation $r
1925
;# Delete the relation page from the editionarea
1926
gui_edition_area_delete_page $r
1931
;# Quit the entity from the relation
1932
gob_relation_delete_entity $r $gm_name
1934
;# Update the relation links
1935
;# Note that this relation can not be reflexive
1936
gm_relation_update_links $r
1943
gob_delete_entity $gm_name
1945
;# Delete the entity page from the editionarea
1946
gui_edition_area_delete_page $gm_name
1958
;# gui_edition_area_delete_page PNAME
1960
;# Deletes the page named PNAME from the edition area
1962
proc gui_edition_area_delete_page {pname} {
1966
global gerwin_editionarea
1968
set userframe [${gmainframe} getframe]
1970
;# Find the page to delete
1971
set index [lsearch $earea_pages $pname]
1973
if {$index != -1} then {
1975
set w [${gerwin_editionarea} getframe $pname]
1976
;#set w [${userframe}.editionarea getframe $pname]
1979
;# Delete the page from the list
1980
set earea_pages [lreplace $earea_pages $index $index]
1982
;# Update the notebook
1983
${gerwin_editionarea} delete $pname
1984
;#${userframe}.editionarea delete $pname
1986
;# Destroy the widgets
1994
;# gui_attribute_is_not_key LISTBOX ENTITY
1996
;# Remove the current LISTBOX selection from the ENTITY key
1998
proc gui_attribute_is_not_key {lb entity} {
2001
global gerwin_relation
2003
set attribute [$lb curselection]
2005
if {! [string equal $attribute ""]} then {
2007
set attribute [$lb get $attribute]
2009
gob_entity_delete_attribute_from_key $entity $attribute
2010
set xpos $gm_entity($entity,xpos)
2011
set ypos $gm_entity($entity,ypos)
2012
gm_delete_entity $entity
2013
gm_draw_entity $entity $xpos $ypos
2015
foreach r [gob_entity_get_relations $entity] {
2017
if {$gerwin_relation($r,reflexive)} then {
2018
gm_relation_update_links_reflexive $r
2020
gm_relation_update_links $r
2028
;# gui_attribute_delete_relation LISTBOX RELATION
2030
;# Delete the LISTBOX selected attribute from RELATION
2032
proc gui_attribute_delete_relation {lb relation} {
2035
global gerwin_relation
2036
global gerwin_editionarea
2038
set attribute [$lb curselection]
2040
if {! [string equal $attribute ""]} then {
2042
set attribute [$lb get $attribute]
2043
set vattribute $attribute
2045
# Support delete or Edit
2046
set editframe [${gerwin_editionarea} getframe $relation]
2047
set aframe [${editframe}.attributes getframe]
2049
${aframe}.nattribute.faux.ftop.label configure -text $vattribute
2051
set dfr [${aframe}.nattribute.faux.fdown.domframe getframe]
2052
${dfr}.label configure -text [gob_relation_get_attribute_domain $relation $vattribute]
2056
gob_relation_delete_attribute $relation $attribute
2057
set xpos $gm_relation($relation,xpos)
2058
set ypos $gm_relation($relation,ypos)
2059
gm_delete_relation $relation
2060
gm_draw_relation $relation $xpos $ypos
2061
gui_edition_area_delete_page $relation
2062
gui_edit_relation $relation
2064
if {$gerwin_relation($relation,reflexive)} then {
2065
gm_relation_update_links_reflexive $relation
2067
gm_relation_update_links $relation
2077
;# gui_attribute_delete_entity LISTBOX ENTITY
2079
;# Delete the LISTBOX selected attribute from ENTITY
2081
proc gui_attribute_delete_entity {lb entity} {
2084
global gerwin_relation
2085
global gerwin_editionarea
2087
set attribute [$lb curselection]
2091
if {! [string equal $attribute ""]} then {
2093
set vattribute [$lb get $attribute]
2095
# Support delete or Edit
2096
set editframe [${gerwin_editionarea} getframe $entity]
2097
set aframe [${editframe}.attributes getframe]
2099
${aframe}.nattribute.faux.ftop.label configure -text $vattribute
2101
set dfr [${aframe}.nattribute.faux.fdown.domframe getframe]
2102
${dfr}.label configure -text [gob_entity_get_attribute_domain $entity $vattribute]
2105
set attribute [$lb get $attribute]
2107
gob_entity_delete_attribute $entity $attribute
2108
set xpos $gm_entity($entity,xpos)
2109
set ypos $gm_entity($entity,ypos)
2110
gm_delete_entity $entity
2111
gm_draw_entity $entity $xpos $ypos
2112
gui_edition_area_delete_page $entity
2113
gui_edit_entity $entity
2115
foreach r [gob_entity_get_relations $entity] {
2117
if {$gerwin_relation($r,reflexive)} then {
2118
gm_relation_update_links_reflexive $r
2120
gm_relation_update_links $r
2130
;# gui_attribute_is_key LISTBOX ENTITY
2132
;# Add the attribute selected in LISTBOX as a new key on ENTITY
2134
proc gui_attribute_is_key {lb entity} {
2137
global gerwin_relation
2139
set attribute [$lb curselection]
2141
if {! [string equal $attribute ""]} then {
2143
set attribute [$lb get $attribute]
2145
;# We exit if the attribute is already a key
2146
if {[gob_entity_is_key $entity $attribute]} then {
2151
gob_entity_add_attribute_to_key $entity $attribute
2152
set xpos $gm_entity($entity,xpos)
2153
set ypos $gm_entity($entity,ypos)
2154
gm_delete_entity $entity
2155
gm_draw_entity $entity $xpos $ypos
2157
foreach r [gob_entity_get_relations $entity] {
2159
if {$gerwin_relation($r,reflexive)} then {
2160
gm_relation_update_links_reflexive $r
2162
gm_relation_update_links $r
2172
;# gui_edit_relation_add_attribute RELATION
2174
;# Add a new attribute with ANAME and ADOMAIN to RELATION
2176
;# ANAME and ADOMAIN cannot be emtpy.
2177
;# All blanks in ANAME and ADOMAIN are transformed to "-" characters.
2179
proc gui_edit_relation_add_attribute {relation} {
2182
global gerwin_relation
2184
set aname $gm_relation($relation,nattribute)
2185
set adomain $gm_relation($relation,ndomain)
2187
;# First of all, make sure both ANAME and ADOMAIN are not empty
2188
if {($aname == "")} then {
2190
gui_notice "Please fill the Name field if you want to add an attribute to the relation."
2194
if {($adomain == "")} then {
2196
gui_notice "Please fill the Domain field if you want to add an attribute to the relation."
2200
;# Replace all blanks with scores
2201
set aname [string map {{ } -} $aname]
2202
set adomain [string map {{ } -} $adomain]
2204
;# Add the attribute to the gob
2205
gob_relation_add_attribute $relation $aname $adomain
2207
set gm_relation($relation,ndomain) {}
2208
set gm_relation($relation,nattribute) {}
2210
set xpos $gm_relation($relation,xpos)
2211
set ypos $gm_relation($relation,ypos)
2213
gm_delete_relation $relation
2214
gm_draw_relation $relation $xpos $ypos
2216
if {$gerwin_relation($relation,reflexive)} then {
2218
gm_relation_update_links_reflexive $relation
2222
gm_relation_update_links $relation
2226
gui_edition_area_delete_page $relation
2227
gui_edit_relation $relation
2234
;# gui_edit_entity_add_attribute ENTITY
2236
;# Add a new attribute with ANAME and ADOMAIN to ENTITY
2238
;# ANAME and ADOMAIN cannot be emtpy.
2239
;# All blanks in ANAME and ADOMAIN are transformed to "-" characters.
2241
proc gui_edit_entity_add_attribute {entity} {
2244
global gerwin_relation
2246
set aname $gm_entity($entity,nattribute)
2247
set adomain $gm_entity($entity,ndomain)
2249
;# First of all, make sure both ANAME and ADOMAIN are not empty
2250
if {($aname == "")} then {
2252
gui_notice "Please fill the Name field if you want to add an attribute to the entity."
2256
if {($adomain == "")} then {
2258
gui_notice "Please fill the Domain field if you want to add an attribute to the entity."
2262
;# Replace all blanks with scores
2263
set aname [string map {{ } -} $aname]
2264
set adomain [string map {{ } -} $adomain]
2266
;# Add the attribute to the gob
2267
gob_entity_add_attribute $entity $aname $adomain
2269
set gm_entity($entity,ndomain) {}
2270
set gm_entity($entity,nattribute) {}
2272
set xpos $gm_entity($entity,xpos)
2273
set ypos $gm_entity($entity,ypos)
2275
gm_delete_entity $entity
2276
gm_draw_entity $entity $xpos $ypos
2278
foreach r [gob_entity_get_relations $entity] {
2280
if {$gerwin_relation($r,reflexive)} then {
2282
gm_relation_update_links_reflexive $r
2287
gm_relation_update_links $r
2292
gui_edition_area_delete_page $entity
2293
gui_edit_entity $entity
2301
;# gui_edit_relation_change_name RELATION
2303
;# Changes the name of RELATION to gm_relation(RELATION,nname)
2305
proc gui_edit_relation_change_name {relation} {
2310
global gerwin_relation
2312
;# See if the new name is empty
2313
if {$gm_relation($relation,nname) == ""} then {
2315
gui_notice "The name of the relation cannot be empty!"
2319
;# Change spaces for underscores
2320
set gm_relation($relation,nname) [string map {{ } _} $gm_relation($relation,nname)]
2322
if {([gob_entity_exist $gm_relation($relation,nname)] ||
2323
[gob_relation_exist $gm_relation($relation,nname)])} then {
2325
gui_notice "The name of any relation or entity must be unique in all the model!"
2329
;# Change the name of the gob
2330
gob_relation_change_name $relation $gm_relation($relation,nname)
2331
set nname $gm_relation($relation,nname)
2332
gui_edition_area_delete_page $relation
2334
gm_relation_change_name $relation $nname
2335
set gm_relation($relation,nname) {}
2337
gui_edit_relation $nname
2339
set xpos $gm_relation($nname,xpos)
2340
set ypos $gm_relation($nname,ypos)
2342
gm_delete_relation $nname
2343
${gcanvas} delete taggroup-Link-$relation
2344
gm_draw_relation $nname $xpos $ypos
2346
if {$gerwin_relation($nname,reflexive)} then {
2348
gm_relation_update_links_reflexive $nname
2352
gm_relation_update_links $nname
2359
;# gui_edit_entity_change_name ENTITY
2361
;# Changes the name of ENTITY to gm_entity(ENTITY,nname)
2364
proc gui_edit_entity_change_name {entity} {
2368
global gerwin_relation
2370
;# See if the new name is empty
2371
if {$gm_entity($entity,nname) == ""} then {
2373
gui_notice "The name of the entity cannot be empty!"
2377
;# Change spaces for underscores
2378
set gm_entity($entity,nname) [string map {{ } _} $gm_entity($entity,nname)]
2380
if {([gob_entity_exist $gm_entity($entity,nname)]) ||
2381
([gob_relation_exist $gm_entity($entity,nname)])} then {
2383
gui_notice "The name of any entity or relation must be unique in all the model!"
2387
;# Change the name of the gob
2388
gob_entity_change_name $entity $gm_entity($entity,nname)
2390
set nname $gm_entity($entity,nname)
2391
gui_edition_area_delete_page $entity
2393
;# Change the name in all relation edition areas
2394
foreach r [gob_entity_get_relations $nname] {
2396
if {[lsearch $earea_pages $r] != -1} then {
2398
gui_edition_area_delete_page $r
2399
gui_edit_relation $r
2404
gui_edit_entity $nname
2406
set xpos $gm_entity($entity,xpos)
2407
set ypos $gm_entity($entity,ypos)
2410
gm_entity_change_name $entity $nname
2411
gm_delete_entity $nname
2412
gm_draw_entity $nname $xpos $ypos
2414
foreach r [gob_entity_get_relations $nname] {
2416
;# TODO: change to simply gm_relation_update_links
2417
if {$gerwin_relation($r,reflexive)} then {
2418
gm_relation_update_links_reflexive $r
2420
gm_relation_update_links $r
2429
;# gui_edit_entity ENTITY
2431
;# Edit all aspects of a given entity, in a page on the
2434
proc gui_edit_entity {entity} {
2437
global gerwin_entity
2440
global gerwin_relation
2443
global gerwin_editionarea
2445
set userframe [${gmainframe} getframe]
2447
;# See if the entity already have a page in the edition area
2448
set index [lsearch $earea_pages $entity]
2449
if {$index != -1} then {
2451
;# Make the page visible
2452
${gerwin_editionarea} raise [lindex $earea_pages $index]
2453
;#${userframe}.editionarea raise [lindex $earea_pages $index]
2459
;# Create a new page for this entity
2460
lappend earea_pages $entity
2461
${gerwin_editionarea} insert end $entity -text $entity
2462
;#${userframe}.editionarea insert end $entity -text $entity
2464
;# Make the entries into the frame
2465
set editframe [${gerwin_editionarea} getframe $entity]
2466
;#set editframe [${userframe}.editionarea getframe $entity]
2469
;##### PROPERTIES FRAME
2471
TitleFrame ${editframe}.properties -side center -text "Entity Properties"
2472
set pframe [${editframe}.properties getframe]
2475
frame ${pframe}.nameline
2477
LabelEntry ${pframe}.nameline.label -label "Name: " -labelwidth 6 \
2478
-text $entity -textvariable gm_entity($entity,nname) \
2479
-helptext "Name of the entity"
2481
button ${pframe}.nameline.button -text "change" -relief groove \
2482
-command [list gui_edit_entity_change_name $entity]
2485
frame ${pframe}.typeline
2486
LabelEntry ${pframe}.typeline.label -label "Type:" -labelwidth 6 \
2487
-textvariable gm_entity($entity,ntype) \
2488
-helptext "Type of the entity"
2489
button ${pframe}.typeline.button -text "change" -relief groove \
2490
-command "gob_entity_change_type $entity \$gm_entity($entity,ntype); \
2491
set ttype \$gm_entity($entity,ntype) ; \
2492
gui_edition_area_delete_page $entity ; \
2493
gm_entity_change_type $entity \$gm_entity($entity,ntype); \
2494
gui_edit_entity $entity ; \
2495
set xpos \$gm_entity($entity,xpos); \
2496
set ypos \$gm_entity($entity,ypos); \
2497
gm_delete_entity $entity; \
2498
gm_draw_entity $entity \$xpos \$ypos ; " \
2504
pack ${pframe}.nameline.label -side left
2505
pack ${pframe}.nameline.button -side left
2508
pack ${pframe}.typeline.label -side left
2509
pack ${pframe}.typeline.button -side left
2511
pack ${pframe}.nameline -side top
2512
pack ${pframe}.typeline -side top
2513
pack ${pframe} -side left -anchor nw
2515
;#### ATTRIBUTES FRAME
2517
TitleFrame ${editframe}.attributes -side center -text "Attributes"
2518
set aframe [${editframe}.attributes getframe]
2520
frame ${aframe}.nattribute
2521
label ${aframe}.nattribute.label -text "New Attribute"
2522
frame ${aframe}.nattribute.faux
2523
frame ${aframe}.nattribute.faux.ftop
2524
frame ${aframe}.nattribute.faux.fdown
2525
LabelEntry ${aframe}.nattribute.faux.ftop.label -label "Name:" -labelwidth 7 \
2526
-labelanchor w -textvariable gm_entity($entity,nattribute) \
2527
-helptext "name for the new attribute"
2529
# LabelEntry ${aframe}.nattribute.faux.fdown.label -label "Domain:" -labelwidth 7 \
2530
# -labelanchor w -textvariable gm_entity($entity,ndomain) \
2531
# -helptext "domain for the new attribute"
2533
LabelFrame ${aframe}.nattribute.faux.fdown.domframe -text "Domain:" \
2536
set dfr [${aframe}.nattribute.faux.fdown.domframe getframe]
2538
ComboBox $dfr.label -editable true \
2539
-textvariable gm_entity($entity,ndomain) \
2540
-helptext "domain for the new attribute" \
2542
-values {varchar(8) varchar(16) varchar(32) int bigint text date}
2544
pack $dfr.label -side top -anchor e
2548
Button ${aframe}.nattribute.button -text "Add" -relief groove \
2549
-command [list gui_edit_entity_add_attribute $entity]
2552
Separator ${aframe}.sep1 -orient vertical
2554
frame ${aframe}.attributes
2556
frame ${aframe}.attributes.frame
2557
scrollbar ${aframe}.attributes.frame.scrollbar \
2558
-command [list ${aframe}.attributes.frame.lbox yview]
2562
set lb [listbox ${aframe}.attributes.frame.lbox \
2563
-yscrollcommand [list ${aframe}.attributes.frame.scrollbar set]]
2565
;# Insert the listbox elements
2566
foreach a [gob_entity_get_attributes $entity] {
2568
set aname [lindex $a 0]
2569
;# Make the embedded window
2570
$lb insert end $aname
2576
set bbox [ButtonBox ${aframe}.bbox -spacing 0 -padx 1 -pady 0 \
2579
${bbox} add -text "Is key" -command [list gui_attribute_is_key $lb $entity] -relief groove
2580
${bbox} add -text "Is not key" -command [list gui_attribute_is_not_key $lb $entity] -relief groove
2581
${bbox} add -text "Del/Edit" -command [list gui_attribute_delete_entity $lb $entity] -relief groove
2583
pack ${aframe}.nattribute.label -side top
2584
pack ${aframe}.nattribute.faux.ftop.label -side top -anchor w
2585
pack ${aframe}.nattribute.faux.ftop -side top
2586
pack ${aframe}.nattribute.faux.fdown.domframe -side top -anchor w
2587
pack ${aframe}.nattribute.faux.fdown -side top
2588
pack ${aframe}.nattribute.faux -side left
2589
pack ${aframe}.nattribute.button -side right
2592
pack ${aframe}.nattribute -side left
2594
pack ${aframe}.sep1 -fill y -padx 8 -side left
2596
pack ${aframe}.attributes.frame.scrollbar -side right -fill y
2597
pack ${aframe}.attributes.frame.lbox -side left
2598
pack ${aframe}.attributes.frame
2600
pack ${aframe}.attributes -side left
2602
pack ${aframe}.bbox -side right
2604
button ${editframe}.quit -text "Close page" -relief groove \
2605
-command "destroy ${editframe} ; \
2606
gui_edition_area_delete_page $entity"
2609
pack ${editframe}.properties -side left -fill both -padx 10
2610
pack ${editframe}.attributes -side left -fill both -padx 10
2611
pack ${editframe}.quit -side right
2615
;# Make the page visible
2616
${gerwin_editionarea} raise $entity
2618
;# Scale the notebook
2619
NoteBook::compute_size ${gerwin_editionarea}
2623
;# gui_edit_relation
2625
;# Edit all aspects of a given relation, in a page on the
2628
proc gui_edit_relation {relation} {
2631
global gerwin_relation
2636
global gerwin_editionarea
2638
set userframe [${gmainframe} getframe]
2640
;# See if the relation already have a page in the edition area
2641
set index [lsearch $earea_pages $relation]
2642
if {$index != -1} then {
2644
;# Make the page visible
2645
${gerwin_editionarea} raise [lindex $earea_pages $index]
2646
;#${userframe}.editionarea raise [lindex $earea_pages $index]
2651
;# Create a new page for this relation
2652
lappend earea_pages $relation
2653
${gerwin_editionarea} insert end $relation -text $relation
2654
;#${userframe}.editionarea insert end $relation -text $relation
2656
;# Make the entries into the frame
2657
set editframe [${gerwin_editionarea} getframe $relation]
2658
;#set editframe [${userframe}.editionarea getframe $relation]
2660
;##### PROPERTIES FRAME
2662
TitleFrame ${editframe}.properties -side center -text "Relation Properties"
2663
set pframe [${editframe}.properties getframe]
2666
frame ${pframe}.nameline
2668
LabelEntry ${pframe}.nameline.label -label "Name: " -labelwidth 6 \
2669
-text $relation -textvariable gm_relation($relation,nname) \
2670
-helptext "Name of the relation"
2672
button ${pframe}.nameline.button -text "change" -relief groove \
2673
-command [list gui_edit_relation_change_name $relation]
2677
pack ${pframe}.nameline.label -side left
2678
pack ${pframe}.nameline.button -side left
2679
pack ${pframe}.nameline -side top
2682
;# RELATION ENTITIES and cardinality (entities 0 and 1 only)
2683
frame ${pframe}.cards
2686
if {[gob_relation_get_num_entities $relation] > 2} then {
2687
;# Show a short label
2688
;#label ${pframe}.cards.label -text "All entitities cardinality X/N"
2689
;#pack ${pframe}.cards.label
2692
;# Binary relation: show cardinality
2694
frame ${pframe}.cards.entity1
2696
set entities [gob_relation_get_entities $relation]
2697
set entity1_name [lindex [lindex $entities 0] 0]
2698
set entity1_mincard [lindex [lindex [lindex $entities 0] 1] 0]
2699
set entity1_maxcard [lindex [lindex [lindex $entities 0] 1] 1]
2700
set entity2_name [lindex [lindex $entities 1] 0]
2701
set entity2_mincard [lindex [lindex [lindex $entities 1] 1] 0]
2702
set entity2_maxcard [lindex [lindex [lindex $entities 1] 1] 1]
2704
Label ${pframe}.cards.entity1.ename -text $entity1_name
2706
;# Set up the variables
2707
set gerwin_relation($relation,e1mincard) $entity1_mincard
2708
set gerwin_relation($relation,e1maxcard) $entity1_maxcard
2711
radiobutton ${pframe}.cards.entity1.rbmin0 -text "0" \
2712
-variable gerwin_relation($relation,e1mincard) -value 0 \
2713
-command "gob_relation_set_entity_min_card $relation $entity1_name \$gerwin_relation($relation,e1mincard) ; \
2714
set xpos \$gm_relation($relation,xpos); \
2715
set ypos \$gm_relation($relation,ypos); \
2716
gm_delete_relation $relation ; \
2717
gm_draw_relation $relation \$xpos \$ypos ; \
2718
if {\$gerwin_relation($relation,reflexive)} then {
2719
gm_relation_update_links_reflexive $relation
2721
gm_relation_update_links $relation
2724
radiobutton ${pframe}.cards.entity1.rbmin1 -text "1" \
2725
-variable gerwin_relation($relation,e1mincard) -value 1 \
2726
-command "gob_relation_set_entity_min_card $relation $entity1_name \$gerwin_relation($relation,e1mincard) ; \
2727
set xpos \$gm_relation($relation,xpos); \
2728
set ypos \$gm_relation($relation,ypos); \
2729
gm_delete_relation $relation ; \
2730
gm_draw_relation $relation \$xpos \$ypos ; \
2731
if {\$gerwin_relation($relation,reflexive)} then {
2732
gm_relation_update_links_reflexive $relation
2734
gm_relation_update_links $relation
2738
label ${pframe}.cards.entity1.sep -text "/"
2741
radiobutton ${pframe}.cards.entity1.rbmax1 -text "1" \
2742
-variable gerwin_relation($relation,e1maxcard) -value 1 \
2743
-command "gob_relation_set_entity_max_card $relation $entity1_name \$gerwin_relation($relation,e1maxcard) ; \
2744
set xpos \$gm_relation($relation,xpos); \
2745
set ypos \$gm_relation($relation,ypos); \
2746
gm_delete_relation $relation ; \
2747
gm_draw_relation $relation \$xpos \$ypos ; \
2748
if {\$gerwin_relation($relation,reflexive)} then {
2749
gm_relation_update_links_reflexive $relation
2751
gm_relation_update_links $relation
2755
radiobutton ${pframe}.cards.entity1.rbmaxN -text "N" \
2756
-variable gerwin_relation($relation,e1maxcard) -value N \
2757
-command "gob_relation_set_entity_max_card $relation $entity1_name \$gerwin_relation($relation,e1maxcard) ; \
2758
set xpos \$gm_relation($relation,xpos); \
2759
set ypos \$gm_relation($relation,ypos); \
2760
gm_delete_relation $relation ; \
2761
gm_draw_relation $relation \$xpos \$ypos ; \
2762
if {\$gerwin_relation($relation,reflexive)} then {
2763
gm_relation_update_links_reflexive $relation
2765
gm_relation_update_links $relation
2768
;# Set gui_e1mincard and gui_e1maxcard as appropiate
2769
set qui_e1mincard [gob_relation_get_entity_min_card $relation $entity1_name]
2770
set gui_e1maxcard [gob_relation_get_entity_max_card $relation $entity1_name]
2773
pack ${pframe}.cards.entity1.ename -side top
2774
pack ${pframe}.cards.entity1.rbmin0 -side left
2775
pack ${pframe}.cards.entity1.rbmin1 -side left
2776
pack ${pframe}.cards.entity1.sep -side left
2777
pack ${pframe}.cards.entity1.rbmax1 -side left
2778
pack ${pframe}.cards.entity1.rbmaxN -side left
2780
pack ${pframe}.cards.entity1 -side left
2782
frame ${pframe}.cards.entity2
2784
;# Set up the variables
2785
set gerwin_relation($relation,e2mincard) $entity2_mincard
2786
set gerwin_relation($relation,e2maxcard) $entity2_maxcard
2788
Label ${pframe}.cards.entity2.ename -text $entity2_name
2791
radiobutton ${pframe}.cards.entity2.rbmin0 -text "0" \
2792
-variable gerwin_relation($relation,e2mincard) -value 0 \
2794
set entities \[gob_relation_get_entities $relation\]
2795
set e1 \[lindex \$entities 0\]
2796
set e2 \[lindex \$entities 1\]
2797
set e2name \[lindex \$e2 0\]
2798
set e2cards \[lindex \$e2 1\]
2799
set gerwin_relation($relation,entities) \[list \$e1 \[list \$e2name \[list \$gerwin_relation($relation,e2mincard) \[lindex \$e2cards 1\]\]\]\]
2800
set xpos \$gm_relation($relation,xpos); \
2801
set ypos \$gm_relation($relation,ypos); \
2802
gm_delete_relation $relation ; \
2803
gm_draw_relation $relation \$xpos \$ypos ; \
2804
if {\$gerwin_relation($relation,reflexive)} then {
2805
gm_relation_update_links_reflexive $relation
2807
gm_relation_update_links $relation
2810
radiobutton ${pframe}.cards.entity2.rbmin1 -text "1" \
2811
-variable gerwin_relation($relation,e2mincard) -value 1 \
2813
set entities \[gob_relation_get_entities $relation\]
2814
set e1 \[lindex \$entities 0\]
2815
set e2 \[lindex \$entities 1\]
2816
set e2name \[lindex \$e2 0\]
2817
set e2cards \[lindex \$e2 1\]
2818
set gerwin_relation($relation,entities) \[list \$e1 \[list \$e2name \[list \$gerwin_relation($relation,e2mincard) \[lindex \$e2cards 1\]\]\]\]
2819
set xpos \$gm_relation($relation,xpos); \
2820
set ypos \$gm_relation($relation,ypos); \
2821
gm_delete_relation $relation ; \
2822
gm_draw_relation $relation \$xpos \$ypos ; \
2823
if {\$gerwin_relation($relation,reflexive)} then {
2824
gm_relation_update_links_reflexive $relation
2826
gm_relation_update_links $relation
2830
label ${pframe}.cards.entity2.sep -text "/"
2833
radiobutton ${pframe}.cards.entity2.rbmax1 -text "1" \
2834
-variable gerwin_relation($relation,e2maxcard) -value 1 \
2836
set entities \[gob_relation_get_entities $relation\]
2837
set e1 \[lindex \$entities 0\]
2838
set e2 \[lindex \$entities 1\]
2839
set e2name \[lindex \$e2 0\]
2840
set e2cards \[lindex \$e2 1\]
2841
set gerwin_relation($relation,entities) \[list \$e1 \[list \$e2name \[list \[lindex \$e2cards 0\] \$gerwin_relation($relation,e2maxcard) \]\]\]
2842
set xpos \$gm_relation($relation,xpos); \
2843
set ypos \$gm_relation($relation,ypos); \
2844
gm_delete_relation $relation ; \
2845
gm_draw_relation $relation \$xpos \$ypos ; \
2846
if {\$gerwin_relation($relation,reflexive)} then {
2847
gm_relation_update_links_reflexive $relation
2849
gm_relation_update_links $relation
2853
radiobutton ${pframe}.cards.entity2.rbmaxN -text "N" \
2854
-variable gerwin_relation($relation,e2maxcard) -value N \
2856
set entities \[gob_relation_get_entities $relation\]
2857
set e1 \[lindex \$entities 0\]
2858
set e2 \[lindex \$entities 1\]
2859
set e2name \[lindex \$e2 0\]
2860
set e2cards \[lindex \$e2 1\]
2861
set gerwin_relation($relation,entities) \[list \$e1 \[list \$e2name \[list \[lindex \$e2cards 0\] \$gerwin_relation($relation,e2maxcard) \]\]\]
2862
set xpos \$gm_relation($relation,xpos); \
2863
set ypos \$gm_relation($relation,ypos); \
2864
gm_delete_relation $relation ; \
2865
gm_draw_relation $relation \$xpos \$ypos ; \
2867
if {\$gerwin_relation($relation,reflexive)} then {
2868
gm_relation_update_links_reflexive $relation
2870
gm_relation_update_links $relation
2874
;# Set gui_e2maxcard as appropiate
2875
set gui_e2maxcard [gob_relation_get_entity_card $relation $entity2_name]
2877
pack ${pframe}.cards.entity2.ename -side top
2878
pack ${pframe}.cards.entity2.rbmin0 -side left
2879
pack ${pframe}.cards.entity2.rbmin1 -side left
2880
pack ${pframe}.cards.entity2.sep -side left
2881
pack ${pframe}.cards.entity2.rbmax1 -side left
2882
pack ${pframe}.cards.entity2.rbmaxN -side left
2884
Separator ${pframe}.cards.sep2 -orient vertical
2885
pack ${pframe}.cards.sep2 -fill y -padx 4 -side left
2887
pack ${pframe}.cards.entity2 -side right
2890
pack ${pframe}.cards -side left
2892
pack ${pframe}.cards -side top
2895
pack ${pframe} -side left -anchor w
2897
;#### ATTRIBUTES FRAME
2899
TitleFrame ${editframe}.attributes -side center -text "Attributes"
2900
set aframe [${editframe}.attributes getframe]
2902
frame ${aframe}.nattribute
2903
label ${aframe}.nattribute.label -text "New Attribute"
2904
frame ${aframe}.nattribute.faux
2905
frame ${aframe}.nattribute.faux.ftop
2906
frame ${aframe}.nattribute.faux.fdown
2907
LabelEntry ${aframe}.nattribute.faux.ftop.label -label "Name:" -labelwidth 7 \
2908
-labelanchor w -textvariable gm_relation($relation,nattribute) \
2909
-helptext "name for the new attribute"
2910
# LabelEntry ${aframe}.nattribute.faux.fdown.label -label "Domain:" -labelwidth 7 \
2911
# -labelanchor w -textvariable gm_relation($relation,ndomain) \
2912
# -helptext "domain for the new attribute"
2914
LabelFrame ${aframe}.nattribute.faux.fdown.domframe -text "Domain:" \
2917
set dfr [${aframe}.nattribute.faux.fdown.domframe getframe]
2919
ComboBox $dfr.label -editable true \
2920
-textvariable gm_relation($relation,ndomain) \
2921
-helptext "domain for the new attribute" \
2923
-values {varchar(8) varchar(16) varchar(32) int bigint text date}
2925
pack $dfr.label -side top -anchor e
2927
Button ${aframe}.nattribute.button -text "Add" -relief groove \
2928
-command [list gui_edit_relation_add_attribute $relation]
2931
Separator ${aframe}.sep1 -orient vertical
2933
frame ${aframe}.attributes
2935
frame ${aframe}.attributes.frame
2936
scrollbar ${aframe}.attributes.frame.scrollbar \
2937
-command [list ${aframe}.attributes.frame.lbox yview]
2941
set lb [listbox ${aframe}.attributes.frame.lbox \
2942
-yscrollcommand [list ${aframe}.attributes.frame.scrollbar set]]
2944
;# Insert the listbox elements
2945
foreach a [gob_relation_get_attributes $relation] {
2947
set aname [lindex $a 0]
2948
;# Make the embedded window
2949
$lb insert end $aname
2955
set bbox [ButtonBox ${aframe}.bbox -spacing 0 -padx 1 -pady 0 \
2958
${bbox} add -text "Del/Edit" -command [list gui_attribute_delete_relation $lb $relation] -relief groove
2960
pack ${aframe}.nattribute.label -side top
2961
pack ${aframe}.nattribute.faux.ftop.label -side top -anchor w
2962
pack ${aframe}.nattribute.faux.ftop -side top
2963
pack ${aframe}.nattribute.faux.fdown.domframe -side top -anchor w
2964
pack ${aframe}.nattribute.faux.fdown -side top
2965
pack ${aframe}.nattribute.faux -side left
2966
pack ${aframe}.nattribute.button -side right
2969
pack ${aframe}.nattribute -side left
2971
pack ${aframe}.sep1 -fill y -padx 8 -side left
2973
pack ${aframe}.attributes.frame.scrollbar -side right -fill y
2974
pack ${aframe}.attributes.frame.lbox -side left
2975
pack ${aframe}.attributes.frame
2977
pack ${aframe}.attributes -side left
2979
pack ${aframe}.bbox -side right
2981
button ${editframe}.quit -text "Close page" -relief groove \
2982
-command "destroy ${editframe} ; \
2983
gui_edition_area_delete_page $relation"
2986
pack ${editframe}.properties -side left -fill both -padx 10
2987
pack ${editframe}.attributes -side left -fill both -padx 10
2988
pack ${editframe}.quit -side right
2992
;# Make the page visible
2993
${gerwin_editionarea} raise $relation
2994
;#${userframe}.editionarea raise $relation
2996
;# Scale the notebook
2997
NoteBook::compute_size ${gerwin_editionarea}
3002
;# gui_select_file_to_save_sql
3004
;# Select a file to save the generated SQL
3006
proc gui_select_file_to_save_sql {} {
3008
set filetypes {{"SQL File" {.sql}}}
3010
set f [tk_getSaveFile -initialdir "." \
3011
-filetypes $filetypes -title "Select a SQL file"]
3013
;# Switch over the result
3021
;# Put the .sql suffix if it is not done
3022
if {! [string match "*.sql" $f] } then {
3035
;# gui_select_file_to_save
3037
;# Select a file to save the project
3039
proc gui_select_file_to_save {} {
3041
set filetypes {{"Gerwin Project" {.ger}}}
3043
set f [tk_getSaveFile -initialdir "." \
3044
-filetypes $filetypes -title "Select a project file"]
3046
;# Switch over the result
3054
;# Put the .ger suffix if it is not done
3055
if {! [string match "*.ger" $f] } then {
3069
;# Edit the actual Project parameters
3070
;# Another edit widget can be put at the right of that.
3072
proc gui_edit_project {} {
3074
global gerwin_cproject_name
3075
global gerwin_cproject_file
3076
global gerwin_editionarea
3079
lappend earea_pages Project
3081
${gerwin_editionarea} insert end Project -text Project
3082
${gerwin_editionarea} raise Project
3084
set widget [${gerwin_editionarea} getframe Project]
3086
TitleFrame ${widget}.editframe -side center -text "Project Properties"
3088
set editwidget [${widget}.editframe getframe]
3091
frame ${editwidget}.nameline
3092
LabelEntry ${editwidget}.nameline.label -label "Project Name:" -labelwidth 16 \
3093
-textvariable gerwin_cproject_name \
3094
-helptext "Name of the current project" -width 50
3097
frame ${editwidget}.fileline
3098
LabelEntry ${editwidget}.fileline.label -label "Project File:" -labelwidth 16 \
3099
-textvariable gerwin_cproject_file \
3100
-helptext "Storage file of the current project" -editable false \
3103
Button ${editwidget}.fileline.button -text "select file" \
3104
-helptext "Select a file to store the project in" \
3105
-command "set tempfile \[gui_select_file_to_save\] ; \
3107
if {\$tempfile != {}} then {
3108
set gerwin_cproject_file \$tempfile
3109
gerwin_save_project_file
3115
frame ${editwidget}.authorline
3116
LabelEntry ${editwidget}.authorline.label -label "Project Author:" -labelwidth 16 \
3117
-textvariable gerwin_cproject_author \
3118
-helptext "Author of the current project" -width 50
3120
pack ${editwidget}.nameline.label -side left -anchor w
3121
pack ${editwidget}.nameline -side top -anchor w
3123
pack ${editwidget}.fileline.label -side left -anchor w
3124
pack ${editwidget}.fileline.button -side left
3125
pack ${editwidget}.fileline -side top -anchor w
3127
pack ${editwidget}.authorline.label -side left -anchor w
3128
pack ${editwidget}.authorline -side top -anchor w
3130
pack ${editwidget} -side top -fill both -expand true
3132
pack ${widget}.editframe -side top ;#-fill both -expand true
3134
;# Scale the notebook
3135
NoteBook::compute_size ${gerwin_editionarea}
3141
;# gui_get_free_oct OBJ TYPE CUAD
3143
;# Get a free oct on CUAD for OBJ-TYPE
3145
proc gui_get_free_oct {obj type cuad} {
3147
global gerwin_entity
3152
;# oct for obj must be o2 or o1
3153
if {[gui_oct_is_busy $obj $type 1]} then {
3166
;# oct for obj must be o3 or o4
3167
if {[gui_oct_is_busy $obj $type 3]} then {
3179
;# oct for object 1 must be o5 or o6
3180
if {[gui_oct_is_busy $obj $type 5]} then {
3194
;# oct for object 1 must be o7 or o8
3195
if {[gui_oct_is_busy $obj $type 8]} then {
3214
;# gui_oct_is_busy OBJ TYPE OCT
3216
;# See if OCT is busy for OBJ-TYPE
3218
proc gui_oct_is_busy {obj type oct} {
3220
global gerwin_entity
3227
;# Get the oct array from the entity
3228
set octarray $gerwin_entity($obj,octs)
3230
if {[lindex $octarray [expr $oct - 1]] != ""} then {
3247
;# gui_get_link_point_from_oct {obj type oct}
3250
proc gui_get_link_point_from_oct {obj type oct} {
3252
global gerwin_entity
3261
;# Get the bbox of the entity
3262
set bbox [${gcanvas} bbox taggroup-$type-$obj]
3263
set x1 [lindex $bbox 0]
3264
set y1 [lindex $bbox 1]
3265
set x2 [lindex $bbox 2]
3266
set y2 [lindex $bbox 3]
3269
;# Calculate the link point based on the oct
3273
return [list $x2 [expr ($y1 + (($y2 - $y1) / 4))]]
3276
return [list [expr ($x1 + ((($x2 - $x1) / 4) * 3))] $y1]
3279
return [list [expr ($x1 + (($x2 - $x1) / 4))] $y1]
3282
return [list $x1 [expr ($y1 + (($y2 - $y1) / 4))]]
3285
return [list $x1 [expr ($y1 + ((($y2 - $y1) /4) * 3))]]
3288
return [list [expr ($x1 + (($x2 - $x1) / 4))] $y2]
3291
return [list [expr ($x1 + ((($x2 - $x1) / 4) * 3))]]
3294
return [list $x2 [expr ($y1 + ((($y2 - $y1) / 4) * 3))]]
3307
;# gui_add_link_to_oct TYPE1 OBJ1 TYPE2 OBJ2 OCT
3309
;# Add a link to OBJ2 to OBJ1's OCT
3311
proc gui_add_link_to_oct {type1 obj1 type2 obj2 oct} {
3313
global gerwin_entity
3316
;# Add the new link to gerwin_links
3317
lappend gerwin_links [list $type1 $obj1 $type2 $obj2]
3318
lappend gerwin_links [list $type2 $obj2 $type1 $obj1]
3325
set temp [lindex $gerwin_entity($obj1,octs) [expr $oct - 1]]
3326
lappend temp [list $type2 $obj2]
3327
set gerwin_entity($obj1,octs) \
3328
[lreplace $gerwin_entity($obj1,octs) [expr $oct - 1] [expr $oct - 1] $temp]
3338
;# gui_redraw_oct TYPE OBJ OCT
3340
;# Redraw all links on the OBJ oct named OCT
3342
proc gui_redraw_oct {type obj oct} {
3344
global gerwin_entity
3351
set oct_content [lindex $gerwin_entity($obj,octs) [expr $oct - 1]]
3353
;# Get the internal pad
3354
set nlinks [llength $oct_content]
3364
;# gui_link {TYPE1 OBJ1} {TYPE2 OBJ2}
3366
;# Makes and draw a link between OBJ1 and OBJ2
3369
proc gui_link {elem1 elem2} {
3371
global gerwin_entity
3376
set type1 [lindex $elem1 0]
3377
set type2 [lindex $elem2 0]
3378
set object1 [lindex $elem1 1]
3379
set object2 [lindex $elem2 1]
3382
set bbox1 [${gcanvas} bbox "taggroup-$type1-$object1"]
3383
set bbox2 [${gcanvas} bbox "taggroup-$type2-$object2"]
3386
set refpoint1x [lindex $bbox1 2]
3387
set refpoint1y [lindex $bbox1 3]
3388
set refpoint2x [lindex $bbox2 2]
3389
set refpoint2y [lindex $bbox2 3]
3392
set cuad1 [gui_get_cuad $refpoint1x $refpoint1y \
3393
$refpoint2x $refpoint2y]
3403
;# Depending of the cuad, we must find an oct link point for both
3406
set oct1 [gui_get_free_oct $object1 $type1 $cuad1]
3407
;# We get oct2 depending of oct1
3421
;# Add the new link to the links of both objects octs
3422
gui_add_link_to_oct $type1 $obj1 $type2 $obj2 $oct1
3423
gui_add_link_to_oct $type2 $obj2 $type1 $obj1 $oct2
3425
;# Redraw the octs links for both objects
3426
;#gui_redraw_oct $type1 $obj1 $oct1
3427
;#gui_redraw_oct $type2 $obj2 $oct2
3429
;# Get the link points
3430
set lpoint1 [gui_get_link_point_from_oct $object1 $type1 $oct1]
3431
set lp1x [lindex $lpoint1 0]
3432
set lp1y [lindex $lpoint1 1]
3433
set lpoint2 [gui_get_link_point_from_oct $object2 $type2 $oct2]
3434
set lp2x [lindex $lpoint2 0]
3435
set lp2y [lindex $lpoint2 1]
3437
;# Get the link's intermediate point
3438
;# It depend of the cuad
3460
${gcanvas} create line $lp1x $lp1y \
3463
-tag $type1-$object1-$type2-$object2
3469
;# gui_link_delete type1 object1 type2 object2
3474
proc gui_link_delete {type1 obj1 type2 obj2} {
3478
${gcanvas} delete $type1-$obj1-$type2-$obj2