document.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:17k
- /*
- * ===========================================================================
- * PRODUCTION $Log: document.cpp,v $
- * PRODUCTION Revision 1000.5 2004/06/01 20:44:03 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.48
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: document.cpp,v 1000.5 2004/06/01 20:44:03 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:
- * CDocument -- the basic data unit for GBENCH
- */
- #include <ncbi_pch.hpp>
- #include <corelib/ncbicntr.hpp>
- #include <gui/core/doc_exception.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/core/document.hpp>
- #include <gui/core/obj_convert.hpp>
- #include <gui/core/iview.hpp>
- #include <objects/seqset/Seq_entry.hpp>
- #include "doc_wkspace.hpp"
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- // static counter for all documents
- static CAtomicCounter s_DocIdCounter;
- // the steps for tiling new views
- static const int kTilingXStep = 25;
- static const int kTilingYStep = 25;
- // the default "top" positions
- static const int kTopXPos = 25;
- static const int kTopYPos = 25;
- CDocument::CDocument()
- : m_LastX(kTopXPos),
- m_LastY(kTopYPos),
- m_DocId(s_DocIdCounter.Add(1)),
- m_AllViewsName("All Views"),
- m_MsgPosted(false)
- {
- }
- CDocument::~CDocument()
- {
- }
- void CDocument::SetScope(CScope& scope)
- {
- CMutexGuard LOCK(m_Mutex);
- m_Scope.Reset(&scope);
- }
- // Show the workspace associated with this document
- void CDocument::ShowWorkspace(void)
- {
- CMutexGuard LOCK(m_Mutex);
- NON_CONST_ITERATE (TViews, iter, m_Views) {
- (*iter)->Show();
- }
- }
- // Hide the workspace associated with this document
- void CDocument::HideWorkspace(void)
- {
- CMutexGuard LOCK(m_Mutex);
- NON_CONST_ITERATE (TViews, iter, m_Views) {
- (*iter)->Hide();
- }
- }
- // internal function to retrieve a single message pool
- CDocument::TViewMsgPool* CDocument::x_GetMessagePool(const string& name,
- bool create)
- {
- if ( !m_MsgPoolMgr.get() ) {
- m_MsgPoolMgr.reset(new TViewMsgPoolMgr());
- }
- TViewMsgPool* pool = m_MsgPoolMgr->FindPool(name);
- if ( !pool && create) {
- pool = m_MsgPoolMgr->CreatePool(name);
- }
- return pool;
- }
- CDocument::TViewMsgPool& CDocument::x_GetAllViewsPool()
- {
- if ( !m_AllViewsPool ) {
- m_AllViewsPool.Reset(x_GetMessagePool(m_AllViewsName, true));
- }
- return *m_AllViewsPool;
- }
- // internal message posting function
- void CDocument::x_PostMessage(TViewMsgPool* pool,
- TUpdateFlags event, const void* data)
- {
- CMutexGuard LOCK(m_Mutex);
- if (m_MsgPosted) {
- // UpdateAllViews has been called from a message event
- // handler. This is not allowed.
- LOG_POST(Error << "CDocument::x_PostMessage(): invoked from "
- "a message event handler");
- return;
- }
- m_MsgPosted = true;
- pool->PostMessage(event, data);
- m_MsgPosted = false;
- }
- //
- // function to update all of our views
- //
- void CDocument::UpdateAllViews()
- {
- PostDocumentChanged();
- }
- void CDocument::PostDocumentChanged(const string& msg_pool)
- {
- TViewMsgPool* pool = x_GetMessagePool(msg_pool);
- if ( !pool ) {
- pool = &x_GetAllViewsPool();
- }
- x_PostMessage(pool, fDocumentChanged, NULL);
- }
- // Force all views to update themselves to show a given visible range
- void CDocument::PostVisibleRangeChanged(const CSeq_loc& loc,
- const string& msg_pool)
- {
- TViewMsgPool* pool = x_GetMessagePool(msg_pool);
- if ( !pool ) {
- pool = &x_GetAllViewsPool();
- }
- x_PostMessage(pool, fVisibleRangeChanged, &loc);
- }
- // Force all views to update themselves to set a group of selections
- void CDocument::PostSelectionChanged(const CSelectionBuffer& buf,
- const string& msg_pool)
- {
- TViewMsgPool* pool = x_GetMessagePool(msg_pool);
- if ( !pool ) {
- pool = &x_GetAllViewsPool();
- }
- x_PostMessage(pool, fSelectionChanged, &buf);
- }
- void CDocument::PostViewCreated(IView& view)
- {
- x_PostMessage(&x_GetAllViewsPool(), fViewCreated, &view);
- }
- void CDocument::PostViewReleased(IView& view)
- {
- x_PostMessage(&x_GetAllViewsPool(), fViewReleased, &view);
- }
- // Send event to a views group message pool
- void CDocument::PostGroupMessage(IView* view, TUpdateFlags event,
- const void* user_data)
- {
- TViewGroupPools::iterator iter = m_ViewGroupPools.find(view);
- if (iter == m_ViewGroupPools.end()) {
- LOG_POST(Error << "CDocument::PostGroupMessage: "
- "No group pool for the view");
- return;
- }
- x_PostMessage(iter->second, event, user_data);
- }
- //
- // attach a view to the current document
- void CDocument::AttachView(IView* view, const string& pool_name)
- {
- CMutexGuard LOCK(m_Mutex);
- m_Views.push_back(CRef<IView>(view));
- //
- // make sure our new view comes up at a tiled position
- //
- int width;
- int height;
- view->GetSize(width, height);
- m_LastX += kTilingXStep;
- m_LastY += kTilingYStep;
- if (m_LastX > Fl::w() - width) {
- m_LastX = kTopXPos;
- }
- if (m_LastY > Fl::h() - height) {
- m_LastY = kTopYPos;
- }
- view->SetPosition(m_LastX, m_LastY);
- //
- // make sure the window is sized to appear wholly in the screen
- //
- bool resize = false;
- if (Fl::w() - m_LastX - width < 0) {
- width = Fl::w() - m_LastX;
- resize = true;
- }
- if (Fl::h() - m_LastY - height < 0) {
- height = Fl::h() - m_LastY;
- resize = true;
- }
- if (resize) {
- view->SetSize(width, height);
- }
- // Add view to "All Views" message pool
- x_GetAllViewsPool().Join(*view);
- // add to the named pool
- if ( !pool_name.empty() ) {
- CRef<TViewMsgPool> my_pool(x_GetMessagePool(pool_name, true));
- my_pool->Join(*view);
-
- // Add view->msgpool map entry
- m_ViewGroupPools[view] = my_pool;
- }
- PostViewCreated(*view);
- CDocManager::UpdateAllViews(fViewCreated);
- // event routing
- IEventTransmitter * vt = view->QueryInterfaceTransmitter();
- if (vt) vt->SetHost(this);
- }
- void CDocument::DetachView(IView* view)
- {
- CMutexGuard LOCK(m_Mutex);
- CRef<IView> ref(view);
- m_Views.remove(ref);
- // Remove view to "All Views" message pool
- x_GetAllViewsPool().Leave(*view);
- // Remove view from group message pool and map
- TViewGroupPools::iterator iter = m_ViewGroupPools.find(view);
- if (iter != m_ViewGroupPools.end()) {
- (iter->second)->Leave(*view);
- m_ViewGroupPools.erase(iter);
- }
- PostViewReleased(*view);
- CDocManager::UpdateAllViews(fViewReleased);
- }
- //
- // clear this document
- //
- void CDocument::Clear()
- {
- CMutexGuard LOCK(m_Mutex);
- m_Views.clear();
- // clear the message pools
- m_AllViewsPool.Reset();
- m_ViewGroupPools.clear();
- m_MsgPoolMgr.reset();
- }
- void CDocument::AttachAnnot(CSeq_annot& annot)
- {
- CObjectConverter::TObjList objs;
- CObjectConverter::Convert(GetScope(), annot,
- CSeq_entry::GetTypeInfo(), objs);
- ITERATE (CObjectConverter::TObjList, obj_iter, objs) {
- const CSeq_entry* entry =
- dynamic_cast<const CSeq_entry*>(obj_iter->GetPointer());
- if ( !entry ) {
- continue;
- }
- GetScope().AddTopLevelSeqEntry(const_cast<CSeq_entry&>(*entry));
- }
- }
- // Transmitter/reciever QI
- IEventTransmitter * CDocument::QueryInterfaceTransmitter(void)
- {
- return dynamic_cast<IEventTransmitter*>(this);
- }
- IEventReceiver * CDocument::QueryInterfaceReceiver(void)
- {
- return dynamic_cast<IEventReceiver*>(this);
- }
- void CDocument::SetHost(IEventTransmitter * host)
- {
- _TRACE("Error: SetHost for CDocument - something gone wrong...");
- }
- void CDocument::FireEvent(const CEvent * evt)
- {
- CDocManager::NotifyAllViews(evt);
- }
- void CDocument::OnEvent(const CEvent * evt)
- {
- NON_CONST_ITERATE (TViews, iter, m_Views) {
- IEventTransmitter * vt = (*iter)->QueryInterfaceTransmitter();
- IEventReceiver * vr = (*iter)->QueryInterfaceReceiver();
- if (vr) {
- if (vt && evt->GetSender()==vt) continue;
- vr->OnEvent(evt);
- }
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: document.cpp,v $
- * Revision 1000.5 2004/06/01 20:44:03 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.48
- *
- * Revision 1.48 2004/05/21 22:27:40 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.47 2004/05/17 13:19:35 dicuccio
- * Removed old document workspace
- *
- * Revision 1.46 2004/03/30 17:09:25 tereshko
- * Added support for events broadcasting
- *
- * Revision 1.45 2004/01/21 12:38:18 dicuccio
- * redesigned CObjectCOnverter API to eliminate temporary object creation
- *
- * Revision 1.44 2004/01/15 17:59:20 dicuccio
- * Rearranged initializers to avoid warning
- *
- * Revision 1.43 2003/12/31 20:26:34 dicuccio
- * Added internal wrappers for accessing view message pools. Fixed error in
- * Clear() - must also delete view groups's pools (caused failure to dereference
- * all documents and views)
- *
- * Revision 1.42 2003/12/22 19:19:24 dicuccio
- * Clarified process of posting messages to other views. Removed CView::Update().
- *
- * Revision 1.41 2003/11/19 20:40:41 friedman
- * Added grouping views into group message pools
- *
- * Revision 1.40 2003/11/18 17:40:16 dicuccio
- * Changed AttachAnnot() to create a parallel seq-entry rather than attaching
- * directly to the current seq-entry
- *
- * Revision 1.39 2003/11/14 17:45:33 dicuccio
- * Added Clear() - clears view list and view pool manager. Changed AttachAnnot()
- * - don't attach directly to original data. Added resize for window to fit
- * screen if the resolution is smaller than the window size.
- *
- * Revision 1.38 2003/11/06 20:03:02 dicuccio
- * Added parameter to AttachView() for view message pool
- *
- * Revision 1.37 2003/11/04 17:16:43 dicuccio
- * Use CObjectCOnverter instead of CPluginUtils. Added code to reposition views
- * on creation to tile nicely on the screen.
- *
- * Revision 1.36 2003/11/04 13:08:53 dicuccio
- * Changed storage of message pool to CRef<> from C++ reference
- *
- * Revision 1.35 2003/11/04 12:45:34 friedman
- * Added all view message pool to be invoked fom UpdateAllViews. Replaces
- * iterating through the all the views and calling Update.
- *
- * Revision 1.34 2003/10/10 17:13:34 dicuccio
- * Implemented DetachView(). Notify doc manager on view creation / view release
- *
- * Revision 1.33 2003/09/04 14:01:51 dicuccio
- * Introduce IDocument and IView as abstract base classes for CDocument and CView
- *
- * Revision 1.32 2003/08/05 17:02:08 dicuccio
- * Changed static counter to match coding standard
- *
- * Revision 1.31 2003/07/31 16:53:44 dicuccio
- * Added unique ID for each document
- *
- * Revision 1.30 2003/07/22 15:28:31 dicuccio
- * Adjusted AttachAnnot() to match API changes in CPluginUtils::Convert()
- *
- * Revision 1.29 2003/06/25 17:02:54 dicuccio
- * Split CPluginHandle into a handle (pointer-to-implementation) and
- * implementation file. Lots of #include file clean-ups.
- *
- * Revision 1.28 2003/06/23 13:23:12 dicuccio
- * Deprecated seq_utils.[h,c]pp - moved functions into gui.utils/utils.hpp
- *
- * Revision 1.27 2003/06/17 19:11:49 dicuccio
- * Added AttachAnnot()
- *
- * Revision 1.26 2003/06/02 16:06:17 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.25 2003/05/09 14:29:51 dicuccio
- * Cleaned out unnecessary local scope
- *
- * Revision 1.24 2003/05/08 16:18:59 dicuccio
- * Changed CFastMutex --> CMutex - guards against recursive locking
- *
- * Revision 1.23 2003/05/05 12:41:55 dicuccio
- * Added mutex to guard access to CDocument's members
- *
- * Revision 1.22 2003/04/29 14:38:04 dicuccio
- * Removed old typing system
- *
- * Revision 1.21 2003/04/24 16:27:47 dicuccio
- * Large API / internals change. Made CDocument an abstract base class; removed
- * notion of document == bioseq-handle
- *
- * Revision 1.20 2003/04/16 11:38:32 dicuccio
- * Cleaned up CDocument's destructor
- *
- * Revision 1.19 2003/04/10 19:48:37 dicuccio
- * Made text description a member variable
- *
- * Revision 1.18 2003/03/31 13:42:18 dicuccio
- * Disabled MDI interface (for now). Changed mechanism of subtype determination
- * to take advantage of more efficient scope resolution
- *
- * Revision 1.17 2003/03/17 14:49:41 dicuccio
- * Added top-level workspace, one per document. Added Hide()/Show() functions
- * for the workspace. Removed header-file dependency on view.hpp
- *
- * Revision 1.16 2003/03/10 22:58:51 kuznets
- * iterate -> ITERATE
- *
- * Revision 1.15 2003/03/03 15:18:46 dicuccio
- * Added views slaved indicator (false by default)
- *
- * Revision 1.14 2003/02/26 14:19:36 dicuccio
- * Removed some unecessary _TARCE() statements
- *
- * Revision 1.13 2003/02/20 19:49:55 dicuccio
- * Created new plugin architecture, based on ASN.1 spec. Moved GBENCH frameowrk
- * over to use new plugin architecture.
- *
- * Revision 1.12 2003/02/10 18:52:58 dicuccio
- * Fixed compilation issues relating to CFeat_CI API change
- *
- * Revision 1.11 2003/02/10 18:12:59 dicuccio
- * Changed mechanism for determining types to a document's features (more
- * efficient mechanism is used)
- *
- * Revision 1.10 2003/02/05 19:52:57 dicuccio
- * Cleaned up data management - save the scope for the bioseq separate from the
- * bioseq; assure that shut-down happens carefully; limit the calls to
- * x_SetTypes()
- *
- * Revision 1.9 2003/01/13 13:10:06 dicuccio
- * Namespace clean-up. Retired namespace gui -> converted all to namespace ncbi.
- * Moved all FLUID-generated code into namespace ncbi.
- *
- * Revision 1.8 2003/01/08 15:33:09 dicuccio
- * Make sure that all Bioseq-set types are parsed.
- *
- * Revision 1.7 2003/01/08 14:49:52 dicuccio
- * Revamped type resolution system - now, each record stores a list of the
- * available types relevant for that record. This permits record typing based on
- * sub-component presence.
- *
- * Revision 1.6 2002/12/09 20:33:52 dicuccio
- * Use seqience::GetTitle instead of home-grown approach
- *
- * Revision 1.5 2002/11/25 20:53:51 dicuccio
- * Added Set() function for bioseq-handle - used by data loader plugins. Added
- * default ctor.
- *
- * Revision 1.4 2002/11/14 16:16:48 dicuccio
- * Added 'pop-set' ast document type. Sorted document types in GetType().
- *
- * Revision 1.3 2002/11/09 20:50:09 dicuccio
- * Changed CDocument::x_GetViews() (non-const) and x_AttachView() from private to
- * public.
- *
- * Revision 1.2 2002/11/07 18:40:05 dicuccio
- * Various std::string fixes (use string::empty(); use implicit creation for
- * return from const char* <-> string).
- * Chanegd code to use ERR_POST() and _TRACE().
- *
- * Revision 1.1 2002/11/06 15:49:48 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */