Class visualization for VToolHeight.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-13 12:27:29 +03:00
parent 4bba3df4af
commit fe5104db01
3 changed files with 182 additions and 2 deletions

View file

@ -0,0 +1,119 @@
/************************************************************************
**
** @file vistoolheight.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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<const VPointF *>(point1Id);
DrawPoint(base_point, first->toQPointF(), supportColor);
if (lineP1Id <= 0)
{
DrawLine(this, QLineF(first->toQPointF(), scenePos), mainColor);
}
else
{
const VPointF *second = data->GeometricObject<const VPointF *>(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<const VPointF *>(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);
}
}

View file

@ -0,0 +1,59 @@
/************************************************************************
**
** @file vistoolheight.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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

View file

@ -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