1
/*****************************************************************
2
* Unipro UGENE - Integrated Bioinformatics Suite
3
* Copyright (C) 2008 Unipro, Russia (http://ugene.unipro.ru)
6
* This source code is distributed under the terms of the
7
* GNU General Public License. See the files COPYING and LICENSE
9
*****************************************************************/
2
* UGENE - Integrated Bioinformatics Tools.
3
* Copyright (C) 2008-2011 UniPro <ugene@unipro.ru>
4
* http://ugene.unipro.ru
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.
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.
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,
11
22
#include "DocActors.h"
12
23
#include "CoreLib.h"
14
#include <workflow_support/CoreDataTypes.h>
15
#include <workflow_support/DelegateEditors.h>
16
#include <workflow_library/BioDatatypes.h>
17
#include <workflow_library/BioActorLibrary.h>
18
#include <core_api/DocumentModel.h>
19
#include <util_gui/DialogUtils.h>
25
#include <U2Designer/DelegateEditors.h>
26
#include <U2Lang/CoreLibConstants.h>
27
#include <U2Lang/BaseTypes.h>
28
#include <U2Lang/BaseSlots.h>
29
#include <U2Lang/BaseAttributes.h>
30
#include <U2Core/DocumentModel.h>
31
#include <U2Core/SaveDocumentTask.h>
32
#include <U2Misc/DialogUtils.h>
22
35
namespace Workflow {
24
DocActorProto::DocActorProto(const DocumentFormatId& fid, bool multi,
25
const Descriptor& desc,
26
const QList<PortDescriptor*>& ports,
27
const QList<Attribute*>& _attrs) :
28
BusActorPrototype(desc, ports, _attrs), fid(fid)
30
attrs << new Attribute(CoreLib::URL_ATTR(), CoreDataTypes::STRING_TYPE(), multi);
31
setEditor(new DelegateEditor(CoreLib::URL_ATTR_ID,
32
new URLDelegate(DialogUtils::prepareDocumentsFileFilter(fid, true), QString(), multi)));
34
setValidator(new ScreenedParamValidator(CoreLib::URL_ATTR_ID, ports.first()->getId(), CoreLib::URL_SLOT_ID));
38
bool DocActorProto::isAcceptableDrop(const QMimeData* md, QVariantMap* params) const {
37
/****************************
39
*****************************/
40
DocActorProto::DocActorProto(const DocumentFormatId& _fid, const Descriptor& _desc, const QList<PortDescriptor*>& _ports,
41
const QList<Attribute*>& _attrs ) : IntegralBusActorPrototype(_desc, _ports, _attrs), fid(_fid) {
44
DocActorProto::DocActorProto(const Descriptor& _desc, const GObjectType& t, const QList<PortDescriptor*>& _ports,
45
const QList<Attribute*>& _attrs ) : IntegralBusActorPrototype(_desc, _ports, _attrs), type(t) {
48
bool DocActorProto::isAcceptableDrop(const QMimeData * md, QVariantMap * params, const QString & urlAttrId ) const {
39
49
QList<DocumentFormat*> fs;
40
QString url = DesignerUtils::getDropUrl(fs, md);
50
QString url = WorkflowUtils::getDropUrl(fs, md);
41
51
foreach(DocumentFormat* df, fs) {
42
52
if (fid == df->getFormatId()) {
44
params->insert(CoreLib::URL_ATTR_ID, url);
54
params->insert( urlAttrId, url );
62
QString DocActorProto::prepareDocumentFilter() {
63
if( !fid.isEmpty() ) {
64
return DialogUtils::prepareDocumentsFileFilter( fid, true );
66
assert( !type.isEmpty() );
67
return DialogUtils::prepareDocumentsFileFilterByObjType( type, true );
71
/****************************
73
*****************************/
74
ReadDocActorProto::ReadDocActorProto(const DocumentFormatId& _fid, const Descriptor& _desc, const QList<PortDescriptor*>& _ports,
75
const QList<Attribute*>& _attrs ) : DocActorProto( _fid, _desc, _ports, _attrs ) {
76
attrs << new Attribute( BaseAttributes::URL_IN_ATTRIBUTE(), BaseTypes::STRING_TYPE(), true );
77
QMap< QString, PropertyDelegate* > delegateMap;
78
delegateMap[BaseAttributes::URL_IN_ATTRIBUTE().getId()] = new URLDelegate( prepareDocumentFilter(), QString(), true );
79
setEditor( new DelegateEditor( delegateMap ) );
82
bool ReadDocActorProto::isAcceptableDrop(const QMimeData * md, QVariantMap * params ) const {
83
return DocActorProto::isAcceptableDrop( md, params, BaseAttributes::URL_IN_ATTRIBUTE().getId() );
86
/****************************
88
*****************************/
89
WriteDocActorProto::WriteDocActorProto(const DocumentFormatId& _fid, const Descriptor& _desc, const QList<PortDescriptor*>& _ports,
90
const QString & portId, const QList<Attribute*>& _attrs)
91
: DocActorProto( _fid, _desc, _ports, _attrs ), outPortId(portId), urlDelegate(NULL) {
95
WriteDocActorProto::WriteDocActorProto(const Descriptor& _desc, const GObjectType & t, const QList<PortDescriptor*>& _ports,
96
const QString & portId, const QList<Attribute*>& _attrs)
97
: DocActorProto(_desc, t, _ports, _attrs), outPortId(portId), urlDelegate(NULL) {
101
bool WriteDocActorProto::isAcceptableDrop(const QMimeData * md, QVariantMap * params ) const {
102
return DocActorProto::isAcceptableDrop( md, params, BaseAttributes::URL_OUT_ATTRIBUTE().getId() );
105
void WriteDocActorProto::construct() {
106
attrs << new Attribute(BaseAttributes::URL_OUT_ATTRIBUTE(), BaseTypes::STRING_TYPE(), false );
107
attrs << new Attribute(BaseAttributes::FILE_MODE_ATTRIBUTE(), BaseTypes::NUM_TYPE(), false, SaveDoc_Roll);
109
QMap< QString, PropertyDelegate* > delegateMap;
110
urlDelegate = new URLDelegate(prepareDocumentFilter(), QString(), false, false, true, 0, fid);
111
delegateMap[BaseAttributes::URL_OUT_ATTRIBUTE().getId()] = urlDelegate;
112
delegateMap[BaseAttributes::FILE_MODE_ATTRIBUTE().getId()] = new FileModeDelegate(attrs.size() > 2);
114
setEditor(new DelegateEditor(delegateMap));
115
setValidator(new ScreenedParamValidator(BaseAttributes::URL_OUT_ATTRIBUTE().getId(), ports.first()->getId(), BaseSlots::URL_SLOT().getId()));
116
setPortValidator(outPortId, new ScreenedSlotValidator(BaseSlots::URL_SLOT().getId()));
119
URLDelegate *WriteDocActorProto::getUrlDelegate() {
123
/****************************
124
* WriteGenbankPrompter
125
*****************************/
53
126
QString WriteGenbankPrompter::composeRichDoc() {
54
BusPort* input = qobject_cast<BusPort*>(target->getPort(CoreLib::DATA_PORT_ID));
56
Actor* seqProducer = input->getProducer(BioActorLibrary::SEQ_SLOT_ID);
127
QString outPortId = target->getInputPorts().first()->getId();
128
IntegralBusPort* input = qobject_cast<IntegralBusPort*>(target->getPort(outPortId));
129
Actor* seqProducer = input->getProducer(BaseSlots::DNA_SEQUENCE_SLOT().getId());
57
130
QString seqName = seqProducer ? tr(" sequence from <u>%1</u>").arg(seqProducer->getLabel()) : "";
58
QString annName = getProducers(CoreLib::DATA_PORT_ID, BioActorLibrary::FEATURE_TABLE_SLOT_ID);
131
QString annName = getProducers(outPortId, BaseSlots::ANNOTATION_TABLE_SLOT().getId());
59
132
if (!annName.isEmpty()) {
60
133
annName = tr(" set of annotations from <u>%1</u>").arg(annName);
63
QString url = getURL(CoreLib::URL_ATTR_ID);
136
QString url = getScreenedURL( qobject_cast<IntegralBusPort*>(target->getPort(outPortId)),
137
BaseAttributes::URL_OUT_ATTRIBUTE().getId(), BaseSlots::URL_SLOT().getId() );
138
url = getHyperlink(BaseAttributes::URL_OUT_ATTRIBUTE().getId(), url);
65
141
if (seqName.isEmpty() && annName.isEmpty()) {
142
QString doc = tr("Write sequence(s) in Genbank format to <u>%1</u>.").arg(url);
67
144
} else if (!seqName.isEmpty() && !annName.isEmpty()) {
68
data = tr("For each %1 and %2").arg(seqName).arg(annName);
145
data = tr("each %1 and %2").arg(seqName).arg(annName);
70
data = tr("For each ") + seqName + annName;
147
data = tr("each ") + seqName + annName;
74
// Actor* acnProducer = input->getProducer(CoreLib::GENBANK_ACN_SLOT.getId());
75
// if (!acnProducer) {
76
// extra = tr("<br>Autogenerate ACN.");
79
QString doc = tr("%1, add Genbank entry to document <u>%2</u>.%3")
80
.arg(data) //sequence from Read Fasta 1
150
return tr("Write %1 in Genbank format, to <u>%2</u>.")
155
/****************************
157
*****************************/
87
158
QString WriteFastaPrompter::composeRichDoc() {
88
BusPort* input = qobject_cast<BusPort*>(target->getPort(CoreLib::DATA_PORT_ID));
89
QString url = getURL(CoreLib::URL_ATTR_ID);
159
QString outPortId = target->getInputPorts().first()->getId();
160
IntegralBusPort* input = qobject_cast<IntegralBusPort*>(target->getPort(outPortId));
161
QString url = getScreenedURL( qobject_cast<IntegralBusPort*>(target->getPort(outPortId)),
162
BaseAttributes::URL_OUT_ATTRIBUTE().getId(), BaseSlots::URL_SLOT().getId() );
163
url = getHyperlink(BaseAttributes::URL_OUT_ATTRIBUTE().getId(), url);
91
Actor* seqProducer = input->getProducer(BioActorLibrary::SEQ_SLOT_ID);
165
Actor* seqProducer = input->getProducer(BaseSlots::DNA_SEQUENCE_SLOT().getId());
92
166
if (!seqProducer) {
167
QString doc = tr("Writes sequence(s) in %1 format to <u>%2</u>.").arg(format).arg(url);
96
QString doc = tr("For each sequence from <u>%1</u>, add entry to document <u>%2</u>.")
171
QString doc = tr("Writes sequence(s) from <u>%1</u> in %2 format to <u>%3</u>.")
97
172
.arg(seqProducer->getLabel())
179
ActorDocument* WriteFastaPrompter::createDescription(Actor* a) {
180
WriteFastaPrompter* doc = new WriteFastaPrompter(format, a);
181
doc->connect(a, SIGNAL(si_labelChanged()), SLOT(sl_actorModified()));
182
doc->connect(a, SIGNAL(si_modified()), SLOT(sl_actorModified()));
183
foreach(Workflow::Port* input, a->getInputPorts()) {
184
doc->connect(input, SIGNAL(bindingChanged()), SLOT(sl_actorModified()));
189
/****************************
191
*****************************/
103
192
QString WriteDocPrompter::composeRichDoc() {
104
BusPort* input = qobject_cast<BusPort*>(target->getPort(CoreLib::DATA_PORT_ID));
105
QString url = getURL(CoreLib::URL_ATTR_ID);
106
QString producers = getProducers(CoreLib::DATA_PORT_ID, slot);
193
QString outPortId = target->getInputPorts().first()->getId();
194
QString url = getScreenedURL( qobject_cast<IntegralBusPort*>(target->getPort(outPortId)),
195
BaseAttributes::URL_OUT_ATTRIBUTE().getId(), BaseSlots::URL_SLOT().getId() );
196
url = getHyperlink(BaseAttributes::URL_OUT_ATTRIBUTE().getId(), url);
198
QString producers = getProducers(outPortId, slot);
107
199
if (producers.isEmpty()) {
200
QString unsetStr = "<font color='red'>"+tr("unset")+"</font>";
201
return spec.arg(unsetStr).arg(url);
110
203
return spec.arg(producers).arg(url);
206
/****************************
208
*****************************/
113
209
QString ReadDocPrompter::composeRichDoc() {
114
return spec.arg(getURL(CoreLib::URL_ATTR_ID));
210
const QString& id = BaseAttributes::URL_IN_ATTRIBUTE().getId();
211
return spec.arg(getHyperlink(id, getURL(id)));
116
214
}//namespace Workflow