compact_policy.cpp

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

CPP
336
字号
/* * =========================================================================== * PRODUCTION $Log: compact_policy.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 21:12:27  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12 * PRODUCTION * =========================================================================== *//*  $Id: compact_policy.cpp,v 1000.2 2004/06/01 21:12:27 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 * * File Description: * */#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <gui/widgets/seq_graphic/compact_policy.hpp>#include <objmgr/util/sequence.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);TModelUnit kCompactSpacerSize     = 3.0f; // 3 pixels befween layout objectsCCompactPolicy::CCompactPolicy(){}//// draw a given feature in a given mode//void CCompactPolicy::x_DrawFeature(CGlPane& pane, const CLayoutFeat* feat,                     GLfloat row_y, EObj_IterMode mode, bool selected) const{    const TModelRect& rcV = pane.GetVisibleRect();    const TModelRect& rcM = pane.GetModelLimitsRect();        TModelUnit offsetX = pane.GetOffsetX();    TModelUnit offsetY = pane.GetOffsetY();        TSeqPos from = feat->GetLocation().GetTotalRange().GetFrom();    TSeqPos to   = feat->GetLocation().GetTotalRange().GetTo();        const CSeqFeatData& data = feat->GetFeature().GetData();    TModelRect frc;    frc.SetLeft(from);    frc.SetRight(to);        TModelRect inrc = frc.IntersectWith(rcV);    GLfloat scaleX  = pane.GetScaleX();    bool has_seq = x_IsSeqLettersFit(pane)  &&                     data.Which() == CSeqFeatData::e_Cdregion;        GLfloat th = m_Font_Helv10.TextHeight();    GLfloat title_y  = row_y + th + 1;    GLfloat line_y1  = selected ? title_y + 3 : row_y + 3;    GLfloat line_y2  = selected && has_seq ? line_y1 + th + 2 : line_y1 + 5;        GLfloat line_ym  = selected && has_seq ? line_y1 + (th + 2) / 2                                           : line_y1 + (3 + 2) / 2;                                               GLfloat strand_y = line_y1 + (has_seq ? th : th - 3);    GLfloat off      = rcM.Top() > 0 ? th - 1 : 0;    bool neg_strand = (sequence::GetStrand(feat->GetLocation())                         == eNa_strand_minus);    switch (mode) {    default:        break;    case eDrawObjectLines:        if (true/*kShowIntrons*/) {  // ^ line            GLfloat prev_to_x = 0.0f;            bool first_pass = true;            x_SetFeatureColor(feat);            ITERATE (vector<TSeqRange>, iter, feat->GetIntervals()) {                const TSeqRange& curr = *iter;                TModelUnit from_x, to_x;                if (neg_strand) {                    from_x = curr.GetTo()+1;                    to_x   = curr.GetFrom();                } else {                    from_x = curr.GetFrom();                    to_x   = curr.GetTo()+1;                }                if (!first_pass) {                    GLfloat middle_x = prev_to_x + (from_x - prev_to_x) / 2.0f;                    glVertex2f(prev_to_x - offsetX, line_ym - offsetY);                    glVertex2f(middle_x - offsetX,  line_y1 - offsetY);                    glVertex2f(middle_x - offsetX,  line_y1 - offsetY);                    glVertex2f(from_x - offsetX,    line_ym - offsetY);                }                prev_to_x  = to_x;                first_pass = false;            }        } else {  // straight line            glVertex2f(from - offsetX, line_ym - offsetY);            glVertex2f(to - offsetX,   line_ym - offsetY);        }        // Draw selection        if (selected) {            x_Color(CSeqGraphicColorConfig::eSelection_Feature);            x_DrawSelection(pane, from, line_y1, to, line_y2);        }        break;    case eDrawObjectQuads:        // Highlight named Seq Annotations        if (feat->GetMappedFeature().GetAnnot().IsNamed()) {            CSeq_annot_Handle annot = feat->GetMappedFeature().GetAnnot();            size_t idx = x_GetSeqAnnotIndex(annot);                        TModelUnit h = x_GetRowHeight(pane, feat, selected);            CGlColor color = m_ColorTable.GetColor(idx);            glColor4f(color.GetRed(), color.GetGreen(), color.GetBlue(), 0.1f);                        // add small overhang of 5 pixels (left and right)            TModelUnit over = pane.UnProjectWidth(5);                        glVertex2f(from - offsetX - over, row_y - offsetY);            glVertex2f(from - offsetX - over, row_y+h - offsetY);            glVertex2f(to - offsetX+1+over, row_y+h - offsetY);            glVertex2f(to - offsetX+1+over, row_y - offsetY);        }        x_SetFeatureColor(feat);                // quad for each interval (exon)        ITERATE (vector<TSeqRange>, iter, feat->GetIntervals()) {            const TSeqRange& curr = *iter;            TModelUnit f = curr.GetFrom();            TModelUnit t = curr.GetTo()+1;// + (neg_strand ? 0.0f : 1.0f);                        if (pane.ProjectX(t) - pane.ProjectX(f) <= 1.0f) {                t = f + pane.UnProjectWidth(1);            }            glVertex2f(f - offsetX, line_y1 - offsetY);            glVertex2f(f - offsetX, line_y2 - offsetY);            glVertex2f(t - offsetX, line_y2 - offsetY);            glVertex2f(t - offsetX, line_y1 - offsetY);        }                break;    case eDrawObjectLabel:        if (!selected) break;                // do not even try to draw labels if less than 1 letter width        if (inrc.Width() <= pane.UnProjectWidth(m_MinLabelWidth)) {            break;        }        string fl_both;        string fl_type;        string fl_content;        string fl_out;        x_GetLabels(feat->GetFeature(), m_Handle.GetScope(),                    &fl_type, &fl_content, &fl_both);        GLfloat widthP     = inrc.Width() / scaleX; // width in pixels        GLfloat lw_type    = m_Font_Helv10.TextWidth(fl_type.c_str() );        if ( lw_type * 3 < widthP) { // 3 widths of eType label width            fl_out = m_Font_Helv10.Truncate(fl_both.c_str(), widthP);        } else {            fl_out = m_Font_Helv10.Truncate(fl_content.c_str(), widthP);        }                if (selected) {            x_Color(CSeqGraphicColorConfig::eSelLabel_Feature);        } else {            x_Color(CSeqGraphicColorConfig::eLabel_Feature);        }        x_Color(CSeqGraphicColorConfig::eSelection_Feature);        GLfloat xM = x_CenterText(pane, inrc,                      m_Font_Helv10.TextWidth(fl_out.c_str()));        m_Font_Helv10.TextOut(xM - offsetX, title_y - off - offsetY, fl_out.c_str());        // draw strand indicator        xM = x_CenterText(pane, inrc, m_Font_Helv10.TextWidth("<"));        glColor3f(0.0f, 0.0f, 0.0f);  // Black                m_Font_Helv10.TextOut(xM - offsetX, strand_y - off - offsetY,                             neg_strand ? "<" : ">");        break;    }}// draw proteint product and label only when selectedvoid CCompactPolicy::x_DrawProteinProduct(CGlPane& pane, const CLayoutFeat* feat,                     GLfloat row_y, EProtSeqType type, bool selected) const{    // draw protein product for selected features only    if (selected) {        CDefaultPolicy::x_DrawProteinProduct(pane, feat, row_y, type, selected);    }}TModelUnit CCompactPolicy::x_GetRowHeight(CGlPane& pane,                 const CLayoutFeat* feat, bool selected) const{    const CSeqFeatData& data = feat->GetFeature().GetData();    bool seq_fit             = x_IsSeqLettersFit(pane);        if (selected  &&  data.Which() == CSeqFeatData::e_Cdregion &&  seq_fit) {        return 30.0f; // two and a half rows for selected CDSs    } else if (selected) {        return 24.0f; // two rows for selected feature    } else {        return 12.0f; // one row for all other cases    }}TModelUnit CCompactPolicy::x_GetRowHeight(CGlPane& pane,                 const CLayoutProtProd* prot, bool selected) const{    if (selected  &&  x_IsSeqLettersFit(pane) ) {        return 30.0f; // one and a half row for selected protein    } else if (selected) {        return 24.0f; // two rows for selected feature    } else {        return 9.0f + kCompactSpacerSize;    }}TModelUnit CCompactPolicy::x_GetRowHeight(CGlPane& pane,                     const CLayoutHistogram* hist, bool selected) const{    return 12.0f + kCompactSpacerSize; // 10 pixels for histogram in this policy}TModelUnit CCompactPolicy::x_GetRowHeight(CGlPane& pane,                    const CLayoutFeatLabel* label, bool selected) const{    return 9.0f + kCompactSpacerSize;  // one row for labels in the compact policy}END_NCBI_SCOPE/* * =========================================================================== * $Log: compact_policy.cpp,v $ * Revision 1000.2  2004/06/01 21:12:27  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12 * * Revision 1.12  2004/05/21 22:27:55  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.11  2004/04/14 11:25:02  lebedev * Use x_DrawSelection from the base class * * Revision 1.10  2004/04/07 13:09:40  dicuccio * Use CSeq_annot_Handle for proper annotation anme comparison * * Revision 1.9  2004/03/30 13:58:37  lebedev * Use elements colors from configuration instead of setting colors directly. * * Revision 1.8  2004/03/23 12:33:55  lebedev * Made sequence and histograms bars a layout objects in the object panel. * Made segment map a number of layout objects. Get rid of fixed size rows in the object panel. * * Revision 1.7  2004/03/11 17:53:06  dicuccio * Deprecated typedefs TPosition, TDimension, TIndex, TColor.  Use TSeqRange instead of TRange * * Revision 1.6  2004/01/29 14:09:35  dicuccio * Drop erroneous constructor call - was creating anonymous object instead of calling base class * * Revision 1.5  2004/01/16 13:40:14  lebedev * Tooltips added * * Revision 1.4  2004/01/05 21:25:05  dicuccio * Code clean-up.  Corrected issue with protein product features not appearing in * the correct color; standardized use of x_SetFeatureColor() * * Revision 1.3  2004/01/05 17:53:15  dicuccio * Use x_GetLabels() * * Revision 1.2  2003/12/22 12:55:49  lebedev * Old files removed * * Revision 1.1  2003/12/16 18:57:43  lebedev * Initial revision * =========================================================================== */

⌨️ 快捷键说明

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