mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-19 03:19:06 -06:00
Merge branch 'master' into issue/1466
This commit is contained in:
@@ -71,14 +71,18 @@ std::string to_string(const openspace::documentation::TestResult& value) {
|
||||
}
|
||||
else {
|
||||
std::stringstream stream;
|
||||
stream << "Failure." << '\n';
|
||||
stream << "Specification Failure. ";
|
||||
|
||||
for (const TestResult::Offense& offense : value.offenses) {
|
||||
stream << " " << ghoul::to_string(offense) << '\n';
|
||||
stream << fmt::format(" {}", ghoul::to_string(offense));
|
||||
if (!offense.explanation.empty()) {
|
||||
stream << fmt::format(" ({})", offense.explanation);
|
||||
}
|
||||
stream << '\n';
|
||||
}
|
||||
|
||||
for (const TestResult::Warning& warning : value.warnings) {
|
||||
stream << " " << ghoul::to_string(warning) << '\n';
|
||||
stream << fmt::format(" {}\n", ghoul::to_string(warning));
|
||||
}
|
||||
|
||||
return stream.str();
|
||||
@@ -129,17 +133,26 @@ namespace openspace::documentation {
|
||||
|
||||
const std::string DocumentationEntry::Wildcard = "*";
|
||||
|
||||
//std::string concatenate(const std::vector<TestResult::Offense>& offenses) {
|
||||
// std::string result = "Error in specification (";
|
||||
// for (const TestResult::Offense& o : offenses) {
|
||||
// if (o.explanation.empty()) {
|
||||
// result += fmt::format("{} ({}), ", o.offender, ghoul::to_string(o.reason));
|
||||
// }
|
||||
// else {
|
||||
// result += fmt::format("{} ({}: {}), ", o.offender, ghoul::to_string(o.reason), o.explanation);
|
||||
// }
|
||||
// }
|
||||
// result.pop_back();
|
||||
// result.back() = ')';
|
||||
// return result;
|
||||
//}
|
||||
|
||||
SpecificationError::SpecificationError(TestResult res, std::string comp)
|
||||
: ghoul::RuntimeError("Error in specification", std::move(comp))
|
||||
, result(std::move(res))
|
||||
{
|
||||
ghoul_assert(!result.success, "Result's success must be false");
|
||||
|
||||
message += " (";
|
||||
for (const TestResult::Offense& o : result.offenses) {
|
||||
message += o.offender + ',';
|
||||
}
|
||||
message.back() = ')';
|
||||
}
|
||||
|
||||
DocumentationEntry::DocumentationEntry(std::string k, std::shared_ptr<Verifier> v,
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <openspace/documentation/documentationengine.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
|
||||
namespace openspace::documentation {
|
||||
|
||||
@@ -177,6 +178,121 @@ std::string StringVerifier::type() const {
|
||||
return "String";
|
||||
}
|
||||
|
||||
TestResult FileVerifier::operator()(const ghoul::Dictionary& dict,
|
||||
const std::string& key) const
|
||||
{
|
||||
TestResult res = StringVerifier::operator()(dict, key);
|
||||
if (!res.success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string file = dict.value<std::string>(key);
|
||||
if (!std::filesystem::exists(file) || !std::filesystem::is_regular_file(file)) {
|
||||
res.success = false;
|
||||
TestResult::Offense off;
|
||||
off.offender = key;
|
||||
off.reason = TestResult::Offense::Reason::Verification;
|
||||
off.explanation = "File did not exist";
|
||||
res.offenses.push_back(off);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string FileVerifier::type() const {
|
||||
return "File";
|
||||
}
|
||||
|
||||
TestResult DirectoryVerifier::operator()(const ghoul::Dictionary& dict,
|
||||
const std::string& key) const
|
||||
{
|
||||
TestResult res = StringVerifier::operator()(dict, key);
|
||||
if (!res.success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string dir = dict.value<std::string>(key);
|
||||
if (!std::filesystem::exists(dir) || !std::filesystem::is_directory(dir)) {
|
||||
res.success = false;
|
||||
TestResult::Offense off;
|
||||
off.offender = key;
|
||||
off.reason = TestResult::Offense::Reason::Verification;
|
||||
off.explanation = "Directory did not exist";
|
||||
res.offenses.push_back(off);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string DirectoryVerifier::type() const {
|
||||
return "Directory";
|
||||
}
|
||||
|
||||
TestResult Color3Verifier::operator()(const ghoul::Dictionary& dictionary,
|
||||
const std::string& key) const
|
||||
{
|
||||
TestResult res = Vector3Verifier<double>::operator()(dictionary, key);
|
||||
if (!res.success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
glm::dvec3 values = dictionary.value<glm::dvec3>(key);
|
||||
if (values.x < 0.0 || values.x > 1.0) {
|
||||
res.success = false;
|
||||
res.offenses.push_back({ key + ".x", TestResult::Offense::Reason::Verification });
|
||||
}
|
||||
|
||||
if (values.y < 0.0 || values.y > 1.0) {
|
||||
res.success = false;
|
||||
res.offenses.push_back({ key + ".y", TestResult::Offense::Reason::Verification });
|
||||
}
|
||||
|
||||
if (values.z < 0.0 || values.z > 1.0) {
|
||||
res.success = false;
|
||||
res.offenses.push_back({ key + ".z", TestResult::Offense::Reason::Verification });
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string Color3Verifier::type() const {
|
||||
return std::string("Color3");
|
||||
}
|
||||
|
||||
TestResult Color4Verifier::operator()(const ghoul::Dictionary& dictionary,
|
||||
const std::string& key) const
|
||||
{
|
||||
TestResult res = Vector4Verifier<double>::operator()(dictionary, key);
|
||||
if (!res.success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<double> values = dictionary.value<std::vector<double>>(key);
|
||||
if (values[0] < 0.0 || values[0] > 1.0) {
|
||||
res.success = false;
|
||||
res.offenses.push_back({ key + ".x", TestResult::Offense::Reason::Verification });
|
||||
}
|
||||
|
||||
if (values[1] < 0.0 || values[1] > 1.0) {
|
||||
res.success = false;
|
||||
res.offenses.push_back({ key + ".y", TestResult::Offense::Reason::Verification });
|
||||
}
|
||||
|
||||
if (values[2] < 0.0 || values[2] > 1.0) {
|
||||
res.success = false;
|
||||
res.offenses.push_back({ key + ".z", TestResult::Offense::Reason::Verification });
|
||||
}
|
||||
|
||||
if (values[3] < 0.0 || values[3] > 1.0) {
|
||||
res.success = false;
|
||||
res.offenses.push_back({ key + ".a", TestResult::Offense::Reason::Verification });
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string Color4Verifier::type() const {
|
||||
return std::string("Color4");
|
||||
}
|
||||
|
||||
template <>
|
||||
TestResult TemplateVerifier<glm::ivec2>::operator()(const ghoul::Dictionary& dict,
|
||||
const std::string& key) const
|
||||
|
||||
@@ -58,7 +58,20 @@ void ModuleEngine::initialize(
|
||||
if (it != moduleConfigurations.end()) {
|
||||
configuration = it->second;
|
||||
}
|
||||
m->initialize(configuration);
|
||||
try {
|
||||
m->initialize(configuration);
|
||||
}
|
||||
catch (const documentation::SpecificationError& e) {
|
||||
//LFATALC(e.component, e.message);
|
||||
for (const documentation::TestResult::Offense& o : e.result.offenses) {
|
||||
LERRORC(e.component, o.offender + ": " + ghoul::to_string(o.reason));
|
||||
}
|
||||
for (const documentation::TestResult::Warning& w : e.result.warnings) {
|
||||
LWARNINGC(e.component, w.offender + ": " + ghoul::to_string(w.reason));
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
addPropertySubOwner(m);
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +71,6 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/logging/consolelog.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/logging/visualstudiooutputlog.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
@@ -83,6 +82,7 @@
|
||||
#include <ghoul/systemcapabilities/openglcapabilitiescomponent.h>
|
||||
#include <glbinding/glbinding.h>
|
||||
#include <glbinding-aux/types_to_string.h>
|
||||
#include <filesystem>
|
||||
#include <future>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
@@ -234,7 +234,6 @@ void OpenSpaceEngine::initialize() {
|
||||
|
||||
using ImmediateFlush = ghoul::logging::LogManager::ImmediateFlush;
|
||||
ghoul::logging::LogManager::initialize(level, ImmediateFlush(immediateFlush));
|
||||
LogMgr.addLog(std::make_unique<ghoul::logging::ConsoleLog>());
|
||||
|
||||
for (const ghoul::Dictionary& log : global::configuration->logging.logs) {
|
||||
try {
|
||||
@@ -1444,6 +1443,52 @@ void OpenSpaceEngine::touchExitCallback(TouchInput input) {
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::handleDragDrop(const std::string& file) {
|
||||
std::filesystem::path f(file);
|
||||
|
||||
ghoul::lua::LuaState s(ghoul::lua::LuaState::IncludeStandardLibrary::Yes);
|
||||
std::string absolutePath = absPath("${SCRIPTS}/drag_drop_handler.lua");
|
||||
int status = luaL_loadfile(s, absolutePath.c_str());
|
||||
if (status != LUA_OK) {
|
||||
std::string error = lua_tostring(s, -1);
|
||||
LERROR(error);
|
||||
return;
|
||||
}
|
||||
|
||||
ghoul::lua::push(s, file);
|
||||
lua_setglobal(s, "filename");
|
||||
|
||||
std::string basename = f.filename().string();
|
||||
ghoul::lua::push(s, basename);
|
||||
lua_setglobal(s, "basename");
|
||||
|
||||
std::string extension = f.extension().string();
|
||||
std::transform(
|
||||
extension.begin(), extension.end(),
|
||||
extension.begin(),
|
||||
[](char c) { return static_cast<char>(::tolower(c)); }
|
||||
);
|
||||
ghoul::lua::push(s, extension);
|
||||
lua_setglobal(s, "extension");
|
||||
|
||||
status = lua_pcall(s, 0, 1, 0);
|
||||
if (status != LUA_OK) {
|
||||
std::string error = lua_tostring(s, -1);
|
||||
LERROR(error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lua_isnil(s, -1)) {
|
||||
LWARNING(fmt::format("Unhandled file dropped: {}", file));
|
||||
return;
|
||||
}
|
||||
|
||||
std::string script = ghoul::lua::value<std::string>(s);
|
||||
global::scriptEngine->queueScript(
|
||||
script,
|
||||
scripting::ScriptEngine::RemoteScripting::Yes
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<std::byte> OpenSpaceEngine::encode() {
|
||||
ZoneScoped
|
||||
|
||||
@@ -45,6 +45,9 @@ SceneGraphNode* sceneGraphNode(const std::string& name) {
|
||||
|
||||
const Renderable* renderable(const std::string& name) {
|
||||
SceneGraphNode* node = sceneGraphNode(name);
|
||||
if (!node) {
|
||||
return nullptr;
|
||||
}
|
||||
return node->renderable();
|
||||
}
|
||||
|
||||
|
||||
@@ -520,9 +520,8 @@ bool Asset::initialize() {
|
||||
loader()->callOnInitialize(this);
|
||||
}
|
||||
catch (const ghoul::lua::LuaRuntimeException& e) {
|
||||
LERROR(fmt::format(
|
||||
"Failed to initialize asset {}; {}: {}", id(), e.component, e.message
|
||||
));
|
||||
LERROR(fmt::format("Failed to initialize asset {}", id()));
|
||||
LERROR(fmt::format("{}: {}", e.component, e.message));
|
||||
// TODO: rollback;
|
||||
setState(State::InitializationFailed);
|
||||
return false;
|
||||
|
||||
@@ -648,10 +648,10 @@ int addSceneGraphNode(lua_State* L) {
|
||||
global::renderEngine->scene()->initializeNode(node);
|
||||
}
|
||||
catch (const documentation::SpecificationError& e) {
|
||||
LERRORC("Scene", ghoul::to_string(e.result));
|
||||
return ghoul::lua::luaError(
|
||||
L,
|
||||
fmt::format("Error loading scene graph node: {}: {}",
|
||||
e.what(), ghoul::to_string(e.result))
|
||||
fmt::format("Error loading scene graph node: {}", e.what())
|
||||
);
|
||||
}
|
||||
catch (const ghoul::RuntimeError& e) {
|
||||
|
||||
Reference in New Issue
Block a user