ARB
TreeDisplay.hxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : TreeDisplay.hxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #ifndef TREEDISPLAY_HXX
12 #define TREEDISPLAY_HXX
13 
14 #ifndef AP_TREE_HXX
15 #include <AP_Tree.hxx>
16 #endif
17 #ifndef GROUP_HXX
18 #include <Group.hxx>
19 #endif
20 #ifndef AWT_CANVAS_HXX
21 #include <awt_canvas.hxx>
22 #endif
23 #ifndef _GLIBCXX_VECTOR
24 #include <vector>
25 #endif
26 #ifndef _GLIBCXX_MAP
27 #include <map>
28 #endif
29 
30 
31 #define td_assert(cond) arb_assert(cond)
32 
33 #define AWAR_DTREE_BASELINEWIDTH "awt/dtree/baselinewidth"
34 #define AWAR_DTREE_VERICAL_DIST "awt/dtree/verticaldist"
35 #define AWAR_DTREE_BRANCH_STYLE "awt/dtree/branch_style"
36 #define AWAR_DTREE_ATTACH_SIZE "awt/dtree/attach_size"
37 #define AWAR_DTREE_ATTACH_LEN "awt/dtree/attach_len"
38 #define AWAR_DTREE_ATTACH_GROUP "awt/dtree/attach_group"
39 #define AWAR_DTREE_GROUP_DOWNSCALE "awt/dtree/downscaling"
40 #define AWAR_DTREE_GROUP_SCALE "awt/dtree/groupscaling"
41 #define AWAR_DTREE_AUTO_JUMP "awt/dtree/autojump"
42 #define AWAR_DTREE_AUTO_JUMP_TREE "awt/dtree/autojump_tree"
43 #define AWAR_DTREE_AUTO_UNFOLD "awt/dtree/auto_unfold"
44 #define AWAR_DTREE_SHOW_BRACKETS "awt/dtree/show_brackets"
45 #define AWAR_DTREE_GROUP_STYLE "awt/dtree/groupstyle"
46 #define AWAR_DTREE_GROUP_ORIENT "awt/dtree/grouporient"
47 #define AWAR_DTREE_GREY_LEVEL "awt/dtree/greylevel"
48 #define AWAR_DTREE_GROUPCOUNTMODE "awt/dtree/groupcountmode"
49 #define AWAR_DTREE_GROUPINFOPOS "awt/dtree/groupinfopos"
50 
51 #define AWAR_DTREE_BOOTSTRAP_MIN "awt/dtree/bootstrap/min"
52 #define AWAR_DTREE_BOOTSTRAP_MAX "awt/dtree/bootstrap/max"
53 #define AWAR_DTREE_BOOTSTRAP_SHOW "awt/dtree/bootstrap/show"
54 #define AWAR_DTREE_BOOTSTRAP_STYLE "awt/dtree/bootstrap/style"
55 #define AWAR_DTREE_CIRCLE_SHOW "awt/dtree/bootstrap/circle/show"
56 #define AWAR_DTREE_CIRCLE_FILL "awt/dtree/bootstrap/circle/fill"
57 #define AWAR_DTREE_CIRCLE_ELLIPSE "awt/dtree/bootstrap/circle/ellipse"
58 #define AWAR_DTREE_CIRCLE_ZOOM "awt/dtree/bootstrap/circle/zoom"
59 #define AWAR_DTREE_CIRCLE_LIMIT "awt/dtree/bootstrap/circle/limit"
60 
61 #define AWAR_DTREE_RADIAL_ZOOM_TEXT "awt/dtree/radial/zoomtext"
62 #define AWAR_DTREE_RADIAL_XPAD "awt/dtree/radial/xpadding"
63 
64 #define AWAR_DTREE_DENDRO_ZOOM_TEXT "awt/dtree/dendro/zoomtext"
65 #define AWAR_DTREE_DENDRO_XPAD "awt/dtree/dendro/xpadding"
66 
67 #define AWAR_DTREE_GROUP_MARKED_THRESHOLD "awt/dtree/markers/group_marked_threshold"
68 #define AWAR_DTREE_GROUP_PARTIALLY_MARKED_THRESHOLD "awt/dtree/markers/group_partially_marked_threshold"
69 #define AWAR_DTREE_MARKER_WIDTH "awt/dtree/markers/marker_width"
70 #define AWAR_DTREE_PARTIAL_GREYLEVEL "awt/dtree/markers/partial_greylevel"
71 
72 #define NT_BOX_WIDTH 7 // pixel
73 #define NT_DIAMOND_RADIUS 5
74 #define NT_ROOT_WIDTH 9
75 #define NT_SELECTED_WIDTH 11
76 
77 #define AWT_TREE(ntw) (ntw)->get_graphic_tree()
78 
80  AP_TREE_NORMAL, // normal tree display (dendrogram)
81  AP_TREE_RADIAL, // radial tree display
82  AP_TREE_IRS, // like AP_TREE_NORMAL, with folding line
84  AP_LIST_SIMPLE // simple display only showing name (used at startup to avoid NDS error messages)
85 };
86 
87 enum AP_tree_jump_type { // bit-values
88  AP_JUMP_KEEP_VISIBLE = 1, // automatically make selected node visible (on changes) [VALUE STORED IN AWAR!]
89  AP_JUMP_LOGICAL_UNZOOM = 2, // adapts logical zoom (if target is outside zoomed subtree)
90  AP_JUMP_FORCE_VCENTER = 4, // force vertical centering (even if visible)
91  AP_JUMP_ALLOW_HCENTER = 8, // force horizontal centering (if vertically centered); only works together with AP_JUMP_FORCE_VCENTER
92  AP_JUMP_FORCE_HCENTER = 16, // force horizontal centering
93  AP_JUMP_BE_VERBOOSE = 32, // tell why nothing happened etc.
94  AP_JUMP_AUTO_UNFOLD = 64, // temporarily auto-unfold folded target node
95 
96  // convenience defs:
97  AP_DONT_JUMP = 0, // [VALUE STORED IN AWAR!]
100 
102 };
103 
109 };
110 
112  CL_NODE = 1,
118 };
119 
120 inline bool is_list_style(AP_tree_display_style style) { return style == AP_LIST_NDS || style == AP_LIST_SIMPLE; }
121 inline bool is_tree_style(AP_tree_display_style style) { return !is_list_style(style); }
122 
123 
125 
127  double ascent;
128  double descent;
129  double height;
130  double width;
131 
132  void init(const AW_font_limits& font_limits, double factor) {
133  ascent = font_limits.ascent*factor;
134  descent = font_limits.descent*factor;
135  height = font_limits.get_height()*factor;
136  width = font_limits.width*factor;
137  }
138 };
139 
145 };
146 
148 
150  double y_branch; // ypos of branch to subtree
151  double y_top; // top ypos of whole subtree
152  double y_bot; // bottom ypos of whole subtree
153  double x_right; // rightmost xpos of whole subtree
154 
155  void combine(const DendroSubtreeLimits& other) {
156  y_top = std::min(y_top, other.y_top);
157  y_bot = std::max(y_bot, other.y_bot);
158  x_right = std::max(x_right, other.x_right);
159  }
160 };
161 
166  virtual ~AWT_command_data() {}
167 };
168 
171  EXPAND_MARKED = 1, // do not collapse groups containing marked species
172  COLLAPSE_TERMINAL = 2, // do not collapse groups with subgroups
174  EXPAND_COLOR = 8, // do not collapse groups containing species with color == parameter 'color_group' (or any color if 'color_group' is -1)
175  EXPAND_ZOMBIES = 16, // do not collapse groups containing zombies
176 };
177 
178 class NodeMarkers {
179  // represents markers at a node (species or group)
180 
181  int nodeSize; // number of species in group (or 1)
182  std::vector<int> mark; // how often each marker is set in group
183 public:
184  NodeMarkers() {} // default for cache
185  explicit NodeMarkers(int numMarks)
186  : nodeSize(0),
187  mark(numMarks, 0)
188  {}
189 
190  void incMarker(size_t markerIdx) {
191  td_assert(markerIdx<mark.size());
192  mark[markerIdx]++;
193  }
194  int markerCount(size_t markerIdx) const {
195  td_assert(markerIdx<mark.size());
196  return mark[markerIdx];
197  }
198 
199  void incNodeSize() { nodeSize++; }
200  int getNodeSize() const { return nodeSize; }
201 
202  double getMarkRate(size_t markerIdx) const { return markerCount(markerIdx) / double(getNodeSize()); }
203 
204  void add(const NodeMarkers& other) {
205  size_t size = mark.size();
206  td_assert(size == other.mark.size());
207  for (size_t i = 0; i<size; ++i) {
208  mark[i] += other.mark[i];
209  }
210  nodeSize += other.nodeSize;
211  }
212 };
213 
215  // defines which markers shall be displayed
216 
217  typedef std::map<const AP_tree*,NodeMarkers> GroupMarkerCache;
218 
219  GroupMarkerCache cache;
220  int numMarkers;
221 
222 public:
223  MarkerDisplay(int numMarkers_)
224  : numMarkers(numMarkers_)
225  {
226  td_assert(numMarkers>0);
227  }
228  virtual ~MarkerDisplay() {}
229 
230  virtual const char *get_marker_name(int markerIdx) const = 0;
231  virtual void retrieve_marker_state(const char *speciesName, NodeMarkers& matches) = 0;
232  virtual void handle_click(int markerIdx, AW_MouseButton button, AWT_graphic_exports& exports) = 0;
233 
234  const NodeMarkers *read_cache(const AP_tree *at) const {
235  GroupMarkerCache::const_iterator found = cache.find(at);
236  return found == cache.end() ? NULp : &found->second;
237  }
238  void write_cache(const AP_tree *at, const NodeMarkers& markers) { cache[at] = markers; }
239  void flush_cache() { cache.erase(cache.begin(), cache.end()); }
240 #if defined(ASSERTION_USED)
241  bool cache_is_flushed() const { return cache.empty(); }
242 #endif
243 
244  int size() const { return numMarkers; }
245 };
246 
247 struct GroupInfo {
248  const char *name;
249  const char *count;
250  unsigned name_len;
251  unsigned count_len;
252 };
253 
255  GI_COMBINED, // only sets GroupInfo::name (will contain "name (count)" or only "name" if counters disabled)
256  GI_SEPARATED, // set GroupInfo::name and GroupInfo::count (to "name" and "count")
257  GI_SEPARATED_PARENTIZED, // like GI_SEPARATED, but GroupInfo::count will be "(count)"
258 };
259 
261  GIP_SEPARATED, // name attached, count overlayed (=old hardcoded default for AP_TREE_NORMAL and AP_TREE_IRS)
262  GIP_ATTACHED, // "name (count)" attached "next to" group (=old hardcoded default for AP_TREE_RADIAL)
263  GIP_OVERLAYED, // "name (count)" overlayed with group polygon
264 };
265 
267  GCM_NONE, // do not show group count (=old hardcoded default for AP_TREE_RADIAL)
268  GCM_MEMBERS, // show number of group members (=old hardcoded default for AP_TREE_NORMAL and AP_TREE_IRS)
269  GCM_MARKED, // show number of marked group members (show nothing if none marked)
270  GCM_BOTH, // show "marked/members" (or "members" if none marked)
271  GCM_PERCENT, // show percent of marked group members (show nothing if none marked)
272  GCM_BOTH_PC, // show "percent/members" (or "members" if none marked)
273 };
274 
276  BS_RECTANGULAR, // traditional rectangular branches
277  BS_DIAGONAL, // diagonal branches (directly from fathers to sons attach point)
278 };
279 
283 };
284 
286  GO_TOP, // long clade side at top
287  GO_BOTTOM, // long clade side at bottom
288  GO_INTERIOR, // long clade side towards center of subtree
289  GO_EXTERIOR, // long clade side towards margin of subtree
290 };
291 
292 class AWT_graphic_tree;
293 DECLARE_CBTYPE_FVV_AND_BUILDERS(GraphicTreeCallback, void, AWT_graphic_tree*); // generates makeGraphicTreeCallback
294 
295 class PaintedNode {
296  AW::Position pos;
297  AP_tree *node;
298 public:
299  PaintedNode() : pos(AW::Origin), node(NULp) {}
300  PaintedNode(const PaintedNode& other) : pos(other.pos), node(other.node) {}
301  PaintedNode(const AW::Position& p, AP_tree *n) : pos(p), node(n) {}
304 
305  bool was_displayed() const { return node || are_distinct(AW::Origin, pos); }
306 
307  const AW::Position& get_pos() const { return pos; }
308  AP_tree *get_node() const { return node; } // NULp in list-mode or if got no tree
309 };
310 
315 };
316 
320 
321  int bootstrap_min; // minimum shown bootstrap (lower values are hidden)
322  int bootstrap_max; // maximum shown bootstrap (higher values are hidden)
323 
325 
328  float fill_level;
329  bool elipsoid;
330 
331  bool show_100_if_empty; // automatically add 100% at branches w/o bootstraps (last loaded state contains bootstraps!)
332 
333  float zoom_factor;
334  float max_radius;
335 
337 
338  BootstrapConfig();
339 
340  void display_remark(AW_device *device, const char *remark, const AW::Position& center, double blen, double bdist, const AW::Position& textpos, AW_pos alignment) const;
341  void display_node_remark(AW_device *device, const AP_tree *at, const AW::Position& center, double blen, double bdist, AW::RoughDirection textArea) const;
342 
344  show_100_if_empty = troot->has_bootstrap();
345  }
346 
347  bool shall_show_remark_for(const TreeNode *node) const {
348  return !node->is_leaf() && (show_100_if_empty || node->get_remark_ptr().isSet());
349  }
350 };
351 
352 class AWT_graphic_tree : public AWT_graphic, virtual Noncopyable {
353  char *species_name;
354  Group selected_group;
355 
356  PaintedNode selSpec; // is set while tree display gets refreshed
357  PaintedNode selGroup; // is set while tree display gets refreshed // @@@ no need to store node; store rectangle area instead of position
358 
359  int baselinewidth;
360 
361  BootstrapConfig bconf;
362 
363  int zombies; // # of zombies during last load()
364  int duplicates; // # of duplicates during last load()
365 
366  AP_tree *tree_proto;
367 
368  bool show_brackets;
369 
370  bool link_to_database; // link on load?
371 
372  GroupStyle group_style;
373  GroupOrientation group_orientation;
374 
375  double list_tree_ruler_y;
376  double irs_tree_ruler_scale_factor;
377  double attach_size; // 1.0 = at bigger subtree ; 0.0 = centered; -1.0 = at smaller subtree (trad.)
378  double attach_len; // 1.0 = at longer branch; 0.0 = centered (trad.); -1.0 = at shorter branch
379  double attach_group; // 1.0 = at longer side; 0.5 = centered (trad.); 0.0 = at shorter side (of group polygon)
380 
381  AWT_scaled_font_limits scaled_font;
382 
383  double scaled_branch_distance; // vertical distance between branches (may be extra-scaled in options)
384 
385  AW_grey_level group_greylevel;
386  AW_grey_level marker_greylevel;
387 
388  AW_device *disp_device; // device for recursive functions
389 
390  const AW_bitset line_filter, vert_line_filter, mark_filter, group_bracket_filter;
391  const AW_bitset leaf_text_filter, group_text_filter, other_text_filter;
392  const AW_bitset ruler_filter, root_filter, marker_filter;
393 
394  GroupInfoPosition group_info_pos;
395  GroupCountMode group_count_mode;
396  BranchStyle branch_style;
397 
398  MarkerDisplay *display_markers;
399  struct {
400  double marked;
402  } groupThreshold;
403 
404  AD_map_viewer_cb map_viewer_cb;
405  AWT_command_data *cmd_data;
406 
407  AP_tree_root *tree_static;
408  AP_tree *displayed_root; // root node of shown (sub-)tree; differs from real root if tree is zoomed logically
409 
410  GraphicTreeCallback tree_changed_cb;
411  static GraphicTreeCallback group_changed_cb;
412 
413  class AP_tree_folding *autoUnfolded;
414 
415  AW_root *aw_root;
416  GBDATA *gb_main;
417 
418  AP_tree_display_style tree_style;
419  bool nds_only_marked; // true -> display only marked species (only for list-styles)
420 
421  AW_pos paint_irs_sub_tree(AP_tree *node, AW_pos x_offset); // returns y pos
422  void unload();
423 
424  // functions to compute displayinformation
425 
426  void show_dendrogram(AP_tree *at, AW::Position& pen, DendroSubtreeLimits& limits);
427  void show_radial_tree(AP_tree *at, const AW::Position& base, const AW::Position& tip, const AW::Angle& orientation, const double tree_spread);
428  void show_nds_list(GBDATA * gb_main, bool use_nds);
429  void show_irs_tree(AP_tree *at, double height);
430 
431  void summarizeGroupMarkers(AP_tree *at, NodeMarkers& markers);
432  void drawMarker(const class MarkerPosition& marker, const bool partial, const int midx);
433  void detectAndDrawMarkers(AP_tree *at, double y1, double y2);
434  void drawMarkerNames(AW::Position& Pen);
435 
436  void pixel_box(int gc, const AW::Position& pos, int pixel_width, AW::FillStyle filled);
437 
438  AP_tree *find_selected_node() const;
439  AP_tree *find_selected_group();
440 
441  void toggle_folding_at(AP_tree *at, bool force_jump);
442 
443  const GroupInfo& get_group_info(AP_tree *at, GroupInfoMode mode, bool swap = false) const;
444 
445  bool handle_cursor(AW_key_code kcode, AW_key_mod mod);
446  void handle_key(AW_device *device, AWT_graphic_event& event);
447 
448  GB_ERROR create_group(AP_tree * at) __ATTR__USERESULT;
449 
450 protected:
451  group_scaling groupScale; // scaling for folded groups
452 
453  void store_command_data(AWT_command_data *new_cmd_data) {
454  delete cmd_data;
455  cmd_data = new_cmd_data;
456  }
457  AWT_command_data *get_command_data() { return cmd_data; }
458 
459 public:
460  AWT_graphic_tree(AW_root *aw_root, GBDATA *gb_main, AD_map_viewer_cb map_viewer_cb);
462 
463  void filled_box(int gc, const AW::Position& pos, int pixel_width) { pixel_box(gc, pos, pixel_width, AW::FillStyle::SOLID); }
464  void empty_box(int gc, const AW::Position& pos, int pixel_width) { pixel_box(gc, pos, pixel_width, AW::FillStyle::EMPTY); }
465  void diamond(int gc, const AW::Position& pos, int pixel_radius);
466 
467  const char *ruler_awar(const char *name);
468 
470  disp_device->set_line_attributes(at->gr.gc, at->get_linewidth()+baselinewidth, AW_SOLID);
471  }
472 
473  virtual void read_tree_settings();
475  AP_tree *root = get_root_node();
476  if (root) {
478  root->compute_tree();
479  }
480  }
482 
483  int draw_branch_line(int gc, const AW::Position& root, const AW::Position& leaf, AW_bitset filter) {
484  const AW_click_cd *old = disp_device->get_click_cd();
485  td_assert(old && old->get_cd1() && old->get_cd2() == CL_NODE); // cd1 should be the node
486 
487  AW_click_cd branch(disp_device, old->get_cd1(), CL_BRANCH);
488  return disp_device->line(gc, root, leaf, filter);
489  }
490 
492 
493  virtual AP_tree_root *create_tree_root(AliView *aliview, AP_sequence *seq_prototype, bool insert_delete_cbs);
494 
495  AW_root *get_root() const { return aw_root; }
496  GBDATA *get_gbmain() const { return gb_main; }
497 
498  AP_tree_root *get_tree_root() { return tree_static; }
499 
500  AP_tree *get_root_node() { return tree_static ? tree_static->get_root_node() : NULp; }
501  const AP_tree *get_root_node() const { return const_cast<AWT_graphic_tree*>(this)->get_root_node(); }
502 
503  AP_tree *get_logical_root() { return displayed_root; }
504  const AP_tree *get_logical_root() const { return displayed_root; }
505 
506  bool is_logically_zoomed() { return displayed_root != get_root_node(); }
508  displayed_root = node;
509  tree_changed_cb(this);
510  }
511 
512  void init(AliView *aliview, AP_sequence *seq_prototype, bool link_to_database_, bool insert_delete_cbs);
514 
515  void show(AW_device *device) OVERRIDE;
516  const AW::Position& get_cursor() const { return selSpec.get_pos(); }
517  const AW::Position& get_group_cursor() const { return selGroup.get_pos(); }
518 
519  void handle_command(AW_device *device, AWT_graphic_event& event) OVERRIDE;
520 
521  void mark_species_in_tree(AP_tree *at, int mark);
522  void mark_species_in_tree_that(AP_tree *at, int mark, bool (*condition)(GBDATA*, void*), void *cd);
523 
524  void mark_species_in_rest_of_tree(AP_tree *at, int mark);
525  void mark_species_in_rest_of_tree_that(AP_tree *at, int mark, bool (*condition)(GBDATA*, void*), void *cd);
526 
527  bool tree_has_marks(AP_tree *at);
528  bool rest_tree_has_marks(AP_tree *at);
529 
530  void detect_group_state(AP_tree *at, AWT_graphic_tree_group_state *state, AP_tree *skip_this_son);
531 
532  bool group_tree(AP_tree *at, CollapseMode mode, int color_group);
533  void group_rest_tree(AP_tree *at, CollapseMode mode, int color_group);
534  void reorderTree(TreeOrder mode);
535  void toggle_group(AP_tree * at);
536 
537  GB_ERROR load_from_DB(GBDATA *gb_main, const char *name) FINAL_OVERRIDE __ATTR__USERESULT;
538  GB_ERROR save_to_DB(GBDATA *gb_main, const char *name) FINAL_OVERRIDE __ATTR__USERESULT;
541 
542  void fast_sync_changed_folding(AP_tree *parent_of_all_changes); // use carefully
543 
545  AP_tree_display_style get_tree_style() const { return tree_style; }
546 
547  double get_irs_tree_ruler_scale_factor() const { return irs_tree_ruler_scale_factor; }
548  void show_ruler(AW_device *device, int gc);
549  void get_zombies_and_duplicates(int& zomb, int& dups) const { zomb = zombies; dups = duplicates; }
550 
552  delete display_markers;
553  display_markers = NULp;
554  }
555  void set_marker_display(MarkerDisplay *display) { // takes ownership of 'display'
557  display_markers = display;
558  }
559  MarkerDisplay *get_marker_display() { return display_markers; }
560 
561  void install_tree_changed_callback(const GraphicTreeCallback& gtcb);
563 
564  static void install_group_changed_callback(const GraphicTreeCallback& gccb) {
565  group_changed_cb = gccb;
566  }
567 
568  void auto_unfold(AP_tree *want_visible);
569  void forget_auto_unfolded();
570 
571 private:
572  void select_group(const Group& group) {
573  if (selected_group != group) {
574  selected_group = group;
575  group_changed_cb(this);
576  }
577  }
578 public:
579  void select_group(AP_tree *node) { // select + locate
580  td_assert(node && node->is_clade());
581  select_group(Group(node));
582  }
583  void select_group(GBDATA *gb_group) { // unlocated select (or deselect if called with NULp)
584  select_group(gb_group ? Group(gb_group) : Group());
585  }
586  void deselect_group() {
587  select_group(Group());
588  }
589  const Group& get_selected_group() const {
590  return selected_group;
591  }
593  AP_tree *node = NULp;
594  if (selected_group.is_valid()) {
595  if (selected_group.locate(in_subtree)) {
596  node = selected_group.get_node();
597  }
598  }
599  return node;
600  }
602  // has to be called whenever the keeled-state of a group may change
603  selected_group.dislocate();
604  }
605 
606 #if defined(UNIT_TESTS) // UT_DIFF
607  friend class fake_AWT_graphic_tree;
608 #endif
610 };
613 
626  AP_tree *tree_node;
627  GBDATA *gb_species;
628 
629  bool ruler;
630  bool branch;
631  int markerflag; // = markerindex + 1
632 
633  const AW_clicked_element *elem;
634 
635  void init() {
636  tree_node = NULp;
637  gb_species = NULp;
638  ruler = false;
639  branch = false;
640  markerflag = 0;
641  }
642 
643  void identify(AWT_graphic_tree *agt) {
644  init();
645  if (elem && elem->does_exist()) {
646  ClickedType what = (ClickedType)elem->cd2();
647 
648  switch (what) {
649  case CL_SPECIES:
650  gb_species = (GBDATA*)elem->cd1();
651  td_assert(gb_species);
652  break;
653 
654  case CL_RULER:
655  ruler = !elem->cd1();
656  break;
657 
658  case CL_FLAG:
659  markerflag = elem->cd1()+1;
660  break;
661 
662  case CL_BRANCH:
663  branch = true;
664  // fall-through!
665  case CL_NODE:
666  tree_node = (AP_tree*)elem->cd1();
667  break;
668 
669  case CL_ROOTNODE:
670  if (agt) tree_node = agt->get_root_node();
671  break;
672 
673 #if defined(DEBUG)
674  default:
675  td_assert(0); // unknown element type
676 #endif
677  }
678  }
679  else { // use whole tree if mouse does not point to a subtree
680  tree_node = agt ? agt->get_root_node() : NULp;
681  }
682  td_assert(implicated(branch, tree_node));
683  }
684 
685 public:
686 
687  ClickedTarget(AWT_graphic_tree *agt, const AW_clicked_element *clicked) : elem(clicked) {
688  // uses root of tree as target, when a position outside of the tree is selected
689  // (e.g. used for key-commands)
690  identify(agt);
691  }
692  ClickedTarget(const AW_clicked_element *clicked) : elem(clicked) {
693  // accept only normal branches as targets
694  identify(NULp);
695  }
696 
697  const AW_clicked_element *element() const { return elem; }
698  AP_tree *node() const { return tree_node; }
699  GBDATA *species() const { return gb_species; }
700  int get_markerindex() const { return markerflag-1; }
701 
702  bool is_text() const { return elem && elem->is_text(); }
703  bool is_line() const { return elem && elem->is_line(); }
704  bool is_branch() const { return branch; }
705  bool is_ruler() const { return ruler; }
706  bool is_marker() const { return markerflag; }
707 
708  double get_rel_attach() const {
709  // return [0..1] according to exact position where element is dropped
710  if (is_line() && (is_branch() || ruler)) return elem->get_rel_pos();
711  return 0.5; // act like "drop on branch-center"
712  }
713 };
714 
715 class TREE_canvas : public AWT_canvas { // derived from Noncopyable
716  AW_awar *awar_tree; // awar containing name of displayed tree
717  int index; // unique index [0..MAX_NT_WINDOWS-1]
718 
719  static int count;
720 
721 public:
722  TREE_canvas(GBDATA *gb_main_, AW_window *aww_, const char *gc_base_name_, AWT_graphic *gfx_, AW_awar *awar_tree_) :
723  AWT_canvas(gb_main_, aww_, gc_base_name_, gfx_),
724  awar_tree(awar_tree_),
725  index(count++)
726  {}
727 
730 
732  user_data = cd;
733  }
734 
736  AW_awar *get_awar_tree() const { return awar_tree; }
737  int get_index() const { return index; }
738 };
739 
740 
741 void TREE_create_awars(AW_root *aw_root, AW_default db);
745 
746 AWT_graphic_tree *NT_generate_tree(AW_root *root, GBDATA *gb_main, AD_map_viewer_cb map_viewer_cb);
747 
748 #else
749 #error TreeDisplay.hxx included twice
750 #endif // TREEDISPLAY_HXX
AP_tree * get_node() const
Definition: Group.hxx:54
void reorderTree(TreeOrder mode)
bool does_exist() const
AWT_graphic_tree * get_graphic_tree() const
void combine(const DendroSubtreeLimits &other)
const char * GB_ERROR
Definition: arb_core.h:25
void set_marker_display(MarkerDisplay *display)
AWT_graphic_tree * NT_generate_tree(AW_root *root, GBDATA *gb_main, AD_map_viewer_cb map_viewer_cb)
long AW_bitset
Definition: aw_base.hxx:44
int getNodeSize() const
int get_markerindex() const
GB_TYPES type
AP_tree * node() const
AP_tree * get_logical_root()
bool warn_inappropriate_mode(AWT_COMMAND_MODE mode)
MarkerDisplay(int numMarkers_)
AP_tree_root * get_tree_root()
virtual AP_tree_root * create_tree_root(AliView *aliview, AP_sequence *seq_prototype, bool insert_delete_cbs)
void mark_species_in_rest_of_tree_that(AP_tree *at, int mark, bool(*condition)(GBDATA *, void *), void *cd)
AWT_COMMAND_MODE
Definition: awt_canvas.hxx:25
GB_ERROR load_from_DB(GBDATA *gb_main, const char *name) FINAL_OVERRIDE __ATTR__USERESULT
short get_height() const
#define implicated(hypothesis, conclusion)
Definition: arb_assert.h:289
AP_tree_jump_reason
void group_rest_tree(AP_tree *at, CollapseMode mode, int color_group)
void set_logical_root_to(AP_tree *node)
void check_for_DB_update(GBDATA *gb_main) FINAL_OVERRIDE
void set_line_attributes(int gc, short width, AW_linestyle style)
Definition: AW_device.cxx:465
AP_tree_jump_type
Definition: TreeDisplay.hxx:87
const AW_bitset circle_filter
void detect_group_state(AP_tree *at, AWT_graphic_tree_group_state *state, AP_tree *skip_this_son)
const char * name
void store_command_data(AWT_command_data *new_cmd_data)
ClickedType
double get_irs_tree_ruler_scale_factor() const
void select_group(AP_tree *node)
bool is_clade() const
Definition: TreeNode.h:439
GB_ERROR save_to_DB(GBDATA *gb_main, const char *name) FINAL_OVERRIDE __ATTR__USERESULT
DECLARE_ASSIGNMENT_OPERATOR(PaintedNode)
void notify_synchronized(GBDATA *gb_main) FINAL_OVERRIDE
AP_tree * get_node() const
AD_MAP_VIEWER_TYPE
virtual ~AWT_command_data()
void forget_auto_unfolded()
AP_tree_members gr
Definition: AP_Tree.hxx:214
void dislocate_selected_group()
bool tree_has_marks(AP_tree *at)
GBDATA * get_gbmain() const
bool is_logically_zoomed()
double getMarkRate(size_t markerIdx) const
const AP_tree * get_root_node() const
const char * count
void add(const NodeMarkers &other)
bool is_valid() const
Definition: Group.hxx:48
ClickedTarget(AWT_graphic_tree *agt, const AW_clicked_element *clicked)
DECLARE_CBTYPE_FVV_AND_BUILDERS(GraphicTreeCallback, void, AWT_graphic_tree *)
void(* screen_update_callback)(AWT_canvas *, AW_CL cd)
Definition: awt_canvas.hxx:296
AW_gc_manager * init_devices(AW_window *, AW_device *, AWT_canvas *ntw) OVERRIDE
Definition: TreeDisplay.cxx:71
void dislocate() const
Definition: Group.hxx:64
GroupOrientation
#define cb(action)
void incMarker(size_t markerIdx)
#define DOWNCAST(totype, expr)
Definition: downcast.h:141
#define FINAL_OVERRIDE
Definition: cxxforward.h:95
BootstrapStyle style
RoughDirection
void diamond(int gc, const AW::Position &pos, int pixel_radius)
void flush_cache()
void(* AD_map_viewer_cb)(GBDATA *gbd, AD_MAP_VIEWER_TYPE type)
bool is_line() const
const AW::Position & get_pos() const
const NodeMarkers * read_cache(const AP_tree *at) const
void set_tree_style(AP_tree_display_style style, AWT_canvas *ntw)
void auto_unfold(AP_tree *want_visible)
MARK_NONFINAL_FUNCTION(AWT_graphic_tree, AP_tree_root *, create_tree_root,(AliView *, AP_sequence *, bool), NULp)
NodeMarkers(int numMarks)
bool is_marker() const
static void install_group_changed_callback(const GraphicTreeCallback &gccb)
double AW_pos
Definition: aw_base.hxx:29
virtual void read_tree_settings()
void compute_tree() FINAL_OVERRIDE
Definition: AP_Tree.cxx:876
virtual const char * get_marker_name(int markerIdx) const =0
PaintedNode(const AW::Position &p, AP_tree *n)
int get_linewidth() const
Definition: AP_Tree.hxx:326
TREE_canvas(GBDATA *gb_main_, AW_window *aww_, const char *gc_base_name_, AWT_graphic *gfx_, AW_awar *awar_tree_)
AW_MouseButton
Definition: aw_window.hxx:70
AW_root * get_root() const
unsigned name_len
void mark_species_in_tree_that(AP_tree *at, int mark, bool(*condition)(GBDATA *, void *), void *cd)
void get_zombies_and_duplicates(int &zomb, int &dups) const
void hide_marker_display()
MARK_NONFINAL_CLASS(AWT_graphic_tree)
void incNodeSize()
virtual ~MarkerDisplay()
static int group[MAXN+1]
Definition: ClustalV.cxx:65
MarkerDisplay * get_marker_display()
AW_CL cd1() const
AW_CL get_cd1() const
Definition: aw_device.hxx:347
bool are_distinct(const Position &p1, const Position &p2)
bool line(int gc, const AW::LineVector &Line, AW_bitset filteri=AW_ALL_DEVICES_SCALED)
Definition: aw_device.hxx:430
AW_CL get_cd2() const
Definition: aw_device.hxx:348
bool rest_tree_has_marks(AP_tree *at)
void at_screen_update_call(screen_update_callback cb, AW_CL cd)
CONSTEXPR_INLINE_Cxx14 void swap(unsigned char &c1, unsigned char &c2)
Definition: ad_io_inline.h:19
screen_update_callback announce_update_cb
Definition: awt_canvas.hxx:304
double scaled_remark_ascend
group_scaling groupScale
CollapseMode
void handle_command(AW_device *device, AWT_graphic_event &event) OVERRIDE
~AWT_graphic_tree() OVERRIDE
AWT_command_data * get_command_data()
AW_window * TREE_create_settings_window(AW_root *aw_root)
int size() const
AP_tree_display_style get_tree_style() const
void uninstall_tree_changed_callback()
void fast_sync_changed_folding(AP_tree *parent_of_all_changes)
AW_window * TREE_create_marker_settings_window(AW_root *root)
virtual void retrieve_marker_state(const char *speciesName, NodeMarkers &matches)=0
GBDATA * species() const
void toggle_group(AP_tree *at)
float AW_grey_level
Definition: aw_base.hxx:46
void show_ruler(AW_device *device, int gc)
ClickedTarget(const AW_clicked_element *clicked)
int draw_branch_line(int gc, const AW::Position &root, const AW::Position &leaf, AW_bitset filter)
bool is_ruler() const
bool is_list_style(AP_tree_display_style style)
int get_index() const
bool group_tree(AP_tree *at, CollapseMode mode, int color_group)
#define td_assert(cond)
Definition: TreeDisplay.hxx:31
AW_CL user_data
Definition: awt_canvas.hxx:305
void write_cache(const AP_tree *at, const NodeMarkers &markers)
void display_node_remark(AW_device *device, const AP_tree *at, const AW::Position &center, double blen, double bdist, AW::RoughDirection textArea) const
bool has_bootstrap() const
Definition: TreeNode.h:101
AWT_graphic * gfx
Definition: awt_canvas.hxx:339
const AW::Position & get_group_cursor() const
const Group & get_selected_group() const
bool locate(AP_tree *subtree) const
Definition: Group.cxx:29
bool is_leaf() const
Definition: TreeNode.h:171
BootstrapStyle
AW_CL cd2() const
void display_remark(AW_device *device, const char *remark, const AW::Position &center, double blen, double bdist, const AW::Position &textpos, AW_pos alignment) const
long AW_CL
Definition: cb.h:21
int markerCount(size_t markerIdx) const
double get_rel_pos() const
BranchStyle
AW_key_code
Definition: aw_keysym.hxx:14
void TREE_create_awars(AW_root *aw_root, AW_default db)
GroupInfoMode
#define OVERRIDE
Definition: cxxforward.h:93
void select_group(GBDATA *gb_group)
GroupStyle
unsigned count_len
AP_tree_display_style
Definition: TreeDisplay.hxx:79
#define __ATTR__USERESULT
Definition: attributes.h:58
void TREE_install_update_callbacks(TREE_canvas *ntw)
double get_rel_attach() const
void filled_box(int gc, const AW::Position &pos, int pixel_width)
AP_tree * locate_selected_group(AP_tree *in_subtree)
bool is_text() const
const AW::Position & get_cursor() const
void set_line_attributes_for(AP_tree *at) const
AP_tree * get_root_node()
static void tree_changed_cb(AW_root *, BranchWindow *bw)
TreeOrder
Definition: TreeNode.h:35
const AW_bitset text_filter
PaintedNode(const PaintedNode &other)
const char * ruler_awar(const char *name)
bool was_displayed() const
#define NULp
Definition: cxxforward.h:97
AWT_graphic_tree(AW_root *aw_root, GBDATA *gb_main, AD_map_viewer_cb map_viewer_cb)
AW_key_mod
Definition: aw_keysym.hxx:46
GroupCountMode
GroupInfoPosition
virtual void handle_click(int markerIdx, AW_MouseButton button, AWT_graphic_exports &exports)=0
bool is_tree_style(AP_tree_display_style style)
void init(AliView *aliview, AP_sequence *seq_prototype, bool link_to_database_, bool insert_delete_cbs)
bool is_branch() const
void install_tree_changed_callback(const GraphicTreeCallback &gtcb)
bool shall_show_remark_for(const TreeNode *node) const
void update_empty_branch_behavior(const TreeRoot *troot)
GBDATA * gb_main
Definition: adname.cxx:33
const AP_tree * get_logical_root() const
void empty_box(int gc, const AW::Position &pos, int pixel_width)
void update_structure() FINAL_OVERRIDE
void mark_species_in_tree(AP_tree *at, int mark)
const SmartCharPtr & get_remark_ptr() const
Definition: TreeNode.h:270
#define min(a, b)
Definition: f2c.h:153
PREPARE_MARK_NONFINAL_CLASS(AWT_graphic_tree)
const Position Origin
uint32_t gc
Definition: AP_Tree.hxx:152
const AW_clicked_element * element() const
AW_awar * get_awar_tree() const
bool cache_is_flushed() const
const AW_click_cd * get_click_cd() const
Definition: aw_device.hxx:382
void show(AW_device *device) OVERRIDE
Definition: Group.hxx:20
void init(const AW_font_limits &font_limits, double factor)
void mark_species_in_rest_of_tree(AP_tree *at, int mark)
Definition: cache.h:31
void apply_zoom_settings_for_treetype(AWT_canvas *ntw)
#define max(a, b)
Definition: f2c.h:154