1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : GEN_nds.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in 2001 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // =============================================================== // |
---|
11 | |
---|
12 | #include "GEN.hxx" |
---|
13 | |
---|
14 | #include <nds.h> |
---|
15 | #include <item_sel_list.h> |
---|
16 | #include <awt_sel_boxes.hxx> |
---|
17 | #include <aw_msg.hxx> |
---|
18 | #include <aw_root.hxx> |
---|
19 | #include <aw_awar.hxx> |
---|
20 | #include <ad_cb.h> |
---|
21 | |
---|
22 | #define gen_assert(bed) arb_assert(bed) |
---|
23 | |
---|
24 | using namespace std; |
---|
25 | |
---|
26 | // Note: this file is based on ../AWT/AWT_nds.cxx |
---|
27 | |
---|
28 | #define GEN_NDS_COUNT 10 |
---|
29 | #define GEN_NDS_STRING_SIZE 4000 |
---|
30 | |
---|
31 | struct GEN_NodeTextBuilder { |
---|
32 | char buf[GEN_NDS_STRING_SIZE]; |
---|
33 | char zbuf[GEN_NDS_COUNT]; |
---|
34 | long lengths[GEN_NDS_COUNT]; |
---|
35 | long rek[GEN_NDS_COUNT]; |
---|
36 | char *dkeys[GEN_NDS_COUNT]; |
---|
37 | char *parsing[GEN_NDS_COUNT]; |
---|
38 | long count; |
---|
39 | int errorclip; |
---|
40 | }; |
---|
41 | |
---|
42 | static GEN_NodeTextBuilder *gen_nds_ms = 0; |
---|
43 | |
---|
44 | void GEN_make_node_text_init(GBDATA *gb_main) { |
---|
45 | GBDATA *gbz, *gbe; |
---|
46 | const char *sf, *sl; |
---|
47 | int count; |
---|
48 | |
---|
49 | sf = "flag1"; |
---|
50 | sl = "len1"; |
---|
51 | |
---|
52 | if (!gen_nds_ms) gen_nds_ms = (GEN_NodeTextBuilder *) GB_calloc(sizeof(GEN_NodeTextBuilder), 1); |
---|
53 | |
---|
54 | GBDATA *gb_arb_presets = GB_search(gb_main, "arb_presets", GB_CREATE_CONTAINER); |
---|
55 | count = 0; |
---|
56 | |
---|
57 | for (gbz = GB_entry(gb_arb_presets, "gene_viewkey"); gbz; gbz = GB_nextEntry(gbz)) { |
---|
58 | // toggle set ? |
---|
59 | if (GB_read_int(GB_entry(gbz, sf))) { |
---|
60 | freeset(gen_nds_ms->dkeys[count], GB_read_string(GB_entry(gbz, "key_text"))); |
---|
61 | if (GB_first_non_key_char(gen_nds_ms->dkeys[count])) { |
---|
62 | gen_nds_ms->rek[count] = 1; |
---|
63 | } |
---|
64 | else { |
---|
65 | gen_nds_ms->rek[count] = 0; |
---|
66 | } |
---|
67 | gen_nds_ms->lengths[count] = GB_read_int(GB_entry(gbz, sl)); |
---|
68 | gbe = GB_entry(gbz, "pars"); |
---|
69 | freenull(gen_nds_ms->parsing[count]); |
---|
70 | if (gbe && GB_read_string_count(gbe)>1) gen_nds_ms->parsing[count] = GB_read_string(gbe); |
---|
71 | count++; |
---|
72 | } |
---|
73 | } |
---|
74 | gen_nds_ms->errorclip = 0; |
---|
75 | gen_nds_ms->count = count; |
---|
76 | } |
---|
77 | |
---|
78 | char *GEN_make_node_text_nds(GBDATA *gb_main, GBDATA * gbd, int mode) { |
---|
79 | // if mode == 0 compress info else format info |
---|
80 | |
---|
81 | char *bp = gen_nds_ms->buf; |
---|
82 | gen_assert(gbd); |
---|
83 | |
---|
84 | long first = 0; |
---|
85 | for (long i = 0; i < gen_nds_ms->count; i++) { |
---|
86 | GBDATA *gbe; |
---|
87 | if (gen_nds_ms->rek[i]) { // hierarchical key |
---|
88 | gbe = GB_search(gbd, gen_nds_ms->dkeys[i], GB_FIND); |
---|
89 | } |
---|
90 | else { // flat entry |
---|
91 | gbe = GB_entry(gbd, gen_nds_ms->dkeys[i]); |
---|
92 | } |
---|
93 | |
---|
94 | if (!mode && !gbe) continue; |
---|
95 | if (!mode && first) { |
---|
96 | (*bp++) = ','; |
---|
97 | } |
---|
98 | (*bp++) = ' '; |
---|
99 | first++; |
---|
100 | if (gbe) { |
---|
101 | switch (GB_read_type(gbe)) { |
---|
102 | case GB_INT: |
---|
103 | if (mode) { |
---|
104 | char buf[20]; |
---|
105 | sprintf(buf, "%%%lii", gen_nds_ms->lengths[i]); |
---|
106 | sprintf(bp, buf, GB_read_int(gbe)); |
---|
107 | } |
---|
108 | else { |
---|
109 | sprintf(bp, "%li", GB_read_int(gbe)); |
---|
110 | } |
---|
111 | bp += strlen(bp); |
---|
112 | break; |
---|
113 | case GB_BYTE: |
---|
114 | if (mode) { |
---|
115 | char buf[20]; |
---|
116 | sprintf(buf, "%%%lii", gen_nds_ms->lengths[i]); |
---|
117 | sprintf(bp, buf, GB_read_byte(gbe)); |
---|
118 | } |
---|
119 | else { |
---|
120 | sprintf(bp, "%i", GB_read_byte(gbe)); |
---|
121 | } |
---|
122 | bp += strlen(bp); |
---|
123 | break; |
---|
124 | case GB_STRING: { |
---|
125 | char *pars = 0; |
---|
126 | const char *p = 0; |
---|
127 | |
---|
128 | if (gen_nds_ms->parsing[i]) { |
---|
129 | char *p2 = GB_read_string(gbe); |
---|
130 | pars = GB_command_interpreter(gb_main, p2, gen_nds_ms->parsing[i], gbd, 0); |
---|
131 | free(p2); |
---|
132 | |
---|
133 | if (!pars) { |
---|
134 | pars = strdup("<error>"); |
---|
135 | if (!gen_nds_ms->errorclip++) { |
---|
136 | aw_message(GB_await_error()); |
---|
137 | } |
---|
138 | } |
---|
139 | p = pars; |
---|
140 | } |
---|
141 | else { |
---|
142 | p = GB_read_char_pntr(gbe); |
---|
143 | } |
---|
144 | |
---|
145 | long dlen = gen_nds_ms->lengths[i]; |
---|
146 | if (dlen + (bp - gen_nds_ms->buf) + 256 > GEN_NDS_STRING_SIZE) { |
---|
147 | dlen = GEN_NDS_STRING_SIZE - 256 - (bp - gen_nds_ms->buf); |
---|
148 | } |
---|
149 | |
---|
150 | if (dlen> 0) { |
---|
151 | int len = strlen(p); |
---|
152 | long j = len; |
---|
153 | if (j > dlen) j = dlen; |
---|
154 | for (; j; j--) *bp++ = *p++; |
---|
155 | if (mode) { |
---|
156 | long post = dlen - len; |
---|
157 | while (post-- > 0) *(bp++) = ' '; |
---|
158 | } |
---|
159 | } |
---|
160 | free(pars); |
---|
161 | break; |
---|
162 | } |
---|
163 | case GB_FLOAT: |
---|
164 | sprintf(bp, "%4.4f", GB_read_float(gbe)); |
---|
165 | bp += strlen(bp); |
---|
166 | break; |
---|
167 | default: |
---|
168 | break; |
---|
169 | } |
---|
170 | } |
---|
171 | else if (mode) { |
---|
172 | long j = gen_nds_ms->lengths[i]; |
---|
173 | if (j + (bp - gen_nds_ms->buf) + 256 > GEN_NDS_STRING_SIZE) { |
---|
174 | j = GEN_NDS_STRING_SIZE - 256 - (bp - gen_nds_ms->buf); |
---|
175 | } |
---|
176 | for (; j > 0; j--) *(bp++) = ' '; |
---|
177 | } |
---|
178 | } |
---|
179 | *bp = 0; |
---|
180 | |
---|
181 | return NDS_mask_nonprintable_chars(gen_nds_ms->buf); |
---|
182 | } |
---|
183 | |
---|
184 | void GEN_create_nds_vars(AW_root *aw_root, AW_default awdef, GBDATA *gb_main, const DatabaseCallback& NDS_changed_callback) { |
---|
185 | GB_ERROR error = GB_push_transaction(gb_main); |
---|
186 | GBDATA *gb_arb_presets = GB_search(gb_main, "arb_presets", GB_CREATE_CONTAINER); |
---|
187 | GBDATA *gb_viewkey = 0; |
---|
188 | |
---|
189 | for (int i=0; i<GEN_NDS_COUNT && !error; i++) { |
---|
190 | char buf[256]; |
---|
191 | char *keystart = buf+sprintf(buf, "tmp/gene_viewkey_%i/", i); |
---|
192 | |
---|
193 | if (gb_viewkey) { |
---|
194 | gen_assert(GB_has_key(gb_viewkey, "gene_viewkey")); |
---|
195 | gb_viewkey = GB_nextEntry(gb_viewkey); |
---|
196 | } |
---|
197 | else { |
---|
198 | gb_viewkey = GB_entry(gb_arb_presets, "gene_viewkey"); |
---|
199 | } |
---|
200 | if (!gb_viewkey) { |
---|
201 | gb_viewkey = GB_create_container(gb_arb_presets, "gene_viewkey"); |
---|
202 | } |
---|
203 | |
---|
204 | if (!gb_viewkey) { |
---|
205 | error = GB_await_error(); |
---|
206 | } |
---|
207 | else { |
---|
208 | GB_add_callback(gb_viewkey, GB_CB_CHANGED, NDS_changed_callback); |
---|
209 | |
---|
210 | const char *default_key = 0; |
---|
211 | switch (i) { |
---|
212 | case 1: default_key = "pos_start"; break; |
---|
213 | case 2: default_key = "pos_stop"; break; |
---|
214 | case 3: default_key = "product"; break; |
---|
215 | default: default_key = "name"; break; |
---|
216 | } |
---|
217 | GBDATA *gb_key_text = GB_searchOrCreate_string(gb_viewkey, "key_text", default_key); |
---|
218 | if (!gb_key_text) error = GB_await_error(); |
---|
219 | else { |
---|
220 | strcpy(keystart, "key_text"); |
---|
221 | aw_root->awar_string(buf, "", awdef); |
---|
222 | aw_root->awar(buf)->map(gb_key_text); |
---|
223 | } |
---|
224 | } |
---|
225 | |
---|
226 | if (!error) { |
---|
227 | GBDATA *gb_pars = GB_searchOrCreate_string(gb_viewkey, "pars", ""); |
---|
228 | if (!gb_pars) error = GB_await_error(); |
---|
229 | else { |
---|
230 | strcpy(keystart, "pars"); |
---|
231 | aw_root->awar_string(buf, "", awdef); |
---|
232 | aw_root->awar(buf)->map(gb_pars); |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | if (!error) { |
---|
237 | GBDATA *gb_flag1 = GB_searchOrCreate_int(gb_viewkey, "flag1", i <= 2 ? 1 : 0); |
---|
238 | if (!gb_flag1) error = GB_await_error(); |
---|
239 | else { |
---|
240 | strcpy(keystart, "flag1"); |
---|
241 | aw_root->awar_int(buf, 0, awdef); |
---|
242 | aw_root->awar(buf)->map(gb_flag1); |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | if (!error) { |
---|
247 | GBDATA *gb_len1 = GB_searchOrCreate_int(gb_viewkey, "len1", 30); |
---|
248 | if (!gb_len1) error = GB_await_error(); |
---|
249 | else { |
---|
250 | strcpy(keystart, "len1"); |
---|
251 | aw_root->awar_int(buf, 0, awdef); |
---|
252 | aw_root->awar(buf)->set_minmax(0, GEN_NDS_STRING_SIZE); |
---|
253 | aw_root->awar(buf)->map(gb_len1); |
---|
254 | } |
---|
255 | } |
---|
256 | } |
---|
257 | |
---|
258 | if (!error) { |
---|
259 | GBDATA *gb_next; |
---|
260 | gen_assert(GB_has_key(gb_viewkey, "gene_viewkey")); |
---|
261 | while (!error && (gb_next = GB_nextEntry(gb_viewkey))) { |
---|
262 | error = GB_delete(gb_next); |
---|
263 | } |
---|
264 | } |
---|
265 | |
---|
266 | aw_root->awar_string("tmp/gene_viewkey/key_text", "", awdef); |
---|
267 | |
---|
268 | error = GB_end_transaction(gb_main, error); |
---|
269 | if (error) aw_message(error); |
---|
270 | } |
---|
271 | |
---|
272 | static void GEN_create_select_nds_window(AW_window *aww, char *key_text, AW_CL cgb_main) |
---|
273 | { |
---|
274 | #if defined(WARN_TODO) |
---|
275 | #warning make this function more general like popup_select_species_field_window |
---|
276 | #endif |
---|
277 | |
---|
278 | static AW_window *win = 0; |
---|
279 | AW_root *aw_root = aww->get_root(); |
---|
280 | aw_root->awar("tmp/gene_viewkey/key_text")->map(key_text); |
---|
281 | if (!win) { |
---|
282 | AW_window_simple *aws = new AW_window_simple; |
---|
283 | aws->init(aw_root, "NDS", "NDS_SELECT"); |
---|
284 | aws->load_xfig("awt/nds_sel.fig"); |
---|
285 | aws->button_length(13); |
---|
286 | |
---|
287 | aws->callback(AW_POPDOWN); |
---|
288 | aws->at("close"); |
---|
289 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
290 | |
---|
291 | create_selection_list_on_itemfields((GBDATA*)cgb_main, aws, "tmp/gene_viewkey/key_text", true, FIELD_FILTER_NDS, "scandb", "rescandb", GEN_get_selector(), 20, 10, SF_STANDARD, NULL); |
---|
292 | |
---|
293 | win = (AW_window*)aws; |
---|
294 | } |
---|
295 | win->activate(); |
---|
296 | } |
---|
297 | |
---|
298 | AW_window *GEN_open_nds_window(AW_root *aw_root, AW_CL cgb_main) |
---|
299 | { |
---|
300 | static AW_window_simple *aws = 0; |
---|
301 | if (!aws) { |
---|
302 | aws = new AW_window_simple; |
---|
303 | |
---|
304 | aws->init(aw_root, "GENE_NDS_PROPS", "Gene NDS"); |
---|
305 | aws->load_xfig("awt/nds.fig"); |
---|
306 | aws->auto_space(10, 5); |
---|
307 | |
---|
308 | aws->callback(AW_POPDOWN); |
---|
309 | aws->at("close"); |
---|
310 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
311 | |
---|
312 | aws->at("help"); |
---|
313 | aws->callback(makeHelpCallback("props_nds.hlp")); |
---|
314 | aws->create_button("HELP", "HELP", "H"); |
---|
315 | |
---|
316 | aws->button_length(13); |
---|
317 | int dummy, closey; |
---|
318 | aws->at_newline(); |
---|
319 | aws->get_at_position(&dummy, &closey); |
---|
320 | |
---|
321 | aws->create_button(0, "K"); |
---|
322 | |
---|
323 | aws->at_newline(); |
---|
324 | |
---|
325 | |
---|
326 | int showx, fieldselectx, fieldx, columnx, srtx, srtux; |
---|
327 | |
---|
328 | aws->auto_space(10, 0); |
---|
329 | |
---|
330 | int i; |
---|
331 | for (i=0; i<GEN_NDS_COUNT; i++) { |
---|
332 | char buf[256]; |
---|
333 | |
---|
334 | sprintf(buf, "tmp/gene_viewkey_%i/flag1", i); |
---|
335 | aws->get_at_position(&showx, &dummy); |
---|
336 | aws->create_toggle(buf); |
---|
337 | |
---|
338 | aws->button_length(20); |
---|
339 | sprintf(buf, "tmp/gene_viewkey_%i/key_text", i); |
---|
340 | aws->get_at_position(&fieldx, &dummy); |
---|
341 | aws->create_input_field(buf, 15); |
---|
342 | |
---|
343 | aws->button_length(0); |
---|
344 | aws->callback((AW_CB)GEN_create_select_nds_window, (AW_CL)strdup(buf), cgb_main); |
---|
345 | aws->get_at_position(&fieldselectx, &dummy); |
---|
346 | sprintf(buf, "SELECT_NDS_%i", i); |
---|
347 | aws->create_button(buf, "S"); |
---|
348 | |
---|
349 | sprintf(buf, "tmp/gene_viewkey_%i/len1", i); |
---|
350 | aws->get_at_position(&columnx, &dummy); |
---|
351 | aws->create_input_field(buf, 4); |
---|
352 | |
---|
353 | sprintf(buf, "tmp/gene_viewkey_%i/pars", i); |
---|
354 | const char *inputFieldAwarName = strdup(buf); |
---|
355 | |
---|
356 | aws->get_at_position(&srtx, &dummy); |
---|
357 | |
---|
358 | aws->button_length(0); |
---|
359 | |
---|
360 | aws->callback(makeWindowCallback(AWT_popup_select_srtaci_window, inputFieldAwarName)); |
---|
361 | sprintf(buf, "SELECT_SRTACI_%i", i); |
---|
362 | aws->create_button(buf, "S", "S"); |
---|
363 | |
---|
364 | aws->get_at_position(&srtux, &dummy); |
---|
365 | aws->create_input_field(inputFieldAwarName, 40); |
---|
366 | aws->at_newline(); |
---|
367 | } |
---|
368 | aws->at(showx, closey); |
---|
369 | |
---|
370 | aws->at_x(fieldselectx); |
---|
371 | aws->create_button(0, "SEL"); |
---|
372 | |
---|
373 | aws->at_x(showx); |
---|
374 | aws->create_button(0, "SHOW"); |
---|
375 | |
---|
376 | aws->at_x(fieldx); |
---|
377 | aws->create_button(0, "FIELD"); |
---|
378 | |
---|
379 | aws->at_x(columnx); |
---|
380 | aws->create_button(0, "WIDTH"); |
---|
381 | |
---|
382 | aws->at_x(srtx); |
---|
383 | aws->create_button(0, "SRT"); |
---|
384 | |
---|
385 | aws->at_x(srtux); |
---|
386 | aws->create_button(0, "ACI/SRT PROGRAM"); |
---|
387 | } |
---|
388 | return aws; |
---|
389 | } |
---|
390 | |
---|