root/trunk/FRII/gui/MappingView.hh

Revision 10, 3.3 kB (checked in by t, 3 years ago)

Tailorization
Import of the upstream sources from

Repository: :pserver:anonymous@cvs.sf.net:/cvsroot/familyjewels

Kind: cvs

Module: FRII

Revision: 2005-12-09 09:00:54 by titus

Original author: tailor@vallista.idyll.org
Date: 2005-12-09 09:00:54

Line 
1 /*
2  * This file is part of the FamilyRelations II source distribution.
3  *
4  * FamilyRelations II is part of the FamilyJewels package for comparative
5  * sequence analysis: http://family.caltech.edu/.
6  *
7  * Contact author: C. Titus Brown, titus@caltech.edu.
8  *
9  * This program and all associated source code files are Copyright (C) 2003,
10  * 2004 the California Institute of Technology, Pasadena, CA, 91125 USA.  It
11  * is under the Lesser GNU Public License; please see the included
12  * LICENSE.txt file for more information, or contact Titus directly.
13  *
14  */
15
16 // Base class for pairwise views (dot-plots or alignments or...).  All
17 // subclasses must support:
18 //    * zooming;
19 //    * display of maps (c.f. MappingContainer.hh);
20 //    * access to top/bottom SequenceViews (c.f. SequenceView.hh).
21 //
22 // See PairwiseMappingView.* and DotPlotMappingView.* for specific subclasses.
23
24 #ifndef MAPPING_VIEW_HH
25 #define MAPPING_VIEW_HH
26
27 #include <FL/Fl.H>
28 #include <FL/Fl_Window.H>
29 #include <FL/Fl_Box.H>
30 #include <FL/fl_draw.H>
31
32 #include <vector>
33 #include <map>
34 #include <assert.h>
35
36 #include "SequenceView.hh"
37 #include "MappingContainer.hh"
38 #include "_Canvas.hh"
39
40 namespace gui {
41   class MappingView : public Fl_Group {
42   protected:
43     const int top_len, bot_len;
44     SequenceView* top_seq, * bot_seq;
45
46     _Canvas* canvas;
47
48     // the stuff to draw
49     std::vector<MappingContainer*> _maps;
50
51     MappingView(int a, int b, int c, int d, int top, int bot)
52       : Fl_Group(a, b, c, d), top_len(top), bot_len(bot),
53         top_seq(NULL), bot_seq(NULL) { };
54   public:
55     // add_map -- add the map to be drawn.
56     void add_map(MappingContainer* m) {
57       _maps.push_back(m);
58
59       MappingContainerChanged_ * listener;
60       listener = new MappingContainerChanged_Redrawer(this);
61
62       m->add_change_listener(listener);
63     }
64
65     // zoom top/bot
66     virtual void zoom_top(int start, int end) {
67       canvas->set_top_sequence_coords(start, end);
68       redraw();
69     }
70
71     virtual void zoom_bot(int start, int end) {
72       canvas->set_bot_sequence_coords(start, end);
73       redraw();
74     }
75
76     virtual void select_top(unsigned int start, unsigned int end) { };
77     virtual void select_bot(unsigned int start, unsigned int end) { };
78
79     // accessor functions
80     SequenceView * get_top_seq_view() const { return top_seq; }
81     SequenceView * get_bot_seq_view() const { return bot_seq; }
82     const _Canvas * get_canvas() const { return canvas; }
83   };
84
85   //
86   // A private little class to adapt sequence view changes to top or bottom
87   // map changes.
88   //
89
90   class SequenceViewListener_MappingAdapter :
91     public SequenceViewListener_ {
92   private:
93     MappingView* view;
94     int position;
95   public:
96     const static int TOP = 0;
97     const static int BOT = 1;
98
99     SequenceViewListener_MappingAdapter(MappingView* v, int p) :
100       SequenceViewListener_(), view(v), position(p) {
101       assert(position == TOP || position == BOT);
102     }
103
104     void notify(SequenceViewCoordinates& coords) {
105       if (position == TOP) {
106         view->zoom_top(coords.start, coords.end);
107       } else {
108         view->zoom_bot(coords.start, coords.end);
109       }
110     }
111
112     void set_selection(unsigned int start, unsigned int end) {
113       if (position == TOP) {
114         view->select_top(start, end);
115       } else {
116         view->select_bot(start, end);
117       }
118     }
119   };
120 }
121
122 #endif // MAPPING_VIEW_HH
123
Note: See TracBrowser for help on using the browser.