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

Go to the SVN repository for this file.

1 /* $Id: phy_tree_view.cpp 47473 2023-04-26 02:25:49Z evgeniev $
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: Vladimir Tereshkov
27  *
28  * File Description:
29  * Phylogenetic tree viewer
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 
35 #include <algorithm>
36 
38 
44 
47 
49 
54 
58 
60 
61 #include <gui/objutils/utils.hpp>
62 #include <gui/objutils/label.hpp>
66 
67 #include <serial/serialimpl.hpp>
68 
69 
77 #include <objects/biotree/Node.hpp>
81 
84 
85 #include <util/compress/lzo.hpp>
86 #include <corelib/ncbitime.hpp>
87 
88 #include <wx/menu.h>
89 #include <wx/app.h>
90 
93 
94 /// Timers:
97 
100 
103 
105 {
106 public:
108  TTreeIdx GetNodeIdx() const { return m_NodeIdx; }
109 
110 protected:
112 };
113 
115 {
116 public:
119  {
120  CPhyloTreeNode& node = tree[node_idx];
121  if ((delta==1 || delta==0) && !(*node).GetSeqID().Empty()){
122  m_Idx->Add(new CSelNodeHandle(node_idx), (*node).GetSeqID().GetObject());
123  }
124  return eTreeTraverse;
125  }
126 private:
128 };
129 
130 
132 {
133 public:
136  CRef<CBioTreeContainer> new_tree) : m_View(view)
137  {
138 
139 
140  {
141  CNcbiOstrstream ostr;
142 
143  ostr << MSerial_AsnText << *prev_tree;
144  string s = CNcbiOstrstreamToString(ostr);
145  size_t len = s.size();
147  m_UtilVec.resize(buf_size);
148 
149  size_t compressed_len;
150  m_Compressor.CompressBuffer(s.data(), len,
151  (void*)(&m_UtilVec[0]), buf_size, &compressed_len);
152 
154  memcpy((void*)(&m_Tree.orig_tree[0]), (void*)(&m_UtilVec[0]),compressed_len);
155  }
156  {
157  CNcbiOstrstream ostr;
158 
159  ostr << MSerial_AsnText << *new_tree;
160  string s = CNcbiOstrstreamToString(ostr);
161  size_t len = s.size();
163  m_UtilVec.resize(buf_size);
164 
165  size_t compressed_len;
166 
167  m_Compressor.CompressBuffer((void*)s.data(), len,
168  (void*)(&m_UtilVec[0]), buf_size, &compressed_len);
169 
171  memcpy((void*)(&m_Tree.new_tree[0]), (void*)(&m_UtilVec[0]),compressed_len);
172  }
173  }
174  virtual void Execute()
175  {
176  CStopWatch timer;
177  timer.Start();
178 
179  size_t uncompressed_len;
180  m_UtilVec.resize(m_UtilVec.capacity());
181 
183  (void*)(&m_UtilVec[0]), m_UtilVec.size(), &uncompressed_len);
184 
185  CNcbiIstrstream istr(string(&(m_UtilVec[0]), uncompressed_len));
186  m_View->CommitTheChanges(istr);
187 
188  CStopWatch timer2;
189  timer2.Start();
190  // Invoked from OnProjectChanged
191  // m_View->OnBioTreeChanged();
192  m_ExecOnBioTreeChanged = timer2.Elapsed();
193 
194  m_ExecuteUndoCommand = timer.Elapsed();
195  }
196  virtual void Unexecute()
197  {
198  size_t uncompressed_len;
199  m_UtilVec.resize(m_UtilVec.capacity());
200 
202  (void*)(&m_UtilVec[0]), m_UtilVec.size(), &uncompressed_len);
203 
204  CNcbiIstrstream istr(string(&(m_UtilVec[0]), uncompressed_len));
205  m_View->CommitTheChanges(istr);
206 
208  }
209  virtual string GetLabel() { return "Phylogenetic tree edit"; }
210 
211 private:
213  static vector<char> m_UtilVec;
215 
216  typedef struct SBTree {
217  vector<char> orig_tree;
218  vector<char> new_tree;
221 };
222 
225 
226 
227 
228 /// SelectionSets are stored in the biotreecontainer's user-data object
229 /// so we need a special change command object to handle it's undo-and redo.
230 /// CChangePhyloTreeCommand which saves the entire tree would also work,
231 /// but is much less (space) efficient
233 {
234 public:
236  CSelectionSetEdit* sel_edit,
239  {
240  m_View = view;
241  m_DS = ds;
242  m_BioTree = bio_tree;
243  m_SelectionEdit.Reset(sel_edit);
244  }
245 
246  void PerformEdit()
247  {
248  // renumber cluster IDs in set to make sure the selection cluster IDs
249  // don't overlap regular cluster IDs:
250  // pick cluster id larger than existing ids:
251  CPhyloTree::TClusterID max_id =
252  m_DS->GetMaxClusterID() + 500 + static_cast<CPhyloTree::TClusterID>(m_DS->GetSelectionSets().GetSets().size());
253  // set ids, first highest then lower.
255 
257 
258  // Need update access to biotree to commit the changes
259  CBioTreeContainer* bio_tree =
260  const_cast<CBioTreeContainer *> (m_BioTree.GetPointer());
261 
262  CBioTreeContainer_Base::TUser& uo = bio_tree->SetUser();
263  if (!uo.CanGetType() || !uo.IsSetType() || uo.GetType().Which() == CObject_id_Base::e_not_set) {
264  CRef<CObject_id> uo_id;
265  uo_id.Reset(new CObject_id());
266  uo_id->SetStr("Tree Metadata");
267  uo.SetType(*uo_id);
268  }
269 
271 
272  // should check first that label updated (for efficiency)
274  }
275 
276  virtual void Execute()
277  {
280 
281  PerformEdit();
282  }
283  virtual void Unexecute()
284  {
286 
287  PerformEdit();
288  }
289 
290  virtual string GetLabel() { return "Phylogenetic tree SelectionSets update"; }
291 
292 private:
294 
295  // project biotreecontainer
297 
300 };
301 
303 {
304 public:
306 
307  bool operator() (const CUpdatedFeature &lhs, const CUpdatedFeature &rhs) const
308  {
309  return (lhs.m_NodeId < rhs.m_NodeId);
310  }
311  bool operator() (const CUpdatedFeature &lhs, const CPhyloNodeData::TID nod_id) const
312  {
313  return (lhs.m_NodeId < nod_id);
314  }
315  bool operator() (const CPhyloNodeData::TID node_id, const CUpdatedFeature &rhs) const
316  {
317  return (node_id < rhs.m_NodeId);
318  }
319 private:
321 };
322 
323 
324 
326 {
327 public:
329  typedef TContainerDict::Tdata::value_type::element_type TCFeatureDescr;
330 
333  typedef TNodeList::value_type::element_type TCNode;
334  typedef TCNode::TFeatures TCNodeFeatureSet;
335  typedef TCNodeFeatureSet::Tdata TNodeFeatureList;
336  typedef TNodeFeatureList::value_type::element_type TCNodeFeature;
337 
338 public:
339  /// IEditCommand merge commands (macros allow changes to both properties
340  /// and selection sets, so allow those to merge):
341  virtual bool CanMerge(IEditCommand* cmd) {
343 
344  if (sel_cmd != NULL && true) {
345  return true;
346  }
347  return false;
348  }
349 
350  virtual void Merge(IEditCommand* cmd) {
352 
353  if (sel_cmd != NULL && m_MergedCmd.IsNull())
354  m_MergedCmd.Reset(sel_cmd);
355  }
356 
357 public:
359  CFeatureEdit* fedit,
362  {
363  m_View = view;
364  m_DS = ds;
365  m_BioTree = bio_tree;
366  m_FeatureEdit.Reset(fedit);
368 
369  // Sort the features in feature edit because if there are a large number of features,
370  // the linear search for them in the biotreecontainer can be very slow.
371  std::sort(fedit->GetUpdated().begin(), fedit->GetUpdated().end());
372  }
373 
375  {
376  // Need update access to biotree to commit the changes
377  CBioTreeContainer* bio_tree =
378  const_cast<CBioTreeContainer *> (m_BioTree.GetPointer());
379 
380  // Update feature dictionary of biotree
381  TContainerDict& fd = bio_tree->SetFdict();
382  fd.Reset();
383  TContainerDict::Tdata& feat_list = fd.Set();
384 
386  TBioTreeFeatureId fid = it->first;
387  const string& fvalue = it->second;
388 
389  {{
391  d->SetId(fid);
392  d->SetName(fvalue);
393 
394  feat_list.push_back(d);
395  }}
396  } // ITERATE
397  }
398 
399  void PerformEdit(CBioTreeFeatureDictionary& dict, bool prev_features)
400  {
401 
402  // Need update access to biotree to commit the changes
403  CBioTreeContainer* bio_tree =
404  const_cast<CBioTreeContainer *> (m_BioTree.GetPointer());
405 
406  //
407  // Update node features of biotree (have to find node by id first):
408  TNodeList node_list = bio_tree->SetNodes().Set();
409  int update_count = 0;
410 
411  NON_CONST_ITERATE(TNodeList, it, node_list) {
412  if (update_count == m_FeatureEdit->GetUpdated().size())
413  break;
414 
415  CRef<TCNode>& cnode = *it;
416 
417  TCNode::TId uid = cnode->GetId();
418 
419  CPhyloTreeNode* node = NULL;
420  auto iter = std::lower_bound(m_FeatureEdit->GetUpdated().begin(), m_FeatureEdit->GetUpdated().end(), uid, SUpdateFeatureCompare(uid));
421  if (iter != m_FeatureEdit->GetUpdated().end() && iter->m_NodeId == uid) {
422  ++update_count;
423 
424  if (iter->m_NodeIdx != CPhyloTree::Null()) {
425  node = &m_DS->GetTree()->GetNode(iter->m_NodeIdx);
426  }
427  else {
428  CPhyloTree::TTreeIdx idx = m_DS->GetTree()->FindNodeById(iter->m_NodeId);
429  if (idx != CPhyloTree::Null())
430  node = &m_DS->GetTree()->GetNode(idx);
431  }
432 
433  if (node != NULL) {
434  // now perform the update:
435  if (prev_features)
436  (*node)->GetBioTreeFeatureList() = iter->GetPrevFeatures();
437  else
438  (*node)->GetBioTreeFeatureList() = iter->GetFeatures();
439 
440  // Propogate features to node elements for display.
441  (*node)->Init(dict, m_DS->GetModel().GetColorTable());
443 
444  cnode->ResetFeatures();
445  TCNodeFeatureSet& fset = cnode->SetFeatures();
446 
447  ITERATE(CBioTreeFeatureList::TFeatureList, it, (*node)->GetBioTreeFeatureList().GetFeatureList()) {
448  TBioTreeFeatureId fid = (*it).id;
449  const string& fvalue = (*it).value;
450 
451  CRef<TCNodeFeature> cfeat(new TCNodeFeature());
452  cfeat->SetFeatureid(fid);
453  cfeat->SetValue(fvalue);
454 
455  fset.Set().push_back(cfeat);
456  } // ITERATE
457  }
458  else {
459  LOG_POST(Error << "Execute properties update error on node ID: " <<
460  iter->m_NodeId);
461  }
462  }
463  }
464  }
465 
466  virtual void Execute()
467  {
468  CStopWatch timer;
469  timer.Start();
470 
471  CPhyloTreeNode* node = NULL;
472 
473  // Update dictionary and save previous version
476 
478 
480 
481  // should check first that label updated (for efficiency)
483 
484  if (m_FeatureEdit->SeqIdEdited())
486 
487  if (!m_MergedCmd.IsNull())
488  m_MergedCmd->Execute();
489 
491  }
492  virtual void Unexecute()
493  {
494  CPhyloTreeNode* node = NULL;
496 
498 
500 
501  // should check first that label updated (for efficiency)
503 
504  if (m_FeatureEdit->SeqIdEdited())
506 
507  if (!m_MergedCmd.IsNull())
509  }
510 
511  virtual string GetLabel() { return "Phylogenetic tree feature update"; }
512 
513 private:
515 
516  // project biotreecontainer
518 
522 
524 };
525 
527 {
528 public:
530  typedef TContainerDict::Tdata::value_type::element_type TCFeatureDescr;
531 
534  typedef TNodeList::value_type::element_type TCNode;
535  typedef TCNode::TFeatures TCNodeFeatureSet;
536  typedef TCNodeFeatureSet::Tdata TNodeFeatureList;
537  typedef TNodeFeatureList::value_type::element_type TCNodeFeature;
538 
539 public:
541  CExpandCollapseNodes* ec_edit,
544  {
545  m_View = view;
546  m_DS = ds;
547  m_BioTree = bio_tree;
548  m_ExpandCollapseEdit.Reset(ec_edit);
549  }
550 
552  CNodeFeature_Base::TValue& collapse_value)
553  {
554  // Need update access to biotree to commit the changes
555  CBioTreeContainer* bio_tree =
556  const_cast<CBioTreeContainer *> (m_BioTree.GetPointer());
557 
558  // Update feature dictionary of biotree
559  TContainerDict& fd = bio_tree->SetFdict();
560  TContainerDict::Tdata& feat_list = fd.Set();
561  bool has_feature = false;
562  TBioTreeFeatureId collapse_fid;
564 
565  // Get ID of collapse feature from dictionary (it should be there). If it is not
566  // there, add it.
567  ITERATE(TContainerDict::Tdata, it, feat_list) {
568  CRef<TCFeatureDescr> fdesc = *it;
569 
570  if (fdesc->GetName() == "$NODE_COLLAPSED") {
571  has_feature = true;
572  collapse_fid = fdesc->GetId();
573  }
574  max_fid = std::max(max_fid, fdesc->GetId());
575  }
576 
577  if (!has_feature) {
578  collapse_fid = max_fid + 1;
579 
581  d->SetId(collapse_fid);
582  d->SetName("$NODE_COLLAPSED");
583 
584  feat_list.push_back(d);
585  }
586 
587 
588  //
589  // Update node features of biotree (have to find node by id first):
590  TNodeList node_list = bio_tree->SetNodes().Set();
591 
592  vector<CPhyloNodeData::TID> node_ids = m_ExpandCollapseEdit->GetIds();
593  std::sort(node_ids.begin(), node_ids.end());
594  int nodes_updated = 0;
595 
596  // Traverse all the nodes in the biotree container. For any nodes with ids
597  // that are in the m_ExpandCollapseEdit object, expand or collapse that
598  // node.
599  NON_CONST_ITERATE(TNodeList, it, node_list) {
600  CRef<TCNode>& cnode = *it;
601 
602  TCNode::TId uid = cnode->GetId();
603  if (std::binary_search(node_ids.begin(), node_ids.end(), uid)) {
604  ++nodes_updated;
605 
606  TTreeIdx node_idx = m_DS->GetTree()->FindNodeById(uid);
607  if (node_idx == CPhyloTree::Null()) {
608  _TRACE("Node not found for id: " << uid);
609  continue;
610  }
611  CPhyloTreeNode& node = m_DS->GetTree()->GetNode(node_idx);
612  node.ExpandCollapse(m_DS->GetTree()->GetFeatureDict(), ec);
613 
614  //if (uid == TCNode::TId(node->GetValue().GetId())) {
615  TCNodeFeatureSet& fset = cnode->SetFeatures();
616  CNodeFeatureSet_Base::Tdata& features = fset.Set();
617  bool collapse_feature_found = false;
618 
619  ITERATE(CNodeFeatureSet_Base::Tdata, it, features) {
620  CRef< CNodeFeature > feature = *it;
621  if (feature->GetFeatureid() == collapse_fid) {
622  // Feature found. Set the updated expand/collapse value.
623  feature->SetValue(collapse_value);
624  collapse_feature_found = true;
625  break;
626  }
627  }
628 
629  // Add the collapse feature if it's not already in the node
630  if (!collapse_feature_found) {
631  CRef<TCNodeFeature> cfeat(new TCNodeFeature());
632  cfeat->SetFeatureid(collapse_fid);
633  cfeat->SetValue(collapse_value);
634 
635  features.push_back(cfeat);
636  }
637  }
638  }
639  if (nodes_updated != node_ids.size()) {
640  _TRACE("Execute properties update error - CBioTreeContainer collapse node update count did not match");
641  }
642  }
643 
644  virtual void Execute()
645  {
646  CStopWatch timer;
647  timer.Start();
648 
650 
651  string feature_value = "0";
653  feature_value = "1";
654 
655  PerformEdit(ec, feature_value);
657 
659  }
660  virtual void Unexecute()
661  {
662  CStopWatch timer;
663  timer.Start();
664 
665  string feature_value;
666 
668  if (ec == CPhyloNodeData::eHideChildren) {
670  feature_value = "1";
671  }
672  else {
674  feature_value = "0";
675  }
676 
677  PerformEdit(ec, feature_value);
679  }
680 
681  virtual string GetLabel() { return "Phylogenetic tree expand/collapse update"; }
682 
683 private:
685 
686  // project biotreecontainer
688 
691 };
692 
704 
707 
709  "Tree View", // type name
710  "phylo_tree_view", // icon alias TODO
711  "Tree View",
712  "View for graphical presentation of hierarchical data (phylogenetic tree, taxonomy tree, etc.) using various layout methods",
713  "PHY_TREE_VIEW", // help ID
714  "Alignment", // category
715  false, // not a singleton
716  "BioTreeContainer",
718 );
719 
721 : m_Panel(nullptr)
722 , m_EditUpdate(false)
723 , m_CurrentNode(CPhyloTreeNode::Null())
724 {
725 #ifdef ATTRIB_MENU_SUPPORT
727  CAttribMenu* sub_menu = m.AddSubMenuUnique("PhyView", this);
728 
729  sub_menu->AddFloatReadOnly("Create Undo Time", &m_CreateUndoCommand);
730  sub_menu->AddFloatReadOnly("Execute Undo Time", &m_ExecuteUndoCommand);
731  sub_menu->AddFloatReadOnly("Create Property Undo Time", &m_CreateProperyUndoCommand);
732  sub_menu->AddFloatReadOnly("Execute Property Undo Count", &m_ExecutePropertyCommand);
733  sub_menu->AddFloatReadOnly("Exec OnBioTreeChanged", &m_ExecOnBioTreeChanged);
734  sub_menu->AddFloatReadOnly("Datasource Init time", &m_DataSourceInitTimer);
735 #endif
736 }
737 
739 {
741 
742 #ifdef ATTRIB_MENU_SUPPORT
744 #endif
745 }
746 
747 
749 {
750  _ASSERT(m_Panel);
751  return m_Panel;
752 }
753 
754 
756 {
757  wxMenu* view_menu = new wxMenu();
758 
759  view_menu->Append( wxID_SEPARATOR, wxT("Actions") );
760 
761  wxMenu* bar_menu = new wxMenu();
762  bar_menu->Append( wxID_ANY, wxT("&View"), view_menu );
763 
764  m_MenuBarMenu.reset( bar_menu );
765 }
766 
767 class CPhyTreePanel : public wxPanel
768 {
769 public:
770  CPhyTreePanel(wxWindow* parent, long childId) : wxPanel(parent), m_ChildId(childId) {}
771 
772  virtual bool ProcessEvent(wxEvent &event);
773 private:
774  long m_ChildId;
775 };
776 
777 bool CPhyTreePanel::ProcessEvent(wxEvent &event)
778 {
779  if (event.IsCommandEvent()) {
780  wxEventType type = event.GetEventType();
781  if (type == wxEVT_UPDATE_UI || type == wxEVT_COMMAND_MENU_SELECTED) {
782  wxWindow* child = FindWindow(m_ChildId);
783  if (child) {
784  wxEvtHandler* evtHandler = child->GetEventHandler();
785  if (evtHandler && evtHandler->ProcessEventLocally(event))
786  return true;
787  }
788  }
789  }
790  return wxPanel::ProcessEvent(event);
791 }
792 
793 void CPhyTreeView::CreateViewWindow(wxWindow* parent)
794 {
795  _ASSERT(!m_Panel);
796 
797  m_Panel = new CPhyTreePanel(parent, kPhylpWidgetID);
798 
800  phyWidget->Create();
801 
802  CQueryParsePanel* queryPanel = new CQueryParsePanel(phyWidget, m_DataSource.GetPointerOrNull());
803  queryPanel->Create(m_Panel, kQueryPanelID);
804  phyWidget->SetQueryPanel(queryPanel);
805 
806  wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
807  m_Panel->SetSizer(sizer);
808 
809  sizer->Add(queryPanel, 0, wxEXPAND);
810  sizer->Add(phyWidget, 1, wxEXPAND);
811 
812  AddListener(phyWidget, ePool_Child);
813  phyWidget->AddListener(this, ePool_Parent);
814 }
815 
817 {
818  if (!m_Panel)
819  return nullptr;
820 
821  return dynamic_cast<CPhyloTreeWidget*>(m_Panel->FindWindow(kPhylpWidgetID));
822 }
823 
825 {
826  if(m_Panel) {
827  m_Panel->Destroy();
828  m_Panel = NULL;
829  }
830 }
831 
832 
834 {
835  return s_PhyTreeViewTypeDescr;
836 }
837 
838 
839 bool CPhyTreeView::InitView(TConstScopedObjects& objects, const objects::CUser_object*)
840 {
841  // exploring objects to find biotree object
842  if(objects.size() > 0) {
843  CPhyloTreeWidget* phyWidget = GetWidget();
844 
846  const CObject* object = it->object.GetPointer();
847  m_BioTreeContainer = dynamic_cast<const CBioTreeContainer *>(object);
848 
849 
850  // first found biotree will be shown
851  if(m_BioTreeContainer) {
852  if (m_BioTreeContainer->GetNodeCount() == 0 ) {
854  }
855  else {
856  break;
857  }
858  }
859  }
860  if (m_BioTreeContainer) {
862  _ASSERT(srv);
863 
864  CScope* scope = objects[0].scope.GetPointer();
865 
866  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
867  if (!ws) return false;
868 
869  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(*objects[0].scope));
870  _ASSERT(doc);
871 
872  phyWidget->LoadSettings();
873 
874  // Tree may have some rendering paameters saved inside asn user object.
875  // Set those here when first loading (don't want to reset them each time
876  // tree is edited).
877 
879  m_InitialLayout = -1;
881  if (m_BioTreeContainer->IsSetUser()) {
882  const CBioTreeContainer_Base::TUser& uo = m_BioTreeContainer->GetUser();
883 
884  if (uo.HasField("layout") &&
885  uo.GetField("layout").GetData().IsInt()) {
886  m_InitialLayout = uo.GetField("layout").GetData().GetInt();
887  }
888 
889  if (uo.HasField("use-distances") &&
890  uo.GetField("use-distances").GetData().IsBool()) {
891  m_InitialUseDistances = uo.GetField("use-distances").GetData().GetBool() ? 1 : 0;
892  }
893 
894  if (uo.HasField("rotate-labels") &&
895  uo.GetField("rotate-labels").GetData().IsBool()) {
896  m_InitialRotateLabels = uo.GetField("rotate-labels").GetData().GetBool() ? 1 : 0;
897  }
898  }
899 
900  // If a specific layout was not saved in the file set it to whatever
901  // layout the user last used
902  if (m_InitialLayout == -1 && phyWidget->HasScheme()) {
903  m_InitialLayout = phyWidget->GetScheme().GetLayoutIdx();
904  }
905 
906  if (doc) {
907  x_AttachToProject(*doc);
908  CProjectViewEvent evt( doc->GetId(), CProjectViewEvent::eData);
909 
910  try {
911  OnProjectChanged(evt);
912  }
913  catch (CException& e) {
914  LOG_POST(Error << "Error loading tree: " << e.GetMsg());
915  return false;
916  }
917 
918  return true;
919  }
920  else {
921  return false;
922  }
923  }
924  else {
926  return false;
927  }
928  }
929  return false;
930 }
931 
932 
934 {
936 
937  if(x_HasProject()) {
939 
940  //
942  return;
943 
944  // If the update is coming because of an edit through this view, there is no reason
945  // to rebuild the data source since this is the view that changed it. But we
946  // do need to redraw the view to reflect the updated data.
947  // m_EditUpdate is a bit of a hack to recognize event coming from this view since undo
948  // manager doesn't track the source view.
949  if (m_EditUpdate) {
950  CPhyloTreeWidget* phyWidget = GetWidget();
951 
952  if (phyWidget) {
954  phyWidget->RedrawDataSource();
955  }
956 
957  m_EditUpdate = false;
958  return;
959  }
960  OnBioTreeChanged();
961  }
962  else {
964  }
965 }
966 
968 {
969  CScope* scope = x_GetScope();
970  _ASSERT(scope);
971 
972  CPhyloTreeWidget* phyWidget = GetWidget();
973 
974  bool initial = m_DataSource.Empty();
975  bool first_update = (phyWidget->GetDS() == NULL);
976 
977  // This will cancel any background processes using the data source
978  phyWidget->RemoveCurrentDataSource();
979 
980  // Delete and recreate the data source
981  CStopWatch timer;
982  timer.Start();
983 
984  // set default scheme
986  if (phyWidget->HasScheme())
987  *m_Scheme = phyWidget->GetScheme();
988 
990  string label_format;
991 
992  /// If label format is saved with tree, set it in the scheme
993  if (m_BioTreeContainer->IsSetUser()) {
994  const CBioTreeContainer_Base::TUser& uo = m_BioTreeContainer->GetUser();
995 
996  // Only copy label-format since that's all that should be there
997  if (uo.HasField("label-format") &&
998  uo.GetField("label-format").GetData().IsStr()) {
999  label_format = uo.GetField("label-format").GetData().GetStr();
1000  m_Scheme->SetLabelFormat() = label_format;
1001  }
1002  }
1003 
1004  // set default label style for tax tree if the tree didn't have a
1005  // label-format saved with it in the user-object
1006  if (m_BioTreeContainer->CanGetTreetype() &&
1007  label_format == "" &&
1008  (m_BioTreeContainer->GetTreetype() == "CommonTaxTree")){
1009  m_Scheme->SetLabelFormat() = "$(name)$(seq-id)";
1011  }
1012  // Forcing label to "$(name)$(seq-id)" is a little odd since it will
1013  // still be set when user is done looking at taxtrees. Users may be confused
1014  // why no label appears in non-taxtrees after viewing a taxtree, so we set
1015  // label back to default it is set to taxtree value...
1016  else if ((!m_BioTreeContainer->CanGetTreetype() ||
1017  (!m_BioTreeContainer->CanGetTreetype() &&
1018  m_BioTreeContainer->GetTreetype() != "CommonTaxTree")) &&
1019  label_format == "" &&
1020  m_Scheme->SetLabelFormat() == "$(name)$(seq-id)"){
1021  m_Scheme->SetLabelFormat() = "$(label)";
1023  }
1024 
1025  if (label_format == "")
1026  label_format = m_Scheme->SetLabelFormat();
1027 
1028  if (m_DataSource.IsNull())
1030  else {
1031  m_DataSource->Clear();
1033  }
1034  m_DataSourceInitTimer = timer.Elapsed();
1035 
1036  // sort if needed
1037  if (m_DataSource->GetTree()->GetFeatureDict().HasFeature("do_sort") && initial) {
1038  m_DataSource->Sort(true);
1039  }
1040 
1041 
1042  // On linux, the gui updates forced by SetDataSource() can
1043  // cause a crash if the window/widget is not yet fully created.
1044  phyWidget->SetDataSourceNoUpdate(m_DataSource);
1045 
1046  // apply distances rendering, if distances available
1047  if (initial) {
1048  phyWidget->SetUseDistances(
1050 
1051  if (m_DataSource->GetTree()->GetFeatureDict().HasFeature("label") &&
1052  label_format == "") {
1053  m_Scheme->SetLabelFormat() = "$(label)";
1055  }
1056  }
1057 
1059  phyWidget->SetScheme(*m_Scheme);
1060 
1061  // datasource labeling (creating labels cach)
1063 
1065 
1066  // Set rendering parameters which are (optionally) stored in biotreecontainer
1067  // only after file is first loaded
1068  if (m_InitialUseDistances != -1) {
1069  phyWidget->SetUseDistances((m_InitialUseDistances==1) ? true : false);
1070  m_InitialUseDistances = -1;
1071  }
1072  if (m_InitialRotateLabels != -1) {
1073  phyWidget->SetRotateLabels((m_InitialRotateLabels==1) ? true : false);
1074  m_InitialRotateLabels = -1;
1075  }
1076 
1077  if (m_InitialLayout != -1) {
1078  // this also does layout so we do not need to call RedrawDataSource
1079  // if this is called
1080  phyWidget->SetCurrRenderer(m_InitialLayout);
1081  m_InitialLayout = -1;
1082  }
1083  else {
1084  // This does layout, which needs labels which are set above.
1085  phyWidget->RedrawDataSource();
1086  }
1087 }
1088 
1089 
1091 {
1093 
1094  CScope* scope = x_GetScope();
1095  m_ObjectIndex.Clear(scope);
1096 
1099 }
1100 
1101 
1103 {
1104  //This is called from the idle update to recheck selection constantly. For that
1105  //reason, it can be a bit expensive.
1106 
1107  CPhyloTreeWidget* phyWidget = GetWidget();
1108 
1109  if (phyWidget && m_DataSource && x_HasProject()) {
1110 
1111  CScope* scope = x_GetScope();
1112 
1113  // Tree traversel doesn't have a const version
1115  CPhyloTree* tree = const_cast<CPhyloTree*>(ds->GetTree());
1116 
1117  //
1118  if (ds->GetTree()->HasCurrentNode()) {
1119  if (m_CurrentNode != ds->GetTree()->GetCurrentNodeIdx()) {
1123  *tree,
1124  m_CurrentNode);
1125 
1126  m_Cont->SetTreetype("Phylogenetic Tree");
1127  }
1128  objs.push_back(SConstScopedObject(m_Cont, scope));
1129  }
1130 
1131  vector<CPhyloTree::TTreeIdx> sel_nodes;
1132  ds->GetTree()->GetSelected(sel_nodes);
1133 
1134  ITERATE(vector<CPhyloTree::TTreeIdx>, it, sel_nodes) {
1135  const CPhyloTreeNode& n = ds->GetTree()->GetNode(*it);
1136  if (!(*n).GetSeqID().Empty()) {
1137  objs.push_back(SConstScopedObject((*n).GetSeqID().GetPointer(), scope));
1138  }
1139  }
1140  }
1141 }
1142 
1143 
1145 {
1146  CPhyloTreeWidget* phyWidget = GetWidget();
1147 
1148  if (phyWidget && m_DataSource && x_HasProject()) {
1149 
1151 
1152  vector<CPhyloTree::TTreeIdx> sel_nodes;
1153  ds->GetTree()->GetSelected(sel_nodes);
1154  if (sel_nodes.size() > 0) {
1155  CBioTreeSelection* bioTreeSelection = new CBioTreeSelection(m_BioTreeContainer);
1156  CBioTreeSelection::TNodeIdsVector &node_ids = bioTreeSelection->GetNodeIds();
1157  CBioTreeSelection::TNodeIdsVector &explicitly_selected_node_ids = bioTreeSelection->GetExplicitlySelectedNodeIds();
1158  ds->GetTree()->GetSelectedIDs(node_ids);
1159  ds->GetTree()->GetExplicitlySelectedIDs(explicitly_selected_node_ids);
1160 
1161  evt.AddIndexed("tree", *bioTreeSelection);
1162  }
1163 
1164  if (ds->GetDictionary().HasFeature("seq-id")) {
1165  TConstObjects objs;
1166  ITERATE(vector<CPhyloTree::TTreeIdx>, it, sel_nodes) {
1167  const CPhyloTreeNode& n = ds->GetTree()->GetNode(*it);
1168  if (!(*n).GetSeqID().Empty()) {
1169  objs.push_back(CConstRef<CObject>((*n).GetSeqID().GetPointer()));
1170  }
1171  }
1172  evt.AddObjectSelection(objs);
1173  }
1174 
1175  if (ds->GetDictionary().HasFeature("tax-id") || ds->GetDictionary().HasFeature("taxid")) {
1176  TBioTreeFeatureId feature_id = ds->GetDictionary().GetId("tax-id");
1177  // allow for common misspelling
1178  if (feature_id == (TBioTreeFeatureId)-1)
1179  feature_id = ds->GetDictionary().GetId("taxid");
1180 
1181  ITERATE(vector<CPhyloTree::TTreeIdx>, it, sel_nodes) {
1182  const CPhyloTreeNode& n = ds->GetTree()->GetNode(*it);
1183  const string& tax_id = (*n).GetBioTreeFeatureList()[feature_id];
1184  if (tax_id != "") {
1186  evt.AddTaxIDSelection(id);
1187  }
1188  }
1189  }
1190  }
1191 }
1192 
1194 {
1195 public:
1197  TBioTreeFeatureId tax_feat_id)
1198  : m_TaxIds(tids)
1199  , m_TaxFeatureId(tax_feat_id) {}
1200 
1202  {
1203  if (delta==1 || delta==0){
1204  CPhyloTreeNode& tree_node = tree[node_idx];
1205  const string& tax_id = (*tree_node).GetBioTreeFeatureList()[m_TaxFeatureId];
1206  if (tax_id != "") {
1208  if (m_TaxIds.IsSelected(id)) {
1209  m_SelNodes.push_back(node_idx);
1210  }
1211  }
1212  }
1213  return eTreeTraverse;
1214  }
1215 
1217  { m_SelNodes = rhs.m_SelNodes; return *this; }
1218 
1219  const vector<CPhyloTree::TTreeIdx>& GetNodes() { return m_SelNodes; }
1220 private:
1221  vector<CPhyloTree::TTreeIdx> m_SelNodes;
1222 
1225 };
1226 
1227 
1229 {
1230 public:
1232  const set<string>& feat_values)
1233  : m_FeatureId(feat_id)
1234  , m_FeatureValues(feat_values)
1235  {
1236  }
1237 
1239  {
1240  if (delta==1 || delta==0) {
1241  CPhyloTreeNode& tree_node = tree[node_idx];
1242  const string& feat_val = (*tree_node).GetBioTreeFeatureList()[m_FeatureId];
1243  if (feat_val != "") {
1244  if (m_FeatureValues.find(feat_val) != m_FeatureValues.end()) {
1245  m_SelNodes.push_back(node_idx);
1246  }
1247  }
1248  }
1249  return eTreeTraverse;
1250  }
1251 
1253  { m_SelNodes = rhs.m_SelNodes; return *this; }
1254 
1255  const vector<CPhyloTree::TTreeIdx>& GetNodes() { return m_SelNodes; }
1256 private:
1257  vector<CPhyloTree::TTreeIdx> m_SelNodes;
1258 
1261 };
1262 
1263 // handles incoming selection broadcast (overriding CView virtual function)
1265 {
1266  CPhyloTreeWidget* phyWidget = GetWidget();
1267 
1268  if (phyWidget == NULL)
1269  return;
1270 
1271  vector<TTreeIdx> sel_nodes;
1272  vector<CPhyloTree::TID> sel_node_ids;
1273 
1275 
1276  TConstObjects objs;
1277  evt.GetIndexed("tree", objs);
1278 
1279  // The selection events only contain selection from a single object, and since
1280  // trees only generate one 'tree' indexed object for the selection, 'objs' should
1281  // only have one element.
1282 
1283  // If we have a tree broadcast and select a feature other than seq-id or taxid, we will
1284  // ignore seq-id and taxid selection. If the feature type IS seq-id or taxid, we will process
1285  // those ids further down under HasObjectSelection since it should be more efficient.
1286  bool select_seqids = true;
1287  bool select_taxids = true;
1288  const CBioTreeSelection* bioTreeSelection = NULL;
1289 
1290  if (objs.size() > 0) {
1291  select_seqids = false;
1292  select_taxids = false;
1293 
1294  bioTreeSelection = dynamic_cast<const CBioTreeSelection*>(objs[0].GetNonNullPointer());
1295 
1296  if (bioTreeSelection != NULL && bioTreeSelection->GetNodeIds().size()) {
1297  CConstRef<objects::CBioTreeContainer> bioTree = bioTreeSelection->GetBioTree();
1298 
1299  // broadcasting selections from a tree to itself is a special case. CSelectionEvent::sm_TreeBroadcastOneToOne
1300  // returns the selection criterion that says that we want to match the trees own
1301  // nodes one-to-one if and only if the two trees are built from the same underlying
1302  // CBioTreeContainer.
1303  bool select_by_id = false;
1306  select_by_id = true;
1307  }
1308 
1309  string feat_name;
1310  TBioTreeFeatureId feature_id = -1;
1311 
1312  if (!select_by_id && bioTree->IsSetFdict()) {
1314  if (ds->GetTree()->GetFeatureDict().HasFeature(*it) &&
1315  bioTreeSelection->HasFeature(*it)) {
1316  feat_name = *it;
1317  feature_id = bioTreeSelection->GetFeatureId(feat_name);
1318  break;
1319  }
1320  }
1321  }
1322 
1323  set<string> selected_feature_values;
1324 
1325  // check for special case of selecting by id:
1326  if (select_by_id) {
1327  const CBioTreeSelection::TNodeIdsVector &nodeIds = bioTreeSelection->GetNodeIds();
1328  sel_node_ids.reserve(nodeIds.size());
1329  std::copy(nodeIds.begin(), nodeIds.end(), back_inserter(sel_node_ids));
1330  }
1331  else if (feature_id != -1) {
1332  if (feat_name == "seq-id")
1333  select_seqids = true;
1334  if (feat_name == "tax-id" || feat_name == "taxid")
1335  select_taxids = true;
1336 
1337  if (!select_seqids && !select_taxids) {
1338  // Iterate over the selection tree and collect all the selected values. Could also
1339  // iterate over the selected nodes for each node in the tree..
1340  // could use set or put all in vector, sort vector and remove non-unique.
1341  std::vector<size_t>::iterator iter;
1342  ITERATE(CBioTreeSelection::TNodeIdsVector, iter, bioTreeSelection->GetNodeIds()) {
1343  string feat_val = bioTreeSelection->GetFeatureValue(*iter,feature_id);
1344  if (feat_val.empty())
1345  continue;
1346  selected_feature_values.insert(feat_val);
1347  }
1348 
1349  // Iterate over the tree to be updated (potentially) and select all those nodes
1350  // that have 'feat_name' equal to one of the selected values
1351  feature_id = ds->GetTree()->GetFeatureDict().GetId(feat_name); // feature_id for the tree in this view
1352  visitor_string_query vsq(feature_id, selected_feature_values);
1353  vsq = TreeDepthFirst(*ds->GetTree(), vsq);
1354  sel_nodes = vsq.GetNodes();
1355  }
1356  }
1357  }
1358  }
1359 
1360  if(evt.HasObjectSelection() && (select_seqids || select_taxids)) {
1361  // get Ids
1362  CSelectionEvent::TIds ids = evt.GetIds();
1363 
1364  // get Ids from TIdLocs
1365  const CSelectionEvent::TIdLocs& locs = evt.GetIdLocs();
1366  ITERATE(CSelectionEvent::TIdLocs, it_loc, locs) {
1367  ids.push_back((*it_loc)->m_Id);
1368  }
1369 
1370  if (ids.size() != 0 && select_seqids) {
1371 
1373 
1374  ITERATE(CSelectionEvent::TIds, it_id, ids) {
1375  const CSeq_id& id = **it_id;
1376  CSeq_id_Descr descr(NULL, id, evt.GetScope()); // TODO - put descr in SelectionEvent
1377 
1378  results.clear();
1380 
1382  const CSelNodeHandle* handle =
1383  reinterpret_cast<const CSelNodeHandle*>(*it_r);
1384  sel_nodes.push_back(handle->GetNodeIdx());
1385  }
1386  }
1387  }
1388  else if (select_taxids) {
1389  if (phyWidget && m_DataSource && x_HasProject()) {
1391 
1392  if (ds->GetDictionary().HasFeature("tax-id") || ds->GetDictionary().HasFeature("taxid")) {
1393 
1394  const CSelectionEvent::TTaxIds& tids = evt.GetTaxIDs();\
1395 
1396  TBioTreeFeatureId feature_id = ds->GetDictionary().GetId("tax-id");
1397  // allow for common misspelling
1398  if (feature_id == (TBioTreeFeatureId)-1)
1399  feature_id = ds->GetDictionary().GetId("taxid");
1400 
1401  if (feature_id != -1) {
1402  visitor_taxid_query vtq(tids, feature_id);
1403  vtq = TreeDepthFirst(*ds->GetTree(), vtq);
1404  sel_nodes = vtq.GetNodes();
1405  }
1406  }
1407  }
1408  }
1409  }
1410 
1412  if (!sel_nodes.empty()) {
1413  m_DataSource->GetTree()->SetSelection(sel_nodes);
1414  // Since we don't know which nodes were explicitly selected in the source, we just
1415  // set the leaves as being the primary selection set since that is most often the case.
1416  // This only has an effect on using the iteration arrows (forward backward) to step through
1417  // the selection set.
1419  }
1420 
1421  if (!sel_node_ids.empty()) {
1422  m_DataSource->GetTree()->SetSelectionIDs(sel_node_ids);
1423  // For selection coming from same biotree, preserve knowledge of which selected
1424  // nodes were explicitly selected (e.g. by meeting query criteria) vs. which were
1425  // selected as the parents or children of those selected nodes.
1426  if (bioTreeSelection != NULL) {
1428  }
1429  }
1430  phyWidget->OnUpdateSelChanged();
1431 }
1432 
1434 {
1435 }
1436 
1437 void CPhyTreeView::SetRegistryPath(const string& reg_path)
1438 {
1439  IRegSettings* reg_set = dynamic_cast<IRegSettings*>(GetWidget());
1440  if (reg_set)
1441  reg_set->SetRegistryPath(reg_path);
1442 }
1443 
1445 {
1446  IRegSettings* reg_set = dynamic_cast<IRegSettings*>(GetWidget());
1447  if (reg_set)
1448  reg_set->LoadSettings();
1449 }
1450 
1451 
1453 {
1454  IRegSettings* reg_set = dynamic_cast<IRegSettings*>(GetWidget());
1455  if (reg_set)
1456  reg_set->SaveSettings();
1457 }
1458 
1459 
1461 {
1462  if(m_BioTreeContainer) {
1463  return m_BioTreeContainer.GetPointer();
1464  }
1465  return NULL;
1466 }
1467 
1468 // This finds the closest node to the root (closest in number of edges,
1469 // not phylogenetic distance) that is either selected or shared (a node that
1470 // has multiple selected children)
1472 {
1473 public:
1475  : m_SelectionRootIdx(-1)
1478 
1480 
1482  {
1483  CPhyloTreeNode& node = tree[node_idx];
1484 
1486 
1487  if (delta == 0 || delta == 1) {
1488  if (((*node).GetSelectedState() == CPhyloNodeData::eSelected) ||
1489  ((*node).GetSelectedState() == CPhyloNodeData::eShared)) {
1490 
1493  m_SelectionRootIdx = node_idx;
1494  }
1495  }
1496  }
1497  return eTreeTraverse;
1498  }
1499 
1503 };
1504 
1506 {
1507  // this can be slow (for very large trees) so let user know we are working
1508  CPhyloTreeWidget* phyWidget = GetWidget();
1509  phyWidget->SetCursor(*wxHOURGLASS_CURSOR);
1510 
1511  CRef<objects::CBioTreeContainer> btc(new objects::CBioTreeContainer());
1512 
1513  // We will create a subtree with all selected and shared nodes (shared on common
1514  // path back towards root). Unless there are no nodes selected in which case
1515  // we will create a subtree from the current node (last node clicked on, including
1516  // via right-mouse)
1517  if (m_DataSource->GetTree()->GetNumSelected() > 0) {
1521 
1522  CPhyloTree::TTreeIdx node_idx = sel_dist.GetSelectionRootIdx();
1523 
1524  if (node_idx == CPhyloTree::Null()) {
1526  sb_srv->SetStatusMessage("No selected nodes found");
1527  return;
1528  }
1529 
1530  TreeConvertSelected2Container(*btc, *m_DataSource->GetTree(), node_idx);
1531  }
1534  TreeConvert2Container(*btc, *m_DataSource->GetTree(), idx);
1535  }
1536  else {
1537  // We should not see this because menu items should not be enabled
1538  // without selected or current node
1540  sb_srv->SetStatusMessage("No selected nodes found");
1541  return;
1542  }
1543 
1544  if (m_BioTreeContainer->IsSetUser()) {
1545  btc->SetUser().Assign(m_BioTreeContainer->GetUser());
1546  }
1547 
1548  CDataLoadingAppJob* job = new CPhyloTreeJob(btc.GetPointer());
1549 
1550  CSelectProjectOptions options;
1552 
1554  CDataLoadingAppTask* task = new CDataLoadingAppTask(prjService, options, *job);
1556 
1557  phyWidget->SetCursor(*wxSTANDARD_CURSOR);
1558 
1559  // Creating a subtree causes the project to be updated which in turn updates (rebuilds
1560  // trees from biotreecontainer) all views. We do not want that since it loses our current
1561  // query selection (and is inefficient)
1562  m_EditUpdate = true;
1563 }
1564 
1565 
1567 {
1569  CPhyloTreeWidget* phyWidget = GetWidget();
1570  _ASSERT(phyWidget);
1571 
1572  if (!phyWidget->HasScheme())
1573  return;
1574 
1575  CExportTreeDlg dlgExport(phyWidget);
1576 
1577  if (dlgExport.ShowModal() != wxID_OK)
1578  return;
1579 
1580  CRef<CBioTreeContainer> new_container(new CBioTreeContainer());
1581  TreeConvert2Container(*new_container, *m_DataSource->GetTree());
1582 
1583  CPhyExportParams& params = dlgExport.GetData();
1584  params.SetLabelFormat(phyWidget->GetScheme().SetLabelFormat().c_str());
1585  params.SetBioTree(new_container);
1586 
1587  CIRef<IAppJob> job(new CPhyExportJob(params));
1588  CRef<CAppJobTask> export_task(new CAppJobTask(*job, true, "Exporting tree..."));
1589  m_Workbench->GetAppTaskService()->AddTask(*export_task);
1590 }
1591 
1593 {
1594  CPhyloTreeWidget* phyWidget = GetWidget();
1595  ICommandProccessor* undoManager = x_GetUndoManager();
1596 
1597  if (evt->GetID() == eCmdRenderingOptionsChanged) {
1598  // There is no undo for this so we don't create a command object
1599  CBioTreeContainer* in_project =
1601 
1602  CBioTreeContainer_Base::TUser& uo = in_project->SetUser();
1603 
1604  if (!uo.CanGetType() || !uo.IsSetType() || uo.GetType().Which()==CObject_id_Base::e_not_set ) {
1605  CRef<CObject_id> uo_id;
1606  uo_id.Reset(new CObject_id());
1607  uo_id->SetStr("Tree Metadata");
1608  uo.SetType(*uo_id);
1609  }
1610 
1611  Int4 current_layout = phyWidget->GetCurrRenderer();
1612  if (uo.HasField("layout") &&
1613  uo.GetField("layout").GetData().IsInt()) {
1614  uo.SetField("layout").SetData().SetInt(current_layout);
1615  }
1616  else {
1617  uo.AddField("layout", current_layout);
1618  }
1619 
1620  // Save distance rendering option too
1621  bool use_distances = phyWidget->GetUseDistances();
1622  if (uo.HasField("use-distances") &&
1623  uo.GetField("use-distances").GetData().IsBool()) {
1624  uo.SetField("use-distances").SetData().SetBool(use_distances);
1625  }
1626  else {
1627  uo.AddField("use-distances", use_distances);
1628  }
1629 
1630  bool rotate_labels = phyWidget->GetRotateLabels();
1631  if (uo.HasField("rotate-labels") &&
1632  uo.GetField("rotate-labels").GetData().IsBool()) {
1633  uo.SetField("rotate-labels").SetData().SetBool(rotate_labels);
1634  }
1635  else {
1636  uo.AddField("rotate-labels", rotate_labels);
1637  }
1638 
1639  // hack to prevent event from x_FireProjectChangedEvent from
1640  // Causing OnProjectChangedEvent to force the model to be recreated from the biotree.
1641  // that should only happen if another view causes the data update.
1642  m_EditUpdate = true;
1643 
1644  IEventAttachment* attach = evt->GetAttachment();
1645  CSelectionSetEdit* sel_edit = dynamic_cast<CSelectionSetEdit*>(attach);
1646  if (sel_edit != NULL) {
1647 
1649  sel_edit,
1650  m_DataSource,
1652 
1653  if (undoManager) {
1654  CIRef<IEditCommand> command(phycmd);
1655  undoManager->Execute(command);
1656  }
1657  }
1658  }
1659  else if (evt->GetID() == eCmdLabelFormatChanged) {
1660  // There is no undo for this so we don't create a command object
1661  CBioTreeContainer* in_project =
1663 
1664  CBioTreeContainer_Base::TUser& uo = in_project->SetUser();
1665 
1666  if (!uo.CanGetType() || !uo.IsSetType() || uo.GetType().Which()==CObject_id_Base::e_not_set ) {
1667  CRef<CObject_id> uo_id;
1668  uo_id.Reset(new CObject_id());
1669  uo_id->SetStr("Tree Metadata");
1670  uo.SetType(*uo_id);
1671  }
1672 
1673  if (phyWidget->HasScheme())
1674  *m_Scheme = phyWidget->GetScheme();
1675  string label_format = m_Scheme->SetLabelFormat();
1676  if (uo.HasField("label-format") &&
1677  uo.GetField("label-format").GetData().IsStr()) {
1678  uo.SetField("label-format").SetData().SetStr(label_format);
1679  }
1680  else {
1681  uo.AddField("label-format", label_format);
1682  }
1683 
1684 
1685  }
1686  else if (evt->GetID() == eCmdTreeLabelSet) {
1687  // There is no undo for this so we don't create a command object
1688  CBioTreeContainer* in_project =
1690 
1691  CBioTreeContainer_Base::TUser& uo = in_project->SetUser();
1692 
1693  if (!uo.CanGetType() || !uo.IsSetType() || uo.GetType().Which()==CObject_id_Base::e_not_set ) {
1694  CRef<CObject_id> uo_id;
1695  uo_id.Reset(new CObject_id());
1696  uo_id->SetStr("Tree Metadata");
1697  uo.SetType(*uo_id);
1698  }
1699 
1700  phyWidget->GetDS()->GetTreeLabel().SaveToUserObject(uo);
1701  }
1702  else if (evt->GetID() == eCmdFeaturesEdited ||
1703  evt->GetID() == eCmdNodeExpandCollapse) {
1704 
1705  // hack to prevent event from x_FireProjectChangedEvent from
1706  // Causing OnProjectChangedEvent to force the model to be recreated from the biotree.
1707  // that should only happen if another view causes the data update.
1708  m_EditUpdate = true;
1709  IEventAttachment* attach = evt->GetAttachment();
1710  CFeatureEdit* fedit = dynamic_cast<CFeatureEdit*>(attach);
1711  if (fedit != NULL) {
1712  CStopWatch timer;
1713  timer.Start();
1714 
1716  fedit,
1717  m_DataSource,
1719 
1720  if (undoManager) {
1722 
1723  CIRef<IEditCommand> command(phycmd);
1724  undoManager->Execute(command);
1725 
1727  }
1728  }
1729  }
1730  else if (evt->GetID() == eCmdGrpExpandCollapse) {
1731  // hack to prevent event from x_FireProjectChangedEvent from
1732  // Causing OnProjectChangedEvent to force the model to be recreated from the biotree.
1733  // that should only happen if another view causes the data update.
1734  m_EditUpdate = true;
1735  IEventAttachment* attach = evt->GetAttachment();
1736  CExpandCollapseNodes* expand_collapse = dynamic_cast<CExpandCollapseNodes*>(attach);
1737  if (expand_collapse != NULL) {
1738  CStopWatch timer;
1739  timer.Start();
1740 
1742  expand_collapse,
1743  m_DataSource,
1745 
1746  if (undoManager) {
1748 
1749  CIRef<IEditCommand> command(phycmd);
1750  undoManager->Execute(command);
1751 
1753  }
1754  }
1755  }
1756  else {
1757  CRef<CBioTreeContainer> new_container(new CBioTreeContainer());
1758  TreeConvert2Container(*new_container, *m_DataSource->GetTree());
1759 
1760  // Copy any user data (selection sets, rendering options etc.) into tree
1761  if (m_BioTreeContainer->IsSetUser()) {
1762  new_container->SetUser().Assign(m_BioTreeContainer->GetUser());
1763  }
1764 
1765  /* Previously we did not have undo for sort, but (by commenting this out) we
1766  have added it back in
1767  if (eCmdTreeSorted == evt->GetID()) {
1768  CNcbiStrstream str;
1769  str << MSerial_AsnText << *new_container;
1770  CommitTheChanges((CNcbiIstrstream&)str);
1771  OnBioTreeChanged();
1772  }
1773  else
1774  */
1775  {
1776  CStopWatch timer;
1777  timer.Start();
1778 
1780  this,
1782  new_container);
1783 
1784  m_CreateUndoCommand = timer.Restart();
1785 
1786  if (undoManager) {
1787  // We do not execute the command here because the
1788  CIRef<IEditCommand> command(phyCommand);
1789  m_EditUpdate = true;
1790  undoManager->Execute(command);
1791 
1792  m_ExecuteUndoCommand = timer.Elapsed();
1793  }
1794  }
1795  }
1796  }
1797 
1799 {
1800  // no alternative for this; special command to update project item may be better
1801  // then dropping const
1802  CBioTreeContainer* in_project =
1804 
1806  bool has_tt = in_project->IsSetTreetype();
1807 
1808  if (has_tt)
1809  tt = in_project->GetTreetype();
1810 
1811  in_project->Reset();
1812  istr >> MSerial_AsnText >> *in_project;
1813 
1814  if (has_tt)
1815  in_project->SetTreetype(tt);
1816 }
1817 
1819 {
1820  CQueryPanelEvent* queryEvt = dynamic_cast<CQueryPanelEvent*>(evt);
1821  if (!queryEvt) return;
1822 
1824  sb_srv->SetStatusMessage(queryEvt->GetStatus());
1825 }
1826 
1827 ///////////////////////////////////////////////////////////////////////////////
1828 /// CPhyTreeViewFactory
1830 {
1831  static string sid("phy_tree_view_factory");
1832  return sid;
1833 }
1834 
1835 
1837 {
1838  static string slabel("Phylogenetic Tree View Factory");
1839  return slabel;
1840 }
1841 
1842 
1844 {
1845  string alias = GetViewTypeDescriptor().GetIconAlias();
1846  provider.RegisterFileAlias(ToWxString(alias), wxT("phylo_tree_view.png"));
1847 }
1848 
1850 {
1851  CPhyloTreeWidget::RegisterCommands(cmd_reg, provider);
1852 }
1853 
1855 {
1856  return s_PhyTreeViewTypeDescr;
1857 }
1858 
1859 
1861 {
1862  return new CPhyTreeView();
1863 }
1864 
1865 
1867 {
1868  /*TFingerprint print(CPhyTreeView::m_TypeDescr.GetLabel(), false);
1869  if(print == fingerprint) {
1870  return new CPhyTreeView();
1871  }*/
1872  return NULL;
1873 }
1874 
1875 
1876 
1878 {
1879  bool found_good = false;
1880  bool found_bad = false;
1881  for( size_t i = 0; i < objects.size(); i++) {
1882  const CObject* obj = objects[i].object;
1883  const type_info& type = typeid(*obj);
1884  if(typeid(CBioTreeContainer) == type) {
1885  found_good = true;
1886  } else {
1887  found_bad = true;
1888  }
1889  }
1890  if(found_good) {
1891  return fCanShowSeparated | (found_bad ? fCanShowSome : fCanShowAll);
1892  }
1893  return 0; // can show nothing
1894 }
1895 
1896 
1897 CPhyloTreeJob::CPhyloTreeJob(const objects::CBioTreeContainer* btc)
1898 {
1899  CFastMutexGuard lock(m_Mutex);
1900  m_Btc.Reset(const_cast<objects::CBioTreeContainer*>(btc));
1901  m_Descr = "Phylogenetic Tree Cutter Tool";
1902 }
1903 
1904 
1906 {
1907  CRef<objects::CProjectItem> item(new objects::CProjectItem());
1908 
1909  string label = "";
1911 
1912  item->SetItem().SetOther().Set(*m_Btc);
1913  item->SetLabel(label);
1914  AddProjectItem(*item);
1915 }
1916 
1917 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
Defines CBioTreeSelection, class used to broadcast selected tree nodes between views.
CAppJobTask CAppJobTask is an adapter that allows for running IAppJobs as Tasks in App Task Service.
static CAttribMenu & GetInstance()
Return a static instance of CAttribMenu.
Definition: attrib_menu.cpp:50
class CAttribMenuItem
CAttribMenu * AddSubMenuUnique(const std::string &name, void *user_value=NULL)
Convienance function to add a submenu to this menu.
CAttribFloatMenuItem * AddFloatReadOnly(const std::string &name, float *user_value)
Add entries to the menu which display the users value but do not update it.
bool RemoveMenuR(const std::string &name, void *user_value=NULL)
Search the menu(s) recursively for menu 'name' with the specified user data 'user_value'.
Feature dictionary.
Definition: bio_tree.hpp:176
const TNodeIdsVector & GetNodeIds() const
Returns const list of selected nodes.
std::vector< objects::CNode::TId > TNodeIdsVector
Vector of node IDs.
const TNodeIdsVector & GetExplicitlySelectedNodeIds() const
Returns const list of explicitly selected nodes.
std::string GetFeatureValue(objects::CNode::TId nodeId, objects::CFeatureDescr::TId featureId) const
Gets the value of a feature for the specified node id.
objects::CFeatureDescr::TId GetFeatureId(const std::string &feature) const
Gets the id of the specified feature.
bool HasFeature(const std::string &feature) const
Checks if the BioTree has the specified feature.
CConstRef< objects::CBioTreeContainer > GetBioTree() const
Returns the BioTree.
CBioTreeContainer::TFdict TContainerDict
TCNode::TFeatures TCNodeFeatureSet
virtual void Execute()
Do the editing action.
TNodeList::value_type::element_type TCNode
CChangePhyloExpandCollapseCmd(CPhyTreeView *view, CExpandCollapseNodes *ec_edit, CRef< CPhyloTreeDataSource > ds, CConstRef< objects::CBioTreeContainer > bio_tree)
CConstRef< objects::CBioTreeContainer > m_BioTree
CBioTreeContainer::TNodes TCNodeSet
CRef< CPhyloTreeDataSource > m_DS
TCNodeFeatureSet::Tdata TNodeFeatureList
CRef< CExpandCollapseNodes > m_ExpandCollapseEdit
TNodeFeatureList::value_type::element_type TCNodeFeature
virtual void Unexecute()
Undo (opposite to Execute())
TContainerDict::Tdata::value_type::element_type TCFeatureDescr
void PerformEdit(CPhyloNodeData::TDisplayChildren ec, CNodeFeature_Base::TValue &collapse_value)
virtual bool CanMerge(IEditCommand *cmd)
IEditCommand merge commands (macros allow changes to both properties and selection sets,...
CBioTreeContainer::TFdict TContainerDict
TCNodeFeatureSet::Tdata TNodeFeatureList
virtual void Unexecute()
Undo (opposite to Execute())
TNodeFeatureList::value_type::element_type TCNodeFeature
virtual void Execute()
Do the editing action.
CRef< CChangePhyloSelectionSetCmd > m_MergedCmd
TCNode::TFeatures TCNodeFeatureSet
virtual string GetLabel()
CRef< CFeatureEdit > m_FeatureEdit
CChangePhyloPropertyCmd(CPhyTreeView *view, CFeatureEdit *fedit, CRef< CPhyloTreeDataSource > ds, CConstRef< objects::CBioTreeContainer > bio_tree)
CRef< CPhyloTreeDataSource > m_DS
TCNodeSet::Tdata TNodeList
CBioTreeContainer::TNodes TCNodeSet
TContainerDict::Tdata::value_type::element_type TCFeatureDescr
virtual void Merge(IEditCommand *cmd)
CConstRef< objects::CBioTreeContainer > m_BioTree
void PerformFeatureDictEdit(CBioTreeFeatureDictionary &dict)
void PerformEdit(CBioTreeFeatureDictionary &dict, bool prev_features)
TNodeList::value_type::element_type TCNode
SelectionSets are stored in the biotreecontainer's user-data object so we need a special change comma...
CConstRef< objects::CBioTreeContainer > m_BioTree
CRef< CSelectionSetEdit > m_SelectionEdit
CChangePhyloSelectionSetCmd(CPhyTreeView *view, CSelectionSetEdit *sel_edit, CRef< CPhyloTreeDataSource > ds, CConstRef< objects::CBioTreeContainer > bio_tree)
virtual void Execute()
Do the editing action.
CRef< CPhyloTreeDataSource > m_DS
virtual void Unexecute()
Undo (opposite to Execute())
static CLZOCompression m_Compressor
CChangePhyloTreeCommand(CPhyTreeView *view, CConstRef< CBioTreeContainer > prev_tree, CRef< CBioTreeContainer > new_tree)
virtual string GetLabel()
struct CChangePhyloTreeCommand::SBTree TBTree
static vector< char > m_UtilVec
virtual void Unexecute()
Undo (opposite to Execute())
virtual void Execute()
Do the editing action.
CConstRef –.
Definition: ncbiobj.hpp:1266
CDataLoadingAppJob - a base class for Jobs loading data into projects.
void AddProjectItem(objects::CProjectItem &item)
CRef< objects::CScope > m_Scope
CDataLoadingAppTask - a task that executes CDataLoadingAppJob.
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
CPhyExportParams & GetData()
Data access.
CFeatureDictSet –.
CGBDocument.
Definition: document.hpp:113
virtual void Create()
creates controls and performs basic initialization
CLZOCompression –.
Definition: lzo.hpp:117
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CNodeSet –.
Definition: NodeSet.hpp:66
void Clear(objects::CScope *scope)
void Add(ISelObjectHandle *obj_handle, CObject &obj)
void GetMatches(const CObject &object, objects::CScope &scope, TResults &results) const
CObject –.
Definition: ncbiobj.hpp:180
CPhyExportJob.
void SetLabelFormat(const wxString &value)
void SetBioTree(CBioTreeContainer *value)
CPhyRebuildIndexVisitor(CObjectIndex &idx)
ETreeTraverseCode operator()(CPhyloTree &tree, CPhyloTree::TTreeIdx node_idx, int delta)
CPhyTreePanel(wxWindow *parent, long childId)
virtual bool ProcessEvent(wxEvent &event)
CPhyTreeView.
objects::CNode::TId TID
vector< CPhyloSelectionSet > & GetSets()
void SetSelectionSetProperty(CPhyloTree *tree_model)
void RenumberClusterIDs(int start_id)
Update all cluster ids using the starting-id as the lowest value.
void SaveToUserObject(objects::CBioTreeContainer_Base::TUser &uo)
void Init(const objects::CBioTreeContainer &tree, objects::CScope &scope, bool expand_all=false)
Throws exception if tree is empty - at least 1 node is required.
CPhyloTree * GetTree()
CTreeLabel GetTreeLabel() const
TClusterID GetMaxClusterID()
void Relabel(CPhyloTreeScheme *scheme, string labelFmt)
void Sort(bool ascending)
CPhyloSelectionSetMgr & GetSelectionSets()
const CBioTreeFeatureDictionary & GetDictionary() const
CTreeGraphicsModel & GetModel()
Get model for rendering.
CPhyloTreeJob.
string GetLabelForNode(const CPhyloTree &tree, const CPhyloTreeNode &node, const string &format)
void SetScheme(CPhyloTreeScheme &sl, const CPhyloTree *tree)
void ExpandCollapse(CBioTreeFeatureDictionary &dict, CPhyloNodeData::TDisplayChildren chds)
Set this node to be expanded/collapsed.
void SetLabel(CBioTreeFeatureDictionary &dict, const string &label)
Set label string and synch value to the feature list for this ndoe.
virtual bool LoadCurrentSettings()
string & SetTooltipFormat(void)
void SetLabelStyle(const TLabelStyle &ls)
string & SetLabelFormat(void)
void SetLabelVisibility(const TLabelsVisibility &lv)
ETreeTraverseCode operator()(CPhyloTree &tree, CPhyloTree::TTreeIdx node_idx, int delta)
TTreeIdx GetSelectionRootIdx() const
class CPhyloTreeWidget
void SetCurrRenderer(int idx)
bool GetUseDistances() const
void SetQueryPanel(CQueryParsePanel *queryPanel)
virtual CPhyloTreeDataSource * GetDS(void)
bool GetRotateLabels() const
virtual void SetDataSourceNoUpdate(CPhyloTreeDataSource *p_ds)
virtual void RemoveCurrentDataSource()
void SetRotateLabels(bool rot)
void SetScheme(CPhyloTreeScheme &sl)
void SetUseDistances(bool bDist)
static void RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
class CPhyloTreeWidget
virtual void RedrawDataSource()
Force tree to be re-masured and call layout.
CPhyloTreeScheme & GetScheme(void)
Tree subclass also has functions and data needed for rendering and selection.
Definition: phylo_tree.hpp:52
void SetExplicitlySelected(const vector< TID > &esel)
Reset explicitly selected nodes to those currently selected nodes that are also found in the vector '...
Definition: phylo_tree.cpp:321
void SetSelectionIDs(const vector< TID > &ids, bool sel=true, bool sel_children=true)
Select a set of nodes - equivalent to calling SetSelection(idx, true, true, true) on each of the node...
Definition: phylo_tree.cpp:346
void SetLeavesExplicitlySelected()
Set the nodes used for iteration to default to the leaf nodes.
Definition: phylo_tree.cpp:337
void ClearSelection()
Sets selection state of all nodes to eNotSelected and clears m_Selected.
Definition: phylo_tree.cpp:242
void GetSelectedIDs(vector< TID > &sel) const
Returns the node ids of selected nodes.
Definition: phylo_tree.cpp:265
CPhyloNodeData::TClusterID TClusterID
Definition: phylo_tree.hpp:54
CPhyloSelectionSetMgr & GetSelectionSets()
Definition: phylo_tree.hpp:326
void SetSelection(TTreeIdx idx, bool sel, bool sel_children=true, bool sel_parents=true)
Select or deselect the node at the specified index and, optionally, its parents and children as well.
Definition: phylo_tree.cpp:577
TTreeIdx GetCurrentNodeIdx() const
Return the index of the currently active node (may be Null()).
Definition: phylo_tree.hpp:268
bool HasCurrentNode() const
Return true if the currently active node is not Null()
Definition: phylo_tree.hpp:274
void GetExplicitlySelectedIDs(vector< TID > &esel) const
Returns only ids of nodes explicitly selected, not their parents or children, i.e.
Definition: phylo_tree.cpp:313
TTreeIdx FindNodeById(TID id) const
Return index of the node with the given id or Null().
Definition: phylo_tree.hpp:307
CBioTreeFeatureDictionary & GetFeatureDict()
Return feature dictionary.
Definition: phylo_tree.hpp:323
void GetSelected(vector< TTreeIdx > &sel) const
Returns indices of selected nodes.
Definition: phylo_tree.cpp:259
size_t GetNumSelected() const
Returns the number of selected nodes.
Definition: phylo_tree.hpp:151
CProjectService - a service providing API for operations with Workspaces and Projects.
virtual void x_ReportInvalidInputData(TConstScopedObjects &objects)
use this function to report incompatible data in InitView()
virtual void OnProjectChanged()
virtual void x_UpdateContentLabel()
unique_ptr< const wxMenu > m_MenuBarMenu
virtual objects::CScope * x_GetScope() const
virtual void x_AttachToProject(CGBDocument &doc)
virtual bool x_HasProject() const
CProjectViewEvent.
Definition: document.hpp:62
EEventSubtype GetSubtype() const
Definition: document.hpp:96
CProjectViewTypeDescriptor - holds description of a project view type.
CProjectView.
virtual CUndoManager * x_GetUndoManager()
gets undo manager
const string & GetStatus() const
CQueryParsePanel.
virtual void Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Create window.
CScope –.
Definition: scope.hpp:92
TTreeIdx GetNodeIdx() const
CSelNodeHandle(CPhyloTree::TTreeIdx node_idx)
CProjectSelectOptions - describes how new Project Items shall be added to a workspace.
void Set_AddToExistingProject(TProjectId &project_id, const string &folder=kEmptyStr)
CSelectionEvent CSelectionEvent is used for broadcasting selection between views.
Definition: obj_event.hpp:68
vector< CConstRef< objects::CSeq_id > > TIds
Definition: obj_event.hpp:75
const TIdLocs & GetIdLocs() const
Definition: obj_event.hpp:123
const TTaxIds & GetTaxIDs() const
Definition: obj_event.hpp:124
static bool sm_TreeBroadcastOneToOne
Node properties used to compare trees when broadcasting.
Definition: obj_event.hpp:216
void AddTaxIDSelection(TTaxId tid)
Definition: obj_event.cpp:306
void GetIndexed(const string &area_name, TConstObjects &objs) const
Get Objects from the private broadcasting area (caller has to make sure output objs is empty)
Definition: obj_event.cpp:240
static vector< string > sm_TreeBroadcastProperties
broadcast sel. between documents
Definition: obj_event.hpp:213
vector< CConstRef< CIdLoc > > TIdLocs
Definition: obj_event.hpp:76
void AddIndexed(const string &area_name, const CObject &obj)
Add private selection broadcasting info.
Definition: obj_event.cpp:235
objects::CScope & GetScope()
Definition: obj_event.hpp:95
const TIds & GetIds() const
Definition: obj_event.hpp:122
bool HasObjectSelection()
Object Selection - represents select Objects (such as features, alignments, etc)
Definition: obj_event.cpp:171
bool AddObjectSelection(const CObject &obj)
Definition: obj_event.cpp:177
CStopWatch –.
Definition: ncbitime.hpp:1937
Class designed to hold a set of tax-ids represented as (on) bits in a bit vector.
bool IsSelected(TTaxId tid) const
bm::id_t TTaxId
CRgbaGradColorTable * GetColorTable()
Get color table used a 1D texture map for edges and nodes.
void SaveToUserObject(CBioTreeContainer_Base::TUser &uo)
static TTreeIdx Null()
Return the index value that represents a NULL node.
Definition: tree_model.hpp:678
TNodeType & GetNode(TTreeIdx idx)
Return a reference to the node at the given index.
Definition: tree_model.hpp:207
TTreeIdx GetRootIdx() const
Return the index of the root node.
Definition: tree_model.hpp:267
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
bool HasField(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Verify that a named field exists.
CUser_object & AddField(const string &label, const string &value, EParseField parse=eParse_String)
add a data field to the user object that holds a given value
CUser_field & SetField(const string &str, const string &delim=".", const string &obj_subtype=kEmptyStr, NStr::ECase use_case=NStr::eCase)
Access a named field in this user object.
const CUser_field & GetField(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Access a named field in this user object.
Definition: User_object.cpp:71
CViewTypeDescriptor - holds description of a view type.
Definition: view.hpp:98
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
Interface (functor) for object editing.
object, that will be attached to event
Definition: event.hpp:51
virtual const CViewTypeDescriptor & GetViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
IRegSettings An interface for objects that save / restore settings using CGuiRegistry.
virtual void SaveSettings() const =0
virtual void LoadSettings()=0
virtual void SetRegistryPath(const string &path)=0
IView - represents a standard visual part of Workbench UI.
Definition: view.hpp:73
CFingerprint identifies an instance of IWMClient and is used for labeling layout positions.
Definition: wm_client.hpp:58
bool operator()(const CUpdatedFeature &lhs, const CUpdatedFeature &rhs) const
CPhyloNodeData::TID m_ID
SUpdateFeatureCompare(const CPhyloNodeData::TID id)
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
TBioTreeFeatureId m_FeatureId
const set< string > & m_FeatureValues
visitor_string_query(TBioTreeFeatureId feat_id, const set< string > &feat_values)
ETreeTraverseCode operator()(CPhyloTree &tree, CPhyloTree::TTreeIdx node_idx, int delta)
const vector< CPhyloTree::TTreeIdx > & GetNodes()
visitor_string_query & operator=(const visitor_string_query &rhs)
vector< CPhyloTree::TTreeIdx > m_SelNodes
ETreeTraverseCode operator()(CPhyloTree &tree, CPhyloTree::TTreeIdx node_idx, int delta)
visitor_taxid_query & operator=(const visitor_taxid_query &rhs)
visitor_taxid_query(const CSelectionEvent::TTaxIds &tids, TBioTreeFeatureId tax_feat_id)
const vector< CPhyloTree::TTreeIdx > & GetNodes()
vector< CPhyloTree::TTreeIdx > m_SelNodes
TBioTreeFeatureId m_TaxFeatureId
const CSelectionEvent::TTaxIds & m_TaxIds
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
static ulg compressed_len
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define false
Definition: bool.h:36
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
virtual bool DecompressBuffer(const void *src_buf, size_t src_len, void *dst_buf, size_t dst_size, size_t *dst_len)
Decompress data in the buffer.
Definition: lzo.cpp:586
virtual bool CompressBuffer(const void *src_buf, size_t src_len, void *dst_buf, size_t dst_size, size_t *dst_len)
Compress data in the buffer.
Definition: lzo.cpp:490
virtual size_t EstimateCompressionBufferSize(size_t src_len)
Estimate buffer size for data compression.
Definition: lzo.cpp:676
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#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
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
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
void AddTask(IAppTask &task)
Add a task to the queue.
virtual CAppTaskService * GetAppTaskService()=0
virtual void RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
called by the framework to give Factory a chance to register commands used by view
CPhyloTree::TTreeIdx m_CurrentNode
void RebuildObjectIndex()
CRef< CPhyloTreeDataSource > m_DataSource
int m_InitialRotateLabels
If rendering parms are stored in biotreecontainer, set them first time.
virtual string GetExtensionIdentifier() const
CPhyTreeViewFactory.
virtual void x_OnSetSelection(CSelectionEvent &evt)
override in derived classes in order to handle selection broadcast
CObjectIndex m_ObjectIndex
CPhyloTreeJob(const objects::CBioTreeContainer *btc)
virtual int TestInputObjects(TConstScopedObjects &objects)
tests input objects (not using object conversion) and returns a combination of ETestResult flags bett...
virtual const CProjectViewTypeDescriptor & GetProjectViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
void OnCreateSelectedSubtree(CEvent *evt)
virtual IView * CreateInstance() const
creates a view instance
virtual void RegisterIconAliases(wxFileArtProvider &provider)
called by the framework to give Factory a chance to register images used by view
virtual void SetRegistryPath(const string &reg_path)
CPhyloTreeWidget * GetWidget() const
virtual bool InitView(TConstScopedObjects &objects, const objects::CUser_object *params)
initialize view with data, inside this function the view must call CProjectService::AttachView to con...
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
void OnBioTreeChanged()
virtual void GetVisibleRanges(CVisibleRange &vrange) const
populate a visible range event for broadcasting
CRef< objects::CBioTreeContainer > m_Cont
virtual void SaveSettings() const
void OnSomethingEdited(CEvent *evt)
void AppliedEditToDataSource()
virtual const CObject * x_GetOrigObject() const
virtual void x_CreateMenuBarMenu()
initializes m_MenuBarMenu; override in derived classes
virtual IView * CreateInstanceByFingerprint(const TFingerprint &fingerprint) const
if fingerprint is recognized - creates and returns a new instance
CRef< CPhyloTreeScheme > m_Scheme
CRef< objects::CBioTreeContainer > m_Btc
virtual void x_CreateProjectItems()
override this function in derived classes and populate m_Items.
CConstRef< objects::CBioTreeContainer > m_BioTreeContainer
void x_QueryStatusChange(CEvent *evt)
void GetSelection(CSelectionEvent &evt) const
get selection for broadcasting
virtual const CViewTypeDescriptor & GetTypeDescriptor() const
return an object providing meta information about thei view type
virtual void DestroyViewWindow()
destroy Window corresponding to the view
virtual void LoadSettings()
void OnExportTree(CEvent *evt)
void CommitTheChanges(CNcbiIstrstream &istr)
virtual void CreateViewWindow(wxWindow *parent)
create Window corresponding to the view
virtual wxWindow * GetWindow()
returns a pointer to the wxWindow representing the client
wxPanel * m_Panel
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
const TEventID GetID(void) const
Inline Implementation.
Definition: event.hpp:164
string m_Descr
mutex to sync our internals
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
virtual const string & GetIconAlias() const
Definition: ui_object.cpp:130
CFastMutex m_Mutex
#define ON_EVENT(type, id, handler)
#define END_EVENT_MAP()
Ends definition of Command Map.
#define BEGIN_EVENT_MAP(thisClass, baseClass)
Begins definition of Command Map for CEventHandler-derived class.
virtual void AddListener(CEventHandler *listener, int pool_name=ePool_Default)
Add a listener.
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
virtual IEventAttachment * GetAttachment(void)
Definition: event.cpp:81
@ eDefault
Definition: label.hpp:73
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
bool Empty(void) const THROWS_NONE
Check if CConstRef is empty – not pointing to any object which means having a null value.
Definition: ncbiobj.hpp:1385
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:735
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
TObjectType * GetNonNullPointer(void) const
Get pointer value and throw a null pointer exception if pointer is null.
Definition: ncbiobj.hpp:1654
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
Definition: ncbiobj.hpp:719
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
#define numeric_limits
Pre-declaration of the "numeric_limits<>" template Forcibly overrides (using preprocessor) the origin...
Definition: ncbi_limits.hpp:92
#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 unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned int.
Definition: ncbistr.cpp:642
double Restart(void)
Return time elapsed since first Start() or last Restart() call (in seconds).
Definition: ncbitime.hpp:2816
double Elapsed(void) const
Return time elapsed since first Start() or last Restart() call (in seconds).
Definition: ncbitime.hpp:2775
void Start(void)
Start the timer.
Definition: ncbitime.hpp:2764
ETreeTraverseCode
Tree traverse code returned by the traverse predicate function.
Definition: ncbi_tree.hpp:51
unsigned int TBioTreeFeatureId
Feature Id.
Definition: bio_tree.hpp:60
TBioTreeFeatureId GetId(const string &feature_name) const
If feature is already registered returns its id by name.
Definition: bio_tree.cpp:209
bool HasFeature(const string &feature_name) const
Check if feature is listed in the dictionary.
Definition: bio_tree.cpp:146
const TFeatureDict & GetFeatureDict() const
Get reference on the internal map.
Definition: bio_tree.hpp:219
vector< CBioTreeFeaturePair > TFeatureList
Definition: bio_tree.hpp:103
@ eTreeTraverse
Keep traversal.
Definition: ncbi_tree.hpp:52
static const char label[]
list< CRef< CFeatureDescr > > Tdata
const TTreetype & GetTreetype(void) const
Get the Treetype member data.
void SetNodes(TNodes &value)
Assign a value to Nodes data member.
void SetFdict(TFdict &value)
Assign a value to Fdict data member.
list< CRef< CNodeFeature > > Tdata
virtual void Reset(void)
Reset the whole object.
CStringUTF8 TValue
void Reset(void)
Reset data member.
void SetTreetype(const TTreetype &value)
Assign a value to Treetype data member.
list< CRef< CNode > > Tdata
Definition: NodeSet_.hpp:89
bool IsSetTreetype(void) const
hint on what kind of tree this is Check if a value has been assigned to Treetype data member.
Tdata & Set(void)
Assign a value to data member.
void SetUser(TUser &value)
Assign a value to User data member.
const TStr & GetStr(void) const
Get the variant data.
bool CanGetType(void) const
Check if it is safe to call GetType method.
bool IsSetType(void) const
type of object within class Check if a value has been assigned to Type data member.
const TData & GetData(void) const
Get the Data member data.
TBool GetBool(void) const
Get the variant data.
E_Choice Which(void) const
Which variant is currently selected.
Definition: Object_id_.hpp:235
bool IsInt(void) const
Check if variant Int is selected.
bool IsStr(void) const
Check if variant Str is selected.
TInt GetInt(void) const
Get the variant data.
TStr & SetStr(void)
Select the variant.
Definition: Object_id_.hpp:304
void SetType(TType &value)
Assign a value to Type data member.
void SetData(TData &value)
Assign a value to Data data member.
const TType & GetType(void) const
Get the Type member data.
bool IsBool(void) const
Check if variant Bool is selected.
@ e_not_set
No variant selected.
Definition: Object_id_.hpp:89
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
for(len=0;yy_str[len];++len)
int i
yy_size_t n
int len
LZO Compression API.
#define wxT(x)
Definition: muParser.cpp:41
constexpr auto sort(_Init &&init)
Defines: CTimeFormat - storage class for time format.
const char * command
T max(T x_, T y_)
Int4 delta(size_t dimension_, const Int4 *score_)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
static int * results[]
USING_SCOPE(objects)
CProjectViewTypeDescriptor s_PhyTreeViewTypeDescr("Tree View", "phylo_tree_view", "Tree View", "View for graphical presentation of hierarchical data (phylogenetic tree, taxonomy tree, etc.) using various layout methods", "PHY_TREE_VIEW", "Alignment", false, "BioTreeContainer", eOneObjectAccepted)
float m_ExecOnBioTreeChanged
float m_CreateProperyUndoCommand
float m_DataSourceInitTimer
float m_ExecutePropertyCommand
float m_ExecuteUndoCommand
float m_CreateUndoCommand
Timers:
void TreeConvert2Container(TBioTreeContainer &tree_container, TPhyloTree &phylo_tree, typename TPhyloTree::TTreeIdx node_idx=TPhyloTree::Null())
Convert tree to ASN.1 BioTree container.
void TreeConvertSelected2Container(TBioTreeContainer &tree_container, TPhyloTree &phylo_tree, typename TPhyloTree::TTreeIdx node_idx=TPhyloTree::Null())
Convert selected nodes from tree to ASN.1 BioTree container.
@ eCmdGrpExpandCollapse
@ eCmdTreeLabelSet
@ eCmdLabelFormatChanged
@ eCmdNodeExpandCollapse
@ eCmdTreeSorted
@ eCmdRenderingOptionsChanged
@ eCmdSomethingEdited
@ eCmdFeaturesEdited
@ eCmdSubtreeFromSelected
@ eCmdExportTree
@ eOneObjectAccepted
wxEVT_COMMAND_MENU_SELECTED
static static static wxID_ANY
CPhyloNodeData::TDisplayChildren GetExpanded() const
vector< CPhyloNodeData::TID > & GetIds()
Edits for one or more nodes.
CBioTreeFeatureDictionary & GetPrevDictionary()
vector< CUpdatedFeature > & GetUpdated()
bool SeqIdEdited()
CBioTreeFeatureDictionary & GetDictionary()
Edits for one or more nodes.
CPhyloSelectionSetMgr & GetUpdatedSet()
CPhyloSelectionSetMgr & GetPrevSet()
CPhyloNodeData::TID m_NodeId
Node id to find node in either tree or biotree.
Definition: type.c:6
#define _ASSERT
Fun TreeDepthFirst(TTreeModel &tree_model, typename TTreeModel::TTreeIdx node_idx, Fun func)
Depth-first tree traversal algorithm.
Definition: tree_model.hpp:355
size_t TTreeIdx
Bi-directionaly linked N way tree allocated in a contiguous memory block.
Definition: tree_model.hpp:48
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Fri Sep 20 14:57:49 2024 by modify_doxy.py rev. 669887