phylo_tree_widget.cpp
来自「ncbi源码」· C++ 代码 · 共 383 行
CPP
383 行
/* * =========================================================================== * PRODUCTION $Log: phylo_tree_widget.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/02 20:24:39 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.17 * PRODUCTION * =========================================================================== *//* $Id: phylo_tree_widget.cpp,v 1000.2 2004/06/02 20:24:39 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 <gui/opengl/glfont.hpp>#include <gui/graph/igraph_utils.hpp>#include <gui/widgets/phylo_tree/phylo_tree_widget.hpp>#include <gui/widgets/fl/menu.hpp>#include <gui/widgets/fl/menu_window.hpp>#include <gui/types.hpp>#include <gui/utils/view_event.hpp>#include <list>#include <FL/Fl.H>BEGIN_NCBI_SCOPEUSING_SCOPE(ncbi::objects);/////////////////////////////////////////////////////////////////////////////////// class CPhyloTreeWidgetCPhyloTreeWidget::CPhyloTreeWidget(int PosX, int PosY, int Width, int Height, const char* label): CGlPaneWidget(PosX, PosY, Width, Height, label), m_pDataSource(NULL), m_pMatrixPane(NULL), m_ScoreIndex(-1){ // setup Port m_Port.SetAdjustmentPolicy(CGlPane::fAdjustAll, CGlPane::fAdjustAll); m_Port.SetMinScaleX(1 / 30.0); m_Port.SetMinScaleY(1 / 30.0); m_Port.SetOriginType(CGlPane::eOriginLeft, CGlPane::eOriginBottom); m_Port.EnableZoom(true, true);}CPhyloTreeWidget::~CPhyloTreeWidget(){}BEGIN_CMD_MAP(CPhyloTreeWidget, CGlPaneWidget) ON_COMMAND(eCmdSetGraphType1, &CPhyloTreeWidget::OnSetGraphType1) ON_COMMAND(eCmdSetGraphType2, &CPhyloTreeWidget::OnSetGraphType2) ON_COMMAND(eCmdSetGraphType3, &CPhyloTreeWidget::OnSetGraphType3) ON_COMMAND(eCmdSetGraphType4, &CPhyloTreeWidget::OnSetGraphType4) ON_COMMAND(eCmdUseDistances, &CPhyloTreeWidget::OnUseDistances) ON_UPDATE_COMMAND_UI(eCmdUseDistances, &CPhyloTreeWidget::OnUpdateUseDistances) ON_UPDATE_COMMAND_UI(eCmdSetGraphType1, &CPhyloTreeWidget::OnUpdateSetGraphType1) ON_UPDATE_COMMAND_UI(eCmdSetGraphType2, &CPhyloTreeWidget::OnUpdateSetGraphType2) ON_UPDATE_COMMAND_UI(eCmdSetGraphType3, &CPhyloTreeWidget::OnUpdateSetGraphType3) ON_UPDATE_COMMAND_UI(eCmdSetGraphType4, &CPhyloTreeWidget::OnUpdateSetGraphType4)END_CMD_MAP()// Events mapEVENT_MAP_RX_BEGIN(CPhyloTreeWidget) EVENT_ACCEPT(CViewEvent::eTreeSelectionChanged, OnSelChangedEvent) EVENT_ACCEPT(CViewEvent::eSelectionChanged, OnSelChangedEvent)EVENT_MAP_RX_ENDvoid CPhyloTreeWidget::OnShowPopup(){ CMenuItem * pRootItem = new CMenuItem(CMenuItem::eSubmenu); pRootItem->AddSubItem("Zoom In", eCmdZoomIn); pRootItem->AddSubItem("Zoom Out", eCmdZoomOut); pRootItem->AddSubItem("Zoom All", eCmdZoomAll); (auto_ptr<CPopupMenu1>(new CPopupMenu1(Fl::event_x_root(), Fl::event_y_root(), pRootItem, this)))->Popup(); }void CPhyloTreeWidget::x_CreatePane(){ m_pMatrixPane = new CPhyloTreePane(0, 0, 0, 0); m_pMatrixPane->AddRenderer(new CPhyloRectCladogram()); m_pMatrixPane->AddRenderer(new CPhyloSlatedCladogram()); m_pMatrixPane->AddRenderer(new CPhyloRadial()); m_pMatrixPane->AddRenderer(new CPhyloForce()); m_pMatrixPane->SetWidget(this);}CGlPaneWidgetChild* CPhyloTreeWidget::x_GetPane(){ return static_cast<CGlPaneWidgetChild*>(m_pMatrixPane);}void CPhyloTreeWidget::x_SetPortLimits(){ m_Port.SetModelLimitsRect(TModelRect(0,0, IPhyloTreeRenderer::GetDimX(), IPhyloTreeRenderer::GetDimY())); }void CPhyloTreeWidget::SetPortLimits(const TModelRect & rect){ m_Port.SetModelLimitsRect(rect); m_Port.ZoomAll(); }void CPhyloTreeWidget::SetDataSource(CPhyloTreeDataSource* p_ds){ m_pDataSource = p_ds; x_Update(); m_pMatrixPane->redraw(); }CPhyloTreeDataSource* CPhyloTreeWidget::GetDS(void){ return m_pDataSource; }const CGlPane& CPhyloTreeWidget::GetPort(void) const{ return x_GetPort();}void CPhyloTreeWidget::OnSetEqualScale(){ TModelUnit scale = min(m_Port.GetScaleX(), m_Port.GetScaleY()); m_Port.SetScale(scale, scale); x_UpdateOnZoom();}void CPhyloTreeWidget::OnSetGraphType1(){ SetCurrRenderer(0); }void CPhyloTreeWidget::OnSetGraphType2(){ SetCurrRenderer(1); }void CPhyloTreeWidget::OnSetGraphType3(){ SetCurrRenderer(2); }void CPhyloTreeWidget::OnSetGraphType4(){ SetCurrRenderer(3); }void CPhyloTreeWidget::OnUpdateSetGraphType1(ICmdUI* pCmdUI){ pCmdUI->SetRadio(m_pMatrixPane->GetCurrRendererIdx()==0); }void CPhyloTreeWidget::OnUpdateSetGraphType2(ICmdUI* pCmdUI){ pCmdUI->SetRadio(m_pMatrixPane->GetCurrRendererIdx()==1);}void CPhyloTreeWidget::OnUpdateSetGraphType3(ICmdUI* pCmdUI){ pCmdUI->SetRadio(m_pMatrixPane->GetCurrRendererIdx()==2);}void CPhyloTreeWidget::OnUpdateSetGraphType4(ICmdUI* pCmdUI){ pCmdUI->SetRadio(m_pMatrixPane->GetCurrRendererIdx()==3);}void CPhyloTreeWidget::OnUseDistances(){ m_pMatrixPane->take_focus(); vector <IPhyloTreeRenderer*> vRend = m_pMatrixPane->GetRenderers(); for (vector <IPhyloTreeRenderer*>::iterator it=vRend.begin(); it!=vRend.end(); it++){ (*it)->SetDistRendering(!(*it)->GetDistRendering()); } x_Update(); }void CPhyloTreeWidget::OnUpdateUseDistances(ICmdUI* pCmdUI){ vector <IPhyloTreeRenderer*> vRend = m_pMatrixPane->GetRenderers(); if (vRend.size()>0){ pCmdUI->SetCheck((*vRend.begin())->GetDistRendering()); }}void CPhyloTreeWidget::x_Update(){ x_SetPortLimits(); m_Port.ZoomAll(); x_UpdatePane(); x_UpdateScrollbars(); x_RedrawControls();}void CPhyloTreeWidget::x_UpdatePane(){ m_pMatrixPane->Update();}void CPhyloTreeWidget::OnSetScaleXY(TModelUnit scale_x, const TModelPoint& point){ double ratio = m_Port.GetScaleY()/m_Port.GetScaleX(); m_Port.SetScaleRefPoint(scale_x, scale_x * ratio, point); x_UpdateOnZoom();}void CPhyloTreeWidget::x_UpdateScrollbars(){ TModelRect rcAll = m_Port.GetModelLimitsRect(); TModelRect rcVisible = m_Port.GetVisibleRect(); if (m_Port.NeedsScrollX()) { m_pScrollX->value((int) rcVisible.Left(), (int) rcVisible.Width(), (int) rcAll.Left(), (int) rcAll.Width()); } else { m_pScrollX->value(0, 0, 0, 0); } if (m_Port.NeedsScrollY()) { m_pScrollY->value((int) (rcAll.Top() - rcVisible.Top()), (int) rcVisible.Height(), (int) rcAll.Bottom(), (int) rcAll.Height()); } else { m_pScrollY->value(0, 0, 0, 0); }}void CPhyloTreeWidget::x_OnScrollX(){ int V = m_pScrollX->value(); double dX = V - m_Port.GetVisibleRect().Left(); m_Port.Scroll(dX, 0); x_RedrawControls(); //###}void CPhyloTreeWidget::x_OnScrollY(){ int V = m_pScrollY->value(); TModelRect rcAll = m_Port.GetModelLimitsRect(); double dY = rcAll.Top() - V - m_Port.GetVisibleRect().Top(); m_Port.Scroll(0, dY); x_RedrawControls();}void CPhyloTreeWidget::SetCurrRenderer(Int4 idx){ m_pMatrixPane->take_focus(); m_pMatrixPane->SetCurrRendererIdx(idx); x_Update(); }vector<string> CPhyloTreeWidget::GetRenderersNames(void){ vector<string> retValue; int size = m_pMatrixPane->GetRenderers().size(); for (Int4 i=0; i<size; i++) retValue.push_back(m_pMatrixPane->GetRenderers()[i]->GetDescription()); return retValue;}void CPhyloTreeWidget :: SendSelChangedEvent(){ CObjectFor< vector<int> > cobj; cobj = m_pDataSource->GetSelectedIds(); CObjectFor< CPhyloTreeDataSource::TIds > csid; csid = m_pDataSource->ConvertId2SeqId(m_pDataSource->GetSelectedIds()); // fire external event FireEvent(CViewEvent::CreateEvent(CViewEvent::eSelectionChanged, CViewEvent::eEventViews, CViewEvent::TEventObject(&csid), this)); // fire internal event FireEvent(CViewEvent::CreateEvent(CViewEvent::eTreeSelectionChanged, CViewEvent::eEventViews, CViewEvent::TEventObject(&cobj), this)); }void CPhyloTreeWidget :: OnSelChangedEvent(CViewEvent::TEventObject obj){ CObjectFor< vector<int> > * cobj = dynamic_cast< CObjectFor< vector<int> > *>(obj.GetPointer()); CObjectFor< CPhyloTreeDataSource::TIds > * csid = dynamic_cast< CObjectFor< CPhyloTreeDataSource::TIds > *>(obj.GetPointer()); if (cobj){ m_pMatrixPane->SetSelectedIDs(*cobj); } else if (csid) { m_pMatrixPane->SetSelectedIDs(m_pDataSource->ConvertSeqId2Id(*csid)); }} END_NCBI_SCOPE/* * =========================================================================== * $Log: phylo_tree_widget.cpp,v $ * Revision 1000.2 2004/06/02 20:24:39 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.17 * * Revision 1.17 2004/06/02 16:39:28 tereshko * Fixed selections and popup behavior under windows * * Revision 1.16 2004/05/21 22:27:54 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.15 2004/05/20 15:30:18 tereshko * Implemented support for new updates-driven menu * * Revision 1.14 2004/05/11 20:53:12 tereshko * Work in progress * * Revision 1.13 2004/05/06 19:42:05 tereshko * Added force layout * * Revision 1.12 2004/04/28 19:27:10 tereshko * Added support for distances rendering * * Revision 1.11 2004/04/20 21:57:19 tereshko * Major rendering, labeling and performance improvements * * Revision 1.10 2004/04/16 16:40:13 dicuccio * Use typedef instead of raw STL container for IDs * * Revision 1.9 2004/04/13 20:28:53 tereshko * Numerous renderers improvements * * Revision 1.8 2004/04/07 13:09:06 dicuccio * Formatting changes. Call redraw() on pane widget after updates. * * Revision 1.7 2004/04/02 16:21:24 yazhuk * Replaced vector<CRef<>> with vector<CConstRef<>> * * Revision 1.6 2004/03/31 17:54:07 tereshko * Changed selection broadcast for internal nodes * * Revision 1.5 2004/03/30 17:11:44 tereshko * Added support for events broadcasting * * Revision 1.4 2004/03/02 18:29:38 tereshko * Added radial tree layout * * Revision 1.3 2004/02/18 15:10:42 tereshko * Added renderer switching handle * * Revision 1.2 2004/02/13 21:18:58 tereshko * Updated to implement new interface functions * * Revision 1.1 2004/02/13 17:05:16 tereshko * Phylogenetic Tree Widget initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?