NCBI C++ ToolKit
search_tool_base.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

00001 #ifndef GUI_SERVICES___SEARCH_TOOL_BASE_HPP
00002 #define GUI_SERVICES___SEARCH_TOOL_BASE_HPP
00003 
00004 /*  $Id: search_tool_base.hpp 27848 2013-04-12 18:51:49Z kuznets $
00005  * ===========================================================================
00006  *
00007  *                            PUBLIC DOMAIN NOTICE
00008  *               National Center for Biotechnology Information
00009  *
00010  *  This software/database is a "United States Government Work" under the
00011  *  terms of the United States Copyright Act.  It was written as part of
00012  *  the author's official duties as a United States Government employee and
00013  *  thus cannot be copyrighted.  This software/database is freely available
00014  *  to the public for use. The National Library of Medicine and the U.S.
00015  *  Government have not placed any restriction on its use or reproduction.
00016  *
00017  *  Although all reasonable efforts have been taken to ensure the accuracy
00018  *  and reliability of the software and data, the NLM and the U.S.
00019  *  Government do not and cannot warrant the performance or results that
00020  *  may be obtained by using this software or data. The NLM and the U.S.
00021  *  Government disclaim all warranties, express or implied, including
00022  *  warranties of performance, merchantability or fitness for any particular
00023  *  purpose.
00024  *
00025  *  Please cite the author in any work or product based on this material.
00026  *
00027  * ===========================================================================
00028  *
00029  * Authors:  Andrey Yazhuk
00030  *
00031  * File Description:
00032  *
00033  */
00034 
00035 #include <gui/core/dm_search_tool.hpp>
00036 
00037 #include <gui/utils/app_job.hpp>
00038 #include <gui/utils/event_translator.hpp>
00039 #include <gui/utils/extension.hpp>
00040 
00041 #include <objects/seqloc/Seq_loc.hpp>
00042 
00043 
00044 BEGIN_NCBI_SCOPE
00045 
00046 class IDMSearchForm;
00047 class CAppJobDispatcher;
00048 class CSearchJobBase;
00049 
00050 
00051 ///////////////////////////////////////////////////////////////////////////////
00052 /// CSearchToolBase
00053 
00054 class  NCBI_GUICORE_EXPORT  CSearchToolBase :
00055     public CObjectEx,
00056     public IExtension,
00057     public CEventHandler,
00058     public IDMSearchTool
00059 {
00060     DECLARE_EVENT_MAP();
00061 public:
00062     enum EPatternType   {
00063         eExactMatch,
00064         eWildcard,
00065         eRegexp,
00066         eNamed
00067     };
00068 
00069     CSearchToolBase();
00070     virtual ~CSearchToolBase();
00071 
00072     /// @name IUITool interface
00073     /// @{
00074     virtual IUITool* Clone() const = 0;
00075     virtual string   GetName() const = 0;
00076     virtual string   GetDescription() const = 0;
00077     /// @}
00078 
00079     /// @name IDMSearchTool implementation
00080     /// @{
00081     virtual CIRef<IDMSearchForm>  CreateSearchForm() = 0;
00082     virtual bool    IsCompatible(IDataMiningContext* context) = 0;
00083     virtual bool    StartSearch(IDMSearchQuery& query, IDMSearchFormController& listener);
00084     virtual bool    CancelSearch(IDMSearchFormController& listener);
00085     virtual bool    PullSearch(IDMSearchQuery& query, IDMSearchFormController& listener);
00086     virtual string  GetJobDescr(IDMSearchFormController& form);
00087     /// @}
00088 
00089     /// CAppJobDispatcher notification handler
00090     void    OnAJNotification(CEvent* evt);
00091     void    OnProgress(CEvent* evt);    
00092 
00093     /// special flags
00094     virtual IDMSearchTool::TUIToolFlags GetFlags(void);
00095 
00096     // conversions
00097     virtual IDMSearchTool::TConversions & GetConversions(void);
00098 
00099     // filters
00100     virtual IDMSearchTool::TFilters & GetFilters(void);
00101     virtual void  SetFilters(IDMSearchTool::TFilters & filters);
00102 
00103     /// String representation of pattern type
00104     static string GetPatternTypeStr(EPatternType ptype);
00105 
00106 protected:
00107     struct SSession    {
00108         CIRef<IDMSearchQuery>       m_Query;
00109         IDMSearchFormController*    m_Listener;
00110         int m_JobID;
00111         string  m_Descr;
00112     };
00113 
00114     /// create a job based on the given query, override in derived classes
00115     virtual CRef<CSearchJobBase> x_CreateJob(IDMSearchQuery& query) = 0;
00116 
00117     int x_GetSessionIndexByID(int job_id);
00118     int x_GetSessionIndexByQuery(IDMSearchQuery& query);
00119     int x_GetSessionIndexByListener(IDMSearchFormController& listener);
00120 
00121     virtual void    x_OnJobCompleted(CAppJobNotification& notify, SSession& session);
00122     virtual void    x_OnJobFailed(CAppJobNotification& notify, SSession& session);
00123     virtual void    x_OnJobCanceled(CAppJobNotification& notify, SSession& session);
00124 
00125 protected:
00126     string  m_Name;
00127 
00128     int                             m_ReportPeriod;
00129     vector<SSession*>               m_Sessions;
00130     IDMSearchTool::TConversions     m_Conversions;
00131     IDMSearchTool::TFilters         m_Filters;
00132     
00133     CRef<CObjectList>               m_Cache;  
00134 };
00135 
00136 
00137 ///////////////////////////////////////////////////////////////////////////////
00138 /// CSearchQueryBase
00139 class NCBI_GUICORE_EXPORT CSearchQueryBase :
00140     public CObject,
00141     public IDMSearchQuery
00142 {
00143 public:
00144    struct  SScopedLoc  {
00145         CRef<objects::CSeq_loc> m_Loc;
00146         CRef<objects::CScope>   m_Scope;
00147         string  m_ContextName;
00148     };
00149     typedef vector<SScopedLoc>   TScopedLocs;
00150 
00151     CSearchQueryBase(TScopedLocs& locs) {   m_ScopedLocs = locs;    }
00152 
00153     TScopedLocs&  GetScopedLocs()   {   return m_ScopedLocs;    }
00154 
00155 protected:
00156     TScopedLocs m_ScopedLocs;
00157 };
00158 
00159 
00160 ///////////////////////////////////////////////////////////////////////////////
00161 /// CSearchJobBase
00162 ///
00163 class NCBI_GUICORE_EXPORT CSearchJobBase : public CJobCancelable
00164 {
00165 public:
00166     typedef CSearchToolBase::EPatternType   TPatternType;
00167 
00168     CSearchJobBase();
00169     virtual ~CSearchJobBase();
00170 
00171     /// @name IAppJob implementation
00172     /// @{
00173     virtual EJobState   Run();
00174     virtual CConstIRef<IAppJobProgress> GetProgress();
00175     virtual CRef<CObject>               GetResult();
00176     virtual CConstIRef<IAppJobError>    GetError();
00177     virtual string    GetDescr() const;
00178     /// @}
00179 
00180     void  SetFilters(IDMSearchTool::TFilters & filters) {m_Filters = filters;}
00181 
00182     int GetResultsCount() const { return m_ResultsCount; }
00183     int GetMaxResultsCount() const { return m_MaxResultsCount; }
00184 
00185 
00186 protected:
00187     /// returns true if Job params are correct, implement in derived classes
00188     virtual bool    x_ValidateParams() = 0;
00189 
00190     virtual void    x_PrepareSearch();
00191 
00192     /// performs searching, assuming that params are correct;
00193     /// Implement in derived classes
00194     virtual EJobState   x_DoSearch() = 0;
00195 
00196     /// add custom columns if needed
00197     virtual void    x_SetupColumns(CObjectList& obj_list);
00198 
00199     /// transfer data from Temp Results to Final
00200     virtual void    x_TransferResults();
00201 
00202     /// factory method creating new column handler for CObjectListWidget
00203     //NCBI_DEPRECATED virtual IObjectColumnHandler* x_GetColumnHandler() const;
00204 
00205     /// factory method creating new model for CObjectListWidget
00206     virtual CObjectListTableModel* x_GetNewOLTModel() const;
00207     
00208     // this function just needs info about OLT model
00209     friend bool CSearchToolBase::PullSearch(IDMSearchQuery& query, IDMSearchFormController& listener);
00210 
00211    
00212 protected:
00213     /// human-readable description of the Job
00214     string  m_Descr;
00215 
00216     /// synchronizes access to the Job members
00217     CMutex  m_Mutex;
00218 
00219     CRef<CAppJobError>  m_Error;
00220 
00221     /// total number of results
00222     int m_ResultsCount;
00223     /// Max possible results count
00224     int m_MaxResultsCount;
00225 
00226     /// accumulates found objects before they are transferred to m_ResultList
00227     CObjectList m_AccList;
00228 
00229     /// holds temporary results, guarded by Mutex
00230     CRef<CDMSearchResult> m_TempResult;
00231 
00232     string  m_ProgressStr; /// guarded by Mutex
00233 
00234     CRef<CDMSearchResult> m_Result; /// holds the final results
00235     
00236     IDMSearchTool::TFilters         m_Filters;
00237 };
00238 
00239 
00240 END_NCBI_SCOPE
00241 
00242 #endif  // GUI_SERVICES___SEARCH_TOOL_BASE_HPP
Modified on Thu Sep 18 17:57:53 2014 by modify_doxy.py rev. 426318