Visualization for VToolTriangle.
--HG-- branch : develop
This commit is contained in:
parent
16fa925021
commit
ade24ab84d
|
@ -30,6 +30,8 @@
|
|||
#include "ui_dialogtriangle.h"
|
||||
#include "../../geometry/vpointf.h"
|
||||
#include "../../container/vcontainer.h"
|
||||
#include "../../visualization/vistooltriangle.h"
|
||||
#include "../../widgets/vmaingraphicsscene.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
|
@ -39,12 +41,12 @@
|
|||
*/
|
||||
DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QWidget *parent)
|
||||
:DialogTool(data, toolId, parent), ui(new Ui::DialogTriangle), number(0), pointName(QString()), axisP1Id(0),
|
||||
axisP2Id(0), firstPointId(0), secondPointId(0)
|
||||
axisP2Id(0), firstPointId(0), secondPointId(0), line (nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
labelEditNamePoint = ui->labelEditNamePoint;
|
||||
|
||||
InitOkCancel(ui);
|
||||
InitOkCancelApply(ui);
|
||||
flagName = false;
|
||||
CheckState();
|
||||
|
||||
|
@ -62,11 +64,14 @@ DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QW
|
|||
this, &DialogTriangle::PointNameChanged);
|
||||
connect(ui->comboBoxAxisP2, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
||||
this, &DialogTriangle::PointNameChanged);
|
||||
|
||||
line = new VisToolTriangle(data);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DialogTriangle::~DialogTriangle()
|
||||
{
|
||||
delete line;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
@ -86,21 +91,29 @@ void DialogTriangle::ChosenObject(quint32 id, const SceneObject &type)
|
|||
case (0):
|
||||
ChangeCurrentText(ui->comboBoxAxisP1, point->name());
|
||||
number++;
|
||||
line->VisualMode(id);
|
||||
emit ToolTip(tr("Select second point of axis"));
|
||||
break;
|
||||
case (1):
|
||||
ChangeCurrentText(ui->comboBoxAxisP2, point->name());
|
||||
number++;
|
||||
line->setPoint2Id(id);
|
||||
line->RefreshGeometry();
|
||||
emit ToolTip(tr("Select first point"));
|
||||
break;
|
||||
case (2):
|
||||
ChangeCurrentText(ui->comboBoxFirstPoint, point->name());
|
||||
number++;
|
||||
line->setHypotenuseP1Id(id);
|
||||
line->RefreshGeometry();
|
||||
emit ToolTip(tr("Select second point"));
|
||||
break;
|
||||
case (3):
|
||||
ChangeCurrentText(ui->comboBoxSecondPoint, point->name());
|
||||
number = 0;
|
||||
line->setHypotenuseP2Id(id);
|
||||
line->RefreshGeometry();
|
||||
prepare = true;
|
||||
emit ToolTip(tr(""));
|
||||
if (isInitialized == false)
|
||||
{
|
||||
|
@ -122,6 +135,12 @@ void DialogTriangle::SaveData()
|
|||
secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint);
|
||||
axisP1Id = getCurrentObjectId(ui->comboBoxAxisP1);
|
||||
axisP2Id = getCurrentObjectId(ui->comboBoxAxisP2);
|
||||
|
||||
line->setPoint1Id(axisP1Id);
|
||||
line->setPoint2Id(axisP2Id);
|
||||
line->setHypotenuseP1Id(firstPointId);
|
||||
line->setHypotenuseP2Id(secondPointId);
|
||||
line->RefreshGeometry();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -134,7 +153,7 @@ void DialogTriangle::PointNameChanged()
|
|||
set.insert(getCurrentObjectId(ui->comboBoxAxisP2));
|
||||
|
||||
QColor color = okColor;
|
||||
if (set.size() != 4)
|
||||
if (set.size() < 3)//Need tree or more unique points for creation triangle
|
||||
{
|
||||
flagError = false;
|
||||
color = errorColor;
|
||||
|
@ -151,6 +170,18 @@ void DialogTriangle::PointNameChanged()
|
|||
CheckState();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogTriangle::ShowVisualization()
|
||||
{
|
||||
if (prepare == false)
|
||||
{
|
||||
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
||||
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
|
||||
scene->addItem(line);
|
||||
line->RefreshGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief setPointName set name of point
|
||||
|
@ -170,6 +201,7 @@ void DialogTriangle::setPointName(const QString &value)
|
|||
void DialogTriangle::setSecondPointId(const quint32 &value)
|
||||
{
|
||||
setPointId(ui->comboBoxSecondPoint, secondPointId, value);
|
||||
line->setHypotenuseP2Id(secondPointId);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -180,6 +212,7 @@ void DialogTriangle::setSecondPointId(const quint32 &value)
|
|||
void DialogTriangle::setFirstPointId(const quint32 &value)
|
||||
{
|
||||
setPointId(ui->comboBoxFirstPoint, firstPointId, value);
|
||||
line->setHypotenuseP1Id(firstPointId);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -190,6 +223,7 @@ void DialogTriangle::setFirstPointId(const quint32 &value)
|
|||
void DialogTriangle::setAxisP2Id(const quint32 &value)
|
||||
{
|
||||
setPointId(ui->comboBoxAxisP2, axisP2Id, value);
|
||||
line->setPoint2Id(axisP2Id);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -200,4 +234,5 @@ void DialogTriangle::setAxisP2Id(const quint32 &value)
|
|||
void DialogTriangle::setAxisP1Id(const quint32 &value)
|
||||
{
|
||||
setPointId(ui->comboBoxAxisP1, axisP1Id, value);
|
||||
line->setPoint1Id(axisP1Id);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace Ui
|
|||
class DialogTriangle;
|
||||
}
|
||||
|
||||
class VisToolTriangle;
|
||||
|
||||
/**
|
||||
* @brief The DialogTriangle class dialog for ToolTriangle. Help create point and edit option.
|
||||
*/
|
||||
|
@ -64,6 +66,7 @@ public slots:
|
|||
virtual void ChosenObject(quint32 id, const SceneObject &type);
|
||||
virtual void PointNameChanged();
|
||||
protected:
|
||||
virtual void ShowVisualization();
|
||||
/**
|
||||
* @brief SaveData Put dialog data in local variables
|
||||
*/
|
||||
|
@ -91,6 +94,8 @@ private:
|
|||
|
||||
/** @brief secondPointId id second point of line */
|
||||
quint32 secondPointId;
|
||||
|
||||
VisToolTriangle *line;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>267</width>
|
||||
<width>285</width>
|
||||
<height>220</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -82,6 +82,12 @@
|
|||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelAxisP1">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>First point of axis</string>
|
||||
</property>
|
||||
|
@ -100,6 +106,12 @@
|
|||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelAxisP2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Second point of axis</string>
|
||||
</property>
|
||||
|
@ -118,6 +130,12 @@
|
|||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelFirstPoint">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>First point</string>
|
||||
</property>
|
||||
|
@ -136,6 +154,12 @@
|
|||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelSecondPoint">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Second point</string>
|
||||
</property>
|
||||
|
@ -156,7 +180,7 @@
|
|||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -580,8 +580,10 @@ void MainWindow::ToolHeight(bool checked)
|
|||
*/
|
||||
void MainWindow::ToolTriangle(bool checked)
|
||||
{
|
||||
SetToolButton<DialogTriangle>(checked, Tool::Triangle, ":/cursor/triangle_cursor.png",
|
||||
tr("Select first point of axis"), &MainWindow::ClosedDialog<VToolTriangle>);
|
||||
SetToolButtonWithApply<DialogTriangle>(checked, Tool::Triangle, ":/cursor/triangle_cursor.png",
|
||||
tr("Select first point of axis"),
|
||||
&MainWindow::ClosedDialogWithApply<VToolTriangle>,
|
||||
&MainWindow::ApplyDialog<VToolTriangle>);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "../../dialogs/tools/dialogtriangle.h"
|
||||
#include "../../geometry/vpointf.h"
|
||||
|
||||
#include <QtMath>
|
||||
|
||||
const QString VToolTriangle::ToolType = QStringLiteral("triangle");
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -86,8 +88,9 @@ void VToolTriangle::setDialog()
|
|||
* @param scene pointer to scene.
|
||||
* @param doc dom document container.
|
||||
* @param data container with variables.
|
||||
* @return the created tool
|
||||
*/
|
||||
void VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data)
|
||||
VToolTriangle* VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data)
|
||||
{
|
||||
SCASSERT(dialog != nullptr);
|
||||
DialogTriangle *dialogTool = qobject_cast<DialogTriangle*>(dialog);
|
||||
|
@ -97,8 +100,14 @@ void VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPatte
|
|||
const quint32 firstPointId = dialogTool->getFirstPointId();
|
||||
const quint32 secondPointId = dialogTool->getSecondPointId();
|
||||
const QString pointName = dialogTool->getPointName();
|
||||
Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, scene, doc, data,
|
||||
Document::FullParse, Source::FromGui);
|
||||
VToolTriangle* point = nullptr;
|
||||
point = Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, scene, doc, data,
|
||||
Document::FullParse, Source::FromGui);
|
||||
if (point != nullptr)
|
||||
{
|
||||
point->dialog=dialogTool;
|
||||
}
|
||||
return point;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -117,11 +126,12 @@ void VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPatte
|
|||
* @param data container with variables.
|
||||
* @param parse parser file mode.
|
||||
* @param typeCreation way we create this tool.
|
||||
* @return the created tool
|
||||
*/
|
||||
void VToolTriangle::Create(const quint32 _id, const QString &pointName, const quint32 &axisP1Id,
|
||||
const quint32 &axisP2Id, const quint32 &firstPointId, const quint32 &secondPointId,
|
||||
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc,
|
||||
VContainer *data, const Document &parse, const Source &typeCreation)
|
||||
VToolTriangle* VToolTriangle::Create(const quint32 _id, const QString &pointName, const quint32 &axisP1Id,
|
||||
const quint32 &axisP2Id, const quint32 &firstPointId, const quint32 &secondPointId,
|
||||
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc,
|
||||
VContainer *data, const Document &parse, const Source &typeCreation)
|
||||
{
|
||||
const VPointF *axisP1 = data->GeometricObject<const VPointF *>(axisP1Id);
|
||||
const VPointF *axisP2 = data->GeometricObject<const VPointF *>(axisP2Id);
|
||||
|
@ -157,7 +167,9 @@ void VToolTriangle::Create(const quint32 _id, const QString &pointName, const qu
|
|||
doc->IncrementReferens(axisP2Id);
|
||||
doc->IncrementReferens(firstPointId);
|
||||
doc->IncrementReferens(secondPointId);
|
||||
return point;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -172,39 +184,31 @@ void VToolTriangle::Create(const quint32 _id, const QString &pointName, const qu
|
|||
QPointF VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint,
|
||||
const QPointF &secondPoint)
|
||||
{
|
||||
qreal c = QLineF(firstPoint, secondPoint).length();
|
||||
qreal a = QLineF(axisP2, firstPoint).length();
|
||||
qreal b = QLineF(axisP2, secondPoint).length();
|
||||
if (fabs(c*c - (a*a + b*b)) < 0.0001)
|
||||
QLineF axis(axisP1, axisP2);
|
||||
QLineF hypotenuse(firstPoint, secondPoint);
|
||||
|
||||
QPointF startPoint;
|
||||
QLineF::IntersectType intersect = axis.intersect(hypotenuse, &startPoint);
|
||||
if (intersect != QLineF::UnboundedIntersection && intersect != QLineF::BoundedIntersection)
|
||||
{
|
||||
QLineF l1(axisP2, firstPoint);
|
||||
QLineF l2(axisP2, secondPoint);
|
||||
if (fabs(l1.angleTo(l2) - 90) < 0.1 || fabs(l2.angleTo(l1) - 90) < 0.1)
|
||||
{
|
||||
return axisP2;
|
||||
}
|
||||
return QPointF();
|
||||
}
|
||||
|
||||
QLineF line = QLineF(axisP1, axisP2);
|
||||
qreal step = 0.01;
|
||||
qreal step = 1;
|
||||
|
||||
QLineF line;
|
||||
line.setP1(startPoint);
|
||||
line.setAngle(axis.angle());
|
||||
line.setLength(step);
|
||||
|
||||
int c = qFloor(hypotenuse.length());
|
||||
while (1)
|
||||
{
|
||||
line.setLength(line.length()+step);
|
||||
a = QLineF(line.p2(), firstPoint).length();
|
||||
b = QLineF(line.p2(), secondPoint).length();
|
||||
if (qFuzzyCompare(c*c, a*a + b*b))
|
||||
int a = qFloor(QLineF(line.p2(), firstPoint).length());
|
||||
int b = qFloor(QLineF(line.p2(), secondPoint).length());
|
||||
if (c*c <= (a*a + b*b))
|
||||
{
|
||||
QLineF l1(axisP2, firstPoint);
|
||||
QLineF l2(axisP2, secondPoint);
|
||||
if (fabs(l1.angleTo(l2) - 90) < 0.1 || fabs(l2.angleTo(l1) - 90) < 0.1)
|
||||
{
|
||||
return line.p2();
|
||||
}
|
||||
}
|
||||
if (c*c < a*a + b*b)
|
||||
{
|
||||
//Still don't know why this code handled. Need to think about that.
|
||||
qDebug()<<"Can't find point."<<Q_FUNC_INFO;
|
||||
return line.p2();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
#include "vtoolpoint.h"
|
||||
|
||||
/**
|
||||
* @brief The VToolTriangle class tool for what find point intersection two foots right triangle.
|
||||
* @brief The VToolTriangle class for tool that find point intersection two foots right triangle
|
||||
* (triangle with 90 degree).
|
||||
*/
|
||||
class VToolTriangle : public VToolPoint
|
||||
{
|
||||
|
@ -42,11 +43,11 @@ public:
|
|||
const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation,
|
||||
QGraphicsItem * parent = nullptr);
|
||||
virtual void setDialog();
|
||||
static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data);
|
||||
static void Create(const quint32 _id, const QString &pointName, const quint32 &axisP1Id, const quint32 &axisP2Id,
|
||||
const quint32 &firstPointId, const quint32 &secondPointId, const qreal &mx, const qreal &my,
|
||||
VMainGraphicsScene *scene, VPattern *doc, VContainer *data,
|
||||
const Document &parse, const Source &typeCreation);
|
||||
static VToolTriangle *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data);
|
||||
static VToolTriangle *Create(const quint32 _id, const QString &pointName, const quint32 &axisP1Id,
|
||||
const quint32 &axisP2Id, const quint32 &firstPointId, const quint32 &secondPointId,
|
||||
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc,
|
||||
VContainer *data, const Document &parse, const Source &typeCreation);
|
||||
static QPointF FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint,
|
||||
const QPointF &secondPoint);
|
||||
static const QString ToolType;
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
#include "visline.h"
|
||||
#include "../container/vcontainer.h"
|
||||
#include "../widgets/vapplication.h"
|
||||
#include "../tools/drawTools/vdrawtool.h"
|
||||
#include "../container/calculator.h"
|
||||
|
||||
|
@ -162,6 +161,7 @@ void VisLine::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const Q
|
|||
|
||||
point->setPos(pos);
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
|
||||
point->setVisible(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -183,19 +183,11 @@ QGraphicsEllipseItem *VisLine::InitPoint(const QColor &color)
|
|||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
|
||||
point->setRect(PointRect());
|
||||
point->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
||||
point->setVisible(false);
|
||||
return point;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QGraphicsLineItem *VisLine::InitLine(const QColor &color)
|
||||
{
|
||||
QGraphicsLineItem *line = new QGraphicsLineItem(this);
|
||||
line->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
line->setZValue(1);
|
||||
line->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
||||
return line;
|
||||
}
|
||||
|
||||
qreal VisLine::CorrectAngle(const qreal &angle) const
|
||||
{
|
||||
qreal ang = angle;
|
||||
|
@ -291,3 +283,18 @@ void VisLine::setPoint1Id(const quint32 &value)
|
|||
{
|
||||
point1Id = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QLineF VisLine::Axis(const QPointF &p, const qreal &angle) const
|
||||
{
|
||||
QPointF endP1 = Ray(p, angle+180);
|
||||
QPointF endP2 = Ray(p, angle);
|
||||
return QLineF(endP1, endP2);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QLineF VisLine::Axis(const QPointF &p1, const QPointF &p2) const
|
||||
{
|
||||
QLineF line(p1, p2);
|
||||
return Axis(p1, line.angle());
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include <QGraphicsLineItem>
|
||||
#include <QPointF>
|
||||
|
||||
#include "../widgets/vapplication.h"
|
||||
|
||||
class VContainer;
|
||||
|
||||
class VisLine: public QObject, public QGraphicsLineItem
|
||||
|
@ -71,11 +73,21 @@ protected:
|
|||
QLineF Line(const QPointF &p1, const qreal& length, const qreal &angle);
|
||||
|
||||
QGraphicsEllipseItem *InitPoint(const QColor &color);
|
||||
QGraphicsLineItem *InitLine(const QColor &color);
|
||||
template <class Item>
|
||||
Item *InitItem(const QColor &color)
|
||||
{
|
||||
Item *item = new Item(this);
|
||||
item->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
item->setZValue(1);
|
||||
item->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
||||
return item;
|
||||
}
|
||||
|
||||
qreal CorrectAngle(const qreal &angle) const;
|
||||
QPointF Ray(const QPointF &firstPoint, const qreal &angle) const;
|
||||
QPointF Ray(const QPointF &firstPoint) const;
|
||||
QLineF Axis(const QPointF &p, const qreal &angle) const;
|
||||
QLineF Axis(const QPointF &p1, const QPointF &p2) const;
|
||||
private:
|
||||
Q_DISABLE_COPY(VisLine)
|
||||
};
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "vistoolalongline.h"
|
||||
#include "../container/vcontainer.h"
|
||||
#include "../geometry/vpointf.h"
|
||||
#include "../widgets/vapplication.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent)
|
||||
|
@ -40,7 +39,7 @@ VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent
|
|||
|
||||
lineP1 = InitPoint(supportColor);
|
||||
lineP2 = InitPoint(supportColor);
|
||||
line = InitLine(supportColor);
|
||||
line = InitItem<QGraphicsLineItem>(supportColor);
|
||||
point = InitPoint(mainColor);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,10 +38,10 @@ VisToolBisector::VisToolBisector(const VContainer *data, QGraphicsItem *parent)
|
|||
{
|
||||
line1P1 = InitPoint(supportColor);
|
||||
line1P2 = InitPoint(supportColor);
|
||||
line1 = InitLine(supportColor);
|
||||
line1 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
line2P2 = InitPoint(supportColor);
|
||||
line2 = InitLine(supportColor);
|
||||
line2 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "vistoolendline.h"
|
||||
#include "../geometry/vpointf.h"
|
||||
#include "../container/vcontainer.h"
|
||||
#include "../widgets/vapplication.h"
|
||||
#include "../tools/vabstracttool.h"
|
||||
|
||||
#include <QGraphicsScene>
|
||||
|
|
|
@ -38,8 +38,8 @@ VisToolHeight::VisToolHeight(const VContainer *data, QGraphicsItem *parent)
|
|||
base_point = InitPoint(supportColor);
|
||||
lineP1 = InitPoint(supportColor);
|
||||
lineP2 = InitPoint(supportColor);
|
||||
line = InitLine(supportColor);
|
||||
line_intersection = InitLine(supportColor);
|
||||
line = InitItem<QGraphicsLineItem>(supportColor);
|
||||
line_intersection = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "vistoolline.h"
|
||||
#include "../container/vcontainer.h"
|
||||
#include "../geometry/vpointf.h"
|
||||
#include "../widgets/vapplication.h"
|
||||
#include "../tools/drawTools/vdrawtool.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -39,7 +39,7 @@ VisToolNormal::VisToolNormal(const VContainer *data, QGraphicsItem *parent)
|
|||
|
||||
lineP1 = InitPoint(supportColor);
|
||||
lineP2 = InitPoint(supportColor);
|
||||
line = InitLine(supportColor);
|
||||
line = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ VisToolPointOfIntersection::VisToolPointOfIntersection(const VContainer *data, Q
|
|||
{
|
||||
axisP1 = InitPoint(supportColor);
|
||||
axisP2 = InitPoint(supportColor);
|
||||
axis2 = InitLine(supportColor);
|
||||
axis2 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
}
|
||||
|
@ -78,14 +78,6 @@ void VisToolPointOfIntersection::setPoint2Id(const quint32 &value)
|
|||
point2Id = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QLineF VisToolPointOfIntersection::Axis(const QPointF &p, const qreal &angle) const
|
||||
{
|
||||
QPointF endP1 = Ray(p, angle);
|
||||
QPointF endP2 = Ray(p, angle+180);
|
||||
return QLineF(endP1, endP2);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolPointOfIntersection::ShowIntersection(const QLineF &axis1, const QLineF &axis2)
|
||||
{
|
||||
|
|
|
@ -49,7 +49,6 @@ private:
|
|||
QGraphicsEllipseItem *axisP2;
|
||||
QGraphicsLineItem *axis2;//axis1 is class themself
|
||||
|
||||
QLineF Axis(const QPointF &p, const qreal &angle) const;
|
||||
void ShowIntersection(const QLineF &axis1, const QLineF &axis2);
|
||||
};
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ VisToolShoulderPoint::VisToolShoulderPoint(const VContainer *data, QGraphicsItem
|
|||
{
|
||||
line1P1 = InitPoint(supportColor);
|
||||
line1P2 = InitPoint(supportColor);
|
||||
line1 = InitLine(supportColor);
|
||||
line1 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
line2P2 = InitPoint(supportColor);
|
||||
line2 = InitLine(supportColor);
|
||||
line3 = InitLine(supportColor);
|
||||
line2 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
line3 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
}
|
||||
|
|
183
src/app/visualization/vistooltriangle.cpp
Normal file
183
src/app/visualization/vistooltriangle.cpp
Normal file
|
@ -0,0 +1,183 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vistooltriangle.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 "vistooltriangle.h"
|
||||
#include "../geometry/vpointf.h"
|
||||
#include "../container/vcontainer.h"
|
||||
#include "../tools/drawTools/vtooltriangle.h"
|
||||
#include "QtMath"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolTriangle::VisToolTriangle(const VContainer *data, QGraphicsItem *parent)
|
||||
:VisLine(data, parent), point2Id(0), hypotenuseP1Id(0), hypotenuseP2Id(0), point(nullptr), axisP1(nullptr),
|
||||
axisP2(nullptr), axis(nullptr), hypotenuseP1(nullptr), hypotenuseP2(nullptr), foot1(nullptr), foot2(nullptr)
|
||||
{
|
||||
axisP1 = InitPoint(supportColor);
|
||||
axisP2 = InitPoint(supportColor);
|
||||
axis = InitItem<QGraphicsPathItem>(supportColor);
|
||||
hypotenuseP1 = InitPoint(supportColor);
|
||||
hypotenuseP2 = InitPoint(supportColor);
|
||||
foot1 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
foot2 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolTriangle::~VisToolTriangle()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolTriangle::RefreshGeometry()
|
||||
{
|
||||
if (point1Id > 0)
|
||||
{
|
||||
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
|
||||
DrawPoint(axisP1, first->toQPointF(), supportColor);
|
||||
|
||||
if (point2Id <= 0)
|
||||
{
|
||||
DrawAimedAxis(axis, QLineF(first->toQPointF(), scenePos), supportColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
const VPointF *second = data->GeometricObject<const VPointF *>(point2Id);
|
||||
DrawPoint(axisP2, second->toQPointF(), supportColor);
|
||||
|
||||
DrawAimedAxis(axis, QLineF(first->toQPointF(), second->toQPointF()), supportColor);
|
||||
|
||||
if (hypotenuseP1Id <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
const VPointF *third = data->GeometricObject<const VPointF *>(hypotenuseP1Id);
|
||||
DrawPoint(hypotenuseP1, third->toQPointF(), supportColor);
|
||||
|
||||
if (hypotenuseP2Id <= 0)
|
||||
{
|
||||
DrawLine(this, QLineF(third->toQPointF(), scenePos), supportColor, Qt::DashLine);
|
||||
|
||||
QPointF trPoint = VToolTriangle::FindPoint(first->toQPointF(), second->toQPointF(),
|
||||
third->toQPointF(), scenePos);
|
||||
DrawPoint(point, trPoint, mainColor);
|
||||
|
||||
DrawLine(foot1, QLineF(third->toQPointF(), trPoint), supportColor, Qt::DashLine);
|
||||
DrawLine(foot2, QLineF(scenePos, trPoint), supportColor, Qt::DashLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
const VPointF *forth = data->GeometricObject<const VPointF *>(hypotenuseP2Id);
|
||||
DrawPoint(hypotenuseP2, forth->toQPointF(), supportColor);
|
||||
|
||||
DrawLine(this, QLineF(third->toQPointF(), forth->toQPointF()), supportColor, Qt::DashLine);
|
||||
|
||||
QPointF trPoint = VToolTriangle::FindPoint(first->toQPointF(), second->toQPointF(),
|
||||
third->toQPointF(), forth->toQPointF());
|
||||
DrawPoint(point, trPoint, mainColor);
|
||||
|
||||
DrawLine(foot1, QLineF(third->toQPointF(), trPoint), supportColor, Qt::DashLine);
|
||||
DrawLine(foot2, QLineF(forth->toQPointF(), trPoint), supportColor, Qt::DashLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolTriangle::setPoint2Id(const quint32 &value)
|
||||
{
|
||||
point2Id = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolTriangle::setHypotenuseP1Id(const quint32 &value)
|
||||
{
|
||||
hypotenuseP1Id = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolTriangle::setHypotenuseP2Id(const quint32 &value)
|
||||
{
|
||||
hypotenuseP2Id = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolTriangle::DrawAimedAxis(QGraphicsPathItem *item, const QLineF &line, const QColor &color,
|
||||
Qt::PenStyle style)
|
||||
{
|
||||
SCASSERT (item != nullptr);
|
||||
|
||||
item->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style));
|
||||
|
||||
QPainterPath path;
|
||||
path.moveTo(line.p1());
|
||||
path.lineTo(line.p2());
|
||||
|
||||
qreal arrow_step = 60/factor;
|
||||
qreal arrow_size = 10/factor;
|
||||
|
||||
if (line.length() < arrow_step)
|
||||
{
|
||||
DrawArrow(line, path, arrow_size);
|
||||
}
|
||||
|
||||
QLineF axis;
|
||||
axis.setP1(line.p1());
|
||||
axis.setAngle(line.angle());
|
||||
axis.setLength(arrow_step);
|
||||
|
||||
int steps = qFloor(line.length()/arrow_step);
|
||||
for(int i=0; i<steps; ++i)
|
||||
{
|
||||
DrawArrow(axis, path, arrow_size);
|
||||
axis.setLength(axis.length()+arrow_step);
|
||||
}
|
||||
item->setPath(path);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolTriangle::DrawArrow(const QLineF &axis, QPainterPath &path, const qreal &arrow_size)
|
||||
{
|
||||
QLineF arrowPart1;
|
||||
arrowPart1.setP1(axis.p2());
|
||||
arrowPart1.setLength(arrow_size);
|
||||
arrowPart1.setAngle(axis.angle()+180+35);
|
||||
|
||||
path.moveTo(arrowPart1.p1());
|
||||
path.lineTo(arrowPart1.p2());
|
||||
|
||||
QLineF arrowPart2;
|
||||
arrowPart2.setP1(axis.p2());
|
||||
arrowPart2.setLength(arrow_size);
|
||||
arrowPart2.setAngle(axis.angle()+180-35);
|
||||
|
||||
path.moveTo(arrowPart2.p1());
|
||||
path.lineTo(arrowPart2.p2());
|
||||
}
|
65
src/app/visualization/vistooltriangle.h
Normal file
65
src/app/visualization/vistooltriangle.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vistooltriangle.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 VISTOOLTRIANGLE_H
|
||||
#define VISTOOLTRIANGLE_H
|
||||
|
||||
#include "visline.h"
|
||||
|
||||
class VisToolTriangle : public VisLine
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VisToolTriangle(const VContainer *data, QGraphicsItem *parent = 0);
|
||||
virtual ~VisToolTriangle();
|
||||
|
||||
virtual void RefreshGeometry();
|
||||
|
||||
void setPoint2Id(const quint32 &value);
|
||||
void setHypotenuseP1Id(const quint32 &value);
|
||||
void setHypotenuseP2Id(const quint32 &value);
|
||||
private:
|
||||
Q_DISABLE_COPY(VisToolTriangle)
|
||||
quint32 point2Id;//axis second point
|
||||
quint32 hypotenuseP1Id;
|
||||
quint32 hypotenuseP2Id;
|
||||
QGraphicsEllipseItem *point;
|
||||
QGraphicsEllipseItem *axisP1;
|
||||
QGraphicsEllipseItem *axisP2;
|
||||
QGraphicsPathItem *axis;
|
||||
QGraphicsEllipseItem *hypotenuseP1;
|
||||
QGraphicsEllipseItem *hypotenuseP2;
|
||||
QGraphicsLineItem *foot1;
|
||||
QGraphicsLineItem *foot2;
|
||||
|
||||
void DrawAimedAxis(QGraphicsPathItem *item, const QLineF &line, const QColor &color,
|
||||
Qt::PenStyle style = Qt::SolidLine);
|
||||
void DrawArrow(const QLineF &axis, QPainterPath &path, const qreal &arrow_size);
|
||||
};
|
||||
|
||||
#endif // VISTOOLTRIANGLE_H
|
|
@ -11,7 +11,8 @@ HEADERS += \
|
|||
visualization/vistoolshoulderpoint.h \
|
||||
visualization/vistoolnormal.h \
|
||||
visualization/vistoolheight.h \
|
||||
visualization/vistoolpointofintersection.h
|
||||
visualization/vistoolpointofintersection.h \
|
||||
visualization/vistooltriangle.h
|
||||
|
||||
SOURCES += \
|
||||
visualization/vgraphicssimpletextitem.cpp \
|
||||
|
@ -26,4 +27,5 @@ SOURCES += \
|
|||
visualization/vistoolshoulderpoint.cpp \
|
||||
visualization/vistoolnormal.cpp \
|
||||
visualization/vistoolheight.cpp \
|
||||
visualization/vistoolpointofintersection.cpp
|
||||
visualization/vistoolpointofintersection.cpp \
|
||||
visualization/vistooltriangle.cpp
|
||||
|
|
Loading…
Reference in New Issue
Block a user