lds_search_dlg.cpp

来自「ncbi源码」· C++ 代码 · 共 284 行

CPP
284
字号
/* * =========================================================================== * PRODUCTION $Log: lds_search_dlg.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 20:58:12  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * PRODUCTION * =========================================================================== *//*  $Id: lds_search_dlg.cpp,v 1000.2 2004/06/01 20:58:12 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:  Anatoliy Kuznetsov * * File Description: *    CLdsSearchDlg - simple search dialog for local storage */#include <ncbi_pch.hpp>#include <objtools/lds/lds.hpp>#include <objtools/lds/lds_set.hpp>#include <objtools/lds/lds_util.hpp>#include <objtools/lds/lds_reader.hpp>#include <objtools/lds/lds_query.hpp>//#include <objtools/lds/admin/lds_admin.hpp>#include "lds_search_dlg.hpp"#include "loader_utils.hpp"BEGIN_NCBI_SCOPEUSING_SCOPE(objects);#include "lds_search_dlg_.cpp"CLdsSearchDlg::CLdsSearchDlg(objects::CLDS_DatabaseHolder* dbh)    : m_RetVal(eCancel),      m_dbh(dbh){    m_Window.reset(x_CreateWindow());    // Feed aliases into the browser    vector<string> aliases;    dbh->EnumerateAliases(&aliases);    unsigned i = 0;    ITERATE(vector<string>, it, aliases) {        void* tmp_ptr=0;        ::memcpy(&tmp_ptr, &i, sizeof(i));        m_AliasList->add(it->c_str(), tmp_ptr);        if (i == 0) {            m_AliasList->select(i + 1, 1);        }        ++i;    }}EDialogReturnValue CLdsSearchDlg::Show(){    m_RetVal = eCancel;    m_Window->show();    while (m_Window->shown()) {        Fl::wait();    }    return m_RetVal;}void CLdsSearchDlg::x_OnOK(){    m_RetVal = eOK;    m_Window->hide();}void CLdsSearchDlg::x_OnCancel(){    m_RetVal = eCancel;    m_Window->hide();}void CLdsSearchDlg::x_OnGo(){    const char* search_text = m_Text->value();    vector<string> str_vec;    NStr::Tokenize(search_text, " ", str_vec, NStr::eMergeDelims);    CLoaderStrFormatter::PrepareSearchVector(str_vec);    if (str_vec.empty()) {        return;    }    m_List->clear();    CLDS_Database* db = 0;    Fl_Browser* alias_lst = m_AliasList;    {{    for (int i = 1;  i <= alias_lst->size();  ++i) {        int selected = alias_lst->selected(i);        if (selected) {            void* data = alias_lst->data(i);            int db_index;            ::memcpy(&db_index, &data, sizeof(db_index));            db = m_dbh->GetDatabase(db_index);            break;        }            } // for i    }}    if (!db)        db = m_dbh->GetDefaultDatabase();    if (!db)        return;    SLDS_TablesCollection& tables = db->GetTables();    CLDS_Set obj_search_results;    CLDS_Query query(tables);    query.FindSequences(str_vec, &obj_search_results);    query.FindSequences(search_text, &obj_search_results);    CLDS_Set obj_read; // list of objects already loaded    if (obj_search_results.size() == 0) {        LOG_POST(Info                 << "Failed to find local sequence(s).");    }    else {        ITERATE (CLDS_Set, rsit, obj_search_results) {            try {                int object_id = *rsit;                tables.object_db.object_id = object_id;                if (tables.object_db.Fetch() == eBDB_Ok) {                    CLDS_Query::SObjectDescr obj_descr =                         query.GetObjectDescr(db->GetObjTypeMap(), object_id);                    string descr;                    descr = NStr::IntToString(object_id);                    descr.append(" ");                    descr.append(obj_descr.type_str);                    descr.append(" ");                    descr.append(obj_descr.title);                    void* tmp_ptr=0;                    ::memcpy(&tmp_ptr, &object_id, sizeof(object_id));                    m_List->add(descr.c_str(), tmp_ptr);                                    }                            }             catch (CLDS_Exception& _DEBUG_ARG(ex))            {                _TRACE("failed to read LDS file: " << ex.what());                        }        } // ITERATE    }    // Looking for annotations    {{        CLDS_Set slist_search_results;        query.FindSeqIdList(str_vec, &slist_search_results);        ITERATE (CLDS_Set, it, slist_search_results) {            try {                int id = *it;                CLDS_Query::SObjectDescr obj_descr =                   query.GetObjectDescr(db->GetObjTypeMap(), id, true);                string descr;                descr = NStr::IntToString(id);                descr.append(" ");                descr.append(obj_descr.type_str);                descr.append(" ");                descr.append(obj_descr.title);                void* tmp_ptr=0;                ::memcpy(&tmp_ptr, &id, sizeof(id));                m_List->add(descr.c_str(), tmp_ptr);                        }            catch (CLDS_Exception& _DEBUG_ARG(ex))            {                _TRACE("failed to read object: " << ex.what());                        }        } // ITERATE    }}    // Select all rows    for (int i = 1;  i <= m_List->size();  ++i) {        m_List->select(i);    }}END_NCBI_SCOPE/* * =========================================================================== * $Log: lds_search_dlg.cpp,v $ * Revision 1000.2  2004/06/01 20:58:12  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * * Revision 1.10  2004/05/21 22:27:48  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.9  2004/03/16 15:59:50  vasilche * Removed warning about unused exception variable * * Revision 1.8  2004/03/11 18:48:18  kuznets * Made use of the query based FindSequences * * Revision 1.7  2004/01/27 18:45:33  dicuccio * Added missing header files * * Revision 1.6  2003/10/29 16:25:07  kuznets * Added support for LDS aliases. * * Revision 1.5  2003/08/08 15:31:03  kuznets * Turn highlighting on for all found records in the search list after search. * * Revision 1.4  2003/08/07 20:31:35  kuznets * Implemented document opening based on lds_search_dlg selection * * Revision 1.3  2003/08/06 20:58:36  kuznets * Implemented "Go" button action (CLdsSearchDlg::x_OnGo()) * * Revision 1.2  2003/08/05 17:16:25  kuznets * Changes to improve code reuse between loaders + CLDS_Database passed as the * construction parameter to the lds search dialog * * Revision 1.1  2003/07/29 14:35:14  dicuccio * Initial revision of LDS search dialog * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?