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 #ifndef _U2_ACTORPROTOTYPE_H_
23 #define _U2_ACTORPROTOTYPE_H_
24 
25 #include <QMimeData>
26 #include <QObject>
27 
28 #include <U2Lang/Descriptor.h>
29 #include <U2Lang/Port.h>
30 
31 namespace U2 {
32 class Attribute;
33 class AttributeScript;
34 class ConfigurationEditor;
35 class ConfigurationValidator;
36 namespace Workflow {
37 
38 class Prompter;
39 
40 /**
41  * Actor represents particular semantic template
42  * and can be configured via set of template-specific parameters
43  * ActorPrototype is such a template
44  */
45 class U2LANG_EXPORT ActorPrototype : public QObject, public VisualDescriptor {
46     Q_OBJECT
47 public:
48     ActorPrototype(const Descriptor &desc,
49                    const QList<PortDescriptor *> &ports = QList<PortDescriptor *>(),
50                    const QList<Attribute *> &attrs = QList<Attribute *>());
51     virtual ~ActorPrototype();
52 
53     QList<PortDescriptor *> getPortDesciptors() const;
54 
55     QList<Attribute *> getAttributes() const;
56     Attribute *getAttribute(const QString &id) const;
57     void addAttribute(Attribute *a);
58     int removeAttribute(Attribute *attr);
59 
60     void setEditor(ConfigurationEditor *e);
61     ConfigurationEditor *getEditor() const;
62 
63     // validator has setter but no getter
64     void setValidator(ConfigurationValidator *v);
65 
66     // prompter has no getter
67     void setPrompter(Prompter *p);
68 
69     // port validators has no getters
70     // all validators will be used as validator in corresponding port
71     // see createInstance()
72     void setPortValidator(const QString &id, ConfigurationValidator *v);
73 
74     // for drag'n'drop purposes
75     virtual bool isAcceptableDrop(const QMimeData *, QVariantMap * = nullptr) const;
76 
77     virtual Actor *createInstance(const ActorId &actorId, AttributeScript *script = nullptr, const QVariantMap &params = QVariantMap());
78 
79     void setDisplayName(const QString &n) override;
80 
81     void setDocumentation(const QString &d) override;
82 
83     void setScriptFlag(bool flag = true);
isScriptFlagSet()84     bool isScriptFlagSet() {
85         return isScript;
86     }
87     void setSchema(const QString &path);
88     void setNonStandard(const QString &path);
isStandardFlagSet()89     bool isStandardFlagSet() {
90         return isStandard;
91     }
isSchemaFlagSet()92     bool isSchemaFlagSet() {
93         return isSchema;
94     }
isExternalTool()95     bool isExternalTool() {
96         return !isStandard && !isSchema && !isScript;
97     }
getFilePath()98     QString getFilePath() {
99         return actorFilePath;
100     }
101 
isAllowsEmptyPorts()102     bool isAllowsEmptyPorts() const {
103         return allowsEmptyPorts;
104     }
setAllowsEmptyPorts(bool value)105     void setAllowsEmptyPorts(bool value) {
106         allowsEmptyPorts = value;
107     }
108 
getInfluenceOnPathFlag()109     bool getInfluenceOnPathFlag() const {
110         return influenceOnPathFlag;
111     }
setInfluenceOnPathFlag(bool value)112     void setInfluenceOnPathFlag(bool value) {
113         influenceOnPathFlag = value;
114     }
115 
116     void addExternalTool(const QString &toolId, const QString &paramId = "");
117     const StrStrMap &getExternalTools() const;
118     void clearExternalTools();
119     int getUsageCounter() const;
120 
121 signals:
122     void si_nameChanged();
123     void si_descriptionChanged();
124 
125 protected:
126     // create port and sets p as owner of new port
127     // caller should add created port to actor's ports see createInstance
128     virtual Port *createPort(const PortDescriptor &d, Actor *p);
129 
130 protected:
131     // list of attributes
132     // can be changed via addAttribute and removeAttribute
133     QList<Attribute *> attrs;
134     // list of port's
135     // real Port's are created via createPort
136     QList<PortDescriptor *> ports;
137     // controller for actor's configuration editor
138     ConfigurationEditor *ed;
139     // makes any non-trivial validations
140     ConfigurationValidator *val;
141     // some realization of Prompter (e.g. PrompterBaseImpl)
142     Prompter *prompter;
143     // as if each port is configuration
144     // we need port validators
145     // QString here - id of corresponding PortDescriptor
146     QMap<QString, ConfigurationValidator *> portValidators;
147     // actor can be written on a script by user
148     // in such case user can define attributes and input, output ports of actor
149     bool isScript;
150     // actor can be a standard actor or external tool or script actor included from file
151     bool isStandard;
152     // if actor is non standard then its meta is kept in actorFilePath
153     QString actorFilePath;
154     // actor can implement some big schema
155     bool isSchema;
156 
157     bool allowsEmptyPorts;
158     bool influenceOnPathFlag;
159 
160     // toolId <-> parameterId (optional)
161     // The actor could use external tools. The map shows what tools are used.
162     // Also the path to a tool can be set in a parameter. In this case the value of map is the parameter's id;
163     // otherwise the value is empty string.
164     StrStrMap externalTools;
165 
166 private slots:
167     void sl_onActorDestruction();
168 
169 private:
170     int usageCounter;
171 };  // ActorPrototype
172 
173 }  // namespace Workflow
174 }  // namespace U2
175 
176 #endif  // _U2_ACTORPROTOTYPE_H_
177