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

Go to the SVN repository for this file.

1 /* $Id: text_view_project_item_extension.cpp 37255 2016-12-20 19:14:10Z katargir $
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: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
39 
40 #include <objmgr/bioseq_ci.hpp>
41 
42 #include <gui/core/document.hpp>
46 
50 
51 
54 
55 ///////////////////////////////////////////////////////////////////////////////
56 /// CTextViewProjectItemExtension
57 
59 {
60  static string sid("text_view_project_item_extension");
61  return sid;
62 }
63 
65 {
66  static string slabel("Text View Project item extension");
67  return slabel;
68 }
69 
70 static bool s_GetFirstBioseqName(const CSeq_entry* entry, CScope& scope, string& sSeqid)
71 {
72  CBioseq_CI bs_it(scope, *entry);
73  if (!bs_it) {
74  return false;
75  }
76 
77  // First bioseq handle
78  const CBioseq_Handle& bsh = *bs_it;
79 
80  // FF config
84  0,
86 
87  // FF context
88  CFlatFileContext ffctx(ffcfg);
89 
90  // First bioseq context
91  CBioseqContext bsctx(bsh, ffctx);
92 
93  // FF LOCUS item
94  CLocusItem locus(bsctx);
95  sSeqid = locus.GetName();
96  return !sSeqid.empty();
97 }
98 
99 static bool s_GetFirstBioseqName(CProjectItem& item, CGBDocument& doc, string& sSeqid)
100 {
101  const CSerialObject* so = item.GetObject();
102  if (!so) return false;
103 
104  const CSeq_submit* submit = dynamic_cast<const CSeq_submit *>(so);
105  if (submit && submit->IsSetData() && submit->IsEntrys()) {
107  if (s_GetFirstBioseqName(*it, *doc.GetScope(), sSeqid)) {
108  return true;
109  }
110  }
111  }
112  const CSeq_entry* entry = dynamic_cast<const CSeq_entry *>(so);
113  if (entry) {
114  if (s_GetFirstBioseqName(entry, *doc.GetScope(), sSeqid)) {
115  return true;
116  }
117  }
118 
119  return false;
120 }
121 
123 {
124  if (!item.HasTag("open_text_view"))
125  return;
126 
127  if (!service_locator) return;
128 
129  CProjectService* prj_srv = service_locator->GetServiceByType<CProjectService>();
130 
131  CRef<CGBWorkspace> ws = prj_srv->GetGBWorkspace();
132  if (!ws) return;
133 
134  const CSerialObject* so = item.GetObject();
135  if (!so) return;
136 
137  CRef<CUser_object> params(new CUser_object());
139  type->SetStr("TextViewParams");
140  params->SetType(*type);
141 
142  CUser_object::TData& data = params->SetData();
143 
144  {{
145  CRef<CUser_field> param(new CUser_field());
147  label->SetStr("TextViewType");
148  param->SetLabel(*label);
149  param->SetData().SetStr("Flat File");
150  data.push_back(param);
151  }}
152 
153  {{
154  CRef<CUser_field> param(new CUser_field());
156  label->SetStr("ExpandAll");
157  param->SetLabel(*label);
158  param->SetData().SetBool(true);
159  data.push_back(param);
160  }}
161 
162  string sSeqid;
163  if (s_GetFirstBioseqName(item, doc, sSeqid)) {
164  CRef<CUser_field> param(new CUser_field());
166  label->SetStr("InitialSequence");
167  param->SetLabel(*label);
168  param->SetData().SetStr(sSeqid);
169  data.push_back(param);
170  }
171 
172  SConstScopedObject viewObject(so, doc.GetScope());
173 
174  COpenViewTask* task = new COpenViewTask(service_locator, "Text View", viewObject, params, true);
175  service_locator->GetServiceByType<CAppTaskService>()->AddTask(*task);
176 }
177 
User-defined methods of the data storage class.
CAppTaskService - Application Task Service.
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_Handle –.
CGBDocument.
Definition: document.hpp:113
const string & GetName(void) const
Definition: locus_item.hpp:113
const CSerialObject * GetObject() const
retrieve the object pointed to as a CObject*
bool HasTag(const string &tag) const
Definition: ProjectItem.hpp:95
CProjectService - a service providing API for operations with Workspaces and Projects.
CRef< objects::CGBWorkspace > GetGBWorkspace()
CRef –.
Definition: ncbiobj.hpp:618
CScope –.
Definition: scope.hpp:92
Definition: Seq_entry.hpp:56
bool IsEntrys(void) const
Definition: Seq_submit.cpp:54
Base class for all serializable objects.
Definition: serialbase.hpp:150
virtual void ProjectItemAttached(objects::CProjectItem &item, CGBDocument &doc, IServiceLocator *service_locator)
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual string GetExtensionIdentifier() const
CTextViewProjectItemExtension.
IServiceLocator - an abstract mechanism for locating services.
Definition: service.hpp:71
static int type
Definition: getdata.c:31
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
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
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static const char label[]
TData & SetData(void)
Assign a value to Data data member.
void SetLabel(TLabel &value)
Assign a value to Label data member.
void SetType(TType &value)
Assign a value to Type data member.
void SetData(TData &value)
Assign a value to Data data member.
vector< CRef< CUser_field > > TData
bool IsSetData(void) const
Check if a value has been assigned to Data data member.
list< CRef< CSeq_entry > > TEntrys
const TEntrys & GetEntrys(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
Definition: type.c:6
USING_SCOPE(objects)
static bool s_GetFirstBioseqName(const CSeq_entry *entry, CScope &scope, string &sSeqid)
Modified on Thu Feb 22 17:08:12 2024 by modify_doxy.py rev. 669887