/* -*-c++-*- */ /* osgEarth - Geospatial SDK for OpenSceneGraph * Copyright 2018 Pelican Mapping * http://osgearth.org * * osgEarth is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see */ #pragma once #include #include #if defined(__has_include) #if __has_include() #include #define OSGEARTH_HAVE_OPEN_EARTH_FILE_GUI #endif #endif #ifdef OSGEARTH_HAVE_OPEN_EARTH_FILE_GUI namespace osgEarth { class OpenEarthFileGUI : public ImGuiPanel { public: OpenEarthFileGUI() : ImGuiPanel("Open Earth File") { } void draw(osg::RenderInfo& ri) override { auto f = pfd::open_file("Choose files to read", pfd::path::home(), { "Earth Files", "*.earth", "All Files", "*" }, pfd::opt::none); if (f.result().size() > 0) { std::string earthFile = f.result()[0]; osg::ref_ptr< osg::Node > node = osgDB::readRefNodeFile(earthFile); if (node.valid()) { MapNode* mapNode = MapNode::findMapNode(node); osgViewer::View* view = dynamic_cast(ri.getView()); if (view && mapNode) { mapNode->open(); auto* em = dynamic_cast(view->getCameraManipulator()); if (em) { em->setNode(nullptr); em->setNode(mapNode); } view->setSceneData(mapNode); } } } setVisible(false); } }; } #endif