ARB
ED4_nds.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : ED4_nds.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #include "ed4_class.hxx"
12 #include "ed4_awars.hxx"
13 
14 #include <nds.h>
15 #include <aw_awar.hxx>
16 #include <aw_msg.hxx>
17 #include <aw_root.hxx>
18 #include <arbdbt.h>
19 #include <gb_aci.h>
20 
21 #define NDS_COUNT 10
22 
23 static char *NDS_command = NULp;
24 static int NDS_width = 1;
25 
26 char *ED4_get_NDS_text(ED4_species_manager *species_man) {
27  GBDATA *gbd = species_man->get_species_pointer();
28 
29  e4_assert(gbd);
30  e4_assert(NDS_command);
31 
32  char *result = GB_command_interpreter_in_env("", NDS_command, GBL_simple_call_env(gbd));
33  if (!result) result = GBS_global_string_copy("<error: %s>", GB_await_error());
34 
35  return NDS_mask_nonprintable_chars(result);
36 }
37 
39  return NDS_width;
40 }
41 
42 static void NDS_changed(AW_root *root, bool doRefresh) {
43  int toggle = root->awar(ED4_AWAR_NDS_SELECT)->read_int();
44 
45  char buf[256];
46  sprintf(buf, ED4_AWAR_NDS_ACI_TEMPLATE, toggle);
47  freeset(NDS_command, root->awar(buf)->read_string());
48 
49  sprintf(buf, ED4_AWAR_NDS_WIDTH_TEMPLATE, toggle);
50  NDS_width = root->awar(buf)->read_int();
51 
52  if (doRefresh) ED4_request_relayout();
53 }
54 
56  int i;
58 
59  RootCallback ndsRefreshCb = makeRootCallback(NDS_changed, true);
60  root->awar_int(ED4_AWAR_NDS_SELECT, 0)->add_callback(ndsRefreshCb);
61  root->awar_int(ED4_AWAR_NDS_INFO_WIDTH, 5)->set_minmax(0, 99)->add_callback(ndsRefreshCb);
62  root->awar_string(ED4_AWAR_NDS_ECOLI_NAME, "Ecoli")->add_callback(ndsRefreshCb);
63 
64  for (i=0; i<NDS_COUNT; i++) {
65  char buf[256];
66  const char *desc;
67 
68  sprintf(buf, ED4_AWAR_NDS_SELECT_TEMPLATE, i);
69  root->awar_int(buf, i==0);
70 
71  sprintf(buf, ED4_AWAR_NDS_DESCRIPTION_TEMPLATE, i);
72  switch (i) {
73  case 0: desc = "Short name"; break;
74  case 1: desc = "Full name"; break;
75  default: desc = ""; break;
76  }
77  root->awar_string(buf, desc);
78 
79  const char *aci;
80  sprintf(buf, ED4_AWAR_NDS_ACI_TEMPLATE, i);
81  switch (i) {
82  case 0: aci = "readdb(name)"; break;
83  case 1: aci = "readdb(full_name)"; break;
84  default: aci = "\"<not defined>\""; break;
85  }
86  root->awar_string(buf, aci)->add_callback(ndsRefreshCb);
87 
88  int len;
89  sprintf(buf, ED4_AWAR_NDS_WIDTH_TEMPLATE, i);
90  switch (i) {
91  case 0: len = 8; break;
92  case 1: len = 26; break;
93  default: len = 20; break;
94  }
95  root->awar_int(buf, len)->add_callback(ndsRefreshCb);
96  }
97 
98  NDS_changed(root, false); // init globals (no refresh needed)
99 }
100 
101 // a crazy implementation of a toggle field
102 static void ed4_nds_select_change(AW_window *aww, int selected) {
103  AW_root *aw_root = aww->get_root();
104  for (int i=0; i<NDS_COUNT; i++) {
105  const char *awar_name = GBS_global_string(ED4_AWAR_NDS_SELECT_TEMPLATE, i);
106  aw_root->awar(awar_name)->write_int((i==selected) ? 1 : 0);
107  }
108  aw_root->awar(ED4_AWAR_NDS_SELECT)->write_int(selected);
109 }
110 
112  AW_window_simple *aws = new AW_window_simple;
113 
114  aws->init(root, "E4_NDS_PROPS", "NDS");
115  aws->load_xfig("edit4/nds.fig");
116 
117  aws->callback(AW_POPDOWN);
118  aws->at("close");
119  aws->create_button("CLOSE", "CLOSE", "C");
120 
121  aws->callback(makeHelpCallback("ed4_nds.hlp"));
122  aws->at("help");
123  aws->create_button("HELP", "HELP", "H");
124 
125  aws->at("infowidth");
126  aws->label("Display width used for info-field");
127  aws->create_input_field(ED4_AWAR_NDS_INFO_WIDTH, 3);
128 
129  aws->at("ecoli_name");
130  aws->label("Name displayed for SAI: ECOLI");
131  aws->create_input_field(ED4_AWAR_NDS_ECOLI_NAME, 20);
132 
133  aws->auto_space(10, 2);
134 
135  aws->at("toggle");
136  aws->at_newline();
137 
138  int dummy, fieldselectx, description_x, aci_x, length_x;
139  aws->get_at_position(&fieldselectx, &dummy);
140 
141  for (int i=0; i<NDS_COUNT; ++i) {
142  char buf[256];
143  sprintf(buf, ED4_AWAR_NDS_SELECT_TEMPLATE, i);
144  aws->callback(makeWindowCallback(ed4_nds_select_change, i)); // @@@ used as TOGGLE_CLICK_CB (see #559)
145  aws->create_toggle(buf);
146 
147  aws->get_at_position(&description_x, &dummy);
148  sprintf(buf, ED4_AWAR_NDS_DESCRIPTION_TEMPLATE, i);
149  aws->create_input_field(buf, 15);
150 
151  aws->get_at_position(&aci_x, &dummy);
152  sprintf(buf, ED4_AWAR_NDS_ACI_TEMPLATE, i);
153  aws->create_input_field(buf, 30);
154 
155  aws->get_at_position(&length_x, &dummy);
156  sprintf(buf, ED4_AWAR_NDS_WIDTH_TEMPLATE, i);
157  aws->create_input_field(buf, 3);
158 
159  aws->at_newline();
160  }
161 
162  aws->at("head");
163  aws->at_x(description_x);
164  aws->create_button(NULp, "DESCRIPTION");
165  aws->at_x(aci_x);
166  aws->create_button(NULp, "ACI PROGRAM");
167  aws->at_x(length_x);
168  aws->create_button(NULp, "WIDTH");
169 
170  return aws;
171 }
172 
string result
void ED4_create_NDS_awars(AW_root *root)
Definition: ED4_nds.cxx:55
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:720
void ED4_request_relayout()
#define ED4_AWAR_NDS_SELECT
Definition: ed4_awars.hxx:68
#define ED4_AWAR_NDS_DESCRIPTION_TEMPLATE
Definition: ed4_awars.hxx:70
long read_int() const
Definition: AW_awar.cxx:184
AW_awar * set_minmax(float min, float max)
Definition: AW_awar.cxx:530
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
ED4_root * ED4_ROOT
Definition: ED4_main.cxx:49
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
char * ED4_get_NDS_text(ED4_species_manager *species_man)
Definition: ED4_nds.cxx:26
#define e4_assert(bed)
Definition: ed4_class.hxx:14
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:231
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:342
#define ED4_AWAR_NDS_ECOLI_NAME
Definition: ed4_awars.hxx:74
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
static void ed4_nds_select_change(AW_window *aww, int selected)
Definition: ED4_nds.cxx:102
GBDATA * get_gb_main() const
Definition: ed4_class.hxx:1422
#define ED4_AWAR_NDS_INFO_WIDTH
Definition: ed4_awars.hxx:73
char * read_string() const
Definition: AW_awar.cxx:198
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
int ED4_get_NDS_width()
Definition: ED4_nds.cxx:38
char * NDS_mask_nonprintable_chars(char *const str)
Definition: nds.cxx:974
static char * NDS_command
Definition: ED4_nds.cxx:23
AW_window * ED4_create_nds_window(AW_root *root)
Definition: ED4_nds.cxx:111
static void NDS_changed(AW_root *root, bool doRefresh)
Definition: ED4_nds.cxx:42
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
#define ED4_AWAR_NDS_WIDTH_TEMPLATE
Definition: ed4_awars.hxx:72
#define ED4_AWAR_NDS_SELECT_TEMPLATE
Definition: ed4_awars.hxx:69
#define NDS_COUNT
Definition: ED4_nds.cxx:21
#define ED4_AWAR_NDS_ACI_TEMPLATE
Definition: ed4_awars.hxx:71
AW_root * get_root()
Definition: aw_window.hxx:359
#define NULp
Definition: cxxforward.h:116
NOT4PERL char * GB_command_interpreter_in_env(const char *str, const char *commands, const GBL_call_env &callEnv)
Definition: gb_aci.cxx:361
GB_transaction ta(gb_var)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
static int NDS_width
Definition: ED4_nds.cxx:24
GB_ERROR write_int(long aw_int)
char * GBS_global_string_copy(const char *templat,...)
Definition: arb_msg.cxx:194