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