VPTissue Reference Manual
PathPage.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "PathPage.h"
21 
26 
27 #include <boost/property_tree/exceptions.hpp>
28 #include <boost/property_tree/xml_parser.hpp>
29 #include <QComboBox>
30 #include <QFileDialog>
31 #include <QFormLayout>
32 #include <QLabel>
33 #include <QLineEdit>
34 #include <QMessageBox>
35 #include <QPushButton>
36 #include <QRadioButton>
37 #include <QSettings>
38 #include <QString>
39 #include <QVBoxLayout>
40 
41 #include <cctype>
42 #include <iostream>
43 #include <memory>
44 
45 using namespace boost::property_tree;
46 using namespace boost::property_tree::xml_parser;
47 
48 namespace SimPT_Parex {
49 
50 PathPage::PathPage(std::shared_ptr<Exploration>& exploration, boost::property_tree::ptree& preferences)
51  : m_exploration(exploration), m_preferences(preferences)
52 {
53  // Set title + text
54  setTitle("Select sim data file");
55  setSubTitle("Please select a sim data file to use as basis for the exploration.");
56 
57  // Set main layout
58  QHBoxLayout* layout = new QHBoxLayout;
59 
60  QLabel* label = new QLabel("Path");
61  m_file_path = new QLineEdit;
62  m_file_path->setReadOnly(true);
63  QPushButton* buttonBrowse = new QPushButton("Browse...");
64 
65  layout->addWidget(label);
66  layout->addWidget(m_file_path);
67  layout->addWidget(buttonBrowse);
68 
69  setLayout(layout);
70 
71  connect(buttonBrowse, SIGNAL(clicked()), this, SLOT(BrowseFile()));
72 }
73 
74 void PathPage::BrowseFile()
75 {
76  QSettings settings;
77 
78  QString path;
79  if (settings.contains("last_leaf_file"))
80  path = settings.value("last_leaf_file").toString();
81  else
82  path = settings.value("workspace").toString();
83 
84  QString file = QFileDialog::getOpenFileName(this, "Browse", path);
85 
86  m_ptree.clear();
87 
88  if (!QFile(file).exists())
89  return;
90 
91  try {
92  read_xml(file.toStdString(), m_ptree, trim_whitespace);
93  } catch (ptree_bad_path& e) {
94  QMessageBox::critical(this, "Read Error", "Error in data input file", QMessageBox::Ok);
95  return;
96  } catch (ptree_bad_data& e) {
97  QMessageBox::critical(this, "Read Error", "Error in data input file.", QMessageBox::Ok);
98  return;
99  } catch (xml_parser_error& e) {
100  QMessageBox::critical(this, "Error", "Not a valid data input file.", QMessageBox::Ok);
101  return;
102  } catch (std::exception& e) {
103  QMessageBox::critical(this, "Error", "Could not read data input file.", QMessageBox::Ok);
104  return;
105  } catch (...) {
106  QMessageBox::critical(this, "Error", "Unknown Exception", QMessageBox::Ok);
107  return;
108  }
109 
110  m_file_path->setText(file);
111  settings.setValue("last_leaf_file", file);
112 
113  emit completeChanged();
114 }
115 
116 bool PathPage::isComplete() const
117 {
118  return !m_ptree.empty();
119 }
120 
121 bool PathPage::validatePage()
122 {
123  m_exploration = std::make_shared<ParameterExploration>("Untitled", m_ptree, m_preferences);
124  return true;
125 }
126 
127 } // namespace
128 
Interface for PathPage.
Interface for RangeSweep.
Interface for ListSweep.
Namespace for SimPT parameter explorer package.
Definition: Client.cpp:52
Interface for ParameterExploration.
Interface for FileExploration.