Sequence View
We have decided to use FLTK and OpenGL for our GUI needs.
Presently, we use FLTK Release 1.1. Internal developers can use pre-built FLTK from $NCBI/fltk/ on UNIX platforms, and from \\DISSY\public\fltk\ on MS-Windows. Its full source archive is available internally at $NCBI/fltk/share/src/fltk-1.1.0-source.tar.bz2.
GUI part of the NCBI C++ Toolkit defines its own namespace: "gui". GUI namespace will also include NCBI namespace. In your code use BEGIN_GUI_SCOPE and END_GUI_SCOPE when working on GUI projects
| Type | Description |
|---|---|
| TColor | used to deal with colors in GUI. Sequence View stores the color that is either an index into a color palette of 256 colors (like FL_YELLOW) or a 24-bit RGB color. The color palette is not the X or WIN32 color map, but instead is an FLTK internal table with fixed contents. Currently defined as Fl_Color. Take a look into FL/Enumerations.H in the FLTK for complete list of definitions. Take a look into FLTK documentation on how to define new colors. |
| TKey | used to store the values for keyboard keys like FL_Left, 'c', 'A', FL_Page_Up. Currently defined as integer. Take a look into FL/Enumerations.H in the FLTK for complete list of definitions. |
| TKeyState | used to store the values for keyboard keys modifiers like Control, Alt or Shift (FL_CTRL, FL_ALT, FL_SHIFT). Currently defined as integer. Take a look into FL/Enumerations.H in the FLTK for complete list of definitions. |
| TLineNo | used to store line numbers in the Sequence View. Currently defined as integer. |
| TCharNo | used to store character positions in the Sequence View. Currently defined as integer. |
| TDimension | used to store various measurements in the Sequence View. Currently defined as integer. |
| TPosition | used to store X or Y coordinates in the Sequence View. Currently defined as integer. |
Sequence View
The Sequence View relies on two external components: OpenGL and FLTK. OpenGL is used for all drawing, FLTK is used to layout and display GUI elements.
The SeqView consists of a three classes:
CSeqPanel
OpenGL panel inherited from Fl_Gl_Window. Actual drawing is done here.
CSeqView
The Sequence View itself. Contains CSeqPanel and Fl_Scrollbar.
CSeqDataSource
A Sequence View data source. Used by CSeqPanel to get sequence and features to draw. All mouse and keyboard events are also handled here. Inherit your data source implementation from this class.
These three steps are required to use SeqView in your code:
Create an instance of Sequence View Widget.
Define your data source (inherit CSeqDataSource and implement required methods)
Register the data source with Sequence View.
The easiest way to setup a Sequence View is to use FLUID - FLTK interface designer:
Add new Fl_Group (New->group->Group in FLUID menu) to your window.
Enter CSeqView as a class name in the C++ tab of the Property dialog.
Enter m_SeqView as a member name.
Enter #include "gui/seq/view.hpp" in the "extra code" field below
FLUID will generate code to create an instance of CSeqView and to add it to your window.
To setup Sequence View manually use the standard FLTK widgets constructor. Something like:
The data source is required to provide Sequence View with the actual sequence data to display. To create a data source:
Inherit your data source from CSeqDataSource
Implement the 4 required methods.
TSeqPos GetSequenceLength()
to return the sequence length
void GetSequence(TSeqPos from, TSeqPos to, string& buffer)
to fill buffer with molecule sequence within a given region
void GetFeatures(TSeqPos from, TSeqPos to, vector& vec)
to fill vector of features within a given region
Implement optional methods, such as keyboard and mouse events handling.
Register your data source with Sequence View by calling SetDataSource() method of the Sequence View.
Sequence View is capable of displaying four different kinds of feature shapes. These shapes are defined in the CVisibleFeature class.
| Feature | Attribute |
|---|---|
| string m_Id | Unique ID to identify feature |
| TseqPos m_From | Feature start |
| TseqPos m_To | Feature finish |
| TColor m_Color | Feature color |
| EType m_Type | Shape to represent the feature. |
| TDimension m_Height | Height of the feature bar. Two extra margin pixels (on top and bottom) will be automatically added to this value. |
| vector< CVisibleFeature > m_SubIntervals | Define sub-intervals for multi features (eMulti type). For all other feature types this will be ignored. |
| Type | Appearance (Heights from 1 to 5) |
|---|---|
| eBox |
![]() |
| eRightArrow |
![]() |
| eLeftArrow |
![]() |
| eMulti |
![]() |
The NCBI C++ Toolkit Object Manager is ideally suited for use in the Sequence View data sources.
Features will be shown in the Sequence View in the exact order of features in "vec" vector. The best way to group features by type is to iterate through one kind of feature after another in the order you would like them to appear in the Sequence View.
The support for keyboard and mouse events is implemented in the Sequence View data source. One can override any of the following virtual functions and implement its own handlers for these events, which are:
KeyPressed, Cut, Copy, Paste, DoubleClick
If a method modifies the data it should return an "eRedraw" – a notice to Sequence View to redraw itself. eNoRedraw indicates that no changes to the data was made and therefore redraw is not necessary.
The KeyPressed method will be called each time a key is pressed in the Sequence View.
In this call "key" is FLTK definition for a key pressed and "key_state" contains keyboard states for Shift, Control, Alt and some other keys. Please refer to FL/Enumerations.H in FLTK for complete list of keys and keystate definitions. The "cursor" contains current position of a Sequence Cursor in the view.
One of possible uses of this method is to implement an "inline" editing of a molecule sequence.
Separately from the keyboard events handler, methods for clipboard shortcuts are implemented. These methods will be called each time a Cut, Copy or Paste key combination is pressed in the Sequence View. These key combinations are platform-dependent and handled by FLTK engine. (For example: Ctrl-C, for Copy on Windows and Option-C on Mac).
In these calls "from" and "to" define the position of the sequence selection in the View and "cursor" is a current cursor position. Don't forget to return eRedraw if the sequence data is modified by those methods.
DoubleClick method is called each time when double-click event occurs in the valid area of the Sequence View.
In this call "at" is a sequence position of the double click and "feature_id" contains the ID of a feature if feature was clicked on.
The following ten methods are available in Sequence View:
SetDataSource, ShowFeatures, HideFeatures, SetSelection, GetSelectionStart, GetSelectionFinish, SetCursor, GetCursor, SetColor and GetColor.
Use SetDataSource method to register a new DataSource with Sequence View.
In this call "ds" is a user data source inherited from CSeqDataSource.
To enable or disable display of a sequence features use the following pair of Sequence View methods.
By default, features are not shown.
Region of the sequence can be selected programmatically using:
To obtain the current sequence selection region, use the following pair of methods:
Position of the cursor in the sequence can be set or retrieved using:
Sequence view allows customizing the color of the following display elements:
Please refer to FLTK documentation for a complete list of fixed color definitions or use fl_rgb_color() call to create your own color:
The following pair of methods allows setting and retrieving the color of a particular display element of a Sequence View.
Demo View is small application to demonstrate the basics of the Sequence View.
demo_view.cpp - code generated by FLUID (Fast Light User Interface Designer). Please use FLUID to open demo_view.fl template file.
CSeqViewTestDS - is a sample data source that uses NCBI C++ Toolkit Object Manager to get real molecules from DB.
The demo data source also implements a sample Cut/Copy/Paste operations and double-click handling.