Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix graph editor defect for name setting #1431

Closed
34 changes: 23 additions & 11 deletions source/MaterialXGraphEditor/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ void Graph::copyUiNode(UiNodePtr node)
mx::NodePtr mxNode;
mxNode = _currGraphElem->addNodeInstance(node->getNode()->getNodeDef());
mxNode->copyContentFrom(node->getNode());
mxNode->setName(newName);
setName(mxNode, newName);
copyNode->setNode(mxNode);
}
else if (node->getInput())
Expand All @@ -1702,18 +1702,20 @@ void Graph::copyUiNode(UiNodePtr node)
mx::OutputPtr mxOutput;
mxOutput = _currGraphElem->addOutput(newName);
mxOutput->copyContentFrom(node->getOutput());
mxOutput->setName(newName);
setName(mxOutput, newName);
copyNode->setOutput(mxOutput);
}
copyNode->getMxElement()->setName(newName);
setName(copyNode->getMxElement(), newName);
copyNode->setName(newName);
//setName(copyNode, newName);
}
else if (node->getNodeGraph())
{
_graphDoc->addNodeGraph();
std::string nodeGraphName = _graphDoc->getNodeGraphs().back()->getName();
copyNode->setNodeGraph(_graphDoc->getNodeGraphs().back());
copyNode->setName(nodeGraphName);
copyNode->setName(nodeGraphName);
copyNodeGraph(node, copyNode);
}
setUiNodeInfo(copyNode, node->getType(), node->getCategory());
Expand All @@ -1724,10 +1726,10 @@ void Graph::copyNodeGraph(UiNodePtr origGraph, UiNodePtr copyGraph)
{
copyGraph->getNodeGraph()->copyContentFrom(origGraph->getNodeGraph());
std::vector<mx::InputPtr> inputs = copyGraph->getNodeGraph()->getActiveInputs();
for (mx::InputPtr input : inputs)
for (const mx::InputPtr& input : inputs)
{
std::string newName = _graphDoc->createValidChildName(input->getName());
input->setName(newName);
setName(input, newName);
}
}
void Graph::copyInputs()
Expand Down Expand Up @@ -3127,14 +3129,14 @@ void Graph::propertyEditor()
{
if (input->getConnectedNode() == _currUiNode->getNode())
{
_currUiNode->getNode()->setName(name);
setName(_currUiNode->getNode(),name);
nodes->getNode()->setConnectedNode(input->getName(), _currUiNode->getNode());
}
}
}
}
_currUiNode->setName(name);
_currUiNode->getNode()->setName(name);
setName(_currUiNode->getNode(),name);
}
}
else if (_currUiNode->getInput())
Expand All @@ -3155,7 +3157,7 @@ void Graph::propertyEditor()
{
if (input->getInterfaceInput() == _currUiNode->getInput())
{
_currUiNode->getInput()->setName(name);
setName(_currUiNode->getInput(),name);
mx::ValuePtr val = _currUiNode->getInput()->getValue();
input->setInterfaceName(name);
mx::InputPtr pt = input->getInterfaceInput();
Expand All @@ -3169,7 +3171,7 @@ void Graph::propertyEditor()
}
}

_currUiNode->getInput()->setName(name);
setName(_currUiNode->getInput(),name);
_currUiNode->setName(name);
}
}
Expand All @@ -3178,7 +3180,7 @@ void Graph::propertyEditor()
if (temp != original)
{
std::string name = _currUiNode->getOutput()->getParent()->createValidChildName(temp);
_currUiNode->getOutput()->setName(name);
setName(_currUiNode->getOutput(),name);
_currUiNode->setName(name);
}
}
Expand All @@ -3191,7 +3193,7 @@ void Graph::propertyEditor()
if (temp != original)
{
std::string name = _currUiNode->getNodeGraph()->getParent()->createValidChildName(temp);
_currUiNode->getNodeGraph()->setName(name);
setName(_currUiNode->getNodeGraph(), name);
_currUiNode->setName(name);
}
}
Expand Down Expand Up @@ -4238,3 +4240,13 @@ void Graph::writeText(std::string fileName, mx::FilePath filePath)
writeOptions.elementPredicate = getElementPredicate();
mx::writeToXmlFile(_graphDoc, filePath, &writeOptions);
}

void Graph::setName(mx::ElementPtr node, const std::string &name) {
if(name.empty()) {
auto childName = _currGraphElem->createValidChildName(name + "1");
node->setName(childName);
} else {
node->setName(name);
}
}

9 changes: 5 additions & 4 deletions source/MaterialXGraphEditor/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct Link

class Graph
{
public:
public:
Graph(const std::string& materialFilename,
const std::string& meshFilename,
const mx::FileSearchPath& searchPath,
Expand All @@ -57,14 +57,14 @@ class Graph

~Graph(){};

private:
private:
mx::ElementPredicate getElementPredicate() const;
void loadStandardLibraries();
void createNodeUIList(mx::DocumentPtr doc);
void buildUiBaseGraph(mx::DocumentPtr doc);
void buildUiNodeGraph(const mx::NodeGraphPtr& nodeGraphs);
void buildGroupNode(UiNodePtr node);

void setName(mx::ElementPtr node, const std::string &name);
// handling link information
void linkGraph();
void connectLinks();
Expand Down Expand Up @@ -237,6 +237,7 @@ class Graph

// DPI scaling for fonts
float _fontScale = 1.0f;

};

#endif
#endif