Added comments, added possibility to open an existing file in tasmet from the command line

This commit is contained in:
Anne de Jong 2017-01-30 21:48:08 +01:00
parent a6a76f65d7
commit dfc84370dc
4 changed files with 72 additions and 28 deletions

View File

@ -395,15 +395,15 @@ void Duct::exportHDF5(const hid_t group_id) const {
}
p.exportHDF5(group_id);
TXData Ts;
Ts.name = "Solid temperature";
Ts.unit = "K";
Ts.symbol = "Ts";
Ts.x = dmat(sys.Ns(),ngp());
for(us gp=0;gp<ngp();gp++){
p.x.col(gp) = Tst(gp);
}
Ts.exportHDF5(group_id);
// TXData Ts;
// Ts.name = "Solid temperature";
// Ts.unit = "K";
// Ts.symbol = "Ts";
// Ts.x = dmat(sys.Ns(),ngp());
// for(us gp=0;gp<ngp();gp++){
// p.x.col(gp) = Tst(gp);
// }
// Ts.exportHDF5(group_id);
}

View File

@ -123,9 +123,9 @@ void TaSMETMainWindow::newModel() {
_filepath = "";
set(_model);
}
void TaSMETMainWindow::loadModel() {
void TaSMETMainWindow::loadModel(const string* filepath_s) {
TRACE(15,"loadModel");
if(isDirty()) {
if(isDirty() && filepath_s == nullptr) {
int answer = saveFileFirstQuestion(this);
if(answer == QMessageBox::Yes) saveModel();
else if(answer == QMessageBox::Cancel) return;
@ -133,16 +133,22 @@ void TaSMETMainWindow::loadModel() {
QString title = tr("Open existing TaSMET model file");
QString filepath = QFileDialog::getOpenFileName(this,
title,
start_file_location,
filetype);
string filepath_s = filepath.toStdString();
if(filepath.size()!=0) {
if(filepath_s == nullptr) {
QString filepath = QFileDialog::getOpenFileName(this,
title,
start_file_location,
filetype);
if(filepath.size()!=0) {
string filepath_s2 = filepath.toStdString();
return loadModel(&filepath_s2);
}
}
else {
try {
TRACE(15,"Setting loaded model");
_filepath = filepath_s;
set(loadMessage<pb::Model>(filepath_s));
_filepath = *filepath_s;
set(loadMessage<pb::Model>(*filepath_s));
}
catch(TaSMETError &e) {
_filepath = "";

View File

@ -25,29 +25,61 @@ class TaSMETMainWindow: public QMainWindow {
// In-memory model
pb::Model _model;
pb::System& _system;
pb::System& _system; /**< In constructor set to the
_model.mutable_system() */
// Where the file is stored
string _filepath = "";
bool _init = true;
bool _init = true; /**< */
public:
TaSMETMainWindow();
~TaSMETMainWindow();
private:
void newModel();
void loadModel();
public:
/**
* Load a model from a file. Called by File->Open. If no filepath
* is given, a dialog is opened to specify the file. This function
* is public such that it can be called for main.cpp.
*
* @param filepath the filepath of the file to load
*/
void loadModel(const string* filepath=nullptr);
private:
/**
* Save the model to a file. If no filepath is given, a dialog is
* opened to ask the user for a filepath.
*
* @param filepath
*/
void saveModel(string* filepath=nullptr);
/**
* Save the model with a different filename.
*/
void saveAsModel();
// When the user interacts, we call this function to update the
// internal state and set the widget status accordingly
/**
* When the user interacts, we call this function to update the
* internal state and set the widget status accordingly.
*/
void changed();
void set(const pb::Model&);
/**
* Change the widget states according to the model
*
* @param model The model to set
*/
void set(const pb::Model& model);
// Check whether the filepath contents agree with the system in
// memory
/**
* Check whether the filepath contents agree with the system in
* memory.
*
* @return true when the model in memory does not agree with the
* file contents.
*/
bool isDirty() const;
private slots:

View File

@ -28,7 +28,8 @@ void catchUnixSignals(const std::vector<int>& quitSignals,
for ( int sig : ignoreSignals )
signal(sig, SIG_IGN);
// each of these signals calls the handler (quits the QCoreApplication).
// each of these signals calls the handler (quits the
// QCoreApplication).
for ( int sig : quitSignals )
signal(sig, handler);
}
@ -61,6 +62,11 @@ int main(int argc, char *argv[]) {
TaSMETMainWindow win;
win.show();
if(argc>1) {
string filepath = argv[1];
win.loadModel(&filepath);
}
return app.exec();
}