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

Go to the SVN repository for this file.

1 /* $Id: document.cpp 46074 2021-01-21 19:47:47Z grichenk $
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  * Author: Vladimir Tereshkov, Andrey Yazhuk
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
32 
33 #include <gui/core/document.hpp>
34 
45 
48 #include <gui/utils/extension.hpp>
49 
52 
54 
55 #include <gui/objutils/label.hpp>
57 
59 
60 /// specific supported project versions
71 
75 
78 #include <objects/general/Date.hpp>
81 
82 #include <serial/objistr.hpp>
83 #include <serial/serial.hpp>
84 #include <serial/pack_string.hpp>
85 #include <serial/objostr.hpp>
86 #include <serial/iterator.hpp>
87 
88 #include <corelib/rwstream.hpp>
89 
91 
93 
94 #include <wx/filename.h>
95 
98 
99 static const char* kLoaderName = "Loader Name";
100 
101 /////////////////////////////////////////////////////////////////////////////
102 /// CGBDocument
103 
105  : m_Service(srv)
106  , m_UndoManager(new CUndoManager(x_GetUndoSize(), this))
107  , m_AssemblyInitialized(false)
108 {
109  m_Id = GetNextId();
110  LOG_POST(Info << "CGBDocument empty constructor");
111 }
112 
114  : CGBProjectHandle(proj_impl)
115  , m_Service(srv)
116  , m_UndoManager(new CUndoManager(x_GetUndoSize(), this))
117  , m_AssemblyInitialized(false)
118 {
119  m_Id = id;
120  LOG_POST(Info << "CGBDocument(src, id, CGBProject_ver2) id = " << id << " " << this);
121 }
122 
123 
125 {
126  for (auto& i : m_JobAdapters)
127  i->Cancel();
128 
129  LOG_POST(Info << "CGBDocument::~CGBDocument");
130 }
131 
132 wxString CGBDocument::GetFileName() const
133 {
135 }
136 
137 void CGBDocument::SetFileName (const wxString& filename)
138 {
140 }
141 
143 {
146  return m_AssemblyAccession;
147 }
148 
150 {
151  m_AssemblyAccession.erase();
152 
153  if (!IsLoaded()) {
154  m_AssemblyInitialized = false;
155  return;
156  }
157 
158  m_AssemblyInitialized = true;
159  const CGC_Assembly* assembly = 0;
160  for (CTypeConstIterator<CProjectItem> it(GetData()); it; ++it) {
161  const CGC_Assembly* obj = dynamic_cast<const CGC_Assembly*>((*it).GetObject());
162  if (obj) {
163  if (assembly) return; // Several assemblies in project
164  assembly = obj;
165  }
166  }
167 
168  if (assembly)
169  m_AssemblyAccession = assembly->GetAccession();
170 }
171 
173 {
174  m_AssemblyAccession.erase();
175  m_AssemblyInitialized = false;
176 }
177 
179 {
180  LOG_POST(Info << "CGBDocument::CreateProjectScope() " << this);
181 
182  _ASSERT( ! GetScope());
183 
185  CRef<CScope> scope(new CScope(*obj_mgr));
186  scope->AddDefaults();
187  SetScope(scope.GetPointer());
188 }
189 
190 class CDocLoadingJob : public CAppJob
191 {
192 public:
193  CDocLoadingJob(CGBDocument& doc, const wxString& path)
194  : CAppJob("Load Project Job"), m_Document(&doc), m_Path(path) {}
195 
196  /// @name IAppJob implementation
197  /// @{
198  virtual EJobState Run();
199  /// @}
200 
201 protected:
203  wxString m_Path;
204 };
205 
207 {
208  IViewManagerService* view_srv = serviceLocator->GetServiceByType<IViewManagerService>();
210  view_srv->GetViews(views);
212  CProjectTreeView* projectTree = dynamic_cast<CProjectTreeView*>((*it).GetPointer());
213  if (projectTree)
214  return dynamic_cast< CProjectTreePanel*>(projectTree->GetWindow());
215  }
216 
217  return 0;
218 }
219 
221 {
223  if (projectTree) projectTree->UpdateViewLabel(*this, view);
224 }
225 
227 {
229  if (projectTree) projectTree->ProjectStateChanged(*this);
230  x_ClearAssembly();
231 }
232 
234 {
236  if (projectTree) projectTree->ProjectViewsChanged(*this);
237 }
238 
240 {
242  if (projectTree) projectTree->ProjectUpdateItems(*this);
243  x_ClearAssembly();
244 }
245 
247 {
249  if (projectTree) projectTree->ProjectUpdateLabel(*this);
250 }
251 
252 IAppJob* CGBDocument::CreateLoadJob(const wxString& fileName)
253 {
254  if (IsLoaded() || m_LoadJob)
255  return 0;
256 
257  m_LoadJob.Reset(new CDocLoadingJob(*this, fileName));
258 
260 
261  return m_LoadJob.GetPointer();
262 }
263 
265 {
266  return m_LoadJob;
267 }
268 
270 {
271  if (m_LoadJob) {
272  m_LoadJob->RequestCancel();
273  m_LoadJob.Reset();
275  }
276 }
277 
279 {
280  m_LoadJob.Reset();
281 }
282 
284 {
286 
287  if (!ok) {
288  if (IsCanceled())
289  return eCanceled;
290 
291  string s = "Failed to load project: \"" + string(m_Path.ToUTF8()) + "\".";
292  CFastMutexGuard lock(m_Mutex);
293  m_Error.Reset(new CAppJobError(s));
294  return eFailed;
295  }
296 
297  _ASSERT(m_Document->GetScope() == NULL);
300 
301  if (IsCanceled())
302  return eCanceled;
303 
304  m_Document->SetLoaded();
305 
306  return eCompleted;
307 }
308 
309 /// NULL stream writer for test serialization
310 class CNullWriter : public IWriter
311 {
312 public:
313  ERW_Result Write(const void* buf, size_t count, size_t* bytes_written)
314  {
315  if (bytes_written) {
316  *bytes_written = count;
317  }
318  return eRW_Success;
319  }
320 
322  {
323  return eRW_Success;
324  }
325 };
326 
327 /// Attach a view to the current document
329 {
330  _ASSERT(view);
331 
332  m_Views.push_back(CIRef<IProjectView>(view));
333 
334  x_AssignViewIndex(view);
335 
336  // event routing
337  CEventHandler* handler = dynamic_cast<CEventHandler*>(view);
338  if(handler) {
340  handler->AddListener(this);
341  }
342 
344 }
345 
346 
347 /// detach a view from the current document
349 {
350  _ASSERT(view);
351 
352  CIRef<IProjectView> ref(view);
353 
354  // unregister event handling
355  CEventHandler* handler = dynamic_cast<CEventHandler*>(view);
356  if (handler) {
358  handler->RemoveListener(this);
359  }
360 
361  m_ViewToIndex.erase(view);
362  TViews::iterator it = std::find(m_Views.begin(), m_Views.end(), ref);
363  m_Views.erase(it);
364 
366 
368 }
369 
370 
372 {
373  _ASSERT(view);
374  const string& title = view->GetClientLabel();
375  int max_index = -1;
376 
378  IProjectView* v = it->first;
379  if (v->GetClientLabel() == title) { // view of the same type
380  max_index = max(max_index, it->second);
381  }
382  }
383  m_ViewToIndex[view] = max_index + 1;
384 }
385 
386 
387 /// Retrieve the existing views for this class
389 {
390  return m_Views;
391 }
392 
393 
395 {
396  return m_Views;
397 }
398 
400 {
401  TEvent* ev = new TEvent( GetId(), subtype );
403  Send( CRef<CEvent>( ev ) );
404  else
405  Post( CRef<CEvent>( ev ) );
406 }
407 
409 {
410  TEvent ev( view, type );
411 
412  Send( &ev );
413 }
414 
415 /*
416 void CGBDocument::x_PostViewEvent( IProjectView& view, CViewEvent::EEventType type )
417 {
418  TEvent* ev = new TEvent( view, TEvent::eProjectChanged );
419  //ev->m_View.Reset( &view );
420 
421  CRef<CEvent> evt( ev );
422  Post( evt );
423 }
424 */
425 
427 {
428  string filename;
429 
430  STempFileLocker(const string& tmp_name)
431  : filename(tmp_name)
432  {
433  }
434 
435  void Lock()
436  {
437  }
438 
439  void Unlock()
440  {
441  if ( !filename.empty() ) {
442  CFile(filename).Remove();
443  }
444  }
445 };
446 
447 bool CGBDocument::LoadFile(const wxString& fname, ICanceled* canceledCallback)
448 {
449  unique_ptr<CNcbiIfstream> istr;
450  string tmp_name;
451  if (fname.StartsWith(wxT("http://")) || fname.StartsWith(wxT("https://"))
452  || fname.StartsWith(wxT("ftp://"))) {
453 
454  unique_ptr<CNcbiIstream> is;
455  if (fname.StartsWith(wxT("http"))) { // this covers both http:// and https://
456  // we always open with the *full* path - this will pass params on
457  // the command line and log them in the weblogs.
458  unique_ptr<CConn_HttpStream> http_str(new CConn_HttpStream(ToStdString(fname)));
459  is.reset(http_str.release());
460  } else {
461  // For FTP connections, we need to separate host name from the path name
462  // separate the host to contact
463  string _fname = ToStdString(fname);
464  string host = _fname;
465  string::size_type pos = host.find_first_of("/", 6);
466  if (pos != string::npos) {
467  host.erase(pos);
468  }
469  host.erase(0, 6);
470 
471  // separate the path to retrieve
472  string path;
473  if (pos != string::npos) {
474  path = _fname.substr(pos, _fname.length() - pos);
475  }
476 
477  // separate the file name
478  //SOCK_SetDataLoggingAPI(eOn);
479  is.reset(new CConn_FTPDownloadStream(host, path));
480  }
481 
482  /// we will be trying a number of things here, so create a
483  /// temporary file stream for this
484  tmp_name = CFile::GetTmpName();
485  {{
486  CNcbiOfstream ostr(tmp_name.c_str(), ios::binary);
487  NcbiStreamCopy(ostr, *is);
488  }}
489  istr.reset(new CNcbiIfstream(tmp_name.c_str(), ios::binary|ios::in));
490 
491  } else {
492  /// default file connection
493  istr.reset(new CNcbiIfstream(fname.fn_str(), ios::binary|ios::in));
494  }
495  _ASSERT(istr.get());
496 
497  STempFileLocker tmp_file(tmp_name);
498  CGuard<STempFileLocker> LOCK(tmp_file);
499 
500  return CGBProjectHandle::Load(*istr, canceledCallback);
501 }
502 
503 void CGBDocument::Save(const wxString& abs_path)
504 {
506  /// configuration parameters controlling serialization
507 
508  /// should the application keep back-up files?
509  bool keep_backups =
510  reg.GetBool("GBENCH.Application.IO.KeepBackups", true);
511 
512  /// do we serialize in text or binary mode?
513  /// we have a compiled-in default and a user-override
514  ESerialDataFormat fmt =
515 #ifdef _DEBUG
517 #else
519 #endif
520  {{
521  string fmt_str = reg.GetString("GBENCH.Application.IO.SerialFormat");
522  if (NStr::CompareNocase(fmt_str, "text") == 0) {
523  fmt = eSerial_AsnText;
524  } else if (NStr::CompareNocase(fmt_str, "binary") == 0) {
525  fmt = eSerial_AsnBinary;
526  }
527  }}
528 
529  // save view-specific settings
530  try {
531  ITERATE (TViews, iter, m_Views) {
532  const IViewSettingsAtProject* setts =
533  dynamic_cast<const IViewSettingsAtProject*>(iter->GetPointer());
534  if (setts)
535  setts->SaveSettingsAtProject(*this);
536  }
537  } NCBI_CATCH("Exception while saving view settings to project");
538 
540  [this, &abs_path, fmt, keep_backups](ICanceled&) { this->x_SaveFile(abs_path, fmt, keep_backups); },
541  wxT("Saving Project..."));
542 
544 }
545 
546 
547 void CGBDocument::x_SaveFile(const wxString& fname, ESerialDataFormat fmt, bool keep_backups)
548 {
549  string fileName(fname.ToUTF8());
550 
551  LOG_POST(Info << "CGBDocument::x_SaveFile(" << fileName << ")");
552 
553  ///
554  /// step 1: write to a new file
555  /// we avoid overwriting an existing file before we are sure that
556  /// serialization has succeeded
557  ///
558 
559  bool serialization_success = true;
560  wxString serialized_fname;
561  try {
562  /// rename the existing file, if any
563  serialized_fname = fname;
564  for (int i = 1; ; ++i) {
565  wxString f = wxString::Format(wxT("%s.%d"), fname.c_str(), i);
566  if ( !::wxFileExists(f) ) {
567  serialized_fname = f;
568  break;
569  }
570  }
571 
572  CNcbiOfstream ostr(serialized_fname.fn_str(), ios::binary);
573  CGBProjectHandle::Save(ostr, fmt);
574  }
575  catch (std::exception& e) {
576  LOG_POST(Error << "CGBProjectHandle::Save(" << fname
577  << "): error in serialization: " << e.what());
578  serialization_success = false;
579  }
580 
581  /// scan the serialized file to make sure that nothing bad happened
582  if (serialization_success) {
583  try {
584  CNcbiIfstream istr(serialized_fname.fn_str(), ios::binary);
585  unique_ptr<CObjectIStream> is(CObjectIStream::Open(fmt, istr));
586 
587  const IGBProject& project = GetProject();
588  switch (project.GetVersion()) {
590  is->Skip(CGBProject::GetTypeInfo());
591  break;
592 
594  is->Skip(CGBProject_ver2::GetTypeInfo());
595  break;
596 
597  default:
598  _ASSERT(false);
599  NCBI_THROW(CException, eUnknown, "Unknown project version");
600  break;
601  }
602  is->Close();
603  if ( !istr ) {
604  NCBI_THROW(CException, eUnknown, "stream read failure");
605  }
606  }
607  catch (std::exception& e) {
608  LOG_POST(Error << "CGBProjectHandle::Save(" << fname
609  << "): error in scanning file: " << e.what());
610  serialization_success = false;
611  }
612  }
613 
614  if ( !serialization_success ) {
615 #ifndef _DEBUG
616  /// in debug mode, we preserve our bread-crumbs
617  ::wxRemoveFile(serialized_fname);
618 #endif
619 
620  string msg("An error occurred while saving '");
621  msg += fname.ToUTF8();
622  msg += "'.\n";
623  if ( ::wxFileExists(fname) ) {
624  msg += "The original file was not overwrtten and should be safe.\n";
625  }
626  msg += "\nYou can try to save the file again, or optionally\n";
627  msg += "export any project items individually to preserve the data.";
629  }
630 
631  ///
632  /// success!
633  ///
634 
635  /// rename the existing file, if any
636  if (keep_backups) {
637  wxString backup_fname = fname + wxT(".bak");
638  if (::wxFileExists(backup_fname))
639  ::wxRemoveFile(backup_fname);
640  if (::wxFileExists(fname))
641  ::wxRenameFile(fname,backup_fname);
642  } else if (::wxFileExists(fname)) {
643  ::wxRemoveFile(fname);
644  }
645  ::wxRenameFile(serialized_fname, fname);
646 }
647 
649 {
650  static int undoSize = -1;
651  if (undoSize == -1) {
652  undoSize = 25;
653  try {
654  CRegistryReadView view = CGuiRegistry::GetInstance().GetReadView("GBENCH.Project.Settings");
655  undoSize = view.GetInt("UndoBufferSize", undoSize);
656  }
657  catch (const exception&) {
658  }
659  }
660  return (size_t)undoSize;
661 }
662 
663 static void s_AttachProjectItem(CProjectItem& item, CScope& scope)
664 {
666  handles->Attach(scope, item);
667  item.SetUserObject(handles);
668  item.SetDisabled(false);
669 }
670 
671 static void s_DetachProjectItem(CProjectItem& item, CScope& scope)
672 {
673  CAttachedHandles* handles = dynamic_cast<CAttachedHandles*>(item.GetUserObject());
674  if (handles)
675  handles->Detach(scope);
676  item.SetDisabled(true);
677 }
678 
679 static void s_CallExtensionProjectItemAttached(CGBDocument& doc, vector<IProjectItemExtension*>& clients, CProjectItem& item, IServiceLocator* srvLocator)
680 {
681  ITERATE(vector<IProjectItemExtension*>, it, clients) {
682  string extName = "Unknown extension";
683  IExtension* ext = dynamic_cast<IExtension*>(*it);
684  if (ext) extName = ext->GetExtensionIdentifier();
685  try {
686  (*it)->ProjectItemAttached(item, doc, srvLocator);
687  } NCBI_CATCH("Project item attached \"" + extName + "\" error.");
688  }
689 }
690 
691 static void s_CallExtensionProjectItemDetached(CGBDocument& doc, vector<IProjectItemExtension*>& clients, CProjectItem& item, IServiceLocator* srvLocator)
692 {
693  ITERATE(vector<IProjectItemExtension*>, it, clients) {
694  string extName = "Unknown extension";
695  IExtension* ext = dynamic_cast<IExtension*>(*it);
696  if (ext) extName = ext->GetExtensionIdentifier();
697  try {
698  (*it)->ProjectItemDetached(item, doc, srvLocator);
699  } NCBI_CATCH("Project item detached \"" + extName + "\" error.");
700  }
701 }
702 
704 {
705  const CSerialObject* obj = item.GetObject();
706  if (obj) {
707  set<IProjectView*> viewToDelete;
709  for (TViews::iterator it = m_Views.begin(); it != m_Views.end(); ++it) {
711  (*it)->GetMainObject(objects);
712  for (TConstScopedObjects::const_iterator it2 = objects.begin(); it2 != objects.end(); ++it2) {
713  const CObject* object = it2->object.GetPointer();
714  if (object == obj)
715  viewToDelete.insert(*it);
716  else
717  objToView[object] = it->GetPointer();
718  }
719  }
720 
721  if (!objToView.empty()) {
722  for (CObjectConstIterator it(*obj); it; ++it) {
724  if (it2 != objToView.end()) {
725  viewToDelete.insert(it2->second);
726  }
727  }
728  }
729 
730  ITERATE (set<IProjectView*>, it, viewToDelete) {
732  }
733  }
734 }
735 
737 {
738  if (!item) return false;
739  vector<CProjectItem*> items;
740  items.push_back(item);
741  return RemoveProjectItems(items);
742 }
743 
744 bool CGBDocument::RemoveProjectItems(const vector<CProjectItem*>& items)
745 {
747  x_DetachProjectItems(items);
749 
750  bool removed = false;
751 
752  for (size_t i = 0; i < items.size(); ++i) {
753  CProjectItem* item = items[i];
754  if (!item) continue;
755 
756  int id = item->GetId();
757  CProjectFolder* folder = SetData().FindProjectItemFolder(id);
758  if (!folder || folder->GetProjectItem(id) != item) continue;
759  folder->RemoveChildItem(id);
760  removed = true;
761  }
762 
763  if (removed) {
764  SetDirty (true);
766  return true;
767  }
768 
769  return false;
770 }
771 
773 {
774  if (!item) return;
775  vector<CProjectItem*> items;
776  items.push_back(item);
777  AttachProjectItems(items);
778 }
779 
781 {
782  if (!item) return;
783  vector<CProjectItem*> items;
784  items.push_back(item);
785  DetachProjectItems(items);
786 }
787 
788 void CGBDocument::AttachProjectItems(const vector<CProjectItem*>& items)
789 {
791 
792  CScope* scope = GetScope();
793  _ASSERT(scope);
794 
795  for (size_t i = 0; i < items.size(); ++i) {
796  CProjectItem* item = items[i];
797  if (!item) continue;
798 
799  s_AttachProjectItem(*item, *scope);
800 
801  vector<IProjectItemExtension*> clients;
803  if (!clients.empty()) {
805  }
806  }
807 
809 }
810 
811 void CGBDocument::DetachProjectItems(const vector<CProjectItem*>& items)
812 {
814  x_DetachProjectItems(items);
816 }
817 
818 bool CGBDocument::x_DetachProjectItems(const vector<CProjectItem*>& items)
819 {
820  vector<CProjectItem*> enabled;
821 
822  for (size_t i = 0; i < items.size(); ++i) {
823  CProjectItem* item = items[i];
824  if (item && item->IsEnabled()) {
825  vector<IProjectItemExtension*> clients;
827  if (!clients.empty()) {
829  }
831  enabled.push_back(item);
832  }
833  }
834 
835  CScope* scope = GetScope();
836  _ASSERT(scope);
837 
838  if (!enabled.empty()) {
840  [&enabled, scope](ICanceled&)
841  {
842  for (auto pi : enabled)
843  s_DetachProjectItem(*pi, *scope);
844  },
845  wxT("Unloading project item..."));
846  return true;
847  }
848 
849  return false;
850 }
851 
852 class CAddItemsData : public CObject
853 {
854 public:
855  CAddItemsData(const string& folderName,
856  vector<CRef<CProjectItem> >& items,
857  const CGBDocument::TLoaders& loaders) :
858  m_FolderName(folderName), m_Items(items), m_Loaders(loaders) {}
859 
860  const string& GetFolderName() const { return m_FolderName; }
861  vector<CRef<CProjectItem> >& GetProjectItems() { return m_Items; }
862  const CGBDocument::TLoaders& GetLoaders() const { return m_Loaders; }
863 
864 private:
865  string m_FolderName;
866  vector<CRef<CProjectItem> > m_Items;
868 };
869 
871 {
872 public:
874  : m_Data(&data), m_Scope(&scope), m_Descr("Attach Project Items") {}
876 
877  /// @name IAppJob implementation
878  /// @{
879  virtual string GetDescr() const { return m_Descr; }
880  virtual EJobState Run()
881  {
882  m_Error.Reset(new CAppJobError("N/A"));
883  for (auto& i : m_Data->GetProjectItems()) {
884  if (IsCanceled()) return eCanceled;
886  }
887  if (IsCanceled()) return eCanceled;
888  return eCompleted;
889  }
891  {
893  }
895  {
896  return CRef<CObject>(m_Data.GetPointer());
897  }
899  {
901  }
902  /// @}
903 
904 protected:
905  virtual string x_GetJobName() const { return m_Descr; }
906 
907 private:
911  string m_Descr;
912 };
913 
915 {
916  CAddItemsData* data = dynamic_cast<CAddItemsData*>(result);
917  if (data) {
918  x_AddItems(data->GetFolderName(), data->GetProjectItems(), data->GetLoaders());
919  }
920 
921  for (list<CRef<CJobAdapter> >::iterator
922  it = m_JobAdapters.begin(); it != m_JobAdapters.end(); ++it) {
923  if ((*it).GetPointer() == &adapter) {
924  m_JobAdapters.erase(it);
925  break;
926  }
927  }
928 }
929 
930 void CGBDocument::OnJobFailed(const string&, CJobAdapter& adapter)
931 {
932  for (list<CRef<CJobAdapter> >::iterator
933  it = m_JobAdapters.begin(); it != m_JobAdapters.end(); ++it) {
934  if ((*it).GetPointer() == &adapter) {
935  m_JobAdapters.erase(it);
936  break;
937  }
938  }
939 }
940 
941 void CGBDocument::AddItems(const string& folderName,
942  vector<CRef<CProjectItem> >& items,
943  const TLoaders& loaders)
944 {
945  // Make unique project item names
946  CUniqueLabelGenerator itemNames;
947  for (CTypeConstIterator<CProjectItem> it(GetData()); it; ++it)
948  itemNames.AddExistingLabel(it->GetLabel());
949 
950  CScope& scope = *GetScope();
951 
952  for (size_t i = 0; i < items.size(); ++i) {
953  CProjectItem& item = *items[i];
954 
955  // make sure item has a label, create it if needed
956  if (!item.IsSetLabel() || item.GetLabel().empty()) {
957  CLabel::SetLabelByData(item, &scope);
958  }
959 
960  // make sure the label is unique
961  string label = item.GetLabel();
962  string uniqueLabel = itemNames.MakeUniqueLabel(label);
963  itemNames.AddExistingLabel(uniqueLabel);
964  if (label != uniqueLabel) {
965  item.SetLabel(uniqueLabel);
966 
967  if (item.GetItem().IsAnnot()) {
968  CSeq_annot& annot = item.SetItem().SetAnnot();
969  if (annot.CanGetDesc()) {
970  for (auto& d : annot.SetDesc().Set()) {
971  if (d->IsName()) {
972  if (d->GetName() == label)
973  d->SetName(uniqueLabel);
974  break;
975  }
976  }
977  }
978  }
979  }
980  }
981 
983 
984  CRef<CJobAdapter> adapter(new CJobAdapter(*this));
985  CRef<CAddItemsData> data(new CAddItemsData(folderName, items, loaders));
987  adapter->Start(*job);
988  m_JobAdapters.push_back(adapter);
989 
990  CAppJobDispatcher::TJobID jobId = adapter->GetJobId();
991  if (jobId != CAppJobDispatcher::eInvalidJobID) {
993 
994  string projName = "N/A";
995  if (IsLoaded()) {
996  const objects::CProjectDescr& descr = GetDescr();
997  projName = descr.GetTitle();
998  }
999  string msg = "Adding items to \"" + projName + "\"";
1000  CIRef<IAppTask> task(new CJobUITask(msg, jobId));
1001  CAppTaskService* task_srv = srvLocator->GetServiceByType<CAppTaskService>();
1002  if (task_srv) task_srv->AddTask(*task);
1003  }
1004 }
1005 
1006 
1007 void CGBDocument::x_AddItems(const string& folderName,
1008  vector<CRef<CProjectItem> >& items,
1009  const TLoaders& loaders)
1010 {
1011  CProjectFolder* folder = 0;
1012  CProjectFolder& topFolder = SetData();
1013  if (!folderName.empty()) {
1014  folder = topFolder.FindChildFolderByTitle(folderName);
1015  if (folder == 0) {
1016  CRef<CProjectFolder> new_folder(new CProjectFolder());
1017  CFolderInfo& info = new_folder->SetInfo();
1018  info.SetTitle(folderName);
1019  info.SetComment(folderName);
1020  info.SetCreate_date().SetToTime(CTime(CTime::eCurrent));
1021  topFolder.AddChildFolder(*new_folder);
1022  folder = new_folder;
1023  }
1024  } else {
1025  folder = &topFolder;
1026  }
1027 
1028  for (size_t i = 0; i < items.size(); ++i)
1029  AddItem(*items[i], *folder);
1030 
1031  CUniqueLabelGenerator loaderNames;
1032  if (GetProject().IsSetDataLoaders()) {
1033  ITERATE (IGBProject::TDataLoaders, iter, GetProject().GetDataLoaders()) {
1034  const string& s = (*iter)->GetLabel();
1035  loaderNames.AddExistingLabel(s);
1036  }
1037  }
1038 
1039  ITERATE (TLoaders, it, loaders) {
1040  TLoaderRef loader = *it;
1041 
1042  const string& loader_type = loader->GetLoader_type();
1043 
1044  IDataLoaderProvider* data_source = x_GetDataSourceByType(loader_type);
1045  if (data_source != 0) {
1046  string loader_name = data_source->GetLoaderName(loader->GetData());
1047 
1048  bool loaded = false;
1049 
1050  NON_CONST_ITERATE (IGBProject::TDataLoaders, it2, GetDataLoaders()) {
1051  CLoaderDescriptor& curr_loader = **it2;
1052  if (curr_loader.GetLoader_type() != loader_type) continue;
1053 
1054  string curr_name = data_source->GetLoaderName(curr_loader.GetData());
1055  if (curr_name == loader_name) {
1056  loaded = true;
1057  break;
1058  }
1059  }
1060  if (loaded)
1061  continue;
1062  }
1063 
1064  string label = loader->GetLabel();
1065  string uniqueLabel = loaderNames.MakeUniqueLabel(label);
1066  if (label != uniqueLabel)
1067  loader->SetLabel(uniqueLabel);
1068  loaderNames.AddExistingLabel(uniqueLabel);
1069 
1070  AddDataLoader(*loader);
1071  AttachDataLoader(*loader);
1072  }
1073 
1074  vector<IProjectItemExtension*> clients;
1076  if (!clients.empty()) {
1077  IServiceLocator* srvLocator = m_Service->GetServiceLocator();
1078  for (size_t i = 0; i < items.size(); ++i)
1079  s_CallExtensionProjectItemAttached(*this, clients, *items[i], srvLocator);
1080  }
1081 
1082  SetDirty (true);
1085 }
1086 
1088 {
1089  if (!loader.GetEnabled() || DetachDataLoader(loader)) {
1090  if (m_Project->IsSetDataLoaders()) {
1091  TDataLoaders& loaders = m_Project->SetDataLoaders();
1092  NON_CONST_ITERATE (IGBProject::TDataLoaders, iter, loaders) {
1093  if ((*iter)->GetLabel() == loader.GetLabel()) {
1094  loaders.erase(iter);
1095  break;
1096  }
1097  }
1098  }
1099  LOG_POST(Info << "Data loader: " << loader.GetLabel() << " is removed!");
1100  return true;
1101  }
1102  return false;
1103 }
1104 
1105 
1107 {
1108  IServiceLocator* srv_locator = m_Service->GetServiceLocator();
1110  srv_locator->GetServiceByType<CUIDataSourceService>();
1112  srv->GetDataSources(data_sources);
1113 
1114  // find the matched one
1115  IDataLoaderProvider* data_source = NULL;
1116  for (size_t i = 0; i < data_sources.size(); ++i) {
1117  CIRef<IUIDataSource> ds = data_sources[i];
1118  IExtension* ext = dynamic_cast<IExtension*>(&ds->GetType());
1119  if (ext && ext->GetExtensionIdentifier() == type) {
1120  data_source = dynamic_cast<IDataLoaderProvider*>(&*ds);
1121  break;
1122  }
1123  }
1124 
1125  return data_source;
1126 }
1127 
1128 
1130 {
1131  _ASSERT(IsLoaded());
1132 
1133  IDataLoaderProvider* data_source = x_GetDataSourceByType(loader.GetLoader_type());
1134  if (data_source == 0)
1135  return false;
1136 
1137  string loader_name;
1138  try {
1139  loader_name = data_source->AddDataLoader(loader.SetData());
1140 
1141  } NCBI_CATCH("Data loader error: " + loader.GetLabel());
1142 
1143  if (loader_name.empty()) {
1144  loader.SetEnabled(false);
1145  return false;
1146  }
1147 
1148  if (loader.SetData().HasField(kLoaderName)) {
1149  loader.SetData().SetField(kLoaderName).SetString(loader_name);
1150  } else {
1151  loader.SetData().AddField(kLoaderName, loader_name);
1152  }
1153 
1155  if (loader.IsSetPriority()) {
1156  priority = loader.GetPriority();
1157  }
1158 
1159  CScope* scope = GetScope();
1160  _ASSERT(scope);
1161  scope->ResetHistory();
1162  scope->AddDataLoader(loader_name, priority);
1163 
1164  loader.SetEnabled(true);
1165 
1166  return true;
1167 }
1168 
1169 
1171 {
1172  _ASSERT(IsLoaded());
1173 
1174  string loader_name;
1175  CConstRef<CUser_field> loader_name_field = loader.GetData().GetFieldRef(kLoaderName);
1176  if (loader_name_field)
1177  loader_name = loader_name_field->GetData().GetStr();
1178  if (loader_name.empty()) {
1179  IDataLoaderProvider* data_source = x_GetDataSourceByType(loader.GetLoader_type());
1180  if (data_source == 0)
1181  return false;
1182  loader_name = data_source->GetLoaderName(loader.GetData());
1183  }
1184  if (loader_name.empty())
1185  return false;
1186 
1187  CScope* scope = GetScope();
1188  _ASSERT(scope);
1189 
1190  bool result = false;
1191  try {
1192  scope->ResetHistory();
1193  scope->RemoveDataLoader(loader_name);
1194  loader.SetEnabled(false);
1195  result = true;
1196  } NCBI_CATCH("Failed to detach data loader \"" + loader.GetLabel() + "\" from scope.");
1197  return result;
1198 }
1199 
1201 {
1204 
1206 }
1207 
1208 
1210 {
1211  _ASSERT(IsLoaded());
1212 
1213  TDataLoaders& loaders = m_Project->SetDataLoaders();
1215  AttachDataLoader(**iter);
1216 }
1217 
1219 {
1220  _ASSERT(IsLoaded());
1221 
1222  TDataLoaders& loaders = m_Project->SetDataLoaders();
1224  DetachDataLoader(**iter);
1225 }
1226 
1228 {
1229  _ASSERT(IsLoaded());
1230 
1231  CScope* scope = GetScope();
1232  _ASSERT(scope);
1233 
1234  vector<IProjectItemExtension*> clients;
1236  IServiceLocator* srvLocator = m_Service->GetServiceLocator();
1237 
1238  for (CTypeIterator<CProjectItem> it(SetData()); it; ++it) {
1239  if (!it->IsEnabled())
1240  continue;
1241  s_AttachProjectItem(*it, *scope);
1242  if (!clients.empty()) {
1243  s_CallExtensionProjectItemAttached(*this, clients, *it, srvLocator);
1244  }
1245  }
1246 }
1247 
1248 typedef vector<pair<CProjectItem*, CSeq_id_Handle> > TGiProjectItems;
1249 
1250 static void s_ReplaceGIs(TGiProjectItems& gis, CScope& scope)
1251 {
1253  ITERATE(TGiProjectItems, it, gis)
1254  input.push_back(it->second);
1255 
1256  scope.GetAccVers(&results, input);
1257 
1258  for (size_t i = 0; i < results.size(); ++i) {
1259  CSeq_id_Handle& h = results[i];
1260  if (h) {
1261  CConstRef<CSeq_id> seqId = h.GetSeqIdOrNull();
1262  if (seqId)
1263  gis[i].first->SetItem().SetId().Assign(*seqId);
1264  }
1265  }
1266 }
1267 
1269 {
1270  CScope* scope = GetScope();
1271  _ASSERT(scope);
1272 
1273  TGiProjectItems gis;
1274 
1275  for (CTypeIterator<CProjectItem> it(SetData()); it; ++it) {
1276  if (!it->CanGetItem() || !it->GetItem().IsId()) continue;
1277  const CSeq_id& seqId = it->GetItem().GetId();
1278  if (!seqId.IsGi()) continue;
1279  gis.push_back(make_pair(&*it, CSeq_id_Handle::GetHandle(seqId)));
1280 
1281  if (gis.size() >= 2000) {
1282  if (canceled && canceled->IsCanceled())
1283  return;
1284  s_ReplaceGIs(gis, *scope);
1285  gis.clear();
1286  }
1287  }
1288 
1289  if (gis.size() > 0) {
1290  if (canceled && canceled->IsCanceled())
1291  return;
1292  s_ReplaceGIs(gis, *scope);
1293  }
1294 }
1295 
1297 {
1298  _ASSERT(IsLoaded());
1299 
1300  CScope* scope = GetScope();
1301  _ASSERT(scope);
1302 
1303  for (CTypeIterator<CProjectItem> it(SetData()); it; ++it) {
1304  s_DetachProjectItem(*it, *scope);
1305  }
1306 }
1307 
1309 {
1310  _ASSERT(IsLoaded());
1313  Clear();
1314 }
1315 
1316 void CGBDocument::UnloadProject(bool reset_hist_async)
1317 {
1318  if (IsLoading()) {
1319  CancelLoading();
1320  return;
1321  }
1322 
1323  if (!IsLoaded())
1324  return;
1325 
1326  wxBusyCursor wait;
1327 
1328  vector<IProjectItemExtension*> clients;
1330  IServiceLocator* srvLocator = m_Service->GetServiceLocator();
1331 
1332  for (CTypeIterator<CProjectItem> it(SetData()); it; ++it) {
1333  if (!clients.empty()) {
1334  s_CallExtensionProjectItemDetached(*this, clients, *it, srvLocator);
1335  }
1336  }
1337 
1338  x_RemoveAllViews(reset_hist_async);
1339  x_UnloadData();
1340 
1342 
1344 }
1345 
1346 void CGBDocument::x_RemoveAllViews(bool reset_hist_async)
1347 {
1348  if (m_Views.empty())
1349  return;
1350 
1351  IServiceLocator* srvLocator = m_Service->GetServiceLocator();
1352  IViewManagerService* view_srv = srvLocator->GetServiceByType<IViewManagerService>();
1353 
1354  TViews views = m_Views;
1355 
1356  for (size_t i = 0; i < views.size(); i++) {
1357  IProjectView& view = *views[i];
1358  view.SetAsyncDestroy(reset_hist_async);
1359  view.DestroyView();
1360  view_srv->RemoveFromWorkbench(view);
1361  }
1362 }
1363 
1364 wxString CGBDocument::GetWorkDir() const
1365 {
1366  for (CTypeConstIterator<CProjectItem> it(GetData()); it; ++it) {
1367  string smartFile;
1368  CProjectItemExtra::GetStr(*it, "SmartFile", smartFile);
1369  if (!smartFile.empty()) {
1370  return wxFileName(wxString::FromUTF8(smartFile.c_str())).GetPath();
1371  }
1372  }
1373  return wxEmptyString;
1374 }
1375 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
std::invoke_result< _Fty, ICanceled & >::type GUI_AsyncExec(_Fty &&_Fnarg, const wxString &msg=wxT("Accessing network..."))
Definition: async_call.hpp:130
const string & GetFolderName() const
Definition: document.cpp:860
vector< CRef< CProjectItem > > m_Items
Definition: document.cpp:866
vector< CRef< CProjectItem > > & GetProjectItems()
Definition: document.cpp:861
CAddItemsData(const string &folderName, vector< CRef< CProjectItem > > &items, const CGBDocument::TLoaders &loaders)
Definition: document.cpp:855
const CGBDocument::TLoaders & GetLoaders() const
Definition: document.cpp:862
string m_FolderName
Definition: document.cpp:865
CGBDocument::TLoaders m_Loaders
Definition: document.cpp:867
CAppJobError Default implementation for IAppJobError - encapsulates a text error message.
CAppJob - default implementation of IAppJob that could be used as a base class.
CAppTaskService - Application Task Service.
virtual string x_GetJobName() const
Definition: document.cpp:905
virtual string GetDescr() const
Returns a human readable description of the Job (optional)
Definition: document.cpp:879
CAttachProjectItemsJob(CAddItemsData &data, CScope &scope)
Definition: document.cpp:873
virtual ~CAttachProjectItemsJob()
Definition: document.cpp:875
CRef< CAddItemsData > m_Data
Definition: document.cpp:908
virtual CRef< CObject > GetResult()
Returns the Job Result.
Definition: document.cpp:894
CRef< CAppJobError > m_Error
Definition: document.cpp:910
virtual CConstIRef< IAppJobError > GetError()
Returns IAppJobError object describing internal error that caused the Job to fail.
Definition: document.cpp:898
CRef< CScope > m_Scope
Definition: document.cpp:909
virtual CConstIRef< IAppJobProgress > GetProgress()
return progress object, the function shall be synchronized internally.
Definition: document.cpp:890
virtual EJobState Run()
Function that does all the useful work, called by the Engine.
Definition: document.cpp:880
void Detach(objects::CScope &scope)
CConn_FtpStream specialization (ctor) for download.
This stream exchanges data with an HTTP server located at the URL: http[s]://host[:port]/path[?...
virtual EJobState Run()
Function that does all the useful work, called by the Engine.
Definition: document.cpp:283
CRef< CGBDocument > m_Document
Definition: document.cpp:202
wxString m_Path
Definition: document.cpp:203
CDocLoadingJob(CGBDocument &doc, const wxString &path)
Definition: document.cpp:193
CEventHandler.
CFile –.
Definition: ncbifile.hpp:1605
CGBDocument.
Definition: document.hpp:113
void SetFileName(const wxString &filename)
Definition: document.cpp:137
void AttachData()
Definition: document.cpp:1200
TViews & x_GetViews(void)
Definition: document.cpp:394
void Save(const wxString &abs_path)
Definition: document.cpp:503
void x_ProjectViewsChanged()
Definition: document.cpp:233
void ProjectItemsChanged()
Definition: document.cpp:239
bool RemoveProjectItems(const vector< objects::CProjectItem * > &items)
Definition: document.cpp:744
friend class CDocLoadingJob
Definition: document.hpp:117
CProjectViewEvent TEvent
Definition: document.hpp:133
void DetachProjectItem(objects::CProjectItem *item)
Definition: document.cpp:780
CIRef< IAppJob > m_LoadJob
Definition: document.hpp:266
virtual void OnJobResult(CObject *result, CJobAdapter &adapter)
Definition: document.cpp:914
string GetDefaultAssembly() const
Definition: document.cpp:142
bool DetachDataLoader(objects::CLoaderDescriptor &loader)
Definition: document.cpp:1170
friend class CAddItemsData
Definition: document.hpp:126
bool LoadFile(const wxString &fname, ICanceled *canceledCallback)
Definition: document.cpp:447
void x_DetachView(IProjectView *view)
detach a view from the current document
Definition: document.cpp:348
TViewToIndex m_ViewToIndex
Definition: document.hpp:262
static size_t x_GetUndoSize()
Definition: document.cpp:648
void x_AddItems(const string &folderName, vector< CRef< objects::CProjectItem > > &items, const TLoaders &loaders)
Definition: document.cpp:1007
void AttachProjectItems(const vector< objects::CProjectItem * > &items)
Definition: document.cpp:788
IDataLoaderProvider * x_GetDataSourceByType(const string &type)
Definition: document.cpp:1106
void ReplaceGiSeqIds(ICanceled *canceled)
Definition: document.cpp:1268
virtual void OnJobFailed(const string &, CJobAdapter &adapter)
Definition: document.cpp:930
virtual void CreateProjectScope()
Definition: document.cpp:178
wxString GetWorkDir() const
Definition: document.cpp:1364
bool RemoveDataLoader(objects::CLoaderDescriptor &loader)
Definition: document.cpp:1087
void x_RemoveAllViews(bool reset_hist_async)
Definition: document.cpp:1346
virtual const TViews & GetViews(void) const
Retrieve the existing views for this class.
Definition: document.cpp:388
void x_CloseProjectItemViews(objects::CProjectItem &item)
Definition: document.cpp:703
void x_ProjectUpdateLabel()
Definition: document.cpp:246
void x_AttachDataLoaders()
Definition: document.cpp:1209
void UnloadProject(bool reset_hist_async=true)
Definition: document.cpp:1316
void x_ClearAssembly() const
Definition: document.cpp:172
CProjectService * m_Service
pointer to the service that manages the document
Definition: document.hpp:258
IAppJob * CreateLoadJob(const wxString &fileName)
Definition: document.cpp:252
void x_AttachProjectItems()
Definition: document.cpp:1227
void AddItems(const string &folderName, vector< CRef< objects::CProjectItem > > &items, const TLoaders &loaders)
Definition: document.cpp:941
CGBDocument(CProjectService *srv)
CGBDocument.
Definition: document.cpp:104
void x_DetachDataLoaders()
Definition: document.cpp:1218
bool AttachDataLoader(objects::CLoaderDescriptor &loader)
Definition: document.cpp:1129
void x_SaveFile(const wxString &fname, ESerialDataFormat fmt, bool keep_backups)
Definition: document.cpp:547
void CancelLoading()
Definition: document.cpp:269
wxString GetFileName() const
Definition: document.cpp:132
void ProjectStateChanged()
Definition: document.cpp:226
void x_AssignViewIndex(IProjectView *view)
Definition: document.cpp:371
void DetachProjectItems(const vector< objects::CProjectItem * > &items)
Definition: document.cpp:811
void x_AttachView(IProjectView *view)
Attach a view to the current document.
Definition: document.cpp:328
vector< TLoaderRef > TLoaders
Definition: document.hpp:217
vector< CIRef< IProjectView > > TViews
Definition: document.hpp:131
bool RemoveProjectItem(objects::CProjectItem *item)
Definition: document.cpp:736
void x_DetachProjectItems()
Definition: document.cpp:1296
void x_InitializeAssembly() const
Definition: document.cpp:149
void x_UnloadData()
Definition: document.cpp:1308
void ResetLoading()
Definition: document.cpp:278
bool m_AssemblyInitialized
Definition: document.hpp:272
virtual void x_FireViewEvent(IProjectView &view, CViewEvent::EEventType type)
Definition: document.cpp:408
bool IsLoading() const
Definition: document.cpp:264
TViews m_Views
Views attached to this project.
Definition: document.hpp:255
string m_AssemblyAccession
Definition: document.hpp:271
list< CRef< CJobAdapter > > m_JobAdapters
Definition: document.hpp:274
virtual void x_FireProjectChanged(TEvent::EEventSubtype subtype)
Definition: document.cpp:399
void ViewLabelChanged(IProjectView &view)
Definition: document.cpp:220
void AttachProjectItem(objects::CProjectItem *item)
Definition: document.cpp:772
void Save(CNcbiOstream &ostr, ESerialDataFormat fmt) const
Serialize to a stream in a given format.
bool Load(CNcbiIstream &istr, ICanceled *canceledCallback)
force a project to be loaded from an external stream
string GetAccession() const
Retrieve the accession for this assembly.
Definition: GC_Assembly.cpp:99
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
string GetString(const string &key, const string &default_val=kEmptyStr) const
Definition: registry.cpp:148
bool GetBool(const string &key, bool default_val=false) const
Definition: registry.cpp:143
Base class to build jobs with cancel functionality.
CLoaderDescriptor –.
NULL stream writer for test serialization.
Definition: document.cpp:311
ERW_Result Write(const void *buf, size_t count, size_t *bytes_written)
Write up to "count" bytes from the buffer pointed to by the "buf" argument onto the output device.
Definition: document.cpp:313
ERW_Result Flush()
Flush pending data (if any) down to the output device.
Definition: document.cpp:321
CObject –.
Definition: ncbiobj.hpp:180
const CProjectFolder * FindProjectItemFolder(CProjectItem::TId id) const
bool RemoveChildItem(CProjectItem &child_item)
const CProjectItem * GetProjectItem(CProjectItem::TId id) const
CProjectFolder * FindChildFolderByTitle(const string &title)
void AddChildFolder(CProjectFolder &child_folder)
static bool GetStr(const objects::CProjectItem &pi, const string &tag, string &value)
CObject * GetUserObject()
const CSerialObject * GetObject() const
retrieve the object pointed to as a CObject*
void SetUserObject(CObject *object)
bool IsEnabled(void) const
enabled flag
CProjectService - a service providing API for operations with Workspaces and Projects.
IServiceLocator * GetServiceLocator()
void RemoveProjectView(IProjectView &view)
removes the view from View manager Service and disconnects it from the project
CProjectTreePanel - a window that represents Project View.
void ProjectUpdateLabel(CGBDocument &doc)
void ProjectViewsChanged(CGBDocument &doc)
void ProjectUpdateItems(CGBDocument &doc)
void ProjectStateChanged(CGBDocument &doc)
void UpdateViewLabel(CGBDocument &doc, IProjectView &view)
CProjectTreeView - a system view that displays Project Tree.
virtual wxWindow * GetWindow()
returns a pointer to the wxWindow representing the client
CProjectViewEvent.
Definition: document.hpp:62
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
int GetInt(const string &key, int default_val=0) const
access a named key at this level, with no recursion
Definition: reg_view.cpp:230
CScope –.
Definition: scope.hpp:92
Base class for all serializable objects.
Definition: serialbase.hpp:150
CTime –.
Definition: ncbitime.hpp:296
Template class for iteration on objects of class C (non-medifiable version)
Definition: iterator.hpp:767
Template class for iteration on objects of class C.
Definition: iterator.hpp:673
CUIDataSourceService.
vector< TUIDataSourceRef > TUIDataSourceVec
CUniqueLabelGenerator Modifies the given label so that it becomes unique in the given set of labels b...
CConstRef< CUser_field > GetFieldRef(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Definition: User_object.cpp:84
@ eViewReleased
a view has been initialized and ready
Definition: view_event.hpp:52
IAppJob.
Definition: app_job.hpp:82
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
IDataLoaderProvider - an interface representing a Data Source.
IExtension IExtension interface represents an abstract pluggable component.
Definition: extension.hpp:57
IGBProject - abstract interface for a project used by CGBProjectHandle.
Definition: igbproject.hpp:57
list< CRef< CLoaderDescriptor > > TDataLoaders
Definition: igbproject.hpp:70
virtual EProjectVersion GetVersion() const =0
retrieve this project's version; this is fixed per subclass
class IProjectView defines the abstract interface for views observing projects.
virtual void SetAsyncDestroy(bool reset_hist_async)=0
Set async destruction mode.
virtual void DestroyView()=0
disconnects view from the project and associated data
IServiceLocator - an abstract mechanism for locating services.
Definition: service.hpp:71
IViewManagerService IViewManagerService manages views in Workbench.
virtual void SaveSettingsAtProject(objects::CGBProjectHandle &project) const =0
virtual string GetClientLabel(IWMClient::ELabel ltype=IWMClient::eDefault) const =0
returns the client label (name) to be displayed in UI
A very basic data-write interface.
void erase(iterator pos)
Definition: map.hpp:167
container_type::iterator iterator
Definition: map.hpp:54
const_iterator end() const
Definition: map.hpp:152
bool empty() const
Definition: map.hpp:149
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
#define false
Definition: bool.h:36
static int type
Definition: getdata.c:31
static FILE * f
Definition: readconf.c:23
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
string
Definition: cgiapp.hpp:690
#define NULL
Definition: ncbistd.hpp:225
#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 Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
#define NCBI_CATCH(message)
Catch CExceptions as well This macro is deprecated - use *_X or *_XX variant instead of it.
Definition: ncbiexpt.hpp:580
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
virtual bool Remove(TRemoveFlags flags=eRecursive) const
Remove a directory entry.
Definition: ncbifile.cpp:2595
static string GetTmpName(ETmpFileCreationMode mode=eTmpFileGetName)
Get temporary file name.
Definition: ncbifile.cpp:2903
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
Definition: service.hpp:91
void AddTask(IAppTask &task)
Add a task to the queue.
vector< CIRef< IView > > TViews
virtual void GetViews(TViews &views)=0
get all registered views
virtual void RemoveFromWorkbench(IView &view)=0
disconnects view from services and removes from the Workbench
virtual string AddDataLoader(const objects::CUser_object &obj)=0
Add a new data loader to object manager.
virtual string GetLoaderName(const objects::CUser_object &obj) const =0
Get the data loader's name based on input object.
const float pi
Definition: math.hpp:54
virtual void RemoveListener(CEventHandler *listener)
Remove a listener.
ICanceled * x_GetICanceled()
CRef< CAppJobError > m_Error
void GetExtensionAsInterface(const string &ext_point_id, vector< CIRef< I > > &interfaces)
GetExtensionAsInterface() is a helper function that extracts all extensions implementing the specifie...
string MakeUniqueLabel(const string &label) const
after considering all existing labels produces a modified unique version of the original label
CAppJobDispatcher::TJobID GetJobId() const
Definition: job_adapter.hpp:68
virtual string GetExtensionIdentifier() const =0
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual bool IsCanceled() const override
static void SetLabelByData(objects::CProjectItem &item, objects::CScope *scope=NULL)
Definition: label.cpp:121
void AddExistingLabel(const string &label)
adds an existing label
void Post(CRef< CEvent > evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Handles an event asynchronously (process and/or dispatch).
CFastMutex m_Mutex
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
virtual void AddListener(CEventHandler *listener, int pool_name=ePool_Default)
Add a listener.
void Start(IAppJob &job)
Definition: job_adapter.cpp:42
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
virtual bool Send(CEvent *evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Sends an event synchronously.
@ eCanceled
Definition: app_job.hpp:91
@ eCompleted
Definition: app_job.hpp:89
@ eFailed
Definition: app_job.hpp:90
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
@ eSerial_AsnBinary
ASN.1 binary.
Definition: serialdef.hpp:74
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Optimized implementation of CSerialObject::Assign, which is not so efficient.
Definition: Seq_id.cpp:318
CConstRef< CSeq_id > GetSeqIdOrNull(void) const
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
void ResetHistory(EActionIfLocked action=eKeepIfLocked)
Clean all unused TSEs from the scope's cache and release the memory.
Definition: scope.cpp:325
void AddDataLoader(const string &loader_name, TPriority pri=kPriority_Default)
Add data loader by name.
Definition: scope.cpp:510
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
TSeq_id_Handles GetAccVers(const TSeq_id_Handles &idhs, TGetFlags flags=0)
Get accession.version Seq-id Returns null CSeq_id_Handles for sequences that aren't found or don't ha...
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
int TPriority
priority type and special value for added objects
Definition: scope.hpp:98
void RemoveDataLoader(const string &loader_name, EActionIfLocked action=eThrowIfLocked)
Revoke data loader from the scope.
Definition: scope.cpp:369
vector< CSeq_id_Handle > TSeq_id_Handles
Bulk retrieval methods Common argument typedef - vector of requested ids.
Definition: scope.hpp:518
@ kPriority_Default
Use default priority for added data.
Definition: scope.hpp:100
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
virtual bool IsCanceled(void) const =0
ERW_Result
Result codes for I/O operations.
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
bool NcbiStreamCopy(CNcbiOstream &os, CNcbiIstream &is)
Copy the entire contents of stream "is" to stream "os".
Definition: ncbistre.cpp:211
@ eRW_Success
Everything is okay, I/O completed.
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
@ eCurrent
Use current time. See also CCurrentTime.
Definition: ncbitime.hpp:300
static const char label[]
bool IsSetLabel(void) const
user-defined label Check if a value has been assigned to Label data member.
void SetDisabled(TDisabled value)
Assign a value to Disabled data member.
void SetLabel(const TLabel &value)
Assign a value to Label data member.
void SetData(TData &value)
Assign a value to Data data member.
TId GetId(void) const
Get the Id member data.
void SetEnabled(TEnabled value)
Assign a value to Enabled data member.
const TLabel & GetLabel(void) const
Get the Label member data.
const TLoader_type & GetLoader_type(void) const
Get the Loader_type member data.
const TLabel & GetLabel(void) const
Get the Label member data.
TEnabled GetEnabled(void) const
Get the Enabled member data.
bool IsSetPriority(void) const
loader priority used in object manager Check if a value has been assigned to Priority data member.
bool IsAnnot(void) const
Check if variant Annot is selected.
const TItem & GetItem(void) const
Get the Item member data.
void SetInfo(TInfo &value)
Assign a value to Info data member.
void SetItem(TItem &value)
Assign a value to Item data member.
TPriority GetPriority(void) const
Get the Priority member data.
const TData & GetData(void) const
Get the Data member data.
const TFilename & GetFilename(void) const
Get the Filename member data.
TFilename & SetFilename(void)
Assign a value to Filename data member.
const TStr & GetStr(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
bool IsGi(void) const
Check if variant Gi is selected.
Definition: Seq_id_.hpp:883
void SetDesc(TDesc &value)
Assign a value to Desc data member.
Definition: Seq_annot_.cpp:223
bool CanGetDesc(void) const
Check if it is safe to call GetDesc method.
Definition: Seq_annot_.hpp:846
USING_SCOPE(objects)
specific supported project versions
static void s_AttachProjectItem(CProjectItem &item, CScope &scope)
Definition: document.cpp:663
vector< pair< CProjectItem *, CSeq_id_Handle > > TGiProjectItems
Definition: document.cpp:1248
static const char * kLoaderName
Definition: document.cpp:99
static void s_ReplaceGIs(TGiProjectItems &gis, CScope &scope)
Definition: document.cpp:1250
static CProjectTreePanel * s_FindProjectTreePanel(IServiceLocator *serviceLocator)
Definition: document.cpp:206
static void s_CallExtensionProjectItemDetached(CGBDocument &doc, vector< IProjectItemExtension * > &clients, CProjectItem &item, IServiceLocator *srvLocator)
Definition: document.cpp:691
static void s_CallExtensionProjectItemAttached(CGBDocument &doc, vector< IProjectItemExtension * > &clients, CProjectItem &item, IServiceLocator *srvLocator)
Definition: document.cpp:679
static void s_DetachProjectItem(CProjectItem &item, CScope &scope)
Definition: document.cpp:671
char * buf
static int input()
int i
static MDB_envinfo info
Definition: mdb_load.c:37
#define wxT(x)
Definition: muParser.cpp:41
CProject * GetProject(wxTreeCtrl &treeCtrl, const CItem &item)
Definition: pt_utils.cpp:77
T max(T x_, T y_)
std::istream & in(std::istream &in_, double &x_)
Format
Definition: njn_ioutil.hpp:52
The Object manager core.
#define count
static int * results[]
#define EXT_POINT__PROJECT_ITEM_EXTENSION
Reader-writer based streams.
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
STempFileLocker(const string &tmp_name)
Definition: document.cpp:430
Definition: type.c:6
#define _ASSERT
else result
Definition: token2.c:20
CScope & GetScope()
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
wxString FnToWxString(const string &s)
Definition: wx_utils.cpp:253
string FnToStdString(const wxString &s)
Definition: wx_utils.cpp:268
Modified on Fri Sep 20 14:58:32 2024 by modify_doxy.py rev. 669887