/************************************************************************ ** ** @file ** @author Roman Telezhynskyi ** @date 12 9, 2016 ** ** @brief ** @copyright ** This source code is part of the Valentina 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), supportColor3(Qt::darkBlue), 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(); } //--------------------------------------------------------------------------------------------------------------------- VScaledEllipse *VisOperation::GetPoint(quint32 i, const QColor &color) { return GetPointItem(points, i, color, this); } //--------------------------------------------------------------------------------------------------------------------- VCurvePathItem *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 (auto id : qAsConst(objects)) { 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) == 8, "Not all objects were handled."); switch(static_cast(obj->getType())) { case GOType::Point: { const QSharedPointer p = Visualization::data->GeometricObject(id); ++iPoint; VScaledEllipse *point = GetPoint(static_cast(iPoint), supportColor2); DrawPoint(point, static_cast(*p), supportColor2); ++iPoint; point = GetPoint(static_cast(iPoint), supportColor); if (object1Id != NULL_ID) { DrawPoint(point, static_cast(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: case GOType::PlaceLabel: Q_UNREACHABLE(); break; } } } QT_WARNING_POP