]>
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 | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
68b21a71 JH |
21 | #include <cassert> |
22 | ||
af503b10 JH |
23 | #include "tracetreeitem.hpp" |
24 | #include "tracetreeitemowner.hpp" | |
6046c19d | 25 | #include "trace.hpp" |
68b21a71 | 26 | |
6046c19d | 27 | using std::dynamic_pointer_cast; |
a5d93c27 JH |
28 | using std::max; |
29 | using std::make_pair; | |
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 { | |
38 | namespace view { | |
39 | ||
c373f828 | 40 | vector< shared_ptr<ViewItem> >& TraceTreeItemOwner::child_items() |
6b715302 | 41 | { |
8dbbc7f0 | 42 | return items_; |
6b715302 JH |
43 | } |
44 | ||
c373f828 | 45 | const vector< shared_ptr<ViewItem> >& TraceTreeItemOwner::child_items() const |
68b21a71 | 46 | { |
8dbbc7f0 | 47 | return items_; |
68b21a71 JH |
48 | } |
49 | ||
c373f828 JH |
50 | vector< std::shared_ptr<TraceTreeItem> > |
51 | TraceTreeItemOwner::trace_tree_child_items() const | |
68b21a71 | 52 | { |
c373f828 | 53 | vector< shared_ptr<TraceTreeItem> > items; |
8dbbc7f0 | 54 | for (auto &i : items_) { |
c373f828 JH |
55 | assert(dynamic_pointer_cast<TraceTreeItem>(i)); |
56 | const shared_ptr<TraceTreeItem> t( | |
57 | static_pointer_cast<TraceTreeItem>(i)); | |
58 | items.push_back(t); | |
59 | } | |
60 | ||
61 | return items; | |
62 | } | |
63 | ||
64 | void TraceTreeItemOwner::clear_child_items() | |
65 | { | |
66 | for (auto &t : trace_tree_child_items()) { | |
67 | assert(t->owner() == this); | |
68 | t->set_owner(nullptr); | |
68b21a71 | 69 | } |
8dbbc7f0 | 70 | items_.clear(); |
68b21a71 JH |
71 | } |
72 | ||
af503b10 | 73 | void TraceTreeItemOwner::add_child_item(std::shared_ptr<TraceTreeItem> item) |
68b21a71 JH |
74 | { |
75 | assert(!item->owner()); | |
76 | item->set_owner(this); | |
8dbbc7f0 | 77 | items_.push_back(item); |
32218d3e JH |
78 | |
79 | extents_changed(true, true); | |
68b21a71 JH |
80 | } |
81 | ||
af503b10 | 82 | void TraceTreeItemOwner::remove_child_item(std::shared_ptr<TraceTreeItem> item) |
68b21a71 JH |
83 | { |
84 | assert(item->owner() == this); | |
85 | item->set_owner(nullptr); | |
8dbbc7f0 JH |
86 | auto iter = std::find(items_.begin(), items_.end(), item); |
87 | assert(iter != items_.end()); | |
88 | items_.erase(iter); | |
32218d3e JH |
89 | |
90 | extents_changed(true, true); | |
68b21a71 JH |
91 | } |
92 | ||
af503b10 | 93 | pair<int, int> TraceTreeItemOwner::v_extents() const |
a5d93c27 | 94 | { |
82ba380c SA |
95 | pair<int, int> extents(INT_MAX, INT_MIN); |
96 | ||
c373f828 JH |
97 | for (const shared_ptr<TraceTreeItem> t : trace_tree_child_items()) { |
98 | assert(t); | |
99 | if (!t->enabled()) | |
a5d93c27 JH |
100 | continue; |
101 | ||
c373f828 JH |
102 | const int child_offset = t->layout_v_offset(); |
103 | const pair<int, int> child_extents = t->v_extents(); | |
a5d93c27 JH |
104 | extents.first = min(child_extents.first + child_offset, |
105 | extents.first); | |
106 | extents.second = max(child_extents.second + child_offset, | |
107 | extents.second); | |
108 | } | |
109 | ||
110 | return extents; | |
111 | } | |
112 | ||
af503b10 | 113 | void TraceTreeItemOwner::restack_items() |
7ff0145f JH |
114 | { |
115 | } | |
116 | ||
68b21a71 JH |
117 | } // view |
118 | } // pv |