From 424e99ebedadee22014900bf652f5ca135a3092a Mon Sep 17 00:00:00 2001 From: aniisaaden Date: Fri, 18 Sep 2020 13:39:41 +0200 Subject: [PATCH] OpenSpace and Glue can both send and receive messages, and update their properties. --- modules/softwareintegration/CMakeLists.txt | 2 + .../network/softwareconnection.cpp | 72 ------------------ .../network/softwareconnection.h | 6 +- .../softwareintegrationmodule.cpp | 76 ++++++++++++++++++- .../softwareintegrationmodule.h | 1 + 5 files changed, 79 insertions(+), 78 deletions(-) diff --git a/modules/softwareintegration/CMakeLists.txt b/modules/softwareintegration/CMakeLists.txt index e5c03734e8..0f7f90ea97 100644 --- a/modules/softwareintegration/CMakeLists.txt +++ b/modules/softwareintegration/CMakeLists.txt @@ -26,12 +26,14 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/softwareintegrationmodule.h + ${CMAKE_CURRENT_SOURCE_DIR}/network/softwareconnection.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepointscloud.h ) source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/softwareintegrationmodule.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/network/softwareconnection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepointscloud.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/softwareintegration/network/softwareconnection.cpp b/modules/softwareintegration/network/softwareconnection.cpp index 38721255c3..2056ece211 100644 --- a/modules/softwareintegration/network/softwareconnection.cpp +++ b/modules/softwareintegration/network/softwareconnection.cpp @@ -141,77 +141,5 @@ namespace openspace { return true; } - void SoftwareConnection::handleProperties(std::string identifier) { - - const Renderable* myRenderable = renderable(identifier); - properties::Property* colorProperty = myRenderable->property("Color"); - properties::Property* opacityProperty = myRenderable->property("Opacity"); - properties::Property* sizeProperty = myRenderable->property("Size"); - - // Update color of renderable - auto updateColor = [colorProperty, identifier]() { - std::string lengthOfIdentifier = std::to_string(identifier.length()); - std::string propertyValue = colorProperty->getStringValue(); - std::string lengthOfValue = std::to_string(propertyValue.length()); - std::string messageType = "UPCO"; - std::string 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(); - std::string lengthOfSubject = os.str(); - - std::string message = messageType + lengthOfSubject + subject; - SoftwareConnection send; - send.sendMessage(message); - LERROR(fmt::format("Meddelandet som skickas {}", message)); - }; - colorProperty->onChange(updateColor); - - /* - - // Update opacity of renderable - auto updateOpacity = [opacityProperty, identifier]() { - std::string lengthOfIdentifier = std::to_string(identifier.length()); - std::string propertyValue = opacityProperty->getStringValue(); - std::string lengthOfValue = std::to_string(propertyValue.length()); - std::string messageType = "UPOP"; - std::string 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(); - std::string lengthOfSubject = os.str(); - - std::string message = messageType + lengthOfSubject + subject; - SoftwareConnection send; - send.sendMessage(message); - LERROR(fmt::format("Meddelandet som skickas {}", message)); - }; - opacityProperty->onChange(updateOpacity); - - // Update size of renderable - auto updateSize = [sizeProperty, identifier]() { - std::string lengthOfIdentifier = std::to_string(identifier.length()); - std::string propertyValue = sizeProperty->getStringValue(); - std::string lengthOfValue = std::to_string(propertyValue.length()); - std::string messageType = "UPSI"; - std::string 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(); - std::string lengthOfSubject = os.str(); - - std::string message = messageType + lengthOfSubject + subject; - SoftwareConnection send; - send.sendMessage(message); - LERROR(fmt::format("Meddelandet som skickas {}", message)); - }; - sizeProperty->onChange(updateSize); - - */ - } - } // namespace openspace diff --git a/modules/softwareintegration/network/softwareconnection.h b/modules/softwareintegration/network/softwareconnection.h index 825688e79c..2b267d57fe 100644 --- a/modules/softwareintegration/network/softwareconnection.h +++ b/modules/softwareintegration/network/softwareconnection.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __OPENSPACE_MODULE_SOFTWAREINTEGRATION___SOFTWAREINTEGRATIONMODULE___H__ -#define __OPENSPACE_MODULE_SOFTWAREINTEGRATION___SOFTWAREINTEGRATIONMODULE___H__ +#ifndef __OPENSPACE_MODULE_SOFTWAREINTEGRATION___SOFTWARECONNECTION___H__ +#define __OPENSPACE_MODULE_SOFTWAREINTEGRATION___SOFTWARECONNECTION___H__ #include #include @@ -69,8 +69,6 @@ public: ghoul::io::TcpSocket* socket(); bool sendMessage(std::string message); - void handleProperties(std::string identifier); - SoftwareConnection::Message receiveMessage(); static const unsigned int ProtocolVersion; diff --git a/modules/softwareintegration/softwareintegrationmodule.cpp b/modules/softwareintegration/softwareintegrationmodule.cpp index 6d2a752a09..357574ca6e 100644 --- a/modules/softwareintegration/softwareintegrationmodule.cpp +++ b/modules/softwareintegration/softwareintegrationmodule.cpp @@ -151,6 +151,79 @@ namespace openspace { } } + void SoftwareIntegrationModule::handleProperties(std::string identifier, const std::shared_ptr& peer) { + + const Renderable* myRenderable = renderable(identifier); + properties::Property* colorProperty = myRenderable->property("Color"); + properties::Property* opacityProperty = myRenderable->property("Opacity"); + properties::Property* sizeProperty = myRenderable->property("Size"); + + // Update color of renderable + auto updateColor = [colorProperty, identifier, peer]() { + std::string lengthOfIdentifier = std::to_string(identifier.length()); + std::string propertyValue = colorProperty->getStringValue(); + std::string lengthOfValue = std::to_string(propertyValue.length()); + std::string messageType = "UPCO"; + std::string 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(); + std::string lengthOfSubject = os.str(); + + std::string message = messageType + lengthOfSubject + subject; + + peer->connection.sendMessage(message); + + LERROR(fmt::format("Meddelandet som skickas {}", message)); + }; + colorProperty->onChange(updateColor); + + /* + + // Update opacity of renderable + auto updateOpacity = [opacityProperty, identifier]() { + std::string lengthOfIdentifier = std::to_string(identifier.length()); + std::string propertyValue = opacityProperty->getStringValue(); + std::string lengthOfValue = std::to_string(propertyValue.length()); + std::string messageType = "UPOP"; + std::string 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(); + std::string lengthOfSubject = os.str(); + + std::string message = messageType + lengthOfSubject + subject; + SoftwareConnection send; + send.sendMessage(message); + LERROR(fmt::format("Meddelandet som skickas {}", message)); + }; + opacityProperty->onChange(updateOpacity); + + // Update size of renderable + auto updateSize = [sizeProperty, identifier]() { + std::string lengthOfIdentifier = std::to_string(identifier.length()); + std::string propertyValue = sizeProperty->getStringValue(); + std::string lengthOfValue = std::to_string(propertyValue.length()); + std::string messageType = "UPSI"; + std::string 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(); + std::string lengthOfSubject = os.str(); + + std::string message = messageType + lengthOfSubject + subject; + SoftwareConnection send; + send.sendMessage(message); + LERROR(fmt::format("Meddelandet som skickas {}", message)); + }; + sizeProperty->onChange(updateSize); + + */ + } + void SoftwareIntegrationModule::handlePeerMessage(PeerMessage peerMessage) { const size_t peerId = peerMessage.peerId; auto it = _peers.find(peerId); @@ -213,8 +286,7 @@ namespace openspace { ); } - SoftwareConnection callback; - callback.handleProperties(identifier); + handleProperties(identifier, peer); break; } diff --git a/modules/softwareintegration/softwareintegrationmodule.h b/modules/softwareintegration/softwareintegrationmodule.h index 4815e20935..c1413b216c 100644 --- a/modules/softwareintegration/softwareintegrationmodule.h +++ b/modules/softwareintegration/softwareintegrationmodule.h @@ -75,6 +75,7 @@ private: std::shared_ptr peer(size_t id); void handlePeer(size_t id); void handlePeerMessage(PeerMessage peerMessage); + void handleProperties(std::string identifier, const std::shared_ptr& peer); std::unordered_map> _peers; mutable std::mutex _peerListMutex; std::thread _serverThread;