blast_poll_table.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:10k
- /*
- * ===========================================================================
- * PRODUCTION $Log: blast_poll_table.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:54:14 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: blast_poll_table.cpp,v 1000.1 2004/06/01 20:54:14 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 "blast_poll_table.hpp"
- #include <gui/objutils/label.hpp>
- #include <gui/objutils/obj_clipboard.hpp>
- #include <gui/utils/gui_event.hpp>
- #include <gui/utils/message_box.hpp>
- #include <gui/widgets/fl/menu.hpp>
- #include <gui/core/view_menu.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/dialogs/file_browser.hpp>
- #include <objmgr/scope.hpp>
- #include <serial/serial.hpp>
- #include <serial/objostr.hpp>
- #include <serial/objistr.hpp>
- #include <corelib/ncbireg.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- CBlastPollTable::CBlastPollTable(int x, int y, int w, int h, const char* label)
- : CTablePanel< CRef<CBlastPollItem> >(x, y, w, h, label)
- {
- //
- // set up the actual columns for our internal data
- //
- SetColumn(eRid, "RID", eString, FL_ALIGN_LEFT, 1.0f);
- SetColumn(eLocation, "Location", eString, FL_ALIGN_LEFT, 1.0f);
- SetColumn(eStatus, "Status", eString, FL_ALIGN_CENTER, 0.5f);
- SetColumn(eSubmit, "Submitted", eString, FL_ALIGN_CENTER, 0.5f);
- SetColumn(eLastPoll, "Polled", eString, FL_ALIGN_CENTER, 0.5f);
- SetCellBox(CFltkUtils::eBox_RightEdge);
- }
- enum EBlastResultsDlgCommands {
- eCmd_NewDocument = eBaseCmdLast + 200,
- eCmd_NewView,
- eCmd_SaveAs
- };
- static
- DEFINE_MENU(PopupMenu)
- MENU_ITEM(eCmd_NewDocument, "Open in New Document")
- SUBMENU("Open a View")
- END_SUBMENU()
- MENU_SEPARATOR()
- MENU_ITEM(eCmd_SaveAs, "Save as File")
- END_MENU()
- BEGIN_CMD_MAP(CBlastPollTable, CCommandTarget)
- ON_COMMAND(eCmd_NewDocument, &CBlastPollTable::OnNewDocument)
- ON_COMMAND(eCmd_SaveAs, &CBlastPollTable::OnSaveAs)
- END_CMD_MAP()
- void CBlastPollTable::OnNewDocument()
- {
- for (size_t i = 0; i < GetRows(); ++i) {
- if ( !IsRowSelected(i) ) {
- continue;
- }
- if (GetData(i)->m_Results) {
- CRef<CScope> scope(new CScope(CDocManager::GetObjectManager()));
- scope->AddDefaults();
- CDocManager::CreateDocument(*scope, *GetData(i)->m_Results);
- CDocManager::UpdateAllViews();
- }
- }
- }
- void CBlastPollTable::OnSaveAs()
- {
- for (size_t i = 0; i < GetRows(); ++i) {
- if ( !IsRowSelected(i) ) {
- continue;
- }
- const CBlastPollItem& item = *GetData(i);
- if (item.m_Results) {
- string fname = NcbiFileBrowser("Save BLAST Results", "", "");
- if (fname.empty()) {
- NcbiMessageBox("Error: No file indicated.");
- continue;
- }
- CNcbiOfstream o_file(fname.c_str(), ios::binary);
- auto_ptr<CObjectOStream> os
- (CObjectOStream::Open(eSerial_AsnBinary, o_file));
- *os << *item.m_Results;
- } else {
- string fname = NcbiFileBrowser("Save BLAST Results", "*.rid", "");
- if (fname.empty()) {
- NcbiMessageBox("Error: No file indicated.");
- continue;
- }
- CNcbiRegistry reg;
- reg.Set("blast-rid", "RID", item.m_Rid,
- CNcbiRegistry::ePersistent);
- if (item.m_QueryLoc) {
- string loc;
- {{
- CNcbiOstrstream ostr;
- auto_ptr<CObjectOStream> os
- (CObjectOStream::Open(eSerial_AsnText, ostr));
- *os << *item.m_QueryLoc;
- os->Flush();
- loc = CNcbiOstrstreamToString(ostr);
- }}
- loc = NStr::Replace(loc, "n", "");
- loc = NStr::Replace(loc, "r", "");
- reg.Set("blast-rid", "QueryLocation", loc,
- CNcbiRegistry::ePersistent);
- }
- CNcbiOfstream o_file(fname.c_str());
- reg.Write(o_file);
- }
- }
- }
- void CBlastPollTable::OnShowPopup()
- {
- CPopupMenu menu(x(), y(), w(), h());
- menu.SetCmdTarget(static_cast<CCommandTarget*>(this));
- add(&menu);
- menu.SetItems(PopupMenu);
- CViewMenuMgr mgr(&menu, "Open a View", this);
- mgr.AddNewViews();
- menu.popup();
- remove(menu);
- }
- int CBlastPollTable::handle(int event)
- {
- int res = CTablePanel< CRef<CBlastPollItem> >::handle(event);
- if (res) {
- return res;
- }
- switch (m_Handler.GetGUISignal()) {
- case CGUIEvent::ePopupSignal:
- OnShowPopup();
- return 1;
- default:
- break;
- }
- return 0;
- }
- int CBlastPollTable::x_OnCopy()
- {
- string str;
- CClipboard::Clear();
- for (size_t i = 0; i < GetRows(); ++i) {
- if ( !IsRowSelected(i) ) {
- continue;
- }
- if (GetData(i)->m_Results) {
- CObjClipboard::Add(GetData(i)->m_Document->GetScope(),
- *GetData(i)->m_Results);
- } else {
- CClipboard::Add(GetData(i)->m_Rid);
- }
- }
- CClipboard::Copy();
- return 1;
- }
- // add an item to the table
- void CBlastPollTable::AddItem(CBlastPollItem& item)
- {
- size_t idx = AddRow();
- SetData(idx, CRef<CBlastPollItem>(&item));
- x_UpdateItem(idx);
- }
- void CBlastPollTable::ActivateItem(size_t idx)
- {
- SetData(idx)->m_Active = true;
- x_UpdateItem(GetData(idx));
- }
- void CBlastPollTable::DeactivateItem(size_t idx)
- {
- SetData(idx)->m_Active = false;
- x_UpdateItem(GetData(idx));
- }
- // remove an item from the table
- void CBlastPollTable::RemoveItem(size_t idx)
- {
- RemoveRow(idx);
- redraw();
- }
- // remove all selected items from the table
- void CBlastPollTable::RemoveSelected()
- {
- for (size_t i = GetRows() - 1; i >= 0; --i) {
- if ( !IsRowSelected(i) ) {
- continue;
- }
-
- RemoveRow(i);
- }
- }
- void CBlastPollTable::MoveUp(size_t idx)
- {
- }
- void CBlastPollTable::MoveDown(size_t idx)
- {
- }
- // update an item in the table
- void CBlastPollTable::UpdateItem(size_t idx, CBlastPollItem& item)
- {
- _ASSERT(idx < GetRows());
- SetData(idx, CRef<CBlastPollItem>(&item));
- x_UpdateItem(idx);
- }
- bool CBlastPollTable::HasRid(const string& rid) const
- {
- for (size_t i = 0; i < GetRows(); ++i) {
- if (GetData(i)->m_Rid == rid) {
- return true;
- }
- }
- return false;
- }
- void CBlastPollTable::GetSelections(TConstScopedObjects& objs) const
- {
- objs.clear();
- for (size_t i = 0; i < GetRows(); ++i) {
- if ( !IsRowSelected(i) ) {
- continue;
- }
- const CBlastPollItem& item = *GetData(i);
- if ( !item.m_Document || !item.m_Results ) {
- continue;
- }
- SConstScopedObject sco;
- sco.scope = &item.m_Document->GetScope();
- sco.object = item.m_Results.GetPointer();
- objs.push_back(sco);
- }
- }
- void CBlastPollTable::SetSelections(const TConstScopedObjects& objs)
- {
- }
- void CBlastPollTable::x_UpdateItem(size_t idx)
- {
- const CBlastPollItem& item = *GetData(idx);
- SetCell(idx, eRid, item.m_Rid);
- if (item.m_QueryLoc) {
- string& str = SetCell(idx, eLocation);
- str.erase();
- CScope* scope = NULL;
- if (item.m_Document) {
- scope = &item.m_Document->GetScope();
- }
- CLabel::GetLabel(*item.m_QueryLoc, &str, CLabel::eDefault, scope);
- }
- SetCell(idx, eStatus, item.m_Status);
- SetCell(idx, eSubmit, item.m_SubmitTime.AsString("h:m:s"));
- SetCell(idx, eLastPoll, item.m_LastPollTime.AsString("h:m:s"));
- redraw();
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: blast_poll_table.cpp,v $
- * Revision 1000.1 2004/06/01 20:54:14 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8
- *
- * Revision 1.8 2004/05/28 15:03:20 dicuccio
- * Use right edge box type
- *
- * Revision 1.7 2004/05/21 22:27:46 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.6 2004/05/07 15:42:08 dicuccio
- * Use CLabel instead of CSeqUtils::GetLabel(). Use CObjClipboard instead of
- * CClipboard
- *
- * Revision 1.5 2004/05/03 13:05:42 dicuccio
- * gui/utils --> gui/objutils where needed
- *
- * Revision 1.4 2004/04/22 13:07:10 dicuccio
- * Really pass selections through in GetSelections()
- *
- * Revision 1.3 2004/04/22 12:22:08 dicuccio
- * Added BLAST RID caching. Added better formatting for BLAST results
- *
- * Revision 1.2 2004/04/07 12:52:18 dicuccio
- * Added copying of seq-align-set to clipboard, if present
- *
- * Revision 1.1 2004/03/05 17:30:34 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */