~ubuntu-branches/debian/jessie/ugene/jessie

« back to all changes in this revision

Viewing changes to src/corelibs/U2View/src/util_dna_assembly/BuildIndexDialog.cpp

  • Committer: Package Import Robot
  • Author(s): Steffen Moeller
  • Date: 2011-11-02 13:29:07 UTC
  • mfrom: (1.2.1) (3.1.11 natty)
  • Revision ID: package-import@ubuntu.com-20111102132907-o34gwnt0uj5g6hen
Tags: 1.9.8+repack-1
* First release to Debian
  - added README.Debian
  - increased policy version to 3.9.2
  - added URLs for version control system
* Added debug package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * UGENE - Integrated Bioinformatics Tools.
 
3
 * Copyright (C) 2008-2011 UniPro <ugene@unipro.ru>
 
4
 * http://ugene.unipro.ru
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; either version 2
 
9
 * of the License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
19
 * MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#include "BuildIndexDialog.h"
 
23
#include "DnaAssemblyGUIExtension.h"
 
24
 
 
25
#include <U2Algorithm/DnaAssemblyAlgRegistry.h>
 
26
#include <U2Core/GUrlUtils.h>
 
27
#include <U2Misc/DialogUtils.h>
 
28
#include <U2Core/DocumentUtils.h>
 
29
 
 
30
#include <QtGui/QFileDialog>
 
31
#include <QtGui/QMessageBox>
 
32
 
 
33
 
 
34
namespace U2 {
 
35
 
 
36
QString BuildIndexDialog::genomePath;
 
37
 
 
38
BuildIndexDialog::BuildIndexDialog(const DnaAssemblyAlgRegistry* registry, QWidget* p)
 
39
: QDialog(p), assemblyRegistry(registry), customGUI(NULL)
 
40
{
 
41
        setupUi(this);
 
42
        QStringList names = registry->getRegisteredAlgorithmsWithIndexFileSupport();
 
43
        methodNamesBox->addItems(names);
 
44
        // TODO: change the way default method is set
 
45
        if (names.size() > 0) {
 
46
                methodNamesBox->setCurrentIndex(names.size() - 1);
 
47
        }
 
48
        sl_onAlgorithmChanged(methodNamesBox->currentText());
 
49
        connect(setIndexFileNameButton, SIGNAL(clicked()), SLOT(sl_onSetIndexFileNameButtonClicked()));
 
50
        connect(addRefButton, SIGNAL(clicked()), SLOT(sl_onAddRefButtonClicked()) );
 
51
        connect(methodNamesBox, SIGNAL(currentIndexChanged(const QString &)), SLOT(sl_onAlgorithmChanged(const QString &)));
 
52
 
 
53
        if (!genomePath.isEmpty()) {
 
54
                refSeqEdit->setText(genomePath);
 
55
                buildIndexUrl(genomePath);
 
56
        }
 
57
}
 
58
 
 
59
void BuildIndexDialog::sl_onAddRefButtonClicked() {
 
60
        LastOpenDirHelper lod;
 
61
        QString filter;
 
62
 
 
63
        lod.url = QFileDialog::getOpenFileName(this, tr("Open reference sequence"), lod.dir, filter);
 
64
        if (lod.url.isEmpty()) {
 
65
                return;
 
66
        }
 
67
 
 
68
        refSeqEdit->setText(lod.url);
 
69
        buildIndexUrl(lod.url);
 
70
}
 
71
 
 
72
void BuildIndexDialog::sl_onSetIndexFileNameButtonClicked() {
 
73
        LastOpenDirHelper lod;
 
74
        lod.url = QFileDialog::getSaveFileName(this, tr("Set index file name"), lod.dir);
 
75
        if (!lod.url.isEmpty()) {
 
76
                GUrl index = lod.url;
 
77
                if (index.lastFileSuffix().isEmpty() && customGUI != NULL) {
 
78
                        QString extension = customGUI->getIndexFileExtension();
 
79
                        if (extension.isEmpty()) {
 
80
                                index = QString( "%1" ).arg( index.getURLString() );
 
81
                        } else {
 
82
                                index = QString( "%1.%2" ).arg( index.getURLString() ).arg(extension);
 
83
                        }
 
84
                }
 
85
                indexFileNameEdit->setText(index.getURLString());
 
86
        }
 
87
}
 
88
 
 
89
void BuildIndexDialog::sl_onAlgorithmChanged(const QString &) {
 
90
        updateState();
 
91
}
 
92
 
 
93
void BuildIndexDialog::updateState() {
 
94
        addGuiExtension();
 
95
}
 
96
 
 
97
void BuildIndexDialog::addGuiExtension() {
 
98
        int insertPos = verticalLayout->count() - 2;
 
99
 
 
100
        // cleanup previous extension
 
101
        if (customGUI != NULL) {
 
102
                layout()->removeWidget(customGUI);         
 
103
                setMinimumHeight(minimumHeight() - customGUI->minimumHeight());
 
104
                delete customGUI;
 
105
                customGUI = NULL;
 
106
        }
 
107
 
 
108
        // insert new extension widget
 
109
        DnaAssemblyAlgorithmEnv* env = assemblyRegistry->getAlgorithm(methodNamesBox->currentText());
 
110
        if (NULL == env) {
 
111
                adjustSize();
 
112
                return;
 
113
        }
 
114
    DnaAssemblyGUIExtensionsFactory* gui = env->getGUIExtFactory();
 
115
    if (gui!=NULL && gui->hasBuildIndexWidget()) {
 
116
                customGUI = gui->createBuildIndexWidget(this);
 
117
                int extensionMinWidth = customGUI->sizeHint().width();
 
118
                int extensionMinHeight = customGUI->sizeHint().height();
 
119
                customGUI->setMinimumWidth(extensionMinWidth);
 
120
                customGUI->setMinimumHeight(extensionMinHeight);
 
121
                verticalLayout->insertWidget(insertPos, customGUI);
 
122
                // adjust sizes
 
123
                setMinimumHeight(customGUI->minimumHeight() + minimumHeight());
 
124
                if (minimumWidth() < customGUI->minimumWidth()) {
 
125
                        setMinimumWidth(customGUI->minimumWidth());
 
126
                }
 
127
                if (!refSeqEdit->text().isEmpty()) {
 
128
                        buildIndexUrl(refSeqEdit->text());
 
129
                }
 
130
                customGUI->show();
 
131
        } else {
 
132
                adjustSize();
 
133
        }
 
134
}
 
135
 
 
136
void BuildIndexDialog::buildIndexUrl(const GUrl& refUrl ) {
 
137
        QString extension("");
 
138
        if (NULL != customGUI) {
 
139
                extension = customGUI->getIndexFileExtension();
 
140
        customGUI->buildIndexUrl(refUrl);
 
141
        }
 
142
        GUrl url;
 
143
        if (extension.isEmpty()) {
 
144
                url = GUrlUtils::rollFileName(refUrl.dirPath() + "/" + refUrl.baseFileName(), DocumentUtils::getNewDocFileNameExcludesHint());
 
145
        } else {
 
146
                url = GUrlUtils::rollFileName(refUrl.dirPath() + "/" + refUrl.baseFileName()+ "." + extension, DocumentUtils::getNewDocFileNameExcludesHint());
 
147
        }
 
148
        
 
149
        indexFileNameEdit->setText(url.getURLString());
 
150
}
 
151
 
 
152
void BuildIndexDialog::accept()
 
153
{
 
154
        if (refSeqEdit->text().isEmpty()) {
 
155
                QMessageBox::information(this, tr("Build index"), tr("Reference sequence url is not set!") );
 
156
        } else if (indexFileNameEdit->text().isEmpty() ) {
 
157
                QMessageBox::information(this, tr("Build index"), tr("Index file name is not set!") );
 
158
        } else {   
 
159
                genomePath.clear();
 
160
                genomePath = refSeqEdit->text();
 
161
 
 
162
                QDialog::accept();
 
163
        }
 
164
}
 
165
 
 
166
const GUrl BuildIndexDialog::getRefSeqUrl() {
 
167
        return refSeqEdit->text();
 
168
}
 
169
 
 
170
const QString BuildIndexDialog::getAlgorithmName() {
 
171
        return methodNamesBox->currentText();
 
172
}
 
173
 
 
174
const QString BuildIndexDialog::getIndexFileName() {
 
175
        return indexFileNameEdit->text();
 
176
}
 
177
 
 
178
QMap<QString, QVariant> BuildIndexDialog::getCustomSettings() {
 
179
        if (customGUI != NULL) {
 
180
                return customGUI->getBuildIndexCustomSettings();
 
181
        } else {
 
182
                return QMap<QString, QVariant>();
 
183
        }
 
184
}
 
185
 
 
186
}//namespace