mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-29 23:39:26 -05:00
Reimplement data item click communication with luaScriptTopic
This commit is contained in:
committed by
Matthias Berg
parent
b762e49c91
commit
5262551964
@@ -35,6 +35,7 @@ source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/dataloadermodule.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/dataloadermodule_lua.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/helpers.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/operators/operator.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/operators/reader.cpp
|
||||
|
||||
@@ -27,10 +27,13 @@
|
||||
#include <modules/dataloader/operators/loader.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include "dataloadermodule_lua.inl"
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "DataLoaderModule";
|
||||
}
|
||||
@@ -117,4 +120,19 @@ openspace::dataloader::Loader* DataLoaderModule::loader() {
|
||||
return _loader.get();
|
||||
}
|
||||
|
||||
scripting::LuaLibrary DataLoaderModule::luaLibrary() const {
|
||||
return{
|
||||
"dataloader",
|
||||
{
|
||||
{
|
||||
"loadItem",
|
||||
&luascriptfunctions::loadItem,
|
||||
{},
|
||||
"string",
|
||||
"Loads a data item into Open Space"
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace openspace::dataloader {
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace scripting { struct LuaLibrary; }
|
||||
|
||||
enum DataTypes {
|
||||
volume
|
||||
};
|
||||
@@ -62,6 +64,8 @@ public:
|
||||
|
||||
void loadDataItem(std::string absPathToItem);
|
||||
|
||||
scripting::LuaLibrary luaLibrary() const override;
|
||||
|
||||
dataloader::Reader* reader();
|
||||
dataloader::Loader* loader();
|
||||
|
||||
|
||||
+17
-14
@@ -22,23 +22,26 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_MODULE_SERVER___LOADDATAITEMTOPIC___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___LOADDATAITEMTOPIC___H__
|
||||
namespace openspace::luascriptfunctions {
|
||||
|
||||
#include <ext/json/json.hpp>
|
||||
#include <modules/server/include/topic.h>
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* loadItem(string):
|
||||
* Load a data item
|
||||
*/
|
||||
int loadItem(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::loadItem");
|
||||
|
||||
namespace openspace {
|
||||
using ghoul::lua::errorLocation;
|
||||
|
||||
class LoadDataItemTopic : public Topic {
|
||||
public:
|
||||
LoadDataItemTopic() : Topic() {};
|
||||
~LoadDataItemTopic() {};
|
||||
void handleJson(nlohmann::json json);
|
||||
bool isDone() { return true; };
|
||||
};
|
||||
std::string path = ghoul::lua::checkStringAndPop(L);
|
||||
|
||||
} // namespace openspace
|
||||
/** handle path to check item type or handle it in different function **/
|
||||
|
||||
#endif // __OPENSPACE_MODULE_SERVER___LOADDATAITEMTOPIC___H__
|
||||
OsEng.moduleEngine().module<DataLoaderModule>()->loadDataItem(path);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace openspace::luascriptfunctions
|
||||
@@ -3,20 +3,56 @@
|
||||
#include <regex>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <ghoul/filesystem/directory.h>
|
||||
|
||||
using Directory = ghoul::filesystem::Directory;
|
||||
using Recursive = ghoul::filesystem::Directory::Recursive;
|
||||
using Sort = ghoul::filesystem::Directory::Sort;
|
||||
|
||||
namespace openspace::dataloader::helpers {
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "Helper";
|
||||
}
|
||||
|
||||
std::string getDirLeaf(std::string dir) {
|
||||
std::regex dirLeaf_regex("([^/]+)/?$");
|
||||
std::smatch dirLeaf_match;
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "Helper";
|
||||
}
|
||||
|
||||
if (std::regex_search(dir, dirLeaf_match, dirLeaf_regex)) {
|
||||
return dirLeaf_match[0].str();
|
||||
} else {
|
||||
LWARNING("Found no match in " + dir + ".");
|
||||
}
|
||||
std::string getDirLeaf(std::string dir) {
|
||||
std::regex dirLeaf_regex("([^/]+)/?$");
|
||||
std::smatch dirLeaf_match;
|
||||
|
||||
if (std::regex_search(dir, dirLeaf_match, dirLeaf_regex)) {
|
||||
return dirLeaf_match[0].str();
|
||||
} else {
|
||||
LWARNING("Found no match in " + dir + ".");
|
||||
}
|
||||
}
|
||||
|
||||
std::string findStateFile(std::string absPathToItem) {
|
||||
Directory topDir("${DATA}/.internal", Directory::RawPath::No);
|
||||
|
||||
Directory volumeDir(
|
||||
topDir.path() +
|
||||
ghoul::filesystem::FileSystem::PathSeparator +
|
||||
"volumes_from_cdf"
|
||||
);
|
||||
|
||||
std::vector<std::string> itemFiles = volumeDir.readFiles(Recursive::No, Sort::No);
|
||||
std::string stateFile = "";
|
||||
|
||||
// Find (first) file with a .state extension
|
||||
std::regex stateExtRegex("^.*\.(state)$");
|
||||
std::smatch stateMatch;
|
||||
for (auto file : itemFiles) {
|
||||
if (std::regex_search(file, stateMatch, stateExtRegex)) {
|
||||
stateFile = file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ghoul_assert(!stateFile.empty(), "Couldn't find a .state file in " + absPathToItem);
|
||||
|
||||
return stateFile;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,4 +2,6 @@
|
||||
|
||||
namespace openspace::dataloader::helpers {
|
||||
std::string getDirLeaf(std::string dir);
|
||||
|
||||
std::string findStateFile(std::string absPathToItem);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <string>
|
||||
#include <modules/dataloader/operators/loader.h>
|
||||
#include <modules/dataloader/dataloadermodule.h>
|
||||
@@ -133,8 +134,8 @@ void Loader::uploadData() {
|
||||
}
|
||||
|
||||
void Loader::createInternalDataItemProperties() {
|
||||
getModule()->validateDataDirectory();
|
||||
std::vector<std::string> volumeItems = getModule()->volumeDataItems();
|
||||
module()->validateDataDirectory();
|
||||
std::vector<std::string> volumeItems = module()->volumeDataItems();
|
||||
|
||||
LDEBUG("volume items vec size " + std::to_string(volumeItems.size()));
|
||||
|
||||
@@ -154,8 +155,8 @@ void Loader::createInternalDataItemProperties() {
|
||||
// loadDataItem(item);
|
||||
});
|
||||
|
||||
addProperty(volumeItemTrigger);
|
||||
LDEBUG("Added property " + dirLeaf);
|
||||
// addProperty(volumeItemTrigger);
|
||||
// LDEBUG("Added property " + dirLeaf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +169,34 @@ void Loader::createInternalDataItemProperties() {
|
||||
|
||||
void Loader::loadDataItem(std::string absPathToItem) {
|
||||
LINFO("Load item " + absPathToItem);
|
||||
|
||||
std::string stateFile = openspace::dataloader::helpers::findStateFile(absPathToItem);
|
||||
|
||||
// extract as dictionary
|
||||
ghoul::Dictionary stateDict = ghoul::lua::loadDictionaryFromFile(stateFile);
|
||||
|
||||
// Renderable
|
||||
// Set Type = RenderableTimeVaryingVolume
|
||||
// Set transferfunction directory
|
||||
// Set source directory to absPathToItem
|
||||
// ?? that's it
|
||||
|
||||
// Make renderable
|
||||
// timevaryingvolume instance?
|
||||
// is the renderable displayed at this point?
|
||||
|
||||
// create rest of, more complete, dictionary for scene graph node
|
||||
const std::string dirLeaf = openspace::dataloader::helpers::getDirLeaf(absPathToItem);
|
||||
const std::string identifier = dirLeaf;
|
||||
const std::string parent = "";
|
||||
|
||||
// create node
|
||||
// SceneGraphNode node = createFromDictionary(?)
|
||||
|
||||
// get scene, add node to scene graph
|
||||
// getScene()->
|
||||
|
||||
// great success
|
||||
}
|
||||
|
||||
// void Loader::createVolumeDataItem(std::string absPath);
|
||||
@@ -200,4 +229,8 @@ ghoul::Dictionary Loader::createTaskDictionary(std::string filePath) {
|
||||
return ghoul::Dictionary(list);
|
||||
}
|
||||
|
||||
}
|
||||
// ghoul::Dictionary Loader::createVolumeItemDictionary(std::string dataDictionaryPath, std::string dataStatePath) {
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -77,4 +77,3 @@ class Loader : public PropertyOwner, public Operator {
|
||||
}
|
||||
|
||||
#endif // __OPENSPACE_MODULE_DATALOADER___LOADER___H__
|
||||
|
||||
|
||||
@@ -3,11 +3,16 @@
|
||||
#include <modules/dataloader/dataloadermodule.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
|
||||
namespace openspace::dataloader {
|
||||
|
||||
DataLoaderModule* Operator::getModule() {
|
||||
DataLoaderModule* Operator::module() {
|
||||
return OsEng.moduleEngine().module<DataLoaderModule>();
|
||||
}
|
||||
|
||||
Scene* Operator::scene() {
|
||||
return OsEng.renderEngine().scene();
|
||||
}
|
||||
|
||||
} // namespace openspace::dataloader
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
namespace openspace {
|
||||
|
||||
class DataLoaderModule;
|
||||
class Scene;
|
||||
|
||||
namespace dataloader {
|
||||
|
||||
@@ -13,10 +14,11 @@ class Operator {
|
||||
virtual ~Operator() {};
|
||||
|
||||
protected:
|
||||
DataLoaderModule* getModule();
|
||||
DataLoaderModule* module();
|
||||
Scene* scene();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace dataloader
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_DATALOADER___OPERATOR___H__
|
||||
@@ -29,10 +29,12 @@
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <regex>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -40,6 +42,10 @@
|
||||
#endif
|
||||
|
||||
|
||||
using Directory = ghoul::filesystem::Directory;
|
||||
using Recursive = ghoul::filesystem::Directory::Recursive;
|
||||
using Sort = ghoul::filesystem::Directory::Sort;
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "Reader";
|
||||
}
|
||||
@@ -77,19 +83,15 @@ Reader::Reader()
|
||||
}
|
||||
|
||||
void Reader::readVolumeDataItems() {
|
||||
ghoul::filesystem::Directory volumeDir(
|
||||
_topDir.path() +
|
||||
ghoul::filesystem::FileSystem::PathSeparator +
|
||||
"volumes_from_cdf"
|
||||
);
|
||||
Directory volumeDir = getVolumeDir();
|
||||
|
||||
std::vector volumeItems = volumeDir.readDirectories(
|
||||
ghoul::filesystem::Directory::Recursive::No,
|
||||
ghoul::filesystem::Directory::Sort::Yes
|
||||
Recursive::No,
|
||||
Sort::Yes
|
||||
);
|
||||
|
||||
getModule()->setVolumeDataItems(volumeItems);
|
||||
getModule()->setDataDirectoryRead(true);
|
||||
module()->setVolumeDataItems(volumeItems);
|
||||
module()->setDataDirectoryRead(true);
|
||||
|
||||
// for (auto el : volumeItems) {
|
||||
// LINFO("A dir: " + el);
|
||||
@@ -111,4 +113,13 @@ void Reader::readVolumeDataItems() {
|
||||
|
||||
// Store a reference somehow if necessary
|
||||
}
|
||||
|
||||
Directory Reader::getVolumeDir() {
|
||||
return Directory(
|
||||
_topDir.path() +
|
||||
ghoul::filesystem::FileSystem::PathSeparator +
|
||||
"volumes_from_cdf"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,11 +34,13 @@
|
||||
namespace openspace::dataloader {
|
||||
|
||||
using properties::PropertyOwner;
|
||||
using Directory = ghoul::filesystem::Directory;
|
||||
|
||||
class Reader : public PropertyOwner, public Operator {
|
||||
public:
|
||||
Reader();
|
||||
|
||||
Directory getVolumeDir();
|
||||
void readVolumeDataItems();
|
||||
|
||||
private:
|
||||
|
||||
@@ -50,7 +50,6 @@ namespace {
|
||||
constexpr const char* AuthenticationTopicKey = "authorize";
|
||||
constexpr const char* GetPropertyTopicKey = "get";
|
||||
constexpr const char* LuaScriptTopicKey = "luascript";
|
||||
constexpr const char* LoadDataItemTopicKey = "loaddataitem";
|
||||
constexpr const char* SetPropertyTopicKey = "set";
|
||||
constexpr const char* SubscriptionTopicKey = "subscribe";
|
||||
constexpr const char* TimeTopicKey = "time";
|
||||
@@ -69,7 +68,6 @@ Connection::Connection(std::unique_ptr<ghoul::io::Socket> s, std::string address
|
||||
_topicFactory.registerClass<AuthorizationTopic>(AuthenticationTopicKey);
|
||||
_topicFactory.registerClass<GetPropertyTopic>(GetPropertyTopicKey);
|
||||
_topicFactory.registerClass<LuaScriptTopic>(LuaScriptTopicKey);
|
||||
_topicFactory.registerClass<LoadDataItemTopic>(LoadDataItemTopicKey);
|
||||
_topicFactory.registerClass<SetPropertyTopic>(SetPropertyTopicKey);
|
||||
_topicFactory.registerClass<SubscriptionTopic>(SubscriptionTopicKey);
|
||||
_topicFactory.registerClass<TimeTopic>(TimeTopicKey);
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2018 *
|
||||
* *
|
||||
* 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 <modules/dataloader/dataloadermodule.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
// #include <openspace/scripting/scriptengine.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <modules/server/include/loaddataitemtopic.h>
|
||||
|
||||
namespace {
|
||||
const std::string ItemPathKey = "item";
|
||||
const std::string _loggerCat = "LoadDataItemTopic";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
void LoadDataItemTopic::handleJson(nlohmann::json json) {
|
||||
try {
|
||||
LINFO("call dataloadermodule function");
|
||||
auto absItemPath = json.at(ItemPathKey).get<std::string>();
|
||||
OsEng.moduleEngine().module<DataLoaderModule>()->loadDataItem(absItemPath);
|
||||
}
|
||||
catch (const std::out_of_range& e) {
|
||||
LERROR("Could not run script -- key or value is missing in payload");
|
||||
LERROR(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ const TOPIC_TYPES = {
|
||||
get: 'get',
|
||||
interaction: 'interaction',
|
||||
luascript: 'luascript',
|
||||
loaddataitem: 'loaddataitem',
|
||||
set: 'set',
|
||||
subscribe: 'subscribe',
|
||||
time: 'time',
|
||||
@@ -138,20 +137,6 @@ class DataManager {
|
||||
this.send(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call data loader for an item
|
||||
* @param item - the item to load
|
||||
*/
|
||||
loadDataItem(item: string) {
|
||||
const message = this.wrapMessage({
|
||||
type: TOPIC_TYPES.loaddataitem,
|
||||
payload: {
|
||||
item,
|
||||
},
|
||||
});
|
||||
this.send(message);
|
||||
}
|
||||
|
||||
createSubscription(key: string, type: string = TOPIC_TYPES.subscribe) {
|
||||
const message = this.wrapMessage({
|
||||
type,
|
||||
|
||||
@@ -31,3 +31,5 @@ export const DeltaTime = 'deltaTime';
|
||||
export const ValuePlaceholder = '___value___';
|
||||
// script for setting deltatime
|
||||
export const SetDeltaTimeScript = `openspace.time.setDeltaTime(${ValuePlaceholder})`;
|
||||
|
||||
export const LoadDataItemScript = `openspace.dataloader.loadItem(${ValuePlaceholder})`;
|
||||
|
||||
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
||||
import styles from './DataItemList.scss';
|
||||
|
||||
import DataManager from '../../../api/DataManager';
|
||||
import { ValuePlaceholder, LoadDataItemScript } from '../../../api/keys';
|
||||
|
||||
import { getDirectoryLeaf } from '../utils/helpers';
|
||||
|
||||
@@ -17,8 +18,8 @@ class DataItemList extends React.Component {
|
||||
}
|
||||
|
||||
handleClick(path) {
|
||||
// DataManager.trigger(`Modules.DataLoader.Loader.ItemTrigger_${dirLeaf}`);
|
||||
DataManager.loadDataItem(path);
|
||||
const script = LoadDataItemScript.replace(ValuePlaceholder, `\'${path}\'`);
|
||||
DataManager.runScript(script);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
Reference in New Issue
Block a user