diff --git a/src/app/container/container.pri b/src/app/container/container.pri index fed806e71..c9c1c2a80 100644 --- a/src/app/container/container.pri +++ b/src/app/container/container.pri @@ -8,7 +8,8 @@ SOURCES += \ container/vlengthline.cpp \ container/vlengthspline.cpp \ container/vlengtharc.cpp \ - container/vlineangle.cpp + container/vlineangle.cpp \ + container/vlengthcurve.cpp HEADERS += \ container/vcontainer.h \ @@ -21,4 +22,5 @@ HEADERS += \ container/vlengthspline.h \ container/vlengtharc.h \ container/vlineangle.h \ - container/variables.h + container/variables.h \ + container/vlengthcurve.h diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index 502ab46a6..ab1859ea0 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -282,17 +282,6 @@ void VContainer::UpdateObject(QHash &obj, const quint32 &id, val p UpdateId(id); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddLengthArc add length of arc to container - * @param id id of arc - */ -void VContainer::AddLengthArc(const quint32 &id) -{ - const VArc * arc = GeometricObject(id); - AddVariable(arc->name(), new VLengthArc(id, arc)); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Clear clear data in container. Id will be 0. diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index 0dbca7bb1..eccd8c4cb 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -33,6 +33,7 @@ #include "../geometry/vdetail.h" #include "../geometry/vgobject.h" #include "../exception/vexceptionbadid.h" +#include "../geometry/vabstractcurve.h" #include #include @@ -118,9 +119,22 @@ public: quint32 AddGObject(VGObject *obj); quint32 AddDetail(VDetail detail); - void AddLengthArc(const quint32 &id); void AddLine(const quint32 &firstPointId, const quint32 &secondPointId); + template + /** + * @brief AddCurveLength add length of curve type to the container + * @param id id of variables + * @param parentId if of parent object. + * + * Parent id - id of cutting point + */ + void AddCurveLength(const quint32 &id, const quint32 &parentId = 0) + { + const VAbstractCurve *var = GeometricObject(id); + AddVariable(var->name(), new TLength(id, parentId, var)); + } + template void AddVariable(const QString& name, T var) { diff --git a/src/app/container/vlengtharc.cpp b/src/app/container/vlengtharc.cpp index 8914bc0ab..bf74d0e1c 100644 --- a/src/app/container/vlengtharc.cpp +++ b/src/app/container/vlengtharc.cpp @@ -27,29 +27,26 @@ *************************************************************************/ #include "vlengtharc.h" -#include "../geometry/varc.h" +#include "../geometry/vabstractcurve.h" #include "../widgets/vapplication.h" //--------------------------------------------------------------------------------------------------------------------- VLengthArc::VLengthArc() - :VInternalVariable(), id(0) + :VLengthCurve() { type = VarType::LengthArc; } //--------------------------------------------------------------------------------------------------------------------- -VLengthArc::VLengthArc(const quint32 &id, const VArc *arc) - :VInternalVariable(), id(id) +VLengthArc::VLengthArc(const quint32 &id, const quint32 &parentId, const VAbstractCurve *arc) + :VLengthCurve(id, parentId, arc) { type = VarType::LengthArc; - SCASSERT(arc != nullptr); - name = arc->name(); - value = qApp->fromPixel(arc->GetLength()); } //--------------------------------------------------------------------------------------------------------------------- VLengthArc::VLengthArc(const VLengthArc &var) - :VInternalVariable(var), id(var.GetId()) + :VLengthCurve(var) {} //--------------------------------------------------------------------------------------------------------------------- @@ -59,17 +56,10 @@ VLengthArc &VLengthArc::operator=(const VLengthArc &var) { return *this; } - VInternalVariable::operator=(var); - this->id = var.GetId(); + VLengthCurve::operator=(var); return *this; } //--------------------------------------------------------------------------------------------------------------------- VLengthArc::~VLengthArc() {} - -//--------------------------------------------------------------------------------------------------------------------- -bool VLengthArc::Filter(quint32 id) -{ - return this->id == id; -} diff --git a/src/app/container/vlengtharc.h b/src/app/container/vlengtharc.h index bf45df4f8..608fd42e2 100644 --- a/src/app/container/vlengtharc.h +++ b/src/app/container/vlengtharc.h @@ -29,28 +29,18 @@ #ifndef VLENGTHARC_H #define VLENGTHARC_H -#include "vinternalvariable.h" +#include "vlengthcurve.h" -class VArc; +class VAbstractCurve; -class VLengthArc :public VInternalVariable +class VLengthArc :public VLengthCurve { public: VLengthArc(); - VLengthArc(const quint32 &id, const VArc * arc); + VLengthArc(const quint32 &id, const quint32 &parentId, const VAbstractCurve *arc); VLengthArc(const VLengthArc &var); VLengthArc &operator=(const VLengthArc &var); virtual ~VLengthArc(); - - virtual bool Filter(quint32 id); - quint32 GetId() const; -private: - quint32 id; }; -inline quint32 VLengthArc::GetId() const -{ - return id; -} - #endif // VLENGTHARC_H diff --git a/src/app/container/vlengthcurve.cpp b/src/app/container/vlengthcurve.cpp new file mode 100644 index 000000000..1f27760a4 --- /dev/null +++ b/src/app/container/vlengthcurve.cpp @@ -0,0 +1,83 @@ +/************************************************************************ + ** + ** @file vlengthcurve.cpp + ** @author Roman Telezhynskyi + ** @date 15 8, 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 + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vlengthcurve.h" +#include "../widgets/vapplication.h" +#include "../geometry/vabstractcurve.h" + +//--------------------------------------------------------------------------------------------------------------------- +VLengthCurve::VLengthCurve() + :VInternalVariable(), id(0), parentId(0) +{ + type = VarType::Unknown; +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthCurve::VLengthCurve(const quint32 &id, const quint32 &parentId, const VAbstractCurve *curve) + :VInternalVariable(), id(id), parentId(parentId) +{ + type = VarType::Unknown; + SCASSERT(curve != nullptr); + name = curve->name(); + value = qApp->fromPixel(curve->GetLength()); +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthCurve::VLengthCurve(const VLengthCurve &var) + :VInternalVariable(var), id(var.GetId()), parentId(var.GetParentId()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthCurve &VLengthCurve::operator=(const VLengthCurve &var) +{ + if ( &var == this ) + { + return *this; + } + VInternalVariable::operator=(var); + this->id = var.GetId(); + this->parentId = var.GetParentId(); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VLengthCurve::~VLengthCurve() +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VLengthCurve::Filter(quint32 id) +{ + if (parentId != 0)//Do not check if value zero + {// Not all curves have parents. Only those who was created after cutting the parent curve. + return this->id == id || parentId == id; + } + else + { + return this->id == id; + } +} diff --git a/src/app/container/vlengthcurve.h b/src/app/container/vlengthcurve.h new file mode 100644 index 000000000..763ba0d11 --- /dev/null +++ b/src/app/container/vlengthcurve.h @@ -0,0 +1,65 @@ +/************************************************************************ + ** + ** @file vlengthcurve.h + ** @author Roman Telezhynskyi + ** @date 15 8, 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 + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VLENGTHCURVE_H +#define VLENGTHCURVE_H + +#include "vinternalvariable.h" + +class VAbstractCurve; + +class VLengthCurve : public VInternalVariable +{ +public: + VLengthCurve(); + VLengthCurve(const quint32 &id, const quint32 &parentId, const VAbstractCurve *curve); + VLengthCurve(const VLengthCurve &var); + VLengthCurve &operator=(const VLengthCurve &var); + virtual ~VLengthCurve(); + + virtual bool Filter(quint32 id); + quint32 GetId() const; + quint32 GetParentId() const; +protected: + quint32 id; + quint32 parentId; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline quint32 VLengthCurve::GetId() const +{ + return id; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline quint32 VLengthCurve::GetParentId() const +{ + return parentId; +} + +#endif // VLENGTHCURVE_H diff --git a/src/app/container/vlengthspline.cpp b/src/app/container/vlengthspline.cpp index 146ad4b46..1d8f38dd2 100644 --- a/src/app/container/vlengthspline.cpp +++ b/src/app/container/vlengthspline.cpp @@ -32,31 +32,31 @@ //--------------------------------------------------------------------------------------------------------------------- VLengthSpline::VLengthSpline() - :VInternalVariable(), id(0) + :VLengthCurve() { type = VarType::LengthSpline; } -VLengthSpline::VLengthSpline(const quint32 &id, const QString &name, const qreal &value) - :VInternalVariable(), id(id) +VLengthSpline::VLengthSpline(const quint32 &id, const quint32 &parentId, const QString &name, const qreal &value) + :VLengthCurve() { type = VarType::LengthSpline; this->name = name; this->value = value; + this->id = id; + this->parentId = parentId; } //--------------------------------------------------------------------------------------------------------------------- -VLengthSpline::VLengthSpline(const quint32 &id, const VAbstractCurve *path) - :VInternalVariable(), id(id) +VLengthSpline::VLengthSpline(const quint32 &id, const quint32 &parentId, const VAbstractCurve *path) + :VLengthCurve(id, parentId, path) { type = VarType::LengthSpline; - this->name = path->name(); - this->value = qApp->fromPixel(path->GetLength()); } //--------------------------------------------------------------------------------------------------------------------- VLengthSpline::VLengthSpline(const VLengthSpline &var) - :VInternalVariable(var), id(var.GetId()) + :VLengthCurve(var) {} //--------------------------------------------------------------------------------------------------------------------- @@ -66,17 +66,10 @@ VLengthSpline &VLengthSpline::operator=(const VLengthSpline &var) { return *this; } - VInternalVariable::operator=(var); - this->id = var.GetId(); + VLengthCurve::operator=(var); return *this; } //--------------------------------------------------------------------------------------------------------------------- VLengthSpline::~VLengthSpline() {} - -//--------------------------------------------------------------------------------------------------------------------- -bool VLengthSpline::Filter(quint32 id) -{ - return this->id == id; -} diff --git a/src/app/container/vlengthspline.h b/src/app/container/vlengthspline.h index 127dc8d33..bc2771486 100644 --- a/src/app/container/vlengthspline.h +++ b/src/app/container/vlengthspline.h @@ -29,30 +29,19 @@ #ifndef VLENGTHSPLINES_H #define VLENGTHSPLINES_H -#include "vinternalvariable.h" +#include "vlengthcurve.h" class VAbstractCurve; -class VLengthSpline :public VInternalVariable +class VLengthSpline :public VLengthCurve { public: VLengthSpline(); - VLengthSpline(const quint32 &id, const QString &name, const qreal &value); - VLengthSpline(const quint32 &id, const VAbstractCurve *path); + VLengthSpline(const quint32 &id, const quint32 &parentId, const QString &name, const qreal &value); + VLengthSpline(const quint32 &id, const quint32 &parentId, const VAbstractCurve *path); VLengthSpline(const VLengthSpline &var); VLengthSpline &operator=(const VLengthSpline &var); virtual ~VLengthSpline(); - - virtual bool Filter(quint32 id); - quint32 GetId() const; -private: - quint32 id; }; -//--------------------------------------------------------------------------------------------------------------------- -inline quint32 VLengthSpline::GetId() const -{ - return id; -} - #endif // VLENGTHSPLINES_H diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index c6a620691..959aff5c5 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -140,12 +140,12 @@ VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &ra if (typeCreation == Source::FromGui) { id = data->AddGObject(arc); - data->AddLengthArc(id); + data->AddCurveLength(id); } else { data->UpdateGObject(id, arc); - data->AddLengthArc(id); + data->AddCurveLength(id); if (parse != Document::FullParse) { doc->UpdateToolData(id, data); diff --git a/src/app/tools/drawTools/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index d38a348e3..1555f0040 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -142,8 +142,8 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS arc1id = data->AddGObject(new VArc(arc1)); arc2id = data->AddGObject(new VArc(arc2)); - data->AddLengthArc(arc1id); - data->AddLengthArc(arc2id); + data->AddCurveLength(arc1id, id); + data->AddCurveLength(arc2id, id); } else { @@ -155,8 +155,8 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS data->UpdateGObject(arc1id, new VArc(arc1)); data->UpdateGObject(arc2id, new VArc(arc2)); - data->AddLengthArc(arc1id); - data->AddLengthArc(arc2id); + data->AddCurveLength(arc1id, id); + data->AddCurveLength(arc2id, id); if (parse != Document::FullParse) { diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index 46db85a02..d6596e3ab 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -136,11 +136,11 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve()); spl1id = data->AddGObject(spline1); - data->AddVariable(spline1->name(), new VLengthSpline(id, spline1)); + data->AddCurveLength(spl1id, id); VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve()); spl2id = data->AddGObject(spline2); - data->AddVariable(spline2->name(), new VLengthSpline(id, spline2)); + data->AddCurveLength(spl2id, id); } else { @@ -152,11 +152,11 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve()); data->UpdateGObject(spl1id, spline1); - data->AddVariable(spline1->name(), new VLengthSpline(id, spline1)); + data->AddCurveLength(spl1id, id); VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve()); data->UpdateGObject(spl2id, spline2); - data->AddVariable(spline2->name(), new VLengthSpline(id, spline2)); + data->AddCurveLength(spl2id, id); if (parse != Document::FullParse) { diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index dde0a50f4..de1e706b6 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -198,18 +198,18 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QSt if (typeCreation == Source::FromGui) { splPath1id = data->AddGObject(splPath1); - data->AddVariable(splPath1->name(), new VLengthSpline(splPath1id, splPath1)); + data->AddCurveLength(splPath1id, id); splPath2id = data->AddGObject(splPath2); - data->AddVariable(splPath2->name(), new VLengthSpline(splPath2id, splPath2)); + data->AddCurveLength(splPath2id, id); } else { data->UpdateGObject(splPath1id, splPath1); - data->AddVariable(splPath1->name(), new VLengthSpline(splPath1id, splPath1)); + data->AddCurveLength(splPath1id, id); data->UpdateGObject(splPath2id, splPath2); - data->AddVariable(splPath2->name(), new VLengthSpline(splPath2id, splPath2)); + data->AddCurveLength(splPath2id, id); if (parse != Document::FullParse) { diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 30297d9c0..482182d66 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -154,12 +154,12 @@ void VToolSpline::Create(const quint32 _id, const quint32 &p1, const quint32 &p4 if (typeCreation == Source::FromGui) { id = data->AddGObject(spline); - data->AddVariable(spline->name(), new VLengthSpline(id, spline)); + data->AddCurveLength(id); } else { data->UpdateGObject(id, spline); - data->AddVariable(spline->name(), new VLengthSpline(id, spline)); + data->AddCurveLength(id); if (parse != Document::FullParse) { doc->UpdateToolData(id, data); diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index 99ea10774..c02f37dad 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -136,12 +136,12 @@ void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphics if (typeCreation == Source::FromGui) { id = data->AddGObject(path); - data->AddVariable(path->name(), new VLengthSpline(id, path)); + data->AddCurveLength(id); } else { data->UpdateGObject(id, path); - data->AddVariable(path->name(), new VLengthSpline(id, path)); + data->AddCurveLength(id); if (parse != Document::FullParse) { doc->UpdateToolData(id, data); diff --git a/src/app/visualization/vistoolcutarc.cpp b/src/app/visualization/vistoolcutarc.cpp index 646beacb5..128c49302 100644 --- a/src/app/visualization/vistoolcutarc.cpp +++ b/src/app/visualization/vistoolcutarc.cpp @@ -36,6 +36,7 @@ VisToolCutArc::VisToolCutArc(const VContainer *data, QGraphicsItem *parent) { point = InitPoint(mainColor, this); point->setZValue(2); + point->setFlag(QGraphicsItem::ItemStacksBehindParent, false); } //---------------------------------------------------------------------------------------------------------------------