diff --git a/Valentina.pro b/Valentina.pro index 496310cf8..fb54f3f3c 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -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 -} +} diff --git a/share/resources/cursor.qrc b/share/resources/cursor.qrc index 0af6dcf3b..4e9cd2b99 100644 --- a/share/resources/cursor.qrc +++ b/share/resources/cursor.qrc @@ -17,5 +17,6 @@ cursor/pointofintersect_cursor.png cursor/spline_cut_point_cursor.png cursor/splinepath_cut_point_cursor.png + cursor/union_cursor.png diff --git a/share/resources/cursor/union_cursor.png b/share/resources/cursor/union_cursor.png new file mode 100644 index 000000000..687d2ca59 Binary files /dev/null and b/share/resources/cursor/union_cursor.png differ diff --git a/share/resources/icon.qrc b/share/resources/icon.qrc index 85c2c0ddf..8ba3c5058 100644 --- a/share/resources/icon.qrc +++ b/share/resources/icon.qrc @@ -39,5 +39,6 @@ icon/32x32/point_of_intersection.png icon/32x32/spline_cut_point.png icon/32x32/splinePath_cut_point.png + icon/32x32/union.png diff --git a/share/resources/icon/32x32/union.png b/share/resources/icon/32x32/union.png new file mode 100644 index 000000000..5c8ad9c88 Binary files /dev/null and b/share/resources/icon/32x32/union.png differ diff --git a/src/container/container.pri b/src/container/container.pri index be62d71f1..b7f46dfd6 100644 --- a/src/container/container.pri +++ b/src/container/container.pri @@ -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 \ diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 1e3f186a9..f21c26977 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -27,18 +27,17 @@ *************************************************************************/ #include "vcontainer.h" -#include "../exception/vexceptionbadid.h" #include +#include qint64 VContainer::_id = 0; VContainer::VContainer() - :base(QHash()), points(QHash()), + :base(QHash()), gObjects(QHash()), standartTable(QHash()), incrementTable(QHash()), - lengthLines(QHash()), lineAngles(QHash()), splines(QHash()), - lengthSplines(QHash()), arcs(QHash()), lengthArcs(QHash()), - splinePaths(QHash()), details(QHash()) + lengthLines(QHash()), lineAngles(QHash()), lengthSplines(QHash()), + lengthArcs(QHash()), details(QHash()) { SetSize(500); SetGrowth(1760); @@ -52,38 +51,74 @@ VContainer &VContainer::operator =(const VContainer &data) } VContainer::VContainer(const VContainer &data) - :base(QHash()), points(QHash()), - standartTable(QHash()), incrementTable(QHash()), - lengthLines(QHash()), lineAngles(QHash()), splines(QHash()), - lengthSplines(QHash()), arcs(QHash()), lengthArcs(QHash()), - splinePaths(QHash()), details(QHash()) + :base(QHash()), gObjects(QHash()), + standartTable(QHash()), incrementTable(QHash()), + lengthLines(QHash()), lineAngles(QHash()), lengthSplines(QHash()), + lengthArcs(QHash()), details(QHash()) { 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 *obj = data.DataGObjects(); + Q_ASSERT(obj != 0); + QHashIterator i(*obj); + while (i.hasNext()) + { + i.next(); + switch (i.value()->getType()) + { + case (GObject::Arc): + { + CopyGObject(data, i.key()); + break; + } + case (GObject::Point): + { + CopyGObject(data, i.key()); + break; + } + case (GObject::Spline): + { + CopyGObject(data, i.key()); + break; + } + case (GObject::SplinePath): + { + CopyGObject(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 -val VContainer::GetObject(const QHash &obj, key id) +const val VContainer::GetObject(const QHash &obj, key id) const { if (obj.contains(id)) { @@ -95,70 +130,75 @@ val VContainer::GetObject(const QHash &obj, key id) } } -VStandartTableRow VContainer::GetStandartTableCell(const QString &name) const +template +val VContainer::GetVariable(const QHash &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 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(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(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(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(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."< 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 VContainer::CheckLoops(const QVector &points) const void VContainer::PrepareDetails(QVector &list) const { - QHashIterator iDetail(details); - while (iDetail.hasNext()) + QHashIterator 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 -void VContainer::UpdateObject(QHash &obj, const qint64 &id, const val& point) +void VContainer::UpdateObject(QHash &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(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 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(firstPointId); + const VPointF *second = GeometricObject(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 -qint64 VContainer::AddObject(QHash &obj, const val& value) +qint64 VContainer::AddObject(QHash &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(firstPoint); + const VPointF *second = GeometricObject(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(firstPoint); + const VPointF *second = GeometricObject(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 VContainer::GetReversePoint(const QVector &points) const diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index 8465a19ae..87f5ce1ab 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -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 + void CopyGObject(const VContainer &data, const qint64 &id) + { + T *obj = new T(*data.GeometricObject(id)); + Q_ASSERT(obj != 0); + UpdateGObject(id, obj); + } /** * @brief setData copy data from container * @param data container */ void setData(const VContainer &data); + template + 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(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 *DataPoints() const {return &points;} - /** - * @brief data container with dataSplines return container of splines - * @return pointer on container of splines - */ - inline const QHash *DataSplines() const {return &splines;} - /** - * @brief data container with dataArcs return container of arcs - * @return pointer on container of arcs - */ - inline const QHash *DataArcs() const {return &arcs;} + inline const QHash *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 *DataLineAngles() const {return &lineAngles;} - /** - * @brief data container with dataSplinePaths return container of spline paths - * @return pointer on container of spline paths - */ - inline const QHash *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 & 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 base; /** - * @brief points container of points + * @brief gObjects graphicals objects of pattern. */ - QHash points; + QHash gObjects; /** * @brief standartTable container of standart table rows */ @@ -517,34 +467,18 @@ private: * @brief lineAngles container of angles of lines */ QHash lineAngles; - /** - * @brief splines container of splines - */ - QHash splines; /** * @brief lengthSplines container of splines length */ QHash lengthSplines; - /** - * @brief arcs container of arcs - */ - QHash arcs; /** * @brief lengthArcs container of arcs length */ QHash lengthArcs; - /** - * @brief splinePaths container of spline paths - */ - QHash splinePaths; /** * @brief details container of details */ QHash 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 &obj, key id); + const val GetObject(const QHash &obj, key id) const; + template + /** + * @brief GetObject return object from container + * @param obj container + * @param id id of object + * @return Object + */ + val GetVariable(const QHash &obj, key id) const; template /** * @brief UpdateObject update object in container @@ -573,7 +515,7 @@ private: * @param id id of existing object * @param point object */ - static void UpdateObject(QHash &obj, const qint64 &id, const val& point); + void UpdateObject(QHash &obj, const qint64 &id, val point); template /** * @brief AddObject add object to container @@ -581,7 +523,7 @@ private: * @param value object * @return id of object in container */ - static qint64 AddObject(QHash &obj, const val& value); + static qint64 AddObject(QHash &obj, val value); }; #endif // VCONTAINER_H diff --git a/src/container/vstandarttablerow.cpp b/src/container/vstandarttablerow.cpp index 668036804..e79809424 100644 --- a/src/container/vstandarttablerow.cpp +++ b/src/container/vstandarttablerow.cpp @@ -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){} diff --git a/src/container/vstandarttablerow.h b/src/container/vstandarttablerow.h index 4a56dad47..ffd973fd8 100644 --- a/src/container/vstandarttablerow.h +++ b/src/container/vstandarttablerow.h @@ -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 diff --git a/src/dialogs/dialogalongline.cpp b/src/dialogs/dialogalongline.cpp index 89bb3b174..651343519 100644 --- a/src/dialogs/dialogalongline.cpp +++ b/src/dialogs/dialogalongline.cpp @@ -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(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); diff --git a/src/dialogs/dialogarc.cpp b/src/dialogs/dialogarc.cpp index b66326639..442aff59f 100644 --- a/src/dialogs/dialogarc.cpp +++ b/src/dialogs/dialogarc.cpp @@ -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(id); - ChangeCurrentText(ui->comboBoxBasePoint, point.name()); + ChangeCurrentText(ui->comboBoxBasePoint, point->name()); emit ToolTip(""); this->show(); } diff --git a/src/dialogs/dialogbisector.cpp b/src/dialogs/dialogbisector.cpp index f6c9c6058..8d3bdd51b 100644 --- a/src/dialogs/dialogbisector.cpp +++ b/src/dialogs/dialogbisector.cpp @@ -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(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); diff --git a/src/dialogs/dialogcutspline.cpp b/src/dialogs/dialogcutspline.cpp index be3f83513..f125429dd 100644 --- a/src/dialogs/dialogcutspline.cpp +++ b/src/dialogs/dialogcutspline.cpp @@ -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(id); + ChangeCurrentText(ui->comboBoxSpline, spl->name()); emit ToolTip(""); this->show(); } diff --git a/src/dialogs/dialogcutspline.h b/src/dialogs/dialogcutspline.h index 85209cb24..a08f1c305 100644 --- a/src/dialogs/dialogcutspline.h +++ b/src/dialogs/dialogcutspline.h @@ -31,8 +31,9 @@ #include "dialogtool.h" -namespace Ui { -class DialogCutSpline; +namespace Ui +{ + class DialogCutSpline; } class DialogCutSpline : public DialogTool diff --git a/src/dialogs/dialogcutsplinepath.cpp b/src/dialogs/dialogcutsplinepath.cpp index dff368e47..bb0694ea4 100644 --- a/src/dialogs/dialogcutsplinepath.cpp +++ b/src/dialogs/dialogcutsplinepath.cpp @@ -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(id); + ChangeCurrentText(ui->comboBoxSplinePath, splPath->name()); emit ToolTip(""); this->show(); } diff --git a/src/dialogs/dialogcutsplinepath.h b/src/dialogs/dialogcutsplinepath.h index 5069688f6..89342a917 100644 --- a/src/dialogs/dialogcutsplinepath.h +++ b/src/dialogs/dialogcutsplinepath.h @@ -31,8 +31,9 @@ #include "dialogtool.h" -namespace Ui { -class DialogCutSplinePath; +namespace Ui +{ + class DialogCutSplinePath; } class DialogCutSplinePath : public DialogTool diff --git a/src/dialogs/dialogdetail.cpp b/src/dialogs/dialogdetail.cpp index 8a86c15ea..ff437406b 100644 --- a/src/dialogs/dialogdetail.cpp +++ b/src/dialogs/dialogdetail.cpp @@ -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(id); + name = point->name(); break; } case (Tool::NodeArc): { - VArc arc = data->GetArc(id); - name = arc.name(); + const VArc *arc = data->GeometricObject(id); + name = arc->name(); break; } case (Tool::NodeSpline): { - VSpline spl = data->GetSpline(id); - name = spl.GetName(); + const VSpline *spl = data->GeometricObject(id); + name = spl->name(); break; } case (Tool::NodeSplinePath): { - VSplinePath splPath = data->GetSplinePath(id); - name = splPath.name(); + const VSplinePath *splPath = data->GeometricObject(id); + name = splPath->name(); break; } default: diff --git a/src/dialogs/dialogendline.cpp b/src/dialogs/dialogendline.cpp index 8bb4f6592..f71ea2c77 100644 --- a/src/dialogs/dialogendline.cpp +++ b/src/dialogs/dialogendline.cpp @@ -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(id); + ChangeCurrentText(ui->comboBoxBasePoint, point->name()); emit ToolTip(""); this->show(); } diff --git a/src/dialogs/dialogheight.cpp b/src/dialogs/dialogheight.cpp index 8b4076411..184cf725d 100644 --- a/src/dialogs/dialogheight.cpp +++ b/src/dialogs/dialogheight.cpp @@ -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(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) diff --git a/src/dialogs/dialoghistory.cpp b/src/dialogs/dialoghistory.cpp index cef3eb755..3a8bc2d9c 100644 --- a/src/dialogs/dialoghistory.cpp +++ b/src/dialogs/dialoghistory.cpp @@ -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 #include @@ -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(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(basePointId)->name(); + QString toolIdName = data->GeometricObject(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(firstPointId)->name(); + QString secondPointIdName = data->GeometricObject(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(basePointId)->name(); + QString secondPointIdName = data->GeometricObject(secondPointId)->name(); + QString toolIdName = data->GeometricObject(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(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(basePointId)->name(); + QString secondPointIdName = data->GeometricObject(secondPointId)->name(); + QString toolIdName = data->GeometricObject(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(firstPointId)->name(); + QString basePointIdName = data->GeometricObject(basePointId)->name(); + QString thirdPointIdName = data->GeometricObject(thirdPointId)->name(); + QString toolIdName = data->GeometricObject(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(p1Line1)->name(); + QString p2Line1Name = data->GeometricObject(p2Line1)->name(); + QString p1Line2Name = data->GeometricObject(p1Line2)->name(); + QString p2Line2Name = data->GeometricObject(p2Line2)->name(); + QString toolIdName = data->GeometricObject(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(tool.getId()); + QString splP1Name = data->GeometricObject(spl->GetP1().id())->name(); + QString splP4Name = data->GeometricObject(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(tool.getId()); + QString arcCenterName = data->GeometricObject(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 points = splPath.GetSplinePath(); + const VSplinePath *splPath = data->GeometricObject(tool.getId()); + QVector points = splPath->GetSplinePath(); if (points.size() != 0 ) { - record = QString(tr("Curve point %1")).arg(data->GetPoint(points[0].P()).name()); + QString pName = data->GeometricObject(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(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(firstPointId)->name(); + QString centerName = data->GeometricObject(center)->name(); + QString secondPointIdName = data->GeometricObject(secondPointId)->name(); + QString toolIdName = data->GeometricObject(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(basePointId)->name(); + QString p1LineIdName = data->GeometricObject(p1LineId)->name(); + QString p2LineIdName = data->GeometricObject(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(axisP1Id)->name(); + QString axisP2IdName = data->GeometricObject(axisP2Id)->name(); + QString firstPointIdName = data->GeometricObject(firstPointId)->name(); + QString secondPointIdName = data->GeometricObject(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(splineId); + QString toolIdName = data->GeometricObject(tool.getId())->name(); + QString splP1Name = data->GeometricObject(spl->GetP1().id())->name(); + QString splP4Name = data->GeometricObject(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(splinePathId); + QVector points = splPath->GetSplinePath(); + if (points.size() != 0 ) + { + QString toolIdName = data->GeometricObject(tool.getId())->name(); + QString pName = data->GeometricObject(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(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()<GetPoint(value); - qint32 index = ui->comboBoxSecondPoint->findText(point.name()); + const VPointF *point = data->GeometricObject(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(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(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); diff --git a/src/dialogs/dialoglineintersect.cpp b/src/dialogs/dialoglineintersect.cpp index e6e4e2e4e..74899f451 100644 --- a/src/dialogs/dialoglineintersect.cpp +++ b/src/dialogs/dialoglineintersect.cpp @@ -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(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(p1Line1); + const VPointF *p2L1 = data->GeometricObject(p2Line1); + const VPointF *p1L2 = data->GeometricObject(p1Line2); + const VPointF *p2L2 = data->GeometricObject(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) diff --git a/src/dialogs/dialognormal.cpp b/src/dialogs/dialognormal.cpp index e018ec574..a65a7f8fd 100644 --- a/src/dialogs/dialognormal.cpp +++ b/src/dialogs/dialognormal.cpp @@ -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(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); diff --git a/src/dialogs/dialognormal.h b/src/dialogs/dialognormal.h index 9beb035a1..556a8b9a2 100644 --- a/src/dialogs/dialognormal.h +++ b/src/dialogs/dialognormal.h @@ -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 */ diff --git a/src/dialogs/dialogpointofcontact.cpp b/src/dialogs/dialogpointofcontact.cpp index 645634e5a..d593310b3 100644 --- a/src/dialogs/dialogpointofcontact.cpp +++ b/src/dialogs/dialogpointofcontact.cpp @@ -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(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); diff --git a/src/dialogs/dialogpointofintersection.cpp b/src/dialogs/dialogpointofintersection.cpp index d0c5ce633..0ec306a6e 100644 --- a/src/dialogs/dialogpointofintersection.cpp +++ b/src/dialogs/dialogpointofintersection.cpp @@ -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(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); diff --git a/src/dialogs/dialogpointofintersection.h b/src/dialogs/dialogpointofintersection.h index 49d7e0f12..4a184a544 100644 --- a/src/dialogs/dialogpointofintersection.h +++ b/src/dialogs/dialogpointofintersection.h @@ -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. */ diff --git a/src/dialogs/dialogs.h b/src/dialogs/dialogs.h index 06b0c2aa6..e61d49cb5 100644 --- a/src/dialogs/dialogs.h +++ b/src/dialogs/dialogs.h @@ -47,5 +47,6 @@ #include "dialogheight.h" #include "dialogcutspline.h" #include "dialogcutsplinepath.h" +#include "dialoguniondetails.h" #endif // DIALOGS_H diff --git a/src/dialogs/dialogs.pri b/src/dialogs/dialogs.pri index d18e02857..3367425c8 100644 --- a/src/dialogs/dialogs.pri +++ b/src/dialogs/dialogs.pri @@ -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 diff --git a/src/dialogs/dialogshoulderpoint.cpp b/src/dialogs/dialogshoulderpoint.cpp index b570adef5..336b12d90 100644 --- a/src/dialogs/dialogshoulderpoint.cpp +++ b/src/dialogs/dialogshoulderpoint.cpp @@ -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(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); diff --git a/src/dialogs/dialogspline.cpp b/src/dialogs/dialogspline.cpp index 03acc8478..88b1a8f19 100644 --- a/src/dialogs/dialogspline.cpp +++ b/src/dialogs/dialogspline.cpp @@ -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(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(ui->comboBoxP1->itemData(index)); - QPointF p1 = data->GetPoint(p1Id).toQPointF(); - QPointF p4 = data->GetPoint(id).toQPointF(); + QPointF p1 = data->GeometricObject(p1Id)->toQPointF(); + QPointF p4 = data->GeometricObject(id)->toQPointF(); ui->spinBoxAngle1->setValue(static_cast(QLineF(p1, p4).angle())); ui->spinBoxAngle2->setValue(static_cast(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; +} diff --git a/src/dialogs/dialogspline.h b/src/dialogs/dialogspline.h index 1ba4b4179..f78b94bd5 100644 --- a/src/dialogs/dialogspline.h +++ b/src/dialogs/dialogspline.h @@ -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 diff --git a/src/dialogs/dialogsplinepath.cpp b/src/dialogs/dialogsplinepath.cpp index 9f837cac3..1aa2ec9f0 100644 --- a/src/dialogs/dialogsplinepath.cpp +++ b/src/dialogs/dialogsplinepath.cpp @@ -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(&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(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(item->data(Qt::UserRole)); - p.SetP(id); - DataPoint(p.P(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2()); + const VPointF *point = data->GeometricObject(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(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(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)); } diff --git a/src/dialogs/dialogtool.cpp b/src/dialogs/dialogtool.cpp index 479a49219..4816d7a5f 100644 --- a/src/dialogs/dialogtool.cpp +++ b/src/dialogs/dialogtool.cpp @@ -28,6 +28,7 @@ #include "dialogtool.h" #include "../container/calculator.h" +#include "../geometry/vgobject.h" #include @@ -66,15 +67,19 @@ void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const { Q_ASSERT(box != 0); box->clear(); - const QHash *points = data->DataPoints(); - QHashIterator i(*points); + const QHash *objs = data->DataGObjects(); + QHashIterator 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(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 *spls = data->DataSplines(); - QHashIterator i(*spls); + const QHash *objs = data->DataGObjects(); + QHashIterator 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(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(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 *splPaths = data->DataSplinePaths(); - QHashIterator i(*splPaths); + const QHash *objs = data->DataGObjects(); + QHashIterator 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(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(i.key()); + box->addItem(splPath->name(), i.key()); + } } } } diff --git a/src/dialogs/dialogtriangle.cpp b/src/dialogs/dialogtriangle.cpp index e9b4a3bc1..e4c1f63aa 100644 --- a/src/dialogs/dialogtriangle.cpp +++ b/src/dialogs/dialogtriangle.cpp @@ -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(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) diff --git a/src/dialogs/dialogtriangle.h b/src/dialogs/dialogtriangle.h index e75d83a8c..0335aa9c4 100644 --- a/src/dialogs/dialogtriangle.h +++ b/src/dialogs/dialogtriangle.h @@ -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 */ diff --git a/src/dialogs/dialoguniondetails.cpp b/src/dialogs/dialoguniondetails.cpp new file mode 100644 index 000000000..9dac1278d --- /dev/null +++ b/src/dialogs/dialoguniondetails.cpp @@ -0,0 +1,135 @@ +/************************************************************************ + ** + ** @file dialoguniondetails.cpp + ** @author Roman Telezhinsky + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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; + } + } + } +} diff --git a/src/dialogs/dialoguniondetails.h b/src/dialogs/dialoguniondetails.h new file mode 100644 index 000000000..2815c65fc --- /dev/null +++ b/src/dialogs/dialoguniondetails.h @@ -0,0 +1,75 @@ +/************************************************************************ + ** + ** @file dialoguniondetails.h + ** @author Roman Telezhinsky + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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 diff --git a/src/dialogs/dialoguniondetails.ui b/src/dialogs/dialoguniondetails.ui new file mode 100644 index 000000000..24e84b14a --- /dev/null +++ b/src/dialogs/dialoguniondetails.ui @@ -0,0 +1,81 @@ + + + DialogUnionDetails + + + + 0 + 0 + 473 + 78 + + + + Dialog + + + + + 120 + 40 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 10 + 20 + 451 + 17 + + + + Do you really want union details? This operation can't be undone. + + + + + + + buttonBox + accepted() + DialogUnionDetails + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogUnionDetails + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/geometry/geometry.pri b/src/geometry/geometry.pri index e04865bed..6d6a337ed 100644 --- a/src/geometry/geometry.pri +++ b/src/geometry/geometry.pri @@ -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 diff --git a/src/geometry/varc.cpp b/src/geometry/varc.cpp index d8f314b8d..4613c243a 100644 --- a/src/geometry/varc.cpp +++ b/src/geometry/varc.cpp @@ -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()), idObject(0), _name(QString()){} - -VArc::VArc (const QHash *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 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())); diff --git a/src/geometry/varc.h b/src/geometry/varc.h index 754e4ddea..dd54e5fe1 100644 --- a/src/geometry/varc.h +++ b/src/geometry/varc.h @@ -29,18 +29,18 @@ #ifndef VARC_H #define VARC_H -#include "vspline.h" +#include "vgobject.h" #include #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 *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 GetDataPoints() const; /** * @brief GetPath будує шлях по даній дузі. * @return повертає шлях. @@ -159,26 +144,7 @@ public: * @return */ QVector 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 points; - /** - * @brief idObject - */ - qint64 idObject; - /** - * @brief _name - */ - QString _name; + VPointF center; }; #endif // VARC_H diff --git a/src/geometry/vdetail.cpp b/src/geometry/vdetail.cpp index a5453788c..24c7811c8 100644 --- a/src/geometry/vdetail.cpp +++ b/src/geometry/vdetail.cpp @@ -29,20 +29,23 @@ #include "vdetail.h" VDetail::VDetail() - :nodes(QVector()), name(QString()), mx(0), my(0), supplement(true), closed(true), width(10){} + :_id(0), nodes(QVector()), name(QString()), mx(0), my(0), supplement(true), closed(true), + width(10){} VDetail::VDetail(const QString &name, const QVector &nodes) - :nodes(QVector()), name(name), mx(0), my(0), supplement(true), closed(true), width(10) + :_id(0), nodes(QVector()), 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); + } +} diff --git a/src/geometry/vdetail.h b/src/geometry/vdetail.h index 958c8f421..16411a50a 100644 --- a/src/geometry/vdetail.h +++ b/src/geometry/vdetail.h @@ -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 &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 */ diff --git a/src/geometry/vgobject.cpp b/src/geometry/vgobject.cpp new file mode 100644 index 000000000..94d025598 --- /dev/null +++ b/src/geometry/vgobject.cpp @@ -0,0 +1,99 @@ +/************************************************************************ + ** + ** @file vgobject.cpp + ** @author Roman Telezhinsky + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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; +} diff --git a/src/geometry/vgobject.h b/src/geometry/vgobject.h new file mode 100644 index 000000000..eb904c072 --- /dev/null +++ b/src/geometry/vgobject.h @@ -0,0 +1,88 @@ +/************************************************************************ + ** + ** @file vgobject.h + ** @author Roman Telezhinsky + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef VGOBJECT_H +#define VGOBJECT_H + +#include "../options.h" +#include "../exception/vexception.h" +#include +#include + + +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 diff --git a/src/container/vpointf.cpp b/src/geometry/vpointf.cpp similarity index 85% rename from src/container/vpointf.cpp rename to src/geometry/vpointf.cpp index 7b2c6187a..33783552f 100644 --- a/src/container/vpointf.cpp +++ b/src/geometry/vpointf.cpp @@ -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; } diff --git a/src/container/vpointf.h b/src/geometry/vpointf.h similarity index 72% rename from src/container/vpointf.h rename to src/geometry/vpointf.h index 39869fb68..63da46ba7 100644 --- a/src/container/vpointf.h +++ b/src/geometry/vpointf.h @@ -32,36 +32,36 @@ #include #include #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 diff --git a/src/geometry/vspline.cpp b/src/geometry/vspline.cpp index 02dbb69b6..f37ba220e 100644 --- a/src/geometry/vspline.cpp +++ b/src/geometry/vspline.cpp @@ -31,34 +31,21 @@ #include VSpline::VSpline() - :p1(0), p2(QPointF()), p3(QPointF()), p4(0), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1), - points(QHash()), 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 *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 *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 = "<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 px; QVector py; - px.append ( GetPointP1 ().x () ); - py.append ( GetPointP1 ().y () ); + px.append ( GetP1 ().x () ); + py.append ( GetP1 ().y () ); QVector& wpx = px; QVector& 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()< 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 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 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(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 VSpline::SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve) { @@ -843,6 +612,7 @@ QVector 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; } diff --git a/src/geometry/vspline.h b/src/geometry/vspline.h index aaca1e2ec..7575c370a 100644 --- a/src/geometry/vspline.h +++ b/src/geometry/vspline.h @@ -29,7 +29,8 @@ #ifndef VSPLINE_H #define VSPLINE_H -#include "../container/vpointf.h" +#include "vpointf.h" +#include "vgobject.h" #include #include @@ -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 *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 *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 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 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 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 diff --git a/src/geometry/vsplinepath.cpp b/src/geometry/vsplinepath.cpp index 68e8cb828..e028b461a 100644 --- a/src/geometry/vsplinepath.cpp +++ b/src/geometry/vsplinepath.cpp @@ -29,16 +29,15 @@ #include "vsplinepath.h" #include "../exception/vexception.h" -VSplinePath::VSplinePath() - : path(QVector()), kCurve(1), points(QHash()), idObject(0), _name(QString()){} - -VSplinePath::VSplinePath(const QHash *points, qreal kCurve, qint64 idObject) - : path(QVector()), kCurve(kCurve), points(*points), idObject(idObject), _name(QString()) -{} +VSplinePath::VSplinePath(qreal kCurve, qint64 idObject, Draw::Draws mode) + : VGObject(GObject::SplinePath, idObject, mode), path(QVector()), 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 VSplinePath::GetPathPoints() const QVector 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 & QVector::operator+=(const QVector & other) instead for. QVector 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 VSplinePath::getPoints() const -{ - return points; -} - -void VSplinePath::setPoints(const QHash *value) -{ - points = *value; -} - diff --git a/src/geometry/vsplinepath.h b/src/geometry/vsplinepath.h index 9a428798e..d5bc1af2c 100644 --- a/src/geometry/vsplinepath.h +++ b/src/geometry/vsplinepath.h @@ -30,9 +30,11 @@ #define VSPLINEPATH_H #include "vsplinepoint.h" -#include "../container/vpointf.h" +#include "vpointf.h" #include "vspline.h" +#include "vgobject.h" #include +#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 *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 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 getPoints() const; - void setPoints(const QHash *value); + virtual QString name() const{return _name;} protected: /** * @brief path вектор з точок сплайна. @@ -197,18 +170,6 @@ protected: * @brief kCurve */ qreal kCurve; - /** - * @brief points - */ - QHash points; - /** - * @brief idObject - */ - qint64 idObject; - /** - * @brief _name - */ - QString _name; }; #endif // VSPLINEPATH_H diff --git a/src/geometry/vsplinepoint.cpp b/src/geometry/vsplinepoint.cpp index e57a7363a..bda00b236 100644 --- a/src/geometry/vsplinepoint.cpp +++ b/src/geometry/vsplinepoint.cpp @@ -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) diff --git a/src/geometry/vsplinepoint.h b/src/geometry/vsplinepoint.h index 9d3bd4667..a1ea6d743 100644 --- a/src/geometry/vsplinepoint.h +++ b/src/geometry/vsplinepoint.h @@ -30,6 +30,7 @@ #define VSPLINEPOINT_H #include +#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 кут дотичної сплайну. */ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f55024164..8951c7890 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -45,8 +45,8 @@ #include 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()), dialogLine(QSharedPointer()), dialogAlongLine(QSharedPointer()), dialogShoulderPoint(QSharedPointer()), dialogNormal(QSharedPointer()), @@ -58,8 +58,9 @@ MainWindow::MainWindow(QWidget *parent) dialogTriangle(QSharedPointer()), dialogPointOfIntersection(QSharedPointer()), dialogCutSpline(QSharedPointer()), dialogCutSplinePath (QSharedPointer()), - dialogHistory(0), doc(0), data(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), - mode(Draw::Calculation) + dialogUnionDetails(QSharedPointer()), + 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(&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(new Dialog(data)); + dialog = QSharedPointer(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, 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(new DialogDetail(data)); + dialogDetail = QSharedPointer(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(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(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 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) diff --git a/src/mainwindow.h b/src/mainwindow.h index 92fdeb275..c29236a4d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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; + /** + * @brief dialogUnionDetails + */ + QSharedPointer 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 */ diff --git a/src/mainwindow.ui b/src/mainwindow.ui index d6a6f02d5..360f0a388 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -47,7 +47,7 @@ 0 0 - 150 + 144 150 @@ -302,7 +302,7 @@ 0 0 - 150 + 100 58 @@ -378,7 +378,7 @@ 0 0 - 150 + 100 104 @@ -596,6 +596,29 @@ + + + + false + + + ... + + + + :/icon/32x32/union.png:/icon/32x32/union.png + + + + 32 + 32 + + + + true + + + diff --git a/src/options.h b/src/options.h index 52881be48..4f1edecdf 100644 --- a/src/options.h +++ b/src/options.h @@ -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 ) diff --git a/src/tablewindow.cpp b/src/tablewindow.cpp index 8fd8cb46f..f5694a1d2 100644 --- a/src/tablewindow.cpp +++ b/src/tablewindow.cpp @@ -34,7 +34,7 @@ TableWindow::TableWindow(QWidget *parent) :QMainWindow(parent), numberDetal(0), colission(0), ui(new Ui::TableWindow), - listDetails(QVector()), outItems(false), collidingItems(false), currentScene(0), + listDetails(QVector()), outItems(false), collidingItems(false), tableScene(0), paper(0), shadowPaper(0), listOutItems(0), listCollidingItems(QList()), 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()<rect().size().toSize(); } @@ -89,7 +90,7 @@ void TableWindow::AddDetail() { if (indexDetailclearSelection(); + tableScene->clearSelection(); VItem* Detail = listDetails[indexDetail]; QObject::connect(Detail, SIGNAL(itemOut(int, bool)), this, SLOT(itemOut(int, bool))); QObject::connect(Detail, SIGNAL(itemColliding(QList, 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); } diff --git a/src/tablewindow.h b/src/tablewindow.h index 82ed71a95..94321fff1 100644 --- a/src/tablewindow.h +++ b/src/tablewindow.h @@ -158,7 +158,7 @@ private: /** * @brief currentScene Зберігається покажчик на сцену. */ - QGraphicsScene* currentScene; + QGraphicsScene* tableScene; /** * @brief paper Зберігається покажчик на прямокутник що імітує листа паперу. */ diff --git a/src/tools/drawTools/vdrawtool.cpp b/src/tools/drawTools/vdrawtool.cpp index 20c93c55b..e34a8fdca 100644 --- a/src/tools/drawTools/vdrawtool.cpp +++ b/src/tools/drawTools/vdrawtool.cpp @@ -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 *history = doc->getHistory(); - if (cursor <= 0) - { - history->append(VToolRecord(id, toolType, doc->GetNameActivDraw())); - } - else - { - qint32 index = 0; - for (qint32 i = 0; isize(); ++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); diff --git a/src/tools/drawTools/vdrawtool.h b/src/tools/drawTools/vdrawtool.h index 71e80bfa5..37d87e419 100644 --- a/src/tools/drawTools/vdrawtool.h +++ b/src/tools/drawTools/vdrawtool.h @@ -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 diff --git a/src/tools/drawTools/vtoolalongline.cpp b/src/tools/drawTools/vtoolalongline.cpp index c8bb272c2..62c8a2053 100644 --- a/src/tools/drawTools/vtoolalongline.cpp +++ b/src/tools/drawTools/vtoolalongline.cpp @@ -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(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(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(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 &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(firstPointId); + const VPointF *secondPoint = data->GeometricObject(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) diff --git a/src/tools/drawTools/vtoolalongline.h b/src/tools/drawTools/vtoolalongline.h index 99dd29f6c..b989b0583 100644 --- a/src/tools/drawTools/vtoolalongline.h +++ b/src/tools/drawTools/vtoolalongline.h @@ -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 */ diff --git a/src/tools/drawTools/vtoolarc.cpp b/src/tools/drawTools/vtoolarc.cpp index 9951bfcfb..2f59bf87f 100644 --- a/src/tools/drawTools/vtoolarc.cpp +++ b/src/tools/drawTools/vtoolarc.cpp @@ -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()) { - VArc arc = data->GetArc(id); + const VArc *arc = data->GeometricObject(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(id); + dialogArc->SetCenter(arc->GetCenter().id()); + dialogArc->SetF1(arc->GetFormulaF1()); + dialogArc->SetF2(arc->GetFormulaF2()); + dialogArc->SetRadius(arc->GetFormulaRadius()); } void VToolArc::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, @@ -99,17 +103,19 @@ void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &rad calcF2 = result; } - VArc arc = VArc(data->DataPoints(), center, calcRadius, radius, calcF1, f1, calcF2, f2 ); + VPointF c = *data->GeometricObject(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(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(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(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(id); QPainterPath path; - path.addPath(arc.GetPath()); + path.addPath(arc->GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); } diff --git a/src/tools/drawTools/vtoolarc.h b/src/tools/drawTools/vtoolarc.h index 57b940c10..cedeed99a 100644 --- a/src/tools/drawTools/vtoolarc.h +++ b/src/tools/drawTools/vtoolarc.h @@ -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 diff --git a/src/tools/drawTools/vtoolbisector.cpp b/src/tools/drawTools/vtoolbisector.cpp index e29886be5..eb973f3af 100644 --- a/src/tools/drawTools/vtoolbisector.cpp +++ b/src/tools/drawTools/vtoolbisector.cpp @@ -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(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 &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(firstPointId); + const VPointF *secondPoint = data->GeometricObject(secondPointId); + const VPointF *thirdPoint = data->GeometricObject(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(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(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); diff --git a/src/tools/drawTools/vtoolbisector.h b/src/tools/drawTools/vtoolbisector.h index 824e102aa..a94fc4f2f 100644 --- a/src/tools/drawTools/vtoolbisector.h +++ b/src/tools/drawTools/vtoolbisector.h @@ -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 */ diff --git a/src/tools/drawTools/vtoolcutspline.cpp b/src/tools/drawTools/vtoolcutspline.cpp index a1c71c1d7..f05e012d1 100644 --- a/src/tools/drawTools/vtoolcutspline.cpp +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -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(id); dialogCutSpline->setFormula(formula); dialogCutSpline->setSplineId(splineId, id); - dialogCutSpline->setPointName(point.name()); + dialogCutSpline->setPointName(point->name()); } void VToolCutSpline::Create(QSharedPointer &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(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(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(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(id)); } void VToolCutSpline::RefreshSpline(VSimpleSpline *spline, qint64 splid, SimpleSpline::Translation tr) { - VSpline spl = VAbstractTool::data.GetSpline(splid); + const VSpline *spl = VAbstractTool::data.GeometricObject(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); } diff --git a/src/tools/drawTools/vtoolcutspline.h b/src/tools/drawTools/vtoolcutspline.h index 795fdd34a..65b23dd11 100644 --- a/src/tools/drawTools/vtoolcutspline.h +++ b/src/tools/drawTools/vtoolcutspline.h @@ -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) diff --git a/src/tools/drawTools/vtoolcutsplinepath.cpp b/src/tools/drawTools/vtoolcutsplinepath.cpp index 92bca9703..277119865 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/tools/drawTools/vtoolcutsplinepath.cpp @@ -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(id); dialogCutSplinePath->setFormula(formula); dialogCutSplinePath->setSplinePathId(splinePathId, id); - dialogCutSplinePath->setPointName(point.name()); + dialogCutSplinePath->setPointName(point->name()); } void VToolCutSplinePath::Create(QSharedPointer &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(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(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(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(id)); } void VToolCutSplinePath::RefreshSpline(VSimpleSpline *spline, qint64 splPathid, SimpleSpline::Translation tr) { - VSplinePath splPath = VAbstractTool::data.GetSplinePath(splPathid); + const VSplinePath *splPath = VAbstractTool::data.GeometricObject(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); } diff --git a/src/tools/drawTools/vtoolcutsplinepath.h b/src/tools/drawTools/vtoolcutsplinepath.h index e5a2af1e4..232511d95 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.h +++ b/src/tools/drawTools/vtoolcutsplinepath.h @@ -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) diff --git a/src/tools/drawTools/vtoolendline.cpp b/src/tools/drawTools/vtoolendline.cpp index 0f08affbc..c8225c361 100644 --- a/src/tools/drawTools/vtoolendline.cpp +++ b/src/tools/drawTools/vtoolendline.cpp @@ -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(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 &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(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(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(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); + } +} diff --git a/src/tools/drawTools/vtoolendline.h b/src/tools/drawTools/vtoolendline.h index a43938d7e..32cfe0365 100644 --- a/src/tools/drawTools/vtoolendline.h +++ b/src/tools/drawTools/vtoolendline.h @@ -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 diff --git a/src/tools/drawTools/vtoolheight.cpp b/src/tools/drawTools/vtoolheight.cpp index 528f1515c..57b3290cc 100644 --- a/src/tools/drawTools/vtoolheight.cpp +++ b/src/tools/drawTools/vtoolheight.cpp @@ -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(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 &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(basePointId); + const VPointF *p1Line = data->GeometricObject(p1LineId); + const VPointF *p2Line = data->GeometricObject(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(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(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); + } +} diff --git a/src/tools/drawTools/vtoolheight.h b/src/tools/drawTools/vtoolheight.h index 3aa016801..d336f7d2d 100644 --- a/src/tools/drawTools/vtoolheight.h +++ b/src/tools/drawTools/vtoolheight.h @@ -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 diff --git a/src/tools/drawTools/vtoolline.cpp b/src/tools/drawTools/vtoolline.cpp index 5b6e0f3bf..4b2e8c7c5 100644 --- a/src/tools/drawTools/vtoolline.cpp +++ b/src/tools/drawTools/vtoolline.cpp @@ -36,10 +36,10 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs dialogLine(QSharedPointer()) { 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(firstPoint); + const VPointF *second = data->GeometricObject(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(firstPoint); + const VPointF *second = VAbstractTool::data.GeometricObject(secondPoint); + this->setLine(QLineF(first->toQPointF(), second->toQPointF())); this->setPen(QPen(currentColor, widthHairLine/factor)); } diff --git a/src/tools/drawTools/vtoolline.h b/src/tools/drawTools/vtoolline.h index 80df5efcf..d02b95f03 100644 --- a/src/tools/drawTools/vtoolline.h +++ b/src/tools/drawTools/vtoolline.h @@ -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 diff --git a/src/tools/drawTools/vtoollineintersect.cpp b/src/tools/drawTools/vtoollineintersect.cpp index 1663b4c71..30fa1fa39 100644 --- a/src/tools/drawTools/vtoollineintersect.cpp +++ b/src/tools/drawTools/vtoollineintersect.cpp @@ -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(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 &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(p1Line1Id); + const VPointF *p2Line1 = data->GeometricObject(p2Line1Id); + const VPointF *p1Line2 = data->GeometricObject(p1Line2Id); + const VPointF *p2Line2 = data->GeometricObject(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(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(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(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(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); diff --git a/src/tools/drawTools/vtoollineintersect.h b/src/tools/drawTools/vtoollineintersect.h index 1812d638f..98a90a32e 100644 --- a/src/tools/drawTools/vtoollineintersect.h +++ b/src/tools/drawTools/vtoollineintersect.h @@ -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 */ diff --git a/src/tools/drawTools/vtoollinepoint.cpp b/src/tools/drawTools/vtoollinepoint.cpp index 00a77acfe..00b960e77 100644 --- a/src/tools/drawTools/vtoollinepoint.cpp +++ b/src/tools/drawTools/vtoollinepoint.cpp @@ -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(basePointId)->toQPointF(); + QPointF point2 = data->GeometricObject(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(id)); + QPointF point = VDrawTool::data.GeometricObject(id)->toQPointF(); + QPointF basePoint = VDrawTool::data.GeometricObject(basePointId)->toQPointF(); mainLine->setLine(QLineF(basePoint - point, QPointF())); if (typeLine == TypeLineNone) { diff --git a/src/tools/drawTools/vtoolnormal.cpp b/src/tools/drawTools/vtoolnormal.cpp index 0acb05cdf..c648b14cc 100644 --- a/src/tools/drawTools/vtoolnormal.cpp +++ b/src/tools/drawTools/vtoolnormal.cpp @@ -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(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 &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(firstPointId); + const VPointF *secondPoint = data->GeometricObject(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(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(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); diff --git a/src/tools/drawTools/vtoolnormal.h b/src/tools/drawTools/vtoolnormal.h index 830eeff5a..61e7fe6fc 100644 --- a/src/tools/drawTools/vtoolnormal.h +++ b/src/tools/drawTools/vtoolnormal.h @@ -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 */ diff --git a/src/tools/drawTools/vtoolpoint.cpp b/src/tools/drawTools/vtoolpoint.cpp index 3deec4002..453dfb2f2 100644 --- a/src/tools/drawTools/vtoolpoint.cpp +++ b/src/tools/drawTools/vtoolpoint.cpp @@ -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(id)); } void VToolPoint::NameChangePosition(const QPointF &pos) { - VPointF point = VAbstractTool::data.GetPoint(id); + VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(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(id)); } void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) diff --git a/src/tools/drawTools/vtoolpointofcontact.cpp b/src/tools/drawTools/vtoolpointofcontact.cpp index 9d94bc7e9..eaf0bfb18 100644 --- a/src/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/tools/drawTools/vtoolpointofcontact.cpp @@ -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(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 ¢er, 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(center); + const VPointF *firstP = data->GeometricObject(firstPointId); + const VPointF *secondP = data->GeometricObject(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(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(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(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(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); diff --git a/src/tools/drawTools/vtoolpointofcontact.h b/src/tools/drawTools/vtoolpointofcontact.h index d53113fa2..c38a23bcb 100644 --- a/src/tools/drawTools/vtoolpointofcontact.h +++ b/src/tools/drawTools/vtoolpointofcontact.h @@ -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 */ diff --git a/src/tools/drawTools/vtoolpointofintersection.cpp b/src/tools/drawTools/vtoolpointofintersection.cpp index dc0d4d7e8..f2dda86da 100644 --- a/src/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/tools/drawTools/vtoolpointofintersection.cpp @@ -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(id); dialogPointOfIntersection->setFirstPointId(firstPointId, id); dialogPointOfIntersection->setSecondPointId(secondPointId, id); - dialogPointOfIntersection->setPointName(p.name()); + dialogPointOfIntersection->setPointName(p->name()); } void VToolPointOfIntersection::Create(QSharedPointer &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(firstPointId); + const VPointF *secondPoint = data->GeometricObject(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(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(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(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); + } +} diff --git a/src/tools/drawTools/vtoolpointofintersection.h b/src/tools/drawTools/vtoolpointofintersection.h index 2aa964adc..f19e8c982 100644 --- a/src/tools/drawTools/vtoolpointofintersection.h +++ b/src/tools/drawTools/vtoolpointofintersection.h @@ -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) /** diff --git a/src/tools/drawTools/vtoolshoulderpoint.cpp b/src/tools/drawTools/vtoolshoulderpoint.cpp index 115cc7b47..2e2567735 100644 --- a/src/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/tools/drawTools/vtoolshoulderpoint.cpp @@ -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(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(p1Line); + const VPointF *secondPoint = data->GeometricObject(p2Line); + const VPointF *shoulderPoint = data->GeometricObject(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(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(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); diff --git a/src/tools/drawTools/vtoolshoulderpoint.h b/src/tools/drawTools/vtoolshoulderpoint.h index a6f9faf1a..95c0565cd 100644 --- a/src/tools/drawTools/vtoolshoulderpoint.h +++ b/src/tools/drawTools/vtoolshoulderpoint.h @@ -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 */ diff --git a/src/tools/drawTools/vtoolsinglepoint.cpp b/src/tools/drawTools/vtoolsinglepoint.cpp index b8f56cf21..cc2d15f13 100644 --- a/src/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/tools/drawTools/vtoolsinglepoint.cpp @@ -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(id); + dialogSinglePoint->setData(p->name(), p->toQPointF()); } void VToolSinglePoint::AddToFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + const VPointF *point = VAbstractTool::data.GeometricObject(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(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(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(id))); } diff --git a/src/tools/drawTools/vtoolsinglepoint.h b/src/tools/drawTools/vtoolsinglepoint.h index 8079d2ce7..837c27748 100644 --- a/src/tools/drawTools/vtoolsinglepoint.h +++ b/src/tools/drawTools/vtoolsinglepoint.h @@ -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 diff --git a/src/tools/drawTools/vtoolspline.cpp b/src/tools/drawTools/vtoolspline.cpp index b1ab4c6dd..6be80255e 100644 --- a/src/tools/drawTools/vtoolspline.cpp +++ b/src/tools/drawTools/vtoolspline.cpp @@ -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(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(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 &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(p1); + VPointF point4 = *data->GeometricObject(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(dialogSpline->getP1()); + VPointF point4 = *VAbstractTool::data.GeometricObject(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(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(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(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(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(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(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(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, diff --git a/src/tools/drawTools/vtoolspline.h b/src/tools/drawTools/vtoolspline.h index cf0aeaf8e..d4133e8ac 100644 --- a/src/tools/drawTools/vtoolspline.h +++ b/src/tools/drawTools/vtoolspline.h @@ -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 diff --git a/src/tools/drawTools/vtoolsplinepath.cpp b/src/tools/drawTools/vtoolsplinepath.cpp index bd656dc79..3c2d4f003 100644 --- a/src/tools/drawTools/vtoolsplinepath.cpp +++ b/src/tools/drawTools/vtoolsplinepath.cpp @@ -37,28 +37,27 @@ VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, controlPoints(QVector()) { ignoreFullUpdate = true; - VSplinePath splPath = data->GetSplinePath(id); + const VSplinePath *splPath = data->GeometricObject(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(id); + dialogSplinePath->SetPath(*splPath); } void VToolSplinePath::Create(QSharedPointer &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(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(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(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(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(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); diff --git a/src/tools/drawTools/vtoolsplinepath.h b/src/tools/drawTools/vtoolsplinepath.h index 5f20851c4..80aa2cf08 100644 --- a/src/tools/drawTools/vtoolsplinepath.h +++ b/src/tools/drawTools/vtoolsplinepath.h @@ -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 diff --git a/src/tools/drawTools/vtooltriangle.cpp b/src/tools/drawTools/vtooltriangle.cpp index e313a659f..af21f9856 100644 --- a/src/tools/drawTools/vtooltriangle.cpp +++ b/src/tools/drawTools/vtooltriangle.cpp @@ -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(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 &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(axisP1Id); + const VPointF *axisP2 = data->GeometricObject(axisP2Id); + const VPointF *firstPoint = data->GeometricObject(firstPointId); + const VPointF *secondPoint = data->GeometricObject(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(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(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(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); + } +} diff --git a/src/tools/drawTools/vtooltriangle.h b/src/tools/drawTools/vtooltriangle.h index 5a9543cde..e6d13c8af 100644 --- a/src/tools/drawTools/vtooltriangle.h +++ b/src/tools/drawTools/vtooltriangle.h @@ -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) /** diff --git a/src/tools/nodeDetails/vabstractnode.cpp b/src/tools/nodeDetails/vabstractnode.cpp index f86408eaf..0b964aea2 100644 --- a/src/tools/nodeDetails/vabstractnode.cpp +++ b/src/tools/nodeDetails/vabstractnode.cpp @@ -30,9 +30,11 @@ #include 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; } diff --git a/src/tools/nodeDetails/vabstractnode.h b/src/tools/nodeDetails/vabstractnode.h index cb52c85f1..f4726933f 100644 --- a/src/tools/nodeDetails/vabstractnode.h +++ b/src/tools/nodeDetails/vabstractnode.h @@ -46,17 +46,20 @@ public: * @param idNode * @param parent */ - VAbstractNode(VDomDocument *doc, VContainer *data, qint64 id, qint64 idNode, QObject *parent = 0 ); + VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &idNode, + const qint64 &idTool, QObject *parent = 0); virtual ~VAbstractNode() {} /** * @brief AttrIdObject */ static const QString AttrIdObject; + static const QString AttrIdTool; protected: /** * @brief idNode */ qint64 idNode; + qint64 idTool; /** * @brief AddToModeling * @param domElement diff --git a/src/tools/nodeDetails/vnodearc.cpp b/src/tools/nodeDetails/vnodearc.cpp index 03c843ac3..ae9d6a66c 100644 --- a/src/tools/nodeDetails/vnodearc.cpp +++ b/src/tools/nodeDetails/vnodearc.cpp @@ -34,29 +34,43 @@ const QString VNodeArc::TagName = QStringLiteral("arc"); const QString VNodeArc::ToolType = QStringLiteral("modeling"); VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Tool::Sources &typeCreation, - QGraphicsItem * parent) - :VAbstractNode(doc, data, id, idArc), QGraphicsPathItem(parent) + const qint64 &idTool, QObject *qoParent, QGraphicsItem *parent) + :VAbstractNode(doc, data, id, idArc, idTool, qoParent), QGraphicsPathItem(parent) { RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); if (typeCreation == Tool::FromGui) { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse, - const Tool::Sources &typeCreation) + const Tool::Sources &typeCreation, const qint64 &idTool, QObject *parent) { + VAbstractTool::AddRecord(id, Tool::NodeArc, doc); if (parse == Document::FullParse) { - VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation); + VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, idTool, parent); Q_ASSERT(arc != 0); doc->AddTool(id, arc); - doc->IncrementReferens(idArc); + if(idTool != 0) + { + doc->IncrementReferens(idTool); + //Some nodes we don't show on scene. Tool that create this nodes must free memory. + VDataTool *tool = doc->getTool(idTool); + Q_ASSERT(tool != 0); + arc->setParent(tool); + } + else + { + doc->IncrementReferens(idArc); + } } else { @@ -76,10 +90,27 @@ void VNodeArc::AddToFile() AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrType, ToolType); AddAttribute(domElement, AttrIdObject, idNode); + if (idTool != 0) + { + AddAttribute(domElement, AttrIdTool, idTool); + } AddToModeling(domElement); } +void VNodeArc::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrIdObject, idNode); + if (idTool != 0) + { + domElement.setAttribute(AttrIdTool, idTool); + } + } +} + void VNodeArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) @@ -103,9 +134,9 @@ void VNodeArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VNodeArc::RefreshGeometry() { - VArc arc = VAbstractTool::data.GetArc(id); + const VArc *arc = VAbstractTool::data.GeometricObject(id); QPainterPath path; - path.addPath(arc.GetPath()); + path.addPath(arc->GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); } diff --git a/src/tools/nodeDetails/vnodearc.h b/src/tools/nodeDetails/vnodearc.h index 571687551..1e263a44f 100644 --- a/src/tools/nodeDetails/vnodearc.h +++ b/src/tools/nodeDetails/vnodearc.h @@ -49,7 +49,8 @@ public: * @param parent */ VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0, + QGraphicsItem * parent = 0); /** * @brief Create * @param doc dom document container @@ -60,7 +61,7 @@ public: * @param typeCreation */ static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse, - const Tool::Sources &typeCreation); + const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *parent = 0); /** * @brief TagName */ @@ -79,6 +80,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 diff --git a/src/tools/nodeDetails/vnodepoint.cpp b/src/tools/nodeDetails/vnodepoint.cpp index dc7e8f293..1a2f63f59 100644 --- a/src/tools/nodeDetails/vnodepoint.cpp +++ b/src/tools/nodeDetails/vnodepoint.cpp @@ -34,9 +34,10 @@ const QString VNodePoint::TagName = QStringLiteral("point"); const QString VNodePoint::ToolType = QStringLiteral("modeling"); VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - const Tool::Sources &typeCreation, QGraphicsItem *parent) - :VAbstractNode(doc, data, id, idPoint), QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0), - lineName(0) + const Tool::Sources &typeCreation, const qint64 &idTool, QObject *qoParent, + QGraphicsItem *parent) + :VAbstractNode(doc, data, id, idPoint, idTool, qoParent), QGraphicsEllipseItem(parent), radius(toPixel(1.5)), + namePoint(0), lineName(0) { namePoint = new VGraphicsSimpleTextItem(this); lineName = new QGraphicsLineItem(this); @@ -46,22 +47,41 @@ VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 id this->setBrush(QBrush(Qt::NoBrush)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); - RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); + RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); if (typeCreation == Tool::FromGui) { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - const Document::Documents &parse, const Tool::Sources &typeCreation) + const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool, + QObject *parent) { + VAbstractTool::AddRecord(id, Tool::NodePoint, doc); if (parse == Document::FullParse) { - VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation); + //TODO Need create garbage collector and remove all nodes, that we don't use. + //Better check garbage before each saving file. Check only modeling tags. + VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, idTool, parent); Q_ASSERT(point != 0); doc->AddTool(id, point); - doc->IncrementReferens(idPoint); + if(idTool != 0) + { + doc->IncrementReferens(idTool); + //Some nodes we don't show on scene. Tool that create this nodes must free memory. + VDataTool *tool = doc->getTool(idTool); + Q_ASSERT(tool != 0); + point->setParent(tool); + } + else + { + doc->IncrementReferens(idPoint); + } } else { @@ -71,23 +91,43 @@ void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 i void VNodePoint::FullUpdateFromFile() { - RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); + RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); } void VNodePoint::AddToFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrType, ToolType); AddAttribute(domElement, AttrIdObject, idNode); - AddAttribute(domElement, AttrMx, toMM(point.mx())); - AddAttribute(domElement, AttrMy, toMM(point.my())); + AddAttribute(domElement, AttrMx, toMM(point->mx())); + AddAttribute(domElement, AttrMy, toMM(point->my())); + if (idTool != 0) + { + AddAttribute(domElement, AttrIdTool, idTool); + } AddToModeling(domElement); } +void VNodePoint::RefreshDataInFile() +{ + const VPointF *point = VAbstractTool::data.GeometricObject(id); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrIdObject, idNode); + domElement.setAttribute(AttrMx, toMM(point->mx())); + domElement.setAttribute(AttrMy, toMM(point->my())); + if (idTool != 0) + { + domElement.setAttribute(AttrIdTool, idTool); + } + } +} + void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) @@ -112,13 +152,13 @@ void VNodePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VNodePoint::NameChangePosition(const QPointF &pos) { - VPointF point = VAbstractTool::data.GetPoint(id); + VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); 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 VNodePoint::UpdateNamePosition(qreal mx, qreal my) diff --git a/src/tools/nodeDetails/vnodepoint.h b/src/tools/nodeDetails/vnodepoint.h index e724430a0..ba95a89b6 100644 --- a/src/tools/nodeDetails/vnodepoint.h +++ b/src/tools/nodeDetails/vnodepoint.h @@ -49,7 +49,8 @@ public: * @param parent */ VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0 ); + const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0, + QGraphicsItem * parent = 0 ); /** * @brief Create * @param doc dom document container @@ -60,7 +61,8 @@ public: * @param typeCreation */ static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - const Document::Documents &parse, const Tool::Sources &typeCreation); + const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0, + QObject *parent = 0); /** * @brief TagName */ @@ -96,6 +98,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 diff --git a/src/tools/nodeDetails/vnodespline.cpp b/src/tools/nodeDetails/vnodespline.cpp index 1dab7b856..22255e243 100644 --- a/src/tools/nodeDetails/vnodespline.cpp +++ b/src/tools/nodeDetails/vnodespline.cpp @@ -34,29 +34,45 @@ const QString VNodeSpline::TagName = QStringLiteral("spline"); const QString VNodeSpline::ToolType = QStringLiteral("modelingSpline"); VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Tool::Sources &typeCreation, QGraphicsItem * parent) - :VAbstractNode(doc, data, id, idSpline), QGraphicsPathItem(parent) + const Tool::Sources &typeCreation, const qint64 &idTool, QObject *qoParent, + QGraphicsItem * parent) + :VAbstractNode(doc, data, id, idSpline, idTool, qoParent), QGraphicsPathItem(parent) { RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); if (typeCreation == Tool::FromGui) { AddToFile(); } + else + { + RefreshDataInFile(); + } } VNodeSpline *VNodeSpline::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Document::Documents &parse, const Tool::Sources &typeCreation) + const Document::Documents &parse, const Tool::Sources &typeCreation, + const qint64 &idTool, QObject *parent) { + VAbstractTool::AddRecord(id, Tool::NodeSpline, doc); VNodeSpline *spl = 0; if (parse == Document::FullParse) { - spl = new VNodeSpline(doc, data, id, idSpline, typeCreation); + spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, idTool, parent); doc->AddTool(id, spl); - doc->IncrementReferens(idSpline); + if(idTool != 0) + { + doc->IncrementReferens(idTool); + //Some nodes we don't show on scene. Tool that create this nodes must free memory. + VDataTool *tool = doc->getTool(idTool); + Q_ASSERT(tool != 0); + spl->setParent(tool); + } + else + { + doc->IncrementReferens(idSpline); + } } else { @@ -77,10 +93,27 @@ void VNodeSpline::AddToFile() AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrType, ToolType); AddAttribute(domElement, AttrIdObject, idNode); + if (idTool != 0) + { + AddAttribute(domElement, AttrIdTool, idTool); + } AddToModeling(domElement); } +void VNodeSpline::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); + if (idTool != 0) + { + domElement.setAttribute(AttrIdTool, idTool); + } + } +} + void VNodeSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) @@ -104,9 +137,9 @@ void VNodeSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VNodeSpline::RefreshGeometry() { - VSpline spl = VAbstractTool::data.GetSpline(id); + const VSpline *spl = VAbstractTool::data.GeometricObject(id); QPainterPath path; - path.addPath(spl.GetPath()); + path.addPath(spl->GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); } diff --git a/src/tools/nodeDetails/vnodespline.h b/src/tools/nodeDetails/vnodespline.h index 0e4b64837..36426b92e 100644 --- a/src/tools/nodeDetails/vnodespline.h +++ b/src/tools/nodeDetails/vnodespline.h @@ -49,7 +49,8 @@ public: * @param parent */ VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0, + QGraphicsItem * parent = 0); /** * @brief Create * @param doc dom document container @@ -61,7 +62,8 @@ public: * @return */ static VNodeSpline *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Document::Documents &parse, const Tool::Sources &typeCreation); + const Document::Documents &parse, const Tool::Sources &typeCreation, + const qint64 &idTool = 0, QObject *parent = 0); /** * @brief TagName */ @@ -80,6 +82,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 diff --git a/src/tools/nodeDetails/vnodesplinepath.cpp b/src/tools/nodeDetails/vnodesplinepath.cpp index 4781ceaa8..f73420ee6 100644 --- a/src/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/tools/nodeDetails/vnodesplinepath.cpp @@ -34,33 +34,49 @@ const QString VNodeSplinePath::TagName = QStringLiteral("spline"); const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath"); VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Tool::Sources &typeCreation, QGraphicsItem * parent) - :VAbstractNode(doc, data, id, idSpline), QGraphicsPathItem(parent) + const Tool::Sources &typeCreation, const qint64 &idTool, QObject *qoParent, + QGraphicsItem * parent) + :VAbstractNode(doc, data, id, idSpline, idTool, qoParent), QGraphicsPathItem(parent) { RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); if (typeCreation == Tool::FromGui) { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Document::Documents &parse, const Tool::Sources &typeCreation) + const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool, + QObject *parent) { + VAbstractTool::AddRecord(id, Tool::NodeSplinePath, doc); if (parse == Document::FullParse) { - VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation); + VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, idTool, parent); Q_ASSERT(splPath != 0); doc->AddTool(id, splPath); - VSplinePath path = data->GetSplinePath(id); - const QVector *points = path.GetPoint(); + const VSplinePath *path = data->GeometricObject(id); + const QVector *points = path->GetPoint(); for (qint32 i = 0; isize(); ++i) { - doc->IncrementReferens(points->at(i).P()); + if(idTool != 0) + { + doc->IncrementReferens(idTool); + //Some nodes we don't show on scene. Tool that create this nodes must free memory. + VDataTool *tool = doc->getTool(idTool); + Q_ASSERT(tool != 0); + splPath->setParent(tool); + } + else + { + doc->IncrementReferens(points->at(i).P().id()); + } } } else @@ -81,10 +97,27 @@ void VNodeSplinePath::AddToFile() AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrType, ToolType); AddAttribute(domElement, AttrIdObject, idNode); + if (idTool != 0) + { + AddAttribute(domElement, AttrIdTool, idTool); + } AddToModeling(domElement); } +void VNodeSplinePath::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); + if (idTool != 0) + { + domElement.setAttribute(AttrIdTool, idTool); + } + } +} + void VNodeSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) @@ -108,9 +141,9 @@ void VNodeSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VNodeSplinePath::RefreshGeometry() { - VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); + const VSplinePath *splPath = VAbstractTool::data.GeometricObject(id); QPainterPath path; - path.addPath(splPath.GetPath()); + path.addPath(splPath->GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); } diff --git a/src/tools/nodeDetails/vnodesplinepath.h b/src/tools/nodeDetails/vnodesplinepath.h index b82e365e8..2d7721442 100644 --- a/src/tools/nodeDetails/vnodesplinepath.h +++ b/src/tools/nodeDetails/vnodesplinepath.h @@ -49,7 +49,8 @@ public: * @param parent */ VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0, + QGraphicsItem * parent = 0); /** * @brief Create * @param doc dom document container @@ -60,7 +61,8 @@ public: * @param typeCreation */ static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Document::Documents &parse, const Tool::Sources &typeCreation); + const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0, + QObject *parent = 0); /** * @brief TagName */ @@ -79,6 +81,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 diff --git a/src/tools/tools.pri b/src/tools/tools.pri index d9074461e..50763e12f 100644 --- a/src/tools/tools.pri +++ b/src/tools/tools.pri @@ -29,7 +29,8 @@ HEADERS += \ src/tools/nodeDetails/vabstractnode.h \ src/tools/nodeDetails/nodedetails.h \ src/tools/drawTools/vtoolcutspline.h \ - src/tools/drawTools/vtoolcutsplinepath.h + src/tools/drawTools/vtoolcutsplinepath.h \ + src/tools/vtooluniondetails.h SOURCES += \ src/tools/vtooldetail.cpp \ @@ -59,4 +60,5 @@ SOURCES += \ src/tools/nodeDetails/vnodearc.cpp \ src/tools/nodeDetails/vabstractnode.cpp \ src/tools/drawTools/vtoolcutspline.cpp \ - src/tools/drawTools/vtoolcutsplinepath.cpp + src/tools/drawTools/vtoolcutsplinepath.cpp \ + src/tools/vtooluniondetails.cpp diff --git a/src/tools/vabstracttool.cpp b/src/tools/vabstracttool.cpp index 21a7b02af..62e5260f6 100644 --- a/src/tools/vabstracttool.cpp +++ b/src/tools/vabstracttool.cpp @@ -68,6 +68,7 @@ const QString VAbstractTool::TypeLineLine = QStringLiteral("hair"); VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black) { + Q_ASSERT(doc != 0); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange); connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile); connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree); @@ -185,3 +186,27 @@ void VAbstractTool::LineCoefficients(const QLineF &line, qreal *a, qreal *b, qre *b = p1.x() - line.p2().x(); *c = - *a * p1.x() - *b * p1.y(); } + +void VAbstractTool::AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc) +{ + qint64 cursor = doc->getCursor(); + QVector *history = doc->getHistory(); + if (cursor <= 0) + { + history->append(VToolRecord(id, toolType, doc->GetNameActivDraw())); + } + else + { + qint32 index = 0; + for (qint32 i = 0; isize(); ++i) + { + VToolRecord rec = history->at(i); + if (rec.getId() == cursor) + { + index = i; + break; + } + } + history->insert(index+1, VToolRecord(id, toolType, doc->GetNameActivDraw())); + } +} diff --git a/src/tools/vabstracttool.h b/src/tools/vabstracttool.h index 038b3e2d4..109ce08a4 100644 --- a/src/tools/vabstracttool.h +++ b/src/tools/vabstracttool.h @@ -239,6 +239,13 @@ public: * @brief TypeLineLine */ static const QString TypeLineLine; + /** + * @brief AddRecord + * @param id + * @param toolType + * @param doc dom document container + */ + static void AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc); public slots: /** * @brief FullUpdateFromFile @@ -285,6 +292,10 @@ protected: * @brief AddToFile */ virtual void AddToFile()=0; + /** + * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. + */ + virtual void RefreshDataInFile()=0; /** * @brief getData * @return diff --git a/src/tools/vdatatool.cpp b/src/tools/vdatatool.cpp index 58a6eb39f..fe6b58ec4 100644 --- a/src/tools/vdatatool.cpp +++ b/src/tools/vdatatool.cpp @@ -28,10 +28,15 @@ #include "vdatatool.h" +VDataTool::VDataTool(VContainer *data, QObject *parent): QObject(parent), data(*data), _referens(1) +{ + Q_ASSERT(data != 0); +} + VDataTool &VDataTool::operator =(const VDataTool &tool) { - data = tool.getData(); - _referens = tool.referens(); + data = tool.getData(); + _referens = tool.referens(); return *this; } diff --git a/src/tools/vdatatool.h b/src/tools/vdatatool.h index a7b0cfcf5..ed58e14db 100644 --- a/src/tools/vdatatool.h +++ b/src/tools/vdatatool.h @@ -44,7 +44,7 @@ public: * @param data * @param parent */ - VDataTool(VContainer *data, QObject *parent = 0): QObject(parent), data(*data), _referens(1){} + VDataTool(VContainer *data, QObject *parent = 0); virtual ~VDataTool(){} /** * @brief operator = @@ -61,7 +61,7 @@ public: * @brief setData * @param value */ - inline void setData(const VContainer *value) {data = *value;} + inline void setData(const VContainer *value){data = *value;} /** * @brief referens * @return diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 5b30f986c..dc4198f91 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -72,7 +72,7 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, RefreshGeometry(); this->setPos(detail.getMx(), detail.getMy()); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - if (typeCreation == Tool::FromGui) + if (typeCreation == Tool::FromGui || typeCreation == Tool::FromTool) { AddToFile(); } @@ -97,29 +97,25 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen { case (Tool::NodePoint): { - VPointF point = data->GetPoint(detail[i].getId()); - id = data->AddPoint(point); + id = CreateNode(data, detail[i].getId()); VNodePoint::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); } break; case (Tool::NodeArc): { - VArc arc = data->GetArc(detail[i].getId()); - id = data->AddArc(arc); + id = CreateNode(data, detail[i].getId()); VNodeArc::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); } break; case (Tool::NodeSpline): { - VSpline spline = data->GetSpline(detail[i].getId()); - id = data->AddSpline(spline); + id = CreateNode(data, detail[i].getId()); VNodeSpline::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); } break; case (Tool::NodeSplinePath): { - VSplinePath splinePath = data->GetSplinePath(detail[i].getId()); - id = data->AddSplinePath(splinePath); + id = CreateNode(data, detail[i].getId()); VNodeSplinePath::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); } break; @@ -134,11 +130,11 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen Create(0, det, scene, doc, data, Document::FullParse, Tool::FromGui); } -void VToolDetail::Create(const qint64 _id, VDetail &newDetail, VMainGraphicsScene *scene, VDomDocument *doc, +void VToolDetail::Create(const qint64 &_id, const VDetail &newDetail, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) { qint64 id = _id; - if (typeCreation == Tool::FromGui) + if (typeCreation == Tool::FromGui || typeCreation == Tool::FromTool) { id = data->AddDetail(newDetail); } @@ -150,6 +146,7 @@ void VToolDetail::Create(const qint64 _id, VDetail &newDetail, VMainGraphicsScen doc->UpdateToolData(id, data); } } + VAbstractTool::AddRecord(id, Tool::Detail, doc); if (parse == Document::FullParse) { VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene); @@ -161,6 +158,34 @@ void VToolDetail::Create(const qint64 _id, VDetail &newDetail, VMainGraphicsScen } } +void VToolDetail::Remove() +{ + //remove form xml file + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + QDomNode element = domElement.parentNode(); + if (element.isNull() == false) + { + //deincrement referens + RemoveReferens(); + element.removeChild(domElement); + //update xml file + //emit FullUpdateTree(); + //remove form scene + emit RemoveTool(this); + } + else + { + qWarning()<<"parentNode isNull"<GeometricObject(det.at(i).getId())); + Q_ASSERT(point != 0); + point->setMode(Draw::Modeling); + BiasRotatePoint(point, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + idObject = data->AddGObject(point); + VPointF *point1 = new VPointF(*point); + Q_ASSERT(point1 != 0); + point1->setMode(Draw::Modeling); + id = data->AddGObject(point1); + VNodePoint::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); + } + } + break; + case (Tool::NodeArc): + { + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + { + id = det.at(i).getId(); + } + else + { + const VArc *arc = data->GeometricObject(det.at(i).getId()); + VPointF p1 = VPointF(arc->GetP1().x(), arc->GetP1().y(), "A", 0, 0); + BiasRotatePoint(&p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + VPointF p2 = VPointF(arc->GetP2().x(), arc->GetP2().y(), "A", 0, 0); + BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + VPointF *center = new VPointF(arc->GetCenter()); + Q_ASSERT(center != 0); + BiasRotatePoint(center, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + + QLineF l1(center->toQPointF(), p1.toQPointF()); + QLineF l2(center->toQPointF(), p2.toQPointF()); + qint64 idCenter = data->AddGObject(center); + Q_UNUSED(idCenter); + VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(), + l1.angle(), QString().setNum(l1.angle()), l2.angle(), + QString().setNum(l2.angle())); + Q_ASSERT(arc1 != 0); + arc1->setMode(Draw::Modeling); + idObject = data->AddGObject(arc1); + + VArc *arc2 = new VArc(*arc1); + Q_ASSERT(arc2 != 0); + arc2->setMode(Draw::Modeling); + id = data->AddGObject(arc2); + + VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); + } + } + break; + case (Tool::NodeSpline): + { + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + { + id = det.at(i).getId(); + } + else + { + const VSpline *spline = data->GeometricObject(det.at(i).getId()); + + VPointF *p1 = new VPointF(spline->GetP1()); + Q_ASSERT(p1 != 0); + BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + qint64 idP1 = data->AddGObject(p1); + + VPointF p2 = VPointF(spline->GetP2().x(), spline->GetP2().y(), "A", 0, 0); + BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + + VPointF p3 = VPointF(spline->GetP3().x(), spline->GetP3().y(), "A", 0, 0); + BiasRotatePoint(&p3, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + + VPointF *p4 = new VPointF(spline->GetP4()); + Q_ASSERT(p4 != 0); + BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + qint64 idP4 = data->AddGObject(p4); + + VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve()); + Q_ASSERT(spl != 0); + spl->setMode(Draw::Modeling); + id = data->AddGObject(spl); + + VSpline *spl1 = new VSpline(*spl); + Q_ASSERT(spl1 != 0); + spl1->setMode(Draw::Modeling); + idObject = data->AddGObject(spl1); + VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); + } + } + break; + case (Tool::NodeSplinePath): + { + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + { + id = det.at(i).getId(); + } + else + { + VSplinePath *path = new VSplinePath(); + Q_ASSERT(path != 0); + path->setMode(Draw::Modeling); + const VSplinePath *splinePath = data->GeometricObject(det.at(i).getId()); + for (qint32 i = 1; i <= splinePath->Count(); ++i) + { + VSpline spline(splinePath->at(i-1).P(), splinePath->at(i).P(), + splinePath->at(i-1).Angle2(), splinePath->at(i).Angle1(), splinePath->at(i-1).KAsm2(), + splinePath->at(i).KAsm1(), splinePath->getKCurve()); + + VPointF *p1 = new VPointF(spline.GetP1()); + Q_ASSERT(p1 != 0); + BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + qint64 idP1 = data->AddGObject(p1); + + VPointF p2 = VPointF(spline.GetP2()); + BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + + VPointF p3 = VPointF(spline.GetP3()); + BiasRotatePoint(&p3, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + + VPointF *p4 = new VPointF(spline.GetP4()); + Q_ASSERT(p4 != 0); + BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + qint64 idP4 = data->AddGObject(p4); + + VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve()); + if (i==1) + { + path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), + splinePath->at(i-1).KAsm1())); + } + path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(), + splinePath->at(i).KAsm1())); + } + idObject = data->AddGObject(path); + + VSplinePath *path1 = new VSplinePath(*path); + Q_ASSERT(path1 != 0); + path1->setMode(Draw::Modeling); + id = data->AddGObject(path1); + VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); + } + } + break; + default: + qWarning()<<"May be wrong tool type!!! Ignoring."<GeometricObject(det.at(i).getId())); + Q_ASSERT(point != 0); + point->setMode(Draw::Modeling); + BiasRotatePoint(point, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + ++idCount; + data->UpdateGObject(idDetail+idCount, point); + + ++idCount; + } + } + break; + case (Tool::NodeArc): + { + if (qFuzzyCompare(dx+1, 1) == false && qFuzzyCompare(dy+1, 1) == false && pRotate != 0) + { + const VArc *arc = data->GeometricObject(det.at(i).getId()); + VPointF p1 = VPointF(arc->GetP1()); + BiasRotatePoint(&p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + VPointF p2 = VPointF(arc->GetP2()); + BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + VPointF *center = new VPointF(arc->GetCenter()); + Q_ASSERT(center != 0); + BiasRotatePoint(center, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + + QLineF l1(center->toQPointF(), p1.toQPointF()); + QLineF l2(center->toQPointF(), p2.toQPointF()); + qint64 idCenter = data->AddGObject(center); + VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(), l1.angle(), + QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle())); + Q_ASSERT(arc1); + arc1->setMode(Draw::Modeling); + ++idCount; + data->UpdateGObject(idDetail+idCount, arc1); + + ++idCount; + } + } + break; + case (Tool::NodeSpline): + { + if (qFuzzyCompare(dx+1, 1) == false && qFuzzyCompare(dy+1, 1) == false && pRotate != 0) + { + const VSpline *spline = data->GeometricObject(det.at(i).getId()); + + VPointF *p1 = new VPointF(spline->GetP1()); + Q_ASSERT(p1 != 0); + BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + qint64 idP1 = data->AddGObject(p1); + + VPointF p2 = VPointF(spline->GetP2()); + BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + + VPointF p3 = VPointF(spline->GetP3()); + BiasRotatePoint(&p3, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + + VPointF *p4 = new VPointF(spline->GetP4()); + Q_ASSERT(p4 != 0); + BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + qint64 idP4 = data->AddGObject(p4); + + VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve()); + Q_ASSERT(spl != 0); + spl->setMode(Draw::Modeling); + ++idCount; + data->UpdateGObject(idDetail+idCount, spl); + + ++idCount; + } + } + break; + case (Tool::NodeSplinePath): + { + if (qFuzzyCompare(dx+1, 1) == false && qFuzzyCompare(dy+1, 1) == false && pRotate != 0) + { + VSplinePath *path = new VSplinePath(); + Q_ASSERT(path != 0); + path->setMode(Draw::Modeling); + const VSplinePath *splinePath = data->GeometricObject(det.at(i).getId()); + for (qint32 i = 1; i <= splinePath->Count(); ++i) + { + VSpline spline(splinePath->at(i-1).P(), splinePath->at(i).P(), + splinePath->at(i-1).Angle2(), splinePath->at(i).Angle1(), splinePath->at(i-1).KAsm2(), + splinePath->at(i).KAsm1(), splinePath->getKCurve()); + + VPointF *p1 = new VPointF(spline.GetP1()); + Q_ASSERT(p1 != 0); + BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + qint64 idP1 = data->AddGObject(p1); + + VPointF p2 = VPointF(spline.GetP2()); + BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + + VPointF p3 = VPointF(spline.GetP3()); + BiasRotatePoint(&p3, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + + VPointF *p4 = new VPointF(spline.GetP4()); + Q_ASSERT(p4 != 0); + BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + qint64 idP4 = data->AddGObject(p4); + + VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve()); + if (i==1) + { + path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), + splinePath->at(i-1).KAsm1())); + } + path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(), + splinePath->at(i).KAsm1())); + } + ++idCount; + data->UpdateGObject(idDetail+idCount, path); + + ++idCount; + } + } + break; + default: + qWarning()<<"May be wrong tool type!!! Ignoring."<setX(point->x()+dx); + point->setY(point->y()+dy); + QLineF line(pRotate, point->toQPointF()); + line.setAngle(line.angle()+angle); + point->setX(line.p2().x()); + point->setY(line.p2().y()); +} + +void VToolUnionDetails::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data) +{ + VDetail d1 = data->GetDetail(dialog->getD1()); + VDetail d2 = data->GetDetail(dialog->getD2()); + ptrdiff_t indexD1 = dialog->getIndexD1(); + ptrdiff_t indexD2 = dialog->getIndexD2(); + Create(0, d1, d2, dialog->getD1(), dialog->getD2(), indexD1, indexD2, scene, doc, data, Document::FullParse, + Tool::FromGui); +} + +void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetail &d2, const qint64 &d1id, + const qint64 &d2id, const ptrdiff_t &indexD1, const ptrdiff_t &indexD2, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ + VToolUnionDetails *unionDetails = 0; + qint64 id = _id; + if (typeCreation == Tool::FromGui) + { + id = data->getNextId(); + } + else + { + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + VAbstractTool::AddRecord(id, Tool::UnionDetails, doc); + if (parse == Document::FullParse) + { + //Scene doesn't show this tool, so doc will destroy this object. + unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation, doc); + QHash* tools = doc->getTools(); + tools->insert(id, unionDetails); + for (ptrdiff_t i = 0; i < d1.CountNode(); ++i) + { + doc->IncrementReferens(d1.at(i).getId()); + } + for (ptrdiff_t i = 0; i < d2.CountNode(); ++i) + { + doc->IncrementReferens(d2.at(i).getId()); + } + + } + + if (typeCreation == Tool::FromGui) + { + qint32 j = 0, i = 0; + qint32 nD1 = d1.CountNode(); + qint32 nD2 = d2.CountNode(); + qint32 pointsD2 = 0; //Keeps count points second detail, what we already add. + VDetail newDetail; + + do + { + AddToNewDetail(unionDetails, doc, data, newDetail, d1, i, id); + ++i; + if (i > indexD1 && pointsD2 < nD2-2) + { + VNodeDetail det1p1; + VNodeDetail det1p2; + d1.NodeOnEdge(indexD1, det1p1, det1p2); + const VPointF *point1 = data->GeometricObject(det1p1.getId()); + const VPointF *point2 = data->GeometricObject(det1p2.getId()); + + VNodeDetail det2p1; + VNodeDetail det2p2; + d2.NodeOnEdge(indexD2, det2p1, det2p2); + VPointF point3 = VPointF(*data->GeometricObject(det2p1.getId())); + VPointF point4 = VPointF(*data->GeometricObject(det2p2.getId())); + + qreal dx = point1->x() - point4.x(); + qreal dy = point1->y() - point4.y(); + + point3.setX(point3.x()+dx); + point3.setY(point3.y()+dy); + + point4.setX(point4.x()+dx); + point4.setY(point4.y()+dy); + + QLineF l1(point1->toQPointF(), point2->toQPointF()); + QLineF l2(point4.toQPointF(), point3.toQPointF()); + qreal angle = l2.angleTo(l1); + + do + { + if (pointsD2 == 0) + { + VNodeDetail node1; + VNodeDetail node2; + d2.NodeOnEdge(indexD2, node1, node2); + ptrdiff_t k = d2.indexOfNode(node2.getId()); + if (k == d2.CountNode()-1) + { + j = 0; + } + else + { + j = d2.indexOfNode(node2.getId())+1; + } + } + if (pointsD2 == nD2 -2) + { + break; + } + if (j >= nD2) + { + j=0; + } + AddToNewDetail(unionDetails, doc, data, newDetail, d2, j, id, dx, dy, det1p1.getId(), angle); + ++pointsD2; + ++j; + } while (pointsD2 < nD2); + } + }while(i* tools = doc->getTools(); + + VToolDetail *toolDet = qobject_cast(tools->value(d1id)); + toolDet->Remove(); + + toolDet = qobject_cast(tools->value(d2id)); + toolDet->Remove(); + } + else + { + qint64 idCount = 0; + qint32 j = 0, i = 0; + qint32 nD1 = d1.CountNode(); + qint32 nD2 = d2.CountNode(); + qint32 pointsD2 = 0; //Keeps count points second detail, what we already add. + + do + { + UpdatePoints(id, data, d1, i, idCount); + ++i; + if (i > indexD1 && pointsD2 < nD2-2) + { + VNodeDetail det1p1; + VNodeDetail det1p2; + d1.NodeOnEdge(indexD1, det1p1, det1p2); + const VPointF *point1 = data->GeometricObject(det1p1.getId()); + const VPointF *point2 = data->GeometricObject(det1p2.getId()); + + VNodeDetail det2p1; + VNodeDetail det2p2; + d2.NodeOnEdge(indexD2, det2p1, det2p2); + VPointF point3 = VPointF(*data->GeometricObject(det2p1.getId())); + VPointF point4 = VPointF(*data->GeometricObject(det2p2.getId())); + + qreal dx = point1->x() - point4.x(); + qreal dy = point1->y() - point4.y(); + + point3.setX(point3.x()+dx); + point3.setY(point3.y()+dy); + + point4.setX(point4.x()+dx); + point4.setY(point4.y()+dy); + + QLineF l1(point1->toQPointF(), point2->toQPointF()); + QLineF l2(point4.toQPointF(), point3.toQPointF()); + qreal angle = l2.angleTo(l1); + + do + { + if (pointsD2 == 0) + { + VNodeDetail node1; + VNodeDetail node2; + d2.NodeOnEdge(indexD2, node1, node2); + ptrdiff_t k = d2.indexOfNode(node2.getId()); + if (k == d2.CountNode()-1) + { + j = 0; + } + else + { + j = d2.indexOfNode(node2.getId())+1; + } + } + if (pointsD2 == nD2-2) + { + break; + } + if (j >= nD2) + { + j=0; + } + UpdatePoints(id, data, d2, j, idCount, dx, dy, det1p1.getId(), angle); + ++pointsD2; + ++j; + } while (pointsD2 < nD2); + } + }while(i VToolUnionDetails::GetDetailFromFile(VDomDocument *doc, const QDomElement &domElement) +{ + QVector vector; + QDomNodeList detailList = domElement.childNodes(); + qint32 num = detailList.size(); + for (qint32 i = 0; i < num; ++i) + { + QDomElement element = detailList.at(i).toElement(); + if (element.isNull() == false) + { + if (element.tagName() == VToolUnionDetails::TagDetail) + { + VDetail d; + QDomNodeList nodeList = element.childNodes(); + qint32 num = nodeList.size(); + for (qint32 j = 0; j < num; ++j) + { + QDomElement element = nodeList.at(j).toElement(); + if (element.isNull() == false) + { + if (element.tagName() == VToolUnionDetails::TagNode) + { + qint64 id = doc->GetParametrLongLong(element, VToolDetail::AttrIdObject, "0"); + qreal mx = toPixel(doc->GetParametrDouble(element, VAbstractTool::AttrMx, "0.0")); + qreal my = toPixel(doc->GetParametrDouble(element, VAbstractTool::AttrMy, "0.0")); + Tool::Tools tool; + NodeDetail::NodeDetails nodeType = NodeDetail::Contour; + QString t = doc->GetParametrString(element, "type", "NodePoint"); + if (t == "NodePoint") + { + tool = Tool::NodePoint; + } + else if (t == "NodeArc") + { + tool = Tool::NodeArc; + } + else if (t == "NodeSpline") + { + tool = Tool::NodeSpline; + } + else if (t == "NodeSplinePath") + { + tool = Tool::NodeSplinePath; + } + d.append(VNodeDetail(id, tool, nodeType, mx, my)); + } + } + } + vector.append(d); + } + } + } + return vector; +} + +void VToolUnionDetails::AddToFile() +{ + QDomElement domElement = doc->createElement(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrIndexD1, indexD1); + AddAttribute(domElement, AttrIndexD2, indexD2); + + AddDetail(domElement, d1); + AddDetail(domElement, d2); + + AddToModeling(domElement); +} + +void VToolUnionDetails::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrIndexD1, indexD1); + domElement.setAttribute(AttrIndexD2, indexD2); + + QDomNode domNode = domElement.firstChild(); + domNode = UpdateDetail(domNode, d1); + UpdateDetail(domNode, d2); + } +} + +void VToolUnionDetails::AddDetail(QDomElement &domElement, VDetail &d) +{ + QDomElement det = doc->createElement(TagDetail); + + for (ptrdiff_t i = 0; i < d.CountNode(); ++i) + { + AddNode(det, d[i]); + } + + domElement.appendChild(det); +} + +void VToolUnionDetails::AddNode(QDomElement &domElement, const VNodeDetail &node) +{ + QDomElement nod = doc->createElement(TagNode); + + AddAttribute(nod, AttrIdObject, node.getId()); + AddAttribute(nod, AttrMx, toMM(node.getMx())); + AddAttribute(nod, AttrMy, toMM(node.getMy())); + if (node.getTypeNode() == NodeDetail::Contour) + { + AddAttribute(nod, AttrNodeType, NodeTypeContour); + } + else + { + AddAttribute(nod, AttrNodeType, NodeTypeModeling); + } + switch (node.getTypeTool()) + { + case (Tool::NodeArc): + AddAttribute(nod, AttrType, QStringLiteral("NodeArc")); + break; + case (Tool::NodePoint): + AddAttribute(nod, AttrType, QStringLiteral("NodePoint")); + break; + case (Tool::NodeSpline): + AddAttribute(nod, AttrType, QStringLiteral("NodeSpline")); + break; + case (Tool::NodeSplinePath): + AddAttribute(nod, AttrType, QStringLiteral("NodeSplinePath")); + break; + default: + qWarning()<<"May be wrong tool type!!! Ignoring."<removeAllChilds(domElement);//delete all nodes in detail + for (ptrdiff_t i = 0; i < d.CountNode(); ++i) + { + AddNode(domElement, d.at(i));//rewrite nodes of detail + } + break; + } + } + } + } + return domNode.nextSibling(); +} + +void VToolUnionDetails::AddToModeling(const QDomElement &domElement) +{ + QDomElement modelingElement; + bool ok = doc->GetActivModelingElement(modelingElement); + if (ok) + { + modelingElement.appendChild(domElement); + } + else + { + qCritical()< + ** @date 26 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 + ** 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 . + ** + *************************************************************************/ + +#ifndef VTOOLUNIONDETAILS_H +#define VTOOLUNIONDETAILS_H + +#include "vabstracttool.h" +#include "../dialogs/dialoguniondetails.h" + +class VToolUnionDetails : public VAbstractTool +{ + Q_OBJECT +public: + VToolUnionDetails(VDomDocument *doc, VContainer *data, const qint64 &id, const VDetail &d1, const VDetail &d2, + const ptrdiff_t &indexD1, const ptrdiff_t &indexD2, + const Tool::Sources &typeCreation, QObject *parent = 0); + virtual void setDialog() {} + /** + * @brief Create + * @param dialog + * @param doc dom document container + * @param data + */ + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + /** + * @brief Create + * @param _id + * @param newDetail + * @param scene + * @param doc dom document container + * @param data + * @param parse + * @param typeCreation + */ + static void Create(const qint64 _id, const VDetail &d1, const VDetail &d2, const qint64 &d1id, const qint64 &d2id, + const ptrdiff_t &indexD1, const ptrdiff_t &indexD2, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + static QVector GetDetailFromFile(VDomDocument *doc, const QDomElement &domElement); + /** + * @brief TagName + */ + static const QString TagName; + static const QString ToolType; + static const QString TagDetail; + static const QString TagNode; + static const QString AttrIndexD1; + static const QString AttrIndexD2; + static const QString AttrIdObject; + static const QString AttrNodeType; + static const QString NodeTypeContour; + static const QString NodeTypeModeling; + + static void AddToNewDetail(QObject *tool, VDomDocument *doc, VContainer *data, VDetail &newDetail, + const VDetail &det, const ptrdiff_t &i, const qint64 &idTool, const qreal &dx = 0, + const qreal &dy = 0, const qint64 &pRotate = 0, const qreal &angle = 0); + static void UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &i, + qint64 &idCount, const qreal &dx = 0, const qreal &dy = 0, const qint64 &pRotate = 0, + const qreal &angle = 0); + static void BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate, + const qreal angle); +public slots: + /** + * @brief FullUpdateFromFile + */ + virtual void FullUpdateFromFile (){} +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(VToolUnionDetails) + VDetail d1; + VDetail d2; + ptrdiff_t indexD1; + ptrdiff_t indexD2; + void AddDetail(QDomElement &domElement, VDetail &d); + void AddNode(QDomElement &domElement, const VNodeDetail &node); + QDomNode UpdateDetail(const QDomNode &domNode, const VDetail &d); + void AddToModeling(const QDomElement &domElement); +}; + +#endif // VTOOLUNIONDETAILS_H diff --git a/src/widgets/vitem.cpp b/src/widgets/vitem.cpp index 536761501..f42b9a4d2 100644 --- a/src/widgets/vitem.cpp +++ b/src/widgets/vitem.cpp @@ -40,7 +40,8 @@ VItem::VItem (const QPainterPath & path, int numInList, QGraphicsItem * parent ) void VItem::checkItemChange() { QRectF rect; - if(paper == 0){ + if (paper == 0) + { qDebug()<<"Don't set paper for detail!!!!"; rect = this->scene()->sceneRect(); } diff --git a/src/widgets/vsimplespline.cpp b/src/widgets/vsimplespline.cpp index a610f8fc0..c77be792a 100644 --- a/src/widgets/vsimplespline.cpp +++ b/src/widgets/vsimplespline.cpp @@ -32,7 +32,7 @@ VSimpleSpline::VSimpleSpline(qint64 id, Qt::GlobalColor *currentColor, qreal *factor, QObject *parent) :QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor) { - if(factor == 0) + if (factor == 0) { setPen(QPen(Qt::black, widthHairLine)); } @@ -56,7 +56,7 @@ void VSimpleSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VSimpleSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - if(factor == 0) + if (factor == 0) { this->setPen(QPen(*currentColor, widthMainLine)); } @@ -69,7 +69,7 @@ void VSimpleSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void VSimpleSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - if(factor == 0) + if (factor == 0) { this->setPen(QPen(*currentColor, widthHairLine)); } diff --git a/src/widgets/vsimplesplinepath.cpp b/src/widgets/vsimplesplinepath.cpp index 134e288ae..fb63883b4 100644 --- a/src/widgets/vsimplesplinepath.cpp +++ b/src/widgets/vsimplesplinepath.cpp @@ -28,8 +28,8 @@ #include "vsimplesplinepath.h" -VSimpleSplinePath::VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor, QObject *parent) - :VAbstractTool(doc, data, id, parent), factor(factor) +VSimpleSplinePath::VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor) + :VAbstractTool(doc, data, id), factor(factor) { } diff --git a/src/widgets/vsimplesplinepath.h b/src/widgets/vsimplesplinepath.h index 03414a39a..034cbc118 100644 --- a/src/widgets/vsimplesplinepath.h +++ b/src/widgets/vsimplesplinepath.h @@ -36,7 +36,7 @@ class VSimpleSplinePath : public VAbstractTool, public QGraphicsPathItem { Q_OBJECT public: - VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor, QObject *parent = 0); + VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor); protected: /** * @brief mouseReleaseEvent diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index 28bd2d0b6..549de7d16 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -34,25 +34,26 @@ #include "../exception/vexceptionobjecterror.h" #include "../exception/vexceptionbadid.h" #include "../tools/vtooldetail.h" +#include "../tools/vtooluniondetails.h" #include "../tools/drawTools/drawtools.h" #include "../tools/nodeDetails/nodedetails.h" #include -VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode) - : QDomDocument(), map(QHash()), nameActivDraw(QString()), data(data), +VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, QObject *parent) + : QObject(parent), QDomDocument(), map(QHash()), nameActivDraw(QString()), data(data), tools(QHash()), history(QVector()), cursor(0), comboBoxDraws(comboBoxDraws), mode(mode){} -VDomDocument::VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, - Draw::Draws *mode) - :QDomDocument(name), map(QHash()), nameActivDraw(QString()), data(data), +VDomDocument::VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, + QObject *parent) + :QObject(parent), QDomDocument(name), map(QHash()), nameActivDraw(QString()), data(data), tools(QHash()), history(QVector()), cursor(0), comboBoxDraws(comboBoxDraws), mode(mode){} VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, - Draw::Draws *mode) - :QDomDocument(doctype), map(QHash()), nameActivDraw(QString()), data(data), + Draw::Draws *mode, QObject *parent) + :QObject(parent), QDomDocument(doctype), map(QHash()), nameActivDraw(QString()), data(data), tools(QHash()), history(QVector()), cursor(0), comboBoxDraws(comboBoxDraws), mode(mode){} @@ -77,6 +78,23 @@ QDomElement VDomDocument::elementById(const QString& id) return QDomElement(); } +void VDomDocument::removeAllChilds(QDomElement &element) +{ + QDomNode domNode = element.firstChild(); + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { + QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + element.removeChild(domElement); + } + } + domNode = element.firstChild(); + } +} + bool VDomDocument::find(const QDomElement &node, const QString& id) { if (node.hasAttribute("id")) @@ -320,6 +338,7 @@ void VDomDocument::Parse(const Document::Documents &parse, VMainGraphicsScene *s { TestUniqueId(); data->Clear(); + data->CreateManTableIGroup(); nameActivDraw.clear(); sceneDraw->clear(); sceneDetail->clear(); @@ -371,6 +390,20 @@ void VDomDocument::Parse(const Document::Documents &parse, VMainGraphicsScene *s } } +VDataTool *VDomDocument::getTool(const qint64 &id) +{ + if (tools.contains(id)) + { + return tools.value(id); + } + else + { + QString error = QString(tr("Can't find tool id = %1 in table.")).arg(id); + throw VException(error); + } + return 0; +} + void VDomDocument::ParseIncrementsElement(const QDomNode &node) { QDomNode domNode = node.firstChild(); @@ -384,14 +417,13 @@ void VDomDocument::ParseIncrementsElement(const QDomNode &node) if (domElement.tagName() == "increment") { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal base = GetParametrDouble(domElement, "base"); - qreal ksize = GetParametrDouble(domElement, "ksize"); - qreal kgrowth = GetParametrDouble(domElement, "kgrowth"); - QString desc = GetParametrString(domElement, "description"); + QString name = GetParametrString(domElement, "name", ""); + qreal base = GetParametrDouble(domElement, "base", "0"); + qreal ksize = GetParametrDouble(domElement, "ksize", "0"); + qreal kgrowth = GetParametrDouble(domElement, "kgrowth", "0"); + QString desc = GetParametrString(domElement, "description", "Description"); data->UpdateId(id); - data->AddIncrementTableRow(name, - VIncrementTableRow(id, base, ksize, kgrowth, desc)); + data->AddIncrementTableRow(name, VIncrementTableRow(id, base, ksize, kgrowth, desc)); } } } @@ -402,7 +434,7 @@ void VDomDocument::ParseIncrementsElement(const QDomNode &node) qint64 VDomDocument::GetParametrId(const QDomElement &domElement) const { Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - qint64 id = GetParametrLongLong(domElement, "id"); + qint64 id = GetParametrLongLong(domElement, "id", "0"); if (id <= 0) { throw VExceptionWrongParameterId(tr("Got wrong parameter id. Need only id > 0."), domElement); @@ -410,12 +442,13 @@ qint64 VDomDocument::GetParametrId(const QDomElement &domElement) const return id; } -qint64 VDomDocument::GetParametrLongLong(const QDomElement &domElement, const QString &name) const +qint64 VDomDocument::GetParametrLongLong(const QDomElement &domElement, const QString &name, + const QString &defValue) const { Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); bool ok = false; - QString parametr = GetParametrString(domElement, name); + QString parametr = GetParametrString(domElement, name, defValue); qint64 id = parametr.toLongLong(&ok); if (ok == false) { @@ -424,11 +457,12 @@ qint64 VDomDocument::GetParametrLongLong(const QDomElement &domElement, const QS return id; } -QString VDomDocument::GetParametrString(const QDomElement &domElement, const QString &name) const +QString VDomDocument::GetParametrString(const QDomElement &domElement, const QString &name, + const QString &defValue) const { Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - QString parameter = domElement.attribute(name, ""); + QString parameter = domElement.attribute(name, defValue); if (parameter.isEmpty()) { throw VExceptionEmptyParameter(tr("Got empty parameter"), name, domElement); @@ -436,15 +470,17 @@ QString VDomDocument::GetParametrString(const QDomElement &domElement, const QSt return parameter; } -qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QString &name) const +qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QString &name, const QString &defValue) const { Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); bool ok = false; - QString parametr = GetParametrString(domElement, name); + QString parametr = GetParametrString(domElement, name, defValue); qreal param = parametr.replace(",", ".").toDouble(&ok); if (ok == false) { + qDebug()<<"defValue"<ClearObject(); + data->ClearCalculationGObjects(); ParseDrawMode(sceneDraw, sceneDetail, domElement, parse, Draw::Calculation); } if (domElement.tagName() == "modeling") @@ -549,6 +585,11 @@ void VDomDocument::ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsSce ParseArcElement(scene, domElement, parse, domElement.attribute("type", "")); continue; } + if (domElement.tagName() == "tools") + { + ParseToolsElement(scene, domElement, parse, domElement.attribute("type", "")); + continue; + } } } } @@ -563,12 +604,12 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo VDetail detail; VDetail oldDetail; qint64 id = GetParametrId(domElement); - detail.setName(GetParametrString(domElement, "name")); - detail.setMx(toPixel(GetParametrDouble(domElement, "mx"))); - detail.setMy(toPixel(GetParametrDouble(domElement, "my"))); - detail.setSupplement(GetParametrLongLong(domElement, "supplement")); - detail.setWidth(GetParametrDouble(domElement, "width")); - detail.setClosed(GetParametrLongLong(domElement, "closed")); + detail.setName(GetParametrString(domElement, VAbstractTool::AttrName, "")); + detail.setMx(toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "0.0"))); + detail.setMy(toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "0.0"))); + detail.setSupplement(GetParametrLongLong(domElement, VToolDetail::AttrSupplement, "1")); + detail.setWidth(GetParametrDouble(domElement, VToolDetail::AttrWidth, "10.0")); + detail.setClosed(GetParametrLongLong(domElement, VToolDetail::AttrClosed, "1")); QDomNodeList nodeList = domElement.childNodes(); qint32 num = nodeList.size(); @@ -577,37 +618,37 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo QDomElement element = nodeList.at(i).toElement(); if (element.isNull() == false) { - if (element.tagName() == "node") + if (element.tagName() == VToolDetail::TagNode) { - qint64 id = GetParametrLongLong(element, "idObject"); - qreal mx = toPixel(GetParametrDouble(element, "mx")); - qreal my = toPixel(GetParametrDouble(element, "my")); + qint64 id = GetParametrLongLong(element, VToolDetail::AttrIdObject, "0"); + qreal mx = toPixel(GetParametrDouble(element, VAbstractTool::AttrMx, "0.0")); + qreal my = toPixel(GetParametrDouble(element, VAbstractTool::AttrMy, "0.0")); Tool::Tools tool; NodeDetail::NodeDetails nodeType = NodeDetail::Contour; - QString t = GetParametrString(element, "type"); + QString t = GetParametrString(element, "type", "NodePoint"); if (t == "NodePoint") { tool = Tool::NodePoint; - VPointF point = data->GetPoint(id); - oldDetail.append(VNodeDetail(point.getIdObject(), tool, NodeDetail::Contour)); +// const VPointF *point = data->GeometricObject(id); +// oldDetail.append(VNodeDetail(point.getIdObject(), tool, NodeDetail::Contour)); } else if (t == "NodeArc") { tool = Tool::NodeArc; - VArc arc = data->GetArc(id); - oldDetail.append(VNodeDetail(arc.getIdObject(), tool, NodeDetail::Contour)); +// VArc arc = data->GetArc(id); +// oldDetail.append(VNodeDetail(arc.getIdObject(), tool, NodeDetail::Contour)); } else if (t == "NodeSpline") { tool = Tool::NodeSpline; - VSpline spl = data->GetSpline(id); - oldDetail.append(VNodeDetail(spl.getIdObject(), tool, NodeDetail::Contour)); +// VSpline spl = data->GetSpline(id); +// oldDetail.append(VNodeDetail(spl.getIdObject(), tool, NodeDetail::Contour)); } else if (t == "NodeSplinePath") { tool = Tool::NodeSplinePath; - VSplinePath splPath = data->GetSplinePath(id); - oldDetail.append(VNodeDetail(splPath.getIdObject(), tool, NodeDetail::Contour)); +// VSplinePath splPath = data->GetSplinePath(id); +// oldDetail.append(VNodeDetail(splPath.getIdObject(), tool, NodeDetail::Contour)); } detail.append(VNodeDetail(id, tool, nodeType, mx, my)); } @@ -636,7 +677,7 @@ void VDomDocument::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomEleme QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - if (domElement.tagName() == "detail") + if (domElement.tagName() == VToolDetail::TagName) { ParseDetailElement(sceneDetail, domElement, parse); } @@ -652,18 +693,19 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen Q_ASSERT(scene != 0); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of point is empty"); - if (type == "single") + if (type == VToolSinglePoint::ToolType) { + VToolSinglePoint *spoint = 0; try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal x = toPixel(GetParametrDouble(domElement, "x")); - qreal y = toPixel(GetParametrDouble(domElement, "y")); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, "A"); + qreal x = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrX, "10.0")); + qreal y = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrY, "10.0")); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); - data->UpdatePoint(id, VPointF(x, y, name, mx, my)); + data->UpdateGObject(id, new VPointF(x, y, name, mx, my)); VDrawTool::AddRecord(id, Tool::SinglePointTool, this); if (parse != Document::FullParse) { @@ -671,7 +713,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen } if (parse == Document::FullParse) { - VToolSinglePoint *spoint = new VToolSinglePoint(this, data, id, Tool::FromFile); + spoint = new VToolSinglePoint(this, data, id, Tool::FromFile); Q_ASSERT(spoint != 0); scene->addItem(spoint); connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); @@ -684,21 +726,23 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen { VExceptionObjectError excep(tr("Error creating or updating single point"), domElement); excep.AddMoreInformation(e.ErrorMessage()); + scene->RemoveTool(spoint); + delete spoint; throw excep; } } - if (type == "endLine") + if (type == VToolEndLine::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - QString typeLine = GetParametrString(domElement, "typeLine"); - QString formula = GetParametrString(domElement, "length"); - qint64 basePointId = GetParametrLongLong(domElement, "basePoint"); - qreal angle = GetParametrDouble(domElement, "angle"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); + QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); + qint64 basePointId = GetParametrLongLong(domElement, VAbstractTool::AttrBasePoint, "0"); + qreal angle = GetParametrDouble(domElement, VAbstractTool::AttrAngle, "0.0"); VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, scene, this, data, parse, Tool::FromFile); @@ -711,18 +755,18 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "alongLine") + if (type == VToolAlongLine::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - QString typeLine = GetParametrString(domElement, "typeLine"); - QString formula = GetParametrString(domElement, "length"); - qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); - qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); + QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); + qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); + qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my, scene, this, data, parse, Tool::FromFile); @@ -735,19 +779,19 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "shoulder") + if (type == VToolShoulderPoint::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - QString typeLine = GetParametrString(domElement, "typeLine"); - QString formula = GetParametrString(domElement, "length"); - qint64 p1Line = GetParametrLongLong(domElement, "p1Line"); - qint64 p2Line = GetParametrLongLong(domElement, "p2Line"); - qint64 pShoulder = GetParametrLongLong(domElement, "pShoulder"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); + QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); + qint64 p1Line = GetParametrLongLong(domElement, VAbstractTool::AttrP1Line, "0"); + qint64 p2Line = GetParametrLongLong(domElement, VAbstractTool::AttrP2Line, "0"); + qint64 pShoulder = GetParametrLongLong(domElement, VAbstractTool::AttrPShoulder, "0"); VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my, scene, this, data, parse, Tool::FromFile); @@ -760,19 +804,19 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "normal") + if (type == VToolNormal::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - QString typeLine = GetParametrString(domElement, "typeLine"); - QString formula = GetParametrString(domElement, "length"); - qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); - qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); - qreal angle = GetParametrDouble(domElement, "angle"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); + QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); + qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); + qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); + qreal angle = GetParametrDouble(domElement, VAbstractTool::AttrAngle, "0.0"); VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle, mx, my, scene, this, data, parse, Tool::FromFile); @@ -785,19 +829,19 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "bisector") + if (type == VToolBisector::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - QString typeLine = GetParametrString(domElement, "typeLine"); - QString formula = GetParametrString(domElement, "length"); - qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); - qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); - qint64 thirdPointId = GetParametrLongLong(domElement, "thirdPoint"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); + QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); + qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); + qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); + qint64 thirdPointId = GetParametrLongLong(domElement, VAbstractTool::AttrThirdPoint, "0"); VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine, name, mx, my, scene, this, data, parse, Tool::FromFile); @@ -810,18 +854,18 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "lineIntersect") + if (type == VToolLineIntersect::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - qint64 p1Line1Id = GetParametrLongLong(domElement, "p1Line1"); - qint64 p2Line1Id = GetParametrLongLong(domElement, "p2Line1"); - qint64 p1Line2Id = GetParametrLongLong(domElement, "p1Line2"); - qint64 p2Line2Id = GetParametrLongLong(domElement, "p2Line2"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + qint64 p1Line1Id = GetParametrLongLong(domElement, VAbstractTool::AttrP1Line1, "0"); + qint64 p2Line1Id = GetParametrLongLong(domElement, VAbstractTool::AttrP2Line1, "0"); + qint64 p1Line2Id = GetParametrLongLong(domElement, VAbstractTool::AttrP1Line2, "0"); + qint64 p2Line2Id = GetParametrLongLong(domElement, VAbstractTool::AttrP2Line2, "0"); VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my, scene, this, data, parse, Tool::FromFile); @@ -834,18 +878,18 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "pointOfContact") + if (type == VToolPointOfContact::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - QString radius = GetParametrString(domElement, "radius"); - qint64 center = GetParametrLongLong(domElement, "center"); - qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); - qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + QString radius = GetParametrString(domElement, VAbstractTool::AttrRadius, "0"); + qint64 center = GetParametrLongLong(domElement, VAbstractTool::AttrCenter, "0"); + qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); + qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); VToolPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my, scene, this, data, parse, Tool::FromFile); @@ -858,17 +902,19 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "modeling") + if (type == VNodePoint::ToolType) { try { qint64 id = GetParametrId(domElement); - qint64 idObject = GetParametrLongLong(domElement, "idObject"); - VPointF point = data->GetPoint(idObject ); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - data->UpdatePoint(id, VPointF(point.x(), point.y(), point.name(), mx, my, idObject )); - VNodePoint::Create(this, data, id, idObject, parse, Tool::FromFile); + qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); + qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0"); + const VPointF *point = data->GeometricObject(idObject ); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + data->UpdateGObject(id, new VPointF(point->x(), point->y(), point->name(), mx, my, idObject, + Draw::Modeling)); + VNodePoint::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); return; } catch (const VExceptionBadId &e) @@ -878,18 +924,18 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "height") + if (type == VToolHeight::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - QString typeLine = GetParametrString(domElement, "typeLine"); - qint64 basePointId = GetParametrLongLong(domElement, "basePoint"); - qint64 p1LineId = GetParametrLongLong(domElement, "p1Line"); - qint64 p2LineId = GetParametrLongLong(domElement, "p2Line"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + QString typeLine = GetParametrString(domElement, VAbstractTool::AttrTypeLine, VAbstractTool::TypeLineLine); + qint64 basePointId = GetParametrLongLong(domElement, VAbstractTool::AttrBasePoint, "0"); + qint64 p1LineId = GetParametrLongLong(domElement, VAbstractTool::AttrP1Line, "0"); + qint64 p2LineId = GetParametrLongLong(domElement, VAbstractTool::AttrP2Line, "0"); VToolHeight::Create(id, name, typeLine, basePointId, p1LineId, p2LineId, mx, my, scene, this, data, parse, Tool::FromFile); @@ -902,18 +948,18 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "triangle") + if (type == VToolTriangle::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - qint64 axisP1Id = GetParametrLongLong(domElement, "axisP1"); - qint64 axisP2Id = GetParametrLongLong(domElement, "axisP2"); - qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); - qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + qint64 axisP1Id = GetParametrLongLong(domElement, VAbstractTool::AttrAxisP1, "0"); + qint64 axisP2Id = GetParametrLongLong(domElement, VAbstractTool::AttrAxisP2, "0"); + qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); + qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); VToolTriangle::Create(id, name, axisP1Id, axisP2Id, firstPointId, secondPointId, mx, my, scene, this, data, parse, Tool::FromFile); @@ -926,16 +972,16 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "pointOfIntersection") + if (type == VToolPointOfIntersection::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); - qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + qint64 firstPointId = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); + qint64 secondPointId = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); VToolPointOfIntersection::Create(id, name, firstPointId, secondPointId, mx, my, scene, this, data, parse, Tool::FromFile); @@ -948,16 +994,16 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "cutSpline") + if (type == VToolCutSpline::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - QString formula = GetParametrString(domElement, "length"); - qint64 splineId = GetParametrLongLong(domElement, "spline"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "0"); + qint64 splineId = GetParametrLongLong(domElement, VToolCutSpline::AttrSpline, "0"); VToolCutSpline::Create(id, name, formula, splineId, mx, my, scene, this, data, parse, Tool::FromFile); return; @@ -969,16 +1015,16 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } - if (type == "cutSplinePath") + if (type == VToolCutSplinePath::ToolType) { try { qint64 id = GetParametrId(domElement); - QString name = GetParametrString(domElement, "name"); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); - QString formula = GetParametrString(domElement, "length"); - qint64 splinePathId = GetParametrLongLong(domElement, "splinePath"); + QString name = GetParametrString(domElement, VAbstractTool::AttrName, ""); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); + QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "0"); + qint64 splinePathId = GetParametrLongLong(domElement, VToolCutSplinePath::AttrSplinePath, "0"); VToolCutSplinePath::Create(id, name, formula, splinePathId, mx, my, scene, this, data, parse, Tool::FromFile); @@ -1001,8 +1047,8 @@ void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement try { qint64 id = GetParametrId(domElement); - qint64 firstPoint = GetParametrLongLong(domElement, "firstPoint"); - qint64 secondPoint = GetParametrLongLong(domElement, "secondPoint"); + qint64 firstPoint = GetParametrLongLong(domElement, VAbstractTool::AttrFirstPoint, "0"); + qint64 secondPoint = GetParametrLongLong(domElement, VAbstractTool::AttrSecondPoint, "0"); VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile); } @@ -1020,18 +1066,18 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme Q_ASSERT(scene != 0); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); - if (type == "simple") + if (type == VToolSpline::ToolType) { try { qint64 id = GetParametrId(domElement); - qint64 point1 = GetParametrLongLong(domElement, "point1"); - qint64 point4 = GetParametrLongLong(domElement, "point4"); - qreal angle1 = GetParametrDouble(domElement, "angle1"); - qreal angle2 = GetParametrDouble(domElement, "angle2"); - qreal kAsm1 = GetParametrDouble(domElement, "kAsm1"); - qreal kAsm2 = GetParametrDouble(domElement, "kAsm2"); - qreal kCurve = GetParametrDouble(domElement, "kCurve"); + qint64 point1 = GetParametrLongLong(domElement, VAbstractTool::AttrPoint1, "0"); + qint64 point4 = GetParametrLongLong(domElement, VAbstractTool::AttrPoint4, "0"); + qreal angle1 = GetParametrDouble(domElement, VAbstractTool::AttrAngle1, "270.0"); + qreal angle2 = GetParametrDouble(domElement, VAbstractTool::AttrAngle2, "90.0"); + qreal kAsm1 = GetParametrDouble(domElement, VAbstractTool::AttrKAsm1, "1.0"); + qreal kAsm2 = GetParametrDouble(domElement, VAbstractTool::AttrKAsm2, "1.0"); + qreal kCurve = GetParametrDouble(domElement, VAbstractTool::AttrKCurve, "1.0"); VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data, parse, Tool::FromFile); @@ -1044,13 +1090,14 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme throw excep; } } - if (type == "path") + if (type == VToolSplinePath::ToolType) { try { qint64 id = GetParametrId(domElement); - qreal kCurve = GetParametrDouble(domElement, "kCurve"); - VSplinePath path(data->DataPoints(), kCurve); + qreal kCurve = GetParametrDouble(domElement, VAbstractTool::AttrKCurve, "1.0"); + VSplinePath *path = new VSplinePath(kCurve); + Q_ASSERT(path != 0); QDomNodeList nodeList = domElement.childNodes(); qint32 num = nodeList.size(); @@ -1059,14 +1106,16 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme QDomElement element = nodeList.at(i).toElement(); if (element.isNull() == false) { - if (element.tagName() == "pathPoint") + if (element.tagName() == VAbstractTool::AttrPathPoint) { - qreal kAsm1 = GetParametrDouble(element, "kAsm1"); - qreal angle = GetParametrDouble(element, "angle"); - qreal kAsm2 = GetParametrDouble(element, "kAsm2"); - qint64 pSpline = GetParametrLongLong(element, "pSpline"); - VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2); - path.append(splPoint); + qreal kAsm1 = GetParametrDouble(element, VAbstractTool::AttrKAsm1, "1.0"); + qreal angle = GetParametrDouble(element, VAbstractTool::AttrAngle, "0"); + qreal kAsm2 = GetParametrDouble(element, VAbstractTool::AttrKAsm2, "1.0"); + qint64 pSpline = GetParametrLongLong(element, VAbstractTool::AttrPSpline, "0"); + VPointF p = *data->GeometricObject(pSpline); + + VSplinePoint splPoint(p, kAsm1, angle, kAsm2); + path->append(splPoint); if (parse == Document::FullParse) { IncrementReferens(pSpline); @@ -1085,16 +1134,18 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme throw excep; } } - if (type == "modelingSpline") + if (type == VNodeSpline::ToolType) { try { qint64 id = GetParametrId(domElement); - qint64 idObject = GetParametrLongLong(domElement, "idObject"); - VSpline spl = data->GetSpline(idObject); - spl.setIdObject(idObject); - data->UpdateSpline(id, spl); - VNodeSpline::Create(this, data, id, idObject, parse, Tool::FromFile); + qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); + qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0"); + VSpline *spl = new VSpline(*data->GeometricObject(idObject)); + Q_ASSERT(spl != 0); + spl->setIdObject(idObject); + data->UpdateGObject(id, spl); + VNodeSpline::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); return; } catch (const VExceptionBadId &e) @@ -1104,16 +1155,18 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme throw excep; } } - if (type == "modelingPath") + if (type == VNodeSplinePath::ToolType) { try { qint64 id = GetParametrId(domElement); - qint64 idObject = GetParametrLongLong(domElement, "idObject"); - VSplinePath path = data->GetSplinePath(idObject); - path.setIdObject(idObject); - data->UpdateSplinePath(id, path); - VNodeSplinePath::Create(this, data, id, idObject, parse, Tool::FromFile); + qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); + qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0"); + VSplinePath *path = new VSplinePath(*data->GeometricObject(idObject)); + Q_ASSERT(path != 0); + path->setIdObject(idObject); + data->UpdateGObject(id, path); + VNodeSplinePath::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); return; } catch (const VExceptionBadId &e) @@ -1131,15 +1184,15 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement Q_ASSERT(scene != 0); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); - if (type == "simple") + if (type == VToolArc::ToolType) { try { qint64 id = GetParametrId(domElement); - qint64 center = GetParametrLongLong(domElement, "center"); - QString radius = GetParametrString(domElement, "radius"); - QString f1 = GetParametrString(domElement, "angle1"); - QString f2 = GetParametrString(domElement, "angle2"); + qint64 center = GetParametrLongLong(domElement, VAbstractTool::AttrCenter, "0"); + QString radius = GetParametrString(domElement, VAbstractTool::AttrRadius, "10"); + QString f1 = GetParametrString(domElement, VAbstractTool::AttrAngle1, "180"); + QString f2 = GetParametrString(domElement, VAbstractTool::AttrAngle2, "270"); VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile); @@ -1152,16 +1205,18 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement throw excep; } } - if (type == "modeling") + if (type == VNodeArc::ToolType) { try { qint64 id = GetParametrId(domElement); - qint64 idObject = GetParametrLongLong(domElement, "idObject"); - VArc arc = data->GetArc(idObject); - arc.setIdObject(idObject); - data->UpdateArc(id, arc); - VNodeArc::Create(this, data, id, idObject, parse, Tool::FromFile); + qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); + qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0"); + VArc *arc = new VArc(*data->GeometricObject(idObject)); + Q_ASSERT(arc != 0); + arc->setIdObject(idObject); + data->UpdateGObject(id, arc); + VNodeArc::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); return; } catch (const VExceptionBadId &e) @@ -1173,13 +1228,43 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement } } +void VDomDocument::ParseToolsElement(VMainGraphicsScene *scene, const QDomElement &domElement, + const Document::Documents &parse, const QString &type) +{ + Q_ASSERT(scene != 0); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); + if (type == VToolUnionDetails::ToolType) + { + try + { + qint64 id = GetParametrId(domElement); + qint64 indexD1 = GetParametrLongLong(domElement, VToolUnionDetails::AttrIndexD1, "-1"); + qint64 indexD2 = GetParametrLongLong(domElement, VToolUnionDetails::AttrIndexD2, "-1"); + + QVector vector = VToolUnionDetails::GetDetailFromFile(this, domElement); + + VToolUnionDetails::Create(id, vector[0], vector[1], 0, 0, indexD1, indexD2, scene, this, data, parse, + Tool::FromFile); + + return; + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating union details"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + } +} + void VDomDocument::FullUpdateTree() { VMainGraphicsScene *scene = new VMainGraphicsScene(); Q_ASSERT(scene != 0); try { - data->ClearObject(); + data->ClearGObjects(); Parse(Document::LiteParse, scene, scene); } catch (const std::bad_alloc &) diff --git a/src/xml/vdomdocument.h b/src/xml/vdomdocument.h index 897cae319..493223779 100644 --- a/src/xml/vdomdocument.h +++ b/src/xml/vdomdocument.h @@ -66,7 +66,7 @@ public: * @param comboBoxDraws * @param mode */ - VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode); + VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, QObject *parent = 0); /** * @brief VDomDocument * @param name @@ -74,7 +74,8 @@ public: * @param comboBoxDraws * @param mode */ - VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode); + VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, + QObject *parent = 0); /** * @brief VDomDocument * @param doc dom document containertype @@ -83,7 +84,7 @@ public: * @param mode */ VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, - Draw::Draws *mode); + Draw::Draws *mode, QObject *parent = 0); ~VDomDocument(){} /** * @brief elementById @@ -91,6 +92,7 @@ public: * @return */ QDomElement elementById(const QString& id); + void removeAllChilds(QDomElement &element); /** * @brief CreateEmptyFile */ @@ -155,6 +157,7 @@ public: * @return */ inline QHash* getTools() {return &tools;} + VDataTool* getTool(const qint64 &id); /** * @brief getHistory * @return @@ -200,6 +203,28 @@ public: * @brief TestUniqueId */ void TestUniqueId() const; + /** + * @brief GetParametrLongLong + * @param domElement + * @param name + * @return + */ + qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name, + const QString &defValue) const; + /** + * @brief GetParametrString + * @param domElement + * @param name + * @return + */ + QString GetParametrString(const QDomElement& domElement, const QString &name, const QString &defValue) const; + /** + * @brief GetParametrDouble + * @param domElement + * @param name + * @return + */ + qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; signals: /** * @brief ChangedActivDraw @@ -211,7 +236,7 @@ signals: * @param oldName * @param newName */ - void ChangedNameDraw(const QString oldName, const QString newName); + void ChangedNameDraw(const QString &oldName, const QString &newName); /** * @brief FullUpdateFromFile */ @@ -381,6 +406,8 @@ private: */ void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement, const Document::Documents &parse, const QString& type); + void ParseToolsElement(VMainGraphicsScene *scene, const QDomElement& domElement, + const Document::Documents &parse, const QString& type); /** * @brief ParseIncrementsElement * @param node @@ -392,27 +419,6 @@ private: * @return */ qint64 GetParametrId(const QDomElement& domElement) const; - /** - * @brief GetParametrLongLong - * @param domElement - * @param name - * @return - */ - qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name) const; - /** - * @brief GetParametrString - * @param domElement - * @param name - * @return - */ - QString GetParametrString(const QDomElement& domElement, const QString &name) const; - /** - * @brief GetParametrDouble - * @param domElement - * @param name - * @return - */ - qreal GetParametrDouble(const QDomElement& domElement, const QString &name) const; /** * @brief CollectId * @param node