-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.h
136 lines (107 loc) · 2.97 KB
/
Node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef NODE_H
#define NODE_H
#include <QString>
#include <QVector>
#include <QPoint>
#include <QColor>
#include "Socket.h"
#include "Edge.h"
#include "Serializable.h"
#include "GraphicsNode.h"
enum NodeType {
Time = 0,
Sin,
Float,
Vec3,
Sphere,
Plane,
Min,
Out
};
class Node : public Serializable
{
public:
Node(const QString &title = QString());
void setPosition(int x, int y);
QPoint getPosition();
void setColor(const QColor &col);
QColor getColor();
// Any node can be eval'd if all the input sockets have edges and the nodes at those edges can be eva'ld
bool canEval() {
if (getInputSockets().isEmpty()) return true;
for (auto socket : getInputSockets()) {
if (!socket->getEdges().isEmpty()) return false;
auto parent = socket->getEdges().first()->getOutputSocket()->getParent();
if (parent) {
if (parent->canEval()) {
return true;
}
else return false;
} else {
return false;
}
}
return true;
}
QString evaldCode;
QVector<QPair<QString, QString>> code;
virtual QPair<QString, QString> eval(QStringList &code) {
return QPair<QString, QString>();
}
NodeType type;
void setDimensions(QSize size) {
dimensions = size;
}
QSize getDimensions() {
return dimensions;
}
QVector<Socket*> getInputSockets();
QVector<Socket*> getOutputSockets();
bool allInputsAreValid() {
for (auto socket : getInputSockets()) {
if (!socket->hasEdge()) return false;
}
return true;
}
const QString getTitle();
Socket *getSocketByIndex(Type type, int index) {
if (type == Type::INTO) {
return inputs.at(index);
} else {
return outputs.at(index);
}
}
void addSocket(Type, Location);
void setRenderer(GraphicsNode *gNode) {
graphicsNode = gNode;
// Maybe the renderer should read properties from the model?
graphicsNode->setTitle(this->getTitle());
graphicsNode->setSize(this->getDimensions());
graphicsNode->setPos(this->getPosition());
graphicsNode->setColor(this->getColor());
graphicsNode->setModel(this);
}
GraphicsNode *getRenderer() {
return graphicsNode;
}
void update() {
updateConnectedEdges();
}
void updateConnectedEdges();
virtual QJsonObject serialize() override;
virtual Node* deserialize(const QJsonObject, NodeScene *ns) override;
void addSocket(Socket *socket);
QPoint getSocketPositionFromLocation(Location location);
QString id;
protected:
QString title;
QString variable;
QPoint pos;
QColor color;
QSize dimensions;
QVector<Socket*> inputs;
QVector<Socket*> outputs;
GraphicsNode *graphicsNode;
QString variablePostFix;
};
#endif // NODE_H