mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-08 04:20:14 -05:00
Create subclass of ScreenSpaceBrowser in SkyBrowserModule and change name of module Skybrowser to SkyBrowser
This commit is contained in:
@@ -27,6 +27,7 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
set(HEADER_FILES
|
||||
|
||||
skybrowsermodule.h
|
||||
include/screenspaceskybrowser.h
|
||||
|
||||
)
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
@@ -35,12 +36,13 @@ set(SOURCE_FILES
|
||||
|
||||
skybrowsermodule.cpp
|
||||
skybrowsermodule_lua.inl
|
||||
src/screenspaceskybrowser.cpp
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
|
||||
|
||||
create_new_module(
|
||||
"Skybrowser"
|
||||
"SkyBrowser"
|
||||
skybrowser_module
|
||||
STATIC
|
||||
${HEADER_FILES} ${SOURCE_FILES}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef __OPENSPACE_MODULE_SKYBROWSER___SCREENSPACESKYBROWSER___H__
|
||||
#define __OPENSPACE_MODULE_SKYBROWSER___SCREENSPACESKYBROWSER___H__
|
||||
|
||||
#include <modules/webbrowser/include/screenspacebrowser.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ScreenSpaceSkyBrowser : public ScreenSpaceBrowser
|
||||
{
|
||||
public:
|
||||
ScreenSpaceSkyBrowser(const ghoul::Dictionary& dictionary);
|
||||
virtual ~ScreenSpaceSkyBrowser() = default;
|
||||
void executeJavascript(std::string& script) const;
|
||||
void translate(glm::vec3 translation);
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __OPENSPACE_MODULE_SKYBROWSER___SCREENSPACESKYBROWSER___H__
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace {
|
||||
"tjobidabidobidabidopp plupp"
|
||||
};
|
||||
|
||||
struct [[codegen::Dictionary(SkybrowserModule)]] Parameters {
|
||||
struct [[codegen::Dictionary(SkyBrowserModule)]] Parameters {
|
||||
|
||||
// [[codegen::verbatim(TestInfo.description)]]
|
||||
std::optional<std::string> test;
|
||||
@@ -78,8 +78,8 @@ namespace {
|
||||
|
||||
namespace openspace {
|
||||
|
||||
SkybrowserModule::SkybrowserModule()
|
||||
: OpenSpaceModule(Name)
|
||||
SkyBrowserModule::SkyBrowserModule()
|
||||
: OpenSpaceModule(SkyBrowserModule::Name)
|
||||
, _testProperty(TestInfo)
|
||||
, _zoomFactor(ZoomInfo, 50.f ,0.1f ,70.f)
|
||||
, _skyBrowser(nullptr)
|
||||
@@ -90,7 +90,7 @@ SkybrowserModule::SkybrowserModule()
|
||||
|
||||
|
||||
|
||||
scripting::LuaLibrary SkybrowserModule::luaLibrary() const {
|
||||
scripting::LuaLibrary SkyBrowserModule::luaLibrary() const {
|
||||
scripting::LuaLibrary res;
|
||||
res.name = "skybrowser";
|
||||
res.functions = {
|
||||
@@ -123,17 +123,23 @@ scripting::LuaLibrary SkybrowserModule::luaLibrary() const {
|
||||
return res;
|
||||
}
|
||||
|
||||
float SkybrowserModule::zoomFactor() const{
|
||||
float SkyBrowserModule::zoomFactor() const{
|
||||
return _zoomFactor;
|
||||
}
|
||||
|
||||
void SkybrowserModule::internalInitialize(const ghoul::Dictionary& dict) {
|
||||
void SkyBrowserModule::internalInitialize(const ghoul::Dictionary& dict) {
|
||||
|
||||
const Parameters p = codegen::bake<Parameters>(dict);
|
||||
_testProperty = p.test.value_or(_testProperty);
|
||||
_zoomFactor = p.zoom.value_or(_zoomFactor);
|
||||
|
||||
// register ScreenSpaceBrowser
|
||||
auto fScreenSpaceRenderable = FactoryManager::ref().factory<ScreenSpaceRenderable>();
|
||||
ghoul_assert(fScreenSpaceRenderable, "ScreenSpaceRenderable factory was not created");
|
||||
fScreenSpaceRenderable->registerClass<ScreenSpaceSkyBrowser>("ScreenSpaceSkyBrowser");
|
||||
}
|
||||
|
||||
bool SkybrowserModule::sendMessageToWWT(const ghoul::Dictionary& msg) {
|
||||
bool SkyBrowserModule::sendMessageToWWT(const ghoul::Dictionary& msg) {
|
||||
if (_skyBrowser) {
|
||||
std::string script = "sendMessageToWWT(" + ghoul::formatJson(msg) + ");";
|
||||
_skyBrowser->executeJavascript(script);
|
||||
@@ -145,7 +151,7 @@ bool SkybrowserModule::sendMessageToWWT(const ghoul::Dictionary& msg) {
|
||||
}
|
||||
}
|
||||
|
||||
void SkybrowserModule::WWTfollowCamera() {
|
||||
void SkyBrowserModule::WWTfollowCamera() {
|
||||
showTarget();
|
||||
while (true) {
|
||||
// Get camera view direction
|
||||
@@ -160,7 +166,7 @@ void SkybrowserModule::WWTfollowCamera() {
|
||||
}
|
||||
}
|
||||
|
||||
ghoul::Dictionary SkybrowserModule::createMessageForMovingWWTCamera(const glm::dvec2 celestCoords, const float fov, const bool moveInstantly) const {
|
||||
ghoul::Dictionary SkyBrowserModule::createMessageForMovingWWTCamera(const glm::dvec2 celestCoords, const float fov, const bool moveInstantly) const {
|
||||
using namespace std::string_literals;
|
||||
ghoul::Dictionary msg;
|
||||
msg.setValue("event", "center_on_coordinates"s);
|
||||
@@ -172,7 +178,7 @@ ghoul::Dictionary SkybrowserModule::createMessageForMovingWWTCamera(const glm::d
|
||||
return msg;
|
||||
}
|
||||
|
||||
ghoul::Dictionary SkybrowserModule::createMessageForPausingWWTTime() const {
|
||||
ghoul::Dictionary SkyBrowserModule::createMessageForPausingWWTTime() const {
|
||||
using namespace std::string_literals;
|
||||
ghoul::Dictionary msg;
|
||||
msg.setValue("event", "pause_time"s);
|
||||
@@ -181,15 +187,15 @@ ghoul::Dictionary SkybrowserModule::createMessageForPausingWWTTime() const {
|
||||
}
|
||||
|
||||
|
||||
void SkybrowserModule::initializeBrowser(ScreenSpaceBrowser* skyBrowser) {
|
||||
void SkyBrowserModule::initializeBrowser(ScreenSpaceSkyBrowser* skyBrowser) {
|
||||
_skyBrowser = skyBrowser;
|
||||
}
|
||||
|
||||
ScreenSpaceBrowser* SkybrowserModule::skyBrowser() {
|
||||
ScreenSpaceSkyBrowser* SkyBrowserModule::skyBrowser() {
|
||||
return _skyBrowser;
|
||||
}
|
||||
|
||||
glm::dvec2 SkybrowserModule::convertGalacticToCelestial(glm::dvec3 rGal) const {
|
||||
glm::dvec2 SkyBrowserModule::convertGalacticToCelestial(glm::dvec3 rGal) const {
|
||||
|
||||
// Used the math from this website: https://gea.esac.esa.int/archive/documentation/GD -->
|
||||
// R2/Data_processing/chap_cu3ast/sec_cu3ast_intro/ssec_cu3ast_intro_tansforms.html#SSS1
|
||||
@@ -208,7 +214,7 @@ glm::dvec2 SkybrowserModule::convertGalacticToCelestial(glm::dvec3 rGal) const {
|
||||
return glm::dvec2(glm::degrees(ra), glm::degrees(dec));
|
||||
}
|
||||
|
||||
void SkybrowserModule::showTarget() const{
|
||||
void SkyBrowserModule::showTarget() const{
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
@@ -228,7 +234,7 @@ void SkybrowserModule::showTarget() const{
|
||||
}
|
||||
|
||||
/*
|
||||
std::vector<documentation::Documentation> SkybrowserModule::documentations() const {
|
||||
std::vector<documentation::Documentation> SkyBrowserModule::documentations() const {
|
||||
return {
|
||||
ExoplanetsDataPreparationTask::documentation(),
|
||||
RenderableOrbitDisc::Documentation()
|
||||
|
||||
@@ -35,14 +35,14 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ScreenSpaceBrowser;
|
||||
class ScreenSpaceSkyBrowser;
|
||||
|
||||
class SkybrowserModule : public OpenSpaceModule {
|
||||
class SkyBrowserModule : public OpenSpaceModule {
|
||||
public:
|
||||
constexpr static const char* Name = "Skybrowser";
|
||||
constexpr static const char* Name = "SkyBrowser";
|
||||
|
||||
SkybrowserModule();
|
||||
virtual ~SkybrowserModule() = default;
|
||||
SkyBrowserModule();
|
||||
virtual ~SkyBrowserModule() = default;
|
||||
|
||||
float zoomFactor() const;
|
||||
glm::dvec2 convertGalacticToCelestial(glm::dvec3 coords) const;
|
||||
@@ -55,8 +55,8 @@ public:
|
||||
|
||||
bool sendMessageToWWT(const ghoul::Dictionary& msg);
|
||||
|
||||
void initializeBrowser(ScreenSpaceBrowser* skyBrowser_);
|
||||
ScreenSpaceBrowser* skyBrowser();
|
||||
void initializeBrowser(ScreenSpaceSkyBrowser* skyBrowser_);
|
||||
ScreenSpaceSkyBrowser* skyBrowser();
|
||||
scripting::LuaLibrary luaLibrary() const override;
|
||||
//std::vector<documentation::Documentation> documentations() const override;
|
||||
|
||||
@@ -65,7 +65,7 @@ protected:
|
||||
|
||||
properties::StringProperty _testProperty;
|
||||
properties::FloatProperty _zoomFactor;
|
||||
ScreenSpaceBrowser* _skyBrowser;
|
||||
ScreenSpaceSkyBrowser* _skyBrowser;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <modules/skybrowser/skybrowsermodule.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <ghoul/misc/dictionaryluaformatter.h>
|
||||
@@ -16,14 +17,14 @@
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <modules/webbrowser/include/screenspacebrowser.h>
|
||||
#include <modules/skybrowser/include/screenspaceskybrowser.h>
|
||||
#include <openspace/interaction/navigationhandler.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <thread>
|
||||
|
||||
|
||||
namespace {
|
||||
constexpr const char _loggerCat[] = "SkybrowserModule";
|
||||
constexpr const char _loggerCat[] = "SkyBrowserModule";
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -32,10 +33,10 @@ namespace openspace::skybrowser::luascriptfunctions {
|
||||
int followCamera(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::followCamera");
|
||||
|
||||
SkybrowserModule* module = global::moduleEngine->module<SkybrowserModule>();
|
||||
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
|
||||
//ghoul::Dictionary message = module->createMessageForPausingWWTTime();
|
||||
//module->sendMessageToWWT(message);
|
||||
std::thread thread(&SkybrowserModule::WWTfollowCamera, module);
|
||||
std::thread thread(&SkyBrowserModule::WWTfollowCamera, module);
|
||||
thread.detach();
|
||||
|
||||
return 1;
|
||||
@@ -44,8 +45,8 @@ namespace openspace::skybrowser::luascriptfunctions {
|
||||
int moveBrowser(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::moveBrowser");
|
||||
|
||||
SkybrowserModule* module = global::moduleEngine->module<SkybrowserModule>();
|
||||
ScreenSpaceBrowser* browser = dynamic_cast<ScreenSpaceBrowser*>(global::renderEngine->screenSpaceRenderable("ScreenSpaceBowser"));
|
||||
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
|
||||
ScreenSpaceSkyBrowser* browser = dynamic_cast<ScreenSpaceSkyBrowser*>(global::renderEngine->screenSpaceRenderable("ScreenSpaceBowser"));
|
||||
|
||||
module->initializeBrowser(browser);
|
||||
module->skyBrowser()->translate(glm::vec3(-0.8, -0.4, 0.0));
|
||||
@@ -57,13 +58,13 @@ namespace openspace::skybrowser::luascriptfunctions {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::createBrowser");
|
||||
ghoul::lua::value<std::string>(L, 1);
|
||||
|
||||
SkybrowserModule* module = global::moduleEngine->module<SkybrowserModule>();
|
||||
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
|
||||
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
std::string node = "{"
|
||||
"Type = 'ScreenSpaceBrowser',"
|
||||
"Type = 'ScreenSpaceSkyBrowser',"
|
||||
"Identifier = 'ScreenSpaceBowser',"
|
||||
"Name = 'Screen Space Bowser',"
|
||||
"Url = 'http://localhost:8000/',"
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <modules/skybrowser/include/screenspaceskybrowser.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <modules/webbrowser/include/webkeyboardhandler.h>
|
||||
#include <modules/webbrowser/include/browserinstance.h>
|
||||
#include <modules/webbrowser/include/screenspacebrowser.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "ScreenSpaceSkyBrowser";
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
ScreenSpaceSkyBrowser::ScreenSpaceSkyBrowser(const ghoul::Dictionary& dictionary)
|
||||
: ScreenSpaceBrowser(dictionary)
|
||||
{
|
||||
std::string identifier;
|
||||
if (dictionary.hasValue<std::string>(KeyIdentifier)) {
|
||||
identifier = dictionary.value<std::string>(KeyIdentifier);
|
||||
}
|
||||
else {
|
||||
identifier = "ScreenSpaceSkyBrowser";
|
||||
}
|
||||
identifier = makeUniqueIdentifier(identifier);
|
||||
setIdentifier(identifier);
|
||||
|
||||
}
|
||||
void ScreenSpaceSkyBrowser::executeJavascript(std::string& script) const {
|
||||
//LINFOC(_loggerCat, "Executing javascript " + script);
|
||||
|
||||
CefRefPtr<CefFrame> frame = _browserInstance->getBrowser()->GetMainFrame();
|
||||
frame->ExecuteJavaScript(script, frame->GetURL(), 0);
|
||||
}
|
||||
|
||||
void ScreenSpaceSkyBrowser::translate(glm::vec3 translation) {
|
||||
glm::vec4 homogenousCoords(glm::vec4(translation, 1.0));
|
||||
glm::vec3 position = _cartesianPosition;
|
||||
_cartesianPosition = glm::translate(glm::mat4(1.f), translation) * glm::vec4(position, 1.0f);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user