- switch(channel->type()->id()) {
- case SR_CHANNEL_LOGIC:
- signal = shared_ptr<view::Signal>(
- new view::LogicSignal(*this, device,
- channel, logic_data_));
- break;
-
- case SR_CHANNEL_ANALOG:
- {
- shared_ptr<data::Analog> data(
- new data::Analog());
- signal = shared_ptr<view::Signal>(
- new view::AnalogSignal(
- *this, channel, data));
- break;
+ // Find the channel in the old signals
+ const auto iter = std::find_if(
+ prev_sigs.cbegin(), prev_sigs.cend(),
+ [&](const shared_ptr<view::Signal> &s) {
+ return s->base()->channel() == channel;
+ });
+ if (iter != prev_sigs.end()) {
+ // Copy the signal from the old set to the new
+ signal = *iter;
+ } else {
+ // Find the signalbase for this channel if possible
+ signalbase.reset();
+ for (const shared_ptr<data::SignalBase> b : signalbases_)
+ if (b->channel() == channel)
+ signalbase = b;
+
+ switch(channel->type()->id()) {
+ case SR_CHANNEL_LOGIC:
+ if (!signalbase) {
+ signalbase = shared_ptr<data::SignalBase>(
+ new data::SignalBase(channel));
+ signalbases_.insert(signalbase);
+
+ all_signal_data_.insert(logic_data_);
+ signalbase->set_data(logic_data_);
+ }
+
+ signal = shared_ptr<view::Signal>(
+ new view::LogicSignal(*this,
+ device_, signalbase));
+ view->add_signal(signal);
+ break;
+
+ case SR_CHANNEL_ANALOG:
+ {
+ if (!signalbase) {
+ signalbase = shared_ptr<data::SignalBase>(
+ new data::SignalBase(channel));
+ signalbases_.insert(signalbase);
+
+ shared_ptr<data::Analog> data(new data::Analog());
+ all_signal_data_.insert(data);
+ signalbase->set_data(data);
+ }
+
+ signal = shared_ptr<view::Signal>(
+ new view::AnalogSignal(
+ *this, signalbase));
+ view->add_signal(signal);
+ break;
+ }
+
+ default:
+ assert(0);
+ break;
+ }