/************************************************************************ ** ** @file ** @author Roman Telezhynskyi ** @date 12 9, 2016 ** ** @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) 2016 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 "visoperation.h" #include "../vgeometry/vabstractcurve.h" #include "../vgeometry/varc.h" #include "../vgeometry/vcubicbezier.h" #include "../vgeometry/vcubicbezierpath.h" #include "../vgeometry/vellipticalarc.h" #include "../vgeometry/vgeometrydef.h" #include "../vgeometry/vgobject.h" #include "../vgeometry/vpointf.h" #include "../vgeometry/vspline.h" #include "../vgeometry/vsplinepath.h" //--------------------------------------------------------------------------------------------------------------------- VisOperation::VisOperation(const VContainer *data, QGraphicsItem *parent) : VisLine(data, parent), objects(), supportColor2(Qt::darkGreen), points(), curves() { } //--------------------------------------------------------------------------------------------------------------------- VisOperation::~VisOperation() { qDeleteAll(points); qDeleteAll(curves); } //--------------------------------------------------------------------------------------------------------------------- void VisOperation::SetObjects(QVector objects) { this->objects = objects; } //--------------------------------------------------------------------------------------------------------------------- void VisOperation::VisualMode(const quint32 &pointId) { Q_UNUSED(pointId); VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); SCASSERT(scene != nullptr); Visualization::scenePos = scene->getScenePos(); RefreshGeometry(); AddOnScene(); } //--------------------------------------------------------------------------------------------------------------------- QGraphicsEllipseItem *VisOperation::GetPoint(quint32 i, const QColor &color) { if (not points.isEmpty() && static_cast(points.size() - 1) >= i) { return points.at(static_cast(i)); } else { auto point = InitPoint(color, this); points.append(point); return point; } return nullptr; } //--------------------------------------------------------------------------------------------------------------------- QGraphicsPathItem *VisOperation::GetCurve(quint32 i, const QColor &color) { if (not curves.isEmpty() && static_cast(curves.size() - 1) >= i) { return curves.at(static_cast(i)); } else { auto curve = InitItem(color, this); curves.append(curve); return curve; } return nullptr; } //--------------------------------------------------------------------------------------------------------------------- QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") void VisOperation::RefreshFlippedObjects(const QPointF &firstPoint, const QPointF &secondPoint) { int iPoint = -1; int iCurve = -1; for (int i = 0; i < objects.size(); ++i) { const quint32 id = objects.at(i); const QSharedPointer obj = Visualization::data->GetGObject(id); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); switch(static_cast(obj->getType())) { case GOType::Point: { const QSharedPointer p = Visualization::data->GeometricObject(id); ++iPoint; QGraphicsEllipseItem *point = GetPoint(iPoint, supportColor2); DrawPoint(point, *p, supportColor2); ++iPoint; point = GetPoint(iPoint, supportColor); if (object1Id != NULL_ID) { DrawPoint(point, p->Flip(QLineF(firstPoint, secondPoint)), supportColor); } break; } case GOType::Arc: { iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); break; } case GOType::EllipticalArc: { iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); break; } case GOType::Spline: { iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); break; } case GOType::SplinePath: { iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); break; } case GOType::CubicBezier: { iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); break; } case GOType::CubicBezierPath: { iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); break; } case GOType::Unknown: break; } } } QT_WARNING_POP