mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-23 05:19:18 -06:00
Adding validation check for _start and _end
This commit is contained in:
@@ -34,22 +34,26 @@
|
||||
#include <openspace/scene/translation.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "RenderableNodeLine";
|
||||
constexpr const char* ProgramName = "NodeLineProgram";
|
||||
constexpr const char* Root = "Root";
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo StartNodeInfo = {
|
||||
"StartNode",
|
||||
"Start Node",
|
||||
"The identifier of the node the line starts from. Defaults to 'Root' if not specified. "
|
||||
"The identifier of the node the line starts from. "
|
||||
"Defaults to 'Root' if not specified. "
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo EndNodeInfo = {
|
||||
"EndNode",
|
||||
"End Node",
|
||||
"The identifier of the node the line ends at. Defaults to 'Root' if not specified. "
|
||||
"The identifier of the node the line ends at. "
|
||||
"Defaults to 'Root' if not specified. "
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo LineColorInfo = {
|
||||
@@ -129,6 +133,9 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)
|
||||
_lineWidth = static_cast<float>(dictionary.value<double>(LineWidthInfo.identifier));
|
||||
}
|
||||
|
||||
_start.onChange([&]() { validateNodes(); });
|
||||
_end.onChange([&]() { validateNodes(); });
|
||||
|
||||
addProperty(_start);
|
||||
addProperty(_end);
|
||||
addProperty(_lineColor);
|
||||
@@ -141,6 +148,16 @@ double RenderableNodeLine::getDistance()
|
||||
return glm::distance(_startPos, _endPos);
|
||||
}
|
||||
|
||||
const std::string RenderableNodeLine::getStart()
|
||||
{
|
||||
return _start.value();
|
||||
}
|
||||
|
||||
const std::string RenderableNodeLine::getEnd()
|
||||
{
|
||||
return _end.value();
|
||||
}
|
||||
|
||||
void RenderableNodeLine::initializeGL() {
|
||||
_program = BaseModule::ProgramObjectManager.request(
|
||||
ProgramName,
|
||||
@@ -294,6 +311,18 @@ void RenderableNodeLine::render(const RenderData& data, RendererTasks&) {
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableNodeLine::validateNodes()
|
||||
{
|
||||
if (!global::renderEngine.scene()->sceneGraphNode(_start)) {
|
||||
LERROR(fmt::format("There is no scenegraph node with id {}, defaults to 'Root'", _start));
|
||||
_start = Root;
|
||||
}
|
||||
if (!global::renderEngine.scene()->sceneGraphNode(_end)) {
|
||||
LERROR(fmt::format("There is no scenegraph node with id {}, defaults to 'Root'", _end));
|
||||
_end = Root;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Returns a position that is relative to the current
|
||||
anchor node. This is a method to handle precision
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <modules/base/rendering/renderablelabels.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/properties/vector/vec3property.h>
|
||||
@@ -52,16 +51,11 @@ public:
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
// Identifier of the optional distance label
|
||||
std::string _distanceLabelId;
|
||||
//SceneGraphNode* distanceLabelNode = nullptr;
|
||||
//RenderableLabels* distanceLabel;
|
||||
|
||||
// Get the distance between the start and end node
|
||||
double getDistance();
|
||||
|
||||
properties::StringProperty _start;
|
||||
properties::StringProperty _end;
|
||||
const std::string getStart();
|
||||
const std::string getEnd();
|
||||
|
||||
private:
|
||||
void initializeGL() override;
|
||||
@@ -70,6 +64,7 @@ private:
|
||||
bool isReady() const override;
|
||||
void updateVertexData();
|
||||
void render(const RenderData& data, RendererTasks& rendererTask) override;
|
||||
void validateNodes();
|
||||
|
||||
void unbindGL();
|
||||
void bindGL();
|
||||
@@ -87,6 +82,8 @@ private:
|
||||
glm::dvec3 _startPos;
|
||||
glm::dvec3 _endPos;
|
||||
|
||||
properties::StringProperty _start;
|
||||
properties::StringProperty _end;
|
||||
properties::Vec3Property _lineColor;
|
||||
properties::FloatProperty _lineWidth;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user