|
rpm-build |
9243a4 |
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
rpm-build |
9243a4 |
/*
|
|
rpm-build |
9243a4 |
* This file is part of the libmspub project.
|
|
rpm-build |
9243a4 |
*
|
|
rpm-build |
9243a4 |
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
rpm-build |
9243a4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
rpm-build |
9243a4 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
rpm-build |
9243a4 |
*/
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
#include "ShapeGroupElement.h"
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
#include <algorithm>
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
#include "Coordinate.h"
|
|
rpm-build |
9243a4 |
#include "MSPUBConstants.h"
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
namespace libmspub
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
ShapeGroupElement::ShapeGroupElement(const std::shared_ptr<ShapeGroupElement> &parent, unsigned seqNum) : m_shapeInfo(), m_parent(parent), m_children(), m_seqNum(seqNum), m_transform()
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
ShapeGroupElement::~ShapeGroupElement()
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
std::shared_ptr<ShapeGroupElement> ShapeGroupElement::create(const std::shared_ptr<ShapeGroupElement> &parent, unsigned seqNum)
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
auto that = std::shared_ptr<ShapeGroupElement>(new ShapeGroupElement(parent, seqNum));
|
|
rpm-build |
9243a4 |
if (parent)
|
|
rpm-build |
9243a4 |
parent->m_children.push_back(that);
|
|
rpm-build |
9243a4 |
return that;
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
void ShapeGroupElement::setShapeInfo(const ShapeInfo &shapeInfo)
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
m_shapeInfo = shapeInfo;
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
void ShapeGroupElement::setTransform(const VectorTransformation2D &transform)
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
m_transform = transform;
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
void ShapeGroupElement::setup(std::function<void(ShapeGroupElement &self)> visitor)
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
visitor(*this);
|
|
rpm-build |
9243a4 |
for (auto &i : m_children)
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
i->setup(visitor);
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
void ShapeGroupElement::visit(std::function<
|
|
rpm-build |
9243a4 |
std::function<void(void)>
|
|
rpm-build |
9243a4 |
(const ShapeInfo &info, const Coordinate &relativeTo, const VectorTransformation2D &foldedTransform, bool isGroup, const VectorTransformation2D &thisTransform)
|
|
rpm-build |
9243a4 |
> visitor, const Coordinate &relativeTo, const VectorTransformation2D &parentFoldedTransform) const
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
const ShapeInfo info = m_shapeInfo.get_value_or(ShapeInfo());
|
|
rpm-build |
9243a4 |
Coordinate coord = info.m_coordinates.get_value_or(Coordinate());
|
|
rpm-build |
9243a4 |
double centerX = ((double)coord.m_xs + (double)coord.m_xe) / (2 * EMUS_IN_INCH);
|
|
rpm-build |
9243a4 |
double centerY = ((double)coord.m_ys + (double)coord.m_ye) / (2 * EMUS_IN_INCH);
|
|
rpm-build |
9243a4 |
double relativeCenterX = ((double)relativeTo.m_xs + (double)relativeTo.m_xe) / (2 * EMUS_IN_INCH);
|
|
rpm-build |
9243a4 |
double relativeCenterY = ((double)relativeTo.m_ys + (double)relativeTo.m_ye) / (2 * EMUS_IN_INCH);
|
|
rpm-build |
9243a4 |
double offsetX = centerX - relativeCenterX;
|
|
rpm-build |
9243a4 |
double offsetY = centerY - relativeCenterY;
|
|
rpm-build |
9243a4 |
VectorTransformation2D foldedTransform = VectorTransformation2D::fromTranslate(-offsetX, -offsetY)
|
|
rpm-build |
9243a4 |
* parentFoldedTransform * VectorTransformation2D::fromTranslate(offsetX, offsetY) * m_transform;
|
|
rpm-build |
9243a4 |
std::function<void(void)> afterOp = visitor(info, relativeTo, foldedTransform, isGroup(), m_transform);
|
|
rpm-build |
9243a4 |
for (const auto &i : m_children)
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
i->visit(visitor, coord, foldedTransform);
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
afterOp();
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
void ShapeGroupElement::visit(std::function<
|
|
rpm-build |
9243a4 |
std::function<void(void)>
|
|
rpm-build |
9243a4 |
(const ShapeInfo &info, const Coordinate &relativeTo, const VectorTransformation2D &foldedTransform, bool isGroup, const VectorTransformation2D &thisTransform)
|
|
rpm-build |
9243a4 |
> visitor) const
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
Coordinate origin;
|
|
rpm-build |
9243a4 |
VectorTransformation2D identity;
|
|
rpm-build |
9243a4 |
visit(visitor, origin, identity);
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
bool ShapeGroupElement::isGroup() const
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
return !m_children.empty();
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
std::shared_ptr<ShapeGroupElement> ShapeGroupElement::getParent() const
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
return m_parent.lock();
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
void ShapeGroupElement::setSeqNum(unsigned seqNum)
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
m_seqNum = seqNum;
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
unsigned ShapeGroupElement::getSeqNum() const
|
|
rpm-build |
9243a4 |
{
|
|
rpm-build |
9243a4 |
return m_seqNum;
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
}
|
|
rpm-build |
9243a4 |
|
|
rpm-build |
9243a4 |
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
|