Skip to content

Commit

Permalink
add mapinspector for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Feb 13, 2015
1 parent 3a231e1 commit c99589b
Show file tree
Hide file tree
Showing 9 changed files with 491 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/osgEarth/Extension
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace osgEarth
/**
* Sets DB options that this extension should use when doing IO operations.
*/
virtual void setDBOptions(const osgDB::Options* options) =0;
virtual void setDBOptions(const osgDB::Options* options) { }


protected:
Expand Down
5 changes: 3 additions & 2 deletions src/osgEarthExtensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ SET(TARGET_COMMON_LIBRARIES
# Folder name for plugins
SET(OSGEARTH_EXTENSIONS_FOLDER Extensions)

add_subdirectory(billboard)
add_subdirectory(bumpmap)
add_subdirectory(mapinspector)
add_subdirectory(normalmap)
add_subdirectory(splat)
add_subdirectory(viewpoints)
add_subdirectory(billboard)
add_subdirectory(terrainshader)
add_subdirectory(viewpoints)

27 changes: 27 additions & 0 deletions src/osgEarthExtensions/mapinspector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# MapInspector Extension
#

SET(TARGET_SRC
MapInspectorPlugin.cpp
MapInspectorExtension.cpp
MapInspectorUI.cpp)

SET(LIB_PUBLIC_HEADERS
MapInspectorExtension
MapInspectorUI)

SET(TARGET_H
${LIB_PUBLIC_HEADERS} )

SET(TARGET_COMMON_LIBRARIES ${TARGET_COMMON_LIBRARIES}
osgEarthUtil
osgEarthFeatures
osgEarthSymbology)

SETUP_EXTENSION(osgearth_mapinspector)

SET(LIB_NAME mapinspector)

INCLUDE(ModuleInstallOsgEarthExtensionIncludes OPTIONAL)

84 changes: 84 additions & 0 deletions src/osgEarthExtensions/mapinspector/MapInspectorExtension
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2014 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 <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTH_MAPINSPECTOR_EXTENSION
#define OSGEARTH_MAPINSPECTOR_EXTENSION 1

#include <osgEarth/Extension>
#include <osgEarth/MapNode>
#include <osgEarth/MapCallback>
#include <osgEarthUtil/Controls>

namespace osgEarth { namespace MapInspector
{
using namespace osgEarth;
using namespace osgEarth::Util::Controls;

/**
* Displays visual metadata about the visible layers in a map.
*/
class MapInspectorExtension : public Extension,
public ExtensionInterface<MapNode>,
public ExtensionInterface<Control>,
public MapCallback
{
public:
META_Object(osgearth_ext_MapInspector, MapInspectorExtension);

// CTORs
MapInspectorExtension();
MapInspectorExtension(const ConfigOptions& options);

// DTOR
virtual ~MapInspectorExtension();


public: // ExtensionInterface<MapNode>

bool connect(MapNode* mapNode);

bool disconnect(MapNode* mapNode);


public: // ExtensionInterface<Control>

bool connect(Control* control);

bool disconnect(Control* control);


public: // MapCallback

void onMapModelChanged(const MapModelChange& change);


protected: // Object

MapInspectorExtension(const MapInspectorExtension& rhs, const osg::CopyOp& op) { }


private:
osg::observer_ptr<MapNode> _mapNode;
osg::ref_ptr<Control> _ui;

void ctor();
};

} } // namespace osgEarth::MapInspector

#endif // OSGEARTH_MAPINSPECTOR_EXTENSION
106 changes: 106 additions & 0 deletions src/osgEarthExtensions/mapinspector/MapInspectorExtension.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2014 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 <http://www.gnu.org/licenses/>
*/
#include "MapInspectorExtension"
#include "MapInspectorUI"

using namespace osgEarth;
using namespace osgEarth::Util;
using namespace osgEarth::Util::Controls;
using namespace osgEarth::MapInspector;

#define LC "[MapInspector] "

MapInspectorExtension::MapInspectorExtension()
{
ctor();
}

MapInspectorExtension::MapInspectorExtension(const ConfigOptions& options)
{
ctor();
}

MapInspectorExtension::~MapInspectorExtension()
{
// nop
}

void
MapInspectorExtension::ctor()
{
OE_INFO << LC << "loaded\n";
_ui = new MapInspectorUI();
}


void
MapInspectorExtension::onMapModelChanged(const MapModelChange& change)
{
osg::ref_ptr<MapNode> mapNode;
_mapNode.lock(mapNode);
static_cast<MapInspectorUI*>(_ui.get())->reinit(mapNode.get());
}

bool
MapInspectorExtension::connect(MapNode* mapNode)
{
OE_INFO << LC << "connected\n";
if ( mapNode )
{
_mapNode = mapNode;
_mapNode->getMap()->addMapCallback(this);
static_cast<MapInspectorUI*>(_ui.get())->reinit(mapNode);
}
return true;
}

bool
MapInspectorExtension::disconnect(MapNode* mapNode)
{
OE_INFO << LC << "disconnected\n";

if ( mapNode )
mapNode->getMap()->removeMapCallback(this);

_mapNode = 0L;
static_cast<MapInspectorUI*>(_ui.get())->reinit(0L);
return true;
}

bool
MapInspectorExtension::connect(Control* control)
{
Container* container = dynamic_cast<Container*>(control);
if ( container && _ui.valid() )
{
container->addControl( _ui.get() );
}
return true;
}

bool
MapInspectorExtension::disconnect(Control* control)
{
Container* container = dynamic_cast<Container*>(control);
if ( container && _ui.valid() )
{
container->removeChild( _ui.get() );
}
return true;
}
55 changes: 55 additions & 0 deletions src/osgEarthExtensions/mapinspector/MapInspectorPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2014 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 <http://www.gnu.org/licenses/>
*/
#include "MapInspectorExtension"

#include <osgDB/ReaderWriter>
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>

namespace osgEarth { namespace MapInspector
{
/**
* Plugin entry point
*/
class MapInspectorPlugin : public osgDB::ReaderWriter
{
public: // Plugin stuff

MapInspectorPlugin() {
supportsExtension( "osgearth_mapinspector", "osgEarth MapInspector Extension" );
}

const char* className() {
return "osgEarth MapInspector Extension";
}

virtual ~MapInspectorPlugin() { }

ReadResult readObject(const std::string& filename, const osgDB::Options* dbOptions) const
{
if ( !acceptsExtension(osgDB::getLowerCaseFileExtension(filename)) )
return ReadResult::FILE_NOT_HANDLED;

return ReadResult( new MapInspectorExtension(Extension::getConfigOptions(dbOptions)) );
}
};

REGISTER_OSGPLUGIN(osgearth_mapinspector, MapInspectorPlugin)

} } // namespace osgEarth::MapInspector
50 changes: 50 additions & 0 deletions src/osgEarthExtensions/mapinspector/MapInspectorUI
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2014 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 <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTH_MAPINSPECTOR_UI
#define OSGEARTH_MAPINSPECTOR_UI 1

#include <osgEarth/MapCallback>
#include <osgEarth/MapNode>
#include <osgEarthUtil/Controls>
#include <osg/View>

namespace osgEarth { namespace MapInspector
{
using namespace osgEarth;

class MapInspectorUI : public osgEarth::Util::Controls::Grid
{
public:
/** create UI */
MapInspectorUI();

/** rebuild everything */
void reinit(MapNode* mapNode);

private:
//osg::observer_ptr<MapNode> _mapNode;
osg::ref_ptr<osg::Group> _annos;

void addTerrainLayer(class TerrainLayer* layer, MapNode* mapNode);
void addModelLayer (class ModelLayer* layer, MapNode* mapNode);
};

} } // namespace

#endif // OSGEARTH_MAPINSPECTOR_UI

0 comments on commit c99589b

Please sign in to comment.