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

Go to the SVN repository for this file.

1 #ifndef GUI_CORE___DOCUMENT__HPP
2 #define GUI_CORE___DOCUMENT__HPP
3 
4 /* $Id: document.hpp 41444 2018-07-30 19:37:01Z katargir $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Vladimir Tereshkov, Andrey Yazhuk
30  *
31  */
32 
34 
39 #include <gui/utils/app_job.hpp>
41 #include <gui/utils/view_event.hpp>
42 
44 
45 #include <wx/string.h>
46 
48 
49 class CProjectService;
51 class CProjectViewBase;
52 
54  class CGBProject;
55  class CGBProject_ver2;
56  class CProjectItem;
58 
59 ///////////////////////////////////////////////////////////////////////////////
60 /// CProjectViewEvent
62 {
63 public:
65  eNone = 0,
69  // Before we change data we syncronously Send
70  // eDataChanging event, so view won't use data
71  // Then we Post eData event
72  // Used in the Undo manager
74  eUnloadProject
75  };
76 
77 public:
79  objects::CGBProjectHandle::TId prj_id, EEventSubtype subtype = eNone
80  )
81  : CViewEvent( eProjectChanged )
82  , m_Subtype( subtype )
83  , m_View()
84  , m_ProjectId( prj_id )
85  {}
86 
89  )
90  : CViewEvent( type )
91  , m_Subtype( subtype )
92  , m_View( &view )
93  , m_ProjectId( objects::CGBProjectHandle::sm_NullId )
94  {}
95 
96  EEventSubtype GetSubtype() const { return m_Subtype; }
97  objects::CGBProjectHandle::TId GetProjectId() { return m_ProjectId; }
98  CIRef<IProjectView> GetProjectView() { return m_View; }
99 
100 
101 protected:
104  objects::CGBProjectHandle::TId m_ProjectId;
105 };
106 
107 ///////////////////////////////////////////////////////////////////////////////
108 /// CGBDocument
110  : public objects::CGBProjectHandle
111  , public CEventHandler
113 {
114  friend class CProjectService;
115  friend class CUndoManager;
116  friend class CProjectLoadingJob;
117  friend class CDocLoadingJob;
118  friend class CProjectLoadingTask;
119  friend class CSmartProjectTask;
120  friend class CDataLoadingAppJob;
121  friend class CProjectTreePanel;
122  friend class CProjectViewBase;
123  friend class CSelectionService;
124  friend class CSelectProjectOptions;
125  friend class CWorkspaceAutoSaver;
126  friend class CAddItemsData;
127 
128  typedef objects::CGBProjectHandle Tparent;
129 
130 public:
131  typedef vector< CIRef<IProjectView> > TViews;
132 
134 
135  /// Retrieve a label for this view. The label has several different
136  enum ELabelType {
137  eType, //< usually a description of the class
138  eContent, //< The content (what the view is looking at)
140  eId, //< an identifier for the view, usually given as a base-26 letter
142  eDefault = eTypeAndContent
143  };
144 
145 public:
147  CGBDocument( CProjectService* srv, TId id, objects::CGBProject_ver2& proj_impl );
148  ~CGBDocument();
149 
150  wxString GetFileName() const;
151  void SetFileName (const wxString& filename);
152 
153  virtual void CreateProjectScope();
154 
155 
156  string GetDefaultAssembly() const;
157 
158  CUndoManager& GetUndoManager() { return *m_UndoManager; }
159 
160  // Load document on worker thread
161  bool IsLoading() const;
162  void CancelLoading();
163  void ResetLoading();
164 
165  bool RemoveProjectItem(objects::CProjectItem* item);
166  bool RemoveProjectItems(const vector<objects::CProjectItem*>& items);
167 
168  void AttachProjectItem(objects::CProjectItem* item);
169  void DetachProjectItem(objects::CProjectItem* item);
170 
171  void AttachProjectItems(const vector<objects::CProjectItem*>& items);
172  void DetachProjectItems(const vector<objects::CProjectItem*>& items);
173 
174  void Save(const wxString& abs_path);
175 
176  void UnloadProject(bool reset_hist_async = true);
177 
178  virtual const TViews& GetViews(void) const;
179 
180  bool RemoveDataLoader(objects::CLoaderDescriptor& loader);
181  bool AttachDataLoader(objects::CLoaderDescriptor& loader);
182  bool DetachDataLoader(objects::CLoaderDescriptor& loader);
183 
184  void ProjectItemsChanged();
185  void ProjectStateChanged();
186 
187  void ViewLabelChanged(IProjectView& view);
188 
189  /// @name CJobAdapter::IJobCallback interface implementation
190  /// @{
191  virtual void OnJobResult(CObject* result, CJobAdapter& adapter);
192  virtual void OnJobFailed(const string&, CJobAdapter& adapter);
193  /// @}
194 
195  wxString GetWorkDir() const;
196 
197 protected:
198  void x_AttachView(IProjectView* view);
199  void x_DetachView(IProjectView* view);
200  TViews& x_GetViews(void);
201  void x_RemoveAllViews(bool reset_hist_async);
202  bool x_DetachProjectItems(const vector<objects::CProjectItem*>& items);
203 
204  virtual void x_FireProjectChanged( TEvent::EEventSubtype subtype );
205  virtual void x_FireViewEvent( IProjectView& view, CViewEvent::EEventType type );
206  // virtual void x_PostViewEvent(IProjectView& view, CViewEvent::EEventType type);
207 
208  // generates index unique for this type of view ans assigns it to a view
209  void x_AssignViewIndex(IProjectView* view);
210 
211  void x_SaveFile(const wxString& fname, ESerialDataFormat fmt, bool keep_backups);
212  bool LoadFile(const wxString& fname, ICanceled* canceledCallback);
213 
214  IAppJob* CreateLoadJob(const wxString& fileName);
215 
217  typedef vector<TLoaderRef> TLoaders;
218 
219  void AddItems(const string& folderName,
220  vector<CRef<objects::CProjectItem> >& items,
221  const TLoaders& loaders);
222 
223  void ReplaceGiSeqIds(ICanceled* canceled);
224 
225  void x_UnloadData();
226 
227  void AttachData();
228 
229 private:
230  void x_AttachDataLoaders();
231  void x_AttachProjectItems();
232  void x_ProjectViewsChanged();
233  void x_ProjectUpdateLabel();
234 
235  void x_AddItems(const string& folderName,
236  vector<CRef<objects::CProjectItem> >& items,
237  const TLoaders& loaders);
238 
239  void x_DetachDataLoaders();
240 
241  void x_DetachProjectItems();
242 
243  void x_CloseProjectItemViews(objects::CProjectItem& item);
244 
245  // Prohibit copy constructor and assignment operator
248 
249  static size_t x_GetUndoSize();
250 
251  IDataLoaderProvider* x_GetDataSourceByType(const string& type);
252 
253 private:
254  /// Views attached to this project
256 
257  /// pointer to the service that manages the document
259 
260  /// map of views to indices for views
263 
264  /// undo manager, project data centric
267 
268  void x_InitializeAssembly() const;
269  void x_ClearAssembly() const;
270 
271  mutable string m_AssemblyAccession;
272  mutable bool m_AssemblyInitialized;
273 
274  list<CRef<CJobAdapter> > m_JobAdapters;
275 };
276 
278 
279 #endif // GUI_CORE___DOCUMENT__HPP
User-defined methods of the data storage class.
User-defined methods of the data storage class.
@ eNone
None specified.
Definition: blast_def.h:326
CDataLoadingAppJob - a base class for Jobs loading data into projects.
CEventHandler.
CGBDocument.
Definition: document.hpp:113
CProjectViewEvent TEvent
Definition: document.hpp:133
CGBDocument & operator=(const CGBDocument &value)
CIRef< IAppJob > m_LoadJob
Definition: document.hpp:266
TViewToIndex m_ViewToIndex
Definition: document.hpp:262
CGBDocument(const CGBDocument &value)
CGBDocument(CProjectService *srv, TId id, objects::CGBProject_ver2 &proj_impl)
bool x_DetachProjectItems(const vector< objects::CProjectItem * > &items)
CUndoManager & GetUndoManager()
Definition: document.hpp:158
CRef< objects::CLoaderDescriptor > TLoaderRef
Definition: document.hpp:216
CProjectService * m_Service
pointer to the service that manages the document
Definition: document.hpp:258
ELabelType
Retrieve a label for this view. The label has several different.
Definition: document.hpp:136
map< IProjectView *, int > TViewToIndex
map of views to indices for views
Definition: document.hpp:261
vector< TLoaderRef > TLoaders
Definition: document.hpp:217
vector< CIRef< IProjectView > > TViews
Definition: document.hpp:131
bool m_AssemblyInitialized
Definition: document.hpp:272
objects::CGBProjectHandle Tparent
Definition: document.hpp:128
TViews m_Views
Views attached to this project.
Definition: document.hpp:255
CRef< CUndoManager > m_UndoManager
undo manager, project data centric
Definition: document.hpp:265
string m_AssemblyAccession
Definition: document.hpp:271
list< CRef< CJobAdapter > > m_JobAdapters
Definition: document.hpp:274
CObject –.
Definition: ncbiobj.hpp:180
CProjectService - a service providing API for operations with Workspaces and Projects.
CProjectTreePanel - a window that represents Project View.
CProjectViewBase - default implementation of IProjectView, the base class for CProjectView and CProje...
CProjectViewEvent.
Definition: document.hpp:62
objects::CGBProjectHandle::TId GetProjectId()
Definition: document.hpp:97
CProjectViewEvent(IProjectView &view, CViewEvent::EEventType type, EEventSubtype subtype=eNone)
Definition: document.hpp:87
CIRef< IProjectView > GetProjectView()
Definition: document.hpp:98
EEventSubtype GetSubtype() const
Definition: document.hpp:96
EEventSubtype m_Subtype
Definition: document.hpp:102
CIRef< IProjectView > m_View
Definition: document.hpp:103
objects::CGBProjectHandle::TId m_ProjectId
Definition: document.hpp:104
CProjectViewEvent(objects::CGBProjectHandle::TId prj_id, EEventSubtype subtype=eNone)
Definition: document.hpp:78
CProjectSelectOptions - describes how new Project Items shall be added to a workspace.
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.
class IProjectView defines the abstract interface for views observing projects.
virtual void OnJobResult(CObject *result, CJobAdapter &adapter)=0
virtual void OnJobFailed(const string &errMsg, CJobAdapter &adapter)=0
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_GUICORE_EXPORT
Definition: gui_export.h:508
static string LoadFile(CNcbiIstream &str)
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Definition: type.c:6
else result
Definition: token2.c:20
Modified on Sun Apr 21 03:38:16 2024 by modify_doxy.py rev. 669887