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

Go to the SVN repository for this file.

1 /* $Id: flat_file_context.cpp 45990 2021-01-20 18:23:43Z grichenk $
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 
37 
43 #include "text_commands.hpp"
44 
45 #include <objmgr/seqdesc_ci.hpp>
46 #include <objmgr/feat_ci.hpp>
47 
56 
58 
59 #include "features_group.hpp"
60 #include "sequence_group.hpp"
61 
64 
65 #include "edit_tb.hpp"
66 
67 #include <wx/menu.h>
68 
71 
72 enum
73 {
79 };
80 
81 BEGIN_EVENT_TABLE( CFlatFileViewContext, CTextPanelContext )
86 
90 
92  objects::IFormatter& formatter,
93  objects::CScope& scope,
94  const CSerialObject* so,
95  IBioseqEditor* bioseqEditor)
96  : CTextPanelContext(3, &scope, so),
97  m_Formatter(&formatter),
98  m_BioseqEditor(bioseqEditor)
99 {
100  if (m_BioseqEditor)
101  m_BioseqEditor->SetCallBack(this);
102 }
103 
105 {
106  if (m_Panel && m_BioseqEditor) {
107  m_Panel->PopEventHandler();
108  }
109 }
110 
112 {
113  if (ShowEditIcons())
114  return 32 + 2 * GetWWidth();
115  else
116  return 3 * GetWWidth();
117 }
118 
120 {
121  return m_BioseqEditor && !RunningInsideNCBI();
122 }
123 
124 namespace {
125  class CAddToolbarTraverser : public ICompositeTraverser
126  {
127  public:
128  CAddToolbarTraverser(IBioseqEditor& editor, bool showIcons)
129  : m_Editor(editor), m_ShowIcons(showIcons) {}
130 
131  virtual bool ProcessItem(CTextItem& textItem)
132  {
133  CFlatFileTextItem* flatTextItem = dynamic_cast<CFlatFileTextItem*>(&textItem);
134  if (!flatTextItem)
135  return true;
136 
137  const IFlatItem* flatItem = flatTextItem->GetFlatItem();
138  if (!flatItem) {
139  flatTextItem->SetEditFlags(0);
140  return true;
141  }
142 
143  flatTextItem->SetEditFlags(m_Editor.GetEditFlags(*flatItem));
144  if (m_ShowIcons)
145  flatTextItem->InitToolbar();
146 
147  return true;
148  }
149 
150  virtual bool ProcessItem(CExpandItem& expandItem)
151  {
152  CFlatFileTextItem* flatTextItem = dynamic_cast<CFlatFileTextItem*>(expandItem.GetExpandedItem());
153  if (!flatTextItem)
154  return true;
155 
156  const IFlatItem* flatItem = flatTextItem->GetFlatItem();
157  if (!flatItem)
158  return true;
159 
160  int flags = m_Editor.GetEditFlags(*flatItem);
161 
162  expandItem.SetSelectable(flags != 0);
163  if (flags != 0 && m_ShowIcons)
164  expandItem.AddGlyph(new CEditToolbar(&expandItem, flags));
165 
166  return true;
167  }
168 
169  private:
170  IBioseqEditor& m_Editor;
171  bool m_ShowIcons;
172  };
173 }
174 
176 {
177  if (!m_Panel || !m_BioseqEditor)
178  return;
179 
180  CCompositeTextItem* root = dynamic_cast<CCompositeTextItem*>(m_Panel->GetRootItem());
181  if (root) {
182  CAddToolbarTraverser traverser(*m_BioseqEditor, ShowEditIcons());
183  for (size_t i = 0; i < root->GetItemCount(); ++i)
184  root->GetItem(i)->Traverse(traverser);
185  }
186 }
187 
189 {
190  if (m_Panel && m_BioseqEditor) {
191  m_Panel->PopEventHandler();
192  }
193 
195 
196  if (m_Panel && m_BioseqEditor) {
197  m_Panel->PushEventHandler(m_BioseqEditor);
198  }
199 }
200 
202 {
203 public:
205 
206  virtual bool ProcessItem(CTextItem& textItem) {
207  CFlatFileLocusItem* locusItem = dynamic_cast<CFlatFileLocusItem*>(&textItem);
208  if (locusItem) {
209  SConstScopedObject seq_loc = locusItem->GetSeqLoc();
210  if (seq_loc.object)
211  m_SeqLocs.push_back(seq_loc);
212  return false;
213  }
214  return true;
215  }
216  virtual bool ProcessItem(CExpandItem& expandItem) { return true; }
217 
219 };
220 
222 {
223  CCompositeTextItem* root = dynamic_cast<CCompositeTextItem*>(m_Panel->GetRootItem());
224  if (!root) return;
226  for (size_t i = 0; i < root->GetItemCount(); ++i) {
227  root->GetItem(i)->Traverse(finder);
228  }
229 }
230 
232 {
233  static bool registered = false;
234  if (!registered) {
235  registered = true;
236 
238  "Expand All Features",
239  "Expand All Features",
242  "Command expands(opens) All Features of a FlatFile view");
244  "Collapse All Features",
245  "Collapse All Features",
248  "Command collapses(closes) All Features of a FlatFile view");
250  "Expand Sequence",
251  "Expand Sequence",
254  "Command expands(opens) All Sequence Blocks of a FlatFile view");
256  "Collapse Sequence",
257  "Collapse Sequence",
260  "Command collapses(closes) Sequence Blocks of a FlatFile view");
262  "Collapse Sequences",
263  "Collapse Sequences",
266  "Command collapses(closes) Sequence Sections of a FlatFile view");
267  }
268 }
269 
270 static
271 WX_DEFINE_MENU(kFlatFileContextMenu)
272  WX_MENU_SEPARATOR_L("Edit Selection")
273  WX_MENU_SEPARATOR_L("FlatFile Blocks")
276 WX_END_MENU()
277 
279 {
281  wxMenu* menu = cmd_reg.CreateMenu(kFlatFileContextMenu);
282  if (m_BioseqEditor) {
283  unique_ptr<wxMenu> editorMenu(m_BioseqEditor->CreateContextMenu());
284  if (editorMenu.get()) {
285  Merge(*menu, *editorMenu);
286  }
287  }
288  return menu;
289 }
290 
291 void CFlatFileViewContext::EditItem(ITextItem* WXUNUSED(item), bool controlDown, bool shiftDown)
292 {
293  if (!m_BioseqEditor || controlDown || shiftDown)
294  return;
295 
296  m_BioseqEditor->EditSelection();
297 }
298 
299 void CFlatFileViewContext::OnExpandAllFeatures(wxCommandEvent& WXUNUSED(event))
300 {
301 /*
302  CCompositeTextItem& composite = m_Panel->GetDisplayItem();
303  bool update = false;
304  for (CCompositeIterator sect_it(*composite, typeid(CCompositeTextItem)); sect_it; ++sect_it) {
305  for (CCompositeIterator it(dynamic_cast<CCompositeTextItem&>(*sect_it), typeid(CFeaturesGroup));
306  it; ++it) {
307  dynamic_cast<CFeaturesGroup&>(*it).ExpandAll(this);
308  update = true;
309  }
310  }
311 
312  if (update) {
313  m_Panel->Layout();
314  m_Panel->Refresh();
315  }
316  */
317 }
318 
319 void CFlatFileViewContext::OnCollapseAllFeatures(wxCommandEvent& WXUNUSED(event))
320 {
321 /*
322  CCompositeTextItem& composite = m_Panel->GetDisplayItem();
323  bool update = false;
324  for (CCompositeIterator sect_it(*composite, typeid(CCompositeTextItem)); sect_it; ++sect_it) {
325  for (CCompositeIterator it(dynamic_cast<CCompositeTextItem&>(*sect_it), typeid(CFeaturesGroup));
326  it; ++it) {
327  dynamic_cast<CFeaturesGroup&>(*it).CollapseAll(this);
328  update = true;
329  }
330  }
331 
332  if (update) {
333  m_Panel->Layout();
334  m_Panel->Refresh();
335  }
336  */
337 }
338 
339 void CFlatFileViewContext::OnExpandSeqBlocks(wxCommandEvent& WXUNUSED(event))
340 {
341 /*
342  CCompositeTextItem& composite = m_Panel->GetDisplayItem();
343  bool update = false;
344  for (CCompositeIterator sect_it(*composite, typeid(CCompositeTextItem)); sect_it; ++sect_it) {
345  for (CCompositeIterator it(dynamic_cast<CCompositeTextItem&>(*sect_it), typeid(CSequenceGroup));
346  it; ++it) {
347  dynamic_cast<CSequenceGroup&>(*it).ExpandAll(this);
348  update = true;
349  }
350  }
351 
352  if (update) {
353  m_Panel->Layout();
354  m_Panel->Refresh();
355  }
356  */
357 }
358 
359 void CFlatFileViewContext::OnCollapseSeqBlocks(wxCommandEvent& WXUNUSED(event))
360 {
361 /*
362  CCompositeTextItem& composite = m_Panel->GetDisplayItem();
363  bool update = false;
364  for (CCompositeIterator sect_it(*composite, typeid(CCompositeTextItem)); sect_it; ++sect_it) {
365  for (CCompositeIterator it(dynamic_cast<CCompositeTextItem&>(*sect_it), typeid(CSequenceGroup));
366  it; ++it) {
367  dynamic_cast<CSequenceGroup&>(*it).CollapseAll(this);
368  update = true;
369  }
370  }
371 
372  if (update) {
373  m_Panel->Layout();
374  m_Panel->Refresh();
375  }
376  */
377 }
378 
380 {
381 public:
383 
384  virtual bool ProcessItem(CTextItem& /*textItem*/) { return true; }
385  virtual bool ProcessItem(CExpandItem& expandItem)
386  {
387  CFlatFileSectionHeader* header = dynamic_cast<CFlatFileSectionHeader*>(expandItem.GetCollapsedItem());
388  if (header) {
389  if ((m_Expand && !expandItem.IsExpanded()) || (!m_Expand && expandItem.IsExpanded())) {
390  expandItem.Toggle(&m_Context, false);
391  }
392  return false;
393  }
394  return true;
395  }
397  bool m_Expand;
398 };
399 
400 
401 void CFlatFileViewContext::OnCollapseSequences(wxCommandEvent& event)
402 {
403  CCompositeTextItem* root = dynamic_cast<CCompositeTextItem*>(m_Panel->GetRootItem());
404  if (!root) return;
405 
406  for (size_t i = 0; i < root->GetItemCount(); ++i) {
407  CExpandSeqsTraverser expander(*this, false);
408  root->GetItem(i)->Traverse(expander);
409  }
410 
411  root->UpdatePositions();
412  m_Panel->Layout();
413  m_Panel->Refresh();
415 }
416 
417 void CFlatFileViewContext::OnExpandAll(wxCommandEvent& event)
418 {
419  CCompositeTextItem* root = dynamic_cast<CCompositeTextItem*>(m_Panel->GetRootItem());
420  if (!root) return;
421 
422  CExpandTraverser expander(*this, true);
423  root->Traverse(expander);
424  root->UpdatePositions();
425  m_Panel->Layout();
426  m_Panel->Refresh();
427 
429 }
430 
431 static
432 WX_DEFINE_MENU(kFlatFileBioseqMenu)
433  WX_SUBMENU("BioSource")
434  WX_MENU_SEPARATOR_L("Edit Bioseq")
436 WX_END_MENU()
437 
438 void CFlatFileViewContext::OnEditBioseq(objects::CBioseq_Handle& bh, wxPoint pos)
439 {
440  if (!m_BioseqEditor)
441  return;
442 
443  pos = m_Panel->CalcScrolledPosition(pos);
444 
446  unique_ptr<wxMenu> menu(cmd_reg.CreateMenu(kFlatFileBioseqMenu));
447 
448  {{
449  unique_ptr<wxMenu> editorMenu(m_BioseqEditor->CreateBioseqMenu());
450  if (editorMenu.get()) {
451  Merge(*menu, *editorMenu);
452  }
453  }}
454 
455  CleanupSeparators(*menu);
456 
457  m_CurBioseq = bh;
458  m_Panel->PopupMenu(menu.get(), pos);
459 }
460 
462 {
463  const objects::IFlatItem* item = ffItem.m_Item.GetPointer();
464 
465  const CSeqdesc* odesc = dynamic_cast<const CSeqdesc*>(item->GetObject());
466  if (odesc) {
467  const CFlatItem* fitem = dynamic_cast<const CFlatItem*>(item);
468  if (fitem) {
469  CBioseqContext* ctx = fitem->GetContext();
470  if (ctx) {
471  return CEditObject(*odesc, ctx->GetHandle().GetSeq_entry_Handle());
472  }
473  }
474  }
475  const CSeq_feat* ofeat = dynamic_cast<const CSeq_feat*>(item->GetObject());
476  if (ofeat) {
477  const CFlatItem* fitem = dynamic_cast<const CFlatItem*>(item);
478  if (fitem) {
479  CBioseqContext* ctx = fitem->GetContext();
480  if (ctx) {
481  return CEditObject(*ofeat, ctx->GetHandle().GetSeq_entry_Handle());
482  }
483  }
484  }
485 
486  const CSourceItem* sourceItem = dynamic_cast<const CSourceItem*>(item);
487  if (sourceItem) {
488  CBioseqContext* ctx = sourceItem->GetContext();
489  if (!ctx)
490  return CEditObject();
491 
492  CBioseq_Handle& bh = ctx->GetHandle();
493  CSeqdesc_CI dsrc_it(bh, CSeqdesc::e_Source);
494  if (dsrc_it) {
495  return CEditObject(*dsrc_it, bh.GetSeq_entry_Handle());
496  }
497  CFeat_CI fsrc_it(bh, CSeqFeatData::e_Biosrc);
498  if (fsrc_it) {
499  CSeq_feat_Handle fh = *fsrc_it;
501  }
502  return CEditObject();
503  }
504 
505  const CSequenceItem* seqItem = dynamic_cast<const CSequenceItem*>(item);
506  if (seqItem) {
507  CBioseqContext* ctx = seqItem->GetContext();
508  if (!ctx)
509  return CEditObject();
510 
511  CBioseq_Handle& bh = ctx->GetHandle();
512  return CEditObject(*bh.GetRangeSeq_loc(seqItem->GetFrom() - 1, seqItem->GetTo() - 1), bh.GetSeq_entry_Handle());
513  }
514 
515  const CCommentItem* commentItem = dynamic_cast<const CCommentItem*>(item);
516  if (commentItem) {
517  const CSeqdesc* desc = dynamic_cast<const CSeqdesc*>(commentItem->GetObject());
518  if (desc) {
519  CBioseqContext* ctx = commentItem->GetContext();
520  if (!ctx)
521  return CEditObject();
522 
523  CBioseq_Handle& bh = ctx->GetHandle();
524 
525  return CEditObject(*desc, bh.GetSeq_entry_Handle());
526  }
527  return CEditObject();
528  }
529 
530  const CSourceFeatureItem* sourceFeatureItem
531  = dynamic_cast<const CSourceFeatureItem*>(item);
532  if (sourceFeatureItem) {
533  const CSeq_feat* seq_feat = dynamic_cast<const CSeq_feat*>(item->GetObject());
534  if (!seq_feat)
535  return CEditObject();
536 
537  CBioseqContext* ctx = sourceFeatureItem->GetContext();
538  if (!ctx)
539  return CEditObject();
540 
541  CBioseq_Handle& bh = ctx->GetHandle();
542 
543  const CSeq_feat::TData& data = seq_feat->GetData();
544  if (data.IsBiosrc()) {
545  const CBioSource& bioSource = data.GetBiosrc();
546  CSeqdesc_CI dsrc_it(ctx->GetHandle(), CSeqdesc::e_Source);
547  if (dsrc_it) {
548  const CSeqdesc& seqDesc = *dsrc_it;
549  if (seqDesc.IsSource()) {
550  const CBioSource& bioSource2 = seqDesc.GetSource();
551  if (&bioSource2 == &bioSource) {
552  return CEditObject(seqDesc, bh.GetSeq_entry_Handle());
553  }
554  }
555  }
556  }
557 
558  //CFeat_CI fsrc_it(ctx->GetHandle(), CSeqFeatData::e_Biosrc);
559  //if (fsrc_it) {
560  // CSeq_feat_Handle fh = *fsrc_it;
561  // objects.push_back(CEditObject(*fh.GetOriginalSeq_feat(), bh.GetSeq_entry_Handle()));
562  // continue;
563  //}
564  return CEditObject(*seq_feat, bh.GetSeq_entry_Handle());
565  }
566 
567  const CLocusItem* locusItem = dynamic_cast<const CLocusItem*>(item);
568  if (locusItem) {
569  CBioseqContext* ctx = locusItem->GetContext();
570  if (!ctx)
571  return CEditObject();
572 
573  CBioseq_Handle& bh = ctx->GetHandle();
574 
575  const CMolInfo* molInfo = dynamic_cast<const CMolInfo*>(item->GetObject());
576  if (!molInfo)
577  return CEditObject();
578  CSeqdesc_CI dsrc_it(ctx->GetHandle(), CSeqdesc::e_Molinfo);
579  for (; dsrc_it; ++dsrc_it) {
580  const CSeqdesc& seqDesc = *dsrc_it;
581  if (&seqDesc.GetMolinfo() == molInfo) {
582  return CEditObject(seqDesc, bh.GetSeq_entry_Handle());
583  }
584  }
585  return CEditObject();
586  }
587 
588  const CDeflineItem* defLineItem = dynamic_cast<const CDeflineItem*>(item);
589  if (defLineItem) {
590  CBioseqContext* ctx = defLineItem->GetContext();
591  if (!ctx)
592  return CEditObject();
593  const CSeqdesc* desc = dynamic_cast<const CSeqdesc*>(item->GetObject());
594  if (desc) {
595  return CEditObject(*desc, ctx->GetHandle().GetSeq_entry_Handle());
596  }
597 
598  CBioseq_Handle& bh = ctx->GetHandle();
600  if (di) {
601  return CEditObject(*di, bh.GetSeq_entry_Handle());
602  }
603  else {
604  CRef<CTitleEdit> titleEdit(new CTitleEdit());
605  titleEdit->SetTitle(defLineItem->GetDefline());
606  return CEditObject(*titleEdit, bh.GetSeq_entry_Handle());
607  }
608  }
609 
610 
611  const CReferenceItem* refItem = dynamic_cast<const CReferenceItem*>(item);
612  if (refItem) {
613  CBioseqContext* ctx = refItem->GetContext();
614  if (!ctx)
615  return CEditObject();
616 
617  CBioseq_Handle& bh = ctx->GetHandle();
618 
619  const CSubmit_block* submitBlock = dynamic_cast<const CSubmit_block*>(item->GetObject());
620  if (submitBlock)
621  return CEditObject(*submitBlock, bh.GetSeq_entry_Handle());
622 
623  const CSeq_feat* seq_feat = dynamic_cast<const CSeq_feat*>(item->GetObject());
624  if (seq_feat) {
625  CSeq_feat_Handle fh = ctx->GetScope().GetSeq_featHandle(*seq_feat, CScope::eMissing_Null);
626  if (fh)
628  return CEditObject();
629  }
630  const CSeqdesc* seqDesc = dynamic_cast<const CSeqdesc*>(item->GetObject());
631  if (seqDesc && seqDesc->IsPub())
632  return CEditObject(*seqDesc, bh.GetSeq_entry_Handle());
633 
634  return CEditObject();
635  }
636 
637 
638  const CFeatureItem* featureItem = dynamic_cast<const CFeatureItem*>(item);
639  if (featureItem) {
640  const CSeq_feat* seq_feat = dynamic_cast<const CSeq_feat*>(item->GetObject());
641  if (!seq_feat)
642  return CEditObject();
643 
644  CBioseqContext* ctx = featureItem->GetContext();
645  if (!ctx)
646  return CEditObject();
647 
648  CSeq_feat_Handle fh = ctx->GetScope().GetSeq_featHandle(*seq_feat, CScope::eMissing_Null);
649  if (fh) {
650  CBioseq_Handle& bh = ctx->GetHandle();
652  }
653  return CEditObject();
654  }
655 
656 
657  const CGenomeProjectItem* genomeProjectItem = dynamic_cast<const CGenomeProjectItem*>(item);
658  if (genomeProjectItem) {
659  CBioseqContext* ctx = genomeProjectItem->GetContext();
660  if (!ctx)
661  return CEditObject();
662 
663  // extract all the useful user objects
664 
665  for (CSeqdesc_CI desc(ctx->GetHandle(), CSeqdesc::e_User); desc; ++desc) {
666  const CUser_object& uo = desc->GetUser();
667 
668  if (!uo.GetType().IsStr())
669  return CEditObject();
670 
671  if (NStr::EqualNocase(uo.GetType().GetStr(), "DBLink")) {
672  CBioseq_Handle& bh = ctx->GetHandle();
673  const CSeqdesc& seqDesc = *desc;
674  return CEditObject(seqDesc, bh.GetSeq_entry_Handle());
675  }
676  }
677  return CEditObject();
678  }
679 
680 
681  const CPrimaryItem* primary_item = dynamic_cast<const CPrimaryItem*>(item);
682  if (primary_item) {
683  CBioseqContext* ctx = primary_item->GetContext();
684  if (!ctx)
685  return CEditObject();
686 
687  for (CSeqdesc_CI desc(ctx->GetHandle(), CSeqdesc::e_User); desc; ++desc) {
688  const CUser_object& uo = desc->GetUser();
689 
690  if (!uo.GetType().IsStr())
691  return CEditObject();
692 
693  if (NStr::EqualNocase(uo.GetType().GetStr(), "TpaAssembly")) {
694  CBioseq_Handle& bh = ctx->GetHandle();
695  const CSeqdesc& seqDesc = *desc;
696  return CEditObject(seqDesc, bh.GetSeq_entry_Handle());
697  }
698  }
699  return CEditObject();
700  }
701 
702  return CEditObject();
703 }
704 
706 {
708  CFlatFileTextItem* ffItem = 0;
709  CExpandItem* expandItem = dynamic_cast<CExpandItem*>(*it);
710 
711  if (expandItem)
712  ffItem = dynamic_cast<CFlatFileTextItem*>(expandItem->GetExpandedItem());
713  else
714  ffItem = dynamic_cast<CFlatFileTextItem*>(*it);
715 
716  if (!ffItem || ffItem->GetEditFlags() == 0 || ffItem->GetFlatItem() == nullptr)
717  continue;
718 
719  itemList.emplace_back(ffItem->GetFlatItem());
720  }
721 }
722 
724 {
726  CFlatFileTextItem* ffItem = 0;
727  CExpandItem* expandItem = dynamic_cast<CExpandItem*>(*it);
728 
729  if (expandItem)
730  ffItem = dynamic_cast<CFlatFileTextItem*>(expandItem->GetExpandedItem());
731  else
732  ffItem = dynamic_cast<CFlatFileTextItem*>(*it);
733 
734  if (!ffItem)
735  continue;
736 
737  CEditObject eo = GetEditObject(*ffItem);
738  if (!eo.m_Obj)
739  continue;
740  objects.push_back(eo);
741  }
742 
743  set<const CObject*> objSet;
744  for (TEditObjectList::iterator it2 = objects.begin(); it2 != objects.end();) {
745  const CObject* pobj = it2->m_Obj.GetPointer();
746  if (objSet.find(pobj) != objSet.end()) {
747  it2 = objects.erase(it2);
748  } else {
749  objSet.insert(pobj);
750  ++it2;
751  }
752  }
753 }
754 
756 {
757  return m_CurBioseq;
758 }
759 
761 {
762  return m_WorkDir;
763 }
764 
765 bool CFlatFileViewContext::FindSequence(const wxString& findText)
766 {
767  if (!m_Panel) return false;
768 
770  cursorPos.ShiftCol(1);
771 
772  string text = ToStdString(findText);
774  if (text.empty()) return false;
775 
777  size_t findLength = text.length();
778  if (findLength > 60) {
779  text = text.substr(0, 60);
780  findLength = 60;
781  }
782 
783  for(CFlatFileSeqBlockIterator it(*m_Panel, cursorPos); it;) {
784  string block1 = *it, block2;
785  string buffer = block1;
786  CFlatFileSeqBlockIterator it2 = it;
787  ++it2;
788  if (it2) {
789  block2 = *it2;
790  if (findLength > 1 && !it2.NextSequence())
791  buffer += block2.substr(0, findLength - 1);
792  }
793  if (buffer.length() >= findLength) {
795  size_t pos = buffer.find(text);
796  if (pos != string::npos) {
797  CTextPosition start = it.GetPosition(pos);
798  CTextPosition end = it.GetPosition(pos + findLength - 1);
799  end.ShiftCol(1);
800  m_Panel->MakePosVisible(start);
801  m_MarkedSeq = CTextBlock(start, end);
802  m_Panel->SetSelection(CTextBlock(start, start));
803  return true;
804  }
805  }
806  it = it2;
807  }
808 
809  return false;
810 }
811 
812 namespace {
813 class CSeqMarkertModifier : public CDrawTextOStream::IStyleModifier
814 {
815 public:
816  static CDrawTextOStream::IStyleModifier& GetInstance()
817  {
818  static CSeqMarkertModifier _inst;
819  return _inst;
820  }
821  virtual void SetStyle(wxDC& dc)
822  {
823  //dc.SetBackgroundMode(wxTRANSPARENT);
824  //dc.SetTextForeground(wxColor(222,50,0));
825 
826  dc.SetBackgroundMode(wxSOLID);
827  dc.SetTextForeground(wxColor(0,0,0));
828  dc.SetTextBackground(wxColor(175,238,238));
829  }
830 };
831 }
832 
834 {
835  if (m_MarkedSeq.IsEmpty()) return;
836 
837  CTextBlock mark = m_MarkedSeq;
838  mark.ShiftRow(-startLine);
839 
840  int startRow = m_MarkedSeq.GetStart().GetRow() - startLine;
841  int endRow = m_MarkedSeq.GetEnd().GetRow() - startLine;
842 
843  CDrawTextOStream::IStyleModifier& seqMarker = CSeqMarkertModifier::GetInstance();
844 
845  if (startRow == endRow) {
846  stream.AddMarker(startRow, m_MarkedSeq.GetStart().GetCol(),
847  startRow, m_MarkedSeq.GetEnd().GetCol(), &seqMarker);
848  return;
849  }
850 
851  stream.AddMarker(startRow, m_MarkedSeq.GetStart().GetCol(),
852  startRow, 80, &seqMarker);
853  for (int i = startRow + 1; i < endRow; ++i)
854  stream.AddMarker(i, 10, i, 80, &seqMarker);
855  stream.AddMarker(endRow, 10, endRow, m_MarkedSeq.GetEnd().GetCol(), &seqMarker);
856 }
857 
CBioseq_Handle –.
ITextItem * GetItem(size_t index)
virtual void UpdatePositions()
virtual bool Traverse(ICompositeTraverser &traverser)
size_t GetItemCount() const
const string & GetDefline(void) const
void AddMarker(int startRow, int startCol, int endRow, int endCol, IStyleModifier *style)
CConstRef< CObject > m_Obj
virtual void Toggle(CTextPanelContext *context, bool update)
Definition: expand_item.cpp:84
void AddGlyph(CGlyph *glyph)
Definition: expand_item.cpp:69
void SetSelectable(bool selectable=true)
Definition: expand_item.hpp:54
virtual bool IsExpanded() const
Definition: expand_item.hpp:63
CTextItem * GetExpandedItem()
Definition: expand_item.hpp:60
CTextItem * GetCollapsedItem()
Definition: expand_item.hpp:59
virtual bool ProcessItem(CExpandItem &expandItem)
virtual bool ProcessItem(CTextItem &)
CExpandSeqsTraverser(CTextPanelContext &context, bool expand)
CTextPanelContext & m_Context
CFeat_CI –.
Definition: feat_ci.hpp:64
virtual bool ProcessItem(CExpandItem &expandItem)
CFindLocusTraverser(TConstScopedObjects &objects)
virtual bool ProcessItem(CTextItem &textItem)
TConstScopedObjects & m_SeqLocs
SConstScopedObject GetSeqLoc()
const objects::IFlatItem * GetFlatItem() const
CConstRef< objects::IFlatItem > m_Item
void SetEditFlags(int flags)
void OnCollapseSeqBlocks(wxCommandEvent &event)
virtual void GetVisibleObjects(TConstScopedObjects &objects)
virtual int GetLeftMargin() const
virtual void GetCurrentSelection(TEditObjectList &objects)
virtual void EditItem(ITextItem *item, bool controlDown, bool shiftDown)
void OnCollapseAllFeatures(wxCommandEvent &event)
void OnCollapseSequences(wxCommandEvent &event)
void OnExpandAll(wxCommandEvent &event)
objects::CBioseq_Handle m_CurBioseq
void OnExpandAllFeatures(wxCommandEvent &event)
virtual void SetPanel(CTextItemPanel *panel)
CEditObject GetEditObject(CFlatFileTextItem &ffItem)
virtual wxString GetWorkDir() const
static void RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
virtual objects::CBioseq_Handle GetCurrentBioseq()
virtual void GetItemSelection(TFlatItemList &itemList)
virtual void InitDrawStream(CDrawTextOStream &stream, int startLine)
virtual void RootInitialized()
virtual bool FindSequence(const wxString &text)
CIRef< IBioseqEditor > m_BioseqEditor
void OnExpandSeqBlocks(wxCommandEvent &event)
CBioseqContext * GetContext(void)
Definition: item_base.hpp:113
const CSerialObject * GetObject(void) const
Definition: item_base.hpp:99
CObject –.
Definition: ncbiobj.hpp:180
CRef –.
Definition: ncbiobj.hpp:618
CScope –.
Definition: scope.hpp:92
CSeq_feat_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
TSeqPos GetTo(void) const
TSeqPos GetFrom(void) const
Base class for all serializable objects.
Definition: serialbase.hpp:150
CSubmit_block –.
bool IsEmpty() const
CTextPosition GetEnd() const
CTextPosition GetStart() const
CTextBlock Normalized() const
void ShiftRow(int delta)
void MakePosVisible(const CTextPosition &pos)
ITextItem * GetRootItem()
virtual bool Layout()
CTextBlock GetTextSelection() const
void SetSelection(const CTextBlock &selection)
virtual void SetPanel(CTextItemPanel *panel)
set< ITextItem * > m_SelectedItems
CTextItemPanel * m_Panel
int GetRow() const
int GetCol() const
void ShiftCol(int delta)
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
static CUICommandRegistry & GetInstance()
the main instance associated with the application
Definition: ui_command.cpp:176
wxMenu * CreateMenu(const SwxMenuItemRec *items)
create a menu from a static definition (see WX_*_MENU macros)
Definition: ui_command.cpp:349
int RegisterCommand(CUICommand *cmd)
assumes ownership of the given object returns a command id (useful when registry is used for auto id ...
Definition: ui_command.cpp:198
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
USING_SCOPE(objects)
@ kCollapseAllFeatures
@ kExpandAllFeatures
@ kCollapseSeqBlocks
@ kCollapseSequences
@ kExpandSeqBlocks
CS_CONTEXT * ctx
Definition: t0006.c:12
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
CConstRef< CObject > object
Definition: objects.hpp:52
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
@ eMissing_Null
Definition: scope.hpp:157
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Get parent Seq-entry handle.
CConstRef< CSeq_feat > GetOriginalSeq_feat(void) const
CRef< CSeq_loc > GetRangeSeq_loc(TSeqPos start, TSeqPos stop, ENa_strand strand=eNa_strand_unknown) const
Return CSeq_loc referencing the given range and strand on the bioseq If start == 0,...
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
#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 void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate whitespace in a string (in-place)
Definition: ncbistr.cpp:3192
#define NcbiEmptyString
Definition: ncbistr.hpp:122
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5347
static string & ToUpper(string &str)
Convert string to upper case – string& version.
Definition: ncbistr.cpp:424
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
const TType & GetType(void) const
Get the Type member data.
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const TSource & GetSource(void) const
Get the variant data.
Definition: Seqdesc_.cpp:566
bool IsSource(void) const
Check if variant Source is selected.
Definition: Seqdesc_.hpp:1190
bool IsPub(void) const
Check if variant Pub is selected.
Definition: Seqdesc_.hpp:1096
const TMolinfo & GetMolinfo(void) const
Get the variant data.
Definition: Seqdesc_.cpp:588
@ e_User
user defined object
Definition: Seqdesc_.hpp:124
@ e_Molinfo
info on the molecule and techniques
Definition: Seqdesc_.hpp:134
@ e_Title
a title for this sequence
Definition: Seqdesc_.hpp:115
@ e_Source
source of materials, includes Org-ref
Definition: Seqdesc_.hpp:133
vector< CEditObject > TEditObjectList
vector< CConstRef< objects::IFlatItem > > TFlatItemList
END_EVENT_TABLE()
int i
static void text(MDB_val *v)
Definition: mdb_dump.c:62
static uint8_t * buffer
Definition: pcre2test.c:1016
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
@ kExpandAll
#define WX_DEFINE_MENU(name)
New macros for defining menus for use with CUICommandRegistry.
Definition: ui_command.hpp:266
#define WX_SUBMENU(label)
Definition: ui_command.hpp:288
#define WX_END_MENU()
Definition: ui_command.hpp:294
#define WX_MENU_SEPARATOR_L(label)
Definition: ui_command.hpp:285
#define WX_MENU_ITEM(cmd)
Definition: ui_command.hpp:270
#define WX_END_SUBMENU()
Definition: ui_command.hpp:291
static CS_CONTEXT * context
Definition: will_convert.c:21
wxMenu * CreateMenu(const CMenuItem *item)
Creates a wxMenu object replicating the structure of CMenuItem.
Definition: wx_utils.cpp:365
void Merge(wxMenu &menu_1, const wxMenu &menu_2)
merges all items form menu_2 into menu_1, preserving the structure if possible
Definition: wx_utils.cpp:579
bool RunningInsideNCBI()
Definition: wx_utils.cpp:1335
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
void CleanupSeparators(wxMenu &menu)
Removes extra separators (in the begining or at the end of the menu, ot those that precede other sepa...
Definition: wx_utils.cpp:668
#define const
Definition: zconf.h:232
Modified on Fri Sep 20 14:58:01 2024 by modify_doxy.py rev. 669887