view_feattable.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:16k
- /*
- * ===========================================================================
- * PRODUCTION $Log: view_feattable.cpp,v $
- * PRODUCTION Revision 1000.7 2004/06/01 21:01:26 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.37
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: view_feattable.cpp,v 1000.7 2004/06/01 21:01:26 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: Mike DiCuccio
- *
- * File Description:
- *
- */
- #include <ncbi_pch.hpp>
- #include "view_feattable.hpp"
- #include "visible_range_dlg.hpp"
- #include "preference_dlg.hpp"
- #include <gui/types.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/core/plugin_utils.hpp>
- #include <gui/core/version.hpp>
- #include <gui/plugin/PluginRequest.hpp>
- #include <gui/plugin/PluginCommand.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginValue.hpp>
- #include <objmgr/scope.hpp>
- #include <objmgr/seq_vector.hpp>
- #include <serial/typeinfo.hpp>
- #include <objmgr/util/sequence.hpp>
- BEGIN_NCBI_SCOPE
- #include "view_feattable_.cpp"
- void CViewFeatTable::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CViewFeatTable", "Feature Table",
- "Tabular list of all features in a record", "");
- // command info
- CPluginCommandSet& cmds = info.SetCommands();
- CPluginCommand& args = cmds.AddViewCommand(eViewCommand_new_view);
- args.AddArgument("loc", "Location to display",
- CSeq_loc::GetTypeInfo());
- }
- CViewFeatTable::CViewFeatTable(const CPluginMessage& msg,
- const string& pool_name)
- : CView()
- {
- m_Window.reset(x_CreateWindow());
- // create our dynamic menu managers
- m_AlgoMenuMgr.reset(new CAlgoMenuMgr(m_Menu, "Tools", this));
- m_ViewMenuMgr.reset(new CViewMenuMgr(m_Menu, "View", this, pool_name));
- m_SortMenuMgr.reset(new CSortMenuMgr(m_Menu, "View"));
- m_SortMenuMgr->AddSortMenu(m_FeatTable);
- // decode the argument
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- const CPluginArg& arg = args["loc"];
- const IDocument* doc = arg.GetDocument();
- const CSeq_loc* loc =
- dynamic_cast<const CSeq_loc*> (arg.GetObject());
- // assign to our core components
- if (doc && loc) {
- x_SetDocument(*doc);
- m_SeqId.Reset(&sequence::GetId(*loc));
- // set sequence range
- x_SetVisibleRange(*loc);
- }
- }
- void CViewFeatTable::OnSelectionChanged(const CSelectionBuffer& buf)
- {
- m_StatusBar->SetMessage("No features.");
- if ( !m_FeatTable || !GetDocument() || &buf == &GetSelBuffer()) {
- return;
- }
- // accept our selections
- SetSelBuffer().Clear();
- m_FeatTable->ClearSelections();
- TConstScopedObjects sels = buf.DecomposeToPairs();
- ITERATE (TConstScopedObjects, iter, sels) {
- SConstScopedObject cso = *iter;
- const IDocument* doc =
- CDocManager::GetDocumentFromScope(*cso.scope);
- // only accept selections for the current document
- if ( doc != m_Document) {
- continue;
- }
- // only select seq-feat selections
- const CSeq_feat* feat =
- dynamic_cast<const CSeq_feat*>(cso.object.GetPointer());
- if ( !feat ) {
- continue;
- }
- // select!
- SetSelBuffer().AddSelection(doc, *feat);
- m_FeatTable->SelectFeature(*feat);
- }
- m_FeatTable->redraw();
- // prepare our status bar message
- x_UpdateStatusMessage();
- // reset our menus
- x_UpdateDynMenus();
- }
- void CViewFeatTable::OnDocumentChanged()
- {
- x_Update();
- }
- void CViewFeatTable::OnVisibleRangeChanged(const CSeq_loc& loc)
- {
- SetVisibleRange(loc);
- m_FeatTable->SetVisibleRange(*m_VisibleRange);
- m_FeatTable->Update(GetDocument()->GetScope().GetBioseqHandle(*m_SeqId));
- }
- void CViewFeatTable::x_Update()
- {
- SetTitle(GetTitle());
- m_StatusBar->SetMessage("No features.");
- if ( !m_FeatTable || !GetDocument() ) {
- return;
- }
- CBioseq_Handle handle =
- GetDocument()->GetScope().GetBioseqHandle(*m_SeqId);
- m_FeatTable->Update(handle);
- SetTitle(x_GetTitle(handle));
- // prepare our status bar message
- x_UpdateStatusMessage();
- // update our dynamic menus
- x_UpdateDynMenus();
- }
- void CViewFeatTable::x_UpdateStatusMessage()
- {
- //
- // prepare our status bar message
- //
- string status_msg;
- int total_feats = m_FeatTable->GetTotalFeats();
- status_msg = NStr::IntToString(total_feats) + " feature";
- if (total_feats != 1) {
- status_msg += "s";
- }
- if (m_FeatTable->GetFilters().GetFilters().size() != 0) {
- int num_filts = m_FeatTable->GetFilters().GetFilters().size();
- status_msg += ", " + NStr::IntToString(num_filts) + " filter";
- if (num_filts != 1) {
- status_msg += "s";
- }
- int filtered_feats = m_FeatTable->GetFilteredFeats();
- status_msg +=
- ", " + NStr::IntToString(filtered_feats) + " feature";
- if (filtered_feats != 1) {
- status_msg += "s match";
- } else {
- status_msg += " matches";
- }
- } else {
- status_msg += ", no filters selected";
- }
- m_StatusBar->SetMessage(status_msg);
- }
- void CViewFeatTable::x_SetVisibleRange(const CSeq_loc& loc)
- {
- if (loc.IsWhole()) {
- CRef<CSeq_loc> seq_loc(new CSeq_loc);
- seq_loc->SetWhole().Assign(*m_SeqId);
- SetVisibleRange(*seq_loc);
- } else {
- TSeqRange range = loc.GetTotalRange();
- x_SetVisibleRange(range);
- }
- }
- void CViewFeatTable::x_SetVisibleRange(const TSeqRange& range)
- {
- CRef<CSeq_loc> seq_loc(new CSeq_loc());
- // Set seq loc with the range
- seq_loc->SetInt().SetFrom(range.GetFrom());
- seq_loc->SetInt().SetTo (range.GetTo());
- seq_loc->SetId(*m_SeqId);
- SetVisibleRange(*seq_loc);
- m_FeatTable->SetVisibleRange(*m_VisibleRange);
- }
- void CViewFeatTable::x_UpdateDynMenus()
- {
- m_ViewMenuMgr->Clear();
- m_AlgoMenuMgr->Clear();
- if ( !GetSelBuffer() ) {
- SetSelBuffer().AddSelection(m_Document, *m_SeqId);
- }
- m_ViewMenuMgr->AddActiveViews(GetDocument());
- m_ViewMenuMgr->AddNewViews();
- m_AlgoMenuMgr->AddAlgoMenu();
- }
-
- const string& CViewFeatTable::GetTitle() const
- {
- static string s_str("Feature Table View");
- return s_str;
- }
- void CViewFeatTable::x_OnHelp()
- {
- }
- void CViewFeatTable::x_OnFilter()
- {
- if ( !m_FilterDlg.get() ) {
- m_FilterDlg.reset(new CFilterDlg());
- m_FilterDlg->SetFilters(&m_FeatTable->GetFilters());
- }
- m_FilterDlg->Show();
- x_Update();
- }
- void CViewFeatTable::x_OnSelChanged()
- {
- SetSelBuffer().Clear();
- for (size_t i = 0; i < m_FeatTable->GetRows(); ++i) {
- if ( !m_FeatTable->row_selected(i) ) {
- continue;
- }
- CMappedFeat feat = m_FeatTable->GetData(i);
- SetSelBuffer().AddSelection(GetDocument(), feat.GetOriginalFeature());
- }
- // update our dynamic menus
- x_UpdateDynMenus();
- //...and notify our connected views
- PostSelectionChanged(GetSelBuffer());
- }
- void CViewFeatTable::x_OnVisibleRangeChange()
- {
- // Get the max value for the "to" field
- CBioseq_Handle handle = GetDocument()->GetScope().GetBioseqHandle(*m_SeqId);
- TSeqPos seq_size = handle.GetSeqVector().size();
- // set the dialog with the current seting
- const CSeq_loc& loc = GetVisibleRange();
- TSeqRange range(loc.GetTotalRange());
-
- CFeatTable::EVisibleRangeMethod method;
- method = m_FeatTable->GetVisibleRangeMethod();
- auto_ptr<CVisibleRangeDialog> dlg;
- if (method == CFeatTable::eScrollTo) {
- dlg.reset(new CVisibleRangeDialog(range.GetFrom(), seq_size));
- } else {
- dlg.reset(new CVisibleRangeDialog(seq_size));
- if (!range.IsWhole() && !range.Empty()) {
- dlg->SetRange(range);
- }
- }
- if (dlg->ShowModal()) {
- if (method == CFeatTable::eScrollTo) {
- range.SetFrom(dlg->GetScrollTo());
- range.SetTo(seq_size);
- } else {
- range = dlg->GetRange();
- }
- x_SetVisibleRange(range);
- m_FeatTable->Update
- (GetDocument()->GetScope().GetBioseqHandle(*m_SeqId));
- // Post a message the the visible range changed
- PostVisibleRangeChanged(GetVisibleRange());
- }
- }
- void CViewFeatTable::x_OnPreferences()
- {
- CFeatTablePreferenceDialog dlg;
- CFeatTable::EVisibleRangeMethod method;
- // set dialog with current setting - Default is Scrool To
- method = m_FeatTable->GetVisibleRangeMethod();
- if (method == CFeatTable::eEntirelyContained) {
- dlg.SetEntirelyContained();
- } else if (method == CFeatTable::eIntersection) {
- dlg.SetIntersection();
- } else {
- dlg.SetScrollTo();
- }
- if (dlg.ShowModal()) {
- // visible range method
- if (dlg.EntirelyContainedMethod()) {
- method = CFeatTable::eEntirelyContained;
- } else if (dlg.ScrollToMethod()) {
- method = CFeatTable::eScrollTo;
- } else if (dlg.IntersectionMethod()) {
- method = CFeatTable::eIntersection;
- }
- m_FeatTable->SetVisibleRangeMethod(method);
- CBioseq_Handle handle =
- m_Document->GetScope().GetBioseqHandle(*m_SeqId);
- m_FeatTable->Update(handle);
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: view_feattable.cpp,v $
- * Revision 1000.7 2004/06/01 21:01:26 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.37
- *
- * Revision 1.37 2004/05/21 22:27:49 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.36 2004/04/16 14:47:27 dicuccio
- * Enabled alignment table view. Use appropriate ISelection interface for dynamic menus
- *
- * Revision 1.35 2004/04/07 13:04:24 dicuccio
- * Changed view API - use CPluginMessage instead of CPluginArgSet. Use
- * TConstScopedObjects instead of CSelectionBuffer::TSelItems.
- *
- * Revision 1.34 2004/03/11 17:47:22 dicuccio
- * Use TSeqRange instead of TRange
- *
- * Revision 1.33 2004/01/27 18:45:35 dicuccio
- * Added missing header files
- *
- * Revision 1.32 2004/01/20 18:17:53 dicuccio
- * Changed to match new API in CTablePanel
- *
- * Revision 1.31 2004/01/07 18:51:46 dicuccio
- * Guard against self-assignment in OnSelectionsChanged()
- *
- * Revision 1.30 2003/12/30 15:03:56 dicuccio
- * Added ability to pass selections into feature table
- *
- * Revision 1.29 2003/12/24 17:23:49 friedman
- * Changed x_UpdateDynMenus to pass in visible range seqloc instead of seqid.
- *
- * Revision 1.28 2003/12/24 16:33:18 friedman
- * Added posting visible range change message.
- *
- * Revision 1.27 2003/12/22 19:32:24 dicuccio
- * Lots of code clean-up. Changed to match new APIs in IView. Added first pass
- * at processing selections (not entirely working)
- *
- * Revision 1.26 2003/12/22 18:15:08 friedman
- * Added various visible range methods and the selection of a method
- * through the preference menu selection and dialog.
- *
- * Revision 1.25 2003/12/03 22:24:12 friedman
- * Added changing visible range of the table.
- *
- * Revision 1.24 2003/11/26 19:45:39 friedman
- * Changed CSeq_id plugn arg to CSeq_loc. Set visible range based on seq loc passed in.
- *
- * Revision 1.23 2003/11/24 15:45:45 dicuccio
- * Renamed CVersion to CPluginVersion
- *
- * Revision 1.22 2003/11/20 21:50:39 jcherry
- * Set status message *after* updating feature table (fixes reporting of
- * number of features)
- *
- * Revision 1.21 2003/11/20 16:54:33 ucko
- * OnVisibleRangeChanged: don't try to introduce const in static_cast<>.
- *
- * Revision 1.20 2003/11/19 20:45:28 friedman
- * Added handling a visible range change event
- *
- * Revision 1.19 2003/11/04 12:51:28 friedman
- * Added event message pool callbacks for the document all-view message pool.
- *
- * Revision 1.18 2003/10/27 20:03:42 dicuccio
- * Rearranged Update() to be consistent
- *
- * Revision 1.17 2003/10/07 13:47:07 dicuccio
- * Renamed CPluginURL* to CPluginValue*
- *
- * Revision 1.16 2003/09/04 14:54:23 dicuccio
- * Use IDocument instead of CDocument. Changed APIs to match changes in IView
- *
- * Revision 1.15 2003/07/31 17:04:34 dicuccio
- * Changed type stored by feature table view - use CMappedFeat instead of CFeature
- * (less memory consumption)
- *
- * Revision 1.14 2003/07/22 15:32:17 dicuccio
- * Changed to make use of new API in plugin_utils.hpp - GetArgValue()
- *
- * Revision 1.13 2003/06/26 15:33:41 dicuccio
- * Moved GetURLValue() from PluginURL.hpp to plugin_utils.hpp. Fixed compilation
- * errors relating to missing #includes
- *
- * Revision 1.12 2003/06/25 17:03:01 dicuccio
- * Split CPluginHandle into a handle (pointer-to-implementation) and
- * implementation file. Lots of #include file clean-ups.
- *
- * Revision 1.11 2003/06/20 14:53:53 dicuccio
- * Revised plugin registration - moved GetInfo() into the plugin handler
- *
- * Revision 1.10 2003/06/02 16:06:24 dicuccio
- * Rearranged src/objects/ subtree. This includes the following shifts:
- * - src/objects/asn2asn --> arc/app/asn2asn
- * - src/objects/testmedline --> src/objects/ncbimime/test
- * - src/objects/objmgr --> src/objmgr
- * - src/objects/util --> src/objmgr/util
- * - src/objects/alnmgr --> src/objtools/alnmgr
- * - src/objects/flat --> src/objtools/flat
- * - src/objects/validator --> src/objtools/validator
- * - src/objects/cddalignview --> src/objtools/cddalignview
- * In addition, libseq now includes six of the objects/seq... libs, and libmmdb
- * replaces the three libmmdb? libs.
- *
- * Revision 1.9 2003/05/19 13:46:51 dicuccio
- * Moved gui/core/plugin/ --> gui/plugin/. Merged core libraries into
- * libgui_core.so
- *
- * Revision 1.8 2003/04/29 14:56:16 dicuccio
- * Reworked FLUID-generated code: better memory management, more explicit control
- * over the constructor
- *
- * Revision 1.7 2003/04/24 16:42:52 dicuccio
- * Updated to reflect changes in IDocument, plugin API
- *
- * Revision 1.6 2003/03/17 14:54:15 dicuccio
- * Changed base class CView - added member variable for FLTK gui component for
- * child windows, which is now maintained via an auto_ptr<>. Eliminated
- * Show()/Hide() as a pure virtual requirement.
- *
- * Revision 1.5 2003/03/03 14:58:56 dicuccio
- * Changed to use visible range from the base class. Added an explicit setter for
- * the visible range
- *
- * Revision 1.4 2003/01/13 13:10:09 dicuccio
- * Namespace clean-up. Retired namespace gui -> converted all to namespace ncbi.
- * Moved all FLUID-generated code into namespace ncbi.
- *
- * Revision 1.3 2003/01/08 14:58:47 dicuccio
- * Major overhaul. Added column selection dialog to base class - moved out of
- * this class. Added ability to sort columns based on menu selections. Added
- * ability to filter features based on a wide range of criteria.
- *
- * Revision 1.2 2002/12/31 16:16:27 dicuccio
- * Fixed odd compiler error in MSVC release builds - ambiguous '&&' operator
- *
- * Revision 1.1 2002/12/30 18:49:41 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */