]> sigrok.org Git - pulseview.git/blob - pv/data/signalbase.cpp
d2dd75ab60f684b65a02611a24c6b4b6283baedb
[pulseview.git] / pv / data / signalbase.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5  * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include "analog.hpp"
23 #include "logic.hpp"
24 #include "signalbase.hpp"
25 #include "signaldata.hpp"
26 #include "decode/row.hpp"
27
28 #include <pv/binding/decoder.hpp>
29
30 using std::dynamic_pointer_cast;
31 using std::shared_ptr;
32
33 using sigrok::Channel;
34 using sigrok::ChannelType;
35
36 namespace pv {
37 namespace data {
38
39 const int SignalBase::ColourBGAlpha = 8*256/100;
40
41 SignalBase::SignalBase(shared_ptr<sigrok::Channel> channel) :
42         channel_(channel)
43 {
44         if (channel_)
45                 internal_name_ = QString::fromStdString(channel_->name());
46 }
47
48 shared_ptr<sigrok::Channel> SignalBase::channel() const
49 {
50         return channel_;
51 }
52
53 QString SignalBase::name() const
54 {
55         return (channel_) ? QString::fromStdString(channel_->name()) : name_;
56 }
57
58 QString SignalBase::internal_name() const
59 {
60         return internal_name_;
61 }
62
63 void SignalBase::set_name(QString name)
64 {
65         if (channel_)
66                 channel_->set_name(name.toUtf8().constData());
67
68         name_ = name;
69
70         name_changed(name);
71 }
72
73 bool SignalBase::enabled() const
74 {
75         return (channel_) ? channel_->enabled() : true;
76 }
77
78 void SignalBase::set_enabled(bool value)
79 {
80         if (channel_) {
81                 channel_->set_enabled(value);
82                 enabled_changed(value);
83         }
84 }
85
86 const ChannelType *SignalBase::type() const
87 {
88         return (channel_) ? channel_->type() : nullptr;
89 }
90
91 unsigned int SignalBase::index() const
92 {
93         return (channel_) ? channel_->index() : (unsigned int)-1;
94 }
95
96 QColor SignalBase::colour() const
97 {
98         return colour_;
99 }
100
101 void SignalBase::set_colour(QColor colour)
102 {
103         colour_ = colour;
104
105         bgcolour_ = colour;
106         bgcolour_.setAlpha(ColourBGAlpha);
107
108         colour_changed(colour);
109 }
110
111 QColor SignalBase::bgcolour() const
112 {
113         return bgcolour_;
114 }
115
116 void SignalBase::set_data(shared_ptr<pv::data::SignalData> data)
117 {
118         data_ = data;
119 }
120
121 shared_ptr<data::Analog> SignalBase::analog_data() const
122 {
123         if (type() == ChannelType::ANALOG)
124                 return dynamic_pointer_cast<data::Analog>(data_);
125         else
126                 return shared_ptr<data::Analog>();
127 }
128
129 shared_ptr<data::Logic> SignalBase::logic_data() const
130 {
131         if (type() == ChannelType::LOGIC)
132                 return dynamic_pointer_cast<data::Logic>(data_);
133         else
134                 return shared_ptr<data::Logic>();
135 }
136
137 #ifdef ENABLE_DECODE
138 bool SignalBase::is_decode_signal() const
139 {
140         return (decoder_stack_ != nullptr);
141 }
142
143 std::shared_ptr<pv::data::DecoderStack> SignalBase::decoder_stack() const
144 {
145         return decoder_stack_;
146 }
147
148 void SignalBase::set_decoder_stack(std::shared_ptr<pv::data::DecoderStack>
149         decoder_stack)
150 {
151         decoder_stack_ = decoder_stack;
152 }
153 #endif
154
155 } // namespace data
156 } // namespace pv