Skip to content

Commit 59a4090

Browse files
Auto layout fix for subgraphs (AcademySoftwareFoundation#1389)
This is a bug fix for auto layout for nodes like triplanarprojection. This pull request also includes formatting fixes.
1 parent 2d566f4 commit 59a4090

1 file changed

Lines changed: 24 additions & 21 deletions

File tree

source/MaterialXGraphEditor/Graph.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,18 @@ ImVec2 Graph::layoutPosition(UiNodePtr layoutNode, ImVec2 startingPos, bool init
481481
// don't set position of group nodes
482482
if (node->getMessage().empty())
483483
{
484-
float x = std::stof(node->getMxElement()->getAttribute("xpos"));
485-
float y = std::stof(node->getMxElement()->getAttribute("ypos"));
486-
x *= DEFAULT_NODE_SIZE.x;
487-
y *= DEFAULT_NODE_SIZE.y;
488-
ed::SetNodePosition(node->getId(), ImVec2(x, y));
489-
node->setPos(ImVec2(x, y));
484+
if (node->getMxElement()->hasAttribute("xpos"))
485+
{
486+
float x = std::stof(node->getMxElement()->getAttribute("xpos"));
487+
if (node->getMxElement()->hasAttribute("ypos"))
488+
{
489+
float y = std::stof(node->getMxElement()->getAttribute("ypos"));
490+
x *= DEFAULT_NODE_SIZE.x;
491+
y *= DEFAULT_NODE_SIZE.y;
492+
ed::SetNodePosition(node->getId(), ImVec2(x, y));
493+
node->setPos(ImVec2(x, y));
494+
}
495+
}
490496
}
491497
}
492498
}
@@ -831,7 +837,7 @@ void Graph::updateMaterials(mx::InputPtr input, mx::ValuePtr value)
831837
// set the value of the selected node constants in the node property editor
832838
void Graph::setConstant(UiNodePtr node, mx::InputPtr& input, const mx::UIProperties& uiProperties)
833839
{
834-
std::string inName = !uiProperties.uiName.empty()? uiProperties.uiName : input->getName();
840+
std::string inName = !uiProperties.uiName.empty() ? uiProperties.uiName : input->getName();
835841
ImGui::PushItemWidth(-1);
836842

837843
mx::ValuePtr minVal = uiProperties.uiMin;
@@ -2940,7 +2946,7 @@ void Graph::graphButtons()
29402946
}
29412947
ImGui::EndMenu();
29422948
}
2943-
2949+
29442950
if (ImGui::BeginMenu("Graph"))
29452951
{
29462952
if (ImGui::MenuItem("Auto Layout"))
@@ -2949,15 +2955,15 @@ void Graph::graphButtons()
29492955
}
29502956
ImGui::EndMenu();
29512957
}
2952-
2958+
29532959
if (ImGui::BeginMenu("Viewer"))
29542960
{
29552961
if (ImGui::MenuItem("Load Geometry"))
29562962
{
29572963
loadGeometry();
29582964
}
29592965
ImGui::EndMenu();
2960-
}
2966+
}
29612967

29622968
if (ImGui::Button("Help"))
29632969
{
@@ -3145,7 +3151,7 @@ void Graph::propertyEditor()
31453151
}
31463152

31473153
const float TEXT_BASE_HEIGHT = ImGui::GetTextLineHeightWithSpacing() * 1.3f;
3148-
const int SCROLL_LINE_COUNT= 20;
3154+
const int SCROLL_LINE_COUNT = 20;
31493155
ImGuiTableFlags tableFlags = ImGuiTableFlags_ScrollY | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings |
31503156
ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_NoBordersInBody;
31513157

@@ -3245,7 +3251,7 @@ void Graph::propertyEditor()
32453251
if (count)
32463252
{
32473253
bool haveTable = ImGui::BeginTable("inputs_input_table", 2, tableFlags,
3248-
ImVec2(0.0f, TEXT_BASE_HEIGHT * std::min(SCROLL_LINE_COUNT, count)));
3254+
ImVec2(0.0f, TEXT_BASE_HEIGHT * std::min(SCROLL_LINE_COUNT, count)));
32493255
if (haveTable)
32503256
{
32513257
ImGui::SetWindowFontScale(_fontScale);
@@ -3302,7 +3308,7 @@ void Graph::propertyEditor()
33023308
if (count)
33033309
{
33043310
bool haveTable = ImGui::BeginTable("inputs_nodegraph_table", 2, tableFlags,
3305-
ImVec2(0.0f, TEXT_BASE_HEIGHT * std::min(SCROLL_LINE_COUNT, count)));
3311+
ImVec2(0.0f, TEXT_BASE_HEIGHT * std::min(SCROLL_LINE_COUNT, count)));
33063312
if (haveTable)
33073313
{
33083314
ImGui::SetWindowFontScale(_fontScale);
@@ -3365,7 +3371,7 @@ void Graph::propertyEditor()
33653371
// Helper to display basic user controls.
33663372
void Graph::showHelp() const
33673373
{
3368-
ImGui::Text("MATERIALX GRAPH EDITOR HELP");
3374+
ImGui::Text("MATERIALX GRAPH EDITOR HELP");
33693375
if (ImGui::CollapsingHeader("Graph"))
33703376
{
33713377
if (ImGui::TreeNode("Navigation"))
@@ -3437,9 +3443,9 @@ void Graph::addNodePopup(bool cursor)
34373443
{
34383444
std::string str(it->second[i][0]);
34393445
std::string nodeName = it->second[i][0];
3440-
//allow spaces to be used to search for node names
3446+
// allow spaces to be used to search for node names
34413447
std::replace(subs.begin(), subs.end(), ' ', '_');
3442-
3448+
34433449
if (str.find(subs) != std::string::npos)
34443450
{
34453451
if (ImGui::MenuItem(getNodeDefId(nodeName).c_str()) || (ImGui::IsItemFocused() && ImGui::IsKeyPressedMap(ImGuiKey_Enter)))
@@ -3819,12 +3825,9 @@ void Graph::drawGraph(ImVec2 mousePos)
38193825

38203826
if (outputNum.size() == 0 && _graphNodes[0]->getMxElement())
38213827
{
3822-
if (_graphNodes[0]->getMxElement()->hasAttribute("xpos"))
3828+
for (UiNodePtr node : _graphNodes)
38233829
{
3824-
for (UiNodePtr node : _graphNodes)
3825-
{
3826-
layoutPosition(node, ImVec2(0, 0), true, 0);
3827-
}
3830+
layoutPosition(node, ImVec2(0, 0), true, 0);
38283831
}
38293832
}
38303833
}

0 commit comments

Comments
 (0)