1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | #include <arbdb.h> |
---|
5 | #include <arbdbt.h> |
---|
6 | |
---|
7 | #include <aw_root.hxx> |
---|
8 | #include <aw_device.hxx> |
---|
9 | #include <aw_window.hxx> |
---|
10 | #include <aw_preset.hxx> |
---|
11 | #include <aw_awars.hxx> |
---|
12 | #include <awt.hxx> |
---|
13 | #include <awtc_rename.hxx> |
---|
14 | |
---|
15 | #include "merge.hxx" |
---|
16 | #include "mg_merge.hxx" |
---|
17 | |
---|
18 | GBDATA *gb_merge = NULL; |
---|
19 | GBDATA *gb_dest = NULL; |
---|
20 | |
---|
21 | void MG_exit(AW_window *aww) { |
---|
22 | if(gb_main) { |
---|
23 | aww->hide(); |
---|
24 | }else{ |
---|
25 | exit (0); |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | int mg_save_enabled = 1; |
---|
30 | |
---|
31 | void |
---|
32 | MG_save_merge_cb(AW_window *aww) |
---|
33 | { |
---|
34 | char *name = aww->get_root()->awar(AWAR_MERGE_DB"/file_name")->read_string(); |
---|
35 | GB_begin_transaction(gb_merge); |
---|
36 | GBT_check_data(gb_merge,0); |
---|
37 | GB_commit_transaction(gb_merge); |
---|
38 | GB_ERROR error = GB_save(gb_merge, name, "b"); |
---|
39 | if (error) aw_message(error); |
---|
40 | else aww->get_root()->awar(AWAR_MERGE_DB"/directory")->touch(); |
---|
41 | delete name; |
---|
42 | } |
---|
43 | |
---|
44 | AW_window *MG_save_source_cb(AW_root *aw_root, char *base_name) |
---|
45 | { |
---|
46 | static AW_window_simple *aws = 0; |
---|
47 | if (aws) return (AW_window *)aws; |
---|
48 | |
---|
49 | aws = new AW_window_simple; |
---|
50 | aws->init( aw_root, "MERGE_SAVE_DB_I", "SAVE ARB DB I", 10, 10 ); |
---|
51 | aws->load_xfig("sel_box.fig"); |
---|
52 | |
---|
53 | aws->at("close");aws->callback((AW_CB0)AW_POPDOWN); |
---|
54 | aws->create_button("CLOSE","CLOSE","C"); |
---|
55 | |
---|
56 | aws->at("save");aws->callback(MG_save_merge_cb); |
---|
57 | aws->create_button("SAVE","SAVE","S"); |
---|
58 | |
---|
59 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
60 | aws->at("cancel"); |
---|
61 | aws->create_button("CLOSE","CANCEL","C"); |
---|
62 | |
---|
63 | awt_create_selection_box((AW_window *)aws,base_name); |
---|
64 | |
---|
65 | return (AW_window *)aws; |
---|
66 | } |
---|
67 | |
---|
68 | void |
---|
69 | MG_save_cb(AW_window *aww) |
---|
70 | { |
---|
71 | char *name = aww->get_root()->awar(AWAR_MAIN_DB"/file_name")->read_string(); |
---|
72 | char *type = aww->get_root()->awar(AWAR_MAIN_DB"/type")->read_string(); |
---|
73 | aw_openstatus("Saving database"); |
---|
74 | GB_begin_transaction(gb_dest); |
---|
75 | GBT_check_data(gb_dest,0); |
---|
76 | GB_commit_transaction(gb_dest); |
---|
77 | GB_ERROR error = GB_save(gb_dest, name, type); |
---|
78 | aw_closestatus(); |
---|
79 | if (error) aw_message(error); |
---|
80 | else aww->get_root()->awar(AWAR_MAIN_DB"/directory")->touch(); |
---|
81 | delete name; |
---|
82 | delete type; |
---|
83 | } |
---|
84 | |
---|
85 | AW_window *MG_save_result_cb(AW_root *aw_root, char *base_name) |
---|
86 | { |
---|
87 | static AW_window_simple *aws = 0; |
---|
88 | if (aws) return (AW_window *)aws; |
---|
89 | aw_root->awar_string( AWAR_DB_COMMENT, "<no description>", gb_dest); |
---|
90 | |
---|
91 | aws = new AW_window_simple; |
---|
92 | aws->init( aw_root, "MERGE_SAVE_WHOLE_DB", "SAVE WHOLE DATABASE", 10, 10 ); |
---|
93 | aws->load_xfig("sel_box.fig"); |
---|
94 | |
---|
95 | aws->at("close");aws->callback((AW_CB0)AW_POPDOWN); |
---|
96 | aws->create_button("CLOSE","CLOSE","C"); |
---|
97 | |
---|
98 | awt_create_selection_box((AW_window *)aws,base_name); |
---|
99 | |
---|
100 | aws->at("user"); |
---|
101 | aws->label("Type"); |
---|
102 | aws->create_option_menu(AWAR_MAIN_DB"/type"); |
---|
103 | aws->insert_option("Binary","B","b"); |
---|
104 | aws->insert_option("Bin (with FastLoad File)","f","bm"); |
---|
105 | aws->update_option_menu(); |
---|
106 | |
---|
107 | aws->at("user2"); |
---|
108 | aws->create_button(0,"Database Description"); |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
113 | aws->at("cancel4"); |
---|
114 | aws->create_button("CLOSE","CANCEL","C"); |
---|
115 | |
---|
116 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
117 | aws->at("cancel4"); |
---|
118 | aws->create_button("CLOSE", "CANCEL","C"); |
---|
119 | |
---|
120 | aws->at("save4");aws->callback(MG_save_cb); |
---|
121 | aws->create_button("SAVE","SAVE","S"); |
---|
122 | |
---|
123 | |
---|
124 | aws->at("user3"); |
---|
125 | aws->create_text_field(AWAR_DB_COMMENT); |
---|
126 | |
---|
127 | return (AW_window *)aws; |
---|
128 | } |
---|
129 | |
---|
130 | void |
---|
131 | MG_save_quick_cb(AW_window *aww) |
---|
132 | { |
---|
133 | char *name = aww->get_root()->awar(AWAR_MAIN_DB"/file_name")->read_string(); |
---|
134 | aw_openstatus("Saving database"); |
---|
135 | GB_begin_transaction(gb_dest); |
---|
136 | GBT_check_data(gb_dest,0); |
---|
137 | GB_commit_transaction(gb_dest); |
---|
138 | GB_ERROR error = GB_save_quick_as(gb_dest, name); |
---|
139 | aw_closestatus(); |
---|
140 | if (error) aw_message(error); |
---|
141 | else aww->get_root()->awar(AWAR_MAIN_DB"/directory")->touch(); |
---|
142 | delete name; |
---|
143 | } |
---|
144 | |
---|
145 | AW_window *MG_save_quick_result_cb(AW_root *aw_root, char *base_name) |
---|
146 | { |
---|
147 | static AW_window_simple *aws = 0; |
---|
148 | if (aws) return (AW_window *)aws; |
---|
149 | |
---|
150 | aws = new AW_window_simple; |
---|
151 | aws->init( aw_root, "SAVE_CHANGES_OF_DB_II_AS", "SAVE CHANGES TO DB2 AS", 10, 10 ); |
---|
152 | aws->load_xfig("sel_box.fig"); |
---|
153 | |
---|
154 | aws->at("close");aws->callback((AW_CB0)AW_POPDOWN); |
---|
155 | aws->create_button("CLOSE","CLOSE","C"); |
---|
156 | |
---|
157 | aws->at("save");aws->callback(MG_save_quick_cb); |
---|
158 | aws->create_button("SAVE","SAVE","S"); |
---|
159 | |
---|
160 | awt_create_selection_box((AW_window *)aws,base_name); |
---|
161 | |
---|
162 | return (AW_window *)aws; |
---|
163 | } |
---|
164 | |
---|
165 | // uses gb_dest and gb_merge |
---|
166 | void MG_start_cb2(AW_window *aww,AW_root *aw_root, int save_enabled) |
---|
167 | { |
---|
168 | mg_save_enabled = save_enabled; |
---|
169 | GB_transaction dummy2(gb_merge); |
---|
170 | // if (GB_read_clients(gb_merge) >= 0) { |
---|
171 | // awt_selection_list_rescan(gb_merge,AWT_NDS_FILTER); |
---|
172 | // } |
---|
173 | |
---|
174 | GB_transaction dummy(gb_dest); |
---|
175 | GBT_mark_all(gb_dest,0); |
---|
176 | // if (GB_read_clients(gb_merge) >= 0) { |
---|
177 | // awt_selection_list_rescan(gb_dest,AWT_NDS_FILTER); |
---|
178 | // } |
---|
179 | |
---|
180 | GB_change_my_security(gb_dest,6,"passwd"); |
---|
181 | GB_change_my_security(gb_merge,6,"passwd"); |
---|
182 | if (aww) aww->hide(); |
---|
183 | |
---|
184 | AW_window_simple_menu *awm = new AW_window_simple_menu(); |
---|
185 | awm->init(aw_root,"ARB_MERGE", "ARB_MERGE", 0,0,400,100); |
---|
186 | awm->load_xfig("merge/main.fig"); |
---|
187 | |
---|
188 | awm->create_menu( 0, "File", "F", "merge_file.hlp", AWM_ALL ); |
---|
189 | if (mg_save_enabled && GB_read_clients(gb_merge)>=0) { |
---|
190 | awm->insert_menu_topic("save_DB1","Save Data Base I ...", "S","save_as.hlp",AWM_ALL, AW_POPUP, (AW_CL)MG_save_source_cb,(AW_CL)AWAR_MERGE_DB ); |
---|
191 | } |
---|
192 | awm->insert_menu_topic("quit","Quit", "Q","quit.hlp", AWM_ALL, (AW_CB)MG_exit, 0, 0 ); |
---|
193 | |
---|
194 | awm->button_length(30); |
---|
195 | |
---|
196 | if (GB_read_clients(gb_merge)>=0){ // There is no reason to rename an newly created database |
---|
197 | awm->at("alignment"); |
---|
198 | awm->callback((AW_CB1)AW_POPUP,(AW_CL)MG_merge_alignment_cb); |
---|
199 | awm->help_text("mg_alignment.hlp"); |
---|
200 | awm->create_button("CHECK_ALIGNMENTS", "Check Alignments ..."); |
---|
201 | |
---|
202 | awm->at("names"); |
---|
203 | awm->callback((AW_CB1)AW_POPUP,(AW_CL)MG_merge_names_cb); |
---|
204 | awm->help_text("mg_names.hlp"); |
---|
205 | awm->create_button("CHECK_NAMES", "Check Names ..."); |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | |
---|
210 | awm->at("species"); |
---|
211 | awm->callback((AW_CB1)AW_POPUP,(AW_CL)MG_merge_species_cb); |
---|
212 | awm->help_text("mg_species.hlp"); |
---|
213 | awm->create_button("TRANSFER_SPECIES", "Transfer Species ... "); |
---|
214 | |
---|
215 | awm->at("extendeds"); |
---|
216 | awm->callback((AW_CB1)AW_POPUP,(AW_CL)MG_merge_extendeds_cb); |
---|
217 | awm->help_text("mg_extendeds.hlp"); |
---|
218 | awm->create_button("TRANSFER_SAIS", "Transfer SAIs ..."); |
---|
219 | |
---|
220 | awm->at("trees"); |
---|
221 | awm->callback((AW_CB1)AW_POPUP,(AW_CL)MG_merge_trees_cb); |
---|
222 | awm->help_text("mg_trees.hlp"); |
---|
223 | awm->create_button("TRANSFER_TREES", "Transfer Trees ..."); |
---|
224 | |
---|
225 | if (save_enabled && GB_read_clients(gb_dest)>=0){ // No need to save when importing data |
---|
226 | awm->at("save"); |
---|
227 | awm->callback(AW_POPUP,(AW_CL)MG_save_result_cb,(AW_CL)AWAR_MAIN_DB); |
---|
228 | awm->create_button("SAVE_WHOLE_DB2", "Save Whole DB II ..."); |
---|
229 | |
---|
230 | awm->at("save_quick"); |
---|
231 | awm->highlight(); |
---|
232 | awm->callback(AW_POPUP,(AW_CL)MG_save_quick_result_cb,(AW_CL)AWAR_MAIN_DB); |
---|
233 | awm->create_button("SAVE_CHANGES_OF_DB2", "Save Changes of DB II as ..."); |
---|
234 | } |
---|
235 | |
---|
236 | awm->button_length(15); |
---|
237 | |
---|
238 | awm->at("db1"); |
---|
239 | awm->create_button(0,AWAR_MERGE_DB"/file_name"); |
---|
240 | |
---|
241 | awm->at("db2"); |
---|
242 | awm->create_button(0,AWAR_MAIN_DB"/file_name"); |
---|
243 | |
---|
244 | awm->button_length(0); |
---|
245 | awm->shadow_width(1); |
---|
246 | awm->at("icon"); |
---|
247 | awm->callback(AW_POPUP_HELP, (AW_CL)"mg_main.hlp"); |
---|
248 | awm->create_button("HELP_MERGE", "#merge/icon.bitmap"); |
---|
249 | |
---|
250 | awm->show(); |
---|
251 | } |
---|
252 | |
---|
253 | void MG_start_cb(AW_window *aww) |
---|
254 | { |
---|
255 | AW_root *awr = aww->get_root(); |
---|
256 | |
---|
257 | char *merge = awr->awar(AWAR_MERGE_DB"/file_name")->read_string(); |
---|
258 | if (!strlen(merge) || (strcmp(merge,":") && GB_size_of_file(merge)<=0)) { |
---|
259 | aw_message("Cannot find database I file"); |
---|
260 | delete merge; |
---|
261 | return; |
---|
262 | } |
---|
263 | |
---|
264 | char *main = awr->awar(AWAR_MAIN_DB"/file_name")->read_string(); |
---|
265 | if (!strlen(main) || (strcmp(merge,":") && GB_size_of_file(main)<=0 )) { |
---|
266 | aw_message("Cannot find main file -> creating empty database"); |
---|
267 | } |
---|
268 | aw_openstatus("Loading databases"); |
---|
269 | |
---|
270 | aw_status("DATABASE I"); |
---|
271 | gb_merge = GBT_open(merge,"rw","$(ARBHOME)/lib/pts/*"); |
---|
272 | if (!gb_merge) { |
---|
273 | aw_message(GB_get_error()); |
---|
274 | delete merge; |
---|
275 | delete main; |
---|
276 | aw_closestatus(); |
---|
277 | return; |
---|
278 | } |
---|
279 | |
---|
280 | aw_status("DATABASE II"); |
---|
281 | gb_dest = GBT_open(main,"rwc","$(ARBHOME)/lib/pts/*"); |
---|
282 | aw_closestatus(); |
---|
283 | delete main; |
---|
284 | delete merge; |
---|
285 | |
---|
286 | if (!gb_dest) { |
---|
287 | aw_message(GB_get_error()); |
---|
288 | return; |
---|
289 | } |
---|
290 | MG_start_cb2(aww,aww->get_root()); |
---|
291 | } |
---|
292 | |
---|
293 | |
---|
294 | AW_window *create_merge_init_window(AW_root *awr) |
---|
295 | { |
---|
296 | AW_window_simple *aws = new AW_window_simple; |
---|
297 | aws->init( awr, "MERGE_SELECT_DATABASES", "MERGE SELECT TWO DATABASES", 100, 100 ); |
---|
298 | aws->load_xfig("merge/startup.fig"); |
---|
299 | |
---|
300 | aws->button_length( 10 ); |
---|
301 | aws->label_length( 10 ); |
---|
302 | |
---|
303 | aws->callback( (AW_CB0)exit); |
---|
304 | aws->at("close"); |
---|
305 | aws->create_button("QUIT","QUIT","A"); |
---|
306 | |
---|
307 | aws->callback(AW_POPUP_HELP,(AW_CL)"arb_merge.hlp"); |
---|
308 | aws->at("help"); |
---|
309 | aws->create_button("HELP","HELP","H"); |
---|
310 | |
---|
311 | awt_create_selection_box(aws,AWAR_MERGE_DB,""); |
---|
312 | aws->at("type"); |
---|
313 | aws->create_option_menu(AWAR_MERGE_DB"/filter"); |
---|
314 | aws->insert_option("ARB","A","arb"); |
---|
315 | aws->insert_default_option("OTHER","O",""); |
---|
316 | aws->update_option_menu(); |
---|
317 | |
---|
318 | awt_create_selection_box(aws,AWAR_MAIN_DB,"m"); |
---|
319 | aws->at("mtype"); |
---|
320 | aws->create_option_menu(AWAR_MAIN_DB"/filter"); |
---|
321 | aws->insert_option("ARB","A","arb"); |
---|
322 | aws->insert_default_option("OTHER","O",""); |
---|
323 | aws->update_option_menu(); |
---|
324 | |
---|
325 | aws->callback(MG_start_cb); |
---|
326 | aws->at("go"); |
---|
327 | aws->highlight(); |
---|
328 | aws->create_button("GO","GO","G"); |
---|
329 | |
---|
330 | aws->button_length(0); |
---|
331 | aws->shadow_width(1); |
---|
332 | aws->at("icon"); |
---|
333 | aws->callback(AW_POPUP_HELP,(AW_CL)"arb_merge.hlp"); |
---|
334 | aws->create_button("HELP_MERGE", "#merge/icon.bitmap"); |
---|
335 | |
---|
336 | return (AW_window *)aws; |
---|
337 | } |
---|
338 | |
---|
339 | void MG_create_all_awars(AW_root *awr, AW_default aw_def,const char *fname_one, const char *fname_two) |
---|
340 | { |
---|
341 | awr->awar_string( AWAR_MAIN_DB"/filter", "arb",aw_def); |
---|
342 | awr->awar_string( AWAR_MAIN_DB"/directory", "",aw_def); |
---|
343 | awr->awar_string( AWAR_MAIN_DB"/file_name", fname_two,aw_def); |
---|
344 | awr->awar_string( AWAR_MAIN_DB"/type", "b",aw_def); |
---|
345 | awr->awar_string( AWAR_MERGE_DB"/filter", "arb",aw_def); |
---|
346 | awr->awar_string( AWAR_MERGE_DB"/directory", "",aw_def); |
---|
347 | awr->awar_string( AWAR_MERGE_DB"/file_name", fname_one,aw_def); |
---|
348 | |
---|
349 | MG_create_trees_awar(awr,aw_def); |
---|
350 | MG_create_extendeds_var(awr,aw_def); |
---|
351 | MG_create_alignment_vars(awr,aw_def); |
---|
352 | MG_create_species_var(awr,aw_def); |
---|
353 | create_rename_variables(awr,aw_def); |
---|
354 | } |
---|
355 | |
---|
356 | AW_window * |
---|
357 | create_MG_main_window(AW_root *aw_root) |
---|
358 | { |
---|
359 | MG_create_all_awars(aw_root,AW_ROOT_DEFAULT); |
---|
360 | AW_window *aww=create_merge_init_window(aw_root); |
---|
361 | aww->show(); |
---|
362 | return aww; |
---|
363 | } |
---|
364 | |
---|
365 | |
---|