Refactoring.
Pass VContainer::AddVariable only a variable, the variable already knows its name. --HG-- branch : develop
This commit is contained in:
parent
2d63440549
commit
1217616813
|
@ -3926,7 +3926,7 @@ void VPattern::ParseIncrementsElement(const QDomNode &node, const Document &pars
|
||||||
increment->SetFormula(value, formula, ok);
|
increment->SetFormula(value, formula, ok);
|
||||||
increment->SetDescription(desc);
|
increment->SetDescription(desc);
|
||||||
increment->SetPreviewCalculation(node.toElement().tagName() == TagPreviewCalculations);
|
increment->SetPreviewCalculation(node.toElement().tagName() == TagPreviewCalculations);
|
||||||
data->AddVariable(name, increment);
|
data->AddVariable(increment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,8 +308,8 @@ void VMeasurements::ReadMeasurements(qreal height, qreal size) const
|
||||||
meash = QSharedPointer<VMeasurement>(new VMeasurement(data, static_cast<quint32>(i), name, value, formula,
|
meash = QSharedPointer<VMeasurement>(new VMeasurement(data, static_cast<quint32>(i), name, value, formula,
|
||||||
ok, fullName, description));
|
ok, fullName, description));
|
||||||
}
|
}
|
||||||
tempData->AddVariable(name, tempMeash);
|
tempData->AddVariable(tempMeash);
|
||||||
data->AddVariable(name, meash);
|
data->AddVariable(meash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -444,11 +444,8 @@ void VContainer::AddLine(const quint32 &firstPointId, const quint32 &secondPoint
|
||||||
const QSharedPointer<VPointF> first = GeometricObject<VPointF>(firstPointId);
|
const QSharedPointer<VPointF> first = GeometricObject<VPointF>(firstPointId);
|
||||||
const QSharedPointer<VPointF> second = GeometricObject<VPointF>(secondPointId);
|
const QSharedPointer<VPointF> second = GeometricObject<VPointF>(secondPointId);
|
||||||
|
|
||||||
VLengthLine *length = new VLengthLine(first.data(), firstPointId, second.data(), secondPointId, *GetPatternUnit());
|
AddVariable(new VLengthLine(first.data(), firstPointId, second.data(), secondPointId, *GetPatternUnit()));
|
||||||
AddVariable(length->GetName(), length);
|
AddVariable(new VLineAngle(first.data(), firstPointId, second.data(), secondPointId));
|
||||||
|
|
||||||
VLineAngle *angle = new VLineAngle(first.data(), firstPointId, second.data(), secondPointId);
|
|
||||||
AddVariable(angle->GetName(), angle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -460,21 +457,15 @@ void VContainer::AddArc(const QSharedPointer<VAbstractCurve> &arc, const quint32
|
||||||
{
|
{
|
||||||
const QSharedPointer<VArc> casted = arc.staticCast<VArc>();
|
const QSharedPointer<VArc> casted = arc.staticCast<VArc>();
|
||||||
|
|
||||||
VArcRadius *radius = new VArcRadius(id, parentId, casted.data(), *GetPatternUnit());
|
AddVariable(new VArcRadius(id, parentId, casted.data(), *GetPatternUnit()));
|
||||||
AddVariable(radius->GetName(), radius);
|
|
||||||
}
|
}
|
||||||
else if (arc->getType() == GOType::EllipticalArc)
|
else if (arc->getType() == GOType::EllipticalArc)
|
||||||
{
|
{
|
||||||
const QSharedPointer<VEllipticalArc> casted = arc.staticCast<VEllipticalArc>();
|
const QSharedPointer<VEllipticalArc> casted = arc.staticCast<VEllipticalArc>();
|
||||||
|
|
||||||
VArcRadius *radius1 = new VArcRadius(id, parentId, casted.data(), 1, *GetPatternUnit());
|
AddVariable(new VArcRadius(id, parentId, casted.data(), 1, *GetPatternUnit()));
|
||||||
AddVariable(radius1->GetName(), radius1);
|
AddVariable(new VArcRadius(id, parentId, casted.data(), 2, *GetPatternUnit()));
|
||||||
|
AddVariable(new VEllipticalArcRotation(id, parentId, casted.data()));
|
||||||
VArcRadius *radius2 = new VArcRadius(id, parentId, casted.data(), 2, *GetPatternUnit());
|
|
||||||
AddVariable(radius2->GetName(), radius2);
|
|
||||||
|
|
||||||
VEllipticalArcRotation *rotation = new VEllipticalArcRotation(id, parentId, casted.data());
|
|
||||||
AddVariable(rotation->GetName(), rotation);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,26 +480,17 @@ void VContainer::AddCurve(const QSharedPointer<VAbstractCurve> &curve, const qui
|
||||||
throw VException(tr("Can't create a curve with type '%1'").arg(static_cast<int>(curveType)));
|
throw VException(tr("Can't create a curve with type '%1'").arg(static_cast<int>(curveType)));
|
||||||
}
|
}
|
||||||
|
|
||||||
VCurveLength *length = new VCurveLength(id, parentId, curve.data(), *GetPatternUnit());
|
AddVariable(new VCurveLength(id, parentId, curve.data(), *GetPatternUnit()));
|
||||||
AddVariable(length->GetName(), length);
|
AddVariable(new VCurveAngle(id, parentId, curve.data(), CurveAngle::StartAngle));
|
||||||
|
AddVariable(new VCurveAngle(id, parentId, curve.data(), CurveAngle::EndAngle));
|
||||||
VCurveAngle *startAngle = new VCurveAngle(id, parentId, curve.data(), CurveAngle::StartAngle);
|
|
||||||
AddVariable(startAngle->GetName(), startAngle);
|
|
||||||
|
|
||||||
VCurveAngle *endAngle = new VCurveAngle(id, parentId, curve.data(), CurveAngle::EndAngle);
|
|
||||||
AddVariable(endAngle->GetName(), endAngle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VContainer::AddSpline(const QSharedPointer<VAbstractBezier> &curve, quint32 id, quint32 parentId)
|
void VContainer::AddSpline(const QSharedPointer<VAbstractBezier> &curve, quint32 id, quint32 parentId)
|
||||||
{
|
{
|
||||||
AddCurve(curve, id, parentId);
|
AddCurve(curve, id, parentId);
|
||||||
|
AddVariable(new VCurveCLength(id, parentId, curve.data(), CurveCLength::C1, *GetPatternUnit()));
|
||||||
VCurveCLength *c1Length = new VCurveCLength(id, parentId, curve.data(), CurveCLength::C1, *GetPatternUnit());
|
AddVariable(new VCurveCLength(id, parentId, curve.data(), CurveCLength::C2, *GetPatternUnit()));
|
||||||
AddVariable(c1Length->GetName(), c1Length);
|
|
||||||
|
|
||||||
VCurveCLength *c2Length = new VCurveCLength(id, parentId, curve.data(), CurveCLength::C2, *GetPatternUnit());
|
|
||||||
AddVariable(c2Length->GetName(), c2Length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -521,22 +503,11 @@ void VContainer::AddCurveWithSegments(const QSharedPointer<VAbstractCubicBezierP
|
||||||
{
|
{
|
||||||
const VSpline spl = curve->GetSpline(i);
|
const VSpline spl = curve->GetSpline(i);
|
||||||
|
|
||||||
VCurveLength *length = new VCurveLength(id, parentId, curve->name(), spl, *GetPatternUnit(), i);
|
AddVariable(new VCurveLength(id, parentId, curve->name(), spl, *GetPatternUnit(), i));
|
||||||
AddVariable(length->GetName(), length);
|
AddVariable(new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::StartAngle, i));
|
||||||
|
AddVariable(new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::EndAngle, i));
|
||||||
VCurveAngle *startAngle = new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::StartAngle, i);
|
AddVariable(new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C1, *GetPatternUnit(), i));
|
||||||
AddVariable(startAngle->GetName(), startAngle);
|
AddVariable(new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C2, *GetPatternUnit(), i));
|
||||||
|
|
||||||
VCurveAngle *endAngle = new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::EndAngle, i);
|
|
||||||
AddVariable(endAngle->GetName(), endAngle);
|
|
||||||
|
|
||||||
VCurveCLength *c1Length = new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C1,
|
|
||||||
*GetPatternUnit(), i);
|
|
||||||
AddVariable(c1Length->GetName(), c1Length);
|
|
||||||
|
|
||||||
VCurveCLength *c2Length = new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C2,
|
|
||||||
*GetPatternUnit(), i);
|
|
||||||
AddVariable(c2Length->GetName(), c2Length);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ public:
|
||||||
VPiecePath GetPiecePath(quint32 id) const;
|
VPiecePath GetPiecePath(quint32 id) const;
|
||||||
quint32 GetPieceForPiecePath(quint32 id) const;
|
quint32 GetPieceForPiecePath(quint32 id) const;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QSharedPointer<T> GetVariable(QString name) const;
|
QSharedPointer<T> GetVariable(const QString &name) const;
|
||||||
quint32 getId() const;
|
quint32 getId() const;
|
||||||
quint32 getNextId() const;
|
quint32 getNextId() const;
|
||||||
void UpdateId(quint32 newId) const;
|
void UpdateId(quint32 newId) const;
|
||||||
|
@ -165,9 +165,9 @@ public:
|
||||||
quint32 parentId = NULL_ID);
|
quint32 parentId = NULL_ID);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void AddVariable(const QString& name, T *var);
|
void AddVariable(T *var);
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void AddVariable(const QString& name, const QSharedPointer<T> &var);
|
void AddVariable(const QSharedPointer<T> &var);
|
||||||
void RemoveVariable(const QString& name);
|
void RemoveVariable(const QString& name);
|
||||||
void RemovePiece(quint32 id);
|
void RemovePiece(quint32 id);
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ const QSharedPointer<T> VContainer::GeometricObject(const quint32 &id) const
|
||||||
* @return variable
|
* @return variable
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QSharedPointer<T> VContainer::GetVariable(QString name) const
|
QSharedPointer<T> VContainer::GetVariable(const QString &name) const
|
||||||
{
|
{
|
||||||
SCASSERT(name.isEmpty()==false)
|
SCASSERT(name.isEmpty()==false)
|
||||||
if (d->variables.contains(name))
|
if (d->variables.contains(name))
|
||||||
|
@ -311,35 +311,36 @@ QSharedPointer<T> VContainer::GetVariable(QString name) const
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void VContainer::AddVariable(const QString& name, T *var)
|
void VContainer::AddVariable(T *var)
|
||||||
{
|
{
|
||||||
AddVariable(name, QSharedPointer<T>(var));
|
AddVariable(QSharedPointer<T>(var));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void VContainer::AddVariable(const QString& name, const QSharedPointer<T> &var)
|
void VContainer::AddVariable(const QSharedPointer<T> &var)
|
||||||
{
|
{
|
||||||
if (d->variables.contains(name))
|
SCASSERT(not var->GetName().isEmpty())
|
||||||
|
if (d->variables.contains(var->GetName()))
|
||||||
{
|
{
|
||||||
if (d->variables.value(name)->GetType() == var->GetType())
|
if (d->variables.value(var->GetName())->GetType() == var->GetType())
|
||||||
{
|
{
|
||||||
QSharedPointer<T> v = qSharedPointerDynamicCast<T>(d->variables.value(name));
|
QSharedPointer<T> v = qSharedPointerDynamicCast<T>(d->variables.value(var->GetName()));
|
||||||
if (v.isNull())
|
if (v.isNull())
|
||||||
{
|
{
|
||||||
throw VExceptionBadId(tr("Can't cast object."), name);
|
throw VExceptionBadId(tr("Can't cast object."), var->GetName());
|
||||||
}
|
}
|
||||||
*v = *var;
|
*v = *var;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw VExceptionBadId(tr("Can't find object. Type mismatch."), name);
|
throw VExceptionBadId(tr("Can't find object. Type mismatch."), var->GetName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
d->variables.insert(name, var);
|
d->variables.insert(var->GetName(), var);
|
||||||
uniqueNames[d->nspace].insert(name);
|
uniqueNames[d->nspace].insert(var->GetName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -484,5 +484,5 @@ void CurrentCurveLength(vidtype curveId, VContainer *data)
|
||||||
SCASSERT(length != nullptr)
|
SCASSERT(length != nullptr)
|
||||||
length->SetName(currentLength);
|
length->SetName(currentLength);
|
||||||
|
|
||||||
data->AddVariable(currentLength, length);
|
data->AddVariable(length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,7 +280,7 @@ void DialogAlongLine::SetCurrentLength()
|
||||||
length->SetName(currentLength);
|
length->SetName(currentLength);
|
||||||
|
|
||||||
VContainer *locData = const_cast<VContainer *> (data);
|
VContainer *locData = const_cast<VContainer *> (data);
|
||||||
locData->AddVariable(currentLength, length);
|
locData->AddVariable(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -810,7 +810,7 @@ void DialogPiecePath::EvalWidth()
|
||||||
currentSA->SetFormula(m_saWidth, QString().setNum(m_saWidth), true);
|
currentSA->SetFormula(m_saWidth, QString().setNum(m_saWidth), true);
|
||||||
currentSA->SetDescription(tr("Current seam allowance"));
|
currentSA->SetDescription(tr("Current seam allowance"));
|
||||||
|
|
||||||
locData->AddVariable(currentSeamAllowance, currentSA);
|
locData->AddVariable(currentSA);
|
||||||
|
|
||||||
EvalWidthBefore();
|
EvalWidthBefore();
|
||||||
EvalWidthAfter();
|
EvalWidthAfter();
|
||||||
|
|
|
@ -2147,7 +2147,7 @@ void DialogSeamAllowance::EvalWidth()
|
||||||
currentSA->SetFormula(m_saWidth, QString().setNum(m_saWidth), true);
|
currentSA->SetFormula(m_saWidth, QString().setNum(m_saWidth), true);
|
||||||
currentSA->SetDescription(tr("Current seam allowance"));
|
currentSA->SetDescription(tr("Current seam allowance"));
|
||||||
|
|
||||||
locData->AddVariable(currentSeamAllowance, currentSA);
|
locData->AddVariable(currentSA);
|
||||||
|
|
||||||
EvalWidthBefore();
|
EvalWidthBefore();
|
||||||
EvalWidthAfter();
|
EvalWidthAfter();
|
||||||
|
|
|
@ -129,7 +129,7 @@ VToolCutArc* VToolCutArc::Create(VToolCutArcInitData &initData)
|
||||||
VCurveLength *length = new VCurveLength(initData.arcId, initData.arcId, arc.data(),
|
VCurveLength *length = new VCurveLength(initData.arcId, initData.arcId, arc.data(),
|
||||||
*initData.data->GetPatternUnit());
|
*initData.data->GetPatternUnit());
|
||||||
length->SetName(currentLength);
|
length->SetName(currentLength);
|
||||||
initData.data->AddVariable(currentLength, length);
|
initData.data->AddVariable(length);
|
||||||
|
|
||||||
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
|
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ VToolCutSpline* VToolCutSpline::Create(VToolCutSplineInitData &initData)
|
||||||
VCurveLength *length = new VCurveLength(initData.splineId, initData.splineId, spl.data(),
|
VCurveLength *length = new VCurveLength(initData.splineId, initData.splineId, spl.data(),
|
||||||
*initData.data->GetPatternUnit());
|
*initData.data->GetPatternUnit());
|
||||||
length->SetName(currentLength);
|
length->SetName(currentLength);
|
||||||
initData.data->AddVariable(currentLength, length);
|
initData.data->AddVariable(length);
|
||||||
|
|
||||||
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
|
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ VToolCutSplinePath* VToolCutSplinePath::Create(VToolCutSplinePathInitData &initD
|
||||||
VCurveLength *length = new VCurveLength(initData.splinePathId, initData.splinePathId, splPath.data(),
|
VCurveLength *length = new VCurveLength(initData.splinePathId, initData.splinePathId, splPath.data(),
|
||||||
*initData.data->GetPatternUnit());
|
*initData.data->GetPatternUnit());
|
||||||
length->SetName(currentLength);
|
length->SetName(currentLength);
|
||||||
initData.data->AddVariable(currentLength, length);
|
initData.data->AddVariable(length);
|
||||||
|
|
||||||
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
|
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
|
||||||
|
|
||||||
|
|
|
@ -260,7 +260,7 @@ VToolAlongLine* VToolAlongLine::Create(VToolAlongLineInitData &initData)
|
||||||
VLengthLine *length = new VLengthLine(firstPoint.data(), initData.firstPointId, secondPoint.data(),
|
VLengthLine *length = new VLengthLine(firstPoint.data(), initData.firstPointId, secondPoint.data(),
|
||||||
initData.secondPointId, *initData.data->GetPatternUnit());
|
initData.secondPointId, *initData.data->GetPatternUnit());
|
||||||
length->SetName(currentLength);
|
length->SetName(currentLength);
|
||||||
initData.data->AddVariable(currentLength, length);
|
initData.data->AddVariable(length);
|
||||||
|
|
||||||
line.setLength(qApp->toPixel(CheckFormula(initData.id, initData.formula, initData.data)));
|
line.setLength(qApp->toPixel(CheckFormula(initData.id, initData.formula, initData.data)));
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ VToolSeamAllowance *VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initD
|
||||||
currentSA->SetFormula(initData.detail.GetSAWidth(), initData.width, true);
|
currentSA->SetFormula(initData.detail.GetSAWidth(), initData.width, true);
|
||||||
currentSA->SetDescription(tr("Current seam allowance"));
|
currentSA->SetDescription(tr("Current seam allowance"));
|
||||||
|
|
||||||
initData.data->AddVariable(currentSeamAllowance, currentSA);
|
initData.data->AddVariable(currentSA);
|
||||||
initData.id = initData.data->AddPiece(initData.detail);
|
initData.id = initData.data->AddPiece(initData.detail);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -136,7 +136,7 @@ VToolSeamAllowance *VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initD
|
||||||
currentSA->SetFormula(calcWidth, initData.width, true);
|
currentSA->SetFormula(calcWidth, initData.width, true);
|
||||||
currentSA->SetDescription(tr("Current seam allowance"));
|
currentSA->SetDescription(tr("Current seam allowance"));
|
||||||
|
|
||||||
initData.data->AddVariable(currentSeamAllowance, currentSA);
|
initData.data->AddVariable(currentSA);
|
||||||
|
|
||||||
initData.data->UpdatePiece(initData.id, initData.detail);
|
initData.data->UpdatePiece(initData.id, initData.detail);
|
||||||
if (initData.parse != Document::FullParse)
|
if (initData.parse != Document::FullParse)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user