From 6956d309bd3262839848c0b4062acde7296c4696 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 10 Sep 2013 15:29:06 +0300 Subject: [PATCH] Big change in architecture of tools. Add modeling tools. --- Valentina.pro | 121 ++++++--- container/calculator.cpp | 4 +- container/vcontainer.cpp | 217 +++++++++++---- container/vcontainer.h | 43 +-- dialogs/dialogalongline.cpp | 22 +- dialogs/dialogalongline.h | 3 +- dialogs/dialogarc.cpp | 22 +- dialogs/dialogarc.h | 2 +- dialogs/dialogbisector.cpp | 22 +- dialogs/dialogbisector.h | 10 +- dialogs/dialogdetail.cpp | 90 +++++-- dialogs/dialogdetail.h | 7 +- dialogs/dialogendline.cpp | 30 ++- dialogs/dialogendline.h | 13 +- dialogs/dialoghistory.cpp | 2 +- dialogs/dialogincrements.cpp | 11 +- dialogs/dialogincrements.h | 6 +- dialogs/dialogline.cpp | 28 +- dialogs/dialogline.h | 13 +- dialogs/dialoglineintersect.cpp | 30 ++- dialogs/dialoglineintersect.h | 9 +- dialogs/dialognormal.cpp | 30 ++- dialogs/dialognormal.h | 15 +- dialogs/dialogpointofcontact.cpp | 28 +- dialogs/dialogpointofcontact.h | 15 +- dialogs/dialogs.h | 20 ++ dialogs/dialogshoulderpoint.cpp | 28 +- dialogs/dialogshoulderpoint.h | 15 +- dialogs/dialogsinglepoint.cpp | 11 +- dialogs/dialogsinglepoint.h | 4 +- dialogs/dialogspline.cpp | 44 +++- dialogs/dialogspline.h | 5 +- dialogs/dialogsplinepath.cpp | 30 ++- dialogs/dialogsplinepath.h | 13 +- dialogs/dialogtool.cpp | 69 +++-- dialogs/dialogtool.h | 20 +- geometry/vdetail.cpp | 10 + geometry/vdetail.h | 1 + geometry/vnodedetail.cpp | 21 +- geometry/vnodedetail.h | 22 +- geometry/vspline.cpp | 20 ++ mainwindow.cpp | 112 +++++--- mainwindow.h | 208 +++++++-------- options.h | 9 +- stable.h | 36 ++- tools/drawTools/drawtools.h | 17 ++ tools/drawTools/vdrawtool.cpp | 79 ++++++ tools/drawTools/vdrawtool.h | 70 +++++ tools/{ => drawTools}/vtoolalongline.cpp | 34 +-- tools/{ => drawTools}/vtoolalongline.h | 11 +- tools/{ => drawTools}/vtoolarc.cpp | 38 +-- tools/drawTools/vtoolarc.h | 39 +++ tools/{ => drawTools}/vtoolbisector.cpp | 30 +-- tools/{ => drawTools}/vtoolbisector.h | 11 +- tools/{ => drawTools}/vtoolendline.cpp | 35 +-- tools/{ => drawTools}/vtoolendline.h | 11 +- tools/{ => drawTools}/vtoolline.cpp | 30 +-- tools/{ => drawTools}/vtoolline.h | 18 +- tools/{ => drawTools}/vtoollineintersect.cpp | 37 +-- tools/{ => drawTools}/vtoollineintersect.h | 15 +- tools/{ => drawTools}/vtoollinepoint.cpp | 20 +- tools/{ => drawTools}/vtoollinepoint.h | 14 +- tools/{ => drawTools}/vtoolnormal.cpp | 34 +-- tools/{ => drawTools}/vtoolnormal.h | 15 +- tools/drawTools/vtoolpoint.cpp | 125 +++++++++ tools/drawTools/vtoolpoint.h | 34 +++ tools/{ => drawTools}/vtoolpointofcontact.cpp | 29 +- tools/{ => drawTools}/vtoolpointofcontact.h | 8 +- tools/{ => drawTools}/vtoolshoulderpoint.cpp | 34 +-- tools/{ => drawTools}/vtoolshoulderpoint.h | 14 +- tools/{ => drawTools}/vtoolsinglepoint.cpp | 33 +-- tools/drawTools/vtoolsinglepoint.h | 30 +++ tools/{ => drawTools}/vtoolspline.cpp | 39 +-- tools/{ => drawTools}/vtoolspline.h | 26 +- tools/{ => drawTools}/vtoolsplinepath.cpp | 26 +- tools/{ => drawTools}/vtoolsplinepath.h | 26 +- tools/modelingTools/modelingtools.h | 17 ++ tools/modelingTools/vmodelingalongline.cpp | 133 ++++++++++ tools/modelingTools/vmodelingalongline.h | 34 +++ tools/modelingTools/vmodelingarc.cpp | 150 +++++++++++ tools/modelingTools/vmodelingarc.h | 36 +++ tools/modelingTools/vmodelingbisector.cpp | 150 +++++++++++ tools/modelingTools/vmodelingbisector.h | 38 +++ tools/modelingTools/vmodelingendline.cpp | 125 +++++++++ tools/modelingTools/vmodelingendline.h | 33 +++ tools/modelingTools/vmodelingline.cpp | 103 ++++++++ tools/modelingTools/vmodelingline.h | 33 +++ .../modelingTools/vmodelinglineintersect.cpp | 128 +++++++++ tools/modelingTools/vmodelinglineintersect.h | 39 +++ tools/modelingTools/vmodelinglinepoint.cpp | 31 +++ tools/modelingTools/vmodelinglinepoint.h | 25 ++ tools/modelingTools/vmodelingnormal.cpp | 142 ++++++++++ tools/modelingTools/vmodelingnormal.h | 37 +++ tools/modelingTools/vmodelingpoint.cpp | 86 ++++++ tools/modelingTools/vmodelingpoint.h | 32 +++ .../modelingTools/vmodelingpointofcontact.cpp | 151 +++++++++++ tools/modelingTools/vmodelingpointofcontact.h | 38 +++ .../modelingTools/vmodelingshoulderpoint.cpp | 159 +++++++++++ tools/modelingTools/vmodelingshoulderpoint.h | 37 +++ tools/modelingTools/vmodelingsinglepoint.cpp | 93 +++++++ tools/modelingTools/vmodelingsinglepoint.h | 29 ++ tools/modelingTools/vmodelingspline.cpp | 219 ++++++++++++++++ tools/modelingTools/vmodelingspline.h | 47 ++++ tools/modelingTools/vmodelingsplinepath.cpp | 245 +++++++++++++++++ tools/modelingTools/vmodelingsplinepath.h | 49 ++++ tools/modelingTools/vmodelingtool.cpp | 26 ++ tools/modelingTools/vmodelingtool.h | 63 +++++ tools/nodeDetails/nodedetails.h | 9 + tools/nodeDetails/vabstractnode.cpp | 21 ++ tools/nodeDetails/vabstractnode.h | 19 ++ tools/nodeDetails/vnodearc.cpp | 70 +++++ tools/nodeDetails/vnodearc.h | 26 ++ tools/nodeDetails/vnodepoint.cpp | 118 +++++++++ tools/nodeDetails/vnodepoint.h | 34 +++ tools/nodeDetails/vnodespline.cpp | 70 +++++ tools/nodeDetails/vnodespline.h | 26 ++ tools/nodeDetails/vnodesplinepath.cpp | 72 +++++ tools/nodeDetails/vnodesplinepath.h | 26 ++ tools/tools.h | 7 + tools/vabstracttool.cpp | 155 ++++++----- tools/vabstracttool.h | 102 ++------ tools/vdatatool.cpp | 3 - tools/vdatatool.h | 5 +- tools/vgraphicspoint.cpp | 39 +++ tools/vgraphicspoint.h | 35 +++ tools/vmodelingarc.cpp | 96 ------- tools/vmodelingarc.h | 30 --- tools/vmodelingpoint.cpp | 55 ---- tools/vmodelingpoint.h | 24 -- tools/vmodelingspline.cpp | 97 ------- tools/vmodelingspline.h | 30 --- tools/vmodelingsplinepath.cpp | 98 ------- tools/vmodelingsplinepath.h | 30 --- tools/vtoolarc.h | 45 ---- tools/vtooldetail.cpp | 247 ++++++++++++++---- tools/vtooldetail.h | 17 +- tools/vtoolpoint.cpp | 240 ----------------- tools/vtoolpoint.h | 48 ---- tools/vtoolsimplepoint.cpp | 9 - tools/vtoolsimplepoint.h | 21 -- tools/vtoolsinglepoint.h | 37 --- widgets/vgraphicssimpletextitem.cpp | 22 +- widgets/vgraphicssimpletextitem.h | 6 - widgets/vmaingraphicsscene.cpp | 3 - widgets/vmaingraphicsscene.h | 5 +- xml/vdomdocument.cpp | 211 ++++++++++----- xml/vdomdocument.h | 16 +- 147 files changed, 5124 insertions(+), 2101 deletions(-) create mode 100644 dialogs/dialogs.h create mode 100644 tools/drawTools/drawtools.h create mode 100644 tools/drawTools/vdrawtool.cpp create mode 100644 tools/drawTools/vdrawtool.h rename tools/{ => drawTools}/vtoolalongline.cpp (83%) rename tools/{ => drawTools}/vtoolalongline.h (81%) rename tools/{ => drawTools}/vtoolarc.cpp (83%) create mode 100644 tools/drawTools/vtoolarc.h rename tools/{ => drawTools}/vtoolbisector.cpp (87%) rename tools/{ => drawTools}/vtoolbisector.h (84%) rename tools/{ => drawTools}/vtoolendline.cpp (83%) rename tools/{ => drawTools}/vtoolendline.h (80%) rename tools/{ => drawTools}/vtoolline.cpp (82%) rename tools/{ => drawTools}/vtoolline.h (66%) rename tools/{ => drawTools}/vtoollineintersect.cpp (83%) rename tools/{ => drawTools}/vtoollineintersect.h (80%) rename tools/{ => drawTools}/vtoollinepoint.cpp (59%) rename tools/{ => drawTools}/vtoollinepoint.h (67%) rename tools/{ => drawTools}/vtoolnormal.cpp (84%) rename tools/{ => drawTools}/vtoolnormal.h (77%) create mode 100644 tools/drawTools/vtoolpoint.cpp create mode 100644 tools/drawTools/vtoolpoint.h rename tools/{ => drawTools}/vtoolpointofcontact.cpp (88%) rename tools/{ => drawTools}/vtoolpointofcontact.h (88%) rename tools/{ => drawTools}/vtoolshoulderpoint.cpp (86%) rename tools/{ => drawTools}/vtoolshoulderpoint.h (77%) rename tools/{ => drawTools}/vtoolsinglepoint.cpp (75%) create mode 100644 tools/drawTools/vtoolsinglepoint.h rename tools/{ => drawTools}/vtoolspline.cpp (90%) rename tools/{ => drawTools}/vtoolspline.h (75%) rename tools/{ => drawTools}/vtoolsplinepath.cpp (94%) rename tools/{ => drawTools}/vtoolsplinepath.h (76%) create mode 100644 tools/modelingTools/modelingtools.h create mode 100644 tools/modelingTools/vmodelingalongline.cpp create mode 100644 tools/modelingTools/vmodelingalongline.h create mode 100644 tools/modelingTools/vmodelingarc.cpp create mode 100644 tools/modelingTools/vmodelingarc.h create mode 100644 tools/modelingTools/vmodelingbisector.cpp create mode 100644 tools/modelingTools/vmodelingbisector.h create mode 100644 tools/modelingTools/vmodelingendline.cpp create mode 100644 tools/modelingTools/vmodelingendline.h create mode 100644 tools/modelingTools/vmodelingline.cpp create mode 100644 tools/modelingTools/vmodelingline.h create mode 100644 tools/modelingTools/vmodelinglineintersect.cpp create mode 100644 tools/modelingTools/vmodelinglineintersect.h create mode 100644 tools/modelingTools/vmodelinglinepoint.cpp create mode 100644 tools/modelingTools/vmodelinglinepoint.h create mode 100644 tools/modelingTools/vmodelingnormal.cpp create mode 100644 tools/modelingTools/vmodelingnormal.h create mode 100644 tools/modelingTools/vmodelingpoint.cpp create mode 100644 tools/modelingTools/vmodelingpoint.h create mode 100644 tools/modelingTools/vmodelingpointofcontact.cpp create mode 100644 tools/modelingTools/vmodelingpointofcontact.h create mode 100644 tools/modelingTools/vmodelingshoulderpoint.cpp create mode 100644 tools/modelingTools/vmodelingshoulderpoint.h create mode 100644 tools/modelingTools/vmodelingsinglepoint.cpp create mode 100644 tools/modelingTools/vmodelingsinglepoint.h create mode 100644 tools/modelingTools/vmodelingspline.cpp create mode 100644 tools/modelingTools/vmodelingspline.h create mode 100644 tools/modelingTools/vmodelingsplinepath.cpp create mode 100644 tools/modelingTools/vmodelingsplinepath.h create mode 100644 tools/modelingTools/vmodelingtool.cpp create mode 100644 tools/modelingTools/vmodelingtool.h create mode 100644 tools/nodeDetails/nodedetails.h create mode 100644 tools/nodeDetails/vabstractnode.cpp create mode 100644 tools/nodeDetails/vabstractnode.h create mode 100644 tools/nodeDetails/vnodearc.cpp create mode 100644 tools/nodeDetails/vnodearc.h create mode 100644 tools/nodeDetails/vnodepoint.cpp create mode 100644 tools/nodeDetails/vnodepoint.h create mode 100644 tools/nodeDetails/vnodespline.cpp create mode 100644 tools/nodeDetails/vnodespline.h create mode 100644 tools/nodeDetails/vnodesplinepath.cpp create mode 100644 tools/nodeDetails/vnodesplinepath.h create mode 100644 tools/tools.h create mode 100644 tools/vgraphicspoint.cpp create mode 100644 tools/vgraphicspoint.h delete mode 100644 tools/vmodelingarc.cpp delete mode 100644 tools/vmodelingarc.h delete mode 100644 tools/vmodelingpoint.cpp delete mode 100644 tools/vmodelingpoint.h delete mode 100644 tools/vmodelingspline.cpp delete mode 100644 tools/vmodelingspline.h delete mode 100644 tools/vmodelingsplinepath.cpp delete mode 100644 tools/vmodelingsplinepath.h delete mode 100644 tools/vtoolarc.h delete mode 100644 tools/vtoolpoint.cpp delete mode 100644 tools/vtoolpoint.h delete mode 100644 tools/vtoolsimplepoint.cpp delete mode 100644 tools/vtoolsimplepoint.h delete mode 100644 tools/vtoolsinglepoint.h diff --git a/Valentina.pro b/Valentina.pro index 699a49bc1..c232a6a3c 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -10,7 +10,8 @@ QT += core gui widgets xml svg printsupport TARGET = Valentina TEMPLATE = app -CONFIG += precompile_header +CONFIG += precompile_header +CONFIG -= debug_and_release debug_and_release_target SOURCES += main.cpp\ mainwindow.cpp \ @@ -19,7 +20,7 @@ SOURCES += main.cpp\ xml/vdomdocument.cpp \ container/vpointf.cpp \ container/vcontainer.cpp \ - tools/vtoolpoint.cpp \ + tools/drawTools/vtoolpoint.cpp \ container/calculator.cpp \ dialogs/dialogincrements.cpp \ container/vstandarttablecell.cpp \ @@ -27,52 +28,68 @@ SOURCES += main.cpp\ widgets/delegate.cpp \ widgets/doubledelegate.cpp \ dialogs/dialogendline.cpp \ - tools/vtoolendline.cpp \ - tools/vtoolline.cpp \ + tools/drawTools/vtoolendline.cpp \ + tools/drawTools/vtoolline.cpp \ tools/vabstracttool.cpp \ dialogs/dialogline.cpp \ - tools/vtoolalongline.cpp \ + tools/drawTools/vtoolalongline.cpp \ dialogs/dialogtool.cpp \ dialogs/dialogalongline.cpp \ - tools/vtoolshoulderpoint.cpp \ + tools/drawTools/vtoolshoulderpoint.cpp \ dialogs/dialogshoulderpoint.cpp \ - tools/vtoolnormal.cpp \ + tools/drawTools/vtoolnormal.cpp \ dialogs/dialognormal.cpp \ - tools/vtoolbisector.cpp \ + tools/drawTools/vtoolbisector.cpp \ dialogs/dialogbisector.cpp \ - tools/vtoollinepoint.cpp \ - tools/vtoollineintersect.cpp \ + tools/drawTools/vtoollinepoint.cpp \ + tools/drawTools/vtoollineintersect.cpp \ dialogs/dialoglineintersect.cpp \ geometry/vspline.cpp \ - tools/vtoolsinglepoint.cpp \ + tools/drawTools/vtoolsinglepoint.cpp \ geometry/varc.cpp \ widgets/vcontrolpointspline.cpp \ - tools/vtoolspline.cpp \ + tools/drawTools/vtoolspline.cpp \ dialogs/dialogspline.cpp \ - tools/vtoolarc.cpp \ + tools/drawTools/vtoolarc.cpp \ dialogs/dialogarc.cpp \ geometry/vsplinepoint.cpp \ geometry/vsplinepath.cpp \ - tools/vtoolsplinepath.cpp \ + tools/drawTools/vtoolsplinepath.cpp \ dialogs/dialogsplinepath.cpp \ widgets/vmaingraphicsscene.cpp \ widgets/vmaingraphicsview.cpp \ tools/vdatatool.cpp \ xml/vtoolrecord.cpp \ dialogs/dialoghistory.cpp \ - tools/vtoolpointofcontact.cpp \ + tools/drawTools/vtoolpointofcontact.cpp \ dialogs/dialogpointofcontact.cpp \ geometry/vnodedetail.cpp \ geometry/vdetail.cpp \ dialogs/dialogdetail.cpp \ tools/vtooldetail.cpp \ - tools/vmodelingpoint.cpp \ - tools/vmodelingspline.cpp \ - tools/vmodelingarc.cpp \ - tools/vmodelingsplinepath.cpp \ widgets/vtablegraphicsview.cpp \ widgets/vitem.cpp \ - tablewindow.cpp + tablewindow.cpp \ + tools/nodeDetails/vnodearc.cpp \ + tools/nodeDetails/vnodepoint.cpp \ + tools/nodeDetails/vnodespline.cpp \ + tools/nodeDetails/vnodesplinepath.cpp \ + tools/drawTools/vdrawtool.cpp \ + tools/nodeDetails/vabstractnode.cpp \ + tools/modelingTools/vmodelingtool.cpp \ + tools/modelingTools/vmodelingalongline.cpp \ + tools/modelingTools/vmodelingarc.cpp \ + tools/modelingTools/vmodelingbisector.cpp \ + tools/modelingTools/vmodelingendline.cpp \ + tools/modelingTools/vmodelingline.cpp \ + tools/modelingTools/vmodelinglineintersect.cpp \ + tools/modelingTools/vmodelinglinepoint.cpp \ + tools/modelingTools/vmodelingnormal.cpp \ + tools/modelingTools/vmodelingpoint.cpp \ + tools/modelingTools/vmodelingpointofcontact.cpp \ + tools/modelingTools/vmodelingshoulderpoint.cpp \ + tools/modelingTools/vmodelingspline.cpp \ + tools/modelingTools/vmodelingsplinepath.cpp HEADERS += mainwindow.h \ widgets/vmaingraphicsscene.h \ @@ -82,7 +99,7 @@ HEADERS += mainwindow.h \ xml/vdomdocument.h \ container/vpointf.h \ container/vcontainer.h \ - tools/vtoolpoint.h \ + tools/drawTools/vtoolpoint.h \ container/calculator.h \ dialogs/dialogincrements.h \ container/vstandarttablecell.h \ @@ -90,51 +107,73 @@ HEADERS += mainwindow.h \ widgets/delegate.h \ widgets/doubledelegate.h \ dialogs/dialogendline.h \ - tools/vtoolendline.h \ - tools/vtoolline.h \ + tools/drawTools/vtoolendline.h \ + tools/drawTools/vtoolline.h \ tools/vabstracttool.h \ dialogs/dialogline.h \ - tools/vtoolalongline.h \ + tools/drawTools/vtoolalongline.h \ dialogs/dialogtool.h \ dialogs/dialogalongline.h \ - tools/vtoolshoulderpoint.h \ + tools/drawTools/vtoolshoulderpoint.h \ dialogs/dialogshoulderpoint.h \ - tools/vtoolnormal.h \ + tools/drawTools/vtoolnormal.h \ dialogs/dialognormal.h \ - tools/vtoolbisector.h \ + tools/drawTools/vtoolbisector.h \ dialogs/dialogbisector.h \ - tools/vtoollinepoint.h \ - tools/vtoollineintersect.h \ + tools/drawTools/vtoollinepoint.h \ + tools/drawTools/vtoollineintersect.h \ dialogs/dialoglineintersect.h \ geometry/vspline.h \ - tools/vtoolsinglepoint.h \ + tools/drawTools/vtoolsinglepoint.h \ geometry/varc.h \ widgets/vcontrolpointspline.h \ - tools/vtoolspline.h \ + tools/drawTools/vtoolspline.h \ dialogs/dialogspline.h \ - tools/vtoolarc.h \ + tools/drawTools/vtoolarc.h \ dialogs/dialogarc.h \ geometry/vsplinepoint.h \ geometry/vsplinepath.h \ - tools/vtoolsplinepath.h \ + tools/drawTools/vtoolsplinepath.h \ dialogs/dialogsplinepath.h \ widgets/vmaingraphicsview.h \ tools/vdatatool.h \ xml/vtoolrecord.h \ dialogs/dialoghistory.h \ - tools/vtoolpointofcontact.h \ + tools/drawTools/vtoolpointofcontact.h \ dialogs/dialogpointofcontact.h \ geometry/vnodedetail.h \ geometry/vdetail.h \ dialogs/dialogdetail.h \ tools/vtooldetail.h \ - tools/vmodelingpoint.h \ - tools/vmodelingspline.h \ - tools/vmodelingarc.h \ - tools/vmodelingsplinepath.h \ widgets/vtablegraphicsview.h \ widgets/vitem.h \ - tablewindow.h + tablewindow.h \ + tools/tools.h \ + tools/drawTools/drawtools.h \ + tools/nodeDetails/nodedetails.h \ + tools/nodeDetails/vnodearc.h \ + tools/nodeDetails/vnodepoint.h \ + tools/nodeDetails/vnodespline.h \ + tools/nodeDetails/vnodesplinepath.h \ + stable.h \ + tools/drawTools/vdrawtool.h \ + tools/nodeDetails/vabstractnode.h \ + dialogs/dialogs.h \ + tools/modelingTools/modelingtools.h \ + tools/modelingTools/vmodelingtool.h \ + tools/modelingTools/vmodelingalongline.h \ + tools/modelingTools/vmodelingarc.h \ + tools/modelingTools/vmodelingbisector.h \ + tools/modelingTools/vmodelingendline.h \ + tools/modelingTools/vmodelingline.h \ + tools/modelingTools/vmodelinglineintersect.h \ + tools/modelingTools/vmodelinglinepoint.h \ + tools/modelingTools/vmodelingnormal.h \ + tools/modelingTools/vmodelingpoint.h \ + tools/modelingTools/vmodelingpointofcontact.h \ + tools/modelingTools/vmodelingshoulderpoint.h \ + tools/modelingTools/vmodelingspline.h \ + tools/modelingTools/vmodelingsplinepath.h FORMS += mainwindow.ui \ dialogs/dialogsinglepoint.ui \ @@ -158,8 +197,6 @@ RESOURCES += \ icon.qrc \ cursor.qrc -CONFIG -= debug_and_release debug_and_release_target - # directory for executable file DESTDIR = bin @@ -176,7 +213,7 @@ RCC_DIR = rcc UI_DIR = uic # Use Precompiled headers (PCH) -PRECOMPILED_HEADER = stable.h +PRECOMPILED_HEADER = stable.h CONFIG(debug, debug|release){ # Debug diff --git a/container/calculator.cpp b/container/calculator.cpp index d24c70523..bb7e34588 100644 --- a/container/calculator.cpp +++ b/container/calculator.cpp @@ -26,12 +26,12 @@ qreal Calculator::eval(QString prog, QString *errorMsg){ this->errorMsg->clear(); debugFormula.clear(); this->prog = prog; - qDebug()<<"Формула: "< -#pragma GCC diagnostic pop -#include "../options.h" +#include "options.h" qint64 VContainer::_id = 0; @@ -150,32 +144,68 @@ void VContainer::UpdateId(qint64 newId){ } } -void VContainer::IncrementReferens(qint64 id, Scene::Type obj){ +void VContainer::IncrementReferens(qint64 id, Scene::Type obj, Draw::Mode mode){ switch( obj ){ case(Scene::Line): break; case(Scene::Point):{ - VPointF point = GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = GetPoint(id); + } else { + point = GetModelingPoint(id); + } point.incrementReferens(); - UpdatePoint(id, point); + if(mode == Draw::Calculation){ + UpdatePoint(id, point); + } else { + UpdateModelingPoint(id, point); + } } break; case(Scene::Arc):{ - VArc arc = GetArc(id); + VArc arc; + if(mode == Draw::Calculation){ + arc = GetArc(id); + } else { + arc = GetModelingArc(id); + } arc.incrementReferens(); - UpdateArc(id, arc); + if(mode == Draw::Calculation){ + UpdateArc(id, arc); + } else { + UpdateModelingArc(id, arc); + } } break; case(Scene::Spline):{ - VSpline spl = GetSpline(id); + VSpline spl; + if(mode == Draw::Calculation){ + spl = GetSpline(id); + } else { + spl = GetModelingSpline(id); + } spl.incrementReferens(); - UpdateSpline(id, spl); + if(mode == Draw::Calculation){ + UpdateSpline(id, spl); + } else { + UpdateModelingSpline(id, spl); + } } break; case(Scene::SplinePath):{ - VSplinePath splPath = GetSplinePath(id); + VSplinePath splPath; + if(mode == Draw::Calculation){ + splPath = GetSplinePath(id); + } else { + splPath = GetModelingSplinePath(id); + } splPath.incrementReferens(); - UpdateSplinePath(id, splPath); + if(mode == Draw::Calculation){ + UpdateSplinePath(id, splPath); + } else { + UpdateModelingSplinePath(id, splPath); + } } break; } @@ -186,26 +216,42 @@ QPainterPath VContainer::ContourPath(qint64 idDetail) const{ QVector points; for(qint32 i = 0; i< detail.CountNode(); ++i){ switch(detail[i].getTypeTool()){ - case(Scene::Line): - break; - case(Scene::Point):{ + case(Tools::NodePoint):{ VPointF point = GetModelingPoint(detail[i].getId()); points.append(point.toQPointF()); } break; - case(Scene::Arc):{ + case(Tools::NodeArc):{ VArc arc = GetModelingArc(detail[i].getId()); - points << arc.GetPoints(); + qreal len1 = GetLengthContour(points, arc.GetPoints()); + qreal lenReverse = GetLengthContour(points, GetReversePoint(arc.GetPoints())); + if(len1 <= lenReverse){ + points << arc.GetPoints(); + } else { + points << GetReversePoint(arc.GetPoints()); + } } break; - case(Scene::Spline):{ + case(Tools::NodeSpline):{ VSpline spline = GetModelingSpline(detail[i].getId()); - points << spline.GetPoints(); + qreal len1 = GetLengthContour(points, spline.GetPoints()); + qreal lenReverse = GetLengthContour(points, GetReversePoint(spline.GetPoints())); + if(len1 <= lenReverse){ + points << spline.GetPoints(); + } else { + points << GetReversePoint(spline.GetPoints()); + } } break; - case(Scene::SplinePath):{ + case(Tools::NodeSplinePath):{ VSplinePath splinePath = GetModelingSplinePath(detail[i].getId()); - points << splinePath.GetPathPoints(); + qreal len1 = GetLengthContour(points, splinePath.GetPathPoints()); + qreal lenReverse = GetLengthContour(points, GetReversePoint(splinePath.GetPathPoints())); + if(len1 <= lenReverse){ + points << splinePath.GetPathPoints(); + } else { + points << GetReversePoint(splinePath.GetPathPoints()); + } } break; } @@ -473,13 +519,20 @@ const QMap *VContainer::DataDetails() const{ return &details; } -void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId){ - QString nameLine = GetNameLine(firstPointId, secondPointId); - VPointF firstPoint = GetPoint(firstPointId); - VPointF secondPoint = GetPoint(secondPointId); - AddLengthLine(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length()/PrintDPI*25.4); - nameLine = GetNameLineAngle(firstPointId, secondPointId); - AddLineAngle(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).angle()); +void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId, Draw::Mode mode){ + QString nameLine = GetNameLine(firstPointId, secondPointId, mode); + VPointF first; + VPointF second; + if(mode == Draw::Calculation){ + first = GetPoint(firstPointId); + second = GetPoint(secondPointId); + } else { + first = GetModelingPoint(firstPointId); + second = GetModelingPoint(secondPointId); + } + AddLengthLine(nameLine, QLineF(first.toQPointF(), second.toQPointF()).length()/PrintDPI*25.4); + nameLine = GetNameLineAngle(firstPointId, secondPointId, mode); + AddLineAngle(nameLine, QLineF(first.toQPointF(), second.toQPointF()).angle()); } template @@ -525,41 +578,76 @@ qint64 VContainer::AddModelingArc(const VArc &arc){ return AddObject(modelingArcs, arc); } -QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const{ - VPointF first = GetPoint(firstPoint); - VPointF second = GetPoint(secondPoint); +QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint, Draw::Mode mode) const{ + VPointF first; + VPointF second; + if(mode == Draw::Calculation){ + first = GetPoint(firstPoint); + second = GetPoint(secondPoint); + } else { + first = GetModelingPoint(firstPoint); + second = GetModelingPoint(secondPoint); + } 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); +QString VContainer::GetNameLineAngle(const qint64 &firstPoint, const qint64 &secondPoint, + Draw::Mode mode) const{ + VPointF first; + VPointF second; + if(mode == Draw::Calculation){ + first = GetPoint(firstPoint); + second = GetPoint(secondPoint); + } else { + first = GetModelingPoint(firstPoint); + second = GetModelingPoint(secondPoint); + } return QString("AngleLine_%1_%2").arg(first.name(), second.name()); } -QString VContainer::GetNameSpline(const qint64 &firstPoint, const qint64 &secondPoint) const{ - VPointF first = GetPoint(firstPoint); - VPointF second = GetPoint(secondPoint); +QString VContainer::GetNameSpline(const qint64 &firstPoint, const qint64 &secondPoint, + Draw::Mode mode) const{ + VPointF first; + VPointF second; + if(mode == Draw::Calculation){ + first = GetPoint(firstPoint); + second = GetPoint(secondPoint); + } else { + first = GetModelingPoint(firstPoint); + second = GetModelingPoint(secondPoint); + } return QString("Spl_%1_%2").arg(first.name(), second.name()); } -QString VContainer::GetNameSplinePath(const VSplinePath &path) const{ +QString VContainer::GetNameSplinePath(const VSplinePath &path, Draw::Mode mode) const{ if(path.Count() == 0){ return QString(); } QString name("SplPath"); for(qint32 i = 1; i <= path.Count(); ++i){ VSpline spl = path.GetSpline(i); - VPointF first = GetPoint(spl.GetP1()); - VPointF second = GetPoint(spl.GetP4()); + VPointF first; + VPointF second; + if(mode == Draw::Calculation){ + first = GetPoint(spl.GetP1()); + second = GetPoint(spl.GetP4()); + } else { + first = GetModelingPoint(spl.GetP1()); + second = GetModelingPoint(spl.GetP4()); + } QString splName = QString("_%1_%2").arg(first.name(), second.name()); name.append(splName); } return name; } -QString VContainer::GetNameArc(const qint64 ¢er, const qint64 &id) const{ - VPointF centerPoint = GetPoint(center); +QString VContainer::GetNameArc(const qint64 ¢er, const qint64 &id, Draw::Mode mode) const{ + VPointF centerPoint; + if(mode == Draw::Calculation){ + centerPoint = GetPoint(center); + } else { + centerPoint = GetModelingPoint(center); + } return QString ("Arc(%1)%2").arg(centerPoint.name()).arg(id); } @@ -568,11 +656,18 @@ void VContainer::AddLengthLine(const QString &name, const qreal &value){ lengthLines[name] = value; } -void VContainer::AddLengthSpline(const qint64 &firstPointId, const qint64 &secondPointId){ - QString nameLine = GetNameSpline(firstPointId, secondPointId); - VPointF firstPoint = GetPoint(firstPointId); - VPointF secondPoint = GetPoint(secondPointId); - AddLengthSpline(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length()); +void VContainer::AddLengthSpline(const qint64 &firstPointId, const qint64 &secondPointId, Draw::Mode mode){ + QString nameLine = GetNameSpline(firstPointId, secondPointId, mode); + VPointF first; + VPointF second; + if(mode == Draw::Calculation){ + first = GetPoint(firstPointId); + second = GetPoint(secondPointId); + } else { + first = GetModelingPoint(firstPointId); + second = GetModelingPoint(secondPointId); + } + AddLengthSpline(nameLine, QLineF(first.toQPointF(), second.toQPointF()).length()); } void VContainer::CreateManTableIGroup (){ @@ -632,3 +727,23 @@ void VContainer::CreateManTableIGroup (){ AddStandartTableCell("DbII", VStandartTableCell(1020, 0, 44)); AddStandartTableCell("Sb", VStandartTableCell(504, 15, 4)); } + +QVector VContainer::GetReversePoint(const QVector &points) const{ + Q_ASSERT(points.size() > 0); + QVector reversePoints; + for (qint32 i = points.size() - 1; i >= 0; --i) { + reversePoints.append(points.at(i)); + } + return reversePoints; +} + +qreal VContainer::GetLengthContour(const QVector &contour, const QVector &newPoints) const{ + qreal length = 0; + QVector points; + points << contour << newPoints; + for (qint32 i = 0; i < points.size()-1; ++i) { + QLineF line(points.at(i), points.at(i+1)); + length += line.length(); + } + return length; +} diff --git a/container/vcontainer.h b/container/vcontainer.h index b0b0d053b..29dc43c76 100644 --- a/container/vcontainer.h +++ b/container/vcontainer.h @@ -1,23 +1,17 @@ #ifndef VCONTAINER_H #define VCONTAINER_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include #include -#pragma GCC diagnostic pop -#include "../options.h" +#include "options.h" #include "vpointf.h" #include "vstandarttablecell.h" #include "vincrementtablerow.h" -#include "../geometry/vspline.h" -#include "../geometry/varc.h" -#include "../geometry/vsplinepath.h" -#include "../geometry/vdetail.h" -#include "../widgets/vitem.h" +#include "geometry/vspline.h" +#include "geometry/varc.h" +#include "geometry/vsplinepath.h" +#include "geometry/vdetail.h" +#include "widgets/vitem.h" /** * @brief The VContainer class @@ -57,23 +51,30 @@ public: void AddStandartTableCell(const QString& name, const VStandartTableCell& cell); void AddIncrementTableRow(const QString& name, const VIncrementTableRow &cell); void AddLengthLine(const QString &name, const qreal &value); - void AddLengthSpline(const qint64 &firstPointId, const qint64 &secondPointId); + void AddLengthSpline(const qint64 &firstPointId, const qint64 &secondPointId, + Draw::Mode mode = Draw::Calculation); void AddLengthSpline(const QString &name, const qreal &value); void AddLengthArc(const qint64 ¢er, const qint64 &id); void AddLengthArc(const QString &name, const qreal &value); void AddLineAngle(const QString &name, const qreal &value); - void AddLine(const qint64 &firstPointId, const qint64 &secondPointId); + void AddLine(const qint64 &firstPointId, const qint64 &secondPointId, + Draw::Mode mode = Draw::Calculation); qint64 AddSpline(const VSpline& spl); qint64 AddModelingSpline(const VSpline& spl); qint64 AddSplinePath(const VSplinePath& splPath); qint64 AddModelingSplinePath(const VSplinePath& splPath); qint64 AddArc(const VArc& arc); qint64 AddModelingArc(const VArc& arc); - QString GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const; - QString GetNameLineAngle(const qint64 &firstPoint, const qint64 &secondPoint) const; - QString GetNameSpline(const qint64 &firstPoint, const qint64 &secondPoint) const; - QString GetNameSplinePath(const VSplinePath &path) const; - QString GetNameArc(const qint64 ¢er, const qint64 &id) const; + QString GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint, + Draw::Mode mode = Draw::Calculation) const; + QString GetNameLineAngle(const qint64 &firstPoint, const qint64 &secondPoint, + Draw::Mode mode = Draw::Calculation) const; + QString GetNameSpline(const qint64 &firstPoint, const qint64 &secondPoint, + Draw::Mode mode = Draw::Calculation) const; + QString GetNameSplinePath(const VSplinePath &path, + Draw::Mode mode = Draw::Calculation) const; + QString GetNameArc(const qint64 ¢er, const qint64 &id, + Draw::Mode mode = Draw::Calculation) const; void UpdatePoint(qint64 id, const VPointF& point); void UpdateModelingPoint(qint64 id, const VPointF& point); void UpdateDetail(qint64 id, const VDetail& detail); @@ -119,7 +120,7 @@ public: const QMap *DataModelingSplinePaths() const; const QMap *DataDetails() const; void UpdateId(qint64 newId); - void IncrementReferens(qint64 id, Scene::Type obj); + void IncrementReferens(qint64 id, Scene::Type obj, Draw::Mode mode = Draw::Calculation); QPainterPath ContourPath(qint64 idDetail) const; void PrepareDetails(QVector & list)const; private: @@ -144,6 +145,8 @@ private: template void UpdateObject(QMap &obj, const qint64 &id, const val& point); template qint64 AddObject(QMap &obj, const val& value); void CreateManTableIGroup (); + QVector GetReversePoint(const QVector &points)const; + qreal GetLengthContour(const QVector &contour, const QVector &newPoints)const; }; #endif // VCONTAINER_H diff --git a/dialogs/dialogalongline.cpp b/dialogs/dialogalongline.cpp index 6e7841255..7fc1d44b5 100644 --- a/dialogs/dialogalongline.cpp +++ b/dialogs/dialogalongline.cpp @@ -1,8 +1,8 @@ #include "dialogalongline.h" #include "ui_dialogalongline.h" -DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), +DialogAlongLine::DialogAlongLine(const VContainer *data, Draw::Mode mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), typeLine(QString()), formula(QString()), firstPointId(0), secondPointId(0){ ui->setupUi(this); listWidget = ui->listWidget; @@ -44,8 +44,24 @@ DialogAlongLine::~DialogAlongLine() } void DialogAlongLine::ChoosedObject(qint64 id, Scene::Type type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } if(type == Scene::Point){ - VPointF point = data->GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } if(number == 0){ qint32 index = ui->comboBoxFirstPoint->findText(point.name()); if ( index != -1 ) { // -1 for not found diff --git a/dialogs/dialogalongline.h b/dialogs/dialogalongline.h index 25fed1471..11868a171 100644 --- a/dialogs/dialogalongline.h +++ b/dialogs/dialogalongline.h @@ -14,7 +14,8 @@ class DialogAlongLine : public DialogTool { Q_OBJECT public: - explicit DialogAlongLine(const VContainer *data, QWidget *parent = 0); + explicit DialogAlongLine(const VContainer *data, Draw::Mode mode = Draw::Calculation, + QWidget *parent = 0); ~DialogAlongLine(); QString getPointName() const; void setPointName(const QString &value); diff --git a/dialogs/dialogarc.cpp b/dialogs/dialogarc.cpp index 76fd5b544..f2e9dd15e 100644 --- a/dialogs/dialogarc.cpp +++ b/dialogs/dialogarc.cpp @@ -2,8 +2,8 @@ #include "ui_dialogarc.h" #include "../container/calculator.h" -DialogArc::DialogArc(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false), +DialogArc::DialogArc(const VContainer *data, Draw::Mode mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false), timerRadius(0), timerF1(0), timerF2(0), center(0), radius(QString()), f1(QString()), f2(QString()){ ui->setupUi(this); @@ -94,8 +94,24 @@ delete ui; } void DialogArc::ChoosedObject(qint64 id, Scene::Type type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } if(type == Scene::Point){ - VPointF point = data->GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } ChangeCurrentText(ui->comboBoxBasePoint, point.name()); this->show(); } diff --git a/dialogs/dialogarc.h b/dialogs/dialogarc.h index e18c033f4..9dbe22fb0 100644 --- a/dialogs/dialogarc.h +++ b/dialogs/dialogarc.h @@ -12,7 +12,7 @@ class DialogArc : public DialogTool { Q_OBJECT public: - explicit DialogArc(const VContainer *data, QWidget *parent = 0); + explicit DialogArc(const VContainer *data, Draw::Mode mode = Draw::Calculation, QWidget *parent = 0); ~DialogArc(); qint64 GetCenter() const; void SetCenter(const qint64 &value); diff --git a/dialogs/dialogbisector.cpp b/dialogs/dialogbisector.cpp index f285a11fe..22c95f3dd 100644 --- a/dialogs/dialogbisector.cpp +++ b/dialogs/dialogbisector.cpp @@ -1,8 +1,8 @@ #include "dialogbisector.h" #include "ui_dialogbisector.h" -DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), +DialogBisector::DialogBisector(const VContainer *data, Draw::Mode mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), typeLine(QString()), formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0){ ui->setupUi(this); listWidget = ui->listWidget; @@ -44,8 +44,24 @@ DialogBisector::~DialogBisector(){ } void DialogBisector::ChoosedObject(qint64 id, Scene::Type type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } if(type == Scene::Point){ - VPointF point = data->GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } if(number == 0){ qint32 index = ui->comboBoxFirstPoint->findText(point.name()); if ( index != -1 ) { // -1 for not found diff --git a/dialogs/dialogbisector.h b/dialogs/dialogbisector.h index 36d358533..749cf0fb1 100644 --- a/dialogs/dialogbisector.h +++ b/dialogs/dialogbisector.h @@ -5,10 +5,9 @@ #include #include #include - -#include "../options.h" -#include "../container/vcontainer.h" -#include "../container/calculator.h" +#include "options.h" +#include "container/vcontainer.h" +#include "container/calculator.h" namespace Ui { class DialogBisector; @@ -19,7 +18,8 @@ class DialogBisector : public DialogTool Q_OBJECT public: - explicit DialogBisector(const VContainer *data, QWidget *parent = 0); + explicit DialogBisector(const VContainer *data, Draw::Mode mode = Draw::Calculation, + QWidget *parent = 0); ~DialogBisector(); QString getPointName() const; void setPointName(const QString &value); diff --git a/dialogs/dialogdetail.cpp b/dialogs/dialogdetail.cpp index e653f4f4b..97ca82433 100644 --- a/dialogs/dialogdetail.cpp +++ b/dialogs/dialogdetail.cpp @@ -1,7 +1,7 @@ #include "dialogdetail.h" DialogDetail::DialogDetail(const VContainer *data, Draw::Mode mode, QWidget *parent) : - DialogTool(data, parent), ui(), details(VDetail()), mode(mode){ + DialogTool(data, mode, parent), ui(), details(VDetail()){ ui.setupUi(this); bOk = ui.buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogDetail::DialogAccepted); @@ -11,8 +11,32 @@ DialogDetail::DialogDetail(const VContainer *data, Draw::Mode mode, QWidget *par } void DialogDetail::ChoosedObject(qint64 id, Scene::Type type){ - if(type != Scene::Line){ - NewItem(id, type, mode); + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } + if(type != Scene::Line && type != Scene::Detail){ + switch(type){ + case(Scene::Arc): + NewItem(id, Tools::NodeArc, mode, NodeDetail::Contour); + break; + case(Scene::Point): + NewItem(id, Tools::NodePoint, mode, NodeDetail::Contour); + break; + case(Scene::Spline): + NewItem(id, Tools::NodeSpline, mode, NodeDetail::Contour); + break; + case(Scene::SplinePath): + NewItem(id, Tools::NodeSplinePath, mode, NodeDetail::Contour); + break; + } this->show(); } } @@ -27,36 +51,54 @@ void DialogDetail::DialogAccepted(){ emit DialogClosed(QDialog::Accepted); } -void DialogDetail::NewItem(qint64 id, Scene::Type typeTool, Draw::Mode mode){ +void DialogDetail::NewItem(qint64 id, Tools::Enum typeTool, Draw::Mode mode, NodeDetail::Type typeNode){ QString name; switch(typeTool){ - case(Scene::Line): + case(Tools::NodePoint):{ + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } + name = point.name(); break; - case(Scene::Point):{ - VPointF point = data->GetPoint(id); - name = point.name(); + } + case(Tools::NodeArc):{ + VArc arc; + if(mode == Draw::Calculation){ + arc = data->GetArc(id); + } else { + arc = data->GetModelingArc(id); } - break; - case(Scene::Arc):{ - VArc arc = data->GetArc(id); - name = data->GetNameArc(arc.GetCenter(), id); + name = data->GetNameArc(arc.GetCenter(), id, mode); + break; + } + case(Tools::NodeSpline):{ + VSpline spl; + if(mode == Draw::Calculation){ + spl = data->GetSpline(id); + } else { + spl = data->GetModelingSpline(id); } - break; - case(Scene::Spline):{ - VSpline spl = data->GetSpline(id); - name = spl.GetName(); + name = spl.GetName(); + break; + } + case(Tools::NodeSplinePath):{ + VSplinePath splPath; + if(mode == Draw::Calculation){ + splPath = data->GetSplinePath(id); + } else { + splPath = data->GetModelingSplinePath(id); } - break; - case(Scene::SplinePath):{ - VSplinePath splPath = data->GetSplinePath(id); - name = data->GetNameSplinePath(splPath); - } - break; + name = data->GetNameSplinePath(splPath, mode); + break; + } } QListWidgetItem *item = new QListWidgetItem(name); item->setFont(QFont("Times", 12, QFont::Bold)); - VNodeDetail node(id, typeTool, mode); + VNodeDetail node(id, typeTool, mode, typeNode); item->setData(Qt::UserRole, QVariant::fromValue(node)); ui.listWidget->addItem(item); } @@ -69,7 +111,7 @@ void DialogDetail::setDetails(const VDetail &value){ details = value; ui.listWidget->clear(); for(qint32 i = 0; i < details.CountNode(); ++i){ - NewItem(details[i].getId(), details[i].getTypeTool(),details[i].getMode()); + NewItem(details[i].getId(), details[i].getTypeTool(),details[i].getMode(), details[i].getTypeNode()); } details.setName(ui.lineEditNameDetail->text()); ui.listWidget->setFocus(Qt::OtherFocusReason); diff --git a/dialogs/dialogdetail.h b/dialogs/dialogdetail.h index 113e8ff36..3cbb5d15d 100644 --- a/dialogs/dialogdetail.h +++ b/dialogs/dialogdetail.h @@ -3,8 +3,8 @@ #include "ui_dialogdetail.h" #include "dialogtool.h" -#include "../container/vcontainer.h" -#include "../geometry/vdetail.h" +#include "container/vcontainer.h" +#include "geometry/vdetail.h" class DialogDetail : public DialogTool { @@ -20,8 +20,7 @@ public slots: private: Ui::DialogDetail ui; VDetail details; - Draw::Mode mode; - void NewItem(qint64 id, Scene::Type typeTool, Draw::Mode mode); + void NewItem(qint64 id, Tools::Enum typeTool, Draw::Mode mode, NodeDetail::Type typeNode); }; #endif // DIALOGDETAIL_H diff --git a/dialogs/dialogendline.cpp b/dialogs/dialogendline.cpp index 5b7a0156e..f713f2b76 100644 --- a/dialogs/dialogendline.cpp +++ b/dialogs/dialogendline.cpp @@ -1,16 +1,12 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" #include "dialogendline.h" #include "ui_dialogendline.h" #include #include -#pragma GCC diagnostic pop -#include "../container/vpointf.h" -#include "../container/calculator.h" +#include "container/vpointf.h" +#include "container/calculator.h" -DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), +DialogEndLine::DialogEndLine(const VContainer *data, Draw::Mode mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), formula(QString()), angle(0), basePointId(0){ ui->setupUi(this); spinBoxAngle = ui->spinBoxAngle; @@ -63,8 +59,24 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent) : } void DialogEndLine::ChoosedObject(qint64 id, Scene::Type type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } if(type == Scene::Point){ - VPointF point = data->GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } ChangeCurrentText(ui->comboBoxBasePoint, point.name()); this->show(); } diff --git a/dialogs/dialogendline.h b/dialogs/dialogendline.h index 053715dd5..56cd392de 100644 --- a/dialogs/dialogendline.h +++ b/dialogs/dialogendline.h @@ -1,17 +1,13 @@ #ifndef DIALOGENDLINE_H #define DIALOGENDLINE_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include "dialogtool.h" #include #include #include -#pragma GCC diagnostic pop - -#include "../options.h" -#include "../container/vcontainer.h" -#include "../container/calculator.h" +#include "options.h" +#include "container/vcontainer.h" +#include "container/calculator.h" namespace Ui { class DialogEndLine; @@ -21,7 +17,8 @@ class DialogEndLine : public DialogTool { Q_OBJECT public: - explicit DialogEndLine(const VContainer *data, QWidget *parent = 0); + explicit DialogEndLine(const VContainer *data, Draw::Mode mode = Draw::Calculation, + QWidget *parent = 0); ~DialogEndLine(); QString getPointName() const; void setPointName(const QString &value); diff --git a/dialogs/dialoghistory.cpp b/dialogs/dialoghistory.cpp index 4253eba5a..cffc806e1 100644 --- a/dialogs/dialoghistory.cpp +++ b/dialogs/dialoghistory.cpp @@ -8,7 +8,7 @@ #include "geometry/vsplinepath.h" DialogHistory::DialogHistory(VContainer *data, VDomDocument *doc, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogHistory), doc(doc), cursorRow(0), cursorToolRecordRow(0){ + DialogTool(data, Draw::Calculation, parent), ui(new Ui::DialogHistory), doc(doc), cursorRow(0), cursorToolRecordRow(0){ ui->setupUi(this); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogHistory::DialogAccepted); diff --git a/dialogs/dialogincrements.cpp b/dialogs/dialogincrements.cpp index 2d748ef9a..4d148a322 100644 --- a/dialogs/dialogincrements.cpp +++ b/dialogs/dialogincrements.cpp @@ -1,16 +1,13 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include "dialogincrements.h" #include "ui_dialogincrements.h" #include #include -#include "../widgets/delegate.h" -#include "../widgets/doubledelegate.h" -#pragma GCC diagnostic pop -#include "../container/vincrementtablerow.h" +#include "widgets/delegate.h" +#include "widgets/doubledelegate.h" +#include "container/vincrementtablerow.h" DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogIncrements), data(data), doc(doc){ + DialogTool(data, Draw::Calculation, parent), ui(new Ui::DialogIncrements), data(data), doc(doc){ ui->setupUi(this); InitialStandartTable(); InitialIncrementTable(); diff --git a/dialogs/dialogincrements.h b/dialogs/dialogincrements.h index ca7d59130..3a257643f 100644 --- a/dialogs/dialogincrements.h +++ b/dialogs/dialogincrements.h @@ -5,10 +5,8 @@ #pragma GCC diagnostic ignored "-Weffc++" #include "dialogtool.h" #include -#include "../xml/vdomdocument.h" -#pragma GCC diagnostic pop -#include "../container/vcontainer.h" - +#include "xml/vdomdocument.h" +#include "container/vcontainer.h" namespace Ui { class DialogIncrements; diff --git a/dialogs/dialogline.cpp b/dialogs/dialogline.cpp index 82e86b326..71c3d8230 100644 --- a/dialogs/dialogline.cpp +++ b/dialogs/dialogline.cpp @@ -1,16 +1,10 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialogline.h" #include "ui_dialogline.h" #include #include -#pragma GCC diagnostic pop -DialogLine::DialogLine(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogLine), number(0), firstPoint(0), secondPoint(0){ +DialogLine::DialogLine(const VContainer *data, Draw::Mode mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(new Ui::DialogLine), number(0), firstPoint(0), secondPoint(0){ ui->setupUi(this); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogLine::DialogAccepted); @@ -61,8 +55,24 @@ void DialogLine::DialogAccepted(){ } void DialogLine::ChoosedObject(qint64 id, Scene::Type type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } if(type == Scene::Point){ - VPointF point = data->GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } if(number == 0){ qint32 index = ui->comboBoxFirstPoint->findText(point.name()); if ( index != -1 ) { // -1 for not found diff --git a/dialogs/dialogline.h b/dialogs/dialogline.h index c66a76b48..dbc8c9cd3 100644 --- a/dialogs/dialogline.h +++ b/dialogs/dialogline.h @@ -1,16 +1,10 @@ #ifndef DIALOGLINE_H #define DIALOGLINE_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialogtool.h" #include -#pragma GCC diagnostic pop -#include "../container/vcontainer.h" -#include "../options.h" +#include "container/vcontainer.h" +#include "options.h" namespace Ui { @@ -21,7 +15,8 @@ class DialogLine : public DialogTool { Q_OBJECT public: - explicit DialogLine(const VContainer *data, QWidget *parent = 0); + explicit DialogLine(const VContainer *data, Draw::Mode mode = Draw::Calculation, + QWidget *parent = 0); ~DialogLine(); qint64 getFirstPoint() const; void setFirstPoint(const qint64 &value); diff --git a/dialogs/dialoglineintersect.cpp b/dialogs/dialoglineintersect.cpp index 17f9891cb..5369b7eb9 100644 --- a/dialogs/dialoglineintersect.cpp +++ b/dialogs/dialoglineintersect.cpp @@ -1,15 +1,9 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialoglineintersect.h" #include "ui_dialoglineintersect.h" -#pragma GCC diagnostic pop -DialogLineIntersect::DialogLineIntersect(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogLineIntersect), number(0), pointName(QString()), p1Line1(0), - p2Line1(0), p1Line2(0), p2Line2(0), flagPoint(true){ +DialogLineIntersect::DialogLineIntersect(const VContainer *data, Draw::Mode mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(new Ui::DialogLineIntersect), number(0), pointName(QString()), + p1Line1(0), p2Line1(0), p1Line2(0), p2Line2(0), flagPoint(true){ ui->setupUi(this); number = 0; bOk = ui->buttonBox->button(QDialogButtonBox::Ok); @@ -31,8 +25,24 @@ DialogLineIntersect::~DialogLineIntersect() } void DialogLineIntersect::ChoosedObject(qint64 id, Scene::Type type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } if(type == Scene::Point){ - VPointF point = data->GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } if(number == 0){ qint32 index = ui->comboBoxP1Line1->findText(point.name()); if ( index != -1 ) { // -1 for not found diff --git a/dialogs/dialoglineintersect.h b/dialogs/dialoglineintersect.h index 271da9973..b6019edb8 100644 --- a/dialogs/dialoglineintersect.h +++ b/dialogs/dialoglineintersect.h @@ -1,13 +1,7 @@ #ifndef DIALOGLINEINTERSECT_H #define DIALOGLINEINTERSECT_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialogtool.h" -#pragma GCC diagnostic pop namespace Ui { class DialogLineIntersect; @@ -17,7 +11,8 @@ class DialogLineIntersect : public DialogTool { Q_OBJECT public: - explicit DialogLineIntersect(const VContainer *data, QWidget *parent = 0); + explicit DialogLineIntersect(const VContainer *data, Draw::Mode mode = Draw::Calculation, + QWidget *parent = 0); ~DialogLineIntersect(); qint64 getP1Line1() const; void setP1Line1(const qint64 &value); diff --git a/dialogs/dialognormal.cpp b/dialogs/dialognormal.cpp index 2658545c9..cd66d0dea 100644 --- a/dialogs/dialognormal.cpp +++ b/dialogs/dialognormal.cpp @@ -1,16 +1,10 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialognormal.h" #include "ui_dialognormal.h" #include -#pragma GCC diagnostic pop -DialogNormal::DialogNormal(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), typeLine(QString()), - formula(QString()), angle(0), firstPointId(0), secondPointId(0){ +DialogNormal::DialogNormal(const VContainer *data, Draw::Mode mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), + typeLine(QString()), formula(QString()), angle(0), firstPointId(0), secondPointId(0){ ui->setupUi(this); spinBoxAngle = ui->spinBoxAngle; listWidget = ui->listWidget; @@ -68,8 +62,24 @@ DialogNormal::~DialogNormal() } void DialogNormal::ChoosedObject(qint64 id, Scene::Type type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } if(type == Scene::Point){ - VPointF point = data->GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } if(number == 0){ qint32 index = ui->comboBoxFirstPoint->findText(point.name()); if ( index != -1 ) { // -1 for not found diff --git a/dialogs/dialognormal.h b/dialogs/dialognormal.h index ee2a2457f..a181e4850 100644 --- a/dialogs/dialognormal.h +++ b/dialogs/dialognormal.h @@ -1,19 +1,13 @@ #ifndef DIALOGNORMAL_H #define DIALOGNORMAL_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialogtool.h" #include #include #include -#pragma GCC diagnostic pop -#include "../options.h" -#include "../container/vcontainer.h" -#include "../container/calculator.h" +#include "options.h" +#include "container/vcontainer.h" +#include "container/calculator.h" namespace Ui { class DialogNormal; @@ -23,7 +17,8 @@ class DialogNormal : public DialogTool { Q_OBJECT public: - explicit DialogNormal(const VContainer *data, QWidget *parent = 0); + explicit DialogNormal(const VContainer *data, Draw::Mode mode = Draw::Calculation, + QWidget *parent = 0); ~DialogNormal(); QString getPointName() const; void setPointName(const QString &value); diff --git a/dialogs/dialogpointofcontact.cpp b/dialogs/dialogpointofcontact.cpp index 1f656dccc..a7e4ef1ee 100644 --- a/dialogs/dialogpointofcontact.cpp +++ b/dialogs/dialogpointofcontact.cpp @@ -1,13 +1,7 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialogpointofcontact.h" -#pragma GCC diagnostic pop -DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(), number(0), pointName(QString()), radius(QString()), center(0), +DialogPointOfContact::DialogPointOfContact(const VContainer *data, Draw::Mode mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(), number(0), pointName(QString()), radius(QString()), center(0), firstPoint(0), secondPoint(0){ ui.setupUi(this); listWidget = ui.listWidget; @@ -44,8 +38,24 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, QWidget *pare } void DialogPointOfContact::ChoosedObject(qint64 id, Scene::Type type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } if(type == Scene::Point){ - VPointF point = data->GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } if(number == 0){ qint32 index = ui.comboBoxFirstPoint->findText(point.name()); if ( index != -1 ) { // -1 for not found diff --git a/dialogs/dialogpointofcontact.h b/dialogs/dialogpointofcontact.h index e02ff16cc..c2780acbc 100644 --- a/dialogs/dialogpointofcontact.h +++ b/dialogs/dialogpointofcontact.h @@ -1,24 +1,19 @@ #ifndef DIALOGPOINTOFCONTACT_H #define DIALOGPOINTOFCONTACT_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "ui_dialogpointofcontact.h" #include "dialogtool.h" -#pragma GCC diagnostic pop -#include "../options.h" -#include "../container/vcontainer.h" -#include "../container/calculator.h" +#include "options.h" +#include "container/vcontainer.h" +#include "container/calculator.h" class DialogPointOfContact : public DialogTool { Q_OBJECT public: - explicit DialogPointOfContact(const VContainer *data, QWidget *parent = 0); + explicit DialogPointOfContact(const VContainer *data, Draw::Mode mode = Draw::Calculation, + QWidget *parent = 0); QString getPointName() const; void setPointName(const QString &value); diff --git a/dialogs/dialogs.h b/dialogs/dialogs.h new file mode 100644 index 000000000..71c4e9b7d --- /dev/null +++ b/dialogs/dialogs.h @@ -0,0 +1,20 @@ +#ifndef DIALOGS_H +#define DIALOGS_H + +#include "dialogalongline.h" +#include "dialogarc.h" +#include "dialogbisector.h" +#include "dialogdetail.h" +#include "dialogendline.h" +#include "dialoghistory.h" +#include "dialogincrements.h" +#include "dialogline.h" +#include "dialoglineintersect.h" +#include "dialognormal.h" +#include "dialogpointofcontact.h" +#include "dialogshoulderpoint.h" +#include "dialogsinglepoint.h" +#include "dialogspline.h" +#include "dialogsplinepath.h" + +#endif // DIALOGS_H diff --git a/dialogs/dialogshoulderpoint.cpp b/dialogs/dialogshoulderpoint.cpp index f6f8b9201..f1ce04add 100644 --- a/dialogs/dialogshoulderpoint.cpp +++ b/dialogs/dialogshoulderpoint.cpp @@ -1,14 +1,8 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialogshoulderpoint.h" #include "ui_dialogshoulderpoint.h" -#pragma GCC diagnostic pop -DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()), +DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, Draw::Mode mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()), typeLine(QString()), formula(QString()), p1Line(0), p2Line(0), pShoulder(0){ ui->setupUi(this); number = 0; @@ -52,8 +46,24 @@ DialogShoulderPoint::~DialogShoulderPoint() } void DialogShoulderPoint::ChoosedObject(qint64 id, Scene::Type type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } if(type == Scene::Point){ - VPointF point = data->GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } if(number == 0){ qint32 index = ui->comboBoxP1Line->findText(point.name()); if ( index != -1 ) { // -1 for not found diff --git a/dialogs/dialogshoulderpoint.h b/dialogs/dialogshoulderpoint.h index 3a80eff8d..f9dd770fc 100644 --- a/dialogs/dialogshoulderpoint.h +++ b/dialogs/dialogshoulderpoint.h @@ -1,16 +1,10 @@ #ifndef DIALOGSHOULDERPOINT_H #define DIALOGSHOULDERPOINT_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialogtool.h" -#pragma GCC diagnostic pop -#include "../options.h" -#include "../container/vcontainer.h" -#include "../container/calculator.h" +#include "options.h" +#include "container/vcontainer.h" +#include "container/calculator.h" namespace Ui { class DialogShoulderPoint; @@ -20,7 +14,8 @@ class DialogShoulderPoint : public DialogTool { Q_OBJECT public: - explicit DialogShoulderPoint(const VContainer *data, QWidget *parent = 0); + explicit DialogShoulderPoint(const VContainer *data, Draw::Mode mode = Draw::Calculation, + QWidget *parent = 0); ~DialogShoulderPoint(); QString getPointName() const; void setPointName(const QString &value); diff --git a/dialogs/dialogsinglepoint.cpp b/dialogs/dialogsinglepoint.cpp index 46bb916ef..c7ee2f7fe 100644 --- a/dialogs/dialogsinglepoint.cpp +++ b/dialogs/dialogsinglepoint.cpp @@ -1,18 +1,13 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialogsinglepoint.h" #include "ui_dialogsinglepoint.h" #include #include #include -#pragma GCC diagnostic pop -#include "../options.h" +#include "options.h" DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogSinglePoint), name(QString()), point(QPointF()){ + DialogTool(data, Draw::Calculation, parent), ui(new Ui::DialogSinglePoint), name(QString()), + point(QPointF()){ ui->setupUi(this); ui->doubleSpinBoxX->setRange(0,PaperSize/PrintDPI*25.4); ui->doubleSpinBoxY->setRange(0,PaperSize/PrintDPI*25.4); diff --git a/dialogs/dialogsinglepoint.h b/dialogs/dialogsinglepoint.h index ca43e3db2..2bf188ffe 100644 --- a/dialogs/dialogsinglepoint.h +++ b/dialogs/dialogsinglepoint.h @@ -1,10 +1,8 @@ #ifndef DIALOGSINGLEPOINT_H #define DIALOGSINGLEPOINT_H -#pragma GCC diagnostic ignored "-Weffc++" #include "dialogtool.h" -#pragma GCC diagnostic warning "-Weffc++" -#include "../container/vcontainer.h" +#include "container/vcontainer.h" namespace Ui { class DialogSinglePoint; diff --git a/dialogs/dialogspline.cpp b/dialogs/dialogspline.cpp index d8b592017..fda6914c3 100644 --- a/dialogs/dialogspline.cpp +++ b/dialogs/dialogspline.cpp @@ -1,8 +1,8 @@ #include "dialogspline.h" #include "ui_dialogspline.h" -DialogSpline::DialogSpline(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogSpline), number(0), p1(0), p4(0), angle1(0), angle2(0), +DialogSpline::DialogSpline(const VContainer *data, Draw::Mode mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(new Ui::DialogSpline), number(0), p1(0), p4(0), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1){ ui->setupUi(this); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); @@ -10,18 +10,37 @@ DialogSpline::DialogSpline(const VContainer *data, QWidget *parent) : QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); connect(bCansel, &QPushButton::clicked, this, &DialogSpline::DialogRejected); - FillComboBoxPoints(ui->comboBoxP1); - FillComboBoxPoints(ui->comboBoxP4); + if(mode == Draw::Calculation){ + FillComboBoxPoints(ui->comboBoxP1); + FillComboBoxPoints(ui->comboBoxP4); + } } -DialogSpline::~DialogSpline() -{ +DialogSpline::~DialogSpline(){ delete ui; } void DialogSpline::ChoosedObject(qint64 id, Scene::Type type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + FillComboBoxPoints(ui->comboBoxP1); + FillComboBoxPoints(ui->comboBoxP4); + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } if(type == Scene::Point){ - VPointF point = data->GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } if(number == 0){ qint32 index = ui->comboBoxP1->findText(point.name()); if ( index != -1 ) { // -1 for not found @@ -37,8 +56,15 @@ void DialogSpline::ChoosedObject(qint64 id, Scene::Type type){ number = 0; 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; + QPointF p4; + if(mode == Draw::Calculation){ + p1 = data->GetPoint(p1Id).toQPointF(); + p4 = data->GetPoint(id).toQPointF(); + } else { + p1 = data->GetModelingPoint(p1Id).toQPointF(); + p4 = data->GetModelingPoint(id).toQPointF(); + } ui->spinBoxAngle1->setValue(static_cast(QLineF(p1, p4).angle())); ui->spinBoxAngle2->setValue(static_cast(QLineF(p4, p1).angle())); } diff --git a/dialogs/dialogspline.h b/dialogs/dialogspline.h index 08bf69f48..db0412458 100644 --- a/dialogs/dialogspline.h +++ b/dialogs/dialogspline.h @@ -2,7 +2,7 @@ #define DIALOGSPLINE_H #include "dialogtool.h" -#include "../container/vcontainer.h" +#include "container/vcontainer.h" namespace Ui { class DialogSpline; @@ -12,7 +12,8 @@ class DialogSpline : public DialogTool { Q_OBJECT public: - explicit DialogSpline(const VContainer *data, QWidget *parent = 0); + explicit DialogSpline(const VContainer *data, Draw::Mode mode = Draw::Calculation, + QWidget *parent = 0); ~DialogSpline(); qint64 getP1() const; void setP1(const qint64 &value); diff --git a/dialogs/dialogsplinepath.cpp b/dialogs/dialogsplinepath.cpp index e727d6001..608d763b8 100644 --- a/dialogs/dialogsplinepath.cpp +++ b/dialogs/dialogsplinepath.cpp @@ -1,15 +1,9 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialogsplinepath.h" #include "ui_dialogsplinepath.h" -#pragma GCC diagnostic pop -#include "../geometry/vsplinepoint.h" +#include "geometry/vsplinepoint.h" -DialogSplinePath::DialogSplinePath(const VContainer *data, QWidget *parent) : - DialogTool(data, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()){ +DialogSplinePath::DialogSplinePath(const VContainer *data, Draw::Mode mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()){ ui->setupUi(this); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogSplinePath::DialogAccepted); @@ -54,6 +48,17 @@ void DialogSplinePath::SetPath(const VSplinePath &value){ void DialogSplinePath::ChoosedObject(qint64 id, Scene::Type type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } if(type == Scene::Point){ NewItem(id, 1, 0, 1); this->show(); @@ -116,7 +121,12 @@ void DialogSplinePath::KAsm2Changed(qreal d){ } void DialogSplinePath::NewItem(qint64 id, qreal kAsm1, qreal angle, qreal kAsm2){ - VPointF point = data->GetPoint(id); + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } QListWidgetItem *item = new QListWidgetItem(point.name()); item->setFont(QFont("Times", 12, QFont::Bold)); VSplinePoint p(id, kAsm1, angle, kAsm2); diff --git a/dialogs/dialogsplinepath.h b/dialogs/dialogsplinepath.h index dc25703df..dec5d53a1 100644 --- a/dialogs/dialogsplinepath.h +++ b/dialogs/dialogsplinepath.h @@ -1,15 +1,9 @@ #ifndef DIALOGSPLINEPATH_H #define DIALOGSPLINEPATH_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialogtool.h" -#pragma GCC diagnostic pop -#include "../container/vcontainer.h" -#include "../geometry/vsplinepath.h" +#include "container/vcontainer.h" +#include "geometry/vsplinepath.h" namespace Ui { class DialogSplinePath; @@ -19,7 +13,8 @@ class DialogSplinePath : public DialogTool { Q_OBJECT public: - explicit DialogSplinePath(const VContainer *data, QWidget *parent = 0); + explicit DialogSplinePath(const VContainer *data, Draw::Mode mode = Draw::Calculation, + QWidget *parent = 0); ~DialogSplinePath(); VSplinePath GetPath() const; void SetPath(const VSplinePath &value); diff --git a/dialogs/dialogtool.cpp b/dialogs/dialogtool.cpp index cef2855d5..ac0b6338e 100644 --- a/dialogs/dialogtool.cpp +++ b/dialogs/dialogtool.cpp @@ -1,18 +1,14 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "dialogtool.h" #include #include -#pragma GCC diagnostic pop -#include "../container/calculator.h" +#include "container/calculator.h" +#include "geometry/vdetail.h" -DialogTool::DialogTool(const VContainer *data, QWidget *parent):QDialog(parent), data(data), +DialogTool::DialogTool(const VContainer *data, Draw::Mode mode, QWidget *parent):QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), timerFormula(0), bOk(0), spinBoxAngle(0), - lineEditFormula(0), listWidget(0), labelResultCalculation(0), labelDescription(0), radioButtonSizeGrowth(0), - radioButtonStandartTable(0), radioButtonIncrements(0), radioButtonLengthLine(0){ + lineEditFormula(0), listWidget(0), labelResultCalculation(0), labelDescription(0), + radioButtonSizeGrowth(0), radioButtonStandartTable(0), radioButtonIncrements(0), + radioButtonLengthLine(0), idDetail(0), mode(mode){ Q_CHECK_PTR(data); timerFormula = new QTimer(this); connect(timerFormula, &QTimer::timeout, this, &DialogTool::EvalFormula); @@ -39,13 +35,36 @@ void DialogTool::showEvent(QShowEvent *event){ void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const{ box->clear(); - const QMap *points = data->DataPoints(); - QMapIterator i(*points); - while (i.hasNext()) { - i.next(); - if(i.key() != id){ - VPointF point = i.value(); - box->addItem(point.name(), i.key()); + if(mode == Draw::Calculation){ + const QMap *points = data->DataPoints(); + QMapIterator i(*points); + while (i.hasNext()) { + i.next(); + if(i.key() != id){ + VPointF point = i.value(); + box->addItem(point.name(), i.key()); + } + } + } else { + if(idDetail <= 0){ + qWarning()<<"Wrong details id."<GetDetail(idDetail); + for(qint32 i = 0; i< det.CountNode(); ++i){ + if(det[i].getTypeTool() == Tools::NodePoint || + det[i].getTypeTool() == Tools::AlongLineTool || + det[i].getTypeTool() == Tools::BisectorTool || + det[i].getTypeTool() == Tools::EndLineTool || + det[i].getTypeTool() == Tools::LineIntersectTool || + det[i].getTypeTool() == Tools::NormalTool || + det[i].getTypeTool() == Tools::PointOfContact || + det[i].getTypeTool() == Tools::ShoulderPointTool){ + if(det[i].getId() != id){ + VPointF point = data->GetModelingPoint(det[i].getId()); + box->addItem(point.name(), det[i].getId()); + } + } } } } @@ -323,6 +342,14 @@ void DialogTool::UpdateList(){ } } +bool DialogTool::CheckObject(const qint64 &id){ + if(mode == Draw::Calculation || idDetail == 0){ + return false; + } + VDetail det = data->GetDetail(idDetail); + return det.Containes(id); +} + template void DialogTool::ShowVariable(const QMap *var){ Q_CHECK_PTR(listWidget); @@ -338,3 +365,11 @@ void DialogTool::ShowVariable(const QMap *var){ } listWidget->setCurrentRow (0); } + +qint64 DialogTool::getIdDetail() const{ + return idDetail; +} + +void DialogTool::setIdDetail(const qint64 &value){ + idDetail = value; +} diff --git a/dialogs/dialogtool.h b/dialogs/dialogtool.h index 9fab4f33b..0e82003da 100644 --- a/dialogs/dialogtool.h +++ b/dialogs/dialogtool.h @@ -1,11 +1,6 @@ #ifndef DIALOGTOOL_H #define DIALOGTOOL_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include #include #include @@ -15,16 +10,18 @@ #include #include #include -#pragma GCC diagnostic pop -#include "../container/vcontainer.h" -#include "../options.h" +#include "container/vcontainer.h" +#include "options.h" class DialogTool : public QDialog { Q_OBJECT public: - DialogTool(const VContainer *data, QWidget *parent = 0); + DialogTool(const VContainer *data, Draw::Mode mode = Draw::Calculation, + QWidget *parent = 0); virtual ~DialogTool(); + qint64 getIdDetail() const; + void setIdDetail(const qint64 &value); signals: void DialogClosed(int result); public slots: @@ -66,6 +63,9 @@ protected: QRadioButton *radioButtonStandartTable; QRadioButton *radioButtonIncrements; QRadioButton *radioButtonLengthLine; + qint64 idDetail; + Draw::Mode mode; + bool CheckObject(const qint64 &id); virtual void closeEvent ( QCloseEvent * event ); virtual void showEvent( QShowEvent *event ); void FillComboBoxPoints(QComboBox *box, const qint64 &id = 0)const; @@ -81,7 +81,7 @@ protected: void Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label); void setCurrentPointId(QComboBox *box, qint64 &pointId, const qint64 &value, const qint64 &id) const; qint64 getCurrentPointId(QComboBox *box) const; - DialogTool(const DialogTool &dialog); + DialogTool(const DialogTool &dialog); const DialogTool &operator=(const DialogTool &dialog); }; diff --git a/geometry/vdetail.cpp b/geometry/vdetail.cpp index 34d30d958..2b63df994 100644 --- a/geometry/vdetail.cpp +++ b/geometry/vdetail.cpp @@ -23,6 +23,16 @@ qint32 VDetail::CountNode() const{ return nodes.size(); } +bool VDetail::Containes(const qint64 &id) const{ + for(qint32 i = 0; i < nodes.size(); ++i){ + VNodeDetail node = nodes[i]; + if(node.getId() == id){ + return true; + } + } + return false; +} + VNodeDetail &VDetail::operator [](int indx){ return nodes[indx]; } diff --git a/geometry/vdetail.h b/geometry/vdetail.h index 95cf3e9cb..49e671fdc 100644 --- a/geometry/vdetail.h +++ b/geometry/vdetail.h @@ -14,6 +14,7 @@ public: void append(const VNodeDetail &node); void Clear(); qint32 CountNode() const; + bool Containes(const qint64 &id)const; VNodeDetail & operator[](int indx); QString getName() const; void setName(const QString &value); diff --git a/geometry/vnodedetail.cpp b/geometry/vnodedetail.cpp index 618185107..e4b498f54 100644 --- a/geometry/vnodedetail.cpp +++ b/geometry/vnodedetail.cpp @@ -1,21 +1,22 @@ #include "vnodedetail.h" -VNodeDetail::VNodeDetail():id(0), typeTool(Scene::Point), mode(Draw::Calculation){ +VNodeDetail::VNodeDetail():id(0), typeTool(Tools::NodePoint), mode(Draw::Calculation), + typeNode(NodeDetail::Contour){ } -VNodeDetail::VNodeDetail(qint64 id, Scene::Type typeTool, Draw::Mode mode):id(id), typeTool(typeTool), -mode(mode){ +VNodeDetail::VNodeDetail(qint64 id, Tools::Enum typeTool, Draw::Mode mode, NodeDetail::Type typeNode):id(id), + typeTool(typeTool), mode(mode), typeNode(typeNode){ } VNodeDetail::VNodeDetail(const VNodeDetail &node):id(node.getId()), typeTool(node.getTypeTool()), - mode(node.getMode()){ + mode(node.getMode()), typeNode(node.getTypeNode()){ } -Scene::Type VNodeDetail::getTypeTool() const{ +Tools::Enum VNodeDetail::getTypeTool() const{ return typeTool; } -void VNodeDetail::setTypeTool(const Scene::Type &value){ +void VNodeDetail::setTypeTool(const Tools::Enum &value){ typeTool = value; } @@ -34,3 +35,11 @@ Draw::Mode VNodeDetail::getMode() const{ void VNodeDetail::setMode(const Draw::Mode &value){ mode = value; } + +NodeDetail::Type VNodeDetail::getTypeNode() const{ + return typeNode; +} + +void VNodeDetail::setTypeNode(const NodeDetail::Type &value){ + typeNode = value; +} diff --git a/geometry/vnodedetail.h b/geometry/vnodedetail.h index e5b3b910c..016ad8518 100644 --- a/geometry/vnodedetail.h +++ b/geometry/vnodedetail.h @@ -3,24 +3,36 @@ #include #include -#include "../options.h" +#include "options.h" + +namespace NodeDetail{ + enum Type + { + Contour, + Modeling + }; +} class VNodeDetail { public: VNodeDetail(); - VNodeDetail(qint64 id, Scene::Type typeTool, Draw::Mode mode); + VNodeDetail(qint64 id, Tools::Enum typeTool, Draw::Mode mode, NodeDetail::Type typeNode); VNodeDetail(const VNodeDetail &node); qint64 getId() const; void setId(const qint64 &value); - Scene::Type getTypeTool() const; - void setTypeTool(const Scene::Type &value); + Tools::Enum getTypeTool() const; + void setTypeTool(const Tools::Enum &value); Draw::Mode getMode() const; void setMode(const Draw::Mode &value); + NodeDetail::Type getTypeNode() const; + void setTypeNode(const NodeDetail::Type &value); + private: qint64 id; - Scene::Type typeTool; + Tools::Enum typeTool; Draw::Mode mode; + NodeDetail::Type typeNode; }; Q_DECLARE_METATYPE(VNodeDetail) diff --git a/geometry/vspline.cpp b/geometry/vspline.cpp index 95be68ee1..453f06b64 100644 --- a/geometry/vspline.cpp +++ b/geometry/vspline.cpp @@ -260,6 +260,26 @@ void VSpline::PutAlongSpl (QPointF &moveP, qreal move ) const{ QVector 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; +// } } QVector VSpline::GetPoints (QPointF p1, QPointF p2, QPointF p3, QPointF p4){ diff --git a/mainwindow.cpp b/mainwindow.cpp index 1c5445003..984cb7f86 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,8 +1,3 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "mainwindow.h" #include "ui_mainwindow.h" #include @@ -13,19 +8,6 @@ #include #include #include -#include "tools/vtoolendline.h" -#include "tools/vtoolline.h" -#include "tools/vtoolalongline.h" -#include "tools/vtoolshoulderpoint.h" -#include "tools/vtoolnormal.h" -#include "tools/vtoolbisector.h" -#include "tools/vtoollineintersect.h" -#include "tools/vtoolspline.h" -#include "tools/vtoolarc.h" -#include "tools/vtoolsplinepath.h" -#include "tools/vtoolpointofcontact.h" -#include "tools/vtooldetail.h" -#pragma GCC diagnostic pop #include "geometry/vspline.h" MainWindow::MainWindow(QWidget *parent) : @@ -145,7 +127,7 @@ void MainWindow::ActionNewDraw(){ connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); QMap* tools = doc->getTools(); tools->insert(id, spoint); - VAbstractTool::AddRecord(id, Tools::SinglePointTool, doc); + VDrawTool::AddRecord(id, Tools::SinglePointTool, doc); SetEnableTool(true); SetEnableWidgets(true); } @@ -193,7 +175,7 @@ void MainWindow::SetToolButton(bool checked, Tools::Enum t, const QString &curso QCursor cur(pixmap, 2, 3); view->setCursor(cur); helpLabel->setText("Виберіть точки."); - dialog = QSharedPointer(new Dialog(data)); + dialog = QSharedPointer(new Dialog(data, mode)); connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialog.data(), &Dialog::ChoosedObject); connect(dialog.data(), &Dialog::DialogClosed, this, closeDialogSlot); connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); @@ -204,6 +186,15 @@ void MainWindow::SetToolButton(bool checked, Tools::Enum t, const QString &curso } } +template +void MainWindow::AddToolToDetail(Tool *tool, const qint64 &id, Tools::Enum typeTool, + const qint64 &idDetail){ + QMap* tools = doc->getTools(); + VToolDetail *det = qobject_cast(tools->value(idDetail)); + Q_CHECK_PTR(det); + det->AddTool(tool, id, typeTool); +} + void MainWindow::ToolEndLine(bool checked){ SetToolButton(checked, Tools::EndLineTool, ":/cursor/endline_cursor.png", dialogEndLine, &MainWindow::ClosedDialogEndLine); @@ -211,7 +202,12 @@ void MainWindow::ToolEndLine(bool checked){ void MainWindow::ClosedDialogEndLine(int result){ if(result == QDialog::Accepted){ - VToolEndLine::Create(dialogEndLine, currentScene, doc, data, mode); + if(mode == Draw::Calculation){ + VToolEndLine::Create(dialogEndLine, currentScene, doc, data); + } else { + VModelingEndLine *endLine = VModelingEndLine::Create(dialogEndLine, doc, data); + AddToolToDetail(endLine, endLine->getId(), Tools::EndLineTool, dialogEndLine->getIdDetail()); + } } ArrowTool(); } @@ -223,7 +219,12 @@ void MainWindow::ToolLine(bool checked){ void MainWindow::ClosedDialogLine(int result){ if(result == QDialog::Accepted){ - VToolLine::Create(dialogLine, currentScene, doc, data, mode); + if(mode == Draw::Calculation){ + VToolLine::Create(dialogLine, currentScene, doc, data); + } else { + VModelingLine *line = VModelingLine::Create(dialogLine, doc, data); + AddToolToDetail(line, line->getId(), Tools::LineTool, dialogLine->getIdDetail()); + } } ArrowTool(); } @@ -235,7 +236,12 @@ void MainWindow::ToolAlongLine(bool checked){ void MainWindow::ClosedDialogAlongLine(int result){ if(result == QDialog::Accepted){ - VToolAlongLine::Create(dialogAlongLine, currentScene, doc, data, mode); + if(mode == Draw::Calculation){ + VToolAlongLine::Create(dialogAlongLine, currentScene, doc, data); + } else{ + VModelingAlongLine *point = VModelingAlongLine::Create(dialogAlongLine, doc, data); + AddToolToDetail(point, point->getId(), Tools::AlongLineTool, dialogAlongLine->getIdDetail()); + } } ArrowTool(); } @@ -247,7 +253,13 @@ void MainWindow::ToolShoulderPoint(bool checked){ void MainWindow::ClosedDialogShoulderPoint(int result){ if(result == QDialog::Accepted){ - VToolShoulderPoint::Create(dialogShoulderPoint, currentScene, doc, data, mode); + if(mode == Draw::Calculation){ + VToolShoulderPoint::Create(dialogShoulderPoint, currentScene, doc, data); + } else { + VModelingShoulderPoint *point = VModelingShoulderPoint::Create(dialogShoulderPoint, doc, data); + AddToolToDetail(point, point->getId(), Tools::ShoulderPointTool, + dialogShoulderPoint->getIdDetail()); + } } ArrowTool(); } @@ -259,7 +271,12 @@ void MainWindow::ToolNormal(bool checked){ void MainWindow::ClosedDialogNormal(int result){ if(result == QDialog::Accepted){ - VToolNormal::Create(dialogNormal, currentScene, doc, data, mode); + if(mode == Draw::Calculation){ + VToolNormal::Create(dialogNormal, currentScene, doc, data); + } else { + VModelingNormal *point = VModelingNormal::Create(dialogNormal, doc, data); + AddToolToDetail(point, point->getId(), Tools::NormalTool, dialogNormal->getIdDetail()); + } } ArrowTool(); } @@ -271,7 +288,12 @@ void MainWindow::ToolBisector(bool checked){ void MainWindow::ClosedDialogBisector(int result){ if(result == QDialog::Accepted){ - VToolBisector::Create(dialogBisector, currentScene, doc, data, mode); + if(mode == Draw::Calculation){ + VToolBisector::Create(dialogBisector, currentScene, doc, data); + } else { + VModelingBisector *point = VModelingBisector::Create(dialogBisector, doc, data); + AddToolToDetail(point, point->getId(), Tools::BisectorTool, dialogBisector->getIdDetail()); + } } ArrowTool(); } @@ -283,7 +305,13 @@ void MainWindow::ToolLineIntersect(bool checked){ void MainWindow::ClosedDialogLineIntersect(int result){ if(result == QDialog::Accepted){ - VToolLineIntersect::Create(dialogLineIntersect, currentScene, doc, data, mode); + if(mode == Draw::Calculation){ + VToolLineIntersect::Create(dialogLineIntersect, currentScene, doc, data); + } else { + VModelingLineIntersect *point = VModelingLineIntersect::Create(dialogLineIntersect, doc, data); + AddToolToDetail(point, point->getId(), Tools::LineIntersectTool, + dialogLineIntersect->getIdDetail()); + } } ArrowTool(); } @@ -295,7 +323,12 @@ void MainWindow::ToolSpline(bool checked){ void MainWindow::ClosedDialogSpline(int result){ if(result == QDialog::Accepted){ - VToolSpline::Create(dialogSpline, currentScene, doc, data, mode); + if(mode == Draw::Calculation){ + VToolSpline::Create(dialogSpline, currentScene, doc, data); + } else { + VModelingSpline *spl = VModelingSpline::Create(dialogSpline, doc, data); + AddToolToDetail(spl, spl->getId(), Tools::SplineTool, dialogSpline->getIdDetail()); + } } ArrowTool(); } @@ -307,7 +340,12 @@ void MainWindow::ToolArc(bool checked){ void MainWindow::ClosedDialogArc(int result){ if(result == QDialog::Accepted){ - VToolArc::Create(dialogArc, currentScene, doc, data, mode); + if(mode == Draw::Calculation){ + VToolArc::Create(dialogArc, currentScene, doc, data); + } else { + VModelingArc *arc = VModelingArc::Create(dialogArc, doc, data); + AddToolToDetail(arc, arc->getId(), Tools::ArcTool, dialogArc->getIdDetail()); + } } ArrowTool(); } @@ -319,7 +357,12 @@ void MainWindow::ToolSplinePath(bool checked){ void MainWindow::ClosedDialogSplinePath(int result){ if(result == QDialog::Accepted){ - VToolSplinePath::Create(dialogSplinePath, currentScene, doc, data, mode); + if(mode == Draw::Calculation){ + VToolSplinePath::Create(dialogSplinePath, currentScene, doc, data); + } else { + VModelingSplinePath *spl = VModelingSplinePath::Create(dialogSplinePath, doc, data); + AddToolToDetail(spl, spl->getId(), Tools::SplinePathTool, dialogSplinePath->getIdDetail()); + } } ArrowTool(); } @@ -331,7 +374,14 @@ void MainWindow::ToolPointOfContact(bool checked){ void MainWindow::ClosedDialogPointOfContact(int result){ if(result == QDialog::Accepted){ - VToolPointOfContact::Create(dialogPointOfContact, currentScene, doc, data, mode); + if(mode == Draw::Calculation){ + VToolPointOfContact::Create(dialogPointOfContact, currentScene, doc, data); + } else { + VModelingPointOfContact *point = VModelingPointOfContact::Create(dialogPointOfContact, doc, + data); + AddToolToDetail(point, point->getId(), Tools::PointOfContact, + dialogPointOfContact->getIdDetail()); + } } ArrowTool(); } diff --git a/mainwindow.h b/mainwindow.h index 4267329ce..c9831b563 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -1,12 +1,6 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include #include #include @@ -15,26 +9,14 @@ #include #include "widgets/vmaingraphicsscene.h" #include "widgets/vmaingraphicsview.h" -#include "dialogs/dialogincrements.h" -#include "dialogs/dialogline.h" -#include "dialogs/dialogalongline.h" -#include "dialogs/dialogshoulderpoint.h" -#include "dialogs/dialogendline.h" -#include "dialogs/dialognormal.h" -#include "dialogs/dialogbisector.h" -#include "dialogs/dialoglineintersect.h" -#include "dialogs/dialogspline.h" -#include "dialogs/dialogarc.h" -#include "dialogs/dialogsplinepath.h" -#include "dialogs/dialoghistory.h" -#include "dialogs/dialogpointofcontact.h" -#include "dialogs/dialogdetail.h" -#include "tools/vtoolsinglepoint.h" +#include "widgets/vitem.h" +#include "dialogs/dialogs.h" +#include "tools/drawTools/drawtools.h" +#include "tools/modelingTools/modelingtools.h" #include "xml/vdomdocument.h" -#pragma GCC diagnostic pop #include "container/vcontainer.h" #include "options.h" -#include "widgets/vitem.h" +#include "tools/vtooldetail.h" namespace Ui { class MainWindow; @@ -44,108 +26,112 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); public slots: - void mouseMove(QPointF scenePos); - void ActionAroowTool(); - void ActionDraw(bool checked); - void ActionDetails(bool checked); - void ActionNewDraw(); - void currentDrawChanged( int index ); - void OptionDraw(); - void ActionSaveAs(); - void ActionSave(); - void ActionOpen(); - void ActionNew(); - void haveChange(); - void ChangedSize(const QString &text); - void ChangedGrowth(const QString & text); - void ActionTable(bool checked); - void ClosedActionTable(); - void ActionHistory(bool checked); - void ActionLayout(bool checked); - void ClosedActionHistory(); - void ToolEndLine(bool checked); - void ClosedDialogEndLine(int result); - void ToolLine(bool checked); - void ClosedDialogLine(int result); - void ToolAlongLine(bool checked); - void ClosedDialogAlongLine(int result); - void ToolShoulderPoint(bool checked); - void ClosedDialogShoulderPoint(int result); - void ToolNormal(bool checked); - void ClosedDialogNormal(int result); - void ToolBisector(bool checked); - void ClosedDialogBisector(int result); - void ToolLineIntersect(bool checked); - void ClosedDialogLineIntersect(int result); - void ToolSpline(bool checked); - void ClosedDialogSpline(int result); - void ToolArc(bool checked); - void ClosedDialogArc(int result); - void ToolSplinePath(bool checked); - void ClosedDialogSplinePath(int result); - void ToolPointOfContact(bool checked); - void ClosedDialogPointOfContact(int result); - void ToolDetail(bool checked); - void ClosedDialogDetail(int result); + void mouseMove(QPointF scenePos); + void ActionAroowTool(); + void ActionDraw(bool checked); + void ActionDetails(bool checked); + void ActionNewDraw(); + void ActionSaveAs(); + void ActionSave(); + void ActionOpen(); + void ActionNew(); + void ActionTable(bool checked); + void ActionHistory(bool checked); + void ActionLayout(bool checked); + void currentDrawChanged( int index ); + void OptionDraw(); + void haveChange(); + void ChangedSize(const QString &text); + void ChangedGrowth(const QString & text); + void ClosedActionTable(); + void ClosedActionHistory(); + void ToolEndLine(bool checked); + void ToolLine(bool checked); + void ToolAlongLine(bool checked); + void ToolShoulderPoint(bool checked); + void ToolNormal(bool checked); + void ToolBisector(bool checked); + void ToolLineIntersect(bool checked); + void ToolSpline(bool checked); + void ToolArc(bool checked); + void ToolSplinePath(bool checked); + void ToolPointOfContact(bool checked); + void ToolDetail(bool checked); + void ClosedDialogEndLine(int result); + void ClosedDialogLine(int result); + void ClosedDialogAlongLine(int result); + void ClosedDialogShoulderPoint(int result); + void ClosedDialogNormal(int result); + void ClosedDialogBisector(int result); + void ClosedDialogLineIntersect(int result); + void ClosedDialogSpline(int result); + void ClosedDialogArc(int result); + void ClosedDialogSplinePath(int result); + void ClosedDialogPointOfContact(int result); + void ClosedDialogDetail(int result); /** * @brief tableClosed Слот, що виконується при отриманні сигналу закриття вікна укладання *деталей моделі. */ - void tableClosed(); + void tableClosed(); signals: /** * @brief ModelChosen Сигнал, що висилається після розрахунку всіх деталей моделі. * @param listDetails Список детайле моделі. */ - void ModelChosen(QVector listDetails); + void ModelChosen(QVector listDetails); protected: - virtual void keyPressEvent ( QKeyEvent * event ); - virtual void showEvent( QShowEvent *event ); + virtual void keyPressEvent ( QKeyEvent * event ); + virtual void showEvent( QShowEvent *event ); private: - Ui::MainWindow *ui; - Tools::Enum tool; - VMainGraphicsScene *currentScene; - VMainGraphicsScene *sceneDraw; - VMainGraphicsScene *sceneDetails; - QLabel *mouseCoordinate; - QLabel *helpLabel; - VMainGraphicsView *view; - bool isInitialized; - DialogIncrements *dialogTable; - QSharedPointer dialogEndLine; - QSharedPointer dialogLine; - QSharedPointer dialogAlongLine; - QSharedPointer dialogShoulderPoint; - QSharedPointer dialogNormal; - QSharedPointer dialogBisector; - QSharedPointer dialogLineIntersect; - QSharedPointer dialogSpline; - QSharedPointer dialogArc; - QSharedPointer dialogSplinePath; - QSharedPointer dialogPointOfContact; - QSharedPointer dialogDetail; - DialogHistory *dialogHistory; - VDomDocument *doc; - VContainer *data; - QComboBox *comboBoxDraws; - QString fileName; - bool changeInFile; - Draw::Mode mode; - MainWindow(const MainWindow &window); - const MainWindow &operator=(const MainWindow &window); - void ToolBarOption(); - void ToolBarDraws(); - void CanselTool(); - void ArrowTool(); - void SetEnableWidgets(bool enable); - void SetEnableTool(bool enable); + Ui::MainWindow *ui; + Tools::Enum tool; + VMainGraphicsScene *currentScene; + VMainGraphicsScene *sceneDraw; + VMainGraphicsScene *sceneDetails; + QLabel *mouseCoordinate; + QLabel *helpLabel; + VMainGraphicsView *view; + bool isInitialized; + DialogIncrements *dialogTable; + QSharedPointer dialogEndLine; + QSharedPointer dialogLine; + QSharedPointer dialogAlongLine; + QSharedPointer dialogShoulderPoint; + QSharedPointer dialogNormal; + QSharedPointer dialogBisector; + QSharedPointer dialogLineIntersect; + QSharedPointer dialogSpline; + QSharedPointer dialogArc; + QSharedPointer dialogSplinePath; + QSharedPointer dialogPointOfContact; + QSharedPointer dialogDetail; + DialogHistory *dialogHistory; + VDomDocument *doc; + VContainer *data; + QComboBox *comboBoxDraws; + QString fileName; + bool changeInFile; + Draw::Mode mode; + MainWindow(const MainWindow &window); + const MainWindow &operator=(const MainWindow &window); + void ToolBarOption(); + void ToolBarDraws(); + void CanselTool(); + void ArrowTool(); + void SetEnableWidgets(bool enable); + void SetEnableTool(bool enable); template - void SetToolButton(bool checked, Tools::Enum t, const QString &cursor, QSharedPointer &dialog, + void SetToolButton(bool checked, Tools::Enum t, const QString &cursor, + QSharedPointer &dialog, Func closeDialogSlot); - void MinimumScrollBar(); + void MinimumScrollBar(); + template + void AddToolToDetail(Tool *tool, const qint64 &id, Tools::Enum typeTool, + const qint64 &idDetail); }; #endif // MAINWINDOW_H diff --git a/options.h b/options.h index 098689cd5..983313b13 100644 --- a/options.h +++ b/options.h @@ -18,7 +18,8 @@ namespace Scene{ Line, Spline, Arc, - SplinePath + SplinePath, + Detail }; } @@ -38,7 +39,11 @@ namespace Tools{ ArcTool, SplinePathTool, PointOfContact, - Detail + Detail, + NodePoint, + NodeArc, + NodeSpline, + NodeSplinePath }; } diff --git a/stable.h b/stable.h index 43303a198..fbecfc763 100644 --- a/stable.h +++ b/stable.h @@ -1,13 +1,27 @@ /* Add C includes here */ - #if defined __cplusplus - /* Add C++ includes here */ - #include - #include - #include - #include - #include "options.h" - #include - #include - #include - #endif +#if defined __cplusplus +/* Add C++ includes here */ +#include +#include +#include +#include +#include +#include +#include "options.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif diff --git a/tools/drawTools/drawtools.h b/tools/drawTools/drawtools.h new file mode 100644 index 000000000..67a310fb2 --- /dev/null +++ b/tools/drawTools/drawtools.h @@ -0,0 +1,17 @@ +#ifndef DRAWTOOLS_H +#define DRAWTOOLS_H + +#include "vtoolalongline.h" +#include "vtoolarc.h" +#include "vtoolbisector.h" +#include "vtoolendline.h" +#include "vtoolline.h" +#include "vtoollineintersect.h" +#include "vtoolnormal.h" +#include "vtoolpointofcontact.h" +#include "vtoolshoulderpoint.h" +#include "vtoolsinglepoint.h" +#include "vtoolspline.h" +#include "vtoolsplinepath.h" + +#endif // DRAWTOOLS_H diff --git a/tools/drawTools/vdrawtool.cpp b/tools/drawTools/vdrawtool.cpp new file mode 100644 index 000000000..ac4dba3d5 --- /dev/null +++ b/tools/drawTools/vdrawtool.cpp @@ -0,0 +1,79 @@ +#include "vdrawtool.h" + +VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) : + VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), + nameActivDraw(doc->GetNameActivDraw()){ + connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VDrawTool::ChangedActivDraw); + connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VDrawTool::ChangedNameDraw); + connect(this->doc, &VDomDocument::ShowTool, this, &VDrawTool::ShowTool); +} + +VDrawTool::~VDrawTool(){ +} + +void VDrawTool::setDialog(){ +} + +void VDrawTool::AddRecord(const qint64 id, Tools::Enum 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::ignoreContextMenu(bool enable){ + ignoreContextMenuEvent = enable; +} + +void VDrawTool::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ + Q_UNUSED(id); + Q_UNUSED(color); + Q_UNUSED(enable); +} + +void VDrawTool::ChangedActivDraw(const QString newName){ + if(nameActivDraw == newName){ + ignoreContextMenuEvent = false; + } else { + ignoreContextMenuEvent = true; + } +} + +void VDrawTool::ChangedNameDraw(const QString oldName, const QString newName){ + if(nameActivDraw == oldName){ + nameActivDraw = newName; + } +} + +void VDrawTool::AddToCalculation(const QDomElement &domElement){ + QDomElement calcElement; + bool ok = doc->GetActivCalculationElement(calcElement); + if(ok){ + qint64 id = doc->getCursor(); + if(id <= 0){ + calcElement.appendChild(domElement); + } else { + QDomElement refElement = doc->elementById(QString().setNum(doc->getCursor())); + if(refElement.isElement()){ + calcElement.insertAfter(domElement,refElement); + doc->setCursor(0); + } else { + qCritical()<<"Не можу знайти елемент після якого потрібно вставляти."<< Q_FUNC_INFO; + } + } + } else { + qCritical()<<"Can't find tag Calculation"<< Q_FUNC_INFO; + } + emit toolhaveChange(); +} diff --git a/tools/drawTools/vdrawtool.h b/tools/drawTools/vdrawtool.h new file mode 100644 index 000000000..533e1ee27 --- /dev/null +++ b/tools/drawTools/vdrawtool.h @@ -0,0 +1,70 @@ +#ifndef VDRAWTOOL_H +#define VDRAWTOOL_H + +#include "../vabstracttool.h" +#include + +class VDrawTool : public VAbstractTool +{ + Q_OBJECT +public: + VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); + virtual ~VDrawTool(); + virtual void setDialog(); + static void AddRecord(const qint64 id, Tools::Enum toolType, VDomDocument *doc); + void ignoreContextMenu(bool enable); +public slots: + virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void ChangedActivDraw(const QString newName); + void ChangedNameDraw(const QString oldName, const QString newName); + virtual void FullUpdateFromGui(int result)=0; +signals: + void RemoveTool(QGraphicsItem *tool); +protected: + bool ignoreContextMenuEvent; + QString nameActivDraw; + void AddToCalculation(const QDomElement &domElement); + template + void ContextMenu(QSharedPointer &dialog, Tool *tool, QGraphicsSceneContextMenuEvent *event, + bool showRemove = true){ + if(!ignoreContextMenuEvent){ + QMenu menu; + QAction *actionOption = menu.addAction("Властивості"); + QAction *actionRemove; + if(showRemove){ + actionRemove = menu.addAction("Видалити"); + } + QAction *selectedAction = menu.exec(event->screenPos()); + if(selectedAction == actionOption){ + dialog = QSharedPointer(new Dialog(getData())); + + connect(qobject_cast< VMainGraphicsScene * >(tool->scene()), &VMainGraphicsScene::ChoosedObject, + dialog.data(), &Dialog::ChoosedObject); + connect(dialog.data(), &Dialog::DialogClosed, tool, + &Tool::FullUpdateFromGui); + connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); + + tool->setDialog(); + + dialog->show(); + } + if(selectedAction == actionRemove){ + //remove form xml file + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + QDomElement element; + bool ok = doc->GetActivCalculationElement(element); + if(ok){ + element.removeChild(domElement); + //update xml file + emit FullUpdateTree(); + //remove form scene + emit RemoveTool(tool); + } + } + } + } + } +}; + +#endif // VDRAWTOOL_H diff --git a/tools/vtoolalongline.cpp b/tools/drawTools/vtoolalongline.cpp similarity index 83% rename from tools/vtoolalongline.cpp rename to tools/drawTools/vtoolalongline.cpp index 7fea11336..4e4fdffa5 100644 --- a/tools/vtoolalongline.cpp +++ b/tools/drawTools/vtoolalongline.cpp @@ -1,17 +1,14 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include "vtoolalongline.h" #include #include #include -#pragma GCC diagnostic pop -#include "../container/calculator.h" +#include "container/calculator.h" -VToolAlongLine::VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, const QString &formula, +VToolAlongLine::VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine, Tool::Enum typeCreation, QGraphicsItem *parent): - VToolLinePoint(doc, data, id, mode, typeLine, formula, firstPointId, 0, parent), secondPointId(secondPointId), + VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent), secondPointId(secondPointId), dialogAlongLine(QSharedPointer()){ if(typeCreation == Tool::FromGui){ @@ -51,12 +48,7 @@ void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ } void VToolAlongLine::AddToFile(){ - VPointF point; - if(mode == Draw::Calculation){ - point = VAbstractTool::data.GetPoint(id); - } else { - point = VAbstractTool::data.GetModelingPoint(id); - } + VPointF point = VAbstractTool::data.GetPoint(id); QDomElement domElement = doc->createElement("point"); AddAttribute(domElement, "id", id); @@ -70,7 +62,7 @@ void VToolAlongLine::AddToFile(){ AddAttribute(domElement, "firstPoint", basePointId); AddAttribute(domElement, "secondPoint", secondPointId); - AddToDraw(domElement); + AddToCalculation(domElement); } void VToolAlongLine::setDialog(){ @@ -86,20 +78,20 @@ void VToolAlongLine::setDialog(){ } void VToolAlongLine::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Draw::Mode mode){ + VDomDocument *doc, VContainer *data){ QString formula = dialog->getFormula(); qint64 firstPointId = dialog->getFirstPointId(); qint64 secondPointId = dialog->getSecondPointId(); QString typeLine = dialog->getTypeLine(); QString pointName = dialog->getPointName(); Create(0, pointName, typeLine, formula, firstPointId, secondPointId, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui, mode); + Document::FullParse, Tool::FromGui); } void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QString &typeLine, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode){ + VContainer *data, Document::Enum parse, Tool::Enum typeCreation){ VPointF firstPoint = data->GetPoint(firstPointId); VPointF secondPoint = data->GetPoint(secondPointId); QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()); @@ -107,7 +99,7 @@ void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QS QString errorMsg; qreal result = cal.eval(formula, &errorMsg); if(errorMsg.isEmpty()){ - line.setLength(result*PrintDPI/25.4); + line.setLength(toPixel(result)); qint64 id = _id; if(typeCreation == Tool::FromGui){ id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); @@ -122,15 +114,11 @@ void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QS } } } - VAbstractTool::AddRecord(id, Tools::AlongLineTool, doc); + VDrawTool::AddRecord(id, Tools::AlongLineTool, doc); data->AddLine(firstPointId, id); data->AddLine(id, secondPointId); - if(mode == Draw::Modeling){ - data->IncrementReferens(firstPointId, Scene::Point); - data->IncrementReferens(secondPointId, Scene::Point); - } if(parse == Document::FullParse){ - VToolAlongLine *point = new VToolAlongLine(doc, data, id, mode, formula, firstPointId, + VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, typeCreation); scene->addItem(point); connect(point, &VToolAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); diff --git a/tools/vtoolalongline.h b/tools/drawTools/vtoolalongline.h similarity index 81% rename from tools/vtoolalongline.h rename to tools/drawTools/vtoolalongline.h index 150d13cc8..b2c375247 100644 --- a/tools/vtoolalongline.h +++ b/tools/drawTools/vtoolalongline.h @@ -1,26 +1,23 @@ #ifndef VTOOLALONGLINE_H #define VTOOLALONGLINE_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include "vtoollinepoint.h" -#include "../dialogs/dialogalongline.h" -#pragma GCC diagnostic pop +#include "dialogs/dialogalongline.h" class VToolAlongLine : public VToolLinePoint { Q_OBJECT public: - VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, const QString &formula, + VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine, Tool::Enum typeCreation, QGraphicsItem * parent = 0); virtual void setDialog(); static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode); + VContainer *data); static void Create(const qint64 _id, const QString &pointName, const QString &typeLine, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode); + VContainer *data, Document::Enum parse, Tool::Enum typeCreation); public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); diff --git a/tools/vtoolarc.cpp b/tools/drawTools/vtoolarc.cpp similarity index 83% rename from tools/vtoolarc.cpp rename to tools/drawTools/vtoolarc.cpp index 2cdd9aa83..da952592e 100644 --- a/tools/vtoolarc.cpp +++ b/tools/drawTools/vtoolarc.cpp @@ -1,15 +1,9 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vtoolarc.h" #include -#pragma GCC diagnostic pop -#include "../container/calculator.h" +#include "../../container/calculator.h" -VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, Tool::Enum typeCreation, - QGraphicsItem *parent):VAbstractTool(doc, data, id, mode), QGraphicsPathItem(parent), +VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, + QGraphicsItem *parent):VDrawTool(doc, data, id), QGraphicsPathItem(parent), dialogArc(QSharedPointer()){ VArc arc = data->GetArc(id); QPainterPath path; @@ -37,17 +31,17 @@ void VToolArc::setDialog(){ } void VToolArc::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode){ + VContainer *data){ qint64 center = dialog->GetCenter(); QString radius = dialog->GetRadius(); QString f1 = dialog->GetF1(); QString f2 = dialog->GetF2(); - Create(0, center, radius, f1, f2, scene, doc, data, Document::FullParse, Tool::FromGui, mode); + Create(0, center, radius, f1, f2, scene, doc, data, Document::FullParse, Tool::FromGui); } void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &radius, const QString &f1, const QString &f2, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode){ + VContainer *data, Document::Enum parse, Tool::Enum typeCreation){ qreal calcRadius = 0, calcF1 = 0, calcF2 = 0; Calculator cal(data); @@ -85,12 +79,9 @@ void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &rad } } data->AddLengthArc(data->GetNameArc(center,id), arc.GetLength()); - VAbstractTool::AddRecord(id, Tools::ArcTool, doc); - if(mode == Draw::Modeling){ - data->IncrementReferens(center, Scene::Point); - } + VDrawTool::AddRecord(id, Tools::ArcTool, doc); if(parse == Document::FullParse){ - VToolArc *toolArc = new VToolArc(doc, data, id, mode, typeCreation); + VToolArc *toolArc = new VToolArc(doc, data, id, typeCreation); scene->addItem(toolArc); connect(toolArc, &VToolArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(toolArc, &VToolArc::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); @@ -122,12 +113,12 @@ void VToolArc::ChangedActivDraw(const QString newName){ this->setPen(QPen(Qt::black, widthHairLine)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); - VAbstractTool::ChangedActivDraw(newName); + VDrawTool::ChangedActivDraw(newName); } else { this->setPen(QPen(Qt::gray, widthHairLine)); this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setAcceptHoverEvents (false); - VAbstractTool::ChangedActivDraw(newName); + VDrawTool::ChangedActivDraw(newName); } } @@ -148,12 +139,7 @@ void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ } void VToolArc::AddToFile(){ - VArc arc; - if(mode == Draw::Calculation){ - arc = VAbstractTool::data.GetArc(id); - } else { - arc = VAbstractTool::data.GetModelingArc(id); - } + VArc arc = VAbstractTool::data.GetArc(id); QDomElement domElement = doc->createElement("arc"); AddAttribute(domElement, "id", id); @@ -163,7 +149,7 @@ void VToolArc::AddToFile(){ AddAttribute(domElement, "angle1", arc.GetFormulaF1()); AddAttribute(domElement, "angle2", arc.GetFormulaF2()); - AddToDraw(domElement); + AddToCalculation(domElement); } void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ diff --git a/tools/drawTools/vtoolarc.h b/tools/drawTools/vtoolarc.h new file mode 100644 index 000000000..118f97ecb --- /dev/null +++ b/tools/drawTools/vtoolarc.h @@ -0,0 +1,39 @@ +#ifndef VTOOLARC_H +#define VTOOLARC_H + +#include "vdrawtool.h" +#include "../../xml/vdomdocument.h" +#include +#include "../../dialogs/dialogarc.h" +#include "../../widgets/vcontrolpointspline.h" +#include "../../container/vcontainer.h" + +class VToolArc :public VDrawTool, public QGraphicsPathItem +{ + Q_OBJECT +public: + VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void Create(const qint64 _id, const qint64 ¢er, const QString &radius, + const QString &f1, const QString &f2, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data, Document::Enum parse, Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void ChangedActivDraw(const QString newName); + virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + QSharedPointer dialogArc; + void RefreshGeometry(); +}; + +#endif // VTOOLARC_H diff --git a/tools/vtoolbisector.cpp b/tools/drawTools/vtoolbisector.cpp similarity index 87% rename from tools/vtoolbisector.cpp rename to tools/drawTools/vtoolbisector.cpp index 13cd68072..b19a7ba31 100644 --- a/tools/vtoolbisector.cpp +++ b/tools/drawTools/vtoolbisector.cpp @@ -1,13 +1,11 @@ -#pragma GCC diagnostic ignored "-Weffc++" #include "vtoolbisector.h" #include -#pragma GCC diagnostic warning "-Weffc++" -VToolBisector::VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode, +VToolBisector::VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const qint64 &thirdPointId, Tool::Enum typeCreation, QGraphicsItem *parent): - VToolLinePoint(doc, data, id, mode, typeLine, formula, secondPointId, 0, parent), firstPointId(0), + VToolLinePoint(doc, data, id, typeLine, formula, secondPointId, 0, parent), firstPointId(0), thirdPointId(0), dialogBisector(QSharedPointer()){ this->firstPointId = firstPointId; this->thirdPointId = thirdPointId; @@ -44,7 +42,7 @@ void VToolBisector::setDialog(){ } void VToolBisector::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Draw::Mode mode){ + VDomDocument *doc, VContainer *data){ QString formula = dialog->getFormula(); qint64 firstPointId = dialog->getFirstPointId(); qint64 secondPointId = dialog->getSecondPointId(); @@ -52,14 +50,14 @@ void VToolBisector::Create(QSharedPointer &dialog, VMainGraphics QString typeLine = dialog->getTypeLine(); QString pointName = dialog->getPointName(); Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, pointName, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui, mode); + Document::FullParse, Tool::FromGui); } void VToolBisector::Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const qint64 &thirdPointId, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode){ + Document::Enum parse, Tool::Enum typeCreation){ VPointF firstPoint = data->GetPoint(firstPointId); VPointF secondPoint = data->GetPoint(secondPointId); VPointF thirdPoint = data->GetPoint(thirdPointId); @@ -85,14 +83,9 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 } } data->AddLine(firstPointId, id); - VAbstractTool::AddRecord(id, Tools::BisectorTool, doc); - if(mode == Draw::Modeling){ - data->IncrementReferens(firstPointId, Scene::Point); - data->IncrementReferens(secondPointId, Scene::Point); - data->IncrementReferens(thirdPointId, Scene::Point); - } + VDrawTool::AddRecord(id, Tools::BisectorTool, doc); if(parse == Document::FullParse){ - VToolBisector *point = new VToolBisector(doc, data, id, mode, typeLine, formula, + VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId, thirdPointId, typeCreation); scene->addItem(point); @@ -137,12 +130,7 @@ void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ } void VToolBisector::AddToFile(){ - VPointF point; - if(mode == Draw::Calculation){ - point = VAbstractTool::data.GetPoint(id); - } else { - point = VAbstractTool::data.GetModelingPoint(id); - } + VPointF point = VAbstractTool::data.GetPoint(id); QDomElement domElement = doc->createElement("point"); AddAttribute(domElement, "id", id); @@ -157,5 +145,5 @@ void VToolBisector::AddToFile(){ AddAttribute(domElement, "secondPoint", basePointId); AddAttribute(domElement, "thirdPoint", thirdPointId); - AddToDraw(domElement); + AddToCalculation(domElement); } diff --git a/tools/vtoolbisector.h b/tools/drawTools/vtoolbisector.h similarity index 84% rename from tools/vtoolbisector.h rename to tools/drawTools/vtoolbisector.h index 25d1a84e6..34c36f0c3 100644 --- a/tools/vtoolbisector.h +++ b/tools/drawTools/vtoolbisector.h @@ -1,16 +1,14 @@ #ifndef VTOOLBISECTOR_H #define VTOOLBISECTOR_H -#pragma GCC diagnostic ignored "-Weffc++" #include #include "vtoollinepoint.h" -#include "../dialogs/dialogbisector.h" -#pragma GCC diagnostic warning "-Weffc++" +#include "../../dialogs/dialogbisector.h" class VToolBisector : public VToolLinePoint { public: - VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode, + VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const qint64 &thirdPointId, Tool::Enum typeCreation, QGraphicsItem * parent = 0); @@ -18,12 +16,11 @@ public: const QPointF &thirdPoint, const qreal& length); virtual void setDialog(); static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode); + VContainer *data); static void Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const qint64 &thirdPointId, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation, - Draw::Mode mode); + VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation); public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); diff --git a/tools/vtoolendline.cpp b/tools/drawTools/vtoolendline.cpp similarity index 83% rename from tools/vtoolendline.cpp rename to tools/drawTools/vtoolendline.cpp index 6c207cd7a..a1e6f0d08 100644 --- a/tools/vtoolendline.cpp +++ b/tools/drawTools/vtoolendline.cpp @@ -1,15 +1,12 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include "vtoolendline.h" #include #include -#include "../widgets/vmaingraphicsscene.h" -#pragma GCC diagnostic pop +#include "../../widgets/vmaingraphicsscene.h" -VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode, const QString &typeLine, +VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint32 &angle, const qint64 &basePointId, Tool::Enum typeCreation, QGraphicsItem *parent): - VToolLinePoint(doc, data, id, mode, typeLine, formula, basePointId, angle, parent), + VToolLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent), dialogEndLine(QSharedPointer()){ if(typeCreation == Tool::FromGui){ @@ -30,20 +27,20 @@ void VToolEndLine::setDialog(){ } void VToolEndLine::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode){ + VContainer *data){ QString pointName = dialog->getPointName(); QString typeLine = dialog->getTypeLine(); QString formula = dialog->getFormula(); qint32 angle = dialog->getAngle(); qint64 basePointId = dialog->getBasePointId(); Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, - Tool::FromGui, mode); + Tool::FromGui); } void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QString &typeLine, const QString &formula, const qint32 &angle, const qint64 &basePointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode){ + VContainer *data, Document::Enum parse, Tool::Enum typeCreation){ VPointF basePoint = data->GetPoint(basePointId); QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y())); @@ -68,12 +65,9 @@ void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QStr } } data->AddLine(basePointId, id); - VAbstractTool::AddRecord(id, Tools::EndLineTool, doc); - if(mode == Draw::Modeling){ - data->IncrementReferens(basePointId, Scene::Point); - } + VDrawTool::AddRecord(id, Tools::EndLineTool, doc); if(parse == Document::FullParse){ - VToolEndLine *point = new VToolEndLine(doc, data, id, mode, typeLine, formula, angle, + VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle, basePointId, typeCreation); scene->addItem(point); connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); @@ -115,25 +109,20 @@ void VToolEndLine::FullUpdateFromGui(int result){ } void VToolEndLine::AddToFile(){ - VPointF point; - if(mode == Draw::Calculation){ - point = VAbstractTool::data.GetPoint(id); - } else { - point = VAbstractTool::data.GetModelingPoint(id); - } + VPointF point = VAbstractTool::data.GetPoint(id); QDomElement domElement = doc->createElement("point"); AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "endLine"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "typeLine", typeLine); AddAttribute(domElement, "length", formula); AddAttribute(domElement, "angle", angle); AddAttribute(domElement, "basePoint", basePointId); - AddToDraw(domElement); + AddToCalculation(domElement); } diff --git a/tools/vtoolendline.h b/tools/drawTools/vtoolendline.h similarity index 80% rename from tools/vtoolendline.h rename to tools/drawTools/vtoolendline.h index 5e86f98c6..d8f155a0a 100644 --- a/tools/vtoolendline.h +++ b/tools/drawTools/vtoolendline.h @@ -1,28 +1,25 @@ #ifndef VTOOLENDLINE_H #define VTOOLENDLINE_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include #include "vtoollinepoint.h" -#include "../dialogs/dialogendline.h" -#pragma GCC diagnostic pop +#include "dialogs/dialogendline.h" class VToolEndLine : public VToolLinePoint { Q_OBJECT public: - VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode, + VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint32 &angle, const qint64 &basePointId, Tool::Enum typeCreation, QGraphicsItem * parent = 0); virtual void setDialog(); static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode); + VContainer *data); static void Create(const qint64 _id, const QString &pointName, const QString &typeLine, const QString &formula, const qint32 &angle, const qint64 &basePointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse, - Tool::Enum typeCreation, Draw::Mode mode); + Tool::Enum typeCreation); public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); diff --git a/tools/vtoolline.cpp b/tools/drawTools/vtoolline.cpp similarity index 82% rename from tools/vtoolline.cpp rename to tools/drawTools/vtoolline.cpp index bf54a8faa..aefb8985e 100644 --- a/tools/vtoolline.cpp +++ b/tools/drawTools/vtoolline.cpp @@ -1,15 +1,9 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vtoolline.h" #include #include -#pragma GCC diagnostic pop -VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, qint64 firstPoint, qint64 secondPoint, - Tool::Enum typeCreation, QGraphicsItem *parent):VAbstractTool(doc, data, id, mode), +VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint, + Tool::Enum typeCreation, QGraphicsItem *parent):VDrawTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), secondPoint(secondPoint), dialogLine(QSharedPointer()){ //Лінія @@ -31,15 +25,15 @@ void VToolLine::setDialog(){ } void VToolLine::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode){ + VContainer *data){ qint64 firstPoint = dialog->getFirstPoint(); qint64 secondPoint = dialog->getSecondPoint(); - Create(0, firstPoint, secondPoint, scene, doc, data, Document::FullParse, Tool::FromGui, mode); + Create(0, firstPoint, secondPoint, scene, doc, data, Document::FullParse, Tool::FromGui); } void VToolLine::Create(const qint64 &id, const qint64 &firstPoint, const qint64 &secondPoint, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse, - Tool::Enum typeCreation, Draw::Mode mode){ + Tool::Enum typeCreation){ Q_CHECK_PTR(scene); Q_CHECK_PTR(doc); Q_CHECK_PTR(data); @@ -51,14 +45,10 @@ void VToolLine::Create(const qint64 &id, const qint64 &firstPoint, const qint64 Q_CHECK_PTR(tool); tool->VDataTool::setData(data); } - VAbstractTool::AddRecord(id, Tools::LineTool, doc); - if(mode == Draw::Modeling){ - data->IncrementReferens(firstPoint, Scene::Point); - data->IncrementReferens(secondPoint, Scene::Point); - } + VDrawTool::AddRecord(id, Tools::LineTool, doc); if(parse == Document::FullParse){ qint64 id = data->getNextId(); - VToolLine *line = new VToolLine(doc, data, id, mode, firstPoint, secondPoint, typeCreation); + VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeCreation); Q_CHECK_PTR(line); scene->addItem(line); connect(line, &VToolLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); @@ -107,11 +97,11 @@ void VToolLine::ChangedActivDraw(const QString newName){ if(nameActivDraw == newName){ this->setPen(QPen(Qt::black, widthHairLine)); this->setAcceptHoverEvents (true); - VAbstractTool::ChangedActivDraw(newName); + VDrawTool::ChangedActivDraw(newName); } else { this->setPen(QPen(Qt::gray, widthHairLine)); this->setAcceptHoverEvents (false); - VAbstractTool::ChangedActivDraw(newName); + VDrawTool::ChangedActivDraw(newName); } } @@ -126,7 +116,7 @@ void VToolLine::AddToFile(){ AddAttribute(domElement, "firstPoint", firstPoint); AddAttribute(domElement, "secondPoint", secondPoint); - AddToDraw(domElement); + AddToCalculation(domElement); } void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ diff --git a/tools/vtoolline.h b/tools/drawTools/vtoolline.h similarity index 66% rename from tools/vtoolline.h rename to tools/drawTools/vtoolline.h index b9e4f0391..b9727fb6f 100644 --- a/tools/vtoolline.h +++ b/tools/drawTools/vtoolline.h @@ -1,28 +1,22 @@ #ifndef VTOOLLINE_H #define VTOOLLINE_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" -#include "vabstracttool.h" +#include "vdrawtool.h" #include "QGraphicsLineItem" -#include "../dialogs/dialogline.h" -#pragma GCC diagnostic pop +#include "../../dialogs/dialogline.h" -class VToolLine: public VAbstractTool, public QGraphicsLineItem +class VToolLine: public VDrawTool, public QGraphicsLineItem { Q_OBJECT public: - VToolLine(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, qint64 firstPoint, + VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint, Tool::Enum typeCreation, QGraphicsItem * parent = 0); virtual void setDialog(); static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode); + VContainer *data); static void Create(const qint64 &id, const qint64 &firstPoint, const qint64 &secondPoint, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse, - Tool::Enum typeCreation, Draw::Mode mode); + Tool::Enum typeCreation); public slots: virtual void FullUpdateFromFile(); virtual void ChangedActivDraw(const QString newName); diff --git a/tools/vtoollineintersect.cpp b/tools/drawTools/vtoollineintersect.cpp similarity index 83% rename from tools/vtoollineintersect.cpp rename to tools/drawTools/vtoollineintersect.cpp index 48f45290f..4e4d64df4 100644 --- a/tools/vtoollineintersect.cpp +++ b/tools/drawTools/vtoollineintersect.cpp @@ -1,16 +1,10 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vtoollineintersect.h" #include -#pragma GCC diagnostic pop -VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode, +VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &p1Line1, const qint64 &p2Line1, const qint64 &p1Line2, const qint64 &p2Line2, Tool::Enum typeCreation, QGraphicsItem *parent): - VToolPoint(doc, data, id, mode, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2), + VToolPoint(doc, data, id, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2), p2Line2(p2Line2), dialogLineIntersect(QSharedPointer()){ if(typeCreation == Tool::FromGui){ AddToFile(); @@ -30,20 +24,20 @@ void VToolLineIntersect::setDialog(){ } void VToolLineIntersect::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Draw::Mode mode){ + VDomDocument *doc, VContainer *data){ qint64 p1Line1Id = dialog->getP1Line1(); qint64 p2Line1Id = dialog->getP2Line1(); qint64 p1Line2Id = dialog->getP1Line2(); qint64 p2Line2Id = dialog->getP2Line2(); QString pointName = dialog->getPointName(); Create(0, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, pointName, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui, mode); + Document::FullParse, Tool::FromGui); } void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, const qint64 &p1Line2Id, const qint64 &p2Line2Id, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode){ + VContainer *data, Document::Enum parse, Tool::Enum typeCreation){ VPointF p1Line1 = data->GetPoint(p1Line1Id); VPointF p2Line1 = data->GetPoint(p2Line1Id); VPointF p1Line2 = data->GetPoint(p1Line2Id); @@ -72,15 +66,9 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const data->AddLine(id, p2Line1Id); data->AddLine(p1Line2Id, id); data->AddLine(id, p2Line2Id); - if(mode == Draw::Modeling){ - data->IncrementReferens(p1Line1Id, Scene::Point); - data->IncrementReferens(p2Line1Id, Scene::Point); - data->IncrementReferens(p1Line2Id, Scene::Point); - data->IncrementReferens(p2Line2Id, Scene::Point); - } - VAbstractTool::AddRecord(id, Tools::LineIntersectTool, doc); + VDrawTool::AddRecord(id, Tools::LineIntersectTool, doc); if(parse == Document::FullParse){ - VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, mode, p1Line1Id, + VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, typeCreation); scene->addItem(point); @@ -100,7 +88,7 @@ void VToolLineIntersect::FullUpdateFromFile(){ p1Line2 = domElement.attribute("p1Line2", "").toLongLong(); p2Line2 = domElement.attribute("p2Line2", "").toLongLong(); } - RefreshGeometry(); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); } void VToolLineIntersect::FullUpdateFromGui(int result){ @@ -123,12 +111,7 @@ void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } void VToolLineIntersect::AddToFile(){ - VPointF point; - if(mode == Draw::Calculation){ - point = VAbstractTool::data.GetPoint(id); - } else { - point = VAbstractTool::data.GetModelingPoint(id); - } + VPointF point = VAbstractTool::data.GetPoint(id); QDomElement domElement = doc->createElement("point"); AddAttribute(domElement, "id", id); @@ -142,5 +125,5 @@ void VToolLineIntersect::AddToFile(){ AddAttribute(domElement, "p1Line2", p1Line2); AddAttribute(domElement, "p2Line2", p2Line2); - AddToDraw(domElement); + AddToCalculation(domElement); } diff --git a/tools/vtoollineintersect.h b/tools/drawTools/vtoollineintersect.h similarity index 80% rename from tools/vtoollineintersect.h rename to tools/drawTools/vtoollineintersect.h index 941795d46..1b84a2bc2 100644 --- a/tools/vtoollineintersect.h +++ b/tools/drawTools/vtoollineintersect.h @@ -1,31 +1,26 @@ #ifndef VTOOLLINEINTERSECT_H #define VTOOLLINEINTERSECT_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vtoolpoint.h" -#include "../dialogs/dialoglineintersect.h" -#pragma GCC diagnostic pop +#include "dialogs/dialoglineintersect.h" class VToolLineIntersect:public VToolPoint { + Q_OBJECT public: VToolLineIntersect(VDomDocument *doc, VContainer *data, - const qint64 &id, Draw::Mode mode, + const qint64 &id, const qint64 &p1Line1, const qint64 &p2Line1, const qint64 &p1Line2, const qint64 &p2Line2, Tool::Enum typeCreation, QGraphicsItem * parent = 0); virtual void setDialog(); static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc,VContainer *data, Draw::Mode mode); + VDomDocument *doc,VContainer *data); static void Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, const qint64 &p1Line2Id, const qint64 &p2Line2Id, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode); + VContainer *data, Document::Enum parse, Tool::Enum typeCreation); public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); diff --git a/tools/vtoollinepoint.cpp b/tools/drawTools/vtoollinepoint.cpp similarity index 59% rename from tools/vtoollinepoint.cpp rename to tools/drawTools/vtoollinepoint.cpp index 5f9b4b4d5..9f471d27d 100644 --- a/tools/vtoollinepoint.cpp +++ b/tools/drawTools/vtoollinepoint.cpp @@ -1,15 +1,9 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vtoollinepoint.h" -#pragma GCC diagnostic pop -VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode, const QString &typeLine, - const QString &formula, const qint64 &basePointId, const qint32 &angle, - QGraphicsItem *parent): VToolPoint(doc, data, id, mode, parent), typeLine(typeLine), formula(formula), - angle(angle), basePointId(basePointId), mainLine(0){ +VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qint64 &basePointId, + const qint32 &angle, QGraphicsItem *parent):VToolPoint(doc, data, id, parent), + typeLine(typeLine), formula(formula), angle(angle), basePointId(basePointId), mainLine(0){ //Лінія, що з'єднує дві точки QPointF point1 = data->GetPoint(basePointId).toQPointF(); QPointF point2 = data->GetPoint(id).toQPointF(); @@ -34,9 +28,9 @@ void VToolLinePoint::ChangedActivDraw(const QString newName){ } void VToolLinePoint::RefreshGeometry(){ - VToolPoint::RefreshGeometry(); - QPointF point = VAbstractTool::data.GetPoint(id).toQPointF(); - QPointF basePoint = VAbstractTool::data.GetPoint(basePointId).toQPointF(); + VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id)); + QPointF point = VDrawTool::data.GetPoint(id).toQPointF(); + QPointF basePoint = VDrawTool::data.GetPoint(basePointId).toQPointF(); mainLine->setLine(QLineF(basePoint - point, point - point)); if(typeLine == "none"){ mainLine->setVisible(false); diff --git a/tools/vtoollinepoint.h b/tools/drawTools/vtoollinepoint.h similarity index 67% rename from tools/vtoollinepoint.h rename to tools/drawTools/vtoollinepoint.h index ea960c9c3..a34ae1490 100644 --- a/tools/vtoollinepoint.h +++ b/tools/drawTools/vtoollinepoint.h @@ -1,29 +1,27 @@ #ifndef VTOOLLINEPOINT_H #define VTOOLLINEPOINT_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include "vtoolpoint.h" -#pragma GCC diagnostic pop class VToolLinePoint : public VToolPoint { + Q_OBJECT public: - VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode, + VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint64 &basePointId, const qint32 &angle, QGraphicsItem * parent = 0); public slots: - virtual void ChangedActivDraw(const QString newName); - virtual void RefreshGeometry(); + virtual void ChangedActivDraw(const QString newName); protected: QString typeLine; QString formula; qint32 angle; qint64 basePointId; QGraphicsLineItem *mainLine; + virtual void RefreshGeometry(); private: - VToolLinePoint(const VToolLinePoint &tool); - const VToolLinePoint &operator=(const VToolLinePoint &tool); + VToolLinePoint(const VToolLinePoint &tool); + const VToolLinePoint &operator=(const VToolLinePoint &tool); }; #endif // VTOOLLINEPOINT_H diff --git a/tools/vtoolnormal.cpp b/tools/drawTools/vtoolnormal.cpp similarity index 84% rename from tools/vtoolnormal.cpp rename to tools/drawTools/vtoolnormal.cpp index 7ee78ab94..7af9b45be 100644 --- a/tools/vtoolnormal.cpp +++ b/tools/drawTools/vtoolnormal.cpp @@ -1,17 +1,11 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vtoolnormal.h" #include -#pragma GCC diagnostic pop -VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode, +VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qreal &angle, const qint64 &firstPointId, const qint64 &secondPointId, Tool::Enum typeCreation, QGraphicsItem *parent): - VToolLinePoint(doc, data, id, mode, typeLine, formula, firstPointId, angle, parent), + VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, angle, parent), secondPointId(secondPointId), dialogNormal(QSharedPointer()){ if(typeCreation == Tool::FromGui){ @@ -34,7 +28,7 @@ void VToolNormal::setDialog(){ } void VToolNormal::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode){ + VContainer *data){ QString formula = dialog->getFormula(); qint64 firstPointId = dialog->getFirstPointId(); qint64 secondPointId = dialog->getSecondPointId(); @@ -42,14 +36,13 @@ void VToolNormal::Create(QSharedPointer &dialog, VMainGraphicsScen QString pointName = dialog->getPointName(); qint32 angle = dialog->getAngle(); Create(0, formula, firstPointId, secondPointId, typeLine, pointName, angle, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui, mode); + Document::FullParse, Tool::FromGui); } void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const QString typeLine, const QString pointName, const qreal angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation, - Draw::Mode mode){ + VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation){ VPointF firstPoint = data->GetPoint(firstPointId); VPointF secondPoint = data->GetPoint(secondPointId); Calculator cal(data); @@ -73,13 +66,9 @@ void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 } } data->AddLine(firstPointId, id); - VAbstractTool::AddRecord(id, Tools::NormalTool, doc); - if(mode == Draw::Modeling){ - data->IncrementReferens(firstPointId, Scene::Point); - data->IncrementReferens(secondPointId, Scene::Point); - } + VDrawTool::AddRecord(id, Tools::NormalTool, doc); if(parse == Document::FullParse){ - VToolNormal *point = new VToolNormal(doc, data, id, mode, typeLine, formula, angle, + VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle, firstPointId, secondPointId, typeCreation); scene->addItem(point); connect(point, &VToolNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); @@ -132,12 +121,7 @@ void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ } void VToolNormal::AddToFile(){ - VPointF point; - if(mode == Draw::Calculation){ - point = VAbstractTool::data.GetPoint(id); - } else { - point = VAbstractTool::data.GetModelingPoint(id); - } + VPointF point = VAbstractTool::data.GetPoint(id); QDomElement domElement = doc->createElement("point"); AddAttribute(domElement, "id", id); @@ -152,5 +136,5 @@ void VToolNormal::AddToFile(){ AddAttribute(domElement, "firstPoint", basePointId); AddAttribute(domElement, "secondPoint", secondPointId); - AddToDraw(domElement); + AddToCalculation(domElement); } diff --git a/tools/vtoolnormal.h b/tools/drawTools/vtoolnormal.h similarity index 77% rename from tools/vtoolnormal.h rename to tools/drawTools/vtoolnormal.h index 6c6410c14..7628c5a7d 100644 --- a/tools/vtoolnormal.h +++ b/tools/drawTools/vtoolnormal.h @@ -1,33 +1,26 @@ #ifndef VTOOLNORMAL_H #define VTOOLNORMAL_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include #include "vtoollinepoint.h" -#include "../dialogs/dialognormal.h" -#pragma GCC diagnostic pop +#include "dialogs/dialognormal.h" class VToolNormal : public VToolLinePoint { + Q_OBJECT public: VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, - Draw::Mode mode, const QString &typeLine, const QString &formula, const qreal &angle, const qint64 &firstPointId, const qint64 &secondPointId, Tool::Enum typeCreation, QGraphicsItem * parent = 0); virtual void setDialog(); static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode); + VContainer *data); static void Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const QString typeLine, const QString pointName, const qreal angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation, - Draw::Mode mode); + VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation); static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length, const qreal &angle = 0); public slots: diff --git a/tools/drawTools/vtoolpoint.cpp b/tools/drawTools/vtoolpoint.cpp new file mode 100644 index 000000000..eaac01cf3 --- /dev/null +++ b/tools/drawTools/vtoolpoint.cpp @@ -0,0 +1,125 @@ +#include "vtoolpoint.h" +#include +#include +#include +#include +#include "container/vpointf.h" + + +VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, + QGraphicsItem *parent):VDrawTool(doc, data, id), + QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0), lineName(0){ + namePoint = new VGraphicsSimpleTextItem(this); + lineName = new QGraphicsLineItem(this); + connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, + &VToolPoint::NameChangePosition); + this->setPen(QPen(Qt::black, widthHairLine)); + this->setBrush(QBrush(Qt::NoBrush)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); +} + +void VToolPoint::NameChangePosition(const QPointF pos){ + VPointF point = VAbstractTool::data.GetPoint(id); + QPointF p = pos - this->pos(); + point.setMx(p.x()); + point.setMy(p.y()); + RefreshLine(); + UpdateNamePosition(point.mx(), point.my()); + VAbstractTool::data.UpdatePoint(id, point); +} + +void VToolPoint::UpdateNamePosition(qreal mx, qreal my){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("mx", QString().setNum(toMM(mx))); + domElement.setAttribute("my", QString().setNum(toMM(my))); + emit toolhaveChange(); + } +} + +void VToolPoint::ChangedActivDraw(const QString newName){ + if(nameActivDraw == newName){ + this->setPen(QPen(Qt::black, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + namePoint->setFlag(QGraphicsItem::ItemIsMovable, true); + namePoint->setFlag(QGraphicsItem::ItemIsSelectable, true); + namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + namePoint->setBrush(QBrush(Qt::black)); + namePoint->setAcceptHoverEvents(true); + lineName->setPen(QPen(Qt::black, widthHairLine)); + VDrawTool::ChangedActivDraw(newName); + } else { + this->setPen(QPen(Qt::gray, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, false); + this->setAcceptHoverEvents (false); + namePoint->setFlag(QGraphicsItem::ItemIsMovable, false); + namePoint->setFlag(QGraphicsItem::ItemIsSelectable, false); + namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); + namePoint->setBrush(QBrush(Qt::gray)); + namePoint->setAcceptHoverEvents(false); + lineName->setPen(QPen(Qt::gray, widthHairLine)); + VDrawTool::ChangedActivDraw(newName); + } +} + +void VToolPoint::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ + if(id == this->id){ + if(enable == false){ + this->setPen(QPen(baseColor, widthHairLine)); + currentColor = baseColor; + } else { + this->setPen(QPen(color, widthHairLine)); + currentColor = color; + } + } +} + +void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(event->button() == Qt::LeftButton){ + emit ChoosedTool(id, Scene::Point); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VToolPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthMainLine)); +} + +void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthHairLine)); +} + +void VToolPoint::RefreshPointGeometry(const VPointF &point){ + QRectF rec = QRectF(0, 0, radius*2, radius*2); + rec.translate(-rec.center().x(), -rec.center().y()); + this->setRect(rec); + this->setPos(point.toQPointF()); + disconnect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, + &VToolPoint::NameChangePosition); + namePoint->setText(point.name()); + namePoint->setPos(QPointF(point.mx(), point.my())); + connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, + &VToolPoint::NameChangePosition); + RefreshLine(); +} + +void VToolPoint::RefreshLine(){ + QRectF nameRec = namePoint->sceneBoundingRect(); + QPointF p1, p2; + LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); + QPointF pRec = LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); + lineName->setLine(QLineF(p1, pRec - scenePos())); + if(QLineF(p1, pRec - scenePos()).length() <= toPixel(4)){ + lineName->setVisible(false); + } else { + lineName->setVisible(true); + } +} + +VToolPoint::~VToolPoint(){ +} diff --git a/tools/drawTools/vtoolpoint.h b/tools/drawTools/vtoolpoint.h new file mode 100644 index 000000000..cd7f92f97 --- /dev/null +++ b/tools/drawTools/vtoolpoint.h @@ -0,0 +1,34 @@ +#ifndef VTOOLPOINT_H +#define VTOOLPOINT_H + +#include "vdrawtool.h" +#include "widgets/vgraphicssimpletextitem.h" +#include "options.h" + +class VToolPoint: public VDrawTool, public QGraphicsEllipseItem +{ + Q_OBJECT +public: + VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem * parent = 0); + virtual ~VToolPoint(); +public slots: + void NameChangePosition(const QPointF pos); + virtual void ChangedActivDraw(const QString newName); + virtual void FullUpdateFromGui(int result) = 0; + virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); +protected: + qreal radius; + VGraphicsSimpleTextItem *namePoint; + QGraphicsLineItem *lineName; + virtual void UpdateNamePosition(qreal mx, qreal my); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RefreshPointGeometry(const VPointF &point); + void RefreshLine(); +private: + VToolPoint(const VToolPoint &tool); + const VToolPoint &operator=(const VToolPoint &tool); +}; + +#endif // VTOOLPOINT_H diff --git a/tools/vtoolpointofcontact.cpp b/tools/drawTools/vtoolpointofcontact.cpp similarity index 88% rename from tools/vtoolpointofcontact.cpp rename to tools/drawTools/vtoolpointofcontact.cpp index 00261faf1..7f315ae68 100644 --- a/tools/vtoolpointofcontact.cpp +++ b/tools/drawTools/vtoolpointofcontact.cpp @@ -1,11 +1,10 @@ #include "vtoolpointofcontact.h" VToolPointOfContact::VToolPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, - Draw::Mode mode, const QString &radius, const qint64 ¢er, const qint64 &firstPointId, const qint64 &secondPointId, Tool::Enum typeCreation, QGraphicsItem *parent) - : VToolPoint(doc, data, id, mode, parent), radius(radius), center(center), firstPointId(firstPointId), + : VToolPoint(doc, data, id, parent), radius(radius), center(center), firstPointId(firstPointId), secondPointId(secondPointId), dialogPointOfContact(QSharedPointer()){ if(typeCreation == Tool::FromGui){ @@ -48,21 +47,21 @@ QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF ¢e } void VToolPointOfContact::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Draw::Mode mode){ + VDomDocument *doc, VContainer *data){ QString radius = dialog->getRadius(); qint64 center = dialog->getCenter(); qint64 firstPointId = dialog->getFirstPoint(); qint64 secondPointId = dialog->getSecondPoint(); QString pointName = dialog->getPointName(); Create(0, radius, center, firstPointId, secondPointId, pointName, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui, mode); + Document::FullParse, Tool::FromGui); } void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const qint64 ¢er, const qint64 &firstPointId, const qint64 &secondPointId, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode){ + Document::Enum parse, Tool::Enum typeCreation){ VPointF centerP = data->GetPoint(center); VPointF firstP = data->GetPoint(firstPointId); VPointF secondP = data->GetPoint(secondPointId); @@ -87,14 +86,9 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const } } } - VAbstractTool::AddRecord(id, Tools::PointOfContact, doc); - if(mode == Draw::Modeling){ - data->IncrementReferens(center, Scene::Point); - data->IncrementReferens(firstPointId, Scene::Point); - data->IncrementReferens(secondPointId, Scene::Point); - } + VDrawTool::AddRecord(id, Tools::PointOfContact, doc); if(parse == Document::FullParse){ - VToolPointOfContact *point = new VToolPointOfContact(doc, data, id, mode, radius, center, + VToolPointOfContact *point = new VToolPointOfContact(doc, data, id, radius, center, firstPointId, secondPointId, typeCreation); scene->addItem(point); connect(point, &VToolPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); @@ -113,7 +107,7 @@ void VToolPointOfContact::FullUpdateFromFile(){ firstPointId = domElement.attribute("firstPoint", "").toLongLong(); secondPointId = domElement.attribute("secondPoint", "").toLongLong(); } - RefreshGeometry(); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); } void VToolPointOfContact::FullUpdateFromGui(int result){ @@ -136,12 +130,7 @@ void VToolPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event } void VToolPointOfContact::AddToFile(){ - VPointF point; - if(mode == Draw::Calculation){ - point = VAbstractTool::data.GetPoint(id); - } else { - point = VAbstractTool::data.GetModelingPoint(id); - } + VPointF point = VAbstractTool::data.GetPoint(id); QDomElement domElement = doc->createElement("point"); AddAttribute(domElement, "id", id); @@ -155,5 +144,5 @@ void VToolPointOfContact::AddToFile(){ AddAttribute(domElement, "firstPoint", firstPointId); AddAttribute(domElement, "secondPoint", secondPointId); - AddToDraw(domElement); + AddToCalculation(domElement); } diff --git a/tools/vtoolpointofcontact.h b/tools/drawTools/vtoolpointofcontact.h similarity index 88% rename from tools/vtoolpointofcontact.h rename to tools/drawTools/vtoolpointofcontact.h index f28ddc7c8..b091ad7e7 100644 --- a/tools/vtoolpointofcontact.h +++ b/tools/drawTools/vtoolpointofcontact.h @@ -2,23 +2,23 @@ #define VTOOLPOINTOFCONTACT_H #include "vtoolpoint.h" -#include "../dialogs/dialogpointofcontact.h" +#include "dialogs/dialogpointofcontact.h" class VToolPointOfContact : public VToolPoint { public: - VToolPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode, + VToolPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &radius, const qint64 ¢er, const qint64 &firstPointId, const qint64 &secondPointId, Tool::Enum typeCreation, QGraphicsItem * parent = 0); virtual void setDialog(); static QPointF FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, const QPointF &secondPoint); static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Draw::Mode mode); + VDomDocument *doc, VContainer *data); static void Create(const qint64 _id, const QString &radius, const qint64 ¢er, const qint64 &firstPointId, const qint64 &secondPointId, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode); + VContainer *data, Document::Enum parse, Tool::Enum typeCreation); public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); diff --git a/tools/vtoolshoulderpoint.cpp b/tools/drawTools/vtoolshoulderpoint.cpp similarity index 86% rename from tools/vtoolshoulderpoint.cpp rename to tools/drawTools/vtoolshoulderpoint.cpp index 269cdf4c3..3866441d8 100644 --- a/tools/vtoolshoulderpoint.cpp +++ b/tools/drawTools/vtoolshoulderpoint.cpp @@ -1,18 +1,12 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vtoolshoulderpoint.h" #include #include -#pragma GCC diagnostic pop -VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode, +VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint64 &p1Line, const qint64 &p2Line, const qint64 &pShoulder, Tool::Enum typeCreation, QGraphicsItem * parent): - VToolLinePoint(doc, data, id, mode, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), pShoulder(pShoulder), + VToolLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), pShoulder(pShoulder), dialogShoulderPoint(QSharedPointer()){ if(typeCreation == Tool::FromGui){ @@ -56,7 +50,7 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li } void VToolShoulderPoint::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Draw::Mode mode){ + VDomDocument *doc, VContainer *data){ QString formula = dialog->getFormula(); qint64 p1Line = dialog->getP1Line(); qint64 p2Line = dialog->getP2Line(); @@ -64,14 +58,14 @@ void VToolShoulderPoint::Create(QSharedPointer &dialog, VMa QString typeLine = dialog->getTypeLine(); QString pointName = dialog->getPointName(); Create(0, formula, p1Line, p2Line, pShoulder, typeLine, pointName, 5, 10, scene, doc, data, - Document::FullParse, Tool::FromGui, mode); + Document::FullParse, Tool::FromGui); } void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const qint64 &p1Line, const qint64 &p2Line, const qint64 &pShoulder, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode){ + Document::Enum parse, Tool::Enum typeCreation){ VPointF firstPoint = data->GetPoint(p1Line); VPointF secondPoint = data->GetPoint(p2Line); VPointF shoulderPoint = data->GetPoint(pShoulder); @@ -98,14 +92,9 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const } data->AddLine(p1Line, id); data->AddLine(p2Line, id); - VAbstractTool::AddRecord(id, Tools::ShoulderPointTool, doc); - if(mode == Draw::Modeling){ - data->IncrementReferens(p1Line, Scene::Point); - data->IncrementReferens(p2Line, Scene::Point); - data->IncrementReferens(pShoulder, Scene::Point); - } + VDrawTool::AddRecord(id, Tools::ShoulderPointTool, doc); if(parse == Document::FullParse){ - VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, mode, typeLine, formula, + VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula, p1Line, p2Line, pShoulder, typeCreation); scene->addItem(point); @@ -150,12 +139,7 @@ void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } void VToolShoulderPoint::AddToFile(){ - VPointF point; - if(mode == Draw::Calculation){ - point = VAbstractTool::data.GetPoint(id); - } else { - point = VAbstractTool::data.GetModelingPoint(id); - } + VPointF point = VAbstractTool::data.GetPoint(id); QDomElement domElement = doc->createElement("point"); AddAttribute(domElement, "id", id); @@ -170,5 +154,5 @@ void VToolShoulderPoint::AddToFile(){ AddAttribute(domElement, "p2Line", p2Line); AddAttribute(domElement, "pShoulder", pShoulder); - AddToDraw(domElement); + AddToCalculation(domElement); } diff --git a/tools/vtoolshoulderpoint.h b/tools/drawTools/vtoolshoulderpoint.h similarity index 77% rename from tools/vtoolshoulderpoint.h rename to tools/drawTools/vtoolshoulderpoint.h index cb1e0ae13..68ab7b42e 100644 --- a/tools/vtoolshoulderpoint.h +++ b/tools/drawTools/vtoolshoulderpoint.h @@ -1,19 +1,13 @@ #ifndef VTOOLSHOULDERPOINT_H #define VTOOLSHOULDERPOINT_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vtoollinepoint.h" -#include "../dialogs/dialogshoulderpoint.h" -#pragma GCC diagnostic pop +#include "dialogs/dialogshoulderpoint.h" class VToolShoulderPoint : public VToolLinePoint { public: - VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, Draw::Mode mode, + VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint64 &p1Line, const qint64 &p2Line, const qint64 &pShoulder, Tool::Enum typeCreation, QGraphicsItem * parent = 0); @@ -21,11 +15,11 @@ public: static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, const qreal &length); static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Draw::Mode mode); + VDomDocument *doc, VContainer *data); static void Create(const qint64 _id, const QString &formula, const qint64 &p1Line, const qint64 &p2Line, const qint64 &pShoulder, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode); + VContainer *data, Document::Enum parse, Tool::Enum typeCreation); public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); diff --git a/tools/vtoolsinglepoint.cpp b/tools/drawTools/vtoolsinglepoint.cpp similarity index 75% rename from tools/vtoolsinglepoint.cpp rename to tools/drawTools/vtoolsinglepoint.cpp index 4645334a0..56f9b5a31 100644 --- a/tools/vtoolsinglepoint.cpp +++ b/tools/drawTools/vtoolsinglepoint.cpp @@ -1,8 +1,3 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vtoolsinglepoint.h" #include #include @@ -10,14 +5,12 @@ #include #include #include -#pragma GCC diagnostic pop #include -#include "../options.h" -#include "../container/vpointf.h" +#include "options.h" +#include "container/vpointf.h" VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, - QGraphicsItem * parent ):VToolPoint(doc, data, id, Draw::Calculation, - parent), + QGraphicsItem * parent ):VToolPoint(doc, data, id, parent), dialogSinglePoint(QSharedPointer()){ this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); @@ -41,12 +34,12 @@ void VToolSinglePoint::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "single"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "x", point.x()/PrintDPI*25.4); - AddAttribute(domElement, "y", point.y()/PrintDPI*25.4); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "x", toMM(point.x())); + AddAttribute(domElement, "y", toMM(point.y())); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); - AddToDraw(domElement); + AddToCalculation(domElement); } QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){ @@ -66,8 +59,8 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, QPointF newPos = value.toPointF(); QDomElement domElement = doc->elementById(QString().setNum(id)); if(domElement.isElement()){ - domElement.setAttribute("x", QString().setNum(newPos.x()/PrintDPI*25.4)); - domElement.setAttribute("y", QString().setNum(newPos.y()/PrintDPI*25.4)); + domElement.setAttribute("x", QString().setNum(toMM(newPos.x()))); + domElement.setAttribute("y", QString().setNum(toMM(newPos.y()))); //I don't now why but signal does not work. doc->FullUpdateTree(); } @@ -80,7 +73,7 @@ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event } void VToolSinglePoint::FullUpdateFromFile(){ - RefreshGeometry(); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); } void VToolSinglePoint::FullUpdateFromGui(int result){ @@ -90,8 +83,8 @@ void VToolSinglePoint::FullUpdateFromGui(int result){ QDomElement domElement = doc->elementById(QString().setNum(id)); if(domElement.isElement()){ domElement.setAttribute("name", name); - domElement.setAttribute("x", QString().setNum(p.x()/PrintDPI*25.4)); - domElement.setAttribute("y", QString().setNum(p.y()/PrintDPI*25.4)); + domElement.setAttribute("x", QString().setNum(toMM(p.x()))); + domElement.setAttribute("y", QString().setNum(toMM(p.y()))); //I don't now why but signal does not work. doc->FullUpdateTree(); } diff --git a/tools/drawTools/vtoolsinglepoint.h b/tools/drawTools/vtoolsinglepoint.h new file mode 100644 index 000000000..c33d0f797 --- /dev/null +++ b/tools/drawTools/vtoolsinglepoint.h @@ -0,0 +1,30 @@ +#ifndef VTOOLSINGLEPOINT_H +#define VTOOLSINGLEPOINT_H + +#include "container/vcontainer.h" +#include "xml/vdomdocument.h" +#include "dialogs/dialogsinglepoint.h" +#include "vtoolpoint.h" + +class VToolSinglePoint : public VToolPoint +{ + Q_OBJECT +public: + VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, + Tool::Enum typeCreation, QGraphicsItem * parent = 0 ); + virtual void setDialog(); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void ChangedActivDraw(const QString newName); +signals: + void FullUpdateTree(); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); +private: + QSharedPointer dialogSinglePoint; +}; + +#endif // VTOOLSINGLEPOINT_H diff --git a/tools/vtoolspline.cpp b/tools/drawTools/vtoolspline.cpp similarity index 90% rename from tools/vtoolspline.cpp rename to tools/drawTools/vtoolspline.cpp index 801868191..dc848a62e 100644 --- a/tools/vtoolspline.cpp +++ b/tools/drawTools/vtoolspline.cpp @@ -1,18 +1,12 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vtoolspline.h" #include #include -#pragma GCC diagnostic pop -#include "../geometry/vspline.h" +#include "geometry/vspline.h" -VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, +VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, - QGraphicsItem *parent):VAbstractTool(doc, data, id, mode), QGraphicsPathItem(parent), + QGraphicsItem *parent):VDrawTool(doc, data, id), QGraphicsPathItem(parent), dialogSpline(QSharedPointer()), controlPoints(QVector()){ VSpline spl = data->GetSpline(id); @@ -60,7 +54,7 @@ void VToolSpline::setDialog(){ } void VToolSpline::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode){ + VContainer *data){ qint64 p1 = dialog->getP1(); qint64 p4 = dialog->getP4(); qreal kAsm1 = dialog->getKAsm1(); @@ -69,13 +63,13 @@ void VToolSpline::Create(QSharedPointer &dialog, VMainGraphicsScen qreal angle2 = dialog->getAngle2(); qreal kCurve = dialog->getKCurve(); Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, doc, data, Document::FullParse, - Tool::FromGui, mode); + Tool::FromGui); } void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse, - Tool::Enum typeCreation, Draw::Mode mode){ + Tool::Enum typeCreation){ VSpline spline = VSpline(data->DataPoints(), p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve); qint64 id = _id; if(typeCreation == Tool::FromGui){ @@ -92,13 +86,9 @@ void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, c } } data->AddLengthSpline(data->GetNameSpline(p1, p4), spline.GetLength()); - VAbstractTool::AddRecord(id, Tools::SplineTool, doc); - if(mode == Draw::Modeling){ - data->IncrementReferens(p1, Scene::Point); - data->IncrementReferens(p4, Scene::Point); - } + VDrawTool::AddRecord(id, Tools::SplineTool, doc); if(parse == Document::FullParse){ - VToolSpline *spl = new VToolSpline(doc, data, id, mode, typeCreation); + VToolSpline *spl = new VToolSpline(doc, data, id, typeCreation); scene->addItem(spl); connect(spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(spl, &VToolSpline::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); @@ -170,12 +160,7 @@ void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ } void VToolSpline::AddToFile(){ - VSpline spl; - if(mode == Draw::Calculation){ - spl = VAbstractTool::data.GetSpline(id); - } else { - spl = VAbstractTool::data.GetModelingSpline(id); - } + VSpline spl = VAbstractTool::data.GetSpline(id); QDomElement domElement = doc->createElement("spline"); AddAttribute(domElement, "id", id); @@ -188,7 +173,7 @@ void VToolSpline::AddToFile(){ AddAttribute(domElement, "kAsm2", spl.GetKasm2()); AddAttribute(domElement, "kCurve", spl.GetKcurve()); - AddToDraw(domElement); + AddToCalculation(domElement); } void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ @@ -240,13 +225,13 @@ void VToolSpline::ChangedActivDraw(const QString newName){ this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); emit setEnabledPoint(true); - VAbstractTool::ChangedActivDraw(newName); + VDrawTool::ChangedActivDraw(newName); } else { this->setPen(QPen(Qt::gray, widthHairLine)); this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setAcceptHoverEvents (false); emit setEnabledPoint(false); - VAbstractTool::ChangedActivDraw(newName); + VDrawTool::ChangedActivDraw(newName); } } diff --git a/tools/vtoolspline.h b/tools/drawTools/vtoolspline.h similarity index 75% rename from tools/vtoolspline.h rename to tools/drawTools/vtoolspline.h index 48b2726a9..edcd563ae 100644 --- a/tools/vtoolspline.h +++ b/tools/drawTools/vtoolspline.h @@ -1,33 +1,27 @@ #ifndef VTOOLSPLINE_H #define VTOOLSPLINE_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" -#include "vabstracttool.h" -#include "../xml/vdomdocument.h" +#include "vdrawtool.h" +#include "xml/vdomdocument.h" #include -#include "../dialogs/dialogspline.h" -#include "../widgets/vcontrolpointspline.h" -#include "../container/vcontainer.h" -#pragma GCC diagnostic pop -#include "../geometry/vsplinepath.h" +#include "dialogs/dialogspline.h" +#include "widgets/vcontrolpointspline.h" +#include "container/vcontainer.h" +#include "geometry/vsplinepath.h" -class VToolSpline:public VAbstractTool, public QGraphicsPathItem +class VToolSpline:public VDrawTool, public QGraphicsPathItem { Q_OBJECT public: - VToolSpline (VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, + VToolSpline (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, QGraphicsItem * parent = 0 ); virtual void setDialog(); static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode); + VContainer *data); static void Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse, - Tool::Enum typeCreation, Draw::Mode mode); + Tool::Enum typeCreation); signals: void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position, const QPointF &controlPoint, const QPointF &splinePoint ); diff --git a/tools/vtoolsplinepath.cpp b/tools/drawTools/vtoolsplinepath.cpp similarity index 94% rename from tools/vtoolsplinepath.cpp rename to tools/drawTools/vtoolsplinepath.cpp index 18d5a0fe6..89b2131eb 100644 --- a/tools/vtoolsplinepath.cpp +++ b/tools/drawTools/vtoolsplinepath.cpp @@ -1,9 +1,9 @@ #include "vtoolsplinepath.h" #include -VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, +VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, - QGraphicsItem *parent):VAbstractTool(doc, data, id, mode), + QGraphicsItem *parent):VDrawTool(doc, data, id), QGraphicsPathItem(parent), dialogSplinePath(QSharedPointer()), controlPoints(QVector()){ VSplinePath splPath = data->GetSplinePath(id); @@ -47,14 +47,14 @@ void VToolSplinePath::setDialog(){ } void VToolSplinePath::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Draw::Mode mode){ + VDomDocument *doc, VContainer *data){ VSplinePath path = dialog->GetPath(); - Create(0, path, scene, doc, data, Document::FullParse, Tool::FromGui, mode); + Create(0, path, scene, doc, data, Document::FullParse, Tool::FromGui); } void VToolSplinePath::Create(const qint64 _id, const VSplinePath &path, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse, - Tool::Enum typeCreation, Draw::Mode mode){ + Tool::Enum typeCreation){ qint64 id = _id; if(typeCreation == Tool::FromGui){ id = data->AddSplinePath(path); @@ -70,15 +70,9 @@ void VToolSplinePath::Create(const qint64 _id, const VSplinePath &path, VMainGra } } data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength()); - VAbstractTool::AddRecord(id, Tools::SplinePathTool, doc); - if(mode == Draw::Modeling){ - const QVector *points = path.GetPoint(); - for(qint32 i = 0; isize(); ++i){ - data->IncrementReferens(points->at(i).P(), Scene::Point); - } - } + VDrawTool::AddRecord(id, Tools::SplinePathTool, doc); if(parse == Document::FullParse){ - VToolSplinePath *spl = new VToolSplinePath(doc, data, id, mode, typeCreation); + VToolSplinePath *spl = new VToolSplinePath(doc, data, id, typeCreation); scene->addItem(spl); connect(spl, &VToolSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(spl, &VToolSplinePath::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); @@ -178,13 +172,13 @@ void VToolSplinePath::ChangedActivDraw(const QString newName){ this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); emit setEnabledPoint(true); - VAbstractTool::ChangedActivDraw(newName); + VDrawTool::ChangedActivDraw(newName); } else { this->setPen(QPen(Qt::gray, widthHairLine)); this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setAcceptHoverEvents (false); emit setEnabledPoint(false); - VAbstractTool::ChangedActivDraw(newName); + VDrawTool::ChangedActivDraw(newName); } } @@ -216,7 +210,7 @@ void VToolSplinePath::AddToFile(){ AddPathPoint(domElement, splPath[i]); } - AddToDraw(domElement); + AddToCalculation(domElement); } void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint){ diff --git a/tools/vtoolsplinepath.h b/tools/drawTools/vtoolsplinepath.h similarity index 76% rename from tools/vtoolsplinepath.h rename to tools/drawTools/vtoolsplinepath.h index cc8bf8fcb..bbb1afe59 100644 --- a/tools/vtoolsplinepath.h +++ b/tools/drawTools/vtoolsplinepath.h @@ -1,33 +1,25 @@ #ifndef VTOOLSPLINEPATH_H #define VTOOLSPLINEPATH_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" -#include "vabstracttool.h" -#include "../xml/vdomdocument.h" +#include "vdrawtool.h" +#include "xml/vdomdocument.h" #include -#include "../dialogs/dialogsplinepath.h" -#include "../widgets/vcontrolpointspline.h" -#pragma GCC diagnostic pop -#include "../container/vcontainer.h" +#include "dialogs/dialogsplinepath.h" +#include "widgets/vcontrolpointspline.h" +#include "container/vcontainer.h" -class VToolSplinePath:public VAbstractTool, public QGraphicsPathItem +class VToolSplinePath:public VDrawTool, public QGraphicsPathItem { Q_OBJECT public: VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, - Draw::Mode mode, Tool::Enum typeCreation, QGraphicsItem * parent = 0); virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); static void Create(const qint64 _id, const VSplinePath &path, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation, - Draw::Mode mode); + VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation); signals: void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, const QPointF &controlPoint, const QPointF &splinePoint); diff --git a/tools/modelingTools/modelingtools.h b/tools/modelingTools/modelingtools.h new file mode 100644 index 000000000..f48c34ae6 --- /dev/null +++ b/tools/modelingTools/modelingtools.h @@ -0,0 +1,17 @@ +#ifndef MODELINGTOOLS_H +#define MODELINGTOOLS_H + +#include "vmodelingalongline.h" +#include "vmodelingarc.h" +#include "vmodelingbisector.h" +#include "vmodelingendline.h" +#include "vmodelingline.h" +#include "vmodelinglineintersect.h" +#include "vmodelingnormal.h" +#include "vmodelingpointofcontact.h" +#include "vmodelingshoulderpoint.h" +#include "vmodelingsinglepoint.h" +#include "vmodelingspline.h" +#include "vmodelingsplinepath.h" + +#endif // MODELINGTOOLS_H diff --git a/tools/modelingTools/vmodelingalongline.cpp b/tools/modelingTools/vmodelingalongline.cpp new file mode 100644 index 000000000..502697797 --- /dev/null +++ b/tools/modelingTools/vmodelingalongline.cpp @@ -0,0 +1,133 @@ +#include "vmodelingalongline.h" +#include +#include +#include +#include "container/calculator.h" + +VModelingAlongLine::VModelingAlongLine(VDomDocument *doc, VContainer *data, qint64 id, + const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const QString &typeLine, + Tool::Enum typeCreation, QGraphicsItem *parent): + VModelingLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent), + secondPointId(secondPointId), dialogAlongLine(QSharedPointer()){ + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VModelingAlongLine::FullUpdateFromFile(){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + typeLine = domElement.attribute("typeLine", ""); + formula = domElement.attribute("length", ""); + basePointId = domElement.attribute("firstPoint", "").toLongLong(); + secondPointId = domElement.attribute("secondPoint", "").toLongLong(); + } + RefreshGeometry(); +} + +void VModelingAlongLine::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogAlongLine->getPointName()); + domElement.setAttribute("typeLine", dialogAlongLine->getTypeLine()); + domElement.setAttribute("length", dialogAlongLine->getFormula()); + domElement.setAttribute("firstPoint", QString().setNum(dialogAlongLine->getFirstPointId())); + domElement.setAttribute("secondPoint", QString().setNum(dialogAlongLine->getSecondPointId())); + emit FullUpdateTree(); + } + + } + dialogAlongLine.clear(); +} + +void VModelingAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogAlongLine, this, event); +} + +void VModelingAlongLine::AddToFile(){ + VPointF point = VAbstractTool::data.GetModelingPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "alongLine"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); + AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + + AddAttribute(domElement, "typeLine", typeLine); + AddAttribute(domElement, "length", formula); + AddAttribute(domElement, "firstPoint", basePointId); + AddAttribute(domElement, "secondPoint", secondPointId); + + AddToModeling(domElement); +} + +void VModelingAlongLine::setDialog(){ + Q_ASSERT(!dialogAlongLine.isNull()); + if(!dialogAlongLine.isNull()){ + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogAlongLine->setTypeLine(typeLine); + dialogAlongLine->setFormula(formula); + dialogAlongLine->setFirstPointId(basePointId, id); + dialogAlongLine->setSecondPointId(secondPointId, id); + dialogAlongLine->setPointName(p.name()); + } +} + +VModelingAlongLine *VModelingAlongLine::Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data){ + QString formula = dialog->getFormula(); + qint64 firstPointId = dialog->getFirstPointId(); + qint64 secondPointId = dialog->getSecondPointId(); + QString typeLine = dialog->getTypeLine(); + QString pointName = dialog->getPointName(); + return Create(0, pointName, typeLine, formula, firstPointId, secondPointId, 5, 10, doc, data, + Document::FullParse, Tool::FromGui); +} + +VModelingAlongLine *VModelingAlongLine::Create(const qint64 _id, const QString &pointName, + const QString &typeLine, const QString &formula, + const qint64 &firstPointId, const qint64 &secondPointId, + const qreal &mx, const qreal &my, VDomDocument *doc, + VContainer *data, Document::Enum parse, + Tool::Enum typeCreation){ + VModelingAlongLine *point = 0; + VPointF firstPoint = data->GetModelingPoint(firstPointId); + VPointF secondPoint = data->GetModelingPoint(secondPointId); + QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()); + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(formula, &errorMsg); + if(errorMsg.isEmpty()){ + line.setLength(toPixel(result)); + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddModelingPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); + } else { + data->UpdateModelingPoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); + if(parse != Document::FullParse){ + QMap* tools = doc->getTools(); + VDataTool *tool = tools->value(id); + if(tool != 0){ + tool->VDataTool::setData(data); + data->IncrementReferens(id, Scene::Point, Draw::Modeling); + } + } + } + data->AddLine(firstPointId, id); + data->AddLine(id, secondPointId); + data->IncrementReferens(firstPointId, Scene::Point, Draw::Modeling); + data->IncrementReferens(secondPointId, Scene::Point, Draw::Modeling); + + if(parse == Document::FullParse){ + point = new VModelingAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, + typeCreation); + QMap* tools = doc->getTools(); + tools->insert(id,point); + } + } + return point; +} diff --git a/tools/modelingTools/vmodelingalongline.h b/tools/modelingTools/vmodelingalongline.h new file mode 100644 index 000000000..d04c338ef --- /dev/null +++ b/tools/modelingTools/vmodelingalongline.h @@ -0,0 +1,34 @@ +#ifndef VMODELINGALONGLINE_H +#define VMODELINGALONGLINE_H + +#include "vmodelinglinepoint.h" +#include "dialogs/dialogalongline.h" + +class VModelingAlongLine : public VModelingLinePoint +{ + Q_OBJECT +public: + VModelingAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula, + const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine, + Tool::Enum typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingAlongLine* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingAlongLine* Create(const qint64 _id, const QString &pointName, const QString &typeLine, + const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, Document::Enum parse, + Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + +private: + qint64 secondPointId; + QSharedPointer dialogAlongLine; +}; + +#endif // VMODELINGALONGLINE_H diff --git a/tools/modelingTools/vmodelingarc.cpp b/tools/modelingTools/vmodelingarc.cpp new file mode 100644 index 000000000..310d554eb --- /dev/null +++ b/tools/modelingTools/vmodelingarc.cpp @@ -0,0 +1,150 @@ +#include "vmodelingarc.h" +#include +#include "container/calculator.h" + +VModelingArc::VModelingArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, + QGraphicsItem *parent):VModelingTool(doc, data, id), QGraphicsPathItem(parent), + dialogArc(QSharedPointer()){ + VArc arc = data->GetModelingArc(id); + QPainterPath path; + path.addPath(arc.GetPath()); + path.setFillRule( Qt::WindingFill ); + this->setPath(path); + this->setPen(QPen(Qt::black, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VModelingArc::setDialog(){ + Q_ASSERT(!dialogArc.isNull()); + if(!dialogArc.isNull()){ + VArc arc = VAbstractTool::data.GetModelingArc(id); + dialogArc->SetCenter(arc.GetCenter()); + dialogArc->SetRadius(arc.GetFormulaRadius()); + dialogArc->SetF1(arc.GetFormulaF1()); + dialogArc->SetF2(arc.GetFormulaF2()); + } +} + +VModelingArc* VModelingArc::Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data){ + qint64 center = dialog->GetCenter(); + QString radius = dialog->GetRadius(); + QString f1 = dialog->GetF1(); + QString f2 = dialog->GetF2(); + return Create(0, center, radius, f1, f2, doc, data, Document::FullParse, Tool::FromGui); +} + +VModelingArc* VModelingArc::Create(const qint64 _id, const qint64 ¢er, const QString &radius, + const QString &f1, const QString &f2, VDomDocument *doc, + VContainer *data, Document::Enum parse, Tool::Enum typeCreation){ + VModelingArc *toolArc = 0; + qreal calcRadius = 0, calcF1 = 0, calcF2 = 0; + + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(radius, &errorMsg); + if(errorMsg.isEmpty()){ + calcRadius = result*PrintDPI/25.4; + } + + errorMsg.clear(); + result = cal.eval(f1, &errorMsg); + if(errorMsg.isEmpty()){ + calcF1 = result; + } + + errorMsg.clear(); + result = cal.eval(f2, &errorMsg); + if(errorMsg.isEmpty()){ + calcF2 = result; + } + + VArc arc = VArc(data->DataModelingPoints(), center, calcRadius, radius, calcF1, f1, calcF2, f2 ); + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddModelingArc(arc); + } else { + data->UpdateModelingArc(id, arc); + if(parse != Document::FullParse){ + QMap* tools = doc->getTools(); + VDataTool *tool = tools->value(id); + if(tool != 0){ + tool->VDataTool::setData(data); + data->IncrementReferens(id, Scene::Arc, Draw::Modeling); + } + } + } + data->AddLengthArc(data->GetNameArc(center,id, Draw::Modeling), arc.GetLength()); + data->IncrementReferens(center, Scene::Point, Draw::Modeling); + if(parse == Document::FullParse){ + toolArc = new VModelingArc(doc, data, id, typeCreation); + QMap* tools = doc->getTools(); + tools->insert(id,toolArc); + } + return toolArc; +} + +void VModelingArc::FullUpdateFromFile(){ + RefreshGeometry(); +} + +void VModelingArc::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("center", QString().setNum(dialogArc->GetCenter())); + domElement.setAttribute("radius", dialogArc->GetRadius()); + domElement.setAttribute("angle1", dialogArc->GetF1()); + domElement.setAttribute("angle2", dialogArc->GetF2()); + emit FullUpdateTree(); + } + } + dialogArc.clear(); +} + +void VModelingArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogArc, this, event); +} + +void VModelingArc::AddToFile(){ + VArc arc = VAbstractTool::data.GetModelingArc(id); + QDomElement domElement = doc->createElement("arc"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "simple"); + AddAttribute(domElement, "center", arc.GetCenter()); + AddAttribute(domElement, "radius", arc.GetFormulaRadius()); + AddAttribute(domElement, "angle1", arc.GetFormulaF1()); + AddAttribute(domElement, "angle2", arc.GetFormulaF2()); + + AddToModeling(domElement); +} + +void VModelingArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(event->button() == Qt::LeftButton){ + emit ChoosedTool(id, Scene::Arc); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VModelingArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthMainLine)); +} + +void VModelingArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthHairLine)); +} + +void VModelingArc::RefreshGeometry(){ + VArc arc = VAbstractTool::data.GetModelingArc(id); + QPainterPath path; + path.addPath(arc.GetPath()); + path.setFillRule( Qt::WindingFill ); + this->setPath(path); +} diff --git a/tools/modelingTools/vmodelingarc.h b/tools/modelingTools/vmodelingarc.h new file mode 100644 index 000000000..36d7af00b --- /dev/null +++ b/tools/modelingTools/vmodelingarc.h @@ -0,0 +1,36 @@ +#ifndef VMODELINGARC_H +#define VMODELINGARC_H + +#include "vmodelingtool.h" +#include "xml/vdomdocument.h" +#include +#include "dialogs/dialogarc.h" +#include "widgets/vcontrolpointspline.h" +#include "container/vcontainer.h" + +class VModelingArc :public VModelingTool, public QGraphicsPathItem +{ + Q_OBJECT +public: + VModelingArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingArc* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingArc* Create(const qint64 _id, const qint64 ¢er, const QString &radius, + const QString &f1, const QString &f2, VDomDocument *doc, VContainer *data, + Document::Enum parse, Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + QSharedPointer dialogArc; + void RefreshGeometry(); +}; + +#endif // VMODELINGARC_H diff --git a/tools/modelingTools/vmodelingbisector.cpp b/tools/modelingTools/vmodelingbisector.cpp new file mode 100644 index 000000000..6b6a7b00e --- /dev/null +++ b/tools/modelingTools/vmodelingbisector.cpp @@ -0,0 +1,150 @@ +#include "vmodelingbisector.h" +#include + +VModelingBisector::VModelingBisector(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const qint64 &thirdPointId, Tool::Enum typeCreation, + QGraphicsItem *parent): + VModelingLinePoint(doc, data, id, typeLine, formula, secondPointId, 0, parent), firstPointId(0), + thirdPointId(0), dialogBisector(QSharedPointer()){ + this->firstPointId = firstPointId; + this->thirdPointId = thirdPointId; + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +QPointF VModelingBisector::FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, + const QPointF &thirdPoint, const qreal &length){ + QLineF line1(secondPoint, firstPoint); + QLineF line2(secondPoint, thirdPoint); + qreal angle = line1.angleTo(line2); + if(angle>180){ + angle = 360 - angle; + } + line1.setAngle(line1.angle()-angle/2); + line1.setLength(length); + return line1.p2(); +} + +void VModelingBisector::setDialog(){ + Q_ASSERT(!dialogBisector.isNull()); + if(!dialogBisector.isNull()){ + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogBisector->setTypeLine(typeLine); + dialogBisector->setFormula(formula); + dialogBisector->setFirstPointId(firstPointId, id); + dialogBisector->setSecondPointId(basePointId, id); + dialogBisector->setThirdPointId(thirdPointId, id); + dialogBisector->setPointName(p.name()); + } +} + +VModelingBisector *VModelingBisector::Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data){ + QString formula = dialog->getFormula(); + qint64 firstPointId = dialog->getFirstPointId(); + qint64 secondPointId = dialog->getSecondPointId(); + qint64 thirdPointId = dialog->getThirdPointId(); + QString typeLine = dialog->getTypeLine(); + QString pointName = dialog->getPointName(); + return Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, pointName, 5, 10, doc, + data, Document::FullParse, Tool::FromGui); +} + +VModelingBisector *VModelingBisector::Create(const qint64 _id, const QString &formula, + const qint64 &firstPointId, const qint64 &secondPointId, + const qint64 &thirdPointId, const QString &typeLine, + const QString &pointName, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, Document::Enum parse, + Tool::Enum typeCreation){ + VModelingBisector *point = 0; + VPointF firstPoint = data->GetModelingPoint(firstPointId); + VPointF secondPoint = data->GetModelingPoint(secondPointId); + VPointF thirdPoint = data->GetModelingPoint(thirdPointId); + + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(formula, &errorMsg); + if(errorMsg.isEmpty()){ + QPointF fPoint = VModelingBisector::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), + thirdPoint.toQPointF(), result*PrintDPI/25.4); + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + } else { + data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + if(parse != Document::FullParse){ + QMap* tools = doc->getTools(); + VDataTool *tool = tools->value(id); + if(tool != 0){ + tool->VDataTool::setData(data); + data->IncrementReferens(id, Scene::Point, Draw::Modeling); + } + } + } + data->AddLine(firstPointId, id, Draw::Modeling); + data->IncrementReferens(firstPointId, Scene::Point, Draw::Modeling); + data->IncrementReferens(secondPointId, Scene::Point, Draw::Modeling); + data->IncrementReferens(thirdPointId, Scene::Point, Draw::Modeling); + if(parse == Document::FullParse){ + point = new VModelingBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId, + thirdPointId, typeCreation); + QMap* tools = doc->getTools(); + tools->insert(id,point); + } + } + return point; +} + +void VModelingBisector::FullUpdateFromFile(){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + typeLine = domElement.attribute("typeLine", ""); + formula = domElement.attribute("length", ""); + firstPointId = domElement.attribute("firstPoint", "").toLongLong(); + basePointId = domElement.attribute("secondPoint", "").toLongLong(); + thirdPointId = domElement.attribute("thirdPoint", "").toLongLong(); + } + RefreshGeometry(); +} + +void VModelingBisector::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogBisector->getPointName()); + domElement.setAttribute("typeLine", dialogBisector->getTypeLine()); + domElement.setAttribute("length", dialogBisector->getFormula()); + domElement.setAttribute("firstPoint", QString().setNum(dialogBisector->getFirstPointId())); + domElement.setAttribute("secondPoint", QString().setNum(dialogBisector->getSecondPointId())); + domElement.setAttribute("thirdPoint", QString().setNum(dialogBisector->getThirdPointId())); + emit FullUpdateTree(); + } + } + dialogBisector.clear(); +} + +void VModelingBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogBisector, this, event); +} + +void VModelingBisector::AddToFile(){ + VPointF point = VAbstractTool::data.GetModelingPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "bisector"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); + AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + + AddAttribute(domElement, "typeLine", typeLine); + AddAttribute(domElement, "length", formula); + AddAttribute(domElement, "firstPoint", firstPointId); + AddAttribute(domElement, "secondPoint", basePointId); + AddAttribute(domElement, "thirdPoint", thirdPointId); + + AddToModeling(domElement); +} diff --git a/tools/modelingTools/vmodelingbisector.h b/tools/modelingTools/vmodelingbisector.h new file mode 100644 index 000000000..7057f21e3 --- /dev/null +++ b/tools/modelingTools/vmodelingbisector.h @@ -0,0 +1,38 @@ +#ifndef VMODELINGBISECTOR_H +#define VMODELINGBISECTOR_H + +#include +#include "vmodelinglinepoint.h" +#include "dialogs/dialogbisector.h" + +class VModelingBisector : public VModelingLinePoint +{ + Q_OBJECT +public: + VModelingBisector(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const qint64 &thirdPointId, Tool::Enum typeCreation, + QGraphicsItem * parent = 0); + static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, + const QPointF &thirdPoint, const qreal& length); + virtual void setDialog(); + static VModelingBisector* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingBisector* Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const qint64 &thirdPointId, + const QString &typeLine, const QString &pointName, const qreal &mx, + const qreal &my, VDomDocument *doc, VContainer *data, + Document::Enum parse, Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + qint64 firstPointId; + qint64 thirdPointId; + QSharedPointer dialogBisector; +}; + +#endif // VMODELINGBISECTOR_H diff --git a/tools/modelingTools/vmodelingendline.cpp b/tools/modelingTools/vmodelingendline.cpp new file mode 100644 index 000000000..81f7780a9 --- /dev/null +++ b/tools/modelingTools/vmodelingendline.cpp @@ -0,0 +1,125 @@ +#include "vmodelingendline.h" +#include +#include +#include "widgets/vmaingraphicsscene.h" + +VModelingEndLine::VModelingEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const QString &formula, const qint32 &angle, const qint64 &basePointId, + Tool::Enum typeCreation, QGraphicsItem *parent): + VModelingLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent), + dialogEndLine(QSharedPointer()){ + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VModelingEndLine::setDialog(){ + Q_ASSERT(!dialogEndLine.isNull()); + if(!dialogEndLine.isNull()){ + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogEndLine->setTypeLine(typeLine); + dialogEndLine->setFormula(formula); + dialogEndLine->setAngle(angle); + dialogEndLine->setBasePointId(basePointId, id); + dialogEndLine->setPointName(p.name()); + } +} + +VModelingEndLine *VModelingEndLine::Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data){ + QString pointName = dialog->getPointName(); + QString typeLine = dialog->getTypeLine(); + QString formula = dialog->getFormula(); + qint32 angle = dialog->getAngle(); + qint64 basePointId = dialog->getBasePointId(); + return Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, doc, data, Document::FullParse, + Tool::FromGui); +} + +VModelingEndLine *VModelingEndLine::Create(const qint64 _id, const QString &pointName, + const QString &typeLine, const QString &formula, + const qint32 &angle, const qint64 &basePointId, const qreal &mx, + const qreal &my, VDomDocument *doc, VContainer *data, + Document::Enum parse, Tool::Enum typeCreation){ + VModelingEndLine *point = 0; + VPointF basePoint = data->GetModelingPoint(basePointId); + QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y())); + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(formula, &errorMsg); + if(errorMsg.isEmpty()){ + line.setLength(result*PrintDPI/25.4); + line.setAngle(angle); + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddModelingPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); + } else { + data->UpdateModelingPoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); + if(parse != Document::FullParse){ + QMap* tools = doc->getTools(); + VDataTool *tool = tools->value(id); + if(tool != 0){ + tool->VDataTool::setData(data); + data->IncrementReferens(id, Scene::Point, Draw::Modeling); + } + } + } + data->AddLine(basePointId, id, Draw::Modeling); + data->IncrementReferens(basePointId, Scene::Point, Draw::Modeling); + if(parse == Document::FullParse){ + point = new VModelingEndLine(doc, data, id, typeLine, formula, angle, basePointId, typeCreation); + QMap* tools = doc->getTools(); + tools->insert(id,point); + } + } + return point; +} + +void VModelingEndLine::FullUpdateFromFile(){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + typeLine = domElement.attribute("typeLine", ""); + formula = domElement.attribute("length", ""); + basePointId = domElement.attribute("basePoint", "").toLongLong(); + angle = domElement.attribute("angle", "").toInt(); + } + RefreshGeometry(); +} + +void VModelingEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogEndLine, this, event); +} + +void VModelingEndLine::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogEndLine->getPointName()); + domElement.setAttribute("typeLine", dialogEndLine->getTypeLine()); + domElement.setAttribute("length", dialogEndLine->getFormula()); + domElement.setAttribute("angle", QString().setNum(dialogEndLine->getAngle())); + domElement.setAttribute("basePoint", QString().setNum(dialogEndLine->getBasePointId())); + emit FullUpdateTree(); + } + } + dialogEndLine.clear(); +} + +void VModelingEndLine::AddToFile(){ + VPointF point = VAbstractTool::data.GetModelingPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "endLine"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); + + AddAttribute(domElement, "typeLine", typeLine); + AddAttribute(domElement, "length", formula); + AddAttribute(domElement, "angle", angle); + AddAttribute(domElement, "basePoint", basePointId); + + AddToModeling(domElement); +} diff --git a/tools/modelingTools/vmodelingendline.h b/tools/modelingTools/vmodelingendline.h new file mode 100644 index 000000000..bb3d5f917 --- /dev/null +++ b/tools/modelingTools/vmodelingendline.h @@ -0,0 +1,33 @@ +#ifndef VMODELINGENDLINE_H +#define VMODELINGENDLINE_H + +#include +#include "vmodelinglinepoint.h" +#include "dialogs/dialogendline.h" + +class VModelingEndLine : public VModelingLinePoint +{ + Q_OBJECT +public: + VModelingEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qint32 &angle, + const qint64 &basePointId, Tool::Enum typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingEndLine* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingEndLine* Create(const qint64 _id, const QString &pointName, const QString &typeLine, + const QString &formula, const qint32 &angle, const qint64 &basePointId, + const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, + Document::Enum parse, Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + QSharedPointer dialogEndLine; +}; + +#endif // VMODELINGENDLINE_H diff --git a/tools/modelingTools/vmodelingline.cpp b/tools/modelingTools/vmodelingline.cpp new file mode 100644 index 000000000..58b094276 --- /dev/null +++ b/tools/modelingTools/vmodelingline.cpp @@ -0,0 +1,103 @@ +#include "vmodelingline.h" +#include +#include + +VModelingLine::VModelingLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, + qint64 secondPoint, Tool::Enum typeCreation, QGraphicsItem *parent): + VModelingTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), + secondPoint(secondPoint), dialogLine(QSharedPointer()){ + //Лінія + VPointF first = data->GetModelingPoint(firstPoint); + VPointF second = data->GetModelingPoint(secondPoint); + this->setLine(QLineF(first.toQPointF(), second.toQPointF())); + this->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VModelingLine::setDialog(){ + dialogLine->setFirstPoint(firstPoint); + dialogLine->setSecondPoint(secondPoint); +} + +VModelingLine *VModelingLine::Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data){ + qint64 firstPoint = dialog->getFirstPoint(); + qint64 secondPoint = dialog->getSecondPoint(); + return Create(0, firstPoint, secondPoint, doc, data, Document::FullParse, Tool::FromGui); +} + +VModelingLine *VModelingLine::Create(const qint64 &id, const qint64 &firstPoint, const qint64 &secondPoint, + VDomDocument *doc, VContainer *data, Document::Enum parse, + Tool::Enum typeCreation){ + VModelingLine *line = 0; + Q_CHECK_PTR(doc); + Q_CHECK_PTR(data); + data->AddLine(firstPoint, secondPoint, Draw::Modeling); + data->IncrementReferens(firstPoint, Scene::Point, Draw::Modeling); + data->IncrementReferens(secondPoint, Scene::Point, Draw::Modeling); + if(parse != Document::FullParse){ + QMap* tools = doc->getTools(); + Q_CHECK_PTR(tools); + VDataTool *tool = tools->value(id); + Q_CHECK_PTR(tool); + tool->VDataTool::setData(data); + } + if(parse == Document::FullParse){ + qint64 id = data->getNextId(); + line = new VModelingLine(doc, data, id, firstPoint, secondPoint, typeCreation); + QMap* tools = doc->getTools(); + tools->insert(id,line); + } + return line; +} + +void VModelingLine::FullUpdateFromFile(){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + firstPoint = domElement.attribute("firstPoint", "").toLongLong(); + secondPoint = domElement.attribute("secondPoint", "").toLongLong(); + } + VPointF first = VAbstractTool::data.GetModelingPoint(firstPoint); + VPointF second = VAbstractTool::data.GetModelingPoint(secondPoint); + this->setLine(QLineF(first.toQPointF(), second.toQPointF())); +} + +void VModelingLine::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("firstPoint", QString().setNum(dialogLine->getFirstPoint())); + domElement.setAttribute("secondPoint", QString().setNum(dialogLine->getSecondPoint())); + emit FullUpdateTree(); + } + } + dialogLine.clear(); +} + +void VModelingLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogLine, this, event); +} + +void VModelingLine::AddToFile(){ + QDomElement domElement = doc->createElement("line"); + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "firstPoint", firstPoint); + AddAttribute(domElement, "secondPoint", secondPoint); + + AddToModeling(domElement); +} + +void VModelingLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthMainLine)); +} + +void VModelingLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthHairLine)); +} diff --git a/tools/modelingTools/vmodelingline.h b/tools/modelingTools/vmodelingline.h new file mode 100644 index 000000000..f40dbbabf --- /dev/null +++ b/tools/modelingTools/vmodelingline.h @@ -0,0 +1,33 @@ +#ifndef VMODELINGLINE_H +#define VMODELINGLINE_H + +#include "vmodelingtool.h" +#include "QGraphicsLineItem" +#include "dialogs/dialogline.h" + +class VModelingLine: public VModelingTool, public QGraphicsLineItem +{ + Q_OBJECT +public: + VModelingLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, + qint64 secondPoint, Tool::Enum typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingLine* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingLine* Create(const qint64 &id, const qint64 &firstPoint, const qint64 &secondPoint, + VDomDocument *doc, VContainer *data, Document::Enum parse, + Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + qint64 firstPoint; + qint64 secondPoint; + QSharedPointer dialogLine; +}; + +#endif // VMODELINGLINE_H diff --git a/tools/modelingTools/vmodelinglineintersect.cpp b/tools/modelingTools/vmodelinglineintersect.cpp new file mode 100644 index 000000000..3d627cf71 --- /dev/null +++ b/tools/modelingTools/vmodelinglineintersect.cpp @@ -0,0 +1,128 @@ +#include "vmodelinglineintersect.h" +#include + +VModelingLineIntersect::VModelingLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id, + const qint64 &p1Line1, const qint64 &p2Line1, const qint64 &p1Line2, + const qint64 &p2Line2, Tool::Enum typeCreation, QGraphicsItem *parent): + VModelingPoint(doc, data, id, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2), + p2Line2(p2Line2), dialogLineIntersect(QSharedPointer()){ + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VModelingLineIntersect::setDialog(){ + Q_ASSERT(!dialogLineIntersect.isNull()); + if(!dialogLineIntersect.isNull()){ + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogLineIntersect->setP1Line1(p1Line1); + dialogLineIntersect->setP2Line1(p2Line1); + dialogLineIntersect->setP1Line2(p1Line2); + dialogLineIntersect->setP2Line2(p2Line2); + dialogLineIntersect->setPointName(p.name()); + } +} + +VModelingLineIntersect *VModelingLineIntersect::Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data){ + qint64 p1Line1Id = dialog->getP1Line1(); + qint64 p2Line1Id = dialog->getP2Line1(); + qint64 p1Line2Id = dialog->getP1Line2(); + qint64 p2Line2Id = dialog->getP2Line2(); + QString pointName = dialog->getPointName(); + return Create(0, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, pointName, 5, 10, doc, data, + Document::FullParse, Tool::FromGui); +} + +VModelingLineIntersect *VModelingLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, + const qint64 &p2Line1Id, const qint64 &p1Line2Id, + const qint64 &p2Line2Id, const QString &pointName, + const qreal &mx, const qreal &my, VDomDocument *doc, + VContainer *data, Document::Enum parse, + Tool::Enum typeCreation){ + VModelingLineIntersect *point = 0; + VPointF p1Line1 = data->GetModelingPoint(p1Line1Id); + VPointF p2Line1 = data->GetModelingPoint(p2Line1Id); + VPointF p1Line2 = data->GetModelingPoint(p1Line2Id); + VPointF p2Line2 = data->GetModelingPoint(p2Line2Id); + + 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){ + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + } else { + data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + if(parse != Document::FullParse){ + QMap* tools = doc->getTools(); + VDataTool *tool = tools->value(id); + if(tool != 0){ + tool->VDataTool::setData(data); + data->IncrementReferens(id, Scene::Point, Draw::Modeling); + } + } + } + data->AddLine(p1Line1Id, id, Draw::Modeling); + data->AddLine(id, p2Line1Id, Draw::Modeling); + data->AddLine(p1Line2Id, id, Draw::Modeling); + data->AddLine(id, p2Line2Id, Draw::Modeling); + if(parse == Document::FullParse){ + point = new VModelingLineIntersect(doc, data, id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, + typeCreation); + QMap* tools = doc->getTools(); + tools->insert(id,point); + } + } + return point; +} + +void VModelingLineIntersect::FullUpdateFromFile(){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + p1Line1 = domElement.attribute("p1Line1", "").toLongLong(); + p2Line1 = domElement.attribute("p2Line1", "").toLongLong(); + p1Line2 = domElement.attribute("p1Line2", "").toLongLong(); + p2Line2 = domElement.attribute("p2Line2", "").toLongLong(); + } + RefreshPointGeometry(VAbstractTool::data.GetModelingPoint(id)); +} + +void VModelingLineIntersect::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogLineIntersect->getPointName()); + domElement.setAttribute("p1Line1", QString().setNum(dialogLineIntersect->getP1Line1())); + domElement.setAttribute("p2Line1", QString().setNum(dialogLineIntersect->getP2Line1())); + domElement.setAttribute("p1Line2", QString().setNum(dialogLineIntersect->getP1Line2())); + domElement.setAttribute("p2Line2", QString().setNum(dialogLineIntersect->getP2Line2())); + emit FullUpdateTree(); + } + } + dialogLineIntersect.clear(); +} + +void VModelingLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogLineIntersect, this, event); +} + +void VModelingLineIntersect::AddToFile(){ + VPointF point = VAbstractTool::data.GetModelingPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "lineIntersect"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); + AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + + AddAttribute(domElement, "p1Line1", p1Line1); + AddAttribute(domElement, "p2Line1", p2Line1); + AddAttribute(domElement, "p1Line2", p1Line2); + AddAttribute(domElement, "p2Line2", p2Line2); + + AddToModeling(domElement); +} diff --git a/tools/modelingTools/vmodelinglineintersect.h b/tools/modelingTools/vmodelinglineintersect.h new file mode 100644 index 000000000..18c22f51b --- /dev/null +++ b/tools/modelingTools/vmodelinglineintersect.h @@ -0,0 +1,39 @@ +#ifndef VMODELINGLINEINTERSECT_H +#define VMODELINGLINEINTERSECT_H + +#include "vmodelingpoint.h" +#include "dialogs/dialoglineintersect.h" + +class VModelingLineIntersect:public VModelingPoint +{ + Q_OBJECT +public: + VModelingLineIntersect(VDomDocument *doc, VContainer *data, + const qint64 &id, + const qint64 &p1Line1, + const qint64 &p2Line1, const qint64 &p1Line2, + const qint64 &p2Line2, Tool::Enum typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingLineIntersect* Create(QSharedPointer &dialog, + VDomDocument *doc,VContainer *data); + static VModelingLineIntersect* Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, + const qint64 &p1Line2Id, const qint64 &p2Line2Id, + const QString &pointName, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, Document::Enum parse, + Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + qint64 p1Line1; + qint64 p2Line1; + qint64 p1Line2; + qint64 p2Line2; + QSharedPointer dialogLineIntersect; +}; + +#endif // VMODELINGLINEINTERSECT_H diff --git a/tools/modelingTools/vmodelinglinepoint.cpp b/tools/modelingTools/vmodelinglinepoint.cpp new file mode 100644 index 000000000..cee9233b8 --- /dev/null +++ b/tools/modelingTools/vmodelinglinepoint.cpp @@ -0,0 +1,31 @@ +#include "vmodelinglinepoint.h" + +VModelingLinePoint::VModelingLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qint64 &basePointId, + const qint32 &angle, QGraphicsItem *parent): + VModelingPoint(doc, data, id, parent), typeLine(typeLine), formula(formula), angle(angle), + basePointId(basePointId), mainLine(0){ + //Лінія, що з'єднує дві точки + QPointF point1 = data->GetModelingPoint(basePointId).toQPointF(); + QPointF point2 = data->GetModelingPoint(id).toQPointF(); + mainLine = new QGraphicsLineItem(QLineF(point1 - point2, point2 - point2), this); + mainLine->setPen(QPen(Qt::black, widthHairLine)); + mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + if(typeLine == "none"){ + mainLine->setVisible(false); + } else { + mainLine->setVisible(true); + } +} + +void VModelingLinePoint::RefreshGeometry(){ + VModelingPoint::RefreshPointGeometry(VModelingTool::data.GetModelingPoint(id)); + QPointF point = VModelingTool::data.GetModelingPoint(id).toQPointF(); + QPointF basePoint = VModelingTool::data.GetModelingPoint(basePointId).toQPointF(); + mainLine->setLine(QLineF(basePoint - point, point - point)); + if(typeLine == "none"){ + mainLine->setVisible(false); + } else { + mainLine->setVisible(true); + } +} diff --git a/tools/modelingTools/vmodelinglinepoint.h b/tools/modelingTools/vmodelinglinepoint.h new file mode 100644 index 000000000..3c3ac2e82 --- /dev/null +++ b/tools/modelingTools/vmodelinglinepoint.h @@ -0,0 +1,25 @@ +#ifndef VMODELINGLINEPOINT_H +#define VMODELINGLINEPOINT_H + +#include "vmodelingpoint.h" + +class VModelingLinePoint : public VModelingPoint +{ + Q_OBJECT +public: + VModelingLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, + const qint64 &basePointId, const qint32 &angle, QGraphicsItem * parent = 0); +protected: + QString typeLine; + QString formula; + qint32 angle; + qint64 basePointId; + QGraphicsLineItem *mainLine; + virtual void RefreshGeometry(); +private: + VModelingLinePoint(const VModelingLinePoint &tool); + const VModelingLinePoint &operator=(const VModelingLinePoint &tool); +}; + +#endif // VMODELINGLINEPOINT_H diff --git a/tools/modelingTools/vmodelingnormal.cpp b/tools/modelingTools/vmodelingnormal.cpp new file mode 100644 index 000000000..c96746cc1 --- /dev/null +++ b/tools/modelingTools/vmodelingnormal.cpp @@ -0,0 +1,142 @@ +#include "vmodelingnormal.h" +#include + +VModelingNormal::VModelingNormal(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, + const QString &formula, const qreal &angle, const qint64 &firstPointId, + const qint64 &secondPointId, Tool::Enum typeCreation, QGraphicsItem *parent): + VModelingLinePoint(doc, data, id, typeLine, formula, firstPointId, angle, parent), + secondPointId(secondPointId), dialogNormal(QSharedPointer()){ + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } + +} + +void VModelingNormal::setDialog(){ + Q_ASSERT(!dialogNormal.isNull()); + if(!dialogNormal.isNull()){ + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogNormal->setTypeLine(typeLine); + dialogNormal->setFormula(formula); + dialogNormal->setAngle(angle); + dialogNormal->setFirstPointId(basePointId, id); + dialogNormal->setSecondPointId(secondPointId, id); + dialogNormal->setPointName(p.name()); + } +} + +VModelingNormal* VModelingNormal::Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data){ + QString formula = dialog->getFormula(); + qint64 firstPointId = dialog->getFirstPointId(); + qint64 secondPointId = dialog->getSecondPointId(); + QString typeLine = dialog->getTypeLine(); + QString pointName = dialog->getPointName(); + qint32 angle = dialog->getAngle(); + return Create(0, formula, firstPointId, secondPointId, typeLine, pointName, angle, 5, 10, doc, data, + Document::FullParse, Tool::FromGui); +} + +VModelingNormal *VModelingNormal::Create(const qint64 _id, const QString &formula, + const qint64 &firstPointId, const qint64 &secondPointId, + const QString typeLine, const QString pointName, + const qreal angle, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, Document::Enum parse, + Tool::Enum typeCreation){ + VModelingNormal *point = 0; + VPointF firstPoint = data->GetModelingPoint(firstPointId); + VPointF secondPoint = data->GetModelingPoint(secondPointId); + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(formula, &errorMsg); + if(errorMsg.isEmpty()){ + QPointF fPoint = VModelingNormal::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), + result*PrintDPI/25.4, angle); + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + } else { + data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + if(parse != Document::FullParse){ + QMap* tools = doc->getTools(); + VDataTool *tool = tools->value(id); + if(tool != 0){ + tool->VDataTool::setData(data); + data->IncrementReferens(id, Scene::Point, Draw::Modeling); + } + } + } + data->AddLine(firstPointId, id, Draw::Modeling); + data->IncrementReferens(firstPointId, Scene::Point, Draw::Modeling); + data->IncrementReferens(secondPointId, Scene::Point, Draw::Modeling); + if(parse == Document::FullParse){ + point = new VModelingNormal(doc, data, id, typeLine, formula, angle, firstPointId, secondPointId, + typeCreation); + QMap* tools = doc->getTools(); + tools->insert(id,point); + } + } + return point; +} + +QPointF VModelingNormal::FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length, + const qreal &angle){ + QLineF line(firstPoint, secondPoint); + QLineF normal = line.normalVector(); + normal.setAngle(normal.angle()+angle); + normal.setLength(length); + return normal.p2(); +} + +void VModelingNormal::FullUpdateFromFile(){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + typeLine = domElement.attribute("typeLine", ""); + formula = domElement.attribute("length", ""); + basePointId = domElement.attribute("firstPoint", "").toLongLong(); + secondPointId = domElement.attribute("secondPoint", "").toLongLong(); + angle = domElement.attribute("angle", "").toInt(); + } + RefreshGeometry(); +} + +void VModelingNormal::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogNormal->getPointName()); + domElement.setAttribute("typeLine", dialogNormal->getTypeLine()); + domElement.setAttribute("length", dialogNormal->getFormula()); + domElement.setAttribute("angle", QString().setNum(dialogNormal->getAngle())); + domElement.setAttribute("firstPoint", QString().setNum(dialogNormal->getFirstPointId())); + domElement.setAttribute("secondPoint", QString().setNum(dialogNormal->getSecondPointId())); + emit FullUpdateTree(); + } + } + dialogNormal.clear(); +} + +void VModelingNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogNormal, this, event); +} + +void VModelingNormal::AddToFile(){ + VPointF point = VAbstractTool::data.GetModelingPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "normal"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); + AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + + AddAttribute(domElement, "typeLine", typeLine); + AddAttribute(domElement, "length", formula); + AddAttribute(domElement, "angle", angle); + AddAttribute(domElement, "firstPoint", basePointId); + AddAttribute(domElement, "secondPoint", secondPointId); + + AddToModeling(domElement); +} diff --git a/tools/modelingTools/vmodelingnormal.h b/tools/modelingTools/vmodelingnormal.h new file mode 100644 index 000000000..a2067eed1 --- /dev/null +++ b/tools/modelingTools/vmodelingnormal.h @@ -0,0 +1,37 @@ +#ifndef VMODELINGNORMAL_H +#define VMODELINGNORMAL_H + +#include +#include "vmodelinglinepoint.h" +#include "dialogs/dialognormal.h" + +class VModelingNormal : public VModelingLinePoint +{ + Q_OBJECT +public: + VModelingNormal(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, + const qreal &angle, const qint64 &firstPointId, + const qint64 &secondPointId, Tool::Enum typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingNormal* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingNormal* Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const QString typeLine, + const QString pointName, const qreal angle, const qreal &mx, + const qreal &my, VDomDocument *doc, VContainer *data, Document::Enum parse, + Tool::Enum typeCreation); + static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, + const qreal &length, const qreal &angle = 0); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + qint64 secondPointId; + QSharedPointer dialogNormal; +}; + +#endif // VMODELINGNORMAL_H diff --git a/tools/modelingTools/vmodelingpoint.cpp b/tools/modelingTools/vmodelingpoint.cpp new file mode 100644 index 000000000..d6eeb2dcc --- /dev/null +++ b/tools/modelingTools/vmodelingpoint.cpp @@ -0,0 +1,86 @@ +#include "vmodelingpoint.h" +#include +#include +#include +#include +#include "container/vpointf.h" + +VModelingPoint::VModelingPoint(VDomDocument *doc, VContainer *data, qint64 id, + QGraphicsItem *parent):VModelingTool(doc, data, id), + QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0), lineName(0){ + namePoint = new VGraphicsSimpleTextItem(this); + lineName = new QGraphicsLineItem(this); + connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, + &VModelingPoint::NameChangePosition); + this->setPen(QPen(Qt::black, widthHairLine)); + this->setBrush(QBrush(Qt::NoBrush)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + RefreshPointGeometry(VAbstractTool::data.GetModelingPoint(id)); +} + +void VModelingPoint::NameChangePosition(const QPointF pos){ + VPointF point = VAbstractTool::data.GetModelingPoint(id); + QPointF p = pos - this->pos(); + point.setMx(p.x()); + point.setMy(p.y()); + RefreshLine(); + UpdateNamePosition(point.mx(), point.my()); + VAbstractTool::data.UpdatePoint(id, point); +} + +void VModelingPoint::UpdateNamePosition(qreal mx, qreal my){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("mx", QString().setNum(toMM(mx))); + domElement.setAttribute("my", QString().setNum(toMM(my))); + emit toolhaveChange(); + } +} + +void VModelingPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(event->button() == Qt::LeftButton){ + emit ChoosedTool(id, Scene::Point); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VModelingPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthMainLine)); +} + +void VModelingPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthHairLine)); +} + +void VModelingPoint::RefreshPointGeometry(const VPointF &point){ + QRectF rec = QRectF(0, 0, radius*2, radius*2); + rec.translate(-rec.center().x(), -rec.center().y()); + this->setRect(rec); + this->setPos(point.toQPointF()); + disconnect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, + &VModelingPoint::NameChangePosition); + namePoint->setText(point.name()); + namePoint->setPos(QPointF(point.mx(), point.my())); + connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, + &VModelingPoint::NameChangePosition); + RefreshLine(); +} + +void VModelingPoint::RefreshLine(){ + QRectF nameRec = namePoint->sceneBoundingRect(); + QPointF p1, p2; + LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); + QPointF pRec = LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); + lineName->setLine(QLineF(p1, pRec - scenePos())); + if(QLineF(p1, pRec - scenePos()).length() <= toPixel(4)){ + lineName->setVisible(false); + } else { + lineName->setVisible(true); + } +} + +VModelingPoint::~VModelingPoint(){ +} diff --git a/tools/modelingTools/vmodelingpoint.h b/tools/modelingTools/vmodelingpoint.h new file mode 100644 index 000000000..95495b70c --- /dev/null +++ b/tools/modelingTools/vmodelingpoint.h @@ -0,0 +1,32 @@ +#ifndef VMODELINGPOINT_H +#define VMODELINGPOINT_H + +#include "vmodelingtool.h" +#include "widgets/vgraphicssimpletextitem.h" +#include "options.h" + +class VModelingPoint: public VModelingTool, public QGraphicsEllipseItem +{ + Q_OBJECT +public: + VModelingPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem * parent = 0); + virtual ~VModelingPoint(); +public slots: + void NameChangePosition(const QPointF pos); + virtual void FullUpdateFromGui(int result) = 0; +protected: + qreal radius; + VGraphicsSimpleTextItem *namePoint; + QGraphicsLineItem *lineName; + virtual void UpdateNamePosition(qreal mx, qreal my); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RefreshPointGeometry(const VPointF &point); + void RefreshLine(); +private: + VModelingPoint(const VModelingPoint &tool); + const VModelingPoint &operator=(const VModelingPoint &tool); +}; + +#endif // VMODELINGPOINT_H diff --git a/tools/modelingTools/vmodelingpointofcontact.cpp b/tools/modelingTools/vmodelingpointofcontact.cpp new file mode 100644 index 000000000..c4aa1237a --- /dev/null +++ b/tools/modelingTools/vmodelingpointofcontact.cpp @@ -0,0 +1,151 @@ +#include "vmodelingpointofcontact.h" + +VModelingPointOfContact::VModelingPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &radius, const qint64 ¢er, + const qint64 &firstPointId, const qint64 &secondPointId, + Tool::Enum typeCreation, QGraphicsItem *parent) + : VModelingPoint(doc, data, id, parent), radius(radius), center(center), firstPointId(firstPointId), + secondPointId(secondPointId), dialogPointOfContact(QSharedPointer()){ + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VModelingPointOfContact::setDialog(){ + Q_ASSERT(!dialogPointOfContact.isNull()); + if(!dialogPointOfContact.isNull()){ + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogPointOfContact->setRadius(radius); + dialogPointOfContact->setCenter(center, id); + dialogPointOfContact->setFirstPoint(firstPointId, id); + dialogPointOfContact->setSecondPoint(secondPointId, id); + dialogPointOfContact->setPointName(p.name()); + } +} + +QPointF VModelingPointOfContact::FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, + const QPointF &secondPoint){ + QPointF pArc; + qreal s = 0.0, s_x, s_y, step = 0.01, distans; + while( s < 1){ + s_x = secondPoint.x()-(qAbs(secondPoint.x()-firstPoint.x()))*s; + s_y = secondPoint.y()-(qAbs(secondPoint.y()-firstPoint.y()))*s; + distans = QLineF(center.x(), center.y(), s_x, s_y).length(); + if(ceil(distans*10) == ceil(radius*10)){ + pArc.rx() = s_x; + pArc.ry() = s_y; + break; + } + if(distans &dialog, + VDomDocument *doc, VContainer *data){ + QString radius = dialog->getRadius(); + qint64 center = dialog->getCenter(); + qint64 firstPointId = dialog->getFirstPoint(); + qint64 secondPointId = dialog->getSecondPoint(); + QString pointName = dialog->getPointName(); + return Create(0, radius, center, firstPointId, secondPointId, pointName, 5, 10, doc, data, + Document::FullParse, Tool::FromGui); +} + +VModelingPointOfContact *VModelingPointOfContact::Create(const qint64 _id, const QString &radius, + const qint64 ¢er, const qint64 &firstPointId, + const qint64 &secondPointId, + const QString &pointName, const qreal &mx, + const qreal &my, VDomDocument *doc, + VContainer *data, Document::Enum parse, + Tool::Enum typeCreation){ + VModelingPointOfContact *point = 0; + VPointF centerP = data->GetModelingPoint(center); + VPointF firstP = data->GetModelingPoint(firstPointId); + VPointF secondP = data->GetModelingPoint(secondPointId); + + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(radius, &errorMsg); + if(errorMsg.isEmpty()){ + QPointF fPoint = VModelingPointOfContact::FindPoint(result*PrintDPI/25.4, centerP.toQPointF(), + firstP.toQPointF(), secondP.toQPointF()); + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + } else { + data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + if(parse != Document::FullParse){ + QMap* tools = doc->getTools(); + VDataTool *tool = tools->value(id); + if(tool != 0){ + tool->VDataTool::setData(data); + data->IncrementReferens(id, Scene::Point, Draw::Modeling); + } + } + } + data->IncrementReferens(center, Scene::Point, Draw::Modeling); + data->IncrementReferens(firstPointId, Scene::Point, Draw::Modeling); + data->IncrementReferens(secondPointId, Scene::Point, Draw::Modeling); + if(parse == Document::FullParse){ + point = new VModelingPointOfContact(doc, data, id, radius, center, firstPointId, secondPointId, + typeCreation); + QMap* tools = doc->getTools(); + tools->insert(id,point); + } + } + return point; +} + +void VModelingPointOfContact::FullUpdateFromFile(){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + radius = domElement.attribute("radius", ""); + center = domElement.attribute("center", "").toLongLong(); + firstPointId = domElement.attribute("firstPoint", "").toLongLong(); + secondPointId = domElement.attribute("secondPoint", "").toLongLong(); + } + RefreshPointGeometry(VAbstractTool::data.GetModelingPoint(id)); +} + +void VModelingPointOfContact::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogPointOfContact->getPointName()); + domElement.setAttribute("radius", dialogPointOfContact->getRadius()); + domElement.setAttribute("center", QString().setNum(dialogPointOfContact->getCenter())); + domElement.setAttribute("firstPoint", QString().setNum(dialogPointOfContact->getFirstPoint())); + domElement.setAttribute("secondPoint", QString().setNum(dialogPointOfContact->getSecondPoint())); + emit FullUpdateTree(); + } + } + dialogPointOfContact.clear(); +} + +void VModelingPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogPointOfContact, this, event); +} + +void VModelingPointOfContact::AddToFile(){ + VPointF point = VAbstractTool::data.GetModelingPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "pointOfContact"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); + AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + + AddAttribute(domElement, "radius", radius); + AddAttribute(domElement, "center", center); + AddAttribute(domElement, "firstPoint", firstPointId); + AddAttribute(domElement, "secondPoint", secondPointId); + + AddToModeling(domElement); +} diff --git a/tools/modelingTools/vmodelingpointofcontact.h b/tools/modelingTools/vmodelingpointofcontact.h new file mode 100644 index 000000000..d5a623e4d --- /dev/null +++ b/tools/modelingTools/vmodelingpointofcontact.h @@ -0,0 +1,38 @@ +#ifndef VMODELINGPOINTOFCONTACT_H +#define VMODELINGPOINTOFCONTACT_H + +#include "vmodelingpoint.h" +#include "dialogs/dialogpointofcontact.h" + +class VModelingPointOfContact : public VModelingPoint +{ + Q_OBJECT +public: + VModelingPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &radius, const qint64 ¢er, const qint64 &firstPointId, + const qint64 &secondPointId, Tool::Enum typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static QPointF FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, + const QPointF &secondPoint); + static VModelingPointOfContact* Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data); + static VModelingPointOfContact* Create(const qint64 _id, const QString &radius, const qint64 ¢er, + const qint64 &firstPointId, const qint64 &secondPointId, + const QString &pointName, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, Document::Enum parse, + Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + QString radius; + qint64 center; + qint64 firstPointId; + qint64 secondPointId; + QSharedPointer dialogPointOfContact; +}; + +#endif // VMODELINGPOINTOFCONTACT_H diff --git a/tools/modelingTools/vmodelingshoulderpoint.cpp b/tools/modelingTools/vmodelingshoulderpoint.cpp new file mode 100644 index 000000000..c7a12fc7e --- /dev/null +++ b/tools/modelingTools/vmodelingshoulderpoint.cpp @@ -0,0 +1,159 @@ +#include "vmodelingshoulderpoint.h" +#include +#include + +VModelingShoulderPoint::VModelingShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qint64 &p1Line, + const qint64 &p2Line, const qint64 &pShoulder, Tool::Enum typeCreation, + QGraphicsItem * parent): + VModelingLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), + pShoulder(pShoulder), dialogShoulderPoint(QSharedPointer()){ + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } + +} + +void VModelingShoulderPoint::setDialog(){ + Q_ASSERT(!dialogShoulderPoint.isNull()); + if(!dialogShoulderPoint.isNull()){ + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogShoulderPoint->setTypeLine(typeLine); + dialogShoulderPoint->setFormula(formula); + dialogShoulderPoint->setP1Line(basePointId, id); + dialogShoulderPoint->setP2Line(p2Line, id); + dialogShoulderPoint->setPShoulder(pShoulder, id); + dialogShoulderPoint->setPointName(p.name()); + } +} + +QPointF VModelingShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, + const qreal &length){ + QLineF line = QLineF(p1Line, p2Line); + qreal dist = line.length(); + if(dist>length){ + qDebug()<<"A3П2="<=length){ + return line.p2(); + } + } +} + +VModelingShoulderPoint *VModelingShoulderPoint::Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data){ + QString formula = dialog->getFormula(); + qint64 p1Line = dialog->getP1Line(); + qint64 p2Line = dialog->getP2Line(); + qint64 pShoulder = dialog->getPShoulder(); + QString typeLine = dialog->getTypeLine(); + QString pointName = dialog->getPointName(); + return Create(0, formula, p1Line, p2Line, pShoulder, typeLine, pointName, 5, 10, doc, data, + Document::FullParse, Tool::FromGui); +} + +VModelingShoulderPoint *VModelingShoulderPoint::Create(const qint64 _id, const QString &formula, + const qint64 &p1Line, const qint64 &p2Line, + const qint64 &pShoulder, const QString &typeLine, + const QString &pointName, const qreal &mx, + const qreal &my, VDomDocument *doc, VContainer *data, + Document::Enum parse, Tool::Enum typeCreation){ + VModelingShoulderPoint *point = 0; + VPointF firstPoint = data->GetModelingPoint(p1Line); + VPointF secondPoint = data->GetModelingPoint(p2Line); + VPointF shoulderPoint = data->GetModelingPoint(pShoulder); + + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(formula, &errorMsg); + if(errorMsg.isEmpty()){ + QPointF fPoint = VModelingShoulderPoint::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), + shoulderPoint.toQPointF(), result*PrintDPI/25.4); + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + } else { + data->UpdateModelingPoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + if(parse != Document::FullParse){ + QMap* tools = doc->getTools(); + VDataTool *tool = tools->value(id); + if(tool != 0){ + tool->VDataTool::setData(data); + data->IncrementReferens(id, Scene::Point, Draw::Modeling); + } + } + } + data->AddLine(p1Line, id, Draw::Modeling); + data->AddLine(p2Line, id, Draw::Modeling); + data->IncrementReferens(p1Line, Scene::Point, Draw::Modeling); + data->IncrementReferens(p2Line, Scene::Point, Draw::Modeling); + data->IncrementReferens(pShoulder, Scene::Point, Draw::Modeling); + if(parse == Document::FullParse){ + point = new VModelingShoulderPoint(doc, data, id, typeLine, formula, p1Line, p2Line, pShoulder, + typeCreation); + QMap* tools = doc->getTools(); + tools->insert(id,point); + } + } + return point; +} + +void VModelingShoulderPoint::FullUpdateFromFile(){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + typeLine = domElement.attribute("typeLine", ""); + formula = domElement.attribute("length", ""); + basePointId = domElement.attribute("p1Line", "").toLongLong(); + p2Line = domElement.attribute("p2Line", "").toLongLong(); + pShoulder = domElement.attribute("pShoulder", "").toLongLong(); + } + RefreshGeometry(); +} + +void VModelingShoulderPoint::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogShoulderPoint->getPointName()); + domElement.setAttribute("typeLine", dialogShoulderPoint->getTypeLine()); + domElement.setAttribute("length", dialogShoulderPoint->getFormula()); + domElement.setAttribute("p1Line", QString().setNum(dialogShoulderPoint->getP1Line())); + domElement.setAttribute("p2Line", QString().setNum(dialogShoulderPoint->getP2Line())); + domElement.setAttribute("pShoulder", QString().setNum(dialogShoulderPoint->getPShoulder())); + emit FullUpdateTree(); + } + } + dialogShoulderPoint.clear(); +} + +void VModelingShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogShoulderPoint, this, event); +} + +void VModelingShoulderPoint::AddToFile(){ + VPointF point = VAbstractTool::data.GetModelingPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "shoulder"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); + AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + + AddAttribute(domElement, "typeLine", typeLine); + AddAttribute(domElement, "length", formula); + AddAttribute(domElement, "p1Line", basePointId); + AddAttribute(domElement, "p2Line", p2Line); + AddAttribute(domElement, "pShoulder", pShoulder); + + AddToModeling(domElement); +} diff --git a/tools/modelingTools/vmodelingshoulderpoint.h b/tools/modelingTools/vmodelingshoulderpoint.h new file mode 100644 index 000000000..6d386afb6 --- /dev/null +++ b/tools/modelingTools/vmodelingshoulderpoint.h @@ -0,0 +1,37 @@ +#ifndef VMODELINGSHOULDERPOINT_H +#define VMODELINGSHOULDERPOINT_H + +#include "vmodelinglinepoint.h" +#include "dialogs/dialogshoulderpoint.h" + +class VModelingShoulderPoint : public VModelingLinePoint +{ + Q_OBJECT +public: + VModelingShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qint64 &p1Line, + const qint64 &p2Line, const qint64 &pShoulder, Tool::Enum typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, + const qreal &length); + static VModelingShoulderPoint* Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data); + static VModelingShoulderPoint* Create(const qint64 _id, const QString &formula, const qint64 &p1Line, + const qint64 &p2Line, const qint64 &pShoulder, + const QString &typeLine, const QString &pointName, + const qreal &mx, const qreal &my, VDomDocument *doc, + VContainer *data, Document::Enum parse, Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + qint64 p2Line; + qint64 pShoulder; + QSharedPointer dialogShoulderPoint; +}; + +#endif // VMODELINGSHOULDERPOINT_H diff --git a/tools/modelingTools/vmodelingsinglepoint.cpp b/tools/modelingTools/vmodelingsinglepoint.cpp new file mode 100644 index 000000000..702f713e3 --- /dev/null +++ b/tools/modelingTools/vmodelingsinglepoint.cpp @@ -0,0 +1,93 @@ +#include "vmodelingsinglepoint.h" +#include +#include +#include +#include +#include +#include +#include +#include "options.h" +#include "container/vpointf.h" + +VModelingSinglePoint::VModelingSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation, + QGraphicsItem * parent ):VModelingPoint(doc, data, id, parent), + dialogSinglePoint(QSharedPointer()){ + this->setFlag(QGraphicsItem::ItemIsMovable, true); + this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VModelingSinglePoint::setDialog(){ + Q_ASSERT(!dialogSinglePoint.isNull()); + if(!dialogSinglePoint.isNull()){ + VPointF p = VAbstractTool::data.GetPoint(id); + dialogSinglePoint->setData(p.name(), p.toQPointF()); + } +} + +void VModelingSinglePoint::AddToFile(){ + VPointF point = VAbstractTool::data.GetPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "single"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "x", toMM(point.x())); + AddAttribute(domElement, "y", toMM(point.y())); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); + + AddToModeling(domElement); +} + +QVariant VModelingSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){ + if (change == ItemPositionChange && scene()) { + // value - это новое положение. + QPointF newPos = value.toPointF(); + QRectF rect = scene()->sceneRect(); + if (!rect.contains(newPos)) { + // Сохраняем элемент внутри прямоугольника сцены. + newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left()))); + newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top()))); + return newPos; + } + } + if (change == ItemPositionHasChanged && scene()) { + // value - это новое положение. + QPointF newPos = value.toPointF(); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("x", QString().setNum(toMM(newPos.x()))); + domElement.setAttribute("y", QString().setNum(toMM(newPos.y()))); + //I don't now why but signal does not work. + doc->FullUpdateTree(); + } + } + return QGraphicsItem::itemChange(change, value); +} + +void VModelingSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){ + ContextMenu(dialogSinglePoint, this, event, false); +} + +void VModelingSinglePoint::FullUpdateFromFile(){ + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); +} + +void VModelingSinglePoint::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QPointF p = dialogSinglePoint->getPoint(); + QString name = dialogSinglePoint->getName(); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", name); + domElement.setAttribute("x", QString().setNum(toMM(p.x()))); + domElement.setAttribute("y", QString().setNum(toMM(p.y()))); + //I don't now why but signal does not work. + doc->FullUpdateTree(); + } + } + dialogSinglePoint.clear(); +} diff --git a/tools/modelingTools/vmodelingsinglepoint.h b/tools/modelingTools/vmodelingsinglepoint.h new file mode 100644 index 000000000..95ab9e29a --- /dev/null +++ b/tools/modelingTools/vmodelingsinglepoint.h @@ -0,0 +1,29 @@ +#ifndef VMODELINGSINGLEPOINT_H +#define VMODELINGSINGLEPOINT_H + +#include "container/vcontainer.h" +#include "xml/vdomdocument.h" +#include "dialogs/dialogsinglepoint.h" +#include "vmodelingpoint.h" + +class VModelingSinglePoint : public VModelingPoint +{ + Q_OBJECT +public: + VModelingSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, + Tool::Enum typeCreation, QGraphicsItem * parent = 0 ); + virtual void setDialog(); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +signals: + void FullUpdateTree(); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); +private: + QSharedPointer dialogSinglePoint; +}; + +#endif // VMODELINGSINGLEPOINT_H diff --git a/tools/modelingTools/vmodelingspline.cpp b/tools/modelingTools/vmodelingspline.cpp new file mode 100644 index 000000000..b2372cea5 --- /dev/null +++ b/tools/modelingTools/vmodelingspline.cpp @@ -0,0 +1,219 @@ +#include "vmodelingspline.h" +#include +#include +#include "geometry/vspline.h" + + +VModelingSpline::VModelingSpline(VDomDocument *doc, VContainer *data, qint64 id, + Tool::Enum typeCreation, + QGraphicsItem *parent):VModelingTool(doc, data, id), QGraphicsPathItem(parent), + dialogSpline(QSharedPointer()), controlPoints(QVector()){ + + VSpline spl = data->GetModelingSpline(id); + QPainterPath path; + path.addPath(spl.GetPath()); + path.setFillRule( Qt::WindingFill ); + this->setPath(path); + this->setPen(QPen(Qt::black, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + + VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePoint::FirstPoint, spl.GetP2(), + spl.GetPointP1().toQPointF(), this); + connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSpline::ControlPointChangePosition); + connect(this, &VModelingSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine); + connect(this, &VModelingSpline::setEnabledPoint, controlPoint1, &VControlPointSpline::setEnabledPoint); + controlPoints.append(controlPoint1); + + VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePoint::LastPoint, spl.GetP3(), + spl.GetPointP4().toQPointF(), this); + connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSpline::ControlPointChangePosition); + connect(this, &VModelingSpline::RefreshLine, controlPoint2, &VControlPointSpline::RefreshLine); + connect(this, &VModelingSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint); + controlPoints.append(controlPoint2); + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VModelingSpline::setDialog(){ + Q_ASSERT(!dialogSpline.isNull()); + if(!dialogSpline.isNull()){ + VSpline spl = VAbstractTool::data.GetModelingSpline(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()); + } +} + +VModelingSpline *VModelingSpline::Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data){ + qint64 p1 = dialog->getP1(); + qint64 p4 = dialog->getP4(); + qreal kAsm1 = dialog->getKAsm1(); + qreal kAsm2 = dialog->getKAsm2(); + qreal angle1 = dialog->getAngle1(); + qreal angle2 = dialog->getAngle2(); + qreal kCurve = dialog->getKCurve(); + return Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, doc, data, Document::FullParse, + Tool::FromGui); +} + +VModelingSpline *VModelingSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, + const qreal &kAsm1, const qreal kAsm2, const qreal &angle1, + const qreal &angle2, const qreal &kCurve, VDomDocument *doc, + VContainer *data, Document::Enum parse, Tool::Enum typeCreation){ + VModelingSpline *spl = 0; + VSpline spline = VSpline(data->DataModelingPoints(), p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve); + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddModelingSpline(spline); + } else { + data->UpdateModelingSpline(id, spline); + if(parse != Document::FullParse){ + QMap* tools = doc->getTools(); + VDataTool *tool = tools->value(id); + Q_CHECK_PTR(tool); + tool->VDataTool::setData(data); + data->IncrementReferens(id, Scene::Spline, Draw::Modeling); + } + } + data->AddLengthSpline(data->GetNameSpline(p1, p4, Draw::Modeling), spline.GetLength()); + data->IncrementReferens(p1, Scene::Point, Draw::Modeling); + data->IncrementReferens(p4, Scene::Point, Draw::Modeling); + if(parse == Document::FullParse){ + spl = new VModelingSpline(doc, data, id, typeCreation); + QMap* tools = doc->getTools(); + tools->insert(id,spl); + } + return spl; +} + +void VModelingSpline::FullUpdateFromFile(){ + RefreshGeometry(); +} + +void VModelingSpline::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + VSpline spl = VSpline (VAbstractTool::data.DataModelingPoints(), dialogSpline->getP1(), + dialogSpline->getP4(), dialogSpline->getAngle1(), dialogSpline->getAngle2(), + dialogSpline->getKAsm1(), dialogSpline->getKAsm2(), dialogSpline->getKCurve()); + + disconnect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSpline::ControlPointChangePosition); + disconnect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSpline::ControlPointChangePosition); + controlPoints[0]->setPos(spl.GetP2()); + controlPoints[1]->setPos(spl.GetP3()); + connect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSpline::ControlPointChangePosition); + connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSpline::ControlPointChangePosition); + + spl = VSpline (VAbstractTool::data.DataModelingPoints(), dialogSpline->getP1(), + controlPoints[0]->pos(), controlPoints[1]->pos(), dialogSpline->getP4(), + dialogSpline->getKCurve()); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("point1", QString().setNum(spl.GetP1())); + domElement.setAttribute("point4", QString().setNum(spl.GetP4())); + domElement.setAttribute("angle1", QString().setNum(spl.GetAngle1())); + domElement.setAttribute("angle2", QString().setNum(spl.GetAngle2())); + domElement.setAttribute("kAsm1", QString().setNum(spl.GetKasm1())); + domElement.setAttribute("kAsm2", QString().setNum(spl.GetKasm2())); + domElement.setAttribute("kCurve", QString().setNum(spl.GetKcurve())); + emit FullUpdateTree(); + } + } + dialogSpline.clear(); +} + +void VModelingSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, + const QPointF pos){ + Q_UNUSED(indexSpline); + VSpline spl = VAbstractTool::data.GetModelingSpline(id); + if(position == SplinePoint::FirstPoint){ + spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve()); + } else { + spl.ModifiSpl (spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve()); + } + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("angle1", QString().setNum(spl.GetAngle1())); + domElement.setAttribute("angle2", QString().setNum(spl.GetAngle2())); + domElement.setAttribute("kAsm1", QString().setNum(spl.GetKasm1())); + domElement.setAttribute("kAsm2", QString().setNum(spl.GetKasm2())); + domElement.setAttribute("kCurve", QString().setNum(spl.GetKcurve())); + emit FullUpdateTree(); + } +} + +void VModelingSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogSpline, this, event); +} + +void VModelingSpline::AddToFile(){ + VSpline spl = VAbstractTool::data.GetModelingSpline(id); + QDomElement domElement = doc->createElement("spline"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "simple"); + AddAttribute(domElement, "point1", spl.GetP1()); + AddAttribute(domElement, "point4", spl.GetP4()); + AddAttribute(domElement, "angle1", spl.GetAngle1()); + AddAttribute(domElement, "angle2", spl.GetAngle2()); + AddAttribute(domElement, "kAsm1", spl.GetKasm1()); + AddAttribute(domElement, "kAsm2", spl.GetKasm2()); + AddAttribute(domElement, "kCurve", spl.GetKcurve()); + + AddToModeling(domElement); +} + +void VModelingSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(event->button() == Qt::LeftButton){ + emit ChoosedTool(id, Scene::Spline); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VModelingSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthMainLine)); +} + +void VModelingSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthHairLine)); +} + +void VModelingSpline::RefreshGeometry(){ + VSpline spl = VAbstractTool::data.GetModelingSpline(id); + QPainterPath path; + path.addPath(spl.GetPath()); + path.setFillRule( Qt::WindingFill ); + this->setPath(path); + QPointF splinePoint = VAbstractTool::data.GetModelingPoint(spl.GetP1()).toQPointF(); + QPointF controlPoint = spl.GetP2(); + emit RefreshLine(1, SplinePoint::FirstPoint, controlPoint, splinePoint); + splinePoint = VAbstractTool::data.GetModelingPoint(spl.GetP4()).toQPointF(); + controlPoint = spl.GetP3(); + emit RefreshLine(1, SplinePoint::LastPoint, controlPoint, splinePoint); + + disconnect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSpline::ControlPointChangePosition); + disconnect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSpline::ControlPointChangePosition); + controlPoints[0]->setPos(spl.GetP2()); + controlPoints[1]->setPos(spl.GetP3()); + connect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSpline::ControlPointChangePosition); + connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSpline::ControlPointChangePosition); +} diff --git a/tools/modelingTools/vmodelingspline.h b/tools/modelingTools/vmodelingspline.h new file mode 100644 index 000000000..e1cf55dc5 --- /dev/null +++ b/tools/modelingTools/vmodelingspline.h @@ -0,0 +1,47 @@ +#ifndef VMODELINGSPLINE_H +#define VMODELINGSPLINE_H + +#include "vmodelingtool.h" +#include "xml/vdomdocument.h" +#include +#include "dialogs/dialogspline.h" +#include "widgets/vcontrolpointspline.h" +#include "container/vcontainer.h" +#include "geometry/vsplinepath.h" + +class VModelingSpline:public VModelingTool, public QGraphicsPathItem +{ + Q_OBJECT +public: + VModelingSpline (VDomDocument *doc, VContainer *data, qint64 id, + Tool::Enum typeCreation, QGraphicsItem * parent = 0 ); + virtual void setDialog(); + static VModelingSpline* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingSpline* Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, + const qreal kAsm2, const qreal &angle1, const qreal &angle2, + const qreal &kCurve, VDomDocument *doc, VContainer *data, + Document::Enum parse, Tool::Enum typeCreation); +signals: + void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position, + const QPointF &controlPoint, const QPointF &splinePoint ); + void setEnabledPoint ( bool enable ); +public slots: + virtual void FullUpdateFromFile (); + virtual void FullUpdateFromGui ( int result ); + void ControlPointChangePosition ( const qint32 &indexSpline, + SplinePoint::Position position, + const QPointF pos); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile (); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + QSharedPointer dialogSpline; + QVector controlPoints; + void RefreshGeometry (); +}; + +#endif // VMODELINGSPLINE_H diff --git a/tools/modelingTools/vmodelingsplinepath.cpp b/tools/modelingTools/vmodelingsplinepath.cpp new file mode 100644 index 000000000..957c762db --- /dev/null +++ b/tools/modelingTools/vmodelingsplinepath.cpp @@ -0,0 +1,245 @@ +#include "vmodelingsplinepath.h" +#include + +VModelingSplinePath::VModelingSplinePath(VDomDocument *doc, VContainer *data, qint64 id, + Tool::Enum typeCreation, + QGraphicsItem *parent):VModelingTool(doc, data, id), + QGraphicsPathItem(parent), dialogSplinePath(QSharedPointer()), + controlPoints(QVector()){ + VSplinePath splPath = data->GetModelingSplinePath(id); + QPainterPath path; + path.addPath(splPath.GetPath()); + path.setFillRule( Qt::WindingFill ); + this->setPath(path); + this->setPen(QPen(Qt::black, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + + for(qint32 i = 1; i<=splPath.Count(); ++i){ + VSpline spl = splPath.GetSpline(i); + VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePoint::FirstPoint, spl.GetP2(), + spl.GetPointP1().toQPointF(), this); + connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSplinePath::ControlPointChangePosition); + connect(this, &VModelingSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine); + connect(this, &VModelingSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); + controlPoints.append(controlPoint); + + controlPoint = new VControlPointSpline(i, SplinePoint::LastPoint, spl.GetP3(), + spl.GetPointP4().toQPointF(), this); + connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSplinePath::ControlPointChangePosition); + connect(this, &VModelingSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine); + connect(this, &VModelingSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); + controlPoints.append(controlPoint); + } + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VModelingSplinePath::setDialog(){ + Q_ASSERT(!dialogSplinePath.isNull()); + if(!dialogSplinePath.isNull()){ + VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); + dialogSplinePath->SetPath(splPath); + } +} + +VModelingSplinePath *VModelingSplinePath::Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data){ + VSplinePath path = dialog->GetPath(); + return Create(0, path, doc, data, Document::FullParse, Tool::FromGui); +} + +VModelingSplinePath * VModelingSplinePath::Create(const qint64 _id, const VSplinePath &path, + VDomDocument *doc, VContainer *data, Document::Enum parse, + Tool::Enum typeCreation){ + VModelingSplinePath *spl = 0; + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddModelingSplinePath(path); + } else { + data->UpdateModelingSplinePath(id, path); + if(parse != Document::FullParse){ + QMap* tools = doc->getTools(); + VDataTool *tool = tools->value(id); + if(tool != 0){ + tool->VDataTool::setData(data); + data->IncrementReferens(id, Scene::SplinePath, Draw::Modeling); + } + } + } + for(qint32 i = 0; i < path.CountPoint(); ++i){ + data->IncrementReferens(path.getIdObject(), Scene::Point, Draw::Modeling); + } + data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength()); + if(parse == Document::FullParse){ + spl = new VModelingSplinePath(doc, data, id, typeCreation); + QMap* tools = doc->getTools(); + tools->insert(id,spl); + } + return spl; +} + +void VModelingSplinePath::FullUpdateFromFile(){ + RefreshGeometry(); +} + +void VModelingSplinePath::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + VSplinePath splPath = dialogSplinePath->GetPath(); + for(qint32 i = 1; i<=splPath.Count(); ++i){ + VSpline spl = splPath.GetSpline(i); + qint32 j = i*2; + disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSplinePath::ControlPointChangePosition); + disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSplinePath::ControlPointChangePosition); + controlPoints[j-2]->setPos(spl.GetP2()); + controlPoints[j-1]->setPos(spl.GetP3()); + connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSplinePath::ControlPointChangePosition); + connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSplinePath::ControlPointChangePosition); + + spl = VSpline (VAbstractTool::data.DataModelingPoints(), 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("kCurve", QString().setNum(splPath.getKCurve())); + UpdatePathPoint(domElement, splPath); + emit FullUpdateTree(); + } + + } + } + dialogSplinePath.clear(); +} + +void VModelingSplinePath::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, + const QPointF pos){ + VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); + VSpline spl = splPath.GetSpline(indexSpline); + if(position == SplinePoint::FirstPoint){ + spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve()); + } else { + spl.ModifiSpl (spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve()); + } + + CorectControlPoints(spl, splPath, indexSpline); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("kCurve", QString().setNum(splPath.getKCurve())); + UpdatePathPoint(domElement, splPath); + emit FullUpdateTree(); + } +} + +void VModelingSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &splPath, + const qint32 &indexSpline){ + VSplinePoint p = splPath.GetSplinePoint(indexSpline, SplinePoint::FirstPoint); + p.SetAngle(spl.GetAngle1()); + p.SetKAsm2(spl.GetKasm1()); + splPath.UpdatePoint(indexSpline, SplinePoint::FirstPoint, p); + + p = splPath.GetSplinePoint(indexSpline, SplinePoint::LastPoint); + p.SetAngle(spl.GetAngle2()-180); + p.SetKAsm1(spl.GetKasm2()); + splPath.UpdatePoint(indexSpline, SplinePoint::LastPoint, p); +} + +void VModelingSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path){ + QDomNodeList nodeList = node.childNodes(); + qint32 num = nodeList.size(); + for(qint32 i = 0; i < num; ++i){ + QDomElement domElement = nodeList.at(i).toElement(); + if(!domElement.isNull()){ + VSplinePoint p = path[i]; + domElement.setAttribute("pSpline", QString().setNum(p.P())); + domElement.setAttribute("kAsm1", QString().setNum(p.KAsm1())); + domElement.setAttribute("kAsm2", QString().setNum(p.KAsm2())); + domElement.setAttribute("angle", QString().setNum(p.Angle2())); + } + } +} + +void VModelingSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogSplinePath, this, event); +} + +void VModelingSplinePath::AddToFile(){ + VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); + QDomElement domElement = doc->createElement("spline"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "path"); + AddAttribute(domElement, "kCurve", splPath.getKCurve()); + + for(qint32 i = 0; i < splPath.CountPoint(); ++i){ + AddPathPoint(domElement, splPath[i]); + } + + AddToModeling(domElement); +} + +void VModelingSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint){ + QDomElement pathPoint = doc->createElement("pathPoint"); + + AddAttribute(pathPoint, "pSpline", splPoint.P()); + AddAttribute(pathPoint, "kAsm1", splPoint.KAsm1()); + AddAttribute(pathPoint, "kAsm2", splPoint.KAsm2()); + AddAttribute(pathPoint, "angle", splPoint.Angle2()); + + domElement.appendChild(pathPoint); +} + +void VModelingSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(event->button() == Qt::LeftButton){ + emit ChoosedTool(id, Scene::SplinePath); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VModelingSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthMainLine)); +} + +void VModelingSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthHairLine)); +} + +void VModelingSplinePath::RefreshGeometry(){ + VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); + QPainterPath path; + path.addPath(splPath.GetPath()); + path.setFillRule( Qt::WindingFill ); + this->setPath(path); + for(qint32 i = 1; i<=splPath.Count(); ++i){ + VSpline spl = splPath.GetSpline(i); + QPointF splinePoint = spl.GetPointP1().toQPointF(); + QPointF controlPoint = spl.GetP2(); + emit RefreshLine(i, SplinePoint::FirstPoint, controlPoint, splinePoint); + splinePoint = spl.GetPointP4().toQPointF(); + controlPoint = spl.GetP3(); + emit RefreshLine(i, SplinePoint::LastPoint, controlPoint, splinePoint); + + qint32 j = i*2; + disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSplinePath::ControlPointChangePosition); + disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSplinePath::ControlPointChangePosition); + controlPoints[j-2]->setPos(spl.GetP2()); + controlPoints[j-1]->setPos(spl.GetP3()); + connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSplinePath::ControlPointChangePosition); + connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, + &VModelingSplinePath::ControlPointChangePosition); + } + +} diff --git a/tools/modelingTools/vmodelingsplinepath.h b/tools/modelingTools/vmodelingsplinepath.h new file mode 100644 index 000000000..3ae864907 --- /dev/null +++ b/tools/modelingTools/vmodelingsplinepath.h @@ -0,0 +1,49 @@ +#ifndef VMODELINGSPLINEPATH_H +#define VMODELINGSPLINEPATH_H + +#include "vmodelingtool.h" +#include "xml/vdomdocument.h" +#include +#include "dialogs/dialogsplinepath.h" +#include "widgets/vcontrolpointspline.h" +#include "container/vcontainer.h" + +class VModelingSplinePath:public VModelingTool, public QGraphicsPathItem +{ + Q_OBJECT +public: + VModelingSplinePath(VDomDocument *doc, VContainer *data, qint64 id, + Tool::Enum typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingSplinePath* Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data); + static VModelingSplinePath* Create(const qint64 _id, const VSplinePath &path, VDomDocument *doc, + VContainer *data, Document::Enum parse, Tool::Enum typeCreation); +signals: + void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, + const QPointF &controlPoint, const QPointF &splinePoint); + void setEnabledPoint(bool enable); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + void ControlPointChangePosition(const qint32 &indexSpline, + SplinePoint::Position position, + const QPointF pos); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + QSharedPointer dialogSplinePath; + QVector controlPoints; + void RefreshGeometry(); + void AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint); + void UpdatePathPoint(QDomNode& node, VSplinePath &path); + void CorectControlPoints(const VSpline &spl, VSplinePath &splPath, + const qint32 &indexSpline); +}; + +#endif // VMODELINGSPLINEPATH_H diff --git a/tools/modelingTools/vmodelingtool.cpp b/tools/modelingTools/vmodelingtool.cpp new file mode 100644 index 000000000..16ee5d6e0 --- /dev/null +++ b/tools/modelingTools/vmodelingtool.cpp @@ -0,0 +1,26 @@ +#include "vmodelingtool.h" + +VModelingTool::VModelingTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent): +VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false){ +} + +VModelingTool::~VModelingTool(){ +} + +void VModelingTool::setDialog(){ +} + +void VModelingTool::ignoreContextMenu(bool enable){ + ignoreContextMenuEvent = enable; +} + +void VModelingTool::AddToModeling(const QDomElement &domElement){ + QDomElement modelingElement; + bool ok = doc->GetActivModelingElement(modelingElement); + if(ok){ + modelingElement.appendChild(domElement); + } else { + qCritical()<<"Can't find tag Modeling"<< Q_FUNC_INFO; + } + emit toolhaveChange(); +} diff --git a/tools/modelingTools/vmodelingtool.h b/tools/modelingTools/vmodelingtool.h new file mode 100644 index 000000000..46603c5ad --- /dev/null +++ b/tools/modelingTools/vmodelingtool.h @@ -0,0 +1,63 @@ +#ifndef VMODELINGTOOL_H +#define VMODELINGTOOL_H + +#include "../vabstracttool.h" +#include + +class VModelingTool: public VAbstractTool +{ + Q_OBJECT +public: + VModelingTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); + virtual ~VModelingTool(); + virtual void setDialog(); + void ignoreContextMenu(bool enable); +public slots: + virtual void FullUpdateFromGui(int result)=0; +protected: + bool ignoreContextMenuEvent; + void AddToModeling(const QDomElement &domElement); + template + void ContextMenu(QSharedPointer &dialog, Tool *tool, QGraphicsSceneContextMenuEvent *event, + bool showRemove = true){ + if(!ignoreContextMenuEvent){ + QMenu menu; + QAction *actionOption = menu.addAction("Властивості"); + QAction *actionRemove; + if(showRemove){ + actionRemove = menu.addAction("Видалити"); + } + QAction *selectedAction = menu.exec(event->screenPos()); + if(selectedAction == actionOption){ + dialog = QSharedPointer(new Dialog(getData())); + + connect(qobject_cast< VMainGraphicsScene * >(tool->scene()), &VMainGraphicsScene::ChoosedObject, + dialog.data(), &Dialog::ChoosedObject); + connect(dialog.data(), &Dialog::DialogClosed, tool, + &Tool::FullUpdateFromGui); + connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); + + tool->setDialog(); + + dialog->show(); + } + if(selectedAction == actionRemove){ + //remove form xml file + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + QDomElement element; + bool ok = doc->GetActivCalculationElement(element); + if(ok){ + element.removeChild(domElement); + //update xml file + emit FullUpdateTree(); + //remove form scene + //emit RemoveTool(tool); + } + } + } + } + } +}; + +#endif // VMODELINGTOOL_H diff --git a/tools/nodeDetails/nodedetails.h b/tools/nodeDetails/nodedetails.h new file mode 100644 index 000000000..544c607fe --- /dev/null +++ b/tools/nodeDetails/nodedetails.h @@ -0,0 +1,9 @@ +#ifndef NODEDETAILS_H +#define NODEDETAILS_H + +#include "vnodearc.h" +#include "vnodepoint.h" +#include "vnodespline.h" +#include "vnodesplinepath.h" + +#endif // NODEDETAILS_H diff --git a/tools/nodeDetails/vabstractnode.cpp b/tools/nodeDetails/vabstractnode.cpp new file mode 100644 index 000000000..c159fb91c --- /dev/null +++ b/tools/nodeDetails/vabstractnode.cpp @@ -0,0 +1,21 @@ +#include "vabstractnode.h" +#include + +VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, qint64 id, qint64 idNode, + Draw::Mode typeobject, QObject *parent) : + VAbstractTool(doc, data, id, parent), idNode(idNode), typeobject(typeobject){ +} + +VAbstractNode::~VAbstractNode(){ +} + +void VAbstractNode::AddToModeling(const QDomElement &domElement){ + QDomElement modelingElement; + bool ok = doc->GetActivModelingElement(modelingElement); + if(ok){ + modelingElement.appendChild(domElement); + } else { + qCritical()<<"Can't find tag Modeling"<< Q_FUNC_INFO; + } + emit toolhaveChange(); +} diff --git a/tools/nodeDetails/vabstractnode.h b/tools/nodeDetails/vabstractnode.h new file mode 100644 index 000000000..986a967ad --- /dev/null +++ b/tools/nodeDetails/vabstractnode.h @@ -0,0 +1,19 @@ +#ifndef VABSTRACTNODE_H +#define VABSTRACTNODE_H + +#include "../vabstracttool.h" + +class VAbstractNode : public VAbstractTool +{ + Q_OBJECT +public: + VAbstractNode(VDomDocument *doc, VContainer *data, qint64 id, qint64 idNode, + Draw::Mode typeobject, QObject *parent = 0 ); + virtual ~VAbstractNode(); +protected: + qint64 idNode; + Draw::Mode typeobject; + void AddToModeling(const QDomElement &domElement); +}; + +#endif // VABSTRACTNODE_H diff --git a/tools/nodeDetails/vnodearc.cpp b/tools/nodeDetails/vnodearc.cpp new file mode 100644 index 000000000..231cb73c6 --- /dev/null +++ b/tools/nodeDetails/vnodearc.cpp @@ -0,0 +1,70 @@ +#include "vnodearc.h" + +VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, Draw::Mode typeobject, + Tool::Enum typeCreation, QGraphicsItem * parent) : + VAbstractNode(doc, data, id, idArc, typeobject), QGraphicsPathItem(parent){ + RefreshGeometry(); + this->setPen(QPen(baseColor, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +VNodeArc *VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, + Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation){ + VNodeArc *arc; + if(parse == Document::FullParse){ + arc = new VNodeArc(doc, data, id, idArc, typeobject, typeCreation); + doc->AddTool(id, arc); + } else { + doc->UpdateToolData(id, data); + } + return arc; +} + +void VNodeArc::FullUpdateFromFile(){ + RefreshGeometry(); +} + +void VNodeArc::AddToFile(){ + QDomElement domElement = doc->createElement("arc"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "modeling"); + AddAttribute(domElement, "idObject", idNode); + if(typeobject == Draw::Calculation){ + AddAttribute(domElement, "typeObject", "Calculation"); + } else { + AddAttribute(domElement, "typeObject", "Modeling"); + } + + AddToModeling(domElement); +} + +void VNodeArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(event->button() == Qt::LeftButton){ + emit ChoosedTool(id, Scene::Arc); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VNodeArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthMainLine)); +} + +void VNodeArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthHairLine)); +} + +void VNodeArc::RefreshGeometry(){ + VArc arc = VAbstractTool::data.GetModelingArc(id); + QPainterPath path; + path.addPath(arc.GetPath()); + path.setFillRule( Qt::WindingFill ); + this->setPath(path); +} diff --git a/tools/nodeDetails/vnodearc.h b/tools/nodeDetails/vnodearc.h new file mode 100644 index 000000000..80153b129 --- /dev/null +++ b/tools/nodeDetails/vnodearc.h @@ -0,0 +1,26 @@ +#ifndef VNODEARC_H +#define VNODEARC_H + +#include "vabstractnode.h" +#include + +class VNodeArc :public VAbstractNode, public QGraphicsPathItem +{ + Q_OBJECT +public: + VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, Draw::Mode typeobject, + Tool::Enum typeCreation, QGraphicsItem * parent = 0); + static VNodeArc *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, + Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); +protected: + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + void RefreshGeometry(); +}; + +#endif // VNODEARC_H diff --git a/tools/nodeDetails/vnodepoint.cpp b/tools/nodeDetails/vnodepoint.cpp new file mode 100644 index 000000000..60eab97aa --- /dev/null +++ b/tools/nodeDetails/vnodepoint.cpp @@ -0,0 +1,118 @@ +#include "vnodepoint.h" + +VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, + Draw::Mode typeobject, Tool::Enum typeCreation, QGraphicsItem *parent) + :VAbstractNode(doc, data, id, idPoint, typeobject), QGraphicsEllipseItem(parent), + radius(toPixel(1.5)), namePoint(0), lineName(0){ + namePoint = new VGraphicsSimpleTextItem(this); + lineName = new QGraphicsLineItem(this); + connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, + &VNodePoint::NameChangePosition); + this->setPen(QPen(Qt::black, widthHairLine)); + this->setBrush(QBrush(Qt::NoBrush)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + RefreshPointGeometry(VAbstractTool::data.GetModelingPoint(id)); + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +VNodePoint *VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, + Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation){ + VNodePoint *point; + if(parse == Document::FullParse){ + point = new VNodePoint(doc, data, id, idPoint, typeobject, typeCreation); + doc->AddTool(id, point); + } else { + doc->UpdateToolData(id, data); + } + return point; +} + +void VNodePoint::FullUpdateFromFile(){ + RefreshPointGeometry(VAbstractTool::data.GetModelingPoint(id)); +} + +void VNodePoint::AddToFile(){ + VPointF point = VAbstractTool::data.GetModelingPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "modeling"); + AddAttribute(domElement, "idObject", idNode); + if(typeobject == Draw::Calculation){ + AddAttribute(domElement, "typeObject", "Calculation"); + } else { + AddAttribute(domElement, "typeObject", "Modeling"); + } + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); + + AddToModeling(domElement); +} + +void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(event->button() == Qt::LeftButton){ + emit ChoosedTool(id, Scene::Point); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VNodePoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthMainLine)); +} + +void VNodePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthHairLine)); +} + + +void VNodePoint::NameChangePosition(const QPointF pos){ + VPointF point = VAbstractTool::data.GetModelingPoint(id); + QPointF p = pos - this->pos(); + point.setMx(p.x()); + point.setMy(p.y()); + RefreshLine(); + UpdateNamePosition(point.mx(), point.my()); + VAbstractTool::data.UpdatePoint(id, point); +} + +void VNodePoint::UpdateNamePosition(qreal mx, qreal my){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("mx", QString().setNum(toMM(mx))); + domElement.setAttribute("my", QString().setNum(toMM(my))); + emit toolhaveChange(); + } +} + +void VNodePoint::RefreshPointGeometry(const VPointF &point){ + QRectF rec = QRectF(0, 0, radius*2, radius*2); + rec.translate(-rec.center().x(), -rec.center().y()); + this->setRect(rec); + this->setPos(point.toQPointF()); + disconnect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, + &VNodePoint::NameChangePosition); + namePoint->setText(point.name()); + namePoint->setPos(QPointF(point.mx(), point.my())); + connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, + &VNodePoint::NameChangePosition); + + RefreshLine(); +} + +void VNodePoint::RefreshLine(){ + QRectF nameRec = namePoint->sceneBoundingRect(); + QPointF p1, p2; + LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); + QPointF pRec = LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); + lineName->setLine(QLineF(p1, pRec - scenePos())); + if(QLineF(p1, pRec - scenePos()).length() <= toPixel(4)){ + lineName->setVisible(false); + } else { + lineName->setVisible(true); + } +} diff --git a/tools/nodeDetails/vnodepoint.h b/tools/nodeDetails/vnodepoint.h new file mode 100644 index 000000000..502d08583 --- /dev/null +++ b/tools/nodeDetails/vnodepoint.h @@ -0,0 +1,34 @@ +#ifndef VNODEPOINT_H +#define VNODEPOINT_H + +#include "vabstractnode.h" +#include "widgets/vgraphicssimpletextitem.h" + +class VNodePoint: public VAbstractNode, public QGraphicsEllipseItem +{ + Q_OBJECT +public: + VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, Draw::Mode typeobject, + Tool::Enum typeCreation, QGraphicsItem * parent = 0 ); + static VNodePoint *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, + Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); + void NameChangePosition(const QPointF pos); +protected: + qreal radius; + VGraphicsSimpleTextItem *namePoint; + QGraphicsLineItem *lineName; + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void UpdateNamePosition(qreal mx, qreal my); + virtual void RefreshPointGeometry(const VPointF &point); + void RefreshLine(); +private: + VNodePoint(const VNodePoint &point); + const VNodePoint &operator=(const VNodePoint &point); +}; + +#endif // VNODEPOINT_H diff --git a/tools/nodeDetails/vnodespline.cpp b/tools/nodeDetails/vnodespline.cpp new file mode 100644 index 000000000..6d791b8fe --- /dev/null +++ b/tools/nodeDetails/vnodespline.cpp @@ -0,0 +1,70 @@ +#include "vnodespline.h" + +VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, + Draw::Mode typeobject, Tool::Enum typeCreation, QGraphicsItem * parent) : + VAbstractNode(doc, data, id, idSpline, typeobject), QGraphicsPathItem(parent){ + RefreshGeometry(); + this->setPen(QPen(baseColor, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +VNodeSpline *VNodeSpline::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, + Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation){ + VNodeSpline *spl; + if(parse == Document::FullParse){ + spl = new VNodeSpline(doc, data, id, idSpline, typeobject, typeCreation); + doc->AddTool(id, spl); + } else { + doc->UpdateToolData(id, data); + } + return spl; +} + +void VNodeSpline::FullUpdateFromFile(){ + RefreshGeometry(); +} + +void VNodeSpline::AddToFile(){ + QDomElement domElement = doc->createElement("spline"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "modelingSpline"); + AddAttribute(domElement, "idObject", idNode); + if(typeobject == Draw::Calculation){ + AddAttribute(domElement, "typeObject", "Calculation"); + } else { + AddAttribute(domElement, "typeObject", "Modeling"); + } + + AddToModeling(domElement); +} + +void VNodeSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(event->button() == Qt::LeftButton){ + emit ChoosedTool(id, Scene::Spline); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VNodeSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthMainLine)); +} + +void VNodeSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthHairLine)); +} + +void VNodeSpline::RefreshGeometry(){ + VSpline spl = VAbstractTool::data.GetModelingSpline(id); + QPainterPath path; + path.addPath(spl.GetPath()); + path.setFillRule( Qt::WindingFill ); + this->setPath(path); +} diff --git a/tools/nodeDetails/vnodespline.h b/tools/nodeDetails/vnodespline.h new file mode 100644 index 000000000..a47b89492 --- /dev/null +++ b/tools/nodeDetails/vnodespline.h @@ -0,0 +1,26 @@ +#ifndef VNODESPLINE_H +#define VNODESPLINE_H + +#include "vabstractnode.h" +#include + +class VNodeSpline:public VAbstractNode, public QGraphicsPathItem +{ + Q_OBJECT +public: + VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, Draw::Mode typeobject, + Tool::Enum typeCreation, QGraphicsItem * parent = 0); + static VNodeSpline *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, + Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile (); +protected: + virtual void AddToFile (); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + void RefreshGeometry (); +}; + +#endif // VNODESPLINE_H diff --git a/tools/nodeDetails/vnodesplinepath.cpp b/tools/nodeDetails/vnodesplinepath.cpp new file mode 100644 index 000000000..d8ced7d9a --- /dev/null +++ b/tools/nodeDetails/vnodesplinepath.cpp @@ -0,0 +1,72 @@ +#include "vnodesplinepath.h" + +VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, + Draw::Mode typeobject, Tool::Enum typeCreation, + QGraphicsItem * parent) : + VAbstractNode(doc, data, id, idSpline, typeobject), QGraphicsPathItem(parent){ + RefreshGeometry(); + this->setPen(QPen(baseColor, widthHairLine)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); + + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +VNodeSplinePath *VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, + qint64 idSpline, Draw::Mode typeobject, Document::Enum parse, + Tool::Enum typeCreation){ + VNodeSplinePath *splPath; + if(parse == Document::FullParse){ + splPath = new VNodeSplinePath(doc, data, id, idSpline, typeobject, typeCreation); + doc->AddTool(id, splPath); + } else { + doc->UpdateToolData(id, data); + } + return splPath; +} + +void VNodeSplinePath::FullUpdateFromFile(){ + RefreshGeometry(); +} + +void VNodeSplinePath::AddToFile(){ + QDomElement domElement = doc->createElement("spline"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "modelingPath"); + AddAttribute(domElement, "idObject", idNode); + if(typeobject == Draw::Calculation){ + AddAttribute(domElement, "typeObject", "Calculation"); + } else { + AddAttribute(domElement, "typeObject", "Modeling"); + } + + AddToModeling(domElement); +} + +void VNodeSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(event->button() == Qt::LeftButton){ + emit ChoosedTool(id, Scene::SplinePath); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VNodeSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthMainLine)); +} + +void VNodeSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthHairLine)); +} + +void VNodeSplinePath::RefreshGeometry(){ + VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); + QPainterPath path; + path.addPath(splPath.GetPath()); + path.setFillRule( Qt::WindingFill ); + this->setPath(path); +} diff --git a/tools/nodeDetails/vnodesplinepath.h b/tools/nodeDetails/vnodesplinepath.h new file mode 100644 index 000000000..3b3412521 --- /dev/null +++ b/tools/nodeDetails/vnodesplinepath.h @@ -0,0 +1,26 @@ +#ifndef VNODESPLINEPATH_H +#define VNODESPLINEPATH_H + +#include "vabstractnode.h" +#include + +class VNodeSplinePath : public VAbstractNode, public QGraphicsPathItem +{ + Q_OBJECT +public: + VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, + Draw::Mode typeobject, Tool::Enum typeCreation, QGraphicsItem * parent = 0); + static VNodeSplinePath *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, + Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation); +public slots: + virtual void FullUpdateFromFile(); +protected: + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + void RefreshGeometry(); +}; + +#endif // VNODESPLINEPATH_H diff --git a/tools/tools.h b/tools/tools.h new file mode 100644 index 000000000..8fcccdeec --- /dev/null +++ b/tools/tools.h @@ -0,0 +1,7 @@ +#ifndef TOOLS_H +#define TOOLS_H + +#include "drawTools/drawtools.h" +#include "nodeDetails/nodedetails.h" + +#endif // TOOLS_H diff --git a/tools/vabstracttool.cpp b/tools/vabstracttool.cpp index ae66fd83e..7e3774ea5 100644 --- a/tools/vabstracttool.cpp +++ b/tools/vabstracttool.cpp @@ -1,46 +1,14 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vabstracttool.h" #include -#pragma GCC diagnostic pop -VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, QObject *parent): - VDataTool(data, parent), doc(doc), id(id), ignoreContextMenuEvent(false), nameActivDraw(QString()), - baseColor(Qt::black), currentColor(Qt::black), mode(mode){ +VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent): + VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black){ this->doc = doc; this->id = id; - nameActivDraw = doc->GetNameActivDraw(); - ignoreContextMenuEvent = false;//don't ignore context menu events; - connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VAbstractTool::ChangedActivDraw); - connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VAbstractTool::ChangedNameDraw); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange); connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile); connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree); - connect(this->doc, &VDomDocument::ShowTool, this, &VAbstractTool::ShowTool); -} - -void VAbstractTool::ChangedNameDraw(const QString oldName, const QString newName){ - if(nameActivDraw == oldName){ - nameActivDraw = newName; - } -} - -void VAbstractTool::ChangedActivDraw(const QString newName){ - if(nameActivDraw == newName){ - ignoreContextMenuEvent = false; - } else { - ignoreContextMenuEvent = true; - } -} - -void VAbstractTool::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ - Q_UNUSED(id); - Q_UNUSED(color); - Q_UNUSED(enable); } void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, const qint64 &value){ @@ -70,60 +38,87 @@ void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, c VAbstractTool::~VAbstractTool(){ } -void VAbstractTool::AddToDraw(const QDomElement &domElement){ - QDomElement calcElement; - if(mode == Draw::Modeling){ - bool ok = doc->GetActivModelingElement(calcElement); - if(ok){ - calcElement.appendChild(domElement); - } +QPointF VAbstractTool::LineIntersectRect(QRectF rec, QLineF line){ + qreal x1, y1, x2, y2; + rec.getCoords(&x1, &y1, &x2, &y2); + QPointF point; + QLineF::IntersectType type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x1,y2)),&point); + if ( type == QLineF::BoundedIntersection ){ + return point; + } + type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x2,y1)),&point); + if ( type == QLineF::BoundedIntersection ){ + return point; + } + type = line.intersect(QLineF(QPointF(x1,y2), QPointF(x2,y2)),&point); + if ( type == QLineF::BoundedIntersection ){ + return point; + } + type = line.intersect(QLineF(QPointF(x2,y1), QPointF(x2,y2)),&point); + if ( type == QLineF::BoundedIntersection ){ + return point; + } + Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину."); + return point; +} + +qint32 VAbstractTool::LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, + QPointF &p2){ + const qreal eps = 1e-8; + //коефіцієнти для рівняння відрізку + qreal a = line.p2().y() - line.p1().y(); + qreal b = line.p1().x() - line.p2().x(); + // В даному випадку не використовується. + //qreal c = - a * line.p1().x() - b * line.p1().y(); + // проекция центра окружности на прямую + QPointF p = ClosestPoint (line, center); + // сколько всего решений? + qint32 flag = 0; + qreal d = QLineF (center, p).length(); + if (qAbs (d - radius) <= eps){ + flag = 1; } else { - bool ok = doc->GetActivCalculationElement(calcElement); - if(ok){ - qint64 id = doc->getCursor(); - if(id <= 0){ - calcElement.appendChild(domElement); - } else { - QDomElement refElement = doc->elementById(QString().setNum(doc->getCursor())); - if(refElement.isElement()){ - calcElement.insertAfter(domElement,refElement); - doc->setCursor(0); - } else { - qCritical()<<"Не можу знайти елемент після якого потрібно вставляти."<< Q_FUNC_INFO; - } - } + if (radius > d){ + flag = 2; } else { - qCritical()<<"Не можу знайти тег калькуляції."<< Q_FUNC_INFO; + return 0; } } - emit toolhaveChange(); + // находим расстояние от проекции до точек пересечения + qreal k = sqrt (radius * radius - d * d); + qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length(); + // добавляем к проекции векторы направленные к точкам пеерсечения + p1 = addVector (p, QPointF (0, 0), QPointF (- b, a), k / t); + p2 = addVector (p, QPointF (0, 0), QPointF (b, - a), k / t); + return flag; +} + +QPointF VAbstractTool::ClosestPoint(QLineF line, QPointF p){ + QLineF lineP2pointFrom = QLineF(line.p2(), p); + qreal angle = 180-line.angleTo(lineP2pointFrom)-90; + QLineF pointFromlineP2 = QLineF(p, line.p2()); + pointFromlineP2.setAngle(pointFromlineP2.angle()+angle); + QPointF point; + QLineF::IntersectType type = pointFromlineP2.intersect(line,&point); + if ( type == QLineF::BoundedIntersection ){ + return point; + } else{ + if ( type == QLineF::NoIntersection || type == QLineF::UnboundedIntersection ){ + Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину."); + return point; + } + } + return point; +} + +QPointF VAbstractTool::addVector(QPointF p, QPointF p1, QPointF p2, qreal k){ + return QPointF (p.x() + (p2.x() - p1.x()) * k, p.y() + (p2.y() - p1.y()) * k); } const VContainer *VAbstractTool::getData()const{ return &data; } -void VAbstractTool::setDialog(){ -} - -void VAbstractTool::AddRecord(const qint64 id, Tools::Enum 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 VAbstractTool::ignoreContextMenu(bool enable){ - ignoreContextMenuEvent = enable; +qint64 VAbstractTool::getId() const{ + return id; } diff --git a/tools/vabstracttool.h b/tools/vabstracttool.h index 589d01413..6ebb2b602 100644 --- a/tools/vabstracttool.h +++ b/tools/vabstracttool.h @@ -1,15 +1,8 @@ #ifndef VABSTRACTTOOL_H #define VABSTRACTTOOL_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" -#include #include "../xml/vdomdocument.h" #include "vdatatool.h" -#pragma GCC diagnostic pop #include "../container/vcontainer.h" namespace Tool{ @@ -24,81 +17,34 @@ class VAbstractTool:public VDataTool { Q_OBJECT public: - VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, - QObject *parent = 0); - virtual ~VAbstractTool(); - virtual void setDialog(); - static void AddRecord(const qint64 id, Tools::Enum toolType, VDomDocument *doc); - void ignoreContextMenu(bool enable); + VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); + virtual ~VAbstractTool(); + static QPointF LineIntersectRect(QRectF rec, QLineF line); + static qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, + QPointF &p2); + static QPointF ClosestPoint(QLineF line, QPointF p); + static QPointF addVector (QPointF p, QPointF p1, QPointF p2, qreal k); + qint64 getId() const; + public slots: - virtual void FullUpdateFromFile()=0; - void ChangedNameDraw(const QString oldName, const QString newName); - virtual void ChangedActivDraw(const QString newName); - virtual void FullUpdateFromGui(int result)=0; - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void FullUpdateFromFile()=0; signals: - void toolhaveChange(); - void ChoosedTool(qint64 id, Scene::Type type); - void FullUpdateTree(); - void RemoveTool(QGraphicsItem *tool); + void toolhaveChange(); + void ChoosedTool(qint64 id, Scene::Type type); + void FullUpdateTree(); protected: - VDomDocument *doc; - qint64 id; - bool ignoreContextMenuEvent; - QString nameActivDraw; + VDomDocument *doc; + qint64 id; const Qt::GlobalColor baseColor; - Qt::GlobalColor currentColor; - Draw::Mode mode; - virtual void AddToFile()=0; - void AddAttribute(QDomElement &domElement, const QString &name, const qint64 &value); - void AddAttribute(QDomElement &domElement, const QString &name, const qint32 &value); - void AddAttribute(QDomElement &domElement, const QString &name, const qreal &value); - void AddAttribute(QDomElement &domElement, const QString &name, const QString &value); - void AddToDraw(const QDomElement &domElement); - const VContainer *getData() const; - template - void ContextMenu(QSharedPointer &dialog, Tool *tool, QGraphicsSceneContextMenuEvent *event, - bool showRemove = true){ - if(!ignoreContextMenuEvent){ - QMenu menu; - QAction *actionOption = menu.addAction("Властивості"); - QAction *actionRemove; - if(showRemove){ - actionRemove = menu.addAction("Видалити"); - } - QAction *selectedAction = menu.exec(event->screenPos()); - if(selectedAction == actionOption){ - dialog = QSharedPointer(new Dialog(getData())); - - connect(qobject_cast< VMainGraphicsScene * >(tool->scene()), &VMainGraphicsScene::ChoosedObject, - dialog.data(), &Dialog::ChoosedObject); - connect(dialog.data(), &Dialog::DialogClosed, tool, - &Tool::FullUpdateFromGui); - connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); - - tool->setDialog(); - - dialog->show(); - } - if(selectedAction == actionRemove){ - //remove form xml file - QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - QDomElement element; - bool ok = doc->GetActivCalculationElement(element); - if(ok){ - element.removeChild(domElement); - //update xml file - emit FullUpdateTree(); - //remove form scene - emit RemoveTool(tool); - } - } - } - } - } + Qt::GlobalColor currentColor; + virtual void AddToFile()=0; + void AddAttribute(QDomElement &domElement, const QString &name, const qint64 &value); + void AddAttribute(QDomElement &domElement, const QString &name, const qint32 &value); + void AddAttribute(QDomElement &domElement, const QString &name, const qreal &value); + void AddAttribute(QDomElement &domElement, const QString &name, const QString &value); + const VContainer *getData() const; private: - VAbstractTool(const VAbstractTool &tool); - const VAbstractTool &operator=(const VAbstractTool &tool); + VAbstractTool(const VAbstractTool &tool); + const VAbstractTool &operator=(const VAbstractTool &tool); }; #endif // VABSTRACTTOOL_H diff --git a/tools/vdatatool.cpp b/tools/vdatatool.cpp index 31f26ac12..3249acfad 100644 --- a/tools/vdatatool.cpp +++ b/tools/vdatatool.cpp @@ -1,7 +1,4 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include "vdatatool.h" -#pragma GCC diagnostic pop VDataTool::VDataTool(VContainer *data, QObject *parent) : QObject(parent), data(*data){ diff --git a/tools/vdatatool.h b/tools/vdatatool.h index 22ef9cdf9..f4934ec42 100644 --- a/tools/vdatatool.h +++ b/tools/vdatatool.h @@ -1,11 +1,8 @@ #ifndef VDATATOOL_H #define VDATATOOL_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include -#pragma GCC diagnostic pop -#include "../container/vcontainer.h" +#include "container/vcontainer.h" class VDataTool : public QObject { diff --git a/tools/vgraphicspoint.cpp b/tools/vgraphicspoint.cpp new file mode 100644 index 000000000..df82f6f1e --- /dev/null +++ b/tools/vgraphicspoint.cpp @@ -0,0 +1,39 @@ +#include "vgraphicspoint.h" +#include "options.h" + +VGraphicsPoint::VGraphicsPoint(QGraphicsItem *parent): QGraphicsEllipseItem(parent), + radius(toPixel(1.5)), namePoint(0), lineName(0){ + //namePoint = new VGraphicsSimpleTextItem(this); + lineName = new QGraphicsLineItem(this); + this->setPen(QPen(Qt::black, widthHairLine)); + this->setBrush(QBrush(Qt::NoBrush)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setAcceptHoverEvents(true); +} + +VGraphicsPoint::~VGraphicsPoint(){ +} + + +void VGraphicsPoint::RefreshLine(){ + QRectF nameRec = namePoint->sceneBoundingRect(); + QPointF p1, p2; + LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); + QPointF pRec = LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); + lineName->setLine(QLineF(p1, pRec - scenePos())); + if(QLineF(p1, pRec - scenePos()).length() <= toPixel(4)){ + lineName->setVisible(false); + } else { + lineName->setVisible(true); + } +} + +void VGraphicsPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(Qt::black, widthMainLine)); +} + +void VGraphicsPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ + Q_UNUSED(event); + this->setPen(QPen(Qt::black, widthHairLine)); +} diff --git a/tools/vgraphicspoint.h b/tools/vgraphicspoint.h new file mode 100644 index 000000000..4bd108524 --- /dev/null +++ b/tools/vgraphicspoint.h @@ -0,0 +1,35 @@ +#ifndef VGRAPHICSPOINT_H +#define VGRAPHICSPOINT_H + +#include +#include +#include "widgets/vgraphicssimpletextitem.h" +#include "../container/vpointf.h" + +class VGraphicsPoint: public QGraphicsEllipseItem +{ +public: + VGraphicsPoint(QGraphicsItem *parent); + virtual ~VGraphicsPoint(); +public slots: + virtual void NameChangePosition(const QPointF pos)=0; +protected: + qreal radius; + VGraphicsSimpleTextItem *namePoint; + QGraphicsLineItem *lineName; + virtual void UpdateNamePosition(qreal mx, qreal my)=0; + void RefreshLine(); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RefreshPointGeometry(const VPointF &point)=0; +private: + VGraphicsPoint(const VGraphicsPoint &point); + const VGraphicsPoint &operator=(const VGraphicsPoint &point); + QPointF LineIntersectRect(QRectF rec, QLineF line) const; + qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, + QPointF &p2) const; + QPointF ClosestPoint(QLineF line, QPointF p) const; + QPointF addVector (QPointF p, QPointF p1, QPointF p2, qreal k) const; +}; + +#endif // VGRAPHICSPOINT_H diff --git a/tools/vmodelingarc.cpp b/tools/vmodelingarc.cpp deleted file mode 100644 index 3ca7f6956..000000000 --- a/tools/vmodelingarc.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include "vmodelingarc.h" - -VModelingArc::VModelingArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, Draw::Mode typeobject, - Tool::Enum typeCreation, QGraphicsItem * parent):VAbstractTool(doc, data, id, Draw::Modeling), - QGraphicsPathItem(parent), idArc(idArc), typeobject(typeobject){ - VArc arc = data->GetModelingArc(id); - QPainterPath path; - path.addPath(arc.GetPath()); - path.setFillRule( Qt::WindingFill ); - this->setPath(path); - this->setPen(QPen(Qt::black, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); - - if(typeCreation == Tool::FromGui){ - AddToFile(); - } -} - -VModelingArc *VModelingArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, - Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation){ - VModelingArc *arc; - if(parse == Document::FullParse){ - arc = new VModelingArc(doc, data, id, idArc, typeobject, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id, arc); - } else { - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - tools->insert(id, tool); - } - } - return arc; -} - -void VModelingArc::FullUpdateFromFile(){ - RefreshGeometry(); -} - -void VModelingArc::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ - if(id == this->id){ - if(enable == false){ - this->setPen(QPen(baseColor, widthHairLine)); - currentColor = baseColor; - } else { - this->setPen(QPen(color, widthHairLine)); - currentColor = color; - } - } -} - -void VModelingArc::FullUpdateFromGui(int result){ - Q_UNUSED(result); -} - -void VModelingArc::AddToFile(){ - QDomElement domElement = doc->createElement("arc"); - - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "modeling"); - AddAttribute(domElement, "idObject", idArc); - if(typeobject == Draw::Calculation){ - AddAttribute(domElement, "typeObject", "Calculation"); - } else { - AddAttribute(domElement, "typeObject", "Modeling"); - } - - AddToDraw(domElement); -} - -void VModelingArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ - emit ChoosedTool(id, Scene::Arc); - } - QGraphicsItem::mouseReleaseEvent(event); -} - -void VModelingArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ - Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); -} - -void VModelingArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ - Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); -} - -void VModelingArc::RefreshGeometry(){ - VArc arc = VAbstractTool::data.GetModelingArc(id); - QPainterPath path; - path.addPath(arc.GetPath()); - path.setFillRule( Qt::WindingFill ); - this->setPath(path); -} diff --git a/tools/vmodelingarc.h b/tools/vmodelingarc.h deleted file mode 100644 index 14d850fc8..000000000 --- a/tools/vmodelingarc.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef VMODELINGARC_H -#define VMODELINGARC_H - -#include "vabstracttool.h" -#include - -class VModelingArc :public VAbstractTool, public QGraphicsPathItem -{ - Q_OBJECT -public: - VModelingArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, Draw::Mode typeobject, - Tool::Enum typeCreation, QGraphicsItem * parent = 0); - static VModelingArc *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, - Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation); -public slots: - virtual void FullUpdateFromFile(); - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); - virtual void FullUpdateFromGui(int result); -protected: - virtual void AddToFile(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); -private: - qint64 idArc; - Draw::Mode typeobject; - void RefreshGeometry(); -}; - -#endif // VMODELINGARC_H diff --git a/tools/vmodelingpoint.cpp b/tools/vmodelingpoint.cpp deleted file mode 100644 index d9c916452..000000000 --- a/tools/vmodelingpoint.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "vmodelingpoint.h" - -VModelingPoint::VModelingPoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - Draw::Mode typeobject, Tool::Enum typeCreation, QGraphicsItem *parent) - :VToolPoint(doc, data, id, Draw::Modeling, parent), idPoint(idPoint), typeobject(typeobject){ - disconnect(this->doc, &VDomDocument::ChangedActivDraw, this, &VModelingPoint::ChangedActivDraw); - disconnect(this->doc, &VDomDocument::ChangedNameDraw, this, &VModelingPoint::ChangedNameDraw); - if(typeCreation == Tool::FromGui){ - AddToFile(); - } -} - -VModelingPoint *VModelingPoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation){ - VModelingPoint *point; - if(parse == Document::FullParse){ - point = new VModelingPoint(doc, data, id, idPoint, typeobject, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id, point); - } else { - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - tools->insert(id, tool); - } - } - return point; -} - -void VModelingPoint::FullUpdateFromFile(){ - RefreshGeometry(); -} - -void VModelingPoint::FullUpdateFromGui(int result){ - Q_UNUSED(result); -} - -void VModelingPoint::AddToFile(){ - VPointF point = VAbstractTool::data.GetModelingPoint(id); - QDomElement domElement = doc->createElement("point"); - - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "modeling"); - AddAttribute(domElement, "idObject", idPoint); - if(typeobject == Draw::Calculation){ - AddAttribute(domElement, "typeObject", "Calculation"); - } else { - AddAttribute(domElement, "typeObject", "Modeling"); - } - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); - - AddToDraw(domElement); -} diff --git a/tools/vmodelingpoint.h b/tools/vmodelingpoint.h deleted file mode 100644 index 3e4ff9efc..000000000 --- a/tools/vmodelingpoint.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef VMODELINGPOINT_H -#define VMODELINGPOINT_H - -#include "vtoolpoint.h" - -class VModelingPoint: public VToolPoint -{ - Q_OBJECT -public: - VModelingPoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, Draw::Mode typeobject, - Tool::Enum typeCreation, QGraphicsItem * parent = 0 ); - static VModelingPoint *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation); -public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); -protected: - virtual void AddToFile(); -private: - qint64 idPoint; - Draw::Mode typeobject; -}; - -#endif // VMODELINGPOINT_H diff --git a/tools/vmodelingspline.cpp b/tools/vmodelingspline.cpp deleted file mode 100644 index b448442b3..000000000 --- a/tools/vmodelingspline.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "vmodelingspline.h" - -VModelingSpline::VModelingSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Mode typeobject, Tool::Enum typeCreation, QGraphicsItem * parent) - :VAbstractTool(doc, data, id, Draw::Modeling), QGraphicsPathItem(parent), idSpline(idSpline), - typeobject(typeobject){ - VSpline spl = data->GetModelingSpline(id); - QPainterPath path; - path.addPath(spl.GetPath()); - path.setFillRule( Qt::WindingFill ); - this->setPath(path); - this->setPen(QPen(Qt::black, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); - - if(typeCreation == Tool::FromGui){ - AddToFile(); - } -} - -VModelingSpline *VModelingSpline::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation){ - VModelingSpline *spl; - if(parse == Document::FullParse){ - spl = new VModelingSpline(doc, data, id, idSpline, typeobject, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id, spl); - } else { - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - tools->insert(id, tool); - } - } - return spl; -} - -void VModelingSpline::FullUpdateFromFile(){ - RefreshGeometry(); -} - -void VModelingSpline::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ - if(id == this->id){ - if(enable == false){ - this->setPen(QPen(baseColor, widthHairLine)); - currentColor = baseColor; - } else { - this->setPen(QPen(color, widthHairLine)); - currentColor = color; - } - } -} - -void VModelingSpline::FullUpdateFromGui(int result){ - Q_UNUSED(result); -} - -void VModelingSpline::AddToFile(){ - QDomElement domElement = doc->createElement("spline"); - - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "modelingSpline"); - AddAttribute(domElement, "idObject", idSpline); - if(typeobject == Draw::Calculation){ - AddAttribute(domElement, "typeObject", "Calculation"); - } else { - AddAttribute(domElement, "typeObject", "Modeling"); - } - - AddToDraw(domElement); -} - -void VModelingSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ - emit ChoosedTool(id, Scene::Spline); - } - QGraphicsItem::mouseReleaseEvent(event); -} - -void VModelingSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ - Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); -} - -void VModelingSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ - Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); -} - -void VModelingSpline::RefreshGeometry(){ - VSpline spl = VAbstractTool::data.GetModelingSpline(id); - QPainterPath path; - path.addPath(spl.GetPath()); - path.setFillRule( Qt::WindingFill ); - this->setPath(path); -} diff --git a/tools/vmodelingspline.h b/tools/vmodelingspline.h deleted file mode 100644 index fd98387bf..000000000 --- a/tools/vmodelingspline.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef VMODELINGSPLINE_H -#define VMODELINGSPLINE_H - -#include "vabstracttool.h" -#include - -class VModelingSpline:public VAbstractTool, public QGraphicsPathItem -{ - Q_OBJECT -public: - VModelingSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, Draw::Mode typeobject, - Tool::Enum typeCreation, QGraphicsItem * parent = 0); - static VModelingSpline *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation); -public slots: - virtual void FullUpdateFromFile (); - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); - virtual void FullUpdateFromGui(int result); -protected: - virtual void AddToFile (); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); -private: - qint64 idSpline; - Draw::Mode typeobject; - void RefreshGeometry (); -}; - -#endif // VMODELINGSPLINE_H diff --git a/tools/vmodelingsplinepath.cpp b/tools/vmodelingsplinepath.cpp deleted file mode 100644 index e0cd6beef..000000000 --- a/tools/vmodelingsplinepath.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include "vmodelingsplinepath.h" - -VModelingSplinePath::VModelingSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Mode typeobject, Tool::Enum typeCreation, - QGraphicsItem * parent):VAbstractTool(doc, data, id, Draw::Modeling), - QGraphicsPathItem(parent), idSpline(idSpline), typeobject(typeobject){ - VSplinePath splPath = data->GetModelingSplinePath(id); - QPainterPath path; - path.addPath(splPath.GetPath()); - path.setFillRule( Qt::WindingFill ); - this->setPath(path); - this->setPen(QPen(Qt::black, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); - - if(typeCreation == Tool::FromGui){ - AddToFile(); - } -} - -VModelingSplinePath *VModelingSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, - qint64 idSpline, Draw::Mode typeobject, Document::Enum parse, - Tool::Enum typeCreation){ - VModelingSplinePath *splPath; - if(parse == Document::FullParse){ - splPath = new VModelingSplinePath(doc, data, id, idSpline, typeobject, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id, splPath); - } else { - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - tools->insert(id, tool); - } - } - return splPath; -} - -void VModelingSplinePath::FullUpdateFromFile(){ - RefreshGeometry(); -} - -void VModelingSplinePath::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ - if(id == this->id){ - if(enable == false){ - this->setPen(QPen(baseColor, widthHairLine)); - currentColor = baseColor; - } else { - this->setPen(QPen(color, widthHairLine)); - currentColor = color; - } - } -} - -void VModelingSplinePath::FullUpdateFromGui(int result){ - Q_UNUSED(result); -} - -void VModelingSplinePath::AddToFile(){ - QDomElement domElement = doc->createElement("spline"); - - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "modelingPath"); - AddAttribute(domElement, "idObject", idSpline); - if(typeobject == Draw::Calculation){ - AddAttribute(domElement, "typeObject", "Calculation"); - } else { - AddAttribute(domElement, "typeObject", "Modeling"); - } - - AddToDraw(domElement); -} - -void VModelingSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ - emit ChoosedTool(id, Scene::SplinePath); - } - QGraphicsItem::mouseReleaseEvent(event); -} - -void VModelingSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ - Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); -} - -void VModelingSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ - Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); -} - -void VModelingSplinePath::RefreshGeometry(){ - VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); - QPainterPath path; - path.addPath(splPath.GetPath()); - path.setFillRule( Qt::WindingFill ); - this->setPath(path); -} diff --git a/tools/vmodelingsplinepath.h b/tools/vmodelingsplinepath.h deleted file mode 100644 index a1259b678..000000000 --- a/tools/vmodelingsplinepath.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef VMODELINGSPLINEPATH_H -#define VMODELINGSPLINEPATH_H - -#include "vabstracttool.h" -#include - -class VModelingSplinePath:public VAbstractTool, public QGraphicsPathItem -{ - Q_OBJECT -public: - VModelingSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Mode typeobject, Tool::Enum typeCreation, QGraphicsItem * parent = 0); - static VModelingSplinePath *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Mode typeobject, Document::Enum parse, Tool::Enum typeCreation); -public slots: - virtual void FullUpdateFromFile(); - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); - virtual void FullUpdateFromGui(int result); -protected: - virtual void AddToFile(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); -private: - qint64 idSpline; - Draw::Mode typeobject; - void RefreshGeometry(); -}; - -#endif // VMODELINGSPLINEPATH_H diff --git a/tools/vtoolarc.h b/tools/vtoolarc.h deleted file mode 100644 index 2a23b3155..000000000 --- a/tools/vtoolarc.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef VTOOLARC_H -#define VTOOLARC_H - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" -#include "vabstracttool.h" -#include "../xml/vdomdocument.h" -#include -#include "../dialogs/dialogarc.h" -#include "../widgets/vcontrolpointspline.h" -#pragma GCC diagnostic pop -#include "../container/vcontainer.h" - -class VToolArc :public VAbstractTool, public QGraphicsPathItem -{ - Q_OBJECT -public: - VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, Tool::Enum typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Draw::Mode mode); - static void Create(const qint64 _id, const qint64 ¢er, const QString &radius, - const QString &f1, const QString &f2, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, Document::Enum parse, Tool::Enum typeCreation, Draw::Mode mode); -public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); - virtual void ChangedActivDraw(const QString newName); - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); -protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); -private: - QSharedPointer dialogArc; - void RefreshGeometry(); -}; - -#endif // VTOOLARC_H diff --git a/tools/vtooldetail.cpp b/tools/vtooldetail.cpp index 355dbbd50..e474c5453 100644 --- a/tools/vtooldetail.cpp +++ b/tools/vtooldetail.cpp @@ -1,58 +1,143 @@ #include "vtooldetail.h" -#include "vmodelingpoint.h" -#include "vmodelingarc.h" -#include "vmodelingspline.h" -#include "vmodelingsplinepath.h" +#include "nodeDetails/nodedetails.h" #include +#include "modelingTools/vmodelingtool.h" +#include "modelingTools/modelingtools.h" VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, VDetail &oldDetail, Tool::Enum typeCreation, Document::Enum parse, VMainGraphicsScene *scene, QGraphicsItem *parent) - :VAbstractTool(doc, data, id, Draw::Modeling), QGraphicsPathItem(parent), - dialogDetail(QSharedPointer()){ + :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), + dialogDetail(QSharedPointer()), sceneDetails(scene){ VDetail detail = data->GetDetail(id); for(qint32 i = 0; i< detail.CountNode(); ++i){ switch(detail[i].getTypeTool()){ - case(Scene::Point):{ - VModelingPoint *point = VModelingPoint::Create(doc, data, detail[i].getId(), oldDetail[i].getId(), - detail[i].getMode(), parse, typeCreation); - connect(point, &VModelingPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + case(Tools::NodePoint):{ + VNodePoint *point = VNodePoint::Create(doc, data, detail[i].getId(), oldDetail[i].getId(), + detail[i].getMode(), parse, typeCreation); + connect(point, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); QMap* tools = doc->getTools(); tools->insert(detail[i].getId(),point); point->setParentItem(this); - } - break; - case(Scene::Arc):{ - VModelingArc *arc = VModelingArc::Create(doc, data, detail[i].getId(), oldDetail[i].getId(), - detail[i].getMode(), parse, typeCreation); - connect(arc, &VModelingArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - QMap* tools = doc->getTools(); - tools->insert(detail[i].getId(), arc); - arc->setParentItem(this); - } - break; - case(Scene::Spline):{ - VModelingSpline *spl = VModelingSpline::Create(doc, data, detail[i].getId(), oldDetail[i].getId(), - detail[i].getMode(), parse, typeCreation); - connect(spl, &VModelingSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + break; + } + case(Tools::NodeArc):{ + VNodeArc *arc = VNodeArc::Create(doc, data, detail[i].getId(), oldDetail[i].getId(), + detail[i].getMode(), parse, typeCreation); + connect(arc, &VNodeArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + QMap* tools = doc->getTools(); + tools->insert(detail[i].getId(), arc); + arc->setParentItem(this); + break; + } + case(Tools::NodeSpline):{ + VNodeSpline *spl = VNodeSpline::Create(doc, data, detail[i].getId(), oldDetail[i].getId(), + detail[i].getMode(), parse, typeCreation); + connect(spl, &VNodeSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); QMap* tools = doc->getTools(); tools->insert(detail[i].getId(), spl); spl->setParentItem(this); - } - break; - case(Scene::SplinePath):{ - VModelingSplinePath *splPath = VModelingSplinePath::Create(doc, data, detail[i].getId(), - oldDetail[i].getId(), - detail[i].getMode(), parse, - typeCreation); - connect(splPath, &VModelingSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + break; + } + case(Tools::NodeSplinePath):{ + VNodeSplinePath *splPath = VNodeSplinePath::Create(doc, data, detail[i].getId(), + oldDetail[i].getId(), + detail[i].getMode(), parse, typeCreation); + connect(splPath, &VNodeSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); QMap* tools = doc->getTools(); tools->insert(detail[i].getId(), splPath); splPath->setParentItem(this); - } break; } - + case(Tools::AlongLineTool):{ + QMap* tools = doc->getTools(); + VModelingAlongLine *tool = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(tool); + connect(tool, &VModelingAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(this); + break; + } + case(Tools::ArcTool):{ + QMap* tools = doc->getTools(); + VModelingArc *tool = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(tool); + connect(tool, &VModelingArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(this); + break; + } + case(Tools::BisectorTool):{ + QMap* tools = doc->getTools(); + VModelingBisector *tool = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(tool); + connect(tool, &VModelingBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(this); + break; + } + case(Tools::EndLineTool):{ + QMap* tools = doc->getTools(); + VModelingEndLine *tool = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(tool); + connect(tool, &VModelingEndLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(this); + break; + } + case(Tools::LineIntersectTool):{ + QMap* tools = doc->getTools(); + VModelingLineIntersect *tool = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(tool); + connect(tool, &VModelingLineIntersect::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(this); + break; + } + case(Tools::LineTool):{ + QMap* tools = doc->getTools(); + VModelingLine *tool = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(tool); + connect(tool, &VModelingLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(this); + break; + } + case(Tools::NormalTool):{ + QMap* tools = doc->getTools(); + VModelingNormal *tool = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(tool); + connect(tool, &VModelingNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(this); + break; + } + case(Tools::PointOfContact):{ + QMap* tools = doc->getTools(); + VModelingPointOfContact *tool = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(tool); + connect(tool, &VModelingPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(this); + break; + } + case(Tools::ShoulderPointTool):{ + QMap* tools = doc->getTools(); + VModelingShoulderPoint *tool = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(tool); + connect(tool, &VModelingShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(this); + break; + } + case(Tools::SplinePathTool):{ + QMap* tools = doc->getTools(); + VModelingSplinePath *tool = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(tool); + connect(tool, &VModelingSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(this); + break; + } + case(Tools::SplineTool):{ + QMap* tools = doc->getTools(); + VModelingSpline *tool = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(tool); + connect(tool, &VModelingSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(this); + break; + } + } } this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -73,13 +158,13 @@ void VToolDetail::setDialog(){ } void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data){ + VContainer *data){ VDetail detail = dialog->getDetails(); VDetail det; for(qint32 i = 0; i< detail.CountNode(); ++i){ qint64 id = 0; switch(detail[i].getTypeTool()){ - case(Scene::Point):{ + case(Tools::NodePoint):{ VPointF point; if(detail[i].getMode() == Draw::Calculation){ point = data->GetPoint(detail[i].getId()); @@ -89,7 +174,7 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen id = data->AddModelingPoint(point); } break; - case(Scene::Arc):{ + case(Tools::NodeArc):{ VArc arc; if(detail[i].getMode() == Draw::Calculation){ arc = data->GetArc(detail[i].getId()); @@ -99,7 +184,7 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen id = data->AddModelingArc(arc); } break; - case(Scene::Spline):{ + case(Tools::NodeSpline):{ VSpline spline; if(detail[i].getMode() == Draw::Calculation){ spline = data->GetSpline(detail[i].getId()); @@ -109,7 +194,7 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen id = data->AddModelingSpline(spline); } break; - case(Scene::SplinePath):{ + case(Tools::NodeSplinePath):{ VSplinePath splinePath; if(detail[i].getMode() == Draw::Calculation){ splinePath = data->GetSplinePath(detail[i].getId()); @@ -119,10 +204,11 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen id = data->AddModelingSplinePath(splinePath); } break; - case(Scene::Line): + default: + qWarning()<<"May be wrong tool type!!! Ignoring."<addItem(detail); - //connect(detail, &VToolBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(detail, &VToolDetail::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); //connect(detail, &VToolBisector::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); QMap* tools = doc->getTools(); tools->insert(id, detail); @@ -194,7 +280,7 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const if (change == ItemPositionHasChanged && scene()) { // value - это новое положение. QPointF newPos = value.toPointF(); - qDebug()<elementById(QString().setNum(id)); if(domElement.isElement()){ domElement.setAttribute("mx", QString().setNum(toMM(newPos.x()))); @@ -206,27 +292,72 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const return QGraphicsItem::itemChange(change, value); } +void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ + if(event->button() == Qt::LeftButton){ + emit ChoosedTool(id, Scene::Detail); + } + QGraphicsItem::mouseReleaseEvent(event); +} + void VToolDetail::AddNode(QDomElement &domElement, VNodeDetail &node){ QDomElement nod = doc->createElement("node"); AddAttribute(nod, "id", node.getId()); + if(node.getTypeNode() == NodeDetail::Contour){ + AddAttribute(nod, "nodeType", "Contour"); + } else { + AddAttribute(nod, "nodeType", "Modeling"); + } switch(node.getTypeTool()){ - case(Scene::Line): - break; - case(Scene::Point): - AddAttribute(nod, "type", "Point"); - break; - case(Scene::Arc): - AddAttribute(nod, "type", "Arc"); - break; - case(Scene::Spline): - AddAttribute(nod, "type", "Spline"); - break; - case(Scene::SplinePath): - AddAttribute(nod, "type", "SplinePath"); + case(Tools::AlongLineTool): + AddAttribute(nod, "type", "AlongLineTool"); + break; + case(Tools::ArcTool): + AddAttribute(nod, "type", "ArcTool"); + break; + case(Tools::BisectorTool): + AddAttribute(nod, "type", "BisectorTool"); + break; + case(Tools::EndLineTool): + AddAttribute(nod, "type", "EndLineTool"); + break; + case(Tools::LineIntersectTool): + AddAttribute(nod, "type", "LineIntersectTool"); + break; + case(Tools::LineTool): + AddAttribute(nod, "type", "LineTool"); + break; + case(Tools::NodeArc): + AddAttribute(nod, "type", "NodeArc"); + break; + case(Tools::NodePoint): + AddAttribute(nod, "type", "NodePoint"); + break; + case(Tools::NodeSpline): + AddAttribute(nod, "type", "NodeSpline"); + break; + case(Tools::NodeSplinePath): + AddAttribute(nod, "type", "NodeSplinePath"); + break; + case(Tools::NormalTool): + AddAttribute(nod, "type", "NormalTool"); + break; + case(Tools::PointOfContact): + AddAttribute(nod, "type", "PointOfContact"); + break; + case(Tools::ShoulderPointTool): + AddAttribute(nod, "type", "ShoulderPointTool"); + break; + case(Tools::SplinePathTool): + AddAttribute(nod, "type", "SplinePathTool"); + break; + case(Tools::SplineTool): + AddAttribute(nod, "type", "SplineTool"); + break; + default: + qWarning()<<"May be wrong tool type!!! Ignoring."< -#include "../dialogs/dialogdetail.h" +#include "dialogs/dialogdetail.h" class VToolDetail: public VAbstractTool, public QGraphicsPathItem { @@ -18,14 +18,29 @@ public: static void Create(const qint64 _id, VDetail &newDetail, VDetail &oldDetail, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, Document::Enum parse, Tool::Enum typeCreation); + template + void AddTool(Tool *tool, const qint64 &id, Tools::Enum typeTool){ + tool->setParentItem(this); + connect(tool, &Tool::ChoosedTool, sceneDetails, &VMainGraphicsScene::ChoosedItem); + VNodeDetail node(id, typeTool, Draw::Modeling, NodeDetail::Modeling); + 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()){ + AddNode(domElement, node); + } + } public slots: virtual void FullUpdateFromFile (); virtual void FullUpdateFromGui(int result); protected: virtual void AddToFile (); QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); private: QSharedPointer dialogDetail; + VMainGraphicsScene *sceneDetails; void RefreshGeometry (); void AddNode(QDomElement &domElement, VNodeDetail &node); }; diff --git a/tools/vtoolpoint.cpp b/tools/vtoolpoint.cpp deleted file mode 100644 index 4017e3dc4..000000000 --- a/tools/vtoolpoint.cpp +++ /dev/null @@ -1,240 +0,0 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" -#include "vtoolpoint.h" -#include -#include -#include -#include -#include "../widgets/vmaingraphicsscene.h" -#pragma GCC diagnostic pop -#include -#include "../container/vpointf.h" - - -VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, - QGraphicsItem *parent):VAbstractTool(doc, data, id, mode), QGraphicsEllipseItem(parent), - radius(1.5*PrintDPI/25.4), namePoint(0), lineName(0){ - //create circle - VPointF point; - if(mode == Draw::Calculation){ - point = data->GetPoint(id); - } else { - point = data->GetModelingPoint(id); - } - QRectF rec = QRectF(0, 0, radius*2, radius*2); - rec.translate(-rec.center().x(), -rec.center().y()); - this->setRect(rec); - this->setPen(QPen(Qt::black, widthHairLine)); - this->setBrush(QBrush(Qt::NoBrush)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); - this->setPos(point.toQPointF()); - - //Тексто мітка точки - namePoint = new VGraphicsSimpleTextItem(point.name(), this); - rec = this->rect(); - namePoint->setPos(QPointF(point.mx(), point.my())); - connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, - &VToolPoint::NameChangePosition); - - //Лінія, що з'єднує точку і мітку - lineName = new QGraphicsLineItem(this); - RefreshLine(); -} - -void VToolPoint::NameChangePosition(const QPointF pos){ - VPointF point; - if(mode == Draw::Calculation){ - point = VAbstractTool::data.GetPoint(id); - } else { - point = VAbstractTool::data.GetModelingPoint(id); - } - QPointF p = pos - this->pos(); - point.setMx(p.x()); - point.setMy(p.y()); - RefreshLine(); - LiteUpdateFromGui(point.mx(), point.my()); - VAbstractTool::data.UpdatePoint(id, point); -} - -QPointF VToolPoint::LineIntersectRect(QRectF rec, QLineF line) const{ - qreal x1, y1, x2, y2; - rec.getCoords(&x1, &y1, &x2, &y2); - QPointF point; - QLineF::IntersectType type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x1,y2)),&point); - if ( type == QLineF::BoundedIntersection ){ - return point; - } - type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x2,y1)),&point); - if ( type == QLineF::BoundedIntersection ){ - return point; - } - type = line.intersect(QLineF(QPointF(x1,y2), QPointF(x2,y2)),&point); - if ( type == QLineF::BoundedIntersection ){ - return point; - } - type = line.intersect(QLineF(QPointF(x2,y1), QPointF(x2,y2)),&point); - if ( type == QLineF::BoundedIntersection ){ - return point; - } - Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину."); - return point; -} - -void VToolPoint::RefreshLine(){ - QRectF nameRec = namePoint->sceneBoundingRect(); - QPointF p1, p2; - LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); - QPointF pRec = LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); - lineName->setLine(QLineF(p1, pRec - scenePos())); - if(QLineF(p1, pRec - scenePos()).length() <= toPixel(4)){ - lineName->setVisible(false); - } else { - lineName->setVisible(true); - } -} - -qint32 VToolPoint::LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, - QPointF &p2) const{ - const qreal eps = 1e-8; - //коефіцієнти для рівняння відрізку - qreal a = line.p2().y() - line.p1().y(); - qreal b = line.p1().x() - line.p2().x(); - // В даному випадку не використовується. - //qreal c = - a * line.p1().x() - b * line.p1().y(); - // проекция центра окружности на прямую - QPointF p = ClosestPoint (line, center); - // сколько всего решений? - qint32 flag = 0; - qreal d = QLineF (center, p).length(); - if (qAbs (d - radius) <= eps){ - flag = 1; - } else { - if (radius > d){ - flag = 2; - } else { - return 0; - } - } - // находим расстояние от проекции до точек пересечения - qreal k = sqrt (radius * radius - d * d); - qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length(); - // добавляем к проекции векторы направленные к точкам пеерсечения - p1 = addVector (p, QPointF (0, 0), QPointF (- b, a), k / t); - p2 = addVector (p, QPointF (0, 0), QPointF (b, - a), k / t); - return flag; -} - -QPointF VToolPoint::ClosestPoint(QLineF line, QPointF p) const{ - QLineF lineP2pointFrom = QLineF(line.p2(), p); - qreal angle = 180-line.angleTo(lineP2pointFrom)-90; - QLineF pointFromlineP2 = QLineF(p, line.p2()); - pointFromlineP2.setAngle(pointFromlineP2.angle()+angle); - QPointF point; - QLineF::IntersectType type = pointFromlineP2.intersect(line,&point); - if ( type == QLineF::BoundedIntersection ){ - return point; - } else{ - if ( type == QLineF::NoIntersection || type == QLineF::UnboundedIntersection ){ - Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину."); - return point; - } - } - return point; -} - -QPointF VToolPoint::addVector(QPointF p, QPointF p1, QPointF p2, qreal k) const{ - return QPointF (p.x() + (p2.x() - p1.x()) * k, p.y() + (p2.y() - p1.y()) * k); -} - -void VToolPoint::LiteUpdateFromGui(qreal mx, qreal my){ - QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("mx", QString().setNum(mx/PrintDPI*25.4)); - domElement.setAttribute("my", QString().setNum(my/PrintDPI*25.4)); - emit toolhaveChange(); - } -} - -void VToolPoint::ChangedActivDraw(const QString newName){ - if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); - namePoint->setFlag(QGraphicsItem::ItemIsMovable, true); - namePoint->setFlag(QGraphicsItem::ItemIsSelectable, true); - namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - namePoint->setBrush(QBrush(Qt::black)); - namePoint->setAcceptHoverEvents(true); - lineName->setPen(QPen(Qt::black, widthHairLine)); - VAbstractTool::ChangedActivDraw(newName); - } else { - this->setPen(QPen(Qt::gray, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, false); - this->setAcceptHoverEvents (false); - namePoint->setFlag(QGraphicsItem::ItemIsMovable, false); - namePoint->setFlag(QGraphicsItem::ItemIsSelectable, false); - namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); - namePoint->setBrush(QBrush(Qt::gray)); - namePoint->setAcceptHoverEvents(false); - lineName->setPen(QPen(Qt::gray, widthHairLine)); - VAbstractTool::ChangedActivDraw(newName); - } -} - -void VToolPoint::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ - if(id == this->id){ - if(enable == false){ - this->setPen(QPen(baseColor, widthHairLine)); - currentColor = baseColor; - } else { - this->setPen(QPen(color, widthHairLine)); - currentColor = color; - } - } -} - -void VToolPoint::RefreshGeometry(){ - VPointF point; - if(mode == Draw::Calculation){ - point = VAbstractTool::data.GetPoint(id); - } else { - point = VAbstractTool::data.GetModelingPoint(id); - } - QRectF rec = QRectF(0, 0, radius*2, radius*2); - rec.translate(-rec.center().x(), -rec.center().y()); - this->setRect(rec); - this->setPos(point.toQPointF()); - disconnect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, - &VToolPoint::NameChangePosition); - namePoint->setText(point.name()); - namePoint->setPos(QPointF(point.mx(), point.my())); - connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, - &VToolPoint::NameChangePosition); - - RefreshLine(); -} - -void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ - emit ChoosedTool(id, Scene::Point); - } - QGraphicsItem::mouseReleaseEvent(event); -} - -void VToolPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ - Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); -} - -void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ - Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); -} - -VToolPoint::~VToolPoint(){ - -} diff --git a/tools/vtoolpoint.h b/tools/vtoolpoint.h deleted file mode 100644 index 5a6d662a3..000000000 --- a/tools/vtoolpoint.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef VTOOLPOINT_H -#define VTOOLPOINT_H - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" -#include -#include -#include "../widgets/vgraphicssimpletextitem.h" -#include "vabstracttool.h" -#pragma GCC diagnostic pop -#include "../options.h" - -class VToolPoint: public VAbstractTool, public QGraphicsEllipseItem -{ - Q_OBJECT -public: - VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, Draw::Mode mode, QGraphicsItem * parent = 0); - virtual ~VToolPoint(); -public slots: - void NameChangePosition(const QPointF pos); - virtual void ChangedActivDraw(const QString newName); - virtual void FullUpdateFromGui(int result) = 0; - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); -protected: - qreal radius; - VGraphicsSimpleTextItem *namePoint; - QGraphicsLineItem *lineName; - virtual void RefreshGeometry(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); -private: - VToolPoint(const VToolPoint &tool); - const VToolPoint &operator=(const VToolPoint &tool); - QPointF LineIntersectRect(QRectF rec, QLineF line) const; - void LiteUpdateFromGui(qreal mx, qreal my); - void RefreshLine(); - qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, - QPointF &p2) const; - QPointF ClosestPoint(QLineF line, QPointF p) const; - QPointF addVector (QPointF p, QPointF p1, QPointF p2, qreal k) const; - -}; - -#endif // VTOOLPOINT_H diff --git a/tools/vtoolsimplepoint.cpp b/tools/vtoolsimplepoint.cpp deleted file mode 100644 index b2d24ef91..000000000 --- a/tools/vtoolsimplepoint.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "vtoolsimplepoint.h" -#include "../container/vpointf.h" - -VToolSimplePoint::VToolSimplePoint(VDomDocument *doc, VContainer *data, qint64 id, - QGraphicsItem *parent):VAbstractTool(doc, data, id), - QGraphicsEllipseItem(parent){ - -} - diff --git a/tools/vtoolsimplepoint.h b/tools/vtoolsimplepoint.h deleted file mode 100644 index 7b442f060..000000000 --- a/tools/vtoolsimplepoint.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef VTOOLSIMPLEPOINT_H -#define VTOOLSIMPLEPOINT_H - -#include -#include - -#include "../options.h" -#include "vabstracttool.h" - -class VToolSimplePoint: public VAbstractTool, public QGraphicsEllipseItem -{ - Q_OBJECT -public: - VToolSimplePoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem * parent = 0); -public slots: - virtual void ChangedActivDraw(const QString newName); -protected: - virtual void RefreshGeometry(); -}; - -#endif // VTOOLSIMPLEPOINT_H diff --git a/tools/vtoolsinglepoint.h b/tools/vtoolsinglepoint.h deleted file mode 100644 index 97255cc65..000000000 --- a/tools/vtoolsinglepoint.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef VTOOLSINGLEPOINT_H -#define VTOOLSINGLEPOINT_H - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" -#include "../container/vcontainer.h" -#include "../xml/vdomdocument.h" -#include "../dialogs/dialogsinglepoint.h" -#include "vtoolpoint.h" -#pragma GCC diagnostic pop - -class VToolSinglePoint : public VToolPoint -{ - Q_OBJECT -public: - VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, - Tool::Enum typeCreation, - QGraphicsItem * parent = 0 ); - virtual void setDialog(); -public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); - virtual void ChangedActivDraw(const QString newName); -signals: - void FullUpdateTree(); -protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); -private: - QSharedPointer dialogSinglePoint; -}; - -#endif // VTOOLSINGLEPOINT_H diff --git a/widgets/vgraphicssimpletextitem.cpp b/widgets/vgraphicssimpletextitem.cpp index 381e0f1ae..deefc02d0 100644 --- a/widgets/vgraphicssimpletextitem.cpp +++ b/widgets/vgraphicssimpletextitem.cpp @@ -1,17 +1,16 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include "vgraphicssimpletextitem.h" #include #include -#pragma GCC diagnostic pop VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent):QGraphicsSimpleTextItem(parent){ + this->setFlag(QGraphicsItem::ItemIsMovable, true); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + this->setAcceptHoverEvents(true); } -VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent ):QGraphicsSimpleTextItem(text, parent){ +VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent ) + :QGraphicsSimpleTextItem(text, parent){ this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); @@ -20,16 +19,7 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphic QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QVariant &value){ if (change == ItemPositionChange && scene()) { - // value - это новое положение. QPointF newPos = value.toPointF() + this->parentItem()->pos(); -// QRectF rect = scene()->sceneRect(); -// if (!rect.contains(newPos)) { -// // Сохраняем элемент внутри прямоугольника сцены. -// newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left()))); -// newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top()))); -// emit NameChangePosition(newPos - this->parentItem()->pos()); -// return newPos - this->parentItem()->pos(); -// } emit NameChangePosition(newPos); } return QGraphicsItem::itemChange(change, value); diff --git a/widgets/vgraphicssimpletextitem.h b/widgets/vgraphicssimpletextitem.h index 80f7a303f..ef8073d78 100644 --- a/widgets/vgraphicssimpletextitem.h +++ b/widgets/vgraphicssimpletextitem.h @@ -1,13 +1,7 @@ #ifndef VGRAPHICSSIMPLETEXTITEM_H #define VGRAPHICSSIMPLETEXTITEM_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include -#pragma GCC diagnostic pop class VGraphicsSimpleTextItem : public QObject, public QGraphicsSimpleTextItem { diff --git a/widgets/vmaingraphicsscene.cpp b/widgets/vmaingraphicsscene.cpp index ce5019d04..61144c26e 100644 --- a/widgets/vmaingraphicsscene.cpp +++ b/widgets/vmaingraphicsscene.cpp @@ -1,11 +1,8 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include "vmaingraphicsscene.h" #include #include #include #include -#pragma GCC diagnostic pop VMainGraphicsScene::VMainGraphicsScene():QGraphicsScene(){ } diff --git a/widgets/vmaingraphicsscene.h b/widgets/vmaingraphicsscene.h index 3e8532e24..f637f0d4e 100644 --- a/widgets/vmaingraphicsscene.h +++ b/widgets/vmaingraphicsscene.h @@ -1,14 +1,11 @@ #ifndef VMAINGRAPHICSSCENE_H #define VMAINGRAPHICSSCENE_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include #include #include -#pragma GCC diagnostic pop -#include "../options.h" +#include "options.h" class VMainGraphicsScene : public QGraphicsScene { diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index f4cef2937..0fdbb92db 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -1,22 +1,12 @@ #include "vdomdocument.h" #include -#include "../tools/vtoolsinglepoint.h" -#include "../tools/vtoolendline.h" -#include "../tools/vtoolline.h" -#include "../tools/vtoolalongline.h" -#include "../tools/vtoolshoulderpoint.h" -#include "../tools/vtoolnormal.h" -#include "../tools/vtoolbisector.h" -#include "../tools/vtoollineintersect.h" -#include "../tools/vtoolspline.h" -#include "../tools/vtoolarc.h" -#include "../tools/vtoolsplinepath.h" -#include "../tools/vtoolpointofcontact.h" -#include "../tools/vmodelingpoint.h" -#include "../tools/vtooldetail.h" -#include "../options.h" -#include "../container/calculator.h" -#include "../geometry/vsplinepoint.h" +#include "tools/drawTools/drawtools.h" +#include "tools/nodeDetails/nodedetails.h" +#include "tools/modelingTools/modelingtools.h" +#include "tools/vtooldetail.h" +#include "options.h" +#include "container/calculator.h" +#include "geometry/vsplinepoint.h" @@ -376,31 +366,54 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo if(!element.isNull()){ if(element.tagName() == "node"){ qint64 id = element.attribute("id","").toLongLong(); - Scene::Type tool; + Tools::Enum tool; Draw::Mode mode; + NodeDetail::Type nodeType = NodeDetail::Contour; QString t = element.attribute("type",""); - if(t == "Point"){ - tool = Scene::Point; + if(t == "NodePoint"){ + tool = Tools::NodePoint; VPointF point = data->GetModelingPoint(id); mode = point.getMode(); - oldDetail.append(VNodeDetail(point.getIdObject(), tool, mode)); - } else if(t == "Arc"){ - tool = Scene::Arc; + oldDetail.append(VNodeDetail(point.getIdObject(), tool, mode, NodeDetail::Contour)); + } else if(t == "NodeArc"){ + tool = Tools::NodeArc; VArc arc = data->GetModelingArc(id); mode = arc.getMode(); - oldDetail.append(VNodeDetail(arc.getIdObject(), tool, mode)); - } else if(t == "Spline"){ - tool = Scene::Spline; + oldDetail.append(VNodeDetail(arc.getIdObject(), tool, mode, NodeDetail::Contour)); + } else if(t == "NodeSpline"){ + tool = Tools::NodeSpline; VSpline spl = data->GetModelingSpline(id); mode = spl.getMode(); - oldDetail.append(VNodeDetail(spl.getIdObject(), tool, mode)); - } else if(t == "SplinePath"){ - tool = Scene::SplinePath; + oldDetail.append(VNodeDetail(spl.getIdObject(), tool, mode, NodeDetail::Contour)); + } else if(t == "NodeSplinePath"){ + tool = Tools::NodeSplinePath; VSplinePath splPath = data->GetModelingSplinePath(id); mode = splPath.getMode(); - oldDetail.append(VNodeDetail(splPath.getIdObject(), tool, mode)); + oldDetail.append(VNodeDetail(splPath.getIdObject(), tool, mode, NodeDetail::Contour)); + } else if(t == "AlongLineTool"){ + tool = Tools::AlongLineTool; + } else if(t == "ArcTool"){ + tool = Tools::ArcTool; + } else if(t == "BisectorTool"){ + tool = Tools::BisectorTool; + } else if(t == "EndLineTool"){ + tool = Tools::EndLineTool; + } else if(t == "LineIntersectTool"){ + tool = Tools::LineIntersectTool; + } else if(t == "LineTool"){ + tool = Tools::LineTool; + } else if(t == "NormalTool"){ + tool = Tools::NormalTool; + } else if(t == "PointOfContact"){ + tool = Tools::PointOfContact; + } else if(t == "ShoulderPointTool"){ + tool = Tools::ShoulderPointTool; + } else if(t == "SplinePathTool"){ + tool = Tools::SplinePathTool; + } else if(t == "SplineTool"){ + tool = Tools::SplineTool; } - detail.append(VNodeDetail(id, tool, mode)); + detail.append(VNodeDetail(id, tool, mode, nodeType)); } } } @@ -428,23 +441,20 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen Document::Enum parse, const QString& type, Draw::Mode mode){ if(type == "single"){ if(!domElement.isNull()){ - QString name; - qreal mx=5, my=10, x, y; - qint64 id; - - id = domElement.attribute("id", "").toLongLong(); - name = domElement.attribute("name", ""); - x = domElement.attribute("x","").toDouble()*PrintDPI/25.4; - y = domElement.attribute("y","").toDouble()*PrintDPI/25.4; - mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; - my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; + qint64 id = domElement.attribute("id", "").toLongLong(); + Q_ASSERT(id > 0); + QString name = domElement.attribute("name", ""); + qreal x = domElement.attribute("x","").toDouble()*PrintDPI/25.4; + qreal y = domElement.attribute("y","").toDouble()*PrintDPI/25.4; + qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; + qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; data->UpdatePoint(id, VPointF(x, y, name, mx, my)); - VAbstractTool::AddRecord(id, Tools::SinglePointTool, this); + VDrawTool::AddRecord(id, Tools::SinglePointTool, this); if(parse != Document::FullParse){ - VToolSinglePoint *spoint = qobject_cast(tools[id]); - spoint->VDataTool::setData(data); - tools[id] = spoint; + VDataTool *tool = tools.value(id); + Q_CHECK_PTR(tool); + tool->VDataTool::setData(data); } if(parse == Document::FullParse){ VToolSinglePoint *spoint = new VToolSinglePoint(this, data, id, Tool::FromFile); @@ -465,8 +475,13 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen QString formula = domElement.attribute("length", ""); qint64 basePointId = domElement.attribute("basePoint", "").toLongLong(); qint32 angle = domElement.attribute("angle", "").toInt(); - VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, scene, this, data, - parse, Tool::FromFile, mode); + if(mode == Draw::Calculation){ + VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, scene, this, + data, parse, Tool::FromFile); + } else { + VModelingEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, this, + data, parse, Tool::FromFile); + } } return; } @@ -480,8 +495,13 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen QString formula = domElement.attribute("length", ""); qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong(); qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong(); - VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my, - scene, this, data, parse, Tool::FromFile, mode); + if(mode == Draw::Calculation){ + VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my, + scene, this, data, parse, Tool::FromFile); + } else { + VModelingAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my, + this, data, parse, Tool::FromFile); + } } return; } @@ -496,8 +516,13 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 p1Line = domElement.attribute("p1Line", "").toLongLong(); qint64 p2Line = domElement.attribute("p2Line", "").toLongLong(); qint64 pShoulder = domElement.attribute("pShoulder", "").toLongLong(); - VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my, - scene, this, data, parse, Tool::FromFile, mode); + if(mode == Draw::Calculation){ + VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my, + scene, this, data, parse, Tool::FromFile); + } else { + VModelingShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, + my, this, data, parse, Tool::FromFile); + } } return; } @@ -512,8 +537,13 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong(); qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong(); qreal angle = domElement.attribute("angle", "").toDouble(); - VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle, - mx, my, scene, this, data, parse, Tool::FromFile, mode); + if(mode == Draw::Calculation){ + VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle, + mx, my, scene, this, data, parse, Tool::FromFile); + } else { + VModelingNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle, + mx, my, this, data, parse, Tool::FromFile); + } } return; } @@ -528,8 +558,13 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong(); qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong(); qint64 thirdPointId = domElement.attribute("thirdPoint", "").toLongLong(); - VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine, - name, mx, my, scene, this, data, parse, Tool::FromFile, mode); + if(mode == Draw::Calculation){ + VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine, + name, mx, my, scene, this, data, parse, Tool::FromFile); + } else { + VModelingBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine, + name, mx, my, this, data, parse, Tool::FromFile); + } } return; } @@ -543,8 +578,13 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 p2Line1Id = domElement.attribute("p2Line1", "").toLongLong(); qint64 p1Line2Id = domElement.attribute("p1Line2", "").toLongLong(); qint64 p2Line2Id = domElement.attribute("p2Line2", "").toLongLong(); - VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my, scene, - this, data, parse, Tool::FromFile, mode); + if(mode == Draw::Calculation){ + VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my, + scene, this, data, parse, Tool::FromFile); + } else { + VModelingLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my, + this, data, parse, Tool::FromFile); + } } return; } @@ -558,8 +598,13 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 center = domElement.attribute("center", "").toLongLong(); qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong(); qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong(); - VToolPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my, - scene, this, data, parse, Tool::FromFile, mode); + if(mode == Draw::Calculation){ + VToolPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my, + scene, this, data, parse, Tool::FromFile); + } else { + VModelingPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, + my, this, data, parse, Tool::FromFile); + } } return; } @@ -581,7 +626,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qreal my = toPixel(domElement.attribute("my","").toDouble()); data->UpdateModelingPoint(id, VPointF(point.x(), point.y(), point.name(), mx, my, typeObject, idObject )); - data->IncrementReferens(idObject, Scene::Point); + data->IncrementReferens(idObject, Scene::Point, typeObject); } return; } @@ -593,7 +638,11 @@ void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement qint64 id = domElement.attribute("id", "").toLongLong(); qint64 firstPoint = domElement.attribute("firstPoint", "").toLongLong(); qint64 secondPoint = domElement.attribute("secondPoint", "").toLongLong(); - VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile, mode); + if(mode == Draw::Calculation){ + VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile); + } else { + VModelingLine::Create(id, firstPoint, secondPoint, this, data, parse, Tool::FromFile); + } } } @@ -609,8 +658,13 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme qreal kAsm1 = domElement.attribute("kAsm1","").toDouble(); qreal kAsm2 = domElement.attribute("kAsm2","").toDouble(); qreal kCurve = domElement.attribute("kCurve","").toDouble(); - VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data, - parse, Tool::FromFile, mode); + if(mode == Draw::Calculation){ + VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, + data, parse, Tool::FromFile); + } else { + VModelingSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, this, + data, parse, Tool::FromFile); + } } return; } @@ -635,7 +689,11 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme } } } - VToolSplinePath::Create(id, path, scene, this, data, parse, Tool::FromFile, mode); + if(mode == Draw::Calculation){ + VToolSplinePath::Create(id, path, scene, this, data, parse, Tool::FromFile); + } else { + VModelingSplinePath::Create(id, path, this, data, parse, Tool::FromFile); + } } return; } @@ -656,8 +714,8 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme spl.setMode(typeObject); spl.setIdObject(idObject); data->UpdateModelingSpline(id, spl); - data->IncrementReferens(spl.GetP1(), Scene::Point); - data->IncrementReferens(spl.GetP4(), Scene::Point); + data->IncrementReferens(spl.GetP1(), Scene::Point, Draw::Modeling); + data->IncrementReferens(spl.GetP4(), Scene::Point, Draw::Modeling); } return; } @@ -680,7 +738,7 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme data->UpdateModelingSplinePath(id, path); const QVector *points = path.GetPoint(); for(qint32 i = 0; isize(); ++i){ - data->IncrementReferens(points->at(i).P(), Scene::Point); + data->IncrementReferens(points->at(i).P(), Scene::Point, Draw::Modeling); } } return; @@ -696,7 +754,11 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement QString radius = domElement.attribute("radius", ""); QString f1 = domElement.attribute("angle1", ""); QString f2 = domElement.attribute("angle2",""); - VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile, mode); + if(mode == Draw::Calculation){ + VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile); + } else { + VModelingArc::Create(id, center, radius, f1, f2, this, data, parse, Tool::FromFile); + } } return; } @@ -849,3 +911,16 @@ void VDomDocument::GarbageCollector(){ } } +void VDomDocument::AddTool(const qint64 &id, VDataTool *tool){ + tools.insert(id, tool); +} + +void VDomDocument::UpdateToolData(const qint64 &id, VContainer *data){ + VDataTool *tool = tools.value(id); + if(tool != 0){ + tool->VDataTool::setData(data); + } else { + qWarning()<<"Can't find tool with id ="<< id<<"."; + } +} + diff --git a/xml/vdomdocument.h b/xml/vdomdocument.h index d67cd0649..df8caeb10 100644 --- a/xml/vdomdocument.h +++ b/xml/vdomdocument.h @@ -1,19 +1,13 @@ #ifndef VDOMDOCUMENT_H #define VDOMDOCUMENT_H -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" #include #include #include #include -#include "../container/vcontainer.h" -#include "../widgets/vmaingraphicsscene.h" -#include "../tools/vdatatool.h" -#pragma GCC diagnostic pop +#include "container/vcontainer.h" +#include "widgets/vmaingraphicsscene.h" +#include "tools/vdatatool.h" #include "vtoolrecord.h" namespace Document{ @@ -53,6 +47,8 @@ public: void setCursor(const qint64 &value); void setCurrentData(); void GarbageCollector(); + void AddTool(const qint64 &id, VDataTool *tool); + void UpdateToolData(const qint64 &id, VContainer *data); signals: void ChangedActivDraw(const QString newName); void ChangedNameDraw(const QString oldName, const QString newName); @@ -92,7 +88,7 @@ private: void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement, Document::Enum parse, Draw::Mode mode); void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement, - Document::Enum parse, const QString& type, Draw::Mode mode); + Document::Enum parse, const QString& type, Draw::Mode mode); void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement, Document::Enum parse, const QString& type, Draw::Mode mode); void ParseIncrementsElement(const QDomNode& node);