| 1 | #include "GDE_extglob.h" | 
|---|
| 2 | #include "GDE_awars.h" | 
|---|
| 3 |  | 
|---|
| 4 | #include <awt_sel_boxes.hxx> | 
|---|
| 5 | #include <awt_filter.hxx> | 
|---|
| 6 |  | 
|---|
| 7 | #include <aw_msg.hxx> | 
|---|
| 8 | #include <aw_awar.hxx> | 
|---|
| 9 | #include <aw_file.hxx> | 
|---|
| 10 | #include <aw_root.hxx> | 
|---|
| 11 | #include <aw_awar_defs.hxx> | 
|---|
| 12 | #include <aw_select.hxx> | 
|---|
| 13 |  | 
|---|
| 14 | #include <arb_str.h> | 
|---|
| 15 |  | 
|---|
| 16 | #include <cmath> | 
|---|
| 17 |  | 
|---|
| 18 | // AISC_MKPT_PROMOTE:#ifndef GDE_MENU_H | 
|---|
| 19 | // AISC_MKPT_PROMOTE:#include "GDE_menu.h" | 
|---|
| 20 | // AISC_MKPT_PROMOTE:#endif | 
|---|
| 21 |  | 
|---|
| 22 | adfiltercbstruct *agde_filter = 0; | 
|---|
| 23 |  | 
|---|
| 24 | Gmenu menu[GDEMAXMENU]; | 
|---|
| 25 | int   num_menus = 0; | 
|---|
| 26 |  | 
|---|
| 27 | static char GDEBLANK[] = "\0"; | 
|---|
| 28 |  | 
|---|
| 29 | #define SLIDERWIDTH 5           // input field width for numbers | 
|---|
| 30 |  | 
|---|
| 31 | struct gde_iteminfo { | 
|---|
| 32 | GmenuItem *item; | 
|---|
| 33 | int        idx; | 
|---|
| 34 | gde_iteminfo(GmenuItem *item_, int idx_) : item(item_), idx(idx_) {} | 
|---|
| 35 | }; | 
|---|
| 36 |  | 
|---|
| 37 | static void GDE_showhelp_cb(AW_window *aw, GmenuItem *gmenuitem, AW_CL /* cd */) { | 
|---|
| 38 | if (gmenuitem->help) { | 
|---|
| 39 | AW_help_popup(aw, gmenuitem->help); | 
|---|
| 40 | } | 
|---|
| 41 | else { | 
|---|
| 42 | aw_message("Sorry - no help available (please report to devel@arb-home.de)"); | 
|---|
| 43 | } | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | static char *GDE_makeawarname_in(GmenuItem *gmenuitem, long i, const char *awar_root) { | 
|---|
| 47 | char *gmenu_label     = GBS_string_2_key(gmenuitem->parent_menu->label); | 
|---|
| 48 | char *gmenuitem_label = GBS_string_2_key(gmenuitem->label); | 
|---|
| 49 | char *arg             = GBS_string_2_key(gmenuitem->arg[i].symbol); | 
|---|
| 50 |  | 
|---|
| 51 | char *name = GBS_global_string_copy("%s/%s/%s/%s", awar_root, gmenu_label, gmenuitem_label, arg); | 
|---|
| 52 |  | 
|---|
| 53 | free(gmenu_label); | 
|---|
| 54 | free(gmenuitem_label); | 
|---|
| 55 | free(arg); | 
|---|
| 56 |  | 
|---|
| 57 | return name; | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | char *GDE_makeawarname(GmenuItem *gmenuitem, long i) { return GDE_makeawarname_in(gmenuitem, i, "gde"); } | 
|---|
| 61 | char *GDE_maketmpawarname(GmenuItem *gmenuitem, long i) { return GDE_makeawarname_in(gmenuitem, i, "tmp/gde"); } | 
|---|
| 62 |  | 
|---|
| 63 | static void GDE_slide_awar_int_cb(AW_window *aws, AW_CL cl_awar_name, AW_CL cd_diff) | 
|---|
| 64 | { | 
|---|
| 65 | int      diff = (int)cd_diff; | 
|---|
| 66 | AW_awar *awar = aws->get_root()->awar((const char *)cl_awar_name); | 
|---|
| 67 |  | 
|---|
| 68 | awar->write_int(awar->read_int()+diff); | 
|---|
| 69 | } | 
|---|
| 70 | static void GDE_slide_awar_float_cb(AW_window *aws, AW_CL cl_awar_name, AW_CL cd_diff) | 
|---|
| 71 | { | 
|---|
| 72 | double   diff    = *(double*)(char*)/*avoid aliasing problems*/cd_diff; | 
|---|
| 73 | AW_awar *awar    = aws->get_root()->awar((const char *)cl_awar_name); | 
|---|
| 74 | double   new_val = awar->read_float()+diff; | 
|---|
| 75 |  | 
|---|
| 76 | if (fabs(new_val) < 0.0001) new_val = 0.0; | 
|---|
| 77 | awar->write_float(new_val); | 
|---|
| 78 |  | 
|---|
| 79 | // do it again (otherwise internal awar-range correction sometimes leads to 1+eXX values) | 
|---|
| 80 | new_val = awar->read_float(); | 
|---|
| 81 | if (fabs(new_val) < 0.0001) new_val = 0.0; | 
|---|
| 82 | awar->write_float(new_val); | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | static void GDE_create_infieldwithpm(AW_window *aws, char *newawar, long width) { | 
|---|
| 86 | aws->create_input_field(newawar, (int)width); | 
|---|
| 87 | if (aws->get_root()->awar(newawar)->get_type() == AW_INT) { | 
|---|
| 88 | aws->button_length(3); | 
|---|
| 89 | char *awar = strdup(newawar); | 
|---|
| 90 | aws->callback(GDE_slide_awar_int_cb, (AW_CL)awar, -1); aws->create_button(0, "-", "-"); | 
|---|
| 91 | aws->callback(GDE_slide_awar_int_cb, (AW_CL)awar, + 1); aws->create_button(0, "+", "+"); | 
|---|
| 92 | } | 
|---|
| 93 | else if (aws->get_root()->awar(newawar)->get_type() == AW_FLOAT) { | 
|---|
| 94 | aws->button_length(3); | 
|---|
| 95 | char *awar = strdup(newawar); | 
|---|
| 96 | aws->callback(GDE_slide_awar_float_cb, (AW_CL)awar, (AW_CL)new double(-0.1)); aws->create_button(0, "-", "-"); | 
|---|
| 97 | aws->callback(GDE_slide_awar_float_cb, (AW_CL)awar, (AW_CL)new double(+0.1)); aws->create_button(0, "+", "+"); | 
|---|
| 98 | } | 
|---|
| 99 | } | 
|---|
| 100 |  | 
|---|
| 101 | static char *gde_filter_weights(GBDATA *gb_sai, AW_CL) { | 
|---|
| 102 | char   *ali_name = GBT_get_default_alignment(GB_get_root(gb_sai)); | 
|---|
| 103 | GBDATA *gb_ali   = GB_entry(gb_sai, ali_name); | 
|---|
| 104 | char   *result   = 0; | 
|---|
| 105 |  | 
|---|
| 106 | if (gb_ali) { | 
|---|
| 107 | GBDATA *gb_type = GB_entry(gb_ali, "_TYPE"); | 
|---|
| 108 | if (gb_type) { | 
|---|
| 109 | const char *type = GB_read_char_pntr(gb_type); | 
|---|
| 110 |  | 
|---|
| 111 | if (GBS_string_matches(type, "PV?:*", GB_MIND_CASE)) { | 
|---|
| 112 | result = GBS_global_string_copy("%s: %s", GBT_read_name(gb_sai), type); | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | } | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 | free(ali_name); | 
|---|
| 119 | return result; | 
|---|
| 120 |  | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | static void refresh_weights_sellist_cb(AW_root*, AW_DB_selection *saisel) { | 
|---|
| 124 | saisel->refresh(); | 
|---|
| 125 | } | 
|---|
| 126 |  | 
|---|
| 127 | static AW_window *GDE_create_filename_browser_window(AW_root *aw_root, const char *awar_prefix, const char *title) { | 
|---|
| 128 | AW_window_simple *aws = new AW_window_simple; | 
|---|
| 129 |  | 
|---|
| 130 | { | 
|---|
| 131 | char *wid = GBS_string_2_key(awar_prefix); | 
|---|
| 132 | aws->init(aw_root, wid, title); | 
|---|
| 133 | free(wid); | 
|---|
| 134 | } | 
|---|
| 135 | aws->load_xfig("sel_box.fig"); | 
|---|
| 136 |  | 
|---|
| 137 | aws->at("close"); | 
|---|
| 138 | aws->callback((AW_CB0) AW_POPDOWN); | 
|---|
| 139 | aws->create_button("CLOSE", "CLOSE", "C"); | 
|---|
| 140 |  | 
|---|
| 141 | AW_create_standard_fileselection(aws, awar_prefix); | 
|---|
| 142 |  | 
|---|
| 143 | return aws; | 
|---|
| 144 | } | 
|---|
| 145 |  | 
|---|
| 146 | static void GDE_popup_filename_browser(AW_window *aw, AW_CL cl_iteminfo, AW_CL cl_title) { | 
|---|
| 147 | gde_iteminfo *info         = (gde_iteminfo*)cl_iteminfo; | 
|---|
| 148 | GmenuItem    *gmenuitem    = info->item; | 
|---|
| 149 | int           idx          = info->idx; | 
|---|
| 150 | char         *base_awar    = GDE_maketmpawarname(gmenuitem, idx); | 
|---|
| 151 |  | 
|---|
| 152 | static GB_HASH *popup_hash  = NULL; | 
|---|
| 153 | if (!popup_hash) popup_hash = GBS_create_hash(20, GB_MIND_CASE); | 
|---|
| 154 |  | 
|---|
| 155 | AW_window *aw_browser = (AW_window*)GBS_read_hash(popup_hash, base_awar); | 
|---|
| 156 | if (!aw_browser) { | 
|---|
| 157 | const char *title = (const char *)cl_title; | 
|---|
| 158 | aw_browser        = GDE_create_filename_browser_window(aw->get_root(), base_awar, title); | 
|---|
| 159 | GBS_write_hash(popup_hash, base_awar, (long)aw_browser); | 
|---|
| 160 | } | 
|---|
| 161 | aw_browser->activate(); | 
|---|
| 162 | free(base_awar); | 
|---|
| 163 | } | 
|---|
| 164 |  | 
|---|
| 165 | static AW_window *GDE_menuitem_cb(AW_root *aw_root, GmenuItem *gmenuitem) { | 
|---|
| 166 | #define BUFSIZE 200 | 
|---|
| 167 | char bf[BUFSIZE+1]; | 
|---|
| 168 | IF_ASSERTION_USED(int printed =) | 
|---|
| 169 | sprintf(bf, "GDE / %s / %s", gmenuitem->parent_menu->label, gmenuitem->label); | 
|---|
| 170 |  | 
|---|
| 171 | gde_assert(printed<=BUFSIZE); | 
|---|
| 172 | char seqtype = gmenuitem->seqtype; | 
|---|
| 173 |  | 
|---|
| 174 | if (gmenuitem->aws == NULL) { | 
|---|
| 175 | AW_window_simple *aws = new AW_window_simple; | 
|---|
| 176 | aws->init(aw_root, bf, bf); | 
|---|
| 177 |  | 
|---|
| 178 | switch (db_access.window_type) { | 
|---|
| 179 | case GDE_WINDOWTYPE_DEFAULT: { | 
|---|
| 180 | if (seqtype == '-') aws->load_xfig("gdeitem_simple.fig"); | 
|---|
| 181 | else                aws->load_xfig("gdeitem.fig"); | 
|---|
| 182 | break; | 
|---|
| 183 | } | 
|---|
| 184 | case GDE_WINDOWTYPE_EDIT4: | 
|---|
| 185 | gde_assert(seqtype != '-'); | 
|---|
| 186 | aws->load_xfig("gde3item.fig"); | 
|---|
| 187 | break; | 
|---|
| 188 | } | 
|---|
| 189 |  | 
|---|
| 190 | aws->button_length(10); | 
|---|
| 191 | aws->at(10, 10); | 
|---|
| 192 | aws->auto_space(0, 10); | 
|---|
| 193 |  | 
|---|
| 194 | aws->at("help"); | 
|---|
| 195 | aws->callback((AW_CB2)GDE_showhelp_cb, (AW_CL)gmenuitem, 0); | 
|---|
| 196 | aws->create_button("GDE_HELP", "HELP", "H"); | 
|---|
| 197 |  | 
|---|
| 198 | aws->at("start"); | 
|---|
| 199 | aws->callback((AW_CB2)GDE_startaction_cb, (AW_CL)gmenuitem, 0); | 
|---|
| 200 | aws->create_button("GO", "GO", "O"); | 
|---|
| 201 |  | 
|---|
| 202 | aws->at("cancel"); | 
|---|
| 203 | aws->callback((AW_CB0)AW_POPDOWN); | 
|---|
| 204 | aws->create_button("CLOSE", "CLOSE", "C"); | 
|---|
| 205 |  | 
|---|
| 206 |  | 
|---|
| 207 | if (gmenuitem->numinputs>0) { | 
|---|
| 208 | switch (db_access.window_type) { | 
|---|
| 209 | case GDE_WINDOWTYPE_DEFAULT: { | 
|---|
| 210 | if (seqtype != '-') { // '-' means "skip sequence export" | 
|---|
| 211 | aws->at("which_alignment"); | 
|---|
| 212 | const char *ali_filter = seqtype == 'A' ? "pro=:ami=" : (seqtype == 'N' ? "dna=:rna=" : "*="); | 
|---|
| 213 | awt_create_ALI_selection_list(db_access.gb_main, (AW_window *)aws, AWAR_GDE_ALIGNMENT, ali_filter); | 
|---|
| 214 |  | 
|---|
| 215 | aws->at("which_species"); | 
|---|
| 216 | aws->create_toggle_field(AWAR_GDE_SPECIES); | 
|---|
| 217 | aws->insert_toggle("all", "a", 0); | 
|---|
| 218 | aws->insert_default_toggle("marked",   "m", 1); | 
|---|
| 219 | aws->update_toggle_field(); | 
|---|
| 220 |  | 
|---|
| 221 | if (seqtype != 'N') { | 
|---|
| 222 | aws->at("stop_codon"); | 
|---|
| 223 | aws->label("Cut stop-codon"); | 
|---|
| 224 | aws->create_toggle(AWAR_GDE_CUTOFF_STOPCODON); | 
|---|
| 225 | } | 
|---|
| 226 | } | 
|---|
| 227 | break; | 
|---|
| 228 | } | 
|---|
| 229 | case GDE_WINDOWTYPE_EDIT4: | 
|---|
| 230 | aws->at("topk"); aws->create_toggle("gde/top_area_kons"); | 
|---|
| 231 | aws->at("middlek"); aws->create_toggle("gde/middle_area_kons"); | 
|---|
| 232 | aws->at("topr"); aws->create_toggle("gde/top_area_remark"); | 
|---|
| 233 | aws->at("middler"); aws->create_toggle("gde/middle_area_remark"); | 
|---|
| 234 | aws->at("top"); aws->create_toggle("gde/top_area"); | 
|---|
| 235 | aws->at("topsai"); aws->create_toggle("gde/top_area_sai"); | 
|---|
| 236 | aws->at("toph"); aws->create_toggle("gde/top_area_helix"); | 
|---|
| 237 | aws->at("middle"); aws->create_toggle("gde/middle_area"); | 
|---|
| 238 | aws->at("middlesai"); aws->create_toggle("gde/middle_area_sai"); | 
|---|
| 239 | aws->at("middleh"); aws->create_toggle("gde/middle_area_helix"); | 
|---|
| 240 | break; | 
|---|
| 241 | } | 
|---|
| 242 |  | 
|---|
| 243 | if (seqtype != '-') { | 
|---|
| 244 | aws->at("compression"); | 
|---|
| 245 | aws->create_option_menu(AWAR_GDE_COMPRESSION, true); | 
|---|
| 246 | aws->insert_option("none", "n", COMPRESS_NONE); | 
|---|
| 247 | aws->insert_option("vertical gaps", "v", COMPRESS_VERTICAL_GAPS); | 
|---|
| 248 | aws->insert_default_option("columns w/o info", "i", COMPRESS_NONINFO_COLUMNS); | 
|---|
| 249 | aws->insert_option("all gaps", "g", COMPRESS_ALL); | 
|---|
| 250 | aws->update_option_menu(); | 
|---|
| 251 |  | 
|---|
| 252 | aws->button_length(12); | 
|---|
| 253 | aws->at("filtername"); | 
|---|
| 254 | if (!agde_filter) { // create only one filter - used for all GDE calls | 
|---|
| 255 | agde_filter = awt_create_select_filter(aws->get_root(), db_access.gb_main, AWAR_GDE_FILTER_NAME); | 
|---|
| 256 | } | 
|---|
| 257 | aws->callback(makeCreateWindowCallback(awt_create_select_filter_win, agde_filter)); | 
|---|
| 258 | aws->create_button("SELECT_FILTER", AWAR_GDE_FILTER_NAME); | 
|---|
| 259 | } | 
|---|
| 260 |  | 
|---|
| 261 | aws->at("paramsb"); | 
|---|
| 262 | } | 
|---|
| 263 | else { | 
|---|
| 264 | aws->at("paramsb"); | 
|---|
| 265 | } | 
|---|
| 266 |  | 
|---|
| 267 |  | 
|---|
| 268 | int labellength = 1; | 
|---|
| 269 | long i; | 
|---|
| 270 | for (i=0; i<gmenuitem->numargs; i++) { | 
|---|
| 271 | if (!(gmenuitem->arg[i].label)) gmenuitem->arg[i].label = GDEBLANK; | 
|---|
| 272 |  | 
|---|
| 273 | const char *label    = gmenuitem->arg[i].label; | 
|---|
| 274 | const char *linefeed = strchr(label, '\n'); | 
|---|
| 275 |  | 
|---|
| 276 | int lablen; | 
|---|
| 277 | while (linefeed) { | 
|---|
| 278 | lablen = linefeed-label; | 
|---|
| 279 | if (lablen>labellength) { | 
|---|
| 280 | labellength = lablen; | 
|---|
| 281 | } | 
|---|
| 282 | label    = linefeed+1; | 
|---|
| 283 | linefeed = strchr(label, '\n'); | 
|---|
| 284 | } | 
|---|
| 285 |  | 
|---|
| 286 | lablen = strlen(label); | 
|---|
| 287 | if (lablen>labellength) { | 
|---|
| 288 | labellength = lablen; | 
|---|
| 289 | } | 
|---|
| 290 | } | 
|---|
| 291 | aws->label_length(labellength); | 
|---|
| 292 | aws->auto_space(0, 0); | 
|---|
| 293 |  | 
|---|
| 294 | for (i=0; i<gmenuitem->numargs; i++) { | 
|---|
| 295 | GmenuItemArg itemarg = gmenuitem->arg[i]; | 
|---|
| 296 |  | 
|---|
| 297 | if (itemarg.type==SLIDER) { | 
|---|
| 298 | char *newawar=GDE_makeawarname(gmenuitem, i); | 
|---|
| 299 | if (int(itemarg.fvalue) == itemarg.fvalue && | 
|---|
| 300 | int(itemarg.min) == itemarg.min && | 
|---|
| 301 | int(itemarg.max) == itemarg.max) { | 
|---|
| 302 | aw_root->awar_int(newawar, (long)itemarg.fvalue, AW_ROOT_DEFAULT); | 
|---|
| 303 | } | 
|---|
| 304 | else { | 
|---|
| 305 | aw_root->awar_float(newawar, itemarg.fvalue, AW_ROOT_DEFAULT); | 
|---|
| 306 | } | 
|---|
| 307 | aw_root->awar(newawar)->set_minmax(itemarg.min, itemarg.max); | 
|---|
| 308 | aws->label(itemarg.label); | 
|---|
| 309 | aws->sens_mask(itemarg.active_mask); | 
|---|
| 310 | GDE_create_infieldwithpm(aws, newawar, SLIDERWIDTH); | 
|---|
| 311 | // maybe bound checking // | 
|---|
| 312 | free(newawar); | 
|---|
| 313 | } | 
|---|
| 314 | else if (itemarg.type==CHOOSER) { | 
|---|
| 315 | char    *defopt           = itemarg.choice[0].method; | 
|---|
| 316 | char    *newawar          = GDE_makeawarname(gmenuitem, i); | 
|---|
| 317 | AW_awar *curr_awar        = aw_root->awar_string(newawar, defopt, AW_ROOT_DEFAULT); | 
|---|
| 318 | char    *curr_value       = curr_awar->read_string(); | 
|---|
| 319 | bool     curr_value_legal = false; | 
|---|
| 320 |  | 
|---|
| 321 | aws->label(itemarg.label); | 
|---|
| 322 | aws->sens_mask(itemarg.active_mask); | 
|---|
| 323 | if ((strcasecmp(itemarg.choice[0].label, "no") == 0) || | 
|---|
| 324 | (strcasecmp(itemarg.choice[0].label, "yes") == 0)) | 
|---|
| 325 | { | 
|---|
| 326 | aws->create_toggle_field(newawar, 1); | 
|---|
| 327 | } | 
|---|
| 328 | else { | 
|---|
| 329 | aws->create_toggle_field(newawar); | 
|---|
| 330 | } | 
|---|
| 331 |  | 
|---|
| 332 | for (long j=0; j<itemarg.numchoices; j++) { | 
|---|
| 333 | if (strcmp(itemarg.choice[j].method, curr_value) == 0) curr_value_legal = true; | 
|---|
| 334 |  | 
|---|
| 335 | if (!j) { | 
|---|
| 336 | aws->insert_default_toggle(itemarg.choice[j].label, "1", itemarg.choice[j].method); | 
|---|
| 337 | } | 
|---|
| 338 | else { | 
|---|
| 339 | aws->insert_toggle(itemarg.choice[j].label, "1", itemarg.choice[j].method); | 
|---|
| 340 | } | 
|---|
| 341 | } | 
|---|
| 342 | if (!curr_value_legal) curr_awar->write_string(defopt); // if saved value no longer occurs in choice -> overwrite with default | 
|---|
| 343 | free(curr_value); | 
|---|
| 344 | aws->update_toggle_field(); | 
|---|
| 345 | free(newawar); | 
|---|
| 346 | } | 
|---|
| 347 | else if (itemarg.type==CHOICE_MENU) { | 
|---|
| 348 | char    *defopt           = itemarg.choice[itemarg.ivalue].method; | 
|---|
| 349 | char    *newawar          = GDE_makeawarname(gmenuitem, i); | 
|---|
| 350 | AW_awar *curr_awar        = aw_root->awar_string(newawar, defopt, AW_ROOT_DEFAULT); | 
|---|
| 351 | char    *curr_value       = curr_awar->read_string(); | 
|---|
| 352 | bool     curr_value_legal = false; | 
|---|
| 353 |  | 
|---|
| 354 | if (itemarg.label[0]) aws->label(itemarg.label); | 
|---|
| 355 | aws->sens_mask(itemarg.active_mask); | 
|---|
| 356 | aws->create_option_menu(newawar, true); | 
|---|
| 357 |  | 
|---|
| 358 | for (long j=0; j<itemarg.numchoices; j++) { | 
|---|
| 359 | if (strcmp(itemarg.choice[j].method, curr_value) == 0) curr_value_legal = true; | 
|---|
| 360 | aws->insert_option(itemarg.choice[j].label, "1", itemarg.choice[j].method); | 
|---|
| 361 | } | 
|---|
| 362 | if (!curr_value_legal) curr_awar->write_string(defopt); // if saved value no longer occurs in choice -> overwrite with default | 
|---|
| 363 | free(curr_value); | 
|---|
| 364 | aws->update_option_menu(); | 
|---|
| 365 | free(newawar); | 
|---|
| 366 | } | 
|---|
| 367 | else if (itemarg.type==TEXTFIELD) { | 
|---|
| 368 | char *defopt  = itemarg.textvalue; | 
|---|
| 369 | char *newawar = GDE_makeawarname(gmenuitem, i); | 
|---|
| 370 | aw_root->awar_string(newawar, defopt, AW_ROOT_DEFAULT); | 
|---|
| 371 | aws->label(itemarg.label); | 
|---|
| 372 | aws->sens_mask(itemarg.active_mask); | 
|---|
| 373 | aws->create_input_field(newawar, itemarg.textwidth);  // TEXTFIELDWIDTH | 
|---|
| 374 | free(newawar); | 
|---|
| 375 | } | 
|---|
| 376 | else if (itemarg.type==FILE_SELECTOR) { | 
|---|
| 377 | char *base_awar = GDE_maketmpawarname(gmenuitem, i); | 
|---|
| 378 | char *name_awar = GBS_global_string_copy("%s/file_name", base_awar); | 
|---|
| 379 |  | 
|---|
| 380 | AW_create_fileselection_awars(aw_root, base_awar, "", itemarg.textvalue, ""); | 
|---|
| 381 |  | 
|---|
| 382 | aws->label(itemarg.label); | 
|---|
| 383 | aws->sens_mask(itemarg.active_mask); | 
|---|
| 384 | aws->create_input_field(name_awar, 40); | 
|---|
| 385 | aws->callback(GDE_popup_filename_browser, (AW_CL)new gde_iteminfo(gmenuitem, i), (AW_CL)strdup(itemarg.label)); | 
|---|
| 386 | aws->create_button("", "Browse"); | 
|---|
| 387 |  | 
|---|
| 388 | free(name_awar); | 
|---|
| 389 | free(base_awar); | 
|---|
| 390 | } | 
|---|
| 391 | else if (itemarg.type==CHOICE_TREE) { | 
|---|
| 392 | char *defopt=itemarg.textvalue; | 
|---|
| 393 | char *newawar=GDE_makeawarname(gmenuitem, i); | 
|---|
| 394 | aw_root->awar_string(newawar, defopt, AW_ROOT_DEFAULT); | 
|---|
| 395 | aws->sens_mask(itemarg.active_mask); | 
|---|
| 396 | if (itemarg.label[0]) aws->create_button(NULL, itemarg.label); | 
|---|
| 397 | awt_create_TREE_selection_list(db_access.gb_main, aws, newawar, true); | 
|---|
| 398 | free(newawar); | 
|---|
| 399 | } | 
|---|
| 400 | else if (itemarg.type==CHOICE_SAI) { | 
|---|
| 401 | char *defopt=itemarg.textvalue; | 
|---|
| 402 | char *newawar=GDE_makeawarname(gmenuitem, i); | 
|---|
| 403 | aw_root->awar_string(newawar, defopt, AW_ROOT_DEFAULT); | 
|---|
| 404 | aws->sens_mask(itemarg.active_mask); | 
|---|
| 405 | if (itemarg.label[0]) aws->create_button(NULL, itemarg.label); | 
|---|
| 406 | awt_create_SAI_selection_list(db_access.gb_main, aws, newawar, true); | 
|---|
| 407 | free(newawar); | 
|---|
| 408 | } | 
|---|
| 409 | else if (itemarg.type==CHOICE_WEIGHTS) { | 
|---|
| 410 | char *defopt  = itemarg.textvalue; | 
|---|
| 411 | char *newawar = GDE_makeawarname(gmenuitem, i); | 
|---|
| 412 |  | 
|---|
| 413 | aw_root->awar_string(newawar, defopt, AW_ROOT_DEFAULT); | 
|---|
| 414 | aws->sens_mask(itemarg.active_mask); | 
|---|
| 415 | if (itemarg.label[0]) aws->create_button(NULL, itemarg.label); | 
|---|
| 416 | AW_DB_selection *saisel = awt_create_SAI_selection_list(db_access.gb_main, aws, newawar, true, gde_filter_weights); | 
|---|
| 417 | free(newawar); | 
|---|
| 418 | aw_root->awar(AWAR_GDE_ALIGNMENT)->add_callback(makeRootCallback(refresh_weights_sellist_cb, saisel)); | 
|---|
| 419 | } | 
|---|
| 420 |  | 
|---|
| 421 | aws->at_newline(); | 
|---|
| 422 | } | 
|---|
| 423 | aws->at_newline(); | 
|---|
| 424 | aws->window_fit(); | 
|---|
| 425 |  | 
|---|
| 426 | gmenuitem->aws = aws; | 
|---|
| 427 | } | 
|---|
| 428 | return gmenuitem->aws; | 
|---|
| 429 | #undef BUFSIZE | 
|---|
| 430 | } | 
|---|
| 431 |  | 
|---|
| 432 |  | 
|---|
| 433 |  | 
|---|
| 434 |  | 
|---|
| 435 | void GDE_load_menu(AW_window *awm, AW_active /*mask*/, const char *menulabel) { | 
|---|
| 436 | // Load GDE menu items. | 
|---|
| 437 | // | 
|---|
| 438 | // If 'menulabel' == NULL -> load all menus | 
|---|
| 439 | // Else                   -> load specified menu | 
|---|
| 440 | // | 
|---|
| 441 | // Always loads complete menu(s). | 
|---|
| 442 |  | 
|---|
| 443 | gde_assert(db_access.gb_main); // forgot to call GDE_init() ? | 
|---|
| 444 |  | 
|---|
| 445 | char hotkey[]   = "x"; | 
|---|
| 446 | bool menuloaded = false; | 
|---|
| 447 |  | 
|---|
| 448 | for (long nmenu = 0; nmenu<num_menus; nmenu++) { | 
|---|
| 449 | { | 
|---|
| 450 | const char *menuname = menu[nmenu].label; | 
|---|
| 451 | if (menulabel) { | 
|---|
| 452 | if (strcmp(menulabel, menuname)) { | 
|---|
| 453 | continue; | 
|---|
| 454 | } | 
|---|
| 455 | } | 
|---|
| 456 | else { | 
|---|
| 457 | hotkey[0] = menu[nmenu].meta; | 
|---|
| 458 | awm->insert_sub_menu(menuname, hotkey, menu[nmenu].active_mask); | 
|---|
| 459 | } | 
|---|
| 460 | } | 
|---|
| 461 |  | 
|---|
| 462 | menuloaded = true; | 
|---|
| 463 |  | 
|---|
| 464 | long num_items = menu[nmenu].numitems; | 
|---|
| 465 | for (long nitem=0; nitem<num_items; nitem++) { | 
|---|
| 466 | GmenuItem *menuitem=&menu[nmenu].item[nitem]; | 
|---|
| 467 | gde_assert(!menuitem->help || ARB_strBeginsWith(menuitem->help, "agde_")); | 
|---|
| 468 | hotkey[0] = menuitem->meta; | 
|---|
| 469 | awm->insert_menu_topic(menuitem->label, menuitem->label, hotkey, | 
|---|
| 470 | menuitem->help, menuitem->active_mask, | 
|---|
| 471 | AW_POPUP, (AW_CL)GDE_menuitem_cb, (AW_CL)menuitem); | 
|---|
| 472 | } | 
|---|
| 473 |  | 
|---|
| 474 | if (!menulabel) { | 
|---|
| 475 | awm->close_sub_menu(); | 
|---|
| 476 | } | 
|---|
| 477 | } | 
|---|
| 478 |  | 
|---|
| 479 | if (!menuloaded && menulabel) { | 
|---|
| 480 | fprintf(stderr, "GDE-Warning: Could not find requested menu '%s'\n", menulabel); | 
|---|
| 481 | } | 
|---|
| 482 | } | 
|---|
| 483 |  | 
|---|
| 484 | struct gde_database_access db_access = { NULL, NULL, GDE_WINDOWTYPE_DEFAULT, 0, NULL}; | 
|---|
| 485 |  | 
|---|
| 486 | GB_ERROR GDE_init(AW_root *aw_root, AW_default aw_def, GBDATA *gb_main, GDE_get_sequences_cb get_sequences, GDE_format_alignment_cb format_ali, gde_window_type window_type, AW_CL client_data) { | 
|---|
| 487 | db_access.get_sequences = get_sequences; | 
|---|
| 488 | db_access.format_ali    = format_ali; | 
|---|
| 489 | db_access.window_type   = window_type; | 
|---|
| 490 | db_access.client_data   = client_data; | 
|---|
| 491 | db_access.gb_main       = gb_main; | 
|---|
| 492 |  | 
|---|
| 493 | aw_root->awar_string(AWAR_GDE_ALIGNMENT, "", aw_def); | 
|---|
| 494 |  | 
|---|
| 495 | switch (db_access.window_type) { | 
|---|
| 496 | case GDE_WINDOWTYPE_EDIT4: | 
|---|
| 497 | aw_root->awar_int("gde/top_area_kons",      1, aw_def); | 
|---|
| 498 | aw_root->awar_int("gde/top_area_remark",    1, aw_def); | 
|---|
| 499 | aw_root->awar_int("gde/middle_area_kons",   1, aw_def); | 
|---|
| 500 | aw_root->awar_int("gde/middle_area_remark", 1, aw_def); | 
|---|
| 501 | aw_root->awar_int("gde/top_area",           1, aw_def); | 
|---|
| 502 | aw_root->awar_int("gde/top_area_sai",       1, aw_def); | 
|---|
| 503 | aw_root->awar_int("gde/top_area_helix",     1, aw_def); | 
|---|
| 504 | aw_root->awar_int("gde/middle_area",        1, aw_def); | 
|---|
| 505 | aw_root->awar_int("gde/middle_area_sai",    1, aw_def); | 
|---|
| 506 | aw_root->awar_int("gde/middle_area_helix",  1, aw_def); | 
|---|
| 507 | aw_root->awar_int("gde/bottom_area",        1, aw_def); | 
|---|
| 508 | aw_root->awar_int("gde/bottom_area_sai",    1, aw_def); | 
|---|
| 509 | aw_root->awar_int("gde/bottom_area_helix",  1, aw_def); | 
|---|
| 510 | break; | 
|---|
| 511 | case GDE_WINDOWTYPE_DEFAULT: | 
|---|
| 512 | break; | 
|---|
| 513 | } | 
|---|
| 514 |  | 
|---|
| 515 | aw_root->awar_string(AWAR_DEFAULT_ALIGNMENT, "", db_access.gb_main); | 
|---|
| 516 |  | 
|---|
| 517 | aw_root->awar_string(AWAR_GDE_FILTER_NAME,      "", aw_def); | 
|---|
| 518 | aw_root->awar_string(AWAR_GDE_FILTER_FILTER,    "", aw_def); | 
|---|
| 519 | aw_root->awar_string(AWAR_GDE_FILTER_ALIGNMENT, "", aw_def); | 
|---|
| 520 |  | 
|---|
| 521 | aw_root->awar_int(AWAR_GDE_CUTOFF_STOPCODON, 0, aw_def); | 
|---|
| 522 | aw_root->awar_int(AWAR_GDE_SPECIES,          1, aw_def); | 
|---|
| 523 |  | 
|---|
| 524 | aw_root->awar_int(AWAR_GDE_COMPRESSION, COMPRESS_NONINFO_COLUMNS, aw_def); | 
|---|
| 525 |  | 
|---|
| 526 | aw_root->awar(AWAR_GDE_ALIGNMENT)->map(AWAR_DEFAULT_ALIGNMENT); | 
|---|
| 527 | aw_root->awar(AWAR_GDE_FILTER_ALIGNMENT)->map(AWAR_DEFAULT_ALIGNMENT); | 
|---|
| 528 |  | 
|---|
| 529 | return LoadMenus(); | 
|---|
| 530 | } | 
|---|
| 531 |  | 
|---|