5a3351cdddb5f42b8a4d86c868e78bc852a2e194
[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   cout << "fumish\n";    
52   seq_box->toggle_align(which_align);
53   seq_box->redraw();
54 }
55
56
57 void
58 toggle_bars_cb(Fl_Button* o, void* v)
59 {
60   SeqWindow* T=(SeqWindow*)v;
61   T->real_toggle_bars_cb();
62 }
63
64
65 void
66 SeqWindow::real_toggle_bars_cb()
67 {
68   seq_box->toggle_bars();
69 }
70
71
72 void
73 toggle_motifs_cb(Fl_Button* o, void* v)
74 {
75   SeqWindow* T=(SeqWindow*)v;
76   T->real_toggle_motifs_cb();
77 }
78
79
80 void
81 SeqWindow::real_toggle_motifs_cb()
82 {
83   seq_box->toggle_motifs();
84 }
85
86
87 // main code, window creation
88
89 SeqWindow::SeqWindow(int w, int h, const char* title, int sq_num,
90                      vector<Sequence> *some_seqs, 
91                      list<ConservedPath > some_paths, 
92                      vector<int> some_lens,
93                      vector<fltk_motif> *some_motifs):
94   Fl_Double_Window(w,h,title)
95 {
96   menu_align_data_bundle * some_menu_data;
97   int window_length, align_number;
98   int i;
99   ostringstream align_id_ostr;
100   string align_id_string;
101   list<ConservedPath >::iterator align_iter;
102
103   // most of this stuff is here just to pass to SeqView object
104   // some is needed to setup the window menus
105   seq_num = sq_num;
106   S = some_seqs;
107   P = some_paths;
108   seq_lens = some_lens;
109   the_motifs = some_motifs;
110
111
112   begin();
113   color(FL_WHITE);
114   resizable(this);
115
116   // make the menu that allows alignment selection
117   choose_align_menu = new Fl_Menu_Button(5, 2, 180, 30, "Choose Alignment");
118   choose_align_menu->color(FL_WHITE,FL_BLUE);
119   choose_align_menu->box(FL_BORDER_BOX);
120   choose_align_menu->clear();
121   
122   // make the menu that allows alignment selection
123   show_align_menu = new Fl_Menu_Button(190, 2, 180, 30, "Show Alignment");
124   show_align_menu->color(FL_WHITE,FL_BLUE);
125   show_align_menu->box(FL_BORDER_BOX);
126   show_align_menu->clear();
127
128
129   // adds menu items for each path
130   align_iter = P.begin();
131   align_number = 0;
132   while(align_iter != P.end())
133   {
134     some_menu_data = new menu_align_data_bundle;
135     some_menu_data->swm_ptr = this;
136     some_menu_data->which_align = align_number;
137     align_id_ostr << (*align_iter).window_size << ": ";
138     for(i = 0; i != seq_num; i++)
139       align_id_ostr << (*align_iter).track_indexes[i] << ", ";
140     align_id_string = align_id_ostr.str();
141     choose_align_menu->add((const char*)align_id_string.c_str(), 0, 
142                            (Fl_Callback *) set_align_cb, 
143                            (void*) some_menu_data);
144     show_align_menu->add((const char*)align_id_string.c_str(), 0, 
145                          (Fl_Callback *) show_align_cb, 
146                          (void*) some_menu_data, FL_MENU_TOGGLE|FL_MENU_VALUE);
147
148     align_id_ostr.str("");
149     ++align_number;
150     ++align_iter;
151   }
152
153   Fl_Button *test_but = new Fl_Button(375, 2, 150, 30, "Toggle Motifs");
154   test_but->color(FL_WHITE,FL_BLUE);
155   test_but->box(FL_BORDER_BOX);
156   test_but->callback((Fl_Callback*) toggle_motifs_cb, this);
157
158   toggle_bars = new Fl_Button(530, 2, 150, 30, "Toggle 10bp bars");
159   toggle_bars->color(FL_WHITE,FL_BLUE);
160   toggle_bars->box(FL_BORDER_BOX);
161   toggle_bars->callback((Fl_Callback*) toggle_bars_cb, this);
162  
163
164   // make the view of the sequence
165   seq_box = new SeqView(0, 34, w, h-34);
166   seq_box->setup(analysis_name, seq_num, S, P, seq_lens, the_motifs);
167   //real_set_align_cb(2);
168
169   end();
170   Fl::visual(FL_DOUBLE|FL_INDEX);
171   show();
172 }