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 "GrouperOutSlot.h"
23
24 #include <QVariant>
25
26 #include <U2Lang/BaseTypes.h>
27
28 namespace U2 {
29
30 /************************************************************************/
31 /* ActionTypes */
32 /************************************************************************/
33 const QString ActionTypes::MERGE_SEQUENCE = QString("merge-sequence");
34 const QString ActionTypes::SEQUENCE_TO_MSA = QString("sequence-to-msa");
35 const QString ActionTypes::MERGE_MSA = QString("merge-msa");
36 const QString ActionTypes::MERGE_STRING = QString("merge-string");
37 const QString ActionTypes::MERGE_ANNS = QString("merge-annotations");
38
isValidType(const QString & type)39 bool ActionTypes::isValidType(const QString &type) {
40 bool result = false;
41
42 result |= (MERGE_SEQUENCE == type);
43 result |= (SEQUENCE_TO_MSA == type);
44 result |= (MERGE_MSA == type);
45 result |= (MERGE_STRING == type);
46 result |= (MERGE_ANNS == type);
47
48 return result;
49 }
50
getDataTypeByAction(const QString & actionType)51 DataTypePtr ActionTypes::getDataTypeByAction(const QString &actionType) {
52 if (MERGE_SEQUENCE == actionType) {
53 return BaseTypes::DNA_SEQUENCE_TYPE();
54 } else if (SEQUENCE_TO_MSA == actionType) {
55 return BaseTypes::MULTIPLE_ALIGNMENT_TYPE();
56 } else if (MERGE_MSA == actionType) {
57 return BaseTypes::MULTIPLE_ALIGNMENT_TYPE();
58 } else if (MERGE_STRING == actionType) {
59 return BaseTypes::STRING_TYPE();
60 } else if (MERGE_ANNS == actionType) {
61 return BaseTypes::ANNOTATION_TABLE_TYPE();
62 } else {
63 assert(false);
64 return DataTypePtr();
65 }
66 }
67
68 /************************************************************************/
69 /* ActionParameters */
70 /************************************************************************/
71 const QString ActionParameters::GAP = QString("gap");
72 const QString ActionParameters::UNIQUE = QString("unique");
73 const QString ActionParameters::SEPARATOR = QString("separator");
74 const QString ActionParameters::MSA_NAME = QString("msa-name");
75 const QString ActionParameters::SEQ_NAME = QString("seq-name");
76 const QString ActionParameters::SEQ_SLOT = QString("seq-slot");
77
getType(const QString & parameter)78 ActionParameters::ParameterType ActionParameters::getType(const QString ¶meter) {
79 if (GAP == parameter) {
80 return INTEGER;
81 } else if (UNIQUE == parameter) {
82 return BOOLEAN;
83 } else if (SEPARATOR == parameter) {
84 return STRING;
85 } else if (MSA_NAME == parameter) {
86 return STRING;
87 } else if (SEQ_NAME == parameter) {
88 return STRING;
89 } else if (SEQ_SLOT == parameter) {
90 return STRING;
91 }
92
93 assert(false);
94 return STRING;
95 }
96
isValidParameter(const QString & actionType,const QString & parameter)97 bool ActionParameters::isValidParameter(const QString &actionType, const QString ¶meter) {
98 bool result = false;
99 if (ActionTypes::MERGE_SEQUENCE == actionType) {
100 result |= (GAP == parameter);
101 result |= (SEQ_NAME == parameter);
102 } else if (ActionTypes::SEQUENCE_TO_MSA == actionType) {
103 result |= (UNIQUE == parameter);
104 result |= (MSA_NAME == parameter);
105 } else if (ActionTypes::MERGE_MSA == actionType) {
106 result |= (UNIQUE == parameter);
107 result |= (MSA_NAME == parameter);
108 } else if (ActionTypes::MERGE_STRING == actionType) {
109 result |= (SEPARATOR == parameter);
110 } else if (ActionTypes::MERGE_ANNS == actionType) {
111 result |= (UNIQUE == parameter);
112 result |= (SEQ_SLOT == parameter);
113 }
114
115 return result;
116 }
117
118 /************************************************************************/
119 /* GrouperSlotAction */
120 /************************************************************************/
GrouperSlotAction(const QString & type)121 GrouperSlotAction::GrouperSlotAction(const QString &type)
122 : type(type) {
123 }
124
GrouperSlotAction(const GrouperSlotAction & other)125 GrouperSlotAction::GrouperSlotAction(const GrouperSlotAction &other)
126 : type(other.type), parameters(other.parameters) {
127 }
128
getType() const129 QString GrouperSlotAction::getType() const {
130 return type;
131 }
132
getParameters() const133 const QVariantMap &GrouperSlotAction::getParameters() const {
134 return parameters;
135 }
136
hasParameter(const QString & parameterId) const137 bool GrouperSlotAction::hasParameter(const QString ¶meterId) const {
138 return parameters.contains(parameterId);
139 }
140
getParameterValue(const QString & parameterId) const141 QVariant GrouperSlotAction::getParameterValue(const QString ¶meterId) const {
142 return parameters.value(parameterId, QVariant());
143 }
144
setParameterValue(const QString & parameterId,const QVariant & value)145 void GrouperSlotAction::setParameterValue(const QString ¶meterId, const QVariant &value) {
146 parameters[parameterId] = value;
147 }
148
149 /************************************************************************/
150 /* GroupOperations */
151 /************************************************************************/
BY_VALUE()152 Descriptor GroupOperations::BY_VALUE() {
153 return Descriptor("by-value", QObject::tr("By value"), QObject::tr("By value"));
154 }
155
BY_NAME()156 Descriptor GroupOperations::BY_NAME() {
157 return Descriptor("by-name", QObject::tr("By name"), QObject::tr("By name"));
158 }
159
BY_ID()160 Descriptor GroupOperations::BY_ID() {
161 return Descriptor("by-id", QObject::tr("By id"), QObject::tr("By id"));
162 }
163
164 /************************************************************************/
165 /* GrouperOutSlot */
166 /************************************************************************/
GrouperOutSlot(const QString & outSlotId,const QString & inSlotStr)167 GrouperOutSlot::GrouperOutSlot(const QString &outSlotId, const QString &inSlotStr)
168 : outSlotId(outSlotId), inSlotStr(inSlotStr), action(nullptr) {
169 }
170
GrouperOutSlot(const GrouperOutSlot & another)171 GrouperOutSlot::GrouperOutSlot(const GrouperOutSlot &another) {
172 outSlotId = another.outSlotId;
173 inSlotStr = another.inSlotStr;
174 if (nullptr == another.action) {
175 action = nullptr;
176 } else {
177 action = new GrouperSlotAction(*another.action);
178 }
179 }
180
~GrouperOutSlot()181 GrouperOutSlot::~GrouperOutSlot() {
182 delete action;
183 }
184
operator ==(const GrouperOutSlot & other) const185 bool GrouperOutSlot::operator==(const GrouperOutSlot &other) const {
186 return this->outSlotId == other.outSlotId;
187 }
188
getAction()189 GrouperSlotAction *GrouperOutSlot::getAction() {
190 return action;
191 }
192
getAction() const193 GrouperSlotAction *GrouperOutSlot::getAction() const {
194 return action;
195 }
196
setAction(const GrouperSlotAction & action)197 void GrouperOutSlot::setAction(const GrouperSlotAction &action) {
198 delete this->action;
199 this->action = new GrouperSlotAction(action);
200 }
201
getOutSlotId() const202 QString GrouperOutSlot::getOutSlotId() const {
203 return outSlotId;
204 }
205
setOutSlotId(const QString & outSlotId)206 void GrouperOutSlot::setOutSlotId(const QString &outSlotId) {
207 this->outSlotId = outSlotId;
208 }
209
getInSlotStr() const210 QString GrouperOutSlot::getInSlotStr() const {
211 return inSlotStr;
212 }
213
setInSlotStr(const QString & slotStr)214 void GrouperOutSlot::setInSlotStr(const QString &slotStr) {
215 this->inSlotStr = slotStr;
216 }
217
setBusMapInSlotStr(const QString & busMapSlotStr)218 void GrouperOutSlot::setBusMapInSlotStr(const QString &busMapSlotStr) {
219 QString result = busMapSlotStr;
220 result.replace(":", ".");
221
222 this->inSlotStr = result;
223 }
224
getBusMapInSlotId() const225 QString GrouperOutSlot::getBusMapInSlotId() const {
226 QString result = inSlotStr;
227 result.replace(".", ":");
228
229 return result;
230 }
231
readable2busMap(const QString & readableSlotStr)232 QString GrouperOutSlot::readable2busMap(const QString &readableSlotStr) {
233 QString result = readableSlotStr;
234 result.replace(".", ":");
235
236 return result;
237 }
238
busMap2readable(const QString & busMapSlotStr)239 QString GrouperOutSlot::busMap2readable(const QString &busMapSlotStr) {
240 QString result = busMapSlotStr;
241 result.replace(":", ".");
242
243 return result;
244 }
245
246 } // namespace U2
247