phylo_tree_pane.cpp

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

CPP
423
字号
/* * =========================================================================== * PRODUCTION $Log: phylo_tree_pane.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/02 20:24:34  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * PRODUCTION * =========================================================================== *//*  $Id: phylo_tree_pane.cpp,v 1000.2 2004/06/02 20:24:34 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:  Vladimir Tereshkov * * File Description: * */#include <ncbi_pch.hpp>#include <corelib/ncbistl.hpp>#include <corelib/ncbitime.hpp>#include <gui/widgets/phylo_tree/phylo_tree_widget.hpp>#include <gui/widgets/phylo_tree/phylo_tree_pane.hpp>#include <FL/Fl.H>BEGIN_NCBI_SCOPE#define AXIS_AREA_W 50#define AXIS_AREA_H 30CPhyloTreePane::CPhyloTreePane(int PosX, int PosY, int Width, int Height, const char* Label):   CGlPaneWidgetChild(PosX, PosY, Width, Height, Label),    m_BackColor(0.95f, 1.0f, 0.95f),    m_pTextFont(NULL),    m_pLblFont(NULL),    m_VertSelHandler(eVert),    m_BottomRuler(true),    m_TopRuler(true),    m_LeftRuler(false),    m_RightRuler(false),    m_CurrRenderer(-1){    m_Renderers.clear();    m_Gen.SetIntegerMode(true, true);    m_Gen.EnableOneBased(true, true);    m_Grid.EnableIntegerCentering(true);    m_pTextFont = new CGlBitmapFont(CGlBitmapFont::eHelvetica12);    m_pLblFont = new CGlBitmapFont(CGlBitmapFont::eHelvetica10);        m_Tooltip.EnableActiveMode(static_cast<ITooltipClient*>(this));    m_Tooltip.SetMode(CTooltip::eHideOnMove);       m_MouseZoomHandler.SetHost(static_cast<IMouseZoomHandlerHost*>(this));    x_RegisterHandler(dynamic_cast<IEventHandler*>(&m_MouseZoomHandler), fMatrixArea, &m_MatrixPane);    m_HorzSelHandler.SetHost(static_cast<ISelHandlerHost*>(this));    x_RegisterHandler(dynamic_cast<IEventHandler*>(&m_HorzSelHandler), fSubjectArea, &m_MatrixPane);    m_VertSelHandler.SetHost(static_cast<ISelHandlerHost*>(this));    x_RegisterHandler(dynamic_cast<IEventHandler*>(&m_VertSelHandler), fQueryArea, &m_MatrixPane);       m_Event.StandardConfig();            x_Layout();    x_SetupAxes();}void    CPhyloTreePane::x_SetupAxes(){    m_TopRuler.SetHorizontal(true, CRuler::eTop);    m_RightRuler.SetHorizontal(false, CRuler::eRight);}TVPPoint CPhyloTreePane::GetPortSize(void){    return TVPPoint(m_rcMatrix.Width(), m_rcMatrix.Height());}void CPhyloTreePane::SetWidget(CPhyloTreeWidget* pParent){    m_pParent = pParent;        if(m_pParent)   {        m_MatrixPane = x_GetParent()->GetPort();    }}void    CPhyloTreePane::resize(int x, int y, int w, int h){    CGlPaneWidgetChild::resize(x, y, w, h);    x_Layout();    m_MatrixPane.SetViewport(m_rcMatrix);    }void    CPhyloTreePane::x_Render(void){    glClearColor(m_BackColor.GetRed(), m_BackColor.GetGreen(), m_BackColor.GetBlue(), m_BackColor.GetAlpha());    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        // optional render background images        x_RenderContent();}int CPhyloTreePane::x_HandleMouseRelease(){           // popup event forwarding to renderer    if(m_Event.GetGUISignal() == CGUIEvent::ePopupSignal)   {                        IEventHandler * handle = dynamic_cast<IEventHandler*>(GetCurrRenderer());               handle->handle(m_Event, m_MatrixPane);                       }         return CGlPaneWidgetChild::x_HandleMouseRelease();    }void    CPhyloTreePane::x_OnShowPopup(){        x_GetParent()->OnShowPopup();}void    CPhyloTreePane::Update(){        _ASSERT(x_GetParent());            if (m_CurrRenderer>=0 && x_GetParent() && x_GetParent()->GetDS()) {        GetCurrRenderer()->Layout(*x_GetParent()->GetDS());                                // if size changed after calculation - correct it!        x_GetParent()->SetPortLimits(GetCurrRenderer()->GetRasterRect());                   }}const CPhyloTreePane::TRangeColl&     CPhyloTreePane::GetSubjectSelection() const{    return m_HorzSelHandler.GetSelection();}const CPhyloTreePane::TRangeColl&     CPhyloTreePane::GetQuerySelection() const{    return m_VertSelHandler.GetSelection();}void    CPhyloTreePane::x_Layout(void){       m_rcMatrix.Init(0,0,w(),h());}void    CPhyloTreePane::x_RenderContent(void){    if(x_GetParent()) {        const CGlPane& VP = x_GetParent()->GetPort();                // prepare CGlPanes        TModelRect rc_M = VP.GetModelLimitsRect();          m_MatrixPane.SetModelLimitsRect(rc_M);            TModelRect rc_V = VP.GetVisibleRect();                m_MatrixPane.SetVisibleRect(rc_V);        // now rendering        x_RenderAxisAndGrid(m_MatrixPane);        //x_RenderSeqPanes();        if (m_CurrRenderer>=0  && m_CurrRenderer<m_Renderers.size()){            m_Renderers[m_CurrRenderer]->Render(m_MatrixPane, *x_GetParent()->GetDS());        }       // x_RenderSelHandler(true, m_MatrixPane, CLinearSelHandler::eActiveState);                //x_RenderSelHandler(false, m_MatrixPane, CLinearSelHandler::eActiveState);        x_RenderMouseZoomHandler(m_MatrixPane);            }}void    CPhyloTreePane::x_RenderAxisAndGrid(CGlPane& gr_pane){    }void    CPhyloTreePane::x_RenderSeqPanes(){    }void    CPhyloTreePane::x_AdjsutToMasterPane(CGlPane& pane, bool b_model_x, bool b_model_y){    const CGlPane& VP = x_GetParent()->GetPort();                TModelRect rc_vis = VP.GetVisibleRect();    TModelRect rc_lim = VP.GetModelLimitsRect();      // assuming that Viewport in the pane has been set properly    if(! b_model_x) { // adjust horz range to represent pixels        int max_x = pane.GetViewport().Width() - 1;        rc_lim.SetHorz(0, max_x);        rc_vis.SetHorz(0, max_x);    }        if(! b_model_y) { // adjust vert range to represent pixels        int max_y = pane.GetViewport().Height() - 1;        rc_lim.SetVert(0, max_y);        rc_vis.SetVert(0, max_y);    }    pane.SetModelLimitsRect(rc_lim);        pane.SetVisibleRect(rc_vis);}int     CPhyloTreePane::x_GetAreaByMousePos(){    int vp_x = Fl::event_x();    int vp_y = h() - Fl::event_y();    if(m_rcMatrix.PtInRect(vp_x, vp_y)) {        return fMatrixArea;    } else if(m_rcBottomSeq.PtInRect(vp_x, vp_y)) {        return fSubjectArea;    } else if(m_rcLeftSeq.PtInRect(vp_x, vp_y)) {        return fQueryArea;    }    return fOther;}void    CPhyloTreePane::x_RenderMouseZoomHandler(CGlPane& pane){    glEnable(GL_BLEND);    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);    m_MouseZoomHandler.Render(pane);    glDisable(GL_BLEND);}void    CPhyloTreePane::x_RenderSelHandler(bool b_horz, CGlPane& pane, CLinearSelHandler::ERenderingOption option){    glEnable(GL_BLEND);    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);    CLinearSelHandler& handler = b_horz ? m_HorzSelHandler : m_VertSelHandler;    handler.Render(pane, option);    glDisable(GL_BLEND);        }/////////////////////////////////////////////////////////////////////////////////// IAlnMarkHandlerHost implementationTModelUnit  CPhyloTreePane::MZHH_GetScale(EScaleType type){    const CGlPane& VP = x_GetParent()->GetPort();    switch(type)    {    case eCurrent:   return VP.GetScaleX();    case eMin: return VP.GetMinScaleX();    case eMax: return VP.GetZoomAllScaleX();    default: _ASSERT(false); return -1;    }}void    CPhyloTreePane::MZHH_SetScale(TModelUnit scale, const TModelPoint& point) {    x_GetParent()->OnSetScaleXY(scale, point);    }void     CPhyloTreePane::MZHH_ZoomRect(const TModelRect& rc){    x_GetParent()->ZoomRect(rc);}void     CPhyloTreePane::MZHH_Scroll(TModelUnit d_x, TModelUnit d_y){    x_GetParent()->Scroll(d_x, d_y);}TVPUnit  CPhyloTreePane::MZHH_GetVPPosByY(int y) const{    return h() - 1  - y;}void    CPhyloTreePane::MZHH_Redraw(void){    redraw();}TVPUnit  CPhyloTreePane::HMGH_GetVPPosByY(int y) const{    return h() - 1  - y;}void    CPhyloTreePane::HMGH_Redraw(void){        redraw();}/////////////////////////////////////////////////////////////////////////////////// ISelHandlerHost implementationvoid CPhyloTreePane::SHH_Redraw(){    redraw();}TModelUnit  CPhyloTreePane::SHH_GetModelByWindow(int z, EOrientation orient){    switch(orient)  {    case eHorz: return m_MatrixPane.UnProjectX(z);    case eVert: return m_MatrixPane.UnProjectY(h() - z);    default:    _ASSERT(false); return -1;    }}TVPUnit     CPhyloTreePane::SHH_GetWindowByModel(TModelUnit z, EOrientation orient){    switch(orient)  {    case eHorz: return m_MatrixPane.ProjectX(z);    case eVert: return h() - m_MatrixPane.ProjectY(z);    default:    _ASSERT(false); return -1;    }}void CPhyloTreePane::AddRenderer(IPhyloTreeRenderer * renderer){    renderer->SetFont(m_pLblFont);    m_Renderers.push_back(renderer);        renderer->SetHost(static_cast<IPhyloTreeRendererHost*>(this));    if (m_CurrRenderer<0) SetCurrRendererIdx(0);     }void CPhyloTreePane::SetCurrRendererIdx(Int4 idx){       if (m_CurrRenderer != idx) {        x_UnregisterHandler(dynamic_cast<IEventHandler*>(GetCurrRenderer()));                m_CurrRenderer = idx;         x_RegisterHandler(dynamic_cast<IEventHandler*>(GetCurrRenderer()), fMatrixArea, &m_MatrixPane);        }}int CPhyloTreePane::handle(int event){        m_Tooltip.Handle(event);    return CGlPaneWidgetChild::handle(event);}bool CPhyloTreePane::TC_NeedTooltip(int x, int y){    return GetCurrRenderer()->TC_NeedTooltip(x, y);    }string  CPhyloTreePane::TC_GetTooltip(int& x, int& y, int& w, int& h){    return GetCurrRenderer()->TC_GetTooltip(x, y, w, h);    }void  CPhyloTreePane::FireCBEvent(void){    m_pParent->SendSelChangedEvent();}               END_NCBI_SCOPE/* * =========================================================================== * $Log: phylo_tree_pane.cpp,v $ * Revision 1000.2  2004/06/02 20:24:34  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * * Revision 1.9  2004/06/02 16:39:28  tereshko * Fixed selections and popup behavior under windows * * Revision 1.8  2004/05/21 22:27:54  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.7  2004/04/28 19:27:10  tereshko * Added support for distances rendering * * Revision 1.6  2004/04/13 20:28:53  tereshko * Numerous renderers improvements * * Revision 1.5  2004/03/30 17:11:44  tereshko * Added support for events broadcasting * * Revision 1.4  2004/03/03 21:42:06  tereshko * Added tooltips support * * Revision 1.3  2004/03/02 18:29:37  tereshko * Added radial tree layout * * Revision 1.2  2004/02/13 21:18:58  tereshko * Updated to implement new interface functions * * Revision 1.1  2004/02/13 17:05:05  tereshko * Phylogenetic Tree Widget initial revision * * =========================================================================== */

⌨️ 快捷键说明

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