Visualization for VToolNormal.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-12 20:02:14 +03:00
parent 00a8242349
commit 30aa0402fe
8 changed files with 256 additions and 31 deletions

View file

@ -255,6 +255,7 @@ void DialogEndLine::ShowDialog(bool click)
this->setModal(true);
this->setAngle(line->Angle());//Show in dialog angle what user choose
emit ToolTip("");
timerFormula->start();
this->show();
}
}

View file

@ -28,6 +28,9 @@
#include "dialognormal.h"
#include "ui_dialognormal.h"
#include "../visualization/vistoolnormal.h"
#include "../widgets/vmaingraphicsscene.h"
#include "../../tools/vabstracttool.h"
//---------------------------------------------------------------------------------------------------------------------
/**
@ -37,7 +40,8 @@
*/
DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), typeLine(QString()),
formula(QString()), angle(0), firstPointId(0), secondPointId(0), formulaBaseHeight(0)
formula(QString()), angle(0), firstPointId(0), secondPointId(0), formulaBaseHeight(0), line(nullptr),
prepare(false)
{
ui->setupUi(this);
InitVariables(ui);
@ -66,6 +70,8 @@ DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidge
this, &DialogNormal::PointNameChanged);
connect(ui->comboBoxSecondPoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogNormal::PointNameChanged);
line = new VisToolNormal(data);
}
//---------------------------------------------------------------------------------------------------------------------
@ -74,7 +80,6 @@ void DialogNormal::FormulaTextChanged()
this->FormulaChangedPlainText();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogNormal::PointNameChanged()
{
@ -94,6 +99,18 @@ void DialogNormal::PointNameChanged()
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogNormal::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogNormal::DeployFormulaTextEdit()
{
@ -103,6 +120,7 @@ void DialogNormal::DeployFormulaTextEdit()
//---------------------------------------------------------------------------------------------------------------------
DialogNormal::~DialogNormal()
{
delete line;
delete ui;
}
@ -114,25 +132,37 @@ DialogNormal::~DialogNormal()
*/
void DialogNormal::ChosenObject(quint32 id, const SceneObject &type)
{
if (type == SceneObject::Point)
if (prepare == false)// After first choose we ignore all objects
{
if (number == 0)
if (type == SceneObject::Point)
{
if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
if (number == 0)
{
number++;
return;
}
}
if (number == 1)
{
if (ChoosedPoint(id, ui->comboBoxSecondPoint, ""))
{
number = 0;
if (isInitialized == false)
if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
{
this->setModal(true);
this->show();
number++;
VMainGraphicsScene *scene = qApp->getCurrentScene();
SCASSERT(scene != nullptr);
line->VisualMode(id, scene->getScenePos());
scene->addItem(line);
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolNormal::SetFactor);
connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolNormal::MousePos);
return;
}
}
if (number == 1)
{
if (ChoosedPoint(id, ui->comboBoxSecondPoint, ""))
{
number = 0;
line->setPoint2Id(id);
line->RefreshGeometry();
prepare = true;
if (isInitialized == false)
{
this->setModal(true);
this->show();
}
}
}
}
@ -165,6 +195,13 @@ void DialogNormal::SaveData()
angle = ui->doubleSpinBoxAngle->value();
firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint);
secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint);
line->setPoint1Id(firstPointId);
line->setPoint2Id(secondPointId);
line->setLength(formula);
line->setAngle(angle);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
@ -175,6 +212,7 @@ void DialogNormal::SaveData()
void DialogNormal::setSecondPointId(const quint32 &value)
{
setPointId(ui->comboBoxSecondPoint, secondPointId, value);
line->setPoint2Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
@ -185,6 +223,7 @@ void DialogNormal::setSecondPointId(const quint32 &value)
void DialogNormal::setFirstPointId(const quint32 &value)
{
setPointId(ui->comboBoxFirstPoint, firstPointId, value);
line->setPoint1Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
@ -196,6 +235,7 @@ void DialogNormal::setAngle(const qreal &value)
{
angle = value;
ui->doubleSpinBoxAngle->setValue(angle);
line->setAngle(angle);
}
//---------------------------------------------------------------------------------------------------------------------
@ -212,6 +252,7 @@ void DialogNormal::setFormula(const QString &value)
this->DeployFormulaTextEdit();
}
ui->plainTextEditFormula->setPlainText(formula);
line->setLength(formula);
}
//---------------------------------------------------------------------------------------------------------------------
@ -223,6 +264,7 @@ void DialogNormal::setTypeLine(const QString &value)
{
typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -36,6 +36,8 @@ namespace Ui
class DialogNormal;
}
class VisToolNormal;
/**
* @brief The DialogNormal class dialog for ToolNormal. 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(DialogNormal)
@ -109,6 +113,11 @@ private:
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
VisToolNormal *line;
/** @brief prepare show if we prepare show dialog after finish working with visual part of tool*/
bool prepare;
/**
* @brief SaveData Put dialog data in local variables
*/

View file

@ -230,7 +230,12 @@ qreal VisLine::CorrectAngle(const qreal &angle) const
//---------------------------------------------------------------------------------------------------------------------
QPointF VisLine::Ray(const QPointF &firstPoint, const qreal &angle) const
{
QLineF line = QLineF();
if(this->scene() == nullptr)
{
return scenePos;// We can't find ray because item doesn't have scene. We eill return cursor position on scene.
}
QLineF line = QLineF();
line.setP1(firstPoint);
line.setAngle(angle);
@ -247,7 +252,7 @@ QPointF VisLine::Ray(const QPointF &firstPoint, const qreal &angle) const
//---------------------------------------------------------------------------------------------------------------------
QPointF VisLine::Ray(const QPointF &firstPoint) const
{
QLineF line = QLineF(firstPoint, scenePos);
QLineF line = QLineF(firstPoint, scenePos);
return Ray(firstPoint, line.angle());
}

View file

@ -55,16 +55,7 @@ void VisToolEndLine::RefreshGeometry()
QLineF line;
if (qFuzzyCompare(1 + length, 1 + 0))
{
QPointF second;
if(this->scene() == nullptr)
{
second = scenePos;
}
else
{
second = Ray(first->toQPointF());
}
line = QLineF(first->toQPointF(), second);
line = QLineF(first->toQPointF(), Ray(first->toQPointF()));
}
else
{

View file

@ -0,0 +1,116 @@
/************************************************************************
**
** @file vistoolnormal.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 12 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 "vistoolnormal.h"
#include "../geometry/vpointf.h"
#include "../tools/drawTools/vtoolnormal.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolNormal::VisToolNormal(const VContainer *data, QGraphicsItem *parent)
: VisLine(data, parent), point2Id(0), point(nullptr), lineP1(nullptr), lineP2(nullptr), line(nullptr), length(0),
angle(0)
{
this->mainColor = Qt::red;
lineP1 = InitPoint(supportColor);
lineP2 = InitPoint(supportColor);
line = InitLine(supportColor);
point = InitPoint(mainColor);
}
//---------------------------------------------------------------------------------------------------------------------
VisToolNormal::~VisToolNormal()
{}
//---------------------------------------------------------------------------------------------------------------------
void VisToolNormal::RefreshGeometry()
{
if (point1Id > 0)
{
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
DrawPoint(lineP1, first->toQPointF(), supportColor);
if (point2Id <= 0)
{
QLineF line_mouse(first->toQPointF(), scenePos);
DrawLine(line, line_mouse, supportColor);
QLineF normal = line_mouse.normalVector();
QPointF endRay = Ray(normal.p1(), normal.angle());
DrawLine(this, QLineF(normal.p1(), endRay), mainColor);
}
else
{
const VPointF *second = data->GeometricObject<const VPointF *>(point2Id);
DrawPoint(lineP2, second->toQPointF(), supportColor);
QLineF line_mouse(first->toQPointF(), second->toQPointF());
DrawLine(line, line_mouse, supportColor);
if (qFuzzyCompare(1 + length, 1 + 0))
{
QLineF normal = line_mouse.normalVector();
QPointF endRay = Ray(normal.p1(), normal.angle());
DrawLine(this, QLineF(normal.p1(), endRay), mainColor);
}
else
{
QPointF fPoint = VToolNormal::FindPoint(first->toQPointF(), second->toQPointF(), length, angle);
QLineF mainLine = QLineF(first->toQPointF(), fPoint);
DrawLine(this, mainLine, mainColor, lineStyle);
DrawPoint(point, mainLine.p2(), mainColor);
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolNormal::setPoint2Id(const quint32 &value)
{
point2Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolNormal::setLength(const QString &expression)
{
length = FindLength(expression);
}
//---------------------------------------------------------------------------------------------------------------------
qreal VisToolNormal::getAngle() const
{
return angle;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolNormal::setAngle(const qreal &value)
{
angle = value;
}

View file

@ -0,0 +1,59 @@
/************************************************************************
**
** @file vistoolnormal.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 12 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 VISTOOLNORMAL_H
#define VISTOOLNORMAL_H
#include "visline.h"
class VisToolNormal : public VisLine
{
Q_OBJECT
public:
VisToolNormal(const VContainer *data, QGraphicsItem *parent = 0);
virtual ~VisToolNormal();
virtual void RefreshGeometry();
void setPoint2Id(const quint32 &value);
void setLength(const QString &expression);
qreal getAngle() const;
void setAngle(const qreal &value);
private:
Q_DISABLE_COPY(VisToolNormal)
quint32 point2Id;
QGraphicsEllipseItem *point;
QGraphicsEllipseItem *lineP1;
QGraphicsEllipseItem *lineP2;
QGraphicsLineItem *line;
qreal length;
qreal angle;
};
#endif // VISTOOLNORMAL_H

View file

@ -8,7 +8,8 @@ HEADERS += \
visualization/vistoolendline.h \
visualization/vistoolalongline.h \
visualization/vistoolbisector.h \
visualization/vistoolshoulderpoint.h
visualization/vistoolshoulderpoint.h \
visualization/vistoolnormal.h
SOURCES += \
visualization/vgraphicssimpletextitem.cpp \
@ -20,4 +21,5 @@ SOURCES += \
visualization/vistoolendline.cpp \
visualization/vistoolalongline.cpp \
visualization/vistoolbisector.cpp \
visualization/vistoolshoulderpoint.cpp
visualization/vistoolshoulderpoint.cpp \
visualization/vistoolnormal.cpp