src/Screens/ModelEditorScreen.cpp
// draw socket editor for current selection
draw socket editor for current selection
draw socket editor for current selection
void drawSocketEditor(ReassignSocketPopup& reassignSocketPopup, UndoableUiModel& uim) {
        OpenSim::Component const* selected = uim.getSelected();
        if (!selected) {
            ImGui::TextUnformatted("cannot draw socket editor: selection is blank (shouldn't be)");
        }
        std::vector<std::string> socknames = const_cast<OpenSim::Component*>(selected)->getSocketNames();
        if (socknames.empty()) {
            ImGui::PushStyleColor(ImGuiCol_Text, OSC_GREYED_RGBA);
            ImGui::Text("    (OpenSim::%s has no sockets)", selected->getConcreteClassName().c_str());
            ImGui::PopStyleColor();
            return;
        }
        ImGui::Columns(2);
        for (std::string const& sn : socknames) {
            ImGui::TextUnformatted(sn.c_str());
            ImGui::NextColumn();
            OpenSim::AbstractSocket const& socket = selected->getSocket(sn);
            std::string sockname = socket.getConnecteePath();
            std::string popupname = std::string{"reassign"} + sockname;
            if (ImGui::Button(sockname.c_str())) {
                ImGui::OpenPopup(popupname.c_str());
            }
            if (ImGui::IsItemHovered()) {
                ImGui::BeginTooltip();
                ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
                ImGui::TextUnformatted(socket.getConnecteeAsObject().getName().c_str());
                ImGui::SameLine();
                ImGui::TextDisabled("%s", socket.getConnecteeAsObject().getConcreteClassName().c_str());
                ImGui::NewLine();
                ImGui::TextDisabled("Left-Click: Reassign this socket's connectee");
                ImGui::TextDisabled("Right-Click: Select the connectee");
                ImGui::PopTextWrapPos();
                ImGui::EndTooltip();
            }
            if (ImGui::IsItemClicked(ImGuiMouseButton_Right) && dynamic_cast<OpenSim::Component const*>(&socket.getConnecteeAsObject())) {
                uim.setSelected(dynamic_cast<OpenSim::Component const*>(&socket.getConnecteeAsObject()));
                ImGui::NextColumn();
                break;  
            }
            if (OpenSim::Object const* connectee = reassignSocketPopup.draw(popupname.c_str(), uim.getModel(), socket); connectee) {
                ImGui::CloseCurrentPopup();
                OpenSim::Object const& existing = socket.getConnecteeAsObject();
                try {
                    uim.updSelected()->updSocket(sn).connect(*connectee);
                    reassignSocketPopup.search[0] = '\0';
                    reassignSocketPopup.error.clear();
                    ImGui::CloseCurrentPopup();
                } catch (std::exception const& ex) {
                    reassignSocketPopup.error = ex.what();
                    uim.updSelected()->updSocket(sn).connect(existing);
                }
            }
            ImGui::NextColumn();
        }
        ImGui::Columns();
    }
void drawSocketEditor ( ReassignSocketPopup & reassignSocketPopup , UndoableUiModel & uim ) { OpenSim :: Component const * selected = uim . getSelected ( ) ; if ( ! selected ) { ImGui :: TextUnformatted ( " " ) ; } std :: vector < std :: string > socknames = const_cast < OpenSim :: Component * > ( selected ) -> getSocketNames ( ) ; if ( socknames . empty ( ) ) { ImGui :: PushStyleColor ( ImGuiCol_Text , OSC_GREYED_RGBA ) ; ImGui :: Text ( " " , selected -> getConcreteClassName ( ) . c_str ( ) ) ; ImGui :: PopStyleColor ( ) ; return ; } ImGui :: Columns ( 2 ) ; for ( std :: string const & sn : socknames ) { ImGui :: TextUnformatted ( sn . c_str ( ) ) ; ImGui :: NextColumn ( ) ; OpenSim :: AbstractSocket const & socket = selected -> getSocket ( sn ) ; std :: string sockname = socket . getConnecteePath ( ) ; std :: string popupname = std :: string { " " } + sockname ; if ( ImGui :: Button ( sockname . c_str ( ) ) ) { ImGui :: OpenPopup ( popupname . c_str ( ) ) ; } if ( ImGui :: IsItemHovered ( ) ) { ImGui :: BeginTooltip ( ) ; ImGui :: PushTextWrapPos ( ImGui :: GetFontSize ( ) * 35.0f ) ; ImGui :: TextUnformatted ( socket . getConnecteeAsObject ( ) . getName ( ) . c_str ( ) ) ; ImGui :: SameLine ( ) ; ImGui :: TextDisabled ( " " , socket . getConnecteeAsObject ( ) . getConcreteClassName ( ) . c_str ( ) ) ; ImGui :: NewLine ( ) ; ImGui :: TextDisabled ( " " ) ; ImGui :: TextDisabled ( " " ) ; ImGui :: PopTextWrapPos ( ) ; ImGui :: EndTooltip ( ) ; } if ( ImGui :: IsItemClicked ( ImGuiMouseButton_Right ) && dynamic_cast < OpenSim :: Component const * > ( & socket . getConnecteeAsObject ( ) ) ) { uim . setSelected ( dynamic_cast < OpenSim :: Component const * > ( & socket . getConnecteeAsObject ( ) ) ) ; ImGui :: NextColumn ( ) ; break ; } if ( OpenSim :: Object const * connectee = reassignSocketPopup . draw ( popupname . c_str ( ) , uim . getModel ( ) , socket ) ; connectee ) { ImGui :: CloseCurrentPopup ( ) ; OpenSim :: Object const & existing = socket . getConnecteeAsObject ( ) ; try { uim . updSelected ( ) -> updSocket ( sn ) . connect ( * connectee ) ; reassignSocketPopup . search [ 0 ] = ' \0 ' ; reassignSocketPopup . error . clear ( ) ; ImGui :: CloseCurrentPopup ( ) ; } catch ( std :: exception const & ex ) { reassignSocketPopup . error = ex . what ( ) ; uim . updSelected ( ) -> updSocket ( sn ) . connect ( existing ) ; } } ImGui :: NextColumn ( ) ; } ImGui :: Columns ( ) ; }
draw socket editor for current selection
draw socket editor for current selection
// else: it has sockets with names, list each socket and provide the user //       with the ability to reassign the socket's connectee // don't continue to traverse the sockets, because the selection changed