1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | |
---|
5 | #include <arbdb.h> |
---|
6 | #include <arbdbt.h> |
---|
7 | #include <ad_config.h> |
---|
8 | #include <aw_awars.hxx> |
---|
9 | #include <aw_root.hxx> |
---|
10 | #include <aw_device.hxx> |
---|
11 | #include <aw_window.hxx> |
---|
12 | |
---|
13 | #include "nt_edconf.hxx" |
---|
14 | |
---|
15 | #include <awt.hxx> |
---|
16 | #include <awt_canvas.hxx> |
---|
17 | #include <awt_tree.hxx> |
---|
18 | #include <awt_dtree.hxx> |
---|
19 | #include <awt_sel_boxes.hxx> |
---|
20 | |
---|
21 | #ifndef ARB_ASSERT_H |
---|
22 | #include <arb_assert.h> |
---|
23 | #endif |
---|
24 | #define nt_assert(bed) arb_assert(bed) |
---|
25 | |
---|
26 | extern GBDATA *GLOBAL_gb_main; |
---|
27 | |
---|
28 | static void init_config_awars(AW_root *root) { |
---|
29 | root->awar_string(AWAR_CONFIGURATION,"default_configuration",GLOBAL_gb_main); |
---|
30 | } |
---|
31 | |
---|
32 | // --------------------------- |
---|
33 | // class Store_species |
---|
34 | // --------------------------- |
---|
35 | // stores a amount of species: |
---|
36 | |
---|
37 | class Store_species |
---|
38 | { |
---|
39 | GBT_TREE *node; |
---|
40 | Store_species *next; |
---|
41 | public: |
---|
42 | Store_species(GBT_TREE *aNode) { |
---|
43 | node = aNode; |
---|
44 | next = 0; |
---|
45 | } |
---|
46 | ~Store_species(); |
---|
47 | |
---|
48 | Store_species* add(Store_species *list) { |
---|
49 | nt_assert(next==0); |
---|
50 | next = list; |
---|
51 | return this; |
---|
52 | } |
---|
53 | |
---|
54 | Store_species* remove() { |
---|
55 | Store_species *follower = next; |
---|
56 | next = 0; |
---|
57 | return follower; |
---|
58 | } |
---|
59 | |
---|
60 | GBT_TREE *getNode() const { return node; } |
---|
61 | |
---|
62 | void call(void (*aPizza)(GBT_TREE*)) const; |
---|
63 | }; |
---|
64 | |
---|
65 | Store_species::~Store_species() { |
---|
66 | delete next; |
---|
67 | } |
---|
68 | |
---|
69 | void Store_species::call(void (*aPizza)(GBT_TREE*)) const { |
---|
70 | aPizza(node); |
---|
71 | if (next) next->call(aPizza); |
---|
72 | } |
---|
73 | |
---|
74 | static void unmark_species(GBT_TREE *node) { |
---|
75 | nt_assert(node); |
---|
76 | nt_assert(node->gb_node); |
---|
77 | nt_assert(GB_read_flag(node->gb_node)!=0); |
---|
78 | GB_write_flag(node->gb_node, 0); |
---|
79 | } |
---|
80 | |
---|
81 | static void mark_species(GBT_TREE *node, Store_species **extra_marked_species) { |
---|
82 | nt_assert(node); |
---|
83 | nt_assert(node->gb_node); |
---|
84 | nt_assert(GB_read_flag(node->gb_node)==0); |
---|
85 | GB_write_flag(node->gb_node, 1); |
---|
86 | |
---|
87 | *extra_marked_species = (new Store_species(node))->add(*extra_marked_species); |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | /** Builds a configuration string from a tree. Returns the number of marked species */ |
---|
93 | /* Syntax: |
---|
94 | |
---|
95 | TAG 1 byte 'GFELS' |
---|
96 | |
---|
97 | G group |
---|
98 | F folded group |
---|
99 | E end of group |
---|
100 | L species |
---|
101 | S SAI |
---|
102 | |
---|
103 | String |
---|
104 | Seperator (char)1 |
---|
105 | |
---|
106 | X:: Y '\0' |
---|
107 | Y:: eps |
---|
108 | Y:: '\AL' 'Name' Y |
---|
109 | Y:: '\AS' 'Name' Y |
---|
110 | Y:: '\AG' 'Gruppenname' '\A' Y '\AE' |
---|
111 | Y:: '\AF' 'Gruppenname' '\A' Y '\AE' |
---|
112 | */ |
---|
113 | |
---|
114 | GBT_TREE *rightmost_leaf(GBT_TREE *node) { |
---|
115 | nt_assert(node); |
---|
116 | while (!node->is_leaf) { |
---|
117 | node = node->rightson; |
---|
118 | nt_assert(node); |
---|
119 | } |
---|
120 | return node; |
---|
121 | } |
---|
122 | |
---|
123 | GBT_TREE *left_neighbour_leaf(GBT_TREE *node) { |
---|
124 | if (node) { |
---|
125 | GBT_TREE *father = node->father; |
---|
126 | while (father) { |
---|
127 | if (father->rightson==node) { |
---|
128 | node = rightmost_leaf(father->leftson); |
---|
129 | nt_assert(node->is_leaf); |
---|
130 | if (!node->gb_node) { // Zombie |
---|
131 | node = left_neighbour_leaf(node); |
---|
132 | } |
---|
133 | return node; |
---|
134 | } |
---|
135 | node = father; |
---|
136 | father = node->father; |
---|
137 | } |
---|
138 | } |
---|
139 | return 0; |
---|
140 | } |
---|
141 | |
---|
142 | int nt_build_conf_string_rek(GB_HASH *used, GBT_TREE *tree, GBS_strstruct *memfile, |
---|
143 | Store_species **extra_marked_species, // all extra marked species are inserted here |
---|
144 | int use_species_aside, // # of species to mark left and right of marked species |
---|
145 | int *auto_mark, // # species to extra-mark (if not already marked) |
---|
146 | int marked_at_left, // # of species which were marked (looking to left) |
---|
147 | int *marked_at_right) // # of species which are marked (when returning from rekursion) |
---|
148 | { |
---|
149 | if (!tree) return 0; |
---|
150 | if (tree->is_leaf){ |
---|
151 | if (!tree->gb_node) { |
---|
152 | *marked_at_right = marked_at_left; |
---|
153 | return 0; // Zombie |
---|
154 | } |
---|
155 | |
---|
156 | if (!GB_read_flag(tree->gb_node)) { // unmarked species |
---|
157 | if (*auto_mark) { |
---|
158 | (*auto_mark)--; |
---|
159 | mark_species(tree, extra_marked_species); |
---|
160 | } |
---|
161 | else { |
---|
162 | *marked_at_right = 0; |
---|
163 | return 0; |
---|
164 | } |
---|
165 | } |
---|
166 | else { // marked species |
---|
167 | if (marked_at_left<use_species_aside) { |
---|
168 | // on the left side there are not as many marked species as needed! |
---|
169 | |
---|
170 | nt_assert(marked_at_left>=0); |
---|
171 | |
---|
172 | GBT_TREE *leaf_at_left = tree; |
---|
173 | int step_over = marked_at_left+1; // step over myself |
---|
174 | int then_mark = use_species_aside-marked_at_left; |
---|
175 | |
---|
176 | while (step_over--) { // step over self and over any adjacent, marked species |
---|
177 | leaf_at_left = left_neighbour_leaf(leaf_at_left); |
---|
178 | } |
---|
179 | |
---|
180 | Store_species *marked_back = 0; |
---|
181 | while (leaf_at_left && then_mark--) { // then additionally mark some species |
---|
182 | if (GB_read_flag(leaf_at_left->gb_node) == 0) { // if they are not marked yet |
---|
183 | mark_species(leaf_at_left, extra_marked_species); |
---|
184 | marked_back = (new Store_species(leaf_at_left))->add(marked_back); |
---|
185 | } |
---|
186 | leaf_at_left = left_neighbour_leaf(leaf_at_left); |
---|
187 | } |
---|
188 | |
---|
189 | while (marked_back) { |
---|
190 | GBS_chrcat(memfile,1); // Seperated by 1 |
---|
191 | GBS_strcat(memfile,"L"); |
---|
192 | GBS_strcat(memfile,marked_back->getNode()->name); |
---|
193 | GBS_write_hash(used,marked_back->getNode()->name,1); // Mark species |
---|
194 | |
---|
195 | Store_species *rest = marked_back->remove(); |
---|
196 | delete marked_back; |
---|
197 | marked_back = rest; |
---|
198 | } |
---|
199 | |
---|
200 | marked_at_left = use_species_aside; |
---|
201 | } |
---|
202 | // now use_species_aside species to left are marked! |
---|
203 | *auto_mark = use_species_aside; |
---|
204 | } |
---|
205 | |
---|
206 | GBS_chrcat(memfile,1); // Seperated by 1 |
---|
207 | GBS_strcat(memfile,"L"); |
---|
208 | GBS_strcat(memfile,tree->name); |
---|
209 | GBS_write_hash(used,tree->name,1); // Mark species |
---|
210 | |
---|
211 | *marked_at_right = marked_at_left+1; |
---|
212 | return 1; |
---|
213 | } |
---|
214 | |
---|
215 | long oldpos = GBS_memoffset(memfile); |
---|
216 | if (tree->gb_node && tree->name){ // but we are a group |
---|
217 | GBDATA *gb_grouped = GB_entry(tree->gb_node,"grouped"); |
---|
218 | GBS_chrcat(memfile,1); // Seperated by 1 |
---|
219 | if (gb_grouped && GB_read_byte(gb_grouped)) { |
---|
220 | GBS_strcat(memfile,"F"); |
---|
221 | }else{ |
---|
222 | GBS_strcat(memfile,"G"); |
---|
223 | } |
---|
224 | |
---|
225 | GBS_strcat(memfile,tree->name); |
---|
226 | } |
---|
227 | |
---|
228 | int right_of_leftson; |
---|
229 | long nspecies = nt_build_conf_string_rek(used, tree->leftson, memfile, extra_marked_species, use_species_aside, auto_mark, marked_at_left, &right_of_leftson); |
---|
230 | nspecies += nt_build_conf_string_rek(used, tree->rightson, memfile, extra_marked_species, use_species_aside, auto_mark, right_of_leftson, marked_at_right); |
---|
231 | |
---|
232 | if (tree->gb_node && tree->name){ // but we are a group |
---|
233 | GBS_chrcat(memfile,1); // Seperated by 1 |
---|
234 | GBS_chrcat(memfile,'E'); // Group end indicated by 'E' |
---|
235 | } |
---|
236 | |
---|
237 | if (!nspecies) { |
---|
238 | long newpos = GBS_memoffset(memfile); |
---|
239 | GBS_str_cut_tail(memfile,newpos-oldpos); // delete group info |
---|
240 | } |
---|
241 | return nspecies; |
---|
242 | } |
---|
243 | |
---|
244 | static GBS_strstruct *nt_build_sai_middle_file; |
---|
245 | static const char *nt_build_sai_last_group_name; |
---|
246 | |
---|
247 | long nt_build_sai_sort_strings(const char *k0,long v0,const char *k1,long v1){ |
---|
248 | AWUSE(v0); AWUSE(v1); |
---|
249 | return strcmp(k0,k1); |
---|
250 | } |
---|
251 | |
---|
252 | #ifdef __cplusplus |
---|
253 | extern "C" { |
---|
254 | #endif |
---|
255 | |
---|
256 | static long nt_build_sai_string_by_hash(const char *key,long val){ |
---|
257 | char *sep = strchr(key,1); |
---|
258 | if (!sep) return val; // what's wrong |
---|
259 | |
---|
260 | if (!nt_build_sai_last_group_name || strncmp(key,nt_build_sai_last_group_name,sep-key)){ // new group |
---|
261 | if (nt_build_sai_last_group_name){ |
---|
262 | GBS_chrcat(nt_build_sai_middle_file,1); // Seperated by 1 |
---|
263 | GBS_chrcat(nt_build_sai_middle_file,'E'); // End of old group |
---|
264 | } |
---|
265 | GBS_chrcat(nt_build_sai_middle_file,1); // Seperated by 1 |
---|
266 | GBS_strcat(nt_build_sai_middle_file,"FSAI:"); |
---|
267 | GBS_strncat(nt_build_sai_middle_file,key,sep-key); |
---|
268 | nt_build_sai_last_group_name = key; |
---|
269 | } |
---|
270 | GBS_chrcat(nt_build_sai_middle_file,1); // Seperated by 1 |
---|
271 | GBS_strcat(nt_build_sai_middle_file,"S"); |
---|
272 | GBS_strcat(nt_build_sai_middle_file,sep+1); |
---|
273 | return val; |
---|
274 | } |
---|
275 | |
---|
276 | #ifdef __cplusplus |
---|
277 | } |
---|
278 | #endif |
---|
279 | |
---|
280 | /** collect all Sais, place some SAI in top area, rest in middle */ |
---|
281 | void nt_build_sai_string(GBS_strstruct *topfile, GBS_strstruct *middlefile){ |
---|
282 | GBDATA *gb_sai_data = GB_search(GLOBAL_gb_main,"extended_data",GB_FIND); |
---|
283 | if (!gb_sai_data) return; |
---|
284 | |
---|
285 | GB_HASH *hash = GBS_create_hash(100, GB_IGNORE_CASE); |
---|
286 | GBDATA *gb_sai; |
---|
287 | |
---|
288 | for (gb_sai = GBT_first_SAI_rel_exdata(gb_sai_data); gb_sai; gb_sai = GBT_next_SAI(gb_sai)) { |
---|
289 | GBDATA *gb_name = GB_search(gb_sai,"name",GB_FIND); |
---|
290 | if (!gb_name) continue; |
---|
291 | |
---|
292 | char *name = GB_read_string(gb_name); |
---|
293 | |
---|
294 | if (strcmp(name, "HELIX") == 0 || strcmp(name, "HELIX_NR") == 0 || strcmp(name, "ECOLI") == 0) { |
---|
295 | GBS_chrcat(topfile,1); // Seperated by 1 |
---|
296 | GBS_strcat(topfile,"S"); |
---|
297 | GBS_strcat(topfile,name); |
---|
298 | } |
---|
299 | else { |
---|
300 | GBDATA *gb_gn = GB_search(gb_sai,"sai_group",GB_FIND); |
---|
301 | char *gn; |
---|
302 | |
---|
303 | if (gb_gn) gn = GB_read_string(gb_gn); |
---|
304 | else gn = strdup("SAI's"); |
---|
305 | |
---|
306 | char *cn = new char[strlen(gn) + strlen(name) + 2]; |
---|
307 | sprintf(cn,"%s%c%s",gn,1,name); |
---|
308 | GBS_write_hash(hash,cn,1); |
---|
309 | free(name); |
---|
310 | delete [] cn; |
---|
311 | free(gn); |
---|
312 | } |
---|
313 | } |
---|
314 | |
---|
315 | // open surrounding SAI-group: |
---|
316 | GBS_chrcat(middlefile, 1); |
---|
317 | GBS_strcat(middlefile, "GSAI-Maingroup"); |
---|
318 | |
---|
319 | nt_build_sai_last_group_name = 0; |
---|
320 | nt_build_sai_middle_file = middlefile; |
---|
321 | GBS_hash_do_sorted_loop(hash,nt_build_sai_string_by_hash,(gbs_hash_sort_func_type)nt_build_sai_sort_strings); |
---|
322 | if (nt_build_sai_last_group_name) { |
---|
323 | GBS_chrcat(middlefile,1); // Seperated by 1 |
---|
324 | GBS_chrcat(middlefile,'E'); // End of old group |
---|
325 | } |
---|
326 | |
---|
327 | // close surrounding SAI-group: |
---|
328 | GBS_chrcat(middlefile,1); |
---|
329 | GBS_chrcat(middlefile,'E'); |
---|
330 | |
---|
331 | GBS_free_hash(hash); |
---|
332 | } |
---|
333 | |
---|
334 | void nt_build_conf_marked(GB_HASH *used, GBS_strstruct *file){ |
---|
335 | GBS_chrcat(file,1); // Seperated by 1 |
---|
336 | GBS_strcat(file,"FMore Sequences"); |
---|
337 | GBDATA *gb_species; |
---|
338 | for (gb_species = GBT_first_marked_species(GLOBAL_gb_main); |
---|
339 | gb_species; |
---|
340 | gb_species = GBT_next_marked_species(gb_species)){ |
---|
341 | char *name = GBT_read_string(gb_species,"name"); |
---|
342 | if (GBS_read_hash(used,name)){ |
---|
343 | free(name); |
---|
344 | continue; |
---|
345 | } |
---|
346 | GBS_chrcat(file,1); |
---|
347 | GBS_strcat(file,"L"); |
---|
348 | GBS_strcat(file,name); |
---|
349 | free(name); |
---|
350 | } |
---|
351 | |
---|
352 | GBS_chrcat(file,1); // Seperated by 1 |
---|
353 | GBS_chrcat(file,'E'); // Group end indicated by 'E' |
---|
354 | } |
---|
355 | |
---|
356 | #define CONFNAME "default_configuration" |
---|
357 | |
---|
358 | void nt_start_editor_on_configuration(AW_window *aww){ |
---|
359 | aww->hide(); |
---|
360 | char *cn = aww->get_root()->awar(AWAR_CONFIGURATION)->read_string(); |
---|
361 | char *com = (char *)GBS_global_string("arb_edit4 -c '%s' &",cn); |
---|
362 | GBCMC_system(GLOBAL_gb_main, com); |
---|
363 | delete cn; |
---|
364 | } |
---|
365 | |
---|
366 | AW_window *NT_start_editor_on_old_configuration(AW_root *awr){ |
---|
367 | static AW_window_simple *aws = 0; |
---|
368 | if (aws) return (AW_window *)aws; |
---|
369 | awr->awar_string(AWAR_CONFIGURATION,"default_configuration",GLOBAL_gb_main); |
---|
370 | aws = new AW_window_simple; |
---|
371 | aws->init( awr, "SELECT_CONFIFURATION", "SELECT A CONFIGURATION"); |
---|
372 | aws->at(10,10); |
---|
373 | aws->auto_space(0,0); |
---|
374 | awt_create_selection_list_on_configurations(GLOBAL_gb_main,(AW_window *)aws,AWAR_CONFIGURATION); |
---|
375 | aws->at_newline(); |
---|
376 | |
---|
377 | aws->callback((AW_CB0)nt_start_editor_on_configuration); |
---|
378 | aws->create_button("START","START"); |
---|
379 | |
---|
380 | aws->callback(AW_POPDOWN); |
---|
381 | aws->create_button("CLOSE","CLOSE","C"); |
---|
382 | |
---|
383 | aws->window_fit(); |
---|
384 | return (AW_window *)aws; |
---|
385 | } |
---|
386 | |
---|
387 | void NT_start_editor_on_tree(AW_window *, GBT_TREE **ptree, int use_species_aside){ |
---|
388 | GB_ERROR error = NT_create_configuration(0,ptree,CONFNAME, use_species_aside); |
---|
389 | if (!error) { |
---|
390 | GBCMC_system(GLOBAL_gb_main, "arb_edit4 -c "CONFNAME" &"); |
---|
391 | } |
---|
392 | } |
---|
393 | |
---|
394 | enum extractType { |
---|
395 | CONF_EXTRACT, |
---|
396 | CONF_MARK, |
---|
397 | CONF_UNMARK, |
---|
398 | CONF_INVERT, |
---|
399 | CONF_COMBINE // logical AND |
---|
400 | }; |
---|
401 | |
---|
402 | void nt_extract_configuration(AW_window *aww, AW_CL cl_extractType){ |
---|
403 | GB_transaction dummy2(GLOBAL_gb_main); // open close transaction |
---|
404 | char *cn = aww->get_root()->awar(AWAR_CONFIGURATION)->read_string(); |
---|
405 | GBDATA *gb_configuration = GBT_find_configuration(GLOBAL_gb_main,cn); |
---|
406 | if (!gb_configuration){ |
---|
407 | aw_message(GBS_global_string("Configuration '%s' not found in the database",cn)); |
---|
408 | } |
---|
409 | else { |
---|
410 | GBDATA *gb_middle_area = GB_search(gb_configuration,"middle_area",GB_STRING); |
---|
411 | char *md = 0; |
---|
412 | if (gb_middle_area){ |
---|
413 | extractType ext_type = extractType(cl_extractType); |
---|
414 | |
---|
415 | GB_HASH *was_marked = 0; // only used for CONF_COMBINE |
---|
416 | |
---|
417 | switch (ext_type) { |
---|
418 | case CONF_EXTRACT: |
---|
419 | GBT_mark_all(GLOBAL_gb_main,0); // unmark all for extract |
---|
420 | break; |
---|
421 | case CONF_COMBINE: { |
---|
422 | // store all marked species in hash and unmark them |
---|
423 | was_marked = GBS_create_hash(GBT_get_species_hash_size(GLOBAL_gb_main), GB_IGNORE_CASE); |
---|
424 | for (GBDATA *gbd = GBT_first_marked_species(GLOBAL_gb_main); gbd; gbd = GBT_next_marked_species(gbd)) { |
---|
425 | int marked = GB_read_flag(gbd); |
---|
426 | if (marked) { |
---|
427 | char *name = GBT_read_name(gbd); |
---|
428 | if (name) { |
---|
429 | GBS_write_hash(was_marked, name, 1); |
---|
430 | free(name); |
---|
431 | } |
---|
432 | GB_write_flag(gbd, 0); |
---|
433 | } |
---|
434 | } |
---|
435 | |
---|
436 | break; |
---|
437 | } |
---|
438 | default : |
---|
439 | break; |
---|
440 | } |
---|
441 | |
---|
442 | md = GB_read_string(gb_middle_area); |
---|
443 | if (md){ |
---|
444 | char *p; |
---|
445 | char tokens[2]; |
---|
446 | tokens[0] = 1; |
---|
447 | tokens[1] = 0; |
---|
448 | for ( p = strtok(md,tokens); p; p = strtok(NULL,tokens)){ |
---|
449 | if (p[0] != 'L') continue; |
---|
450 | GBDATA *gb_species = GBT_find_species(GLOBAL_gb_main,p+1); |
---|
451 | if (gb_species){ |
---|
452 | int mark = GB_read_flag(gb_species); |
---|
453 | switch (ext_type) { |
---|
454 | case CONF_EXTRACT: |
---|
455 | case CONF_MARK: mark = 1; break; |
---|
456 | case CONF_UNMARK: mark = 0; break; |
---|
457 | case CONF_INVERT: mark = 1-mark; break; |
---|
458 | case CONF_COMBINE: { |
---|
459 | nt_assert(mark == 0); // should have been unmarked above |
---|
460 | mark = GBS_read_hash(was_marked, p+1); // mark if was_marked |
---|
461 | break; |
---|
462 | } |
---|
463 | default: nt_assert(0); break; |
---|
464 | } |
---|
465 | GB_write_flag(gb_species,mark); |
---|
466 | } |
---|
467 | } |
---|
468 | } |
---|
469 | |
---|
470 | GBS_free_hash(was_marked); |
---|
471 | } |
---|
472 | free(md); |
---|
473 | } |
---|
474 | free(cn); |
---|
475 | } |
---|
476 | |
---|
477 | void nt_delete_configuration(AW_window *aww){ |
---|
478 | GB_transaction transaction_var(GLOBAL_gb_main); |
---|
479 | char *cn = aww->get_root()->awar(AWAR_CONFIGURATION)->read_string(); |
---|
480 | GBDATA *gb_configuration = GBT_find_configuration(GLOBAL_gb_main,cn); |
---|
481 | if (gb_configuration){ |
---|
482 | GB_ERROR error = GB_delete(gb_configuration); |
---|
483 | if (error) aw_message(error); |
---|
484 | } |
---|
485 | free(cn); |
---|
486 | } |
---|
487 | |
---|
488 | |
---|
489 | GB_ERROR NT_create_configuration(AW_window *, GBT_TREE **ptree,const char *conf_name, int use_species_aside){ |
---|
490 | GBT_TREE *tree = *ptree; |
---|
491 | char *to_free = 0; |
---|
492 | |
---|
493 | if (!conf_name) { |
---|
494 | char *existing_configs = awt_create_string_on_configurations(GLOBAL_gb_main); |
---|
495 | conf_name = to_free = aw_string_selection("CREATE CONFIGURATION", "Enter name of configuration:", AWAR_CONFIGURATION, "default_configuration", existing_configs, 0, 0); |
---|
496 | free(existing_configs); |
---|
497 | } |
---|
498 | if (!conf_name) return GB_export_error("no config name"); |
---|
499 | |
---|
500 | if (use_species_aside==-1) { |
---|
501 | static int last_used_species_aside = 3; |
---|
502 | { |
---|
503 | const char *val = GBS_global_string("%i", last_used_species_aside); |
---|
504 | char *use_species = aw_input("Enter number of extra species to view aside marked:", 0, val); |
---|
505 | if (use_species) use_species_aside = atoi(use_species); |
---|
506 | free(use_species); |
---|
507 | } |
---|
508 | |
---|
509 | if (use_species_aside<1) return GB_export_error("illegal # of species aside"); |
---|
510 | |
---|
511 | last_used_species_aside = use_species_aside; // remember for next time |
---|
512 | } |
---|
513 | |
---|
514 | GB_transaction dummy2(GLOBAL_gb_main); // open close transaction |
---|
515 | GB_HASH *used = GBS_create_hash(GBT_get_species_hash_size(GLOBAL_gb_main), GB_MIND_CASE); |
---|
516 | GBS_strstruct *topfile = GBS_stropen(1000); |
---|
517 | GBS_strstruct *topmid = GBS_stropen(10000); |
---|
518 | { |
---|
519 | GBS_strstruct *middlefile = GBS_stropen(10000); |
---|
520 | nt_build_sai_string(topfile,topmid); |
---|
521 | |
---|
522 | if (use_species_aside) { |
---|
523 | Store_species *extra_marked_species = 0; |
---|
524 | int auto_mark = 0; |
---|
525 | int marked_at_right; |
---|
526 | nt_build_conf_string_rek(used, tree, middlefile, &extra_marked_species, use_species_aside, &auto_mark, use_species_aside, &marked_at_right); |
---|
527 | if (extra_marked_species) { |
---|
528 | extra_marked_species->call(unmark_species); |
---|
529 | delete extra_marked_species; |
---|
530 | } |
---|
531 | } |
---|
532 | else { |
---|
533 | int dummy_1=0, dummy_2; |
---|
534 | nt_build_conf_string_rek(used, tree, middlefile, 0, 0, &dummy_1, 0, &dummy_2); |
---|
535 | } |
---|
536 | nt_build_conf_marked(used,topmid); |
---|
537 | char *mid = GBS_strclose(middlefile); |
---|
538 | GBS_strcat(topmid,mid); |
---|
539 | free(mid); |
---|
540 | } |
---|
541 | |
---|
542 | char *middle = GBS_strclose(topmid); |
---|
543 | char *top = GBS_strclose(topfile); |
---|
544 | |
---|
545 | GBDATA *gb_configuration = GBT_create_configuration(GLOBAL_gb_main,conf_name); |
---|
546 | GB_ERROR error = 0; |
---|
547 | if (!gb_configuration){ |
---|
548 | error = GB_get_error(); |
---|
549 | }else{ |
---|
550 | GBDATA *gb_top_area = GB_search(gb_configuration,"top_area",GB_STRING); |
---|
551 | GBDATA *gb_middle_area = GB_search(gb_configuration,"middle_area",GB_STRING); |
---|
552 | error = GB_write_string(gb_top_area,top); |
---|
553 | if (!error){ |
---|
554 | error = GB_write_string(gb_middle_area,middle); |
---|
555 | } |
---|
556 | } |
---|
557 | free(to_free); |
---|
558 | free(middle); |
---|
559 | free(top); |
---|
560 | GBS_free_hash(used); |
---|
561 | if (error) aw_message(error); |
---|
562 | return error; |
---|
563 | } |
---|
564 | |
---|
565 | void nt_store_configuration(AW_window */*aww*/, AW_CL cl_GBT_TREE_ptr) { |
---|
566 | GBT_TREE **ptree = (GBT_TREE**)cl_GBT_TREE_ptr; |
---|
567 | GB_ERROR err = NT_create_configuration(0, ptree, 0, 0); |
---|
568 | if (err) aw_message(err); |
---|
569 | } |
---|
570 | |
---|
571 | void nt_rename_configuration(AW_window *aww) { |
---|
572 | AW_awar *awar_curr_cfg = aww->get_root()->awar(AWAR_CONFIGURATION); |
---|
573 | char *old_name = awar_curr_cfg->read_string(); |
---|
574 | GB_ERROR err = 0; |
---|
575 | |
---|
576 | GB_transaction dummy(GLOBAL_gb_main); |
---|
577 | |
---|
578 | char *new_name = aw_input("Rename selection", "Enter the new name of the selection", 0, old_name); |
---|
579 | if (new_name) { |
---|
580 | GBDATA *gb_existing_cfg = GBT_find_configuration(GLOBAL_gb_main, new_name); |
---|
581 | if (gb_existing_cfg) { |
---|
582 | err = GBS_global_string("There is already a selection named '%s'", new_name); |
---|
583 | } |
---|
584 | else { |
---|
585 | GBDATA *gb_old_cfg = GBT_find_configuration(GLOBAL_gb_main, old_name); |
---|
586 | if (gb_old_cfg) { |
---|
587 | GBDATA *gb_name = GB_entry(gb_old_cfg, "name"); |
---|
588 | if (gb_name) { |
---|
589 | err = GB_write_string(gb_name, new_name); |
---|
590 | if (!err) awar_curr_cfg->write_string(new_name); |
---|
591 | } |
---|
592 | else { |
---|
593 | err = "Selection has no name"; |
---|
594 | } |
---|
595 | } |
---|
596 | else { |
---|
597 | err = "Can't find that selection"; |
---|
598 | } |
---|
599 | } |
---|
600 | free(new_name); |
---|
601 | } |
---|
602 | |
---|
603 | if (err) aw_message(err); |
---|
604 | |
---|
605 | free(new_name); |
---|
606 | free(old_name); |
---|
607 | } |
---|
608 | // -------------------------------------------------------------------------------------- |
---|
609 | // AW_window *create_configuration_admin_window(AW_root *root, GBT_TREE **ptree) |
---|
610 | // -------------------------------------------------------------------------------------- |
---|
611 | AW_window *create_configuration_admin_window(AW_root *root, GBT_TREE **ptree) { |
---|
612 | static AW_window_simple *aws = 0; |
---|
613 | if (aws) return aws; |
---|
614 | |
---|
615 | init_config_awars(root); |
---|
616 | |
---|
617 | aws = new AW_window_simple; |
---|
618 | aws->init(root, "SPECIES_SELECTIONS", "Species Selections"); |
---|
619 | aws->load_xfig("nt_selection.fig"); |
---|
620 | |
---|
621 | aws->at("close"); |
---|
622 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
623 | aws->create_button("CLOSE","CLOSE","C"); |
---|
624 | |
---|
625 | aws->at("help"); |
---|
626 | aws->callback(AW_POPUP_HELP,(AW_CL)"configuration.hlp"); |
---|
627 | aws->create_button("HELP","HELP","H"); |
---|
628 | |
---|
629 | aws->at("list"); |
---|
630 | awt_create_selection_list_on_configurations(GLOBAL_gb_main, aws, AWAR_CONFIGURATION); |
---|
631 | |
---|
632 | aws->at("store"); |
---|
633 | aws->callback(nt_store_configuration, (AW_CL)ptree); |
---|
634 | aws->create_button("STORE","STORE","S"); |
---|
635 | |
---|
636 | aws->at("extract"); |
---|
637 | aws->callback(nt_extract_configuration, CONF_EXTRACT); |
---|
638 | aws->create_button("EXTRACT","EXTRACT","E"); |
---|
639 | |
---|
640 | aws->at("mark"); |
---|
641 | aws->callback(nt_extract_configuration, CONF_MARK); |
---|
642 | aws->create_button("MARK","MARK","M"); |
---|
643 | |
---|
644 | aws->at("unmark"); |
---|
645 | aws->callback(nt_extract_configuration, CONF_UNMARK); |
---|
646 | aws->create_button("UNMARK","UNMARK","U"); |
---|
647 | |
---|
648 | aws->at("invert"); |
---|
649 | aws->callback(nt_extract_configuration, CONF_INVERT); |
---|
650 | aws->create_button("INVERT","INVERT","I"); |
---|
651 | |
---|
652 | aws->at("combine"); |
---|
653 | aws->callback(nt_extract_configuration, CONF_COMBINE); |
---|
654 | aws->create_button("COMBINE","COMBINE","C"); |
---|
655 | |
---|
656 | aws->at("delete"); |
---|
657 | aws->callback(nt_delete_configuration); |
---|
658 | aws->create_button("DELETE","DELETE","D"); |
---|
659 | |
---|
660 | aws->at("rename"); |
---|
661 | aws->callback(nt_rename_configuration); |
---|
662 | aws->create_button("RENAME","RENAME","R"); |
---|
663 | |
---|
664 | return aws; |
---|
665 | } |
---|
666 | |
---|
667 | void NT_configuration_admin(AW_window *aw_main, AW_CL cl_GBT_TREE_ptr, AW_CL) { |
---|
668 | GBT_TREE **ptree = (GBT_TREE**)cl_GBT_TREE_ptr; |
---|
669 | AW_root *aw_root = aw_main->get_root(); |
---|
670 | AW_window *aww = create_configuration_admin_window(aw_root, ptree); |
---|
671 | |
---|
672 | aww->show(); |
---|
673 | } |
---|
674 | |
---|
675 | // -------------------------------------------------------------------------------- |
---|
676 | // -------------------------------------------------------------------------------- |
---|
677 | // -------------------------------------------------------------------------------- |
---|
678 | |
---|
679 | #if 0 |
---|
680 | |
---|
681 | // obsolete: |
---|
682 | AW_window *NT_extract_configuration(AW_root *awr){ |
---|
683 | static AW_window_simple *aws = 0; |
---|
684 | if (aws) return (AW_window *)aws; |
---|
685 | awr->awar_string(AWAR_CONFIGURATION,"default_configuration",gb_main); |
---|
686 | aws = new AW_window_simple; |
---|
687 | aws->init( awr, "EXTRACT_CONFIGURATION", "EXTRACT A CONFIGURATION", 400, 200 ); |
---|
688 | aws->at(10,10); |
---|
689 | aws->auto_space(0,0); |
---|
690 | awt_create_selection_list_on_configurations(gb_main,(AW_window *)aws,AWAR_CONFIGURATION); |
---|
691 | aws->at_newline(); |
---|
692 | |
---|
693 | aws->callback((AW_CB0)nt_extract_configuration); |
---|
694 | aws->create_button("EXTRACT","EXTRACT","E"); |
---|
695 | |
---|
696 | aws->callback(nt_delete_configuration); |
---|
697 | aws->create_button("DELETE","DELETE"); |
---|
698 | |
---|
699 | aws->callback(AW_POPDOWN); |
---|
700 | aws->create_button("CLOSE","CLOSE","C"); |
---|
701 | |
---|
702 | aws->callback(AW_POPUP_HELP,(AW_CL)"configuration.hlp"); |
---|
703 | aws->create_button("HELP","HELP","H"); |
---|
704 | |
---|
705 | aws->window_fit(); |
---|
706 | return (AW_window *)aws; |
---|
707 | } |
---|
708 | // obsolete: |
---|
709 | GB_ERROR NT_create_configuration_cb(AW_window *aww, AW_CL cl_GBT_TREE_ptr, AW_CL cl_use_species_aside) { |
---|
710 | GBT_TREE **ptree = (GBT_TREE**)(cl_GBT_TREE_ptr); |
---|
711 | int use_species_aside = int(cl_use_species_aside); |
---|
712 | |
---|
713 | init_config_awars(aww->get_root()); |
---|
714 | return NT_create_configuration(0, ptree, 0, use_species_aside); |
---|
715 | } |
---|
716 | |
---|
717 | #endif |
---|