From 01caa6c54d5a2bf2530c59a9497f623873b9434d Mon Sep 17 00:00:00 2001 From: Glenn Waldron Date: Fri, 7 Feb 2025 14:18:22 -0500 Subject: [PATCH] Save node layout for PTML --- src/osgEarthImGui/NodeGraphGUI | 15 ++++++++++++--- src/osgEarthProcedural/NodeGraph | 7 +++++++ src/osgEarthProcedural/ProceduralTiledModelLayer | 3 +-- .../ProceduralTiledModelLayer.cpp | 4 ++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/osgEarthImGui/NodeGraphGUI b/src/osgEarthImGui/NodeGraphGUI index ac7d966dd9..60414715c8 100644 --- a/src/osgEarthImGui/NodeGraphGUI +++ b/src/osgEarthImGui/NodeGraphGUI @@ -68,6 +68,11 @@ namespace osgEarth { auto nodeGraph = NodeGraph::fromConfig(doc->getConfig()); _proceduralModelLayer->setNodeGraph(nodeGraph); + auto state = nodeGraph->userConfig.value("imgui_state"); + if (!state.empty()) + { + ImNodes::LoadCurrentEditorStateFromIniString(state.c_str(), state.length()); + } } } } @@ -79,7 +84,9 @@ namespace osgEarth if (!f.result().empty()) { - Config config = _proceduralModelLayer->getNodeGraph()->getConfig(); + auto graph = _proceduralModelLayer->getNodeGraph(); + graph->userConfig.set("imgui_state", ImNodes::SaveCurrentEditorStateToIniString()); + Config config = graph->getConfig(); std::ofstream out(f.result()); osg::ref_ptr xml = new XmlDocument(config); xml->store(out); @@ -310,6 +317,7 @@ namespace osgEarth // Go ahead and do an update if we are turning on auto update if (_autoUpdate) { + //_proceduralModelLayer->dirty(); _proceduralModelLayer->dirtyNodeGraph(); } } @@ -318,7 +326,8 @@ namespace osgEarth ImGui::SameLine(); if (ImGui::Button("Update")) { - _proceduralModelLayer->dirtyNodeGraph(); + _proceduralModelLayer->dirty(); + //_proceduralModelLayer->dirtyNodeGraph(); } } @@ -803,7 +812,7 @@ namespace osgEarth } } - ImNodes::EndNodeEditor(); + ImNodes::EndNodeEditor(); int start_attr, end_attr; if (ImNodes::IsLinkCreated(&start_attr, &end_attr)) diff --git a/src/osgEarthProcedural/NodeGraph b/src/osgEarthProcedural/NodeGraph index 64199d4f6a..e6e5103148 100644 --- a/src/osgEarthProcedural/NodeGraph +++ b/src/osgEarthProcedural/NodeGraph @@ -2564,6 +2564,9 @@ namespace osgEarth } } conf.set("links", linksConf); + + conf.set("user_config", userConfig); + return conf; } @@ -2612,12 +2615,16 @@ namespace osgEarth } } + graph->userConfig = nodeGraphConf.child("user_config"); + return graph; } std::vector< std::shared_ptr< NodeGraphOperation > > operations; std::mutex _mutex; + + Config userConfig; }; diff --git a/src/osgEarthProcedural/ProceduralTiledModelLayer b/src/osgEarthProcedural/ProceduralTiledModelLayer index 2eea0148e9..3c158ae84c 100644 --- a/src/osgEarthProcedural/ProceduralTiledModelLayer +++ b/src/osgEarthProcedural/ProceduralTiledModelLayer @@ -33,6 +33,7 @@ namespace osgEarth { namespace Procedural { META_LayerOptions(osgEarth, Options, TiledModelLayer::Options); OE_OPTION(ProfileOptions, profile); + OE_OPTION(URI, url); Config getConfig() const override; void fromConfig(const Config& conf); }; @@ -93,7 +94,6 @@ namespace osgEarth { namespace Procedural } } - void registerNode(NodeGraphNode* node) { std::lock_guard< std::mutex> lk(_nodesMutex); @@ -125,7 +125,6 @@ namespace osgEarth { namespace Procedural private: osg::ref_ptr _profile; - std::shared_ptr< NodeGraph > _nodeGraph; }; } } diff --git a/src/osgEarthProcedural/ProceduralTiledModelLayer.cpp b/src/osgEarthProcedural/ProceduralTiledModelLayer.cpp index 45f63830e5..6dc7ce056e 100644 --- a/src/osgEarthProcedural/ProceduralTiledModelLayer.cpp +++ b/src/osgEarthProcedural/ProceduralTiledModelLayer.cpp @@ -36,6 +36,7 @@ void ProceduralTiledModelLayer::Options::fromConfig(const Config& conf) conf.get("min_level", minLevel()); conf.get("max_level", maxLevel()); conf.get("profile", profile()); + conf.get("url", url()); } Config @@ -45,6 +46,7 @@ ProceduralTiledModelLayer::Options::getConfig() const conf.set("min_level", minLevel()); conf.set("max_level", maxLevel()); conf.set("profile", profile()); + conf.set("url", url()); return conf; } @@ -87,6 +89,8 @@ ProceduralTiledModelLayer::openImplementation() if (parent.isError()) return parent; + + _profile = Profile::create(*options().profile()); return Status::NoError;