diff --git a/src/app/visualization/vistoolheight.cpp b/src/app/visualization/vistoolheight.cpp new file mode 100644 index 000000000..0b8063eb6 --- /dev/null +++ b/src/app/visualization/vistoolheight.cpp @@ -0,0 +1,119 @@ +/************************************************************************ + ** + ** @file vistoolheight.cpp + ** @author Roman Telezhynskyi + ** @date 13 8, 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) 2014 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 "vistoolheight.h" +#include "../geometry/vpointf.h" +#include "../tools/drawTools/vtoolheight.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolHeight::VisToolHeight(const VContainer *data, QGraphicsItem *parent) + : VisLine(data, parent), lineP1Id(0), lineP2Id(0), point(nullptr), base_point(nullptr), lineP1(nullptr), + lineP2(nullptr), line(nullptr), line_intersection(nullptr) +{ + base_point = InitPoint(supportColor); + lineP1 = InitPoint(supportColor); + lineP2 = InitPoint(supportColor); + line = InitLine(supportColor); + line_intersection = InitLine(supportColor); + + point = InitPoint(mainColor); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolHeight::~VisToolHeight() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolHeight::RefreshGeometry() +{ + if (point1Id > 0) + { + const VPointF *first = data->GeometricObject(point1Id); + DrawPoint(base_point, first->toQPointF(), supportColor); + + if (lineP1Id <= 0) + { + DrawLine(this, QLineF(first->toQPointF(), scenePos), mainColor); + } + else + { + const VPointF *second = data->GeometricObject(lineP1Id); + DrawPoint(lineP1, second->toQPointF(), supportColor); + + QLineF base_line; + if (lineP2Id <= 0) + { + base_line = QLineF(second->toQPointF(), scenePos); + DrawLine(line, base_line, supportColor); + } + else + { + const VPointF *third = data->GeometricObject(lineP2Id); + DrawPoint(lineP2, third->toQPointF(), supportColor); + + base_line = QLineF(second->toQPointF(), third->toQPointF()); + } + + DrawLine(line, base_line, supportColor); + + QPointF height = VToolHeight::FindPoint(base_line, first->toQPointF()); + QLineF height_line(first->toQPointF(), height); + DrawLine(this, height_line, mainColor); + + ShowIntersection(height_line, base_line); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolHeight::setLineP1Id(const quint32 &value) +{ + lineP1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolHeight::setLineP2Id(const quint32 &value) +{ + lineP2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolHeight::ShowIntersection(const QLineF &height_line, const QLineF &base_line) +{ + QPointF p; + QLineF::IntersectType intersect = height_line.intersect(base_line, &p); + if (intersect == QLineF::UnboundedIntersection) + { + line_intersection->setVisible(true); + DrawLine(line_intersection, QLineF(base_line.p1(), height_line.p2()), supportColor, Qt::DashLine); + } + else if (intersect == QLineF::BoundedIntersection) + { + line_intersection->setVisible(false); + } +} diff --git a/src/app/visualization/vistoolheight.h b/src/app/visualization/vistoolheight.h new file mode 100644 index 000000000..07b0bcd28 --- /dev/null +++ b/src/app/visualization/vistoolheight.h @@ -0,0 +1,59 @@ +/************************************************************************ + ** + ** @file vistoolheight.h + ** @author Roman Telezhynskyi + ** @date 13 8, 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) 2014 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 . + ** + *************************************************************************/ + +#ifndef VISTOOLHEIGHT_H +#define VISTOOLHEIGHT_H + +#include "visline.h" + +class VisToolHeight : public VisLine +{ + Q_OBJECT +public: + VisToolHeight(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolHeight(); + + virtual void RefreshGeometry(); + + void setLineP1Id(const quint32 &value); + void setLineP2Id(const quint32 &value); +private: + Q_DISABLE_COPY(VisToolHeight) + //base point in parent class + quint32 lineP1Id;//first point of line + quint32 lineP2Id;//second point of line + QGraphicsEllipseItem *point; + QGraphicsEllipseItem *base_point; + QGraphicsEllipseItem *lineP1; + QGraphicsEllipseItem *lineP2; + QGraphicsLineItem *line; + QGraphicsLineItem *line_intersection; + void ShowIntersection(const QLineF &height_line, const QLineF &base_line); +}; + +#endif // VISTOOLHEIGHT_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index 1384355c1..0c9db6a78 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -9,7 +9,8 @@ HEADERS += \ visualization/vistoolalongline.h \ visualization/vistoolbisector.h \ visualization/vistoolshoulderpoint.h \ - visualization/vistoolnormal.h + visualization/vistoolnormal.h \ + visualization/vistoolheight.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -22,4 +23,5 @@ SOURCES += \ visualization/vistoolalongline.cpp \ visualization/vistoolbisector.cpp \ visualization/vistoolshoulderpoint.cpp \ - visualization/vistoolnormal.cpp + visualization/vistoolnormal.cpp \ + visualization/vistoolheight.cpp