Skip to content

Commit

Permalink
AnnotationsGUI - show annotation nodes in addition to data nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Oct 23, 2023
1 parent b3aa22c commit 9919a64
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/osgEarth/ImGui/AnnotationsGUI
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "ImGui"
#include <osgEarth/AnnotationData>
#include <osgEarth/ViewFitter>
#include <osg/NodeVisitor>

namespace
Expand Down Expand Up @@ -51,6 +52,8 @@ namespace
struct GetAnnotations : public osg::NodeVisitor
{
osgEarth::EarthManipulator* manip = nullptr;
const osgEarth::SpatialReference* srs = nullptr;
osg::Camera* camera = nullptr;

GetAnnotations()
{
Expand All @@ -60,7 +63,9 @@ namespace

void apply(osg::Node& node) override
{
auto anode = dynamic_cast<osgEarth::AnnotationNode*>(&node);
auto data = dynamic_cast<osgEarth::AnnotationData*>(node.getUserData());

if (data)
{
ImGui::PushID((std::uintptr_t)data);
Expand All @@ -86,10 +91,38 @@ namespace

ImGui::Indent();
}
else if (anode)
{
ImGui::PushID((std::uintptr_t)data);

auto name = anode->getName();
if (name.empty()) name = "[" + std::string(anode->className()) + "]";

bool visible = node.getNodeMask() != 0;
if (ImGui::Checkbox("", &visible))
{
SetAnnotationNodeMask set(visible ? ~0 : 0);
node.accept(set);
}
ImGui::SameLine();
bool is_selected = false;
if (ImGui::Selectable(name.c_str(), &is_selected) && manip)
{
ViewFitter fitter(srs, camera);
Viewpoint vp;
fitter.createViewpoint(anode, vp);
manip->setViewpoint(vp);
}

ImGui::PopID();

ImGui::Indent();

}

traverse(node);

if (data)
if (data || anode)
{
ImGui::Unindent();
}
Expand Down Expand Up @@ -131,6 +164,8 @@ namespace osgEarth
{
GetAnnotations getannos;
getannos.manip = dynamic_cast<osgEarth::EarthManipulator*>(view(ri)->getCameraManipulator());
getannos.srs = _mapNode->getMapSRS();
getannos.camera = camera(ri);
camera(ri)->accept(getannos);
}
ImGui::End();
Expand Down

0 comments on commit 9919a64

Please sign in to comment.