cross_aln_pane.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:12k
- /*
- * ===========================================================================
- * PRODUCTION $Log: cross_aln_pane.cpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 21:06:28 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: cross_aln_pane.cpp,v 1000.2 2004/06/01 21:06:28 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 "cross_aln_pane.hpp"
- #include <gui/utils/fltk_utils.hpp>
- #include <gui/widgets/seq_graphic/seqgraphic_conf.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_SCOPE
- const TModelUnit kMouseZoomFactor = 25.0; // per pixel of mouse movement
- CCrossAlnPane::CCrossAlnPane(int x, int y, int w, int h, const char* label)
- : CGlCanvas2d(x, y, w, h, label)
- {
- m_ConfigSettings.Reset( new CSeqGraphicConfig(NULL) ); // init with default settings
-
- m_Renderer.Reset(new CCrossAlnRenderer());
- m_Renderer->SetConfig(m_ConfigSettings);
-
- m_Event.StandardConfig();
- m_MouseZoomHandler.SetHost(static_cast<IMouseZoomHandlerHost*>(this));
- m_Tooltip.EnableActiveMode(static_cast<ITooltipClient*>(this));
- m_Tooltip.SetMode(CTooltip::eHideOnMove);
- }
- CCrossAlnPane::~CCrossAlnPane()
- {
- }
- void CCrossAlnPane::SetDataSource(CCrossAlnDataSource* ds)
- {
- TVPRect rc(5, 5, w() - 5, h() - 5);
- m_Renderer->SetDataSource(rc, ds);
- m_DS.Reset(ds);
- Update();
-
- //invalidate();
- //redraw();
- }
- void CCrossAlnPane::SelectObject(const CObject* obj)
- {
- if (!obj) {
- return;
- }
- m_Renderer->SelectObject(obj);
- redraw();
- }
- void CCrossAlnPane::ClearSelection()
- {
- m_Renderer->ClearObjectSelection();
- }
- void CCrossAlnPane::Update()
- {
- m_Renderer->Update();
-
- invalidate();
- redraw();
- }
- // retrieve the selections from our renderer
- const TConstObjects& CCrossAlnPane::GetSelectedObjects(void) const
- {
- return m_Renderer->GetSelectedObjects();
- }
- void CCrossAlnPane::x_AdjustScrollBars(void)
- {
- Fl_Scrollbar* scrollX1 = (Fl_Scrollbar*)(parent()->parent()->child(0));
- Fl_Scrollbar* scrollY1 = (Fl_Scrollbar*)(parent()->parent()->child(1));
- Fl_Scrollbar* scrollX2 = (Fl_Scrollbar*)(parent()->parent()->child(2));
- Fl_Scrollbar* scrollY2 = (Fl_Scrollbar*)(parent()->parent()->child(3));
- scrollX1->linesize(1);
- scrollY1->linesize(1);
- scrollX2->linesize(1);
- scrollY2->linesize(1);
-
- const TModelRect& rcV1 = m_Renderer->GetFeatGlPane1().GetVisibleRect();
- const TModelRect& rcM1 = m_Renderer->GetFeatGlPane1().GetModelLimitsRect();
- const TModelRect& rcV2 = m_Renderer->GetFeatGlPane2().GetVisibleRect();
- const TModelRect& rcM2 = m_Renderer->GetFeatGlPane2().GetModelLimitsRect();
-
- scrollX1->value(int(rcV1.Left()), int(rcV1.Width()), 0, int(rcM1.Width()-1));
- scrollX2->value(int(rcV2.Left()), int(rcV2.Width()), 0, int(rcM2.Width()-1));
-
- if (m_Renderer->GetFeatGlPane1().NeedsScrollX()) {
- scrollX1->show();
- } else {
- scrollX1->hide();
- }
-
- if (m_Renderer->GetFeatGlPane2().NeedsScrollX()) {
- scrollX2->show();
- } else {
- scrollX2->hide();
- }
-
- scrollX1->linesize( int(m_Renderer->GetScrollLineSize1()) );
- scrollX1->linesize( int(m_Renderer->GetScrollLineSize2()) );
- scrollY1->value(int(rcV1.Bottom()), abs(int(rcV1.Height())),
- 0, abs(int(rcM1.Height())) );
- scrollY2->value(int(rcV2.Top()), abs(int(rcV2.Height())),
- 0, abs(int(rcM2.Height())) );
- }
- void CCrossAlnPane::draw()
- {
- if (!valid()) {
- TVPRect rc(5, 5, w() - 5, h() - 5);
- m_Renderer->resize(rc);
- }
-
- glClearColor(1, 1, 1, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- if ( !m_DS ) {
- return;
- }
-
- m_Renderer->draw();
- // ZoomHandler indicator
- if (m_HitPane) {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- m_MouseZoomHandler.Render(*m_HitPane);
- glDisable(GL_BLEND);
- }
-
- x_AdjustScrollBars();
-
- return;
- }
- int CCrossAlnPane::handle(int event)
- {
- // Handle focus events before everything else
- if (event == FL_FOCUS || event == FL_UNFOCUS) {
- redraw();
- return 1;
- }
- // Always acquire focus, otherwise keyboard events do not get into the panel
- if(event == FL_PUSH && Fl::focus() != static_cast<Fl_Widget*>(this)) {
- take_focus();
- }
-
- // Process event and feed it to ZoomHandler
- m_Event.OnFLTKEvent(event);
-
- if (m_HitPane) {
- m_MouseZoomHandler.handle(m_Event, *m_HitPane);
- }
- // pass events to the tooltip object
- m_Tooltip.Handle(event);
- CFltkEvent::EEvent ev = CFltkEvent::GetProcessedEvent();
-
- int ev_x = Fl::event_x();
- int ev_y = Fl::event_y();
- const CLayoutObject* obj = NULL;
- //
- // "typed" FLTK event handling
- //
- switch (ev) {
- case CFltkEvent::eSelectState:
- case CFltkEvent::eMultiSelectState:
- switch (event) {
- case FL_PUSH:
- m_HitPane = m_Renderer->PaneHitTest(ev_x, h()-ev_y);
- m_HitPanel = m_Renderer->PanelHitTest(ev_x, h()-ev_y);
-
- obj = m_Renderer->HitTest(ev_x, h()-ev_y);
-
- if (ev == CFltkEvent::eSelectState) {
- m_Renderer->ClearObjectSelection();
- }
-
- if (obj) {
- const CObject* sel_obj = obj->GetObject(
- TSeqPos(m_HitPane->UnProjectX(ev_x)) );
- SelectObject(sel_obj);
- }
-
- // double click zooms on the feature/alignment/etc
- if (Fl::event_clicks()) {
- m_Renderer->ZoomOnObject(obj);
- }
-
- // ping the callback on selection
- // sequence dragging pings the callback on release only
- parent()->parent()->do_callback();
-
- redraw();
- return 1;
- case FL_DRAG:
- return 1;
- case FL_RELEASE:
- m_HitPane = NULL;
- return 1;
- default:
- break;
- }
- break;
- default:
- break;
- }
- return CGlCanvas2d::handle(event);
- }
- // IMouseZoomHandlerHost implementation
- TModelUnit CCrossAlnPane::MZHH_GetScale(EScaleType type)
- {
- switch(type) {
- case eCurrent: return m_HitPane->GetScaleX();
- case eMin: return m_HitPane->GetMinScaleX();
- case eMax: return m_HitPane->GetZoomAllScaleX();
- default: _ASSERT(false); return -1;
- }
- }
- void CCrossAlnPane::MZHH_SetScale(TModelUnit scale, const TModelPoint& point)
- {
- if (m_HitPanel == CCrossAlnRenderer::eFeatures1) {
- m_Renderer->SetScaleRef1(scale, m_HitPane->GetScaleY(), point);
- } else if (m_HitPanel == CCrossAlnRenderer::eFeatures2) {
- m_Renderer->SetScaleRef2(scale, m_HitPane->GetScaleY(), point);
- } else if (m_HitPanel == CCrossAlnRenderer::eCross) {
- m_Renderer->SetScaleRefC(scale, m_HitPane->GetScaleY(), point);
- }
- redraw();
- }
- void CCrossAlnPane::MZHH_ZoomRect(const TModelRect& rc)
- {
- ZoomOnRange( TSeqRange(TSeqPos(rc.Left()), TSeqPos(rc.Right())) );
- }
- void CCrossAlnPane::MZHH_Scroll(TModelUnit d_x, TModelUnit d_y)
- {
- const TModelRect& rc1 = m_Renderer->GetFeatGlPane1().GetVisibleRect();
- const TModelRect& rc2 = m_Renderer->GetFeatGlPane2().GetVisibleRect();
-
- if (m_HitPanel == CCrossAlnRenderer::eFeatures1) {
- Scroll(rc1.Left() + d_x, 0, rc2.Left(), 0);
- } else {
- Scroll(rc1.Left(), 0, rc2.Left() + d_x, 0);
- }
- }
- TVPUnit CCrossAlnPane::MZHH_GetVPPosByY(int y) const
- {
- return h() - 1 - y;
- }
- void CCrossAlnPane::MZHH_Redraw(void)
- {
- redraw();
- }
- // IMouseZoomHandlerHost end
- ///////////////////////////////////////////////////////////////////////////////
- /// ITooltip Implementation
- bool CCrossAlnPane::TC_NeedTooltip(int x, int y)
- {
- m_Renderer->GetTooltip(x, h() - y, &m_TooltipText);
- return m_TooltipText.length() > 0;
- }
- string CCrossAlnPane::TC_GetTooltip(int& x, int& y, int& w, int& h)
- {
- return m_TooltipText;
- }
- // ITooltip end
- // --- Scrolling --------------------------------------------------
- void CCrossAlnPane::Scroll(TModelUnit x1, TModelUnit y1,
- TModelUnit x2, TModelUnit y2)
- {
- // "lock" both scrollbars if Shift key is pressed. That will scroll all panels
- // together (withing each panel limits)
- if (Fl::event_shift()) {
- const TModelRect& rc1 = m_Renderer->GetFeatGlPane1().GetVisibleRect();
- const TModelRect& rc2 = m_Renderer->GetFeatGlPane2().GetVisibleRect();
-
- // Find the scroll "delta"
- int dX1 = int(x1 - rc1.Left());
- int dX2 = int(x2 - rc2.Left());
-
- if (dX1 != 0) x2 = x2 + dX1;
- if (dX2 != 0) x1 = x1 + dX2;
- }
- m_Renderer->Scroll(x1, y1, x2, y2);
-
- redraw();
- }
- void CCrossAlnPane::ZoomOnRange(const TSeqRange& range)
- {
- m_Renderer->ZoomOnRange(range);
- }
- void CCrossAlnPane::ZoomOnAlignment()
- {
- m_Renderer->ZoomOnAlignment();
-
- redraw();
- }
- void CCrossAlnPane::FitToWindow(void)
- {
- m_Renderer->FitToWindow();
- }
- void CCrossAlnPane::ZoomToSequence(void)
- {
- m_Renderer->ZoomToSequence();
- }
- TSeqRange CCrossAlnPane::GetVisibleRange()
- {
- const TModelRect& rc = m_Renderer->GetFeatGlPane1().GetVisibleRect();
- return TSeqRange( TSeqPos(rc.Left()), TSeqPos(rc.Right()) );
- }
- void CCrossAlnPane::SetConfig(CRef<CSeqGraphicConfig> config)
- {
- m_ConfigSettings = config;
- m_Renderer->SetConfig(m_ConfigSettings);
- }
-
-
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: cross_aln_pane.cpp,v $
- * Revision 1000.2 2004/06/01 21:06:28 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8
- *
- * Revision 1.8 2004/05/21 22:27:52 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.7 2004/04/16 14:49:02 dicuccio
- * Use TConstObjects for handling object selections
- *
- * Revision 1.6 2004/04/16 12:28:26 lebedev
- * Use correct CGlPane to UnProject x coordinate for selection.
- *
- * Revision 1.5 2004/04/16 12:07:28 lebedev
- * Use new GetObject(TSeqPos) method is CLayoutObject
- *
- * Revision 1.4 2004/03/11 17:50:41 dicuccio
- * Updated typedefs: dropped TDimension, TPosition, TIndex, TColor; use TSeqRange
- * instead of TRange
- *
- * Revision 1.3 2004/01/27 16:20:40 lebedev
- * Changed stored selection from CLayoutObject to CObject
- *
- * Revision 1.2 2004/01/16 13:40:38 lebedev
- * Tooltips added
- *
- * Revision 1.1 2003/12/22 13:12:33 lebedev
- * Initial revision
- *
- * ===========================================================================
- */