textaln_panel.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:25k
- /*
- * ===========================================================================
- * PRODUCTION $Log: textaln_panel.cpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 21:08:00 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: textaln_panel.cpp,v 1000.2 2004/06/01 21:08:00 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Vlad Lebedev
- *
- */
- #include <ncbi_pch.hpp>
- #include "panel.hpp"
- #include <gui/widgets/aln_data/align_ds.hpp>
- #include <gui/opengl/glcolortable.hpp>
- #include <gui/opengl/glbitmapfont.hpp>
- #include <objects/seqloc/Seq_id.hpp>
- #include <objmgr/util/feature.hpp>
- #include <objmgr/util/sequence.hpp>
- #include <FL/fl_draw.H>
- #include <FL/Fl_Tooltip.H>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(ncbi::objects);
- const int kFontSize = 10; // font size for labels and sequence
- const int kFontWidth = 9; // font width
- const int kCellWidth = 10; // size of one element in the grid
- const int kCellHeight = 13; // do not set less than that
- // or features may not fit
- const size_t kUnknowIdx = ((size_t) (-1));
- const string kLabels = "Labels";
- const string kPosition = "Position";
- CTextAlnPanel::CTextAlnPanel(int x, int y, int w, int h, const char* label)
- : Fl_Gl_Window(x, y, w, h, label)
- , m_Font_8x13(CGlBitmapFont::eBitmap8x13)
- {
- m_DS = NULL;
- m_BackgroundColor = FL_WHITE;
- m_SelectionColor = FL_BLUE;
- m_NumbersColor = FL_BLUE;
- m_GridColor = FL_GRAY;
- m_SequenceColor = FL_BLACK;
- m_MismatchColor = FL_RED;
- m_AlnWidth = 0;
- m_AlnHeight = 0;
- m_Anchor = kUnknowIdx;
- m_ShowSeqAsDots = false;
- m_featDisp = CTextAlnView::eOff;
- }
- CTextAlnPanel::~CTextAlnPanel()
- {
- // delete m_DS;
- }
- TSignedSeqPos CTextAlnPanel::x_GetStartAt(size_t idx, TNumseg seg) const
- {
- return m_DS->GetAlnMgr().GetStart(idx, seg);
- }
- TSeqPos CTextAlnPanel::x_GetAlnWidth(void) const
- {
- return m_DS->GetAlnMgr().GetAlnStop();
- }
- CTextAlnPanel::TDim CTextAlnPanel::x_GetAlnHeigth(void) const
- {
- return m_DS->GetAlnMgr().GetNumRows();
- }
- void CTextAlnPanel::x_PrepareData(void)
- {
- m_ScrX = 0;
- m_ScrY = 0;
- m_AlnWidth = x_GetAlnWidth();
- m_AlnHeight = x_GetAlnHeigth();
- m_ParaG.clear();
- for (TNumrow idx = 0; idx != m_AlnHeight; idx++) {
- if (m_featDisp == CTextAlnView::eAll ||
- (m_featDisp == CTextAlnView::eBase && idx == 0)) {
- x_AddFeaturesAtIndex(idx);
- }
- CParaG para(CParaG::eSequence, idx);
- m_ParaG.push_back(para);
- x_AddInsertsAtIndex(idx);
- }
- }
- void CTextAlnPanel::x_AddInsertsAtIndex(size_t idx)
- {
- CRef<CAlnMap::CAlnChunkVec> chunk_vec = m_DS->GetAlnMgr().GetAlnChunks
- (idx, CAlnMap::TSignedRange(0, m_AlnWidth), CAlnVec::fInsertsOnly);
- if (chunk_vec->size() > 0) {
- CParaG para(CParaG::eInsertion, idx);
- m_ParaG.push_back(para);
- }
- }
- void CTextAlnPanel::x_AddFeaturesAtIndex(size_t idx)
- {
- const CBioseq_Handle& handle = m_DS->GetAlnMgr().GetBioseqHandle(idx);
- for (CFeat_CI feat_it(handle, 0, 0, CSeqFeatData::e_not_set);
- feat_it; ++feat_it) {
- CSeqFeatData::E_Choice type = (*feat_it).GetData().Which();
- if (type == CSeqFeatData::e_Gene || type == CSeqFeatData::e_Rna ||
- type == CSeqFeatData::e_Cdregion || type == CSeqFeatData::e_Prot) {
- const CMappedFeat& feat = *feat_it;
- CParaG para(CParaG::eFeature, idx,
- new CLayoutFeat(*new CMappedFeat(feat)));
- m_ParaG.push_back(para);
- }
- }
- }
- void CTextAlnPanel::ShowSequenceAsDots(bool show_dots)
- {
- m_ShowSeqAsDots = show_dots;
- redraw();
- }
- void CTextAlnPanel::SetAnchor(size_t idx)
- {
- m_Anchor = idx;
- m_DS->SetAlnMgr().SetAnchor(idx);
- x_PrepareData();
- invalidate();
- redraw();
- }
- void CTextAlnPanel::UnsetAnchor(void)
- {
- m_Anchor = kUnknowIdx;
- m_DS->SetAlnMgr().UnsetAnchor();
- x_PrepareData();
- invalidate();
- redraw();
- }
- void CTextAlnPanel::SetDataSource(CAlignDataSource* ds)
- {
- m_DS = ds;
- m_RowSelect.clear(); // reset selections
- m_ColSelect.clear();
- for (TNumrow idx = 0; idx != x_GetAlnHeigth(); idx++)
- m_RowSelect.push_back(false);
- for (size_t idx = 0; idx != x_GetAlnWidth(); idx++)
- m_ColSelect.push_back(false);
- x_PrepareData();
- invalidate();
- redraw();
- }
- void CTextAlnPanel::SelectAll(bool flag)
- {
- if ( !m_DS ) return;
- for (size_t idx = 0; idx != m_RowSelect.size(); idx++)
- m_RowSelect[idx] = flag;
- if (!flag) for (size_t idx = 0; idx != m_ColSelect.size(); idx++)
- m_ColSelect[idx] = flag;
- redraw();
- }
- void CTextAlnPanel::x_DrawSelection(int size, ESelectionType type) const
- {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glColor4f(0.1f, 0.1f, 0.1f, 0.1f);
- glBegin(GL_QUADS);
- if (type == eRow) {
- for (TNumrow row = 0; row != m_ParaG.size(); row++) {
- if (m_RowSelect[m_ParaG[row].GetIndex()]) {
- GLfloat yy = GLfloat(row - m_ScrY) * kCellHeight;
- glVertex2f(0.0f, yy + kCellHeight);
- glVertex2f(size, yy + kCellHeight);
- glVertex2f(size, yy);
- glVertex2f(0.0f, yy);
- }
- }
- } else {
- for (TSeqPos col = 0; col != m_AlnWidth; col++) {
- if (m_ColSelect[col]) {
- GLfloat xx = GLfloat(col - m_ScrX) * kCellWidth;
- glVertex2f(xx, size);
- glVertex2f(xx + kCellWidth, size);
- glVertex2f(xx + kCellWidth, 0.0f);
- glVertex2f(xx, 0.0f);
- }
- }
- }
- glEnd();
- glDisable(GL_BLEND);
- }
- void CTextAlnPanel::x_DrawGrid()
- {
- gl_color(m_GridColor);
- glBegin(GL_LINES);
- for (TSeqPos col = 0; col != m_AlnWidth + 1; col++) {
- GLfloat xx = GLfloat(col - m_ScrX) * kCellWidth;
- glVertex2f(xx, 0.0f);
- glVertex2f(xx, m_Height);
- }
- for (TNumrow row = 0; row != m_ParaG.size(); row++) {
- GLfloat yy = GLfloat(row - m_ScrY) * kCellHeight;
- glVertex2f(0.0f, yy);
- glVertex2f(m_BP[2], yy);
- }
- glEnd();
- x_DrawSelection(m_BP[2], eRow);
- x_DrawSelection(m_BP[3], eCol);
- }
- void CTextAlnPanel::x_DrawSequence(TNumrow row, size_t idx) const
- {
- string seq_draw, seq_base;
- TSeqPos start = m_ScrX;
- TSeqPos finish = m_ScrX + m_BP[2] / kCellWidth;
- m_DS->GetAlnMgr().GetAlnSeqString(seq_draw, idx,
- CAlnMap::TSignedRange(start, finish));
- m_DS->GetAlnMgr().GetAlnSeqString(seq_base, 0,
- CAlnMap::TSignedRange(start, finish));
- GLfloat yy = GLfloat(row - m_ScrY + 1) * kCellHeight + 1;
- for (TSeqPos x = 0; x != seq_draw.length(); x++) {
- GLfloat xx = GLfloat(x * kCellWidth);
- string seq_this = seq_draw.substr(x, 1);
- string seq_other = seq_base.substr(x, 1);
- if (seq_this == " ") seq_this = "-"; // AlnMgr problem fix
- if (seq_this != seq_other) {
- gl_color(m_MismatchColor); // color mismatches
- } else {
- gl_color(m_SequenceColor);
- if (m_ShowSeqAsDots && idx != 0 && seq_this != "-") {
- // draw dots instead (but not on the base sequence)
- seq_this = ".";
- }
- }
- m_Font_8x13.TextOut(xx, yy - 2, seq_this.c_str());
- }
- }
- void CTextAlnPanel::x_DrawFeatures(TNumrow row, size_t idx) const
- {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- GLfloat width = 3;
- const CSeq_loc& loc = m_ParaG[row].Feature()->GetLocation();
- switch (m_ParaG[row].Feature()->GetFeature().GetData().Which()) {
- case CSeqFeatData::e_Gene:
- glColor4f(0.0f, 1.0f, 0.0f, 0.33f);
- width = 3.0f;
- break;
- case CSeqFeatData::e_Rna:
- glColor4f(0.0f, 0.0f, 1.0f, 0.5f);
- width = 5.0f;
- break;
- case CSeqFeatData::e_Cdregion:
- glColor4f(1.0f, 0.0f, 0.0f, 0.33f);
- width = 7.0f;
- break;
- case CSeqFeatData::e_Prot:
- glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
- width = 9.0f;
- break;
- default:
- break;
- }
- TSignedSeqPos s_from = loc.GetTotalRange().GetFrom();
- TSignedSeqPos s_to = loc.GetTotalRange().GetTo();
- TSignedSeqPos al_from = m_DS->GetAlnMgr().GetAlnPosFromSeqPos
- (idx, s_from);
- TSignedSeqPos al_to = m_DS->GetAlnMgr().GetAlnPosFromSeqPos
- (idx, s_to);
- if (al_from == -1) al_from = 0;
- if (al_to == -1) al_to = m_AlnWidth; // some times it happends
- al_from = al_from - m_ScrX; // adjust with scroll values
- al_to = al_to - m_ScrX + 1;
- if (al_from < 0) al_from = 0;
- GLfloat xx1 = al_from * kCellWidth;
- GLfloat xx2 = al_to * kCellWidth;
- GLfloat yy = GLfloat(row - m_ScrY) * kCellHeight +
- GLfloat(kCellHeight / 2);
- x_DrawLine(xx1, yy, xx2, yy, width);
- glDisable(GL_BLEND);
- }
- void CTextAlnPanel::x_DrawInsertions(TNumrow row, size_t idx) const
- {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glLineWidth(1.5f);
- glEnable(GL_POLYGON_SMOOTH);
- glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
- CGlBitmapFont f(CGlBitmapFont::eHelvetica10);
- GLfloat yy = GLfloat(row - m_ScrY) * kCellHeight;
- CRef<CAlnMap::CAlnChunkVec> chunk_vec = m_DS->GetAlnMgr().GetAlnChunks
- (idx, CAlnMap::TSignedRange(0, m_AlnWidth),
- CAlnVec::fInsertsOnly | CAlnVec::fIgnoreGaps);
- string ins_str;
- CGlColorTable table(chunk_vec->size(), 0.5f, 0.75f);
- for (int i = 0; i < chunk_vec->size(); i++) { // for each chunk
- CConstRef<CAlnMap::CAlnChunk> chunk = (*chunk_vec)[i];
- TSeqPos seq_from = chunk->GetRange().GetFrom();
- TSeqPos seq_to = chunk->GetRange().GetTo();
- TSeqPos aln_from = chunk->GetAlnRange().GetFrom();
- m_DS->GetAlnMgr().GetSeqString(ins_str, idx, seq_from, seq_to);
- string to_draw = x_PreprocessSeq(ins_str);
- TSeqPos ins_len = ins_str.length();
- GLfloat ww = gl_width(to_draw.c_str());
- GLfloat xx = GLfloat((aln_from - m_ScrX - 1) * kCellWidth) - ww / 2.0f;
- CGlColor color = table.GetColor(i);
- glColor4f(color.GetRed(), color.GetGreen(), color.GetBlue(), 0.4f);
- glBegin(GL_TRIANGLE_FAN);
- glVertex2f(xx, yy);
- glVertex2f(xx, yy + kCellHeight);
- glVertex2f(xx + ww, yy + kCellHeight);
- glVertex2f(xx + ww, yy);
- glVertex2f(xx + ww / 2, yy - 6);
- glEnd();
- gl_color(FL_RED); //m_SequenceColor); // sequence
- f.TextOut(xx, yy + kCellHeight, to_draw.c_str());
- string label = NStr::UIntToString(ins_len);
- ww = gl_width(label.c_str());
- xx = GLfloat((aln_from - m_ScrX - 1) * kCellWidth) - ww / 2.0f;
- gl_color(FL_BLACK); // size
- f.TextOut(xx, yy + kCellHeight / 2, label.c_str());
- }
- glLineWidth(1.0f);
- glDisable(GL_BLEND);
- glDisable(GL_POLYGON_SMOOTH);
- }
- void CTextAlnPanel::x_DrawTextPanel(void)
- {
- x_ActivateViewPort(m_BP);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- x_DrawGrid();
- TNumrow startY = m_ScrY;
- TNumrow finishY = m_ScrY + m_Height / kCellHeight;
- for (TNumrow row = startY; row != finishY && row < m_ParaG.size(); row++) {
- CParaG para = m_ParaG[row];
- switch(para.GetType()) {
- case CParaG::eFeature:
- x_DrawFeatures(row, para.GetIndex());
- break;
- case CParaG::eSequence:
- x_DrawSequence(row, para.GetIndex());
- break;
- case CParaG::eInsertion:
- x_DrawInsertions(row, para.GetIndex());
- break;
- }
- }
- glPopAttrib();
- }
- void CTextAlnPanel::x_DrawSeqNumPanel(void)
- {
- x_ActivateViewPort(m_NP);
- x_DrawSelection(m_NP[3], eCol);
- TSeqPos startX = m_ScrX;
- TSeqPos finishX = m_ScrX + m_NP[2] / kCellWidth;
- TDim len = NStr::UIntToString(m_AlnWidth).length();
- gl_color(m_GridColor);
- glBegin(GL_LINES);
- for (TSeqPos x = startX; x != finishX; x++) {
- GLfloat xx = GLfloat(x - m_ScrX) * kCellWidth;
- glVertex2f(xx, 0.0f);
- glVertex2f(xx, m_NP[3]);
- }
- for (TNumrow y = 0; y != len; y++) {
- GLfloat yy = y * kFontSize;
- glVertex2f(0.0f, yy);
- glVertex2f(m_NP[2], yy);
- }
- glEnd();
- gl_color(FL_GRAY); // Draw thick separation line
- x_DrawLine(0.0f, len * kFontSize + 1, m_NP[2], len * kFontSize + 1, 2.0f);
- gl_color(m_NumbersColor); // draw labels
- CGlBitmapFont f(CGlBitmapFont::eHelvetica10);
- for (TSeqPos x = startX; x != finishX + 1; x++) {
- GLfloat xx = GLfloat(x - m_ScrX) * kCellWidth;
- if (x % 10 == 0) {
- string s = NStr::UIntToString(x);
- int start = len - s.length();
- for (TNumrow y = start, p = 0; y!= len; y++, p++) {
- string to_draw = s.substr(p, 1);
- GLfloat yy = y * kFontSize + kFontSize - 1;
- f.TextOut(xx + 2, yy, to_draw.c_str());
- }
- } else if (x % 5 == 0) { // draw tick marks
- x_DrawLine(xx + kCellWidth / 2, m_NP[3] - 3 - kFontSize,
- xx + kCellWidth / 2, m_NP[3] - 3, 1.0f);
- }
- }
- glPopAttrib();
- }
- void CTextAlnPanel::x_DrawLabelPanel(void)
- {
- x_ActivateViewPort(m_LP);
- x_DrawSelection(m_LP[2], eRow);
- string label_draw;
- for (TNumrow row = 0; row != m_ParaG.size(); row++) {
- if (m_ParaG[row].GetType() == CParaG::eFeature) {
- string feat_label;
- feature::GetLabel(m_ParaG[row].Feature()->GetFeature(),
- &feat_label, feature::eBoth);
- CGlBitmapFont f(CGlBitmapFont::eHelvetica10);
- GLfloat yy = GLfloat(row - m_ScrY) * kCellHeight + kCellHeight - 3;
- gl_color(m_SequenceColor);
- f.TextOut(2, yy, feat_label.c_str());
- }
- if (m_ParaG[row].GetType() != CParaG::eSequence) continue;
- GLfloat yy = GLfloat(row - m_ScrY + 1) * kCellHeight + 1;
- if (m_Anchor == m_ParaG[row].GetIndex()) { // draw anchor mark
- x_DrawAnchorMark(row);
- }
- gl_color(m_NumbersColor);
- const CSeq_id& id =
- sequence::GetId(m_DS->GetAlnMgr().
- GetBioseqHandle(m_ParaG[row].GetIndex()),
- sequence::eGetId_Best);
- id.GetLabel(&label_draw);
- for (TSeqPos x = 0; x != label_draw.length(); x++) {
- GLfloat xx = kCellWidth + GLfloat(x * kCellWidth) + kCellWidth / 2;
- string seq_this = label_draw.substr(x, 1);
- m_Font_8x13.TextOut(xx, yy - 2, seq_this.c_str());
- }
- }
- gl_color(FL_GRAY); // Draw thick separation line
- x_DrawLine(m_LP[2] - 2, m_LP[1], m_LP[2] - 2, m_LP[3], 2.0f);
- glPopAttrib();
- }
- void CTextAlnPanel::x_DrawAnchorMark(TNumrow row) const
- {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_POLYGON_SMOOTH);
- glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
- gl_color(FL_GREEN);
- GLfloat xx = kCellWidth / 2;
- GLfloat yy = GLfloat(row - m_ScrY) * kCellHeight;
- glBegin(GL_QUADS);
- glVertex2f(xx , yy + kCellHeight / 2);
- glVertex2f(xx + kCellWidth / 2, yy + kCellHeight);
- glVertex2f(xx + kCellWidth , yy + kCellHeight / 2);
- glVertex2f(xx + kCellWidth / 2, yy);
- glEnd();
- glDisable(GL_BLEND);
- glDisable(GL_POLYGON_SMOOTH);
- }
- void CTextAlnPanel::x_DrawInfoPanel(void)
- {
- x_ActivateViewPort(m_IP);
- TDim len = NStr::UIntToString(m_AlnWidth).length();
- gl_color(FL_GRAY); // Draw thick separation line
- x_DrawLine(m_IP[2] - 2, 0.0f, m_IP[2] - 2, m_IP[3], 2.0f);
- x_DrawLine(0.0f, len * kFontSize + 1, m_IP[2], len * kFontSize + 1, 2.0f);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
- x_DrawLine(0.0f, 0.0f, m_IP[2], len * kFontSize + 1, 2.0f);
- glDisable(GL_BLEND);
- glDisable(GL_LINE_SMOOTH);
- glLineWidth(1.0f);
- gl_color(m_NumbersColor);
- CGlBitmapFont f(CGlBitmapFont::eHelvetica10);
- f.TextOut(kCellWidth / 2, len * kFontSize - 2, kLabels.c_str());
- GLfloat xx = m_IP[2] - gl_width(kPosition.c_str()) - kCellWidth;
- f.TextOut(xx, kFontSize - 1, kPosition.c_str());
- glPopAttrib();
- }
- void CTextAlnPanel::draw()
- {
- if (!valid()) {
- x_SetViewPorts ();
- x_AdjustScrollBars();
- }
- glClearColor(1, 1, 1, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- if ( !m_DS ) return;
- x_DrawInfoPanel ();
- x_DrawSeqNumPanel();
- x_DrawTextPanel ();
- x_DrawLabelPanel ();
- return;
- }
- void CTextAlnPanel::x_DrawLine(GLfloat x1, GLfloat y1, GLfloat x2,
- GLfloat y2, GLfloat width) const
- {
- glLineWidth(width);
- glBegin(GL_LINES);
- glVertex2f(x1, y1);
- glVertex2f(x2, y2);
- glEnd();
- glLineWidth(1.0f);
- }
- void CTextAlnPanel::x_SetViewPorts(void)
- {
- m_Width = w();
- m_Height = h();
- gl_font(FL_BOLD, kFontSize);
- TDim m_NPHeight = gl_height() *
- NStr::UIntToString(m_AlnWidth).length();
- TDim m_LPWidth = 0;
- // find out the longest string
- for (TNumrow row = 0; row != m_AlnHeight; row++) {
- const CSeq_id& id =
- sequence::GetId(m_DS->GetAlnMgr().GetBioseqHandle(row),
- sequence::eGetId_Best);
- string str_label;
- id.GetLabel(&str_label);
- TDim len = str_label.length();
- m_LPWidth = max(m_LPWidth, len);
- }
- m_LPWidth = (m_LPWidth + 2) * kCellWidth; // add extra space
- // Numbers panel (on top)
- m_NP[0] = m_LPWidth;
- m_NP[1] = m_Height - m_NPHeight;
- m_NP[2] = m_Width - m_LPWidth;
- m_NP[3] = m_NPHeight;
- // Text panel
- m_BP[0] = m_LPWidth;
- m_BP[1] = 0;
- m_BP[2] = m_Width - m_LPWidth;
- m_BP[3] = m_Height - m_NPHeight;
- // Label panel (on the left)
- m_LP[0] = 0;
- m_LP[1] = 0;
- m_LP[2] = m_LPWidth;
- m_LP[3] = m_Height - m_NPHeight;
- // Info panel (on the left/top corner)
- m_IP[0] = 0;
- m_IP[1] = m_Height - m_NPHeight;
- m_IP[2] = m_LPWidth;
- m_IP[3] = m_NPHeight;
- }
- void CTextAlnPanel::x_AdjustScrollBars(void)
- {
- Fl_Scrollbar* scrollX = (Fl_Scrollbar*)(parent()->child(0));
- Fl_Scrollbar* scrollY = (Fl_Scrollbar*)(parent()->child(1));
- scrollX->linesize(1);
- scrollY->linesize(1);
- scrollX->value(m_ScrX, m_BP[2] / kCellWidth, 0, m_AlnWidth + 1);
- if (m_AlnWidth * kCellWidth < m_BP[2]) scrollX->hide();
- else scrollX->show();
- scrollY->value(m_ScrY, m_BP[3] / kCellHeight, 0, m_ParaG.size());
- if (m_ParaG.size() * kCellHeight < m_BP[3]) scrollY->hide();
- else scrollY->show();
- }
- string CTextAlnPanel::x_PreprocessSeq(const string& s) const
- {
- if (s.length() <= 10) {
- return s;
- } else {
- return s.substr(0, 4) + "..." + s.substr(s.length() - 5, 4);
- }
- }
- void CTextAlnPanel::x_ActivateViewPort(GLuint* port) const
- {
- glPushAttrib(GL_VIEWPORT_BIT);
- glShadeModel(GL_FLAT);
- glViewport(port[0], port[1], port[2], port[3]);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, port[2], port[3], 0, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- int CTextAlnPanel::handle(int event)
- {
- static int s_X, s_Y;
- static bool s_Drag;
- switch (event) {
- case FL_PUSH:
- s_X = Fl::event_x();
- s_Y = Fl::event_y();
- s_Drag = false;
- return 1;
- case FL_DRAG:
- s_Drag = true;
- if (Fl::event_shift()) {
- int pos = Fl::event_x() + m_ScrX * kCellWidth - m_LP[2];
- size_t x = pos / kCellWidth;
- if ( pos < 0 || x < 0 || x >= m_AlnWidth) return 1;
- m_ColSelect[x] = !Fl::event_ctrl();
- redraw();
- } else {
- size_t idx = x_GetAtXY(Fl::event_x(), Fl::event_y());
- if (idx != kUnknowIdx) {
- m_RowSelect[idx] = !Fl::event_ctrl();
- redraw();
- }
- }
- return 1;
- case FL_RELEASE:
- if (s_Drag) {
- s_Drag = false;
- } else {
- size_t idx = x_GetAtXY(Fl::event_x(), Fl::event_y());
- if (idx != kUnknowIdx) {
- m_RowSelect[idx] = !Fl::event_ctrl();
- redraw();
- }
- }
- return 1;
- default:
- return Fl_Gl_Window::handle(event);
- }
- return 0;
- }
- size_t CTextAlnPanel::x_GetAtXY(int x, int y) const
- {
- int pos = y + m_ScrY * kCellHeight - m_NP[3];
- //if (pos < 0) return kUnknowIdx;
- size_t idx = pos / kCellHeight;
- if ( pos < 0 || idx >= m_ParaG.size()) return kUnknowIdx;
- else return m_ParaG[idx].GetIndex();
- }
- // --- Scrolling --------------------------------------------------
- void CTextAlnPanel::Scroll(TSeqPos xPos, TSeqPos yPos)
- {
- m_ScrX = xPos;
- m_ScrY = yPos;
- redraw();
- }
- void CTextAlnPanel::SetFeatureDisplay(CTextAlnView::EFeatureDisplay disp)
- {
- if ( !m_DS ) return;
- m_featDisp = disp;
- x_PrepareData();
- invalidate();
- redraw();
- }
- // Colors
- void CTextAlnPanel::SetColor(CTextAlnView::EDisplayElement elem,
- Fl_Color color)
- {
- switch (elem) {
- case CTextAlnView::eBackground: { m_BackgroundColor = color; break; }
- case CTextAlnView::eGrid: { m_GridColor = color; break; }
- case CTextAlnView::eNumbers: { m_NumbersColor = color; break; }
- case CTextAlnView::eSelection: { m_SelectionColor = color; break; }
- case CTextAlnView::eSequence: { m_SequenceColor = color; break; }
- case CTextAlnView::eMismatch: { m_MismatchColor = color; break; }
- }
- redraw();
- }
- Fl_Color CTextAlnPanel::GetColor(CTextAlnView::EDisplayElement elem) const
- {
- switch (elem) {
- case CTextAlnView::eBackground: return m_BackgroundColor;
- case CTextAlnView::eGrid: return m_GridColor;
- case CTextAlnView::eNumbers: return m_NumbersColor;
- case CTextAlnView::eSelection: return m_SelectionColor;
- case CTextAlnView::eSequence: return m_SequenceColor;
- case CTextAlnView::eMismatch: return m_MismatchColor;
- }
- return FL_BLACK;
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: textaln_panel.cpp,v $
- * Revision 1000.2 2004/06/01 21:08:00 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12
- *
- * Revision 1.12 2004/05/21 22:27:52 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.11 2004/03/11 17:50:41 dicuccio
- * Updated typedefs: dropped TDimension, TPosition, TIndex, TColor; use TSeqRange
- * instead of TRange
- *
- * Revision 1.10 2004/03/05 17:39:13 dicuccio
- * Use sequence::Getid() instead of CSeq_id::GetStringDescr()
- *
- * Revision 1.9 2003/09/29 15:49:58 dicuccio
- * Use CGlBitmapFont instead of home-grown font.
- *
- * Revision 1.8 2003/09/24 19:24:41 ucko
- * ~CTextAlnPanel: stop explicitly deleting m_DS, which is now a CRef.
- *
- * Revision 1.7 2003/09/24 18:34:58 dicuccio
- * Use new generic alignment data source. Removed USING_SCOPE(objects) from
- * headers; used objects:: where necessary
- *
- * Revision 1.6 2003/09/17 16:29:03 dicuccio
- * Use CGlBitmapFont instead of CGlutFont
- *
- * Revision 1.5 2003/08/18 15:23:40 lebedev
- * Changed nales: CFeature -> CLayoutFeat
- *
- * Revision 1.4 2003/07/21 20:28:27 dicuccio
- * Fixed creation of CFeature to match new API
- *
- * Revision 1.3 2003/06/02 16:06:27 dicuccio
- * Rearranged src/objects/ subtree. This includes the following shifts:
- * - src/objects/asn2asn --> arc/app/asn2asn
- * - src/objects/testmedline --> src/objects/ncbimime/test
- * - src/objects/objmgr --> src/objmgr
- * - src/objects/util --> src/objmgr/util
- * - src/objects/alnmgr --> src/objtools/alnmgr
- * - src/objects/flat --> src/objtools/flat
- * - src/objects/validator --> src/objtools/validator
- * - src/objects/cddalignview --> src/objtools/cddalignview
- * In addition, libseq now includes six of the objects/seq... libs, and libmmdb
- * replaces the three libmmdb? libs.
- *
- * Revision 1.2 2003/03/27 20:38:57 dicuccio
- * Fixed compilation errors under Linux (gcc-3.0.4)
- *
- * Revision 1.1 2003/03/27 17:04:32 lebedev
- * Text Alignment Widget: Initial revision
- *
- * ===========================================================================
- */