File: xchan.g

package info (click to toggle)
genesis 2.1-1.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 14,288 kB
  • ctags: 10,667
  • sloc: ansic: 111,959; makefile: 2,240; yacc: 1,797; lex: 976; csh: 54; sh: 13
file content (200 lines) | stat: -rw-r--r-- 6,431 bytes parent folder | download | duplicates (2)
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
//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.
**********************************************************************/

/******************************************************************
      Stuff for connecting chans
******************************************************************/

// called from the chan when a proto of it is dropped onto a pool
// Must be called immediately after the chan has been created
function chanproto_to_pool_link(chan,pool,x,y,z)
	str chan,pool
	float x,y,z

		call /edit/draw/tree MOVECUSTOM {chan} {x} {y + 1} {z} 1
		setfield {chan} xtree_textfg_req {getfield {pool} xtree_fg_req}

		// numerically attach the chan to the pool
		addmsg {pool} {chan} NUMCHAN n
end

// Attaches the pool to the chan as a substrate
function pool_to_chan_add(pool,chan)
	str pool,chan

	echo in pool_to_chan_add with {chan} {pool}
	addmsg {chan} {pool} REAC A B
	addmsg {pool} {chan} SUBSTRATE n vol
	call /edit/draw/tree RESET
end

// Detaches the pool from the chan as a substrate
function pool_to_chan_drop(pool,chan)
	str pool,chan

	echo in pool_to_chan_drop with {chan} {pool}
	deletemsg {pool} 0 -find {chan} REAC
	deletemsg {chan} 0 -find {pool} SUBSTRATE
	call /edit/draw/tree RESET
end

// Attaches the pool to the chan as a product
function chan_to_pool_add(chan,pool)
	str chan,pool

	echo in chan_to_pool_add with {chan} {pool}
	addmsg {chan} {pool} REAC B A
	addmsg {pool} {chan} PRODUCT n vol
	call /edit/draw/tree RESET
end

// Detaches the pool from the chan as a product
function chan_to_pool_drop(chan,pool)
	str chan,pool

	echo in chan_to_pool_drop with {chan} {pool}
	deletemsg {pool} 0 -find {chan} REAC
	deletemsg {chan} 0 -find {pool} PRODUCT
	call /edit/draw/tree RESET
end

/******************************************************************
      Stuff for editing chan
******************************************************************/


function do_update_chaninfo
	str chan = {getfield /parmedit/chan elmpath}


	setfield /parmedit/chan/path value {getpath {chan} -head}
	setfield /parmedit/chan/name value {getpath {chan} -tail}
    setfield /parmedit/chan/n value {getfield {chan} n }
    setfield /parmedit/chan/perm value {getfield {chan} perm}
    setfield /parmedit/chan/gmax value {getfield {chan} gmax }
	setfield /parmedit/chan/notes initialtext {getfield {chan} notes}
	setfield /parmedit/chan/color value {getfield {chan} xtree_fg_req}
end

function make_xedit_chan
	create xform /parmedit/chan [{EX},{EY},{EW},270]
	addfield /parmedit/chan elmpath \
		-description "path of elm being edited"
	ce /parmedit/chan
	create xdialog path -wgeom 60% -title "Parent"
	create xdialog name -xgeom 60% -ygeom 0 -wgeom 40% -title "Name" \
		-script "set_item_name <w> <v>"
	create xdialog color [0%,0:name,50%,30] \
		-script "set_item_color <w> <v>"
	create xdialog n [50%,0:name,50%,30] \
		-script "set_field <w> <v>"
	create xdialog perm [0%,0:n,50%,30] \
		-script "set_field <w> <v>"
	create xdialog gmax [50%,0:n,50%,30] \
		-script "set_field <w> <v>"
	create xbutton savenotes -label NOTES [0,0:last,10%,130] \
		-script "save_item_notes <w>" -offbg gray
	create xtext notes [0:last,0:gmax,90%,130] -editable 1
	create xbutton UPDATE [0%,0:notes,50%,30] \
		-script "do_update_chaninfo"
	create xbutton HIDE [50%,0:notes,50%,30] \
		-script "save_item_notes <w>; xhide /parmedit/chan"
	ce /
end

function edit_chan(reac)
	str reac

	setfield /parmedit/chan elmpath {reac}
	do_update_chaninfo
	xshowontop /parmedit/chan
end

/******************************************************************
      Stuff for initializing chans
******************************************************************/

function kchanproto
	create concchan /chan
		setfield /chan \
			perm 0.1	\
			gmax 0.1

    addfield /chan notes -description "string for chan notes and refs"
    addfield /chan editfunc -description "func for chan edit"
    addfield /chan xtree_fg_req -description "color for chan icon"
    addfield /chan xtree_textfg_req -description "textcolor for chan icon"
    addfield /chan plotfield -description "field to plot"
    addfield /chan manageclass -description "Class that can manage it"
	addfield /chan link_to_manage -descript "func to link chan to manager"
 
    addobject kchan /chan \
        -author "Upi Bhalla Mt Sinai July 1994" \
        -description "concchan plus a notes field"
    setdefault kchan editfunc "edit_chan"
    setdefault kchan xtree_fg_req "brown"
    setdefault kchan xtree_textfg_req "white"
    setdefault kchan plotfield "n"
    setdefault kchan manageclass "kpool"
    setdefault kchan link_to_manage "chanproto_to_pool_link"
end

function xchanproto
	ce /control/lib/tree
	create xshape shape -autoindex \
		-fg black \
		-npts 30 \
		-coords  [1,0,0][1,.8,0][1,.8,0][.6,.8,0][.6,.8,0][.4,.6,0] \
		[.4,.6,0][.2,.8,0][.2,.8,0][-.2,.8,0][-.2,.8,0][-.2,0,0] \
		[-.2,0,0][1,0,0][.6,1,0][.2,1,0][.2,1,0][.4,.8,0][.4,.8.0] \
		[.6,1,0][-1,0,0][-1,.8,0][-1,.8,0][-.6,.8,0][-.6,.8,0] \
		[-.6,0,0][-.6,0,0][-1,0,0] \
		-linewidth 2 \
		-drawmode DrawSegments \
		-value "kchan" \
		-pixflags v -pixflags c \
		-script "edit_chan.D"

	copy {el ^}  /edit/draw/tree -autoindex
	setfield ^ \
		script "edit_chan.D"

    ce /
end


function init_xchan
    // set up the prototype
	kchanproto

	if (DO_X)
	
	    xchanproto
	
		// Set up the calls used to handle dragging chan to pool
		call /edit/draw/tree ADDMSGARROW "/kinetics/##[TYPE=kchan]" \
			"/kinetics/##[TYPE=kpool]" REAC kpool none -1 0 \
			"echo.p dragging <S> to <D> for chan product" \
			"chan_to_pool_add.p <S> <D>" \
			"chan_to_pool_drop.p <S> <D>"
		// This draws the arrow for the product, but flipped:
		call /edit/draw/tree ADDMSGARROW "/kinetics/##[TYPE=kpool]" \
			"/kinetics/##[TYPE=kchan]" PRODUCT kchan orange -1 1 \
			"" "" ""
		call /edit/draw/tree ADDMSGARROW "/kinetics/##[TYPE=kpool]" \
			"/kinetics/##[TYPE=kchan]" SUBSTRATE kchan orange -1 0 \
			"echo.p dragging <S> to <D> for chan substrate" \
			"pool_to_chan_add.p <S> <D>" \
			"pool_to_chan_drop.p <S> <D>"
	
	    // make the editor for chans
	    make_xedit_chan
	end
end	

/******************************************************************/