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

« back to all changes in this revision

Viewing changes to src/plugins/workflow_designer/src/library/DocActors.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
 
* Unipro UGENE - Integrated Bioinformatics Suite
3
 
* Copyright (C) 2008 Unipro, Russia (http://ugene.unipro.ru)
4
 
* All Rights Reserved
5
 
6
 
*     This source code is distributed under the terms of the
7
 
*     GNU General Public License. See the files COPYING and LICENSE
8
 
*     for details.
9
 
*****************************************************************/
 
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
 */
10
21
 
11
22
#include "DocActors.h"
12
23
#include "CoreLib.h"
13
24
 
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>
20
33
 
21
 
namespace GB2 {
 
34
namespace U2 {
22
35
namespace Workflow {
23
36
 
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) 
29
 
{
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)));
33
 
    if (!multi) {
34
 
        setValidator(new ScreenedParamValidator(CoreLib::URL_ATTR_ID, ports.first()->getId(), CoreLib::URL_SLOT_ID));
35
 
    }
36
 
}
37
 
 
38
 
bool DocActorProto::isAcceptableDrop(const QMimeData* md, QVariantMap* params) const {
 
37
/****************************
 
38
 * DocActorProto
 
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) {
 
42
}
 
43
 
 
44
DocActorProto::DocActorProto(const Descriptor& _desc, const GObjectType& t, const QList<PortDescriptor*>& _ports,
 
45
                             const QList<Attribute*>& _attrs ) : IntegralBusActorPrototype(_desc, _ports, _attrs), type(t) {
 
46
}
 
47
 
 
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()) {
43
53
            if (params) {
44
 
                params->insert(CoreLib::URL_ATTR_ID, url);
 
54
                params->insert( urlAttrId, url );
45
55
            }
46
56
            return true;
47
57
        }
48
58
    }
49
 
 
50
59
    return false;
51
60
}
52
61
 
 
62
QString DocActorProto::prepareDocumentFilter() {
 
63
    if( !fid.isEmpty() ) {
 
64
        return DialogUtils::prepareDocumentsFileFilter( fid, true );
 
65
    } else {
 
66
        assert( !type.isEmpty() );
 
67
        return DialogUtils::prepareDocumentsFileFilterByObjType( type, true );
 
68
    }
 
69
}
 
70
 
 
71
/****************************
 
72
 * ReadDocActorProto
 
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 ) );
 
80
}
 
81
 
 
82
bool ReadDocActorProto::isAcceptableDrop(const QMimeData * md, QVariantMap * params ) const {
 
83
    return DocActorProto::isAcceptableDrop( md, params, BaseAttributes::URL_IN_ATTRIBUTE().getId() );
 
84
}
 
85
 
 
86
/****************************
 
87
 * WriteDocActorProto
 
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) {
 
92
    construct();
 
93
}
 
94
 
 
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) {
 
98
    construct();
 
99
}
 
100
 
 
101
bool WriteDocActorProto::isAcceptableDrop(const QMimeData * md, QVariantMap * params ) const {
 
102
    return DocActorProto::isAcceptableDrop( md, params, BaseAttributes::URL_OUT_ATTRIBUTE().getId() );
 
103
}
 
104
 
 
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);
 
108
 
 
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);
 
113
 
 
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()));
 
117
}
 
118
 
 
119
URLDelegate *WriteDocActorProto::getUrlDelegate() {
 
120
    return urlDelegate;
 
121
}
 
122
 
 
123
/****************************
 
124
 * WriteGenbankPrompter
 
125
 *****************************/
53
126
QString WriteGenbankPrompter::composeRichDoc() {
54
 
    BusPort* input = qobject_cast<BusPort*>(target->getPort(CoreLib::DATA_PORT_ID));
55
 
 
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);
61
134
    }
62
 
 
63
 
    QString url = getURL(CoreLib::URL_ATTR_ID);
 
135
    
 
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);
 
139
    
64
140
    QString data;
65
141
    if (seqName.isEmpty() && annName.isEmpty()) {
66
 
        return url;
 
142
        QString doc = tr("Write sequence(s) in Genbank format to <u>%1</u>.").arg(url);
 
143
        return doc;
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);
69
146
    } else {
70
 
        data = tr("For each ") + seqName + annName;
 
147
        data = tr("each ") + seqName + annName;
71
148
    }
72
 
 
73
 
    QString extra;
74
 
    //     Actor* acnProducer = input->getProducer(CoreLib::GENBANK_ACN_SLOT.getId());
75
 
    //     if (!acnProducer) {
76
 
    //         extra = tr("<br>Autogenerate ACN.");
77
 
    //     }
78
 
 
79
 
    QString doc = tr("%1, add Genbank entry to document <u>%2</u>.%3")
80
 
        .arg(data) //sequence from Read Fasta 1
81
 
        .arg(url) 
82
 
        .arg(extra);
83
 
 
84
 
    return doc;
 
149
    
 
150
    return tr("Write %1 in Genbank format, to <u>%2</u>.")
 
151
        .arg(data)
 
152
        .arg(url);
85
153
}
86
154
 
 
155
/****************************
 
156
 * WriteFastaPrompter
 
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);
90
164
 
91
 
    Actor* seqProducer = input->getProducer(BioActorLibrary::SEQ_SLOT_ID);
 
165
    Actor* seqProducer = input->getProducer(BaseSlots::DNA_SEQUENCE_SLOT().getId());
92
166
    if (!seqProducer) {
93
 
        return url;
 
167
        QString doc = tr("Writes sequence(s) in %1 format to <u>%2</u>.").arg(format).arg(url);
 
168
        return doc;
94
169
    }
95
170
 
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())
 
173
        .arg(format)
98
174
        .arg(url);
99
175
 
100
176
    return doc;
101
177
}
102
178
 
 
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()));
 
185
    }
 
186
    return doc;
 
187
}
 
188
 
 
189
/****************************
 
190
 * WriteDocPrompter
 
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);
 
197
    
 
198
    QString producers = getProducers(outPortId, slot);
107
199
    if (producers.isEmpty()) {
108
 
        return url;
 
200
        QString unsetStr = "<font color='red'>"+tr("unset")+"</font>";
 
201
        return spec.arg(unsetStr).arg(url);
109
202
    }
110
203
    return spec.arg(producers).arg(url);
111
204
}
112
205
 
 
206
/****************************
 
207
 * ReadDocPrompter
 
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)));
115
212
}
 
213
 
116
214
}//namespace Workflow
117
 
}//namespace GB2
 
215
}//namespace U2