| 12
 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
 
 | //genesis
/**********************************************************************
** This program is part of kinetikit and is
**           copyright (C) 1995-1997 Upinder S. Bhalla.
** It is made available under the terms of the GNU General Public License. 
** See the file COPYRIGHT for the full notice.
**********************************************************************/
/* By Upinder S. Bhalla, Mount Sinai School of Medicine */
// this file sets up the basic X interface for kkit
int auto_plot = 1
 
int EX = WINWID/2 - BORDER // x position for edit windows
int GH = WINHT/3 - BORDER  // height of graphs
int EY = GH // y position for edit windows
int EW = WINWID/2 - BORDER // width of edit windows
int TW = WINWID/2 - BORDER // Width of title bar.
int TH = 200 // height of title bar
int TB = TH + WMH + 2 * BORDER 
int EDW = WINWID/2 - BORDER // width of edit/draw window
int EDH = WINHT - TB - BORDER - WMH // height of edit/draw window
include xcontrol.g
include xcomparemodel.g
function do_warning(is_cline,text)
	int is_cline
	str text
	if (is_cline)
		echo {text}
	else 
		setfield /warning/label label {text}
		xshowontop /warning
		xflushevents
	end
end
function edit_object(elm)
	str elm
	echo in edit_object {elm}
end
function drag_from_lib(dest,destval,srcval,x,y,z)
	str dest,destval,srcval
	float x,y,z
	str destclass
	echo in drag_from_lib {dest} {destval} {srcval}
	if ({strncmp {dest} "/edit/draw" 10} == 0)
		if ({strlen {destval}} == 0)
			destclass = "group"
			destval = "/kinetics"
		else
			destclass = {getfield {destval} object->name}
		end
		echo srcval = {srcval} destclass = {destclass}
		if ({strcmp {getdefault {srcval} manageclass} {destclass}} == 0)
			create {srcval} {destval}/{srcval} -autoindex
			call /edit/draw/tree RESET
			if ({exists {el ^} "link_to_manage"})
				callfunc {getfield {el ^} link_to_manage} \
					{el ^} {destval} {x} {y} {z}
			else
				call /edit/draw/tree MOVECUSTOM {el ^} {x} {y} {z} 1
			end
		else
			do_warning 0 {{srcval} @ "s must be created on a " @ \
				{getdefault {srcval} manageclass}}
				return
		end
		/* Set the clock for the new element */
		useclock {el ^} {SIMCLOCK}
		/* Edit the new element */
		callfunc {getfield {el ^} editfunc} {el ^}
	end
end
function drag_from_edit(dest,srcval,x,y,z)
	str dest,srcval
	float x,y,z
	int movekids = 1
	// echo in drag_from_edit {src} {dest} {srcval}
	if ({exists {srcval} movealone})
		movekids = 1 - {getfield {srcval} movealone}
	end
		
	if ({strcmp {dest} "/edit/draw"} == 0)
		call /edit/draw/tree MOVECUSTOM {srcval} {x} {y} {z} {movekids}
	end
end
function edit_elm(elm)
	callfunc {getfield {elm} editfunc} {elm}
end
function edit_obj(obj)
	echo in edit_obj with {obj}
end
function make_xedit
	/* Create the editor form */
    create xform /edit [0,{TB},{EDW},{EDH}]
	create xcoredraw /edit/draw [0,0,100%,100%] \
		-xmin -5 -xmax 5 -ymin -5 -ymax 5 -fg black
	create xtree /edit/draw/tree
		setfield ^ \
			treemode custom \
			path "/kinetics/##[]" \
			hlmode none \
		script "edit_elm.D <v>; drag_from_edit.w <d> <S> <x> <y> <z>"
		/* get rid of the default settings */
		call ^ ADDMSGARROW "" "" "" "" none 0 0 "" "" ""
	disable /edit
//    xshow /edit
end
function make_xlibrary
	/* creating the library form */
	/* The lib is now located in /control */
	// create xform /lib [1,115,250,200]
	create xcoredraw /control/lib [0,0:runtime,100%,0:NULL.bottom] \
		-xmin -1 -xmax 8 -ymin -1 -ymax 1
	create xtree /control/lib/tree
	setfield /control/lib/tree \
		path "kpool kreac kenz stim group xtab kchan" \
		treemode obj_grid \
		orientation r \
		sizescale 0.4 \
		script "drag_from_lib.w <d> <D> <S> <x> <y> <z>; edit_obj.D <v>"
	disable /control/lib
	// xshow /lib
end
function make_xclipboard
	create xform /clipboard [255,115,250,200]
	create xcoredraw /clipboard/draw [0,0,100%,100%] \
		-xmin -10 -xmax 10  -ymin -3 -ymax 1.5 \
		-fg black
	create xtree /clipboard/draw/tree
	setfield /clipboard/draw/tree \
		path "/kclip/##[]" \
		treemode custom \
		sizescale 0.4 \
		script "drag_from_clip.w <d> <S> <x> <y> <z>; edit_elmD <v>"
	disable /clipboard
end
function do_copy(elm)
	str elm
	if ({strcmp {getpath {elm} -head} "/edit/draw"} == 0)
		copy  {elm} {elm}/.. -autoindex
	end
	/*
	str name
	foreach name ({el /edit/draw/tree -listname select_elist})
		copy {name} {name}/.. -autoindex
	end
	*/
	call /edit/draw/tree RESET
end
function do_delete(src,elm)
	str src,elm
	// echo deleting {elm} from {src}
	if (({strncmp {src} "/edit/draw/" 11} == 0))
		delete  {elm}
		call /edit/draw/tree RESET
	end
	/*
	str name
	foreach name ({el /edit/draw/tree -listname select_elist})
		delete {name}
	end
	*/
end
function make_xedittools
// This also uses /control/lib as the parent draw widget
	create xgif /control/lib/del -filename del.gif \
		-tx 7 \
		-script "do_delete.p <s> <S>"
end
function make_xwarning
    create xform /warning [100,400,700,100]
    create xlabel /warning/label -title "Warning" -hgeom 50%
    create xbutton /warning/done [40%,60,20%,30%] -label "OK" \
        -script "xhide /warning"
	disable /warning
end
function make_xinform
    create xform /inform [200,500,500,100]
    create xlabel /inform/label -title "hello" [0,0,100%,100%]
	create xbutton /inform/ok -title "OK" [40%,40%,20%,40%] \
    	 -script "xhide /inform"
	disable /inform
end
function do_inform(text)
	str text
	setfield /inform/label label {text}
	xshowontop /inform
	xflushevents
end
function set_field(widget,value)
	str widget,value
	str elm = {getfield {{widget} @ "/.."} elmpath}
	str field = {getfield {widget} name}
	setfield {elm} {field} {value}
end
function set_item_name(widget,value)
	str widget,value
	str elm = {getfield {widget}/.. elmpath}
	str nm = {getpath {elm} -tail}
	if ({strcmp {nm} {value}} == 0)
		return
	end
	if ({exists {elm}/../{value}})
		do_warning 0 {"Rename failed. Element " @ {nm} @ \
			" already exists."}
		return
	end
	move {elm} {elm}/../{value}
	callfunc {getfield {el ^} editfunc} {el ^}
	call /edit/draw/tree RESET
end
function save_item_notes(widget)
	str widget
	str elm = {getfield {{widget} @ "/.."} elmpath}
	call {widget}/../notes PROCESS
	setfield {elm} notes {getfield {widget}/../notes initialtext}
end
function set_item_color(widget,color)
	str widget,color
	str elm = {getfield {{widget} @ "/.."} elmpath}
	str kids
	str manager
	str elmclass = {getfield {elm} object->name}
/* We need to change the plot colors here */
/* Changing the color of the elm */
	setfield {elm} xtree_fg_req {color}
/* Changing the textcolor of the elm kids */
	foreach kids ({el {elm}/#[]})
		manager = {getfield {kids} manageclass}
		if ({strcmp {manager} {elmclass}} == 0)
			setfield {kids} xtree_textfg_req {color}
		end
	end
	call /edit/draw/tree RESET
end
function xbegin
	/* Set the global flag for the interface to 1 */
	/* build the colorscale */
	xcolorscale rainbow2
	/* set up the postscript stuff */
	setpostscript -filename "display.ps" -inverse 0
	make_xedit
	// make_xclipboard
	create neutral /parmedit
	disable /parmedit
	make_xwarning
	make_xinform
	make_xcontrol
	make_xlibrary
	make_xfile
	//make_xgraphs
	make_opencontrol
	make_plotcontrol
	make_pscontrol
	make_comparecontrol
	make_simcontrol
	make_simhelp
	make_xedittools
	make_editcontrol
	make_toolcontrol
	simobjdump xtree path script namemode sizescale
	simobjdump xcoredraw xmin xmax ymin ymax
	simobjdump xtext editable
end
function xmiddle
end
function xend
	xhide /about
	xshow /edit
	xshow /control
	xshow /graphs
	call /edit/draw/tree RESET
	call /control/lib/tree RESET
	setfield /edit/draw/tree sizescale 0.6
	setfield /control/lib/tree sizescale 0.4
end
 |