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

« back to all changes in this revision

Viewing changes to source/VISUAL/TOPPASInputFileListVertex.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

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
 
1
// --------------------------------------------------------------------------
 
2
//                   OpenMS -- Open-Source Mass Spectrometry
 
3
// --------------------------------------------------------------------------
 
4
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
 
5
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
 
6
//
 
7
// This software is released under a three-clause BSD license:
 
8
//  * Redistributions of source code must retain the above copyright
 
9
//    notice, this list of conditions and the following disclaimer.
 
10
//  * Redistributions in binary form must reproduce the above copyright
 
11
//    notice, this list of conditions and the following disclaimer in the
 
12
//    documentation and/or other materials provided with the distribution.
 
13
//  * Neither the name of any author or any participating institution
 
14
//    may be used to endorse or promote products derived from this software
 
15
//    without specific prior written permission.
 
16
// For a full list of authors, refer to the file AUTHORS.
 
17
// --------------------------------------------------------------------------
 
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
19
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
20
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
21
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
 
22
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
23
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
25
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
26
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
27
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
28
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
29
//
23
30
// --------------------------------------------------------------------------
24
31
// $Maintainer: Johannes Junker $
41
48
 
42
49
namespace OpenMS
43
50
{
44
 
        TOPPASInputFileListVertex::TOPPASInputFileListVertex()
45
 
                :       TOPPASVertex(),
46
 
                        key_()
47
 
        {
48
 
                pen_color_ = Qt::black;
49
 
                brush_color_ = Qt::lightGray;
50
 
        }
51
 
        
52
 
        TOPPASInputFileListVertex::TOPPASInputFileListVertex(const QStringList& files)
53
 
                :       TOPPASVertex(),
54
 
                        key_()
55
 
        {
56
 
                pen_color_ = Qt::black;
57
 
                brush_color_ = Qt::lightGray;
 
51
  TOPPASInputFileListVertex::TOPPASInputFileListVertex() :
 
52
    TOPPASVertex(),
 
53
    key_()
 
54
  {
 
55
    pen_color_ = Qt::black;
 
56
    brush_color_ = Qt::lightGray;
 
57
  }
 
58
 
 
59
  TOPPASInputFileListVertex::TOPPASInputFileListVertex(const QStringList & files) :
 
60
    TOPPASVertex(),
 
61
    key_()
 
62
  {
 
63
    pen_color_ = Qt::black;
 
64
    brush_color_ = Qt::lightGray;
58
65
    setFilenames(files);
59
 
        }
60
 
        
61
 
        TOPPASInputFileListVertex::TOPPASInputFileListVertex(const TOPPASInputFileListVertex& rhs)
62
 
                :       TOPPASVertex(rhs),
63
 
                        key_()
64
 
        {
65
 
                pen_color_ = Qt::black;
66
 
                brush_color_ = Qt::lightGray;
67
 
        }
68
 
        
69
 
        TOPPASInputFileListVertex::~TOPPASInputFileListVertex()
70
 
        {
71
 
        
72
 
        }
73
 
        
74
 
        TOPPASInputFileListVertex& TOPPASInputFileListVertex::operator= (const TOPPASInputFileListVertex& rhs)
75
 
        {
76
 
                TOPPASVertex::operator=(rhs);
77
 
                
78
 
                key_ = rhs.key_;
79
 
                
80
 
                return *this;
81
 
        }
82
 
        
83
 
        void TOPPASInputFileListVertex::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* /*e*/)
84
 
        {
85
 
                showFilesDialog();
86
 
        }
87
 
        
88
 
        void TOPPASInputFileListVertex::showFilesDialog()
89
 
        {
 
66
  }
 
67
 
 
68
  TOPPASInputFileListVertex::TOPPASInputFileListVertex(const TOPPASInputFileListVertex & rhs) :
 
69
    TOPPASVertex(rhs),
 
70
    key_()
 
71
  {
 
72
    pen_color_ = Qt::black;
 
73
    brush_color_ = Qt::lightGray;
 
74
  }
 
75
 
 
76
  TOPPASInputFileListVertex::~TOPPASInputFileListVertex()
 
77
  {
 
78
 
 
79
  }
 
80
 
 
81
  TOPPASInputFileListVertex & TOPPASInputFileListVertex::operator=(const TOPPASInputFileListVertex & rhs)
 
82
  {
 
83
    TOPPASVertex::operator=(rhs);
 
84
 
 
85
    key_ = rhs.key_;
 
86
 
 
87
    return *this;
 
88
  }
 
89
 
 
90
  String TOPPASInputFileListVertex::getName() const
 
91
  {
 
92
    return "InputVertex";
 
93
  }
 
94
 
 
95
  void TOPPASInputFileListVertex::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * /*e*/)
 
96
  {
 
97
    showFilesDialog();
 
98
  }
 
99
 
 
100
  void TOPPASInputFileListVertex::showFilesDialog()
 
101
  {
90
102
    TOPPASInputFilesDialog tifd(this->getFileNames());
91
 
                if (tifd.exec())
92
 
                {
 
103
    if (tifd.exec())
 
104
    {
93
105
      QStringList updated_filelist;
94
 
                        tifd.getFilenames(updated_filelist);
 
106
      tifd.getFilenames(updated_filelist);
95
107
      this->setFilenames(updated_filelist); // to correct filenames (separators etc)
96
 
                        qobject_cast<TOPPASScene*>(scene())->setChanged(true);
97
 
                        qobject_cast<TOPPASScene*>(scene())->updateEdgeColors();
98
 
                        emit somethingHasChanged();
99
 
                }
100
 
        }
101
 
        
102
 
 
103
 
        
104
 
        void TOPPASInputFileListVertex::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
105
 
        {
106
 
                QPen pen(pen_color_, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
107
 
                if (isSelected())
108
 
                {
109
 
                        pen.setWidth(2);
110
 
                        painter->setBrush(brush_color_.darker(130));
111
 
                        pen.setColor(Qt::darkBlue);
112
 
                }
113
 
                else
114
 
                {
115
 
                        painter->setBrush(brush_color_);
116
 
                }
117
 
                painter->setPen(pen);
118
 
                
119
 
                QPainterPath path;
120
 
                path.addRoundRect(-70.0, -40.0, 140.0, 80.0, 20, 20);           
121
 
                painter->drawPath(path);
122
 
                
123
 
                pen.setColor(pen_color_);
124
 
                painter->setPen(pen);
 
108
      qobject_cast<TOPPASScene *>(scene())->setChanged(true);
 
109
      qobject_cast<TOPPASScene *>(scene())->updateEdgeColors();
 
110
      emit somethingHasChanged();
 
111
    }
 
112
  }
 
113
 
 
114
  void TOPPASInputFileListVertex::paint(QPainter * painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
 
115
  {
 
116
    QPen pen(pen_color_, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
117
    if (isSelected())
 
118
    {
 
119
      pen.setWidth(2);
 
120
      painter->setBrush(brush_color_.darker(130));
 
121
      pen.setColor(Qt::darkBlue);
 
122
    }
 
123
    else
 
124
    {
 
125
      painter->setBrush(brush_color_);
 
126
    }
 
127
    painter->setPen(pen);
 
128
 
 
129
    QPainterPath path;
 
130
    path.addRoundRect(-70.0, -40.0, 140.0, 80.0, 20, 20);
 
131
    painter->drawPath(path);
 
132
 
 
133
    pen.setColor(pen_color_);
 
134
    painter->setPen(pen);
 
135
 
 
136
    // display number of input files
125
137
    QString text = QString::number(getFileNames().size())
126
138
                   + " input file"
127
 
                                                                         + (getFileNames().size() == 1 ? "" : "s");
128
 
                QRectF text_boundings = painter->boundingRect(QRectF(0,0,0,0), Qt::AlignCenter, text);
129
 
                painter->drawText(-(int)(text_boundings.width()/2.0), (int)(text_boundings.height()/4.0), text);
130
 
 
131
 
                //topo sort number
 
139
                   + (getFileNames().size() == 1 ? "" : "s");
 
140
    QRectF text_boundings = painter->boundingRect(QRectF(0, 0, 0, 0), Qt::AlignCenter, text);
 
141
    painter->drawText(-(int)(text_boundings.width() / 2.0), (int)(text_boundings.height() / 4.0), text);
 
142
 
 
143
    // display file type(s)
 
144
    Map<QString, Size> suffices;
 
145
    foreach(QString fn, getFileNames())
 
146
    {
 
147
      QStringList l = QFileInfo(fn).completeSuffix().split('.');
 
148
      QString suf = ((l.size() > 1 && l[l.size() - 2].size() <= 4) ? l[l.size() - 2] + "." : QString()) + l.back(); // take up to two dots as suffix (the first only if its <=4 chars, e.g. we want ".prot.xml" or ".tar.gz", but not "stupid.filename.with.longdots.mzML")
 
149
      ++suffices[suf];
 
150
    }
 
151
    StringList text_l;
 
152
    for (Map<QString, Size>::const_iterator sit = suffices.begin(); sit != suffices.end(); ++sit)
 
153
    {
 
154
      if (suffices.size() > 1)
 
155
        text_l.push_back(String(".") + sit->first + "(" + String(sit->second) + ")");
 
156
      else
 
157
        text_l.push_back(String(".") + sit->first);
 
158
    }
 
159
    text = text_l.concatenate(" | ").toQString();
 
160
    text_boundings = painter->boundingRect(QRectF(0, 0, 0, 0), Qt::AlignCenter, text);
 
161
    painter->drawText(-(int)(text_boundings.width() / 2.0), 35 - (int)(text_boundings.height() / 4.0), text);
 
162
 
 
163
    // topological sort number
132
164
    qreal x_pos = -63.0;
133
165
    qreal y_pos = -19.0;
134
166
    painter->drawText(x_pos, y_pos, QString::number(topo_nr_));
135
 
        
136
 
                // recycling status
 
167
 
 
168
    // recycling status
137
169
    if (this->allow_output_recycling_)
138
170
    {
139
171
      painter->setPen(Qt::green);
140
 
      QSvgRenderer* svg_renderer = new QSvgRenderer(QString(":/Recycling_symbol.svg"), 0);
 
172
      QSvgRenderer * svg_renderer = new QSvgRenderer(QString(":/Recycling_symbol.svg"), 0);
141
173
      svg_renderer->render(painter, QRectF(-7, -32, 14, 14));
142
174
    }
143
 
                
144
 
  }
145
 
        
146
 
        QRectF TOPPASInputFileListVertex::boundingRect() const
147
 
        {
148
 
                return QRectF(-71,-41,142,82);
149
 
        }
150
 
        
151
 
        QPainterPath TOPPASInputFileListVertex::shape () const
152
 
        {
153
 
                QPainterPath shape;
154
 
                shape.addRoundRect(-71.0, -41.0, 142.0, 81.0, 20, 20);
155
 
                return shape;
156
 
        }
157
 
        
158
 
        bool TOPPASInputFileListVertex::fileNamesValid()
159
 
        {
 
175
 
 
176
  }
 
177
 
 
178
  QRectF TOPPASInputFileListVertex::boundingRect() const
 
179
  {
 
180
    return QRectF(-71, -41, 142, 82);
 
181
  }
 
182
 
 
183
  QPainterPath TOPPASInputFileListVertex::shape() const
 
184
  {
 
185
    QPainterPath shape;
 
186
    shape.addRoundRect(-71.0, -41.0, 142.0, 81.0, 20, 20);
 
187
    return shape;
 
188
  }
 
189
 
 
190
  bool TOPPASInputFileListVertex::fileNamesValid()
 
191
  {
160
192
    QStringList fl = getFileNames();
161
 
    foreach (const QString& file, fl)
162
 
                {
 
193
    foreach(const QString &file, fl)
 
194
    {
163
195
      if (!File::exists(file))
164
196
      {
165
 
                                return false;
 
197
        return false;
166
198
      }
167
 
                }
 
199
    }
168
200
    return true;
169
 
        }
170
 
        
171
 
        void TOPPASInputFileListVertex::openContainingFolder()
172
 
        {
 
201
  }
 
202
 
 
203
  void TOPPASInputFileListVertex::openContainingFolder()
 
204
  {
173
205
    std::set<String> directories;
174
206
    QStringList fl = getFileNames();
175
 
    for (int i = 0; i < fl.size(); ++i)
176
 
    { // collect unique directories
 
207
    for (int i = 0; i < fl.size(); ++i) // collect unique directories
 
208
    {
177
209
      QFileInfo fi(fl[i]);
178
210
      directories.insert(String(QFileInfo(fi.canonicalFilePath()).path()));
179
211
    }
180
212
 
181
213
    // open them
182
 
    for (std::set<String>::const_iterator it=directories.begin();it!=directories.end();++it)
 
214
    for (std::set<String>::const_iterator it = directories.begin(); it != directories.end(); ++it)
183
215
    {
184
216
      QString path = QDir::toNativeSeparators(it->toQString());
 
217
#if defined(__APPLE__)
 
218
      QProcess* p = new QProcess();
 
219
      p->setProcessChannelMode(QProcess::ForwardedChannels);
 
220
      QStringList app_args;
 
221
      app_args.append(path);
 
222
      p->start("/usr/bin/open", app_args);
 
223
      if (!p->waitForStarted())
 
224
      {
 
225
        // execution failed
 
226
        QMessageBox::warning(0, "Open Folder Error", "The folder " + path + " could not be opened!");
 
227
        LOG_ERROR << "Failed to open folder " << path.toStdString() << std::endl;
 
228
        LOG_ERROR << p->errorString().toStdString() << std::endl;
 
229
      }
 
230
#else
185
231
      if (!QDir(path).exists() || (!QDesktopServices::openUrl(QUrl("file:///" + path, QUrl::TolerantMode))))
186
232
      {
187
233
        QMessageBox::warning(0, "Open Folder Error", String("The folder " + path + " could not be opened!").toQString());
188
234
      }
 
235
#endif
189
236
    }
190
 
        }
191
 
        
192
 
        void TOPPASInputFileListVertex::run()
193
 
        {
 
237
  }
 
238
 
 
239
  void TOPPASInputFileListVertex::run()
 
240
  {
194
241
    round_total_   = (int) output_files_.size(); // for now each file is one round; for the future we might allow to create blocks of files (e.g. for replicate measurements)
195
242
    round_counter_ = (int) round_total_;
196
243
 
198
245
 
199
246
    //std::cerr << "#" << this->getTopoNr() << " set #rounds: " << round_total_ << "\n";
200
247
 
201
 
                for (EdgeIterator it = outEdgesBegin(); it != outEdgesEnd(); ++it)
202
 
                {
203
 
                        TOPPASVertex* tv = (*it)->getTargetVertex();
204
 
                        if (tv && !tv->isFinished()) // this tool might have already been called by another path, so do not call it again (as this will throw an error)
205
 
                        {
206
 
                                tv->run();
207
 
                        }
208
 
                }
209
 
        }
210
 
        
211
 
        void TOPPASInputFileListVertex::setKey(const QString& key)
212
 
        {
213
 
                key_ = key;
214
 
                setToolTip(key);
215
 
        }
216
 
        
217
 
        const QString& TOPPASInputFileListVertex::getKey()
218
 
        {
219
 
                return key_;
220
 
        }
221
 
        
222
 
        void TOPPASInputFileListVertex::setFilenames(const QStringList& files)
223
 
        {
 
248
    for (ConstEdgeIterator it = outEdgesBegin(); it != outEdgesEnd(); ++it)
 
249
    {
 
250
      TOPPASVertex * tv = (*it)->getTargetVertex();
 
251
      if (tv && !tv->isFinished())       // this tool might have already been called by another path, so do not call it again (as this will throw an error)
 
252
      {
 
253
        tv->run();
 
254
      }
 
255
    }
 
256
  }
 
257
 
 
258
  void TOPPASInputFileListVertex::setKey(const QString & key)
 
259
  {
 
260
    key_ = key;
 
261
  }
 
262
 
 
263
  const QString & TOPPASInputFileListVertex::getKey()
 
264
  {
 
265
    return key_;
 
266
  }
 
267
 
 
268
  void TOPPASInputFileListVertex::setFilenames(const QStringList & files)
 
269
  {
224
270
    output_files_.clear();
225
271
    output_files_.resize(files.size()); // for now, assume one file per round (we could later extend that)
226
 
    for (int f=0; f<files.size(); ++f)
 
272
    for (int f = 0; f < files.size(); ++f)
227
273
    {
228
274
      output_files_[f][-1].filenames << QDir::toNativeSeparators(files[f]);
229
275
    }
230
 
        }
231
 
        
 
276
 
 
277
    setToolTip(files.join("\n"));
 
278
  }
 
279
 
 
280
  void TOPPASInputFileListVertex::outEdgeHasChanged()
 
281
  {
 
282
    reset(true);
 
283
    qobject_cast<TOPPASScene *>(scene())->updateEdgeColors();
 
284
    TOPPASVertex::outEdgeHasChanged();
 
285
  }
 
286
 
232
287
}