There can be only one (filename convention)
[mussa.git] / gui / SeqWindow.cpp
1 //  This file is part of the Mussa source distribution.
2 //  http://mussa.caltech.edu/
3 //  Contact author: Tristan  De Buysscher, tristan@caltech.edu
4
5 // This program and all associated source code files are Copyright (C) 2005
6 // the California Institute of Technology, Pasadena, CA, 91125 USA.  It is
7 // under the GNU Public License; please see the included LICENSE.txt
8 // file for more information, or contact Tristan directly.
9
10
11 #include "gui/SeqWindow.hpp"
12
13 #include <sstream>
14
15 #include <FL/Fl.H>
16
17 using namespace std;
18
19 void
20 set_align_cb(Fl_Widget* widg, void* the_data)
21 {
22   menu_align_data_bundle * blah = (menu_align_data_bundle *) the_data;
23   SeqWindow* T= blah->swm_ptr;
24   T->real_set_align_cb(blah->which_align);
25 }
26
27
28 void
29 SeqWindow::real_set_align_cb(int which_align)
30 {
31   seq_box->align_offsets(which_align);
32   seq_box->redraw();
33 }
34
35
36 void
37 show_align_cb(Fl_Widget* widg, void* the_data)
38 {
39   menu_align_data_bundle * blah = (menu_align_data_bundle *) the_data;
40   SeqWindow* T= blah->swm_ptr;
41   T->real_show_align_cb(blah->which_align);
42 }
43
44
45 void
46 SeqWindow::real_show_align_cb(int which_align)
47 {
48   vector<int> a_path;
49   int window_length;
50
51
52   cout << "fumish\n";    
53   seq_box->toggle_align(which_align);
54   seq_box->redraw();
55 }
56
57
58 void
59 toggle_bars_cb(Fl_Button* o, void* v)
60 {
61   SeqWindow* T=(SeqWindow*)v;
62   T->real_toggle_bars_cb();
63 }
64
65
66 void
67 SeqWindow::real_toggle_bars_cb()
68 {
69   seq_box->toggle_bars();
70 }
71
72
73 void
74 toggle_motifs_cb(Fl_Button* o, void* v)
75 {
76   SeqWindow* T=(SeqWindow*)v;
77   T->real_toggle_motifs_cb();
78 }
79
80
81 void
82 SeqWindow::real_toggle_motifs_cb()
83 {
84   seq_box->toggle_motifs();
85 }
86
87
88 // main code, window creation
89
90 SeqWindow::SeqWindow(int w, int h, const char* title, int sq_num,
91                      vector<Sequence> *some_seqs, 
92                      list<ExtendedConservedPath > some_paths, 
93                      vector<int> some_lens,
94                      vector<motif> *some_motifs):
95   Fl_Double_Window(w,h,title)
96 {
97   menu_align_data_bundle * some_menu_data;
98   int window_length, align_number;
99   int i;
100   ostringstream align_id_ostr;
101   string align_id_string;
102   list<ExtendedConservedPath >::iterator align_iter;
103
104   // most of this stuff is here just to pass to SeqView object
105   // some is needed to setup the window menus
106   seq_num = sq_num;
107   S = some_seqs;
108   P = some_paths;
109   seq_lens = some_lens;
110   the_motifs = some_motifs;
111
112
113   begin();
114   color(FL_WHITE);
115   resizable(this);
116
117   // make the menu that allows alignment selection
118   choose_align_menu = new Fl_Menu_Button(5, 2, 180, 30, "Choose Alignment");
119   choose_align_menu->color(FL_WHITE,FL_BLUE);
120   choose_align_menu->box(FL_BORDER_BOX);
121   choose_align_menu->clear();
122   
123   // make the menu that allows alignment selection
124   show_align_menu = new Fl_Menu_Button(190, 2, 180, 30, "Show Alignment");
125   show_align_menu->color(FL_WHITE,FL_BLUE);
126   show_align_menu->box(FL_BORDER_BOX);
127   show_align_menu->clear();
128
129
130   // adds menu items for each path
131   align_iter = P.begin();
132   align_number = 0;
133   while(align_iter != P.end())
134   {
135     some_menu_data = new menu_align_data_bundle;
136     some_menu_data->swm_ptr = this;
137     some_menu_data->which_align = align_number;
138     align_id_ostr << (*align_iter)[0] << ": ";
139     for(i = 1; i <= seq_num; i++)
140       align_id_ostr << (*align_iter)[i] << ", ";
141     align_id_string = align_id_ostr.str();
142     choose_align_menu->add((const char*)align_id_string.c_str(), 0, 
143                            (Fl_Callback *) set_align_cb, 
144                            (void*) some_menu_data);
145     show_align_menu->add((const char*)align_id_string.c_str(), 0, 
146                          (Fl_Callback *) show_align_cb, 
147                          (void*) some_menu_data, FL_MENU_TOGGLE|FL_MENU_VALUE);
148
149     align_id_ostr.str("");
150     ++align_number;
151     ++align_iter;
152   }
153
154   /*
155   show_align_menu->add("f&ee"); 
156   show_align_menu->add("f&ie"); 
157   show_align_menu->add("f&oe"); 
158   show_align_menu->add("f&um"); 
159   */
160
161   Fl_Button *test_but = new Fl_Button(375, 2, 150, 30, "Toggle Motifs");
162   test_but->color(FL_WHITE,FL_BLUE);
163   test_but->box(FL_BORDER_BOX);
164   test_but->callback((Fl_Callback*) toggle_motifs_cb, this);
165
166   toggle_bars = new Fl_Button(530, 2, 150, 30, "Toggle 10bp bars");
167   toggle_bars->color(FL_WHITE,FL_BLUE);
168   toggle_bars->box(FL_BORDER_BOX);
169   toggle_bars->callback((Fl_Callback*) toggle_bars_cb, this);
170  
171
172   // make the view of the sequence
173   seq_box = new SeqView(0, 34, w, h-34);
174   seq_box->setup(analysis_name, seq_num, S, P, seq_lens, the_motifs);
175   //real_set_align_cb(2);
176
177   end();
178   Fl::visual(FL_DOUBLE|FL_INDEX);
179   show();
180 }
181
182
183
184 /*
185   some_menu_data = new menu_align_data_bundle;
186   some_menu_data->swm_ptr = this;
187   some_menu_data->which_align = 2;
188   choose_align_menu->add("f&ie", FL_ALT+'i', (Fl_Callback *) set_align_cb,
189                   (void*) some_menu_data);
190
191   some_menu_data = new menu_align_data_bundle;
192   some_menu_data->swm_ptr = this;
193   some_menu_data->which_align = 3;
194   choose_align_menu->add("f&oe", FL_ALT+'o', (Fl_Callback *) set_align_cb,
195                   (void*) some_menu_data);
196
197   some_menu_data = new menu_align_data_bundle;
198   some_menu_data->swm_ptr = this;
199   some_menu_data->which_align = 4;
200   choose_align_menu->add("f&um", FL_ALT+'u', (Fl_Callback *) set_align_cb,
201                   (void*) some_menu_data);
202 */
203
204
205
206