1#  mapremote.tcl:
2#  Tcl code for the embedded variant. The bulk of the code here is for the
3#  GUI that gets the host and port number for the ECLiPSe side. When these
4#  are supplied by the user, the code then connects to the ECLiPSe side and
5#  calls map_init
6
7switch $tcl_platform(platform) {
8    unix {
9	set tkecl(ECLIPSEDIR) $env(ECLIPSEDIR)
10    }
11    windows {
12	package require registry
13	set tkecl(ECLIPSEDIR) [registry get \
14	    HKEY_LOCAL_MACHINE\\SOFTWARE\\IC-Parc\\Eclipse\\6.2 ECLIPSEDIR]
15    }
16    default {
17	error "$tcl_platform(platform) not supported"
18	exit
19    }
20}
21
22set lib_tcl_path [file join $tkecl(ECLIPSEDIR) lib_tcl]
23lappend auto_path $lib_tcl_path
24
25package require eclipse_tools
26package require remote_eclipse
27
28proc attach_remote_ec {} {
29    global map_remote
30
31    if {($map_remote(host) != "" && $map_remote(port) != "")} {
32	ec_remote_init $map_remote(host) $map_remote(port) map_init
33	set map_remote(connected) 1
34	destroy .e
35    }
36}
37
38
39proc quit {} {
40
41    if {![ec_running]} {
42	ec_disconnect tcl
43    }
44
45    destroy .
46}
47
48set map_remote(connected) 0
49set map_remote(host) localhost
50set map_remote(port) ""
51
52source [file join $lib_tcl_path "mapcolour.tcl"]
53
54foreach arg $argv {
55    switch -- $argstate {
56	flag {
57	    switch -exact -- $arg {
58		-h {set argstate host}
59		-p {set argstate port}
60		default: {error "Unknown flag $arg"}
61	    }
62	}
63	host {
64	    set map_remote(host) $arg
65	    set argstate flag
66	}
67	port {
68	    set map_remote(port) $arg
69	    set argstate flag
70	}
71    }
72}
73
74if {$map_remote(port) == ""} {
75
76    ;# popup a window to ask for host and port...
77    toplevel .e
78    wm title .e "Connecting to..."
79    pack [message .e.ins -justify center -aspect 350 -padx 10 -pady 10 -relief ridge -borderwidth 2 -text \
80  "Specify hostname and port number of ECLiPSe session to connect \
81   to (Use remote_connect/3)"] \
82    -expand true -fill both
83    pack [frame .e.host] -expand true -fill both
84    pack [label .e.host.l -text "Host:"] -side left
85    pack [entry .e.host.e -textvariable map_remote(host) -relief sunken] -side right
86    pack [frame .e.port] -expand true -fill both
87    pack [label .e.port.l -text "Port:"] -side left
88    pack [entry .e.port.e -textvariable map_remote(port) -relief sunken] -side right
89    pack [button .e.ok -text "OK" -command attach_remote_ec] -expand true -fill both -side bottom
90
91    wm title . "Map Colouring Demo (Remote Tcl Interface)"
92
93    bind .e.port.e <Return> attach_remote_ec
94    bind .e.port.e <Destroy> {if {!$map_remote(connected)} exit}
95
96    wm withdraw .
97    tkwait window .e
98    wm deiconify .
99}
100
101