diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h index 0a838d25b45678053447ec750581ce6323c6b4a6..b388acb0ac34ec9cd1837a2ddc6869ab42551e08 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h @@ -189,6 +189,10 @@ namespace Mantid /// Load facility information from instrumentDir/Facilities.xml file void updateFacilities(const std::string& facilityName = ""); + /// Get the list of facilities + const std::vector<FacilityInfo*> getFacilities()const; + /// Get the list of facility names + const std::vector<std::string> getFacilityNames()const; /// Get the default facility const FacilityInfo& getFacility()const; /// Get a facility diff --git a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp index ffeea231fefb2fcd0c67e1a08eea1b22f76ce8c3..122caecc5d6f1fcb2979ebc23c0eee627de70e08 100644 --- a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp +++ b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp @@ -1566,6 +1566,29 @@ const InstrumentInfo & ConfigServiceImpl::getInstrument(const std::string& instr throw Exception::NotFoundError("Instrument", instrumentName); } +/** Gets a vector of the facility Information objects + * @return A vector of FacilityInfo objects + */ +const std::vector<FacilityInfo*> ConfigServiceImpl::getFacilities() const +{ + return m_facilities; +} + +/** Gets a vector of the facility names + * @return A vector of the facility Names + */ +const std::vector<std::string> ConfigServiceImpl::getFacilityNames()const +{ + auto names = std::vector<std::string>(m_facilities.size()); + auto itFacilities = m_facilities.begin(); + auto itNames = names.begin(); + for (; itFacilities != m_facilities.end(); ++itFacilities,++itNames) + { + *itNames = (**itFacilities).name(); + } + return names; +} + /** Get the default facility * @return the facility information object */ @@ -1576,7 +1599,7 @@ const FacilityInfo& ConfigServiceImpl::getFacility() const { defFacility = "ISIS"; } - return getFacility(defFacility); + return this->getFacility(defFacility); } /** diff --git a/Code/Mantid/Framework/Kernel/src/MultiFileNameParser.cpp b/Code/Mantid/Framework/Kernel/src/MultiFileNameParser.cpp index 714f911df3e7ceb9b7b6aec4dd9d41e81e5a84eb..62bb18908c9073c78440cb94addc5c01a74c4124 100644 --- a/Code/Mantid/Framework/Kernel/src/MultiFileNameParser.cpp +++ b/Code/Mantid/Framework/Kernel/src/MultiFileNameParser.cpp @@ -199,18 +199,10 @@ namespace Kernel { ConfigServiceImpl & config = ConfigService::Instance(); - std::string supportedFacilities = config.getString("supported.facilities"); - - std::vector<std::string> allFacilityNames; - boost::split( - allFacilityNames, - supportedFacilities, - boost::is_any_of(";")); - - for( auto facilityName = allFacilityNames.begin(); facilityName != allFacilityNames.end(); ++facilityName ) + auto facilities = config.getFacilities(); + for( auto itFacility = facilities.begin(); itFacility != facilities.end(); ++itFacility ) { - const FacilityInfo & facility = config.getFacility(*facilityName); - const std::vector<InstrumentInfo> instruments = facility.instruments(); + const std::vector<InstrumentInfo> instruments = (**itFacility).instruments(); for( auto instrument = instruments.begin(); instrument != instruments.end(); ++instrument ) { diff --git a/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h b/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h index 3a2ae99896677a380ae9554fd6d1bf59ac09d6c9..de4a2d413f0816fe3bb4f3b5c23d25206fc1c9bf 100644 --- a/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h +++ b/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h @@ -115,6 +115,23 @@ public: // // Non existent facility // TS_ASSERT_THROWS(ConfigService::Instance().setFacility(""), Mantid::Kernel::Exception::NotFoundError); + } + + void testFacilityList() + { + std::vector<FacilityInfo*> facilities = ConfigService::Instance().getFacilities(); + std::vector<std::string> names = ConfigService::Instance().getFacilityNames(); + + TS_ASSERT_LESS_THAN(0,names.size()); + TS_ASSERT_EQUALS(facilities.size(),names.size()); + auto itFacilities = facilities.begin(); + auto itNames = names.begin(); + for (; itFacilities != facilities.end(); ++itFacilities,++itNames) + { + TS_ASSERT_EQUALS(*itNames, (**itFacilities).name()); + } + + } void testInstrumentSearch() diff --git a/Code/Mantid/Framework/Kernel/test/MultiFileNameParserTest.h b/Code/Mantid/Framework/Kernel/test/MultiFileNameParserTest.h index dfd28d4cba749a4a6676ea8061fd24cdd0c3d781..d2ba2caaa936981d87174de0a91efc28187f3c84 100644 --- a/Code/Mantid/Framework/Kernel/test/MultiFileNameParserTest.h +++ b/Code/Mantid/Framework/Kernel/test/MultiFileNameParserTest.h @@ -363,7 +363,6 @@ public: void test_instrument_with_multiple_padding() { - Mantid::Kernel::ConfigService::Instance().setString("supported.facilities", "TEST"); Parser parser; parser.parse("TESTHISTOLISTENER123,299-301"); diff --git a/Code/Mantid/Framework/Properties/Mantid.properties.template b/Code/Mantid/Framework/Properties/Mantid.properties.template index ea49e0c98b4c5a7629b2f1200e46c669b9b6c5f4..c2d11747debd1cae7042e02effa6d65be75398f6 100644 --- a/Code/Mantid/Framework/Properties/Mantid.properties.template +++ b/Code/Mantid/Framework/Properties/Mantid.properties.template @@ -9,9 +9,6 @@ # This File will be overwritten with each new version of Mantid, however # we will never alter your user.properties file so settings there are safe. -# A semi-colon separated list of supported facilities -supported.facilities = ISIS;SNS;HFIR;NCNR;LENS;ILL;SINQ;LLB - # Set a default facility default.facility = ISIS diff --git a/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/ConfigService.cpp b/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/ConfigService.cpp index 861c8ae81854e621abb29ab41de0d4a483814b9a..5b23f35fa780854e1b179dfbe683ac3ac5dc6e92 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/ConfigService.cpp +++ b/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/ConfigService.cpp @@ -1,6 +1,7 @@ #include "MantidKernel/ConfigService.h" #include "MantidKernel/FacilityInfo.h" #include "MantidPythonInterface/kernel/Converters/PySequenceToVector.h" +#include "MantidPythonInterface/kernel/StlExportDefinitions.h" #include <boost/python/class.hpp> #include <boost/python/def.hpp> #include <boost/python/reference_existing_object.hpp> @@ -37,6 +38,10 @@ namespace void export_ConfigService() { + using Mantid::PythonInterface::std_vector_exporter; + + std_vector_exporter<FacilityInfo*>::wrap("std_vector_facilityinfo"); + class_<ConfigServiceImpl, boost::noncopyable>("ConfigServiceImpl", no_init) .def("reset", &ConfigServiceImpl::reset, "Clears all user settings and removes the user properties file") @@ -48,6 +53,10 @@ void export_ConfigService() .def("getInstrumentDirectory", &ConfigServiceImpl::getInstrumentDirectory, "Returns the directory used for the instrument definitions") + .def("getFacilityNames", &ConfigServiceImpl::getFacilityNames, "Returns the default facility") + + .def("getFacilities", &ConfigServiceImpl::getFacilities, "Returns the default facility") + .def("getFacility", (const FacilityInfo&(ConfigServiceImpl::*)() const)&ConfigServiceImpl::getFacility, return_value_policy<reference_existing_object>(), "Returns the default facility") diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/ConfigServiceTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/ConfigServiceTest.py index 4a17a0c34ad037d55eb95eaf09387bc5288525ab..edbe56ec0883c66406c11751aec977dc9e980b41 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/ConfigServiceTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/ConfigServiceTest.py @@ -28,7 +28,20 @@ class ConfigServiceTest(unittest.TestCase): facility = config.getFacility("ISIS") self.assertTrue(isinstance(facility, FacilityInfo)) self.assertRaises(RuntimeError, config.getFacility, "MadeUpFacility") - + + def test_getFacilities_Returns_A_FacilityInfo_List(self): + facilities = config.getFacilities() + self.assertTrue(isinstance(facilities[0], FacilityInfo)) + + def test_getFacilities_and_Facility_Names_are_in_sync_and_non_empty(self): + facilities = config.getFacilities() + names = config.getFacilityNames() + + self.assertTrue(len(names)>0) + self.assertEquals(len(names),len(facilities)) + for i in range(len(names)): + self.assertEquals(names[i],facilities[i].name()) + def test_getInstrumentReturns_A_InstrumentInfo_Object(self): self.assertTrue(isinstance(config.getInstrument("WISH"), InstrumentInfo)) self.assertRaises(RuntimeError, config.getInstrument, "MadeUpInstrument") diff --git a/Code/Mantid/MantidPlot/src/ConfigDialog.cpp b/Code/Mantid/MantidPlot/src/ConfigDialog.cpp index 3845979e32213a0fff1cf9dc7fd906b37ffc844a..280d422f514e87b33efc5fb2abb9c2727b57d30b 100644 --- a/Code/Mantid/MantidPlot/src/ConfigDialog.cpp +++ b/Code/Mantid/MantidPlot/src/ConfigDialog.cpp @@ -677,13 +677,15 @@ void ConfigDialog::initMantidPage() // Populate boxes Mantid::Kernel::ConfigServiceImpl & mantid_config = Mantid::Kernel::ConfigService::Instance(); - QString property = QString::fromStdString(mantid_config.getString("supported.facilities")); - QStringList prop_list = property.split(";", QString::SkipEmptyParts); - facility->addItems(prop_list); + auto faclist = mantid_config.getFacilityNames(); + for ( auto it = faclist.begin(); it != faclist.end(); ++it ) + { + facility->addItem(QString::fromStdString(*it)); + } // Set default property - property = QString::fromStdString(mantid_config.getFacility().name()); + QString property = QString::fromStdString(mantid_config.getFacility().name()); int index = facility->findText(property); if( index < 0 ) { diff --git a/Code/Mantid/MantidPlot/src/Mantid/FirstTimeSetup.cpp b/Code/Mantid/MantidPlot/src/Mantid/FirstTimeSetup.cpp index 361bccedde702458453bca6676b610207fea17a1..fad72df740c812ee0dd9b869c52ef5a453351455 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/FirstTimeSetup.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/FirstTimeSetup.cpp @@ -21,10 +21,10 @@ void FirstTimeSetup::initLayout() // Populate list of facilities m_uiForm.cbFacility->clear(); - QStringList faclist = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("supported.facilities")).split(";"); - for ( QStringList::iterator it = faclist.begin(); it != faclist.end(); ++it ) + auto faclist = Mantid::Kernel::ConfigService::Instance().getFacilityNames(); + for ( auto it = faclist.begin(); it != faclist.end(); ++it ) { - m_uiForm.cbFacility->addItem(*it); + m_uiForm.cbFacility->addItem(QString::fromStdString(*it)); } }