~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/VISUAL/DIALOGS/TOPPASToolConfigDialog.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework 
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
9
//  This library is free software; you can redistribute it and/or
 
10
//  modify it under the terms of the GNU Lesser General Public
 
11
//  License as published by the Free Software Foundation; either
 
12
//  version 2.1 of the License, or (at your option) any later version.
 
13
//
 
14
//  This library is distributed in the hope that it will be useful,
 
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
//  Lesser General Public License for more details.
 
18
//
 
19
//  You should have received a copy of the GNU Lesser General Public
 
20
//  License along with this library; if not, write to the Free Software
 
21
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Johannes Junker $
 
25
// $Authors: Johannes Junker $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
// OpenMS includes
 
29
#include <OpenMS/VISUAL/DIALOGS/TOPPASToolConfigDialog.h>
 
30
#include <OpenMS/VISUAL/ParamEditor.h>
 
31
#include <OpenMS/APPLICATIONS/TOPPBase.h>
 
32
#include <OpenMS/SYSTEM/File.h>
 
33
#include <QtCore/QStringList>
 
34
#include <QtGui/QPushButton>
 
35
#include <QtGui/QHBoxLayout>
 
36
#include <QtGui/QGridLayout>
 
37
#include <QtGui/QLabel>
 
38
#include <QtGui/QMessageBox>
 
39
#include <QtGui/QRadioButton>
 
40
#include <QtGui/QFileDialog>
 
41
#include <QtGui/QCheckBox>
 
42
 
 
43
using namespace std;
 
44
 
 
45
namespace OpenMS
 
46
{
 
47
        TOPPASToolConfigDialog::TOPPASToolConfigDialog( QWidget * parent, Param& param, String default_dir, String tool_name, String tool_type, QVector<String> hidden_entries)
 
48
                : QDialog(parent),
 
49
                        param_(&param),
 
50
                        default_dir_(default_dir),
 
51
                        tool_name_(tool_name),
 
52
                        tool_type_(tool_type),
 
53
                        hidden_entries_(hidden_entries)
 
54
        {
 
55
    QGridLayout *main_grid = new QGridLayout(this);
 
56
 
 
57
                //Add advanced mode check box           
 
58
    editor_ = new ParamEditor(this);
 
59
                main_grid->addWidget(editor_,0,0,1,1);          
 
60
                
 
61
                QHBoxLayout* hbox = new QHBoxLayout;
 
62
    QPushButton* load_button = new QPushButton(tr("&Load"));
 
63
                connect(load_button,SIGNAL(clicked()),this,SLOT(loadINI_()));
 
64
                hbox->addWidget(load_button);
 
65
    QPushButton* store_button = new QPushButton(tr("&Store"));
 
66
                connect(store_button,SIGNAL(clicked()),this,SLOT(storeINI_()));
 
67
                hbox->addWidget(store_button);
 
68
                hbox->addStretch();
 
69
 
 
70
    // cancel button
 
71
    QPushButton* cancel_button = new QPushButton(tr("&Cancel"));
 
72
    connect(cancel_button,SIGNAL(clicked()),this,SLOT(reject()));
 
73
    hbox->addWidget(cancel_button);
 
74
 
 
75
    // ok button
 
76
    QPushButton* ok_button_ = new QPushButton(tr("&Ok"));
 
77
                connect(ok_button_, SIGNAL(clicked()),this,SLOT(ok_()));
 
78
                hbox->addWidget(ok_button_);
 
79
 
 
80
                main_grid->addLayout(hbox,1,0,1,1);
 
81
                
 
82
                setLayout(main_grid);
 
83
                
 
84
                editor_->load(*param_);
 
85
                
 
86
                String str;
 
87
                
 
88
                editor_->setFocus(Qt::MouseFocusReason);
 
89
                
 
90
    setWindowTitle(tool_name.toQString() + " " + tr("configuration"));
 
91
        }
 
92
        
 
93
        TOPPASToolConfigDialog::~TOPPASToolConfigDialog()
 
94
        {
 
95
        
 
96
        }
 
97
 
 
98
        void TOPPASToolConfigDialog::ok_()
 
99
        {
 
100
                editor_->store();
 
101
                
 
102
                accept();
 
103
        }
 
104
        
 
105
        void TOPPASToolConfigDialog::loadINI_()
 
106
        {
 
107
                QString string;
 
108
                filename_=QFileDialog::getOpenFileName(this,tr("Open ini file"),default_dir_.c_str(),tr("ini files (*.ini);; all files (*.*)"));
 
109
                //not file selected
 
110
                if(filename_.isEmpty())
 
111
                {
 
112
                        return;
 
113
                }
 
114
                if(!arg_param_.empty())
 
115
                {
 
116
                        arg_param_.clear();
 
117
                        param_->clear();
 
118
                        editor_->clear();
 
119
                }
 
120
                try
 
121
                {
 
122
                        arg_param_.load(filename_.toStdString());
 
123
                }
 
124
                catch(Exception::BaseException& e)
 
125
                {
 
126
                        QMessageBox::critical(this,"Error",(String("Error loading INI file: ")+e.getMessage()).c_str());
 
127
                        arg_param_.clear();
 
128
                        return;
 
129
                }
 
130
                //Extract the required parameters
 
131
                *param_=arg_param_.copy(tool_name_ + ":1:", true);
 
132
                //param_->remove("log");
 
133
                //param_->remove("no_progress");
 
134
                //param_->remove("debug");
 
135
                
 
136
                //remove parameters already explained by edges and the "type" parameter
 
137
                foreach (const String& name, hidden_entries_)
 
138
                {
 
139
                        param_->remove(name);
 
140
                }
 
141
                
 
142
                //load data into editor
 
143
                editor_->load(*param_);
 
144
        }
 
145
        
 
146
        void TOPPASToolConfigDialog::storeINI_()
 
147
        {
 
148
                //nothing to save
 
149
                if (param_->empty()) return;
 
150
                filename_=QFileDialog::getSaveFileName(this,tr("Save ini file"),default_dir_.c_str(),tr("ini files (*.ini)"));
 
151
                //not file selected
 
152
                if(filename_.isEmpty())
 
153
                {
 
154
                        return;
 
155
                }
 
156
                if(!filename_.endsWith(".ini")) filename_.append(".ini");
 
157
                editor_->store();
 
158
                arg_param_.insert(tool_name_ + ":1:", *param_);
 
159
                try
 
160
                {
 
161
                        QString tmp_ini_file = File::getTempDirectory().toQString() + QDir::separator() + "TOPPAS_" + tool_name_.toQString() + "_";
 
162
                        if (tool_type_ != "")
 
163
                        {
 
164
                                tmp_ini_file += tool_type_.toQString() + "_";
 
165
                        }
 
166
                        tmp_ini_file += File::getUniqueName().toQString() + "_tmp.ini";
 
167
                        //store current parameters
 
168
                        arg_param_.store(tmp_ini_file.toStdString());
 
169
                        //restore other parameters that might be missing
 
170
                        String call = String("\"") + File::getExecutablePath() + tool_name_ + "\"" + " -write_ini " + String(filename_) + " -ini " + String(tmp_ini_file);
 
171
                        if (tool_type_ != "")
 
172
                        {
 
173
                                call += " -type " + tool_type_;
 
174
                        }
 
175
                        
 
176
                        if (system(call.c_str()) != 0)
 
177
                        {
 
178
                                QMessageBox::critical(0, "Error", (String("Could not execute '") + call + "'!\n\nMake sure the TOPP tools are present in '" + File::getExecutablePath() + "', that you have permission to write to the temporary file path, and that there is space left in the temporary file path.").c_str());
 
179
                                return;
 
180
                        }
 
181
                }
 
182
                catch(Exception::BaseException& e)
 
183
                {
 
184
                        QMessageBox::critical(this,"Error",(String("Error storing INI file: ")+e.getMessage()).c_str());
 
185
                        return;
 
186
                }
 
187
        }
 
188
}
 
189