/***************************************************************************************** * * * OpenSpace * * * * Copyright (c) 2014-2017 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * * without restriction, including without limitation the rights to use, copy, modify, * * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * * permit persons to whom the Software is furnished to do so, subject to the following * * conditions: * * * * The above copyright notice and this permission notice shall be included in all copies * * or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ #include #include #include #include #include #include #include #include namespace openspace { namespace globebrowsing { namespace luascriptfunctions { /** Adds a layer to the specified globe. */ int addLayer(lua_State* L) { using ghoul::lua::errorLocation; // Argument locations const int GlobeLocation = -3; const int LayerGroupLocation = -2; const int DictionaryLocation = -1; int nArguments = lua_gettop(L); if (nArguments != 3) { return luaL_error(L, "Expected %i arguments, got %i", 3, nArguments); } // String arguments const std::string GlobeName = luaL_checkstring(L, GlobeLocation); const std::string LayerGroupName = luaL_checkstring(L, LayerGroupLocation); // Get the node and make sure it exists SceneGraphNode* node = OsEng.renderEngine().scene()->sceneGraphNode(GlobeName); if (!node) { return luaL_error(L, ("Unknown globe name: " + GlobeName).c_str()); } // Get the renderable globe RenderableGlobe* globe = dynamic_cast(node->renderable()); if (!globe) { return luaL_error(L, ("Renderable is not a globe: " + GlobeName).c_str()); } // Get the layer group layergroupid::GroupID groupID = layergroupid::getGroupIDFromName(LayerGroupName); if (groupID == layergroupid::GroupID::Unknown) { return luaL_error(L, ("Unknown layer group: " + LayerGroupName).c_str()); } // Get the dictionary defining the layer ghoul::Dictionary d; try { ghoul::lua::luaDictionaryFromState(L, d); } catch (const ghoul::lua::LuaFormatException& e) { LERRORC("addLayerFromDictionary", e.what()); return 0; } globe->layerManager()->addLayer(groupID, d); return 0; } /** Deletes a layer from the specified globe. */ int deleteLayer(lua_State* L) { using ghoul::lua::errorLocation; // Argument locations const int GlobeLocation = -3; const int LayerGroupLocation = -2; const int NameLocation = -1; int nArguments = lua_gettop(L); if (nArguments != 3) { return luaL_error(L, "Expected %i arguments, got %i", 3, nArguments); } // String arguments const std::string GlobeName = luaL_checkstring(L, GlobeLocation); const std::string LayerGroupName = luaL_checkstring(L, LayerGroupLocation); const std::string LayerName = luaL_checkstring(L, NameLocation); // Get the node and make sure it exists SceneGraphNode* node = OsEng.renderEngine().scene()->sceneGraphNode(GlobeName); if (!node) { return luaL_error(L, ("Unknown globe name: " + GlobeName).c_str()); } // Get the renderable globe RenderableGlobe* globe = dynamic_cast(node->renderable()); if (!globe) { return luaL_error(L, ("Renderable is not a globe: " + GlobeName).c_str()); } // Get the layer group layergroupid::GroupID groupID = layergroupid::getGroupIDFromName(LayerGroupName); if (groupID == layergroupid::GroupID::Unknown) { return luaL_error(L, ("Unknown layer group: " + LayerGroupName).c_str()); } globe->layerManager()->deleteLayer(groupID, LayerName); return 0; } } // namespace luascriptfunctions } // nameapace globebrowsing } // namespace openspace