NCBI C++ ToolKit
data_track.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: data_track.cpp 46174 2021-01-28 02:26:06Z evgeniev $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Liangshou Wu
27  *
28  */
29 #include <ncbi_pch.hpp>
30 
34 
36 
39  &CDataTrack::OnAJNotification)
41  &CDataTrack::OnAJProgress)
43 
45 {}
46 
47 
49 {}
50 
51 
52 void CDataTrack::Update(bool layout_only)
53 {
54  if (!m_On) {
55  return;
56  }
57 
58  if ( !layout_only && m_Expanded) {
59  // loading the data
60  x_UpdateData();
61  }
63 }
64 
65 
67 {
69  if (ds) {
70  ds->DeleteAllJobs();
71  }
72 }
73 
74 
76 {
78  if (ds) {
79  return ds->AllJobsFinished();
80  }
81  return true;
82 }
83 
84 
86 {
87  CAppJobNotification* notn = dynamic_cast<CAppJobNotification*>(evt);
88  _ASSERT(notn);
90  if (notn) {
91  int job_id = notn->GetJobID();
92 
93  if (job_id != -1 && !x_IsJobNeeded(job_id)) {
95  return;
96  }
97  switch(notn->GetState()) {
99  //LOG_POST(Info << "CDataTrack: completed job:" << job_id);
100  x_OnJobCompleted(*notn);
101  break;
102  case IAppJob::eFailed:
103  x_OnJobFailed(*notn);
104  break;
105  case IAppJob::eCanceled:
106  //x_OnJobCanceled(*notn, *session);
107  break;
108  default:
109  break;
110  } // switch
111  } // notn
112 
114  if (ds && ds->AllJobsFinished() && m_JNotificationDepth == 1) {
116  }
118 }
119 
120 
122 {
123  CAppJobNotification* notn = dynamic_cast<CAppJobNotification*>(evt);
124  _ASSERT(notn);
125  if (notn) {
126  CConstIRef<IAppJobProgress> progress = notn->GetProgress();
127  if (progress) {
128  int p = (int)(progress->GetNormDone() * 100);
129  string msg = kEmptyStr;
130  if ( !progress->GetText().empty() ) {
131  msg = ", " + progress->GetText();
132  }
133 
134  if (p == m_Progress && msg == m_Msg) {
135  return;
136  }
137  x_SetStatus(msg, p);
139  }
140  }
141 }
142 
143 void CDataTrack::x_Expand(bool expand)
144 {
145  if ((m_Attrs & fCollapsible) && !expand) {
146  DeleteAllJobs();
147  }
148  CLayoutTrack::x_Expand(expand);
149 }
150 
151 /* virtual */
153 {
155  if (ds) {
156  return ds->IsJobNeeded(id);
157  }
158  return false;
159 }
160 
161 
162 /* virtual */
164 {
165  STrackErrorStatus errorStatus;
168  errorStatus.m_ShortErrorMsg = "Could not retrieve data";
169  CConstIRef<IAppJobError> appError = notify.GetError();
170  if (appError.NotNull()) {
171  errorStatus.m_ErrorMsg = "Track data loading failed";
172  LOG_POST(Warning << "Track load error detected, message: " << appError->GetText());
173  }
174  SetErrorStatus(errorStatus);
175 
176  SetMsg(", could not retrieve data");
178  if (ds) {
179  ds->ClearJobID(notify.GetJobID());
180  }
181 }
182 
183 
184 /* virtual */
186 {
187  if (GetChildren().empty()) {
188  m_Msg += ", No data";
189  if(!isInErrorStatus()) {
192  "No data in this range",
193  "No track data found in this range"));
194  }
195 }
196  x_SetStatus(m_Msg, 100);
197 }
198 
199 
CAppJobNotification Notification send by CAppJobEventTranslator.
CConstRef –.
Definition: ncbiobj.hpp:1266
CDataTrack - a abstract base class for layout tracks which need to deal with background data retrieva...
Definition: data_track.hpp:55
virtual void x_OnJobFailed(CAppJobNotification &notify)
Definition: data_track.cpp:163
virtual ~CDataTrack()
Definition: data_track.cpp:48
void OnAJNotification(CEvent *evt)
event handlers for job notification event.
Definition: data_track.cpp:85
virtual CRef< CSGGenBankDS > GetDataSource()=0
Method for accessing the data source.
virtual void x_Expand(bool expand)
Collapse or expand the track.
Definition: data_track.cpp:143
virtual void x_UpdateData()=0
update track content.
virtual bool x_IsJobNeeded(CAppJobDispatcher::TJobID id) const
Definition: data_track.cpp:152
virtual void x_OnAllJobsFinished()
Definition: data_track.cpp:185
void OnAJProgress(CEvent *evt)
Definition: data_track.cpp:121
virtual void Update(bool layout_only)
Update content and layout including the bounding box.
Definition: data_track.cpp:52
virtual void x_OnJobCompleted(CAppJobNotification &notify)=0
virtual bool AllJobsFinished() const
Definition: data_track.cpp:75
virtual void DeleteAllJobs()
Definition: data_track.cpp:66
int m_JNotificationDepth
it is possible that OnAJNotification() is recursively called several times and therefore excessively ...
Definition: data_track.hpp:109
CEventHandler.
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
File Description:
const CLayoutGroup::TObjectList & GetChildren() const
virtual void Update(bool layout_only)
Update content and layout including the bounding box.
bool m_Expanded
is this track in expanded state
void SetErrorStatus(const TTrackErrorStatus &ErrorStatus)
virtual void x_Expand(bool expand)
Collapse or expand the track.
string m_Msg
special message need to show on title bar
bool m_On
is this track shown
void x_OnLayoutChanged()
update the layout.
TTrackAttrFlags m_Attrs
various track attributes
bool isInErrorStatus() const
@ fCollapsible
can be collpased and expanded.
void x_SetStatus(const string &msg, int progress)
void SetMsg(const string &msg)
int m_Progress
any job progress index (0 - 100)
CRef –.
Definition: ncbiobj.hpp:618
CRenderingContext offers the basic context and utility methods for rendering layout objects in featur...
ON_EVENT(CAppJobNotification, CAppJobNotification::eStateChanged, &CDataTrack::OnAJNotification) ON_EVENT(CAppJobNotification
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
TErrorCode m_ErrorCode
Definition: track_info.hpp:98
CConstIRef< IAppJobError > GetError() const
returns non-null pointer only if job Failed
TErrorSeverity m_ErrorSeverity
Definition: track_info.hpp:97
CConstIRef< IAppJobProgress > GetProgress() const
returns non-null pointer only if notification type is eProgress
#define END_EVENT_MAP()
Ends definition of Command Map.
#define BEGIN_EVENT_MAP(thisClass, baseClass)
Begins definition of Command Map for CEventHandler-derived class.
TJobState GetState() const
@ eCanceled
Definition: app_job.hpp:91
@ eCompleted
Definition: app_job.hpp:89
@ eFailed
Definition: app_job.hpp:90
bool NotNull(void) const THROWS_NONE
Check if pointer is not null – same effect as NotEmpty().
Definition: ncbiobj.hpp:1410
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
constexpr bool empty(list< Ts... >) noexcept
#define _ASSERT
Modified on Mon Dec 11 02:36:42 2023 by modify_doxy.py rev. 669887