1 /**
2 * UGENE - Integrated Bioinformatics Tools.
3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4 * http://ugene.net
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 "SelectorActors.h"
23
24 #include <U2Core/U2SafePoints.h>
25
26 #include <U2Lang/ActorPrototypeRegistry.h>
27 #include <U2Lang/SelectorValue.h>
28 #include <U2Lang/WorkflowEnv.h>
29 #include <U2Lang/WorkflowUtils.h>
30
31 namespace U2 {
32
SelectorActors()33 SelectorActors::SelectorActors() {
34 widget = nullptr;
35 srcActor = nullptr;
36 }
37
SelectorActors(ElementSelectorWidget * _widget,const QList<Actor * > & allActors,U2OpStatus & os)38 SelectorActors::SelectorActors(ElementSelectorWidget *_widget, const QList<Actor *> &allActors, U2OpStatus &os)
39 : widget(_widget) {
40 srcActor = WorkflowUtils::actorById(allActors, widget->getActorId());
41 if (nullptr == srcActor) {
42 os.setError(QObject::tr("Unknown actor id: %1").arg(widget->getActorId()));
43 return;
44 }
45
46 foreach (const SelectorValue &value, widget->getValues()) {
47 Actor *a = nullptr;
48 if (value.getProtoId() == srcActor->getProto()->getId()) {
49 a = srcActor;
50 } else {
51 ActorPrototype *proto = WorkflowEnv::getProtoRegistry()->getProto(value.getProtoId());
52 a = proto->createInstance(widget->getActorId());
53 }
54 actors[value.getValue()] = a;
55 }
56 }
57
~SelectorActors()58 SelectorActors::~SelectorActors() {
59 }
60
getActor(const QString & value) const61 Actor *SelectorActors::getActor(const QString &value) const {
62 return actors.value(value, nullptr);
63 }
64
getSourceActor() const65 Actor *SelectorActors::getSourceActor() const {
66 return srcActor;
67 }
68
getMappings(const QString & value) const69 QList<PortMapping> SelectorActors::getMappings(const QString &value) const {
70 foreach (const SelectorValue &sv, widget->getValues()) {
71 if (sv.getValue() == value) {
72 return sv.getMappings();
73 }
74 }
75 return QList<PortMapping>();
76 }
77
78 } // namespace U2
79