ARB
GEN_nds.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : GEN_nds.cxx //
4 // Purpose : //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in 2001 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // =============================================================== //
11 
12 #include "GEN.hxx"
13 
14 #include <nds.h>
15 #include <item_sel_list.h>
16 #include <awt_sel_boxes.hxx>
17 
18 #include <aw_msg.hxx>
19 #include <aw_root.hxx>
20 #include <aw_awar.hxx>
21 
22 #include <ad_cb.h>
23 #include <gb_aci.h>
24 
25 #define gen_assert(bed) arb_assert(bed)
26 
27 using namespace std;
28 
29 // Note: this file is based on ../AWT/AWT_nds.cxx
30 
31 #define GEN_NDS_COUNT 10
32 #define GEN_NDS_STRING_SIZE 4000
33 
36  char zbuf[GEN_NDS_COUNT];
37  long lengths[GEN_NDS_COUNT];
38  long rek[GEN_NDS_COUNT];
39  char *dkeys[GEN_NDS_COUNT];
40  char *parsing[GEN_NDS_COUNT];
41  long count;
42  int errorclip;
43 };
44 
46 
48  const char *sf = "flag1";
49  const char *sl = "len1";
50 
51  if (!gen_nds_ms) ARB_calloc(gen_nds_ms, 1);
52 
53  GBDATA *gb_arb_presets = GB_search(gb_main, "arb_presets", GB_CREATE_CONTAINER);
54  int count = 0;
55 
56  for (GBDATA *gbz = GB_entry(gb_arb_presets, "gene_viewkey"); gbz; gbz = GB_nextEntry(gbz)) {
57  // toggle set ?
58  if (GB_read_int(GB_entry(gbz, sf))) {
59  freeset(gen_nds_ms->dkeys[count], GB_read_string(GB_entry(gbz, "key_text")));
60  if (GB_first_non_key_char(gen_nds_ms->dkeys[count])) {
61  gen_nds_ms->rek[count] = 1;
62  }
63  else {
64  gen_nds_ms->rek[count] = 0;
65  }
66  gen_nds_ms->lengths[count] = GB_read_int(GB_entry(gbz, sl));
67  GBDATA *gbe = GB_entry(gbz, "pars");
68  freenull(gen_nds_ms->parsing[count]);
69  if (gbe && GB_read_string_count(gbe)>1) gen_nds_ms->parsing[count] = GB_read_string(gbe);
70  count++;
71  }
72  }
73 
74  gen_nds_ms->errorclip = 0;
75  gen_nds_ms->count = count;
76 }
77 
78 char *GEN_make_node_text_nds(GBDATA *gbd, int mode) {
79  // if mode == 0 compress info else format info
80 
81  char *bp = gen_nds_ms->buf;
82  gen_assert(gbd);
83 
84  long first = 0;
85  for (long i = 0; i < gen_nds_ms->count; i++) {
86  GBDATA *gbe;
87  if (gen_nds_ms->rek[i]) { // hierarchical key
88  gbe = GB_search(gbd, gen_nds_ms->dkeys[i], GB_FIND);
89  }
90  else { // flat entry
91  gbe = GB_entry(gbd, gen_nds_ms->dkeys[i]);
92  }
93 
94  if (!mode && !gbe) continue;
95  if (!mode && first) {
96  (*bp++) = ',';
97  }
98  (*bp++) = ' ';
99  first++;
100  if (gbe) {
101  switch (GB_read_type(gbe)) {
102  case GB_INT:
103  if (mode) {
104  char buf[20];
105  sprintf(buf, "%%%lii", gen_nds_ms->lengths[i]);
106  sprintf(bp, buf, GB_read_int(gbe));
107  }
108  else {
109  sprintf(bp, "%li", GB_read_int(gbe));
110  }
111  bp += strlen(bp);
112  break;
113  case GB_BYTE:
114  if (mode) {
115  char buf[20];
116  sprintf(buf, "%%%lii", gen_nds_ms->lengths[i]);
117  sprintf(bp, buf, GB_read_byte(gbe));
118  }
119  else {
120  sprintf(bp, "%i", GB_read_byte(gbe));
121  }
122  bp += strlen(bp);
123  break;
124  case GB_STRING: {
125  char *pars = NULp;
126  const char *p = NULp;
127 
128  if (gen_nds_ms->parsing[i]) {
129  char *p2 = GB_read_string(gbe);
130  pars = GB_command_interpreter_in_env(p2, gen_nds_ms->parsing[i], GBL_simple_call_env(gbd));
131  free(p2);
132 
133  if (!pars) {
134  pars = ARB_strdup("<error>");
135  if (!gen_nds_ms->errorclip++) {
137  }
138  }
139  p = pars;
140  }
141  else {
142  p = GB_read_char_pntr(gbe);
143  }
144 
145  long dlen = gen_nds_ms->lengths[i];
146  if (dlen + (bp - gen_nds_ms->buf) + 256 > GEN_NDS_STRING_SIZE) {
147  dlen = GEN_NDS_STRING_SIZE - 256 - (bp - gen_nds_ms->buf);
148  }
149 
150  if (dlen> 0) {
151  int len = strlen(p);
152  long j = len;
153  if (j > dlen) j = dlen;
154  for (; j; j--) *bp++ = *p++; // LOOP_VECTORIZED // tested down to gcc 5.5.0 (may fail on older gcc versions)
155  if (mode) {
156  long post = dlen - len;
157  while (post-- > 0) *(bp++) = ' ';
158  }
159  }
160  free(pars);
161  break;
162  }
163  case GB_FLOAT:
164  sprintf(bp, "%4.4f", GB_read_float(gbe));
165  bp += strlen(bp);
166  break;
167  default:
168  break;
169  }
170  }
171  else if (mode) {
172  long j = gen_nds_ms->lengths[i];
173  if (j + (bp - gen_nds_ms->buf) + 256 > GEN_NDS_STRING_SIZE) {
174  j = GEN_NDS_STRING_SIZE - 256 - (bp - gen_nds_ms->buf);
175  }
176  for (; j > 0; j--) *(bp++) = ' ';
177  }
178  }
179  *bp = 0;
180 
181  return NDS_mask_nonprintable_chars(gen_nds_ms->buf);
182 }
183 
184 void GEN_create_nds_vars(AW_root *aw_root, AW_default awdef, GBDATA *gb_main, const DatabaseCallback& NDS_changed_callback) {
186  GBDATA *gb_arb_presets = GB_search(gb_main, "arb_presets", GB_CREATE_CONTAINER);
187  GBDATA *gb_viewkey = NULp;
188 
189  for (int i=0; i<GEN_NDS_COUNT && !error; i++) {
190  char buf[256];
191  char *keystart = buf+sprintf(buf, "tmp/gene_viewkey_%i/", i);
192 
193  if (gb_viewkey) {
194  gen_assert(GB_has_key(gb_viewkey, "gene_viewkey"));
195  gb_viewkey = GB_nextEntry(gb_viewkey);
196  }
197  else {
198  gb_viewkey = GB_entry(gb_arb_presets, "gene_viewkey");
199  }
200  if (!gb_viewkey) {
201  gb_viewkey = GB_create_container(gb_arb_presets, "gene_viewkey");
202  }
203 
204  if (!gb_viewkey) {
205  error = GB_await_error();
206  }
207  else {
208  GB_add_callback(gb_viewkey, GB_CB_CHANGED, NDS_changed_callback);
209 
210  const char *default_key = NULp;
211  switch (i) {
212  case 1: default_key = "pos_start"; break;
213  case 2: default_key = "pos_stop"; break;
214  case 3: default_key = "product"; break;
215  default: default_key = "name"; break;
216  }
217  GBDATA *gb_key_text = GB_searchOrCreate_string(gb_viewkey, "key_text", default_key);
218  if (!gb_key_text) error = GB_await_error();
219  else {
220  strcpy(keystart, "key_text");
221  aw_root->awar_string(buf, "", awdef);
222  aw_root->awar(buf)->map(gb_key_text);
223  }
224  }
225 
226  if (!error) {
227  GBDATA *gb_pars = GB_searchOrCreate_string(gb_viewkey, "pars", "");
228  if (!gb_pars) error = GB_await_error();
229  else {
230  strcpy(keystart, "pars");
231  aw_root->awar_string(buf, "", awdef);
232  aw_root->awar(buf)->map(gb_pars);
233  }
234  }
235 
236  if (!error) {
237  GBDATA *gb_flag1 = GB_searchOrCreate_int(gb_viewkey, "flag1", i <= 2 ? 1 : 0);
238  if (!gb_flag1) error = GB_await_error();
239  else {
240  strcpy(keystart, "flag1");
241  aw_root->awar_int(buf, 0, awdef);
242  aw_root->awar(buf)->map(gb_flag1);
243  }
244  }
245 
246  if (!error) {
247  GBDATA *gb_len1 = GB_searchOrCreate_int(gb_viewkey, "len1", 30);
248  if (!gb_len1) error = GB_await_error();
249  else {
250  strcpy(keystart, "len1");
251  aw_root->awar_int(buf, 0, awdef);
252  aw_root->awar(buf)->set_minmax(0, GEN_NDS_STRING_SIZE);
253  aw_root->awar(buf)->map(gb_len1);
254  }
255  }
256  }
257 
258  if (!error) {
259  GBDATA *gb_next;
260  gen_assert(GB_has_key(gb_viewkey, "gene_viewkey"));
261  while (!error && (gb_next = GB_nextEntry(gb_viewkey))) {
262  error = GB_delete(gb_next);
263  }
264  }
265 
266  aw_root->awar_string("tmp/gene_viewkey/key_text", "", awdef);
267 
268  error = GB_end_transaction(gb_main, error);
269  if (error) aw_message(error);
270 }
271 
273  static AW_window_simple *aws = NULp;
274  if (!aws) {
275  aws = new AW_window_simple;
276 
277  aws->init(aw_root, "GENE_NDS_PROPS", "Gene NDS");
278  aws->load_xfig("awt/nds.fig");
279  aws->auto_space(10, 5);
280 
281  aws->callback(AW_POPDOWN);
282  aws->at("close");
283  aws->create_button("CLOSE", "CLOSE", "C");
284 
285  aws->at("help");
286  aws->callback(makeHelpCallback("props_nds.hlp"));
287  aws->create_button("HELP", "HELP", "H");
288 
289  aws->button_length(13);
290  int dummy, closey;
291  aws->at_newline();
292  aws->get_at_position(&dummy, &closey);
293 
294  aws->create_button(NULp, "K");
295 
296  aws->at_newline();
297 
298  int showx, fieldx, columnx, srtx, srtux;
299 
300  aws->auto_space(10, 0);
301 
302  for (int i=0; i<GEN_NDS_COUNT; i++) {
303  char buf[256];
304 
305  sprintf(buf, "tmp/gene_viewkey_%i/flag1", i);
306  aws->get_at_position(&showx, &dummy);
307  aws->create_toggle(buf);
308 
309  sprintf(buf, "tmp/gene_viewkey_%i/key_text", i);
310  aws->get_at_position(&fieldx, &dummy);
311  create_itemfield_selection_button(aws, FieldSelDef(buf, gb_main, GEN_get_selector(), FIELD_FILTER_NDS, "display-field"), NULp);
312 
313  sprintf(buf, "tmp/gene_viewkey_%i/len1", i);
314  aws->get_at_position(&columnx, &dummy);
315  aws->create_input_field(buf, 4);
316 
317  sprintf(buf, "tmp/gene_viewkey_%i/pars", i);
318  const char *inputFieldAwarName = ARB_strdup(buf);
319 
320  aws->get_at_position(&srtx, &dummy);
321 
322  aws->button_length(0);
323 
324  aws->callback(makeWindowCallback(NDS_popup_select_srtaci_window, inputFieldAwarName));
325  sprintf(buf, "SELECT_SRTACI_%i", i);
326  aws->create_button(buf, "S", "S");
327 
328  aws->get_at_position(&srtux, &dummy);
329  aws->create_input_field(inputFieldAwarName, 50);
330  aws->at_newline();
331  }
332  aws->at(showx, closey);
333 
334  aws->at_x(showx);
335  aws->create_button(NULp, "SHOW");
336 
337  aws->at_x(fieldx);
338  aws->create_button(NULp, "FIELD");
339 
340  aws->at_x(columnx);
341  aws->create_button(NULp, "WIDTH");
342 
343  aws->at_x(srtx);
344  aws->create_button(NULp, "SRT");
345 
346  aws->at_x(srtux);
347  aws->create_button(NULp, "ACI/SRT PROGRAM");
348  }
349  return aws;
350 }
351 
char * GEN_make_node_text_nds(GBDATA *gbd, int mode)
Definition: GEN_nds.cxx:78
ItemSelector & GEN_get_selector()
void GEN_create_nds_vars(AW_root *aw_root, AW_default awdef, GBDATA *gb_main, const DatabaseCallback &NDS_changed_callback)
Definition: GEN_nds.cxx:184
static GEN_NodeTextBuilder * gen_nds_ms
Definition: GEN_nds.cxx:45
#define GEN_NDS_STRING_SIZE
Definition: GEN_nds.cxx:32
Definition: arbdb.h:65
long GB_read_int(GBDATA *gbd)
Definition: arbdb.cxx:729
GBDATA * GB_searchOrCreate_string(GBDATA *gb_container, const char *fieldpath, const char *default_value)
Definition: adquery.cxx:546
GB_ERROR GB_add_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
Definition: ad_cb.cxx:356
GBDATA * GB_nextEntry(GBDATA *entry)
Definition: adquery.cxx:339
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2561
char buf[GEN_NDS_STRING_SIZE]
Definition: GEN_nds.cxx:35
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
AW_awar * set_minmax(float min, float max)
Definition: AW_awar.cxx:530
long rek[GEN_NDS_COUNT]
Definition: GEN_nds.cxx:38
STL namespace.
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2494
CONSTEXPR long FIELD_FILTER_NDS
Definition: item_sel_list.h:52
GB_ERROR GB_delete(GBDATA *&source)
Definition: arbdb.cxx:1916
char * dkeys[GEN_NDS_COUNT]
Definition: GEN_nds.cxx:39
void create_itemfield_selection_button(AW_window *aws, const FieldSelDef &selDef, const char *at)
size_t GB_read_string_count(GBDATA *gbd)
Definition: arbdb.cxx:916
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:342
GBDATA * GB_create_container(GBDATA *father, const char *key)
Definition: arbdb.cxx:1829
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
Definition: arbdb.h:67
GB_TYPES GB_read_type(GBDATA *gbd)
Definition: arbdb.cxx:1643
void NDS_popup_select_srtaci_window(AW_window *aww, const char *acisrt_awarname)
Definition: nds.cxx:406
const char * GB_first_non_key_char(const char *str)
Definition: adquery.cxx:416
static void error(const char *msg)
Definition: mkptypes.cxx:96
GBDATA * GB_searchOrCreate_int(GBDATA *gb_container, const char *fieldpath, long default_value)
Definition: adquery.cxx:569
float GB_read_float(GBDATA *gbd)
Definition: arbdb.cxx:744
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
bool GB_has_key(GBDATA *gbd, const char *key)
Definition: arbdb.cxx:1707
Definition: arbdb.h:86
#define GEN_NDS_COUNT
Definition: GEN_nds.cxx:31
char * NDS_mask_nonprintable_chars(char *const str)
Definition: nds.cxx:974
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
TYPE * ARB_calloc(size_t nelem)
Definition: arb_mem.h:81
AW_window * GEN_open_nds_window(AW_root *aw_root, GBDATA *gb_main)
Definition: GEN_nds.cxx:272
int GB_read_byte(GBDATA *gbd)
Definition: arbdb.cxx:734
AW_awar * map(const char *awarn)
Definition: AW_awar.cxx:521
char * GB_read_string(GBDATA *gbd)
Definition: arbdb.cxx:909
#define gen_assert(bed)
Definition: GEN_nds.cxx:25
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
void GEN_make_node_text_init(GBDATA *gb_main)
Definition: GEN_nds.cxx:47
#define NULp
Definition: cxxforward.h:116
char * parsing[GEN_NDS_COUNT]
Definition: GEN_nds.cxx:40
NOT4PERL char * GB_command_interpreter_in_env(const char *str, const char *commands, const GBL_call_env &callEnv)
Definition: gb_aci.cxx:361
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
Definition: arbdb.cxx:904
GBDATA * gb_main
Definition: adname.cxx:32
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
long lengths[GEN_NDS_COUNT]
Definition: GEN_nds.cxx:37
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334
Definition: arbdb.h:66