seqgraphic_pane.cpp

来自「ncbi源码」· C++ 代码 · 共 993 行 · 第 1/2 页

CPP
993
字号
/* * =========================================================================== * PRODUCTION $Log: seqgraphic_pane.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 21:12:53  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.31 * PRODUCTION * =========================================================================== *//*  $Id: seqgraphic_pane.cpp,v 1000.2 2004/06/01 21:12:53 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 "seqgraphic_pane.hpp"#include <gui/utils/fltk_utils.hpp>#include <gui/objutils/obj_clipboard.hpp>#include <gui/widgets/seq_graphic/seqgraphic_conf.hpp>#include <gui/config/feat_config_list.hpp>#include <objmgr/util/feature.hpp>#include <util/regexp.hpp>#include <algorithm>#include <math.h>#include <FL/glut.H>#include <FL/fl_draw.H>BEGIN_NCBI_SCOPEconst TModelUnit kMouseZoomFactor = 25.0;   // per pixel of mouse movementCSeqGraphicPane::CSeqGraphicPane(int x, int y, int w, int h)    : CGlPaneWidgetChild(x, y, w, h, ""){    m_VisibleRangeChanged = false;    m_Renderer.Reset(new CSeqGraphicRenderer());        m_Event.StandardConfig();        // Register additional widget-specific states    // ZoomIn, ZoomOut and Lense Zoom:    m_Event.RegisterState(CGUIEvent::eInsZoomStateIn,                  0, 'i');    m_Event.RegisterState(CGUIEvent::eInsZoomStateOut, CGUIEvent::fShift, 'i');    m_Event.RegisterState(CGUIEvent::eLensZoomState,                   0, 'l');        /**    m_Event.RegisterState(eLensZoomState, 0, 'l');    m_Event.RegisterState(eZoomInState,      0, '+');    m_Event.RegisterState(eZoomOutState,     0, '-');    m_Event.RegisterState(eZoomInFullState,  0, '*');    m_Event.RegisterState(eZoomOutFullState, 0, '=');    **/    m_TimerActive = false;    //m_MouseScrollHandler.SetHost(static_cast<IMouseScrollHandlerHost*>(this));    //x_RegisterHandler(dynamic_cast<IEventHandler*>(&m_MouseScrollHandler), fScrollArea, &m_Renderer->GetFixedGlPane());    m_MouseZoomHandler.SetHost(static_cast<IMouseZoomHandlerHost*>(this));    x_RegisterHandler(dynamic_cast<IEventHandler*>(&m_MouseZoomHandler), fFeaturesArea, &m_Renderer->GetFeatGlPane());        m_SelHandler.SetHost(static_cast<ISelHandlerHost*>(this));    x_RegisterHandler(dynamic_cast<IEventHandler*>(&m_SelHandler), fSeqRulerArea, &m_Renderer->GetRulerGlPane());        m_Tooltip.EnableActiveMode(static_cast<ITooltipClient*>(this));    m_Tooltip.SetMode(CTooltip::eHideOnMove);}CSeqGraphicPane::~CSeqGraphicPane(){}void CSeqGraphicPane::SetDataSource(CSeqGraphicDataSource* ds){    TVPRect rc(0, 0, w() - 0, h() - 0);    m_Renderer->SetDataSource(rc, ds);    m_DS.Reset(ds);        m_SelHandler.ResetSelection(false);        invalidate();    redraw();}void CSeqGraphicPane::SetWidget(CSeqGraphicWidget* widget){    m_ParentWidget = widget;}// Set/Clear selectionvoid CSeqGraphicPane::SelectObject(const CObject* obj){    if (!obj) {        return;    }        m_LastSelObj.Reset(obj);        m_Renderer->SelectObject(obj);    redraw();}void CSeqGraphicPane::SelectSeqLoc(const CSeq_loc* loc){    TRangeColl r = TRangeColl( loc->GetTotalRange() );    m_SelHandler.SetSelection(r, false);    redraw();}void CSeqGraphicPane::ClearSelection(){    m_SelHandler.ResetSelection(false);    m_Renderer->ClearObjectSelection();        redraw();}// retrieve the selections from our rendererconst TConstObjects& CSeqGraphicPane::GetSelectedObjects(void) const{    return m_Renderer->GetSelectedObjects();}const CSeqGraphicPane::TRangeColl&CSeqGraphicPane::GetSelectedSeqRanges(void) const{    return m_SelHandler.GetSelection();}const CSeqGraphicDataSource* CSeqGraphicPane::GetDataSource(void) const{    return m_DS.GetPointer();}void CSeqGraphicPane::SetZoomX(float value){    m_Renderer->SetZoomX(value);    // indicate a visible range change    m_VisibleRangeChanged = true;    invalidate();    redraw();}int CSeqGraphicPane::SearchFeature(string pattern,        string feature, bool is_local){    m_SearchResults.clear();    m_SearchIndex = 0;            int (*pf)(int) = tolower;  // explicit cast to resolve the ambiguity        const TModelRect& rc = is_local ?                            m_Renderer->GetFeatGlPane().GetVisibleRect() :                            m_Renderer->GetFeatGlPane().GetModelLimitsRect();                                          TSeqRange range = TSeqRange(TSeqPos(rc.Left()), TSeqPos(rc.Right()));        std::transform(pattern.begin(), pattern.end(),                    pattern.begin(), pf);    CRegexp exp_pattern(pattern);        int type, sub_type;    GetFeatConfigList()->GetTypeSubType(feature, type, sub_type);    SAnnotSelector selector =        CSeqUtils::GetAnnotSelector        (static_cast<CSeqFeatData::ESubtype>(sub_type));        CLayoutFeat::TFeatList feats;    CSeqUtils::GetFeatures(m_DS->GetBioseqHandle(), range, selector, feats);    NON_CONST_ITERATE (CLayoutFeat::TFeatList, iter, feats) {        CLayoutFeat& feat = **iter;                string label;        feature::GetLabel(feat.GetFeature(), &label,                           feature::eContent,                          &m_DS->GetBioseqHandle().GetScope());                                  std::transform(label.begin(), label.end(), label.begin(), pf);                if (exp_pattern.GetMatch(label.c_str()).length() > 0) {            m_SearchResults.push_back(*iter);        }    }    if (m_SearchResults.size() > 0)         m_Renderer->ZoomOnObject(m_SearchResults[m_SearchIndex]);  // actual zoom            invalidate();    redraw();        return m_SearchResults.size();}int CSeqGraphicPane::SearchFeatureNext(){   if (m_SearchIndex < m_SearchResults.size() - 1) {        ++m_SearchIndex;        m_Renderer->ZoomOnObject(m_SearchResults[m_SearchIndex]);                invalidate();        redraw();    }    return m_SearchIndex;}int CSeqGraphicPane::SearchFeaturePrev(){    if (m_SearchIndex > 0) {        m_SearchIndex--;        m_Renderer->ZoomOnObject(m_SearchResults[m_SearchIndex]);                invalidate();        redraw();    }    return m_SearchIndex;}void CSeqGraphicPane::x_AdjustScrollBars(void){    Fl_Scrollbar* scrollX = (Fl_Scrollbar*)(parent()->parent()->child(0));    Fl_Scrollbar* scrollY = (Fl_Scrollbar*)(parent()->parent()->child(1));    scrollX->linesize(1);    scrollY->linesize(1);        const TModelRect& rcV = m_Renderer->GetFeatGlPane().GetVisibleRect();    const TModelRect& rcM = m_Renderer->GetFeatGlPane().GetModelLimitsRect();        scrollX->value(int(rcV.Left()), int(rcV.Width()), 0, int(rcM.Width()-1));                       if (m_Renderer->GetFeatGlPane().NeedsScrollX()) {        scrollX->show();    } else {        scrollX->hide();    }        scrollX->linesize( int(m_Renderer->GetScrollLineSize()) );    scrollY->value(int(rcV.Top()), abs(int(rcV.Height())),                    0, abs(int(rcM.Height())) );    /*if (m_Renderer->NeedsScrollY()) {        scrollY->show();    } else {        scrollY->hide();    }*/}void CSeqGraphicPane::x_AdjustZoomSlider(void){    Fl_Value_Slider* m_SlideZoomX =        (Fl_Value_Slider*)(parent()->parent()->child(2));            m_SlideZoomX->range(0, 1);    m_SlideZoomX->value(m_Renderer->GetZoomX());    m_SlideZoomX->step(0.001);}void CSeqGraphicPane::x_Render(){    if (!valid()) {        TVPRect rc(0, 0, w() - 0, h() - 0);        m_Renderer->Resize(rc);    }        glClearColor(1, 1, 1, 0);    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    if ( !m_DS ) {        return;    }        m_Renderer->Render();        // ZoomHandler indicator and Linear selection    glEnable(GL_BLEND);    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);    m_MouseZoomHandler.Render(m_Renderer->GetFeatGlPane());        //m_MouseScrollHandler.Render(m_Renderer->GetFixedGlPane());    // draw linear selection    CGlColor m_SelGray      (0.5f, 0.5f, 0.5f, 0.20f);    CGlColor m_SelBlue      (0.0f, 0.0f, 0.5f, 0.50f);    CGlColor m_SelBlueBorder(0.0f, 0.0f, 0.6f, 0.55f);                    // draw linear selection    m_SelHandler.SetColor(CLinearSelHandler::eSelection, m_SelBlue);    m_SelHandler.SetColor(CLinearSelHandler::ePasssiveSelection, m_SelBlueBorder);    m_SelHandler.Render(m_Renderer->GetRulerGlPane());        m_SelHandler.SetColor(CLinearSelHandler::ePasssiveSelection, m_SelGray);        // Linear selection handler does not honor EnableOffset flags yet    // disable offsets before drawing and reenable them after    m_Renderer->GetFeatGlPane().EnableOffset(false);    m_SelHandler.Render(m_Renderer->GetFeatGlPane(), CLinearSelHandler::ePassiveState);    m_Renderer->GetFeatGlPane().EnableOffset(true);        glDisable(GL_BLEND);        x_AdjustScrollBars();    x_AdjustZoomSlider();}int CSeqGraphicPane::handle(int event){    int ev_x = Fl::event_x();    int ev_y = Fl::event_y();    CGUIEvent::EGUIState  state  = m_Event.GetGUIState();    CGUIEvent::EGUISignal signal = m_Event.GetGUISignal();        switch (state) {    case CGUIEvent::eCopyState:        x_Handle_ClipboardCopy();        break;    case CGUIEvent::eCutState:    case CGUIEvent::ePasteState:    case CGUIEvent::eUndoState:    case CGUIEvent::eRedoState:        // editing not yet supported        break;    case CGUIEvent::eSelectState:    case CGUIEvent::eSelectIncState:        if (signal == CGUIEvent::eSelectSignal) {            const CLayoutObject* obj = m_Renderer->HitTest(ev_x, h()-ev_y);            // Distinguish selection and incremental selection            if (state == CGUIEvent::eSelectState) {                m_Renderer->ClearObjectSelection();            }            // Save last clicked objects            if (obj) {                const CObject* sel_obj = obj->GetObject(                         TSeqPos(m_Renderer->GetFeatGlPane().UnProjectX(ev_x)) );                                m_LastSelLayoutObj.Reset(obj);                SelectObject(sel_obj);            }            // double click zooms on the feature/alignment/etc            if (Fl::event_clicks()) {                m_Renderer->ZoomOnObject(obj);            }                // ping the callback on selection            if (obj) {                parent()->parent()->do_callback(parent()->parent());            }            redraw();        }        break;    case CGUIEvent::ePopupState:        break;            case CGUIEvent::eInsZoomStateIn:    case CGUIEvent::eInsZoomStateOut:        m_ZoomingIn = state == CGUIEvent::eInsZoomStateIn;        x_Handle_TimerZoom();                break;            case CGUIEvent::eLensZoomState:        x_Handle_LensZoom();        break;            default:        break;    }    // pass events to the tooltip object    m_Tooltip.Handle(event);        return CGlPaneWidgetChild::handle(event);}// called by Fl::add_timeoutvoid s_CSeqGraphicPane_ZoomTimer(void* parent){    CSeqGraphicPane* pane = (CSeqGraphicPane*)parent;    if (pane->m_TimerActive) { // still need zoom?        CGlPane& ref_pane = pane->m_Renderer->GetFeatGlPane();        TModelPoint ref_point = ref_pane.UnProject(pane->m_TimerX,                                 pane->MZHH_GetVPPosByY(pane->m_TimerY));        TModelUnit scaleX = ref_pane.GetScaleX();        TModelUnit scaleY = ref_pane.GetScaleY();        // Zoom In or Zoom Out        scaleX = pane->m_ZoomingIn ? scaleX / 1.5f : scaleX * 1.5f;                pane->m_Renderer->SetScaleRef(scaleX, scaleY, ref_point);            pane->m_VisibleRangeChanged = true;  // visible range changed            pane->redraw();        if (pane->m_TimerActive) // if still active            Fl::add_timeout(0.25, s_CSeqGraphicPane_ZoomTimer, parent);    }}void CSeqGraphicPane::x_Handle_TimerZoom(){    switch(m_Event.GetFLTKEvent()) {    case FL_PUSH:        m_TimerActive = true;        m_TimerX = Fl::event_x();        m_TimerY = h() - Fl::event_y();            s_CSeqGraphicPane_ZoomTimer(this);        break;    case FL_DRAG:        m_TimerActive = false;        break;            case FL_RELEASE:        m_TimerActive = false;        break;    default:        break;    } // switch (FLTK event) }void CSeqGraphicPane::x_Handle_LensZoom(){    // it will make sence to move the Lens Zoom into separate handler    // like mouse_scroll_handler    switch(m_Event.GetFLTKEvent()) {

⌨️ 快捷键说明

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