"Fossies" - the Fresh Open Source Software Archive

Member "fityk-1.3.1/wxgui/dload.cpp" (13 May 2016, 5224 Bytes) of package /linux/misc/fityk-1.3.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "dload.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.3.0_vs_1.3.1.

    1 // This file is part of fityk program. Copyright 2001-2013 Marcin Wojdyr
    2 // Licence: GNU General Public License ver. 2+
    3 ///  Custom Data Load Dialog (DLoadDlg) and helpers
    4 
    5 #include <vector>
    6 #include <wx/wx.h>
    7 #include <wx/statline.h>
    8 #include <wx/file.h>
    9 #include <wx/filename.h>
   10 
   11 #include "dload.h"
   12 #include "xybrowser.h"
   13 #include "frame.h"  // frame->add_recent_data_file()
   14 #include "fityk/logic.h" // ftk->get_settings()
   15 #include "fityk/settings.h"
   16 #include "fityk/data.h" // get_file_basename()
   17 #include "fityk/common.h"
   18 
   19 using namespace std;
   20 using fityk::Data;
   21 
   22 /// data_idx - data slot to be used by "Replace ..." button, -1 means none
   23 /// data - used for default settings (path, columns, etc.), not NULL
   24 DLoadDlg::DLoadDlg(wxWindow* parent, int data_idx, Data* data,
   25                    const wxString& dir)
   26     : wxDialog(parent, wxID_ANY, wxT("Load Data"),
   27                wxDefaultPosition, wxDefaultSize,
   28                wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER),
   29       data_idx_(data_idx)
   30 {
   31     wxBoxSizer *top_sizer = new wxBoxSizer(wxVERTICAL);
   32     browser_ = new XyFileBrowser(this);
   33     top_sizer->Add(browser_, 1, wxEXPAND);
   34     top_sizer->Add(new wxStaticLine(this, -1), 0, wxEXPAND|wxLEFT|wxRIGHT, 5);
   35     wxBoxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);
   36     wxString repl = "&Replace @" + s2wx(data_idx >= 0 ? S(data_idx) : S("?"));
   37     open_here_btn_ = new wxButton(this, -1, repl);
   38     if (data_idx < 0)
   39         open_here_btn_->Enable(false);
   40     open_new_btn_ = new wxButton(this, -1, wxT("&Open in new slot"));
   41     button_sizer->Add(open_here_btn_, 0, wxALL, 5);
   42     button_sizer->Add(open_new_btn_, 0, wxALL, 5);
   43     button_sizer->Add(new wxButton(this, wxID_CLOSE, wxT("&Close")),
   44                       0, wxALL, 5);
   45     top_sizer->Add(button_sizer, 0, wxALL|wxALIGN_CENTER, 0);
   46     SetSizerAndFit(top_sizer);
   47     SetSize(wxSize(700, 600));
   48     SetEscapeId(wxID_CLOSE);
   49 
   50     wxFileName path;
   51     if (!data->get_filename().empty())
   52         browser_->filectrl->SetPath(s2wx(data->get_filename()));
   53     else
   54         browser_->filectrl->SetDirectory(dir);
   55     browser_->update_file_options();
   56 
   57     if (data->get_given_x() != fityk::LoadSpec::NN)
   58         browser_->x_column->SetValue(data->get_given_x());
   59     if (data->get_given_y() != fityk::LoadSpec::NN)
   60         browser_->y_column->SetValue(data->get_given_y());
   61     if (data->get_given_s() != fityk::LoadSpec::NN) {
   62         browser_->std_dev_b->SetValue(true);
   63         browser_->s_column->SetValue(data->get_given_s());
   64     } else if (S(ftk->get_settings()->default_sigma) == "sqrt") {
   65         browser_->sd_sqrt_rb->SetValue(true);
   66     } else {
   67         browser_->sd_1_rb->SetValue(true);
   68     }
   69     browser_->update_s_column();
   70 
   71     Connect(open_here_btn_->GetId(), wxEVT_COMMAND_BUTTON_CLICKED,
   72             wxCommandEventHandler(DLoadDlg::OnOpenHere));
   73     Connect(open_new_btn_->GetId(), wxEVT_COMMAND_BUTTON_CLICKED,
   74             wxCommandEventHandler(DLoadDlg::OnOpenNew));
   75 }
   76 
   77 
   78 void DLoadDlg::exec_command(bool replace)
   79 {
   80     string cols;
   81     int x = browser_->x_column->GetValue();
   82     int y = browser_->y_column->GetValue();
   83     bool has_s = browser_->std_dev_b->GetValue();
   84     int sig = browser_->s_column->GetValue();
   85     int b = browser_->block_ch->GetSelection();
   86     // default parameter values are not passed explicitely
   87     if (x != 1 || y != 2 || has_s || b != 0) {
   88         cols = ":" + S(x) + ":" + S(y) + ":";
   89         if (has_s)
   90             cols += S(sig);
   91         cols += ":";
   92         if (b != 0)
   93             cols += S(b);
   94     }
   95 
   96     string with_options;
   97     if (!has_s) {
   98         bool default_sqrt = (S(ftk->get_settings()->default_sigma) == "sqrt");
   99         bool set_sqrt = browser_->sd_sqrt_rb->GetValue();
  100         if (set_sqrt != default_sqrt) {
  101             if (set_sqrt)
  102                 with_options = "with default_sigma=sqrt ";
  103             else
  104                 with_options = "with default_sigma=one ";
  105         }
  106     }
  107     wxArrayString paths;
  108     browser_->filectrl->GetPaths(paths);
  109     string trailer;
  110     string lua_trailer;
  111     string fmt = browser_->get_filetype();
  112     if (fmt != "" || browser_->comma_cb->GetValue()) {
  113         trailer = " " + (fmt == "" ? "_" : fmt);
  114         lua_trailer = ", '" + fmt + "'";
  115         if (browser_->comma_cb->GetValue()) {
  116             trailer += " decimal_comma";
  117             lua_trailer += ", 'decimal_comma'";
  118         }
  119     }
  120     for (size_t i = 0; i < paths.GetCount(); ++i) {
  121         string cmd;
  122         if (paths[i].Find('\'') == wxNOT_FOUND)
  123             cmd = "@" + (replace ? S(data_idx_) : S("+")) +
  124                    " < '" + wx2s(paths[i]) + cols + "'" + trailer;
  125         else // very special case
  126             cmd = "lua F:load(" + S(replace ? data_idx_ : -1) +
  127                    ", [[" + wx2s(paths[i]) + "]], " + S(b) + ", " +
  128                    S(x) + ", " + S(y) + ", " + S(sig) + lua_trailer + ")";
  129         exec(with_options + cmd);
  130         wxString title = browser_->title_tc->GetValue().Trim();
  131         if (!title.empty() && title != browser_->auto_title_) {
  132             int slot = (replace ? data_idx_ : ftk->dk.count() - 1);
  133             exec("@" + S(slot) + ": title = '" + wx2s(title) + "'");
  134         }
  135         frame->add_recent_data_file(paths[i]);
  136     }
  137 }
  138