source: branches/nameserver/SL/TREEDISP/TreeDisplay.hxx

Last change on this file was 18125, checked in by westram, 5 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.2 KB
Line 
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
79enum AP_tree_display_style {
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
83    AP_LIST_NDS,
84    AP_LIST_SIMPLE // simple display only showing name (used at startup to avoid NDS error messages)
85};
86
87enum 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!]
98    AP_JUMP_SMART_CENTER = AP_JUMP_FORCE_VCENTER|AP_JUMP_ALLOW_HCENTER, // [VALUE STORED IN AWAR!]
99    AP_JUMP_FORCE_CENTER = AP_JUMP_FORCE_VCENTER|AP_JUMP_FORCE_HCENTER, // [VALUE STORED IN AWAR!]
100
101    AP_JUMP_BY_BUTTON = AP_JUMP_SMART_CENTER|AP_JUMP_LOGICAL_UNZOOM|AP_JUMP_AUTO_UNFOLD|AP_JUMP_BE_VERBOOSE,
102};
103
104enum AP_tree_jump_reason {
105    AP_JUMP_REASON_TREE,
106    AP_JUMP_REASON_STYLE,
107    AP_JUMP_REASON_SPECIES,
108    AP_JUMP_REASON_GROUP,
109};
110
111enum ClickedType {
112    CL_NODE = 1,
113    CL_SPECIES,
114    CL_RULER,
115    CL_FLAG,
116    CL_BRANCH,
117    CL_ROOTNODE,
118};
119
120inline bool is_list_style(AP_tree_display_style style) { return style == AP_LIST_NDS || style == AP_LIST_SIMPLE; }
121inline bool is_tree_style(AP_tree_display_style style) { return !is_list_style(style); }
122
123
124class AWT_graphic_tree_group_state;
125
126struct AWT_scaled_font_limits {
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
140enum AD_MAP_VIEWER_TYPE {
141    ADMVT_NONE = 0,
142    ADMVT_INFO,
143    ADMVT_WWW,
144    ADMVT_SELECT
145};
146
147typedef void (*AD_map_viewer_cb)(GBDATA *gbd, AD_MAP_VIEWER_TYPE type);
148
149struct DendroSubtreeLimits {
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
162struct AWT_command_data {
163    /*! any kind of data which has to be stored between different events (e.g. to support drag&drop)
164     * Purpose of this class is to allow to delete such data w/o knowing anything else.
165     */
166    virtual ~AWT_command_data() {}
167};
168
169enum CollapseMode {
170    COLLAPSE_ALL      = 0,
171    EXPAND_MARKED     = 1,  // do not collapse groups containing marked species
172    COLLAPSE_TERMINAL = 2,  // do not collapse groups with subgroups
173    EXPAND_ALL        = 4,
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
178class 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
183public:
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
214class MarkerDisplay {
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
222public:
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
247struct GroupInfo {
248    const char *name;
249    const char *count;
250    unsigned    name_len;
251    unsigned    count_len;
252};
253
254enum GroupInfoMode {
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
260enum GroupInfoPosition {
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
266enum GroupCountMode {
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
275enum BranchStyle {
276    BS_RECTANGULAR, // traditional rectangular branches
277    BS_DIAGONAL,    // diagonal branches (directly from fathers to sons attach point)
278};
279
280enum GroupStyle {
281    GS_TRAPEZE,
282    GS_TRIANGLE,
283};
284
285enum GroupOrientation {
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
292class AWT_graphic_tree;
293DECLARE_CBTYPE_FVV_AND_BUILDERS(GraphicTreeCallback, void, AWT_graphic_tree*); // generates makeGraphicTreeCallback
294
295class PaintedNode {
296    AW::Position  pos;
297    AP_tree      *node;
298public:
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) {}
302    DECLARE_ASSIGNMENT_OPERATOR(PaintedNode);
303    ~PaintedNode() {}
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
311enum BootstrapStyle {
312    BS_PERCENT,
313    BS_PERCENT_NOSIGN,
314    BS_FLOAT,
315};
316
317struct BootstrapConfig {
318    const AW_bitset circle_filter;
319    const AW_bitset text_filter;
320
321    int bootstrap_min; // minimum shown bootstrap (lower values are hidden)
322    int bootstrap_max; // maximum shown bootstrap (higher values are hidden)
323
324    BootstrapStyle style;
325
326    bool  show_boots;
327    bool  show_circle;
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
336    double scaled_remark_ascend;
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
343    void update_empty_branch_behavior(const TreeRoot *troot)  {
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
352class 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;
401        double partiallyMarked;
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
450protected:
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
459public:
460    AWT_graphic_tree(AW_root *aw_root, GBDATA *gb_main, AD_map_viewer_cb map_viewer_cb);
461    ~AWT_graphic_tree() OVERRIDE;
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
469    void set_line_attributes_for(AP_tree *at) const {
470        disp_device->set_line_attributes(at->gr.gc, at->get_linewidth()+baselinewidth, AW_SOLID);
471    }
472
473    virtual void read_tree_settings();
474    void update_structure() FINAL_OVERRIDE {
475        AP_tree *root = get_root_node();
476        if (root) {
477            forget_auto_unfolded();
478            root->compute_tree();
479        }
480    }
481    void apply_zoom_settings_for_treetype(AWT_canvas *ntw);
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
491    bool warn_inappropriate_mode(AWT_COMMAND_MODE mode);
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(); }
507    void set_logical_root_to(AP_tree *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);
513    AW_gc_manager *init_devices(AW_window *, AW_device *, AWT_canvas *ntw) OVERRIDE;
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;
539    void     check_for_DB_update(GBDATA *gb_main) FINAL_OVERRIDE;
540    void     notify_synchronized(GBDATA *gb_main) FINAL_OVERRIDE;
541
542    void fast_sync_changed_folding(AP_tree *parent_of_all_changes); // use carefully
543
544    void set_tree_style(AP_tree_display_style style, AWT_canvas *ntw);
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
551    void hide_marker_display() {
552        delete display_markers;
553        display_markers = NULp;
554    }
555    void set_marker_display(MarkerDisplay *display) { // takes ownership of 'display'
556        hide_marker_display();
557        display_markers = display;
558    }
559    MarkerDisplay *get_marker_display() { return display_markers; }
560
561    void install_tree_changed_callback(const GraphicTreeCallback& gtcb);
562    void uninstall_tree_changed_callback();
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
571private:
572    void select_group(const Group& group) {
573        if (selected_group != group) {
574            selected_group = group;
575            group_changed_cb(this);
576        }
577    }
578public:
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    }
592    AP_tree *locate_selected_group(AP_tree *in_subtree) {
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    }
601    void dislocate_selected_group() {
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
609    PREPARE_MARK_NONFINAL_CLASS(AWT_graphic_tree);
610};
611MARK_NONFINAL_CLASS(AWT_graphic_tree);
612MARK_NONFINAL_FUNCTION(AWT_graphic_tree,AP_tree_root*,create_tree_root,(AliView*,AP_sequence*,bool),NULp);
613
614class ClickedTarget {
615    /*! Represents any target corresponding to some (mouse-)position in the tree display.
616     *
617     * The target is e.g. used as target for keystrokes or mouse clicks.
618     *
619     * For AP_LIST_NDS, this only represents the species (w/o any tree information).
620     * For other tree display modes, this represents a specific tree node.
621     *
622     * The space outside the tree does represent the whole tree (aka the root-node).
623     * (the necessary distance to the tree-structure/-text is defined by AWT_CATCH)
624     */
625
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
685public:
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
715class 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
721public:
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
728    void at_screen_update_call(screen_update_callback cb, AW_CL cd) {
729        td_assert(!announce_update_cb || (announce_update_cb == cb && user_data == cd));
730
731        announce_update_cb = cb;
732        user_data          = cd;
733    }
734
735    AWT_graphic_tree *get_graphic_tree() const { return DOWNCAST(AWT_graphic_tree*, gfx); }
736    AW_awar *get_awar_tree() const { return awar_tree; }
737    int get_index() const { return index; }
738};
739
740
741void       TREE_create_awars(AW_root *aw_root, AW_default db);
742void       TREE_install_update_callbacks(TREE_canvas *ntw);
743AW_window *TREE_create_settings_window(AW_root *aw_root);
744AW_window *TREE_create_marker_settings_window(AW_root *root);
745
746AWT_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
Note: See TracBrowser for help on using the repository browser.