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
48 changes: 29 additions & 19 deletions source/MaterialXGraphEditor/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,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 @@ -1656,18 +1656,18 @@ 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);
copyNode->setName(newName);
setName(copyNode->getMxElement(), 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);
setName(copyNode, nodeGraphName);
copyNodeGraph(node, copyNode);
}
setUiNodeInfo(copyNode, node->getType(), node->getCategory());
Expand All @@ -1678,10 +1678,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 @@ -1970,7 +1970,7 @@ void Graph::buildGroupNode(UiNodePtr node)
ImVec2 nameSize = ImGui::CalcTextSize(temp.c_str());
ImGui::PushItemWidth(nameSize.x);
ImGui::InputText("##edit", &tempName);
node->setName(tempName);
setName(node,tempName);
ImGui::PopID();
ImGui::EndGroup();

Expand Down Expand Up @@ -3081,14 +3081,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, name);
setName(_currUiNode->getNode(),name);
}
}
else if (_currUiNode->getInput())
Expand All @@ -3109,7 +3109,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 @@ -3123,30 +3123,30 @@ void Graph::propertyEditor()
}
}

_currUiNode->getInput()->setName(name);
_currUiNode->setName(name);
setName(_currUiNode->getInput(),name);
setName(_currUiNode,name);
}
}
else if (_currUiNode->getOutput())
{
if (temp != original)
{
std::string name = _currUiNode->getOutput()->getParent()->createValidChildName(temp);
_currUiNode->getOutput()->setName(name);
_currUiNode->setName(name);
setName(_currUiNode->getOutput(),name);
setName(_currUiNode,name);
}
}
else if (_currUiNode->getCategory() == "group")
{
_currUiNode->setName(temp);
setName(_currUiNode, temp);
}
else if (_currUiNode->getCategory() == "nodegraph")
{
if (temp != original)
{
std::string name = _currUiNode->getNodeGraph()->getParent()->createValidChildName(temp);
_currUiNode->getNodeGraph()->setName(name);
_currUiNode->setName(name);
setName(_currUiNode->getNodeGraph(), name);
setName(_currUiNode,name);
}
}

Expand Down Expand Up @@ -4200,3 +4200,13 @@ void Graph::writeText(std::string fileName, mx::FilePath filePath)
writeOptions.elementPredicate = getElementPredicate();
mx::writeToXmlFile(_graphDoc, filePath, &writeOptions);
}

template <typename Element>
void Graph::setName(const Element& node, const std::string &name) {
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
if(name.empty()) {
auto childName = _currGraphElem->createValidChildName(name + "1");
node->setName(childName);
} else {
node->setName(name);
}
}
13 changes: 7 additions & 6 deletions source/MaterialXGraphEditor/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ struct Link
int id;
int _startAttr, _endAttr;
Link() :
_startAttr(-1),
_endAttr(-1)
_startAttr(-1),
_endAttr(-1)
{
static int _id = 0;
id = ++_id;
Expand All @@ -34,7 +34,7 @@ struct Link

class Graph
{
public:
public:
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
Graph(const std::string& materialFilename,
const std::string& meshFilename,
const mx::FileSearchPath& searchPath,
Expand All @@ -57,14 +57,15 @@ 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);

template <typename Element>
void setName(const Element& node,const std::string &name);
// handling link information
void linkGraph();
void connectLinks();
Expand Down Expand Up @@ -239,4 +240,4 @@ class Graph
float _fontScale = 1.0f;
};

#endif
#endif