StoreProgress::StoreProgress(const QString &file_name,
const std::shared_ptr<sigrok::OutputFormat> output_format,
const map<string, VariantBase> &options,
+ const std::pair<uint64_t, uint64_t> sample_range,
const Session &session, QWidget *parent) :
QProgressDialog(tr("Saving..."), tr("Cancel"), 0, 0, parent),
- session_(file_name.toStdString(), output_format, options, session)
+ session_(file_name.toStdString(), output_format, options, sample_range,
+ session)
{
connect(&session_, SIGNAL(progress_updated()),
this, SLOT(on_progress_updated()));
StoreProgress(const QString &file_name,
const std::shared_ptr<sigrok::OutputFormat> output_format,
const std::map<std::string, Glib::VariantBase> &options,
- const Session &session, QWidget *parent = 0);
+ const std::pair<uint64_t, uint64_t> sample_range,
+ const Session &session,
+ QWidget *parent = 0);
virtual ~StoreProgress();
#include "mainwindow.hpp"
#include "devicemanager.hpp"
+#include "util.hpp"
+#include "data/segment.hpp"
#include "devices/hardwaredevice.hpp"
#include "devices/inputfile.hpp"
#include "devices/sessionfile.hpp"
session_(device_manager),
action_open_(new QAction(this)),
action_save_as_(new QAction(this)),
+ action_save_selection_as_(new QAction(this)),
action_connect_(new QAction(this)),
action_quit_(new QAction(this)),
action_view_zoom_in_(new QAction(this)),
options = dlg.options();
}
+ const std::pair<uint64_t, uint64_t> sample_range = std::make_pair(0, 0);
+
StoreProgress *dlg = new StoreProgress(file_name, format, options,
- session_, this);
+ sample_range, session_, this);
dlg->run();
}
action_save_as_->setObjectName(QString::fromUtf8("actionSaveAs"));
menu_file->addAction(action_save_as_);
+ action_save_selection_as_->setText(tr("Save Selected &Range As..."));
+ action_save_selection_as_->setIcon(QIcon::fromTheme("document-save-as",
+ QIcon(":/icons/document-save-as.png")));
+ action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
+ action_save_selection_as_->setObjectName(QString::fromUtf8("actionSaveSelectionAs"));
+ menu_file->addAction(action_save_selection_as_);
+
menu_file->addSeparator();
widgets::ExportMenu *menu_file_export = new widgets::ExportMenu(this,
session_error(errorMessage, infoMessage); });
}
+void MainWindow::save_selection_to_file()
+{
+ // Stop any currently running capture session
+ session_.stop_capture();
+
+ // Get sample rate
+ double samplerate = 0.0;
+
+ for (const shared_ptr<pv::data::SignalData> d : session_.get_data()) {
+ assert(d);
+ const vector< shared_ptr<pv::data::Segment> > segments =
+ d->segments();
+ for (const shared_ptr<pv::data::Segment> &s : segments)
+ samplerate = std::max(samplerate, s->samplerate());
+ }
+
+ if (samplerate == 0.0)
+ samplerate = 1;
+
+ // Verify that the cursors are active and fetch their values
+ if (!view_->cursors()->enabled()) {
+ show_session_error(tr("Missing Cursors"), tr("You need to set the " \
+ "cursors before you can save the data enclosed by them " \
+ "to a session file (e.g. using ALT-V - Show Cursors)."));
+ return;
+ }
+
+ const pv::util::Timestamp& start_time = view_->cursors()->first()->time();
+ const pv::util::Timestamp& end_time = view_->cursors()->second()->time();
+
+ const uint64_t start_sample = start_time.convert_to<double>() * samplerate;
+ const uint64_t end_sample = end_time.convert_to<double>() * samplerate;
+
+ const std::pair<uint64_t, uint64_t> sample_range =
+ std::make_pair(start_sample, end_sample);
+
+ // Ask for output file name
+ QSettings settings;
+ const QString dir = settings.value(SettingSaveDirectory).toString();
+
+ shared_ptr<OutputFormat> format =
+ device_manager_.context()->output_formats()["srzip"];
+
+ const vector<string> exts = format->extensions();
+ QString filter = tr("%1 files ").arg(
+ QString::fromStdString(format->description()));
+
+ if (exts.empty())
+ filter += "(*.*)";
+ else
+ filter += QString("(*.%1);;%2 (*.*)").arg(
+ QString::fromStdString(join(exts, ", *."))).arg(
+ tr("All Files"));
+
+ const QString file_name = QFileDialog::getSaveFileName(
+ this, tr("Save File"), dir, filter);
+
+ if (file_name.isEmpty())
+ return;
+
+ const QString abs_path = QFileInfo(file_name).absolutePath();
+ settings.setValue(SettingSaveDirectory, abs_path);
+
+ // Show the options dialog
+ map<string, Glib::VariantBase> options;
+ if (!format->options().empty()) {
+ dialogs::InputOutputOptions dlg(
+ tr("Export %1").arg(QString::fromStdString(
+ format->description())),
+ format->options(), this);
+ if (!dlg.exec())
+ return;
+ options = dlg.options();
+ }
+
+ // Save
+ pv::dialogs::StoreProgress *dlg = new pv::dialogs::StoreProgress(file_name,
+ format, options, sample_range, session_, this);
+ dlg->run();
+}
+
void MainWindow::closeEvent(QCloseEvent *event)
{
save_ui_settings();
export_file(device_manager_.context()->output_formats()["srzip"]);
}
+void MainWindow::on_actionSaveSelectionAs_triggered()
+{
+ save_selection_to_file();
+}
+
void MainWindow::on_actionConnect_triggered()
{
// Stop any currently running capture session
QAction* action_open() const;
QAction* action_save_as() const;
+ QAction* action_save_selection_as() const;
QAction* action_connect() const;
QAction* action_quit() const;
QAction* action_view_zoom_in() const;
const std::map<std::string, Glib::VariantBase> &options =
std::map<std::string, Glib::VariantBase>());
+ void save_selection_to_file();
+
private:
void closeEvent(QCloseEvent *event);
void on_actionOpen_triggered();
void on_actionSaveAs_triggered();
+ void on_actionSaveSelectionAs_triggered();
void on_actionQuit_triggered();
void on_actionConnect_triggered();
QAction *const action_open_;
QAction *const action_save_as_;
+ QAction *const action_save_selection_as_;
QAction *const action_connect_;
QAction *const action_quit_;
QAction *const action_view_zoom_in_;
StoreSession::StoreSession(const std::string &file_name,
const shared_ptr<OutputFormat> &output_format,
- const map<string, VariantBase> &options, const Session &session) :
+ const map<string, VariantBase> &options,
+ const std::pair<uint64_t, uint64_t> sample_range,
+ const Session &session) :
file_name_(file_name),
output_format_(output_format),
options_(options),
+ sample_range_(sample_range),
session_(session),
interrupt_(false),
units_stored_(0),
const shared_ptr<data::LogicSegment> segment(segments.front());
assert(segment);
+ // Check whether the user wants to export a certain sample range
+ if (sample_range_.first == sample_range_.second) {
+ start_sample_ = 0;
+ sample_count_ = segment->get_sample_count();
+ } else {
+ start_sample_ = std::min(sample_range_.first, sample_range_.second);
+ sample_count_ = std::abs(sample_range_.second - sample_range_.first);
+ }
+
// Begin storing
try {
const auto context = session_.device_manager().context();
{
assert(segment);
- uint64_t start_sample = 0, sample_count;
unsigned progress_scale = 0;
/// TODO: Wrap this in a std::unique_ptr when we transition to C++11
const int unit_size = segment->unit_size();
assert(unit_size != 0);
- sample_count = segment->get_sample_count();
-
// Qt needs the progress values to fit inside an int. If they would
// not, scale the current and max values down until they do.
- while ((sample_count >> progress_scale) > INT_MAX)
+ while ((sample_count_ >> progress_scale) > INT_MAX)
progress_scale ++;
- unit_count_ = sample_count >> progress_scale;
+ unit_count_ = sample_count_ >> progress_scale;
const unsigned int samples_per_block = BlockSize / unit_size;
- while (!interrupt_ && start_sample < sample_count)
+ while (!interrupt_ && sample_count_)
{
progress_updated();
- const uint64_t end_sample = min(
- start_sample + samples_per_block, sample_count);
- segment->get_samples(data, start_sample, end_sample);
+ const uint64_t packet_len =
+ std::min((uint64_t)samples_per_block, sample_count_);
+
+ segment->get_samples(data, start_sample_, start_sample_ + packet_len);
- size_t length = (end_sample - start_sample) * unit_size;
+ size_t length = packet_len * unit_size;
try {
const auto context = session_.device_manager().context();
break;
}
- start_sample = end_sample;
- units_stored_ = start_sample >> progress_scale;
+ sample_count_ -= packet_len;
+ start_sample_ += packet_len;
+ units_stored_ = unit_count_ - (sample_count_ >> progress_scale);
}
// Zeroing the progress variables indicates completion
StoreSession(const std::string &file_name,
const std::shared_ptr<sigrok::OutputFormat> &output_format,
const std::map<std::string, Glib::VariantBase> &options,
+ const std::pair<uint64_t, uint64_t> sample_range,
const Session &session);
~StoreSession();
const std::string file_name_;
const std::shared_ptr<sigrok::OutputFormat> output_format_;
const std::map<std::string, Glib::VariantBase> options_;
+ const std::pair<uint64_t, uint64_t> sample_range_;
const Session &session_;
std::shared_ptr<sigrok::Output> output_;
mutable std::mutex mutex_;
QString error_;
+
+ uint64_t start_sample_, sample_count_;
};
} // pv