[project @ 10]
[mussa.git] / mussa_gui_conn_window.cc
1 #include "mussa_gui_conn_window.hh"
2
3
4 void
5 load_ana_cb(Fl_Button* o, void* v)
6 {
7   ConnWindow* T=(ConnWindow*)v;
8   T->real_load_ana_cb();
9 }
10
11
12 void
13 ConnWindow::real_load_ana_cb()
14 {
15   char *picked_file;
16   string a_file_path;
17   string err_msg;
18
19   cout << "Load!  Load!  Load, ye yellow-bellied seadogs!\n";
20   picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
21   a_file_path = picked_file;
22   cout << picked_file << endl; 
23   cout << a_file_path << endl;
24   cout << a_file_path.substr(0,a_file_path.find(".mu")) << endl;
25
26   // load the analysis
27   an_analysis = new Mussa();
28   err_msg = an_analysis->load(a_file_path.substr(0,a_file_path.find(".mu")));
29
30   if (err_msg == "")
31   {
32     // relabel window with the analysis name
33     window_name = "Mussa: " + an_analysis->ana_name;
34     label((const char*)window_name.c_str());
35     // show the user the analysis
36     conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
37                     an_analysis->window, &(an_analysis->the_Seqs), 
38                     &(an_analysis->the_paths));
39     conn_box->scale_paths();
40   }
41   else
42   {
43     fl_alert(err_msg.c_str());
44     cout << err_msg << endl;
45   }
46 }
47
48
49 void
50 do_ana_cb(Fl_Button* o, void* v)
51 {
52   ConnWindow* T=(ConnWindow*)v;
53   T->real_do_ana_cb();
54 }
55
56
57 void
58 ConnWindow::real_do_ana_cb()
59 {
60   char *picked_file;
61   string a_file_path;
62   string err_msg;
63
64   picked_file = fl_file_chooser("Analysis Config File", "", "", 1);
65   a_file_path = picked_file;
66
67   an_analysis = new Mussa();
68   err_msg = an_analysis->load_mupa_file(a_file_path);
69
70   if (err_msg == "")
71   {
72     err_msg = an_analysis->analyze(0, 0);
73   }
74
75   if (err_msg == "")
76   {
77     // relabel window with the analysis name
78     window_name = "Mussa: " + an_analysis->ana_name;
79     label((const char*)window_name.c_str());
80     // show the user the analysis
81     conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
82                     an_analysis->window, &(an_analysis->the_Seqs), 
83                     &(an_analysis->the_paths));
84     conn_box->scale_paths();
85   }
86   else
87   {
88     fl_alert(err_msg.c_str());
89     cout << err_msg;
90   }
91 }
92
93 void
94 setup_ana_cb(Fl_Button* o, void* v)
95 {
96   ConnWindow* T=(ConnWindow*)v;
97   T->real_setup_ana_cb();
98 }
99
100 void
101 ConnWindow::real_setup_ana_cb()
102 {
103   an_analysis = new Mussa();
104   setup_win = new SetupWindow(650,700,"Analysis Setup", an_analysis);
105
106   while(setup_win->visible())
107     Fl::wait(.1);
108   cout << "Like a warm summer day\n";
109
110   // relabel window with the analysis name
111   window_name = "Mussa: " + an_analysis->ana_name;
112   label((const char*)window_name.c_str());
113   // is it this easy?  what if setup window encounters an error...??
114   conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
115                   an_analysis->window, &(an_analysis->the_Seqs), 
116                   &(an_analysis->the_paths));
117   cout << "Like a warm day in may\n";
118   conn_box->scale_paths();
119 }
120
121 // all the crap needed for dealing with the scale bars
122 void
123 toggle_scale_bars_cb(Fl_Button* o, void* v)
124 {
125   ConnWindow* T=(ConnWindow*)v;
126   T->real_toggle_bars_cb();
127 }
128
129 void
130 ConnWindow::real_toggle_bars_cb()
131 {
132   conn_box->toggle_bars();
133 }
134
135 void
136 set_bar_len_cb(Fl_Input* o, void* v)
137 {
138   ConnWindow* T=(ConnWindow*)v;
139   cout << "WAAAAAAAAA\n";
140   T->real_set_bar_len_cb(o);
141 }
142
143 void
144 ConnWindow::real_set_bar_len_cb(Fl_Input* o)
145 {
146   int new_bar_len;
147  
148   new_bar_len = atoi(o->value());
149   cout << "new bar len = " << new_bar_len << endl;
150   conn_box->set_bar_interval(new_bar_len);
151 }
152
153
154 // all the crap needed for dealing with the scale lines
155 void
156 toggle_scale_lines_cb(Fl_Button* o, void* v)
157 {
158   ConnWindow* T=(ConnWindow*)v;
159   T->real_toggle_lines_cb();
160 }
161
162 void
163 ConnWindow::real_toggle_lines_cb()
164 {
165   conn_box->toggle_lines();
166 }
167
168 void
169 set_line_len_cb(Fl_Input* o, void* v)
170 {
171   ConnWindow* T=(ConnWindow*)v;
172   cout << "WAAAAAAAAA\n";
173   T->real_set_line_len_cb(o);
174 }
175
176 void
177 ConnWindow::real_set_line_len_cb(Fl_Input* o)
178 {
179   int new_line_len;
180  
181   new_line_len = atoi(o->value());
182   cout << "new line len = " << new_line_len << endl;
183   conn_box->set_line_interval(new_line_len);
184 }
185
186
187
188 ConnWindow::ConnWindow(int w, int h, const char* title):
189   Fl_Double_Window(w,h,title)
190 {
191   int button_len = 120;
192   Fl_Color a_color = fl_rgb_color(150, 200, 255);;
193
194   padding = 5;
195
196   begin();
197   //fl_color(150,200,255);
198   color(FL_WHITE);
199   resizable(this);
200
201  
202   // create file menu button
203   file_menu = new Fl_Menu_Button(padding, 2, button_len, 30, "File");
204   file_menu->color(FL_WHITE,a_color);
205   file_menu->box(FL_BORDER_BOX);
206   file_menu->clear();
207
208   // add menu items
209   file_menu->add("Do Analysis", 0, (Fl_Callback *) do_ana_cb, this);
210   file_menu->add("Load Analysis", 0, (Fl_Callback *) load_ana_cb, this);
211   file_menu->add("Setup Analysis", 0, (Fl_Callback *) setup_ana_cb, this);
212
213   toggle_divs = new Fl_Button(padding+button_len, 2, button_len, 30, "Toggle Bars");
214   toggle_divs->color(FL_WHITE,a_color);
215   toggle_divs->box(FL_BORDER_BOX);
216   toggle_divs->callback((Fl_Callback*) toggle_scale_bars_cb, this);
217  
218   new_input = new Fl_Input(padding+3*button_len, 2, button_len, 30, "Bar Length (bp)");
219   new_input->value("");
220   new_input->when(FL_WHEN_ENTER_KEY);
221   new_input->callback((Fl_Callback*)set_bar_len_cb, this);
222
223   toggle_lines = new Fl_Button(padding+4*button_len, 2, button_len, 30, "Toggle Lines");
224   toggle_lines->color(FL_WHITE,a_color);
225   toggle_lines->box(FL_BORDER_BOX);
226   toggle_lines->callback((Fl_Callback*) toggle_scale_lines_cb, this);
227  
228   line_input = new Fl_Input(padding+6*button_len, 2, button_len, 30, "Line Length (bp)");
229   line_input->value("");
230   line_input->when(FL_WHEN_ENTER_KEY);
231   line_input->callback((Fl_Callback*)set_line_len_cb, this);
232  
233
234   // create the connections box
235   conn_box = new ConnView(padding, padding + 30, w-2*padding, h-2*padding-30);
236   //conn_box = new ConnView(padding, padding, w-2*padding, h-2*padding);
237
238   end();
239   show();
240 }
241
242
243 ConnWindow::~ConnWindow()
244 {}
245
246
247 void
248 ConnWindow::add_ana(Mussa *the_ana)
249 {
250   an_analysis = the_ana;
251
252   conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
253                   an_analysis->window, &(an_analysis->the_Seqs), 
254                   &(an_analysis->the_paths));
255   conn_box->scale_paths();
256 }