Send over image name and url to GUI api

This commit is contained in:
Ylva Selling
2021-04-07 16:09:14 +02:00
parent 794902d5cb
commit 3f68ea9b4d
3 changed files with 28 additions and 12 deletions

View File

@@ -27,7 +27,8 @@ namespace openspace {
void loadWTMLCollectionsFromDirectory(std::string directory);
int loadAllImagesFromXMLs();
void printAllUrls();
std::vector<std::string> getAllThumbnailUrls();
std::vector < std::pair < std::string, std::string> > getAllThumbnailUrls();
const std::vector<ImageData>& getImages() const;
private:
int loadPlace(tinyxml2::XMLElement* place, std::string collectionName);

View File

@@ -63,24 +63,36 @@ namespace openspace::skybrowser::luascriptfunctions {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::moveBrowser");
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
module->getWWTDataHandler()->loadWTMLCollectionsFromDirectory(absPath("${MODULE_SKYBROWSER}/WWTimagedata/"));
module->getWWTDataHandler()->printAllUrls();
LINFO(std::to_string(module->getWWTDataHandler()->loadAllImagesFromXMLs()));
std::string noOfLoadedImgs = std::to_string(module->getWWTDataHandler()->loadAllImagesFromXMLs());
LINFO("Loaded " + noOfLoadedImgs + " WorldWide Telescope images.");
return 1;
}
int createBrowser(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::createBrowser");
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
std::vector<std::string> names = module->getWWTDataHandler()->getAllThumbnailUrls();
// If no data has been loaded yet, load it!
if (module->getWWTDataHandler()->getImages().size() == 0) {
moveBrowser(L);
}
std::vector<std::pair<std::string, std::string>> names = module->getWWTDataHandler()->getAllThumbnailUrls();
lua_newtable(L);
int number = 1;
for (const std::string& s : names) {
lua_pushstring(L, s.c_str());
for (const std::pair<std::string, std::string>& s : names) {
lua_newtable(L);
lua_pushstring(L, s.first.c_str());
lua_rawseti(L, -2, 1);
lua_pushstring(L, s.second.c_str());
lua_rawseti(L, -2, 2);
lua_rawseti(L, -2, number);
++number;
}
return 1;
}
int adjustCamera(lua_State* L) {

View File

@@ -209,12 +209,15 @@ namespace openspace {
return node;
}
std::vector<std::string> WWTDataHandler::getAllThumbnailUrls() {
std::vector<std::string> imgUrls;
std::vector < std::pair < std::string, std::string> > WWTDataHandler::getAllThumbnailUrls() {
std::vector < std::pair < std::string, std::string> > imgResult;
std::for_each(images.begin(), images.end(), [&](ImageData obj) {
imgUrls.push_back(obj.thumbnailUrl);
imgResult.push_back(std::pair(obj.name, obj.thumbnailUrl));
});
return imgUrls;
return imgResult;
}
const std::vector<ImageData>& WWTDataHandler::getImages() const {
return images;
}
}