#include "PathNode.h"

#include "Path.h"
#include "SceneInfo.h"

#include "SceneModel.h"

PathNode::PathNode(const Transform& transform, const std::string& psPath)
	: GeometryNode(transform),
	    mPathString(psPath)
{

}

std::unique_ptr<PathNode> PathNode::Create(const Transform& transform, const std::string& psPath)
{
	return std::make_unique<PathNode>(transform, psPath);
}

GeometryNode::Type PathNode::getType() 
{
	return GeometryNode::Type::Path;
}

const std::string& PathNode::getPathString() const
{
	return mPathString;
}

void PathNode::setPathString(const std::string& psPath)
{
	mPathString = psPath;
}

void PathNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
{
    if (!mBackgroundItem)
    {
        if (sceneInfo->mSupportsGeometryPrimitives)
        {
            auto path = std::make_unique<GeometryPath>();
            path->buildFromPostscript(mPathString);
            mBackgroundItem = std::make_unique<SceneModel>(std::move(path));
            mBackgroundItem->setName(mName + "_Model");
        }      
    }
    else
    {
        if (sceneInfo->mSupportsGeometryPrimitives)
        {
            auto path = std::make_unique<GeometryPath>();
            path->buildFromPostscript(mPathString);
            mBackgroundItem->updateGeometry(std::move(path));
        }
    }
}