Refactoring.

--HG--
branch : develop
This commit is contained in:
dismine 2014-06-26 13:26:13 +03:00
parent f8882f48f1
commit 88b8a00a2e
10 changed files with 243 additions and 309 deletions

View File

@ -0,0 +1,107 @@
/************************************************************************
**
** @file vtoolcut.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 25 6, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vtoolcut.h"
#include "../../geometry/vpointf.h"
//---------------------------------------------------------------------------------------------------------------------
VToolCut::VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
const quint32 &curveCutId, const quint32 &curve1id, const quint32 &curve2id,
QGraphicsItem *parent)
:VToolPoint(doc, data, id, parent), formula(formula), firstCurve(nullptr), secondCurve(nullptr),
curveCutId(curveCutId), curve1id(curve1id), curve2id(curve2id)
{
Q_ASSERT_X(curveCutId > 0, Q_FUNC_INFO, "curveCutId <= 0");
Q_ASSERT_X(curve1id > 0, Q_FUNC_INFO, "curve1id <= 0");
Q_ASSERT_X(curve2id > 0, Q_FUNC_INFO, "curve2id <= 0");
firstCurve = new VSimpleCurve(curve1id, &currentColor, &factor);
firstCurve->setParentItem(this);
connect(firstCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed);
secondCurve = new VSimpleCurve(curve2id, &currentColor, &factor);
secondCurve->setParentItem(this);
connect(secondCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChangedActivDraw disable or enable context menu after change active pattern peace.
* @param newName new name active pattern peace.
*/
void VToolCut::ChangedActivDraw(const QString &newName)
{
bool flag = true;
if (nameActivDraw == newName)
{
currentColor = Qt::black;
flag = true;
}
else
{
currentColor = Qt::gray;
flag = false;
}
firstCurve->ChangedActivDraw(flag);
secondCurve->ChangedActivDraw(flag);
VToolPoint::ChangedActivDraw(newName);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshGeometry refresh item on scene.
*/
void VToolCut::RefreshGeometry()
{
RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint);
RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint);
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<const VPointF *>(id));
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RemoveReferens decrement referens value for used objects.
*/
void VToolCut::RemoveReferens()
{
doc->DecrementReferens(curveCutId);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCut::FullUpdateCurveFromFile(const QString &attrCurve)
{
Q_ASSERT_X(attrCurve.isEmpty() == false, Q_FUNC_INFO, "attribute name is empty");
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
formula = domElement.attribute(AttrLength, "");
curveCutId = domElement.attribute(attrCurve, "").toUInt();
}
RefreshGeometry();
}

View File

@ -0,0 +1,66 @@
/************************************************************************
**
** @file vtoolcut.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 25 6, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VTOOLCUT_H
#define VTOOLCUT_H
#include "vtoolpoint.h"
#include "../../widgets/vsimplecurve.h"
class VToolCut : public VToolPoint
{
Q_OBJECT
public:
VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula, const quint32 &curveCutId,
const quint32 &curve1id, const quint32 &curve2id, QGraphicsItem * parent = nullptr);
public slots:
virtual void ChangedActivDraw(const QString &newName);
virtual void CurveChoosed(quint32 id)=0;
protected:
/** @brief formula keep formula of length */
QString formula;
/** @brief firstCurve first curve after cutting. */
VSimpleCurve *firstCurve;
/** @brief secondCurve second curve after cutting. */
VSimpleCurve *secondCurve;
quint32 curveCutId;
quint32 curve1id;
quint32 curve2id;
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr)=0;
void RefreshGeometry();
virtual void RemoveReferens();
void FullUpdateCurveFromFile(const QString &attrCurve);
private:
Q_DISABLE_COPY(VToolCut)
};
#endif // VTOOLCUT_H

View File

@ -33,7 +33,7 @@
#include "../../geometry/varc.h"
const QString VToolCutArc::ToolType = QStringLiteral("cutArc");
const QString VToolCutArc::AttrArc = QStringLiteral("arc");
const QString VToolCutArc::AttrArc = QStringLiteral("arc");
//---------------------------------------------------------------------------------------------------------------------
/**
@ -51,22 +51,10 @@ const QString VToolCutArc::AttrArc = QStringLiteral("arc");
VToolCutArc::VToolCutArc(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
const quint32 &arcId, const quint32 &arc1id, const quint32 &arc2id,
const Source &typeCreation, QGraphicsItem * parent)
:VToolPoint(doc, data, id, parent), formula(formula), arcId(arcId), firstArc(), secondArc(), arc1id(arc1id),
arc2id(arc2id)
:VToolCut(doc, data, id, formula, arcId, arc1id, arc2id, parent)
{
Q_ASSERT_X(arcId > 0, Q_FUNC_INFO, "arcId <= 0");
Q_ASSERT_X(arc1id > 0, Q_FUNC_INFO, "arc1id <= 0");
Q_ASSERT_X(arc2id > 0, Q_FUNC_INFO, "arc2id <= 0");
firstArc = new VSimpleCurve(arc1id, &currentColor, &factor);
RefreshArc(firstArc, arc1id, SimpleCurvePoint::ForthPoint);
firstArc->setParentItem(this);
connect(firstArc, &VSimpleCurve::Choosed, this, &VToolCutArc::ArcChoosed);
secondArc = new VSimpleCurve(arc2id, &currentColor, &factor);
RefreshArc(secondArc, arc2id, SimpleCurvePoint::FirstPoint);
secondArc->setParentItem(this);
connect(secondArc, &VSimpleCurve::Choosed, this, &VToolCutArc::ArcChoosed);
RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint);
RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint);
if (typeCreation == Source::FromGui)
{
@ -89,7 +77,7 @@ void VToolCutArc::setDialog()
SCASSERT(dialogTool != nullptr);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogTool->setFormula(formula);
dialogTool->setArcId(arcId, id);
dialogTool->setArcId(curveCutId, id);
dialogTool->setPointName(point->name());
}
@ -204,48 +192,19 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS
*/
void VToolCutArc::FullUpdateFromFile()
{
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
formula = domElement.attribute(AttrLength, "");
arcId = domElement.attribute(AttrArc, "").toUInt();
}
RefreshGeometry();
FullUpdateCurveFromFile(AttrArc);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ArcChoosed send signal about selection from cutted arc.
* @brief CurveChoosed send signal about selection from cutted arc.
* @param id object id in container.
*/
void VToolCutArc::ArcChoosed(quint32 id)
void VToolCutArc::CurveChoosed(quint32 id)
{
emit ChoosedTool(id, SceneObject::Arc);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChangedActivDraw disable or enable context menu after change active pattern peace.
* @param newName new name active pattern peace.
*/
void VToolCutArc::ChangedActivDraw(const QString &newName)
{
bool flag = true;
if (nameActivDraw == newName)
{
currentColor = Qt::black;
flag = true;
}
else
{
currentColor = Qt::gray;
flag = false;
}
firstArc->ChangedActivDraw(flag);
secondArc->ChangedActivDraw(flag);
VToolPoint::ChangedActivDraw(newName);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ShowContextMenu show context menu.
@ -282,7 +241,7 @@ void VToolCutArc::AddToFile()
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my()));
doc->SetAttribute(domElement, AttrLength, formula);
doc->SetAttribute(domElement, AttrArc, arcId);
doc->SetAttribute(domElement, AttrArc, curveCutId);
AddToCalculation(domElement);
}
@ -301,21 +260,10 @@ void VToolCutArc::RefreshDataInFile()
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx()));
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my()));
doc->SetAttribute(domElement, AttrLength, formula);
doc->SetAttribute(domElement, AttrArc, arcId);
doc->SetAttribute(domElement, AttrArc, curveCutId);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshGeometry refresh item on scene.
*/
void VToolCutArc::RefreshGeometry()
{
RefreshArc(firstArc, arc1id, SimpleCurvePoint::ForthPoint);
RefreshArc(secondArc, arc2id, SimpleCurvePoint::FirstPoint);
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<const VPointF *>(id));
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SaveDialog save options into file after change in dialog.
@ -332,14 +280,14 @@ void VToolCutArc::SaveDialog(QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshArc refresh arc on scene.
* @param sArc arc.
* @param arcid arc id.
* @param tr arc type.
* @brief RefreshCurve refresh curve on scene.
* @param curve curve.
* @param curveId curve id.
* @param tr point type.
*/
void VToolCutArc::RefreshArc(VSimpleCurve *sArc, quint32 arcid, SimpleCurvePoint tr)
void VToolCutArc::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr)
{
const VArc *arc = VAbstractTool::data.GeometricObject<const VArc *>(arcid);
const VArc *arc = VAbstractTool::data.GeometricObject<const VArc *>(curveId);
QPainterPath path;
path.addPath(arc->GetPath());
path.setFillRule( Qt::WindingFill );
@ -351,5 +299,5 @@ void VToolCutArc::RefreshArc(VSimpleCurve *sArc, quint32 arcid, SimpleCurvePoint
{
path.translate(-arc->GetP2().x(), -arc->GetP2().y());
}
sArc->setPath(path);
curve->setPath(path);
}

View File

@ -29,13 +29,12 @@
#ifndef VTOOLCUTARC_H
#define VTOOLCUTARC_H
#include "vtoolpoint.h"
#include "../../widgets/vsimplecurve.h"
#include "vtoolcut.h"
/**
* @brief The VToolCutArc class tool for cutting arc.
*/
class VToolCutArc : public VToolPoint
class VToolCutArc : public VToolCut
{
Q_OBJECT
public:
@ -51,36 +50,16 @@ public:
static const QString AttrArc;
public slots:
virtual void FullUpdateFromFile();
void ArcChoosed(quint32 id);
virtual void ChangedActivDraw(const QString &newName);
virtual void CurveChoosed(quint32 id);
virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
virtual void RefreshDataInFile();
void RefreshGeometry();
virtual void SaveDialog(QDomElement &domElement);
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr);
private:
Q_DISABLE_COPY(VToolCutArc)
/** @brief formula keep formula of length */
QString formula;
/** @brief arcId keep id of arc */
quint32 arcId;
/** @brief firstArc first arc after cutting. */
VSimpleCurve *firstArc;
/** @brief secondArc second arc after cutting. */
VSimpleCurve *secondArc;
/** @brief arc1id id first arc after cutting. */
const quint32 arc1id;
/** @brief arc2id id second arc after cutting. */
const quint32 arc2id;
void RefreshArc(VSimpleCurve *sArc, quint32 arcid, SimpleCurvePoint tr);
};
#endif // VTOOLCUTARC_H

View File

@ -33,7 +33,7 @@
#include <geometry/vspline.h>
const QString VToolCutSpline::ToolType = QStringLiteral("cutSpline");
const QString VToolCutSpline::ToolType = QStringLiteral("cutSpline");
const QString VToolCutSpline::AttrSpline = QStringLiteral("spline");
//---------------------------------------------------------------------------------------------------------------------
@ -50,22 +50,10 @@ const QString VToolCutSpline::AttrSpline = QStringLiteral("spline");
VToolCutSpline::VToolCutSpline(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
const quint32 &splineId, const quint32 &spl1id, const quint32 &spl2id,
const Source &typeCreation, QGraphicsItem *parent)
:VToolPoint(doc, data, id, parent), formula(formula), splineId(splineId), firstSpline(), secondSpline(),
spl1id(spl1id), spl2id(spl2id)
:VToolCut(doc, data, id, formula, splineId, spl1id, spl2id, parent)
{
Q_ASSERT_X(splineId > 0, Q_FUNC_INFO, "splineId <= 0");
Q_ASSERT_X(spl1id > 0, Q_FUNC_INFO, "spl1id <= 0");
Q_ASSERT_X(spl2id > 0, Q_FUNC_INFO, "spl2id <= 0");
firstSpline = new VSimpleCurve(spl1id, &currentColor, &factor);
RefreshSpline(firstSpline, spl1id, SimpleCurvePoint::ForthPoint);
firstSpline->setParentItem(this);
connect(firstSpline, &VSimpleCurve::Choosed, this, &VToolCutSpline::SplineChoosed);
secondSpline = new VSimpleCurve(spl2id, &currentColor, &factor);
RefreshSpline(secondSpline, spl2id, SimpleCurvePoint::FirstPoint);
secondSpline->setParentItem(this);
connect(secondSpline, &VSimpleCurve::Choosed, this, &VToolCutSpline::SplineChoosed);
RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint);
RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint);
if (typeCreation == Source::FromGui)
{
@ -88,7 +76,7 @@ void VToolCutSpline::setDialog()
SCASSERT(dialogTool != nullptr);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogTool->setFormula(formula);
dialogTool->setSplineId(splineId, id);
dialogTool->setSplineId(curveCutId, id);
dialogTool->setPointName(point->name());
}
@ -196,48 +184,19 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString
*/
void VToolCutSpline::FullUpdateFromFile()
{
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
formula = domElement.attribute(AttrLength, "");
splineId = domElement.attribute(AttrSpline, "").toUInt();
}
RefreshGeometry();
FullUpdateCurveFromFile(AttrSpline);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SplineChoosed send signal about selection from spline.
* @brief CurveChoosed send signal about selection from spline.
* @param id object id in container.
*/
void VToolCutSpline::SplineChoosed(quint32 id)
void VToolCutSpline::CurveChoosed(quint32 id)
{
emit ChoosedTool(id, SceneObject::Spline);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChangedActivDraw disable or enable context menu after change active pattern peace.
* @param newName new name active pattern peace.
*/
void VToolCutSpline::ChangedActivDraw(const QString &newName)
{
bool flag = true;
if (nameActivDraw == newName)
{
currentColor = Qt::black;
flag = true;
}
else
{
currentColor = Qt::gray;
flag = false;
}
firstSpline->ChangedActivDraw(flag);
secondSpline->ChangedActivDraw(flag);
VToolPoint::ChangedActivDraw(newName);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ShowContextMenu show context menu.
@ -274,7 +233,7 @@ void VToolCutSpline::AddToFile()
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my()));
doc->SetAttribute(domElement, AttrLength, formula);
doc->SetAttribute(domElement, AttrSpline, splineId);
doc->SetAttribute(domElement, AttrSpline, curveCutId);
AddToCalculation(domElement);
}
@ -293,30 +252,10 @@ void VToolCutSpline::RefreshDataInFile()
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx()));
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my()));
doc->SetAttribute(domElement, AttrLength, formula);
doc->SetAttribute(domElement, AttrSpline, splineId);
doc->SetAttribute(domElement, AttrSpline, curveCutId);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshGeometry refresh item on scene.
*/
void VToolCutSpline::RefreshGeometry()
{
RefreshSpline(firstSpline, spl1id, SimpleCurvePoint::ForthPoint);
RefreshSpline(secondSpline, spl2id, SimpleCurvePoint::FirstPoint);
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<const VPointF *>(id));
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RemoveReferens decrement referens value for used objects.
*/
void VToolCutSpline::RemoveReferens()
{
doc->DecrementReferens(splineId);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SaveDialog save options into file after change in dialog.
@ -333,14 +272,14 @@ void VToolCutSpline::SaveDialog(QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshSpline refresh spline on scene.
* @param spline spline.
* @param splid spline id.
* @param tr spline type.
* @brief RefreshCurve refresh curve on scene.
* @param curve curve.
* @param curveId curve id.
* @param tr point type.
*/
void VToolCutSpline::RefreshSpline(VSimpleCurve *spline, quint32 splid, SimpleCurvePoint tr)
void VToolCutSpline::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr)
{
const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(splid);
const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(curveId);
QPainterPath path;
path.addPath(spl->GetPath());
path.setFillRule( Qt::WindingFill );
@ -352,5 +291,5 @@ void VToolCutSpline::RefreshSpline(VSimpleCurve *spline, quint32 splid, SimpleCu
{
path.translate(-spl->GetP4().toQPointF().x(), -spl->GetP4().toQPointF().y());
}
spline->setPath(path);
curve->setPath(path);
}

View File

@ -29,13 +29,12 @@
#ifndef VTOOLCUTSPLINE_H
#define VTOOLCUTSPLINE_H
#include "vtoolpoint.h"
#include "../../widgets/vsimplecurve.h"
#include "vtoolcut.h"
/**
* @brief The VToolCutSpline class for tool CutSpline. This tool find point on spline and cut spline on two.
*/
class VToolCutSpline : public VToolPoint
class VToolCutSpline : public VToolCut
{
Q_OBJECT
public:
@ -52,38 +51,16 @@ public:
static const QString AttrSpline;
public slots:
virtual void FullUpdateFromFile();
void SplineChoosed(quint32 id);
virtual void ChangedActivDraw(const QString &newName);
virtual void CurveChoosed(quint32 id);
virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
virtual void RefreshDataInFile();
void RefreshGeometry();
virtual void RemoveReferens();
virtual void SaveDialog(QDomElement &domElement);
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr);
private:
Q_DISABLE_COPY(VToolCutSpline)
/** @brief formula keep formula of length. */
QString formula;
/** @brief splineId keep id of spline. */
quint32 splineId;
/** @brief firstSpline first spline after cutting. */
VSimpleCurve *firstSpline;
/** @brief secondSpline second spline after cutting. */
VSimpleCurve *secondSpline;
/** @brief spl1id id first spline after cutting. */
const quint32 spl1id;
/** @brief spl2id id second spline after cutting. */
const quint32 spl2id;
void RefreshSpline(VSimpleCurve *spline, quint32 splid, SimpleCurvePoint tr);
};
#endif // VTOOLCUTSPLINE_H

View File

@ -33,7 +33,7 @@
#include "../../geometry/vsplinepath.h"
const QString VToolCutSplinePath::ToolType = QStringLiteral("cutSplinePath");
const QString VToolCutSplinePath::ToolType = QStringLiteral("cutSplinePath");
const QString VToolCutSplinePath::AttrSplinePath = QStringLiteral("splinePath");
//---------------------------------------------------------------------------------------------------------------------
@ -53,22 +53,10 @@ VToolCutSplinePath::VToolCutSplinePath(VPattern *doc, VContainer *data, const qu
const QString &formula, const quint32 &splinePathId,
const quint32 &splPath1id, const quint32 &splPath2id,
const Source &typeCreation, QGraphicsItem *parent)
:VToolPoint(doc, data, id, parent), formula(formula), splinePathId(splinePathId), firstSpline(), secondSpline(),
splPath1id (splPath1id), splPath2id(splPath2id)
:VToolCut(doc, data, id, formula, splinePathId, splPath1id, splPath2id, parent)
{
Q_ASSERT_X(splinePathId > 0, Q_FUNC_INFO, "splinePathId <= 0");
Q_ASSERT_X(splPath1id > 0, Q_FUNC_INFO, "spl1id <= 0");
Q_ASSERT_X(splPath2id > 0, Q_FUNC_INFO, "spl2id <= 0");
firstSpline = new VSimpleCurve(splPath1id, &currentColor, &factor);
RefreshSpline(firstSpline, splPath1id, SimpleCurvePoint::ForthPoint);
firstSpline->setParentItem(this);
connect(firstSpline, &VSimpleCurve::Choosed, this, &VToolCutSplinePath::SplineChoosed);
secondSpline = new VSimpleCurve(splPath2id, &currentColor, &factor);
RefreshSpline(secondSpline, splPath2id, SimpleCurvePoint::FirstPoint);
secondSpline->setParentItem(this);
connect(secondSpline, &VSimpleCurve::Choosed, this, &VToolCutSplinePath::SplineChoosed);
RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint);
RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint);
if (typeCreation == Source::FromGui)
{
@ -91,7 +79,7 @@ void VToolCutSplinePath::setDialog()
SCASSERT(dialogTool != nullptr);
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
dialogTool->setFormula(formula);
dialogTool->setSplinePathId(splinePathId, id);
dialogTool->setSplinePathId(curveCutId, id);
dialogTool->setPointName(point->name());
}
@ -251,48 +239,19 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QSt
*/
void VToolCutSplinePath::FullUpdateFromFile()
{
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
formula = domElement.attribute(AttrLength, "");
splinePathId = domElement.attribute(AttrSplinePath, "").toUInt();
}
RefreshGeometry();
FullUpdateCurveFromFile(AttrSplinePath);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SplineChoosed send signal about selection splinePath.
* @brief CurveChoosed send signal about selection splinePath.
* @param id object id in container.
*/
void VToolCutSplinePath::SplineChoosed(quint32 id)
void VToolCutSplinePath::CurveChoosed(quint32 id)
{
emit ChoosedTool(id, SceneObject::SplinePath);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChangedActivDraw disable or enable context menu after change active pattern peace.
* @param newName new name active pattern peace.
*/
void VToolCutSplinePath::ChangedActivDraw(const QString &newName)
{
bool flag = true;
if (nameActivDraw == newName)
{
currentColor = Qt::black;
flag = true;
}
else
{
currentColor = Qt::gray;
flag = false;
}
firstSpline->ChangedActivDraw(flag);
secondSpline->ChangedActivDraw(flag);
VToolPoint::ChangedActivDraw(newName);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ShowContextMenu show context menu.
@ -329,7 +288,7 @@ void VToolCutSplinePath::AddToFile()
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my()));
doc->SetAttribute(domElement, AttrLength, formula);
doc->SetAttribute(domElement, AttrSplinePath, splinePathId);
doc->SetAttribute(domElement, AttrSplinePath, curveCutId);
AddToCalculation(domElement);
}
@ -348,30 +307,10 @@ void VToolCutSplinePath::RefreshDataInFile()
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx()));
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my()));
doc->SetAttribute(domElement, AttrLength, formula);
doc->SetAttribute(domElement, AttrSplinePath, splinePathId);
doc->SetAttribute(domElement, AttrSplinePath, curveCutId);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshGeometry refresh item on scene.
*/
void VToolCutSplinePath::RefreshGeometry()
{
RefreshSpline(firstSpline, splPath1id, SimpleCurvePoint::ForthPoint);
RefreshSpline(secondSpline, splPath2id, SimpleCurvePoint::FirstPoint);
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<const VPointF *>(id));
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RemoveReferens decrement referens value for used objects.
*/
void VToolCutSplinePath::RemoveReferens()
{
doc->DecrementReferens(splinePathId);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SaveDialog save options into file after change in dialog.
@ -388,14 +327,14 @@ void VToolCutSplinePath::SaveDialog(QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshSpline refresh splinePath on scene.
* @param spline splinePath.
* @param splPathid splinePath id.
* @param tr splineType type.
* @brief RefreshCurve refresh curve on scene.
* @param curve curve.
* @param curveId curve id.
* @param tr point type.
*/
void VToolCutSplinePath::RefreshSpline(VSimpleCurve *spline, quint32 splPathid, SimpleCurvePoint tr)
void VToolCutSplinePath::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr)
{
const VSplinePath *splPath = VAbstractTool::data.GeometricObject<const VSplinePath *>(splPathid);
const VSplinePath *splPath = VAbstractTool::data.GeometricObject<const VSplinePath *>(curveId);
QPainterPath path;
path.addPath(splPath->GetPath());
path.setFillRule( Qt::WindingFill );
@ -409,5 +348,5 @@ void VToolCutSplinePath::RefreshSpline(VSimpleCurve *spline, quint32 splPathid,
VSpline spl = splPath->GetSpline(splPath->Count());
path.translate(-spl.GetP4().toQPointF().x(), -spl.GetP4().toQPointF().y());
}
spline->setPath(path);
curve->setPath(path);
}

View File

@ -29,14 +29,13 @@
#ifndef VTOOLCUTSPLINEPATH_H
#define VTOOLCUTSPLINEPATH_H
#include "vtoolpoint.h"
#include "../../widgets/vsimplecurve.h"
#include "vtoolcut.h"
/**
* @brief The VToolCutSplinePath class for tool CutSplinePath. This tool find point on splinePath and cut splinePath on
* two.
*/
class VToolCutSplinePath : public VToolPoint
class VToolCutSplinePath : public VToolCut
{
Q_OBJECT
public:
@ -53,38 +52,16 @@ public:
static const QString AttrSplinePath;
public slots:
virtual void FullUpdateFromFile();
void SplineChoosed(quint32 id);
virtual void ChangedActivDraw(const QString &newName);
virtual void CurveChoosed(quint32 id);
virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
virtual void RefreshDataInFile();
void RefreshGeometry();
virtual void RemoveReferens();
virtual void SaveDialog(QDomElement &domElement);
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr);
private:
Q_DISABLE_COPY(VToolCutSplinePath)
/** @brief formula keep formula of length */
QString formula;
/** @brief splineId keep id of spline. */
quint32 splinePathId;
/** @brief firstSpline first splinePath after cutting. */
VSimpleCurve *firstSpline;
/** @brief secondSpline second splinePath after cutting. */
VSimpleCurve *secondSpline;
/** @brief splPath1id id first splinePath after cutting. */
const quint32 splPath1id;
/** @brief splPath2id id second splinePath after cutting. */
const quint32 splPath2id;
void RefreshSpline(VSimpleCurve *spline, quint32 splPathid, SimpleCurvePoint tr);
};
#endif // VTOOLCUTSPLINEPATH_H

View File

@ -32,7 +32,8 @@ HEADERS += \
tools/drawTools/vtoolcutsplinepath.h \
tools/vtooluniondetails.h \
tools/drawTools/vtoolcutarc.h \
tools/drawTools/vabstractspline.h
tools/drawTools/vabstractspline.h \
tools/drawTools/vtoolcut.h
SOURCES += \
tools/vtooldetail.cpp \
@ -65,4 +66,5 @@ SOURCES += \
tools/drawTools/vtoolcutsplinepath.cpp \
tools/vtooluniondetails.cpp \
tools/drawTools/vtoolcutarc.cpp \
tools/drawTools/vabstractspline.cpp
tools/drawTools/vabstractspline.cpp \
tools/drawTools/vtoolcut.cpp

View File

@ -55,13 +55,13 @@ protected:
private:
Q_DISABLE_COPY(VSimpleCurve)
/** @brief id spline id. */
quint32 id;
quint32 id;
/** @brief factor scale factor. */
qreal *factor;
qreal *factor;
/** @brief currentColor current color. */
Qt::GlobalColor *currentColor;
Qt::GlobalColor *currentColor;
};
#endif // VSIMPLECURVE_H