Vespucci  1.0.0
scriptdialog.cpp
Go to the documentation of this file.
1 #include "GUI/scriptdialog.h"
2 #include "ui_scriptdialog.h"
3 #include <cstdlib>
4 #include <cstdio>
6 
7 ScriptDialog::ScriptDialog(QWidget *parent, QSharedPointer<VespucciWorkspace> ws, const QString &dataset_key) :
8  QDialog(parent),
9  ui(new Ui::ScriptDialog)
10 {
11  ui->setupUi(this);
12  dataset_ = ws->GetDataset(dataset_key);
13  workspace_ = ws;
14 }
15 
17 {
18  delete ui;
19 }
20 
21 void ScriptDialog::on_buttonBox_accepted()
22 {
23  //Parse input
24  /*
25  try{
26  std::string cmd = ui->codePlainTextEdit->document()->toPlainText().toStdString();
27  QStringList invars = ui->sendPlainTextEdit->document()->toPlainText().split("\n");
28  QStringList outvars = ui->receivePlainTextEdit->document()->toPlainText().split("\n");
29 
30  //parse syntax for input box
31  std::map<std::string, arma::mat> in_data;
32  arma::mat *matrix_ptr;
33  std::cout << "parsing invars..." << std::endl;
34  for (int i = 0; i < invars.size(); ++i){
35  std::cout << "invars[i] = " << invars[i].toStdString() << std::endl;
36  if (invars[i] == "spectra")
37  matrix_ptr = dataset_->spectra_ptr();
38  else if (invars[i] == "abscissa")\
39  matrix_ptr = dataset_->wavelength_ptr();
40  else if (invars[i] == "x")
41  matrix_ptr = dataset_->x_ptr();
42  else if (invars[i] == "y")
43  matrix_ptr = dataset_->y_ptr();
44  else{
45  matrix_ptr = dataset_->AnalysisResult(invars[i]);
46  }
47 
48  if (matrix_ptr != NULL)
49  in_data[invars[i].toStdString()] = *matrix_ptr;
50  }
51 
52  std::cout << "parsing outvars\n";
53 
54  std::string interpreter_key;
55  std::string vespucci_key;
56  std::map<std::string, std::string> variable_keys;
57  for (int i = 0; i < outvars.size(); ++i){
58  std::cout << "outvars[i] = " << outvars[i].toStdString() << "\n";
59 
60  vespucci_key = outvars[i].split("=")[0].trimmed().toStdString();
61  interpreter_key = outvars[i].split("=")[1].trimmed().toStdString();
62  std::cout << vespucci_key << ", " << interpreter_key << std::endl;
63  variable_keys[vespucci_key] = interpreter_key;
64  }
65  std::map<std::string, arma::mat> data;
66  std::cout << "R stuff\n";
67 
68  if (ui->interpreterComboBox->currentText() == "R"){
69  workspace_->settings()->beginGroup("environment");
70  QString r_home = workspace_->settings()->value("R_HOME").toString();
71  workspace_->settings()->endGroup();
72  r_home = "R_HOME=" + r_home;
73  char* R_HOME;
74  snprintf(R_HOME, r_home.size(), r_home.toStdString().c_str());
75  putenv(R_HOME); //set R_HOME environment variable
76  int argc = 1;
77  char first_arg[] = "vespucci"; //done to avoid string conversion
78  char* argv[1];
79  argv[0] = first_arg;
80  QScopedPointer<VespucciR> R_instance(new VespucciR(argc, argv));
81  //send variables to R
82  R_instance->SetEnvironment(in_data);
83  //Run R code
84  std::cout << "Run Script" << std::endl;
85  R_instance->RunScript(cmd);
86  //retrieve output from R
87  std::cout << "Get Environment" << std::endl;
88  data = R_instance->GetEnvironment(variable_keys);
89  std::cout << "Add Results" << std::endl;
90  dataset_->AddAnalysisResults(data);
91  }
92  else if (ui->interpreterComboBox->currentText() == "Octave"){
93  //Do Octave stuff
94  }
95  else{
96  QMessageBox::information(this, "Unknown or Unsupported Interpreter", "This interpreter is not usable from Vespucci", QMessageBox::Close);
97  }
98  }
99  catch(exception e){
100  cerr << e.what();
101  QMessageBox::warning(this, "Exception Occurred", "An exception " + QString::fromStdString(e.what()) + " occurred");
102  //go back to normal.
103  }
104 
105 
106 */
107 
108 }
109 
Definition: ahcadialog.h:26
ScriptDialog(QWidget *parent, QSharedPointer< VespucciWorkspace > ws, const QString &dataset_key)
Definition: scriptdialog.cpp:7