コード例 #1
0
// See if we can find the given file. The rules are
//  - if it is an absolute pathname, we only get one shot, else:
//  - define "modelDir" to be the absolute pathname of the 
//      directory from which we read in the .osim model, if we did,
//      otherwise modelDir="." (current directory).
//  - look for the geometry file in modelDir
//  - look for the geometry file in modelDir/Geometry
//  - look for the geometry file in installDir/Geometry
bool ModelVisualizer::
findGeometryFile(const Model& aModel, 
                 const std::string&          geoFile,
                 bool&                       geoFileIsAbsolute,
                 SimTK::Array_<std::string>& attempts)
{
    attempts.clear();
    std::string geoDirectory, geoFileName, geoExtension; 
    SimTK::Pathname::deconstructPathname(geoFile, 
        geoFileIsAbsolute, geoDirectory, geoFileName, geoExtension);

    bool foundIt = false;
    if (geoFileIsAbsolute) {
        attempts.push_back(geoFile);
        foundIt = Pathname::fileExists(attempts.back());
    } else {  
        const string geoDir = "Geometry" + Pathname::getPathSeparator();
        string modelDir;
        if (aModel.getInputFileName() == "Unassigned") 
            modelDir = Pathname::getCurrentWorkingDirectory();
        else {
            bool isAbsolutePath; string directory, fileName, extension; 
            SimTK::Pathname::deconstructPathname(
                aModel.getInputFileName(),
                isAbsolutePath, directory, fileName, extension);
            modelDir = isAbsolutePath 
                ? directory
                : Pathname::getCurrentWorkingDirectory() + directory;
        }

        attempts.push_back(modelDir + geoFile);
        foundIt = Pathname::fileExists(attempts.back());

        if (!foundIt) {
            attempts.push_back(modelDir + geoDir + geoFile); 
            foundIt = Pathname::fileExists(attempts.back());
        }

        if (!foundIt) {
            const string installDir = 
                Pathname::getInstallDir("OPENSIM_HOME", "OpenSim");
            attempts.push_back(installDir + geoDir + geoFile);
            foundIt = Pathname::fileExists(attempts.back());
        }
    }

    return foundIt;
}