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 */