Skip to content
Snippets Groups Projects
Commit c55cf4a4 authored by Charles Villard's avatar Charles Villard
Browse files

edit: Node: fix optional inputs in node treated as input graph

parent 100e2ef6
No related branches found
No related tags found
No related merge requests found
Pipeline #57195 failed
...@@ -225,10 +225,10 @@ public: ...@@ -225,10 +225,10 @@ public:
if ((inputCategory(i) == InputCategory::Data || inputCategory(i) == InputCategory::OptionalData) if ((inputCategory(i) == InputCategory::Data || inputCategory(i) == InputCategory::OptionalData)
&& input(i).second == gk_IODefaultIndex) && input(i).second == gk_IODefaultIndex)
{ {
break; return i;
} }
} }
return (i < nbInputs()) ? i : gk_IODefaultIndex; return gk_IODefaultIndex;
} }
......
...@@ -149,7 +149,9 @@ bool Aidge::Node::valid() const { ...@@ -149,7 +149,9 @@ bool Aidge::Node::valid() const {
Aidge::IOIndex_t Aidge::Node::getNbFreeDataInputs() const { Aidge::IOIndex_t Aidge::Node::getNbFreeDataInputs() const {
IOIndex_t nbFreeDataIn = 0; IOIndex_t nbFreeDataIn = 0;
for (IOIndex_t i = 0; i < nbInputs(); ++i) { for (IOIndex_t i = 0; i < nbInputs(); ++i) {
if (input(i).second == gk_IODefaultIndex) { if ((inputCategory(i) == InputCategory::Data
|| inputCategory(i) == InputCategory::OptionalData)
&& input(i).second == gk_IODefaultIndex) {
++nbFreeDataIn; ++nbFreeDataIn;
} }
} }
...@@ -289,10 +291,17 @@ void Aidge::Node::addChild(std::shared_ptr<Node> otherNode, const IOIndex_t outI ...@@ -289,10 +291,17 @@ void Aidge::Node::addChild(std::shared_ptr<Node> otherNode, const IOIndex_t outI
void Aidge::Node::addChild(std::shared_ptr<GraphView> otherView, const IOIndex_t outId, void Aidge::Node::addChild(std::shared_ptr<GraphView> otherView, const IOIndex_t outId,
std::pair<std::shared_ptr<Node>, IOIndex_t> otherInId) { std::pair<std::shared_ptr<Node>, IOIndex_t> otherInId) {
if (!otherInId.first) { if (!otherInId.first) {
AIDGE_ASSERT(otherView->inputNodes().size() == 1U, AIDGE_ASSERT(otherView->getNbFreeDataInputs() == 1U,
"Input node of GraphView {} need to be specified, because it has more than one input ({} inputs), when trying to add it as a child of node {} (of type {})", "Input node of GraphView {} need to be specified, because it has more than one input ({} inputs), when trying to add it as a child of node {} (of type {})",
otherView->name(), otherView->inputNodes().size(), name(), type()); otherView->name(), otherView->inputNodes().size(), name(), type());
otherInId.first = *(otherView->inputNodes().begin());
otherInId.first = *(std::find_if(
otherView->inputNodes().begin(),
otherView->inputNodes().end(),
[](const auto &node) {
return node->getFirstFreeDataInput() != gk_IODefaultIndex;
}
));
} }
otherInId.second = (otherInId.second != gk_IODefaultIndex) otherInId.second = (otherInId.second != gk_IODefaultIndex)
? otherInId.second ? otherInId.second
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment