69 lines
1.3 KiB
C++
69 lines
1.3 KiB
C++
#include "WireNode.h"
|
|
|
|
#include "LineNode.h"
|
|
|
|
WireNode::WireNode(const Transform& transform)
|
|
: AbstractVisualNode(transform)
|
|
{
|
|
|
|
}
|
|
|
|
void WireNode::setContent(Wire* wire)
|
|
{
|
|
mContent = wire;
|
|
mContentDirty = true;
|
|
}
|
|
|
|
void WireNode::setInputLocation(const Point2& point)
|
|
{
|
|
if (mInputLocation != point)
|
|
{
|
|
mContentDirty = true;
|
|
mInputLocation = point;
|
|
}
|
|
}
|
|
|
|
void WireNode::setOutputLocation(const Point2& point)
|
|
{
|
|
if (mOutputLocation != point)
|
|
{
|
|
mContentDirty = true;
|
|
mOutputLocation = point;
|
|
}
|
|
}
|
|
|
|
void WireNode::update(SceneInfo* sceneInfo)
|
|
{
|
|
if (mContentDirty)
|
|
{
|
|
createOrUpdateGeometry(sceneInfo);
|
|
mContentDirty = false;
|
|
}
|
|
}
|
|
|
|
void WireNode::createOrUpdateGeometry(SceneInfo*)
|
|
{
|
|
if (!mLine)
|
|
{
|
|
auto loc = mOutputLocation;
|
|
loc.moveBy(-mInputLocation.getX(), -mInputLocation.getY(), -mInputLocation.getZ());
|
|
|
|
std::vector<Point2> points;
|
|
|
|
if (loc.getY() == 0.0)
|
|
{
|
|
points = { loc };
|
|
}
|
|
else
|
|
{
|
|
auto join0 = Point2(loc.getX() * 3.0 / 4.0, 0.0);
|
|
auto join1 = Point2(loc.getX() * 3.0 / 4.0, loc.getY());
|
|
points = { join0, join1 , loc};
|
|
}
|
|
|
|
|
|
mLine = std::make_unique<LineNode>(Transform(mInputLocation), points);
|
|
|
|
addChild(mLine.get());
|
|
}
|
|
}
|