From b0403489acaf6e3d044819eb42fea6df521abe74 Mon Sep 17 00:00:00 2001 From: aniisaaden Date: Wed, 16 Sep 2020 16:02:56 +0200 Subject: [PATCH] Implemented messaging prototype for OpenSpace sending updated property values - work in progress --- .../softwareintegrationmodule.cpp | 83 +++++++++++++++++-- .../softwareintegrationmodule.h | 1 + 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/modules/softwareintegration/softwareintegrationmodule.cpp b/modules/softwareintegration/softwareintegrationmodule.cpp index ada72c2ac8..d10cadd6cc 100644 --- a/modules/softwareintegration/softwareintegrationmodule.cpp +++ b/modules/softwareintegration/softwareintegrationmodule.cpp @@ -45,7 +45,10 @@ #include #include #include + #include +#include +#include using namespace std::string_literals; @@ -134,13 +137,8 @@ namespace openspace { throw SoftwareConnectionLostError(); } - // TESTING SENDING MESSAGE - std::string header = "O"; - sendMessage(header); - LERROR(fmt::format("Meddelandet som skickas {}", header)); - // TESTING SENDING MESSAGE - + handleProperties(); // Read message type: Byte 1-4 std::string type; @@ -190,6 +188,79 @@ namespace openspace { return true; } + void SoftwareConnection::handleProperties() { + + std::string messageType; + std::string propertyValue; + std::string identifier = "testtesttest"; + + std::string subject; + std::string lengthOfSubject; + std::string lengthOfIdentifier = std::to_string(identifier.length()); + std::string lengthOfValue; + + std::string message; + + + // Update color of renderable + /*const Renderable* myrenderable = renderable("RenderablePointsCloud"); + properties::Property* colorProperty = myrenderable->property("Color"); + // colorProperty->onChange([&]() { + propertyValue = colorProperty->getStringValue(); + lengthOfValue = std::to_string(propertyValue.length()); + messageType = "UPCO"; + subject = lengthOfIdentifier + identifier + lengthOfValue + propertyValue; + + // Format length of subject to always be 4 digits + std::ostringstream os; + os << std::setfill('0') << std::setw(4) << subject.length(); + lengthOfSubject = os.str(); + + message = messageType + lengthOfSubject + subject; + + sendMessage(message); + LERROR(fmt::format("Meddelandet som skickas {}", message)); + + + // Update opacity of renderable + const Renderable* myrenderable = renderable("RenderablePointsCloud"); + properties::Property* opacityProperty = myrenderable->property("Opacity"); + //opacityProperty->onChange([&]() { + propertyValue = opacityProperty->getStringValue(); + lengthOfValue = std::to_string(propertyValue.length()); + messageType = "UPOP"; + subject = lengthOfIdentifier + identifier + lengthOfValue + propertyValue; + + // Format length of subject to always be 4 digits + std::ostringstream os; + os << std::setfill('0') << std::setw(4) << subject.length(); + lengthOfSubject = os.str(); + + message = messageType + lengthOfSubject + subject; + + sendMessage(message); + LERROR(fmt::format("Meddelandet som skickas {}", message));*/ + + // Update size of renderable + const Renderable* myrenderable = renderable("RenderablePointsCloud"); + properties::Property* sizeProperty = myrenderable->property("Size");; + //opacityProperty->onChange([&]() { + propertyValue = sizeProperty->getStringValue(); + lengthOfValue = std::to_string(propertyValue.length()); + messageType = "UPSI"; + subject = lengthOfIdentifier + identifier + lengthOfValue + propertyValue; + + // Format length of subject to always be 4 digits + std::ostringstream os; + os << std::setfill('0') << std::setw(4) << subject.length(); + lengthOfSubject = os.str(); + + message = messageType + lengthOfSubject + subject; + + sendMessage(message); + LERROR(fmt::format("Meddelandet som skickas {}", message)); + } + // Server void SoftwareIntegrationModule::start(int port) { diff --git a/modules/softwareintegration/softwareintegrationmodule.h b/modules/softwareintegration/softwareintegrationmodule.h index e705d00a9f..6a3471cf49 100644 --- a/modules/softwareintegration/softwareintegrationmodule.h +++ b/modules/softwareintegration/softwareintegrationmodule.h @@ -80,6 +80,7 @@ public: bool sendMessage(std::string message); //bool sendMessage(const SoftwareConnection::Message& message); + void handleProperties(); SoftwareConnection::Message receiveMessage();