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

Go to the SVN repository for this file.

1 /* $Id: asn_view_context.cpp 41060 2018-05-16 18:11:00Z 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 
36 
43 
45 
46 #include <wx/menu.h>
47 #include <wx/settings.h>
48 #include <wx/dcclient.h>
49 
52 
53 CAsnViewContext::CAsnViewContext(objects::CScope& scope, const CSerialObject* so, IBioseqEditor* bioseqEditor, bool tooltpContext)
54  : CTextPanelContext(1, &scope, so),
55  m_BioseqEditor(bioseqEditor),
56  m_TooltipContext(tooltpContext),
57  m_ShowAsnTypes(false),
58  m_ShowPathToRoot(false)
59 {
60  if (m_BioseqEditor)
61  m_BioseqEditor->SetCallBack(this);
62 }
63 
65 {
66  if (m_Panel && m_BioseqEditor) {
67  m_Panel->PopEventHandler();
68  }
69 
71 
72  if (m_Panel && m_BioseqEditor) {
73  m_Panel->PushEventHandler(m_BioseqEditor);
74  }
75 }
76 
78 {
79  if (m_Panel && m_BioseqEditor) {
80  m_Panel->PopEventHandler();
81  }
82 }
83 
85 {
86  m_ShowAsnTypes = show;
87 }
88 
90 {
91  m_ShowPathToRoot = show;
92 }
93 
95 {
96  CCompositeTextItem* composite = dynamic_cast<CCompositeTextItem*>(container);
97  if (composite == 0 || composite->GetItemCount() == 0)
98  return;
99 
100  CAsnHeaderItem* headerItem = dynamic_cast<CAsnHeaderItem*>(composite->GetItem(0));
101  if (headerItem) {
102  AddHier(headerItem);
103  return;
104  }
105 
106  CAsnElementBlockStart* blockStart = dynamic_cast<CAsnElementBlockStart*>(composite->GetItem(0));
107  if (blockStart) {
108  AddHier(blockStart);
109  return;
110  }
111 }
112 
114 {
115  if (!m_ShowPathToRoot || m_MouseOverItem == 0 || m_Hier.empty())
116  return NULL;
117 
118  CTextItemPanel* tooltipWnd = new CTextItemPanel( m_Panel, wxID_ANY, wxDefaultPosition, wxSize(0,0), wxBORDER_SIMPLE|wxHSCROLL|wxVSCROLL );
119  tooltipWnd->Hide();
120  tooltipWnd->SetBackgroundColour(wxColor(255, 255, 225));
121 
122  CCompositeTextItem* mainItem = new CCompositeTextItem();
123 
125  info->AddLine("Path to Root:");
126  mainItem->AddItem(info);
127 
128  for (size_t i = 0; i < m_Hier.size(); ++i) {
129  ITextItem* item = m_Hier[i]->Clone();
130  if (item) {
131  mainItem->AddItem(item);
132  }
133  }
134 
135  CTextPanelContext* context = new CAsnViewContext(*m_Scope, 0, 0, true);
136 
137  try {
138  wxClientDC dc(tooltipWnd);
139  tooltipWnd->InitDC(dc);
140  context->CalcWSize(dc);
141  mainItem->CalcSize(dc, context);
142  } catch (const exception&) {
143  }
144  wxSize size = mainItem->GetSize();
145  tooltipWnd->SetClientSize(size);
146 
147  tooltipWnd->SetMainItem(mainItem, context);
148  tooltipWnd->Layout();
149 
150  return tooltipWnd;
151 }
152 
153 namespace {
154  class CUpdtateEditingTraverser : public ICompositeTraverser
155  {
156  public:
157  CUpdtateEditingTraverser(IBioseqEditor& editor, CScope& scope)
158  : m_Editor(editor), m_Scope(scope) {}
159 
160  virtual bool ProcessItem(CTextItem& textItem)
161  {
162  CAsnElementItem* asnItem = dynamic_cast<CAsnElementItem*>(&textItem);
163  if (asnItem)
164  x_UpdateEditFlags(*asnItem);
165  return true;
166  }
167  virtual bool ProcessItem(CExpandItem& expandItem)
168  {
169  int flags = 0;
170  CAsnElementItem* asnItem = dynamic_cast<CAsnElementItem*>(expandItem.GetCollapsedItem());
171  if (asnItem)
172  flags = x_UpdateEditFlags(*asnItem);
173  expandItem.SetSelectable(flags != 0);
174 
175  return true;
176  }
177 
178  private:
179  int x_UpdateEditFlags(CAsnElementItem& asnItem)
180  {
181  int flags = 0;
182  CEditObject eo = asnItem.GetEditObject(m_Scope);
183  if (eo.m_Obj)
184  flags = m_Editor.GetEditFlags(eo);
185  asnItem.SetEditFlags(flags);
186  return flags;
187  }
188 
189  IBioseqEditor& m_Editor;
190  CScope& m_Scope;
191  };
192 }
193 
195 {
196  if (m_Panel && m_BioseqEditor) {
197  CCompositeTextItem* root = dynamic_cast<CCompositeTextItem*>(m_Panel->GetRootItem());
198  if (root) {
199  CUpdtateEditingTraverser traverser(*m_BioseqEditor, *m_Scope);
200  for (size_t i = 0; i < root->GetItemCount(); ++i)
201  root->GetItem(i)->Traverse(traverser);
202  }
203  }
204 }
205 
206 
208 {
209  if (m_BioseqEditor) {
210  return m_BioseqEditor->CreateContextMenu();
211  }
212  return 0;
213 }
214 
216 {
218  CAsnElementItem* asnItem = 0;
219  CExpandItem* expandItem = dynamic_cast<CExpandItem*>(*it);
220  if (expandItem) {
221  asnItem = dynamic_cast<CAsnElementItem*>(expandItem->GetCollapsedItem());
222  }
223  else
224  asnItem = dynamic_cast<CAsnElementItem*>(*it);
225 
226  if (!asnItem)
227  continue;
228 
229  CEditObject eo = asnItem->GetEditObject(*m_Scope);
230  if (!eo.m_Obj)
231  continue;
232  objects.push_back(eo);
233  }
234 
235  set<const CObject*> objSet;
236  for (TEditObjectList::iterator it2 = objects.begin(); it2 != objects.end();) {
237  const CObject* pobj = it2->m_Obj.GetPointer();
238  if (objSet.find(pobj) != objSet.end()) {
239  it2 = objects.erase(it2);
240  } else {
241  objSet.insert(pobj);
242  ++it2;
243  }
244  }
245 }
246 
248 {
249  return CBioseq_Handle();
250 }
251 
253 {
254  return m_WorkDir;
255 }
256 
257 
static CRef< CScope > m_Scope
USING_SCOPE(objects)
void SetEditFlags(int flags)
CEditObject GetEditObject(objects::CScope &scope)
virtual objects::CBioseq_Handle GetCurrentBioseq()
virtual void SetPanel(CTextItemPanel *panel)
CIRef< IBioseqEditor > m_BioseqEditor
virtual void RootInitialized()
virtual wxWindow * CreateTooltipWindow()
void SetShowAsnTypes(bool show)
virtual wxString GetWorkDir() const
virtual void GetCurrentSelection(TEditObjectList &objects)
virtual void MouseMoveInContainer(ITextItem *container)
virtual wxMenu * CreateMenu() const
void SetShowPathToRoot(bool show)
CAsnViewContext(objects::CScope &scope, const CSerialObject *so, IBioseqEditor *bioseqEditor=0, bool tooltpContext=false)
CBioseq_Handle –.
ITextItem * GetItem(size_t index)
virtual void CalcSize(wxDC &dc, CTextPanelContext *context)
size_t GetItemCount() const
void AddItem(ITextItem *item, bool updatePositions=true)
CConstRef< CObject > m_Obj
void SetSelectable(bool selectable=true)
Definition: expand_item.hpp:54
CTextItem * GetCollapsedItem()
Definition: expand_item.hpp:59
CObject –.
Definition: ncbiobj.hpp:180
CScope –.
Definition: scope.hpp:92
Base class for all serializable objects.
Definition: serialbase.hpp:150
void InitDC(wxDC &dc)
void SetMainItem(ITextItem *item, CTextPanelContext *context)
ITextItem * GetRootItem()
virtual bool Layout()
virtual wxSize GetSize() const
Definition: text_item.hpp:140
ITextItem * m_MouseOverItem
friend class CTextItemPanel
void AddHier(ITextItem *item)
CRef< objects::CScope > m_Scope
vector< ITextItem * > m_Hier
virtual void SetPanel(CTextItemPanel *panel)
set< ITextItem * > m_SelectedItems
CTextItemPanel * m_Panel
IBioseqEditor.
virtual bool Traverse(ICompositeTraverser &)=0
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
static uch flags
#define false
Definition: bool.h:36
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
vector< CEditObject > TEditObjectList
int i
static MDB_envinfo info
Definition: mdb_load.c:37
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
static CS_CONTEXT * context
Definition: will_convert.c:21
Modified on Fri Sep 20 14:57:33 2024 by modify_doxy.py rev. 669887