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

Go to the SVN repository for this file.

1 /* Id: phylo_save_selection_dlg.cpp 36876 2016-11-09 13:02:26Z falkrb $
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:
27  *
28  * File Description:
29  *
30  */
31 #include <ncbi_pch.hpp>////@begin includes
32 ////@end includes
33 
35 
36 #include <corelib/ncbiobj.hpp>
37 
43 
44 #include <wx/msgdlg.h>
45 #include <wx/textctrl.h>
46 #include <wx/stattext.h>
47 #include <wx/statbox.h>
48 #include <wx/sizer.h>
49 #include <wx/clrpicker.h>
50 #include <wx/bitmap.h>
51 #include <wx/listctrl.h>
52 #include <wx/button.h>
53 #include <wx/imaglist.h>
54 
55 ////@begin XPM images
56 ////@end XPM images
57 static const char * checked_xpm[] = {
58 "16 16 4 1",
59 " c None",
60 ". c #808080",
61 "X c Black",
62 "o c #c0c0c0",
63 " ",
64 " ",
65 " ............ ",
66 " .XXXXXXXXXXo ",
67 " .X o ",
68 " .X X o ",
69 " .X XX o ",
70 " .X X XXX o ",
71 " .X XX XXX o ",
72 " .X XXXXX o ",
73 " .X XXX o ",
74 " .X X o ",
75 " .X o ",
76 " .ooooooooooo ",
77 " ",
78 " "};
79 /* XPM */
80 static const char * unchecked_xpm[] = {
81 "16 16 4 1",
82 " c None",
83 ". c #808080",
84 "X c Black",
85 "o c #c0c0c0",
86 " ",
87 " ",
88 " ............ ",
89 " .XXXXXXXXXXo ",
90 " .X o ",
91 " .X o ",
92 " .X o ",
93 " .X o ",
94 " .X o ",
95 " .X o ",
96 " .X o ",
97 " .X o ",
98 " .X o ",
99 " .ooooooooooo ",
100 " ",
101 " "};
102 
103 static const char * up_xpm[] = {
104 "16 16 2 1",
105 " c None",
106 "X c Gray25",
107 " ",
108 " ",
109 " ",
110 " ",
111 " X ",
112 " XXX ",
113 " XXXXX ",
114 " XXXXXXX ",
115 " XXXXXXXXX ",
116 " XXXXXXXXXXX ",
117 " XXXXXXXXXXXXX ",
118 " XXXXXXXXXXXXXXX",
119 " ",
120 " ",
121 " ",
122 " "};
123 
124 
125 static const char * down_xpm[] = {
126 "16 16 2 1",
127 " c None",
128 "X c Gray25",
129 " ",
130 " ",
131 " ",
132 " ",
133 " XXXXXXXXXXXXXXX",
134 " XXXXXXXXXXXXX ",
135 " XXXXXXXXXXX ",
136 " XXXXXXXXX ",
137 " XXXXXXX ",
138 " XXXXX ",
139 " XXX ",
140 " X ",
141 " ",
142 " ",
143 " ",
144 " "};
145 
147 
148 IMPLEMENT_DYNAMIC_CLASS( CPhyloSaveSelectiondlg, wxDialog )
149 
150 BEGIN_EVENT_TABLE( CPhyloSaveSelectiondlg, wxDialog )
151 
152 ////@begin CPhyloSaveSelectiondlg event table entries
154 
156 
158 
160 
162 
164 
166 
167  EVT_BUTTON( wxID_OK, CPhyloSaveSelectiondlg::OnOkClick )
168 
169 ////@end CPhyloSaveSelectiondlg event table entries
170 
172 
174 {
175  Init();
176 }
177 
178 CPhyloSaveSelectiondlg::CPhyloSaveSelectiondlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
179 {
180  Init();
181  Create(parent, id, caption, pos, size, style);
182 }
183 
184 bool CPhyloSaveSelectiondlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
185 {
186 ////@begin CPhyloSaveSelectiondlg creation
187  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
188  wxDialog::Create( parent, id, caption, pos, size, style );
189 
190  CreateControls();
191  if (GetSizer())
192  {
193  GetSizer()->SetSizeHints(this);
194  }
195  Centre();
196 ////@end CPhyloSaveSelectiondlg creation
197 
198  wxImageList *il = new wxImageList(16, 16, true, 2);
199  il->Add( wxBitmap( unchecked_xpm ) );
200  il->Add( wxBitmap( checked_xpm ) );
201  m_SelList->AssignImageList(il, wxIMAGE_LIST_SMALL);
202 
203  wxListItem itemCol;
204  itemCol.SetText(wxT("Select"));
205  itemCol.SetWidth(60);
206  m_SelList->InsertColumn(0, itemCol);
207 
208  itemCol.SetText(wxT("Name"));
209  itemCol.SetWidth(370);
210  m_SelList->InsertColumn(1, itemCol);
211 
212  return true;
213 }
214 
216 {
217 ////@begin CPhyloSaveSelectiondlg destruction
218 ////@end CPhyloSaveSelectiondlg destruction
219 }
220 
222 {
223 ////@begin CPhyloSaveSelectiondlg member initialisation
224  m_SelList = NULL;
227  m_ButtonUp = NULL;
228  m_ButtonDown = NULL;
229  m_DeleteBtn = NULL;
231 ////@end CPhyloSaveSelectiondlg member initialisation
232 
233  m_CurrentItem = -1;
234 }
235 
237 {
238 ////@begin CPhyloSaveSelectiondlg content construction
239  CPhyloSaveSelectiondlg* itemDialog1 = this;
240 
241  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
242  itemDialog1->SetSizer(itemBoxSizer2);
243 
244  wxStaticBox* itemStaticBoxSizer3Static = new wxStaticBox(itemDialog1, wxID_ANY, wxEmptyString);
245  wxStaticBoxSizer* itemStaticBoxSizer3 = new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxHORIZONTAL);
246  itemBoxSizer2->Add(itemStaticBoxSizer3, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
247 
248  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
249  itemStaticBoxSizer3->Add(itemBoxSizer4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
250 
251  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
252  itemBoxSizer4->Add(itemBoxSizer5, 0, wxALIGN_LEFT|wxALL, 5);
253 
254  m_SelList = new wxListCtrl( itemStaticBoxSizer3->GetStaticBox(), ID_SEL_LISTCTRL, wxDefaultPosition, wxSize(540, 200), wxLC_REPORT|wxLC_NO_SORT_HEADER|wxLC_SINGLE_SEL|wxLC_HRULES|wxLC_VRULES );
255  m_SelList->SetHelpText(_("List of saved selections"));
257  m_SelList->SetToolTip(_("List of saved selections"));
258  itemBoxSizer5->Add(m_SelList, 1, wxGROW|wxALL, 5);
259 
260  wxStaticBox* itemStaticBoxSizer7Static = new wxStaticBox(itemStaticBoxSizer3->GetStaticBox(), wxID_ANY, _("Update Selection Name, Color or Order"));
261  wxStaticBoxSizer* itemStaticBoxSizer7 = new wxStaticBoxSizer(itemStaticBoxSizer7Static, wxHORIZONTAL);
262  itemBoxSizer4->Add(itemStaticBoxSizer7, 0, wxALIGN_LEFT|wxALL, 5);
263 
264  wxStaticText* itemStaticText8 = new wxStaticText( itemStaticBoxSizer7->GetStaticBox(), wxID_STATIC, _("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
265  itemStaticBoxSizer7->Add(itemStaticText8, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP|wxBOTTOM, 5);
266 
267  m_SelectionName = new wxTextCtrl( itemStaticBoxSizer7->GetStaticBox(), ID_SELECTION, wxEmptyString, wxDefaultPosition, wxSize(180, -1), 0 );
268  m_SelectionName->Enable(false);
269  itemStaticBoxSizer7->Add(m_SelectionName, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
270 
271  m_SelColorPicker = new wxColourPickerCtrl( itemStaticBoxSizer7->GetStaticBox(), ID_SEL_COLOR_PICKER, wxColour(), wxDefaultPosition, wxDefaultSize, wxCLRP_DEFAULT_STYLE );
272  m_SelColorPicker->Enable(false);
273  itemStaticBoxSizer7->Add(m_SelColorPicker, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
274 
275  m_ButtonUp = new wxButton( itemStaticBoxSizer7->GetStaticBox(), ID_BITMAPBUTTON_UP, wxEmptyString, wxDefaultPosition, wxSize(24, -1), 0 );
276  m_ButtonUp->Enable(false);
277  itemStaticBoxSizer7->Add(m_ButtonUp, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM, 5);
278 
279  m_ButtonDown = new wxButton( itemStaticBoxSizer7->GetStaticBox(), ID_BITMAPBUTTON_DOWN, wxEmptyString, wxDefaultPosition, wxSize(24, -1), 0 );
280  m_ButtonDown->Enable(false);
281  itemStaticBoxSizer7->Add(m_ButtonDown, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP|wxBOTTOM, 5);
282 
283  m_DeleteBtn = new wxButton( itemStaticBoxSizer7->GetStaticBox(), ID_DELETE_SEL_BTN, _("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
284  m_DeleteBtn->Enable(false);
285  itemStaticBoxSizer7->Add(m_DeleteBtn, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM, 5);
286 
287  m_AddSelectionBtn = new wxButton( itemStaticBoxSizer7->GetStaticBox(), ID_ADD_CURRENT_SEL_BTN, _("Add New"), wxDefaultPosition, wxDefaultSize, 0 );
288  itemStaticBoxSizer7->Add(m_AddSelectionBtn, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5);
289 
290  wxBoxSizer* itemBoxSizer15 = new wxBoxSizer(wxHORIZONTAL);
291  itemBoxSizer2->Add(itemBoxSizer15, 0, wxALIGN_RIGHT|wxALL, 5);
292 
293  wxButton* itemButton16 = new wxButton( itemDialog1, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
294  itemBoxSizer15->Add(itemButton16, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
295 
296  // Connect events and objects
297  m_SelList->Connect(ID_SEL_LISTCTRL, wxEVT_LEFT_DOWN, wxMouseEventHandler(CPhyloSaveSelectiondlg::OnLeftDown), NULL, this);
298 ////@end CPhyloSaveSelectiondlg content construction
299 
300  m_ButtonUp->SetBitmap(wxBitmap(up_xpm));
301  m_ButtonDown->SetBitmap(wxBitmap(down_xpm));
302 }
303 
305 {
306  return true;
307 }
308 wxBitmap CPhyloSaveSelectiondlg::GetBitmapResource( const wxString& name )
309 {
310  // Bitmap retrieval
311 ////@begin CPhyloSaveSelectiondlg bitmap retrieval
312  wxUnusedVar(name);
313  return wxNullBitmap;
314 ////@end CPhyloSaveSelectiondlg bitmap retrieval
315 }
316 wxIcon CPhyloSaveSelectiondlg::GetIconResource( const wxString& name )
317 {
318  // Icon retrieval
319 ////@begin CPhyloSaveSelectiondlg icon retrieval
320  wxUnusedVar(name);
321  return wxNullIcon;
322 ////@end CPhyloSaveSelectiondlg icon retrieval
323 }
324 
326 {
327  m_SelectionName->Enable(b);
328  m_SelColorPicker->Enable(b);
329  m_ButtonUp->Enable(b);
330  m_ButtonDown->Enable(b);
331  m_DeleteBtn->Enable(b);
332  //m_AddSelectionBtn->Enable(b);
333 }
334 
336 {
337  // Get currently selected nodes (the current selection set)
338  vector<CPhyloTree::TTreeIdx> currently_selected;
339  ds->GetTree()->GetSelected(currently_selected);
340  std::sort(currently_selected.begin(), currently_selected.end());
341 
342  // Get the selection set that results when we apply the results
343  // from the last query. Note that when we call SetSelection()
344  // parent or child nodes not in the query results may become part of
345  // the selection set.
346  vector<CPhyloTree::TTreeIdx> last_query_results;
347  ds->GetTree()->GetExplicitlySelected(last_query_results);
348 
349  ds->GetTree()->SetSelection(last_query_results);
350  vector<CPhyloTree::TTreeIdx> last_query_selection;
351  ds->GetTree()->GetSelected(last_query_selection);
352  std::sort(last_query_selection.begin(), last_query_selection.end());
353 
354  // reset the current selection
355  ds->GetTree()->ClearSelection();
356  ds->GetTree()->SetSelection(currently_selected);
357 
358  // 'name' is the last query string. If the current selection set does
359  // not match the last query, set name to blank to avoid confusion
360  if (last_query_selection != currently_selected)
361  name = "";
362 
363  m_DS = ds;
364 
365  // Need to collect all colors in clusters and in selection sets that
366  // are not currently active. We will use these colors when we try to
367  // find a new color that is sufficiently different from the current colors.
368  std::vector<CRgbaColor> current_colors;
369 
370  m_AddSelectionBtn->Enable(false);
371 
373  if (currently_selected.size() != 0) {
374  // Don't put in a duplicate name (names are the most recent selection
375  // query, but they do not necessarily match the current selection set -
376  // we give the user a chance here to set the name).
378  m_AddSelectionBtn->Enable(true);
379  m_DeleteBtn->Enable(false); // can't delete a set that has not been added.
380 
381  m_SelectionName->SetValue(name);
382  vector<CPhyloSelectionSet>& sel_sets = m_DS->GetSelectionSets().GetSets();
383 
384  // If it's a duplicate name AND the nodes are the same as the entry already in the
385  // table disable the controls and do not give the opportunity to add a new set.
386  // Otherwise generate a name
387  vector<CPhyloTree::TID> currently_selected;
388  ds->GetTree()->GetSelectedIDs(currently_selected);
389  std::sort(currently_selected.begin(), currently_selected.end());
390  for (size_t i = 0; i < sel_sets.size(); ++i) {
391  if (!sel_sets[i].GetSelected())
392  current_colors.push_back(sel_sets[i].GetColor());
393 
394  if (name == sel_sets[i].GetName()) {
395  vector<CPhyloTree::TID> already_selected = sel_sets[i].GetSelectionSet();
396  std::sort(already_selected.begin(), already_selected.end());
397 
398  if (already_selected == currently_selected) {
399  m_SelectionName->SetValue("");
401  m_AddSelectionBtn->Enable(false);
402  }
403  else {
404  name = "";
405  }
406  break;
407  }
408  }
409  }
410 
411  /// If the user can add this selection, pick a reasonable color for it
412  if (m_AddSelectionBtn->IsEnabled()) {
413  if (name == "") {
414  m_SelectionName->SetValue("<<Enter Selection Name>>");
415  m_SelectionName->SelectAll();
416  }
417 
419 
421  CRgbaColor c = ds->GetModel().GetColorTable()->GetColor(citer->second);
422  current_colors.push_back(c);
423  }
424 
425  CRgbaColor color(102, 153, 204);
426  CRgbaColor white(255, 255, 255, 255);
427 
428  float num_colors = (float)ctcmap.size();
429  float color_step = num_colors ? (180.0f / num_colors) : 0;
430  float rotate_angle = color_step + 100.0f;
431 
432  float max_color_dist = 0.0f;
433  CRgbaColor best_color = color;
434 
435  // Find a color that is as far away visually as possible from the other
436  // selection set colors and colors of normal clusters in the tree.
437  for (size_t i = 0; i < 2 * current_colors.size(); ++i) {
438  // protect from bright colors (almost white) since they are harder to see
439  float c_dist = CRgbaColor::ColorDistance(white, color);
440  while (c_dist < 0.7f) {
441  color.Darken(0.1f);
442  c_dist = CRgbaColor::ColorDistance(white, color);
443  }
444 
445  float min_color_dist = 1e10f;
446 
447  // Find the closest color from among all current selection/cluster colors in use
448  for (size_t j = 0; j < current_colors.size(); ++j) {
449  float dist = CRgbaColor::ColorDistance(current_colors[j], color);
450  if (dist < min_color_dist) {
451  min_color_dist = dist;
452  }
453  }
454 
455  // If the closet color is further away than the closest color
456  // for all previous colors wever tried, save the current color.
457  if (min_color_dist > max_color_dist) {
458  max_color_dist = min_color_dist;
459  best_color = color;
460  }
461 
462  color = CRgbaColor::RotateColor(color, rotate_angle);
463  }
464 
465  m_SelColorPicker->SetColour(wxColour(best_color.GetRedUC(),
466  best_color.GetGreenUC(), best_color.GetBlueUC()));
467  }
468 
470 }
471 
473 {
474  m_SelList->DeleteAllItems();
475  vector<CPhyloSelectionSet>& sel_sets = m_DS->GetSelectionSets().GetSets();
476 
477  for (size_t i=0; i<sel_sets.size(); ++i) {
478  wxListItem item;
479  item.SetId(i);
480  item.SetText( sel_sets[i].GetName() );
481  CRgbaColor c = sel_sets[i].GetColor();
482  item.SetTextColour(wxColour(c.GetRedUC(), c.GetGreenUC(), c.GetBlueUC(), c.GetAlphaUC()));
483  m_SelList->InsertItem( item );
484 
485  // set value in first column
486  wxListItem info;
487  info.SetImage(-1);
488  info.SetId(i);
489  info.SetColumn(1);
490  info.SetText(sel_sets[i].GetName());
491  m_SelList->SetItem(info);
492 
493  info.SetImage(sel_sets[i].GetSelected() ? 1 : 0);
494  //info.SetId(i);
495  info.SetColumn(0);
496  info.SetText("");
497  m_SelList->SetItem(info);
498  }
499 }
500 
501 void CPhyloSaveSelectiondlg::OnOkClick( wxCommandEvent& event )
502 {
503  x_SetClusterIds();
504  event.Skip();
505 }
506 
507 
509 {
510  // single selection list so this should always be true.
511  if (m_SelList->GetSelectedItemCount() == 1) {
512  wxListItem info;
514  // Selecting existing set takes away any chance to add current set
515  m_AddSelectionBtn->Enable(false);
516  if (m_DS->GetSelectionSets().GetSets().size() < 2) {
517  m_ButtonDown->Enable(false);
518  m_ButtonUp->Enable(false);
519  }
520 
521  m_CurrentItem = event.GetIndex();
522  info.SetId(event.GetIndex());
523  info.m_mask = wxLIST_MASK_TEXT;
524  info.m_col = 1;
525  m_SelList->GetItem(info);
526  m_SelectionName->ChangeValue(info.GetText());
527 
528  vector<CPhyloSelectionSet>& sel_sets = m_DS->GetSelectionSets().GetSets();
529  CRgbaColor c = sel_sets[m_CurrentItem].GetColor();
530  m_SelColorPicker->SetColour(wxColour(c.GetRedUC(), c.GetGreenUC(), c.GetBlueUC(), c.GetAlphaUC()));
531  }
532 }
533 
534 void CPhyloSaveSelectiondlg::OnLeftDown( wxMouseEvent& event )
535 {
536  if (event.LeftDown())
537  {
538  int flags;
539  long item = m_SelList->HitTest(event.GetPosition(), flags);
540  if (item > -1 && (flags & wxLIST_HITTEST_ONITEMICON))
541  {
542  bool is_checked;
543  wxListItem info;
544  info.m_mask = wxLIST_MASK_IMAGE ;
545  info.m_itemId = item;
546 
547  if ( m_SelList->GetItem(info))
548  is_checked = (info.m_image == 1);
549  else
550  is_checked = false;
551 
552  m_SelList->SetItemImage(item, (is_checked ? 0 : 1));
553 
554  // Update datasource
555  vector<CPhyloSelectionSet>& sel_sets = m_DS->GetSelectionSets().GetSets();
556  sel_sets[item].SetSelected((is_checked ? 0 : 1));
557 
558  return;
559  }
560  }
561 
562  event.Skip();
563 }
564 
565 
566 void CPhyloSaveSelectiondlg::OnBitmapbuttonUpClick( wxCommandEvent& /*event*/ )
567 {
568  vector<CPhyloSelectionSet>& sel_sets = m_DS->GetSelectionSets().GetSets();
569 
570  if (m_CurrentItem >= 1 && m_CurrentItem < long(sel_sets.size())) {
571  std::iter_swap(sel_sets.begin() + m_CurrentItem, sel_sets.begin() + (m_CurrentItem - 1));
572 
573  // Re-create displayed list
575 
576  // Keep selection on same item
577  m_CurrentItem -= 1;
578  m_SelList->SetItemState(m_CurrentItem, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
579  }
580 }
581 
582 void CPhyloSaveSelectiondlg::OnBitmapbuttonDownClick( wxCommandEvent& /*event*/ )
583 {
584  vector<CPhyloSelectionSet>& sel_sets = m_DS->GetSelectionSets().GetSets();
585 
586  if (m_CurrentItem >= 0 && m_CurrentItem < long(sel_sets.size()-1) ) {
587  std::iter_swap(sel_sets.begin() + m_CurrentItem, sel_sets.begin() + (m_CurrentItem +1));
588 
589  // Re-create displayed list
591 
592  // Keep selection on same item
593  m_CurrentItem += 1;
594  m_SelList->SetItemState(m_CurrentItem, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
595  }
596 }
597 
599 {
600  vector<CPhyloSelectionSet>& sel_sets = m_DS->GetSelectionSets().GetSets();
601 
602  if (m_CurrentItem >= 0 && m_CurrentItem < long(sel_sets.size())) {
603  wxColour c = event.GetColour();
604 
605  sel_sets[m_CurrentItem].SetColor(CRgbaColor(c.Red(), c.Green(), c.Blue(), c.Alpha()));
606 
607  // Update the text color of the item in the list.
608  m_SelList->SetItemTextColour(m_CurrentItem, c);
609  m_SelList->Refresh();
610  }
611 }
612 
613 void CPhyloSaveSelectiondlg::OnSelectionTextUpdated( wxCommandEvent& /*event*/ )
614 {
615  vector<CPhyloSelectionSet>& sel_sets = m_DS->GetSelectionSets().GetSets();
616 
617  if (m_CurrentItem >= 0 && m_CurrentItem < long(sel_sets.size())) {
618  wxListItem info;
619  info.SetImage(-1);
620  info.SetId(m_CurrentItem);
621  info.m_mask = wxLIST_MASK_TEXT;
622  info.SetColumn(1);
623  info.SetText(m_SelectionName->GetValue());
624  m_SelList->SetItem(info);
625 
626  sel_sets[m_CurrentItem].SetName(ToStdString(m_SelectionName->GetValue()));
627  }
628 }
629 
630 
631 void CPhyloSaveSelectiondlg::OnDeleteSelBtnClick( wxCommandEvent& /*event*/ )
632 {
633  vector<CPhyloSelectionSet>& sel_sets = m_DS->GetSelectionSets().GetSets();
634 
635  if (m_CurrentItem >= 0 && m_CurrentItem < long(sel_sets.size())) {
636  sel_sets.erase(sel_sets.begin() + m_CurrentItem);
637  m_CurrentItem -= 1;
638 
640 
641  // Re-create displayed list
643  }
644 }
645 
646 
647 void CPhyloSaveSelectiondlg::OnAddCurrentSelBtnClick( wxCommandEvent& /*event*/ )
648 {
649  vector<CPhyloTree::TID> currently_selected;
650  m_DS->GetTree()->GetSelectedIDs(currently_selected);
651  std::sort(currently_selected.begin(), currently_selected.end());
652  int max_cluster_id = 500;
653 
654  vector<CPhyloSelectionSet>& sel_sets = m_DS->GetSelectionSets().GetSets();
655  if (currently_selected.size() > 0) {
656 
657  m_SelectionName->TransferDataFromWindow();
658 
659  // If it's a duplicate - don't add and give the user a message.
660  for (size_t i=0; i<sel_sets.size(); ++i) {
661  vector<CPhyloTree::TID> selected = sel_sets[i].GetSelectionSet();
662  std::sort(selected.begin(), selected.end());
663  if (selected == currently_selected) {
664  wxMessageBox("Current selection set is identical to existing set:\n" + sel_sets[i].GetName(), "Unable to Add Selection", wxOK | wxICON_WARNING);
665 
666  return;
667  }
668  if (sel_sets[i].GetClusterID() >= max_cluster_id)
669  max_cluster_id = sel_sets[i].GetClusterID()+1;
670  }
671 
672  // Insert new selection set at beginning of list.
673  // the cluster id here will be overridden when we save since we have to keep cluster ids in order.
674  sel_sets.push_back(CPhyloSelectionSet(currently_selected, ToStdString(m_SelectionName->GetValue()), max_cluster_id));
675 
676  // Set color
677  wxColour c = m_SelColorPicker->GetColour();
678  sel_sets[sel_sets.size()-1].SetColor(CRgbaColor(c.Red(), c.Green(), c.Blue(), c.Alpha()));
679  // default to on (new set should be selected)
680  sel_sets[sel_sets.size()-1].SetSelected(true);
681 
683  m_SelectionName->SetValue("");
684  m_SelList->Refresh();
685  }
686 
688  m_AddSelectionBtn->Enable(false);
689 }
690 
691 // Cluster IDs for these selection have to do two things:
692 // 1. avoid overlap with existing IDs (picking a higher number)
693 // 2. be in numerical order with the elements at the beginning of
694 // the list having higher numbers and sets lower in the list
695 // having lower numbers. 'higher priority' sets color to overlay
696 // colors of lower priority sets when we propogate set colors
697 // back toward the root of the tree.
699 {
700 
701  CPhyloTree* t = m_DS->GetTree();
702  int max_cluster_id = -1;
703  size_t i;
704 
705  for (i=0; i<t->GetSize(); ++i) {
706  max_cluster_id = std::max(max_cluster_id, t->GetNodeValue(i).GetClusterID());
707  }
708 
709  // pick cluster id much larger than existing ids:
710  max_cluster_id += 500 + t->GetSelectionSets().GetSets().size();
711 
712  // set ids, first highest then lower.
713  t->GetSelectionSets().RenumberClusterIDs(max_cluster_id);
714 }
715 
716 
718 
void OnSelColorPickerColourPickerChanged(wxColourPickerEvent &event)
wxColourPickerCtrl * m_SelColorPicker
void OnDeleteSelBtnClick(wxCommandEvent &event)
CRef< CPhyloTreeDataSource > m_DS
wxIcon GetIconResource(const wxString &name)
void OnLeftDown(wxMouseEvent &event)
void OnBitmapbuttonDownClick(wxCommandEvent &event)
void OnBitmapbuttonUpClick(wxCommandEvent &event)
bool Create(wxWindow *parent, wxWindowID id=10054, const wxString &caption=_("Save Selection"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
void OnOkClick(wxCommandEvent &event)
wxBitmap GetBitmapResource(const wxString &name)
void OnSelListctrlSelected(wxListEvent &event)
void OnSelectionTextUpdated(wxCommandEvent &event)
void SetSelections(CRef< CPhyloTreeDataSource > ds, string name)
void OnAddCurrentSelBtnClick(wxCommandEvent &event)
vector< CPhyloSelectionSet > & GetSets()
const TClusterToColorMap & GetClusterToColorMap() const
Get map that translates cluster-ids to color indices.
CPhyloTree * GetTree()
std::map< int, size_t > TClusterToColorMap
CPhyloSelectionSetMgr & GetSelectionSets()
CTreeGraphicsModel & GetModel()
Get model for rendering.
Tree subclass also has functions and data needed for rendering and selection.
Definition: phylo_tree.hpp:52
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
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
void GetExplicitlySelected(vector< TTreeIdx > &esel) const
Returns only indices of nodes explicitly selected, not their parents or children, i....
Definition: phylo_tree.cpp:273
void GetSelected(vector< TTreeIdx > &sel) const
Returns indices of selected nodes.
Definition: phylo_tree.cpp:259
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
CRgbaGradColorTable * GetColorTable()
Get color table used a 1D texture map for edges and nodes.
#define _(proto)
Definition: ct_nlmzip_i.h:78
static uch flags
CRgbaColor & GetColor(CSeqFeatData::ESubtype subtype)
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
CRgbaColor & GetColor(size_t i)
static CRgbaColor RotateColor(const CRgbaColor &c, float degrees)
Rotate the hue of the color by degrees.
unsigned char GetRedUC(void) const
Get specific channels in unsigned char values.
Definition: rgba_color.hpp:345
static float ColorDistance(const CRgbaColor &c1, const CRgbaColor &c2)
returns the distance in the RGB color cube between the two colors, scaled to a range [0,...
unsigned char GetGreenUC(void) const
Definition: rgba_color.hpp:351
unsigned char GetAlphaUC(void) const
Definition: rgba_color.hpp:363
static CRgbaColor GetColor(const string &color_type)
return a color based on a string.
unsigned char GetBlueUC(void) const
Definition: rgba_color.hpp:357
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void iter_swap(Iter it1, Iter it2)
Definition: ncbistl.hpp:192
n background color
END_EVENT_TABLE()
int i
static MDB_envinfo info
Definition: mdb_load.c:37
#define wxT(x)
Definition: muParser.cpp:41
constexpr auto sort(_Init &&init)
const struct ncbi::grid::netcache::search::fields::SIZE size
EIPRangeType t
Definition: ncbi_localip.c:101
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
T max(T x_, T y_)
static const char * checked_xpm[]
static const char * down_xpm[]
static const char * up_xpm[]
static const char * unchecked_xpm[]
#define ID_SELECTION
#define ID_SEL_COLOR_PICKER
#define ID_BITMAPBUTTON_DOWN
#define ID_SEL_LISTCTRL
#define ID_BITMAPBUTTON_UP
#define ID_DELETE_SEL_BTN
#define ID_ADD_CURRENT_SEL_BTN
static static static wxID_ANY
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Fri Sep 20 14:57:21 2024 by modify_doxy.py rev. 669887