src/Screens/ModelEditorScreen.cpp
// draw right-click context menu for the 3D viewer
draw right-click context menu for the 3D viewer
draw right - click context menu for the 3D viewer
void draw3DViewerContextMenu(
            ModelEditorScreen::Impl& impl,
            OpenSim::Component const& selected) {
        ImGui::TextDisabled("%s (%s)", selected.getName().c_str(), selected.getConcreteClassName().c_str());
        ImGui::Separator();
        ImGui::Dummy(ImVec2{0.0f, 3.0f});
        if (ImGui::BeginMenu("Select Owner")) {
            OpenSim::Component const* c = &selected;
            impl.st->setHovered(nullptr);
            while (c->hasOwner()) {
                c = &c->getOwner();
                char buf[128];
                std::snprintf(buf, sizeof(buf), "%s (%s)", c->getName().c_str(), c->getConcreteClassName().c_str());
                if (ImGui::MenuItem(buf)) {
                    impl.st->setSelected(c);
                }
                if (ImGui::IsItemHovered()) {
                    impl.st->setHovered(c);
                }
            }
            ImGui::EndMenu();
        }
        if (ImGui::BeginMenu("Request Outputs")) {
            DrawHelpMarker("Request that these outputs are plotted whenever a simulation is ran. The outputs will appear in the 'outputs' tab on the simulator screen");
            OpenSim::Component const* c = &selected;
            int imguiId = 0;
            while (c) {
                ImGui::PushID(imguiId++);
                ImGui::Dummy(ImVec2{0.0f, 2.0f});
                ImGui::TextDisabled("%s (%s)", c->getName().c_str(), c->getConcreteClassName().c_str());
                ImGui::Separator();
                for (auto const& o : c->getOutputs()) {
                    char buf[256];
                    std::snprintf(buf, sizeof(buf), "  %s", o.second->getName().c_str());
                    auto const& suboutputs = getOutputSubfields(*o.second);
                    if (suboutputs.empty()) {
                        if (ImGui::MenuItem(buf)) {
                           impl.st->desiredOutputs.emplace_back(*c, *o.second);
                        }
                        if (ImGui::IsItemHovered()) {
                            ImGui::BeginTooltip();
                            ImGui::Text("Output Type = %s", o.second->getTypeName().c_str());
                            ImGui::EndTooltip();
                        }
                    } else {
                        if (ImGui::BeginMenu(buf)) {
                            for (PlottableOutputSubfield const& pos : suboutputs) {
                                if (ImGui::MenuItem(pos.name)) {
                                    impl.st->desiredOutputs.emplace_back(*c, *o.second, pos);
                                }
                            }
                            ImGui::EndMenu();
                        }
                        if (ImGui::IsItemHovered()) {
                            ImGui::BeginTooltip();
                            ImGui::Text("Output Type = %s", o.second->getTypeName().c_str());
                            ImGui::EndTooltip();
                        }
                    }
                }
                if (c->getNumOutputs() == 0) {
                    ImGui::TextDisabled("  (has no outputs)");
                }
                ImGui::PopID();
                c = c->hasOwner() ? &c->getOwner() : nullptr;
            }
            ImGui::EndMenu();
        }
    }
void draw3DViewerContextMenu ( ModelEditorScreen :: Impl & impl , OpenSim :: Component const & selected ) { ImGui :: TextDisabled ( " " , selected . getName ( ) . c_str ( ) , selected . getConcreteClassName ( ) . c_str ( ) ) ; ImGui :: Separator ( ) ; ImGui :: Dummy ( ImVec2 { 0.0f , 3.0f } ) ; if ( ImGui :: BeginMenu ( " " ) ) { OpenSim :: Component const * c = & selected ; impl . st -> setHovered ( nullptr ) ; while ( c -> hasOwner ( ) ) { c = & c -> getOwner ( ) ; char buf [ 128 ] ; std :: snprintf ( buf , sizeof ( buf ) , " " , c -> getName ( ) . c_str ( ) , c -> getConcreteClassName ( ) . c_str ( ) ) ; if ( ImGui :: MenuItem ( buf ) ) { impl . st -> setSelected ( c ) ; } if ( ImGui :: IsItemHovered ( ) ) { impl . st -> setHovered ( c ) ; } } ImGui :: EndMenu ( ) ; } if ( ImGui :: BeginMenu ( " " ) ) { DrawHelpMarker ( " " ) ; OpenSim :: Component const * c = & selected ; int imguiId = 0 ; while ( c ) { ImGui :: PushID ( imguiId ++ ) ; ImGui :: Dummy ( ImVec2 { 0.0f , 2.0f } ) ; ImGui :: TextDisabled ( " " , c -> getName ( ) . c_str ( ) , c -> getConcreteClassName ( ) . c_str ( ) ) ; ImGui :: Separator ( ) ; for ( auto const & o : c -> getOutputs ( ) ) { char buf [ 256 ] ; std :: snprintf ( buf , sizeof ( buf ) , " " , o . second -> getName ( ) . c_str ( ) ) ; auto const & suboutputs = getOutputSubfields ( * o . second ) ; if ( suboutputs . empty ( ) ) { if ( ImGui :: MenuItem ( buf ) ) { impl . st -> desiredOutputs . emplace_back ( * c , * o . second ) ; } if ( ImGui :: IsItemHovered ( ) ) { ImGui :: BeginTooltip ( ) ; ImGui :: Text ( " " , o . second -> getTypeName ( ) . c_str ( ) ) ; ImGui :: EndTooltip ( ) ; } } else { if ( ImGui :: BeginMenu ( buf ) ) { for ( PlottableOutputSubfield const & pos : suboutputs ) { if ( ImGui :: MenuItem ( pos . name ) ) { impl . st -> desiredOutputs . emplace_back ( * c , * o . second , pos ) ; } } ImGui :: EndMenu ( ) ; } if ( ImGui :: IsItemHovered ( ) ) { ImGui :: BeginTooltip ( ) ; ImGui :: Text ( " " , o . second -> getTypeName ( ) . c_str ( ) ) ; ImGui :: EndTooltip ( ) ; } } } if ( c -> getNumOutputs ( ) == 0 ) { ImGui :: TextDisabled ( " " ) ; } ImGui :: PopID ( ) ; c = c -> hasOwner ( ) ? & c -> getOwner ( ) : nullptr ; } ImGui :: EndMenu ( ) ; } }
draw right-click context menu for the 3D viewer
draw right - click context menu for the 3D viewer
// can only plot top-level of output // can plot suboutputs