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

Go to the SVN repository for this file.

1 /* $Id: select_project_options.cpp 45881 2021-01-05 03:10:02Z rudnev $
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: Andrey Yazhuk, Liangshou Wu
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
34 #include <gui/core/document.hpp>
39 #include <objects/general/Date.hpp>
40 
42 
43 #include <serial/iterator.hpp>
45 
48 
49 ///////////////////////////////////////////////////////////////////////////////
50 /// CSelectProjectOptions
52 : m_Action(eInvalidAction), m_NewProjectName("New Project")
53 {
54 }
55 
56 
58 {
60 }
61 
62 
64 {
66  m_TargetProjectId = CGBDocument::GetNextId();//GenerateNewId();
67  m_FolderName = folder;
68 }
69 
70 
72 {
74  m_FolderName = "";
75 }
76 
77 
79  const string& folder)
80 {
82  m_TargetProjectId = project_id;
83  m_FolderName = folder;
84 }
85 
86 
88 {
89  return m_Action;
90 }
91 
92 
94 {
95  return m_TargetProjectId;
96 }
97 
98 
100 {
101  return m_FolderName;
102 }
103 
105 {
106  TItems items;
107  TLoaders loaders;
108  ITERATE(TData, it, data) {
109  if (it->first) loaders.push_back(it->first);
110  ITERATE(TItems, it2, it->second)
111  items.push_back(*it2);
112  }
113 
114  if (m_Action == eDecideLater) {
115  if (!x_ShowSelectProjectDialog(service, items))
116  return false;
117  }
118 
119  switch(m_Action) {
120  case eCreateNewProject:
121  x_CreateOneProject(service, items, loaders);
122  return true;
123 
125  x_CreateSeparateProjects(service, data);
126  return true;
127 
129  x_AddToExistingProject(service, items, loaders);
130  return true;
131  }
132  case eDecideLater:
133  break;
134  default:
135  _ASSERT(false);
136  }
137  return false;
138 }
139 
141 {
142  CRef<CScope> default_scope( new CScope(*CObjectManager::GetInstance()));
143  default_scope->AddDefaults();
144 
146  for( size_t i = 0; i < items.size(); i++ ) {
147  const CProjectItem& item = *items[i];
148  objects.push_back(SConstScopedObject(item.GetObject(), default_scope));
149  }
150 
151  CProjectSelectorDlg dlg(NULL, wxID_ANY, wxT("Select project for items"));
152 
153  dlg.SetProjectService(service);
154  dlg.SetObjects(objects);
155  dlg.SetRegistryPath("Dialogs.DataLoadingTask.ProjectSelector");
156  if (dlg.ShowModal() != wxID_OK)
157  return false;
158 
159  SProjectSelectorParams params;
160  dlg.GetParams(params);
161  params.ToLoadingOptions(*this);
162 
163  return true;
164 }
165 
167 {
168  CRef<CGBWorkspace> ws = service->GetGBWorkspace();
169  if (!ws) return;
170 
171  CGBProjectHandle* project = ws->GetProjectFromId(m_TargetProjectId);
172  if (!project) {
173  LOG_POST(Error << "AddItemsToProject: project " << m_TargetProjectId << " doesn't exist");
174  return;
175  }
176 
177  CGBDocument& doc = dynamic_cast<CGBDocument&>(*project);
178  doc.AddItems(m_FolderName, items, loaders);
179 }
180 
182 {
183  const CWorkspaceFolder& root = ws.GetWorkspace();
184  for (CTypeConstIterator<CGBProjectHandle> it(root); it; ++it) {
185  const string& s = it->GetTitle();
186  projectNames.AddExistingLabel(s);
187  }
188 }
189 
190 CGBDocument* CSelectProjectOptions::CreateProject(CProjectService* service, const string& prjName, const string& prjDesc)
191 {
192  _ASSERT(service);
193  CGBProject_ver2* prj_obj = new CGBProject_ver2();
194  CRef<CGBDocument> doc(new CGBDocument(service, CGBDocument::GetNextId(), *prj_obj));
195 
196  doc->CreateProjectScope();
197 
198  // initialize project data
199  CProjectDescr& descr = doc->SetProject().SetDescr();
200  doc->SetDescr().SetTitle(prjName);
201  descr.SetComment(prjDesc);
202 
203  CTime time(CTime::eCurrent);
204  descr.SetCreateDate(time);
205  descr.SetModifiedDate(time);
206 
207  return doc.Release();
208 }
209 
211 {
212  if (!service->HasWorkspace())
213  service->CreateNewWorkspace();
214  CRef<CGBWorkspace> ws = service->GetGBWorkspace();
215 
216  CUniqueLabelGenerator projectNames;
217  InitProjectnameGenerator(*ws, projectNames);
218  string projectName = projectNames.MakeUniqueLabel(m_NewProjectName);
219 
220  CRef<CGBDocument> doc(CreateProject(service, projectName, m_NewProjectName));
221 
222  doc->AddItems(m_FolderName, items, loaders);
223  service->AddProject(*doc);
224 }
225 
226 /// for every Project Item in m_Items creates a new project,
227 /// adds the item to the project and loads the data
229 {
230  if (!service->HasWorkspace())
231  service->CreateNewWorkspace();
232  CRef<CGBWorkspace> ws = service->GetGBWorkspace();
233 
234  CUniqueLabelGenerator projectNames;
235  InitProjectnameGenerator(*ws, projectNames);
236 
237  ITERATE(TData, it, data) {
238  if (!it->second.empty()) {
239  ITERATE(TItems, it2, it->second) {
240  string projectName = projectNames.MakeUniqueLabel(m_NewProjectName);
241  projectNames.AddExistingLabel(projectName);
242  CRef<CGBDocument> doc(CreateProject(service, projectName, m_NewProjectName));
243 
244  TItems items;
245  items.push_back(*it2);
246 
247  TLoaders loaders;
248  if (it->first) {
250  loader->Assign(*it->first);
251  loaders.push_back(loader);
252  }
253 
254  doc->AddItems("", items, loaders);
255  service->AddProject(*doc);
256  }
257  }
258  else {
259  if (it->first) {
260  string projectName = projectNames.MakeUniqueLabel(m_NewProjectName);
261  projectNames.AddExistingLabel(projectName);
262  CRef<CGBDocument> doc(CreateProject(service, projectName, m_NewProjectName));
263 
264  TItems items;
265  TLoaders loaders;
267  loader->Assign(*it->first);
268  loaders.push_back(loader);
269  doc->AddItems("", items, loaders);
270  service->AddProject(*doc);
271  }
272  }
273  }
274 }
275 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
virtual void SetRegistryPath(const string &path)
Definition: dialog.cpp:59
CGBDocument.
Definition: document.hpp:113
virtual void CreateProjectScope()
Definition: document.cpp:178
void AddItems(const string &folderName, vector< CRef< objects::CProjectItem > > &items, const TLoaders &loaders)
Definition: document.cpp:941
CGBWorkspace.
Definition: GBWorkspace.hpp:63
CLoaderDescriptor –.
void SetCreateDate(const CTime &time)
SetCreateDate() will add a descriptor for creation date.
void SetModifiedDate(const CTime &time)
SetModifiedDate() will add a descriptor for the update date.
const CSerialObject * GetObject() const
retrieve the object pointed to as a CObject*
void SetObjects(TConstScopedObjects &objects)
void SetProjectService(CProjectService *prj_srv)
void GetParams(SProjectSelectorParams &params) const
CProjectService - a service providing API for operations with Workspaces and Projects.
CRef< objects::CGBWorkspace > GetGBWorkspace()
void AddProject(CGBDocument &doc)
CScope –.
Definition: scope.hpp:92
bool AddItemsToWorkspace(CProjectService *service, const TData &data)
void Set_CreateNewProject(const string &folder=kEmptyStr)
void x_AddToExistingProject(CProjectService *service, TItems &items, const TLoaders &loaders)
void x_CreateSeparateProjects(CProjectService *service, const TData &data)
for every Project Item in m_Items creates a new project, adds the item to the project and loads the d...
objects::CGBProjectHandle::TId TProjectId
static CGBDocument * CreateProject(CProjectService *service, const string &prjName, const string &prjDesc)
void x_CreateOneProject(CProjectService *service, TItems &items, const TLoaders &loaders)
bool x_ShowSelectProjectDialog(CProjectService *service, TItems &items)
void Set_AddToExistingProject(TProjectId &project_id, const string &folder=kEmptyStr)
vector< TLoaderRef > TLoaders
static void InitProjectnameGenerator(objects::CGBWorkspace &ws, CUniqueLabelGenerator &projectNames)
CSelectProjectOptions()
CSelectProjectOptions.
CTime –.
Definition: ncbitime.hpp:296
Template class for iteration on objects of class C (non-medifiable version)
Definition: iterator.hpp:767
CUniqueLabelGenerator Modifies the given label so that it becomes unique in the given set of labels b...
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#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
string MakeUniqueLabel(const string &label) const
after considering all existing labels produces a modified unique version of the original label
void AddExistingLabel(const string &label)
adds an existing label
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
TObjectType * Release(void)
Release a reference to the object and return a pointer to the object.
Definition: ncbiobj.hpp:846
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
@ eCurrent
Use current time. See also CCurrentTime.
Definition: ncbitime.hpp:300
void SetComment(const TComment &value)
Assign a value to Comment data member.
const TWorkspace & GetWorkspace(void) const
Get the Workspace member data.
int i
#define wxT(x)
Definition: muParser.cpp:41
The Object manager core.
USING_SCOPE(objects)
static static static wxID_ANY
SProjectSelectorParams - holds data for CProjectSelectorPanel.
void ToLoadingOptions(CSelectProjectOptions &options)
#define _ASSERT
Modified on Fri Sep 20 14:58:06 2024 by modify_doxy.py rev. 669887