Skip to content

Commit 86acb1d

Browse files
authored
Improve handling of top-level inputs in Graph Editor (#2830)
- Fix setting of interface names on connection - Copies logic from commit: [PR](#2785) - This is a general logic fix. 09f66bb - Fix connection renaming setting on input rename. Was not considering nodegraph to upstream connections
1 parent b26de54 commit 86acb1d

2 files changed

Lines changed: 35 additions & 9 deletions

File tree

source/MaterialXCore/Interface.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ void Input::setConnectedInterfaceName(const string& interfaceName)
249249
if (!interfaceName.empty())
250250
{
251251
ConstGraphElementPtr graph = getAncestorOfType<GraphElement>();
252+
if (graph && graph == getParent())
253+
{
254+
// This element is a direct child of a graph element, so its
255+
// interface name references a value element in the parent scope.
256+
ConstElementPtr graphParent = graph->getParent();
257+
graph = graphParent ? graphParent->getAncestorOfType<GraphElement>() : nullptr;
258+
}
252259
if (graph && graph->getInput(interfaceName))
253260
{
254261
setInterfaceName(interfaceName);

source/MaterialXGraphEditor/Graph.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,35 +3324,54 @@ void Graph::propertyEditor()
33243324
}
33253325
else if (_currUiNode->getInput())
33263326
{
3327+
mx::InputPtr currUINodeInput = _currUiNode->getInput();
3328+
33273329
if (temp != original)
33283330
{
3329-
std::string name = _currUiNode->getInput()->getParent()->createValidChildName(temp);
3330-
std::vector<UiNodePtr> downstreamNodes = _currUiNode->getOutputConnections();
3331-
for (UiNodePtr uiNode : downstreamNodes)
3331+
std::string name = currUINodeInput->getParent()->createValidChildName(temp);
3332+
3333+
for (UiNodePtr uiNode : _currUiNode->getOutputConnections())
33323334
{
3335+
// Is not an input port
33333336
if (uiNode->getInput() == nullptr)
33343337
{
3338+
// Is a node
33353339
if (uiNode->getNode())
33363340
{
33373341
for (mx::InputPtr input : uiNode->getNode()->getActiveInputs())
33383342
{
3339-
if (input->getInterfaceInput() == _currUiNode->getInput())
3343+
if (input->getInterfaceInput() == currUINodeInput)
33403344
{
3341-
_currUiNode->getInput()->setName(name);
3342-
mx::ValuePtr val = _currUiNode->getInput()->getValue();
3345+
currUINodeInput->setName(name);
3346+
input->setConnectedInterfaceName(name);
3347+
}
3348+
}
3349+
}
3350+
// Is a node graph
3351+
else if (uiNode->getNodeGraph())
3352+
{
3353+
for (mx::InputPtr input : uiNode->getNodeGraph()->getActiveInputs())
3354+
{
3355+
if (input->getInterfaceName() == currUINodeInput->getName())
3356+
{
3357+
currUINodeInput->setName(name);
33433358
input->setConnectedInterfaceName(name);
3344-
mx::InputPtr pt = input->getInterfaceInput();
33453359
}
33463360
}
33473361
}
33483362
else
33493363
{
3350-
uiNode->getOutput()->setConnectedNode(_currUiNode->getNode());
3364+
// Is an output port
3365+
mx::OutputPtr outputPtr = uiNode->getOutput();
3366+
if (outputPtr)
3367+
{
3368+
outputPtr->setConnectedNode(_currUiNode->getNode());
3369+
}
33513370
}
33523371
}
33533372
}
33543373

3355-
_currUiNode->getInput()->setName(name);
3374+
currUINodeInput->setName(name);
33563375
_currUiNode->setName(name);
33573376
}
33583377
}

0 commit comments

Comments
 (0)