1 | // ================================================================ // |
---|
2 | // // |
---|
3 | // File : AWTC_submission.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // ================================================================ // |
---|
10 | |
---|
11 | #include <aw_window.hxx> |
---|
12 | #include <aw_awars.hxx> |
---|
13 | #include <aw_edit.hxx> |
---|
14 | #include <aw_root.hxx> |
---|
15 | #include <aw_msg.hxx> |
---|
16 | |
---|
17 | #include <arbdbt.h> |
---|
18 | #include <arb_strbuf.h> |
---|
19 | #include <arb_strarray.h> |
---|
20 | #include <gb_aci.h> |
---|
21 | |
---|
22 | #define awtc_assert(bed) arb_assert(bed) |
---|
23 | |
---|
24 | #define AWAR_SUBMIT_PARSER "tmp/submission/parser" |
---|
25 | #define AWAR_SUBMIT_PARSED "tmp/submission/parsed" |
---|
26 | |
---|
27 | #define AWAR_SUBMIT_SOURCE "submission/source" |
---|
28 | #define AWAR_SUBMIT_FILE "submission/file" |
---|
29 | #define AWAR_SUBMIT_PRIVAT "submission/privat" |
---|
30 | |
---|
31 | void AWTC_create_submission_variables(AW_root *root, AW_default db1) { |
---|
32 | root->awar_string(AWAR_SUBMIT_SOURCE, "", db1); |
---|
33 | root->awar_string(AWAR_SUBMIT_PARSER, "press READ INFO", db1); |
---|
34 | root->awar_string(AWAR_SUBMIT_PARSED, "", db1); |
---|
35 | root->awar_string(AWAR_SUBMIT_FILE, "", db1); |
---|
36 | root->awar_string(AWAR_SUBMIT_PRIVAT, "$(ADDRESS)=TUM Munich:\n", db1); |
---|
37 | } |
---|
38 | |
---|
39 | static void ed_calltexe_event(AW_window *aww, const char *varname) { |
---|
40 | AW_edit(aww->get_root()->awar(varname)->read_char_pntr()); |
---|
41 | } |
---|
42 | |
---|
43 | static AW_window *create_calltexe_window(AW_root *root, const char *varname) { |
---|
44 | AW_window_simple *aws = new AW_window_simple; |
---|
45 | { |
---|
46 | char *var_id = GBS_string_2_key(varname); |
---|
47 | char *window_id = GBS_global_string_copy("SUBM_TEXTEDIT_%s", var_id); |
---|
48 | aws->init(root, window_id, "START TEXT EDITOR"); |
---|
49 | free(window_id); |
---|
50 | free(var_id); |
---|
51 | } |
---|
52 | |
---|
53 | aws->load_xfig("calltexe.fig"); |
---|
54 | aws->label_length(18); |
---|
55 | aws->button_length(8); |
---|
56 | |
---|
57 | aws->at("close"); |
---|
58 | aws->callback(AW_POPDOWN); |
---|
59 | aws->create_button("CLOSE", "CLOSE", "O"); |
---|
60 | |
---|
61 | aws->at("file"); |
---|
62 | aws->create_input_field(varname, 34); |
---|
63 | |
---|
64 | aws->at("edit"); |
---|
65 | aws->callback(makeWindowCallback(ed_calltexe_event, varname)); |
---|
66 | aws->create_button("EDIT", "EDIT", "E"); |
---|
67 | |
---|
68 | return aws; |
---|
69 | } |
---|
70 | |
---|
71 | static void ed_submit_info_event_rm(char *string) { |
---|
72 | char *p = string; |
---|
73 | int c; |
---|
74 | while ((c=*p) != 0) { |
---|
75 | if (c==':') *p = ';'; |
---|
76 | if (c=='=') *p = '-'; |
---|
77 | p++; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | static void ed_submit_info_event(AW_window *aww, GBDATA *gb_main) { |
---|
82 | AW_root *aw_root = aww->get_root(); |
---|
83 | |
---|
84 | GB_transaction ta(gb_main); |
---|
85 | char *species_name = aw_root->awar(AWAR_SPECIES_NAME)->read_string(); |
---|
86 | GBDATA *gb_species = GBT_find_species(gb_main, species_name); |
---|
87 | GBS_strstruct strstruct(1000); |
---|
88 | |
---|
89 | if (gb_species) { |
---|
90 | for (GBDATA *gb_entry = GB_child(gb_species); gb_entry; gb_entry = GB_nextChild(gb_entry)) { |
---|
91 | int type = GB_read_type(gb_entry); |
---|
92 | switch (type) { |
---|
93 | case GB_STRING: |
---|
94 | case GB_INT: |
---|
95 | case GB_BITS: |
---|
96 | case GB_FLOAT: { |
---|
97 | char *key = GB_read_key(gb_entry); |
---|
98 | |
---|
99 | strstruct.cat("$("); |
---|
100 | strstruct.cat(key); |
---|
101 | strstruct.cat(")="); |
---|
102 | free(key); |
---|
103 | |
---|
104 | key = GB_read_as_string(gb_entry); |
---|
105 | ed_submit_info_event_rm(key); |
---|
106 | strstruct.cat(key); |
---|
107 | free(key); |
---|
108 | |
---|
109 | strstruct.cat(":\n"); |
---|
110 | break; |
---|
111 | } |
---|
112 | default: |
---|
113 | break; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | const char *srt_submit = |
---|
118 | "*=" |
---|
119 | "$(SEQ_LEN)\\=*(|sequence|len(.-))\\:\n" |
---|
120 | "$(SEQ_A)\\=*(|sequence|count(aA))\\:\n" |
---|
121 | "$(SEQ_C)\\=*(|sequence|count(cC))\\:\n" |
---|
122 | "$(SEQ_G)\\=*(|sequence|count(gG))\\:\n" |
---|
123 | "$(SEQ_T)\\=*(|sequence|count(tT))\\:\n" |
---|
124 | "$(SEQ_U)\\=*(|sequence|count(uU))\\:\n" |
---|
125 | "$(SEQUENCE)\\=*(|sequence|remove(.-)|format_sequence(firsttab\\=12;tab\\=12;width\\=60;numleft;gap\\=10))\\:\n"; |
---|
126 | |
---|
127 | GBL_env env(gb_main, NULp); |
---|
128 | GBL_call_env callEnv(gb_species, env); |
---|
129 | char *seq_info = GBS_string_eval_in_env(" ", srt_submit, callEnv); |
---|
130 | if (seq_info) { |
---|
131 | strstruct.cat(seq_info); |
---|
132 | free(seq_info); |
---|
133 | } |
---|
134 | else { |
---|
135 | aw_message(GB_await_error()); |
---|
136 | } |
---|
137 | } |
---|
138 | else { |
---|
139 | strstruct.cat("Species not found"); |
---|
140 | } |
---|
141 | |
---|
142 | char *parser = strstruct.release(); |
---|
143 | aw_root->awar(AWAR_SUBMIT_PARSER)->write_string(parser); |
---|
144 | |
---|
145 | free(parser); |
---|
146 | free(species_name); |
---|
147 | } |
---|
148 | |
---|
149 | static void ed_save_var_to_file(AW_window *aww, const char *data_var, const char *file_var) { |
---|
150 | AW_root *aw_root = aww->get_root(); |
---|
151 | char *data = aw_root->awar(data_var)->read_string(); |
---|
152 | char *file_name = aw_root->awar(file_var)->read_string(); |
---|
153 | FILE *out = fopen(file_name, "w"); |
---|
154 | |
---|
155 | if (out) { |
---|
156 | fprintf(out, "%s", data); |
---|
157 | fclose(out); |
---|
158 | } |
---|
159 | else { |
---|
160 | aw_message(GB_IO_error("saving info", file_name)); |
---|
161 | } |
---|
162 | free(file_name); |
---|
163 | free(data); |
---|
164 | } |
---|
165 | static void ed_submit_parse_event(AW_window *aww) { |
---|
166 | AW_root *aw_root = aww->get_root(); |
---|
167 | char *parser = aw_root->awar(AWAR_SUBMIT_PARSER)->read_string(); |
---|
168 | char *dest; |
---|
169 | char *dest2; |
---|
170 | char *privat; |
---|
171 | char *p, *d; |
---|
172 | int c; |
---|
173 | |
---|
174 | for (d = p = parser; *p; p++) { |
---|
175 | if ((c=*p)==':') { |
---|
176 | if (p[1] == '\n') p++; // skip newline |
---|
177 | } |
---|
178 | *(d++) = c; |
---|
179 | } |
---|
180 | *d = 0; |
---|
181 | char *sub_file = aw_root->awar(AWAR_SUBMIT_SOURCE)->read_string(); |
---|
182 | char *source = GB_read_file(sub_file); |
---|
183 | if (source) { |
---|
184 | dest = GBS_string_eval(source, parser); |
---|
185 | if (!dest) dest = ARB_strdup(GB_await_error()); |
---|
186 | } |
---|
187 | else { |
---|
188 | dest = GBS_global_string_copy("submission form not found\n(Reason: %s)", GB_await_error()); |
---|
189 | } |
---|
190 | |
---|
191 | awtc_assert(dest); // should contain partly filled form or error message |
---|
192 | |
---|
193 | privat = aw_root->awar(AWAR_SUBMIT_PRIVAT)->read_string(); |
---|
194 | for (d = p = privat; *p; p++) { |
---|
195 | if ((c=*p)==':') { |
---|
196 | if (p[1] == '\n') p++; // skip newline |
---|
197 | } |
---|
198 | *(d++) = c; |
---|
199 | } |
---|
200 | *d = 0; |
---|
201 | |
---|
202 | dest2 = GBS_string_eval(dest, privat); |
---|
203 | if (!dest2) dest2 = ARB_strdup(GB_await_error()); |
---|
204 | |
---|
205 | aw_root->awar(AWAR_SUBMIT_PARSED)->write_string(dest2); |
---|
206 | |
---|
207 | free(dest); |
---|
208 | free(dest2); |
---|
209 | free(privat); |
---|
210 | free(source); |
---|
211 | free (sub_file); |
---|
212 | free(parser); |
---|
213 | } |
---|
214 | |
---|
215 | static void ed_submit_gen_event(AW_window *aww) { |
---|
216 | AW_root *aw_root = aww->get_root(); |
---|
217 | char buffer[256]; |
---|
218 | char *name = aw_root->awar(AWAR_SPECIES_NAME)->read_string(); |
---|
219 | sprintf(buffer, "%s.submit", name); |
---|
220 | free(name); |
---|
221 | aw_root->awar(AWAR_SUBMIT_FILE)->write_string(buffer); |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | AW_window *AWTC_create_submission_window(AW_root *root, GBDATA *gb_main) { |
---|
226 | AW_window_simple *aws = new AW_window_simple; |
---|
227 | aws->init(root, "SUBMISSION", "SUBMISSION"); |
---|
228 | |
---|
229 | aws->load_xfig("submiss.fig"); |
---|
230 | aws->label_length(18); |
---|
231 | aws->button_length(8); |
---|
232 | |
---|
233 | aws->at("close"); |
---|
234 | aws->callback(AW_POPDOWN); |
---|
235 | aws->create_button("CLOSE", "CLOSE", "O"); |
---|
236 | |
---|
237 | aws->callback(makeHelpCallback("submission.hlp")); |
---|
238 | aws->at("help"); |
---|
239 | aws->create_button("HELP", "HELP", "H"); |
---|
240 | |
---|
241 | aws->button_length(15); |
---|
242 | |
---|
243 | aws->at("privat"); |
---|
244 | aws->create_text_field(AWAR_SUBMIT_PRIVAT, 80, 5); |
---|
245 | |
---|
246 | aws->at("parsed_info"); |
---|
247 | aws->create_text_field(AWAR_SUBMIT_PARSER, 80, 6); |
---|
248 | |
---|
249 | aws->at("parsed"); |
---|
250 | aws->create_text_field(AWAR_SUBMIT_PARSED, 80, 13); |
---|
251 | |
---|
252 | aws->at("species"); |
---|
253 | aws->label("Species Name:"); |
---|
254 | aws->create_input_field(AWAR_SPECIES_NAME, 12); |
---|
255 | |
---|
256 | aws->at("submission"); |
---|
257 | { |
---|
258 | StrArray submits; |
---|
259 | GBS_read_dir(submits, GB_path_in_ARBLIB("submit"), NULp); |
---|
260 | |
---|
261 | if (!submits.empty()) { |
---|
262 | aws->label("Select a Form"); |
---|
263 | aws->create_option_menu(AWAR_SUBMIT_SOURCE); |
---|
264 | for (int i = 0; submits[i]; ++i) { |
---|
265 | aws->insert_option(submits[i], "", submits[i]); |
---|
266 | } |
---|
267 | aws->insert_default_option("default", "d", "default"); |
---|
268 | aws->update_option_menu(); |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | aws->at("gen"); |
---|
273 | aws->label("Gen File Name"); |
---|
274 | aws->callback(ed_submit_gen_event); |
---|
275 | aws->create_button("GEN_FILE_NAME", "CREATE NAME", "C"); |
---|
276 | |
---|
277 | aws->at("file"); |
---|
278 | aws->label("or enter"); |
---|
279 | aws->create_input_field(AWAR_SUBMIT_FILE, 30); |
---|
280 | |
---|
281 | aws->at("info"); |
---|
282 | aws->callback(makeWindowCallback(ed_submit_info_event, gb_main)); |
---|
283 | aws->create_button("READ_INFO", "READ INFO", "R"); |
---|
284 | |
---|
285 | aws->at("parse"); |
---|
286 | aws->callback(ed_submit_parse_event); |
---|
287 | aws->create_button("FILL_OUT_FORM", "FILL THE FORM", "F"); |
---|
288 | |
---|
289 | aws->at("write"); |
---|
290 | aws->callback(makeWindowCallback(ed_save_var_to_file, AWAR_SUBMIT_PARSED, AWAR_SUBMIT_FILE)); |
---|
291 | aws->create_button("SAVE", "SAVE TO FILE", "S"); |
---|
292 | |
---|
293 | aws->button_length(20); |
---|
294 | aws->at("edit"); |
---|
295 | aws->callback(makeCreateWindowCallback(create_calltexe_window, AWAR_SUBMIT_SOURCE)); |
---|
296 | aws->create_button("EDIT_FORM", "EDIT FORM", "R"); |
---|
297 | |
---|
298 | aws->at("editresult"); |
---|
299 | aws->callback(makeCreateWindowCallback(create_calltexe_window, AWAR_SUBMIT_FILE)); |
---|
300 | aws->create_button("EDIT_SAVED", "EDIT SAVED", "S"); |
---|
301 | |
---|
302 | aws->at("privatlabel"); |
---|
303 | aws->create_button(NULp, "Your private data"); |
---|
304 | |
---|
305 | return aws; |
---|
306 | } |
---|