/************************************************************************ ** ** @file vistoolsplinepath.cpp ** @author Roman Telezhynskyi ** @date 7 9, 2014 ** ** @brief ** @copyright ** This source code is part of the Valentine project, a pattern making ** program, whose allow create and modeling patterns of clothing. ** Copyright (C) 2013-2015 Valentina project ** All Rights Reserved. ** ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** *************************************************************************/ #include "vistoolsplinepath.h" //--------------------------------------------------------------------------------------------------------------------- VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent) : VisPath(data, parent), points(QVector()), line(nullptr), path(VSplinePath()) { line = InitItem(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- VisToolSplinePath::~VisToolSplinePath() { qDeleteAll(points.begin(), points.end()); } //--------------------------------------------------------------------------------------------------------------------- void VisToolSplinePath::RefreshGeometry() { if (path.CountPoint() > 0) { QVector pathPoints = path.GetSplinePath(); if (path.CountPoint() == 1) { QGraphicsEllipseItem *point = this->getPoint(0); DrawPoint(point, pathPoints.at(0).P().toQPointF(), supportColor); if (mode == Mode::Creation) { QLineF sceneLine = QLineF(pathPoints.at(0).P().toQPointF(), Visualization::scenePos); DrawLine(line, sceneLine, mainColor, lineStyle); path[0].SetAngle2(sceneLine.angle()); emit PathChanged(path); } } else { for (int i = 0; i < pathPoints.size(); ++i) { QGraphicsEllipseItem *point = this->getPoint(static_cast(i)); DrawPoint(point, pathPoints.at(i).P().toQPointF(), supportColor); } if (mode == Mode::Creation) { QLineF sceneLine = QLineF(pathPoints.at(pathPoints.size() - 1).P().toQPointF(), Visualization::scenePos); DrawLine(line, sceneLine, mainColor, lineStyle); path[pathPoints.size() - 1].SetAngle2(sceneLine.angle()); emit PathChanged(path); } DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); } if (path.CountPoint() < 3) { Visualization::toolTip = tr("Curved path: select three or more points"); } else { Visualization::toolTip = tr("Curved path: select three or more points, " "Enter - finish creation"); } } } //--------------------------------------------------------------------------------------------------------------------- void VisToolSplinePath::setPath(const VSplinePath &value) { path = value; } //--------------------------------------------------------------------------------------------------------------------- // cppcheck-suppress unusedFunction VSplinePath VisToolSplinePath::getPath() { return path; } //--------------------------------------------------------------------------------------------------------------------- QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i) { if (static_cast(points.size() - 1) >= i && points.isEmpty() == false) { return points.at(static_cast(i)); } else { QGraphicsEllipseItem * point = InitPoint(supportColor, this); points.append(point); return point; } return nullptr; }