⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 features_panel_ir.cpp

📁 ncbi源码
💻 CPP
字号:
/* * =========================================================================== * PRODUCTION $Log: features_panel_ir.cpp,v $ * PRODUCTION Revision 1000.3  2004/06/01 21:12:35  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.19 * PRODUCTION * =========================================================================== *//*  $Id: features_panel_ir.cpp,v 1000.3 2004/06/01 21:12:35 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 <gui/widgets/seq_graphic/features_panel_ir.hpp>#include <algorithm>#include <ctype.h>#include <math.h>#include <objmgr/scope.hpp>#include <objmgr/util/feature.hpp>#include <objmgr/util/sequence.hpp>#include <objtools/alnmgr/alnmix.hpp>#include <serial/iterator.hpp>#include <util/sequtil/sequtil_manip.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);const TModelUnit kPixPerBase4Sequence = 8.0f; // at this point sequence will fitconst int        kLabelsMaxWidth      = 90;   // width of a feature label small//const TSeqPos    kGenesOverviewZoom  = 150;  // 150 bp per pixelCFeaturesPanelIR::CFeaturesPanelIR(){}CFeaturesPanelIR::~CFeaturesPanelIR(){}void CFeaturesPanelIR::SetHandle(const CBioseq_Handle& handle){    m_Handle = handle;    if (m_RenderPolicy) {        m_RenderPolicy->SetHandle(handle);    }    if (m_LayoutPolicy) {        m_LayoutPolicy->SetHandle(handle);    }}void CFeaturesPanelIR::SetRenderPolicy(IPolicy* policy){    m_RenderPolicy.Reset(policy);    if (m_RenderPolicy) {        m_RenderPolicy->SetConfig(m_ConfigSettings);        m_RenderPolicy->SetHandle(m_Handle);    }}void CFeaturesPanelIR::SetLayoutPolicy(ILayoutPolicy* policy){    m_LayoutPolicy.Reset(policy);    if (m_LayoutPolicy) {        m_LayoutPolicy->SetConfig(m_ConfigSettings);        m_LayoutPolicy->SetHandle(m_Handle);    }}void CFeaturesPanelIR::SetConfig(CSeqGraphicConfig* config){    m_ConfigSettings = config;    if (m_RenderPolicy) {        m_RenderPolicy->SetConfig(config);    }    if (m_LayoutPolicy) {        m_LayoutPolicy->SetConfig(config);    }}TModelUnit CFeaturesPanelIR::GetHeight(CGlPane& pane){    m_LayoutPolicy->PrepareData(pane, m_PackedObjects);    m_RowCount = 0;    pane.OpenOrtho();    x_MainObjectIterator(pane, IPolicy::eCalcObjectRows);    pane.Close();    return (m_RowCount + 5);// * m_RenderPolicy->GetOneRowHeight();}void CFeaturesPanelIR::Render(CGlPane& pane){        pane.OpenOrtho();    glBegin(GL_LINES);    x_DrawXGrid(pane);    glEnd();    m_ConfigSettings->GetElementColor(CSeqGraphicColorConfig::eGridHorizontal);    x_MainObjectIterator(pane, IPolicy::eDrawObjectGrid);    glEnable(GL_BLEND);    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);    glEnable(GL_LINE_SMOOTH);    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);    glLineWidth(1.5f);    x_MainObjectIterator(pane, IPolicy::eDrawObjectQuads);    x_MainObjectIterator(pane, IPolicy::eDrawObjectLines);    x_MainObjectIterator(pane, IPolicy::eDrawObjectLabel);    glDisable(GL_BLEND);    glDisable(GL_LINE_SMOOTH);    glLineWidth(1.0f);    pane.Close();}TVPRect CFeaturesPanelIR::GetVPRect(){    TVPRect rc(0, 0, 0, 0);    return rc;}TModelRect CFeaturesPanelIR::GetModelRect(){    TModelRect rc(0, 0);    rc.SetSize(0, m_RowCount + 5);// * m_RenderPolicy->GetOneRowHeight());    return rc;}bool CFeaturesPanelIR::x_IsSeqLettersFit(CGlPane& pane) const{    return pane.GetScaleX() <= 1.0f / kPixPerBase4Sequence;}const CLayoutObject*CFeaturesPanelIR::HitTest(CGlPane& pane, int x, int y){    pane.OpenOrtho();    m_LastClick = pane.UnProject(x, y);    pane.Close();    m_RenderPolicy->SetHitPoint(m_LastClick);    const CLayoutObject* obj = x_MainObjectIterator(pane, IPolicy::eObjectHitTest);    return obj;}void CFeaturesPanelIR::GetTooltip(const CLayoutObject* obj, string* title) const{    m_RenderPolicy->GetTitle(obj, title, CLabel::eTooltipDetailed);}void CFeaturesPanelIR::GetHTMLActiveAreas(CGlPane& pane,                                          IPolicy::TAreaVector* p_areas){    m_RenderPolicy->SetActiveArea(p_areas);    x_MainObjectIterator(pane, IPolicy::eGetHTMLAreas);}const CLayoutObject* CFeaturesPanelIR::x_MainObjectIterator(CGlPane& pane,                                       IPolicy::EObj_IterMode mode){    glLineWidth(1.0f);    switch (mode) {    case IPolicy::eDrawObjectLines:    case IPolicy::eDrawObjectGrid:        glBegin(GL_LINES);        break;    case IPolicy::eDrawObjectQuads:        glBegin(GL_QUADS);        break;    default:        break;    }    TModelUnit row = 0.0f;    vector<CLayoutFeat::TFeatList> leaves;    ITERATE (CLayout::TLayout, row_iter, m_PackedObjects.GetLayout()) {        TModelUnit new_row = row;        ITERATE (CLayout::TLayoutRow, obj_iter, *row_iter) {            TModelUnit temp_row = row;            const CLayoutObject* obj = *obj_iter;            const CLayoutFeat* curr_feat =                dynamic_cast<const CLayoutFeat*>(obj);            bool selected = x_IsObjectSelected(obj);            // First, decompose into a vector of leaves suitable for            // rendering.  we do this in an odd way - we exclude the current            // feature and only examine its kids.            leaves.clear();            if (curr_feat) {                ITERATE (CLayoutFeat::TFeatList, kid_iter,                         curr_feat->GetChildren()) {                    x_DecomposeToLeaves(*kid_iter, leaves);                }            }            // render the current feature            if (m_RenderPolicy->ProcessObject(pane, *obj_iter, temp_row,                                              mode, selected)) {                return *obj_iter;            }            temp_row += m_RenderPolicy->GetRowHeight(pane, *obj_iter, selected);            // now, render all the leaf arrays            ITERATE (vector<CLayoutFeat::TFeatList>, leaf_iter, leaves) {                ITERATE (CLayoutFeat::TFeatList, iter, *leaf_iter) {                    bool selected = x_IsObjectSelected(iter->GetPointer());                    if (m_RenderPolicy->ProcessObject(pane, *iter, temp_row,                                                      mode, selected)) {                        return *iter;                    }                    temp_row += m_RenderPolicy->GetRowHeight(pane, *iter, selected);                }            }  // leaf arrays            new_row = max (new_row, temp_row);        } // top features        row = new_row;    } // row iterator    switch (mode) {    case IPolicy::eDrawObjectLines:    case IPolicy::eDrawObjectQuads:    case IPolicy::eDrawObjectGrid:        glEnd();        break;    case IPolicy::eCalcObjectRows:        m_RowCount = row;  // save number of rows        break;    default:        break;    }    return NULL;}//// recursive function to extract a set of paths from the root of a given tree// to each of the leaves.//void CFeaturesPanelIR::x_DecomposeToLeaves(const CLayoutFeat* feat,                                           vector<CLayoutFeat::TFeatList>& leaves){    CLayoutFeat::TFeatList leaf;    x_DecomposeToLeaves(feat, leaves, leaf);}void CFeaturesPanelIR::x_DecomposeToLeaves(const CLayoutFeat* feat,                                           vector<CLayoutFeat::TFeatList>& leaves,                                           CLayoutFeat::TFeatList& leaf){    leaf.push_back(CRef<CLayoutFeat>(const_cast<CLayoutFeat*>(feat)));    if (feat->GetChildren().size()) {        ITERATE (CLayoutFeat::TFeatList, iter, feat->GetChildren()) {            CLayoutFeat::TFeatList sub_leaf(leaf);            x_DecomposeToLeaves(*iter, leaves, sub_leaf);        }    } else {        leaves.push_back(leaf);    }}void CFeaturesPanelIR::x_DrawXGrid(CGlPane& pane) const{    if ( x_IsSeqLettersFit(pane) ) {        const TModelRect& rc = pane.GetVisibleRect();        m_ConfigSettings->GetElementColor(                                          CSeqGraphicColorConfig::eGridVertical);        TModelUnit x = rc.Left() - (int)(rc.Left()) % 3;        TModelUnit x_end = rc.Right() + (int)(rc.Right()) % 3;        for (;  x <= x_end;  x += 3)         {            glVertex2d(x - pane.GetOffsetX(), rc.Top()    - pane.GetOffsetY() );            glVertex2d(x - pane.GetOffsetX(), rc.Bottom() - pane.GetOffsetY() );        }    }}// Selectionsvoid CFeaturesPanelIR::SetSelectedObjects(TConstObjects* objs){    m_SelectedObjects = objs;}bool CFeaturesPanelIR::x_IsObjectSelected(const CLayoutObject* obj) const{    // Make sure we iterate through all selected objects    bool found = false;    ITERATE (TConstObjects, iter, *m_SelectedObjects) {        try {            const CObject* tmp = *iter;            if (obj->HasObject(tmp))                found = true;        }        catch (...) {        }    }    return found;}END_NCBI_SCOPE/* * =========================================================================== * $Log: features_panel_ir.cpp,v $ * Revision 1000.3  2004/06/01 21:12:35  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.19 * * Revision 1.19  2004/05/21 22:27:55  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.18  2004/05/14 15:57:11  lebedev * Optional argument to specify the type of title/tooltip added * * Revision 1.17  2004/04/22 18:15:57  lebedev * Slightly changed how the layout objects get selected * * Revision 1.16  2004/04/16 14:52:19  dicuccio * Pass params as raw pointers, not CRef<> * * Revision 1.15  2004/04/15 13:02:13  lebedev * HitTesting for LayoutObjects changed * * Revision 1.14  2004/04/14 11:25:48  lebedev * Added rendering of Mate Pairs. * * Revision 1.13  2004/04/06 13:43:07  dicuccio * Formatting changes.  Folded long lines, removed trailing white space * * Revision 1.12  2004/03/31 16:08:58  lebedev * Methods to get HTML active areas added. * * Revision 1.11  2004/03/30 13:58:37  lebedev * Use elements colors from configuration instead of setting colors directly. * * Revision 1.10  2004/03/23 12:33:56  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.9  2004/03/11 17:53:06  dicuccio * Deprecated typedefs TPosition, TDimension, TIndex, TColor.  Use TSeqRange * instead of TRange * * Revision 1.8  2004/02/24 14:45:25  lebedev * Better implementation of main rendering loop. Code clean-up. * * Revision 1.7  2004/02/13 18:14:33  lebedev * Make use of new ILayoutPolicy interface * * Revision 1.6  2004/01/27 16:14:19  lebedev * Changed stored selection from CLayoutObject to CObject * * Revision 1.5  2004/01/20 19:42:44  rsmith * make SetConfig, SetPolicy and SetHandle safer. * * Revision 1.4  2004/01/16 13:40:15  lebedev * Tooltips added * * Revision 1.3  2004/01/05 19:13:53  dicuccio * Use a more optimal mechanism for rendering grid * * Revision 1.2  2003/12/31 20:30:21  dicuccio * Wrap call to CLayoutObject::GetObject() in try/catch to avoide a catastrophic * exception * * Revision 1.1  2003/12/22 12:58:59  lebedev * Files renamed * * Revision 1.21  2003/12/16 18:56:38  lebedev * Introduced Rendering Policies for feature panels * * Revision 1.20  2003/12/09 12:32:43  lebedev * Trim gene names in overview mode to fit in columns.  * Option to show feature names in detailed mode * * Revision 1.19  2003/11/17 21:05:39  yazhuk * Updated CGlBitmapFont::Truncate() calls to conform with the new argument set * * Revision 1.18  2003/11/13 19:11:06  lebedev * Objects selection reorganized. One row ofset bug in selection fixed * * Revision 1.17  2003/11/13 14:26:14  lebedev * Do not reverse the sequence for neg. strand CDSs (just complement) * * Revision 1.16  2003/11/10 18:47:07  ucko * Adjust for const-correctness. * * Revision 1.15  2003/11/10 17:01:38  lebedev * Display of SeqGraphs and named SeqAnnots added * * Revision 1.14  2003/11/04 17:50:00  dicuccio * Fixed compiler warning on MSVC * * Revision 1.13  2003/11/04 17:00:39  lebedev * Reverse and Compliment the sequence displayed under CDSs and Proteins on * negative strand * * Revision 1.12  2003/11/04 13:55:14  dicuccio * Fixed compiler warning on MSVC * * Revision 1.11  2003/10/30 13:21:59  lebedev * Display of master sequence under selected CDSs and Proteins added * * Revision 1.10  2003/10/28 19:01:43  dicuccio * Fixed compilation errors.  Pass CBioseq_Handle by const-ref and store as * value, not as pointer * * Revision 1.9  2003/10/28 15:29:07  lebedev * Use new configuration library * * Revision 1.8  2003/10/24 13:22:27  lebedev * Re-enable display of proteins * * Revision 1.7  2003/10/22 18:31:38  lebedev * Zoom that follows mouse added * * Revision 1.6  2003/10/21 12:59:51  lebedev * Rendering of alignments changed * * Revision 1.5  2003/10/20 16:31:24  lebedev * Offset IRenderable panels to bypass OpenGL matrices precision loss on * big sequences. * * Revision 1.4  2003/10/15 19:27:16  ucko * Fix test for the presence of a product to compile.... * * Revision 1.3  2003/10/15 18:26:55  dicuccio * Reformatted code.  Added '*' to indicate features with products * * Revision 1.2  2003/10/09 18:02:02  lebedev * Compilation error fixed * * Revision 1.1  2003/10/09 16:27:41  lebedev * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

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