]>
Commit | Line | Data |
---|---|---|
18f7104f JH |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
efdec55a | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
18f7104f JH |
18 | */ |
19 | ||
68b21a71 JH |
20 | #include <cassert> |
21 | ||
af503b10 JH |
22 | #include "tracetreeitem.hpp" |
23 | #include "tracetreeitemowner.hpp" | |
6046c19d | 24 | #include "trace.hpp" |
68b21a71 | 25 | |
6046c19d | 26 | using std::dynamic_pointer_cast; |
6f925ba9 | 27 | using std::find; |
a5d93c27 | 28 | using std::make_pair; |
6f925ba9 | 29 | using std::max; |
a5d93c27 JH |
30 | using std::min; |
31 | using std::pair; | |
873cbed0 | 32 | using std::set; |
68b21a71 | 33 | using std::shared_ptr; |
c373f828 | 34 | using std::static_pointer_cast; |
68b21a71 JH |
35 | using std::vector; |
36 | ||
37 | namespace pv { | |
f4e57597 SA |
38 | namespace views { |
39 | namespace TraceView { | |
68b21a71 | 40 | |
a8743cd9 | 41 | const ViewItemOwner::item_list& TraceTreeItemOwner::child_items() const |
68b21a71 | 42 | { |
8dbbc7f0 | 43 | return items_; |
68b21a71 JH |
44 | } |
45 | ||
6f925ba9 | 46 | vector< shared_ptr<TraceTreeItem> > |
c373f828 | 47 | TraceTreeItemOwner::trace_tree_child_items() const |
68b21a71 | 48 | { |
c373f828 | 49 | vector< shared_ptr<TraceTreeItem> > items; |
8dbbc7f0 | 50 | for (auto &i : items_) { |
c373f828 JH |
51 | assert(dynamic_pointer_cast<TraceTreeItem>(i)); |
52 | const shared_ptr<TraceTreeItem> t( | |
53 | static_pointer_cast<TraceTreeItem>(i)); | |
54 | items.push_back(t); | |
55 | } | |
56 | ||
57 | return items; | |
58 | } | |
59 | ||
60 | void TraceTreeItemOwner::clear_child_items() | |
61 | { | |
62 | for (auto &t : trace_tree_child_items()) { | |
63 | assert(t->owner() == this); | |
64 | t->set_owner(nullptr); | |
68b21a71 | 65 | } |
8dbbc7f0 | 66 | items_.clear(); |
68b21a71 JH |
67 | } |
68 | ||
6f925ba9 | 69 | void TraceTreeItemOwner::add_child_item(shared_ptr<TraceTreeItem> item) |
68b21a71 JH |
70 | { |
71 | assert(!item->owner()); | |
72 | item->set_owner(this); | |
8dbbc7f0 | 73 | items_.push_back(item); |
32218d3e JH |
74 | |
75 | extents_changed(true, true); | |
68b21a71 JH |
76 | } |
77 | ||
6f925ba9 | 78 | void TraceTreeItemOwner::remove_child_item(shared_ptr<TraceTreeItem> item) |
68b21a71 JH |
79 | { |
80 | assert(item->owner() == this); | |
81 | item->set_owner(nullptr); | |
6f925ba9 | 82 | auto iter = find(items_.begin(), items_.end(), item); |
8dbbc7f0 JH |
83 | assert(iter != items_.end()); |
84 | items_.erase(iter); | |
32218d3e JH |
85 | |
86 | extents_changed(true, true); | |
68b21a71 JH |
87 | } |
88 | ||
af503b10 | 89 | pair<int, int> TraceTreeItemOwner::v_extents() const |
a5d93c27 | 90 | { |
d9177e6c | 91 | bool has_children = false; |
82ba380c | 92 | |
d9177e6c | 93 | pair<int, int> extents(INT_MAX, INT_MIN); |
c373f828 JH |
94 | for (const shared_ptr<TraceTreeItem> t : trace_tree_child_items()) { |
95 | assert(t); | |
96 | if (!t->enabled()) | |
a5d93c27 JH |
97 | continue; |
98 | ||
d9177e6c SA |
99 | has_children = true; |
100 | ||
c373f828 JH |
101 | const int child_offset = t->layout_v_offset(); |
102 | const pair<int, int> child_extents = t->v_extents(); | |
a5d93c27 JH |
103 | extents.first = min(child_extents.first + child_offset, |
104 | extents.first); | |
105 | extents.second = max(child_extents.second + child_offset, | |
106 | extents.second); | |
107 | } | |
108 | ||
d9177e6c SA |
109 | if (!has_children) |
110 | extents = make_pair(0, 0); | |
111 | ||
a5d93c27 JH |
112 | return extents; |
113 | } | |
114 | ||
ac0708fb SA |
115 | bool TraceTreeItemOwner::reassign_bgcolour_states(bool next_bgcolour_state) |
116 | { | |
117 | vector< shared_ptr<TraceTreeItem> > items = trace_tree_child_items(); | |
118 | ||
119 | // Sort items according to vertical position | |
120 | sort(items.begin(), items.end(), | |
121 | [](const shared_ptr<TraceTreeItem> a, const shared_ptr<TraceTreeItem> b) { | |
122 | return a->layout_v_offset() > b->layout_v_offset(); }); | |
123 | ||
124 | for (const shared_ptr<TraceTreeItem> item : items) { | |
125 | item->set_bgcolour_state(next_bgcolour_state); | |
126 | next_bgcolour_state = !next_bgcolour_state; | |
127 | } | |
128 | ||
129 | return next_bgcolour_state; | |
130 | } | |
131 | ||
af503b10 | 132 | void TraceTreeItemOwner::restack_items() |
7ff0145f JH |
133 | { |
134 | } | |
135 | ||
f4e57597 SA |
136 | } // namespace TraceView |
137 | } // namespace views | |
138 | } // namespace pv |