예제 #1
0
void ResourceManager::_findDataPaths() {
    mDataPathsSearched = true;

    // check recursively upwards
    QDir dir(QCoreApplication::applicationDirPath());

    while(!dir.isRoot()) {
        QDir data(dir.absolutePath() + "/data");
        if(data.exists()) {
            addDataPath(data.absolutePath());
            break;
        }
        dir.cdUp();
    }

    // check compiled-in path (DT_DATA_PATH)
#ifdef DT_DATA_PATH
    QDir data_path(DT_DATA_PATH);
    if(data_path.exists()) {
        AddDataPath(data_path.absolutePath());
    } else {
        Logger::Get().Error("Compiled-in data path <" + DT_DATA_PATH + "> not found.");
    }
#else
    // warn if we also did not find one previously
    if(dir.isRoot()) {
        // did not find the data path
        Logger::get().warning("No relative data path found.");
    }
#endif
}
예제 #2
0
	void RuntimeEnvironment::processCommandLine( int argc, char *argv[] )
	{
		if (!pathInitialized)
			init();

		// Declare the supported options.
		boost::program_options::options_description desc("Simox runtime options");
		desc.add_options()
			("help", "Simox command line parser: Set options with '--key value'\n")
			("data-path", boost::program_options::value< std::vector< std::string > >()->composing(), "Set data path. Multiple data paths are allowed.")
			;
		for (size_t i=0;i<processKeys.size();i++)
			desc.add_options()
			(processKeys[i].c_str(), boost::program_options::value< std::vector< std::string > >(), processKeys[i].c_str())
			;

		boost::program_options::parsed_options parsed = 
			boost::program_options::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); 

		boost::program_options::variables_map vm;
		//boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
		boost::program_options::store(parsed,vm);
		boost::program_options::notify(vm);  
		
		// process data-path entries
		if (vm.count("data-path"))
		{
			//VR_INFO << "Data paths are: " << endl;
			std::vector< std::string > dp = vm["data-path"].as< std::vector< std::string > >();
			for (size_t i=0;i<dp.size();i++)
			{
				addDataPath(dp[i]);
				//VR_INFO << dp[i] << "\n";
			}
		}

		// process generic keys
		for (size_t i=0;i<processKeys.size();i++)
		{
			if (vm.count(processKeys[i].c_str()))
			{
				std::vector< std::string > dp = vm[processKeys[i].c_str()].as< std::vector< std::string > >();
				if (dp.size()>1)
					VR_WARNING << "More than one parameter for key " << processKeys[i] << ". taking the first one..." << endl;
				if (dp.size()>0)
					addKeyValuePair(processKeys[i],dp[0]); // take the first one...
			}

		}

		// collect unrecognized arguments
		std::vector<std::string> options = boost::program_options::collect_unrecognized(parsed.options, boost::program_options::include_positional);
		for (size_t i=0;i<options.size();i++)
		{
			unrecognizedOptions.push_back(options[i]);
		}


	}
예제 #3
0
	void RuntimeEnvironment::init()
	{
		if (!pathInitialized)
		{
			pathInitialized = true;
			bool pathFound = false;
			char * simox_data_path = getenv("SIMOX_DATA_PATH");
			if (simox_data_path)
			{
				pathFound = addDataPath(std::string(simox_data_path),true);
			}
			char * vr_data_path = getenv("VIRTUAL_ROBOT_DATA_PATH");
			if (vr_data_path)
			{
				pathFound = addDataPath(std::string(vr_data_path),true);
			}
			if (!pathFound)
			{
				// test for Simox_DIR
				simox_data_path = getenv("Simox_DIR");
				if (simox_data_path)
				{
					std::string sd(simox_data_path);
					sd += std::string("/data");
					pathFound = addDataPath(sd,true);
					if (!pathFound)
					{
						std::string sd(simox_data_path);
						sd += std::string("/VirtualRobot/data");
						pathFound = addDataPath(sd,true);
					}
					if (!pathFound)
					{
						std::string sd(simox_data_path);
						sd += std::string("../VirtualRobot/data");
						pathFound = addDataPath(sd,true);
					}
				}
			}
#ifdef Simox_DATA_PATH
			pathFound = pathFound | addDataPath(std::string(Simox_DATA_PATH),true);
#endif
#ifdef VirtualRobot_DATA_PATH
			pathFound = pathFound | addDataPath(std::string(VirtualRobot_DATA_PATH),true);
#endif
#ifdef VirtualRobot_SRC_DATA_PATH
			pathFound = pathFound | addDataPath(std::string(VirtualRobot_SRC_DATA_PATH),true);
#endif
			// check standard linux install path
			if (!pathFound)
			{
				pathFound = addDataPath(std::string("/usr/local/data"),true);
			}

			// last chance, check for inbuild paths
			if (!pathFound)
			{
			  boost::filesystem::path p(boost::filesystem::current_path());
			  boost::filesystem::path p1 = boost::filesystem::operator/(p,"../VirtualRobot/data");
			  boost::filesystem::path p2 = boost::filesystem::operator/(p,"../../VirtualRobot/data");
			  boost::filesystem::path p3 = boost::filesystem::operator/(p,"../../../VirtualRobot/data");
			  boost::filesystem::path p4 = boost::filesystem::operator/(p,"../../../../VirtualRobot/data");
			  pathFound = pathFound | addDataPath(p1.string(),true);
			  pathFound = pathFound | addDataPath(p2.string(),true);
			  pathFound = pathFound | addDataPath(p3.string(),true);
			  pathFound = pathFound | addDataPath(p4.string(),true);
			}
		}
	}