alignment_widget.cpp 4.65 KB
Newer Older
Benoit Valot's avatar
Benoit Valot committed
1
2
3
4
5
6
7
8
9
10
11
/*
 * alignment_widget.cpp
 *
 *  Created on: 1 août 2012
 *      Author: valot
 */

#include "alignment_widget.h"
#include <QMessageBox>

AlignmentWidget::AlignmentWidget(QWidget * parent):
Benoit Valot's avatar
Benoit Valot committed
12
MasschroQWidget(parent){
13

14
15
16
	_loadingThreadRef = new MsrunSimpleLoaderThread();
	_loadingThreadRef->setMaxProgress(2);
	connect(_loadingThreadRef, SIGNAL(loadedMsrun(Msrun *)), this,
Benoit Valot's avatar
Benoit Valot committed
17
			SLOT(doneLoadindMsrunRef(Msrun *)));
18
	connect(_loadingThreadRef, SIGNAL(errorDuringLoading(QString)), this,
Benoit Valot's avatar
Benoit Valot committed
19
20
			SLOT(errorLoadindMsrunRef(QString)));

21
22
23
	_loadingThreadToAligned = new MsrunSimpleLoaderThread();
	_loadingThreadToAligned->setMaxProgress(2);
	connect(_loadingThreadToAligned, SIGNAL(loadedMsrun(Msrun *)), this,
Benoit Valot's avatar
Benoit Valot committed
24
			SLOT(doneLoadindMsrunAligned(Msrun *)));
25
	connect(_loadingThreadToAligned, SIGNAL(errorDuringLoading(QString)), this,
Benoit Valot's avatar
Benoit Valot committed
26
27
			SLOT(errortLoadindMsrunAligned(QString)));

28
29
30
	_alignment_thread = new AlignmentThread();
	_alignment_thread->setMaxProgress(2);
	connect(_alignment_thread, SIGNAL(finishAlignment()), this,
Benoit Valot's avatar
Benoit Valot committed
31
			SLOT(doneAlignment()));
32
	connect(_alignment_thread, SIGNAL(errorDuringAlignment(QString)), this,
Benoit Valot's avatar
Benoit Valot committed
33
34
35
36
			SLOT(errorAlignment(QString)));
}

AlignmentWidget::~AlignmentWidget() {
37

Benoit Valot's avatar
Benoit Valot committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
}

void AlignmentWidget::doneLoadindMsrunRef(Msrun * ref){
	_msrunRef = ref;
	if(_msrunRef==0){
		this->viewError("Msrun Ref are null?");
		_loadingMsrunRefLabel->stopLoading("");
	}else{
		_loadingMsrunRefLabel->stopLoading("MsRun correctly load");
		this->completDataToMsrun(_msrunRef);
	}
}

void AlignmentWidget::doneLoadindMsrunAligned(Msrun * aligned){
	_msunToAligned = aligned;
	if(_msunToAligned==0){
		this->viewError("Msrun aligned are null?");
		_loadingMsruntoALignedLabel->stopLoading("");
	}else{
		_loadingMsruntoALignedLabel->stopLoading("MsRun correctly load");
		this->completDataToMsrun(_msunToAligned);
	}
}

void AlignmentWidget::viewError(QString error) {
	QMessageBox::warning(this, tr("Oops! an error occurred in MassChroQ. Dont Panic :"),
			error);
}

QString AlignmentWidget::strippedFilename(const QString & fullFilename) {
	return QFileInfo(fullFilename).fileName();
}

void AlignmentWidget::errorAlignment(QString error){
	_runningQLabel->stopLoading("");
	this->viewError(error);
}

void AlignmentWidget::errorLoadindMsrunRef(QString error){
	_loadingMsrunRefLabel->stopLoading("Problems");
	_msrunRef=0;
	this->viewError(error);
}

void AlignmentWidget::errortLoadindMsrunAligned(QString error){
	_loadingMsruntoALignedLabel->stopLoading("Problems");
	_msunToAligned=0;
	this->viewError(error);
}

void AlignmentWidget::deleteMsrun(Msrun * msrun){
	if(msrun!=0){
		delete(msrun);
		msrun=0;
	}
}

void AlignmentWidget::completDataToMsrun(Msrun * msrun){
	qDebug()<<"Complete data to Msrun";
}

void AlignmentWidget::doneAlignment() {
Olivier Langella's avatar
Olivier Langella committed
100
    qDebug()<< "AlignmentWidget::doneAlignment begin";
Benoit Valot's avatar
Benoit Valot committed
101
	_runningQLabel->stopLoading("");
102
	this->emitSignalDoneAlignement();
Olivier Langella's avatar
Olivier Langella committed
103
     qDebug()<< "AlignmentWidget::doneAlignment end";
Benoit Valot's avatar
Benoit Valot committed
104
105
106
}

void AlignmentWidget::startAlignment() {
107
108
109
110
	if (this->isLoadingRunning()) {
		this->viewError(tr("Unable to start alignment while loading MsRuns.\n Please wait"));
		return;
	}
Benoit Valot's avatar
Benoit Valot committed
111
112
113
	if (_msunToAligned == 0) {
		this->viewError(
				tr(
114
						"There is no MsRun to align.\n Please choose one!"));
Benoit Valot's avatar
Benoit Valot committed
115
116
117
118
		return;
	} else if (_msrunRef == 0) {
		this->viewError(
				tr(
119
						"There is no MsRun reference.\n Please choose one!"));
Benoit Valot's avatar
Benoit Valot committed
120
121
122
		return;
	}
	_runningQLabel->startLoading("Alignment in progress");
123
	_alignment_thread->performedAlignment(_alignmentBase, _msrunRef,
Benoit Valot's avatar
Benoit Valot committed
124
125
			_msunToAligned);
}
126
127
128
129
130
131
132

void AlignmentWidget::deleteLoadingThread(){
	qDebug()<<"delete Loading thread";
	delete(_loadingThreadRef);
	delete(_loadingThreadToAligned);
	delete(_alignment_thread);
}
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

void AlignmentWidget::triggerLoadingMsRunToAlign(Msrun * msrun) {
	if (msrun != 0) {
		//_text_edit_ref->setText(msrun->getXmlFileInfo().fileName());
		this->_loadingMsruntoALignedLabel->startLoading("Loading");
		_loadingThreadToAligned->loadMsrun(msrun);
 		this->deleteMsrun(this->_msunToAligned);
	} else {
		this->viewError(
				tr(
						"There is no MsRun to align.\n Please choose one!"));
		return;
	}
}

void AlignmentWidget::triggerLoadingMsRunRef(Msrun * msrun) {
	if (msrun != 0) {
		//_text_edit_ref->setText(msrun->getXmlFileInfo().fileName());
		_loadingMsrunRefLabel->startLoading("Loading");
		_loadingThreadRef->loadMsrun(msrun);
		this->deleteMsrun(_msrunRef);
	} else {
		this->viewError(
				tr(
						"There is no MsRun reference.\n Please choose one!"));
		return;
	}
}

bool AlignmentWidget::isAlignmentRunning() {
	if(_alignment_thread->isRunning()) return true;
	return false;
}
166
167
168
169
170
171

bool AlignmentWidget::isLoadingRunning() {
	if(_loadingThreadToAligned->isRunning()) return true;
	if(_loadingThreadRef->isRunning()) return true;
	return false;
}