Visualization for VToolPointOfContact.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-14 16:43:30 +03:00
parent c7c86cf416
commit 3b129aa94e
9 changed files with 230 additions and 17 deletions

View file

@ -30,6 +30,8 @@
#include "../../geometry/vpointf.h"
#include "../../container/vcontainer.h"
#include "../../visualization/vistoolpointofcontact.h"
#include "../../widgets/vmaingraphicsscene.h"
//---------------------------------------------------------------------------------------------------------------------
/**
@ -39,7 +41,7 @@
*/
DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfContact), number(0), pointName(QString()),
radius(QString()), center(0), firstPoint(0), secondPoint(0), formulaBaseHeight(0)
radius(QString()), center(0), firstPoint(0), secondPoint(0), formulaBaseHeight(0), line(nullptr)
{
ui->setupUi(this);
InitVariables(ui);
@ -85,6 +87,15 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32
this, &DialogPointOfContact::PointNameChanged);
connect(ui->comboBoxCenter, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogPointOfContact::PointNameChanged);
line = new VisToolPointOfContact(data);
}
//---------------------------------------------------------------------------------------------------------------------
DialogPointOfContact::~DialogPointOfContact()
{
delete line;
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
@ -118,6 +129,18 @@ void DialogPointOfContact::PointNameChanged()
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfContact::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfContact::DeployFormulaTextEdit()
{
@ -142,6 +165,7 @@ void DialogPointOfContact::ChosenObject(quint32 id, const SceneObject &type)
{ // -1 for not found
ui->comboBoxFirstPoint->setCurrentIndex(index);
number++;
line->VisualMode(id);
emit ToolTip(tr("Select second point of line"));
return;
}
@ -153,6 +177,8 @@ void DialogPointOfContact::ChosenObject(quint32 id, const SceneObject &type)
{ // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);
number++;
line->setLineP2Id(id);
line->RefreshGeometry();
emit ToolTip(tr("Select point of center of arc"));
return;
}
@ -164,6 +190,9 @@ void DialogPointOfContact::ChosenObject(quint32 id, const SceneObject &type)
{ // -1 for not found
ui->comboBoxCenter->setCurrentIndex(index);
number = 0;
line->setRadiusId(id);
line->RefreshGeometry();
prepare = true;
emit ToolTip("");
}
if (isInitialized == false)
@ -184,6 +213,12 @@ void DialogPointOfContact::SaveData()
center = getCurrentObjectId(ui->comboBoxCenter);
firstPoint = getCurrentObjectId(ui->comboBoxFirstPoint);
secondPoint = getCurrentObjectId(ui->comboBoxSecondPoint);
line->setPoint1Id(firstPoint);
line->setLineP2Id(secondPoint);
line->setRadiusId(center);
line->setRadius(radius);
line->RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
@ -194,6 +229,7 @@ void DialogPointOfContact::SaveData()
void DialogPointOfContact::setSecondPoint(const quint32 &value)
{
setPointId(ui->comboBoxSecondPoint, secondPoint, value);
line->setLineP2Id(secondPoint);
}
//---------------------------------------------------------------------------------------------------------------------
@ -204,6 +240,7 @@ void DialogPointOfContact::setSecondPoint(const quint32 &value)
void DialogPointOfContact::setFirstPoint(const quint32 &value)
{
setPointId(ui->comboBoxFirstPoint, firstPoint, value);
line->setPoint1Id(firstPoint);
}
//---------------------------------------------------------------------------------------------------------------------
@ -214,6 +251,7 @@ void DialogPointOfContact::setFirstPoint(const quint32 &value)
void DialogPointOfContact::setCenter(const quint32 &value)
{
setPointId(ui->comboBoxCenter, center, value);
line->setRadiusId(center);
}
//---------------------------------------------------------------------------------------------------------------------
@ -230,6 +268,7 @@ void DialogPointOfContact::setRadius(const QString &value)
this->DeployFormulaTextEdit();
}
ui->plainTextEditFormula->setPlainText(radius);
line->setRadius(radius);
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -36,6 +36,9 @@ namespace Ui
{
class DialogPointOfContact;
}
class VisToolPointOfContact;
/**
* @brief The DialogPointOfContact class dialog for ToolPointOfContact. Help create point and edit option.
*/
@ -44,6 +47,7 @@ class DialogPointOfContact : public DialogTool
Q_OBJECT
public:
DialogPointOfContact(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
virtual ~DialogPointOfContact();
QString getPointName() const;
void setPointName(const QString &value);
@ -71,6 +75,7 @@ public slots:
void FormulaTextChanged();
virtual void PointNameChanged();
protected:
virtual void ShowVisualization();
/**
* @brief SaveData Put dialog data in local variables
*/
@ -101,6 +106,8 @@ private:
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
VisToolPointOfContact *line;
};
//---------------------------------------------------------------------------------------------------------------------

View file

@ -272,7 +272,7 @@
<item>
<widget class="QLabel" name="labelArcCenter">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -285,7 +285,7 @@
<item>
<widget class="QComboBox" name="comboBoxCenter">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -308,7 +308,7 @@
<item>
<widget class="QLabel" name="labelFirstPoint">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -321,7 +321,7 @@
<item>
<widget class="QComboBox" name="comboBoxFirstPoint">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -341,7 +341,7 @@
<item>
<widget class="QLabel" name="labelSecondPoint">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -354,7 +354,7 @@
<item>
<widget class="QComboBox" name="comboBoxSecondPoint">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>

View file

@ -83,7 +83,7 @@ void VToolPointOfContact::setDialog()
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief FindPoint return point intersection line and arc.
* @param arcRadius string with formula radius arc.
* @param arcRadius string with formula arc radius.
* @param center center arc point.
* @param firstPoint first line point.
* @param secondPoint second line point.

View file

@ -70,9 +70,8 @@ void VisLine::MousePos(const QPointF &scenePos)
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VisLine::PointRect()
QRectF VisLine::PointRect(const qreal &radius)
{
const qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm);
QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor);
rec.translate(-rec.center().x(), -rec.center().y());
return rec;
@ -155,12 +154,12 @@ void VisLine::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QC
}
//---------------------------------------------------------------------------------------------------------------------
void VisLine::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color)
void VisLine::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style)
{
SCASSERT (point != nullptr);
point->setPos(pos);
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor, style));
point->setVisible(true);
}
@ -181,7 +180,7 @@ QGraphicsEllipseItem *VisLine::InitPoint(const QColor &color)
point->setZValue(1);
point->setBrush(QBrush(Qt::NoBrush));
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
point->setRect(PointRect());
point->setRect(PointRect(qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm)));
point->setFlags(QGraphicsItem::ItemStacksBehindParent);
point->setVisible(false);
return point;

View file

@ -64,12 +64,13 @@ protected:
Qt::PenStyle lineStyle;
quint32 point1Id;
QString toolTip;
QRectF PointRect();
QRectF PointRect(const qreal &radius);
qreal FindLength(const QString &expression);
qreal FindVal(const QString &expression);
void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
Qt::PenStyle style = Qt::SolidLine);
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color);
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color,
Qt::PenStyle style = Qt::SolidLine);
QLineF Line(const QPointF &p1, const qreal& length, const qreal &angle);
QGraphicsEllipseItem *InitPoint(const QColor &color);

View file

@ -0,0 +1,107 @@
/************************************************************************
**
** @file vistoolpointofcontact.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 14 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 "vistoolpointofcontact.h"
#include "../geometry/vpointf.h"
#include "../tools/drawTools/vtoolpointofcontact.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolPointOfContact::VisToolPointOfContact(const VContainer *data, QGraphicsItem *parent)
:VisLine(data, parent), lineP2Id(0), radiusId(0), point(nullptr), lineP1(nullptr), lineP2(nullptr),
arc_point(nullptr), circle(nullptr), radius(0)
{
arc_point = InitPoint(supportColor);
lineP1 = InitPoint(supportColor);
lineP2 = InitPoint(supportColor);
circle = InitItem<QGraphicsEllipseItem>(supportColor);
point = InitPoint(mainColor);
}
//---------------------------------------------------------------------------------------------------------------------
VisToolPointOfContact::~VisToolPointOfContact()
{}
//---------------------------------------------------------------------------------------------------------------------
void VisToolPointOfContact::RefreshGeometry()
{
if (point1Id > 0)
{
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
DrawPoint(lineP1, first->toQPointF(), supportColor);
if (lineP2Id <= 0)
{
DrawLine(this, QLineF(first->toQPointF(), scenePos), supportColor);
}
else
{
const VPointF *second = data->GeometricObject<const VPointF *>(lineP2Id);
DrawPoint(lineP2, second->toQPointF(), supportColor);
DrawLine(this, QLineF(first->toQPointF(), second->toQPointF()), supportColor);
if (radiusId <= 0)
{
return;
}
else
{
const VPointF *third = data->GeometricObject<const VPointF *>(radiusId);
DrawPoint(arc_point, third->toQPointF(), supportColor);
if (qFuzzyCompare(1 + radius, 1 + 0) == false)
{
QPointF fPoint = VToolPointOfContact::FindPoint(radius, third->toQPointF(), first->toQPointF(),
second->toQPointF());
DrawPoint(point, fPoint, mainColor);
circle->setRect(PointRect(radius));
DrawPoint(circle, third->toQPointF(), supportColor, Qt::DashLine);
}
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolPointOfContact::setLineP2Id(const quint32 &value)
{
lineP2Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolPointOfContact::setRadiusId(const quint32 &value)
{
radiusId = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolPointOfContact::setRadius(const QString &expression)
{
radius = FindLength(expression);
}

View file

@ -0,0 +1,58 @@
/************************************************************************
**
** @file vistoolpointofcontact.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 14 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 VISTOOLPOINTOFCONTACT_H
#define VISTOOLPOINTOFCONTACT_H
#include "visline.h"
class VisToolPointOfContact : public VisLine
{
Q_OBJECT
public:
VisToolPointOfContact(const VContainer *data, QGraphicsItem *parent = 0);
virtual ~VisToolPointOfContact();
virtual void RefreshGeometry();
void setLineP2Id(const quint32 &value);
void setRadiusId(const quint32 &value);
void setRadius(const QString &expression);
private:
Q_DISABLE_COPY(VisToolPointOfContact)
quint32 lineP2Id;
quint32 radiusId;
QGraphicsEllipseItem *point;
QGraphicsEllipseItem *lineP1;
QGraphicsEllipseItem *lineP2;
QGraphicsEllipseItem *arc_point;
QGraphicsEllipseItem *circle;
qreal radius;
};
#endif // VISTOOLPOINTOFCONTACT_H

View file

@ -12,7 +12,8 @@ HEADERS += \
visualization/vistoolnormal.h \
visualization/vistoolheight.h \
visualization/vistoolpointofintersection.h \
visualization/vistooltriangle.h
visualization/vistooltriangle.h \
visualization/vistoolpointofcontact.h
SOURCES += \
visualization/vgraphicssimpletextitem.cpp \
@ -28,4 +29,5 @@ SOURCES += \
visualization/vistoolnormal.cpp \
visualization/vistoolheight.cpp \
visualization/vistoolpointofintersection.cpp \
visualization/vistooltriangle.cpp
visualization/vistooltriangle.cpp \
visualization/vistoolpointofcontact.cpp