Visualization for VToolShoulderPoint.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-25 12:55:27 +03:00
parent b8f6629dd1
commit 2ff611b923
13 changed files with 276 additions and 55 deletions

View File

@ -158,7 +158,6 @@ void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type)
if (isInitialized == false)
{
line->setPoint2Id(id);
line->setMainColor(Qt::red);
line->RefreshGeometry();
prepare = true;

View File

@ -186,7 +186,6 @@ void DialogBisector::ChosenObject(quint32 id, const SceneObject &type)
ui->comboBoxThirdPoint->setCurrentIndex(index);
number = 0;
line->setPoint3Id(id);
line->setMainColor(Qt::red);
line->RefreshGeometry();
prepare = true;
emit ToolTip("");

View File

@ -207,7 +207,6 @@ void DialogEndLine::ShowDialog(bool click)
}
this->setModal(true);
this->setAngle(line->Angle());//Show in dialog angle what user choose
line->setMainColor(Qt::red);//Now linw will be red
emit ToolTip("");
this->show();
}

View File

@ -31,6 +31,9 @@
#include "../../geometry/vpointf.h"
#include "../../container/vcontainer.h"
#include "../../visualization/vistoolshoulderpoint.h"
#include "../../widgets/vmaingraphicsscene.h"
#include "../../tools/vabstracttool.h"
//---------------------------------------------------------------------------------------------------------------------
/**
@ -40,7 +43,8 @@
*/
DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()),
typeLine(QString()), formula(QString()), p1Line(0), p2Line(0), pShoulder(0), formulaBaseHeight(0)
typeLine(QString()), formula(QString()), p1Line(0), p2Line(0), pShoulder(0), formulaBaseHeight(0), line (nullptr),
prepare(false)
{
ui->setupUi(this);
InitVariables(ui);
@ -70,6 +74,8 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent
this, &DialogShoulderPoint::PointNameChanged);
connect(ui->comboBoxPShoulder, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogShoulderPoint::PointNameChanged);
line = new VisToolShoulderPoint(data);
}
//---------------------------------------------------------------------------------------------------------------------
@ -103,6 +109,19 @@ void DialogShoulderPoint::PointNameChanged()
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogShoulderPoint::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogShoulderPoint::DeployFormulaTextEdit()
{
@ -112,6 +131,7 @@ void DialogShoulderPoint::DeployFormulaTextEdit()
//---------------------------------------------------------------------------------------------------------------------
DialogShoulderPoint::~DialogShoulderPoint()
{
delete line;
delete ui;
}
@ -122,39 +142,53 @@ DialogShoulderPoint::~DialogShoulderPoint()
* @param type type of object
*/
void DialogShoulderPoint::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
{
qint32 index = ui->comboBoxPShoulder->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxPShoulder->setCurrentIndex(index);
number++;
VMainGraphicsScene *scene = qApp->getCurrentScene();
SCASSERT(scene != nullptr);
line->VisualMode(id, scene->getScenePos());
scene->addItem(line);
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolShoulderPoint::SetFactor);
connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolShoulderPoint::MousePos);
emit ToolTip(tr("Select first point of line"));
return;
}
}
if (number == 1)
{
qint32 index = ui->comboBoxP1Line->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP1Line->setCurrentIndex(index);
number++;
line->setLineP1Id(id);
line->RefreshGeometry();
emit ToolTip(tr("Select second point of line"));
return;
}
}
if (number == 1)
{
qint32 index = ui->comboBoxP2Line->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP2Line->setCurrentIndex(index);
number++;
emit ToolTip(tr("Select point of shoulder"));
return;
}
}
if (number == 2)
{
qint32 index = ui->comboBoxPShoulder->findText(point->name());
qint32 index = ui->comboBoxP2Line->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxPShoulder->setCurrentIndex(index);
ui->comboBoxP2Line->setCurrentIndex(index);
number = 0;
line->setLineP2Id(id);
line->RefreshGeometry();
prepare = true;
emit ToolTip("");
}
if (isInitialized == false)
@ -165,6 +199,7 @@ void DialogShoulderPoint::ChosenObject(quint32 id, const SceneObject &type)
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
@ -192,6 +227,13 @@ void DialogShoulderPoint::SaveData()
p1Line = getCurrentObjectId(ui->comboBoxP1Line);
p2Line = getCurrentObjectId(ui->comboBoxP2Line);
pShoulder = getCurrentObjectId(ui->comboBoxPShoulder);
line->setPoint1Id(pShoulder);
line->setLineP1Id(p1Line);
line->setLineP2Id(p2Line);
line->setLength(formula);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
@ -203,6 +245,7 @@ void DialogShoulderPoint::SaveData()
void DialogShoulderPoint::setPShoulder(const quint32 &value, const quint32 &id)
{
setPointId(ui->comboBoxPShoulder, pShoulder, value, id);
line->setPoint1Id(pShoulder);
}
//---------------------------------------------------------------------------------------------------------------------
@ -214,6 +257,7 @@ void DialogShoulderPoint::setPShoulder(const quint32 &value, const quint32 &id)
void DialogShoulderPoint::setP2Line(const quint32 &value, const quint32 &id)
{
setPointId(ui->comboBoxP2Line, p2Line, value, id);
line->setLineP2Id(p2Line);
}
//---------------------------------------------------------------------------------------------------------------------
@ -225,6 +269,7 @@ void DialogShoulderPoint::setP2Line(const quint32 &value, const quint32 &id)
void DialogShoulderPoint::setP1Line(const quint32 &value, const quint32 &id)
{
setPointId(ui->comboBoxP1Line, p1Line, value, id);
line->setLineP1Id(p1Line);
}
//---------------------------------------------------------------------------------------------------------------------
@ -241,6 +286,7 @@ void DialogShoulderPoint::setFormula(const QString &value)
this->DeployFormulaTextEdit();
}
ui->plainTextEditFormula->setPlainText(formula);
line->setLength(formula);
}
//---------------------------------------------------------------------------------------------------------------------
@ -252,6 +298,7 @@ void DialogShoulderPoint::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -36,6 +36,8 @@ namespace Ui
class DialogShoulderPoint;
}
class VisToolShoulderPoint;
/**
* @brief The DialogShoulderPoint class dialog for ToolShoulderPoint. Help create point and edit option.
*/
@ -79,6 +81,8 @@ public slots:
*/
void FormulaTextChanged();
virtual void PointNameChanged();
protected:
virtual void ShowVisualization();
private:
Q_DISABLE_COPY(DialogShoulderPoint)
@ -108,6 +112,8 @@ private:
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
VisToolShoulderPoint *line;
bool prepare;
/**
* @brief SaveData Put dialog data in local variables

View File

@ -481,7 +481,7 @@ void MainWindow::ClosedDialogAlongLine(int result)
void MainWindow::ToolShoulderPoint(bool checked)
{
SetToolButtonWithApply<DialogShoulderPoint>(checked, Tool::ShoulderPointTool, ":/cursor/shoulder_cursor.png",
tr("Select first point of line"), &MainWindow::ClosedDialogShoulderPoint,
tr("Select point of shoulder"), &MainWindow::ClosedDialogShoulderPoint,
&MainWindow::ApplyDialogShoulderPoint);
}

View File

@ -38,6 +38,7 @@ VisLine::VisLine(const VContainer *data, QGraphicsItem *parent)
mainColor(Qt::red), supportColor(Qt::magenta), lineStyle(Qt::SolidLine), point1Id(0), toolTip(QString())
{
this->setZValue(1);// Show on top real tool
this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
}
//---------------------------------------------------------------------------------------------------------------------
@ -232,7 +233,6 @@ void VisLine::setScenePos(const QPointF &value)
//---------------------------------------------------------------------------------------------------------------------
void VisLine::VisualMode(const quint32 &pointId, const QPointF &scenePos)
{
this->mainColor = Qt::black;
this->point1Id = pointId;
this->scenePos = scenePos;
RefreshGeometry();

View File

@ -46,7 +46,7 @@ public:
void setLineStyle(const Qt::PenStyle &value);
virtual void RefreshGeometry()=0;
void setScenePos(const QPointF &value);
virtual void VisualMode(const quint32 &pointId, const QPointF &scenePos);
void VisualMode(const quint32 &pointId, const QPointF &scenePos);
void setMainColor(const QColor &value);
signals:
void ToolTip(const QString &toolTip);

View File

@ -76,16 +76,6 @@ void VisToolEndLine::RefreshGeometry()
"<b>Enter</b> - finish creation")).arg(this->line().angle());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolEndLine::VisualMode(const quint32 &pointId, const QPointF &scenePos)
{
this->mainColor = Qt::black;
this->point1Id = pointId;
this->scenePos = scenePos;
RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
qreal VisToolEndLine::Angle() const
{

View File

@ -41,7 +41,6 @@ public:
virtual ~VisToolEndLine();
virtual void RefreshGeometry();
void VisualMode(const quint32 &pointId, const QPointF &scenePos);
qreal Angle() const;
void setAngle(const qreal &value);
void setLength(const QString &expression);

View File

@ -0,0 +1,121 @@
/************************************************************************
**
** @file vistoolshoulderpoint.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 25 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 "vistoolshoulderpoint.h"
#include "../tools/drawTools/vtoolshoulderpoint.h"
#include "../geometry/vpointf.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolShoulderPoint::VisToolShoulderPoint(const VContainer *data, QGraphicsItem *parent)
:VisLine(data, parent), lineP1Id(0), lineP2Id(0), point(nullptr), line1P1(nullptr), line1P2(nullptr),
line1(nullptr), line2P2(nullptr), line2(nullptr), line3(nullptr), length(0)
{
line1P1 = InitPoint(supportColor);
line1P2 = InitPoint(supportColor);
line1 = InitLine(supportColor);
line2P2 = InitPoint(supportColor);
line2 = InitLine(supportColor);
line3 = InitLine(supportColor);
point = InitPoint(mainColor);
}
//---------------------------------------------------------------------------------------------------------------------
VisToolShoulderPoint::~VisToolShoulderPoint()
{}
//---------------------------------------------------------------------------------------------------------------------
void VisToolShoulderPoint::RefreshGeometry()
{
if (point1Id > 0)
{
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
DrawPoint(line1P1, first->toQPointF(), supportColor);
if (lineP1Id <= 0)
{
DrawLine(line1, QLineF(first->toQPointF(), scenePos), supportColor);
}
else
{
const VPointF *second = data->GeometricObject<const VPointF *>(lineP1Id);
DrawPoint(line1P2, second->toQPointF(), supportColor);
DrawLine(line1, QLineF(first->toQPointF(), second->toQPointF()), supportColor);
if (lineP2Id <= 0)
{
DrawLine(line2, QLineF(second->toQPointF(), scenePos), supportColor);
}
else
{
const VPointF *third = data->GeometricObject<const VPointF *>(lineP2Id);
DrawPoint(line2P2, third->toQPointF(), supportColor);
DrawLine(line2, QLineF(second->toQPointF(), third->toQPointF()), supportColor);
if (qFuzzyCompare(1 + length, 1 + 0) == false)
{
QPointF fPoint = VToolShoulderPoint::FindPoint(second->toQPointF(), third->toQPointF(),
first->toQPointF(), length);
QLineF mainLine = QLineF(second->toQPointF(), fPoint);
DrawLine(this, mainLine, mainColor, lineStyle);
DrawPoint(point, mainLine.p2(), mainColor);
DrawLine(line3, QLineF(first->toQPointF(), mainLine.p2()), supportColor, Qt::DashLine);
}
else
{
qreal angle = QLineF(second->toQPointF(), third->toQPointF()).angle();
QPointF endRay = Ray(second->toQPointF(), angle);
QLineF mainLine = Line(second->toQPointF(), QLineF(second->toQPointF(), endRay).length(), angle);
DrawLine(this, mainLine, mainColor, lineStyle);
}
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolShoulderPoint::setLineP1Id(const quint32 &value)
{
lineP1Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolShoulderPoint::setLineP2Id(const quint32 &value)
{
lineP2Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolShoulderPoint::setLength(const QString &expression)
{
length = FindLength(expression);
}

View File

@ -0,0 +1,59 @@
/************************************************************************
**
** @file vistoolshoulderpoint.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 25 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 VISTOOLSHOULDERPOINT_H
#define VISTOOLSHOULDERPOINT_H
#include "visline.h"
class VisToolShoulderPoint : public VisLine
{
Q_OBJECT
public:
VisToolShoulderPoint(const VContainer *data, QGraphicsItem *parent = 0);
virtual ~VisToolShoulderPoint();
virtual void RefreshGeometry();
void setLineP1Id(const quint32 &value);
void setLineP2Id(const quint32 &value);
void setLength(const QString &expression);
private:
Q_DISABLE_COPY(VisToolShoulderPoint)
quint32 lineP1Id;
quint32 lineP2Id;
QGraphicsEllipseItem *point;
QGraphicsEllipseItem *line1P1;
QGraphicsEllipseItem *line1P2;
QGraphicsLineItem *line1;
QGraphicsEllipseItem *line2P2;
QGraphicsLineItem *line2;
QGraphicsLineItem *line3;
qreal length;
};
#endif // VISTOOLSHOULDERPOINT_H

View File

@ -7,7 +7,8 @@ HEADERS += \
visualization/vistoolline.h \
visualization/vistoolendline.h \
visualization/vistoolalongline.h \
visualization/vistoolbisector.h
visualization/vistoolbisector.h \
visualization/vistoolshoulderpoint.h
SOURCES += \
visualization/vgraphicssimpletextitem.cpp \
@ -18,4 +19,5 @@ SOURCES += \
visualization/vistoolline.cpp \
visualization/vistoolendline.cpp \
visualization/vistoolalongline.cpp \
visualization/vistoolbisector.cpp
visualization/vistoolbisector.cpp \
visualization/vistoolshoulderpoint.cpp