Visualization for VToolBisector.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-24 16:26:59 +03:00
parent 0dbd72be67
commit b8f6629dd1
13 changed files with 355 additions and 103 deletions

View File

@ -31,6 +31,9 @@
#include "../../geometry/vpointf.h"
#include "../../container/vcontainer.h"
#include "../../visualization/vistoolbisector.h"
#include "../../widgets/vmaingraphicsscene.h"
#include "../../tools/vabstracttool.h"
//---------------------------------------------------------------------------------------------------------------------
/**
@ -40,8 +43,8 @@
*/
DialogBisector::DialogBisector(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), typeLine(QString()),
formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0),
formulaBaseHeight(0)
formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0), formulaBaseHeight(0), line(nullptr),
prepare(false)
{
ui->setupUi(this);
InitVariables(ui);
@ -72,6 +75,8 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent)
this, &DialogBisector::PointNameChanged);
connect(ui->comboBoxThirdPoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogBisector::PointNameChanged);
line = new VisToolBisector(data);
}
//---------------------------------------------------------------------------------------------------------------------
@ -105,6 +110,18 @@ void DialogBisector::PointNameChanged()
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogBisector::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolBisector::SetFactor);
scene->addItem(line);
line->RefreshGeometry();
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogBisector::DeployFormulaTextEdit()
{
@ -114,6 +131,7 @@ void DialogBisector::DeployFormulaTextEdit()
//---------------------------------------------------------------------------------------------------------------------
DialogBisector::~DialogBisector()
{
delete line;
delete ui;
}
@ -125,6 +143,8 @@ DialogBisector::~DialogBisector()
*/
void DialogBisector::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
@ -135,6 +155,12 @@ void DialogBisector::ChosenObject(quint32 id, const SceneObject &type)
{ // -1 for not found
ui->comboBoxFirstPoint->setCurrentIndex(index);
number++;
VMainGraphicsScene *scene = qApp->getCurrentScene();
SCASSERT(scene != nullptr);
line->VisualMode(id, scene->getScenePos());
scene->addItem(line);
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolBisector::SetFactor);
connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolBisector::MousePos);
emit ToolTip(tr("Select second point of angle"));
return;
}
@ -146,6 +172,8 @@ void DialogBisector::ChosenObject(quint32 id, const SceneObject &type)
{ // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);
number++;
line->setPoint2Id(id);
line->RefreshGeometry();
emit ToolTip(tr("Select third point of angle"));
return;
}
@ -157,6 +185,10 @@ void DialogBisector::ChosenObject(quint32 id, const SceneObject &type)
{ // -1 for not found
ui->comboBoxThirdPoint->setCurrentIndex(index);
number = 0;
line->setPoint3Id(id);
line->setMainColor(Qt::red);
line->RefreshGeometry();
prepare = true;
emit ToolTip("");
}
if (isInitialized == false)
@ -166,6 +198,7 @@ void DialogBisector::ChosenObject(quint32 id, const SceneObject &type)
}
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -188,6 +221,7 @@ void DialogBisector::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------
@ -204,6 +238,7 @@ void DialogBisector::setFormula(const QString &value)
this->DeployFormulaTextEdit();
}
ui->plainTextEditFormula->setPlainText(formula);
line->setLength(formula);
}
//---------------------------------------------------------------------------------------------------------------------
@ -215,6 +250,7 @@ void DialogBisector::setFormula(const QString &value)
void DialogBisector::setFirstPointId(const quint32 &value, const quint32 &id)
{
setPointId(ui->comboBoxFirstPoint, firstPointId, value, id);
line->setPoint1Id(firstPointId);
}
//---------------------------------------------------------------------------------------------------------------------
@ -226,6 +262,7 @@ void DialogBisector::setFirstPointId(const quint32 &value, const quint32 &id)
void DialogBisector::setSecondPointId(const quint32 &value, const quint32 &id)
{
setPointId(ui->comboBoxSecondPoint, secondPointId, value, id);
line->setPoint2Id(secondPointId);
}
//---------------------------------------------------------------------------------------------------------------------
@ -237,6 +274,7 @@ void DialogBisector::setSecondPointId(const quint32 &value, const quint32 &id)
void DialogBisector::setThirdPointId(const quint32 &value, const quint32 &id)
{
setPointId(ui->comboBoxThirdPoint, thirdPointId, value, id);
line->setPoint3Id(thirdPointId);
}
//---------------------------------------------------------------------------------------------------------------------
@ -265,4 +303,11 @@ void DialogBisector::SaveData()
firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint);
secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint);
thirdPointId = getCurrentObjectId(ui->comboBoxThirdPoint);
line->setPoint1Id(firstPointId);
line->setPoint2Id(secondPointId);
line->setPoint3Id(thirdPointId);
line->setLength(formula);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->RefreshGeometry();
}

View File

@ -36,6 +36,8 @@ namespace Ui
class DialogBisector;
}
class VisToolBisector;
/**
* @brief The DialogBisector class dialog for ToolBisector. Help create point and edit option.
*/
@ -80,6 +82,8 @@ public slots:
*/
void FormulaTextChanged();
virtual void PointNameChanged();
protected:
virtual void ShowVisualization();
private:
Q_DISABLE_COPY(DialogBisector)
@ -109,6 +113,8 @@ private:
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
VisToolBisector *line;
bool prepare;
/**
* @brief SaveData Put dialog data in local variables

View File

@ -269,7 +269,7 @@
<item>
<widget class="QLabel" name="labelFirstPoint">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -293,7 +293,7 @@
<item>
<widget class="QLabel" name="labelSecondPoint">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -317,7 +317,7 @@
<item>
<widget class="QLabel" name="labelThirdPoint">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>

View File

@ -65,6 +65,23 @@ VToolBisector::VToolBisector(VPattern *doc, VContainer *data, const quint32 &id,
}
}
//---------------------------------------------------------------------------------------------------------------------
qreal VToolBisector::BisectorAngle(const QPointF &firstPoint, const QPointF &secondPoint, const QPointF &thirdPoint)
{
QLineF line1(secondPoint, firstPoint);
QLineF line2(secondPoint, thirdPoint);
qreal angle = line1.angleTo(line2);
if (angle>180)
{
angle = 360 - angle;
return line1.angle()-angle/2;
}
else
{
return line1.angle()+angle/2;
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief FindPoint find bisector point.
@ -78,17 +95,7 @@ QPointF VToolBisector::FindPoint(const QPointF &firstPoint, const QPointF &secon
const QPointF &thirdPoint, const qreal &length)
{
QLineF line1(secondPoint, firstPoint);
QLineF line2(secondPoint, thirdPoint);
qreal angle = line1.angleTo(line2);
if (angle>180)
{
angle = 360 - angle;
line1.setAngle(line1.angle()-angle/2);
}
else
{
line1.setAngle(line1.angle()+angle/2);
}
line1.setAngle(BisectorAngle(firstPoint, secondPoint, thirdPoint));
line1.setLength(length);
return line1.p2();
}

View File

@ -42,6 +42,7 @@ public:
VToolBisector(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, const QString &formula,
const quint32 &firstPointId, const quint32 &secondPointId, const quint32 &thirdPointId,
const Source &typeCreation, QGraphicsItem * parent = nullptr);
static qreal BisectorAngle(const QPointF &firstPoint, const QPointF &secondPoint, const QPointF &thirdPoint);
static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const QPointF &thirdPoint,
const qreal& length);
virtual void setDialog();

View File

@ -147,6 +147,7 @@ QGraphicsEllipseItem *VisLine::InitPoint(const QColor &color)
point->setBrush(QBrush(Qt::NoBrush));
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
point->setRect(PointRect());
point->setFlags(QGraphicsItem::ItemStacksBehindParent);
return point;
}
@ -160,6 +161,61 @@ QGraphicsLineItem *VisLine::InitLine(const QColor &color)
return line;
}
qreal VisLine::CorrectAngle(const qreal &angle) const
{
qreal ang = angle;
if (angle > 360)
{
ang = angle - 360 * qFloor(angle/360);
}
switch(qFloor((qAbs(ang)+22.5)/45))
{
case 0: // <22.5
return 0;
case 1: // <67.5
return 45;
case 2: // <112.5
return 90;
case 3: // <157.5
return 135;
case 4: // <202.5
return 180;
case 5: // <247.5
return 225;
case 6: // < 292.5
return 270;
case 7: // <337.5
return 315;
default: // <360
return 0;
}
}
//---------------------------------------------------------------------------------------------------------------------
QPointF VisLine::Ray(const QPointF &firstPoint, const qreal &angle) const
{
QLineF line = QLineF();
line.setP1(firstPoint);
line.setAngle(angle);
QRectF scRect = this->scene()->sceneRect();
qreal diagonal = sqrt(pow(scRect.height(), 2) + pow(scRect.width(), 2));
line.setLength(diagonal);
if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
{
line.setAngle(CorrectAngle(line.angle()));
}
return VAbstractTool::LineIntersectRect(scRect, line);
}
//---------------------------------------------------------------------------------------------------------------------
QPointF VisLine::Ray(const QPointF &firstPoint) const
{
QLineF line = QLineF(firstPoint, scenePos);
return Ray(firstPoint, line.angle());
}
//---------------------------------------------------------------------------------------------------------------------
void VisLine::setMainColor(const QColor &value)
{

View File

@ -71,6 +71,10 @@ protected:
QGraphicsEllipseItem *InitPoint(const QColor &color);
QGraphicsLineItem *InitLine(const QColor &color);
qreal CorrectAngle(const qreal &angle) const;
QPointF Ray(const QPointF &firstPoint, const qreal &angle) const;
QPointF Ray(const QPointF &firstPoint) const;
private:
Q_DISABLE_COPY(VisLine)
};

View File

@ -72,8 +72,7 @@ void VisToolAlongLine::RefreshGeometry()
{
DrawLine(line, QLineF(first->toQPointF(), scenePos), supportColor);
}
if (point2Id > 0)
else
{
const VPointF *second = data->GeometricObject<const VPointF *>(point2Id);
DrawPoint(lineP2, second->toQPointF(), supportColor);

View File

@ -0,0 +1,121 @@
/************************************************************************
**
** @file vistoolbisector.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 24 7, 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 "vistoolbisector.h"
#include "../geometry/vpointf.h"
#include "../container/vcontainer.h"
#include "../tools/drawTools/vtoolbisector.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolBisector::VisToolBisector(const VContainer *data, QGraphicsItem *parent)
:VisLine(data, parent), point2Id(0), point3Id(0), point(nullptr), line1P1(nullptr), line1P2(nullptr),
line1(nullptr), line2P2(nullptr), line2(nullptr), length(0)
{
line1P1 = InitPoint(supportColor);
line1P2 = InitPoint(supportColor);
line1 = InitLine(supportColor);
line2P2 = InitPoint(supportColor);
line2 = InitLine(supportColor);
point = InitPoint(mainColor);
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolBisector::setPoint2Id(const quint32 &value)
{
point2Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolBisector::setPoint3Id(const quint32 &value)
{
point3Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolBisector::setLength(const QString &expression)
{
length = FindLength(expression);
}
//---------------------------------------------------------------------------------------------------------------------
VisToolBisector::~VisToolBisector()
{}
//---------------------------------------------------------------------------------------------------------------------
void VisToolBisector::RefreshGeometry()
{
if (point1Id > 0)
{
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
DrawPoint(line1P1, first->toQPointF(), supportColor);
if (point2Id <= 0)
{
DrawLine(line1, QLineF(first->toQPointF(), scenePos), supportColor);
}
else
{
const VPointF *second = data->GeometricObject<const VPointF *>(point2Id);
DrawPoint(line1P2, second->toQPointF(), supportColor);
DrawLine(line1, QLineF(first->toQPointF(), second->toQPointF()), supportColor);
if (point3Id <= 0)
{
DrawLine(line2, QLineF(second->toQPointF(), scenePos), supportColor);
}
else
{
const VPointF *third = data->GeometricObject<const VPointF *>(point3Id);
DrawPoint(line2P2, third->toQPointF(), supportColor);
DrawLine(line2, QLineF(second->toQPointF(), third->toQPointF()), supportColor);
if (qFuzzyCompare(1 + length, 1 + 0) == false)
{
qreal angle = VToolBisector::BisectorAngle(first->toQPointF(), second->toQPointF(),
third->toQPointF());
QLineF mainLine = Line(second->toQPointF(), length, angle);
DrawLine(this, mainLine, mainColor, lineStyle);
DrawPoint(point, mainLine.p2(), mainColor);
}
else
{
qreal angle = VToolBisector::BisectorAngle(first->toQPointF(), second->toQPointF(),
third->toQPointF());
QPointF endRay = Ray(second->toQPointF(), angle);
QLineF mainLine = Line(second->toQPointF(), QLineF(second->toQPointF(), endRay).length(), angle);
DrawLine(this, mainLine, mainColor, lineStyle);
}
}
}
}
}

View File

@ -0,0 +1,58 @@
/************************************************************************
**
** @file vistoolbisector.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 24 7, 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 VISTOOLBISECTOR_H
#define VISTOOLBISECTOR_H
#include "visline.h"
class VisToolBisector :public VisLine
{
Q_OBJECT
public:
VisToolBisector(const VContainer *data, QGraphicsItem *parent = 0);
virtual ~VisToolBisector();
virtual void RefreshGeometry();
void setPoint2Id(const quint32 &value);
void setPoint3Id(const quint32 &value);
void setLength(const QString &expression);
private:
Q_DISABLE_COPY(VisToolBisector)
quint32 point2Id;
quint32 point3Id;
QGraphicsEllipseItem *point;
QGraphicsEllipseItem *line1P1;
QGraphicsEllipseItem *line1P2;
QGraphicsLineItem *line1;
QGraphicsEllipseItem *line2P2;
QGraphicsLineItem *line2;
qreal length;
};
#endif // VISTOOLBISECTOR_H

View File

@ -62,7 +62,7 @@ void VisToolEndLine::RefreshGeometry()
}
else
{
second = CorrectRay(first->toQPointF());
second = Ray(first->toQPointF());
}
line = QLineF(first->toQPointF(), second);
}
@ -92,51 +92,6 @@ qreal VisToolEndLine::Angle() const
return this->line().angle();
}
//---------------------------------------------------------------------------------------------------------------------
qreal VisToolEndLine::CorrectAngle(const qreal &angle) const
{
qreal ang = angle;
if (angle > 360)
{
ang = angle - 360 * qFloor(angle/360);
}
switch(qFloor((qAbs(ang)+22.5)/45))
{
case 0: // <22.5
return 0;
case 1: // <67.5
return 45;
case 2: // <112.5
return 90;
case 3: // <157.5
return 135;
case 4: // <202.5
return 180;
case 5: // <247.5
return 225;
case 6: // < 292.5
return 270;
case 7: // <337.5
return 315;
default: // <360
return 0;
}
}
QPointF VisToolEndLine::CorrectRay(const QPointF &firstPoint) const
{
QLineF line = QLineF(firstPoint, scenePos);
QRectF scRect = this->scene()->sceneRect();
qreal diagonal = sqrt(pow(scRect.height(), 2) + pow(scRect.width(), 2));
line.setLength(diagonal);
if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
{
line.setAngle(CorrectAngle(line.angle()));
}
return VAbstractTool::LineIntersectRect(scRect, line);
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolEndLine::setAngle(const qreal &value)
{

View File

@ -50,8 +50,6 @@ private:
qreal length;
qreal angle;
QGraphicsEllipseItem *point;
qreal CorrectAngle(const qreal &angle) const;
QPointF CorrectRay(const QPointF &firstPoint) const;
};
#endif // VISTOOLENDLINE_H

View File

@ -6,7 +6,8 @@ HEADERS += \
visualization/visline.h \
visualization/vistoolline.h \
visualization/vistoolendline.h \
visualization/vistoolalongline.h
visualization/vistoolalongline.h \
visualization/vistoolbisector.h
SOURCES += \
visualization/vgraphicssimpletextitem.cpp \
@ -16,4 +17,5 @@ SOURCES += \
visualization/visline.cpp \
visualization/vistoolline.cpp \
visualization/vistoolendline.cpp \
visualization/vistoolalongline.cpp
visualization/vistoolalongline.cpp \
visualization/vistoolbisector.cpp