source: trunk/SL/AP_TREE/AP_TreeShader.hxx

Last change on this file was 17944, checked in by westram, 5 years ago
  • FIXES crash in RELEASE version (when invalid color group occurs in database).
  • add assertions against
    • invalid color_groups and
    • invalid unshaded GCs.
  • ARBDB color-group interface:
    • define number of allowed color groups in ARBDB
    • fix interface types (long→int)
    • report error when color_group passed to GBT_set_color_group is out-of-range.
    • GBT_get_color_group does range check. returns 0 if out-of-range.
File size: 3.1 KB
Line 
1// ============================================================ //
2//                                                              //
3//   File      : AP_TreeShader.hxx                              //
4//   Purpose   : separate GC calculation from AP_TREE library   //
5//                                                              //
6//   Coded by Ralf Westram (coder@reallysoft.de) in June 2016   //
7//   http://www.arb-home.de/                                    //
8//                                                              //
9// ============================================================ //
10
11#ifndef AP_TREESHADER_HXX
12#define AP_TREESHADER_HXX
13
14#ifndef AP_TREECOLORS_HXX
15#include <AP_TreeColors.hxx>
16#endif
17#ifndef AD_COLORSET_H
18#include <ad_colorset.h>
19#endif
20#ifndef ITEM_SHADER_H
21#include <item_shader.h>
22#endif
23
24#define ap_assert(cond) arb_assert(cond)
25
26class GBDATA;
27
28class AP_TreeShader {
29protected:
30    bool colorize_marked;
31    bool colorize_groups;
32    bool shade_species;
33public:
34    AP_TreeShader() :
35        colorize_marked(false),
36        colorize_groups(false),
37        shade_species(false)
38    {}
39    virtual ~AP_TreeShader() {}
40    virtual void init() = 0; // called by AP_tree::set_tree_shader when installed
41
42    bool does_shade() const { return shade_species; }
43
44    virtual void update_settings() = 0;
45    virtual ShadedValue calc_shaded_leaf_GC(GBDATA *gb_node) const = 0;
46    virtual ShadedValue calc_shaded_inner_GC(const ShadedValue& left, float left_ratio, const ShadedValue& right) const = 0;
47    virtual int to_GC(const ShadedValue& val) const = 0;
48
49    int calc_leaf_GC(GBDATA *gb_node, bool is_marked) const {
50        int gc = AWT_GC_NONE_MARKED;
51        if (gb_node) {
52            if (is_marked && colorize_marked) {
53                gc = AWT_GC_ALL_MARKED;
54            }
55            else if (colorize_groups) { // check for user color
56                int color_group = GBT_get_color_group(gb_node);
57                if (color_group) {
58                    ap_assert(color_group>0 && color_group<=AW_COLOR_GROUPS); // color_group has to be in range [1..AW_COLOR_GROUPS]
59                    gc = AWT_GC_FIRST_COLOR_GROUP+color_group-1;
60                }
61            }
62        }
63        else {
64            gc = AWT_GC_ONLY_ZOMBIES;
65        }
66        ap_assert(gc>=0 && gc<AWT_GC_FIRST_RANGE_COLOR); // when violated -> leads to crash in PARSIMONY.
67        return gc;
68    }
69
70    int calc_inner_GC(int left_gc, int right_gc) const {
71        int gc;
72
73        if (left_gc == right_gc) gc = left_gc;
74
75        else if (left_gc == AWT_GC_ALL_MARKED || right_gc == AWT_GC_ALL_MARKED) gc = AWT_GC_SOME_MARKED;
76
77        else if (left_gc  == AWT_GC_ONLY_ZOMBIES) gc = right_gc;
78        else if (right_gc == AWT_GC_ONLY_ZOMBIES) gc = left_gc;
79
80        else if (left_gc == AWT_GC_SOME_MARKED || right_gc == AWT_GC_SOME_MARKED) gc = AWT_GC_SOME_MARKED;
81
82        else {
83            ap_assert(left_gc != AWT_GC_ALL_MARKED  && right_gc != AWT_GC_ALL_MARKED);
84            ap_assert(left_gc != AWT_GC_SOME_MARKED && right_gc != AWT_GC_SOME_MARKED);
85            gc = AWT_GC_NONE_MARKED;
86        }
87
88        return gc;
89    }
90};
91
92
93#else
94#error AP_TreeShader.hxx included twice
95#endif // AP_TREESHADER_HXX
Note: See TracBrowser for help on using the repository browser.