src/App.cpp
// initialize OpenSim for osc
//
// this involves setting up OpenSim's log, registering types, dirs, etc.
initialize OpenSim for osc
this involves setting up OpenSim's log, registering types, dirs, etc.
initialize OpenSim for osc this involves setting up OpenSim ' s log registering types dirs etc .
static bool EnsureOpenSimInitialized(Config const& config)
{
    static bool initializeOnceGlobally = [&config]()
    {
         it *writes* OSIM files using the locale, so you can end up with entries like:
             <PathPoint_X>0,1323</PathPoint_X>
         but it *reads* OSIM files with the assumption that numbers will be in the format 'x.y'
        osc::log::info("setting locale to US (so that numbers are always in the format '0.x'");
        char const* locale = "C";
        SetEnv("LANG", locale, 1);
        SetEnv("LC_CTYPE", locale, 1);
        SetEnv("LC_NUMERIC", locale, 1);
        SetEnv("LC_TIME", locale, 1);
        SetEnv("LC_COLLATE", locale, 1);
        SetEnv("LC_MONETARY", locale, 1);
        SetEnv("LC_MESSAGES", locale, 1);
        SetEnv("LC_ALL", locale, 1);
#ifdef LC_CTYPE
        setlocale(LC_CTYPE, locale);
#endif
#ifdef LC_NUMERIC
        setlocale(LC_NUMERIC, locale);
#endif
#ifdef LC_TIME
        setlocale(LC_TIME, locale);
#endif
#ifdef LC_COLLATE
        setlocale(LC_COLLATE, locale);
#endif
#ifdef LC_MONETARY
        setlocale(LC_MONETARY, locale);
#endif
#ifdef LC_MESSAGES
        setlocale(LC_MESSAGES, locale);
#endif
#ifdef LC_ALL
        setlocale(LC_ALL, locale);
#endif
        std::locale::global(std::locale{locale});
         disable OpenSim's `opensim.log` default
         by default, OpenSim creates an `opensim.log` file in the process's working
         directory. This should be disabled because it screws with running multiple
         instances of the UI on filesystems that use locking (e.g. Windows) and
         because it's incredibly obnoxious to have `opensim.log` appear in every
         working directory from which osc is ran
        osc::log::info("removing OpenSim's default log (opensim.log)");
        OpenSim::Logger::removeFileSink();
         add OSC in-memory logger
         this logger collects the logs into a global mutex-protected in-memory structure
         that the UI can can trivially render (w/o reading files etc.)
        osc::log::info("attaching OpenSim to this log");
        OpenSim::Logger::addSink(std::make_shared<OpenSimLogSink>());
         explicitly load OpenSim libs
         this is necessary because some compilers will refuse to link a library
         unless symbols from that library are directly used.
         Unfortunately, OpenSim relies on weak linkage *and* static library-loading
         side-effects. This means that (e.g.) the loading of muscles into the runtime
         happens in a static initializer *in the library*.
         osc may not link that library, though, because the source code in OSC may
         not *directly* use a symbol exported by the library (e.g. the code might use
         OpenSim::Muscle references, but not actually concretely refer to a muscle
         implementation method (e.g. a ctor)
        osc::log::info("registering OpenSim types");
        RegisterTypes_osimCommon();
        RegisterTypes_osimSimulation();
        RegisterTypes_osimActuators();
        RegisterTypes_osimAnalyses();
        RegisterTypes_osimTools();
         globally set OpenSim's geometry search path
         when an osim file contains relative geometry path (e.g. "sphere.vtp"), the
         OpenSim implementation will look in these directories for that file
        osc::log::info("registering OpenSim geometry search path to use osc resources");
        std::filesystem::path applicationWideGeometryDir = GetResource(config, "geometry");
        OpenSim::ModelVisualizer::addDirToGeometrySearchPaths(applicationWideGeometryDir.string());
        osc::log::info("added geometry search path entry: %s", applicationWideGeometryDir.string().c_str());
        return true;
    }();
    return initializeOnceGlobally;
}
static bool EnsureOpenSimInitialized ( Config const & config ) { static bool initializeOnceGlobally = [ & config ] ( ) { osc :: log :: info ( " " ) ; char const * locale = " " ; SetEnv ( " " , locale , 1 ) ; SetEnv ( " " , locale , 1 ) ; SetEnv ( " " , locale , 1 ) ; SetEnv ( " " , locale , 1 ) ; SetEnv ( " " , locale , 1 ) ; SetEnv ( " " , locale , 1 ) ; SetEnv ( " " , locale , 1 ) ; SetEnv ( " " , locale , 1 ) ; #ifdef LC_CTYPE setlocale ( LC_CTYPE , locale ) ; #endif #ifdef LC_NUMERIC setlocale ( LC_NUMERIC , locale ) ; #endif #ifdef LC_TIME setlocale ( LC_TIME , locale ) ; #endif #ifdef LC_COLLATE setlocale ( LC_COLLATE , locale ) ; #endif #ifdef LC_MONETARY setlocale ( LC_MONETARY , locale ) ; #endif #ifdef LC_MESSAGES setlocale ( LC_MESSAGES , locale ) ; #endif #ifdef LC_ALL setlocale ( LC_ALL , locale ) ; #endif std :: locale :: global ( std :: locale { locale } ) ; osc :: log :: info ( " " ) ; OpenSim :: Logger :: removeFileSink ( ) ; osc :: log :: info ( " " ) ; OpenSim :: Logger :: addSink ( std :: make_shared < OpenSimLogSink > ( ) ) ; osc :: log :: info ( " " ) ; RegisterTypes_osimCommon ( ) ; RegisterTypes_osimSimulation ( ) ; RegisterTypes_osimActuators ( ) ; RegisterTypes_osimAnalyses ( ) ; RegisterTypes_osimTools ( ) ; osc :: log :: info ( " " ) ; std :: filesystem :: path applicationWideGeometryDir = GetResource ( config , " " ) ; OpenSim :: ModelVisualizer :: addDirToGeometrySearchPaths ( applicationWideGeometryDir . string ( ) ) ; osc :: log :: info ( " " , applicationWideGeometryDir . string ( ) . c_str ( ) ) ; return true ; } ( ) ; return initializeOnceGlobally ; }
initialize OpenSim for osc
this involves setting up OpenSim's log, registering types, dirs, etc.
initialize OpenSim for osc this involves setting up OpenSim ' s log registering types dirs etc .
// these are because OpenSim is inconsistient about handling locales // // it *writes* OSIM files using the locale, so you can end up with entries like: // //     <PathPoint_X>0,1323</PathPoint_X> // // but it *reads* OSIM files with the assumption that numbers will be in the format 'x.y' // disable OpenSim's `opensim.log` default // // by default, OpenSim creates an `opensim.log` file in the process's working // directory. This should be disabled because it screws with running multiple // instances of the UI on filesystems that use locking (e.g. Windows) and // because it's incredibly obnoxious to have `opensim.log` appear in every // working directory from which osc is ran // add OSC in-memory logger // // this logger collects the logs into a global mutex-protected in-memory structure // that the UI can can trivially render (w/o reading files etc.) // explicitly load OpenSim libs // // this is necessary because some compilers will refuse to link a library // unless symbols from that library are directly used. // // Unfortunately, OpenSim relies on weak linkage *and* static library-loading // side-effects. This means that (e.g.) the loading of muscles into the runtime // happens in a static initializer *in the library*. // // osc may not link that library, though, because the source code in OSC may // not *directly* use a symbol exported by the library (e.g. the code might use // OpenSim::Muscle references, but not actually concretely refer to a muscle // implementation method (e.g. a ctor) // globally set OpenSim's geometry search path // // when an osim file contains relative geometry path (e.g. "sphere.vtp"), the // OpenSim implementation will look in these directories for that file