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 39822 2017-11-08 16:43:19Z 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 
void AddHier(ITextItem *item)
CBioseq_Handle –.
void CalcWSize(wxDC &dc)
virtual objects::CBioseq_Handle GetCurrentBioseq()
virtual void MouseMoveInContainer(ITextItem *container)
virtual wxWindow * CreateTooltipWindow()
USING_SCOPE(objects)
CTextItem * GetCollapsedItem()
Definition: expand_item.hpp:59
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator find(const key_type &key) const
Definition: set.hpp:137
#define NULL
Definition: ncbistd.hpp:225
const_iterator end() const
Definition: set.hpp:136
void SetShowPathToRoot(bool show)
virtual bool Layout()
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:795
int i
void SetSelectable(bool selectable=true)
Definition: expand_item.hpp:54
virtual wxMenu * CreateMenu() const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
friend class CTextItemPanel
virtual void SetPanel(CTextItemPanel *panel)
void SetEditFlags(int flags)
virtual void GetCurrentSelection(TEditObjectList &objects)
void InitDC(wxDC &dc)
CEditObject GetEditObject(objects::CScope &scope)
set< ITextItem * > m_SelectedItems
void AddItem(ITextItem *item, bool updatePositions=true)
virtual void CalcSize(wxDC &dc, CTextPanelContext *context)
void SetMainItem(ITextItem *item, CTextPanelContext *context)
ITextItem * GetRootItem()
int size
vector< ITextItem * > m_Hier
static MDB_envinfo info
Definition: mdb_load.c:37
void SetShowAsnTypes(bool show)
virtual wxSize GetSize() const
Definition: text_item.hpp:140
virtual bool ProcessItem(CTextItem &textItem)=0
vector< CEditObject > TEditObjectList
CIRef< IBioseqEditor > m_BioseqEditor
CScope –.
Definition: scope.hpp:90
ITextItem * GetItem(size_t index)
CTextItemPanel * m_Panel
static CRef< CScope > m_Scope
static uch flags
Base class for all serializable objects.
Definition: serialbase.hpp:149
CObject –.
Definition: ncbiobj.hpp:180
virtual bool Traverse(ICompositeTraverser &)=0
IBioseqEditor.
CRef< objects::CScope > m_Scope
ITextItem * m_MouseOverItem
Definition: dbpivot.c:60
size_t GetItemCount() const
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
CConstRef< CObject > m_Obj
virtual void SetPanel(CTextItemPanel *panel)
static static static wxID_ANY
CAsnViewContext(objects::CScope &scope, const CSerialObject *so, IBioseqEditor *bioseqEditor=0, bool tooltpContext=false)
virtual void RootInitialized()
void AddLine(const string &line)
Modified on Mon Apr 23 11:43:37 2018 by modify_doxy.py rev. 546573