view_graphic.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:19k
- /*
- * ===========================================================================
- * PRODUCTION $Log: view_graphic.cpp,v $
- * PRODUCTION Revision 1000.7 2004/06/01 20:59:43 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.64
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: view_graphic.cpp,v 1000.7 2004/06/01 20:59:43 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:
- * User-modifiable portion of main graphical sequence viewer class
- */
- #include <ncbi_pch.hpp>
- #include "view_graphic.hpp"
- #include <gui/core/doc_manager.hpp>
- #include <gui/core/idocument.hpp>
- #include <gui/core/selection_buffer.hpp>
- #include <gui/core/version.hpp>
- #include <gui/core/view_exception.hpp>
- #include <gui/core/plugin_utils.hpp>
- #include <gui/plugin/PluginRequest.hpp>
- #include <gui/plugin/PluginCommand.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginValue.hpp>
- #include <util/range.hpp>
- #include <objmgr/util/sequence.hpp>
- #include <gui/widgets/seq_graphic/seqgraphic_conf.hpp>
- #include <gui/widgets/seq_graphic/seqgraphic_ds.hpp>
- #include <gui/dialogs/config/theme_config_panel.hpp>
- // #include <gui/dialogs/config/theme_config_panel2.hpp>
- #include <gui/dialogs/config/theme_mediator.hpp>
- #include <gui/dialogs/config/theme_dlg.hpp>
- // #include <gui/dialogs/config/config_dlg.hpp>
- #include <gui/config/settings.hpp>
- BEGIN_NCBI_SCOPE
- // We include the generated _.cpp file here. This avoids a nasty bug in some
- // versions of gcc in which inline functions are not intantiated.
- #include "view_graphic_.cpp"
- void CViewGraphic::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CViewGraphic", "Graphical View",
- "Graphical view of sequence and features", "");
- // command info
- CPluginCommandSet& cmds = info.SetCommands();
- CPluginCommand& args = cmds.AddViewCommand(eViewCommand_new_view);
- args.AddArgument("loc", "Location to display",
- CSeq_loc::GetTypeInfo());
- }
- DEFINE_MENU(ToolBarMenu)
- MENU_ITEM(eCmdPrevExon, "Prev. Exon")
- MENU_ITEM(eCmdNextExon, "Next. Exon")
- END_MENU()
- BEGIN_CMD_MAP(CViewGraphic, CCommandTarget)
- //ON_COMMAND(eCmdPrevExon, &CViewGraphic::x_OnPrevExon)
- //ON_COMMAND(eCmdNextExon, &CViewGraphic::x_OnNextExon)
- END_CMD_MAP()
- void CViewGraphic::x_OnPrevExon()
- {
- m_SeqWidget->OnPrevExon();
- }
- void CViewGraphic::x_OnNextExon()
- {
- m_SeqWidget->OnNextExon();
- }
- CViewGraphic::CViewGraphic(const CPluginMessage& msg, const string& pool_name)
- : CView()
- {
- m_Window.reset(x_CreateWindow());
- m_ToolBar->SetItems(ToolBarMenu);
- m_ToolBar->SetCmdTarget(this);
- AddChildCmdTarget(m_SeqWidget);
-
- // decode the argument
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- const CPluginArg& arg = args["loc"];
- const CSeq_loc& loc = dynamic_cast<const CSeq_loc&> (arg.AsObject());
- const IDocument* doc = arg.GetDocument();
- // assign to our core components
- x_SetDocument(*doc);
- m_SeqId.Reset(&sequence::GetId(loc));
- // create the configuration object.
- CRef<CPluginConfigCache> thePCC
- (&CDocManager::GetSettings().SetPluginConfig());
- CRef<CSeqGraphicConfig> configSettings(new CSeqGraphicConfig(thePCC));
- x_SetConfig(configSettings);
-
- // create our data source
- m_DataSource.Reset
- (new CSeqGraphicDataSource(m_Document->GetScope(), *m_SeqId));
- m_SeqWidget->SetDataSource(m_DataSource);
- // set our visible range
- CRef<CSeq_loc> seq_loc(new CSeq_loc);
- // get sequence range
- TSeqRange range = loc.GetTotalRange();
- m_SeqWidget->ZoomOnRange(range);
- // 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);
- // create the dynamic menu managers
- m_ViewMenuMgr.reset
- (new CViewMenuMgr(m_MenuBar, "View", m_SeqWidget, pool_name));
- m_ToolMenuMgr.reset
- (new CAlgoMenuMgr(m_MenuBar, "Tools", m_SeqWidget));
- }
- void CViewGraphic::OnDocumentChanged()
- {
- // if our document has changed, we clear our selections because they
- // may no longer be valid
- SetSelBuffer().Clear();
- // set our window title as well
- SetTitle(x_GetTitle(m_DataSource->GetBioseqHandle()));
- m_SeqWidget->redraw();
- //
- // fill our dynamic menus
- //
- x_UpdateDynMenus();
- }
- void CViewGraphic::OnSelectionChanged(const CSelectionBuffer& buf)
- {
- SetSelBuffer().Copy(buf);
- m_SeqWidget->ClearSelection();
- TConstScopedObjects sels = GetSelBuffer().DecomposeToPairs();
- ITERATE (TConstScopedObjects, iter, sels) {
- SConstScopedObject cso = *iter;
- const IDocument* doc = CDocManager::GetDocumentFromScope(*cso.scope);
- const CObject* obj = cso.object;
- // only accept selections for the current document
- if ( doc != m_Document) {
- continue;
- }
- // select ranges on sequence
- const CSeq_loc* loc = dynamic_cast<const CSeq_loc*>(obj);
- if (loc) {
- m_SeqWidget->SelectSeqLoc(loc);
- } else {
- m_SeqWidget->SelectObject(obj);
- }
- }
- //
- // fill our dynamic menus
- //
- x_UpdateDynMenus();
- }
- void CViewGraphic::OnVisibleRangeChanged(const CSeq_loc& loc)
- {
- SetVisibleRange(loc);
- }
- void CViewGraphic::x_UpdateDynMenus()
- {
- // view menu first
- m_ToolMenuMgr->Clear();
- m_ViewMenuMgr->Clear();
- if ( !GetSelBuffer() ) {
- SetSelBuffer().AddSelection(GetDocument(), *m_SeqId);
- }
- m_ViewMenuMgr->AddActiveViews(GetDocument());
- m_ViewMenuMgr->AddNewViews();
- m_ToolMenuMgr->AddAlgoMenu();
- // m_PopupMenu was "eating" mouse move events. The tooltips never come up in the widget.
- //m_PopupMenu->copy(m_MenuBar->menu());
- }
- const string& CViewGraphic::GetTitle(void) const
- {
- static string s_str("Graphical View");
- return s_str;
- }
- void CViewGraphic::SetVisibleRange(const CSeq_loc& loc)
- {
- // call the base class
- CView::SetVisibleRange(loc);
- // do our widget-specific things
- TSeqRange range = loc.GetTotalRange();
- m_SeqWidget->ZoomOnRange(range);
- m_SeqWidget->redraw();
- //x_UpdateDynMenus();
- }
- void CViewGraphic::SetFeatureFocus(const CSeq_feat& feat)
- {
- }
- void CViewGraphic::x_Print(const CPrintOptions& opts)
- {
- m_SeqWidget->Print(opts);
- }
- void CViewGraphic::x_PanelCallback()
- {
- vector< CRef<CSeq_loc> > locs = m_SeqWidget->GetSelectedSeqLocs();
- TConstObjects objs = m_SeqWidget->GetSelectedObjects();
- bool update_menus = false;
- if (locs.size() || objs.size()) {
- // retrieve selections
- // selections come in two forms: sets of layout objects and sets of
- // seq-locs representing selected ranges
- SetSelBuffer().Clear();
- // seq-locs first
- ITERATE(vector< CRef<CSeq_loc> >, loc_iter, locs) {
- SetSelBuffer().AddSelection(GetDocument(), **loc_iter);
- }
- // now, selected layout objects
- ITERATE(TConstObjects, obj_iter, objs) {
- const CObject& obj = obj_iter->GetObject();
- SetSelBuffer().AddSelection(GetDocument(), obj);
- }
- update_menus = true;
- } else if (GetSelBuffer()) {
- SetSelBuffer().Clear();
- update_menus = true;
- }
- // Handle a visible range change
- if (m_SeqWidget->VisibleRangeChanged()) {
- TSeqRange range = m_SeqWidget->GetVisibleRange();
- // Set seq loc with the range
- CRef<CSeq_loc> loc(new CSeq_loc);
- loc->SetInt().SetFrom(range.GetFrom());
- loc->SetInt().SetTo (range.GetTo());
- loc->SetId(*m_SeqId);
- SetVisibleRange(*loc);
- // Post a message the the visible range changed
- PostVisibleRangeChanged(GetVisibleRange());
- // Reset the panel's VisibleRangeChanged flag
- m_SeqWidget->ResetVisibleRangeChanged();
- update_menus = true;
- }
- if (update_menus) {
- x_UpdateDynMenus();
- PostSelectionChanged(GetSelBuffer());
- }
- }
- void CViewGraphic:: x_OnZoomToSequence()
- {
- m_SeqWidget->SetZoomX( 1.0f );
- }
- void CViewGraphic:: x_OnFitToWindow()
- {
- m_SeqWidget->SetZoomX( 0.0f );
- }
- void CViewGraphic::x_SetConfig(CRef<CSeqGraphicConfig> config)
- {
- m_ConfigSettings = config;
- m_SeqWidget->SetConfig(m_ConfigSettings);
- }
- void CViewGraphic::x_OnPreferences()
- {
- // create panel
- //CFeatConfigPanel preference_panel;
- CThemeConfigPanel preference_panel;
- // CThemeConfigPanel2 preference_panel;
- // preference_panel.SetLayoutDirection(CThemeConfigPanel2::eLayoutDirection_Vertical);
-
- // create configuration mediator from data set and panel
- // CFeatConfigMediator preference_mediator(*m_ConfigSettings, preference_panel);
- CThemeMediator preference_mediator(*m_ConfigSettings, preference_panel);
- // create and display dialog given the mediator.
- // CConfigDlg preference_dialog(preference_mediator);
- CThemeDlg preference_dialog(preference_mediator);
- EDialogReturnValue dlg_ret = preference_dialog.ShowModal();
- if (eCancel == dlg_ret) {
- return;
- }
- // when dialog is done, save values to persistent storage (plugin config cache file).
- CDocManager::GetSettings().SavePluginConfig();
-
- // redraw and change settings to show the changes in the preferences.
- m_SeqWidget->UpdateConfig();
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: view_graphic.cpp,v $
- * Revision 1000.7 2004/06/01 20:59:43 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.64
- *
- * Revision 1.64 2004/05/21 22:27:49 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.63 2004/04/16 14:45:01 dicuccio
- * Code clean-up. Use TConstObjects for passing / retrieving selections. Use seq
- * graphic widget for marshalling selections
- *
- * Revision 1.62 2004/04/07 13:05:10 dicuccio
- * Changed view API - require CPluginMessage instead of CPluginArgSet
- *
- * Revision 1.61 2004/03/12 16:01:39 lebedev
- * Command map added. Ability to move between selected feature exon added.
- *
- * Revision 1.60 2004/03/11 17:46:58 dicuccio
- * Use TSeqRange instead of TRange
- *
- * Revision 1.59 2004/02/17 20:35:28 rsmith
- * moved core/settings.[ch]pp and core/system_path.[ch]pp to config and utils, respectively.
- *
- * Revision 1.58 2004/02/02 18:48:00 rsmith
- * commented out alternate preference panel
- *
- * Revision 1.57 2004/01/27 16:16:26 lebedev
- * Interfaces for view to view communication implemented
- *
- * Revision 1.56 2004/01/20 20:36:36 rsmith
- * Call the widget's UpdateConfig, not just redraw, after changing the configuration object.
- *
- * Revision 1.55 2004/01/20 14:11:19 rsmith
- * configuration done with a Theme dialog.
- *
- * Revision 1.54 2003/12/30 15:03:21 dicuccio
- * Fixed for change in file locations
- *
- * Revision 1.53 2003/12/29 20:18:05 rsmith
- * (correction to previous commit log) Move config settings initialization higher in the constructor since other members cstrs depend on it.
- *
- * Revision 1.52 2003/12/29 20:09:39 rsmith
- * add feat_config_list include (NOT: See next log.)
- *
- * Revision 1.51 2003/12/22 19:31:36 dicuccio
- * Lots of changes. Added better handling of messages received from other views.
- * Initial attempt at passing in selections (not entirely working)
- *
- * Revision 1.50 2003/12/22 13:02:18 lebedev
- * Plugin updated to use new datasource
- *
- * Revision 1.49 2003/11/27 20:22:05 ucko
- * Don't try to introduce const in static_cast<>.
- *
- * Revision 1.48 2003/11/26 19:48:40 friedman
- * Added handling rceiving visible range change
- *
- * Revision 1.47 2003/11/24 15:45:44 dicuccio
- * Renamed CVersion to CPluginVersion
- *
- * Revision 1.46 2003/11/19 20:43:59 friedman
- * Added detecting visible range change and posting a message
- *
- * Revision 1.45 2003/11/18 20:44:32 rsmith
- * Add configuration object and preference dialog.
- *
- * Revision 1.44 2003/11/04 17:49:25 dicuccio
- * Changed calling parameters for plugins - pass CPluginMessage instead of paired
- * CPluginCommand/CPluginReply
- *
- * Revision 1.43 2003/11/04 12:51:28 friedman
- * Added event message pool callbacks for the document all-view message pool.
- *
- * Revision 1.42 2003/10/27 20:03:42 dicuccio
- * Rearranged Update() to be consistent
- *
- * Revision 1.41 2003/10/27 16:15:17 dicuccio
- * Implemented initial zoom state
- *
- * Revision 1.40 2003/10/16 15:51:24 dicuccio
- * Set the title to something meaningful - include the sequence title and
- * accession. Only update dynamic menus if selections or document have changed.
- * Properly set dynamic menus to include information for the viewed seq-id, not
- * the document's seq-id.
- *
- * Revision 1.39 2003/10/15 13:42:31 dicuccio
- * Cleaned up the title - now reflects the actual sequence being viewed
- *
- * Revision 1.38 2003/10/07 13:47:06 dicuccio
- * Renamed CPluginURL* to CPluginValue*
- *
- * Revision 1.37 2003/09/30 19:53:53 dicuccio
- * Disable popup menu (again!) pending crash fix
- *
- * Revision 1.36 2003/09/30 15:18:45 dicuccio
- * Re-enabled popup menu
- *
- * Revision 1.35 2003/09/24 18:27:35 dicuccio
- * Uncommented recreation of data source on document change
- *
- * Revision 1.34 2003/09/04 14:54:22 dicuccio
- * Use IDocument instead of CDocument. Changed APIs to match changes in IView
- *
- * Revision 1.33 2003/08/18 16:19:32 lebedev
- * Change viewer to use new methods for showing/hiding features
- *
- * Revision 1.32 2003/07/23 19:13:13 dicuccio
- * Added menu options for fconfiguring the view
- *
- * Revision 1.31 2003/07/21 19:33:47 dicuccio
- * Added handling of selections in GUI - use menus
- *
- * Revision 1.30 2003/06/25 17:03:00 dicuccio
- * Split CPluginHandle into a handle (pointer-to-implementation) and
- * implementation file. Lots of #include file clean-ups.
- *
- * Revision 1.29 2003/06/20 19:51:27 dicuccio
- * Fixed compiler error on MSVC related to operator&&
- *
- * Revision 1.28 2003/06/20 14:53:52 dicuccio
- * Revised plugin registration - moved GetInfo() into the plugin handler
- *
- * Revision 1.27 2003/05/19 13:44:42 dicuccio
- * Moved gui/core/plugin/ --> gui/plugin. Merged core libraries into
- * libgui_core.so. Revamped graphical view to use Vlad Lebedev's new widget.
- *
- * Revision 1.26 2003/04/30 13:21:19 dicuccio
- * Added callback for expanded view. Make sure that the visible range gets
- * propagated correctly
- *
- * Revision 1.25 2003/04/29 14:54:44 dicuccio
- * Reworked FLUID-generated code: better memory management, more explicit
- * control over the constructor
- *
- * Revision 1.24 2003/04/24 16:41:55 dicuccio
- * Updated to reflect changes in plugin, IDocument API
- *
- * Revision 1.23 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.22 2003/03/03 14:55:18 dicuccio
- * Remiplemented using visible range in base class
- *
- * Revision 1.21 2003/02/20 19:49:59 dicuccio
- * Created new plugin architecture, based on ASN.1 spec. Moved GBENCH frameowrk
- * over to use new plugin architecture.
- *
- * Revision 1.20 2003/01/16 14:55:22 dicuccio
- * Added CFeaturePanel::Clear(). Fixed issue with some panels not being
- * properly cleared on update.
- *
- * Revision 1.19 2003/01/15 21:10:40 dicuccio
- * Large updates. Added support for rendering all feature types. Separated
- * features into distinct panels based on types. Added ability to specify
- * linking / packing as menu options.
- *
- * Revision 1.18 2003/01/13 13:10:08 dicuccio
- * Namespace clean-up. Retired namespace gui -> converted all to namespace
- * ncbi. Moved all FLUID-generated code into namespace ncbi.
- *
- * Revision 1.17 2003/01/09 14:50:41 dicuccio
- * Use 'const CBioseq_Handle&' instead of 'CBioseq_Handle&'
- *
- * Revision 1.16 2002/12/20 19:52:22 dicuccio
- * Cnaged TRange::SetFrom()/TRange::SetTo() --> TRange::Set()
- *
- * Revision 1.15 2002/12/20 19:22:52 dicuccio
- * Lots of changes to the menus. Standardized the menu syntax across all views.
- * Changed to use new dynamic menu managers.
- *
- * Revision 1.14 2002/12/19 18:18:20 dicuccio
- * Fixed thinko: don't clear the selection buffer unless the underlying document
- * changes.
- *
- * Revision 1.13 2002/12/13 13:18:52 dicuccio
- * Added work-around for inlining problems in some versions of gcc: directly
- * include a FLUID-generated '*_.cpp' file in the corresponding '*.cpp' and
- * remove this file from the build. Thanks Aaron!
- *
- * Revision 1.12 2002/12/12 15:23:49 dicuccio
- * Changed SetSelBuffer() -> non-const GetSelBuffer().
- *
- * Revision 1.11 2002/12/09 20:37:14 dicuccio
- * Switch to using CSeq_id::GetStringDescr()
- *
- * Revision 1.10 2002/12/09 15:41:30 dicuccio
- * When changing the selection past the end of the controlled sequence, must
- * preserve the size of the selection (no shrinking)
- *
- * Revision 1.9 2002/11/29 16:09:37 dicuccio
- * Use USING_SCOPE instead of BEGIN/END_SCOPE for out-of-scope classes. Fixed
- * function overload resolution issues in Windows.
- *
- * Revision 1.8 2002/11/29 15:35:30 dicuccio
- * Modified to use gui/utils. Moved utils.[h,c]pp into gui/utils. Split
- * utils.[h,c]pp into four files - feature.[h,c]pp and utils.[h,c]pp.
- *
- * Revision 1.7 2002/11/27 17:38:06 lebedev
- * Switched to Sequence Icon View Widget
- *
- * Revision 1.6 2002/11/26 17:15:25 lebedev
- * Switched to SeqInfo widget in graphics viewer
- *
- * Revision 1.5 2002/11/22 18:05:34 dicuccio
- * Fixed memory leak - must remember to delete main window.
- *
- * Revision 1.4 2002/11/19 17:11:13 dicuccio
- * Standardized creation of title.
- *
- * Revision 1.3 2002/11/09 20:57:08 dicuccio
- * Performance improvements: Implemented smarter widget update (use update
- * flags to specify update conditions); use a more intuitive (and flexible)
- * mechanism to obtain features from the object manager.
- *
- * Revision 1.2 2002/11/08 02:14:42 dicuccio
- * Minor code clean-ups (reformat text, eliminate dead variables, favor NCBI
- * macros)
- *
- * Revision 1.1 2002/11/07 16:27:27 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */