From b2378b4fad886acd2c036a55b51acfa53cf93fc7 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 23 Dec 2013 13:13:28 +0200 Subject: [PATCH 01/15] Cursor and icon for tool "Union details". --HG-- branch : feature --- share/resources/cursor.qrc | 1 + share/resources/cursor/union_cursor.png | Bin 0 -> 1359 bytes share/resources/icon.qrc | 1 + share/resources/icon/32x32/union.png | Bin 0 -> 796 bytes src/mainwindow.ui | 28 ++++++++++++++++++++---- 5 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 share/resources/cursor/union_cursor.png create mode 100644 share/resources/icon/32x32/union.png 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 0000000000000000000000000000000000000000..687d2ca5921dfeafe05867413343ef81d66cd7e2 GIT binary patch literal 1359 zcmV-V1+e;wP)Vl&|00006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru-3%8C3Kt(ErP=@h06}y` zSad^gZEa<4bO1wAML|?gQaT`KWG!lNWoICEF)lD5D0OpbZf77#N=G0{P(?=|b~Z98 zEFf`pVQgu1c_2L?IWP*aMOc#n00fUoL_t(Y$HkUyXq9Cc$A9^$Raot;uQyWoQ7zMuPfuIu{$ua_JCPuaV7?~L`19Xr$`bzsk) zJ-1e^S|xRLbs{1w9;xx#+S*Hil$Di9>V8j8&w|=@0362w;P&m?5{X2_bzN4kUL7ef zFaKo0Bj2!L!zDm$+ZLsi0MgRZ(!S7kt<;6*d5BCQKQJ(`eAljBZ??3wR6UZ&{pfvF zN=a2!m9)3FKek|;r;0HK01?5mEQ*SXXl!g8T`<^{nksFj)bz9ONNZ~=N+}74!%|sU znX_P=`+TR0QVPd$5D_k1xDfaEJ3Bkog2A3DT5Dplm^3vtiPoB?rY7p^>*vRKx`=(T zZ5z+?0Mzm0#{sCRshNM+(?PDaMnn*i>1K5O`gMTN+O=y-=e5*Q)o(aTscH4!Wo2ba zNlA%3H0-GvK34)NrDm)rCML+q$srnzF6-{@&Re%`-9UA9_3%R_Tsr8}Iii%Jx3`x_ zB+@%NI!bJ3?jnSt5+Eu93&o(Px@yrUcC6lpSY;0^s$J1KlI1ah_xfo-JkHtYL);zNYAa8aIKmZudm~j3;F~*>jlIrSe)6vn9 zDKXCilgS^eb7#&1d^Wpr0{K8Qa5HU(Gsa+979t{+WsMtSMvXC}ZEbD2TefVuH;3`% zz;598X#+1UTUK^Xl0iDNhKlF9?wv#;(VLr_+qrMwzMjIu z!hzD#Qq|YjH&;nWGQw%uy>lo1{kP0-zxES7|2?*C1JnQqJ*|6zZHt#I`N085BoY8p zP*8Ah`}XZW9zJ~d!$cx+O>522(2#K)$I8jcF_V*%7-J+mJDWftKr9yXjq9WX0x%LA zQ5|2O^wAU%!M5#TrPM20>*s(shKGhm6u|oR>o1)?efp`DD_0I(zI?ePZ9|yKg&AvO zj1rMwfco|`9oOvaMV|3Iv29yv?aAinH;#)4+1UY#7KaFh3JEVQrR$p$n}BEitMhw6 z{*^0N?jAdKY{k~CTYvtyIq!KMj^l{d+6CU<^g_c3;H4ZX0NR4VVB5sR1Vh6yKv?8v z0Sp3V4>XMefdIB``-%Dl@OV;-lNtspflq;ArPTC!*L49ZfY0yCnCrS&mX)#f0(|#v z7b2p72v7~!fZBg#zpbV|dL4K=<5ega3^G1GKHcroU9skp7wc*{akA@4;8mbES?h~{ z62N=;wQUD8PPKSE?s}eQX|3icon/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 0000000000000000000000000000000000000000..5c8ad9c88bbd265e5b44d8b819be2b1ec3dccc68 GIT binary patch literal 796 zcmV+%1LOROP) zA8gzIZU%4}xBxr`MuChE`<4Jl9j!V7DdU$_b0{Z(6c7SjU|HsTEeI3=T|jFt$B;N@ zfN>!16SL(&Jy7jv6|_w&lMBEC5ChITT7C2*x@}q~f&Pu8GbCx40)E)0wd4~6DVbN+ za|}q%4WElUE&J}bO{?0`YDa8wVom2cU$7x-RkAcwqs2o*o6L z0c-)1lr+D1H=)V^5_5@yG5|pT@DqTVNJXR)Xa**L0id?6qqXn=vdz&d0=xmnfG>_# z;h_)D3H&X|jh2?pI$E8$a;>EaSg}p(Vl)~p@fa8^Gy?!JJ%*!I5pZ8xv^gZLcp5nD zXysLg3oO{C<@yO=pIPT=#E?jIg9l&QVf0O_bpbz*IPkv`t`JT;S zS&~B@^wcUN!4|VdO8R)Uk&$)tK+_h;I3@e{gn-);FqS2q-YJbW7$^qz0+)b!M=N8K z>GFKtkfYU|t-JwlTy2jIJ{@QTZoV3R*#;ywu{2m@8NX(fSszzonC-cgo0u)Ee5jjsUC0gr$Y z37(c-PfKUHGPeWA9IcA8TPj}w1`xJQYp1*e&d8fE4NObmN?_d4>LIXfn^tQ3hh*FS a8T$h-hx-LH+r7U40000 - 4 + 3 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,26 @@ + + + + ... + + + + :/icon/32x32/union.png:/icon/32x32/union.png + + + + 32 + 32 + + + + true + + + From 60224819e430e19d30022c5a48fbabc3eca066d4 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 23 Dec 2013 19:23:50 +0200 Subject: [PATCH 02/15] Dialog for tool "UnitDetails". --HG-- branch : feature --- src/dialogs/dialogs.pri | 9 +- src/dialogs/dialoguniondetails.cpp | 117 ++++++++++++++++++++++ src/dialogs/dialoguniondetails.h | 75 ++++++++++++++ src/dialogs/dialoguniondetails.ui | 81 +++++++++++++++ src/mainwindow.cpp | 5 +- src/mainwindow.ui | 7 +- src/tools/nodeDetails/vnodearc.cpp | 2 - src/tools/nodeDetails/vnodespline.cpp | 2 - src/tools/nodeDetails/vnodesplinepath.cpp | 2 - 9 files changed, 288 insertions(+), 12 deletions(-) create mode 100644 src/dialogs/dialoguniondetails.cpp create mode 100644 src/dialogs/dialoguniondetails.h create mode 100644 src/dialogs/dialoguniondetails.ui 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/dialoguniondetails.cpp b/src/dialogs/dialoguniondetails.cpp new file mode 100644 index 000000000..f1922fdea --- /dev/null +++ b/src/dialogs/dialoguniondetails.cpp @@ -0,0 +1,117 @@ +/************************************************************************ + ** + ** @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), details(VDetail()), d1(0), d2(0), d1P1(0), d1P2(0), + d2P1(0), d2P2(0), numberD(0), numberP(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, d1P1, d1P2); + } + else + { + ChoosedDetail(id, type, d2, d2P1, d2P2); + } +} + +void DialogUnionDetails::DialogAccepted() +{ + emit ToolTip(""); + 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, qint64 &p1, + qint64 &p2) +{ + 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")); + } + if (numberP == 1) + { + p2 = id; + ++numberD; + if(numberD > 1) + { + ++numberP; + emit ToolTip(""); + this->show(); + } + else + { + numberP = 0; + emit ToolTip(tr("Select detail")); + } + } + } +} diff --git a/src/dialogs/dialoguniondetails.h b/src/dialogs/dialoguniondetails.h new file mode 100644 index 000000000..55825e07c --- /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(); +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; + /** + * @brief details detail + */ + VDetail details; + qint64 d1; + qint64 d2; + qint64 d1P1; + qint64 d1P2; + qint64 d2P1; + qint64 d2P2; + qint32 numberD; + qint32 numberP; + bool CheckObject(const qint64 &id, const qint64 &idDetail) const; + void ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, qint64 &p1, + qint64 &p2); +}; + +#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/mainwindow.cpp b/src/mainwindow.cpp index 5ea03bfb3..e0296fa20 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1080,7 +1080,7 @@ void MainWindow::SetEnableTool(bool enable) } else { - modelingTools = enable; // Soon we will have some tools for modeling. + modelingTools = enable; } //Drawing Tools ui->toolButtonEndLine->setEnabled(drawTools); @@ -1100,6 +1100,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() diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 674702e62..75381f5f9 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -40,7 +40,7 @@ - 3 + 4 @@ -597,7 +597,10 @@ - + + + false + ... diff --git a/src/tools/nodeDetails/vnodearc.cpp b/src/tools/nodeDetails/vnodearc.cpp index 03c843ac3..e6edbd547 100644 --- a/src/tools/nodeDetails/vnodearc.cpp +++ b/src/tools/nodeDetails/vnodearc.cpp @@ -39,8 +39,6 @@ VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, { RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); if (typeCreation == Tool::FromGui) { diff --git a/src/tools/nodeDetails/vnodespline.cpp b/src/tools/nodeDetails/vnodespline.cpp index 1dab7b856..c95ab9684 100644 --- a/src/tools/nodeDetails/vnodespline.cpp +++ b/src/tools/nodeDetails/vnodespline.cpp @@ -39,8 +39,6 @@ VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 { RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); if (typeCreation == Tool::FromGui) { diff --git a/src/tools/nodeDetails/vnodesplinepath.cpp b/src/tools/nodeDetails/vnodesplinepath.cpp index 4781ceaa8..997e3d556 100644 --- a/src/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/tools/nodeDetails/vnodesplinepath.cpp @@ -39,8 +39,6 @@ VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, { RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); if (typeCreation == Tool::FromGui) { From 5ac6302130e6ce4e58af92da8a79d40f234d65b7 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 23 Dec 2013 21:50:30 +0200 Subject: [PATCH 03/15] Set default value for attributes in pattern's file. --HG-- branch : feature --- src/xml/vdomdocument.cpp | 312 ++++++++++++++++++++------------------- src/xml/vdomdocument.h | 7 +- 2 files changed, 161 insertions(+), 158 deletions(-) diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index 28bd2d0b6..64de855f1 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -384,11 +384,11 @@ 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)); @@ -402,7 +402,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 +410,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 +425,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,12 +438,12 @@ 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) { @@ -563,12 +565,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,14 +579,14 @@ 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; @@ -636,7 +638,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,16 +654,16 @@ 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) { 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)); VDrawTool::AddRecord(id, Tool::SinglePointTool, this); @@ -687,18 +689,18 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen 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 +713,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 +737,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 +762,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 +787,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 +812,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 +836,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,15 +860,15 @@ 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"); + qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); VPointF point = data->GetPoint(idObject ); - qreal mx = toPixel(GetParametrDouble(domElement, "mx")); - qreal my = toPixel(GetParametrDouble(domElement, "my")); + qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); + qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); data->UpdatePoint(id, VPointF(point.x(), point.y(), point.name(), mx, my, idObject )); VNodePoint::Create(this, data, id, idObject, parse, Tool::FromFile); return; @@ -878,18 +880,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 +904,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 +928,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 +950,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 +971,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 +1003,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 +1022,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,12 +1046,12 @@ 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"); + qreal kCurve = GetParametrDouble(domElement, VAbstractTool::AttrKCurve, "1.0"); VSplinePath path(data->DataPoints(), kCurve); QDomNodeList nodeList = domElement.childNodes(); @@ -1059,12 +1061,12 @@ 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"); + 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"); VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2); path.append(splPoint); if (parse == Document::FullParse) @@ -1085,12 +1087,12 @@ 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"); + qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); VSpline spl = data->GetSpline(idObject); spl.setIdObject(idObject); data->UpdateSpline(id, spl); @@ -1104,12 +1106,12 @@ 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"); + qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); VSplinePath path = data->GetSplinePath(idObject); path.setIdObject(idObject); data->UpdateSplinePath(id, path); @@ -1131,15 +1133,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,12 +1154,12 @@ 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"); + qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); VArc arc = data->GetArc(idObject); arc.setIdObject(idObject); data->UpdateArc(id, arc); diff --git a/src/xml/vdomdocument.h b/src/xml/vdomdocument.h index 897cae319..cf0415277 100644 --- a/src/xml/vdomdocument.h +++ b/src/xml/vdomdocument.h @@ -398,21 +398,22 @@ private: * @param name * @return */ - qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name) const; + 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 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; + qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; /** * @brief CollectId * @param node From 7d0611004a9427f75657a29af6db2228684f4991 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 23 Dec 2013 22:14:45 +0200 Subject: [PATCH 04/15] Static attribute name. --HG-- branch : feature --- src/dialogs/dialoghistory.cpp | 57 ++++++++++++++++++----------------- src/xml/vdomdocument.h | 44 +++++++++++++-------------- 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/dialogs/dialoghistory.cpp b/src/dialogs/dialoghistory.cpp index cef3eb755..c99b81bd9 100644 --- a/src/dialogs/dialoghistory.cpp +++ b/src/dialogs/dialoghistory.cpp @@ -31,6 +31,7 @@ #include "../geometry/varc.h" #include "../geometry/vspline.h" #include "../geometry/vsplinepath.h" +#include "../tools/vabstracttool.h" #include #include @@ -178,7 +179,7 @@ QString DialogHistory::Record(const VToolRecord &tool) 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()); @@ -187,8 +188,8 @@ QString DialogHistory::Record(const VToolRecord &tool) 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()); @@ -197,8 +198,8 @@ QString DialogHistory::Record(const VToolRecord &tool) 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(), @@ -211,8 +212,8 @@ QString DialogHistory::Record(const VToolRecord &tool) 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(), @@ -222,9 +223,9 @@ QString DialogHistory::Record(const VToolRecord &tool) 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(), @@ -235,22 +236,22 @@ QString DialogHistory::Record(const VToolRecord &tool) 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(p2Line1).name(), + data->GetPoint(p1Line2).name(), + data->GetPoint(p2Line2).name(), data->GetPoint(tool.getId()).name()); 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()); + data->GetPoint(spl.GetP4()).name()); } break; case Tool::ArcTool: @@ -278,9 +279,9 @@ QString DialogHistory::Record(const VToolRecord &tool) 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"); } 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(), @@ -293,9 +294,9 @@ 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(), @@ -309,10 +310,10 @@ 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(), diff --git a/src/xml/vdomdocument.h b/src/xml/vdomdocument.h index cf0415277..f0c38fd04 100644 --- a/src/xml/vdomdocument.h +++ b/src/xml/vdomdocument.h @@ -200,6 +200,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 @@ -392,28 +414,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 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; /** * @brief CollectId * @param node From cdf2e02eef0abe1df84ee1acf804382284312f4e Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 24 Dec 2013 11:58:23 +0200 Subject: [PATCH 05/15] History records for tools "CutSpline" and "CutSplinePath". --HG-- branch : feature --- src/dialogs/dialoghistory.cpp | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/dialogs/dialoghistory.cpp b/src/dialogs/dialoghistory.cpp index c99b81bd9..9c25c253a 100644 --- a/src/dialogs/dialoghistory.cpp +++ b/src/dialogs/dialoghistory.cpp @@ -32,6 +32,8 @@ #include "../geometry/vspline.h" #include "../geometry/vsplinepath.h" #include "../tools/vabstracttool.h" +#include "../tools/drawTools/vtoolcutspline.h" +#include "../tools/drawTools/vtoolcutsplinepath.h" #include #include @@ -320,6 +322,42 @@ QString DialogHistory::Record(const VToolRecord &tool) data->GetPoint(firstPointId).name(), data->GetPoint(secondPointId).name()); break; } + case Tool::CutSplineTool: + { + qint64 splineId = 0; + domElement = doc->elementById(QString().setNum(tool.getId())); + if (domElement.isElement()) + { + splineId = doc->GetParametrLongLong(domElement, VToolCutSpline::AttrSpline, "0"); + } + VSpline spl = data->GetSpline(splineId); + record = QString(tr("%1 - cut curve %2_%3")).arg(data->GetPoint(tool.getId()).name(), + data->GetPoint(spl.GetP1()).name(), + data->GetPoint(spl.GetP4()).name()); + } + break; + case Tool::CutSplinePathTool: + { + qint64 splinePathId = 0; + domElement = doc->elementById(QString().setNum(tool.getId())); + if (domElement.isElement()) + { + splinePathId = doc->GetParametrLongLong(domElement, VToolCutSplinePath::AttrSplinePath, "0"); + } + VSplinePath splPath = data->GetSplinePath(splinePathId); + QVector points = splPath.GetSplinePath(); + if (points.size() != 0 ) + { + record = QString(tr("%1 - cut curve point %2")).arg(data->GetPoint(tool.getId()).name(), + data->GetPoint(points[0].P()).name()); + for (qint32 i = 1; i< points.size(); ++i) + { + QString name = QString("_%1").arg(data->GetPoint(points[i].P()).name()); + record.append(name); + } + } + } + break; default: qWarning()< Date: Tue, 24 Dec 2013 13:24:29 +0200 Subject: [PATCH 06/15] Method for refreshing attributes in file. --HG-- branch : feature --- src/tools/drawTools/vtoolalongline.cpp | 20 ++++++++++ src/tools/drawTools/vtoolalongline.h | 4 ++ src/tools/drawTools/vtoolarc.cpp | 17 +++++++++ src/tools/drawTools/vtoolarc.h | 4 ++ src/tools/drawTools/vtoolbisector.cpp | 21 +++++++++++ src/tools/drawTools/vtoolbisector.h | 4 ++ src/tools/drawTools/vtoolcutspline.cpp | 18 +++++++++ src/tools/drawTools/vtoolcutspline.h | 7 ++++ src/tools/drawTools/vtoolcutsplinepath.cpp | 18 +++++++++ src/tools/drawTools/vtoolcutsplinepath.h | 7 ++++ src/tools/drawTools/vtoolendline.cpp | 20 ++++++++++ src/tools/drawTools/vtoolendline.h | 4 ++ src/tools/drawTools/vtoolheight.cpp | 20 ++++++++++ src/tools/drawTools/vtoolheight.h | 4 ++ src/tools/drawTools/vtoolline.cpp | 14 +++++++ src/tools/drawTools/vtoolline.h | 4 ++ src/tools/drawTools/vtoollineintersect.cpp | 20 ++++++++++ src/tools/drawTools/vtoollineintersect.h | 4 ++ src/tools/drawTools/vtoolnormal.cpp | 22 ++++++++++- src/tools/drawTools/vtoolnormal.h | 4 ++ src/tools/drawTools/vtoolpointofcontact.cpp | 20 ++++++++++ src/tools/drawTools/vtoolpointofcontact.h | 4 ++ .../drawTools/vtoolpointofintersection.cpp | 18 +++++++++ .../drawTools/vtoolpointofintersection.h | 4 ++ src/tools/drawTools/vtoolshoulderpoint.cpp | 21 +++++++++++ src/tools/drawTools/vtoolshoulderpoint.h | 4 ++ src/tools/drawTools/vtoolsinglepoint.cpp | 18 +++++++++ src/tools/drawTools/vtoolsinglepoint.h | 4 ++ src/tools/drawTools/vtoolspline.cpp | 20 ++++++++++ src/tools/drawTools/vtoolspline.h | 4 ++ src/tools/drawTools/vtoolsplinepath.cpp | 37 +++++++++++++++++++ src/tools/drawTools/vtoolsplinepath.h | 4 ++ src/tools/drawTools/vtooltriangle.cpp | 20 ++++++++++ src/tools/drawTools/vtooltriangle.h | 4 ++ src/tools/nodeDetails/vnodearc.cpp | 13 +++++++ src/tools/nodeDetails/vnodearc.h | 4 ++ src/tools/nodeDetails/vnodepoint.cpp | 16 ++++++++ src/tools/nodeDetails/vnodepoint.h | 4 ++ src/tools/nodeDetails/vnodespline.cpp | 13 +++++++ src/tools/nodeDetails/vnodespline.h | 4 ++ src/tools/nodeDetails/vnodesplinepath.cpp | 13 +++++++ src/tools/nodeDetails/vnodesplinepath.h | 4 ++ src/tools/vabstracttool.h | 4 ++ src/tools/vtooldetail.cpp | 18 +++++++++ src/tools/vtooldetail.h | 4 ++ 45 files changed, 514 insertions(+), 1 deletion(-) diff --git a/src/tools/drawTools/vtoolalongline.cpp b/src/tools/drawTools/vtoolalongline.cpp index c8bb272c2..7b2c29892 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() @@ -106,6 +110,22 @@ void VToolAlongLine::AddToFile() AddToCalculation(domElement); } +void VToolAlongLine::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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); 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..db2f91b10 100644 --- a/src/tools/drawTools/vtoolarc.cpp +++ b/src/tools/drawTools/vtoolarc.cpp @@ -49,6 +49,10 @@ VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::S { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolArc::setDialog() @@ -199,6 +203,19 @@ void VToolArc::AddToFile() AddToCalculation(domElement); } +void VToolArc::RefreshDataInFile() +{ + VArc arc = VAbstractTool::data.GetArc(id); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrCenter, arc.GetCenter()); + 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) 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..637ed4bdd 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, @@ -204,6 +208,23 @@ void VToolBisector::AddToFile() AddToCalculation(domElement); } +void VToolBisector::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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..0a62b55ca 100644 --- a/src/tools/drawTools/vtoolcutspline.cpp +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -58,6 +58,10 @@ VToolCutSpline::VToolCutSpline(VDomDocument *doc, VContainer *data, const qint64 { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolCutSpline::setDialog() @@ -222,6 +226,20 @@ void VToolCutSpline::AddToFile() AddToCalculation(domElement); } +void VToolCutSpline::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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); 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..d563c217f 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/tools/drawTools/vtoolcutsplinepath.cpp @@ -60,6 +60,10 @@ VToolCutSplinePath::VToolCutSplinePath(VDomDocument *doc, VContainer *data, cons { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolCutSplinePath::setDialog() @@ -289,6 +293,20 @@ void VToolCutSplinePath::AddToFile() AddToCalculation(domElement); } +void VToolCutSplinePath::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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); 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..bfd8e8085 100644 --- a/src/tools/drawTools/vtoolendline.cpp +++ b/src/tools/drawTools/vtoolendline.cpp @@ -43,6 +43,10 @@ VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolEndLine::setDialog() @@ -166,3 +170,19 @@ void VToolEndLine::AddToFile() AddToCalculation(domElement); } + +void VToolEndLine::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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..1d48a7dbf 100644 --- a/src/tools/drawTools/vtoolheight.cpp +++ b/src/tools/drawTools/vtoolheight.cpp @@ -41,6 +41,10 @@ VToolHeight::VToolHeight(VDomDocument *doc, VContainer *data, const qint64 &id, { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolHeight::setDialog() @@ -187,3 +191,19 @@ void VToolHeight::AddToFile() AddToCalculation(domElement); } + +void VToolHeight::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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..8b61e012b 100644 --- a/src/tools/drawTools/vtoolline.cpp +++ b/src/tools/drawTools/vtoolline.cpp @@ -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); 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..6db550e12 100644 --- a/src/tools/drawTools/vtoollineintersect.cpp +++ b/src/tools/drawTools/vtoollineintersect.cpp @@ -42,6 +42,10 @@ VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, cons { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolLineIntersect::setDialog() @@ -184,6 +188,22 @@ void VToolLineIntersect::AddToFile() AddToCalculation(domElement); } +void VToolLineIntersect::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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/vtoolnormal.cpp b/src/tools/drawTools/vtoolnormal.cpp index 0acb05cdf..d00089f6f 100644 --- a/src/tools/drawTools/vtoolnormal.cpp +++ b/src/tools/drawTools/vtoolnormal.cpp @@ -42,7 +42,10 @@ VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, { AddToFile(); } - + else + { + RefreshDataInFile(); + } } void VToolNormal::setDialog() @@ -190,6 +193,23 @@ void VToolNormal::AddToFile() AddToCalculation(domElement); } +void VToolNormal::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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/vtoolpointofcontact.cpp b/src/tools/drawTools/vtoolpointofcontact.cpp index 9d94bc7e9..f1365103d 100644 --- a/src/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/tools/drawTools/vtoolpointofcontact.cpp @@ -42,6 +42,10 @@ VToolPointOfContact::VToolPointOfContact(VDomDocument *doc, VContainer *data, co { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolPointOfContact::setDialog() @@ -207,6 +211,22 @@ void VToolPointOfContact::AddToFile() AddToCalculation(domElement); } +void VToolPointOfContact::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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..8bec57a1d 100644 --- a/src/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/tools/drawTools/vtoolpointofintersection.cpp @@ -41,6 +41,10 @@ VToolPointOfIntersection::VToolPointOfIntersection(VDomDocument *doc, VContainer { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolPointOfIntersection::setDialog() @@ -152,3 +156,17 @@ void VToolPointOfIntersection::AddToFile() AddToCalculation(domElement); } + +void VToolPointOfIntersection::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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..adda7877f 100644 --- a/src/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/tools/drawTools/vtoolshoulderpoint.cpp @@ -42,6 +42,10 @@ VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, cons { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolShoulderPoint::setDialog() @@ -211,6 +215,23 @@ void VToolShoulderPoint::AddToFile() AddToCalculation(domElement); } +void VToolShoulderPoint::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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..cd70c474b 100644 --- a/src/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/tools/drawTools/vtoolsinglepoint.cpp @@ -41,6 +41,10 @@ VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolSinglePoint::setDialog() @@ -66,6 +70,20 @@ void VToolSinglePoint::AddToFile() AddToCalculation(domElement); } +void VToolSinglePoint::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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()) 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..f7534aeec 100644 --- a/src/tools/drawTools/vtoolspline.cpp +++ b/src/tools/drawTools/vtoolspline.cpp @@ -68,6 +68,10 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, const T { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolSpline::setDialog() @@ -222,6 +226,22 @@ void VToolSpline::AddToFile() AddToCalculation(domElement); } +void VToolSpline::RefreshDataInFile() +{ + VSpline spl = VAbstractTool::data.GetSpline(id); + 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())); + } +} + void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) 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..25f9ee03e 100644 --- a/src/tools/drawTools/vtoolsplinepath.cpp +++ b/src/tools/drawTools/vtoolsplinepath.cpp @@ -69,6 +69,10 @@ VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolSplinePath::setDialog() @@ -271,6 +275,39 @@ void VToolSplinePath::AddToFile() AddToCalculation(domElement); } +void VToolSplinePath::RefreshDataInFile() +{ + VSplinePath splPath = VAbstractTool::data.GetSplinePath(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 (VAbstractTool::data.DataPoints(), 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); diff --git a/src/tools/drawTools/vtoolsplinepath.h b/src/tools/drawTools/vtoolsplinepath.h index 5f20851c4..2febbba44 100644 --- a/src/tools/drawTools/vtoolsplinepath.h +++ b/src/tools/drawTools/vtoolsplinepath.h @@ -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..fcd425df6 100644 --- a/src/tools/drawTools/vtooltriangle.cpp +++ b/src/tools/drawTools/vtooltriangle.cpp @@ -41,6 +41,10 @@ VToolTriangle::VToolTriangle(VDomDocument *doc, VContainer *data, const qint64 & { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VToolTriangle::setDialog() @@ -212,3 +216,19 @@ void VToolTriangle::AddToFile() AddToCalculation(domElement); } + +void VToolTriangle::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(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, QString().setNum(axisP1Id)); + domElement.setAttribute(AttrAxisP2, QString().setNum(axisP2Id)); + domElement.setAttribute(AttrFirstPoint, QString().setNum(firstPointId)); + domElement.setAttribute(AttrSecondPoint, QString().setNum(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/vnodearc.cpp b/src/tools/nodeDetails/vnodearc.cpp index e6edbd547..0d58f0b07 100644 --- a/src/tools/nodeDetails/vnodearc.cpp +++ b/src/tools/nodeDetails/vnodearc.cpp @@ -44,6 +44,10 @@ VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse, @@ -78,6 +82,15 @@ void VNodeArc::AddToFile() AddToModeling(domElement); } +void VNodeArc::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); + } +} + void VNodeArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) diff --git a/src/tools/nodeDetails/vnodearc.h b/src/tools/nodeDetails/vnodearc.h index 571687551..5693fd307 100644 --- a/src/tools/nodeDetails/vnodearc.h +++ b/src/tools/nodeDetails/vnodearc.h @@ -79,6 +79,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..8ab9c79de 100644 --- a/src/tools/nodeDetails/vnodepoint.cpp +++ b/src/tools/nodeDetails/vnodepoint.cpp @@ -51,6 +51,10 @@ VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 id { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, @@ -88,6 +92,18 @@ void VNodePoint::AddToFile() AddToModeling(domElement); } +void VNodePoint::RefreshDataInFile() +{ + VPointF point = VAbstractTool::data.GetPoint(id); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); + domElement.setAttribute(AttrMx, QString().setNum(toMM(point.mx()))); + domElement.setAttribute(AttrMy, QString().setNum(toMM(point.my()))); + } +} + void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) diff --git a/src/tools/nodeDetails/vnodepoint.h b/src/tools/nodeDetails/vnodepoint.h index e724430a0..f2616fbac 100644 --- a/src/tools/nodeDetails/vnodepoint.h +++ b/src/tools/nodeDetails/vnodepoint.h @@ -96,6 +96,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 c95ab9684..9934f2ca5 100644 --- a/src/tools/nodeDetails/vnodespline.cpp +++ b/src/tools/nodeDetails/vnodespline.cpp @@ -44,6 +44,10 @@ VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 { AddToFile(); } + else + { + RefreshDataInFile(); + } } VNodeSpline *VNodeSpline::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, @@ -79,6 +83,15 @@ void VNodeSpline::AddToFile() AddToModeling(domElement); } +void VNodeSpline::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); + } +} + void VNodeSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) diff --git a/src/tools/nodeDetails/vnodespline.h b/src/tools/nodeDetails/vnodespline.h index 0e4b64837..e3ac4b963 100644 --- a/src/tools/nodeDetails/vnodespline.h +++ b/src/tools/nodeDetails/vnodespline.h @@ -80,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/vnodesplinepath.cpp b/src/tools/nodeDetails/vnodesplinepath.cpp index 997e3d556..6be0872fa 100644 --- a/src/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/tools/nodeDetails/vnodesplinepath.cpp @@ -44,6 +44,10 @@ VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, { AddToFile(); } + else + { + RefreshDataInFile(); + } } void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, @@ -83,6 +87,15 @@ void VNodeSplinePath::AddToFile() AddToModeling(domElement); } +void VNodeSplinePath::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); + } +} + void VNodeSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) diff --git a/src/tools/nodeDetails/vnodesplinepath.h b/src/tools/nodeDetails/vnodesplinepath.h index b82e365e8..840f7dc5f 100644 --- a/src/tools/nodeDetails/vnodesplinepath.h +++ b/src/tools/nodeDetails/vnodesplinepath.h @@ -79,6 +79,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/vabstracttool.h b/src/tools/vabstracttool.h index 038b3e2d4..e7950b4f0 100644 --- a/src/tools/vabstracttool.h +++ b/src/tools/vabstracttool.h @@ -285,6 +285,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/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 5b30f986c..28c29e845 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -215,6 +215,24 @@ void VToolDetail::AddToFile() } } +void VToolDetail::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + VDetail det = VAbstractTool::data.GetDetail(id); + domElement.setAttribute(AttrName, det.getName()); + domElement.setAttribute(AttrSupplement, QString().setNum(det.getSupplement())); + domElement.setAttribute(AttrClosed, QString().setNum(det.getClosed())); + domElement.setAttribute(AttrWidth, QString().setNum(det.getWidth())); + RemoveAllChild(domElement); + for (ptrdiff_t i = 0; i < det.CountNode(); ++i) + { + AddNode(domElement, det[i]); + } + } +} + QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionHasChanged && scene()) diff --git a/src/tools/vtooldetail.h b/src/tools/vtooldetail.h index 571d13c05..65cfcaf37 100644 --- a/src/tools/vtooldetail.h +++ b/src/tools/vtooldetail.h @@ -156,6 +156,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 From 41f5f207d866b6f22431176f8dab6daceafe2193 Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 29 Dec 2013 18:48:57 +0200 Subject: [PATCH 07/15] Commit after success build. Still not stable. --HG-- branch : feature --- Valentina.pro | 2 +- src/container/container.pri | 2 - src/container/vcontainer.cpp | 367 ++++----- src/container/vcontainer.h | 164 ++-- src/dialogs/dialogalongline.cpp | 6 +- src/dialogs/dialogarc.cpp | 4 +- src/dialogs/dialogbisector.cpp | 8 +- src/dialogs/dialogcutspline.cpp | 4 +- src/dialogs/dialogcutsplinepath.cpp | 4 +- src/dialogs/dialogdetail.cpp | 16 +- src/dialogs/dialogendline.cpp | 4 +- src/dialogs/dialogheight.cpp | 8 +- src/dialogs/dialoghistory.cpp | 138 ++-- src/dialogs/dialogincrements.cpp | 41 +- src/dialogs/dialogline.cpp | 14 +- src/dialogs/dialoglineintersect.cpp | 22 +- src/dialogs/dialognormal.cpp | 6 +- src/dialogs/dialogpointofcontact.cpp | 8 +- src/dialogs/dialogpointofintersection.cpp | 6 +- src/dialogs/dialogs.h | 1 + src/dialogs/dialogshoulderpoint.cpp | 8 +- src/dialogs/dialogspline.cpp | 20 +- src/dialogs/dialogspline.h | 4 +- src/dialogs/dialogsplinepath.cpp | 21 +- src/dialogs/dialogtool.cpp | 61 +- src/dialogs/dialogtriangle.cpp | 10 +- src/dialogs/dialoguniondetails.cpp | 11 +- src/dialogs/dialoguniondetails.h | 10 +- src/geometry/geometry.pri | 8 +- src/geometry/varc.cpp | 67 +- src/geometry/varc.h | 65 +- src/geometry/vdetail.cpp | 36 +- src/geometry/vdetail.h | 6 + src/geometry/vgobject.cpp | 99 +++ src/geometry/vgobject.h | 89 +++ src/{container => geometry}/vpointf.cpp | 9 +- src/{container => geometry}/vpointf.h | 44 +- src/geometry/vspline.cpp | 330 ++------ src/geometry/vspline.h | 150 +--- src/geometry/vsplinepath.cpp | 52 +- src/geometry/vsplinepath.h | 52 +- src/geometry/vsplinepoint.cpp | 4 +- src/geometry/vsplinepoint.h | 9 +- src/mainwindow.cpp | 54 +- src/mainwindow.h | 23 +- src/options.h | 5 +- src/tools/drawTools/vtoolalongline.cpp | 30 +- src/tools/drawTools/vtoolarc.cpp | 54 +- src/tools/drawTools/vtoolbisector.cpp | 34 +- src/tools/drawTools/vtoolcutspline.cpp | 72 +- src/tools/drawTools/vtoolcutsplinepath.cpp | 130 ++-- src/tools/drawTools/vtoolendline.cpp | 28 +- src/tools/drawTools/vtoolheight.cpp | 32 +- src/tools/drawTools/vtoolline.cpp | 14 +- src/tools/drawTools/vtoollineintersect.cpp | 40 +- src/tools/drawTools/vtoollinepoint.cpp | 10 +- src/tools/drawTools/vtoolnormal.cpp | 30 +- src/tools/drawTools/vtoolpoint.cpp | 19 +- src/tools/drawTools/vtoolpointofcontact.cpp | 38 +- .../drawTools/vtoolpointofintersection.cpp | 32 +- src/tools/drawTools/vtoolshoulderpoint.cpp | 34 +- src/tools/drawTools/vtoolsinglepoint.cpp | 32 +- src/tools/drawTools/vtoolspline.cpp | 124 +-- src/tools/drawTools/vtoolsplinepath.cpp | 80 +- src/tools/drawTools/vtoolsplinepath.h | 2 +- src/tools/drawTools/vtooltriangle.cpp | 46 +- src/tools/nodeDetails/vnodearc.cpp | 4 +- src/tools/nodeDetails/vnodepoint.cpp | 28 +- src/tools/nodeDetails/vnodespline.cpp | 4 +- src/tools/nodeDetails/vnodesplinepath.cpp | 10 +- src/tools/tools.pri | 6 +- src/tools/vtooldetail.cpp | 132 ++-- src/tools/vtooldetail.h | 9 +- src/tools/vtooluniondetails.cpp | 721 ++++++++++++++++++ src/tools/vtooluniondetails.h | 125 +++ src/xml/vdomdocument.cpp | 125 ++- src/xml/vdomdocument.h | 3 + 77 files changed, 2390 insertions(+), 1730 deletions(-) create mode 100644 src/geometry/vgobject.cpp create mode 100644 src/geometry/vgobject.h rename src/{container => geometry}/vpointf.cpp (85%) rename src/{container => geometry}/vpointf.h (72%) create mode 100644 src/tools/vtooluniondetails.cpp create mode 100644 src/tools/vtooluniondetails.h diff --git a/Valentina.pro b/Valentina.pro index 496310cf8..508c984d5 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -133,4 +133,4 @@ INSTALLS += target \ desktop \ pixmaps \ translations -} +} 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..6cc374f3d 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -30,15 +30,15 @@ #include "../exception/vexceptionbadid.h" #include +#include qint64 VContainer::_id = 0; VContainer::VContainer() - :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()) { SetSize(500); SetGrowth(1760); @@ -52,11 +52,10 @@ 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); } @@ -64,26 +63,23 @@ VContainer::VContainer(const VContainer &data) void VContainer::setData(const VContainer &data) { base = *data.DataBase(); - points = *data.DataPoints(); + gObjects = *data.DataGObjects(); 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,13 +91,26 @@ 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 +{ + if (obj.contains(id)) + { + return obj.value(id); + } + else + { + throw VExceptionBadId(tr("Can't find object"), id); + } +} + +const VStandartTableRow *VContainer::GetStandartTableCell(const QString &name) const { Q_ASSERT(name.isEmpty()==false); return GetObject(standartTable, name); } -VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const +const VIncrementTableRow *VContainer::GetIncrementTableRow(const QString& name) const { Q_ASSERT(name.isEmpty()==false); return GetObject(incrementTable, name); @@ -110,53 +119,38 @@ VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const 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 -{ - return GetObject(splines, id); -} - -VArc VContainer::GetArc(qint64 id) const -{ - return GetObject(arcs, id); -} - -VSplinePath VContainer::GetSplinePath(qint64 id) const -{ - return GetObject(splinePaths, id); -} - -VDetail VContainer::GetDetail(qint64 id) const +const VDetail *VContainer::GetDetail(qint64 id) const { return GetObject(details, id); } -qint64 VContainer::AddPoint(const VPointF &point) +qint64 VContainer::AddGObject(VGObject *obj) { - return AddObject(points, point); + return AddObject(gObjects, obj); } -qint64 VContainer::AddDetail(const VDetail &detail) +qint64 VContainer::AddDetail(VDetail *detail) { return AddObject(details, detail); } @@ -177,101 +171,100 @@ void VContainer::UpdateId(qint64 newId) QPainterPath VContainer::ContourPath(qint64 idDetail) const { - VDetail detail = GetDetail(idDetail); + const VDetail *detail = GetDetail(idDetail); QVector points; QVector pointsEkv; - for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) + 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()); - if (detail.getSupplement() == true) + 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(); - if (detail.getSupplement() == true) + 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()); - if (detail.getSupplement() == true) + 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(); - if (detail.getSupplement() == true) + 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()); - if (detail.getSupplement() == true) + 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(); - if (detail.getSupplement() == true) + 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()); - if (detail.getSupplement() == true) + 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."<at(i).getTypeTool(); break; } } @@ -284,16 +277,16 @@ QPainterPath VContainer::ContourPath(qint64 idDetail) const } path.lineTo(points[0]); - if (detail.getSupplement() == true) + if (detail->getSupplement() == true) { QPainterPath ekv; - if (detail.getClosed() == true) + if (detail->getClosed() == true) { - ekv = Equidistant(pointsEkv, Detail::CloseEquidistant, toPixel(detail.getWidth())); + ekv = Equidistant(pointsEkv, Detail::CloseEquidistant, toPixel(detail->getWidth())); } else { - ekv = Equidistant(pointsEkv, Detail::OpenEquidistant, toPixel(detail.getWidth())); + ekv = Equidistant(pointsEkv, Detail::OpenEquidistant, toPixel(detail->getWidth())); } path.addPath(ekv); path.setFillRule(Qt::WindingFill); @@ -363,7 +356,7 @@ QPainterPath VContainer::Equidistant(QVector 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 +501,21 @@ 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); + delete GetObject(gObjects, id); obj[id] = point; UpdateId(id); } @@ -532,7 +528,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) @@ -549,19 +546,19 @@ void VContainer::AddLineAngle(const QString &name, const qreal &value) qreal VContainer::GetValueStandartTableCell(const QString& name) const { - VStandartTableRow cell = GetStandartTableCell(name); + const VStandartTableRow *cell = GetStandartTableCell(name); qreal k_size = ( static_cast (size()/10.0) - 50.0 ) / 2.0; qreal k_growth = ( static_cast (growth()/10.0) - 176.0 ) / 6.0; - qreal value = cell.GetBase() + k_size*cell.GetKsize() + k_growth*cell.GetKgrowth(); + qreal value = cell->GetBase() + k_size*cell->GetKsize() + k_growth*cell->GetKgrowth(); return value; } qreal VContainer::GetValueIncrementTableRow(const QString& name) const { - VIncrementTableRow cell = GetIncrementTableRow(name); + const VIncrementTableRow *cell = GetIncrementTableRow(name); qreal k_size = ( static_cast (size()/10.0) - 50.0 ) / 2.0; qreal k_growth = ( static_cast (growth()/10.0) - 176.0 ) / 6.0; - qreal value = cell.getBase() + k_size*cell.getKsize() + k_growth*cell.getKgrowth(); + qreal value = cell->getBase() + k_size*cell->getKsize() + k_growth*cell->getKgrowth(); return value; } @@ -580,10 +577,8 @@ void VContainer::Clear() void VContainer::ClearObject() { - points.clear(); - splines.clear(); - arcs.clear(); - splinePaths.clear(); + qDeleteAll(gObjects); + gObjects.clear(); } qreal VContainer::FindVar(const QString &name, bool *ok)const @@ -631,77 +626,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); -} - void VContainer::AddLengthLine(const QString &name, const qreal &value) { Q_ASSERT(name.isEmpty() == false); @@ -710,60 +677,60 @@ 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)); - AddStandartTableCell("Vpt", VStandartTableRow(1438, 3, 52)); - AddStandartTableCell("Vst", VStandartTableRow(1257, -1, 49)); - AddStandartTableCell("Vlt", VStandartTableRow(1102, 0, 43)); - AddStandartTableCell("Vk", VStandartTableRow(503, 0, 22)); - AddStandartTableCell("Vsht", VStandartTableRow(1522, 2, 54)); - AddStandartTableCell("Vzy", VStandartTableRow(1328, 0, 49)); - AddStandartTableCell("Vlop", VStandartTableRow(1320, 0, 49)); - AddStandartTableCell("Vps", VStandartTableRow(811, -1, 36)); - AddStandartTableCell("Ssh", VStandartTableRow(202, 4, 1)); - 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)); - AddStandartTableCell("Oi", VStandartTableRow(380, 8, 6)); - AddStandartTableCell("Osch", VStandartTableRow(234, 4, 4)); - AddStandartTableCell("Dsb", VStandartTableRow(1120, 0, 44)); - AddStandartTableCell("Dsp", VStandartTableRow(1110, 0, 43)); - AddStandartTableCell("Dn", VStandartTableRow(826, -3, 37)); - AddStandartTableCell("Dps", VStandartTableRow(316, 4, 7)); - AddStandartTableCell("Dpob", VStandartTableRow(783, 14, 15)); - AddStandartTableCell("Ds", VStandartTableRow(260, 1, 6)); - AddStandartTableCell("Op", VStandartTableRow(316, 12, 0)); - AddStandartTableCell("Ozap", VStandartTableRow(180, 4, 0)); - AddStandartTableCell("Pkis", VStandartTableRow(250, 4, 0)); - AddStandartTableCell("SHp", VStandartTableRow(160, 1, 4)); - AddStandartTableCell("Dlych", VStandartTableRow(500, 2, 15)); - AddStandartTableCell("Dzap", VStandartTableRow(768, 2, 24)); - AddStandartTableCell("DIIIp", VStandartTableRow(970, 2, 29)); - AddStandartTableCell("Vprp", VStandartTableRow(214, 3, 3)); - AddStandartTableCell("Vg", VStandartTableRow(262, 8, 3)); - AddStandartTableCell("Dtp", VStandartTableRow(460, 7, 9)); - AddStandartTableCell("Dp", VStandartTableRow(355, 5, 5)); - AddStandartTableCell("Vprz", VStandartTableRow(208, 3, 5)); - AddStandartTableCell("Dts", VStandartTableRow(438, 2, 10)); - AddStandartTableCell("DtsI", VStandartTableRow(469, 2, 10)); - AddStandartTableCell("Dvcht", VStandartTableRow(929, 9, 19)); - AddStandartTableCell("SHg", VStandartTableRow(370, 14, 4)); - AddStandartTableCell("Cg", VStandartTableRow(224, 6, 0)); - AddStandartTableCell("SHs", VStandartTableRow(416, 10, 2)); - AddStandartTableCell("dpzr", VStandartTableRow(121, 6, 0)); - AddStandartTableCell("Ogol", VStandartTableRow(576, 4, 4)); - AddStandartTableCell("Ssh1", VStandartTableRow(205, 5, 0)); - AddStandartTableCell("St", VStandartTableRow(410, 20, 0)); - AddStandartTableCell("Drzap", VStandartTableRow(594, 3, 19)); - AddStandartTableCell("DbII", VStandartTableRow(1020, 0, 44)); - AddStandartTableCell("Sb", VStandartTableRow(504, 15, 4)); + AddStandartTableCell("Pkor", new VStandartTableRow(84, 0, 3)); + AddStandartTableCell("Pkor", new VStandartTableRow(84, 0, 3)); + AddStandartTableCell("Vtos", new VStandartTableRow(1450, 2, 51)); + AddStandartTableCell("Vtosh", new VStandartTableRow(1506, 2, 54)); + AddStandartTableCell("Vpt", new VStandartTableRow(1438, 3, 52)); + AddStandartTableCell("Vst", new VStandartTableRow(1257, -1, 49)); + AddStandartTableCell("Vlt", new VStandartTableRow(1102, 0, 43)); + AddStandartTableCell("Vk", new VStandartTableRow(503, 0, 22)); + AddStandartTableCell("Vsht", new VStandartTableRow(1522, 2, 54)); + AddStandartTableCell("Vzy", new VStandartTableRow(1328, 0, 49)); + AddStandartTableCell("Vlop", new VStandartTableRow(1320, 0, 49)); + AddStandartTableCell("Vps", new VStandartTableRow(811, -1, 36)); + AddStandartTableCell("Ssh", new VStandartTableRow(202, 4, 1)); + AddStandartTableCell("SgI", new VStandartTableRow(517, 18, 2)); + AddStandartTableCell("SgII", new VStandartTableRow(522, 19, 1)); + AddStandartTableCell("SgIII", new VStandartTableRow(500, 20, 0)); + AddStandartTableCell("St", new VStandartTableRow(390, 20, 0)); + AddStandartTableCell("Sb", new VStandartTableRow(492, 15, 5)); + AddStandartTableCell("SbI", new VStandartTableRow(482, 12, 6)); + AddStandartTableCell("Obed", new VStandartTableRow(566, 18, 6)); + AddStandartTableCell("Ok", new VStandartTableRow(386, 8, 8)); + AddStandartTableCell("Oi", new VStandartTableRow(380, 8, 6)); + AddStandartTableCell("Osch", new VStandartTableRow(234, 4, 4)); + AddStandartTableCell("Dsb", new VStandartTableRow(1120, 0, 44)); + AddStandartTableCell("Dsp", new VStandartTableRow(1110, 0, 43)); + AddStandartTableCell("Dn", new VStandartTableRow(826, -3, 37)); + AddStandartTableCell("Dps", new VStandartTableRow(316, 4, 7)); + AddStandartTableCell("Dpob", new VStandartTableRow(783, 14, 15)); + AddStandartTableCell("Ds", new VStandartTableRow(260, 1, 6)); + AddStandartTableCell("Op", new VStandartTableRow(316, 12, 0)); + AddStandartTableCell("Ozap", new VStandartTableRow(180, 4, 0)); + AddStandartTableCell("Pkis", new VStandartTableRow(250, 4, 0)); + AddStandartTableCell("SHp", new VStandartTableRow(160, 1, 4)); + AddStandartTableCell("Dlych", new VStandartTableRow(500, 2, 15)); + AddStandartTableCell("Dzap", new VStandartTableRow(768, 2, 24)); + AddStandartTableCell("DIIIp", new VStandartTableRow(970, 2, 29)); + AddStandartTableCell("Vprp", new VStandartTableRow(214, 3, 3)); + AddStandartTableCell("Vg", new VStandartTableRow(262, 8, 3)); + AddStandartTableCell("Dtp", new VStandartTableRow(460, 7, 9)); + AddStandartTableCell("Dp", new VStandartTableRow(355, 5, 5)); + AddStandartTableCell("Vprz", new VStandartTableRow(208, 3, 5)); + AddStandartTableCell("Dts", new VStandartTableRow(438, 2, 10)); + AddStandartTableCell("DtsI", new VStandartTableRow(469, 2, 10)); + AddStandartTableCell("Dvcht", new VStandartTableRow(929, 9, 19)); + AddStandartTableCell("SHg", new VStandartTableRow(370, 14, 4)); + AddStandartTableCell("Cg", new VStandartTableRow(224, 6, 0)); + AddStandartTableCell("SHs", new VStandartTableRow(416, 10, 2)); + AddStandartTableCell("dpzr", new VStandartTableRow(121, 6, 0)); + AddStandartTableCell("Ogol", new VStandartTableRow(576, 4, 4)); + AddStandartTableCell("Ssh1", new VStandartTableRow(205, 5, 0)); + AddStandartTableCell("St", new VStandartTableRow(410, 20, 0)); + AddStandartTableCell("Drzap", new VStandartTableRow(594, 3, 19)); + AddStandartTableCell("DbII", new VStandartTableRow(1020, 0, 44)); + AddStandartTableCell("Sb", new VStandartTableRow(504, 15, 4)); } QVector VContainer::GetReversePoint(const QVector &points) const diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index 8465a19ae..c776860c8 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -35,6 +35,7 @@ #include "../geometry/vsplinepath.h" #include "../geometry/vdetail.h" #include "../widgets/vitem.h" +#include "../geometry/vgobject.h" /** * @brief The VContainer class container of all variables. @@ -63,24 +64,32 @@ public: * @param data container */ void setData(const VContainer &data); + template + const T GeometricObject(qint64 id) const + { + const T obj = dynamic_cast(GetObject(gObjects, id)); + 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 +114,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,26 +130,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, 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) + inline void AddIncrementTableRow(const QString& name, VIncrementTableRow *row) {incrementTable[name] = row;} /** * @brief AddLengthLine add length of line to container @@ -196,30 +187,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 +206,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 @@ -368,20 +311,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 @@ -391,12 +324,12 @@ public: * @brief data container with dataStandartTable return container of standart table * @return pointer on container of standart table */ - inline const QHash *DataStandartTable() const {return &standartTable;} + inline const QHash *DataStandartTable() const {return &standartTable;} /** * @brief data container with dataIncrementTable return container of increment table * @return pointer on container of increment table */ - inline const QHash *DataIncrementTable() const {return &incrementTable;} + inline const QHash *DataIncrementTable() const {return &incrementTable;} /** * @brief data container with dataLengthLines return container of lines lengths * @return pointer on container of lines lengths @@ -417,16 +350,11 @@ 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 */ - inline const QHash *DataDetails() const {return &details;} + inline const QHash *DataDetails() const {return &details;} /** * @brief UpdateId update id. If new id bigger when current save new like current. * @param newId id @@ -498,17 +426,17 @@ 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 */ - QHash standartTable; + QHash standartTable; /** * @brief incrementTable */ - QHash incrementTable; + QHash incrementTable; /** * @brief lengthLines container of lines lengths */ @@ -517,30 +445,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; + QHash details; /** * @brief CreateManTableIGroup generate man standart table of measurements */ @@ -565,7 +481,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 +497,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 +505,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/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/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/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 9c25c253a..1e114b1bb 100644 --- a/src/dialogs/dialoghistory.cpp +++ b/src/dialogs/dialoghistory.cpp @@ -175,53 +175,72 @@ 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 = 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 = 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 = 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 = 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()) { @@ -229,12 +248,16 @@ QString DialogHistory::Record(const VToolRecord &tool) 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()) { @@ -243,41 +266,50 @@ QString DialogHistory::Record(const VToolRecord &tool) 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()) { @@ -285,10 +317,14 @@ QString DialogHistory::Record(const VToolRecord &tool) 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; @@ -300,9 +336,11 @@ QString DialogHistory::Record(const VToolRecord &tool) 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: @@ -317,9 +355,12 @@ QString DialogHistory::Record(const VToolRecord &tool) 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: @@ -330,10 +371,11 @@ QString DialogHistory::Record(const VToolRecord &tool) { splineId = doc->GetParametrLongLong(domElement, VToolCutSpline::AttrSpline, "0"); } - VSpline spl = data->GetSpline(splineId); - record = QString(tr("%1 - cut curve %2_%3")).arg(data->GetPoint(tool.getId()).name(), - data->GetPoint(spl.GetP1()).name(), - data->GetPoint(spl.GetP4()).name()); + 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: @@ -344,15 +386,17 @@ QString DialogHistory::Record(const VToolRecord &tool) { splinePathId = doc->GetParametrLongLong(domElement, VToolCutSplinePath::AttrSplinePath, "0"); } - VSplinePath splPath = data->GetSplinePath(splinePathId); - QVector points = splPath.GetSplinePath(); + const VSplinePath *splPath = data->GeometricObject(splinePathId); + QVector points = splPath->GetSplinePath(); if (points.size() != 0 ) { - record = QString(tr("%1 - cut curve point %2")).arg(data->GetPoint(tool.getId()).name(), - data->GetPoint(points[0].P()).name()); + 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) { - 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); } } diff --git a/src/dialogs/dialogincrements.cpp b/src/dialogs/dialogincrements.cpp index dc357c9e1..25e5e26b7 100644 --- a/src/dialogs/dialogincrements.cpp +++ b/src/dialogs/dialogincrements.cpp @@ -69,14 +69,14 @@ DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget void DialogIncrements::FillStandartTable() { - const QHash *standartTable = data->DataStandartTable(); + const QHash *standartTable = data->DataStandartTable(); qint32 currentRow = -1; - QHashIterator i(*standartTable); + QHashIterator i(*standartTable); ui->tableWidgetStandart->setRowCount ( standartTable->size() ); while (i.hasNext()) { i.next(); - VStandartTableRow cell = i.value(); + VStandartTableRow *cell = i.value(); currentRow++; QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); @@ -88,19 +88,19 @@ void DialogIncrements::FillStandartTable() item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetStandart->setItem(currentRow, 1, item); - item = new QTableWidgetItem(QString().setNum(cell.GetBase())); + item = new QTableWidgetItem(QString().setNum(cell->GetBase())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetStandart->setItem(currentRow, 2, item); - item = new QTableWidgetItem(QString().setNum(cell.GetKsize())); + item = new QTableWidgetItem(QString().setNum(cell->GetKsize())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetStandart->setItem(currentRow, 3, item); - item = new QTableWidgetItem(QString().setNum(cell.GetKgrowth())); + item = new QTableWidgetItem(QString().setNum(cell->GetKgrowth())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetStandart->setItem(currentRow, 4, item); - item = new QTableWidgetItem(cell.GetDescription()); + item = new QTableWidgetItem(cell->GetDescription()); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetStandart->setItem(currentRow, 5, item); } @@ -111,15 +111,15 @@ void DialogIncrements::FillStandartTable() void DialogIncrements::FillIncrementTable() { - const QHash *incrementTable = data->DataIncrementTable(); - QHashIterator i(*incrementTable); + const QHash *incrementTable = data->DataIncrementTable(); + QHashIterator i(*incrementTable); QMap map; //Sorting QHash by id while (i.hasNext()) { i.next(); - VIncrementTableRow cell = i.value(); - map.insert(cell.getId(), i.key()); + VIncrementTableRow *cell = i.value(); + map.insert(cell->getId(), i.key()); } qint32 currentRow = -1; @@ -127,14 +127,14 @@ void DialogIncrements::FillIncrementTable() while (iMap.hasNext()) { iMap.next(); - VIncrementTableRow cell = incrementTable->value(iMap.value()); + VIncrementTableRow *cell = incrementTable->value(iMap.value()); currentRow++; ui->tableWidgetIncrement->setRowCount ( incrementTable->size() ); QTableWidgetItem *item = new QTableWidgetItem(iMap.value()); item->setTextAlignment(Qt::AlignHCenter); item->setFont(QFont("Times", 12, QFont::Bold)); - item->setData(Qt::UserRole, cell.getId()); + item->setData(Qt::UserRole, cell->getId()); ui->tableWidgetIncrement->setItem(currentRow, 0, item); item = new QTableWidgetItem(QString().setNum(data->GetValueIncrementTableRow(iMap.value()))); @@ -145,19 +145,19 @@ void DialogIncrements::FillIncrementTable() item->setFlags(flags); ui->tableWidgetIncrement->setItem(currentRow, 1, item); - item = new QTableWidgetItem(QString().setNum(cell.getBase())); + item = new QTableWidgetItem(QString().setNum(cell->getBase())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 2, item); - item = new QTableWidgetItem(QString().setNum(cell.getKsize())); + item = new QTableWidgetItem(QString().setNum(cell->getKsize())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 3, item); - item = new QTableWidgetItem(QString().setNum(cell.getKgrowth())); + item = new QTableWidgetItem(QString().setNum(cell->getKgrowth())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 4, item); - item = new QTableWidgetItem(cell.getDescription()); + item = new QTableWidgetItem(cell->getDescription()); item->setTextAlignment(Qt::AlignLeft); ui->tableWidgetIncrement->setItem(currentRow, 5, item); } @@ -325,7 +325,7 @@ void DialogIncrements::clickedToolButtonAdd() qreal ksize = 0; qreal kgrowth = 0; QString description = QString(tr("Description")); - VIncrementTableRow incrementRow = VIncrementTableRow(id, base, ksize, kgrowth, description); + VIncrementTableRow *incrementRow = new VIncrementTableRow(id, base, ksize, kgrowth, description); data->AddIncrementTableRow(name, incrementRow); AddIncrementToFile(id, name, base, ksize, kgrowth, description); @@ -499,8 +499,9 @@ void DialogIncrements::cellChanged ( qint32 row, qint32 column ) if (domElement.isElement()) { domElement.setAttribute("description", item->text()); - VIncrementTableRow incr = data->GetIncrementTableRow(itemName->text()); - incr.setDescription(item->text()); + VIncrementTableRow *incr = new VIncrementTableRow(*data->GetIncrementTableRow(itemName->text())); + Q_ASSERT(incr != 0); + incr->setDescription(item->text()); data->UpdateIncrementTableRow(itemName->text(), incr); ui->tableWidgetIncrement->resizeColumnsToContents(); ui->tableWidgetIncrement->resizeRowsToContents(); diff --git a/src/dialogs/dialogline.cpp b/src/dialogs/dialogline.cpp index 69fd50d93..123210e31 100644 --- a/src/dialogs/dialogline.cpp +++ b/src/dialogs/dialogline.cpp @@ -54,8 +54,8 @@ DialogLine::~DialogLine() void DialogLine::setSecondPoint(const qint64 &value) { secondPoint = value; - VPointF point = data->GetPoint(value); - qint32 index = ui->comboBoxSecondPoint->findText(point.name()); + const VPointF *point = data->GeometricObject(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/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/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/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 04e8aa35a..a57ad6fb9 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,8 +88,8 @@ 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(); @@ -92,16 +97,24 @@ void DialogTool::FillComboBoxSplines(QComboBox *box, const qint64 &id, ComboMode { 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,8 +124,8 @@ 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(); @@ -120,16 +133,24 @@ void DialogTool::FillComboBoxSplinesPath(QComboBox *box, const qint64 &id, Combo { 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()); + } } } } @@ -489,17 +510,17 @@ void DialogTool::ValChenged(int row) } if (radioButtonStandartTable->isChecked()) { - VStandartTableRow stable = data->GetStandartTableCell(item->text()); + const VStandartTableRow *stable = data->GetStandartTableCell(item->text()); QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandartTableCell(item->text())) - .arg(stable.GetDescription()); + .arg(stable->GetDescription()); labelDescription->setText(desc); return; } if (radioButtonIncrements->isChecked()) { - VIncrementTableRow itable = data->GetIncrementTableRow(item->text()); + const VIncrementTableRow *itable = data->GetIncrementTableRow(item->text()); QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueIncrementTableRow(item->text())) - .arg(itable.getDescription()); + .arg(itable->getDescription()); labelDescription->setText(desc); return; } 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/dialoguniondetails.cpp b/src/dialogs/dialoguniondetails.cpp index f1922fdea..58c269518 100644 --- a/src/dialogs/dialoguniondetails.cpp +++ b/src/dialogs/dialoguniondetails.cpp @@ -30,7 +30,7 @@ #include "ui_dialoguniondetails.h" DialogUnionDetails::DialogUnionDetails(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogUnionDetails), details(VDetail()), d1(0), d2(0), d1P1(0), d1P2(0), + DialogTool(data, parent), ui(new Ui::DialogUnionDetails), d1(0), d2(0), d1P1(0), d1P2(0), d2P1(0), d2P2(0), numberD(0), numberP(0) { ui->setupUi(this); @@ -59,7 +59,6 @@ void DialogUnionDetails::ChoosedObject(qint64 id, const Scene::Scenes &type) void DialogUnionDetails::DialogAccepted() { - emit ToolTip(""); emit DialogClosed(QDialog::Accepted); } @@ -69,8 +68,8 @@ bool DialogUnionDetails::CheckObject(const qint64 &id, const qint64 &idDetail) c { return false; } - VDetail det = data->GetDetail(idDetail); - return det.Containes(id); + const VDetail *det = data->GetDetail(idDetail); + return det->Containes(id); } void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, qint64 &p1, @@ -99,6 +98,10 @@ void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &ty } if (numberP == 1) { + if(id == p1) + { + return; + } p2 = id; ++numberD; if(numberD > 1) diff --git a/src/dialogs/dialoguniondetails.h b/src/dialogs/dialoguniondetails.h index 55825e07c..8b4ed6798 100644 --- a/src/dialogs/dialoguniondetails.h +++ b/src/dialogs/dialoguniondetails.h @@ -41,6 +41,12 @@ class DialogUnionDetails : public DialogTool public: explicit DialogUnionDetails(const VContainer *data, QWidget *parent = 0); ~DialogUnionDetails(); + inline qint64 getD1() const {return d1;} + inline qint64 getD2() const {return d2;} + inline qint64 getD1P1() const {return d1P1;} + inline qint64 getD1P2() const {return d1P2;} + inline qint64 getD2P1() const {return d2P1;} + inline qint64 getD2P2() const {return d2P2;} public slots: /** * @brief ChoosedObject gets id and type of selected object. Save correct data and ignore wrong. @@ -55,10 +61,6 @@ public slots: private: Q_DISABLE_COPY(DialogUnionDetails) Ui::DialogUnionDetails *ui; - /** - * @brief details detail - */ - VDetail details; qint64 d1; qint64 d2; qint64 d1P1; 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..674c92dd4 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..e412c0279 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 повертає шлях. @@ -158,27 +143,7 @@ public: * @param number * @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;} + QVector SplOfArc( qint32 number ) const; private: /** * @brief f1 початковий кут в градусах @@ -207,19 +172,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..15dfe150d 100644 --- a/src/geometry/vdetail.cpp +++ b/src/geometry/vdetail.cpp @@ -29,16 +29,16 @@ #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) @@ -66,7 +66,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 +81,31 @@ 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; +} + diff --git a/src/geometry/vdetail.h b/src/geometry/vdetail.h index 958c8f421..ffb362f1f 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,12 @@ 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); + 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..6c9f5b24a --- /dev/null +++ b/src/geometry/vgobject.h @@ -0,0 +1,89 @@ +/************************************************************************ + ** + ** @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 +{ + Q_DECLARE_TR_FUNCTIONS(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..86e91d629 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,7 @@ 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;} private: - /** - * @brief _name name of point - */ - QString _name; /** * @brief _mx offset name respect to x */ @@ -155,10 +131,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..46768147a 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; @@ -213,7 +150,7 @@ qreal VSpline::LengthT(qreal t) const 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,7 +174,7 @@ 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 @@ -267,7 +204,7 @@ QPointF VSpline::CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPo } } - 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 +216,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 +235,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 +568,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 +592,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 +611,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 +621,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..98b6f666a 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,6 +166,11 @@ 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 { @@ -190,8 +193,8 @@ 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) { @@ -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..a50aeb5a8 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,6 @@ 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); protected: /** * @brief path вектор з точок сплайна. @@ -197,18 +169,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 e0296fa20..2dbde633f 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,7 +58,8 @@ MainWindow::MainWindow(QWidget *parent) dialogTriangle(QSharedPointer()), dialogPointOfIntersection(QSharedPointer()), dialogCutSpline(QSharedPointer()), dialogCutSplinePath (QSharedPointer()), - dialogHistory(0), doc(0), data(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), + dialogUnionDetails(QSharedPointer()), + dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), mode(Draw::Calculation) { ui->setupUi(this); @@ -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->ClearObject(); //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,17 @@ 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); +} + +void MainWindow::ClosedDialogUnionDetails(int result) +{ + ClosedDialog(dialogUnionDetails, result); +} + void MainWindow::About() { QString fullName = QString("Valentina %1").arg(APP_VERSION); @@ -956,7 +966,7 @@ void MainWindow::Clear() { setWindowTitle("Valentina"); fileName.clear(); - data->Clear(); + pattern->Clear(); doc->clear(); sceneDraw->clear(); sceneDetails->clear(); @@ -991,14 +1001,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 +1030,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 +1052,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 +1070,7 @@ void MainWindow::ActionLayout(bool checked) Q_UNUSED(checked); hide(); QVector listDetails; - data->PrepareDetails(listDetails); + pattern->PrepareDetails(listDetails); emit ModelChosen(listDetails); } @@ -1205,7 +1215,7 @@ MainWindow::~MainWindow() CanselTool(); delete ui; - delete data; + delete pattern; if (doc->isNull() == false) { delete doc; diff --git a/src/mainwindow.h b/src/mainwindow.h index 92fdeb275..53a57350b 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 */ 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/tools/drawTools/vtoolalongline.cpp b/src/tools/drawTools/vtoolalongline.cpp index 7b2c29892..62c8a2053 100644 --- a/src/tools/drawTools/vtoolalongline.cpp +++ b/src/tools/drawTools/vtoolalongline.cpp @@ -93,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); @@ -112,13 +112,13 @@ void VToolAlongLine::AddToFile() void VToolAlongLine::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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(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); @@ -135,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, @@ -160,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); @@ -172,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/vtoolarc.cpp b/src/tools/drawTools/vtoolarc.cpp index db2f91b10..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)); @@ -58,11 +58,11 @@ VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::S 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, @@ -103,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); @@ -190,29 +192,29 @@ 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() { - VArc arc = VAbstractTool::data.GetArc(id); + const VArc *arc = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - domElement.setAttribute(AttrCenter, arc.GetCenter()); - domElement.setAttribute(AttrRadius, arc.GetFormulaRadius()); - domElement.setAttribute(AttrAngle1, arc.GetFormulaF1()); - domElement.setAttribute(AttrAngle2, arc.GetFormulaF2()); + domElement.setAttribute(AttrCenter, arc->GetCenter().id()); + domElement.setAttribute(AttrRadius, arc->GetFormulaRadius()); + domElement.setAttribute(AttrAngle1, arc->GetFormulaF1()); + domElement.setAttribute(AttrAngle2, arc->GetFormulaF2()); } } @@ -239,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/vtoolbisector.cpp b/src/tools/drawTools/vtoolbisector.cpp index 637ed4bdd..eb973f3af 100644 --- a/src/tools/drawTools/vtoolbisector.cpp +++ b/src/tools/drawTools/vtoolbisector.cpp @@ -73,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, @@ -101,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) { @@ -190,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); @@ -210,13 +210,13 @@ void VToolBisector::AddToFile() void VToolBisector::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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(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); diff --git a/src/tools/drawTools/vtoolcutspline.cpp b/src/tools/drawTools/vtoolcutspline.cpp index 0a62b55ca..7e3bd24dc 100644 --- a/src/tools/drawTools/vtoolcutspline.cpp +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -67,10 +67,10 @@ VToolCutSpline::VToolCutSpline(VDomDocument *doc, VContainer *data, const qint64 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, @@ -87,53 +87,61 @@ 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)); + VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my); + Q_ASSERT(p != 0); + id = data->AddGObject(p); spl1id = id + 1; spl2id = id + 2; - 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); @@ -211,14 +219,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); @@ -228,13 +236,13 @@ void VToolCutSpline::AddToFile() void VToolCutSpline::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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(AttrName, point->name()); + domElement.setAttribute(AttrMx, toMM(point->mx())); + domElement.setAttribute(AttrMy, toMM(point->my())); domElement.setAttribute(AttrLength, formula); domElement.setAttribute(AttrSpline, splineId); } @@ -244,22 +252,22 @@ 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) { - 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/vtoolcutsplinepath.cpp b/src/tools/drawTools/vtoolcutsplinepath.cpp index d563c217f..2083c82e6 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/tools/drawTools/vtoolcutsplinepath.cpp @@ -69,10 +69,10 @@ VToolCutSplinePath::VToolCutSplinePath(VDomDocument *doc, VContainer *data, cons 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, @@ -89,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); @@ -97,109 +97,115 @@ 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) { - 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) { - 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) { - 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) { - 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, @@ -278,14 +284,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); @@ -295,13 +301,13 @@ void VToolCutSplinePath::AddToFile() void VToolCutSplinePath::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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(AttrName, point->name()); + domElement.setAttribute(AttrMx, toMM(point->mx())); + domElement.setAttribute(AttrMy, toMM(point->my())); domElement.setAttribute(AttrLength, formula); domElement.setAttribute(AttrSplinePath, splinePathId); } @@ -311,24 +317,24 @@ 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) { - 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/vtoolendline.cpp b/src/tools/drawTools/vtoolendline.cpp index bfd8e8085..c8225c361 100644 --- a/src/tools/drawTools/vtoolendline.cpp +++ b/src/tools/drawTools/vtoolendline.cpp @@ -52,12 +52,12 @@ VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id 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, @@ -77,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); @@ -89,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) { @@ -154,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); @@ -173,13 +173,13 @@ void VToolEndLine::AddToFile() void VToolEndLine::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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(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); diff --git a/src/tools/drawTools/vtoolheight.cpp b/src/tools/drawTools/vtoolheight.cpp index 1d48a7dbf..57b3290cc 100644 --- a/src/tools/drawTools/vtoolheight.cpp +++ b/src/tools/drawTools/vtoolheight.cpp @@ -50,12 +50,12 @@ VToolHeight::VToolHeight(VDomDocument *doc, VContainer *data, const qint64 &id, 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, @@ -76,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); @@ -174,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); @@ -194,13 +194,13 @@ void VToolHeight::AddToFile() void VToolHeight::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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(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); diff --git a/src/tools/drawTools/vtoolline.cpp b/src/tools/drawTools/vtoolline.cpp index 8b61e012b..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); @@ -206,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/vtoollineintersect.cpp b/src/tools/drawTools/vtoollineintersect.cpp index 6db550e12..30fa1fa39 100644 --- a/src/tools/drawTools/vtoollineintersect.cpp +++ b/src/tools/drawTools/vtoollineintersect.cpp @@ -51,12 +51,12 @@ VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, cons 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, @@ -77,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) @@ -91,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); @@ -99,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); @@ -137,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) @@ -161,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) @@ -171,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); @@ -190,13 +190,13 @@ void VToolLineIntersect::AddToFile() void VToolLineIntersect::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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(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); 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 d00089f6f..c648b14cc 100644 --- a/src/tools/drawTools/vtoolnormal.cpp +++ b/src/tools/drawTools/vtoolnormal.cpp @@ -51,13 +51,13 @@ VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, 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, @@ -79,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) { @@ -175,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); @@ -195,13 +195,13 @@ void VToolNormal::AddToFile() void VToolNormal::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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(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); 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 f1365103d..eaf0bfb18 100644 --- a/src/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/tools/drawTools/vtoolpointofcontact.cpp @@ -51,12 +51,12 @@ VToolPointOfContact::VToolPointOfContact(VDomDocument *doc, VContainer *data, co 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, @@ -103,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); @@ -160,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) @@ -184,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) @@ -194,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); @@ -213,13 +213,13 @@ void VToolPointOfContact::AddToFile() void VToolPointOfContact::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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(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); diff --git a/src/tools/drawTools/vtoolpointofintersection.cpp b/src/tools/drawTools/vtoolpointofintersection.cpp index 8bec57a1d..f2dda86da 100644 --- a/src/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/tools/drawTools/vtoolpointofintersection.cpp @@ -50,10 +50,10 @@ VToolPointOfIntersection::VToolPointOfIntersection(VDomDocument *doc, VContainer 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, @@ -70,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); @@ -110,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) @@ -142,14 +142,14 @@ 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); @@ -159,13 +159,13 @@ void VToolPointOfIntersection::AddToFile() void VToolPointOfIntersection::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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(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/vtoolshoulderpoint.cpp b/src/tools/drawTools/vtoolshoulderpoint.cpp index adda7877f..2e2567735 100644 --- a/src/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/tools/drawTools/vtoolshoulderpoint.cpp @@ -51,13 +51,13 @@ VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, cons 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, @@ -105,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) @@ -197,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); @@ -217,13 +217,13 @@ void VToolShoulderPoint::AddToFile() void VToolShoulderPoint::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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(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); diff --git a/src/tools/drawTools/vtoolsinglepoint.cpp b/src/tools/drawTools/vtoolsinglepoint.cpp index cd70c474b..f40c0ef71 100644 --- a/src/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/tools/drawTools/vtoolsinglepoint.cpp @@ -50,37 +50,37 @@ VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 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() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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()))); + 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()))); } } @@ -130,7 +130,7 @@ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event void VToolSinglePoint::FullUpdateFromFile() { - RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); + RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); } void VToolSinglePoint::FullUpdateFromGui(int result) @@ -169,5 +169,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/vtoolspline.cpp b/src/tools/drawTools/vtoolspline.cpp index f7534aeec..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); @@ -77,14 +77,14 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, const T 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, @@ -106,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); @@ -145,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, @@ -160,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(); } } @@ -182,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()) @@ -210,35 +214,35 @@ 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() { - VSpline spl = VAbstractTool::data.GetSpline(id); + const VSpline *spl = VAbstractTool::data.GeometricObject(id); 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()); } } @@ -265,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/vtoolsplinepath.cpp b/src/tools/drawTools/vtoolsplinepath.cpp index 25f9ee03e..9b7373240 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); @@ -78,35 +77,36 @@ VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, 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); @@ -149,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); @@ -170,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); - VSpline spl = splPath.GetSpline(indexSpline); + VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); + VSpline spl; 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); @@ -214,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()); } } } @@ -260,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); @@ -277,7 +277,7 @@ void VToolSplinePath::AddToFile() void VToolSplinePath::RefreshDataInFile() { - VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); + VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); for (qint32 i = 1; i<=splPath.Count(); ++i) { VSpline spl = splPath.GetSpline(i); @@ -293,8 +293,8 @@ void VToolSplinePath::RefreshDataInFile() 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); @@ -312,7 +312,7 @@ void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint & { 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()); @@ -343,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 2febbba44..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); /** diff --git a/src/tools/drawTools/vtooltriangle.cpp b/src/tools/drawTools/vtooltriangle.cpp index fcd425df6..af21f9856 100644 --- a/src/tools/drawTools/vtooltriangle.cpp +++ b/src/tools/drawTools/vtooltriangle.cpp @@ -50,12 +50,12 @@ VToolTriangle::VToolTriangle(VDomDocument *doc, VContainer *data, const qint64 & 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, @@ -75,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); @@ -163,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) @@ -200,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); @@ -219,16 +219,16 @@ void VToolTriangle::AddToFile() void VToolTriangle::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + 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, QString().setNum(axisP1Id)); - domElement.setAttribute(AttrAxisP2, QString().setNum(axisP2Id)); - domElement.setAttribute(AttrFirstPoint, QString().setNum(firstPointId)); - domElement.setAttribute(AttrSecondPoint, QString().setNum(secondPointId)); + 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/nodeDetails/vnodearc.cpp b/src/tools/nodeDetails/vnodearc.cpp index 0d58f0b07..353a35810 100644 --- a/src/tools/nodeDetails/vnodearc.cpp +++ b/src/tools/nodeDetails/vnodearc.cpp @@ -114,9 +114,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/vnodepoint.cpp b/src/tools/nodeDetails/vnodepoint.cpp index 8ab9c79de..e06c6a040 100644 --- a/src/tools/nodeDetails/vnodepoint.cpp +++ b/src/tools/nodeDetails/vnodepoint.cpp @@ -46,7 +46,7 @@ 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(); @@ -75,32 +75,32 @@ 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())); AddToModeling(domElement); } void VNodePoint::RefreshDataInFile() { - VPointF point = VAbstractTool::data.GetPoint(id); + const VPointF *point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); - domElement.setAttribute(AttrMx, QString().setNum(toMM(point.mx()))); - domElement.setAttribute(AttrMy, QString().setNum(toMM(point.my()))); + domElement.setAttribute(AttrIdObject, idNode); + domElement.setAttribute(AttrMx, toMM(point->mx())); + domElement.setAttribute(AttrMy, toMM(point->my())); } } @@ -128,13 +128,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/vnodespline.cpp b/src/tools/nodeDetails/vnodespline.cpp index 9934f2ca5..b2fbcaa10 100644 --- a/src/tools/nodeDetails/vnodespline.cpp +++ b/src/tools/nodeDetails/vnodespline.cpp @@ -115,9 +115,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/vnodesplinepath.cpp b/src/tools/nodeDetails/vnodesplinepath.cpp index 6be0872fa..8d1a98fd6 100644 --- a/src/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/tools/nodeDetails/vnodesplinepath.cpp @@ -58,11 +58,11 @@ void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qin VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation); 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()); + doc->IncrementReferens(points->at(i).P().id()); } } else @@ -119,9 +119,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/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/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 28c29e845..472ee1098 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -44,7 +44,7 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialogDetail(QSharedPointer()), sceneDetails(scene) { - VDetail detail = data->GetDetail(id); + VDetail detail = VDetail(*data->GetDetail(id)); for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) { switch (detail[i].getTypeTool()) @@ -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(); } @@ -81,15 +81,16 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, void VToolDetail::setDialog() { Q_ASSERT(dialogDetail.isNull() == false); - VDetail detail = VAbstractTool::data.GetDetail(id); - dialogDetail->setDetails(detail); + const VDetail *detail = VAbstractTool::data.GeometricObject(id); + dialogDetail->setDetails(*detail); } void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { VDetail detail = dialog->getDetails(); - VDetail det; + VDetail *det = new VDetail(); + Q_ASSERT(det != 0); for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) { qint64 id = 0; @@ -97,29 +98,33 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen { case (Tool::NodePoint): { - VPointF point = data->GetPoint(detail[i].getId()); - id = data->AddPoint(point); + VPointF *point = new VPointF(*data->GeometricObject(detail[i].getId())); + Q_ASSERT(point != 0); + id = data->AddGObject(point); 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); + VArc *arc = new VArc(*data->GeometricObject(detail[i].getId())); + Q_ASSERT(arc != 0); + id = data->AddGObject(arc); 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); + VSpline *spline = new VSpline(*data->GeometricObject(detail[i].getId())); + Q_ASSERT(spline != 0); + id = data->AddGObject(spline); 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); + VSplinePath *splinePath = new VSplinePath(*data->GeometricObject(detail[i].getId())); + Q_ASSERT(splinePath != 0); + id = data->AddGObject(splinePath); VNodeSplinePath::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); } break; @@ -128,17 +133,17 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen break; } VNodeDetail node(id, detail[i].getTypeTool(), NodeDetail::Contour); - det.append(node); + det->append(node); } - det.setName(detail.getName()); + det->setName(detail.getName()); 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, 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); } @@ -161,6 +166,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"<d1, this->d1P1, this->d1P2); + CorectPoints(this->d2, this->d2P1, this->d2P2); + + if (typeCreation == Tool::FromGui) + { + AddToFile(); + } + else + { + RefreshDataInFile(); + } +} + +void VToolUnionDetails::CorectPoints(const VDetail &detail, qint64 &p1, qint64 &p2) +{ + if(p1 == p2) + { + qWarning()<<"Union points equal."; + return; + } + bool p1flag = false; + bool p2flag = false; + for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) + { + if(detail.at(i).getTypeTool() == Tool::NodePoint) + { + if(p1 == detail.at(i).getId()) + { + p1flag = true; + } + if(p2 == detail.at(i).getId()) + { + p2flag = true; + } + if(p1flag == true && p2flag == false) + { + return; + } + if(p2flag == true && p1flag == false) + { + qint64 p = p1; + p1 = p2; + p2 = p; + return; + } + } + } +} + +void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail *newDetail, const VDetail &det, const ptrdiff_t &a, + const ptrdiff_t &b, const qreal &dx, const qreal &dy, const qint64 &pRotate, + const qreal &angle) const +{ + for (ptrdiff_t i = a; i <= b; ++i) + { + qint64 id = 0; + switch (det.at(i).getTypeTool()) + { + case (Tool::NodePoint): + { + if( qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && (pRotate == 0)) + { + id = det.at(i).getId(); + } + else + { + VPointF *point = new VPointF(*data->GeometricObject(det.at(i).getId())); + Q_ASSERT(point != 0); + BiasRotatePoint(point, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); + id = data->AddGObject(point); + VNodePoint::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui ); + } + } + 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); + id = data->AddGObject(arc1); + VNodeArc::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui); + } + } + 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()); + id = data->AddGObject(spl); + VNodeSpline::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui); + } + } + 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); + 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())); + } + id = data->AddGObject(path); + VNodeSplinePath::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui); + } + } + break; + default: + qWarning()<<"May be wrong tool type!!! Ignoring."<append(VNodeDetail(id, det.at(i).getTypeTool(), NodeDetail::Contour)); + } +} + +void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &a, + const ptrdiff_t &b, const qreal &dx, const qreal &dy, const qint64 &pRotate, + const qreal &angle) const +{ + qint64 idCount = 0; + for (ptrdiff_t i = a; i <= b; ++i) + { + switch (det.at(i).getTypeTool()) + { + case (Tool::NodePoint): + { + if(qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + { + ++idCount; + } + else + { + VPointF *point = new VPointF(*data->GeometricObject(det.at(i).getId())); + Q_ASSERT(point != 0); + BiasRotatePoint(point, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + ++idCount; + data->UpdateGObject(idDetail+idCount, point); + } + } + break; + case (Tool::NodeArc): + { + if(qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + { + ++idCount; + } + else + { + 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); + ++idCount; + data->UpdateGObject(idDetail+idCount, arc1); + } + } + break; + case (Tool::NodeSpline): + { + if(qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + { + ++idCount; + } + 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()); + 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); + ++idCount; + data->UpdateGObject(idDetail+idCount, spl); + } + } + break; + case (Tool::NodeSplinePath): + { + if(qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + { + ++idCount; + } + else + { + VSplinePath *path = new VSplinePath(); + Q_ASSERT(path != 0); + 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); + } + } + break; + default: + qWarning()<<"May be wrong tool type!!! Ignoring."<setX(point->x()+dx); + point->setY(point->y()+dy); + QLineF l(pRotate, point->toQPointF()); + l.setAngle(angle); + point->setX(l.p2().x()); + point->setY(l.p2().y()); +} + +void VToolUnionDetails::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data) +{ + VDetail d1 = VDetail(*data->GetDetail(dialog->getD1())); + VDetail d2 = VDetail(*data->GetDetail(dialog->getD2())); + qint64 d1P1 = dialog->getD1P1(); + qint64 d1P2 = dialog->getD1P2(); + qint64 d2P1 = dialog->getD2P1(); + qint64 d2P2 = dialog->getD2P2(); + Create(0, d1, d2, dialog->getD1(), dialog->getD2(), d1P1, d1P2, d2P1, d2P2, 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 qint64 &d1P1, const qint64 &d1P2, const qint64 &d2P1, + const qint64 &d2P2, 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); + } + } + if (parse == Document::FullParse) + { + unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, d1P1, d1P2, d2P1, d2P2, typeCreation); + 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) + { + //Update corected points + qint64 d1P1 = unionDetails->getD1P1(); + qint64 d1P2 = unionDetails->getD1P2(); + qint64 d2P1 = unionDetails->getD2P1(); + qint64 d2P2 = unionDetails->getD2P2(); + + VDetail *newDetail = new VDetail(); + Q_ASSERT(newDetail != 0); + unionDetails->AddToNewDetail(data, newDetail, d1, d1.indexOfNode(d1P1), d1.indexOfNode(d1P2)); + + const VNodeDetail det1p2 = d1.at(d1.indexOfNode(d1P2)); + const VPointF *point2 = data->GeometricObject(det1p2.getId()); + const VNodeDetail det2p1 = d2.at(d2.indexOfNode(d2P1)); + const VPointF *point1 = data->GeometricObject(det2p1.getId()); + qreal dx = point2->x() - point1->x(); + qreal dy = point2->y() - point1->y(); + const VNodeDetail det1p1 = d1.at(d1.indexOfNode(d1P1)); + const VPointF *point3 = data->GeometricObject(det1p1.getId()); + const VNodeDetail det2p2 = d1.at(d1.indexOfNode(d2P2)); + const VPointF *point4 = data->GeometricObject(det2p2.getId()); + QLineF l1(point3->toQPointF(), point2->toQPointF()); + QLineF l2(point4->toQPointF(), point1->toQPointF()); + qreal angle = l2.angle() + l2.angleTo(l1); + + unionDetails->AddToNewDetail(data, newDetail, d2, d2.indexOfNode(d2P1)+1, d2.indexOfNode(d2P2)-1, dx, dy, + d1P2, angle); + + newDetail->setName("Detail"); + VToolDetail::Create(0, newDetail, scene, doc, data, parse, Tool::FromTool); + QHash* tools = doc->getTools(); + VToolDetail *toolDet = qobject_cast(tools->value(d1id)); + toolDet->Remove(); + toolDet = qobject_cast(tools->value(d2id)); + toolDet->Remove(); + } + else + { + unionDetails = qobject_cast(doc->getTool(id)); + + unionDetails->UpdatePoints(id, data, d1, d1.indexOfNode(d1P1), d1.indexOfNode(d1P2)); + + VNodeDetail det1p2 = d1.at(d1.indexOfNode(d1P2)); + const VPointF *point2 = data->GeometricObject(det1p2.getId()); + VNodeDetail det2p1 = d2.at(d2.indexOfNode(d2P1)); + const VPointF *point1 = data->GeometricObject(det2p1.getId()); + qreal dx = point2->x() - point1->x(); + qreal dy = point2->y() - point1->y(); + const VNodeDetail det1p1 = d1.at(d1.indexOfNode(d1P1)); + const VPointF *point3 = data->GeometricObject(det1p1.getId()); + const VNodeDetail det2p2 = d1.at(d1.indexOfNode(d2P2)); + const VPointF *point4 = data->GeometricObject(det2p2.getId()); + QLineF l1(point3->toQPointF(), point2->toQPointF()); + QLineF l2(point4->toQPointF(), point1->toQPointF()); + qreal angle = l2.angle() + l2.angleTo(l1); + + unionDetails->UpdatePoints(id, data, d2, d2.indexOfNode(d2P1)+1, d2.indexOfNode(d2P2)-1, dx, dy, + d1P2, angle); + } +} + +QVector 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) + { + QDomNodeList nodeList = domElement.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; + } + vector[i].append(VNodeDetail(id, tool, nodeType, mx, my)); + } + } + } + } + } + } + return vector; +} + +void VToolUnionDetails::AddToFile() +{ + QDomElement domElement = doc->createElement(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrD1P1, d1P1); + AddAttribute(domElement, AttrD1P2, d1P2); + AddAttribute(domElement, AttrD2P1, d2P1); + AddAttribute(domElement, AttrD2P2, d2P2); + + AddDetail(domElement, d1); + AddDetail(domElement, d2); + + AddToModeling(domElement); +} + +void VToolUnionDetails::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrD1P1, d1P1); + domElement.setAttribute(AttrD1P2, d1P2); + domElement.setAttribute(AttrD2P1, d2P1); + domElement.setAttribute(AttrD2P2, d2P2); + + 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, 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."<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 qint64 &d1P1, const qint64 &d1P2, const qint64 &d2P1, const qint64 &d2P2, + const Tool::Sources &typeCreation); + 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 qint64 &d1P1, const qint64 &d1P2, const qint64 &d2P1, const qint64 &d2P2, + 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 AttrD1P1; + static const QString AttrD1P2; + static const QString AttrD2P1; + static const QString AttrD2P2; + static const QString AttrIdObject; + static const QString AttrNodeType; + static const QString NodeTypeContour; + static const QString NodeTypeModeling; + + inline qint64 getD1P1() const{return d1P1;} + inline qint64 getD1P2() const{return d1P2;} + inline qint64 getD2P1() const{return d2P1;} + inline qint64 getD2P2() const{return d2P2;} + void AddToNewDetail(VContainer *data, VDetail *newDetail, const VDetail &det, const ptrdiff_t &a, + const ptrdiff_t &b, const qreal &dx = 0, const qreal &dy = 0, const qint64 &pRotate = 0, + const qreal &angle = 0) const; + void UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &a, + const ptrdiff_t &b, const qreal &dx = 0, const qreal &dy = 0, const qint64 &pRotate = 0, + const qreal &angle = 0) const; + void BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate, + const qreal angle)const; +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; + qint64 d1P1; + qint64 d1P2; + qint64 d2P1; + qint64 d2P2; + void AddDetail(QDomElement &domElement, VDetail &d); + void AddNode(QDomElement &domElement, VNodeDetail &node); + QDomNode UpdateDetail(QDomNode &domNode, VDetail &d); + void UpdateNode(QDomNode &domNode, VNodeDetail &node); + void AddToModeling(const QDomElement &domElement); + void CorectPoints(const VDetail &detail, qint64 &p1, qint64 &p2); + +}; + +#endif // VTOOLUNIONDETAILS_H diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index 64de855f1..b8287798c 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -34,6 +34,7 @@ #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" @@ -371,6 +372,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(); @@ -390,8 +405,7 @@ void VDomDocument::ParseIncrementsElement(const QDomNode &node) 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, new VIncrementTableRow(id, base, ksize, kgrowth, desc)); } } } @@ -551,6 +565,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; + } } } } @@ -562,15 +581,16 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); try { - VDetail detail; + VDetail *detail = new VDetail(); + Q_ASSERT(detail != 0); VDetail oldDetail; qint64 id = GetParametrId(domElement); - 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")); + 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(); @@ -590,28 +610,28 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo 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)); + detail->append(VNodeDetail(id, tool, nodeType, mx, my)); } } } @@ -665,7 +685,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen 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) { @@ -866,10 +886,11 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen { qint64 id = GetParametrId(domElement); qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); - VPointF point = data->GetPoint(idObject ); + 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->UpdatePoint(id, VPointF(point.x(), point.y(), point.name(), mx, my, idObject )); + 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); return; } @@ -1052,7 +1073,8 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme { qint64 id = GetParametrId(domElement); qreal kCurve = GetParametrDouble(domElement, VAbstractTool::AttrKCurve, "1.0"); - VSplinePath path(data->DataPoints(), kCurve); + VSplinePath *path = new VSplinePath(kCurve); + Q_ASSERT(path != 0); QDomNodeList nodeList = domElement.childNodes(); qint32 num = nodeList.size(); @@ -1067,8 +1089,10 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme qreal angle = GetParametrDouble(element, VAbstractTool::AttrAngle, "0"); qreal kAsm2 = GetParametrDouble(element, VAbstractTool::AttrKAsm2, "1.0"); qint64 pSpline = GetParametrLongLong(element, VAbstractTool::AttrPSpline, "0"); - VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2); - path.append(splPoint); + VPointF p = *data->GeometricObject(pSpline); + + VSplinePoint splPoint(p, kAsm1, angle, kAsm2); + path->append(splPoint); if (parse == Document::FullParse) { IncrementReferens(pSpline); @@ -1093,9 +1117,10 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme { qint64 id = GetParametrId(domElement); qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); - VSpline spl = data->GetSpline(idObject); - spl.setIdObject(idObject); - data->UpdateSpline(id, spl); + 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); return; } @@ -1112,9 +1137,10 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme { qint64 id = GetParametrId(domElement); qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); - VSplinePath path = data->GetSplinePath(idObject); - path.setIdObject(idObject); - data->UpdateSplinePath(id, path); + 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); return; } @@ -1160,9 +1186,10 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement { qint64 id = GetParametrId(domElement); qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); - VArc arc = data->GetArc(idObject); - arc.setIdObject(idObject); - data->UpdateArc(id, arc); + 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); return; } @@ -1175,6 +1202,38 @@ 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 d1P1 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD1P1, "0"); + qint64 d1P2 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD1P2, "0"); + qint64 d2P1 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD2P1, "0"); + qint64 d2P2 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD2P2, "0"); + + QVector vector = VToolUnionDetails::GetDetailFromFile(this, domElement); + + VToolUnionDetails::Create(id, vector[0], vector[1], 0, 0, d1P1, d1P2, d2P1, d2P2, 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(); diff --git a/src/xml/vdomdocument.h b/src/xml/vdomdocument.h index f0c38fd04..33c6179fe 100644 --- a/src/xml/vdomdocument.h +++ b/src/xml/vdomdocument.h @@ -155,6 +155,7 @@ public: * @return */ inline QHash* getTools() {return &tools;} + VDataTool* getTool(const qint64 &id); /** * @brief getHistory * @return @@ -403,6 +404,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 From eddcaf8ff2b5026a97840135e65cf41c08d109a1 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 30 Dec 2013 13:28:33 +0200 Subject: [PATCH 08/15] Fixed crashes. Still have memory leak. --HG-- branch : feature --- Valentina.pro | 2 +- src/container/vcontainer.cpp | 70 +++++++++++++++++++++--- src/container/vcontainer.h | 19 +++++-- src/geometry/varc.h | 4 +- src/geometry/vdetail.cpp | 9 ++- src/geometry/vdetail.h | 3 +- src/geometry/vgobject.cpp | 6 +- src/geometry/vgobject.h | 8 +-- src/geometry/vpointf.h | 2 + src/geometry/vspline.h | 1 + src/geometry/vsplinepath.h | 4 +- src/tools/drawTools/vtoolcutspline.cpp | 2 - src/tools/drawTools/vtoolsinglepoint.cpp | 5 +- src/tools/drawTools/vtoolsplinepath.cpp | 2 +- src/tools/vdatatool.h | 2 +- src/tools/vtooldetail.cpp | 4 ++ src/xml/vdomdocument.cpp | 2 + 17 files changed, 113 insertions(+), 32 deletions(-) diff --git a/Valentina.pro b/Valentina.pro index 508c984d5..fb54f3f3c 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -126,7 +126,7 @@ 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 \ diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 6cc374f3d..02f22013d 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -27,7 +27,6 @@ *************************************************************************/ #include "vcontainer.h" -#include "../exception/vexceptionbadid.h" #include #include @@ -63,7 +62,48 @@ VContainer::VContainer(const VContainer &data) void VContainer::setData(const VContainer &data) { base = *data.DataBase(); - gObjects = *data.DataGObjects(); + + 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): + { + VArc *arc = new VArc(*data.GeometricObject(i.key())); + Q_ASSERT(arc != 0); + gObjects.insert(i.key(), arc); + break; + } + case(GObject::Point): + { + VPointF *point = new VPointF(*data.GeometricObject(i.key())); + Q_ASSERT(point != 0); + gObjects.insert(i.key(), point); + break; + } + case(GObject::Spline): + { + VSpline *spl = new VSpline(*data.GeometricObject(i.key())); + Q_ASSERT(spl != 0); + gObjects.insert(i.key(), spl); + break; + } + case(GObject::SplinePath): + { + VSplinePath *path = new VSplinePath(*data.GeometricObject(i.key())); + Q_ASSERT(path != 0); + gObjects.insert(i.key(), path); + break; + } + } + } + //gObjects = *data.DataGObjects(); standartTable = *data.DataStandartTable(); incrementTable = *data.DataIncrementTable(); lengthLines = *data.DataLengthLines(); @@ -79,7 +119,7 @@ const VGObject *VContainer::GetGObject(qint64 id)const } template -const val *VContainer::GetObject(const QHash &obj, key id) const +const val VContainer::GetObject(const QHash &obj, key id) const { if (obj.contains(id)) { @@ -510,12 +550,15 @@ void VContainer::PrepareDetails(QVector &list) const } template -void VContainer::UpdateObject(QHash &obj, const qint64 &id, 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); - delete GetObject(gObjects, id); + point->setId(id); +// if (gObjects.contains(id)) +// { +// delete gObjects.value(id); +// } obj[id] = point; UpdateId(id); } @@ -565,7 +608,15 @@ qreal VContainer::GetValueIncrementTableRow(const QString& name) const void VContainer::Clear() { _id = 0; + if(standartTable.size()>0) + { + qDeleteAll(standartTable); + } standartTable.clear(); + if(incrementTable.size()>0) + { + qDeleteAll(incrementTable); + } incrementTable.clear(); lengthLines.clear(); lengthArcs.clear(); @@ -577,7 +628,10 @@ void VContainer::Clear() void VContainer::ClearObject() { - qDeleteAll(gObjects); + if(gObjects.size()>0) + { + qDeleteAll(gObjects); + } gObjects.clear(); } @@ -634,7 +688,7 @@ void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId } template -qint64 VContainer::AddObject(QHash &obj, val *value) +qint64 VContainer::AddObject(QHash &obj, val value) { Q_ASSERT(value != 0); qint64 id = getNextId(); diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index c776860c8..14c86bed8 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -36,6 +36,7 @@ #include "../geometry/vdetail.h" #include "../widgets/vitem.h" #include "../geometry/vgobject.h" +#include "../exception/vexceptionbadid.h" /** * @brief The VContainer class container of all variables. @@ -67,7 +68,17 @@ public: template const T GeometricObject(qint64 id) const { - const T obj = dynamic_cast(GetObject(gObjects, id)); + 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); + T obj = qobject_cast(gObj); Q_ASSERT(obj != 0); return obj; } @@ -481,7 +492,7 @@ private: * @param id id of object * @return Object */ - const val *GetObject(const QHash &obj, key id) const; + const val GetObject(const QHash &obj, key id) const; template /** * @brief GetObject return object from container @@ -497,7 +508,7 @@ private: * @param id id of existing object * @param point object */ - void UpdateObject(QHash &obj, const qint64 &id, val* point); + void UpdateObject(QHash &obj, const qint64 &id, val point); template /** * @brief AddObject add object to container @@ -505,7 +516,7 @@ private: * @param value object * @return id of object in container */ - static qint64 AddObject(QHash &obj, val *value); + static qint64 AddObject(QHash &obj, val value); }; #endif // VCONTAINER_H diff --git a/src/geometry/varc.h b/src/geometry/varc.h index e412c0279..e1af9dda1 100644 --- a/src/geometry/varc.h +++ b/src/geometry/varc.h @@ -42,7 +42,8 @@ class QPainterPath; */ class VArc: public VGObject { - Q_DECLARE_TR_FUNCTIONS(VArc) + Q_OBJECT + //Q_DECLARE_TR_FUNCTIONS(VArc) public: /** * @brief VArc конструктор по замовчуванню. @@ -144,6 +145,7 @@ public: * @return */ QVector SplOfArc( qint32 number ) const; + virtual QString name() const{return _name;} private: /** * @brief f1 початковий кут в градусах diff --git a/src/geometry/vdetail.cpp b/src/geometry/vdetail.cpp index 15dfe150d..86b3129bd 100644 --- a/src/geometry/vdetail.cpp +++ b/src/geometry/vdetail.cpp @@ -29,20 +29,23 @@ #include "vdetail.h" VDetail::VDetail() - :_id(0), nodes(QVector()), name(QString()), mx(0), my(0), supplement(true), closed(true), width(10){} + :QObject(), _id(0), nodes(QVector()), name(QString()), mx(0), my(0), supplement(true), closed(true), + width(10){} VDetail::VDetail(const QString &name, const QVector &nodes) - :_id(0), nodes(QVector()), name(name), mx(0), my(0), supplement(true), closed(true), width(10) + :QObject(), _id(0), nodes(QVector()), name(name), mx(0), my(0), supplement(true), closed(true), + width(10) { this->nodes = nodes; } VDetail::VDetail(const VDetail &detail) - :_id(0), nodes(detail.getNodes()), name(detail.getName()), mx(detail.getMx()), my(detail.getMy()), + :QObject(), _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(); diff --git a/src/geometry/vdetail.h b/src/geometry/vdetail.h index ffb362f1f..239a2ce6e 100644 --- a/src/geometry/vdetail.h +++ b/src/geometry/vdetail.h @@ -54,8 +54,9 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Detail::Equidistants) /** * @brief The VDetail class */ -class VDetail +class VDetail: public QObject { + Q_OBJECT public: /** * @brief VDetail diff --git a/src/geometry/vgobject.cpp b/src/geometry/vgobject.cpp index 94d025598..ddec0e5f0 100644 --- a/src/geometry/vgobject.cpp +++ b/src/geometry/vgobject.cpp @@ -29,17 +29,17 @@ #include "vgobject.h" VGObject::VGObject() - :_id(0), type(GObject::Point), idObject(0), _name(QString()), mode(Draw::Calculation) + :QObject(), _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) + :QObject(), _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()) + :QObject(), _id(obj.id()), type(obj.getType()), idObject(obj.getIdObject()), _name(obj.name()), mode(obj.getMode()) { } diff --git a/src/geometry/vgobject.h b/src/geometry/vgobject.h index 6c9f5b24a..b71a5496b 100644 --- a/src/geometry/vgobject.h +++ b/src/geometry/vgobject.h @@ -45,9 +45,9 @@ namespace GObject } Q_DECLARE_OPERATORS_FOR_FLAGS(GObject::Types) -class VGObject +class VGObject :public QObject { - Q_DECLARE_TR_FUNCTIONS(VGObject) + Q_OBJECT public: VGObject(); VGObject(const GObject::Type &type, const qint64 &idObject = 0, const Draw::Draws &mode = Draw::Calculation); @@ -61,8 +61,8 @@ public: Draw::Draws getMode() const; void setMode(const Draw::Draws &value); GObject::Type getType() const; - qint64 id() const; - void setId(const qint64 &id); + qint64 id() const; + void setId(const qint64 &id); protected: /** * @brief _id id in container. Ned for arcs, spline and spline paths. diff --git a/src/geometry/vpointf.h b/src/geometry/vpointf.h index 86e91d629..ffa62b7be 100644 --- a/src/geometry/vpointf.h +++ b/src/geometry/vpointf.h @@ -39,6 +39,7 @@ */ class VPointF:public VGObject { + Q_OBJECT public: /** * @brief VPointF creat empty point @@ -114,6 +115,7 @@ public: * @param value y coordinate */ inline void setY(const qreal &value){_y = value;} + virtual QString name() const{return _name;} private: /** * @brief _mx offset name respect to x diff --git a/src/geometry/vspline.h b/src/geometry/vspline.h index 7575c370a..18db98a62 100644 --- a/src/geometry/vspline.h +++ b/src/geometry/vspline.h @@ -45,6 +45,7 @@ class QString; */ class VSpline :public VGObject { + Q_OBJECT public: /** * @brief VSpline default constructor diff --git a/src/geometry/vsplinepath.h b/src/geometry/vsplinepath.h index a50aeb5a8..bbd4b2792 100644 --- a/src/geometry/vsplinepath.h +++ b/src/geometry/vsplinepath.h @@ -51,7 +51,8 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( SplinePoint::Positions ) */ class VSplinePath :public VGObject { - Q_DECLARE_TR_FUNCTIONS(VSplinePath) + Q_OBJECT + //Q_DECLARE_TR_FUNCTIONS(VSplinePath) public: /** * @brief VSplinePath конструктор по замовчуванню. @@ -160,6 +161,7 @@ public: */ QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; + virtual QString name() const{return _name;} protected: /** * @brief path вектор з точок сплайна. diff --git a/src/tools/drawTools/vtoolcutspline.cpp b/src/tools/drawTools/vtoolcutspline.cpp index 7e3bd24dc..cf2927c93 100644 --- a/src/tools/drawTools/vtoolcutspline.cpp +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -104,8 +104,6 @@ void VToolCutSpline::Create(const qint64 _id, const QString &pointName, VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my); Q_ASSERT(p != 0); id = data->AddGObject(p); - spl1id = id + 1; - spl2id = id + 2; VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve()); Q_ASSERT(spline1); diff --git a/src/tools/drawTools/vtoolsinglepoint.cpp b/src/tools/drawTools/vtoolsinglepoint.cpp index f40c0ef71..cc2d15f13 100644 --- a/src/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/tools/drawTools/vtoolsinglepoint.cpp @@ -130,7 +130,8 @@ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event void VToolSinglePoint::FullUpdateFromFile() { - RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); + VPointF point = *VAbstractTool::data.GeometricObject(id); + RefreshPointGeometry(point); } void VToolSinglePoint::FullUpdateFromGui(int result) @@ -169,5 +170,5 @@ void VToolSinglePoint::ChangedActivDraw(const QString &newName) void VToolSinglePoint::SetFactor(qreal factor) { VDrawTool::SetFactor(factor); - RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); + RefreshPointGeometry(*(VAbstractTool::data.GeometricObject(id))); } diff --git a/src/tools/drawTools/vtoolsplinepath.cpp b/src/tools/drawTools/vtoolsplinepath.cpp index 9b7373240..3c2d4f003 100644 --- a/src/tools/drawTools/vtoolsplinepath.cpp +++ b/src/tools/drawTools/vtoolsplinepath.cpp @@ -171,7 +171,7 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons const QPointF &pos) { VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); - VSpline spl; + VSpline spl = splPath.GetSpline(indexSpline); if (position == SplinePoint::FirstPoint) { spl = VSpline(spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve()); diff --git a/src/tools/vdatatool.h b/src/tools/vdatatool.h index a7b0cfcf5..0b7a30070 100644 --- a/src/tools/vdatatool.h +++ b/src/tools/vdatatool.h @@ -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 472ee1098..38d0c8f70 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -100,6 +100,7 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen { VPointF *point = new VPointF(*data->GeometricObject(detail[i].getId())); Q_ASSERT(point != 0); + point->setMode(Draw::Modeling); id = data->AddGObject(point); VNodePoint::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); } @@ -108,6 +109,7 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen { VArc *arc = new VArc(*data->GeometricObject(detail[i].getId())); Q_ASSERT(arc != 0); + arc->setMode(Draw::Modeling); id = data->AddGObject(arc); VNodeArc::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); } @@ -116,6 +118,7 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen { VSpline *spline = new VSpline(*data->GeometricObject(detail[i].getId())); Q_ASSERT(spline != 0); + spline->setMode(Draw::Modeling); id = data->AddGObject(spline); VNodeSpline::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); } @@ -124,6 +127,7 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen { VSplinePath *splinePath = new VSplinePath(*data->GeometricObject(detail[i].getId())); Q_ASSERT(splinePath != 0); + splinePath->setMode(Draw::Modeling); id = data->AddGObject(splinePath); VNodeSplinePath::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); } diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index b8287798c..57a7f45ab 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -461,6 +461,8 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri qreal param = parametr.replace(",", ".").toDouble(&ok); if (ok == false) { + qDebug()<<"defValue"< Date: Mon, 30 Dec 2013 20:59:33 +0200 Subject: [PATCH 09/15] Fix memory leak. --HG-- branch : feature --- src/container/vcontainer.cpp | 267 ++++++++++++++-------------- src/container/vcontainer.h | 40 ++--- src/container/vstandarttablerow.cpp | 3 +- src/container/vstandarttablerow.h | 4 +- src/dialogs/dialogincrements.cpp | 41 +++-- src/dialogs/dialogtool.cpp | 8 +- src/dialogs/dialoguniondetails.cpp | 4 +- src/geometry/vdetail.h | 2 +- src/mainwindow.cpp | 7 +- src/tablewindow.cpp | 47 ++--- src/tablewindow.h | 2 +- src/tools/vabstracttool.cpp | 1 + src/tools/vdatatool.cpp | 9 +- src/tools/vdatatool.h | 2 +- src/tools/vtooldetail.cpp | 49 +++-- src/tools/vtooldetail.h | 6 +- src/tools/vtooluniondetails.cpp | 13 +- src/tools/vtooluniondetails.h | 2 +- src/xml/vdomdocument.cpp | 25 +-- 19 files changed, 275 insertions(+), 257 deletions(-) diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 02f22013d..44a8d4395 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -35,9 +35,9 @@ qint64 VContainer::_id = 0; VContainer::VContainer() :base(QHash()), gObjects(QHash()), - standartTable(QHash()), incrementTable(QHash()), + standartTable(QHash()), incrementTable(QHash()), lengthLines(QHash()),lineAngles(QHash()), lengthSplines(QHash()), - lengthArcs(QHash()), details(QHash()) + lengthArcs(QHash()), details(QHash()) { SetSize(500); SetGrowth(1760); @@ -52,13 +52,19 @@ VContainer &VContainer::operator =(const VContainer &data) VContainer::VContainer(const VContainer &data) :base(QHash()), gObjects(QHash()), - standartTable(QHash()), incrementTable(QHash()), + standartTable(QHash()), incrementTable(QHash()), lengthLines(QHash()), lineAngles(QHash()), lengthSplines(QHash()), - lengthArcs(QHash()), details(QHash()) + lengthArcs(QHash()), details(QHash()) { setData(data); } +VContainer::~VContainer() +{ + qDeleteAll(gObjects); + gObjects.clear(); +} + void VContainer::setData(const VContainer &data) { base = *data.DataBase(); @@ -73,37 +79,36 @@ void VContainer::setData(const VContainer &data) i.next(); switch(i.value()->getType()) { - case(GObject::Arc): - { + case(GObject::Arc): + { VArc *arc = new VArc(*data.GeometricObject(i.key())); Q_ASSERT(arc != 0); - gObjects.insert(i.key(), arc); + UpdateGObject(i.key(), arc); break; - } - case(GObject::Point): - { + } + case(GObject::Point): + { VPointF *point = new VPointF(*data.GeometricObject(i.key())); Q_ASSERT(point != 0); - gObjects.insert(i.key(), point); + UpdateGObject(i.key(), point); break; - } - case(GObject::Spline): - { + } + case(GObject::Spline): + { VSpline *spl = new VSpline(*data.GeometricObject(i.key())); Q_ASSERT(spl != 0); - gObjects.insert(i.key(), spl); + UpdateGObject(i.key(), spl); break; - } - case(GObject::SplinePath): - { + } + case(GObject::SplinePath): + { VSplinePath *path = new VSplinePath(*data.GeometricObject(i.key())); Q_ASSERT(path != 0); - gObjects.insert(i.key(), path); + UpdateGObject(i.key(), path); break; - } + } } } - //gObjects = *data.DataGObjects(); standartTable = *data.DataStandartTable(); incrementTable = *data.DataIncrementTable(); lengthLines = *data.DataLengthLines(); @@ -144,16 +149,16 @@ val VContainer::GetVariable(const QHash &obj, key id) const } } -const VStandartTableRow *VContainer::GetStandartTableCell(const QString &name) const +const VStandartTableRow VContainer::GetStandartTableCell(const QString &name) const { Q_ASSERT(name.isEmpty()==false); - return GetObject(standartTable, name); + return GetVariable(standartTable, name); } -const VIncrementTableRow *VContainer::GetIncrementTableRow(const QString& name) const +const VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const { Q_ASSERT(name.isEmpty()==false); - return GetObject(incrementTable, name); + return GetVariable(incrementTable, name); } qreal VContainer::GetLine(const QString &name) const @@ -180,9 +185,9 @@ qreal VContainer::GetLineAngle(const QString &name) const return GetVariable(lineAngles, name); } -const VDetail *VContainer::GetDetail(qint64 id) const +const VDetail VContainer::GetDetail(qint64 id) const { - return GetObject(details, id); + return GetVariable(details, id); } qint64 VContainer::AddGObject(VGObject *obj) @@ -190,9 +195,16 @@ qint64 VContainer::AddGObject(VGObject *obj) return AddObject(gObjects, obj); } -qint64 VContainer::AddDetail(VDetail *detail) +qint64 VContainer::AddDetail(VDetail detail) { - return AddObject(details, detail); + qint64 id = getNextId(); + details[id] = detail; + return id; +} + +void VContainer::AddIncrementTableRow(const QString &name, VIncrementTableRow row) +{ + incrementTable[name] = row; } qint64 VContainer::getNextId() @@ -211,100 +223,100 @@ void VContainer::UpdateId(qint64 newId) QPainterPath VContainer::ContourPath(qint64 idDetail) const { - const VDetail *detail = GetDetail(idDetail); + VDetail detail = GetDetail(idDetail); QVector points; QVector pointsEkv; - for (ptrdiff_t i = 0; i< detail->CountNode(); ++i) + for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) { - switch (detail->at(i).getTypeTool()) + switch (detail.at(i).getTypeTool()) { case (Tool::NodePoint): { - const VPointF *point = GeometricObject(detail->at(i).getId()); + const VPointF *point = GeometricObject(detail.at(i).getId()); points.append(point->toQPointF()); - if (detail->getSupplement() == true) + if (detail.getSupplement() == true) { QPointF pEkv = point->toQPointF(); - pEkv.setX(pEkv.x()+detail->at(i).getMx()); - pEkv.setY(pEkv.y()+detail->at(i).getMy()); + pEkv.setX(pEkv.x()+detail.at(i).getMx()); + pEkv.setY(pEkv.y()+detail.at(i).getMy()); pointsEkv.append(pEkv); } } break; case (Tool::NodeArc): { - const VArc *arc = GeometricObject(detail->at(i).getId()); + 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(); - if (detail->getSupplement() == true) + if (detail.getSupplement() == true) { - pointsEkv << biasPoints(arc->GetPoints(), detail->at(i).getMx(), detail->at(i).getMy()); + pointsEkv << biasPoints(arc->GetPoints(), detail.at(i).getMx(), detail.at(i).getMy()); } } else { points << GetReversePoint(arc->GetPoints()); - if (detail->getSupplement() == true) + if (detail.getSupplement() == true) { - pointsEkv << biasPoints(GetReversePoint(arc->GetPoints()), detail->at(i).getMx(), - detail->at(i).getMy()); + pointsEkv << biasPoints(GetReversePoint(arc->GetPoints()), detail.at(i).getMx(), + detail.at(i).getMy()); } } } break; case (Tool::NodeSpline): { - const VSpline *spline = GeometricObject(detail->at(i).getId()); + 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(); - if (detail->getSupplement() == true) + if (detail.getSupplement() == true) { - pointsEkv << biasPoints(spline->GetPoints(), detail->at(i).getMx(), detail->at(i).getMy()); + pointsEkv << biasPoints(spline->GetPoints(), detail.at(i).getMx(), detail.at(i).getMy()); } } else { points << GetReversePoint(spline->GetPoints()); - if (detail->getSupplement() == true) + if (detail.getSupplement() == true) { - pointsEkv << biasPoints(GetReversePoint(spline->GetPoints()), detail->at(i).getMx(), - detail->at(i).getMy()); + pointsEkv << biasPoints(GetReversePoint(spline->GetPoints()), detail.at(i).getMx(), + detail.at(i).getMy()); } } } break; case (Tool::NodeSplinePath): { - const VSplinePath *splinePath = GeometricObject(detail->at(i).getId()); + 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(); - if (detail->getSupplement() == true) + if (detail.getSupplement() == true) { - pointsEkv << biasPoints(splinePath->GetPathPoints(), detail->at(i).getMx(), detail->at(i).getMy()); + pointsEkv << biasPoints(splinePath->GetPathPoints(), detail.at(i).getMx(), detail.at(i).getMy()); } } else { points << GetReversePoint(splinePath->GetPathPoints()); - if (detail->getSupplement() == true) + if (detail.getSupplement() == true) { - pointsEkv << biasPoints(GetReversePoint(splinePath->GetPathPoints()), detail->at(i).getMx(), - detail->at(i).getMy()); + pointsEkv << biasPoints(GetReversePoint(splinePath->GetPathPoints()), detail.at(i).getMx(), + detail.at(i).getMy()); } } } break; default: - qWarning()<<"Get wrong tool type. Ignore."<at(i).getTypeTool(); + qWarning()<<"Get wrong tool type. Ignore."<getSupplement() == true) + if (detail.getSupplement() == true) { QPainterPath ekv; - if (detail->getClosed() == true) + if (detail.getClosed() == true) { - ekv = Equidistant(pointsEkv, Detail::CloseEquidistant, toPixel(detail->getWidth())); + ekv = Equidistant(pointsEkv, Detail::CloseEquidistant, toPixel(detail.getWidth())); } else { - ekv = Equidistant(pointsEkv, Detail::OpenEquidistant, toPixel(detail->getWidth())); + ekv = Equidistant(pointsEkv, Detail::OpenEquidistant, toPixel(detail.getWidth())); } path.addPath(ekv); path.setFillRule(Qt::WindingFill); @@ -541,7 +553,7 @@ QVector VContainer::CheckLoops(const QVector &points) const void VContainer::PrepareDetails(QVector &list) const { - QHashIterator idetail(details); + QHashIterator idetail(details); while (idetail.hasNext()) { idetail.next(); @@ -589,41 +601,32 @@ void VContainer::AddLineAngle(const QString &name, const qreal &value) qreal VContainer::GetValueStandartTableCell(const QString& name) const { - const VStandartTableRow *cell = GetStandartTableCell(name); + VStandartTableRow cell = GetStandartTableCell(name); qreal k_size = ( static_cast (size()/10.0) - 50.0 ) / 2.0; qreal k_growth = ( static_cast (growth()/10.0) - 176.0 ) / 6.0; - qreal value = cell->GetBase() + k_size*cell->GetKsize() + k_growth*cell->GetKgrowth(); + qreal value = cell.GetBase() + k_size*cell.GetKsize() + k_growth*cell.GetKgrowth(); return value; } qreal VContainer::GetValueIncrementTableRow(const QString& name) const { - const VIncrementTableRow *cell = GetIncrementTableRow(name); + VIncrementTableRow cell = GetIncrementTableRow(name); qreal k_size = ( static_cast (size()/10.0) - 50.0 ) / 2.0; qreal k_growth = ( static_cast (growth()/10.0) - 176.0 ) / 6.0; - qreal value = cell->getBase() + k_size*cell->getKsize() + k_growth*cell->getKgrowth(); + qreal value = cell.getBase() + k_size*cell.getKsize() + k_growth*cell.getKgrowth(); return value; } void VContainer::Clear() { _id = 0; - if(standartTable.size()>0) - { - qDeleteAll(standartTable); - } standartTable.clear(); - if(incrementTable.size()>0) - { - qDeleteAll(incrementTable); - } incrementTable.clear(); lengthLines.clear(); lengthArcs.clear(); lineAngles.clear(); details.clear(); ClearObject(); - CreateManTableIGroup (); } void VContainer::ClearObject() @@ -718,9 +721,11 @@ void VContainer::UpdateGObject(qint64 id, VGObject* obj) UpdateObject(gObjects, id, obj); } -void VContainer::UpdateDetail(qint64 id,VDetail *detail) +void VContainer::UpdateDetail(qint64 id,VDetail detail) { - UpdateObject(details, id, detail); + Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); + details[id] = detail; + UpdateId(id); } void VContainer::AddLengthLine(const QString &name, const qreal &value) @@ -731,60 +736,64 @@ void VContainer::AddLengthLine(const QString &name, const qreal &value) void VContainer::CreateManTableIGroup () { - AddStandartTableCell("Pkor", new VStandartTableRow(84, 0, 3)); - AddStandartTableCell("Pkor", new VStandartTableRow(84, 0, 3)); - AddStandartTableCell("Vtos", new VStandartTableRow(1450, 2, 51)); - AddStandartTableCell("Vtosh", new VStandartTableRow(1506, 2, 54)); - AddStandartTableCell("Vpt", new VStandartTableRow(1438, 3, 52)); - AddStandartTableCell("Vst", new VStandartTableRow(1257, -1, 49)); - AddStandartTableCell("Vlt", new VStandartTableRow(1102, 0, 43)); - AddStandartTableCell("Vk", new VStandartTableRow(503, 0, 22)); - AddStandartTableCell("Vsht", new VStandartTableRow(1522, 2, 54)); - AddStandartTableCell("Vzy", new VStandartTableRow(1328, 0, 49)); - AddStandartTableCell("Vlop", new VStandartTableRow(1320, 0, 49)); - AddStandartTableCell("Vps", new VStandartTableRow(811, -1, 36)); - AddStandartTableCell("Ssh", new VStandartTableRow(202, 4, 1)); - AddStandartTableCell("SgI", new VStandartTableRow(517, 18, 2)); - AddStandartTableCell("SgII", new VStandartTableRow(522, 19, 1)); - AddStandartTableCell("SgIII", new VStandartTableRow(500, 20, 0)); - AddStandartTableCell("St", new VStandartTableRow(390, 20, 0)); - AddStandartTableCell("Sb", new VStandartTableRow(492, 15, 5)); - AddStandartTableCell("SbI", new VStandartTableRow(482, 12, 6)); - AddStandartTableCell("Obed", new VStandartTableRow(566, 18, 6)); - AddStandartTableCell("Ok", new VStandartTableRow(386, 8, 8)); - AddStandartTableCell("Oi", new VStandartTableRow(380, 8, 6)); - AddStandartTableCell("Osch", new VStandartTableRow(234, 4, 4)); - AddStandartTableCell("Dsb", new VStandartTableRow(1120, 0, 44)); - AddStandartTableCell("Dsp", new VStandartTableRow(1110, 0, 43)); - AddStandartTableCell("Dn", new VStandartTableRow(826, -3, 37)); - AddStandartTableCell("Dps", new VStandartTableRow(316, 4, 7)); - AddStandartTableCell("Dpob", new VStandartTableRow(783, 14, 15)); - AddStandartTableCell("Ds", new VStandartTableRow(260, 1, 6)); - AddStandartTableCell("Op", new VStandartTableRow(316, 12, 0)); - AddStandartTableCell("Ozap", new VStandartTableRow(180, 4, 0)); - AddStandartTableCell("Pkis", new VStandartTableRow(250, 4, 0)); - AddStandartTableCell("SHp", new VStandartTableRow(160, 1, 4)); - AddStandartTableCell("Dlych", new VStandartTableRow(500, 2, 15)); - AddStandartTableCell("Dzap", new VStandartTableRow(768, 2, 24)); - AddStandartTableCell("DIIIp", new VStandartTableRow(970, 2, 29)); - AddStandartTableCell("Vprp", new VStandartTableRow(214, 3, 3)); - AddStandartTableCell("Vg", new VStandartTableRow(262, 8, 3)); - AddStandartTableCell("Dtp", new VStandartTableRow(460, 7, 9)); - AddStandartTableCell("Dp", new VStandartTableRow(355, 5, 5)); - AddStandartTableCell("Vprz", new VStandartTableRow(208, 3, 5)); - AddStandartTableCell("Dts", new VStandartTableRow(438, 2, 10)); - AddStandartTableCell("DtsI", new VStandartTableRow(469, 2, 10)); - AddStandartTableCell("Dvcht", new VStandartTableRow(929, 9, 19)); - AddStandartTableCell("SHg", new VStandartTableRow(370, 14, 4)); - AddStandartTableCell("Cg", new VStandartTableRow(224, 6, 0)); - AddStandartTableCell("SHs", new VStandartTableRow(416, 10, 2)); - AddStandartTableCell("dpzr", new VStandartTableRow(121, 6, 0)); - AddStandartTableCell("Ogol", new VStandartTableRow(576, 4, 4)); - AddStandartTableCell("Ssh1", new VStandartTableRow(205, 5, 0)); - AddStandartTableCell("St", new VStandartTableRow(410, 20, 0)); - AddStandartTableCell("Drzap", new VStandartTableRow(594, 3, 19)); - AddStandartTableCell("DbII", new VStandartTableRow(1020, 0, 44)); - AddStandartTableCell("Sb", new VStandartTableRow(504, 15, 4)); + AddStandartTableCell("Pkor", VStandartTableRow(84, 0, 3)); + AddStandartTableCell("Vtos", VStandartTableRow(1450, 2, 51)); + AddStandartTableCell("Vtosh", VStandartTableRow(1506, 2, 54)); + AddStandartTableCell("Vpt", VStandartTableRow(1438, 3, 52)); + AddStandartTableCell("Vst", VStandartTableRow(1257, -1, 49)); + AddStandartTableCell("Vlt", VStandartTableRow(1102, 0, 43)); + AddStandartTableCell("Vk", VStandartTableRow(503, 0, 22)); + AddStandartTableCell("Vsht", VStandartTableRow(1522, 2, 54)); + AddStandartTableCell("Vzy", VStandartTableRow(1328, 0, 49)); + AddStandartTableCell("Vlop", VStandartTableRow(1320, 0, 49)); + AddStandartTableCell("Vps", VStandartTableRow(811, -1, 36)); + AddStandartTableCell("Ssh", VStandartTableRow(202, 4, 1)); + AddStandartTableCell("SgI", VStandartTableRow(517, 18, 2)); + AddStandartTableCell("SgII", VStandartTableRow(522, 19, 1)); + AddStandartTableCell("SgIII", VStandartTableRow(500, 20, 0)); + AddStandartTableCell("SbI", VStandartTableRow(482, 12, 6)); + AddStandartTableCell("Obed", VStandartTableRow(566, 18, 6)); + AddStandartTableCell("Ok", VStandartTableRow(386, 8, 8)); + AddStandartTableCell("Oi", VStandartTableRow(380, 8, 6)); + AddStandartTableCell("Osch", VStandartTableRow(234, 4, 4)); + AddStandartTableCell("Dsb", VStandartTableRow(1120, 0, 44)); + AddStandartTableCell("Dsp", VStandartTableRow(1110, 0, 43)); + AddStandartTableCell("Dn", VStandartTableRow(826, -3, 37)); + AddStandartTableCell("Dps", VStandartTableRow(316, 4, 7)); + AddStandartTableCell("Dpob", VStandartTableRow(783, 14, 15)); + AddStandartTableCell("Ds", VStandartTableRow(260, 1, 6)); + AddStandartTableCell("Op", VStandartTableRow(316, 12, 0)); + AddStandartTableCell("Ozap", VStandartTableRow(180, 4, 0)); + AddStandartTableCell("Pkis", VStandartTableRow(250, 4, 0)); + AddStandartTableCell("SHp", VStandartTableRow(160, 1, 4)); + AddStandartTableCell("Dlych", VStandartTableRow(500, 2, 15)); + AddStandartTableCell("Dzap", VStandartTableRow(768, 2, 24)); + AddStandartTableCell("DIIIp", VStandartTableRow(970, 2, 29)); + AddStandartTableCell("Vprp", VStandartTableRow(214, 3, 3)); + AddStandartTableCell("Vg", VStandartTableRow(262, 8, 3)); + AddStandartTableCell("Dtp", VStandartTableRow(460, 7, 9)); + AddStandartTableCell("Dp", VStandartTableRow(355, 5, 5)); + AddStandartTableCell("Vprz", VStandartTableRow(208, 3, 5)); + AddStandartTableCell("Dts", VStandartTableRow(438, 2, 10)); + AddStandartTableCell("DtsI", VStandartTableRow(469, 2, 10)); + AddStandartTableCell("Dvcht", VStandartTableRow(929, 9, 19)); + AddStandartTableCell("SHg", VStandartTableRow(370, 14, 4)); + AddStandartTableCell("Cg", VStandartTableRow(224, 6, 0)); + AddStandartTableCell("SHs", VStandartTableRow(416, 10, 2)); + AddStandartTableCell("dpzr", VStandartTableRow(121, 6, 0)); + AddStandartTableCell("Ogol", VStandartTableRow(576, 4, 4)); + AddStandartTableCell("Ssh1", VStandartTableRow(205, 5, 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)); + + //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 14c86bed8..0511196be 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -60,6 +60,7 @@ public: * @param data container */ VContainer(const VContainer &data); + ~VContainer(); /** * @brief setData copy data from container * @param data container @@ -94,13 +95,13 @@ public: * @param name name of standart table row * @return row of standart table */ - const 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 */ - const 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 @@ -130,7 +131,7 @@ public: * @param id id of detail * @return detail */ - const VDetail *GetDetail(qint64 id) const; + const VDetail GetDetail(qint64 id) const; /** * @brief getId return current id * @return current id @@ -147,21 +148,20 @@ public: * @param detail new detail * @return return id of new detail in container */ - qint64 AddDetail(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, VStandartTableRow *cell) + inline void AddStandartTableCell(const QString& name, 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, 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 @@ -223,20 +223,20 @@ public: * @param id id of existing detail * @param detail detail */ - void UpdateDetail(qint64 id, VDetail *detail); + 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, 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, VIncrementTableRow *row) + inline void UpdateIncrementTableRow(const QString& name, VIncrementTableRow row) {incrementTable[name] = row;} /** * @brief GetValueStandartTableCell return value of standart table row by name @@ -335,12 +335,12 @@ public: * @brief data container with dataStandartTable return container of standart table * @return pointer on container of standart table */ - inline const QHash *DataStandartTable() const {return &standartTable;} + inline const QHash *DataStandartTable() const {return &standartTable;} /** * @brief data container with dataIncrementTable return container of increment table * @return pointer on container of increment table */ - inline const QHash *DataIncrementTable() const {return &incrementTable;} + inline const QHash *DataIncrementTable() const {return &incrementTable;} /** * @brief data container with dataLengthLines return container of lines lengths * @return pointer on container of lines lengths @@ -365,7 +365,7 @@ public: * @brief data container with dataDetails return container of details * @return pointer on container of details */ - inline const QHash *DataDetails() const {return &details;} + inline const QHash *DataDetails() const {return &details;} /** * @brief UpdateId update id. If new id bigger when current save new like current. * @param newId id @@ -427,6 +427,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. @@ -443,11 +447,11 @@ private: /** * @brief standartTable container of standart table rows */ - QHash standartTable; + QHash standartTable; /** * @brief incrementTable */ - QHash incrementTable; + QHash incrementTable; /** * @brief lengthLines container of lines lengths */ @@ -467,11 +471,7 @@ private: /** * @brief details container of details */ - QHash details; - /** - * @brief CreateManTableIGroup generate man standart table of measurements - */ - void CreateManTableIGroup (); + QHash details; /** * @brief GetReversePoint return revers container of points * @param points container with points 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/dialogincrements.cpp b/src/dialogs/dialogincrements.cpp index 25e5e26b7..dc357c9e1 100644 --- a/src/dialogs/dialogincrements.cpp +++ b/src/dialogs/dialogincrements.cpp @@ -69,14 +69,14 @@ DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget void DialogIncrements::FillStandartTable() { - const QHash *standartTable = data->DataStandartTable(); + const QHash *standartTable = data->DataStandartTable(); qint32 currentRow = -1; - QHashIterator i(*standartTable); + QHashIterator i(*standartTable); ui->tableWidgetStandart->setRowCount ( standartTable->size() ); while (i.hasNext()) { i.next(); - VStandartTableRow *cell = i.value(); + VStandartTableRow cell = i.value(); currentRow++; QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); @@ -88,19 +88,19 @@ void DialogIncrements::FillStandartTable() item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetStandart->setItem(currentRow, 1, item); - item = new QTableWidgetItem(QString().setNum(cell->GetBase())); + item = new QTableWidgetItem(QString().setNum(cell.GetBase())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetStandart->setItem(currentRow, 2, item); - item = new QTableWidgetItem(QString().setNum(cell->GetKsize())); + item = new QTableWidgetItem(QString().setNum(cell.GetKsize())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetStandart->setItem(currentRow, 3, item); - item = new QTableWidgetItem(QString().setNum(cell->GetKgrowth())); + item = new QTableWidgetItem(QString().setNum(cell.GetKgrowth())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetStandart->setItem(currentRow, 4, item); - item = new QTableWidgetItem(cell->GetDescription()); + item = new QTableWidgetItem(cell.GetDescription()); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetStandart->setItem(currentRow, 5, item); } @@ -111,15 +111,15 @@ void DialogIncrements::FillStandartTable() void DialogIncrements::FillIncrementTable() { - const QHash *incrementTable = data->DataIncrementTable(); - QHashIterator i(*incrementTable); + const QHash *incrementTable = data->DataIncrementTable(); + QHashIterator i(*incrementTable); QMap map; //Sorting QHash by id while (i.hasNext()) { i.next(); - VIncrementTableRow *cell = i.value(); - map.insert(cell->getId(), i.key()); + VIncrementTableRow cell = i.value(); + map.insert(cell.getId(), i.key()); } qint32 currentRow = -1; @@ -127,14 +127,14 @@ void DialogIncrements::FillIncrementTable() while (iMap.hasNext()) { iMap.next(); - VIncrementTableRow *cell = incrementTable->value(iMap.value()); + VIncrementTableRow cell = incrementTable->value(iMap.value()); currentRow++; ui->tableWidgetIncrement->setRowCount ( incrementTable->size() ); QTableWidgetItem *item = new QTableWidgetItem(iMap.value()); item->setTextAlignment(Qt::AlignHCenter); item->setFont(QFont("Times", 12, QFont::Bold)); - item->setData(Qt::UserRole, cell->getId()); + item->setData(Qt::UserRole, cell.getId()); ui->tableWidgetIncrement->setItem(currentRow, 0, item); item = new QTableWidgetItem(QString().setNum(data->GetValueIncrementTableRow(iMap.value()))); @@ -145,19 +145,19 @@ void DialogIncrements::FillIncrementTable() item->setFlags(flags); ui->tableWidgetIncrement->setItem(currentRow, 1, item); - item = new QTableWidgetItem(QString().setNum(cell->getBase())); + item = new QTableWidgetItem(QString().setNum(cell.getBase())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 2, item); - item = new QTableWidgetItem(QString().setNum(cell->getKsize())); + item = new QTableWidgetItem(QString().setNum(cell.getKsize())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 3, item); - item = new QTableWidgetItem(QString().setNum(cell->getKgrowth())); + item = new QTableWidgetItem(QString().setNum(cell.getKgrowth())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 4, item); - item = new QTableWidgetItem(cell->getDescription()); + item = new QTableWidgetItem(cell.getDescription()); item->setTextAlignment(Qt::AlignLeft); ui->tableWidgetIncrement->setItem(currentRow, 5, item); } @@ -325,7 +325,7 @@ void DialogIncrements::clickedToolButtonAdd() qreal ksize = 0; qreal kgrowth = 0; QString description = QString(tr("Description")); - VIncrementTableRow *incrementRow = new VIncrementTableRow(id, base, ksize, kgrowth, description); + VIncrementTableRow incrementRow = VIncrementTableRow(id, base, ksize, kgrowth, description); data->AddIncrementTableRow(name, incrementRow); AddIncrementToFile(id, name, base, ksize, kgrowth, description); @@ -499,9 +499,8 @@ void DialogIncrements::cellChanged ( qint32 row, qint32 column ) if (domElement.isElement()) { domElement.setAttribute("description", item->text()); - VIncrementTableRow *incr = new VIncrementTableRow(*data->GetIncrementTableRow(itemName->text())); - Q_ASSERT(incr != 0); - incr->setDescription(item->text()); + VIncrementTableRow incr = data->GetIncrementTableRow(itemName->text()); + incr.setDescription(item->text()); data->UpdateIncrementTableRow(itemName->text(), incr); ui->tableWidgetIncrement->resizeColumnsToContents(); ui->tableWidgetIncrement->resizeRowsToContents(); diff --git a/src/dialogs/dialogtool.cpp b/src/dialogs/dialogtool.cpp index a57ad6fb9..d37e59330 100644 --- a/src/dialogs/dialogtool.cpp +++ b/src/dialogs/dialogtool.cpp @@ -510,17 +510,17 @@ void DialogTool::ValChenged(int row) } if (radioButtonStandartTable->isChecked()) { - const VStandartTableRow *stable = data->GetStandartTableCell(item->text()); + VStandartTableRow stable = data->GetStandartTableCell(item->text()); QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandartTableCell(item->text())) - .arg(stable->GetDescription()); + .arg(stable.GetDescription()); labelDescription->setText(desc); return; } if (radioButtonIncrements->isChecked()) { - const VIncrementTableRow *itable = data->GetIncrementTableRow(item->text()); + VIncrementTableRow itable = data->GetIncrementTableRow(item->text()); QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueIncrementTableRow(item->text())) - .arg(itable->getDescription()); + .arg(itable.getDescription()); labelDescription->setText(desc); return; } diff --git a/src/dialogs/dialoguniondetails.cpp b/src/dialogs/dialoguniondetails.cpp index 58c269518..181551334 100644 --- a/src/dialogs/dialoguniondetails.cpp +++ b/src/dialogs/dialoguniondetails.cpp @@ -68,8 +68,8 @@ bool DialogUnionDetails::CheckObject(const qint64 &id, const qint64 &idDetail) c { return false; } - const VDetail *det = data->GetDetail(idDetail); - return det->Containes(id); + VDetail det = data->GetDetail(idDetail); + return det.Containes(id); } void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, qint64 &p1, diff --git a/src/geometry/vdetail.h b/src/geometry/vdetail.h index 239a2ce6e..b862e9e3d 100644 --- a/src/geometry/vdetail.h +++ b/src/geometry/vdetail.h @@ -54,7 +54,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Detail::Equidistants) /** * @brief The VDetail class */ -class VDetail: public QObject +class VDetail :public QObject { Q_OBJECT public: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2dbde633f..0b9497304 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1216,10 +1216,9 @@ MainWindow::~MainWindow() delete ui; delete pattern; - if (doc->isNull() == false) - { - delete doc; - } + delete doc; + delete sceneDetails; + delete sceneDraw; } void MainWindow::OpenPattern(const QString &fileName) diff --git a/src/tablewindow.cpp b/src/tablewindow.cpp index e804b3350..2b86180b1 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/vabstracttool.cpp b/src/tools/vabstracttool.cpp index 21a7b02af..a8f4b36e7 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); 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 0b7a30070..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 = diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 38d0c8f70..1a03395ad 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -44,7 +44,7 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialogDetail(QSharedPointer()), sceneDetails(scene) { - VDetail detail = VDetail(*data->GetDetail(id)); + VDetail detail = data->GetDetail(id); for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) { switch (detail[i].getTypeTool()) @@ -89,8 +89,7 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen VContainer *data) { VDetail detail = dialog->getDetails(); - VDetail *det = new VDetail(); - Q_ASSERT(det != 0); + VDetail det; for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) { qint64 id = 0; @@ -137,13 +136,13 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen break; } VNodeDetail node(id, detail[i].getTypeTool(), NodeDetail::Contour); - det->append(node); + det.append(node); } - det->setName(detail.getName()); + det.setName(detail.getName()); 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, VDetail newDetail, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) { qint64 id = _id; @@ -228,20 +227,20 @@ void VToolDetail::FullUpdateFromGui(int result) void VToolDetail::AddToFile() { - const VDetail *detail = VAbstractTool::data.GetDetail(id); + VDetail detail = VAbstractTool::data.GetDetail(id); QDomElement domElement = doc->createElement(TagName); AddAttribute(domElement, AttrId, id); - AddAttribute(domElement, AttrName, detail->getName()); - AddAttribute(domElement, AttrMx, toMM(detail->getMx())); - AddAttribute(domElement, AttrMy, toMM(detail->getMy())); - AddAttribute(domElement, AttrSupplement, detail->getSupplement()); - AddAttribute(domElement, AttrClosed, detail->getClosed()); - AddAttribute(domElement, AttrWidth, detail->getWidth()); + AddAttribute(domElement, AttrName, detail.getName()); + AddAttribute(domElement, AttrMx, toMM(detail.getMx())); + AddAttribute(domElement, AttrMy, toMM(detail.getMy())); + AddAttribute(domElement, AttrSupplement, detail.getSupplement()); + AddAttribute(domElement, AttrClosed, detail.getClosed()); + AddAttribute(domElement, AttrWidth, detail.getWidth()); - for (ptrdiff_t i = 0; i < detail->CountNode(); ++i) + for (ptrdiff_t i = 0; i < detail.CountNode(); ++i) { - AddNode(domElement, detail->at(i)); + AddNode(domElement, detail.at(i)); } QDomElement element; @@ -257,15 +256,15 @@ void VToolDetail::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - const VDetail *det = VAbstractTool::data.GetDetail(id); - domElement.setAttribute(AttrName, det->getName()); - domElement.setAttribute(AttrSupplement, QString().setNum(det->getSupplement())); - domElement.setAttribute(AttrClosed, QString().setNum(det->getClosed())); - domElement.setAttribute(AttrWidth, QString().setNum(det->getWidth())); + VDetail det = VAbstractTool::data.GetDetail(id); + domElement.setAttribute(AttrName, det.getName()); + domElement.setAttribute(AttrSupplement, QString().setNum(det.getSupplement())); + domElement.setAttribute(AttrClosed, QString().setNum(det.getClosed())); + domElement.setAttribute(AttrWidth, QString().setNum(det.getWidth())); RemoveAllChild(domElement); - for (ptrdiff_t i = 0; i < det->CountNode(); ++i) + for (ptrdiff_t i = 0; i < det.CountNode(); ++i) { - AddNode(domElement, det->at(i)); + AddNode(domElement, det.at(i)); } } } @@ -329,10 +328,10 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) void VToolDetail::RemoveReferens() { - const VDetail *detail = VAbstractTool::data.GetDetail(id); - for (ptrdiff_t i = 0; i< detail->CountNode(); ++i) + VDetail detail = VAbstractTool::data.GetDetail(id); + for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) { - doc->DecrementReferens(detail->at(i).getId()); + doc->DecrementReferens(detail.at(i).getId()); } } diff --git a/src/tools/vtooldetail.h b/src/tools/vtooldetail.h index b7ff3209b..34291b0a7 100644 --- a/src/tools/vtooldetail.h +++ b/src/tools/vtooldetail.h @@ -75,7 +75,7 @@ public: * @param parse * @param typeCreation */ - static void Create(const qint64 _id, VDetail *newDetail, VMainGraphicsScene *scene, + static void Create(const qint64 _id, VDetail newDetail, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation); template @@ -90,8 +90,8 @@ public: tool->setParentItem(this); connect(tool, &T::ChoosedTool, sceneDetails, &VMainGraphicsScene::ChoosedItem); VNodeDetail node(id, typeTool, Draw::Modeling, NodeDetail::Modeling); - VDetail *det = VAbstractTool::data.GetDetail(this->id); - det->append(node); + VDetail det = VAbstractTool::data.GetDetail(this->id); + det.append(node); VAbstractTool::data.UpdateDetail(this->id, det); QDomElement domElement = doc->elementById(QString().setNum(this->id)); if (domElement.isElement()) diff --git a/src/tools/vtooluniondetails.cpp b/src/tools/vtooluniondetails.cpp index 89411a107..dbd97c297 100644 --- a/src/tools/vtooluniondetails.cpp +++ b/src/tools/vtooluniondetails.cpp @@ -97,7 +97,7 @@ void VToolUnionDetails::CorectPoints(const VDetail &detail, qint64 &p1, qint64 & } } -void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail *newDetail, const VDetail &det, const ptrdiff_t &a, +void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, const VDetail &det, const ptrdiff_t &a, const ptrdiff_t &b, const qreal &dx, const qreal &dy, const qint64 &pRotate, const qreal &angle) const { @@ -237,7 +237,7 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail *newDetail, con qWarning()<<"May be wrong tool type!!! Ignoring."<append(VNodeDetail(id, det.at(i).getTypeTool(), NodeDetail::Contour)); + newDetail.append(VNodeDetail(id, det.at(i).getTypeTool(), NodeDetail::Contour)); } } @@ -395,8 +395,8 @@ void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const q void VToolUnionDetails::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data) { - VDetail d1 = VDetail(*data->GetDetail(dialog->getD1())); - VDetail d2 = VDetail(*data->GetDetail(dialog->getD2())); + VDetail d1 = data->GetDetail(dialog->getD1()); + VDetail d2 = data->GetDetail(dialog->getD2()); qint64 d1P1 = dialog->getD1P1(); qint64 d1P2 = dialog->getD1P2(); qint64 d2P1 = dialog->getD2P1(); @@ -447,8 +447,7 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai qint64 d2P1 = unionDetails->getD2P1(); qint64 d2P2 = unionDetails->getD2P2(); - VDetail *newDetail = new VDetail(); - Q_ASSERT(newDetail != 0); + VDetail newDetail; unionDetails->AddToNewDetail(data, newDetail, d1, d1.indexOfNode(d1P1), d1.indexOfNode(d1P2)); const VNodeDetail det1p2 = d1.at(d1.indexOfNode(d1P2)); @@ -468,7 +467,7 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai unionDetails->AddToNewDetail(data, newDetail, d2, d2.indexOfNode(d2P1)+1, d2.indexOfNode(d2P2)-1, dx, dy, d1P2, angle); - newDetail->setName("Detail"); + newDetail.setName("Detail"); VToolDetail::Create(0, newDetail, scene, doc, data, parse, Tool::FromTool); QHash* tools = doc->getTools(); VToolDetail *toolDet = qobject_cast(tools->value(d1id)); diff --git a/src/tools/vtooluniondetails.h b/src/tools/vtooluniondetails.h index 52404d83e..b06c7473d 100644 --- a/src/tools/vtooluniondetails.h +++ b/src/tools/vtooluniondetails.h @@ -83,7 +83,7 @@ public: inline qint64 getD1P2() const{return d1P2;} inline qint64 getD2P1() const{return d2P1;} inline qint64 getD2P2() const{return d2P2;} - void AddToNewDetail(VContainer *data, VDetail *newDetail, const VDetail &det, const ptrdiff_t &a, + void AddToNewDetail(VContainer *data, VDetail newDetail, const VDetail &det, const ptrdiff_t &a, const ptrdiff_t &b, const qreal &dx = 0, const qreal &dy = 0, const qint64 &pRotate = 0, const qreal &angle = 0) const; void UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &a, diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index 57a7f45ab..f5fb29fc1 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -321,6 +321,7 @@ void VDomDocument::Parse(const Document::Documents &parse, VMainGraphicsScene *s { TestUniqueId(); data->Clear(); + data->CreateManTableIGroup(); nameActivDraw.clear(); sceneDraw->clear(); sceneDetail->clear(); @@ -405,7 +406,7 @@ void VDomDocument::ParseIncrementsElement(const QDomNode &node) qreal kgrowth = GetParametrDouble(domElement, "kgrowth", "0"); QString desc = GetParametrString(domElement, "description", "Description"); data->UpdateId(id); - data->AddIncrementTableRow(name, new VIncrementTableRow(id, base, ksize, kgrowth, desc)); + data->AddIncrementTableRow(name, VIncrementTableRow(id, base, ksize, kgrowth, desc)); } } } @@ -583,16 +584,15 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); try { - VDetail *detail = new VDetail(); - Q_ASSERT(detail != 0); + VDetail detail; VDetail oldDetail; qint64 id = GetParametrId(domElement); - 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")); + 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(); @@ -633,7 +633,7 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo // VSplinePath splPath = data->GetSplinePath(id); // oldDetail.append(VNodeDetail(splPath.getIdObject(), tool, NodeDetail::Contour)); } - detail->append(VNodeDetail(id, tool, nodeType, mx, my)); + detail.append(VNodeDetail(id, tool, nodeType, mx, my)); } } } @@ -678,6 +678,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of point is empty"); if (type == VToolSinglePoint::ToolType) { + VToolSinglePoint *spoint = 0; try { qint64 id = GetParametrId(domElement); @@ -695,7 +696,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); @@ -708,6 +709,8 @@ 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; } } From 6669a0a15ae297652b31b761417eae405ea35d1c Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 30 Dec 2013 21:33:30 +0200 Subject: [PATCH 10/15] dynamic_cast instead qobject_cast. --HG-- branch : feature --- src/container/vcontainer.h | 4 ++-- src/geometry/varc.h | 3 +-- src/geometry/vdetail.cpp | 6 +++--- src/geometry/vdetail.h | 3 +-- src/geometry/vgobject.cpp | 6 +++--- src/geometry/vgobject.h | 3 +-- src/geometry/vpointf.h | 1 - src/geometry/vspline.h | 1 - src/geometry/vsplinepath.h | 3 +-- 9 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index 0511196be..da8e1b40d 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -78,8 +78,8 @@ public: { throw VExceptionBadId(tr("Can't find object"), id); } - //T obj = dynamic_cast(gObj); - T obj = qobject_cast(gObj); + T obj = dynamic_cast(gObj); + //T obj = qobject_cast(gObj); Q_ASSERT(obj != 0); return obj; } diff --git a/src/geometry/varc.h b/src/geometry/varc.h index e1af9dda1..379360356 100644 --- a/src/geometry/varc.h +++ b/src/geometry/varc.h @@ -42,8 +42,7 @@ class QPainterPath; */ class VArc: public VGObject { - Q_OBJECT - //Q_DECLARE_TR_FUNCTIONS(VArc) + Q_DECLARE_TR_FUNCTIONS(VArc) public: /** * @brief VArc конструктор по замовчуванню. diff --git a/src/geometry/vdetail.cpp b/src/geometry/vdetail.cpp index 86b3129bd..8244be9be 100644 --- a/src/geometry/vdetail.cpp +++ b/src/geometry/vdetail.cpp @@ -29,18 +29,18 @@ #include "vdetail.h" VDetail::VDetail() - :QObject(), _id(0), nodes(QVector()), name(QString()), mx(0), my(0), supplement(true), closed(true), + :_id(0), nodes(QVector()), name(QString()), mx(0), my(0), supplement(true), closed(true), width(10){} VDetail::VDetail(const QString &name, const QVector &nodes) - :QObject(), _id(0), nodes(QVector()), name(name), mx(0), my(0), supplement(true), closed(true), + :_id(0), nodes(QVector()), name(name), mx(0), my(0), supplement(true), closed(true), width(10) { this->nodes = nodes; } VDetail::VDetail(const VDetail &detail) - :QObject(), _id(0), 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) diff --git a/src/geometry/vdetail.h b/src/geometry/vdetail.h index b862e9e3d..ffb362f1f 100644 --- a/src/geometry/vdetail.h +++ b/src/geometry/vdetail.h @@ -54,9 +54,8 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Detail::Equidistants) /** * @brief The VDetail class */ -class VDetail :public QObject +class VDetail { - Q_OBJECT public: /** * @brief VDetail diff --git a/src/geometry/vgobject.cpp b/src/geometry/vgobject.cpp index ddec0e5f0..94d025598 100644 --- a/src/geometry/vgobject.cpp +++ b/src/geometry/vgobject.cpp @@ -29,17 +29,17 @@ #include "vgobject.h" VGObject::VGObject() - :QObject(), _id(0), type(GObject::Point), idObject(0), _name(QString()), mode(Draw::Calculation) + :_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) - :QObject(), _id(0), type(type), idObject(idObject), _name(QString()), mode(mode) + :_id(0), type(type), idObject(idObject), _name(QString()), mode(mode) { } VGObject::VGObject(const VGObject &obj) - :QObject(), _id(obj.id()), type(obj.getType()), idObject(obj.getIdObject()), _name(obj.name()), mode(obj.getMode()) + :_id(obj.id()), type(obj.getType()), idObject(obj.getIdObject()), _name(obj.name()), mode(obj.getMode()) { } diff --git a/src/geometry/vgobject.h b/src/geometry/vgobject.h index b71a5496b..eb904c072 100644 --- a/src/geometry/vgobject.h +++ b/src/geometry/vgobject.h @@ -45,9 +45,8 @@ namespace GObject } Q_DECLARE_OPERATORS_FOR_FLAGS(GObject::Types) -class VGObject :public QObject +class VGObject { - Q_OBJECT public: VGObject(); VGObject(const GObject::Type &type, const qint64 &idObject = 0, const Draw::Draws &mode = Draw::Calculation); diff --git a/src/geometry/vpointf.h b/src/geometry/vpointf.h index ffa62b7be..63da46ba7 100644 --- a/src/geometry/vpointf.h +++ b/src/geometry/vpointf.h @@ -39,7 +39,6 @@ */ class VPointF:public VGObject { - Q_OBJECT public: /** * @brief VPointF creat empty point diff --git a/src/geometry/vspline.h b/src/geometry/vspline.h index 18db98a62..7575c370a 100644 --- a/src/geometry/vspline.h +++ b/src/geometry/vspline.h @@ -45,7 +45,6 @@ class QString; */ class VSpline :public VGObject { - Q_OBJECT public: /** * @brief VSpline default constructor diff --git a/src/geometry/vsplinepath.h b/src/geometry/vsplinepath.h index bbd4b2792..d5bc1af2c 100644 --- a/src/geometry/vsplinepath.h +++ b/src/geometry/vsplinepath.h @@ -51,8 +51,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( SplinePoint::Positions ) */ class VSplinePath :public VGObject { - Q_OBJECT - //Q_DECLARE_TR_FUNCTIONS(VSplinePath) + Q_DECLARE_TR_FUNCTIONS(VSplinePath) public: /** * @brief VSplinePath конструктор по замовчуванню. From a9dfc45f99d1daadba5f4e2032cf576d62b8faa5 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 31 Dec 2013 10:08:14 +0200 Subject: [PATCH 11/15] Template CopyGObject. --HG-- branch : feature --- src/container/vcontainer.cpp | 18 ++++++------------ src/container/vcontainer.h | 8 +++++++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 44a8d4395..937d586e6 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -81,32 +81,26 @@ void VContainer::setData(const VContainer &data) { case(GObject::Arc): { - VArc *arc = new VArc(*data.GeometricObject(i.key())); - Q_ASSERT(arc != 0); - UpdateGObject(i.key(), arc); + CopyGObject(data, i.key()); break; } case(GObject::Point): { - VPointF *point = new VPointF(*data.GeometricObject(i.key())); - Q_ASSERT(point != 0); - UpdateGObject(i.key(), point); + CopyGObject(data, i.key()); break; } case(GObject::Spline): { - VSpline *spl = new VSpline(*data.GeometricObject(i.key())); - Q_ASSERT(spl != 0); - UpdateGObject(i.key(), spl); + CopyGObject(data, i.key()); break; } case(GObject::SplinePath): { - VSplinePath *path = new VSplinePath(*data.GeometricObject(i.key())); - Q_ASSERT(path != 0); - UpdateGObject(i.key(), path); + CopyGObject(data, i.key()); break; } + default: + qWarning()<<"Don't know how copy this type."; } } standartTable = *data.DataStandartTable(); diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index da8e1b40d..49a1bfb58 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -61,6 +61,13 @@ public: */ 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 @@ -79,7 +86,6 @@ public: throw VExceptionBadId(tr("Can't find object"), id); } T obj = dynamic_cast(gObj); - //T obj = qobject_cast(gObj); Q_ASSERT(obj != 0); return obj; } From 8e82a80463c8b17f5e3010f1ec630205220ca7eb Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 31 Dec 2013 10:28:53 +0200 Subject: [PATCH 12/15] Template CreateNode. --HG-- branch : feature --- src/tools/vtooldetail.cpp | 20 ++++---------------- src/tools/vtooldetail.h | 9 +++++++++ src/xml/vdomdocument.h | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 1a03395ad..0703cff28 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -97,37 +97,25 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen { case (Tool::NodePoint): { - VPointF *point = new VPointF(*data->GeometricObject(detail[i].getId())); - Q_ASSERT(point != 0); - point->setMode(Draw::Modeling); - id = data->AddGObject(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 = new VArc(*data->GeometricObject(detail[i].getId())); - Q_ASSERT(arc != 0); - arc->setMode(Draw::Modeling); - id = data->AddGObject(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 = new VSpline(*data->GeometricObject(detail[i].getId())); - Q_ASSERT(spline != 0); - spline->setMode(Draw::Modeling); - id = data->AddGObject(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 = new VSplinePath(*data->GeometricObject(detail[i].getId())); - Q_ASSERT(splinePath != 0); - splinePath->setMode(Draw::Modeling); - id = data->AddGObject(splinePath); + id = CreateNode(data, detail[i].getId()); VNodeSplinePath::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); } break; diff --git a/src/tools/vtooldetail.h b/src/tools/vtooldetail.h index 34291b0a7..5b9891af1 100644 --- a/src/tools/vtooldetail.h +++ b/src/tools/vtooldetail.h @@ -56,6 +56,15 @@ public: * @brief setDialog */ virtual void setDialog(); + template + static qint64 CreateNode(VContainer *data, const qint64 &id) + { + T *node = new T(*data->GeometricObject(id)); + Q_ASSERT(node != 0); + node->setMode(Draw::Modeling); + return data->AddGObject(node); + } + /** * @brief Create * @param dialog diff --git a/src/xml/vdomdocument.h b/src/xml/vdomdocument.h index 33c6179fe..8b69b8ad3 100644 --- a/src/xml/vdomdocument.h +++ b/src/xml/vdomdocument.h @@ -234,7 +234,7 @@ signals: * @param oldName * @param newName */ - void ChangedNameDraw(const QString oldName, const QString newName); + void ChangedNameDraw(const QString &oldName, const QString &newName); /** * @brief FullUpdateFromFile */ From 3b1a654581f41d7dd1157edfffa874cc767ecfc9 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 31 Dec 2013 10:44:54 +0200 Subject: [PATCH 13/15] Fixed vera++ warnings. --HG-- branch : feature --- src/container/vcontainer.cpp | 18 +++--- src/dialogs/dialogcutspline.h | 5 +- src/dialogs/dialogcutsplinepath.h | 5 +- src/dialogs/dialognormal.h | 2 +- src/dialogs/dialogpointofintersection.h | 2 +- src/dialogs/dialogtool.cpp | 14 ++--- src/dialogs/dialogtriangle.h | 2 +- src/dialogs/dialoguniondetails.cpp | 6 +- src/dialogs/dialoguniondetails.h | 9 +-- src/geometry/varc.cpp | 4 +- src/geometry/varc.h | 2 +- src/geometry/vdetail.cpp | 1 - src/geometry/vspline.cpp | 11 ++-- src/geometry/vsplinepath.cpp | 6 +- src/mainwindow.cpp | 2 +- src/tools/drawTools/vtoolcutspline.cpp | 2 +- src/tools/drawTools/vtoolcutsplinepath.cpp | 26 ++++---- src/tools/vtooluniondetails.cpp | 69 ++++++++++++---------- src/widgets/vitem.cpp | 3 +- src/widgets/vsimplespline.cpp | 6 +- 20 files changed, 106 insertions(+), 89 deletions(-) diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 937d586e6..af07753d7 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -36,7 +36,7 @@ qint64 VContainer::_id = 0; VContainer::VContainer() :base(QHash()), gObjects(QHash()), standartTable(QHash()), incrementTable(QHash()), - lengthLines(QHash()),lineAngles(QHash()), lengthSplines(QHash()), + lengthLines(QHash()), lineAngles(QHash()), lengthSplines(QHash()), lengthArcs(QHash()), details(QHash()) { SetSize(500); @@ -77,24 +77,24 @@ void VContainer::setData(const VContainer &data) while (i.hasNext()) { i.next(); - switch(i.value()->getType()) + switch (i.value()->getType()) { - case(GObject::Arc): + case (GObject::Arc): { CopyGObject(data, i.key()); break; } - case(GObject::Point): + case (GObject::Point): { CopyGObject(data, i.key()); break; } - case(GObject::Spline): + case (GObject::Spline): { CopyGObject(data, i.key()); break; } - case(GObject::SplinePath): + case (GObject::SplinePath): { CopyGObject(data, i.key()); break; @@ -560,7 +560,7 @@ void VContainer::UpdateObject(QHash &obj, const qint64 &id, val poi { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); Q_ASSERT(point != 0); - point->setId(id); + point->setId(id); // if (gObjects.contains(id)) // { // delete gObjects.value(id); @@ -625,7 +625,7 @@ void VContainer::Clear() void VContainer::ClearObject() { - if(gObjects.size()>0) + if (gObjects.size()>0) { qDeleteAll(gObjects); } @@ -715,7 +715,7 @@ void VContainer::UpdateGObject(qint64 id, VGObject* obj) UpdateObject(gObjects, id, obj); } -void VContainer::UpdateDetail(qint64 id,VDetail detail) +void VContainer::UpdateDetail(qint64 id, VDetail detail) { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); details[id] = detail; 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.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/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/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/dialogtool.cpp b/src/dialogs/dialogtool.cpp index d37e59330..46cab17e7 100644 --- a/src/dialogs/dialogtool.cpp +++ b/src/dialogs/dialogtool.cpp @@ -75,7 +75,7 @@ void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const if (i.key() != id) { VGObject *obj = i.value(); - if(obj->getType() == GObject::Point && obj->getMode() == Draw::Calculation) + if (obj->getType() == GObject::Point && obj->getMode() == Draw::Calculation) { const VPointF *point = data->GeometricObject(i.key()); box->addItem(point->name(), i.key()); @@ -93,12 +93,12 @@ void DialogTool::FillComboBoxSplines(QComboBox *box, const qint64 &id, ComboMode while (i.hasNext()) { i.next(); - if(cut == ComboMode::CutSpline) + if (cut == ComboMode::CutSpline) { if (i.key() != id + 1 && i.key() != id + 2) { VGObject *obj = i.value(); - if(obj->getType() == GObject::Spline && obj->getMode() == Draw::Calculation) + if (obj->getType() == GObject::Spline && obj->getMode() == Draw::Calculation) { const VSpline *spl = data->GeometricObject(i.key()); box->addItem(spl->name(), i.key()); @@ -110,7 +110,7 @@ void DialogTool::FillComboBoxSplines(QComboBox *box, const qint64 &id, ComboMode if (i.key() != id) { VGObject *obj = i.value(); - if(obj->getType() == GObject::Spline && obj->getMode() == Draw::Calculation) + if (obj->getType() == GObject::Spline && obj->getMode() == Draw::Calculation) { const VSpline *spl = data->GeometricObject(i.key()); box->addItem(spl->name(), i.key()); @@ -129,12 +129,12 @@ void DialogTool::FillComboBoxSplinesPath(QComboBox *box, const qint64 &id, Combo while (i.hasNext()) { i.next(); - if(cut == ComboMode::CutSpline) + if (cut == ComboMode::CutSpline) { if (i.key() != id + 1 && i.key() != id + 2) { VGObject *obj = i.value(); - if(obj->getType() == GObject::SplinePath && obj->getMode() == Draw::Calculation) + if (obj->getType() == GObject::SplinePath && obj->getMode() == Draw::Calculation) { const VSplinePath *splPath = data->GeometricObject(i.key()); box->addItem(splPath->name(), i.key()); @@ -146,7 +146,7 @@ void DialogTool::FillComboBoxSplinesPath(QComboBox *box, const qint64 &id, Combo if (i.key() != id) { VGObject *obj = i.value(); - if(obj->getType() == GObject::SplinePath && obj->getMode() == Draw::Calculation) + 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.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 index 181551334..f6ce3501f 100644 --- a/src/dialogs/dialoguniondetails.cpp +++ b/src/dialogs/dialoguniondetails.cpp @@ -47,7 +47,7 @@ DialogUnionDetails::~DialogUnionDetails() void DialogUnionDetails::ChoosedObject(qint64 id, const Scene::Scenes &type) { - if(numberD == 0) + if (numberD == 0) { ChoosedDetail(id, type, d1, d1P1, d1P2); } @@ -98,13 +98,13 @@ void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &ty } if (numberP == 1) { - if(id == p1) + if (id == p1) { return; } p2 = id; ++numberD; - if(numberD > 1) + if (numberD > 1) { ++numberP; emit ToolTip(""); diff --git a/src/dialogs/dialoguniondetails.h b/src/dialogs/dialoguniondetails.h index 8b4ed6798..edfb9a9ed 100644 --- a/src/dialogs/dialoguniondetails.h +++ b/src/dialogs/dialoguniondetails.h @@ -31,16 +31,17 @@ #include "dialogtool.h" -namespace Ui { -class DialogUnionDetails; +namespace Ui +{ + class DialogUnionDetails; } class DialogUnionDetails : public DialogTool { Q_OBJECT public: - explicit DialogUnionDetails(const VContainer *data, QWidget *parent = 0); - ~DialogUnionDetails(); + explicit DialogUnionDetails(const VContainer *data, QWidget *parent = 0); + ~DialogUnionDetails(); inline qint64 getD1() const {return d1;} inline qint64 getD2() const {return d2;} inline qint64 getD1P1() const {return d1P1;} diff --git a/src/geometry/varc.cpp b/src/geometry/varc.cpp index 674c92dd4..4613c243a 100644 --- a/src/geometry/varc.cpp +++ b/src/geometry/varc.cpp @@ -40,8 +40,8 @@ VArc::VArc () 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) + : 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()); diff --git a/src/geometry/varc.h b/src/geometry/varc.h index 379360356..dd54e5fe1 100644 --- a/src/geometry/varc.h +++ b/src/geometry/varc.h @@ -143,7 +143,7 @@ public: * @param number * @return */ - QVector SplOfArc( qint32 number ) const; + QVector SplOfArc( qint32 number ) const; virtual QString name() const{return _name;} private: /** diff --git a/src/geometry/vdetail.cpp b/src/geometry/vdetail.cpp index 8244be9be..759107312 100644 --- a/src/geometry/vdetail.cpp +++ b/src/geometry/vdetail.cpp @@ -111,4 +111,3 @@ void VDetail::setId(const qint64 &id) { _id = id; } - diff --git a/src/geometry/vspline.cpp b/src/geometry/vspline.cpp index 46768147a..f37ba220e 100644 --- a/src/geometry/vspline.cpp +++ b/src/geometry/vspline.cpp @@ -74,8 +74,8 @@ VSpline::VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm } 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) + :VGObject(GObject::Spline, idObject, mode), p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), angle2(0), kAsm1(1), + kAsm2(1), kCurve(1) { CreateName(); @@ -145,7 +145,7 @@ 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; @@ -180,7 +180,7 @@ qreal VSpline::LengthT(qreal t) const 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; } @@ -199,7 +199,8 @@ 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; } } diff --git a/src/geometry/vsplinepath.cpp b/src/geometry/vsplinepath.cpp index 98b6f666a..e028b461a 100644 --- a/src/geometry/vsplinepath.cpp +++ b/src/geometry/vsplinepath.cpp @@ -174,14 +174,14 @@ const VSplinePoint &VSplinePath::at(ptrdiff_t indx) const 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; } @@ -196,7 +196,7 @@ QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF 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; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0b9497304..e330fa982 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1084,7 +1084,7 @@ void MainWindow::SetEnableTool(bool enable) { bool drawTools = false; bool modelingTools = false; - if(mode == Draw::Calculation) + if (mode == Draw::Calculation) { drawTools = enable; } diff --git a/src/tools/drawTools/vtoolcutspline.cpp b/src/tools/drawTools/vtoolcutspline.cpp index cf2927c93..f05e012d1 100644 --- a/src/tools/drawTools/vtoolcutspline.cpp +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -259,7 +259,7 @@ void VToolCutSpline::RefreshSpline(VSimpleSpline *spline, qint64 splid, SimpleSp QPainterPath path; path.addPath(spl->GetPath()); path.setFillRule( Qt::WindingFill ); - if(tr == SimpleSpline::FirstPoint) + if (tr == SimpleSpline::FirstPoint) { path.translate(-spl->GetP1().toQPointF().x(), -spl->GetP1().toQPointF().y()); } diff --git a/src/tools/drawTools/vtoolcutsplinepath.cpp b/src/tools/drawTools/vtoolcutsplinepath.cpp index 2083c82e6..277119865 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/tools/drawTools/vtoolcutsplinepath.cpp @@ -120,13 +120,15 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons Q_ASSERT(splPath1); VSplinePath *splPath2 = new VSplinePath(); Q_ASSERT(splPath2); - for(qint32 i = 0; i < splPath->CountPoint(); i++) + 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(*p, spl1.GetKasm2(), spl1.GetAngle2()+180, spl2.GetKasm1()); + VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2()+180, + spl2.GetKasm1()); splPath1->append(cutPoint); continue; } @@ -134,7 +136,7 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons } else { - if(i == p2) + if (i == p2) { VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1(), spl2.GetKasm1()); splPath2->append(cutPoint); @@ -169,13 +171,15 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons Q_ASSERT(splPath1 != 0); VSplinePath *splPath2 = new VSplinePath(); Q_ASSERT(splPath2 != 0); - for(qint32 i = 0; i < splPath->CountPoint(); i++) + 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(*p, spl1.GetKasm2(), spl1.GetAngle2()+180, spl2.GetKasm1()); + VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2()+180, + spl2.GetKasm1()); splPath1->append(cutPoint); continue; } @@ -183,7 +187,7 @@ void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, cons } else { - if(i == p2) + if (i == p2) { VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1(), spl2.GetKasm1()); splPath2->append(cutPoint); @@ -326,7 +330,7 @@ void VToolCutSplinePath::RefreshSpline(VSimpleSpline *spline, qint64 splPathid, QPainterPath path; path.addPath(splPath->GetPath()); path.setFillRule( Qt::WindingFill ); - if(tr == SimpleSpline::FirstPoint) + if (tr == SimpleSpline::FirstPoint) { VSpline spl = splPath->GetSpline(1); path.translate(-spl.GetP1().toQPointF().x(), -spl.GetP1().toQPointF().y()); diff --git a/src/tools/vtooluniondetails.cpp b/src/tools/vtooluniondetails.cpp index dbd97c297..92b4ea5e6 100644 --- a/src/tools/vtooluniondetails.cpp +++ b/src/tools/vtooluniondetails.cpp @@ -63,7 +63,7 @@ VToolUnionDetails::VToolUnionDetails(VDomDocument *doc, VContainer *data, const void VToolUnionDetails::CorectPoints(const VDetail &detail, qint64 &p1, qint64 &p2) { - if(p1 == p2) + if (p1 == p2) { qWarning()<<"Union points equal."; return; @@ -72,21 +72,21 @@ void VToolUnionDetails::CorectPoints(const VDetail &detail, qint64 &p1, qint64 & bool p2flag = false; for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) { - if(detail.at(i).getTypeTool() == Tool::NodePoint) + if (detail.at(i).getTypeTool() == Tool::NodePoint) { - if(p1 == detail.at(i).getId()) + if (p1 == detail.at(i).getId()) { p1flag = true; } - if(p2 == detail.at(i).getId()) + if (p2 == detail.at(i).getId()) { p2flag = true; } - if(p1flag == true && p2flag == false) + if (p1flag == true && p2flag == false) { return; } - if(p2flag == true && p1flag == false) + if (p2flag == true && p1flag == false) { qint64 p = p1; p1 = p2; @@ -108,7 +108,7 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons { case (Tool::NodePoint): { - if( qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && (pRotate == 0)) + if ( qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && (pRotate == 0)) { id = det.at(i).getId(); } @@ -125,7 +125,7 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons break; case (Tool::NodeArc): { - if(qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { id = det.at(i).getId(); } @@ -156,7 +156,7 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons break; case (Tool::NodeSpline): { - if(qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { id = det.at(i).getId(); } @@ -188,7 +188,7 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons break; case (Tool::NodeSplinePath): { - if(qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { id = det.at(i).getId(); } @@ -205,22 +205,26 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons VPointF *p1 = new VPointF(spline.GetP1()); Q_ASSERT(p1 != 0); - BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + 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); + BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); VPointF p3 = VPointF(spline.GetP3()); - BiasRotatePoint(&p3, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + 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); + 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) + if (i==1) { path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), splinePath->at(i-1).KAsm1())); @@ -252,7 +256,7 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c { case (Tool::NodePoint): { - if(qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { ++idCount; } @@ -268,7 +272,7 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c break; case (Tool::NodeArc): { - if(qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { ++idCount; } @@ -281,7 +285,8 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c 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); + BiasRotatePoint(center, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); QLineF l1(center->toQPointF(), p1.toQPointF()); QLineF l2(center->toQPointF(), p2.toQPointF()); @@ -296,7 +301,7 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c break; case (Tool::NodeSpline): { - if(qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { ++idCount; } @@ -329,7 +334,7 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c break; case (Tool::NodeSplinePath): { - if(qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { ++idCount; } @@ -346,22 +351,26 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c VPointF *p1 = new VPointF(spline.GetP1()); Q_ASSERT(p1 != 0); - BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + 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); + BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); VPointF p3 = VPointF(spline.GetP3()); - BiasRotatePoint(&p3, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + 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); + 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) + if (i==1) { path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), splinePath->at(i-1).KAsm1())); @@ -386,10 +395,10 @@ void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const q { point->setX(point->x()+dx); point->setY(point->y()+dy); - QLineF l(pRotate, point->toQPointF()); - l.setAngle(angle); - point->setX(l.p2().x()); - point->setY(l.p2().y()); + QLineF line(pRotate, point->toQPointF()); + line.setAngle(angle); + point->setX(line.p2().x()); + point->setY(line.p2().y()); } void VToolUnionDetails::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, @@ -439,7 +448,7 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai } - if(typeCreation == Tool::FromGui) + if (typeCreation == Tool::FromGui) { //Update corected points qint64 d1P1 = unionDetails->getD1P1(); 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)); } From 7cf058bf705d75d86d37ac51fd352539011e4dba Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 2 Jan 2014 17:50:01 +0200 Subject: [PATCH 14/15] Union details tool. --HG-- branch : feature --- src/container/vcontainer.cpp | 30 +- src/container/vcontainer.h | 3 +- src/dialogs/dialoghistory.cpp | 14 + src/dialogs/dialoguniondetails.cpp | 43 +- src/dialogs/dialoguniondetails.h | 25 +- src/geometry/vdetail.cpp | 72 ++ src/geometry/vdetail.h | 8 +- src/mainwindow.cpp | 18 +- src/mainwindow.h | 1 + src/tools/drawTools/vdrawtool.cpp | 28 +- src/tools/drawTools/vdrawtool.h | 9 +- src/tools/nodeDetails/vabstractnode.cpp | 6 +- src/tools/nodeDetails/vabstractnode.h | 5 +- src/tools/nodeDetails/vnodearc.cpp | 28 +- src/tools/nodeDetails/vnodearc.h | 4 +- src/tools/nodeDetails/vnodepoint.cpp | 26 +- src/tools/nodeDetails/vnodepoint.h | 4 +- src/tools/nodeDetails/vnodespline.cpp | 27 +- src/tools/nodeDetails/vnodespline.h | 5 +- src/tools/nodeDetails/vnodesplinepath.cpp | 26 +- src/tools/nodeDetails/vnodesplinepath.h | 5 +- src/tools/vabstracttool.cpp | 28 +- src/tools/vabstracttool.h | 9 +- src/tools/vtooldetail.cpp | 32 +- src/tools/vtooluniondetails.cpp | 849 +++++++++++----------- src/tools/vtooluniondetails.h | 47 +- src/widgets/vsimplesplinepath.cpp | 4 +- src/widgets/vsimplesplinepath.h | 2 +- src/xml/vdomdocument.cpp | 55 +- src/xml/vdomdocument.h | 8 +- 30 files changed, 839 insertions(+), 582 deletions(-) diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index af07753d7..f21c26977 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -561,10 +561,11 @@ void VContainer::UpdateObject(QHash &obj, const qint64 &id, val poi 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); -// } + if (gObjects.contains(id)) + { + delete gObjects.value(id); + gObjects.remove(id); + } obj[id] = point; UpdateId(id); } @@ -620,10 +621,10 @@ void VContainer::Clear() lengthArcs.clear(); lineAngles.clear(); details.clear(); - ClearObject(); + ClearGObjects(); } -void VContainer::ClearObject() +void VContainer::ClearGObjects() { if (gObjects.size()>0) { @@ -632,6 +633,23 @@ void VContainer::ClearObject() 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 { if (base.contains(name)) diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index 49a1bfb58..d4ef49161 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -263,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 */ diff --git a/src/dialogs/dialoghistory.cpp b/src/dialogs/dialoghistory.cpp index 1e114b1bb..3a8bc2d9c 100644 --- a/src/dialogs/dialoghistory.cpp +++ b/src/dialogs/dialoghistory.cpp @@ -402,6 +402,20 @@ QString DialogHistory::Record(const VToolRecord &tool) } } 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()<setupUi(this); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); @@ -49,11 +49,11 @@ void DialogUnionDetails::ChoosedObject(qint64 id, const Scene::Scenes &type) { if (numberD == 0) { - ChoosedDetail(id, type, d1, d1P1, d1P2); + ChoosedDetail(id, type, d1, indexD1); } else { - ChoosedDetail(id, type, d2, d2P1, d2P2); + ChoosedDetail(id, type, d2, indexD2); } } @@ -72,8 +72,7 @@ bool DialogUnionDetails::CheckObject(const qint64 &id, const qint64 &idDetail) c return det.Containes(id); } -void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, qint64 &p1, - qint64 &p2) +void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, ptrdiff_t &index) { if (idDetail == 0) { @@ -95,25 +94,41 @@ void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &ty p1 = id; ++numberP; emit ToolTip(tr("Select second point")); + return; } if (numberP == 1) { if (id == p1) { + emit ToolTip(tr("Select another second point")); return; } - p2 = id; - ++numberD; - if (numberD > 1) + VDetail d = data->GetDetail(idDetail); + if (d.OnEdge(p1, id)) { - ++numberP; - emit ToolTip(""); - this->show(); + 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 { - numberP = 0; - emit ToolTip(tr("Select detail")); + emit ToolTip(tr("Select another second point")); + return; } } } diff --git a/src/dialogs/dialoguniondetails.h b/src/dialogs/dialoguniondetails.h index edfb9a9ed..2815c65fc 100644 --- a/src/dialogs/dialoguniondetails.h +++ b/src/dialogs/dialoguniondetails.h @@ -42,12 +42,10 @@ class DialogUnionDetails : public DialogTool public: explicit DialogUnionDetails(const VContainer *data, QWidget *parent = 0); ~DialogUnionDetails(); - inline qint64 getD1() const {return d1;} - inline qint64 getD2() const {return d2;} - inline qint64 getD1P1() const {return d1P1;} - inline qint64 getD1P2() const {return d1P2;} - inline qint64 getD2P1() const {return d2P1;} - inline qint64 getD2P2() const {return d2P2;} + 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. @@ -62,17 +60,16 @@ public slots: private: Q_DISABLE_COPY(DialogUnionDetails) Ui::DialogUnionDetails *ui; + ptrdiff_t indexD1; + ptrdiff_t indexD2; qint64 d1; qint64 d2; - qint64 d1P1; - qint64 d1P2; - qint64 d2P1; - qint64 d2P2; - qint32 numberD; - qint32 numberP; + 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, qint64 &p1, - qint64 &p2); + void ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, ptrdiff_t &index); }; #endif // DIALOGUNIONDETAILS_H diff --git a/src/geometry/vdetail.cpp b/src/geometry/vdetail.cpp index 759107312..24c7811c8 100644 --- a/src/geometry/vdetail.cpp +++ b/src/geometry/vdetail.cpp @@ -111,3 +111,75 @@ 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 ffb362f1f..16411a50a 100644 --- a/src/geometry/vdetail.h +++ b/src/geometry/vdetail.h @@ -176,9 +176,11 @@ public: */ inline void setNodes(const QVector &value) {nodes = value;} ptrdiff_t indexOfNode(const qint64 &id) const; - qint64 id() const; - void setId(const qint64 &id); - + 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; /** diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e330fa982..ae7a14741 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -60,7 +60,7 @@ MainWindow::MainWindow(QWidget *parent) dialogCutSpline(QSharedPointer()), dialogCutSplinePath (QSharedPointer()), dialogUnionDetails(QSharedPointer()), dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), - mode(Draw::Calculation) + mode(Draw::Calculation), currentDrawIndex(0) { ui->setupUi(this); ToolBarOption(); @@ -179,7 +179,7 @@ void MainWindow::ActionNewDraw() } connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::currentDrawChanged); - pattern->ClearObject(); + pattern->ClearGObjects(); //Create single point qint64 id = pattern->AddGObject(new VPointF(toPixel((10+comboBoxDraws->count()*5)), toPixel(10), "А", 5, 10)); VToolSinglePoint *spoint = new VToolSinglePoint(doc, pattern, id, Tool::FromGui); @@ -504,6 +504,8 @@ 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) @@ -801,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()<<"Get wrong tool type. Ignore."; break; @@ -854,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(); @@ -883,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); diff --git a/src/mainwindow.h b/src/mainwindow.h index 53a57350b..c29236a4d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -506,6 +506,7 @@ private: * @brief mode */ Draw::Draws mode; + qint32 currentDrawIndex; /** * @brief ToolBarOption */ 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/nodeDetails/vabstractnode.cpp b/src/tools/nodeDetails/vabstractnode.cpp index f86408eaf..f2920e388 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) + : VAbstractTool(doc, data, id), idNode(idNode), idTool(idTool) { _referens = 0; } diff --git a/src/tools/nodeDetails/vabstractnode.h b/src/tools/nodeDetails/vabstractnode.h index cb52c85f1..fce0527fe 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); 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 353a35810..eb7244526 100644 --- a/src/tools/nodeDetails/vnodearc.cpp +++ b/src/tools/nodeDetails/vnodearc.cpp @@ -34,8 +34,8 @@ 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, QGraphicsItem * parent) + :VAbstractNode(doc, data, id, idArc, idTool), QGraphicsPathItem(parent) { RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); @@ -51,14 +51,22 @@ VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, } 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) { + 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); Q_ASSERT(arc != 0); doc->AddTool(id, arc); - doc->IncrementReferens(idArc); + if(idTool != 0) + { + doc->IncrementReferens(idTool); + } + else + { + doc->IncrementReferens(idArc); + } } else { @@ -78,6 +86,10 @@ void VNodeArc::AddToFile() AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrType, ToolType); AddAttribute(domElement, AttrIdObject, idNode); + if (idTool != 0) + { + AddAttribute(domElement, AttrIdTool, idTool); + } AddToModeling(domElement); } @@ -87,7 +99,11 @@ void VNodeArc::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); + domElement.setAttribute(AttrIdObject, idNode); + if (idTool != 0) + { + domElement.setAttribute(AttrIdTool, idTool); + } } } diff --git a/src/tools/nodeDetails/vnodearc.h b/src/tools/nodeDetails/vnodearc.h index 5693fd307..1fe760f30 100644 --- a/src/tools/nodeDetails/vnodearc.h +++ b/src/tools/nodeDetails/vnodearc.h @@ -49,7 +49,7 @@ 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, QGraphicsItem * parent = 0); /** * @brief Create * @param doc dom document container @@ -60,7 +60,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); /** * @brief TagName */ diff --git a/src/tools/nodeDetails/vnodepoint.cpp b/src/tools/nodeDetails/vnodepoint.cpp index e06c6a040..aaf0bd1a7 100644 --- a/src/tools/nodeDetails/vnodepoint.cpp +++ b/src/tools/nodeDetails/vnodepoint.cpp @@ -34,8 +34,8 @@ 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), + const Tool::Sources &typeCreation, const qint64 &idTool, QGraphicsItem *parent) + :VAbstractNode(doc, data, id, idPoint, idTool), QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0), lineName(0) { namePoint = new VGraphicsSimpleTextItem(this); @@ -58,14 +58,22 @@ VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 id } 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) { + VAbstractTool::AddRecord(id, Tool::NodePoint, doc); if (parse == Document::FullParse) { - VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation); + VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, idTool); Q_ASSERT(point != 0); doc->AddTool(id, point); - doc->IncrementReferens(idPoint); + if(idTool != 0) + { + doc->IncrementReferens(idTool); + } + else + { + doc->IncrementReferens(idPoint); + } } else { @@ -88,6 +96,10 @@ void VNodePoint::AddToFile() AddAttribute(domElement, AttrIdObject, idNode); AddAttribute(domElement, AttrMx, toMM(point->mx())); AddAttribute(domElement, AttrMy, toMM(point->my())); + if (idTool != 0) + { + AddAttribute(domElement, AttrIdTool, idTool); + } AddToModeling(domElement); } @@ -101,6 +113,10 @@ void VNodePoint::RefreshDataInFile() domElement.setAttribute(AttrIdObject, idNode); domElement.setAttribute(AttrMx, toMM(point->mx())); domElement.setAttribute(AttrMy, toMM(point->my())); + if (idTool != 0) + { + domElement.setAttribute(AttrIdTool, idTool); + } } } diff --git a/src/tools/nodeDetails/vnodepoint.h b/src/tools/nodeDetails/vnodepoint.h index f2616fbac..2657ec20d 100644 --- a/src/tools/nodeDetails/vnodepoint.h +++ b/src/tools/nodeDetails/vnodepoint.h @@ -49,7 +49,7 @@ 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, QGraphicsItem * parent = 0 ); /** * @brief Create * @param doc dom document container @@ -60,7 +60,7 @@ 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); /** * @brief TagName */ diff --git a/src/tools/nodeDetails/vnodespline.cpp b/src/tools/nodeDetails/vnodespline.cpp index b2fbcaa10..8916c819b 100644 --- a/src/tools/nodeDetails/vnodespline.cpp +++ b/src/tools/nodeDetails/vnodespline.cpp @@ -34,8 +34,8 @@ 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, QGraphicsItem * parent) + :VAbstractNode(doc, data, id, idSpline, idTool), QGraphicsPathItem(parent) { RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); @@ -51,14 +51,23 @@ VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 } 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) { + 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); doc->AddTool(id, spl); - doc->IncrementReferens(idSpline); + if(idTool != 0) + { + doc->IncrementReferens(idTool); + } + else + { + doc->IncrementReferens(idSpline); + } } else { @@ -79,6 +88,10 @@ void VNodeSpline::AddToFile() AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrType, ToolType); AddAttribute(domElement, AttrIdObject, idNode); + if (idTool != 0) + { + AddAttribute(domElement, AttrIdTool, idTool); + } AddToModeling(domElement); } @@ -89,6 +102,10 @@ void VNodeSpline::RefreshDataInFile() if (domElement.isElement()) { domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); + if (idTool != 0) + { + domElement.setAttribute(AttrIdTool, idTool); + } } } diff --git a/src/tools/nodeDetails/vnodespline.h b/src/tools/nodeDetails/vnodespline.h index e3ac4b963..1c42e4f7b 100644 --- a/src/tools/nodeDetails/vnodespline.h +++ b/src/tools/nodeDetails/vnodespline.h @@ -49,7 +49,7 @@ 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, QGraphicsItem * parent = 0); /** * @brief Create * @param doc dom document container @@ -61,7 +61,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); /** * @brief TagName */ diff --git a/src/tools/nodeDetails/vnodesplinepath.cpp b/src/tools/nodeDetails/vnodesplinepath.cpp index 8d1a98fd6..020de500d 100644 --- a/src/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/tools/nodeDetails/vnodesplinepath.cpp @@ -34,8 +34,8 @@ 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, QGraphicsItem * parent) + :VAbstractNode(doc, data, id, idSpline, idTool), QGraphicsPathItem(parent) { RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); @@ -51,18 +51,26 @@ VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, } 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) { + 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); Q_ASSERT(splPath != 0); doc->AddTool(id, splPath); const VSplinePath *path = data->GeometricObject(id); const QVector *points = path->GetPoint(); for (qint32 i = 0; isize(); ++i) { - doc->IncrementReferens(points->at(i).P().id()); + if(idTool != 0) + { + doc->IncrementReferens(idTool); + } + else + { + doc->IncrementReferens(points->at(i).P().id()); + } } } else @@ -83,6 +91,10 @@ void VNodeSplinePath::AddToFile() AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrType, ToolType); AddAttribute(domElement, AttrIdObject, idNode); + if (idTool != 0) + { + AddAttribute(domElement, AttrIdTool, idTool); + } AddToModeling(domElement); } @@ -93,6 +105,10 @@ void VNodeSplinePath::RefreshDataInFile() if (domElement.isElement()) { domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); + if (idTool != 0) + { + domElement.setAttribute(AttrIdTool, idTool); + } } } diff --git a/src/tools/nodeDetails/vnodesplinepath.h b/src/tools/nodeDetails/vnodesplinepath.h index 840f7dc5f..7ffcbaee6 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, + 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 idSpline, - const Document::Documents &parse, const Tool::Sources &typeCreation); + const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0); /** * @brief TagName */ diff --git a/src/tools/vabstracttool.cpp b/src/tools/vabstracttool.cpp index a8f4b36e7..5fc75916f 100644 --- a/src/tools/vabstracttool.cpp +++ b/src/tools/vabstracttool.cpp @@ -65,8 +65,8 @@ const QString VAbstractTool::AttrAxisP2 = QStringLiteral("axisP2"); const QString VAbstractTool::TypeLineNone = QStringLiteral("none"); 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) +VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id) + :VDataTool(data), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black) { Q_ASSERT(doc != 0); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange); @@ -186,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 e7950b4f0..8d6412db7 100644 --- a/src/tools/vabstracttool.h +++ b/src/tools/vabstracttool.h @@ -46,7 +46,7 @@ public: * @param id * @param parent */ - VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); + VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id); virtual ~VAbstractTool() {} /** * @brief LineIntersectRect @@ -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 diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 0703cff28..f71db07a8 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -81,8 +81,8 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, void VToolDetail::setDialog() { Q_ASSERT(dialogDetail.isNull() == false); - const VDetail *detail = VAbstractTool::data.GeometricObject(id); - dialogDetail->setDetails(*detail); + VDetail detail = VAbstractTool::data.GetDetail(id); + dialogDetail->setDetails(detail); } void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, @@ -146,6 +146,7 @@ void VToolDetail::Create(const qint64 _id, VDetail newDetail, VMainGraphicsScene doc->UpdateToolData(id, data); } } + VAbstractTool::AddRecord(id, Tool::Detail, doc); if (parse == Document::FullParse) { VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene); @@ -170,7 +171,7 @@ void VToolDetail::Remove() RemoveReferens(); element.removeChild(domElement); //update xml file - emit FullUpdateTree(); + //emit FullUpdateTree(); //remove form scene emit RemoveTool(this); } @@ -310,7 +311,30 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } if (selectedAction == actionRemove) { - 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"<d1, this->d1P1, this->d1P2); - CorectPoints(this->d2, this->d2P1, this->d2P2); - if (typeCreation == Tool::FromGui) { AddToFile(); @@ -61,342 +56,320 @@ VToolUnionDetails::VToolUnionDetails(VDomDocument *doc, VContainer *data, const } } -void VToolUnionDetails::CorectPoints(const VDetail &detail, qint64 &p1, qint64 &p2) +void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDetail &newDetail, const VDetail &det, + const ptrdiff_t &i, const qint64 &idTool, const qreal &dx, const qreal &dy, + const qint64 &pRotate, const qreal &angle) { - if (p1 == p2) + qint64 id = 0, idObject = 0; + switch (det.at(i).getTypeTool()) { - qWarning()<<"Union points equal."; - return; - } - bool p1flag = false; - bool p2flag = false; - for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) - { - if (detail.at(i).getTypeTool() == Tool::NodePoint) + case (Tool::NodePoint): { - if (p1 == detail.at(i).getId()) + if ( qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && (pRotate == 0)) { - p1flag = true; + id = det.at(i).getId(); } - if (p2 == detail.at(i).getId()) + else { - p2flag = true; - } - if (p1flag == true && p2flag == false) - { - return; - } - if (p2flag == true && p1flag == false) - { - qint64 p = p1; - p1 = p2; - p2 = p; - return; + VPointF *point = new VPointF(*data->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); } } - } -} - -void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, const VDetail &det, const ptrdiff_t &a, - const ptrdiff_t &b, const qreal &dx, const qreal &dy, const qint64 &pRotate, - const qreal &angle) const -{ - for (ptrdiff_t i = a; i <= b; ++i) - { - qint64 id = 0; - switch (det.at(i).getTypeTool()) + break; + case (Tool::NodeArc): { - case (Tool::NodePoint): + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { - if ( qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && (pRotate == 0)) - { - id = det.at(i).getId(); - } - else - { - VPointF *point = new VPointF(*data->GeometricObject(det.at(i).getId())); - Q_ASSERT(point != 0); - BiasRotatePoint(point, dx, dy, data->GeometricObject(pRotate)->toQPointF(), - angle); - id = data->AddGObject(point); - VNodePoint::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui ); - } + id = det.at(i).getId(); } - break; - case (Tool::NodeArc): + else { - 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); + 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); - id = data->AddGObject(arc1); - VNodeArc::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui); - } + 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); } - break; - case (Tool::NodeSpline): + } + break; + case (Tool::NodeSpline): + { + if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) { - 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()); + id = det.at(i).getId(); + } + else + { + const VSpline *spline = data->GeometricObject(det.at(i).getId()); - VPointF *p1 = new VPointF(spline->GetP1()); + 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); + } + } + 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); + 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()); - id = data->AddGObject(spl); - VNodeSpline::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui); - } - } - 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); - 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())); - } - id = data->AddGObject(path); - VNodeSplinePath::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui); - } - } - break; - default: - qWarning()<<"May be wrong tool type!!! Ignoring."<GeometricObject(det.at(i).getId())); - Q_ASSERT(point != 0); - BiasRotatePoint(point, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); - ++idCount; - data->UpdateGObject(idDetail+idCount, point); - } - } - break; - case (Tool::NodeArc): - { - if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) - { - ++idCount; - } - else - { - 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(), + VPointF p2 = VPointF(spline.GetP2()); + BiasRotatePoint(&p2, 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); - ++idCount; - data->UpdateGObject(idDetail+idCount, arc1); - } - } - break; - case (Tool::NodeSpline): - { - if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) - { - ++idCount; - } - else - { - const VSpline *spline = data->GeometricObject(det.at(i).getId()); + VPointF p3 = VPointF(spline.GetP3()); + BiasRotatePoint(&p3, dx, dy, data->GeometricObject(pRotate)->toQPointF(), + angle); - 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()); + VPointF *p4 = new VPointF(spline.GetP4()); Q_ASSERT(p4 != 0); - BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); + 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); - ++idCount; - data->UpdateGObject(idDetail+idCount, spl); - } - } - break; - case (Tool::NodeSplinePath): - { - if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) - { - ++idCount; - } - else - { - VSplinePath *path = new VSplinePath(); - Q_ASSERT(path != 0); - const VSplinePath *splinePath = data->GeometricObject(det.at(i).getId()); - for (qint32 i = 1; i <= splinePath->Count(); ++i) + VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve()); + if (i==1) { - 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())); + path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), + splinePath->at(i-1).KAsm1())); } - ++idCount; - data->UpdateGObject(idDetail+idCount, path); + 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); } - 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(angle); + line.setAngle(line.angle()+angle); point->setX(line.p2().x()); point->setY(line.p2().y()); } @@ -406,20 +379,17 @@ void VToolUnionDetails::Create(QSharedPointer &dialog, VMain { VDetail d1 = data->GetDetail(dialog->getD1()); VDetail d2 = data->GetDetail(dialog->getD2()); - qint64 d1P1 = dialog->getD1P1(); - qint64 d1P2 = dialog->getD1P2(); - qint64 d2P1 = dialog->getD2P1(); - qint64 d2P2 = dialog->getD2P2(); - Create(0, d1, d2, dialog->getD1(), dialog->getD2(), d1P1, d1P2, d2P1, d2P2, scene, doc, data, Document::FullParse, + 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 qint64 &d1P1, const qint64 &d1P2, const qint64 &d2P1, - const qint64 &d2P2, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + 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) { @@ -432,9 +402,10 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai doc->UpdateToolData(id, data); } } + VAbstractTool::AddRecord(id, Tool::UnionDetails, doc); if (parse == Document::FullParse) { - unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, d1P1, d1P2, d2P1, d2P2, typeCreation); + VToolUnionDetails *unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation); QHash* tools = doc->getTools(); tools->insert(id, unionDetails); for (ptrdiff_t i = 0; i < d1.CountNode(); ++i) @@ -450,62 +421,155 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai if (typeCreation == Tool::FromGui) { - //Update corected points - qint64 d1P1 = unionDetails->getD1P1(); - qint64 d1P2 = unionDetails->getD1P2(); - qint64 d2P1 = unionDetails->getD2P1(); - qint64 d2P2 = unionDetails->getD2P2(); - + 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; - unionDetails->AddToNewDetail(data, newDetail, d1, d1.indexOfNode(d1P1), d1.indexOfNode(d1P2)); - const VNodeDetail det1p2 = d1.at(d1.indexOfNode(d1P2)); - const VPointF *point2 = data->GeometricObject(det1p2.getId()); - const VNodeDetail det2p1 = d2.at(d2.indexOfNode(d2P1)); - const VPointF *point1 = data->GeometricObject(det2p1.getId()); - qreal dx = point2->x() - point1->x(); - qreal dy = point2->y() - point1->y(); - const VNodeDetail det1p1 = d1.at(d1.indexOfNode(d1P1)); - const VPointF *point3 = data->GeometricObject(det1p1.getId()); - const VNodeDetail det2p2 = d1.at(d1.indexOfNode(d2P2)); - const VPointF *point4 = data->GeometricObject(det2p2.getId()); - QLineF l1(point3->toQPointF(), point2->toQPointF()); - QLineF l2(point4->toQPointF(), point1->toQPointF()); - qreal angle = l2.angle() + l2.angleTo(l1); + do + { + AddToNewDetail(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()); - unionDetails->AddToNewDetail(data, newDetail, d2, d2.indexOfNode(d2P1)+1, d2.indexOfNode(d2P2)-1, dx, dy, - d1P2, angle); + 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(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 { - unionDetails = qobject_cast(doc->getTool(id)); + 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. - unionDetails->UpdatePoints(id, data, d1, d1.indexOfNode(d1P1), d1.indexOfNode(d1P2)); + 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 det1p2 = d1.at(d1.indexOfNode(d1P2)); - const VPointF *point2 = data->GeometricObject(det1p2.getId()); - VNodeDetail det2p1 = d2.at(d2.indexOfNode(d2P1)); - const VPointF *point1 = data->GeometricObject(det2p1.getId()); - qreal dx = point2->x() - point1->x(); - qreal dy = point2->y() - point1->y(); - const VNodeDetail det1p1 = d1.at(d1.indexOfNode(d1P1)); - const VPointF *point3 = data->GeometricObject(det1p1.getId()); - const VNodeDetail det2p2 = d1.at(d1.indexOfNode(d2P2)); - const VPointF *point4 = data->GeometricObject(det2p2.getId()); - QLineF l1(point3->toQPointF(), point2->toQPointF()); - QLineF l2(point4->toQPointF(), point1->toQPointF()); - qreal angle = l2.angle() + l2.angleTo(l1); + VNodeDetail det2p1; + VNodeDetail det2p2; + d2.NodeOnEdge(indexD2, det2p1, det2p2); + VPointF point3 = VPointF(*data->GeometricObject(det2p1.getId())); + VPointF point4 = VPointF(*data->GeometricObject(det2p2.getId())); - unionDetails->UpdatePoints(id, data, d2, d2.indexOfNode(d2P1)+1, d2.indexOfNode(d2P2)-1, dx, dy, - d1P2, angle); + 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 Q { if (element.tagName() == VToolUnionDetails::TagDetail) { - QDomNodeList nodeList = domElement.childNodes(); + VDetail d; + QDomNodeList nodeList = element.childNodes(); qint32 num = nodeList.size(); for (qint32 j = 0; j < num; ++j) { @@ -552,10 +617,11 @@ QVector VToolUnionDetails::GetDetailFromFile(VDomDocument *doc, const Q { tool = Tool::NodeSplinePath; } - vector[i].append(VNodeDetail(id, tool, nodeType, mx, my)); + d.append(VNodeDetail(id, tool, nodeType, mx, my)); } } } + vector.append(d); } } } @@ -568,10 +634,8 @@ void VToolUnionDetails::AddToFile() AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrType, ToolType); - AddAttribute(domElement, AttrD1P1, d1P1); - AddAttribute(domElement, AttrD1P2, d1P2); - AddAttribute(domElement, AttrD2P1, d2P1); - AddAttribute(domElement, AttrD2P2, d2P2); + AddAttribute(domElement, AttrIndexD1, indexD1); + AddAttribute(domElement, AttrIndexD2, indexD2); AddDetail(domElement, d1); AddDetail(domElement, d2); @@ -584,10 +648,8 @@ void VToolUnionDetails::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - domElement.setAttribute(AttrD1P1, d1P1); - domElement.setAttribute(AttrD1P2, d1P2); - domElement.setAttribute(AttrD2P1, d2P1); - domElement.setAttribute(AttrD2P2, d2P2); + domElement.setAttribute(AttrIndexD1, indexD1); + domElement.setAttribute(AttrIndexD2, indexD2); QDomNode domNode = domElement.firstChild(); domNode = UpdateDetail(domNode, d1); @@ -607,7 +669,7 @@ void VToolUnionDetails::AddDetail(QDomElement &domElement, VDetail &d) domElement.appendChild(det); } -void VToolUnionDetails::AddNode(QDomElement &domElement, VNodeDetail &node) +void VToolUnionDetails::AddNode(QDomElement &domElement, const VNodeDetail &node) { QDomElement nod = doc->createElement(TagNode); @@ -643,7 +705,7 @@ void VToolUnionDetails::AddNode(QDomElement &domElement, VNodeDetail &node) domElement.appendChild(nod); } -QDomNode VToolUnionDetails::UpdateDetail(QDomNode &domNode, VDetail &d) +QDomNode VToolUnionDetails::UpdateDetail(const QDomNode &domNode, const VDetail &d) { //QDomNode domNode = domElement.firstChild(); while (domNode.isNull() == false) @@ -655,10 +717,12 @@ QDomNode VToolUnionDetails::UpdateDetail(QDomNode &domNode, VDetail &d) { if (domElement.tagName() == VToolUnionDetails::TagDetail) { + doc->removeAllChilds(domElement);//delete all nodes in detail for (ptrdiff_t i = 0; i < d.CountNode(); ++i) { - UpdateNode(domElement, d[i]); + AddNode(domElement, d.at(i));//rewrite nodes of detail } + break; } } } @@ -666,53 +730,6 @@ QDomNode VToolUnionDetails::UpdateDetail(QDomNode &domNode, VDetail &d) return domNode.nextSibling(); } -void VToolUnionDetails::UpdateNode(QDomNode &domNode, VNodeDetail &node) -{ - while (domNode.isNull() == false) - { - if (domNode.isElement()) - { - QDomElement domElement = domNode.toElement(); - if (domElement.isNull() == false) - { - if (domElement.tagName() == VToolUnionDetails::TagNode) - { - domElement.setAttribute( AttrIdObject, node.getId()); - domElement.setAttribute(AttrMx, toMM(node.getMx())); - domElement.setAttribute(AttrMy, toMM(node.getMy())); - if (node.getTypeNode() == NodeDetail::Contour) - { - domElement.setAttribute(AttrNodeType, NodeTypeContour); - } - else - { - domElement.setAttribute(AttrNodeType, NodeTypeModeling); - } - switch (node.getTypeTool()) - { - case (Tool::NodeArc): - domElement.setAttribute(AttrType, QStringLiteral("NodeArc")); - break; - case (Tool::NodePoint): - domElement.setAttribute(AttrType, QStringLiteral("NodePoint")); - break; - case (Tool::NodeSpline): - domElement.setAttribute(AttrType, QStringLiteral("NodeSpline")); - break; - case (Tool::NodeSplinePath): - domElement.setAttribute(AttrType, QStringLiteral("NodeSplinePath")); - break; - default: - qWarning()<<"May be wrong tool type!!! Ignoring."< GetDetailFromFile(VDomDocument *doc, const QDomElement &domElement); /** * @brief TagName @@ -70,27 +70,21 @@ public: static const QString ToolType; static const QString TagDetail; static const QString TagNode; - static const QString AttrD1P1; - static const QString AttrD1P2; - static const QString AttrD2P1; - static const QString AttrD2P2; + static const QString AttrIndexD1; + static const QString AttrIndexD2; static const QString AttrIdObject; static const QString AttrNodeType; static const QString NodeTypeContour; static const QString NodeTypeModeling; - inline qint64 getD1P1() const{return d1P1;} - inline qint64 getD1P2() const{return d1P2;} - inline qint64 getD2P1() const{return d2P1;} - inline qint64 getD2P2() const{return d2P2;} - void AddToNewDetail(VContainer *data, VDetail newDetail, const VDetail &det, const ptrdiff_t &a, - const ptrdiff_t &b, const qreal &dx = 0, const qreal &dy = 0, const qint64 &pRotate = 0, - const qreal &angle = 0) const; - void UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &a, - const ptrdiff_t &b, const qreal &dx = 0, const qreal &dy = 0, const qint64 &pRotate = 0, - const qreal &angle = 0) const; - void BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate, - const qreal angle)const; + static void AddToNewDetail(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 @@ -109,17 +103,12 @@ private: Q_DISABLE_COPY(VToolUnionDetails) VDetail d1; VDetail d2; - qint64 d1P1; - qint64 d1P2; - qint64 d2P1; - qint64 d2P2; + ptrdiff_t indexD1; + ptrdiff_t indexD2; void AddDetail(QDomElement &domElement, VDetail &d); - void AddNode(QDomElement &domElement, VNodeDetail &node); - QDomNode UpdateDetail(QDomNode &domNode, VDetail &d); - void UpdateNode(QDomNode &domNode, VNodeDetail &node); + void AddNode(QDomElement &domElement, const VNodeDetail &node); + QDomNode UpdateDetail(const QDomNode &domNode, const VDetail &d); void AddToModeling(const QDomElement &domElement); - void CorectPoints(const VDetail &detail, qint64 &p1, qint64 &p2); - }; #endif // VTOOLUNIONDETAILS_H 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 f5fb29fc1..549de7d16 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -40,20 +40,20 @@ #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){} @@ -78,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")) @@ -510,7 +527,7 @@ void VDomDocument::ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphics { if (domElement.tagName() == "calculation") { - data->ClearObject(); + data->ClearCalculationGObjects(); ParseDrawMode(sceneDraw, sceneDetail, domElement, parse, Draw::Calculation); } if (domElement.tagName() == "modeling") @@ -891,12 +908,13 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen { qint64 id = GetParametrId(domElement); 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); + VNodePoint::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); return; } catch (const VExceptionBadId &e) @@ -1122,11 +1140,12 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme { qint64 id = GetParametrId(domElement); 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); + VNodeSpline::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); return; } catch (const VExceptionBadId &e) @@ -1142,11 +1161,12 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme { qint64 id = GetParametrId(domElement); 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); + VNodeSplinePath::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); return; } catch (const VExceptionBadId &e) @@ -1191,11 +1211,12 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement { qint64 id = GetParametrId(domElement); 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); + VNodeArc::Create(this, data, id, idObject, parse, Tool::FromFile, idTool); return; } catch (const VExceptionBadId &e) @@ -1218,14 +1239,12 @@ void VDomDocument::ParseToolsElement(VMainGraphicsScene *scene, const QDomElemen try { qint64 id = GetParametrId(domElement); - qint64 d1P1 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD1P1, "0"); - qint64 d1P2 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD1P2, "0"); - qint64 d2P1 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD2P1, "0"); - qint64 d2P2 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD2P2, "0"); + 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, d1P1, d1P2, d2P1, d2P2, scene, this, data, parse, + VToolUnionDetails::Create(id, vector[0], vector[1], 0, 0, indexD1, indexD2, scene, this, data, parse, Tool::FromFile); return; @@ -1245,7 +1264,7 @@ void VDomDocument::FullUpdateTree() 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 8b69b8ad3..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 */ From 75b125194bd82b7454f77c51a40ff8f8a86c7305 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 2 Jan 2014 19:16:16 +0200 Subject: [PATCH 15/15] Tried fix some memory leaks. --HG-- branch : feature --- src/container/vcontainer.h | 2 +- src/tools/nodeDetails/vabstractnode.cpp | 4 ++-- src/tools/nodeDetails/vabstractnode.h | 2 +- src/tools/nodeDetails/vnodearc.cpp | 12 +++++++---- src/tools/nodeDetails/vnodearc.h | 5 +++-- src/tools/nodeDetails/vnodepoint.cpp | 18 +++++++++++----- src/tools/nodeDetails/vnodepoint.h | 6 ++++-- src/tools/nodeDetails/vnodespline.cpp | 13 ++++++++---- src/tools/nodeDetails/vnodespline.h | 5 +++-- src/tools/nodeDetails/vnodesplinepath.cpp | 14 ++++++++---- src/tools/nodeDetails/vnodesplinepath.h | 5 +++-- src/tools/vabstracttool.cpp | 4 ++-- src/tools/vabstracttool.h | 2 +- src/tools/vtooldetail.cpp | 2 +- src/tools/vtooldetail.h | 2 +- src/tools/vtooluniondetails.cpp | 26 ++++++++++++----------- src/tools/vtooluniondetails.h | 8 +++---- 17 files changed, 80 insertions(+), 50 deletions(-) diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index d4ef49161..87f5ce1ab 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -160,7 +160,7 @@ public: * @param name name of row of standart table * @param cell row of standart table */ - inline void AddStandartTableCell(const QString& name, VStandartTableRow cell) + inline void AddStandartTableCell(const QString& name, const VStandartTableRow &cell) {standartTable[name] = cell;} /** * @brief AddIncrementTableRow add new row of increment table diff --git a/src/tools/nodeDetails/vabstractnode.cpp b/src/tools/nodeDetails/vabstractnode.cpp index f2920e388..0b964aea2 100644 --- a/src/tools/nodeDetails/vabstractnode.cpp +++ b/src/tools/nodeDetails/vabstractnode.cpp @@ -33,8 +33,8 @@ const QString VAbstractNode::AttrIdObject = QStringLiteral("idObject"); const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool"); VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &idNode, - const qint64 &idTool) - : VAbstractTool(doc, data, id), idNode(idNode), idTool(idTool) + 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 fce0527fe..f4726933f 100644 --- a/src/tools/nodeDetails/vabstractnode.h +++ b/src/tools/nodeDetails/vabstractnode.h @@ -47,7 +47,7 @@ public: * @param parent */ VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &idNode, - const qint64 &idTool); + const qint64 &idTool, QObject *parent = 0); virtual ~VAbstractNode() {} /** * @brief AttrIdObject diff --git a/src/tools/nodeDetails/vnodearc.cpp b/src/tools/nodeDetails/vnodearc.cpp index eb7244526..ae9d6a66c 100644 --- a/src/tools/nodeDetails/vnodearc.cpp +++ b/src/tools/nodeDetails/vnodearc.cpp @@ -34,8 +34,8 @@ 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, - const qint64 &idTool, QGraphicsItem * parent) - :VAbstractNode(doc, data, id, idArc, idTool), QGraphicsPathItem(parent) + const qint64 &idTool, QObject *qoParent, QGraphicsItem *parent) + :VAbstractNode(doc, data, id, idArc, idTool, qoParent), QGraphicsPathItem(parent) { RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); @@ -51,17 +51,21 @@ VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, } void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse, - const Tool::Sources &typeCreation, const qint64 &idTool) + 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, idTool); + VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, idTool, parent); Q_ASSERT(arc != 0); doc->AddTool(id, arc); 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 { diff --git a/src/tools/nodeDetails/vnodearc.h b/src/tools/nodeDetails/vnodearc.h index 1fe760f30..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, const qint64 &idTool = 0, 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 qint64 &idTool = 0); + const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *parent = 0); /** * @brief TagName */ diff --git a/src/tools/nodeDetails/vnodepoint.cpp b/src/tools/nodeDetails/vnodepoint.cpp index aaf0bd1a7..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, const qint64 &idTool, QGraphicsItem *parent) - :VAbstractNode(doc, data, id, idPoint, idTool), 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); @@ -58,17 +59,24 @@ VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 id } void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool) + 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, idTool); + //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); 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 { diff --git a/src/tools/nodeDetails/vnodepoint.h b/src/tools/nodeDetails/vnodepoint.h index 2657ec20d..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, const qint64 &idTool = 0, 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 qint64 &idTool = 0); + const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0, + QObject *parent = 0); /** * @brief TagName */ diff --git a/src/tools/nodeDetails/vnodespline.cpp b/src/tools/nodeDetails/vnodespline.cpp index 8916c819b..22255e243 100644 --- a/src/tools/nodeDetails/vnodespline.cpp +++ b/src/tools/nodeDetails/vnodespline.cpp @@ -34,8 +34,9 @@ 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, const qint64 &idTool, QGraphicsItem * parent) - :VAbstractNode(doc, data, id, idSpline, idTool), 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)); @@ -52,17 +53,21 @@ VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 VNodeSpline *VNodeSpline::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, const Document::Documents &parse, const Tool::Sources &typeCreation, - const qint64 &idTool) + 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, idTool); + spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, idTool, parent); doc->AddTool(id, spl); 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 { diff --git a/src/tools/nodeDetails/vnodespline.h b/src/tools/nodeDetails/vnodespline.h index 1c42e4f7b..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, const qint64 &idTool = 0, QGraphicsItem * parent = 0); + const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0, + QGraphicsItem * parent = 0); /** * @brief Create * @param doc dom document container @@ -62,7 +63,7 @@ public: */ static VNodeSpline *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, const Document::Documents &parse, const Tool::Sources &typeCreation, - const qint64 &idTool = 0); + const qint64 &idTool = 0, QObject *parent = 0); /** * @brief TagName */ diff --git a/src/tools/nodeDetails/vnodesplinepath.cpp b/src/tools/nodeDetails/vnodesplinepath.cpp index 020de500d..f73420ee6 100644 --- a/src/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/tools/nodeDetails/vnodesplinepath.cpp @@ -34,8 +34,9 @@ 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, const qint64 &idTool, QGraphicsItem * parent) - :VAbstractNode(doc, data, id, idSpline, idTool), 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)); @@ -51,12 +52,13 @@ VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, } void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool) + 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, idTool); + VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, idTool, parent); Q_ASSERT(splPath != 0); doc->AddTool(id, splPath); const VSplinePath *path = data->GeometricObject(id); @@ -66,6 +68,10 @@ void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qin 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 { diff --git a/src/tools/nodeDetails/vnodesplinepath.h b/src/tools/nodeDetails/vnodesplinepath.h index 7ffcbaee6..2d7721442 100644 --- a/src/tools/nodeDetails/vnodesplinepath.h +++ b/src/tools/nodeDetails/vnodesplinepath.h @@ -49,7 +49,7 @@ public: * @param parent */ VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - const Tool::Sources &typeCreation, const qint64 &idTool = 0, + const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0, QGraphicsItem * parent = 0); /** * @brief Create @@ -61,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 qint64 &idTool = 0); + const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0, + QObject *parent = 0); /** * @brief TagName */ diff --git a/src/tools/vabstracttool.cpp b/src/tools/vabstracttool.cpp index 5fc75916f..62e5260f6 100644 --- a/src/tools/vabstracttool.cpp +++ b/src/tools/vabstracttool.cpp @@ -65,8 +65,8 @@ const QString VAbstractTool::AttrAxisP2 = QStringLiteral("axisP2"); const QString VAbstractTool::TypeLineNone = QStringLiteral("none"); const QString VAbstractTool::TypeLineLine = QStringLiteral("hair"); -VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id) - :VDataTool(data), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black) +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); diff --git a/src/tools/vabstracttool.h b/src/tools/vabstracttool.h index 8d6412db7..109ce08a4 100644 --- a/src/tools/vabstracttool.h +++ b/src/tools/vabstracttool.h @@ -46,7 +46,7 @@ public: * @param id * @param parent */ - VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id); + VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); virtual ~VAbstractTool() {} /** * @brief LineIntersectRect diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index f71db07a8..dc4198f91 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -130,7 +130,7 @@ 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; diff --git a/src/tools/vtooldetail.h b/src/tools/vtooldetail.h index 5b9891af1..5ec8032a6 100644 --- a/src/tools/vtooldetail.h +++ b/src/tools/vtooldetail.h @@ -84,7 +84,7 @@ public: * @param parse * @param typeCreation */ - static void Create(const qint64 _id, VDetail newDetail, VMainGraphicsScene *scene, + static void Create(const qint64 &_id, const VDetail &newDetail, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation); template diff --git a/src/tools/vtooluniondetails.cpp b/src/tools/vtooluniondetails.cpp index 1c62d666f..b7b30cb5e 100644 --- a/src/tools/vtooluniondetails.cpp +++ b/src/tools/vtooluniondetails.cpp @@ -43,8 +43,8 @@ const QString VToolUnionDetails::NodeTypeModeling = QStringLiteral("Modeling"); VToolUnionDetails::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) - :VAbstractTool(doc, data, id), d1(d1), d2(d2), indexD1(indexD1), indexD2(indexD2) + const Tool::Sources &typeCreation, QObject *parent) + :VAbstractTool(doc, data, id, parent), d1(d1), d2(d2), indexD1(indexD1), indexD2(indexD2) { if (typeCreation == Tool::FromGui) { @@ -56,9 +56,9 @@ VToolUnionDetails::VToolUnionDetails(VDomDocument *doc, VContainer *data, const } } -void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDetail &newDetail, const VDetail &det, - const ptrdiff_t &i, const qint64 &idTool, const qreal &dx, const qreal &dy, - const qint64 &pRotate, const qreal &angle) +void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContainer *data, VDetail &newDetail, + const VDetail &det, const ptrdiff_t &i, const qint64 &idTool, const qreal &dx, + const qreal &dy, const qint64 &pRotate, const qreal &angle) { qint64 id = 0, idObject = 0; switch (det.at(i).getTypeTool()) @@ -81,7 +81,7 @@ void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDet Q_ASSERT(point1 != 0); point1->setMode(Draw::Modeling); id = data->AddGObject(point1); - VNodePoint::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool); + VNodePoint::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); } } break; @@ -119,7 +119,7 @@ void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDet arc2->setMode(Draw::Modeling); id = data->AddGObject(arc2); - VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool); + VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); } } break; @@ -158,7 +158,7 @@ void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDet Q_ASSERT(spl1 != 0); spl1->setMode(Draw::Modeling); idObject = data->AddGObject(spl1); - VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool); + VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); } } break; @@ -215,7 +215,7 @@ void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDet Q_ASSERT(path1 != 0); path1->setMode(Draw::Modeling); id = data->AddGObject(path1); - VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool); + VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool); } } break; @@ -390,6 +390,7 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) { + VToolUnionDetails *unionDetails = 0; qint64 id = _id; if (typeCreation == Tool::FromGui) { @@ -405,7 +406,8 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai VAbstractTool::AddRecord(id, Tool::UnionDetails, doc); if (parse == Document::FullParse) { - VToolUnionDetails *unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation); + //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) @@ -429,7 +431,7 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai do { - AddToNewDetail(doc, data, newDetail, d1, i, id); + AddToNewDetail(unionDetails, doc, data, newDetail, d1, i, id); ++i; if (i > indexD1 && pointsD2 < nD2-2) { @@ -483,7 +485,7 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai { j=0; } - AddToNewDetail(doc, data, newDetail, d2, j, id, dx, dy, det1p1.getId(), angle); + AddToNewDetail(unionDetails, doc, data, newDetail, d2, j, id, dx, dy, det1p1.getId(), angle); ++pointsD2; ++j; } while (pointsD2 < nD2); diff --git a/src/tools/vtooluniondetails.h b/src/tools/vtooluniondetails.h index 225ebc4bd..4d5b8af37 100644 --- a/src/tools/vtooluniondetails.h +++ b/src/tools/vtooluniondetails.h @@ -38,7 +38,7 @@ class VToolUnionDetails : public VAbstractTool 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); + const Tool::Sources &typeCreation, QObject *parent = 0); virtual void setDialog() {} /** * @brief Create @@ -77,9 +77,9 @@ public: static const QString NodeTypeContour; static const QString NodeTypeModeling; - static void AddToNewDetail(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 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);