seq_graph.cpp

来自「ncbi源码」· C++ 代码 · 共 240 行

CPP
240
字号
/* * =========================================================================== * PRODUCTION $Log: seq_graph.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 21:11:17  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5 * PRODUCTION * =========================================================================== *//*  $Id: seq_graph.cpp,v 1000.2 2004/06/01 21:11:17 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:  Andrey Yazhuk * * File Description: * */#include <ncbi_pch.hpp>#include <corelib/ncbistl.hpp>#include <gui/widgets/hit_matrix/seq_graph.hpp>//#include <gui/graph/igraph_utils.hpp>#include <objmgr/seq_vector.hpp> #include <objmgr/util/sequence.hpp>#include <FL/Fl.H>#include <math.h>BEGIN_NCBI_SCOPECSequenceGraph::CSequenceGraph(bool b_horz):   m_bHorz(b_horz),    m_pTextFont(NULL),    m_pSeqFont(NULL),     m_BackColor(0.95f, 0.95f, 0.95f),    m_SeqBarColor(0.8f, 0.8f, 1.0f),    m_TextColor(0.0f, 0.0f, 0.0f){}void    CSequenceGraph::SetFonts(CGlBitmapFont* txt_font, CGlBitmapFont* seq_font){    m_pTextFont = txt_font;    m_pSeqFont = seq_font;}void    CSequenceGraph::SetBioseqHandle(CBioseq_Handle& handle){    m_Handle = handle;    m_Label.erase();    if (m_Handle) {        const CSeq_id& best_id =            sequence::GetId(m_Handle, sequence::eGetId_Best);        best_id.GetLabel(&m_Label);    }}static int kSeparator = 6;static int kLabelOffset = 20;static int kSeqBarMargin = 3;TVPPoint CSequenceGraph::PreferredSize(){    float seq_h = m_pSeqFont->GetMetric(CGlBitmapFont::eMetric_MaxCharWidth);    float w = 0, h = 0;            if(m_bHorz) {        float text_h = m_pTextFont->GetMetric(CGlBitmapFont::eMetric_CharHeight);        h = seq_h + text_h + 2 * kSeqBarMargin + 3 * kSeparator;            w = 2 * kLabelOffset + m_pTextFont->TextWidth(m_Label.c_str());            } else {        float seq_sym_w = m_pSeqFont->GetMetric(CGlBitmapFont::eMetric_MaxCharWidth);        float text_sym_w = m_pTextFont->GetMetric(CGlBitmapFont::eMetric_MaxCharWidth);        w = seq_sym_w + text_sym_w + 2 * kSeqBarMargin + 3 * kSeparator;        h = 2 * kLabelOffset + m_Label.size() * (seq_h + 1);    }    return TVPPoint( (int) ceil(w), (int) ceil(h));}void    CSequenceGraph::Render(CGlPane& pane){    if(m_Handle)    {        _ASSERT(m_pTextFont  &&  m_pSeqFont);                glColorC(m_BackColor);        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);        const   TVPRect&    rc_VP = pane.GetViewport();        float seq_h = m_pSeqFont->GetMetric(CGlBitmapFont::eMetric_MaxCharWidth);        float seq_sym_w = m_pSeqFont->GetMetric(CGlBitmapFont::eMetric_MaxCharWidth);        if(m_bHorz) {            float bar_h = seq_h + kSeqBarMargin * 2;            pane.OpenPixels();                        // fill background            glRectd(rc_VP.Left(), rc_VP.Bottom(), rc_VP.Right(), rc_VP.Top());            // draw seq label            glColorC(m_TextColor);            float text_h = m_pTextFont->GetMetric(CGlBitmapFont::eMetric_CharHeight);            float x = rc_VP.Left() + kLabelOffset;            float y = rc_VP.Bottom() + kSeparator;            m_pTextFont->TextOut(x, y, m_Label.c_str());            // draw sequence bar            glColorC(m_SeqBarColor);            y = text_h + 2 * kSeparator;            glRectd(rc_VP.Left(),  y, rc_VP.Right(), y + bar_h);            pane.Close();                        // draw sequence            double min_w = 1.0 / seq_sym_w;            TModelUnit scale_x = pane.GetScaleX();            if(min_w > scale_x)    {    // sequence is visible                pane.OpenOrtho();                    TModelRect rc_model = pane.GetVisibleRect();                    TSeqPos start = (TSeqPos) floor(rc_model.Left());                TSeqPos stop = (TSeqPos) ceil(rc_model.Right());                            // get the sequence                                CSeqVector v_seq = m_Handle.GetSeqVector();                string seq;                v_seq.GetSeqData(start, stop, seq);                fill(seq.begin(), seq.end(), 'G'); // ### temp hack                                glColorC(m_TextColor);                x = start + 0.5;                y += kSeqBarMargin;                m_pSeqFont->ArrayTextOut(x, y, 1.0f, 0.0f, seq.c_str(),                                          (float) scale_x, 0.0f);                pane.Close();                        }                    } else { // vertical orientation            float bar_w = seq_sym_w + kSeqBarMargin * 2;            pane.OpenPixels();                        // fill background            glRectd(rc_VP.Left(), rc_VP.Bottom(), rc_VP.Right(), rc_VP.Top());            // draw seq label            glColorC(m_TextColor);            float text_h = m_pTextFont->GetMetric(CGlBitmapFont::eMetric_CharHeight);            float x = rc_VP.Right() - bar_w - 2 * kSeparator - seq_sym_w;            float y = rc_VP.Bottom() + kLabelOffset;            m_pTextFont->ArrayTextOut(x, y, 0.0f, text_h + 1, m_Label.c_str(),                                      0.0f, (float) pane.GetScaleY());            // draw sequence bar            glColorC(m_SeqBarColor);            x = rc_VP.Right() - kSeparator - bar_w;            glRectd(x, rc_VP.Bottom(), x + bar_w, rc_VP.Top());                        pane.Close();            // draw sequence                        double min_h = 1.0 / seq_h;            TModelUnit scale_y = pane.GetScaleY();            if(min_h > scale_y) {    // sequence is visible                pane.OpenOrtho();                        TModelRect rc_model = pane.GetVisibleRect();                    TSeqPos start = (TSeqPos) floor(rc_model.Bottom());                TSeqPos stop = (TSeqPos) ceil(rc_model.Top());                            // get the sequence                                CSeqVector v_seq = m_Handle.GetSeqVector();                string seq;                v_seq.GetSeqData(start, stop, seq);                fill(seq.begin(), seq.end(), 'T'); // ### temp hack                                glColorC(m_TextColor);                x += kSeqBarMargin;                y = start + 0.5;                m_pSeqFont->ArrayTextOut(x, y, 0.0f, 1.0f, seq.c_str(),                                          0.0f, (float) scale_y);                pane.Close();                        }                        }             }}END_NCBI_SCOPE/* * =========================================================================== * $Log: seq_graph.cpp,v $ * Revision 1000.2  2004/06/01 21:11:17  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5 * * Revision 1.5  2004/05/21 22:27:54  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.4  2004/03/05 17:40:06  dicuccio * Use sequence::GetId() instead of CSeq-id::GetStringDescr() * * Revision 1.3  2003/11/18 18:06:37  ucko * Fixed gcc ERRORS - should #include <math.h>. * * Revision 1.2  2003/11/18 17:57:23  yazhuk * Fixed GCC warnings * * Revision 1.1  2003/11/17 20:41:17  yazhuk * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?