Toggling visibility of SGN works from Glue and from OpenSpace

This commit is contained in:
aniisaaden
2020-09-22 15:33:44 +02:00
parent 6cd82e8e8a
commit 9eb33f6775
4 changed files with 48 additions and 0 deletions
@@ -125,6 +125,8 @@ namespace openspace {
return Message(MessageType::Opacity, messageBuffer);
else if( type == "UPSI")
return Message(MessageType::Size, messageBuffer);
else if (type == "TOVI")
return Message(MessageType::Visibility, messageBuffer);
else if (type == "DISC")
return Message(MessageType::Disconnection, messageBuffer);
else {
@@ -45,6 +45,7 @@ public:
Color,
Opacity,
Size,
Visibility,
Disconnection
};
@@ -103,6 +103,12 @@ namespace openspace {
new DoubleVerifier,
Optional::Yes,
SizeInfo.description
},
{
ToggleVisibilityInfo.identifier,
new BoolVerifier,
Optional::Yes,
ToggleVisibilityInfo.description
}
}
};
@@ -157,6 +157,7 @@ namespace openspace {
properties::Property* colorProperty = myRenderable->property("Color");
properties::Property* opacityProperty = myRenderable->property("Opacity");
properties::Property* sizeProperty = myRenderable->property("Size");
properties::Property* visibilityProperty = myRenderable->property("ToggleVisibility");
// Update color of renderable
auto updateColor = [colorProperty, identifier, peer]() {
@@ -211,6 +212,30 @@ namespace openspace {
peer->connection.sendMessage(message);
};
sizeProperty->onChange(updateSize);
// Toggle visibility of renderable
auto toggleVisibility = [visibilityProperty, identifier, peer]() {
std::string lengthOfIdentifier = std::to_string(identifier.length());
std::string messageType = "TOVI";
std::string propertyValue;
if (visibilityProperty->getStringValue() == "false")
propertyValue = "F";
else
propertyValue = "T";
std::string subject = lengthOfIdentifier + identifier + propertyValue;
// We don't need a lengthOfValue here because it will always be 1 character
// 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);
};
visibilityProperty->onChange(toggleVisibility);
}
void SoftwareIntegrationModule::handlePeerMessage(PeerMessage peerMessage) {
@@ -320,6 +345,20 @@ namespace openspace {
sizeProperty->set(size);
break;
}
case SoftwareConnection::MessageType::Visibility: {
std::string identifier = readIdentifier(message);
std::string visibility;
visibility.push_back(message[messageOffset]);
// Update size of renderable
const Renderable* myrenderable = renderable(identifier);
properties::Property* visibilityProperty = myrenderable->property("ToggleVisibility");
if(visibility == "F")
visibilityProperty->set(false);
else
visibilityProperty->set(true);
break;
}
case SoftwareConnection::MessageType::Disconnection: {
disconnect(*peer);
break;