don't police data type connections between nodes

Nodes were previously written to be "strongly typed" in that a parameter's
"type" enforced whether it could be connected to another. All code related
to that has now been removed since not only is it hard to maintain and
likely unnecessary, it's possible the nodes will work differently later on
anyway.
This commit is contained in:
itsmattkc
2019-10-25 00:44:14 +11:00
parent 076f2699c5
commit 4d96ac9e39
24 changed files with 83 additions and 249 deletions
+1 -62
View File
@@ -48,7 +48,7 @@ const QString NodeParam::id()
QString NodeParam::name()
{
if (name_.isEmpty()) {
return GetDefaultDataTypeName(data_type());
return tr("Value");
}
return name_;
@@ -86,61 +86,6 @@ void NodeParam::DisconnectAll()
}
}
bool NodeParam::AreDataTypesCompatible(NodeParam *a, NodeParam *b)
{
// Make sure one is an input and one is an output
if (a->type() == b->type()) {
return false;
}
NodeInput* input;
NodeOutput* output;
// Work out which parameter is which
if (a->type() == NodeParam::kInput) {
input = static_cast<NodeInput*>(a);
output = static_cast<NodeOutput*>(b);
} else {
input = static_cast<NodeInput*>(b);
output = static_cast<NodeOutput*>(a);
}
return AreDataTypesCompatible(output->data_type(), input->inputs());
}
bool NodeParam::AreDataTypesCompatible(const NodeParam::DataType &output_type, const NodeParam::DataType &input_type)
{
if (input_type == output_type) {
return true;
}
if (input_type == kNone) {
return false;
}
if (input_type == kAny) {
return true;
}
// Allow for up-converting integers to floats (but not the other way around)
if (output_type == kInt && input_type == kFloat) {
return true;
}
return false;
}
bool NodeParam::AreDataTypesCompatible(const DataType &output_type, const QList<DataType>& input_types)
{
for (int i=0;i<input_types.size();i++) {
if (AreDataTypesCompatible(output_type, input_types.at(i))) {
return true;
}
}
return false;
}
NodeEdgePtr NodeParam::ConnectEdge(NodeOutput *output, NodeInput *input)
{
// If the input can only accept one input (the default) and has one already, disconnect it
@@ -153,12 +98,6 @@ NodeEdgePtr NodeParam::ConnectEdge(NodeOutput *output, NodeInput *input)
}
}
// Refuse to make a connection that is incompatible
if (!input->can_accept_type(output->data_type())) {
qWarning() << tr("Tried to make an invalid Node connection");
return nullptr;
}
// Ensure both nodes are in the same graph
if (output->parent()->parent() != input->parent()->parent()) {
qWarning() << tr("Tried to connect two nodes that aren't part of the same graph");