From 16fa925021a4d20b1017f65e6749012521ddc27f Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 13 Aug 2014 14:31:01 +0300 Subject: [PATCH] Visualization for VToolPointOfIntersection. --HG-- branch : develop --- .../tools/dialogpointofintersection.cpp | 29 ++++++++++++++++++- .../dialogs/tools/dialogpointofintersection.h | 4 +++ src/app/mainwindow.cpp | 8 +++-- .../drawTools/vtoolpointofintersection.cpp | 26 ++++++++++++----- .../drawTools/vtoolpointofintersection.h | 11 +++---- .../tools/drawTools/vtoolshoulderpoint.cpp | 2 ++ .../vistoolpointofintersection.cpp | 5 ++-- 7 files changed, 66 insertions(+), 19 deletions(-) diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index a15e56de2..a8d6cb4d0 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -31,6 +31,8 @@ #include "../../geometry/vpointf.h" #include "../../container/vcontainer.h" +#include "../../visualization/vistoolpointofintersection.h" +#include "../../widgets/vmaingraphicsscene.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -40,7 +42,7 @@ */ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersection), number(0), pointName(QString()), - firstPointId(0), secondPointId(0) + firstPointId(0), secondPointId(0), line(nullptr) { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; @@ -57,11 +59,14 @@ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, con this, &DialogPointOfIntersection::PointNameChanged); connect(ui->comboBoxSecondPoint, static_cast(&QComboBox::currentIndexChanged), this, &DialogPointOfIntersection::PointNameChanged); + + line = new VisToolPointOfIntersection(data); } //--------------------------------------------------------------------------------------------------------------------- DialogPointOfIntersection::~DialogPointOfIntersection() { + delete line; delete ui; } @@ -73,6 +78,7 @@ DialogPointOfIntersection::~DialogPointOfIntersection() void DialogPointOfIntersection::setSecondPointId(const quint32 &value) { setPointId(ui->comboBoxSecondPoint, secondPointId, value); + line->setPoint2Id(secondPointId); } //--------------------------------------------------------------------------------------------------------------------- @@ -93,6 +99,7 @@ void DialogPointOfIntersection::ChosenObject(quint32 id, const SceneObject &type { // -1 for not found ui->comboBoxFirstPoint->setCurrentIndex(index); number++; + line->VisualMode(id); emit ToolTip(tr("Select point horizontally")); return; } @@ -104,6 +111,9 @@ void DialogPointOfIntersection::ChosenObject(quint32 id, const SceneObject &type { // -1 for not found ui->comboBoxSecondPoint->setCurrentIndex(index); number = 0; + line->setPoint2Id(id); + line->RefreshGeometry(); + prepare = true; emit ToolTip(""); } if (isInitialized == false) @@ -121,6 +131,10 @@ void DialogPointOfIntersection::SaveData() pointName = ui->lineEditNamePoint->text(); firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); + + line->setPoint1Id(firstPointId); + line->setPoint2Id(secondPointId); + line->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -151,6 +165,18 @@ void DialogPointOfIntersection::UpdateList() */ } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointOfIntersection::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor); + scene->addItem(line); + line->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setFirstPointId set id of first point @@ -159,6 +185,7 @@ void DialogPointOfIntersection::UpdateList() void DialogPointOfIntersection::setFirstPointId(const quint32 &value) { setPointId(ui->comboBoxFirstPoint, firstPointId, value); + line->setPoint1Id(firstPointId); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogpointofintersection.h b/src/app/dialogs/tools/dialogpointofintersection.h index 6878f0c52..ef1074baf 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.h +++ b/src/app/dialogs/tools/dialogpointofintersection.h @@ -36,6 +36,8 @@ namespace Ui class DialogPointOfIntersection; } +class VisToolPointOfIntersection; + /** * @brief The DialogPointOfIntersection class dialog for ToolPointOfIntersection. Help create point and edit option. */ @@ -59,6 +61,7 @@ public slots: virtual void PointNameChanged(); virtual void UpdateList(); protected: + virtual void ShowVisualization(); /** * @brief SaveData Put dialog data in local variables */ @@ -80,6 +83,7 @@ private: /** @brief secondPointId id second point of line */ quint32 secondPointId; + VisToolPointOfIntersection *line; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 03a47ad54..e671b8050 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -591,9 +591,11 @@ void MainWindow::ToolTriangle(bool checked) */ void MainWindow::ToolPointOfIntersection(bool checked) { - SetToolButton(checked, Tool::PointOfIntersection, - ":/cursor/pointofintersect_cursor.png", tr("Select point vertically"), - &MainWindow::ClosedDialog); + SetToolButtonWithApply(checked, Tool::PointOfIntersection, + ":/cursor/pointofintersect_cursor.png", + tr("Select point vertically"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolpointofintersection.cpp b/src/app/tools/drawTools/vtoolpointofintersection.cpp index affb53783..3ff069da6 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersection.cpp @@ -81,9 +81,10 @@ void VToolPointOfIntersection::setDialog() * @param scene pointer to scene. * @param doc dom document container. * @param data container with variables. + * @return the created tool */ -void VToolPointOfIntersection::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, - VContainer *data) +VToolPointOfIntersection *VToolPointOfIntersection::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data) { SCASSERT(dialog != nullptr); DialogPointOfIntersection *dialogTool = qobject_cast(dialog); @@ -91,7 +92,14 @@ void VToolPointOfIntersection::Create(DialogTool *dialog, VMainGraphicsScene *sc const quint32 firstPointId = dialogTool->getFirstPointId(); const quint32 secondPointId = dialogTool->getSecondPointId(); const QString pointName = dialogTool->getPointName(); - Create(0, pointName, firstPointId, secondPointId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + VToolPointOfIntersection *point = nullptr; + point = Create(0, pointName, firstPointId, secondPointId, 5, 10, scene, doc, data, Document::FullParse, + Source::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- @@ -108,11 +116,13 @@ void VToolPointOfIntersection::Create(DialogTool *dialog, VMainGraphicsScene *sc * @param data container with variables. * @param parse parser file mode. * @param typeCreation way we create this tool. + * @return the created tool */ -void VToolPointOfIntersection::Create(const quint32 _id, const QString &pointName, const quint32 &firstPointId, - const quint32 &secondPointId, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolPointOfIntersection *VToolPointOfIntersection::Create(const quint32 _id, const QString &pointName, + const quint32 &firstPointId, const quint32 &secondPointId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation) { const VPointF *firstPoint = data->GeometricObject(firstPointId); const VPointF *secondPoint = data->GeometricObject(secondPointId); @@ -143,7 +153,9 @@ void VToolPointOfIntersection::Create(const quint32 _id, const QString &pointNam doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolpointofintersection.h b/src/app/tools/drawTools/vtoolpointofintersection.h index 74e83a32b..ef8518dce 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.h +++ b/src/app/tools/drawTools/vtoolpointofintersection.h @@ -42,11 +42,12 @@ public: const quint32 &secondPointId, const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog(); - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); - static void Create(const quint32 _id, const QString &pointName, const quint32 &firstPointId, - const quint32 &secondPointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolPointOfIntersection *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data); + static VToolPointOfIntersection *Create(const quint32 _id, const QString &pointName, const quint32 &firstPointId, + const quint32 &secondPointId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation); static const QString ToolType; public slots: virtual void FullUpdateFromFile(); diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index c2121a374..bec148cee 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -125,6 +125,7 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li * @param scene pointer to scene. * @param doc dom document container. * @param data container with variables. + * @return the created tool */ VToolShoulderPoint* VToolShoulderPoint::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) @@ -165,6 +166,7 @@ VToolShoulderPoint* VToolShoulderPoint::Create(DialogTool *dialog, VMainGraphics * @param data container with variables. * @param parse parser file mode. * @param typeCreation way we create this tool. + * @return the created tool */ VToolShoulderPoint* VToolShoulderPoint::Create(const quint32 _id, QString &formula, const quint32 &p1Line, const quint32 &p2Line, const quint32 &pShoulder, const QString &typeLine, diff --git a/src/app/visualization/vistoolpointofintersection.cpp b/src/app/visualization/vistoolpointofintersection.cpp index 3dde9a150..ea0684e70 100644 --- a/src/app/visualization/vistoolpointofintersection.cpp +++ b/src/app/visualization/vistoolpointofintersection.cpp @@ -59,7 +59,6 @@ void VisToolPointOfIntersection::RefreshGeometry() QLineF axisL2; if (point2Id <= 0) { - DrawPoint(axisP2, scenePos, supportColor); axisL2 = Axis(scenePos, 180); } else @@ -67,9 +66,9 @@ void VisToolPointOfIntersection::RefreshGeometry() const VPointF *second = data->GeometricObject(point2Id); DrawPoint(axisP2, second->toQPointF(), supportColor); axisL2 = Axis(second->toQPointF(), 180); + ShowIntersection(axisL1, axisL2); } DrawLine(axis2, axisL2, supportColor, Qt::DashLine); - ShowIntersection(axisL1, axisL2); } } @@ -99,6 +98,6 @@ void VisToolPointOfIntersection::ShowIntersection(const QLineF &axis1, const QLi } else { - point->setVisible(true); + point->setVisible(false); } }