857e49b174d8e55d6135582ec98f05b42bed3798
[mussa.git] / gui / SeqTextWindow.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/SeqTextWindow.hpp"
12
13 #include <iostream>
14 using namespace std;
15 void
16 get_seq_cb(Fl_Button* o, void* v)
17 {
18   SeqTextWindow* T=(SeqTextWindow*)v;
19   T->real_get_seq_cb();
20 }
21
22 void
23 SeqTextWindow::real_get_seq_cb()
24 {
25   string sub_seq_formatted;
26   int seq_len, i, line_len;
27
28
29   cout << "length = " << seq_end-seq_start << endl;
30
31   // make sure inputed values within valid ranges
32   if ((seq_end > seq_start) && (seq_id > -1) && (seq_id < the_seqs.size()) )
33   {
34     sub_sequence = the_seqs[seq_id].subseq(seq_start, seq_end-seq_start);
35
36     sub_seq_formatted = "";
37     seq_len = sub_sequence.size();
38     line_len = 40;
39     for (i = 0; i < seq_len; i += line_len)
40     {
41       sub_seq_formatted.append(sub_sequence.substr(i,line_len));
42       sub_seq_formatted.append("\n");
43     }
44
45     seq_display->value((const char *)sub_seq_formatted.c_str());
46   }
47 }
48
49
50 // *** input seq index id
51
52 void
53 set_seq_id_cb(Fl_Input* o, void* v)
54 {
55   SeqTextWindow* T=(SeqTextWindow*)v;
56   T->real_set_seq_id_cb(o);
57 }
58
59 void
60 SeqTextWindow::real_set_seq_id_cb(Fl_Input* o)
61 {
62   seq_id = atoi(o->value()) - 1;   // -1 since arrays start at 0
63 }
64
65
66 // *** input seq start index
67
68 void
69 set_seq_start_cb(Fl_Input* o, void* v)
70 {
71   SeqTextWindow* T=(SeqTextWindow*)v;
72   T->real_set_seq_start_cb(o);
73 }
74
75 void
76 SeqTextWindow::real_set_seq_start_cb(Fl_Input* o)
77 {
78   seq_start = atoi(o->value());
79 }
80
81 // *** input seq end index
82
83 void
84 set_seq_end_cb(Fl_Input* o, void* v)
85 {
86   SeqTextWindow* T=(SeqTextWindow*)v;
87   T->real_set_seq_end_cb(o);
88 }
89
90 void
91 SeqTextWindow::real_set_seq_end_cb(Fl_Input* o)
92 {
93   seq_end = atoi(o->value());
94 }
95
96
97 SeqTextWindow::SeqTextWindow(int w, int h, const char* title,
98                        vector<Sequence> some_Seqs):Fl_Window(w,h,title)
99 {
100   string a_name;
101   color(FL_WHITE);
102   the_seqs = some_Seqs;
103
104
105   seq_id = -1;
106   seq_start = 1000000;
107   seq_end = -1000000;
108
109   begin();
110
111   seq_id_input = new Fl_Input(80,10,30,30, "Seq num: ");
112   seq_id_input->value("");
113   seq_id_input->callback((Fl_Callback*)set_seq_id_cb, this);
114
115   seq_start_input = new Fl_Input(160,10,100,30, " start: ");
116   seq_start_input->value("");
117   seq_start_input->callback((Fl_Callback*)set_seq_start_cb, this);
118
119   seq_end_input = new Fl_Input(310,10,100,30, "end: ");
120   seq_end_input->value("");
121   seq_end_input->callback((Fl_Callback*)set_seq_end_cb, this);
122
123   seq_display = new Fl_Multiline_Output(10, 50, w-20, h-60, "");
124   seq_display->value("");
125
126   //seq_display2 = new Fl_Text_Display(10,100, w-20, h-110,"");
127
128   // button to get the sequence
129   get_seq_but = new Fl_Button(w-80,10,80,30,"Get Seq");
130   get_seq_but->callback((Fl_Callback*)get_seq_cb, this);
131
132
133   end();
134   //resizable(this);
135   show();
136 }
137
138
139 SeqTextWindow::~SeqTextWindow(){}
140
141 /*
142   cout << "fee\n";
143   cout << "fie\n";
144   cout << "foe\n";
145   cout << "fum\n";
146 */