Merge with feature

--HG--
branch : develop
This commit is contained in:
dismine 2014-01-02 19:16:51 +02:00
commit b970a54051
124 changed files with 3765 additions and 1858 deletions

View File

@ -126,11 +126,11 @@ pixmaps.path = $$DATADIR/pixmaps/
pixmaps.files += dist/$${TARGET}.png
INSTALL_TRANSLATIONS += share/translations/valentina_ru.qm \
share/translations/valentina_uk.qm \
share/translations/valentina_de.qm \
share/translations/valentina_de.qm
translations.path = $$DATADIR/$${TARGET}/translations/
translations.files = $$INSTALL_TRANSLATIONS
INSTALLS += target \
desktop \
pixmaps \
translations
}
}

View File

@ -17,5 +17,6 @@
<file>cursor/pointofintersect_cursor.png</file>
<file>cursor/spline_cut_point_cursor.png</file>
<file>cursor/splinepath_cut_point_cursor.png</file>
<file>cursor/union_cursor.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -39,5 +39,6 @@
<file>icon/32x32/point_of_intersection.png</file>
<file>icon/32x32/spline_cut_point.png</file>
<file>icon/32x32/splinePath_cut_point.png</file>
<file>icon/32x32/union.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 796 B

View File

@ -1,12 +1,10 @@
SOURCES += \
src/container/vpointf.cpp \
src/container/vincrementtablerow.cpp \
src/container/vcontainer.cpp \
src/container/calculator.cpp \
src/container/vstandarttablerow.cpp
HEADERS += \
src/container/vpointf.h \
src/container/vincrementtablerow.h \
src/container/vcontainer.h \
src/container/calculator.h \

View File

@ -27,18 +27,17 @@
*************************************************************************/
#include "vcontainer.h"
#include "../exception/vexceptionbadid.h"
#include <QDebug>
#include <QtAlgorithms>
qint64 VContainer::_id = 0;
VContainer::VContainer()
:base(QHash<QString, qint32>()), points(QHash<qint64, VPointF>()),
:base(QHash<QString, qint32>()), gObjects(QHash<qint64, VGObject *>()),
standartTable(QHash<QString, VStandartTableRow>()), incrementTable(QHash<QString, VIncrementTableRow>()),
lengthLines(QHash<QString, qreal>()), lineAngles(QHash<QString, qreal>()), splines(QHash<qint64, VSpline>()),
lengthSplines(QHash<QString, qreal>()), arcs(QHash<qint64, VArc>()), lengthArcs(QHash<QString, qreal>()),
splinePaths(QHash<qint64, VSplinePath>()), details(QHash<qint64, VDetail>())
lengthLines(QHash<QString, qreal>()), lineAngles(QHash<QString, qreal>()), lengthSplines(QHash<QString, qreal>()),
lengthArcs(QHash<QString, qreal>()), details(QHash<qint64, VDetail>())
{
SetSize(500);
SetGrowth(1760);
@ -52,38 +51,74 @@ VContainer &VContainer::operator =(const VContainer &data)
}
VContainer::VContainer(const VContainer &data)
:base(QHash<QString, qint32>()), points(QHash<qint64, VPointF>()),
standartTable(QHash<QString, VStandartTableRow>()), incrementTable(QHash<QString, VIncrementTableRow>()),
lengthLines(QHash<QString, qreal>()), lineAngles(QHash<QString, qreal>()), splines(QHash<qint64, VSpline>()),
lengthSplines(QHash<QString, qreal>()), arcs(QHash<qint64, VArc>()), lengthArcs(QHash<QString, qreal>()),
splinePaths(QHash<qint64, VSplinePath>()), details(QHash<qint64, VDetail>())
:base(QHash<QString, qint32>()), gObjects(QHash<qint64, VGObject *>()),
standartTable(QHash<QString, VStandartTableRow>()), incrementTable(QHash<QString, VIncrementTableRow>()),
lengthLines(QHash<QString, qreal>()), lineAngles(QHash<QString, qreal>()), lengthSplines(QHash<QString, qreal>()),
lengthArcs(QHash<QString, qreal>()), details(QHash<qint64, VDetail>())
{
setData(data);
}
VContainer::~VContainer()
{
qDeleteAll(gObjects);
gObjects.clear();
}
void VContainer::setData(const VContainer &data)
{
base = *data.DataBase();
points = *data.DataPoints();
qDeleteAll(gObjects);
gObjects.clear();
const QHash<qint64, VGObject*> *obj = data.DataGObjects();
Q_ASSERT(obj != 0);
QHashIterator<qint64, VGObject*> i(*obj);
while (i.hasNext())
{
i.next();
switch (i.value()->getType())
{
case (GObject::Arc):
{
CopyGObject<VArc>(data, i.key());
break;
}
case (GObject::Point):
{
CopyGObject<VPointF>(data, i.key());
break;
}
case (GObject::Spline):
{
CopyGObject<VSpline>(data, i.key());
break;
}
case (GObject::SplinePath):
{
CopyGObject<VSplinePath>(data, i.key());
break;
}
default:
qWarning()<<"Don't know how copy this type.";
}
}
standartTable = *data.DataStandartTable();
incrementTable = *data.DataIncrementTable();
lengthLines = *data.DataLengthLines();
lineAngles = *data.DataLineAngles();
splines = *data.DataSplines();
lengthSplines = *data.DataLengthSplines();
arcs = *data.DataArcs();
lengthArcs = *data.DataLengthArcs();
splinePaths = *data.DataSplinePaths();
details = *data.DataDetails();
}
VPointF VContainer::GetPoint(qint64 id) const
const VGObject *VContainer::GetGObject(qint64 id)const
{
return GetObject(points, id);
return GetObject(gObjects, id);
}
template <typename key, typename val>
val VContainer::GetObject(const QHash<key, val> &obj, key id)
const val VContainer::GetObject(const QHash<key, val> &obj, key id) const
{
if (obj.contains(id))
{
@ -95,70 +130,75 @@ val VContainer::GetObject(const QHash<key, val> &obj, key id)
}
}
VStandartTableRow VContainer::GetStandartTableCell(const QString &name) const
template <typename key, typename val>
val VContainer::GetVariable(const QHash<key, val> &obj, key id) const
{
Q_ASSERT(name.isEmpty()==false);
return GetObject(standartTable, name);
if (obj.contains(id))
{
return obj.value(id);
}
else
{
throw VExceptionBadId(tr("Can't find object"), id);
}
}
VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const
const VStandartTableRow VContainer::GetStandartTableCell(const QString &name) const
{
Q_ASSERT(name.isEmpty()==false);
return GetObject(incrementTable, name);
return GetVariable(standartTable, name);
}
const VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const
{
Q_ASSERT(name.isEmpty()==false);
return GetVariable(incrementTable, name);
}
qreal VContainer::GetLine(const QString &name) const
{
Q_ASSERT(name.isEmpty()==false);
return GetObject(lengthLines, name);
return GetVariable(lengthLines, name);
}
qreal VContainer::GetLengthArc(const QString &name) const
{
Q_ASSERT(name.isEmpty()==false);
return GetObject(lengthArcs, name);
return GetVariable(lengthArcs, name);
}
qreal VContainer::GetLengthSpline(const QString &name) const
{
Q_ASSERT(name.isEmpty()==false);
return GetObject(lengthSplines, name);
return GetVariable(lengthSplines, name);
}
qreal VContainer::GetLineAngle(const QString &name) const
{
Q_ASSERT(name.isEmpty()==false);
return GetObject(lineAngles, name);
return GetVariable(lineAngles, name);
}
VSpline VContainer::GetSpline(qint64 id) const
const VDetail VContainer::GetDetail(qint64 id) const
{
return GetObject(splines, id);
return GetVariable(details, id);
}
VArc VContainer::GetArc(qint64 id) const
qint64 VContainer::AddGObject(VGObject *obj)
{
return GetObject(arcs, id);
return AddObject(gObjects, obj);
}
VSplinePath VContainer::GetSplinePath(qint64 id) const
qint64 VContainer::AddDetail(VDetail detail)
{
return GetObject(splinePaths, id);
qint64 id = getNextId();
details[id] = detail;
return id;
}
VDetail VContainer::GetDetail(qint64 id) const
void VContainer::AddIncrementTableRow(const QString &name, VIncrementTableRow row)
{
return GetObject(details, id);
}
qint64 VContainer::AddPoint(const VPointF &point)
{
return AddObject(points, point);
}
qint64 VContainer::AddDetail(const VDetail &detail)
{
return AddObject(details, detail);
incrementTable[name] = row;
}
qint64 VContainer::getNextId()
@ -182,96 +222,95 @@ QPainterPath VContainer::ContourPath(qint64 idDetail) const
QVector<QPointF> pointsEkv;
for (ptrdiff_t i = 0; i< detail.CountNode(); ++i)
{
switch (detail[i].getTypeTool())
switch (detail.at(i).getTypeTool())
{
case (Tool::NodePoint):
{
VPointF point = GetPoint(detail[i].getId());
points.append(point.toQPointF());
const VPointF *point = GeometricObject<const VPointF*>(detail.at(i).getId());
points.append(point->toQPointF());
if (detail.getSupplement() == true)
{
QPointF pEkv = point.toQPointF();
pEkv.setX(pEkv.x()+detail[i].getMx());
pEkv.setY(pEkv.y()+detail[i].getMy());
QPointF pEkv = point->toQPointF();
pEkv.setX(pEkv.x()+detail.at(i).getMx());
pEkv.setY(pEkv.y()+detail.at(i).getMy());
pointsEkv.append(pEkv);
}
}
break;
case (Tool::NodeArc):
{
VArc arc = GetArc(detail[i].getId());
qreal len1 = GetLengthContour(points, arc.GetPoints());
qreal lenReverse = GetLengthContour(points, GetReversePoint(arc.GetPoints()));
const VArc *arc = GeometricObject<const VArc *>(detail.at(i).getId());
qreal len1 = GetLengthContour(points, arc->GetPoints());
qreal lenReverse = GetLengthContour(points, GetReversePoint(arc->GetPoints()));
if (len1 <= lenReverse)
{
points << arc.GetPoints();
points << arc->GetPoints();
if (detail.getSupplement() == true)
{
pointsEkv << biasPoints(arc.GetPoints(), detail[i].getMx(), detail[i].getMy());
pointsEkv << biasPoints(arc->GetPoints(), detail.at(i).getMx(), detail.at(i).getMy());
}
}
else
{
points << GetReversePoint(arc.GetPoints());
points << GetReversePoint(arc->GetPoints());
if (detail.getSupplement() == true)
{
pointsEkv << biasPoints(GetReversePoint(arc.GetPoints()), detail[i].getMx(), detail[i].getMy());
pointsEkv << biasPoints(GetReversePoint(arc->GetPoints()), detail.at(i).getMx(),
detail.at(i).getMy());
}
}
}
break;
case (Tool::NodeSpline):
{
VSpline spline = GetSpline(detail[i].getId());
qreal len1 = GetLengthContour(points, spline.GetPoints());
qreal lenReverse = GetLengthContour(points, GetReversePoint(spline.GetPoints()));
const VSpline *spline = GeometricObject<const VSpline *>(detail.at(i).getId());
qreal len1 = GetLengthContour(points, spline->GetPoints());
qreal lenReverse = GetLengthContour(points, GetReversePoint(spline->GetPoints()));
if (len1 <= lenReverse)
{
points << spline.GetPoints();
points << spline->GetPoints();
if (detail.getSupplement() == true)
{
pointsEkv << biasPoints(spline.GetPoints(), detail[i].getMx(), detail[i].getMy());
pointsEkv << biasPoints(spline->GetPoints(), detail.at(i).getMx(), detail.at(i).getMy());
}
}
else
{
points << GetReversePoint(spline.GetPoints());
points << GetReversePoint(spline->GetPoints());
if (detail.getSupplement() == true)
{
pointsEkv << biasPoints(GetReversePoint(spline.GetPoints()), detail[i].getMx(),
detail[i].getMy());
pointsEkv << biasPoints(GetReversePoint(spline->GetPoints()), detail.at(i).getMx(),
detail.at(i).getMy());
}
}
}
break;
case (Tool::NodeSplinePath):
{
VSplinePath splinePath = GetSplinePath(detail[i].getId());
qreal len1 = GetLengthContour(points, splinePath.GetPathPoints());
qreal lenReverse = GetLengthContour(points, GetReversePoint(splinePath.GetPathPoints()));
const VSplinePath *splinePath = GeometricObject<const VSplinePath *>(detail.at(i).getId());
qreal len1 = GetLengthContour(points, splinePath->GetPathPoints());
qreal lenReverse = GetLengthContour(points, GetReversePoint(splinePath->GetPathPoints()));
if (len1 <= lenReverse)
{
points << splinePath.GetPathPoints();
points << splinePath->GetPathPoints();
if (detail.getSupplement() == true)
{
pointsEkv << biasPoints(splinePath.GetPathPoints(), detail[i].getMx(), detail[i].getMy());
pointsEkv << biasPoints(splinePath->GetPathPoints(), detail.at(i).getMx(), detail.at(i).getMy());
}
}
else
{
points << GetReversePoint(splinePath.GetPathPoints());
points << GetReversePoint(splinePath->GetPathPoints());
if (detail.getSupplement() == true)
{
pointsEkv << biasPoints(GetReversePoint(splinePath.GetPathPoints()), detail[i].getMx(),
detail[i].getMy());
pointsEkv << biasPoints(GetReversePoint(splinePath->GetPathPoints()), detail.at(i).getMx(),
detail.at(i).getMy());
}
}
}
break;
case (Tool::SplineTool):
break;//Nothing to do, just ignore.
default:
qWarning()<<"Get wrong tool type. Ignore."<<detail[i].getTypeTool();
qWarning()<<"Get wrong tool type. Ignore."<<detail.at(i).getTypeTool();
break;
}
}
@ -363,7 +402,7 @@ QPainterPath VContainer::Equidistant(QVector<QPointF> points, const Detail::Equi
continue;
}
else if (i == points.size()-1 && eqv == Detail::OpenEquidistant)
{//остання точка, polyline doesn't closed
{//last point, polyline doesn't closed
ekvPoints.append(SingleParallelPoint(QLineF(points[points.size()-1], points[points.size()-2]), -90,
width));
continue;
@ -508,18 +547,25 @@ QVector<QPointF> VContainer::CheckLoops(const QVector<QPointF> &points) const
void VContainer::PrepareDetails(QVector<VItem *> &list) const
{
QHashIterator<qint64, VDetail> iDetail(details);
while (iDetail.hasNext())
QHashIterator<qint64, VDetail> idetail(details);
while (idetail.hasNext())
{
iDetail.next();
list.append(new VItem(ContourPath(iDetail.key()), list.size()));
idetail.next();
list.append(new VItem(ContourPath(idetail.key()), list.size()));
}
}
template <typename val>
void VContainer::UpdateObject(QHash<qint64, val> &obj, const qint64 &id, const val& point)
void VContainer::UpdateObject(QHash<qint64, val> &obj, const qint64 &id, val point)
{
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
Q_ASSERT(point != 0);
point->setId(id);
if (gObjects.contains(id))
{
delete gObjects.value(id);
gObjects.remove(id);
}
obj[id] = point;
UpdateId(id);
}
@ -532,7 +578,8 @@ void VContainer::AddLengthSpline(const QString &name, const qreal &value)
void VContainer::AddLengthArc(const qint64 &id)
{
AddLengthArc(GetArc(id).name(), toMM(GetArc(id).GetLength()));
const VArc * arc = GeometricObject<const VArc *>(id);
AddLengthArc(arc->name(), toMM(arc->GetLength()));
}
void VContainer::AddLengthArc(const QString &name, const qreal &value)
@ -574,16 +621,33 @@ void VContainer::Clear()
lengthArcs.clear();
lineAngles.clear();
details.clear();
ClearObject();
CreateManTableIGroup ();
ClearGObjects();
}
void VContainer::ClearObject()
void VContainer::ClearGObjects()
{
points.clear();
splines.clear();
arcs.clear();
splinePaths.clear();
if (gObjects.size()>0)
{
qDeleteAll(gObjects);
}
gObjects.clear();
}
void VContainer::ClearCalculationGObjects()
{
if (gObjects.size()>0)
{
QHashIterator<qint64, VGObject*> i(gObjects);
while (i.hasNext())
{
i.next();
if (i.value()->getMode() == Draw::Calculation)
{
delete i.value();
gObjects.remove(i.key());
}
}
}
}
qreal VContainer::FindVar(const QString &name, bool *ok)const
@ -631,75 +695,49 @@ qreal VContainer::FindVar(const QString &name, bool *ok)const
void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId)
{
QString nameLine = GetNameLine(firstPointId, secondPointId);
VPointF first = GetPoint(firstPointId);
VPointF second = GetPoint(secondPointId);
AddLengthLine(nameLine, toMM(QLineF(first.toQPointF(), second.toQPointF()).length()));
const VPointF *first = GeometricObject<const VPointF *>(firstPointId);
const VPointF *second = GeometricObject<const VPointF *>(secondPointId);
AddLengthLine(nameLine, toMM(QLineF(first->toQPointF(), second->toQPointF()).length()));
nameLine = GetNameLineAngle(firstPointId, secondPointId);
AddLineAngle(nameLine, QLineF(first.toQPointF(), second.toQPointF()).angle());
}
qint64 VContainer::AddSpline(const VSpline &spl)
{
return AddObject(splines, spl);
}
qint64 VContainer::AddSplinePath(const VSplinePath &splPath)
{
return AddObject(splinePaths, splPath);
}
qint64 VContainer::AddArc(const VArc &arc)
{
return AddObject(arcs, arc);
AddLineAngle(nameLine, QLineF(first->toQPointF(), second->toQPointF()).angle());
}
template <typename key, typename val>
qint64 VContainer::AddObject(QHash<key, val> &obj, const val& value)
qint64 VContainer::AddObject(QHash<key, val> &obj, val value)
{
Q_ASSERT(value != 0);
qint64 id = getNextId();
value->setId(id);
obj[id] = value;
return id;
}
QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const
{
VPointF first = GetPoint(firstPoint);
VPointF second = GetPoint(secondPoint);
const VPointF *first = GeometricObject<const VPointF *>(firstPoint);
const VPointF *second = GeometricObject<const VPointF *>(secondPoint);
return QString("Line_%1_%2").arg(first.name(), second.name());
return QString("Line_%1_%2").arg(first->name(), second->name());
}
QString VContainer::GetNameLineAngle(const qint64 &firstPoint, const qint64 &secondPoint) const
{
VPointF first = GetPoint(firstPoint);
VPointF second = GetPoint(secondPoint);
const VPointF *first = GeometricObject<const VPointF *>(firstPoint);
const VPointF *second = GeometricObject<const VPointF *>(secondPoint);
return QString("AngleLine_%1_%2").arg(first.name(), second.name());
return QString("AngleLine_%1_%2").arg(first->name(), second->name());
}
void VContainer::UpdatePoint(qint64 id, const VPointF &point)
void VContainer::UpdateGObject(qint64 id, VGObject* obj)
{
UpdateObject(points, id, point);
UpdateObject(gObjects, id, obj);
}
void VContainer::UpdateDetail(qint64 id, const VDetail &detail)
void VContainer::UpdateDetail(qint64 id, VDetail detail)
{
UpdateObject(details, id, detail);
}
void VContainer::UpdateSpline(qint64 id, const VSpline &spl)
{
UpdateObject(splines, id, spl);
}
void VContainer::UpdateSplinePath(qint64 id, const VSplinePath &splPath)
{
UpdateObject(splinePaths, id, splPath);
}
void VContainer::UpdateArc(qint64 id, const VArc &arc)
{
UpdateObject(arcs, id, arc);
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
details[id] = detail;
UpdateId(id);
}
void VContainer::AddLengthLine(const QString &name, const qreal &value)
@ -710,7 +748,6 @@ void VContainer::AddLengthLine(const QString &name, const qreal &value)
void VContainer::CreateManTableIGroup ()
{
AddStandartTableCell("Pkor", VStandartTableRow(84, 0, 3));
AddStandartTableCell("Pkor", VStandartTableRow(84, 0, 3));
AddStandartTableCell("Vtos", VStandartTableRow(1450, 2, 51));
AddStandartTableCell("Vtosh", VStandartTableRow(1506, 2, 54));
@ -726,8 +763,6 @@ void VContainer::CreateManTableIGroup ()
AddStandartTableCell("SgI", VStandartTableRow(517, 18, 2));
AddStandartTableCell("SgII", VStandartTableRow(522, 19, 1));
AddStandartTableCell("SgIII", VStandartTableRow(500, 20, 0));
AddStandartTableCell("St", VStandartTableRow(390, 20, 0));
AddStandartTableCell("Sb", VStandartTableRow(492, 15, 5));
AddStandartTableCell("SbI", VStandartTableRow(482, 12, 6));
AddStandartTableCell("Obed", VStandartTableRow(566, 18, 6));
AddStandartTableCell("Ok", VStandartTableRow(386, 8, 8));
@ -760,10 +795,17 @@ void VContainer::CreateManTableIGroup ()
AddStandartTableCell("dpzr", VStandartTableRow(121, 6, 0));
AddStandartTableCell("Ogol", VStandartTableRow(576, 4, 4));
AddStandartTableCell("Ssh1", VStandartTableRow(205, 5, 0));
AddStandartTableCell("St", VStandartTableRow(410, 20, 0));
//TODO Posible duplicate. Need check.
//AddStandartTableCell("St", VStandartTableRow(410, 20, 0));
AddStandartTableCell("St", VStandartTableRow(390, 20, 0));
AddStandartTableCell("Drzap", VStandartTableRow(594, 3, 19));
AddStandartTableCell("DbII", VStandartTableRow(1020, 0, 44));
AddStandartTableCell("Sb", VStandartTableRow(504, 15, 4));
//TODO Posible duplicate. Need check.
//AddStandartTableCell("Sb", VStandartTableRow(504, 15, 4));
AddStandartTableCell("Sb", VStandartTableRow(492, 15, 5));
}
QVector<QPointF> VContainer::GetReversePoint(const QVector<QPointF> &points) const

View File

@ -35,6 +35,8 @@
#include "../geometry/vsplinepath.h"
#include "../geometry/vdetail.h"
#include "../widgets/vitem.h"
#include "../geometry/vgobject.h"
#include "../exception/vexceptionbadid.h"
/**
* @brief The VContainer class container of all variables.
@ -58,29 +60,54 @@ public:
* @param data container
*/
VContainer(const VContainer &data);
~VContainer();
template <typename T>
void CopyGObject(const VContainer &data, const qint64 &id)
{
T *obj = new T(*data.GeometricObject<const T *>(id));
Q_ASSERT(obj != 0);
UpdateGObject(id, obj);
}
/**
* @brief setData copy data from container
* @param data container
*/
void setData(const VContainer &data);
template <typename T>
const T GeometricObject(qint64 id) const
{
VGObject *gObj = 0;
if (gObjects.contains(id))
{
gObj = gObjects.value(id);
}
else
{
throw VExceptionBadId(tr("Can't find object"), id);
}
T obj = dynamic_cast<T>(gObj);
Q_ASSERT(obj != 0);
return obj;
}
/**
* @brief GetPoint returns a point by id
* @brief GetGObject returns a point by id
* @param id id of point
* @return point
*/
VPointF GetPoint(qint64 id) const;
const VGObject *GetGObject(qint64 id) const;
/**
* @brief GetStandartTableCell return standart table row by name
* @param name name of standart table row
* @return row of standart table
*/
VStandartTableRow GetStandartTableCell(const QString& name) const;
const VStandartTableRow GetStandartTableCell(const QString& name) const;
/**
* @brief GetIncrementTableRow return increment table row by name
* @param name name of increment table row
* @return row of increment table
*/
VIncrementTableRow GetIncrementTableRow(const QString& name) const;
const VIncrementTableRow GetIncrementTableRow(const QString& name) const;
/**
* @brief GetLine return length of line by name
* @param name name of line
@ -105,30 +132,12 @@ public:
* @return angle in degree
*/
qreal GetLineAngle(const QString &name) const;
/**
* @brief GetSpline return spline by id
* @param id id of spline
* @return spline
*/
VSpline GetSpline(qint64 id) const;
/**
* @brief GetArc return arc by id
* @param id id of arc
* @return arc
*/
VArc GetArc(qint64 id) const;
/**
* @brief GetSplinePath return spline path by id
* @param id id of spline path
* @return spline path
*/
VSplinePath GetSplinePath(qint64 id) const;
/**
* @brief GetDetail return detail by id
* @param id id of detail
* @return detail
*/
VDetail GetDetail(qint64 id) const;
const VDetail GetDetail(qint64 id) const;
/**
* @brief getId return current id
* @return current id
@ -139,27 +148,26 @@ public:
* @param point new point
* @return return id of new point in container
*/
qint64 AddPoint(const VPointF& point);
qint64 AddGObject(VGObject *obj);
/**
* @brief AddDetail add new detail to container
* @param detail new detail
* @return return id of new detail in container
*/
qint64 AddDetail(const VDetail& detail);
qint64 AddDetail(VDetail detail);
/**
* @brief AddStandartTableCell add new row of standart table
* @param name name of row of standart table
* @param cell row of standart table
*/
inline void AddStandartTableCell(const QString& name, const VStandartTableRow& cell)
inline void AddStandartTableCell(const QString& name, const VStandartTableRow &cell)
{standartTable[name] = cell;}
/**
* @brief AddIncrementTableRow add new row of increment table
* @param name name of new row of increment table
* @param row new row of increment table
*/
inline void AddIncrementTableRow(const QString& name, const VIncrementTableRow &row)
{incrementTable[name] = row;}
void AddIncrementTableRow(const QString& name, VIncrementTableRow row);
/**
* @brief AddLengthLine add length of line to container
* @param name name of line
@ -196,30 +204,6 @@ public:
* @param mode mode of line
*/
void AddLine(const qint64 &firstPointId, const qint64 &secondPointId);
/**
* @brief AddSpline add spline to container
* @param spl new spline
* @return id of spline in container
*/
qint64 AddSpline(const VSpline& spl);
/**
* @brief AddSplinePath add spline path to container
* @param splPath new spline path
* @return id of spline path in container
*/
qint64 AddSplinePath(const VSplinePath& splPath);
/**
* @brief AddArc add arc to container
* @param arc new arc
* @return id of arc in container in container
*/
qint64 AddArc(const VArc& arc);
/**
* @brief AddArcModeling add arc modeling to container
* @param arc new arc modeling
* @return id of new arc modeling in container
*/
qint64 AddArcModeling(const VArc& arc);
/**
* @brief GetNameLine return name of line
* @param firstPoint id of first point of line
@ -239,50 +223,26 @@ public:
* @param id id of existing point
* @param point point
*/
void UpdatePoint(qint64 id, const VPointF& point);
void UpdateGObject(qint64 id, VGObject* obj);
/**
* @brief UpdateDetail update detail by id
* @param id id of existing detail
* @param detail detail
*/
void UpdateDetail(qint64 id, const VDetail& detail);
/**
* @brief UpdateSpline update spline by id
* @param id if of existing spline
* @param spl spline
*/
void UpdateSpline(qint64 id, const VSpline& spl);
/**
* @brief UpdateSplinePath update spline path by id
* @param id id of existing spline path
* @param splPath spline path
*/
void UpdateSplinePath(qint64 id, const VSplinePath& splPath);
/**
* @brief UpdateArc update arc by id
* @param id id of existing arc
* @param arc arc
*/
void UpdateArc(qint64 id, const VArc& arc);
/**
* @brief UpdateArcModeling update arc modeling by id
* @param id id of existing arc modeling
* @param arc arc modeling
*/
void UpdateArcModeling(qint64 id, const VArc& arc);
void UpdateDetail(qint64 id, VDetail detail);
/**
* @brief UpdateStandartTableCell update standart table row by name
* @param name name of row
* @param cell row of standart table
*/
inline void UpdateStandartTableCell(const QString& name, const VStandartTableRow& cell)
inline void UpdateStandartTableCell(const QString& name, VStandartTableRow cell)
{standartTable[name] = cell;}
/**
* @brief UpdateIncrementTableRow update increment table row by name
* @param name name of row
* @param row row
*/
inline void UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& row)
inline void UpdateIncrementTableRow(const QString& name, VIncrementTableRow row)
{incrementTable[name] = row;}
/**
* @brief GetValueStandartTableCell return value of standart table row by name
@ -303,7 +263,8 @@ public:
/**
* @brief ClearObject points, splines, arcs, spline paths will be cleared.
*/
void ClearObject();
void ClearGObjects();
void ClearCalculationGObjects();
/**
* @brief ClearIncrementTable clear increment table
*/
@ -368,20 +329,10 @@ public:
*/
inline void RemoveIncrementTableRow(const QString& name) {incrementTable.remove(name);}
/**
* @brief data container with dataPoints return container of points
* @return pointer on container of points
* @brief data container with datagObjects return container of gObjects
* @return pointer on container of gObjects
*/
inline const QHash<qint64, VPointF> *DataPoints() const {return &points;}
/**
* @brief data container with dataSplines return container of splines
* @return pointer on container of splines
*/
inline const QHash<qint64, VSpline> *DataSplines() const {return &splines;}
/**
* @brief data container with dataArcs return container of arcs
* @return pointer on container of arcs
*/
inline const QHash<qint64, VArc> *DataArcs() const {return &arcs;}
inline const QHash<qint64, VGObject*> *DataGObjects() const {return &gObjects;}
/**
* @brief data container with dataBase return container of data
* @return pointer on container of base data
@ -417,11 +368,6 @@ public:
* @return pointer on container of angles of line
*/
inline const QHash<QString, qreal> *DataLineAngles() const {return &lineAngles;}
/**
* @brief data container with dataSplinePaths return container of spline paths
* @return pointer on container of spline paths
*/
inline const QHash<qint64, VSplinePath> *DataSplinePaths() const {return &splinePaths;}
/**
* @brief data container with dataDetails return container of details
* @return pointer on container of details
@ -488,6 +434,10 @@ public:
* @param list list of details
*/
void PrepareDetails(QVector<VItem *> & list) const;
/**
* @brief CreateManTableIGroup generate man standart table of measurements
*/
void CreateManTableIGroup ();
private:
/**
* @brief _id current id. New object will have value +1. For full class equal 0.
@ -498,9 +448,9 @@ private:
*/
QHash<QString, qint32> base;
/**
* @brief points container of points
* @brief gObjects graphicals objects of pattern.
*/
QHash<qint64, VPointF> points;
QHash<qint64, VGObject*> gObjects;
/**
* @brief standartTable container of standart table rows
*/
@ -517,34 +467,18 @@ private:
* @brief lineAngles container of angles of lines
*/
QHash<QString, qreal> lineAngles;
/**
* @brief splines container of splines
*/
QHash<qint64, VSpline> splines;
/**
* @brief lengthSplines container of splines length
*/
QHash<QString, qreal> lengthSplines;
/**
* @brief arcs container of arcs
*/
QHash<qint64, VArc> arcs;
/**
* @brief lengthArcs container of arcs length
*/
QHash<QString, qreal> lengthArcs;
/**
* @brief splinePaths container of spline paths
*/
QHash<qint64, VSplinePath> splinePaths;
/**
* @brief details container of details
*/
QHash<qint64, VDetail> details;
/**
* @brief CreateManTableIGroup generate man standart table of measurements
*/
void CreateManTableIGroup ();
/**
* @brief GetReversePoint return revers container of points
* @param points container with points
@ -565,7 +499,15 @@ private:
* @param id id of object
* @return Object
*/
static val GetObject(const QHash<key, val> &obj, key id);
const val GetObject(const QHash<key, val> &obj, key id) const;
template <typename key, typename val>
/**
* @brief GetObject return object from container
* @param obj container
* @param id id of object
* @return Object
*/
val GetVariable(const QHash<key, val> &obj, key id) const;
template <typename val>
/**
* @brief UpdateObject update object in container
@ -573,7 +515,7 @@ private:
* @param id id of existing object
* @param point object
*/
static void UpdateObject(QHash<qint64, val> &obj, const qint64 &id, const val& point);
void UpdateObject(QHash<qint64, val > &obj, const qint64 &id, val point);
template <typename key, typename val>
/**
* @brief AddObject add object to container
@ -581,7 +523,7 @@ private:
* @param value object
* @return id of object in container
*/
static qint64 AddObject(QHash<key, val> &obj, const val& value);
static qint64 AddObject(QHash<key, val> &obj, val value);
};
#endif // VCONTAINER_H

View File

@ -31,5 +31,6 @@
VStandartTableRow::VStandartTableRow()
:base(0), ksize(0), kgrowth(0), description(QString()){}
VStandartTableRow::VStandartTableRow(qint32 base, qreal ksize, qreal kgrowth, QString description)
VStandartTableRow::VStandartTableRow(const qint32 &base, const qreal &ksize, const qreal &kgrowth,
const QString &description)
:base(base), ksize(ksize), kgrowth(kgrowth), description(description){}

View File

@ -48,7 +48,9 @@ public:
* @param kgrowth increment in growths
* @param description description of increment
*/
VStandartTableRow(qint32 base, qreal ksize, qreal kgrowth, QString description = QString());
VStandartTableRow(const qint32 &base, const qreal &ksize, const qreal &kgrowth,
const QString &description = QString());
~VStandartTableRow(){}
/**
* @brief GetBase return value in base size and growth
* @return value

View File

@ -85,10 +85,10 @@ void DialogAlongLine::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
{
qint32 index = ui->comboBoxFirstPoint->findText(point.name());
qint32 index = ui->comboBoxFirstPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxFirstPoint->setCurrentIndex(index);
@ -99,7 +99,7 @@ void DialogAlongLine::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 1)
{
qint32 index = ui->comboBoxSecondPoint->findText(point.name());
qint32 index = ui->comboBoxSecondPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);

View File

@ -122,9 +122,9 @@ void DialogArc::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
ChangeCurrentText(ui->comboBoxBasePoint, point.name());
ChangeCurrentText(ui->comboBoxBasePoint, point->name());
emit ToolTip("");
this->show();
}

View File

@ -86,10 +86,10 @@ void DialogBisector::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
{
qint32 index = ui->comboBoxFirstPoint->findText(point.name());
qint32 index = ui->comboBoxFirstPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxFirstPoint->setCurrentIndex(index);
@ -100,7 +100,7 @@ void DialogBisector::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 1)
{
qint32 index = ui->comboBoxSecondPoint->findText(point.name());
qint32 index = ui->comboBoxSecondPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);
@ -111,7 +111,7 @@ void DialogBisector::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 2)
{
qint32 index = ui->comboBoxThirdPoint->findText(point.name());
qint32 index = ui->comboBoxThirdPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxThirdPoint->setCurrentIndex(index);

View File

@ -97,8 +97,8 @@ void DialogCutSpline::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Spline)
{
VSpline spl = data->GetSpline(id);
ChangeCurrentText(ui->comboBoxSpline, spl.name());
const VSpline *spl = data->GeometricObject<const VSpline *>(id);
ChangeCurrentText(ui->comboBoxSpline, spl->name());
emit ToolTip("");
this->show();
}

View File

@ -31,8 +31,9 @@
#include "dialogtool.h"
namespace Ui {
class DialogCutSpline;
namespace Ui
{
class DialogCutSpline;
}
class DialogCutSpline : public DialogTool

View File

@ -98,8 +98,8 @@ void DialogCutSplinePath::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::SplinePath)
{
VSplinePath splPath = data->GetSplinePath(id);
ChangeCurrentText(ui->comboBoxSplinePath, splPath.name());
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(id);
ChangeCurrentText(ui->comboBoxSplinePath, splPath->name());
emit ToolTip("");
this->show();
}

View File

@ -31,8 +31,9 @@
#include "dialogtool.h"
namespace Ui {
class DialogCutSplinePath;
namespace Ui
{
class DialogCutSplinePath;
}
class DialogCutSplinePath : public DialogTool

View File

@ -103,26 +103,26 @@ void DialogDetail::NewItem(qint64 id, const Tool::Tools &typeTool, const NodeDet
{
case (Tool::NodePoint):
{
VPointF point = data->GetPoint(id);
name = point.name();
const VPointF *point = data->GeometricObject<const VPointF *>(id);
name = point->name();
break;
}
case (Tool::NodeArc):
{
VArc arc = data->GetArc(id);
name = arc.name();
const VArc *arc = data->GeometricObject<const VArc *>(id);
name = arc->name();
break;
}
case (Tool::NodeSpline):
{
VSpline spl = data->GetSpline(id);
name = spl.GetName();
const VSpline *spl = data->GeometricObject<const VSpline *>(id);
name = spl->name();
break;
}
case (Tool::NodeSplinePath):
{
VSplinePath splPath = data->GetSplinePath(id);
name = splPath.name();
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(id);
name = splPath->name();
break;
}
default:

View File

@ -97,8 +97,8 @@ void DialogEndLine::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
ChangeCurrentText(ui->comboBoxBasePoint, point.name());
const VPointF *point = data->GeometricObject<const VPointF *>(id);
ChangeCurrentText(ui->comboBoxBasePoint, point->name());
emit ToolTip("");
this->show();
}

View File

@ -90,21 +90,21 @@ void DialogHeight::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
switch (number)
{
case (0):
ChangeCurrentText(ui->comboBoxBasePoint, point.name());
ChangeCurrentText(ui->comboBoxBasePoint, point->name());
number++;
emit ToolTip(tr("Select first point of line"));
break;
case (1):
ChangeCurrentText(ui->comboBoxP1Line, point.name());
ChangeCurrentText(ui->comboBoxP1Line, point->name());
number++;
emit ToolTip(tr("Select second point of line"));
break;
case (2):
ChangeCurrentText(ui->comboBoxP2Line, point.name());
ChangeCurrentText(ui->comboBoxP2Line, point->name());
number = 0;
emit ToolTip(tr(""));
if (isInitialized == false)

View File

@ -31,6 +31,9 @@
#include "../geometry/varc.h"
#include "../geometry/vspline.h"
#include "../geometry/vsplinepath.h"
#include "../tools/vabstracttool.h"
#include "../tools/drawTools/vtoolcutspline.h"
#include "../tools/drawTools/vtoolcutsplinepath.h"
#include <QDebug>
#include <QPushButton>
@ -172,120 +175,156 @@ QString DialogHistory::Record(const VToolRecord &tool)
case Tool::ArrowTool:
break;
case Tool::SinglePointTool:
record = QString(tr("%1 - Base point")).arg(data->GetPoint(tool.getId()).name());
{
QString name = data->GeometricObject<const VPointF *>(tool.getId())->name();
record = QString(tr("%1 - Base point")).arg(name);
break;
}
case Tool::EndLineTool:
{
domElement = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement())
{
basePointId = domElement.attribute("basePoint", "").toLongLong();
basePointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrBasePoint, "0");
}
record = QString(tr("%1_%2 - Line from point %1 to point %2")).arg(data->GetPoint(basePointId).name(),
data->GetPoint(tool.getId()).name());
QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name();
QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
record = QString(tr("%1_%2 - Line from point %1 to point %2")).arg(basePointIdName, toolIdName);
break;
}
case Tool::LineTool:
{
domElement = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement())
{
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
firstPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0");
secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0");
}
record = QString(tr("%1_%2 - Line from point %1 to point %2")).arg(data->GetPoint(firstPointId).name(),
data->GetPoint(secondPointId).name());
QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name();
QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name();
record = QString(tr("%1_%2 - Line from point %1 to point %2")).arg(firstPointIdName, secondPointIdName);
break;
}
case Tool::AlongLineTool:
{
domElement = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement())
{
basePointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
basePointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0");
secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0");
}
record = QString(tr("%3 - Point along line %1_%2")).arg(data->GetPoint(basePointId).name(),
data->GetPoint(secondPointId).name(),
data->GetPoint(tool.getId()).name());
QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name();
QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name();
QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
record = QString(tr("%3 - Point along line %1_%2")).arg(basePointIdName, secondPointIdName, toolIdName);
break;
}
case Tool::ShoulderPointTool:
record = QString(tr("%1 - Point of shoulder")).arg(data->GetPoint(tool.getId()).name());
{
QString name = data->GeometricObject<const VPointF *>(tool.getId())->name();
record = QString(tr("%1 - Point of shoulder")).arg(name);
break;
}
case Tool::NormalTool:
{
domElement = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement())
{
basePointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
basePointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0");
secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0");
}
record = QString(tr("%3 - normal to line %1_%2")).arg(data->GetPoint(basePointId).name(),
data->GetPoint(secondPointId).name(),
data->GetPoint(tool.getId()).name());
QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name();
QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name();
QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
record = QString(tr("%3 - normal to line %1_%2")).arg(basePointIdName, secondPointIdName, toolIdName);
break;
}
case Tool::BisectorTool:
{
domElement = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement())
{
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
basePointId = domElement.attribute("secondPoint", "").toLongLong();
thirdPointId = domElement.attribute("thirdPoint", "").toLongLong();
firstPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0");
secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0");
thirdPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrThirdPoint, "0");
}
record = QString(tr("%4 - bisector of angle %1_%2_%3")).arg(data->GetPoint(firstPointId).name(),
data->GetPoint(basePointId).name(),
data->GetPoint(thirdPointId).name(),
data->GetPoint(tool.getId()).name());
QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name();
QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name();
QString thirdPointIdName = data->GeometricObject<const VPointF *>(thirdPointId)->name();
QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
record = QString(tr("%4 - bisector of angle %1_%2_%3")).arg(firstPointIdName, basePointIdName,
thirdPointIdName, toolIdName);
break;
}
case Tool::LineIntersectTool:
{
domElement = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement())
{
p1Line1 = domElement.attribute("p1Line1", "").toLongLong();
p2Line1 = domElement.attribute("p2Line1", "").toLongLong();
p1Line2 = domElement.attribute("p1Line2", "").toLongLong();
p2Line2 = domElement.attribute("p2Line2", "").toLongLong();
p1Line1 = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP1Line1, "0");
p2Line1 = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP2Line1, "0");
p1Line2 = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP1Line2, "0");
p2Line2 = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP2Line2, "0");
}
record = QString(tr("%5 - intersection of lines %1_%2 and %3_%4")).arg(data->GetPoint(p1Line1).name(),
data->GetPoint(p2Line1).name(),
data->GetPoint(p1Line2).name(),
data->GetPoint(p2Line2).name(),
data->GetPoint(tool.getId()).name());
QString p1Line1Name = data->GeometricObject<const VPointF *>(p1Line1)->name();
QString p2Line1Name = data->GeometricObject<const VPointF *>(p2Line1)->name();
QString p1Line2Name = data->GeometricObject<const VPointF *>(p1Line2)->name();
QString p2Line2Name = data->GeometricObject<const VPointF *>(p2Line2)->name();
QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
record = QString(tr("%5 - intersection of lines %1_%2 and %3_%4")).arg(p1Line1Name, p2Line1Name,
p1Line2Name, p2Line2Name,
toolIdName);
break;
}
case Tool::SplineTool:
{
VSpline spl = data->GetSpline(tool.getId());
record = QString(tr("Curve %1_%2")).arg(data->GetPoint(spl.GetP1()).name(),
data->GetPoint(spl.GetP4()).name());
const VSpline *spl = data->GeometricObject<const VSpline *>(tool.getId());
QString splP1Name = data->GeometricObject<const VSpline *>(spl->GetP1().id())->name();
QString splP4Name = data->GeometricObject<const VSpline *>(spl->GetP4().id())->name();
record = QString(tr("Curve %1_%2")).arg(splP1Name, splP4Name);
}
break;
case Tool::ArcTool:
{
VArc arc = data->GetArc(tool.getId());
record = QString(tr("Arc with center in point %1")).arg(data->GetPoint(arc.GetCenter()).name());
const VArc *arc = data->GeometricObject<const VArc *>(tool.getId());
QString arcCenterName = data->GeometricObject<const VArc *>(arc->GetCenter().id())->name();
record = QString(tr("Arc with center in point %1")).arg(arcCenterName);
}
break;
case Tool::SplinePathTool:
{
VSplinePath splPath = data->GetSplinePath(tool.getId());
QVector<VSplinePoint> points = splPath.GetSplinePath();
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(tool.getId());
QVector<VSplinePoint> points = splPath->GetSplinePath();
if (points.size() != 0 )
{
record = QString(tr("Curve point %1")).arg(data->GetPoint(points[0].P()).name());
QString pName = data->GeometricObject<const VPointF *>(points[0].P().id())->name();
record = QString(tr("Curve point %1")).arg(pName);
for (qint32 i = 1; i< points.size(); ++i)
{
QString name = QString("_%1").arg(data->GetPoint(points[i].P()).name());
pName = data->GeometricObject<const VPointF *>(points[i].P().id())->name();
QString name = QString("_%1").arg(pName);
record.append(name);
}
}
}
break;
case Tool::PointOfContact:
{
domElement = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement())
{
center = domElement.attribute("center", "").toLongLong();
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
center = doc->GetParametrLongLong(domElement, VAbstractTool::AttrCenter, "0");
firstPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0");
secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0");
}
QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name();
QString centerName = data->GeometricObject<const VPointF *>(center)->name();
QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name();
QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
record = QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3")).arg(
data->GetPoint(center).name(), data->GetPoint(firstPointId).name(),
data->GetPoint(secondPointId).name(), data->GetPoint(tool.getId()).name());
centerName, firstPointIdName, secondPointIdName, toolIdName);
break;
}
case Tool::Height:
{
qint64 p1LineId = 0;
@ -293,13 +332,15 @@ QString DialogHistory::Record(const VToolRecord &tool)
domElement = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement())
{
basePointId = domElement.attribute("basePoint", "").toLongLong();
p1LineId = domElement.attribute("p1Line", "").toLongLong();
p2LineId = domElement.attribute("p2Line", "").toLongLong();
basePointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrBasePoint, "0");
p1LineId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP1Line, "0");
p2LineId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrP2Line, "0");
}
record = QString(tr("Point of perpendicular from point %1 to line %2_%3")).arg(
data->GetPoint(basePointId).name(), data->GetPoint(p1LineId).name(),
data->GetPoint(p2LineId).name());
QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name();
QString p1LineIdName = data->GeometricObject<const VPointF *>(p1LineId)->name();
QString p2LineIdName = data->GeometricObject<const VPointF *>(p2LineId)->name();
record = QString(tr("Point of perpendicular from point %1 to line %2_%3")).arg( basePointIdName,
p1LineIdName, p2LineIdName);
break;
}
case Tool::Triangle:
@ -309,16 +350,72 @@ QString DialogHistory::Record(const VToolRecord &tool)
domElement = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement())
{
axisP1Id = domElement.attribute("axisP1", "").toLongLong();
axisP2Id = domElement.attribute("axisP2", "").toLongLong();
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
axisP1Id = doc->GetParametrLongLong(domElement, VAbstractTool::AttrAxisP1, "0");
axisP2Id = doc->GetParametrLongLong(domElement, VAbstractTool::AttrAxisP2, "0");
firstPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0");
secondPointId = doc->GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0");
}
record = QString(tr("Triangle: axis %1_%2, points %3 and %4")).arg(
data->GetPoint(axisP1Id).name(), data->GetPoint(axisP2Id).name(),
data->GetPoint(firstPointId).name(), data->GetPoint(secondPointId).name());
QString axisP1IdName = data->GeometricObject<const VPointF *>(axisP1Id)->name();
QString axisP2IdName = data->GeometricObject<const VPointF *>(axisP2Id)->name();
QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name();
QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name();
record = QString(tr("Triangle: axis %1_%2, points %3 and %4")).arg( axisP1IdName, axisP2IdName,
firstPointIdName, secondPointIdName);
break;
}
case Tool::CutSplineTool:
{
qint64 splineId = 0;
domElement = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement())
{
splineId = doc->GetParametrLongLong(domElement, VToolCutSpline::AttrSpline, "0");
}
const VSpline *spl = data->GeometricObject<const VSpline *>(splineId);
QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
QString splP1Name = data->GeometricObject<const VPointF *>(spl->GetP1().id())->name();
QString splP4Name = data->GeometricObject<const VPointF *>(spl->GetP4().id())->name();
record = QString(tr("%1 - cut curve %2_%3")).arg(toolIdName, splP1Name, splP4Name);
}
break;
case Tool::CutSplinePathTool:
{
qint64 splinePathId = 0;
domElement = doc->elementById(QString().setNum(tool.getId()));
if (domElement.isElement())
{
splinePathId = doc->GetParametrLongLong(domElement, VToolCutSplinePath::AttrSplinePath, "0");
}
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(splinePathId);
QVector<VSplinePoint> points = splPath->GetSplinePath();
if (points.size() != 0 )
{
QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name();
QString pName = data->GeometricObject<const VPointF *>(points[0].P().id())->name();
record = QString(tr("%1 - cut curve point %2")).arg(toolIdName, pName);
for (qint32 i = 1; i< points.size(); ++i)
{
pName = data->GeometricObject<const VPointF *>(points[i].P().id())->name();
QString name = QString("_%1").arg(pName);
record.append(name);
}
}
}
break;
//Because "history" not only show history of pattern, but help restore current data for each pattern's piece, we
//need add record about details and nodes, but don't show them.
case Tool::Detail:
break;
case Tool::UnionDetails:
break;
case Tool::NodeArc:
break;
case Tool::NodePoint:
break;
case Tool::NodeSpline:
break;
case Tool::NodeSplinePath:
break;
default:
qWarning()<<tr("Got wrong tool type. Ignore.");
break;

View File

@ -54,8 +54,8 @@ DialogLine::~DialogLine()
void DialogLine::setSecondPoint(const qint64 &value)
{
secondPoint = value;
VPointF point = data->GetPoint(value);
qint32 index = ui->comboBoxSecondPoint->findText(point.name());
const VPointF *point = data->GeometricObject<const VPointF *>(value);
qint32 index = ui->comboBoxSecondPoint->findText(point->name());
if (index != -1)
{
ui->comboBoxSecondPoint->setCurrentIndex(index);
@ -65,8 +65,8 @@ void DialogLine::setSecondPoint(const qint64 &value)
void DialogLine::setFirstPoint(const qint64 &value)
{
firstPoint = value;
VPointF point = data->GetPoint(value);
qint32 index = ui->comboBoxFirstPoint->findText(point.name());
const VPointF *point = data->GeometricObject<const VPointF *>(value);
qint32 index = ui->comboBoxFirstPoint->findText(point->name());
if (index != -1)
{
ui->comboBoxFirstPoint->setCurrentIndex(index);
@ -87,10 +87,10 @@ void DialogLine::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
{
qint32 index = ui->comboBoxFirstPoint->findText(point.name());
qint32 index = ui->comboBoxFirstPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxFirstPoint->setCurrentIndex(index);
@ -101,7 +101,7 @@ void DialogLine::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 1)
{
qint32 index = ui->comboBoxSecondPoint->findText(point.name());
qint32 index = ui->comboBoxSecondPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);

View File

@ -61,10 +61,10 @@ void DialogLineIntersect::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
{
qint32 index = ui->comboBoxP1Line1->findText(point.name());
qint32 index = ui->comboBoxP1Line1->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP1Line1->setCurrentIndex(index);
@ -76,7 +76,7 @@ void DialogLineIntersect::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 1)
{
qint32 index = ui->comboBoxP2Line1->findText(point.name());
qint32 index = ui->comboBoxP2Line1->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP2Line1->setCurrentIndex(index);
@ -88,7 +88,7 @@ void DialogLineIntersect::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 2)
{
qint32 index = ui->comboBoxP1Line2->findText(point.name());
qint32 index = ui->comboBoxP1Line2->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP1Line2->setCurrentIndex(index);
@ -100,7 +100,7 @@ void DialogLineIntersect::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 3)
{
qint32 index = ui->comboBoxP2Line2->findText(point.name());
qint32 index = ui->comboBoxP2Line2->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP2Line2->setCurrentIndex(index);
@ -176,13 +176,13 @@ void DialogLineIntersect::CheckState()
bool DialogLineIntersect::CheckIntersecion()
{
VPointF p1L1 = data->GetPoint(p1Line1);
VPointF p2L1 = data->GetPoint(p2Line1);
VPointF p1L2 = data->GetPoint(p1Line2);
VPointF p2L2 = data->GetPoint(p2Line2);
const VPointF *p1L1 = data->GeometricObject<const VPointF *>(p1Line1);
const VPointF *p2L1 = data->GeometricObject<const VPointF *>(p2Line1);
const VPointF *p1L2 = data->GeometricObject<const VPointF *>(p1Line2);
const VPointF *p2L2 = data->GeometricObject<const VPointF *>(p2Line2);
QLineF line1(p1L1.toQPointF(), p2L1.toQPointF());
QLineF line2(p1L2.toQPointF(), p2L2.toQPointF());
QLineF line1(p1L1->toQPointF(), p2L1->toQPointF());
QLineF line2(p1L2->toQPointF(), p2L2->toQPointF());
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)

View File

@ -102,10 +102,10 @@ void DialogNormal::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
{
qint32 index = ui->comboBoxFirstPoint->findText(point.name());
qint32 index = ui->comboBoxFirstPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxFirstPoint->setCurrentIndex(index);
@ -116,7 +116,7 @@ void DialogNormal::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 1)
{
qint32 index = ui->comboBoxSecondPoint->findText(point.name());
qint32 index = ui->comboBoxSecondPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);

View File

@ -96,7 +96,7 @@ public:
*/
inline qint64 getFirstPointId() const {return firstPointId;}
/**
* @brief setFirstPointId set id of first point
* @brief setFirstPointId set id of first point
* @param value id
* @param id don't show this id in list
*/

View File

@ -79,10 +79,10 @@ void DialogPointOfContact::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
{
qint32 index = ui.comboBoxFirstPoint->findText(point.name());
qint32 index = ui.comboBoxFirstPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui.comboBoxFirstPoint->setCurrentIndex(index);
@ -93,7 +93,7 @@ void DialogPointOfContact::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 1)
{
qint32 index = ui.comboBoxSecondPoint->findText(point.name());
qint32 index = ui.comboBoxSecondPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui.comboBoxSecondPoint->setCurrentIndex(index);
@ -104,7 +104,7 @@ void DialogPointOfContact::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 2)
{
qint32 index = ui.comboBoxCenter->findText(point.name());
qint32 index = ui.comboBoxCenter->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui.comboBoxCenter->setCurrentIndex(index);

View File

@ -65,10 +65,10 @@ void DialogPointOfIntersection::ChoosedObject(qint64 id, const Scene::Scenes &ty
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
{
qint32 index = ui->comboBoxFirstPoint->findText(point.name());
qint32 index = ui->comboBoxFirstPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxFirstPoint->setCurrentIndex(index);
@ -79,7 +79,7 @@ void DialogPointOfIntersection::ChoosedObject(qint64 id, const Scene::Scenes &ty
}
if (number == 1)
{
qint32 index = ui->comboBoxSecondPoint->findText(point.name());
qint32 index = ui->comboBoxSecondPoint->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxSecondPoint->setCurrentIndex(index);

View File

@ -66,7 +66,7 @@ public:
*/
inline qint64 getFirstPointId() const {return firstPointId;}
/**
* @brief setFirstPointId set id of first point
* @brief setFirstPointId set id of first point
* @param value id
* @param id don't show this id in list.
*/

View File

@ -47,5 +47,6 @@
#include "dialogheight.h"
#include "dialogcutspline.h"
#include "dialogcutsplinepath.h"
#include "dialoguniondetails.h"
#endif // DIALOGS_H

View File

@ -20,7 +20,8 @@ HEADERS += \
src/dialogs/dialogarc.h \
src/dialogs/dialogalongline.h \
src/dialogs/dialogcutspline.h \
src/dialogs/dialogcutsplinepath.h
src/dialogs/dialogcutsplinepath.h \
src/dialogs/dialoguniondetails.h
SOURCES += \
src/dialogs/dialogtriangle.cpp \
@ -43,7 +44,8 @@ SOURCES += \
src/dialogs/dialogarc.cpp \
src/dialogs/dialogalongline.cpp \
src/dialogs/dialogcutspline.cpp \
src/dialogs/dialogcutsplinepath.cpp
src/dialogs/dialogcutsplinepath.cpp \
src/dialogs/dialoguniondetails.cpp
FORMS += \
src/dialogs/dialogtriangle.ui \
@ -65,4 +67,5 @@ FORMS += \
src/dialogs/dialogarc.ui \
src/dialogs/dialogalongline.ui \
src/dialogs/dialogcutspline.ui \
src/dialogs/dialogcutsplinepath.ui
src/dialogs/dialogcutsplinepath.ui \
src/dialogs/dialoguniondetails.ui

View File

@ -87,10 +87,10 @@ void DialogShoulderPoint::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
{
qint32 index = ui->comboBoxP1Line->findText(point.name());
qint32 index = ui->comboBoxP1Line->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP1Line->setCurrentIndex(index);
@ -101,7 +101,7 @@ void DialogShoulderPoint::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 1)
{
qint32 index = ui->comboBoxP2Line->findText(point.name());
qint32 index = ui->comboBoxP2Line->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP2Line->setCurrentIndex(index);
@ -112,7 +112,7 @@ void DialogShoulderPoint::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 2)
{
qint32 index = ui->comboBoxPShoulder->findText(point.name());
qint32 index = ui->comboBoxPShoulder->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxPShoulder->setCurrentIndex(index);

View File

@ -51,14 +51,19 @@ DialogSpline::~DialogSpline()
delete ui;
}
qint64 DialogSpline::getP1() const
{
return p1;
}
void DialogSpline::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
{
qint32 index = ui->comboBoxP1->findText(point.name());
qint32 index = ui->comboBoxP1->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP1->setCurrentIndex(index);
@ -69,7 +74,7 @@ void DialogSpline::ChoosedObject(qint64 id, const Scene::Scenes &type)
}
if (number == 1)
{
qint32 index = ui->comboBoxP4->findText(point.name());
qint32 index = ui->comboBoxP4->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP4->setCurrentIndex(index);
@ -78,8 +83,8 @@ void DialogSpline::ChoosedObject(qint64 id, const Scene::Scenes &type)
index = ui->comboBoxP1->currentIndex();
qint64 p1Id = qvariant_cast<qint64>(ui->comboBoxP1->itemData(index));
QPointF p1 = data->GetPoint(p1Id).toQPointF();
QPointF p4 = data->GetPoint(id).toQPointF();
QPointF p1 = data->GeometricObject<const VPointF *>(p1Id)->toQPointF();
QPointF p4 = data->GeometricObject<const VPointF *>(id)->toQPointF();
ui->spinBoxAngle1->setValue(static_cast<qint32>(QLineF(p1, p4).angle()));
ui->spinBoxAngle2->setValue(static_cast<qint32>(QLineF(p4, p1).angle()));
@ -145,3 +150,8 @@ void DialogSpline::setP1(const qint64 &value)
p1 = value;
ChangeCurrentData(ui->comboBoxP1, value);
}
qint64 DialogSpline::getP4() const
{
return p4;
}

View File

@ -54,7 +54,7 @@ public:
* @brief getP1 return id first point of spline
* @return id
*/
inline qint64 getP1() const {return p1;}
qint64 getP1() const;
/**
* @brief setP1 set id first point of spline
* @param value id
@ -64,7 +64,7 @@ public:
* @brief getP4 return id fourth point of spline
* @return id
*/
inline qint64 getP4() const {return p4;}
qint64 getP4() const;
/**
* @brief setP4 set id fourth point of spline
* @param value id

View File

@ -44,8 +44,6 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, QWidget *parent)
FillComboBoxPoints(ui->comboBoxPoint);
path = VSplinePath(data->DataPoints());
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogSplinePath::PointChenged);
connect(ui->comboBoxPoint, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogSplinePath::currentPointChanged);
@ -70,7 +68,7 @@ void DialogSplinePath::SetPath(const VSplinePath &value)
ui->listWidget->clear();
for (qint32 i = 0; i < path.CountPoint(); ++i)
{
NewItem(path[i].P(), path[i].KAsm1(), path[i].Angle2(), path[i].KAsm2());
NewItem(path[i].P().id(), path[i].KAsm1(), path[i].Angle2(), path[i].KAsm2());
}
ui->listWidget->setFocus(Qt::OtherFocusReason);
ui->doubleSpinBoxKcurve->setValue(path.getKCurve());
@ -108,7 +106,7 @@ void DialogSplinePath::PointChenged(int row)
}
QListWidgetItem *item = ui->listWidget->item( row );
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
DataPoint(p.P(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
DataPoint(p.P().id(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
EnableFields();
}
@ -118,8 +116,9 @@ void DialogSplinePath::currentPointChanged(int index)
qint32 row = ui->listWidget->currentRow();
QListWidgetItem *item = ui->listWidget->item( row );
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
p.SetP(id);
DataPoint(p.P(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
const VPointF *point = data->GeometricObject<const VPointF *>(id);
p.SetP(*point);
DataPoint(p.P().id(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
EnableFields();
item->setData(Qt::UserRole, QVariant::fromValue(p));
}
@ -154,11 +153,11 @@ void DialogSplinePath::KAsm2Changed(qreal d)
void DialogSplinePath::NewItem(qint64 id, qreal kAsm1, qreal angle, qreal kAsm2)
{
VPointF point = data->GetPoint(id);
QListWidgetItem *item = new QListWidgetItem(point.name());
const VPointF *point = data->GeometricObject<const VPointF *>(id);
QListWidgetItem *item = new QListWidgetItem(point->name());
item->setFont(QFont("Times", 12, QFont::Bold));
VSplinePoint p(id, kAsm1, angle, kAsm2);
DataPoint(id, kAsm1, angle+180, kAsm2, angle);
VSplinePoint p(*point, kAsm1, angle, kAsm2);
DataPoint(point->id(), kAsm1, angle+180, kAsm2, angle);
item->setData(Qt::UserRole, QVariant::fromValue(p));
ui->listWidget->addItem(item);
EnableFields();
@ -222,6 +221,6 @@ void DialogSplinePath::SetAngle(qint32 angle)
QListWidgetItem *item = ui->listWidget->item( row );
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
p.SetAngle(angle);
DataPoint(p.P(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
DataPoint(p.P().id(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
item->setData(Qt::UserRole, QVariant::fromValue(p));
}

View File

@ -28,6 +28,7 @@
#include "dialogtool.h"
#include "../container/calculator.h"
#include "../geometry/vgobject.h"
#include <QtWidgets>
@ -66,15 +67,19 @@ void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const
{
Q_ASSERT(box != 0);
box->clear();
const QHash<qint64, VPointF> *points = data->DataPoints();
QHashIterator<qint64, VPointF> i(*points);
const QHash<qint64, VGObject*> *objs = data->DataGObjects();
QHashIterator<qint64, VGObject*> i(*objs);
while (i.hasNext())
{
i.next();
if (i.key() != id)
{
VPointF point = i.value();
box->addItem(point.name(), i.key());
VGObject *obj = i.value();
if (obj->getType() == GObject::Point && obj->getMode() == Draw::Calculation)
{
const VPointF *point = data->GeometricObject<const VPointF *>(i.key());
box->addItem(point->name(), i.key());
}
}
}
}
@ -83,25 +88,33 @@ void DialogTool::FillComboBoxSplines(QComboBox *box, const qint64 &id, ComboMode
{
Q_ASSERT(box != 0);
box->clear();
const QHash<qint64, VSpline> *spls = data->DataSplines();
QHashIterator<qint64, VSpline> i(*spls);
const QHash<qint64, VGObject *> *objs = data->DataGObjects();
QHashIterator<qint64, VGObject*> i(*objs);
while (i.hasNext())
{
i.next();
if(cut == ComboMode::CutSpline)
if (cut == ComboMode::CutSpline)
{
if (i.key() != id + 1 && i.key() != id + 2)
{
VSpline spl = i.value();
box->addItem(spl.name(), i.key());
VGObject *obj = i.value();
if (obj->getType() == GObject::Spline && obj->getMode() == Draw::Calculation)
{
const VSpline *spl = data->GeometricObject<const VSpline *>(i.key());
box->addItem(spl->name(), i.key());
}
}
}
else
{
if (i.key() != id)
{
VSpline spl = i.value();
box->addItem(spl.name(), i.key());
VGObject *obj = i.value();
if (obj->getType() == GObject::Spline && obj->getMode() == Draw::Calculation)
{
const VSpline *spl = data->GeometricObject<const VSpline *>(i.key());
box->addItem(spl->name(), i.key());
}
}
}
}
@ -111,25 +124,33 @@ void DialogTool::FillComboBoxSplinesPath(QComboBox *box, const qint64 &id, Combo
{
Q_ASSERT(box != 0);
box->clear();
const QHash<qint64, VSplinePath> *splPaths = data->DataSplinePaths();
QHashIterator<qint64, VSplinePath> i(*splPaths);
const QHash<qint64, VGObject *> *objs = data->DataGObjects();
QHashIterator<qint64, VGObject *> i(*objs);
while (i.hasNext())
{
i.next();
if(cut == ComboMode::CutSpline)
if (cut == ComboMode::CutSpline)
{
if (i.key() != id + 1 && i.key() != id + 2)
{
VSplinePath splPath = i.value();
box->addItem(splPath.name(), i.key());
VGObject *obj = i.value();
if (obj->getType() == GObject::SplinePath && obj->getMode() == Draw::Calculation)
{
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(i.key());
box->addItem(splPath->name(), i.key());
}
}
}
else
{
if (i.key() != id)
{
VSplinePath splPath = i.value();
box->addItem(splPath.name(), i.key());
VGObject *obj = i.value();
if (obj->getType() == GObject::SplinePath && obj->getMode() == Draw::Calculation)
{
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(i.key());
box->addItem(splPath->name(), i.key());
}
}
}
}

View File

@ -61,26 +61,26 @@ void DialogTriangle::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (type == Scene::Point)
{
VPointF point = data->GetPoint(id);
const VPointF *point = data->GeometricObject<const VPointF *>(id);
switch (number)
{
case (0):
ChangeCurrentText(ui->comboBoxAxisP1, point.name());
ChangeCurrentText(ui->comboBoxAxisP1, point->name());
number++;
emit ToolTip(tr("Select second point of axis"));
break;
case (1):
ChangeCurrentText(ui->comboBoxAxisP2, point.name());
ChangeCurrentText(ui->comboBoxAxisP2, point->name());
number++;
emit ToolTip(tr("Select first point"));
break;
case (2):
ChangeCurrentText(ui->comboBoxFirstPoint, point.name());
ChangeCurrentText(ui->comboBoxFirstPoint, point->name());
number++;
emit ToolTip(tr("Select second point"));
break;
case (3):
ChangeCurrentText(ui->comboBoxSecondPoint, point.name());
ChangeCurrentText(ui->comboBoxSecondPoint, point->name());
number = 0;
emit ToolTip(tr(""));
if (isInitialized == false)

View File

@ -78,7 +78,7 @@ public:
*/
inline qint64 getFirstPointId() const {return firstPointId;}
/**
* @brief setFirstPointId set id of first point
* @brief setFirstPointId set id of first point
* @param value id
* @param id don't show this point in list
*/

View File

@ -0,0 +1,135 @@
/************************************************************************
**
** @file dialoguniondetails.cpp
** @author Roman Telezhinsky <dismine@gmail.com>
** @date 23 12, 2013
**
** @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) 2013 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 "dialoguniondetails.h"
#include "ui_dialoguniondetails.h"
DialogUnionDetails::DialogUnionDetails(const VContainer *data, QWidget *parent) :
DialogTool(data, parent), ui(new Ui::DialogUnionDetails), indexD1(0), indexD2(0), d1(0), d2(0), numberD(0),
numberP(0), p1(0), p2(0)
{
ui->setupUi(this);
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
connect(bOk, &QPushButton::clicked, this, &DialogUnionDetails::DialogAccepted);
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
connect(bCansel, &QPushButton::clicked, this, &DialogUnionDetails::DialogRejected);
}
DialogUnionDetails::~DialogUnionDetails()
{
delete ui;
}
void DialogUnionDetails::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (numberD == 0)
{
ChoosedDetail(id, type, d1, indexD1);
}
else
{
ChoosedDetail(id, type, d2, indexD2);
}
}
void DialogUnionDetails::DialogAccepted()
{
emit DialogClosed(QDialog::Accepted);
}
bool DialogUnionDetails::CheckObject(const qint64 &id, const qint64 &idDetail) const
{
if (idDetail == 0)
{
return false;
}
VDetail det = data->GetDetail(idDetail);
return det.Containes(id);
}
void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, ptrdiff_t &index)
{
if (idDetail == 0)
{
if (type == Scene::Detail)
{
idDetail = id;
emit ToolTip(tr("Select first point"));
return;
}
}
if (CheckObject(id, idDetail) == false)
{
return;
}
if (type == Scene::Point)
{
if (numberP == 0)
{
p1 = id;
++numberP;
emit ToolTip(tr("Select second point"));
return;
}
if (numberP == 1)
{
if (id == p1)
{
emit ToolTip(tr("Select another second point"));
return;
}
VDetail d = data->GetDetail(idDetail);
if (d.OnEdge(p1, id))
{
p2 = id;
index = d.Edge(p1, p2);
++numberD;
if (numberD > 1)
{
++numberP;
emit ToolTip("");
this->show();
return;
}
else
{
numberP = 0;
p1 = 0;
p2 = 0;
emit ToolTip(tr("Select detail"));
return;
}
}
else
{
emit ToolTip(tr("Select another second point"));
return;
}
}
}
}

View File

@ -0,0 +1,75 @@
/************************************************************************
**
** @file dialoguniondetails.h
** @author Roman Telezhinsky <dismine@gmail.com>
** @date 23 12, 2013
**
** @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) 2013 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 DIALOGUNIONDETAILS_H
#define DIALOGUNIONDETAILS_H
#include "dialogtool.h"
namespace Ui
{
class DialogUnionDetails;
}
class DialogUnionDetails : public DialogTool
{
Q_OBJECT
public:
explicit DialogUnionDetails(const VContainer *data, QWidget *parent = 0);
~DialogUnionDetails();
inline qint64 getD1() const {return d1;}
inline qint64 getD2() const {return d2;}
inline ptrdiff_t getIndexD1() const {return indexD1;}
inline ptrdiff_t getIndexD2() const {return indexD2;}
public slots:
/**
* @brief ChoosedObject gets id and type of selected object. Save correct data and ignore wrong.
* @param id id of point or detail
* @param type type of object
*/
void ChoosedObject(qint64 id, const Scene::Scenes &type);
/**
* @brief DialogAccepted save data and emit signal about closed dialog.
*/
virtual void DialogAccepted();
private:
Q_DISABLE_COPY(DialogUnionDetails)
Ui::DialogUnionDetails *ui;
ptrdiff_t indexD1;
ptrdiff_t indexD2;
qint64 d1;
qint64 d2;
qint32 numberD; // number of detail, what we already have
qint32 numberP; // number of points, what we already have
qint64 p1;
qint64 p2;
bool CheckObject(const qint64 &id, const qint64 &idDetail) const;
void ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, ptrdiff_t &index);
};
#endif // DIALOGUNIONDETAILS_H

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogUnionDetails</class>
<widget class="QDialog" name="DialogUnionDetails">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>473</width>
<height>78</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>120</x>
<y>40</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>451</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Do you really want union details? This operation can't be undone.</string>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogUnionDetails</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DialogUnionDetails</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -4,7 +4,9 @@ HEADERS += \
src/geometry/vspline.h \
src/geometry/vnodedetail.h \
src/geometry/vdetail.h \
src/geometry/varc.h
src/geometry/varc.h \
src/geometry/vgobject.h \
src/geometry/vpointf.h
SOURCES += \
src/geometry/vsplinepoint.cpp \
@ -12,4 +14,6 @@ SOURCES += \
src/geometry/vspline.cpp \
src/geometry/vnodedetail.cpp \
src/geometry/vdetail.cpp \
src/geometry/varc.cpp
src/geometry/varc.cpp \
src/geometry/vgobject.cpp \
src/geometry/vpointf.cpp

View File

@ -27,33 +27,36 @@
*************************************************************************/
#include "varc.h"
#include "vspline.h"
#include "../exception/vexception.h"
class QRectF;
VArc::VArc ()
: f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), formulaRadius(QString()),
center(0), points(QHash<qint64, VPointF>()), idObject(0), _name(QString()){}
VArc::VArc (const QHash<qint64, VPointF> *points, qint64 center, qreal radius, QString formulaRadius,
qreal f1, QString formulaF1, qreal f2, QString formulaF2, qint64 idObject)
: f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), radius(radius), formulaRadius(formulaRadius),
center(center), points(*points), idObject(idObject), _name(QString())
:VGObject(GObject::Arc), f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0),
formulaRadius(QString()), center(VPointF())
{
/**
* @todo Change name of arc in formula. Name now not unique.
*/
_name = QString ("Arc_%1").arg(this->GetCenterVPoint().name());
}
VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2,
QString formulaF2, qint64 idObject, Draw::Draws mode)
: VGObject(GObject::Arc, idObject, mode), f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2),
radius(radius), formulaRadius(formulaRadius), center(center)
{
//TODO Change name of arc in formula. Name now not unique.
_name = QString ("Arc_%1").arg(this->GetCenter().name());
}
VArc::VArc(const VArc &arc)
: f1(arc.GetF1()), formulaF1(arc.GetFormulaF1()), f2(arc.GetF2()),
: VGObject(arc), f1(arc.GetF1()), formulaF1(arc.GetFormulaF1()), f2(arc.GetF2()),
formulaF2(arc.GetFormulaF2()), radius(arc.GetRadius()), formulaRadius(arc.GetFormulaRadius()),
center(arc.GetCenter()), points(arc.GetDataPoints()), idObject(arc.getIdObject()), _name(arc.name()){}
center(arc.GetCenter())
{
}
VArc &VArc::operator =(const VArc &arc)
{
this->points = arc.GetDataPoints();
VGObject::operator=(arc);
this->f1 = arc.GetF1();
this->formulaF1 = arc.GetFormulaF1();
this->f2 = arc.GetF2();
@ -61,55 +64,29 @@ VArc &VArc::operator =(const VArc &arc)
this->radius = arc.GetRadius();
this->formulaRadius = arc.GetFormulaRadius();
this->center = arc.GetCenter();
this->idObject = arc.getIdObject();
this->_name = arc.name();
return *this;
}
QPointF VArc::GetCenterPoint() const
{
return GetCenterVPoint().toQPointF();
}
VPointF VArc::GetCenterVPoint() const
{
if (points.contains(center))
{
return points.value(center);
}
else
{
QString error = QString(tr("Can't find id = %1 in table.")).arg(center);
throw VException(error);
}
return VPointF();
}
QPointF VArc::GetP1() const
{
QPointF p1 ( GetCenterPoint().x () + radius, GetCenterPoint().y () );
QLineF centerP1(GetCenterPoint(), p1);
QPointF p1 ( GetCenter().x () + radius, GetCenter().y () );
QLineF centerP1(GetCenter().toQPointF(), p1);
centerP1.setAngle(f1);
return centerP1.p2();
}
QPointF VArc::GetP2 () const
{
QPointF p2 ( GetCenterPoint().x () + radius, GetCenterPoint().y () );
QLineF centerP2(GetCenterPoint(), p2);
QPointF p2 ( GetCenter().x () + radius, GetCenter().y () );
QLineF centerP2(GetCenter().toQPointF(), p2);
centerP2.setAngle(f2);
return centerP2.p2();
}
const QHash<qint64, VPointF> VArc::GetDataPoints() const
{
return points;
}
QPainterPath VArc::GetPath() const
{
QPainterPath Path;
QPointF center = GetCenterPoint();
QPointF center = GetCenter().toQPointF();
QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2);
Path.moveTo(GetP1());
qreal angle = QLineF(center, GetP1()).angleTo(QLineF(center, GetP2()));

View File

@ -29,18 +29,18 @@
#ifndef VARC_H
#define VARC_H
#include "vspline.h"
#include "vgobject.h"
#include <QCoreApplication>
#include "../options.h"
#include "vpointf.h"
class QString;
class QLineF;
class QPainterPath;
class QPointF;
/**
* @brief VArc клас, що реалізує дугу. Дуга розраховується за годиниковою стрілкою.
*/
class VArc
class VArc: public VGObject
{
Q_DECLARE_TR_FUNCTIONS(VArc)
public:
@ -55,8 +55,8 @@ public:
* @param f1 початковий кут в градусах.
* @param f2 кінцевий кут в градусах.
*/
VArc (const QHash<qint64, VPointF> *points, qint64 center, qreal radius, QString formulaRadius,
qreal f1, QString formulaF1, qreal f2, QString formulaF2, qint64 idObject = 0);
VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2,
QString formulaF2, qint64 idObject = 0, Draw::Draws mode = Draw::Calculation);
/**
* @brief VArc
* @param arc
@ -107,32 +107,17 @@ public:
* @brief GetCenter повертає точку центра дуги.
* @return повертає точку центра дуги.
*/
inline qint64 GetCenter () const {return center;}
/**
* @brief GetCenterPoint
* @return
*/
QPointF GetCenterPoint() const;
/**
* @brief GetCenterVPoint
* @return
*/
VPointF GetCenterVPoint() const;
inline VPointF GetCenter () const {return center;}
/**
* @brief GetP1 повертає першу точку з якої починається дуга.
* @return точку початку дуги.
*/
QPointF GetP1 () const;
QPointF GetP1() const;
/**
* @brief GetP2 повертає другу точку в якій закінчується дуга.
* @return точку кінця дуги.
*/
QPointF GetP2 () const;
/**
* @brief GetDataPoints
* @return
*/
const QHash<qint64, VPointF> GetDataPoints() const;
/**
* @brief GetPath будує шлях по даній дузі.
* @return повертає шлях.
@ -159,26 +144,7 @@ public:
* @return
*/
QVector<QPointF> SplOfArc( qint32 number ) const;
/**
* @brief getIdObject
* @return
*/
inline qint64 getIdObject() const {return idObject;}
/**
* @brief setIdObject
* @param value
*/
inline void setIdObject(const qint64 &value) {idObject = value;}
/**
* @brief name
* @return
*/
QString name() const {return _name;}
/**
* @brief setName
* @param name
*/
void setName(const QString &name) {_name = name;}
virtual QString name() const{return _name;}
private:
/**
* @brief f1 початковий кут в градусах
@ -207,19 +173,7 @@ private:
/**
* @brief center центральна точка дуги.
*/
qint64 center;
/**
* @brief points
*/
QHash<qint64, VPointF> points;
/**
* @brief idObject
*/
qint64 idObject;
/**
* @brief _name
*/
QString _name;
VPointF center;
};
#endif // VARC_H

View File

@ -29,20 +29,23 @@
#include "vdetail.h"
VDetail::VDetail()
:nodes(QVector<VNodeDetail>()), name(QString()), mx(0), my(0), supplement(true), closed(true), width(10){}
:_id(0), nodes(QVector<VNodeDetail>()), name(QString()), mx(0), my(0), supplement(true), closed(true),
width(10){}
VDetail::VDetail(const QString &name, const QVector<VNodeDetail> &nodes)
:nodes(QVector<VNodeDetail>()), name(name), mx(0), my(0), supplement(true), closed(true), width(10)
:_id(0), nodes(QVector<VNodeDetail>()), name(name), mx(0), my(0), supplement(true), closed(true),
width(10)
{
this->nodes = nodes;
}
VDetail::VDetail(const VDetail &detail)
:nodes(detail.getNodes()), name(detail.getName()), mx(detail.getMx()), my(detail.getMy()),
:_id(0), nodes(detail.getNodes()), name(detail.getName()), mx(detail.getMx()), my(detail.getMy()),
supplement(detail.getSupplement()), closed(detail.getClosed()), width(detail.getWidth()){}
VDetail &VDetail::operator =(const VDetail &detail)
{
_id = detail.id();
nodes = detail.getNodes();
name = detail.getName();
mx = detail.getMx();
@ -66,7 +69,7 @@ void VDetail::Clear()
bool VDetail::Containes(const qint64 &id) const
{
for (qint32 i = 0; i < nodes.size(); ++i)
for (ptrdiff_t i = 0; i < nodes.size(); ++i)
{
VNodeDetail node = nodes[i];
if (node.getId() == id)
@ -81,3 +84,102 @@ VNodeDetail &VDetail::operator [](ptrdiff_t indx)
{
return nodes[indx];
}
const VNodeDetail &VDetail::at(ptrdiff_t indx) const
{
return nodes[indx];
}
ptrdiff_t VDetail::indexOfNode(const qint64 &id) const
{
for (ptrdiff_t i = 0; i < nodes.size(); ++i)
{
VNodeDetail node = nodes[i];
if (node.getId() == id)
{
return i;
}
}
return -1;
}
qint64 VDetail::id() const
{
return _id;
}
void VDetail::setId(const qint64 &id)
{
_id = id;
}
bool VDetail::OnEdge(const qint64 &p1, const qint64 &p2) const
{
ptrdiff_t i = indexOfNode(p1);
ptrdiff_t j1 = 0, j2 = 0;
if (i == nodes.size() - 1)
{
j1 = i-1;
j2 = 0;
}
else if (i == 0)
{
j1 = nodes.size() - 1;
j2 = i + 1;
}
else
{
j1 = i - 1;
j2 = i + 1;
}
if (nodes.at(j1).getId() == p2 || nodes.at(j2).getId() == p2)
{
return true;
}
else
{
return false;
}
}
ptrdiff_t VDetail::Edge(const qint64 &p1, const qint64 &p2) const
{
if (OnEdge(p1, p2) == false)
{
qWarning()<<"Points don't on edge.";
return -1;
}
ptrdiff_t i = indexOfNode(p1);
ptrdiff_t j = indexOfNode(p2);
ptrdiff_t min = qMin(i, j);
if (min == 0 && (i == nodes.size() - 1 || j == nodes.size() - 1))
{
return nodes.size() - 1;
}
else
{
return min;
}
}
void VDetail::NodeOnEdge(const ptrdiff_t &index, VNodeDetail &p1, VNodeDetail &p2) const
{
if (index <= 0 || index > nodes.size())
{
qWarning()<<"Wrong edge index";
return;
}
p1 = nodes.at(index);
if (index + 1 > nodes.size() - 1)
{
p2 = nodes.at(0);
}
else
{
p2 = nodes.at(index+1);
}
}

View File

@ -104,6 +104,7 @@ public:
* @return
*/
VNodeDetail & operator[](ptrdiff_t indx);
const VNodeDetail & at ( ptrdiff_t indx ) const;
/**
* @brief getName
* @return
@ -174,7 +175,14 @@ public:
* @param value
*/
inline void setNodes(const QVector<VNodeDetail> &value) {nodes = value;}
ptrdiff_t indexOfNode(const qint64 &id) const;
qint64 id() const;
void setId(const qint64 &id);
bool OnEdge(const qint64 &p1, const qint64 &p2)const;
ptrdiff_t Edge(const qint64 &p1, const qint64 &p2)const;
void NodeOnEdge(const ptrdiff_t &index, VNodeDetail &p1, VNodeDetail &p2)const;
private:
qint64 _id;
/**
* @brief nodes
*/

99
src/geometry/vgobject.cpp Normal file
View File

@ -0,0 +1,99 @@
/************************************************************************
**
** @file vgobject.cpp
** @author Roman Telezhinsky <dismine@gmail.com>
** @date 27 12, 2013
**
** @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) 2013 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 "vgobject.h"
VGObject::VGObject()
:_id(0), type(GObject::Point), idObject(0), _name(QString()), mode(Draw::Calculation)
{
}
VGObject::VGObject(const GObject::Type &type, const qint64 &idObject, const Draw::Draws &mode)
:_id(0), type(type), idObject(idObject), _name(QString()), mode(mode)
{
}
VGObject::VGObject(const VGObject &obj)
:_id(obj.id()), type(obj.getType()), idObject(obj.getIdObject()), _name(obj.name()), mode(obj.getMode())
{
}
VGObject &VGObject::operator=(const VGObject &obj)
{
this->_id = obj.id();
this->type = obj.getType();
this->idObject = obj.getIdObject();
this->_name = obj.name();
this->mode = obj.getMode();
return *this;
}
qint64 VGObject::getIdObject() const
{
return idObject;
}
void VGObject::setIdObject(const qint64 &value)
{
idObject = value;
}
QString VGObject::name() const
{
return _name;
}
void VGObject::setName(const QString &name)
{
_name = name;
}
Draw::Draws VGObject::getMode() const
{
return mode;
}
void VGObject::setMode(const Draw::Draws &value)
{
mode = value;
}
GObject::Type VGObject::getType() const
{
return type;
}
qint64 VGObject::id() const
{
return _id;
}
void VGObject::setId(const qint64 &id)
{
_id = id;
}

88
src/geometry/vgobject.h Normal file
View File

@ -0,0 +1,88 @@
/************************************************************************
**
** @file vgobject.h
** @author Roman Telezhinsky <dismine@gmail.com>
** @date 27 12, 2013
**
** @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) 2013 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 VGOBJECT_H
#define VGOBJECT_H
#include "../options.h"
#include "../exception/vexception.h"
#include <QCoreApplication>
#include <QHash>
namespace GObject
{
/**
* @brief The NodeDetail enum
*/
enum Type { Point, Arc, Spline, SplinePath };
Q_DECLARE_FLAGS(Types, Type)
}
Q_DECLARE_OPERATORS_FOR_FLAGS(GObject::Types)
class VGObject
{
public:
VGObject();
VGObject(const GObject::Type &type, const qint64 &idObject = 0, const Draw::Draws &mode = Draw::Calculation);
VGObject(const VGObject &obj);
VGObject& operator= (const VGObject &obj);
virtual ~VGObject(){}
qint64 getIdObject() const;
void setIdObject(const qint64 &value);
virtual QString name() const;
void setName(const QString &name);
Draw::Draws getMode() const;
void setMode(const Draw::Draws &value);
GObject::Type getType() const;
qint64 id() const;
void setId(const qint64 &id);
protected:
/**
* @brief _id id in container. Ned for arcs, spline and spline paths.
*/
qint64 _id;
/**
* @brief type type of graphical object
*/
GObject::Type type;
/**
* @brief idObject id of parent object. Only for modeling. All another return 0.
*/
qint64 idObject;
/**
* @brief _name object name
*/
QString _name;
/**
* @brief mode object created in calculation or drawing mode
*/
Draw::Draws mode;
};
#endif // VGOBJECT_H

View File

@ -28,13 +28,18 @@
#include "vpointf.h"
VPointF::VPointF(qreal x, qreal y, QString name, qreal mx, qreal my, qint64 idObject, Draw::Draws mode)
:VGObject(GObject::Point, idObject, mode), _mx(mx), _my(my), _x(x), _y(y)
{
this->_name = name;
}
VPointF &VPointF::operator =(const VPointF &point)
{
_name = point.name();
VGObject::operator=(point);
_mx = point.mx();
_my = point.my();
_x = point.x();
_y = point.y();
idObject = point.getIdObject();
return *this;
}

View File

@ -32,36 +32,36 @@
#include <QPointF>
#include <QString>
#include "../options.h"
#include "vgobject.h"
/**
* @brief The VPointF class keep data of point.
*/
class VPointF
class VPointF:public VGObject
{
public:
/**
* @brief VPointF creat empty point
*/
inline VPointF ()
:_name(QString()), _mx(0), _my(0), _x(0), _y(0), idObject(0){}
:VGObject(GObject::Point, 0, Draw::Calculation), _mx(0), _my(0), _x(0), _y(0){}
/**
* @brief VPointF copy constructor
* @param point
*/
inline VPointF (const VPointF &point )
:_name(point.name()), _mx(point.mx()), _my(point.my()), _x(point.x()), _y(point.y()),
idObject(point.getIdObject()){}
:VGObject(point), _mx(point.mx()), _my(point.my()), _x(point.x()), _y(point.y()){}
inline VPointF (const QPointF &point )
:VGObject(VPointF()), _mx(0), _my(0), _x(point.x()), _y(point.y()){}
/**
* @brief VPointF create new point
* @param x x coordinate
* @param y y coordinate
* @param name name of point
* @param mx offset name respect to x
* @param my offset name respect to y
* @param idObject point modeling keep here id of parent point
*/
inline VPointF ( qreal x, qreal y, QString name, qreal mx, qreal my, qint64 idObject = 0)
:_name(name), _mx(mx), _my(my), _x(x), _y(y), idObject(idObject){}
VPointF ( qreal x, qreal y, QString name, qreal mx, qreal my, qint64 idObject = 0,
Draw::Draws mode = Draw::Calculation);
/**
* @brief operator = assignment operator
* @param point point
@ -69,11 +69,6 @@ public:
*/
VPointF &operator=(const VPointF &point);
~VPointF(){}
/**
* @brief name return name of point
* @return name
*/
inline QString name() const { return _name;}
/**
* @brief mx return offset name respect to x
* @return offset
@ -84,11 +79,6 @@ public:
* @return offset
*/
inline qreal my() const {return _my;}
/**
* @brief setName set name of point
* @param name name
*/
inline void setName(const QString &name) {_name = name;}
/**
* @brief setMx set offset name respect to x
* @param mx offset
@ -124,21 +114,8 @@ public:
* @param value y coordinate
*/
inline void setY(const qreal &value){_y = value;}
/**
* @brief getIdObject return id of parrent.
* @return id
*/
inline qint64 getIdObject() const {return idObject;}
/**
* @brief setIdObject set id of parent
* @param value id
*/
inline void setIdObject(const qint64 &value) {idObject = value;}
virtual QString name() const{return _name;}
private:
/**
* @brief _name name of point
*/
QString _name;
/**
* @brief _mx offset name respect to x
*/
@ -155,10 +132,6 @@ private:
* @brief _y y coordinate
*/
qreal _y;
/**
* @brief idObject id of parent. Only for point modeling. All another return 0.
*/
qint64 idObject;
};
#endif // VPOINTF_H

View File

@ -31,34 +31,21 @@
#include <QDebug>
VSpline::VSpline()
:p1(0), p2(QPointF()), p3(QPointF()), p4(0), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1),
points(QHash<qint64, VPointF>()), idObject(0), _name(QString()){}
:VGObject(GObject::Spline), p1(VPointF()), p2(QPointF()), p3(QPointF()), p4(VPointF()), angle1(0), angle2(0),
kAsm1(1), kAsm2(1), kCurve(1){}
VSpline::VSpline ( const VSpline & spline )
:p1(spline.GetP1 ()), p2(spline.GetP2 ()), p3(spline.GetP3 ()), p4(spline.GetP4 ()), angle1(spline.GetAngle1 ()),
angle2(spline.GetAngle2 ()), kAsm1(spline.GetKasm1()), kAsm2(spline.GetKasm2()), kCurve(spline.GetKcurve()),
points(spline.GetDataPoints()), idObject(spline.getIdObject()), _name(spline.name()){}
:VGObject(spline), p1(spline.GetP1 ()), p2(spline.GetP2 ()), p3(spline.GetP3 ()), p4(spline.GetP4 ()),
angle1(spline.GetAngle1 ()), angle2(spline.GetAngle2 ()), kAsm1(spline.GetKasm1()), kAsm2(spline.GetKasm2()),
kCurve(spline.GetKcurve()){}
VSpline::VSpline (const QHash<qint64, VPointF> *points, qint64 p1, qint64 p4, qreal angle1, qreal angle2,
qreal kAsm1, qreal kAsm2, qreal kCurve, qint64 idObject)
:p1(p1), p2(QPointF()), p3(QPointF()), p4(p4), angle1(angle1), angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2),
kCurve(kCurve), points(*points), idObject(idObject), _name(QString())
VSpline::VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve,
qint64 idObject, Draw::Draws mode)
:VGObject(GObject::Spline, idObject, mode), p1(p1), p2(QPointF()), p3(QPointF()), p4(p4), angle1(angle1),
angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2), kCurve(kCurve)
{
_name = QString("Spl_%1_%2").arg(this->GetPointP1().name(), this->GetPointP4().name());
ModifiSpl ( p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve );
}
CreateName();
VSpline::VSpline (const QHash<qint64, VPointF> *points, qint64 p1, QPointF p2, QPointF p3, qint64 p4,
qreal kCurve, qint64 idObject)
:p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1), points(*points),
idObject(idObject), _name(QString())
{
_name = QString("Spl_%1_%2").arg(this->GetPointP1().name(), this->GetPointP4().name());
ModifiSpl ( p1, p2, p3, p4, kCurve);
}
void VSpline::ModifiSpl ( qint64 p1, qint64 p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve)
{
this->p1 = p1;
this->p4 = p4;
this->angle1 = angle1;
@ -66,130 +53,80 @@ void VSpline::ModifiSpl ( qint64 p1, qint64 p4, qreal angle1, qreal angle2, qrea
this->kAsm1 = kAsm1;
this->kAsm2 = kAsm2;
this->kCurve = kCurve;
QLineF p1pX(GetPointP1().x(), GetPointP1().y(), GetPointP1().x() + 100, GetPointP1().y());
QLineF p1pX(GetP1().x(), GetP1().y(), GetP1().x() + 100, GetP1().y());
p1pX.setAngle( angle1 );
qreal L = 0, radius = 0, angle = 90;
// angle = QLineF(GetPointP1(), p1pX.p2()).angleTo(QLineF(GetPointP1(), GetPointP4()));
// if ( angle > 180 ){
// angle = 360 - angle;
// }
QPointF point1 = GetPointP1().toQPointF();
QPointF point4 = GetPointP4().toQPointF();
QPointF point1 = GetP1().toQPointF();
QPointF point4 = GetP4().toQPointF();
radius = QLineF(QPointF(point1.x(), point4.y()), point4).length();
// radius = QLineF(GetPointP1(), GetPointP4()).length() / 2 / sin( angle * M_PI / 180.0 );
L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 );
QLineF p1p2(GetPointP1().x(), GetPointP1().y(), GetPointP1().x() + L * kAsm1, GetPointP1().y());
QLineF p1p2(GetP1().x(), GetP1().y(), GetP1().x() + L * kAsm1, GetP1().y());
p1p2.setAngle(angle1);
QLineF p4p3(GetPointP4().x(), GetPointP4().y(), GetPointP4().x() + L * kAsm2, GetPointP4().y());
QLineF p4p3(GetP4().x(), GetP4().y(), GetP4().x() + L * kAsm2, GetP4().y());
p4p3.setAngle(angle2);
this->p2 = p1p2.p2();
this->p3 = p4p3.p2();
}
void VSpline::ModifiSpl (const qint64 &p1, const QPointF &p2, const QPointF &p3, const qint64 &p4, const qreal &kCurve)
VSpline::VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve, qint64 idObject, Draw::Draws mode)
:VGObject(GObject::Spline, idObject, mode), p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), angle2(0), kAsm1(1),
kAsm2(1), kCurve(1)
{
CreateName();
this->p1 = p1;
this->p2 = p2;
this->p3 = p3;
this->p4 = p4;
this->angle1 = QLineF ( GetPointP1().toQPointF(), p2 ).angle();
this->angle2 = QLineF ( GetPointP4().toQPointF(), p3 ).angle();
this->angle1 = QLineF ( GetP1().toQPointF(), p2 ).angle();
this->angle2 = QLineF ( GetP4().toQPointF(), p3 ).angle();
QLineF p1pX(GetPointP1().x(), GetPointP1().y(), GetPointP1().x() + 100, GetPointP1().y());
QLineF p1pX(GetP1().x(), GetP1().y(), GetP1().x() + 100, GetP1().y());
p1pX.setAngle( angle1 );
qreal L = 0, radius = 0, angle = 90;
// angle = QLineF(GetPointP1(), p1pX.p2()).angleTo(QLineF(GetPointP1(), GetPointP4()));
// if ( angle >= 180 ){
// angle = 360 - angle;
// }
QPointF point1 = GetPointP1().toQPointF();
QPointF point4 = GetPointP4().toQPointF();
QPointF point1 = GetP1().toQPointF();
QPointF point4 = GetP4().toQPointF();
radius = QLineF(QPointF(point1.x(), point4.y()), point4).length();
// radius = QLineF(GetPointP1(), GetPointP4()).length() / 2 / sin( angle * M_PI / 180.0 );
L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 );
this->kCurve = kCurve;
this->kAsm1 = QLineF ( GetPointP1().toQPointF(), p2 ).length()/L;
this->kAsm2 = QLineF ( GetPointP4().toQPointF(), p3 ).length()/L;
}
//void VSpline::RotationSpl (QPointF pRotate, qreal angle ){
// QLineF pRotateP1 (pRotate, p1);
// pRotateP1.setAngle(angle);
// p1 = pRotateP1.p2();
// QLineF pRotateP2 (pRotate, p2);
// pRotateP2.setAngle(angle);
// p2 = pRotateP2.p2();
// QLineF pRotateP3 (pRotate, p3);
// pRotateP3.setAngle(angle);
// p3 = pRotateP3.p2();
// QLineF pRotateP4 (pRotate, p4);
// pRotateP4.setAngle(angle);
// p4 = pRotateP4.p2();
// angle1 = QLineF(p1, p2).angle();
// angle2 = QLineF(p4, p2).angle();
//}
//void VSpline::BiasSpl ( qreal mx, qreal my ){
// p1 = QPointF(p1.x()+mx, p1.y()+my);
// p2 = QPointF(p2.x()+mx, p2.y()+my);
// p3 = QPointF(p3.x()+mx, p3.y()+my);
// p4 = QPointF(p4.x()+mx, p4.y()+my);
//}
VPointF VSpline::GetPointP1() const
{
if (points.contains(p1))
{
return points.value(p1);
}
else
{
qCritical()<<"Не можу знайти id = "<<p1<<" в таблиці.";
throw "Не можу знайти точку за id.";
}
return VPointF();
}
VPointF VSpline::GetPointP4() const
{
if (points.contains(p4))
{
return points.value(p4);
}
else
{
qCritical()<<"Не можу знайти id = "<<p4<<" в таблиці.";
throw "Не можу знайти точку за id.";
}
return VPointF();
this->kAsm1 = QLineF ( GetP1().toQPointF(), p2 ).length()/L;
this->kAsm2 = QLineF ( GetP4().toQPointF(), p3 ).length()/L;
}
qreal VSpline::GetLength () const
{
return LengthBezier ( GetPointP1().toQPointF(), this->p2, this->p3, GetPointP4().toQPointF());
return LengthBezier ( GetP1().toQPointF(), this->p2, this->p3, GetP4().toQPointF());
}
QString VSpline::GetName() const
QString VSpline::name() const
{
VPointF first = GetPointP1();
VPointF second = GetPointP4();
return QString("Spl_%1_%2").arg(first.name(), second.name());
return _name;
}
QLineF::IntersectType VSpline::CrossingSplLine ( const QLineF &line, QPointF *intersectionPoint ) const
{
QVector<qreal> px;
QVector<qreal> py;
px.append ( GetPointP1 ().x () );
py.append ( GetPointP1 ().y () );
px.append ( GetP1 ().x () );
py.append ( GetP1 ().y () );
QVector<qreal>& wpx = px;
QVector<qreal>& wpy = py;
PointBezier_r ( GetPointP1 ().x (), GetPointP1 ().y (), GetP2 ().x (), GetP2 ().y (),
GetP3 ().x (), GetP3 ().y (), GetPointP4 ().x (), GetPointP4 ().y (),
PointBezier_r ( GetP1 ().x (), GetP1 ().y (), GetP2 ().x (), GetP2 ().y (),
GetP3 ().x (), GetP3 ().y (), GetP4 ().x (), GetP4 ().y (),
0, wpx, wpy);
px.append ( GetPointP4 ().x () );
py.append ( GetPointP4 ().y () );
px.append ( GetP4 ().x () );
py.append ( GetP4 ().y () );
qint32 i = 0;
QPointF crosPoint;
QLineF::IntersectType type = QLineF::NoIntersection;
@ -208,12 +145,12 @@ QLineF::IntersectType VSpline::CrossingSplLine ( const QLineF &line, QPointF *in
qreal VSpline::LengthT(qreal t) const
{
if(t < 0 || t > 1)
if (t < 0 || t > 1)
{
qWarning()<<"Wrong value t.";
return 0;
}
QLineF seg1_2 ( GetPointP1 ().toQPointF(), GetP2 () );
QLineF seg1_2 ( GetP1 ().toQPointF(), GetP2 () );
seg1_2.setLength(seg1_2.length () * t);
QPointF p12 = seg1_2.p2();
@ -225,7 +162,7 @@ qreal VSpline::LengthT(qreal t) const
seg12_23.setLength(seg12_23.length () * t);
QPointF p123 = seg12_23.p2();
QLineF seg3_4 ( GetP3 (), GetPointP4 ().toQPointF() );
QLineF seg3_4 ( GetP3 (), GetP4 ().toQPointF() );
seg3_4.setLength(seg3_4.length () * t);
QPointF p34 = seg3_4.p2();
@ -237,13 +174,13 @@ qreal VSpline::LengthT(qreal t) const
seg123_234.setLength(seg123_234.length () * t);
QPointF p1234 = seg123_234.p2();
return LengthBezier ( GetPointP1().toQPointF(), p12, p123, p1234);
return LengthBezier ( GetP1().toQPointF(), p12, p123, p1234);
}
QPointF VSpline::CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3 ) const
{
//Always need return two splines, so we must correct wrong length.
if(length < GetLength()*0.02)
if (length < GetLength()*0.02)
{
length = GetLength()*0.02;
}
@ -262,12 +199,13 @@ QPointF VSpline::CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPo
{
parT = parT + step;
qreal splLength = LengthT(parT);
if(splLength >= length || parT > 1){
if (splLength >= length || parT > 1)
{
break;
}
}
QLineF seg1_2 ( GetPointP1 ().toQPointF(), GetP2 () );
QLineF seg1_2 ( GetP1 ().toQPointF(), GetP2 () );
seg1_2.setLength(seg1_2.length () * parT);
QPointF p12 = seg1_2.p2();
@ -279,7 +217,7 @@ QPointF VSpline::CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPo
seg12_23.setLength(seg12_23.length () * parT);
QPointF p123 = seg12_23.p2();
QLineF seg3_4 ( GetP3 (), GetPointP4 ().toQPointF() );
QLineF seg3_4 ( GetP3 (), GetP4 ().toQPointF() );
seg3_4.setLength(seg3_4.length () * parT);
QPointF p34 = seg3_4.p2();
@ -298,59 +236,9 @@ QPointF VSpline::CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPo
return p1234;
}
//void VSpline::CutSpline ( QPointF point, VSpline* curFir, VSpline* curSec ) const{
// qreal t = param_t (point);
// qreal length = t*this->GetLength();
// CutSpline ( length, curFir, curSec );
//}
//void VSpline::PutAlongSpl (QPointF &moveP, qreal move ) const{
// if ( GetLength () < move ){
// qDebug()<<"Довжина більше довжини сплайну.";
// qDebug()<<GetLength()<<"<"<<move;
// throw "Довжина більше довжини сплайну.";
// }
// if ( move <= 0 ){
// qDebug()<<"Довжина менше дорівнює нулю.";
// throw "Довжина менше дорівнює нулю.";
// }
// qreal t = 0;
// if ( move == 0 ){
// t = 0;
// } else {
// t = move / GetLength ();
// moveP.setX ( pow ( 1 - t, 3 ) * GetPointP1 ().x () + 3 * t * pow ( 1 - t, 2 ) *
// GetP2 ().x () + 3 * t * t * ( 1 - t ) * GetP3 ().x () +
// pow ( t, 3 ) * GetPointP4 ().x () );
// moveP.setY ( pow ( 1 - t, 3 ) * GetPointP1 ().y () + 3 * t * pow ( 1 - t, 2 ) *
// GetP2 ().y () + 3 * t * t * ( 1 - t ) * GetP3 ().y () +
// pow ( t, 3 ) * GetPointP4 ().y () );
// }
//}
QVector<QPointF> VSpline::GetPoints () const
{
return GetPoints(GetPointP1().toQPointF(), p2, p3, GetPointP4().toQPointF());
// QLineF line1(points.at(0).toPoint(), points.at(1).toPoint());
// line1.setLength(500);
// QLineF line2 = line1;
// line2.setAngle(line2.angle()+90);
// qreal xk1 = line1.p2().x();
// qreal xk0 = line1.p1().x();
// qreal y = line2.p2().y();
// qreal yk0 = line1.p1().y();
// qreal yk1 = line1.p2().y();
// qreal x = line2.p2().x();
// qreal check = (xk1 - xk0) * (y - yk0) - (yk1 - yk0) * (x - xk0);
// if(check > 0){
// return points;
// } else {
// QVector<QPointF> reversePoints;
// for (qint32 i = points.size() - 1; i >= 0; --i) {
// reversePoints.append(points.at(i));
// }
// return reversePoints;
// }
return GetPoints(GetP1().toQPointF(), p2, p3, GetP4().toQPointF());
}
QVector<QPointF> VSpline::GetPoints (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
@ -681,6 +569,11 @@ qreal VSpline::CalcSqDistance (qreal x1, qreal y1, qreal x2, qreal y2)
return dx * dx + dy * dy;
}
void VSpline::CreateName()
{
_name = QString("Spl_%1_%2").arg(this->GetP1().name(), this->GetP4().name());
}
QPainterPath VSpline::GetPath() const
{
QPainterPath splinePath;
@ -700,130 +593,6 @@ QPainterPath VSpline::GetPath() const
return splinePath;
}
/* Cubic equation solution. Real coefficients case.
int Cubic(double *x,double a,double b,double c);
Parameters:
x - solution array (size 3). On output:
3 real roots -> then x is filled with them;
1 real + 2 complex -> x[0] is real, x[1] is real part of
complex roots, x[2] - non-negative
imaginary part.
a, b, c - coefficients, as described
Returns: 3 - 3 real roots;
1 - 1 real root + 2 complex;
2 - 1 real root + complex roots imaginary part is zero
(i.e. 2 real roots).
*/
//qint32 VSpline::Cubic(qreal *x, qreal a, qreal b, qreal c){
// qreal q,r,r2,q3;
//
// q = (a*a - 3.*b)/9.;
// r = (a*(2.*a*a - 9.*b) + 27.*c)/54.;
// r2 = r*r;
// q3 = pow(q,3);
// if(r2<q3) {
// qreal t = acos(r/sqrt(q3));
// a/=3.;
// q = -2.*sqrt(q);
// x[0] = q*cos(t/3.)-a;
// x[1] = q*cos((t + M_2PI)/3.) - a;
// x[2] = q*cos((t - M_2PI)/3.) - a;
// return(3);
// } else {
// qreal aa,bb;
// if(r<=0.){
// r=-r;
// }
// aa = -pow(r + sqrt(r2-q3),1./3.);
// if(aa!=0.){
// bb=q/aa;
// } else {
// bb=0.;
// }
// a/=3.;
// q = aa+bb;
// r = aa-bb;
// x[0] = q-a;
// x[1] = (-0.5)*q-a;
// x[2] = (sqrt(3.)*0.5)*fabs(r);
// if(x[2]==0.){
// return(2);
// }
// return(1);
// }
//}
//
//qreal VSpline::calc_t (qreal curve_coord1, qreal curve_coord2, qreal curve_coord3,
// qreal curve_coord4, qreal point_coord) const{
// qreal P1, P2, P3, P4, Bt;
// qreal a, b, c, d, ret_t;
//
// qreal *t = static_cast<qreal *>(malloc(3*sizeof(qreal)));
// P1 = curve_coord1;
// P2 = curve_coord2;
// P3 = curve_coord3;
// P4 = curve_coord4;
// Bt = point_coord;
//
// a = -P1 + 3*P2 - 3*P3 + P4;
// b = 3*P1 - 6*P2 + 3*P3;
// c = -3*P1 + 3*P2;
// d = -Bt + P1;
//
// if(Cubic(t, b/a, c/a, d/a) == 3){
// ret_t = t[2];
// } else {
// ret_t = t[0];
// }
// /*
// * Повертається три значення, але експереминтально знайдено що шукане
// * значення знаходиться в третьому.
// */
//
// free(t);
// if(ret_t<0 || ret_t>1){
// qDebug()<<"Неправильне значення параметра. фунція calc_t";
// throw"Неправильне значення параметра. фунція calc_t";
// }
// return ret_t;
//}
/*
* Функція знаходить підходяще значення параметна t якому відповідає точка на сплайні.
*/
//qreal VSpline::param_t (QPointF pBt)const{
// qreal t_x, t_y;
// t_x = calc_t (GetPointP1().x(), p2.x(), p3.x(), GetPointP4().x(), pBt.x());
// t_y = calc_t (GetPointP1().y(), p2.y(), p3.y(), GetPointP4().y(), pBt.y());
// /*
// * Порівнюємо значення по х і по у і визначаємо найбільше. Це значення і
// * буде шуканим.
// */
// if(t_x>t_y)
// return t_x;
// else
// return t_y;
//}
//
//void VSpline::Mirror(const QPointF Pmirror){
// QPointF P1 = p1;
// P1 = QPointF(P1.x() - Pmirror.x(), P1.y() - Pmirror.y());
// P1 = QPointF(P1.x() * -1.0, P1.y() * 1.0);
// P1 = QPointF(P1.x() + Pmirror.x(), P1.y() + Pmirror.y());
// QPointF P2 = p2;
// P2 = QPointF(P2.x() - Pmirror.x(), P2.y() - Pmirror.y());
// P2 = QPointF(P2.x() * -1.0, P2.y() * 1.0);
// P2 = QPointF(P2.x() + Pmirror.x(), P2.y() + Pmirror.y());
// QPointF P3 = p3;
// P3 = QPointF(P3.x() - Pmirror.x(), P3.y() - Pmirror.y());
// P3 = QPointF(P3.x() * -1.0, P3.y() * 1.0);
// P3 = QPointF(P3.x() + Pmirror.x(), P3.y() + Pmirror.y());
// QPointF P4 = p4;
// P4 = QPointF(P4.x() - Pmirror.x(), P4.y() - Pmirror.y());
// P4 = QPointF(P4.x() * -1.0, P4.y() * 1.0);
// P4 = QPointF(P4.x() + Pmirror.x(), P4.y() + Pmirror.y());
// this->ModifiSpl(P1, P2, P3, P4);
//}
QVector<QPointF> VSpline::SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1,
qreal kAsm2, qreal kCurve)
{
@ -843,6 +612,7 @@ QVector<QPointF> VSpline::SplinePoints(const QPointF &p1, const QPointF &p4, qre
VSpline &VSpline::operator =(const VSpline &spline)
{
VGObject::operator=(spline);
this->p1 = spline.GetP1 ();
this->p2 = spline.GetP2 ();
this->p3 = spline.GetP3 ();
@ -852,8 +622,5 @@ VSpline &VSpline::operator =(const VSpline &spline)
this->kAsm1 = spline.GetKasm1();
this->kAsm2 = spline.GetKasm2();
this->kCurve = spline.GetKcurve();
this->points = spline.GetDataPoints();
this->idObject = spline.getIdObject();
this->_name = spline.name();
return *this;
}

View File

@ -29,7 +29,8 @@
#ifndef VSPLINE_H
#define VSPLINE_H
#include "../container/vpointf.h"
#include "vpointf.h"
#include "vgobject.h"
#include <QHash>
#include <QLineF>
@ -42,7 +43,7 @@ class QString;
/**
* @brief VSpline class that implements the spline.
*/
class VSpline
class VSpline :public VGObject
{
public:
/**
@ -64,8 +65,8 @@ public:
* @param kAsm1 коефіцієнт довжини першої напрямної.
* @param kAsm2 коефіцієнт довжини другої напрямної.
*/
VSpline (const QHash<qint64, VPointF> *points, qint64 p1, qint64 p4, qreal angle1, qreal angle2, qreal kAsm1,
qreal kAsm2, qreal kCurve, qint64 idObject = 0);
VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve,
qint64 idObject = 0, Draw::Draws mode = Draw::Calculation);
/**
* @brief VSpline конструктор.
* @param p1 початкова точка сплайну.
@ -73,51 +74,13 @@ public:
* @param p3 друга контролююча точка сплайну.
* @param p4 кінцева точка сплайну.
*/
VSpline (const QHash<qint64, VPointF> *points, qint64 p1, QPointF p2, QPointF p3, qint64 p4,
qreal kCurve, qint64 idObject = 0);
/**
* @brief ModifiSpl модифікує сплайн.
* @param p1 початкова точка сплайну.
* @param p4 кінцева точка сплайну.
* @param angle1 кут в градусах першої напрямної.
* @param angle2 кут в градусах другої напрямної.
* @param kCurve коефіцієнт кривизни сплайну.
* @param kAsm1 коефіцієнт довжини першої напрямної.
* @param kAsm2 коефіцієнт довжини другої напрямної.
*/
void ModifiSpl ( qint64 p1, qint64 p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2,
qreal kCurve);
/**
* @brief ModifiSpl модифікує сплайн.
* @param p1 початкова точка сплайну.
* @param p2 перша контролююча точка сплайну.
* @param p3 друга контролююча точка сплайну.
* @param p4 кінцева точка сплайну.
*/
void ModifiSpl (const qint64 &p1, const QPointF &p2, const QPointF &p3, const qint64 &p4,
const qreal &kCurve);
// /**
// * @brief RotationSpl поворот сплайна навколо точки на кут в градусах проти годиникової стрілки.
// * @param pRotate точка навколо якої повертаємо.
// * @param angle кут в градусах.
// */
// void RotationSpl ( QPointF pRotate, qreal angle );
// /**
// * @brief BiasSpl зміщує сплайн.
// * @param mx зміщення по х координаті.
// * @param my зміщення по у координаті.
// */
// void BiasSpl ( qreal mx, qreal my );
VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve, qint64 idObject = 0,
Draw::Draws mode = Draw::Calculation);
/**
* @brief GetP1 повертає першу точку сплайну.
* @return перша точка сплайну.
*/
qint64 GetP1 () const {return p1;}
/**
* @brief GetPointP1
* @return
*/
VPointF GetPointP1() const;
VPointF GetP1 () const {return p1;}
/**
* @brief GetP2 повертує першу контрольну точку сплайну.
* @return перша контрольна точка сплайну.
@ -132,12 +95,7 @@ public:
* @brief GetP4 повертає останню точку сплайну.
* @return остання точка сплайну.
*/
inline qint64 GetP4 () const {return p4;}
/**
* @brief GetPointP4
* @return
*/
VPointF GetPointP4 () const;
inline VPointF GetP4 () const {return p4;}
/**
* @brief GetAngle1 повертає кут першої напрямної.
* @return кут в градусах.
@ -154,10 +112,10 @@ public:
*/
qreal GetLength () const;
/**
* @brief GetName
* @brief name
* @return
*/
QString GetName () const;
QString name () const;
/**
* @brief GetKasm1
* @return
@ -173,11 +131,6 @@ public:
* @return
*/
inline qreal GetKcurve() const {return kCurve;}
/**
* @brief GetDataPoints
* @return
*/
inline const QHash<qint64, VPointF> GetDataPoints() const {return points;}
/**
* @brief CrossingSplLine перевіряє перетин сплайну з лінією.
* @param line лінія з якою перевіряється перетин.
@ -197,19 +150,6 @@ public:
* @return point of cutting. This point is forth point of first spline and first point of second spline.
*/
QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const;
/**
* @brief CutSpline розрізає сплайн.
* @param point точка що ділить сплайн.
* @param curFir перший сплайн.
* @param curSec другий сплайн.
*/
// void CutSpline (QPointF point, VSpline* curFir, VSpline* curSec ) const;
/**
* @brief PutAlongSpl розміщає точку на сплайні.
* @param moveP точка яка розміщується на сплайні.
* @param move довжина від початку сплайну.
*/
// void PutAlongSpl ( QPointF &moveP, qreal move ) const;
/**
* @brief GetPoints повертає точки з яких складається сплайн.
* @return список точок.
@ -220,11 +160,6 @@ public:
* @return шлях.
*/
QPainterPath GetPath() const;
/**
* @brief Mirror вертикальне дзеркалення сплайну відносно точки.
* @param Pmirror точка відносно якої відбувається вертикальне дзеркалення сплайну.
*/
// void Mirror(const QPointF Pmirror);
/**
* @brief SplinePoints
* @param p1
@ -238,32 +173,12 @@ public:
*/
static QVector<QPointF> SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1,
qreal kAsm2, qreal kCurve);
/**
* @brief getIdObject
* @return
*/
inline qint64 getIdObject() const {return idObject;}
/**
* @brief setIdObject
* @param value
*/
inline void setIdObject(const qint64 &value) {idObject = value;}
/**
* @brief operator =
* @param spl
* @return
*/
VSpline &operator=(const VSpline &spl);
/**
* @brief name
* @return
*/
QString name() const {return _name;}
/**
* @brief setName
* @param name
*/
void setName(const QString &name) {_name = name;}
protected:
/**
* @brief GetPoints повертає точки з яких складається сплайн.
@ -278,7 +193,7 @@ private:
/**
* @brief p1 початкова точка сплайну
*/
qint64 p1; // перша точка
VPointF p1; // перша точка
/**
* @brief p2 перша контрольна точка сплайну.
*/
@ -290,7 +205,7 @@ private:
/**
* @brief p4 кінцеві точка сплайну.
*/
qint64 p4; // четверта точка
VPointF p4; // четверта точка
/**
* @brief angle1 кут в градусах першої напрямної.
*/
@ -311,18 +226,6 @@ private:
* @brief kCurve
*/
qreal kCurve;
/**
* @brief points
*/
QHash<qint64, VPointF> points;
/**
* @brief idObject
*/
qint64 idObject;
/**
* @brief _name
*/
QString _name;
/**
* @brief LengthBezier повертає дожину сплайну за його чотирьма точками.
* @param p1 початкова точка сплайну.
@ -357,32 +260,7 @@ private:
* @return довжину.
*/
static qreal CalcSqDistance ( qreal x1, qreal y1, qreal x2, qreal y2);
// /**
// * @brief Cubic знаходить розв'язок кубічного рівняння.
// * @param x коефіцієнт.
// * @param a коефіцієнт.
// * @param b коефіцієнт.
// * @param c коефіцієнт.
// * @return повертає корені рівняння.
// */
// static qint32 Cubic(qreal *x, qreal a, qreal b, qreal c);
/**
* @brief calc_t знаходить параметр t якому відповідає точка на сплайні.
* @param curve_coord1 координата Х або У кривої.
* @param curve_coord2 координата Х або У кривої.
* @param curve_coord3 координата Х або У кривої.
* @param curve_coord4 координата Х або У кривої.
* @param point_coord координата Х або У точки на кривій.
* @return
*/
// static qreal calc_t (qreal curve_coord1, qreal curve_coord2, qreal curve_coord3, qreal curve_coord4,
// qreal point_coord)const;
/**
* @brief param_t знаходить підходяще значення параметра t якому відповідає точка на сплайні
* @param pBt точка для якої шукається значення параметра t.
* @return підходяще значення t.
*/
// qreal param_t (QPointF pBt)const;
void CreateName();
};
#endif // VSPLINE_H

View File

@ -29,16 +29,15 @@
#include "vsplinepath.h"
#include "../exception/vexception.h"
VSplinePath::VSplinePath()
: path(QVector<VSplinePoint>()), kCurve(1), points(QHash<qint64, VPointF>()), idObject(0), _name(QString()){}
VSplinePath::VSplinePath(const QHash<qint64, VPointF> *points, qreal kCurve, qint64 idObject)
: path(QVector<VSplinePoint>()), kCurve(kCurve), points(*points), idObject(idObject), _name(QString())
{}
VSplinePath::VSplinePath(qreal kCurve, qint64 idObject, Draw::Draws mode)
: VGObject(GObject::SplinePath, idObject, mode), path(QVector<VSplinePoint>()), kCurve(kCurve)
{
}
VSplinePath::VSplinePath(const VSplinePath &splPath)
: path(*splPath.GetPoint()), kCurve(splPath.getKCurve()), points(splPath.GetDataPoints()),
idObject(splPath.getIdObject()), _name(splPath.name()){}
: VGObject(splPath), path(*splPath.GetPoint()), kCurve(splPath.getKCurve())
{
}
void VSplinePath::append(const VSplinePoint &point)
{
@ -47,8 +46,8 @@ void VSplinePath::append(const VSplinePoint &point)
for (qint32 i = 1; i <= this->Count(); ++i)
{
VSpline spl = this->GetSpline(i);
VPointF first = spl.GetPointP1();
VPointF second = spl.GetPointP4();
VPointF first = spl.GetP1();
VPointF second = spl.GetP4();
QString splName = QString("_%1_%2").arg(first.name(), second.name());
_name.append(splName);
}
@ -76,7 +75,7 @@ VSpline VSplinePath::GetSpline(qint32 index) const
{
throw VException(tr("This spline does not exist."));
}
VSpline spl(&points, path[index-1].P(), path[index].P(), path[index-1].Angle2(), path[index].Angle1(),
VSpline spl(path[index-1].P(), path[index].P(), path[index-1].Angle2(), path[index].Angle1(),
path[index-1].KAsm2(), path[index].KAsm1(), this->kCurve);
return spl;
}
@ -86,7 +85,7 @@ QPainterPath VSplinePath::GetPath() const
QPainterPath painterPath;
for (qint32 i = 1; i <= Count(); ++i)
{
VSpline spl(&points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(),
VSpline spl(path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(),
path[i-1].KAsm2(), path[i].KAsm1(), this->kCurve);
painterPath.addPath(spl.GetPath());
}
@ -98,8 +97,9 @@ QVector<QPointF> VSplinePath::GetPathPoints() const
QVector<QPointF> pathPoints;
for (qint32 i = 1; i <= Count(); ++i)
{
VSpline spl(&points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(),
VSpline spl(path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(),
path[i-1].KAsm2(), path[i].KAsm1(), this->kCurve);
//TODO Use QVector<T> & QVector::operator+=(const QVector<T> & other) instead for.
QVector<QPointF> splP = spl.GetPoints();
for (qint32 j = 0; j < splP.size(); ++j)
{
@ -114,7 +114,7 @@ qreal VSplinePath::GetLength() const
qreal length = 0;
for (qint32 i = 1; i <= Count(); ++i)
{
VSpline spl(&points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(),
VSpline spl(path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(),
path[i].KAsm1(), kCurve);
length += spl.GetLength();
}
@ -155,11 +155,9 @@ VSplinePoint VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePoint::Positi
VSplinePath &VSplinePath::operator =(const VSplinePath &path)
{
VGObject::operator=(path);
this->path = path.GetSplinePath();
this->kCurve = path.getKCurve();
this->points = path.GetDataPoints();
this->idObject = path.getIdObject();
this->_name = path.name();
return *this;
}
@ -168,17 +166,22 @@ VSplinePoint & VSplinePath::operator[](ptrdiff_t indx)
return path[indx];
}
const VSplinePoint &VSplinePath::at(ptrdiff_t indx) const
{
return path[indx];
}
QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3,
QPointF &spl2p2, QPointF &spl2p3) const
{
if(Count() < 2)
if (Count() < 2)
{
throw VException(tr("Can't cut spline path with one point"));
}
//Always need return two spline paths, so we must correct wrong length.
qreal fullLength = GetLength();
if(length < fullLength * 0.02)
if (length < fullLength * 0.02)
{
length = fullLength * 0.02;
}
@ -190,10 +193,10 @@ QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF
fullLength = 0;
for (qint32 i = 1; i <= Count(); ++i)
{
VSpline spl = VSpline(&points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(),
path[i-1].KAsm2(), path[i].KAsm1(), kCurve);
VSpline spl = VSpline(path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(),
path[i].KAsm1(), kCurve);
fullLength += spl.GetLength();
if(fullLength > length)
if (fullLength > length)
{
p1 = i-1;
p2 = i;
@ -202,14 +205,3 @@ QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF
}
return QPointF();
}
QHash<qint64, VPointF> VSplinePath::getPoints() const
{
return points;
}
void VSplinePath::setPoints(const QHash<qint64, VPointF> *value)
{
points = *value;
}

View File

@ -30,9 +30,11 @@
#define VSPLINEPATH_H
#include "vsplinepoint.h"
#include "../container/vpointf.h"
#include "vpointf.h"
#include "vspline.h"
#include "vgobject.h"
#include <QApplication>
#include "../container/vcontainer.h"
namespace SplinePoint
{
@ -47,18 +49,14 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( SplinePoint::Positions )
/**
* @brief The VSplinePath клас, що розраховує шлях сплайнів.
*/
class VSplinePath
class VSplinePath :public VGObject
{
Q_DECLARE_TR_FUNCTIONS(VSplinePath)
public:
/**
* @brief VSplinePath конструктор по замовчуванню.
*/
VSplinePath();
/**
* @brief VSplinePath конструктор по замовчуванню.
*/
VSplinePath(const QHash<qint64, VPointF> *points, qreal kCurve = 1, qint64 idObject = 0);
VSplinePath(qreal kCurve = 1, qint64 idObject = 0, Draw::Draws mode = Draw::Calculation);
/**
* @brief VSplinePath
* @param splPath
@ -105,11 +103,6 @@ public:
* @return
*/
qreal GetLength() const;
/**
* @brief GetDataPoints
* @return
*/
inline QHash<qint64, VPointF> GetDataPoints() const {return points;}
/**
* @brief UpdatePoint
* @param indexSpline
@ -155,26 +148,7 @@ public:
* @return
*/
VSplinePoint &operator[](ptrdiff_t indx);
/**
* @brief getIdObject
* @return
*/
inline qint64 getIdObject() const {return idObject;}
/**
* @brief setIdObject
* @param value
*/
inline void setIdObject(const qint64 &value) {idObject = value;}
/**
* @brief name
* @return
*/
QString name() const {return _name;}
/**
* @brief setName
* @param name
*/
void setName(const QString &name) {_name = name;}
const VSplinePoint &at(ptrdiff_t indx) const;
/**
* @brief CutSplinePath
* @param length
@ -186,8 +160,7 @@ public:
*/
QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2,
QPointF &spl2p3) const;
QHash<qint64, VPointF> getPoints() const;
void setPoints(const QHash<qint64, VPointF> *value);
virtual QString name() const{return _name;}
protected:
/**
* @brief path вектор з точок сплайна.
@ -197,18 +170,6 @@ protected:
* @brief kCurve
*/
qreal kCurve;
/**
* @brief points
*/
QHash<qint64, VPointF> points;
/**
* @brief idObject
*/
qint64 idObject;
/**
* @brief _name
*/
QString _name;
};
#endif // VSPLINEPATH_H

View File

@ -29,9 +29,9 @@
#include "vsplinepoint.h"
VSplinePoint::VSplinePoint()
:pSpline(0), angle(0), kAsm1(1), kAsm2(1){}
:pSpline(VPointF()), angle(0), kAsm1(1), kAsm2(1){}
VSplinePoint::VSplinePoint(qint64 pSpline, qreal kAsm1, qreal angle, qreal kAsm2)
VSplinePoint::VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle, qreal kAsm2)
:pSpline(pSpline), angle(angle), kAsm1(kAsm1), kAsm2(kAsm2){}
VSplinePoint::VSplinePoint(const VSplinePoint &point)

View File

@ -30,6 +30,7 @@
#define VSPLINEPOINT_H
#include <QMetaType>
#include "vpointf.h"
/**
* @brief The VSplinePoint клас, що містить у собі інформацію про точки сплайну.
@ -47,7 +48,7 @@ public:
* @param angle кут дотичної сплайна.
* @param factor коефіцієнт довжини дотичної.
*/
VSplinePoint(qint64 pSpline, qreal kAsm1, qreal angle, qreal kAsm2);
VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle, qreal kAsm2);
/**
* @brief VSplinePoint
* @param point
@ -58,12 +59,12 @@ public:
* @brief P повертає точку.
* @return точка.
*/
inline qint64 P() const {return pSpline;}
inline VPointF P() const {return pSpline;}
/**
* @brief SetP
* @param value
*/
inline void SetP(const qint64 &value) {pSpline = value;}
inline void SetP(const VPointF &value) {pSpline = value;}
/**
* @brief Angle1 повертає кут дотичної сплайна.
* @return кут в градусах.
@ -103,7 +104,7 @@ protected:
/**
* @brief pSpline точка сплайну.
*/
qint64 pSpline;
VPointF pSpline;
/**
* @brief angle кут дотичної сплайну.
*/

View File

@ -45,8 +45,8 @@
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::MainWindow), tool(Tool::ArrowTool), currentScene(0), sceneDraw(0),
sceneDetails(0), mouseCoordinate(0), helpLabel(0), view(0), isInitialized(false), dialogTable(0),
:QMainWindow(parent), ui(new Ui::MainWindow), pattern(0), doc(0), tool(Tool::ArrowTool), currentScene(0),
sceneDraw(0), sceneDetails(0), mouseCoordinate(0), helpLabel(0), view(0), isInitialized(false), dialogTable(0),
dialogEndLine(QSharedPointer<DialogEndLine>()), dialogLine(QSharedPointer<DialogLine>()),
dialogAlongLine(QSharedPointer<DialogAlongLine>()),
dialogShoulderPoint(QSharedPointer<DialogShoulderPoint>()), dialogNormal(QSharedPointer<DialogNormal>()),
@ -58,8 +58,9 @@ MainWindow::MainWindow(QWidget *parent)
dialogTriangle(QSharedPointer<DialogTriangle>()),
dialogPointOfIntersection(QSharedPointer<DialogPointOfIntersection>()),
dialogCutSpline(QSharedPointer<DialogCutSpline>()), dialogCutSplinePath (QSharedPointer<DialogCutSplinePath>()),
dialogHistory(0), doc(0), data(0), comboBoxDraws(0), fileName(QString()), changeInFile(false),
mode(Draw::Calculation)
dialogUnionDetails(QSharedPointer<DialogUnionDetails>()),
dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false),
mode(Draw::Calculation), currentDrawIndex(0)
{
ui->setupUi(this);
ToolBarOption();
@ -107,16 +108,14 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->toolButtonPointOfIntersection, &QToolButton::clicked, this, &MainWindow::ToolPointOfIntersection);
connect(ui->toolButtonSplineCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutSpline);
connect(ui->toolButtonSplinePathCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutSplinePath);
connect(ui->toolButtonUnionDetails, &QToolButton::clicked, this, &MainWindow::ToolUnionDetails);
data = new VContainer;
pattern = new VContainer();
doc = new VDomDocument(data, comboBoxDraws, &mode);
doc = new VDomDocument(pattern, comboBoxDraws, &mode);
doc->CreateEmptyFile();
connect(doc, &VDomDocument::haveChange, this, &MainWindow::haveChange);
fileName.clear();
changeInFile = false;
//Autosaving file each 5 minutes
QTimer *timer = new QTimer(this);
timer->setTimerType(Qt::VeryCoarseTimer);
@ -180,10 +179,10 @@ void MainWindow::ActionNewDraw()
}
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&MainWindow::currentDrawChanged);
data->ClearObject();
pattern->ClearGObjects();
//Create single point
qint64 id = data->AddPoint(VPointF(toPixel((10+comboBoxDraws->count()*5)), toPixel(10), "А", 5, 10));
VToolSinglePoint *spoint = new VToolSinglePoint(doc, data, id, Tool::FromGui);
qint64 id = pattern->AddGObject(new VPointF(toPixel((10+comboBoxDraws->count()*5)), toPixel(10), "А", 5, 10));
VToolSinglePoint *spoint = new VToolSinglePoint(doc, pattern, id, Tool::FromGui);
sceneDraw->addItem(spoint);
connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem);
connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor);
@ -251,7 +250,7 @@ void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &curso
QCursor cur(pixmap, 2, 3);
view->setCursor(cur);
helpLabel->setText(toolTip);
dialog = QSharedPointer<Dialog>(new Dialog(data));
dialog = QSharedPointer<Dialog>(new Dialog(pattern));
connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialog.data(), &Dialog::ChoosedObject);
connect(dialog.data(), &Dialog::DialogClosed, this, closeDialogSlot);
connect(dialog.data(), &Dialog::ToolTip, this, &MainWindow::ShowToolTip);
@ -282,7 +281,7 @@ void MainWindow::ClosedDialog(QSharedPointer<Dialog> &dialog, int result)
{
if (result == QDialog::Accepted)
{
DrawTool::Create(dialog, currentScene, doc, data);
DrawTool::Create(dialog, currentScene, doc, pattern);
}
ArrowTool();
}
@ -443,7 +442,7 @@ void MainWindow::ToolDetail(bool checked)
QCursor cur(pixmap, 2, 3);
view->setCursor(cur);
helpLabel->setText(tr("Select points, arcs, curves clockwise."));
dialogDetail = QSharedPointer<DialogDetail>(new DialogDetail(data));
dialogDetail = QSharedPointer<DialogDetail>(new DialogDetail(pattern));
connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogDetail.data(),
&DialogDetail::ChoosedObject);
connect(dialogDetail.data(), &DialogDetail::DialogClosed, this, &MainWindow::ClosedDialogDetail);
@ -462,7 +461,7 @@ void MainWindow::ClosedDialogDetail(int result)
{
if (result == QDialog::Accepted)
{
VToolDetail::Create(dialogDetail, sceneDetails, doc, data);
VToolDetail::Create(dialogDetail, sceneDetails, doc, pattern);
}
ArrowTool();
}
@ -501,6 +500,19 @@ void MainWindow::ClosedDialogPointOfIntersection(int result)
ClosedDialog<VToolPointOfIntersection>(dialogPointOfIntersection, result);
}
void MainWindow::ToolUnionDetails(bool checked)
{
SetToolButton(checked, Tool::UnionDetails, ":/cursor/union_cursor.png",
tr("Select detail"), dialogUnionDetails, &MainWindow::ClosedDialogUnionDetails);
//Must disconnect this signal here.
disconnect(doc, &VDomDocument::FullUpdateFromFile, dialogUnionDetails.data(), &DialogUnionDetails::UpdateList);
}
void MainWindow::ClosedDialogUnionDetails(int result)
{
ClosedDialog<VToolUnionDetails>(dialogUnionDetails, result);
}
void MainWindow::About()
{
QString fullName = QString("Valentina %1").arg(APP_VERSION);
@ -791,6 +803,12 @@ void MainWindow::CanselTool()
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break;
case Tool::UnionDetails:
dialogUnionDetails.clear();
ui->toolButtonUnionDetails->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break;
default:
qWarning()<<"Got wrong tool type. Ignored.";
break;
@ -844,6 +862,8 @@ void MainWindow::ActionDraw(bool checked)
verScrollBar = view->verticalScrollBar();
verScrollBar->setValue(currentScene->getVerScrollBar());
comboBoxDraws->setCurrentIndex(currentDrawIndex);
mode = Draw::Calculation;
SetEnableTool(true);
doc->setCurrentData();
@ -873,6 +893,10 @@ void MainWindow::ActionDetails(bool checked)
horScrollBar->setValue(currentScene->getHorScrollBar());
verScrollBar = view->verticalScrollBar();
verScrollBar->setValue(currentScene->getVerScrollBar());
currentDrawIndex = comboBoxDraws->currentIndex();
comboBoxDraws->setCurrentIndex(comboBoxDraws->count()-1);
mode = Draw::Modeling;
SetEnableTool(true);
ui->toolBox->setCurrentIndex(4);
@ -956,7 +980,7 @@ void MainWindow::Clear()
{
setWindowTitle("Valentina");
fileName.clear();
data->Clear();
pattern->Clear();
doc->clear();
sceneDraw->clear();
sceneDetails->clear();
@ -991,14 +1015,14 @@ void MainWindow::haveChange()
void MainWindow::ChangedSize(const QString & text)
{
qint32 size = text.toInt();
data->SetSize(size*10);
pattern->SetSize(size*10);
doc->FullUpdateTree();
}
void MainWindow::ChangedGrowth(const QString &text)
{
qint32 growth = text.toInt();
data->SetGrowth(growth*10);
pattern->SetGrowth(growth*10);
doc->FullUpdateTree();
}
@ -1020,7 +1044,7 @@ void MainWindow::ActionTable(bool checked)
{
if (checked)
{
dialogTable = new DialogIncrements(data, doc, this);
dialogTable = new DialogIncrements(pattern, doc, this);
connect(dialogTable, &DialogIncrements::DialogClosed, this,
&MainWindow::ClosedActionTable);
dialogTable->show();
@ -1042,7 +1066,7 @@ void MainWindow::ActionHistory(bool checked)
{
if (checked)
{
dialogHistory = new DialogHistory(data, doc, this);
dialogHistory = new DialogHistory(pattern, doc, this);
dialogHistory->setWindowFlags(Qt::Window);
connect(dialogHistory, &DialogHistory::DialogClosed, this,
&MainWindow::ClosedActionHistory);
@ -1060,7 +1084,7 @@ void MainWindow::ActionLayout(bool checked)
Q_UNUSED(checked);
hide();
QVector<VItem*> listDetails;
data->PrepareDetails(listDetails);
pattern->PrepareDetails(listDetails);
emit ModelChosen(listDetails);
}
@ -1074,13 +1098,13 @@ void MainWindow::SetEnableTool(bool enable)
{
bool drawTools = false;
bool modelingTools = false;
if(mode == Draw::Calculation)
if (mode == Draw::Calculation)
{
drawTools = enable;
}
else
{
modelingTools = enable; // Soon we will have some tools for modeling.
modelingTools = enable;
}
//Drawing Tools
ui->toolButtonEndLine->setEnabled(drawTools);
@ -1100,6 +1124,9 @@ void MainWindow::SetEnableTool(bool enable)
ui->toolButtonPointOfIntersection->setEnabled(drawTools);
ui->toolButtonSplineCutPoint->setEnabled(drawTools);
ui->toolButtonSplinePathCutPoint->setEnabled(drawTools);
//Modeling Tools
ui->toolButtonUnionDetails->setEnabled(modelingTools);
}
void MainWindow::MinimumScrollBar()
@ -1202,11 +1229,10 @@ MainWindow::~MainWindow()
CanselTool();
delete ui;
delete data;
if (doc->isNull() == false)
{
delete doc;
}
delete pattern;
delete doc;
delete sceneDetails;
delete sceneDraw;
}
void MainWindow::OpenPattern(const QString &fileName)

View File

@ -35,6 +35,7 @@
#include "widgets/vitem.h"
#include "dialogs/dialogs.h"
#include "tools/vtooldetail.h"
#include "tools/vtooluniondetails.h"
#include "tools/drawTools/drawtools.h"
#include "xml/vdomdocument.h"
@ -232,6 +233,7 @@ public slots:
* @param checked
*/
void ToolPointOfIntersection(bool checked);
void ToolUnionDetails(bool checked);
/**
* @brief ClosedDialogEndLine
* @param result
@ -312,6 +314,7 @@ public slots:
* @param result
*/
void ClosedDialogPointOfIntersection(int result);
void ClosedDialogUnionDetails(int result);
/**
* @brief ClosedDialogCutSpline handler close event tool CutSpline
* @param result result of working of dialog
@ -367,6 +370,14 @@ private:
* @brief ui keeps information about user interface
*/
Ui::MainWindow *ui;
/**
* @brief pattern container with data (points, arcs, splines, spline paths, variables)
*/
VContainer *pattern;
/**
* @brief doc dom document container
*/
VDomDocument *doc;
/**
* @brief tool
*/
@ -471,18 +482,14 @@ private:
* @brief dialogCutSplinePath pointer to the dialog tool cut spline path
*/
QSharedPointer<DialogCutSplinePath> dialogCutSplinePath;
/**
* @brief dialogUnionDetails
*/
QSharedPointer<DialogUnionDetails> dialogUnionDetails;
/**
* @brief dialogHistory
*/
DialogHistory *dialogHistory;
/**
* @brief doc dom document container
*/
VDomDocument *doc;
/**
* @brief data container with data
*/
VContainer *data;
/**
* @brief comboBoxDraws
*/
@ -499,6 +506,7 @@ private:
* @brief mode
*/
Draw::Draws mode;
qint32 currentDrawIndex;
/**
* @brief ToolBarOption
*/

View File

@ -47,7 +47,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>150</width>
<width>144</width>
<height>150</height>
</rect>
</property>
@ -302,7 +302,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>150</width>
<width>100</width>
<height>58</height>
</rect>
</property>
@ -378,7 +378,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>150</width>
<width>100</width>
<height>104</height>
</rect>
</property>
@ -596,6 +596,29 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="toolButtonUnionDetails">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../share/resources/icon.qrc">
<normaloff>:/icon/32x32/union.png</normaloff>:/icon/32x32/union.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

View File

@ -77,14 +77,15 @@ namespace Tool
NodeSplinePath,
Height,
Triangle,
PointOfIntersection
PointOfIntersection,
UnionDetails
};
Q_DECLARE_FLAGS(Tools, Tool)
/**
* @brief The Source enum
*/
enum Source { FromGui, FromFile };
enum Source { FromGui, FromFile, FromTool };
Q_DECLARE_FLAGS(Sources, Source)
}
Q_DECLARE_OPERATORS_FOR_FLAGS( Tool::Tools )

View File

@ -34,7 +34,7 @@
TableWindow::TableWindow(QWidget *parent)
:QMainWindow(parent), numberDetal(0), colission(0), ui(new Ui::TableWindow),
listDetails(QVector<VItem*>()), outItems(false), collidingItems(false), currentScene(0),
listDetails(QVector<VItem*>()), outItems(false), collidingItems(false), tableScene(0),
paper(0), shadowPaper(0), listOutItems(0), listCollidingItems(QList<QGraphicsItem*>()),
indexDetail(0), sceneRect(QRectF())
{
@ -46,12 +46,12 @@ TableWindow::TableWindow(QWidget *parent)
outItems = collidingItems = false;
//sceneRect = QRectF(0, 0, toPixel(203), toPixel(287));
sceneRect = QRectF(0, 0, toPixel(823), toPixel(1171));
currentScene = new QGraphicsScene(sceneRect);
QBrush *brush = new QBrush();
brush->setStyle( Qt::SolidPattern );
brush->setColor( QColor( Qt::gray ) );
currentScene->setBackgroundBrush( *brush );
VTableGraphicsView* view = new VTableGraphicsView(currentScene);
tableScene = new QGraphicsScene(sceneRect);
QBrush brush;
brush.setStyle( Qt::SolidPattern );
brush.setColor( QColor( Qt::gray ) );
tableScene->setBackgroundBrush( brush );
VTableGraphicsView* view = new VTableGraphicsView(tableScene);
view->fitInView(view->scene()->sceneRect(), Qt::KeepAspectRatio);
ui->horizontalLayout->addWidget(view);
connect(ui->actionTurn, &QAction::triggered, view, &VTableGraphicsView::rotateItems);
@ -68,6 +68,7 @@ TableWindow::TableWindow(QWidget *parent)
TableWindow::~TableWindow()
{
delete tableScene;
delete ui;
}
@ -77,11 +78,11 @@ void TableWindow::AddPaper()
sceneRect.getCoords(&x1, &y1, &x2, &y2);
shadowPaper = new QGraphicsRectItem(QRectF(x1+4, y1+4, x2+4, y2+4));
shadowPaper->setBrush(QBrush(Qt::black));
currentScene->addItem(shadowPaper);
tableScene->addItem(shadowPaper);
paper = new QGraphicsRectItem(QRectF(x1, y1, x2, y2));
paper->setPen(QPen(Qt::black, widthMainLine));
paper->setBrush(QBrush(Qt::white));
currentScene->addItem(paper);
tableScene->addItem(paper);
qDebug()<<paper->rect().size().toSize();
}
@ -89,7 +90,7 @@ void TableWindow::AddDetail()
{
if (indexDetail<listDetails.count())
{
currentScene->clearSelection();
tableScene->clearSelection();
VItem* Detail = listDetails[indexDetail];
QObject::connect(Detail, SIGNAL(itemOut(int, bool)), this, SLOT(itemOut(int, bool)));
QObject::connect(Detail, SIGNAL(itemColliding(QList<QGraphicsItem*>, int)), this,
@ -102,7 +103,7 @@ void TableWindow::AddDetail()
Detail->setFlag(QGraphicsItem::ItemIsSelectable, true);
Detail->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
Detail->setPaper(paper);
currentScene->addItem(Detail);
tableScene->addItem(Detail);
Detail->setSelected(true);
indexDetail++;
if (indexDetail==listDetails.count())
@ -148,7 +149,7 @@ void TableWindow::showEvent ( QShowEvent * event )
void TableWindow::StopTable()
{
hide();
currentScene->clear();
tableScene->clear();
delete listOutItems;
listDetails.clear();
//sceneRect = QRectF(0, 0, 230*resol/25.9, 327*resol/25.9);
@ -166,8 +167,8 @@ void TableWindow::saveScene()
QBrush *brush = new QBrush();
brush->setColor( QColor( Qt::white ) );
currentScene->setBackgroundBrush( *brush );
currentScene->clearSelection(); // Selections would also render to the file, so need delete them
tableScene->setBackgroundBrush( *brush );
tableScene->clearSelection(); // Selections would also render to the file, so need delete them
shadowPaper->setVisible(false);
QFileInfo fi(name);
if (fi.suffix() == "svg")
@ -185,7 +186,7 @@ void TableWindow::saveScene()
brush->setColor( QColor( Qt::gray ) );
brush->setStyle( Qt::SolidPattern );
currentScene->setBackgroundBrush( *brush );
tableScene->setBackgroundBrush( *brush );
shadowPaper->setVisible(true);
delete brush;
}
@ -310,9 +311,9 @@ void TableWindow::GetNextDetail()
void TableWindow::AddLength()
{
QRectF rect = currentScene->sceneRect();
QRectF rect = tableScene->sceneRect();
rect.setHeight(rect.height()+toPixel(279));
currentScene->setSceneRect(rect);
tableScene->setSceneRect(rect);
rect = shadowPaper->rect();
rect.setHeight(rect.height()+toPixel(279));
shadowPaper->setRect(rect);
@ -325,18 +326,18 @@ void TableWindow::AddLength()
void TableWindow::RemoveLength()
{
if (sceneRect.height() <= currentScene->sceneRect().height() - 100)
if (sceneRect.height() <= tableScene->sceneRect().height() - 100)
{
QRectF rect = currentScene->sceneRect();
QRectF rect = tableScene->sceneRect();
rect.setHeight(rect.height()-toPixel(279));
currentScene->setSceneRect(rect);
tableScene->setSceneRect(rect);
rect = shadowPaper->rect();
rect.setHeight(rect.height()-toPixel(279));
shadowPaper->setRect(rect);
rect = paper->rect();
rect.setHeight(rect.height()-toPixel(279));
paper->setRect(rect);
if (fabs(sceneRect.height() - currentScene->sceneRect().height()) < 0.01)
if (fabs(sceneRect.height() - tableScene->sceneRect().height()) < 0.01)
{
ui->actionRemove->setDisabled(true);
}
@ -378,7 +379,7 @@ void TableWindow::SvgFile(const QString &name) const
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, 1.2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter.setBrush ( QBrush ( Qt::NoBrush ) );
currentScene->render(&painter);
tableScene->render(&painter);
painter.end();
}
@ -395,6 +396,6 @@ void TableWindow::PngFile(const QString &name) const
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter.setBrush ( QBrush ( Qt::NoBrush ) );
currentScene->render(&painter);
tableScene->render(&painter);
image.save(name);
}

View File

@ -158,7 +158,7 @@ private:
/**
* @brief currentScene Зберігається покажчик на сцену.
*/
QGraphicsScene* currentScene;
QGraphicsScene* tableScene;
/**
* @brief paper Зберігається покажчик на прямокутник що імітує листа паперу.
*/

View File

@ -30,8 +30,8 @@
qreal VDrawTool::factor = 1;
VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent)
:VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), ignoreFullUpdate(false),
VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id)
:VAbstractTool(doc, data, id), ignoreContextMenuEvent(false), ignoreFullUpdate(false),
nameActivDraw(doc->GetNameActivDraw())
{
connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VDrawTool::ChangedActivDraw);
@ -39,30 +39,6 @@ VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *pa
connect(this->doc, &VDomDocument::ShowTool, this, &VDrawTool::ShowTool);
}
void VDrawTool::AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc)
{
qint64 cursor = doc->getCursor();
QVector<VToolRecord> *history = doc->getHistory();
if (cursor <= 0)
{
history->append(VToolRecord(id, toolType, doc->GetNameActivDraw()));
}
else
{
qint32 index = 0;
for (qint32 i = 0; i<history->size(); ++i)
{
VToolRecord rec = history->at(i);
if (rec.getId() == cursor)
{
index = i;
break;
}
}
history->insert(index+1, VToolRecord(id, toolType, doc->GetNameActivDraw()));
}
}
void VDrawTool::ShowTool(qint64 id, Qt::GlobalColor color, bool enable)
{
Q_UNUSED(id);

View File

@ -48,19 +48,12 @@ public:
* @param id
* @param parent
*/
VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0);
VDrawTool(VDomDocument *doc, VContainer *data, qint64 id);
virtual ~VDrawTool() {}
/**
* @brief setDialog
*/
virtual void setDialog() {}
/**
* @brief AddRecord
* @param id
* @param toolType
* @param doc dom document container
*/
static void AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc);
/**
* @brief ignoreContextMenu
* @param enable

View File

@ -43,6 +43,10 @@ VToolAlongLine::VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, c
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolAlongLine::FullUpdateFromFile()
@ -89,14 +93,14 @@ void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolAlongLine::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrTypeLine, typeLine);
AddAttribute(domElement, AttrLength, formula);
@ -106,6 +110,22 @@ void VToolAlongLine::AddToFile()
AddToCalculation(domElement);
}
void VToolAlongLine::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my()));
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrTypeLine, typeLine);
domElement.setAttribute(AttrLength, formula);
domElement.setAttribute(AttrFirstPoint, basePointId);
domElement.setAttribute(AttrSecondPoint, secondPointId);
}
}
void VToolAlongLine::RemoveReferens()
{
doc->DecrementReferens(secondPointId);
@ -115,12 +135,12 @@ void VToolAlongLine::RemoveReferens()
void VToolAlongLine::setDialog()
{
Q_ASSERT(dialogAlongLine.isNull() == false);
VPointF p = VAbstractTool::data.GetPoint(id);
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogAlongLine->setTypeLine(typeLine);
dialogAlongLine->setFormula(formula);
dialogAlongLine->setFirstPointId(basePointId, id);
dialogAlongLine->setSecondPointId(secondPointId, id);
dialogAlongLine->setPointName(p.name());
dialogAlongLine->setPointName(p->name());
}
void VToolAlongLine::Create(QSharedPointer<DialogAlongLine> &dialog, VMainGraphicsScene *scene,
@ -140,9 +160,9 @@ void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QS
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF());
const VPointF *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
QLineF line = QLineF(firstPoint->toQPointF(), secondPoint->toQPointF());
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
@ -152,13 +172,13 @@ void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QS
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
id = data->AddGObject( new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
}
else
{
data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
data->UpdateGObject(id, new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
if (parse != Document::FullParse)

View File

@ -116,6 +116,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief RemoveReferens
*/

View File

@ -36,9 +36,9 @@ VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::S
QGraphicsItem *parent)
:VDrawTool(doc, data, id), QGraphicsPathItem(parent), dialogArc(QSharedPointer<DialogArc>())
{
VArc arc = data->GetArc(id);
const VArc *arc = data->GeometricObject<const VArc *>(id);
QPainterPath path;
path.addPath(arc.GetPath());
path.addPath(arc->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
this->setPen(QPen(Qt::black, widthHairLine/factor));
@ -49,16 +49,20 @@ VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::S
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolArc::setDialog()
{
Q_ASSERT(dialogArc.isNull() == false);
VArc arc = VAbstractTool::data.GetArc(id);
dialogArc->SetCenter(arc.GetCenter());
dialogArc->SetF1(arc.GetFormulaF1());
dialogArc->SetF2(arc.GetFormulaF2());
dialogArc->SetRadius(arc.GetFormulaRadius());
const VArc *arc = VAbstractTool::data.GeometricObject<const VArc *>(id);
dialogArc->SetCenter(arc->GetCenter().id());
dialogArc->SetF1(arc->GetFormulaF1());
dialogArc->SetF2(arc->GetFormulaF2());
dialogArc->SetRadius(arc->GetFormulaRadius());
}
void VToolArc::Create(QSharedPointer<DialogArc> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
@ -99,17 +103,19 @@ void VToolArc::Create(const qint64 _id, const qint64 &center, const QString &rad
calcF2 = result;
}
VArc arc = VArc(data->DataPoints(), center, calcRadius, radius, calcF1, f1, calcF2, f2 );
VPointF c = *data->GeometricObject<const VPointF *>(center);
VArc *arc = new VArc(c, calcRadius, radius, calcF1, f1, calcF2, f2 );
Q_ASSERT(arc != 0);
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddArc(arc);
data->AddLengthArc(arc.name(), toMM(arc.GetLength()));
id = data->AddGObject(arc);
data->AddLengthArc(arc->name(), toMM(arc->GetLength()));
}
else
{
data->UpdateArc(id, arc);
data->AddLengthArc(arc.name(), toMM(arc.GetLength()));
data->UpdateGObject(id, arc);
data->AddLengthArc(arc->name(), toMM(arc->GetLength()));
if (parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
@ -186,19 +192,32 @@ void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolArc::AddToFile()
{
VArc arc = VAbstractTool::data.GetArc(id);
const VArc *arc = VAbstractTool::data.GeometricObject<const VArc *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrCenter, arc.GetCenter());
AddAttribute(domElement, AttrRadius, arc.GetFormulaRadius());
AddAttribute(domElement, AttrAngle1, arc.GetFormulaF1());
AddAttribute(domElement, AttrAngle2, arc.GetFormulaF2());
AddAttribute(domElement, AttrCenter, arc->GetCenter().id());
AddAttribute(domElement, AttrRadius, arc->GetFormulaRadius());
AddAttribute(domElement, AttrAngle1, arc->GetFormulaF1());
AddAttribute(domElement, AttrAngle2, arc->GetFormulaF2());
AddToCalculation(domElement);
}
void VToolArc::RefreshDataInFile()
{
const VArc *arc = VAbstractTool::data.GeometricObject<const VArc *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrCenter, arc->GetCenter().id());
domElement.setAttribute(AttrRadius, arc->GetFormulaRadius());
domElement.setAttribute(AttrAngle1, arc->GetFormulaF1());
domElement.setAttribute(AttrAngle2, arc->GetFormulaF2());
}
}
void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
@ -222,16 +241,16 @@ void VToolArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void VToolArc::RemoveReferens()
{
VArc arc = VAbstractTool::data.GetArc(id);
doc->DecrementReferens(arc.GetCenter());
const VArc *arc = VAbstractTool::data.GeometricObject<const VArc *>(id);
doc->DecrementReferens(arc->GetCenter().id());
}
void VToolArc::RefreshGeometry()
{
this->setPen(QPen(currentColor, widthHairLine/factor));
VArc arc = VAbstractTool::data.GetArc(id);
const VArc *arc = VAbstractTool::data.GeometricObject<const VArc *>(id);
QPainterPath path;
path.addPath(arc.GetPath());
path.addPath(arc->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
}

View File

@ -125,6 +125,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief mouseReleaseEvent
* @param event

View File

@ -45,6 +45,10 @@ VToolBisector::VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
QPointF VToolBisector::FindPoint(const QPointF &firstPoint, const QPointF &secondPoint,
@ -69,13 +73,13 @@ QPointF VToolBisector::FindPoint(const QPointF &firstPoint, const QPointF &secon
void VToolBisector::setDialog()
{
Q_ASSERT(dialogBisector.isNull() == false);
VPointF p = VAbstractTool::data.GetPoint(id);
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogBisector->setTypeLine(typeLine);
dialogBisector->setFormula(formula);
dialogBisector->setFirstPointId(firstPointId, id);
dialogBisector->setSecondPointId(basePointId, id);
dialogBisector->setThirdPointId(thirdPointId, id);
dialogBisector->setPointName(p.name());
dialogBisector->setPointName(p->name());
}
void VToolBisector::Create(QSharedPointer<DialogBisector> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
@ -97,26 +101,26 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
VPointF thirdPoint = data->GetPoint(thirdPointId);
const VPointF *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
const VPointF *thirdPoint = data->GeometricObject<const VPointF *>(thirdPointId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if (errorMsg.isEmpty())
{
QPointF fPoint = VToolBisector::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
thirdPoint.toQPointF(), toPixel(result));
QPointF fPoint = VToolBisector::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
thirdPoint->toQPointF(), toPixel(result));
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
}
else
{
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
if (parse != Document::FullParse)
{
@ -186,14 +190,14 @@ void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolBisector::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrTypeLine, typeLine);
AddAttribute(domElement, AttrLength, formula);
@ -204,6 +208,23 @@ void VToolBisector::AddToFile()
AddToCalculation(domElement);
}
void VToolBisector::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my()));
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrTypeLine, typeLine);
domElement.setAttribute(AttrLength, formula);
domElement.setAttribute(AttrFirstPoint, firstPointId);
domElement.setAttribute(AttrSecondPoint, basePointId);
domElement.setAttribute(AttrThirdPoint, thirdPointId);
}
}
void VToolBisector::RemoveReferens()
{
doc->DecrementReferens(firstPointId);

View File

@ -129,6 +129,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief RemoveReferens
*/

View File

@ -58,15 +58,19 @@ VToolCutSpline::VToolCutSpline(VDomDocument *doc, VContainer *data, const qint64
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolCutSpline::setDialog()
{
Q_ASSERT(dialogCutSpline.isNull() == false);
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogCutSpline->setFormula(formula);
dialogCutSpline->setSplineId(splineId, id);
dialogCutSpline->setPointName(point.name());
dialogCutSpline->setPointName(point->name());
}
void VToolCutSpline::Create(QSharedPointer<DialogCutSpline> &dialog, VMainGraphicsScene *scene,
@ -83,53 +87,59 @@ void VToolCutSpline::Create(const qint64 _id, const QString &pointName,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VSpline spl = data->GetSpline(splineId);
const VSpline *spl = data->GeometricObject<const VSpline *>(splineId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if (errorMsg.isEmpty())
{
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
QPointF point = spl.CutSpline(toPixel(result), spl1p2, spl1p3, spl2p2, spl2p3);
QPointF point = spl->CutSpline(toPixel(result), spl1p2, spl1p3, spl2p2, spl2p3);
qint64 id = _id;
qint64 spl1id = 0;
qint64 spl2id = 0;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(point.x(), point.y(), pointName, mx, my));
spl1id = id + 1;
spl2id = id + 2;
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
Q_ASSERT(p != 0);
id = data->AddGObject(p);
VSpline spline1 = VSpline(data->DataPoints(), spl.GetP1(), spl1p2, spl1p3, id, spl.GetKcurve());
spl1id = data->AddSpline(spline1);
data->AddLengthSpline(spline1.name(), toMM(spline1.GetLength()));
VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve());
Q_ASSERT(spline1);
spl1id = data->AddGObject(spline1);
data->AddLengthSpline(spline1->name(), toMM(spline1->GetLength()));
VSpline spline2 = VSpline(data->DataPoints(), id, spl2p2, spl2p3, spl.GetP4(), spl.GetKcurve());
spl2id = data->AddSpline(spline2);
data->AddLengthSpline(spline2.name(), toMM(spline2.GetLength()));
VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve());
Q_ASSERT(spline2);
spl2id = data->AddGObject(spline2);
data->AddLengthSpline(spline2->name(), toMM(spline2->GetLength()));
}
else
{
data->UpdatePoint(id, VPointF(point.x(), point.y(), pointName, mx, my));
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
Q_ASSERT(p != 0);
data->UpdateGObject(id, p);
spl1id = id + 1;
spl2id = id + 2;
VSpline spline1 = VSpline(data->DataPoints(), spl.GetP1(), spl1p2, spl1p3, id, spl.GetKcurve());
data->UpdateSpline(spl1id, spline1);
data->AddLengthSpline(spline1.name(), toMM(spline1.GetLength()));
VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve());
Q_ASSERT(spline1);
data->UpdateGObject(spl1id, spline1);
data->AddLengthSpline(spline1->name(), toMM(spline1->GetLength()));
VSpline spline2 = VSpline(data->DataPoints(), id, spl2p2, spl2p3, spl.GetP4(), spl.GetKcurve());
data->UpdateSpline(spl2id, spline2);
data->AddLengthSpline(spline2.name(), toMM(spline2.GetLength()));
VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve());
Q_ASSERT(spline2);
data->UpdateGObject(spl2id, spline2);
data->AddLengthSpline(spline2->name(), toMM(spline2->GetLength()));
if (parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
}
}
//VDrawTool::AddRecord(id, Tool::CutSplineTool, doc);
VDrawTool::AddRecord(id, Tool::CutSplineTool, doc);
if (parse == Document::FullParse)
{
VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, spl1id, spl2id, typeCreation);
@ -207,14 +217,14 @@ void VToolCutSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolCutSpline::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrLength, formula);
AddAttribute(domElement, AttrSpline, splineId);
@ -222,26 +232,40 @@ void VToolCutSpline::AddToFile()
AddToCalculation(domElement);
}
void VToolCutSpline::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my()));
domElement.setAttribute(AttrLength, formula);
domElement.setAttribute(AttrSpline, splineId);
}
}
void VToolCutSpline::RefreshGeometry()
{
RefreshSpline(firstSpline, spl1id, SimpleSpline::ForthPoint);
RefreshSpline(secondSpline, spl2id, SimpleSpline::FirstPoint);
VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id));
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<const VPointF *>(id));
}
void VToolCutSpline::RefreshSpline(VSimpleSpline *spline, qint64 splid, SimpleSpline::Translation tr)
{
VSpline spl = VAbstractTool::data.GetSpline(splid);
const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(splid);
QPainterPath path;
path.addPath(spl.GetPath());
path.addPath(spl->GetPath());
path.setFillRule( Qt::WindingFill );
if(tr == SimpleSpline::FirstPoint)
if (tr == SimpleSpline::FirstPoint)
{
path.translate(-spl.GetPointP1().toQPointF().x(), -spl.GetPointP1().toQPointF().y());
path.translate(-spl->GetP1().toQPointF().x(), -spl->GetP1().toQPointF().y());
}
else
{
path.translate(-spl.GetPointP4().toQPointF().x(), -spl.GetPointP4().toQPointF().y());
path.translate(-spl->GetP4().toQPointF().x(), -spl->GetP4().toQPointF().y());
}
spline->setPath(path);
}

View File

@ -119,6 +119,13 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief RefreshGeometry
*/
void RefreshGeometry();
private:
Q_DISABLE_COPY(VToolCutSpline)

View File

@ -60,15 +60,19 @@ VToolCutSplinePath::VToolCutSplinePath(VDomDocument *doc, VContainer *data, cons
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolCutSplinePath::setDialog()
{
Q_ASSERT(dialogCutSplinePath.isNull() == false);
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogCutSplinePath->setFormula(formula);
dialogCutSplinePath->setSplinePathId(splinePathId, id);
dialogCutSplinePath->setPointName(point.name());
dialogCutSplinePath->setPointName(point->name());
}
void VToolCutSplinePath::Create(QSharedPointer<DialogCutSplinePath> &dialog, VMainGraphicsScene *scene,
@ -85,7 +89,7 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VSplinePath splPath = data->GetSplinePath(splinePathId);
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(splinePathId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
@ -93,109 +97,119 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons
{
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
qint32 p1 = 0, p2 = 0;
QPointF point = splPath.CutSplinePath(toPixel(result), p1, p2, spl1p2, spl1p3, spl2p2, spl2p3);
QPointF point = splPath->CutSplinePath(toPixel(result), p1, p2, spl1p2, spl1p3, spl2p2, spl2p3);
qint64 id = _id;
qint64 splPath1id = 0;
qint64 splPath2id = 0;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(point.x(), point.y(), pointName, mx, my));
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
Q_ASSERT(p);
id = data->AddGObject(p);
splPath1id = id + 1;
splPath2id = id + 2;
VSplinePoint splP1 = splPath[p1];
VSplinePoint splP2 = splPath[p2];
VSpline spl1 = VSpline(data->DataPoints(), splP1.P(), spl1p2, spl1p3, id, splPath.getKCurve());
VSpline spl2 = VSpline(data->DataPoints(), id, spl2p2, spl2p3, splP2.P(), splPath.getKCurve());
VSplinePoint splP1 = splPath->at(p1);
VSplinePoint splP2 = splPath->at(p2);
VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p, splPath->getKCurve());
VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P(), splPath->getKCurve());
VSplinePath splPath1, splPath2;
splPath1.setPoints(data->DataPoints());
splPath2.setPoints(data->DataPoints());
for(qint32 i = 0; i < splPath.CountPoint(); i++)
VSplinePath *splPath1 = new VSplinePath();
Q_ASSERT(splPath1);
VSplinePath *splPath2 = new VSplinePath();
Q_ASSERT(splPath2);
for (qint32 i = 0; i < splPath->CountPoint(); i++)
{
if(i <= p1 && i < p2){
if(i == p1)
if (i <= p1 && i < p2)
{
if (i == p1)
{
splPath1.append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1(), spl1.GetKasm1()));
VSplinePoint cutPoint = VSplinePoint(id, spl1.GetKasm2(), spl1.GetAngle2()+180, spl2.GetKasm1());
splPath1.append(cutPoint);
splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1(), spl1.GetKasm1()));
VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2()+180,
spl2.GetKasm1());
splPath1->append(cutPoint);
continue;
}
splPath1.append(splPath[i]);
splPath1->append(splPath->at(i));
}
else
{
if(i == p2)
if (i == p2)
{
VSplinePoint cutPoint = VSplinePoint(id, spl1.GetKasm2(), spl2.GetAngle1(), spl2.GetKasm1());
splPath2.append(cutPoint);
splPath2.append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2()+180, splP2.KAsm2()));
VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1(), spl2.GetKasm1());
splPath2->append(cutPoint);
splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2()+180, splP2.KAsm2()));
continue;
}
splPath2.append(splPath[i]);
splPath2->append(splPath->at(i));
}
}
splPath1id = data->AddSplinePath(splPath1);
data->AddLengthSpline(splPath1.name(), toMM(splPath1.GetLength()));
splPath1id = data->AddGObject(splPath1);
data->AddLengthSpline(splPath1->name(), toMM(splPath1->GetLength()));
splPath2id = data->AddSplinePath(splPath2);
data->AddLengthSpline(splPath2.name(), toMM(splPath2.GetLength()));
splPath2id = data->AddGObject(splPath2);
data->AddLengthSpline(splPath2->name(), toMM(splPath2->GetLength()));
}
else
{
data->UpdatePoint(id, VPointF(point.x(), point.y(), pointName, mx, my));
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
Q_ASSERT(p);
data->UpdateGObject(id, p);
splPath1id = id + 1;
splPath2id = id + 2;
VSplinePoint splP1 = splPath[p1];
VSplinePoint splP2 = splPath[p2];
VSpline spl1 = VSpline(data->DataPoints(), splP1.P(), spl1p2, spl1p3, id, splPath.getKCurve());
VSpline spl2 = VSpline(data->DataPoints(), id, spl2p2, spl2p3, splP2.P(), splPath.getKCurve());
VSplinePoint splP1 = splPath->at(p1);
VSplinePoint splP2 = splPath->at(p2);
VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p, splPath->getKCurve());
VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P(), splPath->getKCurve());
VSplinePath splPath1, splPath2;
splPath1.setPoints(data->DataPoints());
splPath2.setPoints(data->DataPoints());
for(qint32 i = 0; i < splPath.CountPoint(); i++)
VSplinePath *splPath1 = new VSplinePath();
Q_ASSERT(splPath1 != 0);
VSplinePath *splPath2 = new VSplinePath();
Q_ASSERT(splPath2 != 0);
for (qint32 i = 0; i < splPath->CountPoint(); i++)
{
if(i <= p1 && i < p2){
if(i == p1)
if (i <= p1 && i < p2)
{
if (i == p1)
{
splPath1.append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1(), spl1.GetKasm1()));
VSplinePoint cutPoint = VSplinePoint(id, spl1.GetKasm2(), spl1.GetAngle2()+180, spl2.GetKasm1());
splPath1.append(cutPoint);
splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1(), spl1.GetKasm1()));
VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2()+180,
spl2.GetKasm1());
splPath1->append(cutPoint);
continue;
}
splPath1.append(splPath[i]);
splPath1->append(splPath->at(i));
}
else
{
if(i == p2)
if (i == p2)
{
VSplinePoint cutPoint = VSplinePoint(id, spl1.GetKasm2(), spl2.GetAngle1(), spl2.GetKasm1());
splPath2.append(cutPoint);
splPath2.append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2()+180, splP2.KAsm2()));
VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1(), spl2.GetKasm1());
splPath2->append(cutPoint);
splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2()+180, splP2.KAsm2()));
continue;
}
splPath2.append(splPath[i]);
splPath2->append(splPath->at(i));
}
}
data->UpdateSplinePath(splPath1id, splPath1);
data->AddLengthSpline(splPath1.name(), toMM(splPath1.GetLength()));
data->UpdateGObject(splPath1id, splPath1);
data->AddLengthSpline(splPath1->name(), toMM(splPath1->GetLength()));
data->UpdateSplinePath(splPath2id, splPath2);
data->AddLengthSpline(splPath2.name(), toMM(splPath2.GetLength()));
data->UpdateGObject(splPath2id, splPath2);
data->AddLengthSpline(splPath2->name(), toMM(splPath2->GetLength()));
if (parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
}
}
//VDrawTool::AddRecord(id, Tool::CutSplineTool, doc);
VDrawTool::AddRecord(id, Tool::CutSplinePathTool, doc);
if (parse == Document::FullParse)
{
VToolCutSplinePath *point = new VToolCutSplinePath(doc, data, id, formula, splinePathId, splPath1id,
@ -274,14 +288,14 @@ void VToolCutSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolCutSplinePath::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrLength, formula);
AddAttribute(domElement, AttrSplinePath, splinePathId);
@ -289,28 +303,42 @@ void VToolCutSplinePath::AddToFile()
AddToCalculation(domElement);
}
void VToolCutSplinePath::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my()));
domElement.setAttribute(AttrLength, formula);
domElement.setAttribute(AttrSplinePath, splinePathId);
}
}
void VToolCutSplinePath::RefreshGeometry()
{
RefreshSpline(firstSpline, splPath1id, SimpleSpline::ForthPoint);
RefreshSpline(secondSpline, splPath2id, SimpleSpline::FirstPoint);
VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id));
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<const VPointF *>(id));
}
void VToolCutSplinePath::RefreshSpline(VSimpleSpline *spline, qint64 splPathid, SimpleSpline::Translation tr)
{
VSplinePath splPath = VAbstractTool::data.GetSplinePath(splPathid);
const VSplinePath *splPath = VAbstractTool::data.GeometricObject<const VSplinePath *>(splPathid);
QPainterPath path;
path.addPath(splPath.GetPath());
path.addPath(splPath->GetPath());
path.setFillRule( Qt::WindingFill );
if(tr == SimpleSpline::FirstPoint)
if (tr == SimpleSpline::FirstPoint)
{
VSpline spl = splPath.GetSpline(1);
path.translate(-spl.GetPointP1().toQPointF().x(), -spl.GetPointP1().toQPointF().y());
VSpline spl = splPath->GetSpline(1);
path.translate(-spl.GetP1().toQPointF().x(), -spl.GetP1().toQPointF().y());
}
else
{
VSpline spl = splPath.GetSpline(splPath.Count());
path.translate(-spl.GetPointP4().toQPointF().x(), -spl.GetPointP4().toQPointF().y());
VSpline spl = splPath->GetSpline(splPath->Count());
path.translate(-spl.GetP4().toQPointF().x(), -spl.GetP4().toQPointF().y());
}
spline->setPath(path);
}

View File

@ -109,6 +109,13 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief RefreshGeometry
*/
void RefreshGeometry();
private:
Q_DISABLE_COPY(VToolCutSplinePath)

View File

@ -43,17 +43,21 @@ VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolEndLine::setDialog()
{
Q_ASSERT(dialogEndLine.isNull() == false);
VPointF p = VAbstractTool::data.GetPoint(id);
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogEndLine->setTypeLine(typeLine);
dialogEndLine->setFormula(formula);
dialogEndLine->setAngle(angle);
dialogEndLine->setBasePointId(basePointId, id);
dialogEndLine->setPointName(p.name());
dialogEndLine->setPointName(p->name());
}
void VToolEndLine::Create(QSharedPointer<DialogEndLine> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
@ -73,8 +77,8 @@ void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QStr
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VPointF basePoint = data->GetPoint(basePointId);
QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y()));
const VPointF *basePoint = data->GeometricObject<const VPointF *>(basePointId);
QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y()));
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
@ -85,12 +89,12 @@ void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QStr
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
id = data->AddGObject(new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
data->AddLine(basePointId, id);
}
else
{
data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
data->UpdateGObject(id, new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
data->AddLine(basePointId, id);
if (parse != Document::FullParse)
{
@ -150,14 +154,14 @@ void VToolEndLine::FullUpdateFromGui(int result)
void VToolEndLine::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrTypeLine, typeLine);
AddAttribute(domElement, AttrLength, formula);
@ -166,3 +170,19 @@ void VToolEndLine::AddToFile()
AddToCalculation(domElement);
}
void VToolEndLine::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my()));
domElement.setAttribute(AttrTypeLine, typeLine);
domElement.setAttribute(AttrLength, formula);
domElement.setAttribute(AttrAngle, angle);
domElement.setAttribute(AttrBasePoint, basePointId);
}
}

View File

@ -111,6 +111,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
private:
/**
* @brief dialogEndLine pointer to the dialog

View File

@ -41,17 +41,21 @@ VToolHeight::VToolHeight(VDomDocument *doc, VContainer *data, const qint64 &id,
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolHeight::setDialog()
{
Q_ASSERT(dialogHeight.isNull() == false);
VPointF p = VAbstractTool::data.GetPoint(id);
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogHeight->setTypeLine(typeLine);
dialogHeight->setBasePointId(basePointId, id);
dialogHeight->setP1LineId(p1LineId, id);
dialogHeight->setP2LineId(p2LineId, id);
dialogHeight->setPointName(p.name());
dialogHeight->setPointName(p->name());
}
void VToolHeight::Create(QSharedPointer<DialogHeight> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
@ -72,22 +76,22 @@ void VToolHeight::Create(const qint64 _id, const QString &pointName, const QStri
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VPointF basePoint = data->GetPoint(basePointId);
VPointF p1Line = data->GetPoint(p1LineId);
VPointF p2Line = data->GetPoint(p2LineId);
const VPointF *basePoint = data->GeometricObject<const VPointF *>(basePointId);
const VPointF *p1Line = data->GeometricObject<const VPointF *>(p1LineId);
const VPointF *p2Line = data->GeometricObject<const VPointF *>(p2LineId);
QPointF pHeight = FindPoint(QLineF(p1Line.toQPointF(), p2Line.toQPointF()), basePoint.toQPointF());
QPointF pHeight = FindPoint(QLineF(p1Line->toQPointF(), p2Line->toQPointF()), basePoint->toQPointF());
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(pHeight.x(), pHeight.y(), pointName, mx, my));
id = data->AddGObject(new VPointF(pHeight.x(), pHeight.y(), pointName, mx, my));
data->AddLine(basePointId, id);
data->AddLine(p1LineId, id);
data->AddLine(p2LineId, id);
}
else
{
data->UpdatePoint(id, VPointF(pHeight.x(), pHeight.y(), pointName, mx, my));
data->UpdateGObject(id, new VPointF(pHeight.x(), pHeight.y(), pointName, mx, my));
data->AddLine(basePointId, id);
data->AddLine(p1LineId, id);
data->AddLine(p2LineId, id);
@ -170,14 +174,14 @@ void VToolHeight::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolHeight::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrTypeLine, typeLine);
AddAttribute(domElement, AttrBasePoint, basePointId);
@ -187,3 +191,19 @@ void VToolHeight::AddToFile()
AddToCalculation(domElement);
}
void VToolHeight::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my()));
domElement.setAttribute(AttrTypeLine, typeLine);
domElement.setAttribute(AttrBasePoint, basePointId);
domElement.setAttribute(AttrP1Line, p1LineId);
domElement.setAttribute(AttrP2Line, p2LineId);
}
}

View File

@ -118,6 +118,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
private:
/**
* @brief dialogHeight

View File

@ -36,10 +36,10 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs
dialogLine(QSharedPointer<DialogLine>())
{
ignoreFullUpdate = true;
//Лінія
VPointF first = data->GetPoint(firstPoint);
VPointF second = data->GetPoint(secondPoint);
this->setLine(QLineF(first.toQPointF(), second.toQPointF()));
//Line
const VPointF *first = data->GeometricObject<const VPointF *>(firstPoint);
const VPointF *second = data->GeometricObject<const VPointF *>(secondPoint);
this->setLine(QLineF(first->toQPointF(), second->toQPointF()));
this->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setAcceptHoverEvents(true);
@ -49,6 +49,10 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolLine::setDialog()
@ -166,6 +170,16 @@ void VToolLine::AddToFile()
AddToCalculation(domElement);
}
void VToolLine::RefreshDataInFile()
{
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrFirstPoint, firstPoint);
domElement.setAttribute(AttrSecondPoint, secondPoint);
}
}
void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
@ -192,8 +206,8 @@ void VToolLine::RefreshGeometry()
firstPoint = domElement.attribute(AttrFirstPoint, "").toLongLong();
secondPoint = domElement.attribute(AttrSecondPoint, "").toLongLong();
}
VPointF first = VAbstractTool::data.GetPoint(firstPoint);
VPointF second = VAbstractTool::data.GetPoint(secondPoint);
this->setLine(QLineF(first.toQPointF(), second.toQPointF()));
const VPointF *first = VAbstractTool::data.GeometricObject<const VPointF *>(firstPoint);
const VPointF *second = VAbstractTool::data.GeometricObject<const VPointF *>(secondPoint);
this->setLine(QLineF(first->toQPointF(), second->toQPointF()));
this->setPen(QPen(currentColor, widthHairLine/factor));
}

View File

@ -120,6 +120,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief hoverMoveEvent
* @param event

View File

@ -42,17 +42,21 @@ VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, cons
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolLineIntersect::setDialog()
{
Q_ASSERT(dialogLineIntersect.isNull() == false);
VPointF p = VAbstractTool::data.GetPoint(id);
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogLineIntersect->setP1Line1(p1Line1);
dialogLineIntersect->setP2Line1(p2Line1);
dialogLineIntersect->setP1Line2(p1Line2);
dialogLineIntersect->setP2Line2(p2Line2);
dialogLineIntersect->setPointName(p.name());
dialogLineIntersect->setPointName(p->name());
}
void VToolLineIntersect::Create(QSharedPointer<DialogLineIntersect> &dialog, VMainGraphicsScene *scene,
@ -73,13 +77,13 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const
VDomDocument *doc, VContainer *data, const Document::Documents &parse,
const Tool::Sources &typeCreation)
{
VPointF p1Line1 = data->GetPoint(p1Line1Id);
VPointF p2Line1 = data->GetPoint(p2Line1Id);
VPointF p1Line2 = data->GetPoint(p1Line2Id);
VPointF p2Line2 = data->GetPoint(p2Line2Id);
const VPointF *p1Line1 = data->GeometricObject<const VPointF *>(p1Line1Id);
const VPointF *p2Line1 = data->GeometricObject<const VPointF *>(p2Line1Id);
const VPointF *p1Line2 = data->GeometricObject<const VPointF *>(p1Line2Id);
const VPointF *p2Line2 = data->GeometricObject<const VPointF *>(p2Line2Id);
QLineF line1(p1Line1.toQPointF(), p2Line1.toQPointF());
QLineF line2(p1Line2.toQPointF(), p2Line2.toQPointF());
QLineF line1(p1Line1->toQPointF(), p2Line1->toQPointF());
QLineF line2(p1Line2->toQPointF(), p2Line2->toQPointF());
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
@ -87,7 +91,7 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
@ -95,7 +99,7 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const
}
else
{
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
@ -133,7 +137,7 @@ void VToolLineIntersect::FullUpdateFromFile()
p1Line2 = domElement.attribute(AttrP1Line2, "").toLongLong();
p2Line2 = domElement.attribute(AttrP2Line2, "").toLongLong();
}
RefreshPointGeometry(VAbstractTool::data.GetPoint(id));
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<const VPointF *>(id));
}
void VToolLineIntersect::FullUpdateFromGui(int result)
@ -157,7 +161,7 @@ void VToolLineIntersect::FullUpdateFromGui(int result)
void VToolLineIntersect::SetFactor(qreal factor)
{
VDrawTool::SetFactor(factor);
RefreshPointGeometry(VAbstractTool::data.GetPoint(id));
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<const VPointF *>(id));
}
void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
@ -167,14 +171,14 @@ void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolLineIntersect::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrP1Line1, p1Line1);
AddAttribute(domElement, AttrP2Line1, p2Line1);
@ -184,6 +188,22 @@ void VToolLineIntersect::AddToFile()
AddToCalculation(domElement);
}
void VToolLineIntersect::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my()));
domElement.setAttribute(AttrP1Line1, p1Line1);
domElement.setAttribute(AttrP2Line1, p2Line1);
domElement.setAttribute(AttrP1Line2, p1Line2);
domElement.setAttribute(AttrP2Line2, p2Line2);
}
}
void VToolLineIntersect::RemoveReferens()
{
doc->DecrementReferens(p1Line1);

View File

@ -116,6 +116,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief RemoveReferens
*/

View File

@ -35,8 +35,8 @@ VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64
mainLine(0)
{
Q_ASSERT_X(basePointId > 0, Q_FUNC_INFO, "basePointId <= 0");
QPointF point1 = data->GetPoint(basePointId).toQPointF();
QPointF point2 = data->GetPoint(id).toQPointF();
QPointF point1 = data->GeometricObject<const VPointF *>(basePointId)->toQPointF();
QPointF point2 = data->GeometricObject<const VPointF *>(id)->toQPointF();
mainLine = new QGraphicsLineItem(QLineF(point1 - point2, QPointF()), this);
mainLine->setPen(QPen(Qt::black, widthHairLine/factor));
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
@ -67,9 +67,9 @@ void VToolLinePoint::ChangedActivDraw(const QString &newName)
void VToolLinePoint::RefreshGeometry()
{
mainLine->setPen(QPen(currentColor, widthHairLine/factor));
VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id));
QPointF point = VDrawTool::data.GetPoint(id).toQPointF();
QPointF basePoint = VDrawTool::data.GetPoint(basePointId).toQPointF();
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<const VPointF *>(id));
QPointF point = VDrawTool::data.GeometricObject<const VPointF *>(id)->toQPointF();
QPointF basePoint = VDrawTool::data.GeometricObject<const VPointF *>(basePointId)->toQPointF();
mainLine->setLine(QLineF(basePoint - point, QPointF()));
if (typeLine == TypeLineNone)
{

View File

@ -42,19 +42,22 @@ VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id,
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolNormal::setDialog()
{
Q_ASSERT(dialogNormal.isNull() == false);
VPointF p = VAbstractTool::data.GetPoint(id);
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogNormal->setTypeLine(typeLine);
dialogNormal->setFormula(formula);
dialogNormal->setAngle(angle);
dialogNormal->setFirstPointId(basePointId, id);
dialogNormal->setSecondPointId(secondPointId, id);
dialogNormal->setPointName(p.name());
dialogNormal->setPointName(p->name());
}
void VToolNormal::Create(QSharedPointer<DialogNormal> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
@ -76,24 +79,24 @@ void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64
VDomDocument *doc, VContainer *data, const Document::Documents &parse,
const Tool::Sources &typeCreation)
{
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
const VPointF *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if (errorMsg.isEmpty())
{
QPointF fPoint = VToolNormal::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
QPointF fPoint = VToolNormal::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
toPixel(result), angle);
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
}
else
{
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
if (parse != Document::FullParse)
{
@ -172,14 +175,14 @@ void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolNormal::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrTypeLine, typeLine);
AddAttribute(domElement, AttrLength, formula);
@ -190,6 +193,23 @@ void VToolNormal::AddToFile()
AddToCalculation(domElement);
}
void VToolNormal::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my()));
domElement.setAttribute(AttrTypeLine, typeLine);
domElement.setAttribute(AttrLength, formula);
domElement.setAttribute(AttrAngle, angle);
domElement.setAttribute(AttrFirstPoint, basePointId);
domElement.setAttribute(AttrSecondPoint, secondPointId);
}
}
void VToolNormal::RemoveReferens()
{
doc->DecrementReferens(secondPointId);

View File

@ -130,6 +130,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief RemoveReferens
*/

View File

@ -40,18 +40,19 @@ VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphics
this->setBrush(QBrush(Qt::NoBrush));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setAcceptHoverEvents(true);
RefreshPointGeometry(VAbstractTool::data.GetPoint(id));
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<const VPointF *>(id));
}
void VToolPoint::NameChangePosition(const QPointF &pos)
{
VPointF point = VAbstractTool::data.GetPoint(id);
VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject<const VPointF *>(id));
Q_ASSERT(point != 0);
QPointF p = pos - this->pos();
point.setMx(p.x());
point.setMy(p.y());
point->setMx(p.x());
point->setMy(p.y());
RefreshLine();
UpdateNamePosition(point.mx(), point.my());
VAbstractTool::data.UpdatePoint(id, point);
UpdateNamePosition(point->mx(), point->my());
VAbstractTool::data.UpdateGObject(id, point);
}
void VToolPoint::UpdateNamePosition(qreal mx, qreal my)
@ -59,8 +60,8 @@ void VToolPoint::UpdateNamePosition(qreal mx, qreal my)
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrMx, QString().setNum(toMM(mx)));
domElement.setAttribute(AttrMy, QString().setNum(toMM(my)));
domElement.setAttribute(AttrMx, toMM(mx));
domElement.setAttribute(AttrMy, toMM(my));
emit toolhaveChange();
}
}
@ -98,7 +99,7 @@ void VToolPoint::ShowTool(qint64 id, Qt::GlobalColor color, bool enable)
void VToolPoint::SetFactor(qreal factor)
{
VDrawTool::SetFactor(factor);
RefreshPointGeometry(VAbstractTool::data.GetPoint(id));
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<const VPointF *>(id));
}
void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)

View File

@ -42,17 +42,21 @@ VToolPointOfContact::VToolPointOfContact(VDomDocument *doc, VContainer *data, co
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolPointOfContact::setDialog()
{
Q_ASSERT(dialogPointOfContact.isNull() == false);
VPointF p = VAbstractTool::data.GetPoint(id);
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogPointOfContact->setRadius(radius);
dialogPointOfContact->setCenter(center, id);
dialogPointOfContact->setFirstPoint(firstPointId, id);
dialogPointOfContact->setSecondPoint(secondPointId, id);
dialogPointOfContact->setPointName(p.name());
dialogPointOfContact->setPointName(p->name());
}
QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF &center, const QPointF &firstPoint,
@ -99,28 +103,28 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VPointF centerP = data->GetPoint(center);
VPointF firstP = data->GetPoint(firstPointId);
VPointF secondP = data->GetPoint(secondPointId);
const VPointF *centerP = data->GeometricObject<const VPointF *>(center);
const VPointF *firstP = data->GeometricObject<const VPointF *>(firstPointId);
const VPointF *secondP = data->GeometricObject<const VPointF *>(secondPointId);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(radius, &errorMsg);
if (errorMsg.isEmpty())
{
QPointF fPoint = VToolPointOfContact::FindPoint(toPixel(result), centerP.toQPointF(),
firstP.toQPointF(), secondP.toQPointF());
QPointF fPoint = VToolPointOfContact::FindPoint(toPixel(result), centerP->toQPointF(),
firstP->toQPointF(), secondP->toQPointF());
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
data->AddLine(secondPointId, id);
data->AddLine(center, id);
}
else
{
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
data->AddLine(secondPointId, id);
data->AddLine(center, id);
@ -156,7 +160,7 @@ void VToolPointOfContact::FullUpdateFromFile()
firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong();
secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong();
}
RefreshPointGeometry(VAbstractTool::data.GetPoint(id));
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<const VPointF *>(id));
}
void VToolPointOfContact::FullUpdateFromGui(int result)
@ -180,7 +184,7 @@ void VToolPointOfContact::FullUpdateFromGui(int result)
void VToolPointOfContact::SetFactor(qreal factor)
{
VDrawTool::SetFactor(factor);
RefreshPointGeometry(VAbstractTool::data.GetPoint(id));
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<const VPointF *>(id));
}
void VToolPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
@ -190,14 +194,14 @@ void VToolPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event
void VToolPointOfContact::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrRadius, radius);
AddAttribute(domElement, AttrCenter, center);
@ -207,6 +211,22 @@ void VToolPointOfContact::AddToFile()
AddToCalculation(domElement);
}
void VToolPointOfContact::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my()));
domElement.setAttribute(AttrRadius, radius);
domElement.setAttribute(AttrCenter, center);
domElement.setAttribute(AttrFirstPoint, firstPointId);
domElement.setAttribute(AttrSecondPoint, secondPointId);
}
}
void VToolPointOfContact::RemoveReferens()
{
doc->DecrementReferens(center);

View File

@ -126,6 +126,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief RemoveReferens
*/

View File

@ -41,15 +41,19 @@ VToolPointOfIntersection::VToolPointOfIntersection(VDomDocument *doc, VContainer
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolPointOfIntersection::setDialog()
{
Q_ASSERT(dialogPointOfIntersection.isNull() == false);
VPointF p = VAbstractTool::data.GetPoint(id);
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogPointOfIntersection->setFirstPointId(firstPointId, id);
dialogPointOfIntersection->setSecondPointId(secondPointId, id);
dialogPointOfIntersection->setPointName(p.name());
dialogPointOfIntersection->setPointName(p->name());
}
void VToolPointOfIntersection::Create(QSharedPointer<DialogPointOfIntersection> &dialog, VMainGraphicsScene *scene,
@ -66,18 +70,18 @@ void VToolPointOfIntersection::Create(const qint64 _id, const QString &pointName
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
const VPointF *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
QPointF point(firstPoint.x(), secondPoint.y());
QPointF point(firstPoint->x(), secondPoint->y());
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(point.x(), point.y(), pointName, mx, my));
id = data->AddGObject(new VPointF(point.x(), point.y(), pointName, mx, my));
}
else
{
data->UpdatePoint(id, VPointF(point.x(), point.y(), pointName, mx, my));
data->UpdateGObject(id, new VPointF(point.x(), point.y(), pointName, mx, my));
if (parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
@ -106,7 +110,7 @@ void VToolPointOfIntersection::FullUpdateFromFile()
firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong();
secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong();
}
VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id));
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<const VPointF *>(id));
}
void VToolPointOfIntersection::FullUpdateFromGui(int result)
@ -138,17 +142,31 @@ void VToolPointOfIntersection::contextMenuEvent(QGraphicsSceneContextMenuEvent *
void VToolPointOfIntersection::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrFirstPoint, firstPointId);
AddAttribute(domElement, AttrSecondPoint, secondPointId);
AddToCalculation(domElement);
}
void VToolPointOfIntersection::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrName, toMM(point->mx()));
domElement.setAttribute(AttrName, toMM(point->my()));
domElement.setAttribute(AttrFirstPoint, firstPointId);
domElement.setAttribute(AttrSecondPoint, secondPointId);
}
}

View File

@ -111,6 +111,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
private:
Q_DISABLE_COPY(VToolPointOfIntersection)
/**

View File

@ -42,18 +42,22 @@ VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, cons
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolShoulderPoint::setDialog()
{
Q_ASSERT(dialogShoulderPoint.isNull() == false);
VPointF p = VAbstractTool::data.GetPoint(id);
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogShoulderPoint->setTypeLine(typeLine);
dialogShoulderPoint->setFormula(formula);
dialogShoulderPoint->setP1Line(basePointId, id);
dialogShoulderPoint->setP2Line(p2Line, id);
dialogShoulderPoint->setPShoulder(pShoulder, id);
dialogShoulderPoint->setPointName(p.name());
dialogShoulderPoint->setPointName(p->name());
}
QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder,
@ -101,27 +105,27 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VPointF firstPoint = data->GetPoint(p1Line);
VPointF secondPoint = data->GetPoint(p2Line);
VPointF shoulderPoint = data->GetPoint(pShoulder);
const VPointF *firstPoint = data->GeometricObject<const VPointF *>(p1Line);
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(p2Line);
const VPointF *shoulderPoint = data->GeometricObject<const VPointF *>(pShoulder);
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if (errorMsg.isEmpty())
{
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
shoulderPoint.toQPointF(), toPixel(result));
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
shoulderPoint->toQPointF(), toPixel(result));
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
}
else
{
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
if (parse != Document::FullParse)
@ -193,14 +197,14 @@ void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolShoulderPoint::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrTypeLine, typeLine);
AddAttribute(domElement, AttrLength, formula);
@ -211,6 +215,23 @@ void VToolShoulderPoint::AddToFile()
AddToCalculation(domElement);
}
void VToolShoulderPoint::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrName, toMM(point->mx()));
domElement.setAttribute(AttrName, toMM(point->my()));
domElement.setAttribute(AttrTypeLine, typeLine);
domElement.setAttribute(AttrLength, formula);
domElement.setAttribute(AttrP1Line, basePointId);
domElement.setAttribute(AttrP2Line, p2Line);
domElement.setAttribute(AttrPShoulder, pShoulder);
}
}
void VToolShoulderPoint::RemoveReferens()
{
doc->DecrementReferens(p2Line);

View File

@ -128,6 +128,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief RemoveReferens
*/

View File

@ -41,31 +41,49 @@ VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolSinglePoint::setDialog()
{
Q_ASSERT(dialogSinglePoint.isNull() == false);
VPointF p = VAbstractTool::data.GetPoint(id);
dialogSinglePoint->setData(p.name(), p.toQPointF());
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogSinglePoint->setData(p->name(), p->toQPointF());
}
void VToolSinglePoint::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrX, toMM(point.x()));
AddAttribute(domElement, AttrY, toMM(point.y()));
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrX, toMM(point->x()));
AddAttribute(domElement, AttrY, toMM(point->y()));
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddToCalculation(domElement);
}
void VToolSinglePoint::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrX, QString().setNum(toMM(point->x())));
domElement.setAttribute(AttrY, QString().setNum(toMM(point->y())));
domElement.setAttribute(AttrMx, QString().setNum(toMM(point->mx())));
domElement.setAttribute(AttrMy, QString().setNum(toMM(point->my())));
}
}
QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionChange && scene())
@ -112,7 +130,8 @@ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event
void VToolSinglePoint::FullUpdateFromFile()
{
RefreshPointGeometry(VAbstractTool::data.GetPoint(id));
VPointF point = *VAbstractTool::data.GeometricObject<const VPointF *>(id);
RefreshPointGeometry(point);
}
void VToolSinglePoint::FullUpdateFromGui(int result)
@ -151,5 +170,5 @@ void VToolSinglePoint::ChangedActivDraw(const QString &newName)
void VToolSinglePoint::SetFactor(qreal factor)
{
VDrawTool::SetFactor(factor);
RefreshPointGeometry(VAbstractTool::data.GetPoint(id));
RefreshPointGeometry(*(VAbstractTool::data.GeometricObject<const VPointF *>(id)));
}

View File

@ -92,6 +92,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief itemChange
* @param change

View File

@ -39,25 +39,25 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, const T
{
ignoreFullUpdate = true;
VSpline spl = data->GetSpline(id);
const VSpline *spl = data->GeometricObject<const VSpline *>(id);
QPainterPath path;
path.addPath(spl.GetPath());
path.addPath(spl->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
this->setPen(QPen(Qt::black, widthHairLine/factor));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setAcceptHoverEvents(true);
VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePoint::FirstPoint, spl.GetP2(),
spl.GetPointP1().toQPointF(), this);
VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePoint::FirstPoint, spl->GetP2(),
spl->GetP1().toQPointF(), this);
connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
connect(this, &VToolSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine);
connect(this, &VToolSpline::setEnabledPoint, controlPoint1, &VControlPointSpline::setEnabledPoint);
controlPoints.append(controlPoint1);
VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePoint::LastPoint, spl.GetP3(),
spl.GetPointP4().toQPointF(), this);
VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePoint::LastPoint, spl->GetP3(),
spl->GetP4().toQPointF(), this);
connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
connect(this, &VToolSpline::RefreshLine, controlPoint2, &VControlPointSpline::RefreshLine);
@ -68,19 +68,23 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, const T
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolSpline::setDialog()
{
Q_ASSERT(dialogSpline.isNull() == false);
VSpline spl = VAbstractTool::data.GetSpline(id);
dialogSpline->setP1(spl.GetP1());
dialogSpline->setP4(spl.GetP4());
dialogSpline->setAngle1(spl.GetAngle1());
dialogSpline->setAngle2(spl.GetAngle2());
dialogSpline->setKAsm1(spl.GetKasm1());
dialogSpline->setKAsm2(spl.GetKasm2());
dialogSpline->setKCurve(spl.GetKcurve());
const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(id);
dialogSpline->setP1(spl->GetP1().id());
dialogSpline->setP4(spl->GetP4().id());
dialogSpline->setAngle1(spl->GetAngle1());
dialogSpline->setAngle2(spl->GetAngle2());
dialogSpline->setKAsm1(spl->GetKasm1());
dialogSpline->setKAsm2(spl->GetKasm2());
dialogSpline->setKCurve(spl->GetKcurve());
}
void VToolSpline::Create(QSharedPointer<DialogSpline> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
@ -102,17 +106,20 @@ void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, c
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VSpline spline = VSpline(data->DataPoints(), p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve);
VPointF point1 = *data->GeometricObject<const VPointF *>(p1);
VPointF point4 = *data->GeometricObject<const VPointF *>(p4);
VSpline *spline = new VSpline(point1, point4, angle1, angle2, kAsm1, kAsm2, kCurve);
Q_ASSERT(spline != 0);
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddSpline(spline);
data->AddLengthSpline(spline.name(), toMM(spline.GetLength()));
id = data->AddGObject(spline);
data->AddLengthSpline(spline->name(), toMM(spline->GetLength()));
}
else
{
data->UpdateSpline(id, spline);
data->AddLengthSpline(spline.name(), toMM(spline.GetLength()));
data->UpdateGObject(id, spline);
data->AddLengthSpline(spline->name(), toMM(spline->GetLength()));
if (parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
@ -141,8 +148,9 @@ void VToolSpline::FullUpdateFromGui(int result)
{
if (result == QDialog::Accepted)
{
VSpline spl = VSpline (VAbstractTool::data.DataPoints(), dialogSpline->getP1(),
dialogSpline->getP4(), dialogSpline->getAngle1(), dialogSpline->getAngle2(),
VPointF point1 = *VAbstractTool::data.GeometricObject<const VPointF *>(dialogSpline->getP1());
VPointF point4 = *VAbstractTool::data.GeometricObject<const VPointF *>(dialogSpline->getP4());
VSpline spl = VSpline (point1, point4, dialogSpline->getAngle1(), dialogSpline->getAngle2(),
dialogSpline->getKAsm1(), dialogSpline->getKAsm2(), dialogSpline->getKCurve());
disconnect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this,
@ -156,18 +164,17 @@ void VToolSpline::FullUpdateFromGui(int result)
connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
spl = VSpline (VAbstractTool::data.DataPoints(), dialogSpline->getP1(), controlPoints[0]->pos(),
controlPoints[1]->pos(), dialogSpline->getP4(), dialogSpline->getKCurve());
spl = VSpline (point1, controlPoints[0]->pos(), controlPoints[1]->pos(), point4, dialogSpline->getKCurve());
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrPoint1, QString().setNum(spl.GetP1()));
domElement.setAttribute(AttrPoint4, QString().setNum(spl.GetP4()));
domElement.setAttribute(AttrAngle1, QString().setNum(spl.GetAngle1()));
domElement.setAttribute(AttrAngle2, QString().setNum(spl.GetAngle2()));
domElement.setAttribute(AttrKAsm1, QString().setNum(spl.GetKasm1()));
domElement.setAttribute(AttrKAsm2, QString().setNum(spl.GetKasm2()));
domElement.setAttribute(AttrKCurve, QString().setNum(spl.GetKcurve()));
domElement.setAttribute(AttrPoint1, spl.GetP1().id());
domElement.setAttribute(AttrPoint4, spl.GetP4().id());
domElement.setAttribute(AttrAngle1, spl.GetAngle1());
domElement.setAttribute(AttrAngle2, spl.GetAngle2());
domElement.setAttribute(AttrKAsm1, spl.GetKasm1());
domElement.setAttribute(AttrKAsm2, spl.GetKasm2());
domElement.setAttribute(AttrKCurve, spl.GetKcurve());
emit FullUpdateTree();
}
}
@ -178,14 +185,15 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const Sp
const QPointF &pos)
{
Q_UNUSED(indexSpline);
VSpline spl = VAbstractTool::data.GetSpline(id);
const VSpline *spline = VAbstractTool::data.GeometricObject<const VSpline *>(id);
VSpline spl;
if (position == SplinePoint::FirstPoint)
{
spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());
spl = VSpline(spline->GetP1(), pos, spline->GetP3(), spline->GetP4(), spline->GetKcurve());
}
else
{
spl.ModifiSpl (spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve());
spl = VSpline(spline->GetP1(), spline->GetP2(), pos, spline->GetP4(), spline->GetKcurve());
}
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
@ -206,22 +214,38 @@ void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolSpline::AddToFile()
{
VSpline spl = VAbstractTool::data.GetSpline(id);
const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrPoint1, spl.GetP1());
AddAttribute(domElement, AttrPoint4, spl.GetP4());
AddAttribute(domElement, AttrAngle1, spl.GetAngle1());
AddAttribute(domElement, AttrAngle2, spl.GetAngle2());
AddAttribute(domElement, AttrKAsm1, spl.GetKasm1());
AddAttribute(domElement, AttrKAsm2, spl.GetKasm2());
AddAttribute(domElement, AttrKCurve, spl.GetKcurve());
AddAttribute(domElement, AttrPoint1, spl->GetP1().id());
AddAttribute(domElement, AttrPoint4, spl->GetP4().id());
AddAttribute(domElement, AttrAngle1, spl->GetAngle1());
AddAttribute(domElement, AttrAngle2, spl->GetAngle2());
AddAttribute(domElement, AttrKAsm1, spl->GetKasm1());
AddAttribute(domElement, AttrKAsm2, spl->GetKasm2());
AddAttribute(domElement, AttrKCurve, spl->GetKcurve());
AddToCalculation(domElement);
}
void VToolSpline::RefreshDataInFile()
{
const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrPoint1, spl->GetP1().id());
domElement.setAttribute(AttrPoint4, spl->GetP4().id());
domElement.setAttribute(AttrAngle1, spl->GetAngle1());
domElement.setAttribute(AttrAngle2, spl->GetAngle2());
domElement.setAttribute(AttrKAsm1, spl->GetKasm1());
domElement.setAttribute(AttrKAsm2, spl->GetKasm2());
domElement.setAttribute(AttrKCurve, spl->GetKcurve());
}
}
void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
@ -245,32 +269,32 @@ void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void VToolSpline::RemoveReferens()
{
VSpline spl = VAbstractTool::data.GetSpline(id);
doc->DecrementReferens(spl.GetP1());
doc->DecrementReferens(spl.GetP4());
const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(id);
doc->DecrementReferens(spl->GetP1().id());
doc->DecrementReferens(spl->GetP4().id());
}
void VToolSpline::RefreshGeometry()
{
this->setPen(QPen(currentColor, widthHairLine/factor));
VSpline spl = VAbstractTool::data.GetSpline(id);
const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(id);
QPainterPath path;
path.addPath(spl.GetPath());
path.addPath(spl->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
QPointF splinePoint = VAbstractTool::data.GetPoint(spl.GetP1()).toQPointF();
QPointF controlPoint = spl.GetP2();
QPointF splinePoint = VAbstractTool::data.GeometricObject<const VPointF *>(spl->GetP1().id())->toQPointF();
QPointF controlPoint = spl->GetP2();
emit RefreshLine(1, SplinePoint::FirstPoint, controlPoint, splinePoint);
splinePoint = VAbstractTool::data.GetPoint(spl.GetP4()).toQPointF();
controlPoint = spl.GetP3();
splinePoint = VAbstractTool::data.GeometricObject<const VPointF *>(spl->GetP4().id())->toQPointF();
controlPoint = spl->GetP3();
emit RefreshLine(1, SplinePoint::LastPoint, controlPoint, splinePoint);
disconnect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
disconnect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
controlPoints[0]->setPos(spl.GetP2());
controlPoints[1]->setPos(spl.GetP3());
controlPoints[0]->setPos(spl->GetP2());
controlPoints[1]->setPos(spl->GetP3());
connect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,

View File

@ -153,6 +153,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile ();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief mouseReleaseEvent
* @param event

View File

@ -37,28 +37,27 @@ VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id,
controlPoints(QVector<VControlPointSpline *>())
{
ignoreFullUpdate = true;
VSplinePath splPath = data->GetSplinePath(id);
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(id);
QPainterPath path;
path.addPath(splPath.GetPath());
path.addPath(splPath->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
this->setPen(QPen(Qt::black, widthHairLine/factor));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setAcceptHoverEvents(true);
for (qint32 i = 1; i<=splPath.Count(); ++i)
for (qint32 i = 1; i<=splPath->Count(); ++i)
{
VSpline spl = splPath.GetSpline(i);
VSpline spl = splPath->GetSpline(i);
VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePoint::FirstPoint, spl.GetP2(),
spl.GetPointP1().toQPointF(), this);
spl.GetP1().toQPointF(), this);
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
controlPoints.append(controlPoint);
controlPoint = new VControlPointSpline(i, SplinePoint::LastPoint, spl.GetP3(),
spl.GetPointP4().toQPointF(), this);
controlPoint = new VControlPointSpline(i, SplinePoint::LastPoint, spl.GetP3(), spl.GetP4().toQPointF(), this);
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
@ -69,40 +68,45 @@ VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id,
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolSplinePath::setDialog()
{
Q_ASSERT(dialogSplinePath.isNull() == false);
VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
dialogSplinePath->SetPath(splPath);
const VSplinePath *splPath = VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
dialogSplinePath->SetPath(*splPath);
}
void VToolSplinePath::Create(QSharedPointer<DialogSplinePath> &dialog, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data)
{
VSplinePath path = dialog->GetPath();
for (qint32 i = 0; i < path.CountPoint(); ++i)
VSplinePath *path = new VSplinePath(dialog->GetPath());
Q_ASSERT(path);
for (qint32 i = 0; i < path->CountPoint(); ++i)
{
doc->IncrementReferens(path[i].P());
doc->IncrementReferens((*path)[i].P().id());
}
Create(0, path, scene, doc, data, Document::FullParse, Tool::FromGui);
}
void VToolSplinePath::Create(const qint64 _id, const VSplinePath &path, VMainGraphicsScene *scene,
void VToolSplinePath::Create(const qint64 _id, VSplinePath *path, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data, const Document::Documents &parse,
const Tool::Sources &typeCreation)
{
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddSplinePath(path);
data->AddLengthSpline(path.name(), toMM(path.GetLength()));
id = data->AddGObject(path);
data->AddLengthSpline(path->name(), toMM(path->GetLength()));
}
else
{
data->UpdateSplinePath(id, path);
data->AddLengthSpline(path.name(), toMM(path.GetLength()));
data->UpdateGObject(id, path);
data->AddLengthSpline(path->name(), toMM(path->GetLength()));
if (parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
@ -145,8 +149,8 @@ void VToolSplinePath::FullUpdateFromGui(int result)
connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
spl = VSpline (VAbstractTool::data.DataPoints(), spl.GetP1(), controlPoints[j-2]->pos(),
controlPoints[j-1]->pos(), spl.GetP4(), splPath.getKCurve());
spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(),
splPath.getKCurve());
CorectControlPoints(spl, splPath, i);
CorectControlPoints(spl, splPath, i);
@ -166,15 +170,15 @@ void VToolSplinePath::FullUpdateFromGui(int result)
void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, const SplinePoint::Position &position,
const QPointF &pos)
{
VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
VSpline spl = splPath.GetSpline(indexSpline);
if (position == SplinePoint::FirstPoint)
{
spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());
spl = VSpline(spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());
}
else
{
spl.ModifiSpl (spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve());
spl = VSpline(spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve());
}
CorectControlPoints(spl, splPath, indexSpline);
@ -210,10 +214,10 @@ void VToolSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path)
if (domElement.isNull() == false)
{
VSplinePoint p = path[i];
domElement.setAttribute(AttrPSpline, QString().setNum(p.P()));
domElement.setAttribute(AttrKAsm1, QString().setNum(p.KAsm1()));
domElement.setAttribute(AttrKAsm2, QString().setNum(p.KAsm2()));
domElement.setAttribute(AttrAngle, QString().setNum(p.Angle2()));
domElement.setAttribute(AttrPSpline, p.P().id());
domElement.setAttribute(AttrKAsm1, p.KAsm1());
domElement.setAttribute(AttrKAsm2, p.KAsm2());
domElement.setAttribute(AttrAngle, p.Angle2());
}
}
}
@ -256,7 +260,7 @@ void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolSplinePath::AddToFile()
{
VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
@ -271,11 +275,44 @@ void VToolSplinePath::AddToFile()
AddToCalculation(domElement);
}
void VToolSplinePath::RefreshDataInFile()
{
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
for (qint32 i = 1; i<=splPath.Count(); ++i)
{
VSpline spl = splPath.GetSpline(i);
qint32 j = i*2;
disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
controlPoints[j-2]->setPos(spl.GetP2());
controlPoints[j-1]->setPos(spl.GetP3());
connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(),
splPath.getKCurve());
CorectControlPoints(spl, splPath, i);
CorectControlPoints(spl, splPath, i);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrKCurve, QString().setNum(splPath.getKCurve()));
UpdatePathPoint(domElement, splPath);
}
}
}
void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint)
{
QDomElement pathPoint = doc->createElement(AttrPathPoint);
AddAttribute(pathPoint, AttrPSpline, splPoint.P());
AddAttribute(pathPoint, AttrPSpline, splPoint.P().id());
AddAttribute(pathPoint, AttrKAsm1, splPoint.KAsm1());
AddAttribute(pathPoint, AttrKAsm2, splPoint.KAsm2());
AddAttribute(pathPoint, AttrAngle, splPoint.Angle2());
@ -306,28 +343,28 @@ void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void VToolSplinePath::RemoveReferens()
{
VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
for (qint32 i = 0; i < splPath.Count(); ++i)
{
doc->DecrementReferens(splPath[i].P());
doc->DecrementReferens(splPath[i].P().id());
}
}
void VToolSplinePath::RefreshGeometry()
{
this->setPen(QPen(currentColor, widthHairLine/factor));
VSplinePath splPath = VAbstractTool::data.GetSplinePath(id);
const VSplinePath *splPath = VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
QPainterPath path;
path.addPath(splPath.GetPath());
path.addPath(splPath->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
for (qint32 i = 1; i<=splPath.Count(); ++i)
for (qint32 i = 1; i<=splPath->Count(); ++i)
{
VSpline spl = splPath.GetSpline(i);
QPointF splinePoint = spl.GetPointP1().toQPointF();
VSpline spl = splPath->GetSpline(i);
QPointF splinePoint = spl.GetP1().toQPointF();
QPointF controlPoint = spl.GetP2();
emit RefreshLine(i, SplinePoint::FirstPoint, controlPoint, splinePoint);
splinePoint = spl.GetPointP4().toQPointF();
splinePoint = spl.GetP4().toQPointF();
controlPoint = spl.GetP3();
emit RefreshLine(i, SplinePoint::LastPoint, controlPoint, splinePoint);

View File

@ -74,7 +74,7 @@ public:
* @param parse
* @param typeCreation
*/
static void Create(const qint64 _id, const VSplinePath &path, VMainGraphicsScene *scene,
static void Create(const qint64 _id, VSplinePath *path, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data, const Document::Documents &parse,
const Tool::Sources &typeCreation);
/**
@ -145,6 +145,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
/**
* @brief mouseReleaseEvent
* @param event

View File

@ -41,17 +41,21 @@ VToolTriangle::VToolTriangle(VDomDocument *doc, VContainer *data, const qint64 &
{
AddToFile();
}
else
{
RefreshDataInFile();
}
}
void VToolTriangle::setDialog()
{
Q_ASSERT(dialogTriangle.isNull() == false);
VPointF p = VAbstractTool::data.GetPoint(id);
const VPointF *p = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogTriangle->setAxisP1Id(axisP1Id, id);
dialogTriangle->setAxisP2Id(axisP2Id, id);
dialogTriangle->setFirstPointId(firstPointId, id);
dialogTriangle->setSecondPointId(secondPointId, id);
dialogTriangle->setPointName(p.name());
dialogTriangle->setPointName(p->name());
}
void VToolTriangle::Create(QSharedPointer<DialogTriangle> &dialog, VMainGraphicsScene *scene,
@ -71,21 +75,21 @@ void VToolTriangle::Create(const qint64 _id, const QString &pointName, const qin
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VPointF axisP1 = data->GetPoint(axisP1Id);
VPointF axisP2 = data->GetPoint(axisP2Id);
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
const VPointF *axisP1 = data->GeometricObject<const VPointF *>(axisP1Id);
const VPointF *axisP2 = data->GeometricObject<const VPointF *>(axisP2Id);
const VPointF *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
QPointF point = FindPoint(axisP1.toQPointF(), axisP2.toQPointF(), firstPoint.toQPointF(),
secondPoint.toQPointF());
QPointF point = FindPoint(axisP1->toQPointF(), axisP2->toQPointF(), firstPoint->toQPointF(),
secondPoint->toQPointF());
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
id = data->AddPoint(VPointF(point.x(), point.y(), pointName, mx, my));
id = data->AddGObject(new VPointF(point.x(), point.y(), pointName, mx, my));
}
else
{
data->UpdatePoint(id, VPointF(point.x(), point.y(), pointName, mx, my));
data->UpdateGObject(id, new VPointF(point.x(), point.y(), pointName, mx, my));
if (parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
@ -159,7 +163,7 @@ void VToolTriangle::FullUpdateFromFile()
firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong();
secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong();
}
VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id));
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<const VPointF *>(id));
}
void VToolTriangle::FullUpdateFromGui(int result)
@ -196,14 +200,14 @@ void VToolTriangle::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void VToolTriangle::AddToFile()
{
VPointF point = VAbstractTool::data.GetPoint(id);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->createElement(TagName);
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrName, point.name());
AddAttribute(domElement, AttrMx, toMM(point.mx()));
AddAttribute(domElement, AttrMy, toMM(point.my()));
AddAttribute(domElement, AttrName, point->name());
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
AddAttribute(domElement, AttrAxisP1, axisP1Id);
AddAttribute(domElement, AttrAxisP2, axisP2Id);
@ -212,3 +216,19 @@ void VToolTriangle::AddToFile()
AddToCalculation(domElement);
}
void VToolTriangle::RefreshDataInFile()
{
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrName, point->name());
domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my()));
domElement.setAttribute(AttrAxisP1, axisP1Id);
domElement.setAttribute(AttrAxisP2, axisP2Id);
domElement.setAttribute(AttrFirstPoint, firstPointId);
domElement.setAttribute(AttrSecondPoint, secondPointId);
}
}

View File

@ -125,6 +125,10 @@ protected:
* @brief AddToFile
*/
virtual void AddToFile();
/**
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
*/
virtual void RefreshDataInFile();
private:
Q_DISABLE_COPY(VToolTriangle)
/**

View File

@ -30,9 +30,11 @@
#include <QDebug>
const QString VAbstractNode::AttrIdObject = QStringLiteral("idObject");
const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool");
VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, qint64 id, qint64 idNode, QObject *parent)
: VAbstractTool(doc, data, id, parent), idNode(idNode)
VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &idNode,
const qint64 &idTool, QObject *parent)
: VAbstractTool(doc, data, id, parent), idNode(idNode), idTool(idTool)
{
_referens = 0;
}

Some files were not shown because too many files have changed in this diff Show More