| 1 | #include <stdio.h> |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <string.h> |
|---|
| 4 | #include <arbdb.h> |
|---|
| 5 | #include <arbdbt.h> |
|---|
| 6 | #include <aw_root.hxx> |
|---|
| 7 | #include <aw_device.hxx> |
|---|
| 8 | #include <aw_window.hxx> |
|---|
| 9 | #include <aw_awars.hxx> |
|---|
| 10 | |
|---|
| 11 | #include "awt.hxx" |
|---|
| 12 | #include "awtfilter.hxx" |
|---|
| 13 | #include <awt_tree.hxx> |
|---|
| 14 | #include <awt_sel_boxes.hxx> |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | /** recalc filter */ |
|---|
| 19 | void awt_create_select_filter_window_aw_cb(void *dummy, struct adfiltercbstruct *cbs) |
|---|
| 20 | { // update the variables |
|---|
| 21 | AW_root *aw_root = cbs->awr; |
|---|
| 22 | AWUSE(dummy); |
|---|
| 23 | char buffer[256]; |
|---|
| 24 | GB_push_transaction(cbs->gb_main); |
|---|
| 25 | char *target = aw_root->awar(cbs->def_subname)->read_string(); |
|---|
| 26 | char *to_free_target = target; |
|---|
| 27 | char *use = aw_root->awar(cbs->def_alignment)->read_string(); |
|---|
| 28 | char *name = strchr(target,1); |
|---|
| 29 | GBDATA *gbd = 0; |
|---|
| 30 | if (name){ |
|---|
| 31 | *(name++) = 0; |
|---|
| 32 | target++; |
|---|
| 33 | GBDATA *gb_species; |
|---|
| 34 | if (target[-1] == '@'){ |
|---|
| 35 | gb_species = GBT_find_species(cbs->gb_main,name); |
|---|
| 36 | }else{ |
|---|
| 37 | gb_species = GBT_find_SAI(cbs->gb_main,name); |
|---|
| 38 | } |
|---|
| 39 | if (gb_species){ |
|---|
| 40 | GBDATA *gb_ali = GB_search(gb_species,use,GB_FIND); |
|---|
| 41 | if (gb_ali) { |
|---|
| 42 | gbd = GB_search(gb_ali,target,GB_FIND); |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | if (!gbd){ // nothing selected |
|---|
| 47 | aw_root->awar(cbs->def_name)->write_string("none"); |
|---|
| 48 | aw_root->awar(cbs->def_source)->write_string("No Filter Sequence ->All Columns Selected"); |
|---|
| 49 | aw_root->awar(cbs->def_filter)->write_string(""); |
|---|
| 50 | aw_root->awar(cbs->def_len) ->write_int(-1); // export filter |
|---|
| 51 | }else{ |
|---|
| 52 | GBDATA *gb_name = GB_get_father(gbd); // ali_xxxx |
|---|
| 53 | gb_name = GB_brother(gb_name,"name"); |
|---|
| 54 | char *name2 = GB_read_string(gb_name); |
|---|
| 55 | aw_root->awar(cbs->def_name)->write_string(name2); |
|---|
| 56 | free(name2); |
|---|
| 57 | char *_2filter = aw_root->awar(cbs->def_2filter)->read_string(); |
|---|
| 58 | long _2filter_len = strlen(_2filter); |
|---|
| 59 | |
|---|
| 60 | char *s,*str; |
|---|
| 61 | long len = GBT_get_alignment_len(cbs->gb_main,use); |
|---|
| 62 | GBS_strstruct *strstruct = GBS_stropen(5000); |
|---|
| 63 | long i; for (i=0;i<len;i++) { // build position line |
|---|
| 64 | if (i%10 == 0) { |
|---|
| 65 | GBS_chrcat(strstruct,'#'); |
|---|
| 66 | }else if (i%5==0) { |
|---|
| 67 | GBS_chrcat(strstruct,'|'); |
|---|
| 68 | }else{ |
|---|
| 69 | GBS_chrcat(strstruct,'.'); |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | GBS_chrcat(strstruct,'\n'); |
|---|
| 73 | char *data = GBS_mempntr(strstruct); |
|---|
| 74 | |
|---|
| 75 | for (i=0;i<len-10;i++) { // place markers |
|---|
| 76 | if (i%10 == 0) { |
|---|
| 77 | sprintf(buffer,"%li",i+1); |
|---|
| 78 | strncpy(data+i+1,buffer,strlen(buffer)); |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | if (GB_read_type(gbd) == GB_STRING) { // read the filter |
|---|
| 83 | str = GB_read_string(gbd); |
|---|
| 84 | }else{ |
|---|
| 85 | str = GB_read_bits(gbd,'-','+'); |
|---|
| 86 | } |
|---|
| 87 | GBS_strcat(strstruct,str); |
|---|
| 88 | GBS_chrcat(strstruct,'\n'); |
|---|
| 89 | char *canc = aw_root->awar(cbs->def_cancel)->read_string(); |
|---|
| 90 | long min = aw_root->awar(cbs->def_min)->read_int()-1; |
|---|
| 91 | long max = aw_root->awar(cbs->def_max)->read_int()-1; |
|---|
| 92 | long flen = 0; |
|---|
| 93 | for (i=0,s=str; *s; ++s,++i){ // transform the filter |
|---|
| 94 | if (strchr(canc,*s) || (i<min) || (max>0 && i > max) ) |
|---|
| 95 | { |
|---|
| 96 | *s = '0'; |
|---|
| 97 | }else{ |
|---|
| 98 | if (i > _2filter_len || _2filter[i] != '0') { |
|---|
| 99 | *s = '1'; |
|---|
| 100 | flen++; |
|---|
| 101 | }else{ |
|---|
| 102 | *s = '0'; |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | GBS_strcat(strstruct,str); |
|---|
| 107 | GBS_chrcat(strstruct,'\n'); |
|---|
| 108 | data = GBS_strclose(strstruct); |
|---|
| 109 | aw_root->awar(cbs->def_len) ->write_int(flen); // export filter |
|---|
| 110 | aw_root->awar(cbs->def_filter)->write_string(str); // export filter |
|---|
| 111 | aw_root->awar(cbs->def_source)->write_string(data); // set display |
|---|
| 112 | free(_2filter); |
|---|
| 113 | free(str); |
|---|
| 114 | free(canc); |
|---|
| 115 | free(data); |
|---|
| 116 | } |
|---|
| 117 | free(to_free_target); |
|---|
| 118 | free(use); |
|---|
| 119 | GB_pop_transaction(cbs->gb_main); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | static void awt_add_sequences_to_list(struct adfiltercbstruct *cbs, const char *use, GBDATA *gb_extended, const char *pre, char tpre) { |
|---|
| 123 | GBDATA *gb_ali = GB_entry(gb_extended, use); |
|---|
| 124 | |
|---|
| 125 | if (gb_ali) { |
|---|
| 126 | int count = 0; |
|---|
| 127 | GBDATA *gb_type = GB_entry(gb_ali, "_TYPE"); |
|---|
| 128 | const char *TYPE = gb_type ? GB_read_char_pntr(gb_type) : ""; |
|---|
| 129 | const char *name = GBT_read_name(gb_extended); |
|---|
| 130 | GBDATA *gb_data; |
|---|
| 131 | |
|---|
| 132 | for (gb_data = GB_child(gb_ali); gb_data; gb_data = GB_nextChild(gb_data)) { |
|---|
| 133 | if (GB_read_key_pntr(gb_data)[0] != '_') { |
|---|
| 134 | long type = GB_read_type(gb_data); |
|---|
| 135 | |
|---|
| 136 | if (type == GB_BITS || type == GB_STRING) { |
|---|
| 137 | char *str; |
|---|
| 138 | |
|---|
| 139 | if (count) str = GBS_global_string_copy("%s%-20s SEQ_%i %s", pre, name, count + 1, TYPE); |
|---|
| 140 | else str = GBS_global_string_copy("%s%-20s %s", pre, name, TYPE); |
|---|
| 141 | |
|---|
| 142 | const char *target = GBS_global_string("%c%s%c%s", tpre, GB_read_key_pntr(gb_data), 1, name); |
|---|
| 143 | |
|---|
| 144 | cbs->aw_filt->insert_selection(cbs->id, str, target); |
|---|
| 145 | free(str); |
|---|
| 146 | count++; |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | void awt_create_select_filter_window_gb_cb(void *, struct adfiltercbstruct *cbs) { |
|---|
| 154 | // update list widget and variables |
|---|
| 155 | GB_push_transaction(cbs->gb_main); |
|---|
| 156 | GBDATA *gb_extended; |
|---|
| 157 | |
|---|
| 158 | if (cbs->id) { |
|---|
| 159 | char *use = cbs->awr->awar(cbs->def_alignment)->read_string(); |
|---|
| 160 | |
|---|
| 161 | cbs->aw_filt->clear_selection_list(cbs->id); |
|---|
| 162 | cbs->aw_filt->insert_default_selection( cbs->id, "none", "" ); |
|---|
| 163 | |
|---|
| 164 | const char *name = GBT_readOrCreate_char_pntr(cbs->gb_main, AWAR_SPECIES_NAME, ""); |
|---|
| 165 | if (name[0]){ |
|---|
| 166 | GBDATA *gb_species = GBT_find_species(cbs->gb_main,name); |
|---|
| 167 | if (gb_species){ |
|---|
| 168 | awt_add_sequences_to_list(cbs,use,gb_species,"SEL. SPECIES:",'@'); |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | for (gb_extended = GBT_first_SAI(cbs->gb_main); |
|---|
| 173 | gb_extended; |
|---|
| 174 | gb_extended = GBT_next_SAI(gb_extended)) |
|---|
| 175 | { |
|---|
| 176 | awt_add_sequences_to_list(cbs,use,gb_extended,"",' '); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | cbs->aw_filt->update_selection_list( cbs->id ); |
|---|
| 180 | free(use); |
|---|
| 181 | } |
|---|
| 182 | awt_create_select_filter_window_aw_cb(0,cbs); |
|---|
| 183 | GB_pop_transaction(cbs->gb_main); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | adfiltercbstruct *awt_create_select_filter(AW_root *aw_root, GBDATA *gb_main, const char *def_name) { |
|---|
| 188 | // def_name = filter name awar (has to exist, name has to be "SOMETHING/name") |
|---|
| 189 | // awars "SOMETHING/filter" (STRING) and "SOMETHING/alignment" (STRING) have to exist as well! |
|---|
| 190 | struct adfiltercbstruct *acbs = new adfiltercbstruct ; |
|---|
| 191 | acbs->gb_main = gb_main; |
|---|
| 192 | GB_push_transaction(acbs->gb_main); |
|---|
| 193 | AW_default aw_def = aw_root->get_default(def_name); |
|---|
| 194 | |
|---|
| 195 | #if defined(DEBUG) |
|---|
| 196 | { |
|---|
| 197 | int len = strlen(def_name); |
|---|
| 198 | |
|---|
| 199 | awt_assert(len >= 5); |
|---|
| 200 | awt_assert(strcmp(def_name+len-5, "/name") == 0); // filter awar has to be "SOMETHING/name" |
|---|
| 201 | } |
|---|
| 202 | #endif // DEBUG |
|---|
| 203 | |
|---|
| 204 | acbs->def_name = GBS_string_eval(def_name,"/name=/name",0); |
|---|
| 205 | acbs->def_filter = GBS_string_eval(def_name,"/name=/filter",0); |
|---|
| 206 | acbs->def_alignment = GBS_string_eval(def_name,"/name=/alignment",0); |
|---|
| 207 | |
|---|
| 208 | acbs->def_min = GBS_string_eval(def_name,"*/name=tmp/*1/min:tmp/tmp=tmp",0); |
|---|
| 209 | acbs->def_max = GBS_string_eval(def_name,"*/name=tmp/*1/max:tmp/tmp=tmp",0); |
|---|
| 210 | aw_root->awar_int(acbs->def_min)->add_callback((AW_RCB1)awt_create_select_filter_window_aw_cb,(AW_CL)acbs); |
|---|
| 211 | aw_root->awar_int(acbs->def_max)->add_callback((AW_RCB1)awt_create_select_filter_window_aw_cb,(AW_CL)acbs); |
|---|
| 212 | |
|---|
| 213 | acbs->def_len = GBS_string_eval(def_name,"*/name=tmp/*1/len:tmp/tmp=tmp",0); |
|---|
| 214 | aw_root->awar_int(acbs->def_len); |
|---|
| 215 | |
|---|
| 216 | acbs->def_dest = GBS_string_eval(def_name,"*/name=tmp/*1/dest:tmp/tmp=tmp",0); |
|---|
| 217 | aw_root->awar_string(acbs->def_dest,"",aw_def); |
|---|
| 218 | |
|---|
| 219 | acbs->def_cancel = GBS_string_eval(def_name,"*/name=*1/cancel",0); |
|---|
| 220 | aw_root->awar_string(acbs->def_cancel,".0-=",aw_def); |
|---|
| 221 | |
|---|
| 222 | acbs->def_simplify = GBS_string_eval(def_name,"*/name=*1/simplify",0); |
|---|
| 223 | aw_root->awar_int(acbs->def_simplify,0,aw_def); |
|---|
| 224 | |
|---|
| 225 | acbs->def_subname = GBS_string_eval(def_name,"*/name=tmp/*1/subname:tmp/tmp=tmp",0); |
|---|
| 226 | aw_root->awar_string(acbs->def_subname); |
|---|
| 227 | |
|---|
| 228 | acbs->def_source = GBS_string_eval(def_name,"*/name=tmp/*/source:tmp/tmp=tmp",0); |
|---|
| 229 | aw_root->awar_string(acbs->def_source); |
|---|
| 230 | |
|---|
| 231 | acbs->def_2name = GBS_string_eval(def_name,"*/name=tmp/*/2filter/name:tmp/tmp=tmp",0); |
|---|
| 232 | acbs->def_2filter = GBS_string_eval(def_name,"*/name=tmp/*/2filter/filter:tmp/tmp=tmp",0); |
|---|
| 233 | acbs->def_2alignment = GBS_string_eval(def_name,"*/name=tmp/*/2filter/alignment:tmp/tmp=tmp",0); |
|---|
| 234 | |
|---|
| 235 | aw_root->awar_string(acbs->def_2name)->write_string( "- none -" ); |
|---|
| 236 | aw_root->awar_string(acbs->def_2filter); |
|---|
| 237 | aw_root->awar_string(acbs->def_2alignment); |
|---|
| 238 | |
|---|
| 239 | acbs->id = 0; |
|---|
| 240 | acbs->aw_filt = 0; |
|---|
| 241 | acbs->awr = aw_root; |
|---|
| 242 | { |
|---|
| 243 | char *fname = aw_root->awar(acbs->def_name)->read_string(); |
|---|
| 244 | const char *fsname = GBS_global_string(" data%c%s",1,fname); |
|---|
| 245 | free(fname); |
|---|
| 246 | aw_root->awar(acbs->def_subname)->write_string(fsname); // cause an callback |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | aw_root->awar(acbs->def_subname)->touch(); // cause an callback |
|---|
| 250 | |
|---|
| 251 | GBDATA *gb_sai_data = GBT_get_SAI_data(acbs->gb_main); |
|---|
| 252 | GBDATA *gb_sel = GB_search(acbs->gb_main, AWAR_SPECIES_NAME, GB_STRING); |
|---|
| 253 | |
|---|
| 254 | GB_add_callback(gb_sai_data, GB_CB_CHANGED, (GB_CB)awt_create_select_filter_window_gb_cb, (int *)acbs); |
|---|
| 255 | GB_add_callback(gb_sel, GB_CB_CHANGED, (GB_CB)awt_create_select_filter_window_gb_cb, (int *)acbs); |
|---|
| 256 | |
|---|
| 257 | aw_root->awar(acbs->def_alignment)->add_callback((AW_RCB1)awt_create_select_filter_window_gb_cb, (AW_CL)acbs); |
|---|
| 258 | aw_root->awar(acbs->def_2filter) ->add_callback((AW_RCB1)awt_create_select_filter_window_aw_cb, (AW_CL)acbs); |
|---|
| 259 | aw_root->awar(acbs->def_subname) ->add_callback((AW_RCB1)awt_create_select_filter_window_aw_cb, (AW_CL)acbs); |
|---|
| 260 | |
|---|
| 261 | awt_create_select_filter_window_gb_cb(0,acbs); |
|---|
| 262 | |
|---|
| 263 | GB_pop_transaction(acbs->gb_main); |
|---|
| 264 | return acbs; |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | void awt_set_awar_to_valid_filter_good_for_tree_methods(GBDATA *gb_main, AW_root *awr, const char *awar_name){ |
|---|
| 269 | GB_transaction transaction_var(gb_main); |
|---|
| 270 | if (GBT_find_SAI(gb_main,"POS_VAR_BY_PARSIMONY")){ |
|---|
| 271 | awr->awar(awar_name)->write_string("POS_VAR_BY_PARSIMONY"); |
|---|
| 272 | return; |
|---|
| 273 | } |
|---|
| 274 | if (GBT_find_SAI(gb_main,"ECOLI")){ |
|---|
| 275 | awr->awar(awar_name)->write_string("ECOLI"); |
|---|
| 276 | return; |
|---|
| 277 | } |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | static AW_window *awt_create_2_filter_window(AW_root *aw_root, adfiltercbstruct *acbs) { |
|---|
| 281 | GB_push_transaction(acbs->gb_main); |
|---|
| 282 | aw_root->awar(acbs->def_2alignment)->map( acbs->def_alignment); |
|---|
| 283 | adfiltercbstruct *s2filter = awt_create_select_filter(aw_root, acbs->gb_main, acbs->def_2name); |
|---|
| 284 | GB_pop_transaction(acbs->gb_main); |
|---|
| 285 | return awt_create_select_filter_win(aw_root, (AW_CL)s2filter); |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | char *AWT_get_combined_filter_name(AW_root *aw_root, GB_CSTR prefix) { |
|---|
| 289 | char *combined_name = aw_root->awar(GBS_global_string("%s/filter/name", prefix))->read_string(); // "gde/filter/name" |
|---|
| 290 | const char *awar_prefix = AWAR_GDE_FILTER; |
|---|
| 291 | const char *awar_repeated = "/2filter"; |
|---|
| 292 | const char *awar_postfix = "/name"; |
|---|
| 293 | int prefix_len = strlen(awar_prefix); |
|---|
| 294 | int repeated_len = strlen(awar_repeated); |
|---|
| 295 | int postfix_len = strlen(awar_postfix); |
|---|
| 296 | int count; |
|---|
| 297 | |
|---|
| 298 | for (count = 1; ; ++count) { |
|---|
| 299 | char *awar_name = new char[prefix_len + count*repeated_len + postfix_len + 1]; |
|---|
| 300 | strcpy(awar_name, awar_prefix); |
|---|
| 301 | int c; |
|---|
| 302 | for (c=0; c<count; ++c) strcat(awar_name, awar_repeated); |
|---|
| 303 | strcat(awar_name, awar_postfix); |
|---|
| 304 | |
|---|
| 305 | AW_awar *awar_found = aw_root->awar_no_error(awar_name); |
|---|
| 306 | delete [] awar_name; |
|---|
| 307 | |
|---|
| 308 | if (!awar_found) break; // no more filters defined |
|---|
| 309 | char *content = awar_found->read_string(); |
|---|
| 310 | |
|---|
| 311 | if (strstr(content, "none")==0) { // don't add filters named 'none' |
|---|
| 312 | freeset(combined_name, GBS_global_string_copy("%s/%s", combined_name, content)); |
|---|
| 313 | } |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | return combined_name; |
|---|
| 317 | } |
|---|
| 318 | |
|---|
| 319 | AW_window *awt_create_select_filter_win(AW_root *aw_root, AW_CL res_of_create_select_filter) { |
|---|
| 320 | struct adfiltercbstruct *acbs = (struct adfiltercbstruct *)res_of_create_select_filter; |
|---|
| 321 | |
|---|
| 322 | if (!acbs->aw_filt) { |
|---|
| 323 | GB_push_transaction(acbs->gb_main); |
|---|
| 324 | |
|---|
| 325 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 326 | { |
|---|
| 327 | int checksum = GBS_checksum(acbs->def_name, true, NULL); |
|---|
| 328 | char *window_id = GBS_global_string_copy("FILTER_SELECT_%i", checksum); // make window id awar specific |
|---|
| 329 | |
|---|
| 330 | aws->init( aw_root, window_id, "Select Filter"); |
|---|
| 331 | free(window_id); |
|---|
| 332 | } |
|---|
| 333 | aws->load_xfig("awt/filter.fig"); |
|---|
| 334 | aws->button_length( 10 ); |
|---|
| 335 | |
|---|
| 336 | aws->at("close");aws->callback((AW_CB0)AW_POPDOWN); |
|---|
| 337 | aws->create_button("CLOSE", "CLOSE","C"); |
|---|
| 338 | |
|---|
| 339 | aws->at("help");aws->callback(AW_POPUP_HELP,(AW_CL)"sel_fil.hlp"); |
|---|
| 340 | aws->create_button("HELP", "HELP","H"); |
|---|
| 341 | |
|---|
| 342 | acbs->aw_filt = aws; // store the filter selection window in 'acbs' |
|---|
| 343 | |
|---|
| 344 | aws->at("filter"); |
|---|
| 345 | acbs->id = aws->create_selection_list(acbs->def_subname,0,"",20,3); |
|---|
| 346 | |
|---|
| 347 | aws->at("2filter"); |
|---|
| 348 | aws->callback(AW_POPUP,(AW_CL)awt_create_2_filter_window,(AW_CL)acbs); |
|---|
| 349 | aws->create_button(acbs->def_2name,acbs->def_2name); |
|---|
| 350 | |
|---|
| 351 | aws->at("zero"); |
|---|
| 352 | aws->callback((AW_CB1)awt_create_select_filter_window_aw_cb,(AW_CL)acbs); |
|---|
| 353 | aws->create_input_field(acbs->def_cancel,10); |
|---|
| 354 | |
|---|
| 355 | aws->at("sequence"); |
|---|
| 356 | aws->create_text_field(acbs->def_source,1,1); |
|---|
| 357 | |
|---|
| 358 | aws->at("min"); |
|---|
| 359 | aws->create_input_field(acbs->def_min,4); |
|---|
| 360 | |
|---|
| 361 | aws->at("max"); |
|---|
| 362 | aws->create_input_field(acbs->def_max,4); |
|---|
| 363 | |
|---|
| 364 | aws->at("simplify"); |
|---|
| 365 | aws->create_option_menu(acbs->def_simplify); |
|---|
| 366 | aws->insert_option("ORIGINAL DATA","O",0); |
|---|
| 367 | aws->sens_mask(AWM_EXP); |
|---|
| 368 | aws->insert_option("TRANSVERSIONS ONLY","T",1); |
|---|
| 369 | aws->insert_option("SIMPLIFIED AA","A",2); |
|---|
| 370 | aws->sens_mask(AWM_ALL); |
|---|
| 371 | aws->update_option_menu(); |
|---|
| 372 | |
|---|
| 373 | awt_create_select_filter_window_gb_cb(0,acbs); |
|---|
| 374 | |
|---|
| 375 | aws->button_length( 7 ); |
|---|
| 376 | aws->at("len"); aws->create_button(0,acbs->def_len); |
|---|
| 377 | |
|---|
| 378 | GB_pop_transaction(acbs->gb_main); |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | return acbs->aw_filt; |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | AP_filter *awt_get_filter(AW_root *aw_root, adfiltercbstruct *acbs) { |
|---|
| 385 | AP_filter *filter = new AP_filter; |
|---|
| 386 | bool initialized = false; |
|---|
| 387 | |
|---|
| 388 | if (acbs) { |
|---|
| 389 | GB_push_transaction(acbs->gb_main); |
|---|
| 390 | |
|---|
| 391 | char *filter_string = aw_root->awar(acbs->def_filter)->read_string(); |
|---|
| 392 | long len = 0; |
|---|
| 393 | |
|---|
| 394 | { |
|---|
| 395 | char *use = aw_root->awar(acbs->def_alignment)->read_string(); |
|---|
| 396 | |
|---|
| 397 | len = GBT_get_alignment_len(acbs->gb_main,use); |
|---|
| 398 | free(use); |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | if (len != -1) { // have alignment |
|---|
| 402 | filter->init(filter_string,"0",len); |
|---|
| 403 | initialized = true; |
|---|
| 404 | |
|---|
| 405 | int sim = aw_root->awar(acbs->def_simplify)->read_int(); |
|---|
| 406 | filter->enable_simplify((AWT_FILTER_SIMPLIFY)sim); |
|---|
| 407 | free(filter_string); |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | GB_pop_transaction(acbs->gb_main); |
|---|
| 411 | } |
|---|
| 412 | |
|---|
| 413 | if (!initialized) { |
|---|
| 414 | filter->init("","0",10); |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | return filter; |
|---|
| 418 | } |
|---|