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->SetDescription(desc);
|
||||
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,
|
||||
ok, fullName, description));
|
||||
}
|
||||
tempData->AddVariable(name, tempMeash);
|
||||
data->AddVariable(name, meash);
|
||||
tempData->AddVariable(tempMeash);
|
||||
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> second = GeometricObject<VPointF>(secondPointId);
|
||||
|
||||
VLengthLine *length = new VLengthLine(first.data(), firstPointId, second.data(), secondPointId, *GetPatternUnit());
|
||||
AddVariable(length->GetName(), length);
|
||||
|
||||
VLineAngle *angle = new VLineAngle(first.data(), firstPointId, second.data(), secondPointId);
|
||||
AddVariable(angle->GetName(), angle);
|
||||
AddVariable(new VLengthLine(first.data(), firstPointId, second.data(), secondPointId, *GetPatternUnit()));
|
||||
AddVariable(new VLineAngle(first.data(), firstPointId, second.data(), secondPointId));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -460,21 +457,15 @@ void VContainer::AddArc(const QSharedPointer<VAbstractCurve> &arc, const quint32
|
|||
{
|
||||
const QSharedPointer<VArc> casted = arc.staticCast<VArc>();
|
||||
|
||||
VArcRadius *radius = new VArcRadius(id, parentId, casted.data(), *GetPatternUnit());
|
||||
AddVariable(radius->GetName(), radius);
|
||||
AddVariable(new VArcRadius(id, parentId, casted.data(), *GetPatternUnit()));
|
||||
}
|
||||
else if (arc->getType() == GOType::EllipticalArc)
|
||||
{
|
||||
const QSharedPointer<VEllipticalArc> casted = arc.staticCast<VEllipticalArc>();
|
||||
|
||||
VArcRadius *radius1 = new VArcRadius(id, parentId, casted.data(), 1, *GetPatternUnit());
|
||||
AddVariable(radius1->GetName(), radius1);
|
||||
|
||||
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);
|
||||
AddVariable(new VArcRadius(id, parentId, casted.data(), 1, *GetPatternUnit()));
|
||||
AddVariable(new VArcRadius(id, parentId, casted.data(), 2, *GetPatternUnit()));
|
||||
AddVariable(new VEllipticalArcRotation(id, parentId, casted.data()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)));
|
||||
}
|
||||
|
||||
VCurveLength *length = new VCurveLength(id, parentId, curve.data(), *GetPatternUnit());
|
||||
AddVariable(length->GetName(), length);
|
||||
|
||||
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);
|
||||
AddVariable(new VCurveLength(id, parentId, curve.data(), *GetPatternUnit()));
|
||||
AddVariable(new VCurveAngle(id, parentId, curve.data(), CurveAngle::StartAngle));
|
||||
AddVariable(new VCurveAngle(id, parentId, curve.data(), CurveAngle::EndAngle));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VContainer::AddSpline(const QSharedPointer<VAbstractBezier> &curve, quint32 id, quint32 parentId)
|
||||
{
|
||||
AddCurve(curve, id, parentId);
|
||||
|
||||
VCurveCLength *c1Length = new VCurveCLength(id, parentId, curve.data(), CurveCLength::C1, *GetPatternUnit());
|
||||
AddVariable(c1Length->GetName(), c1Length);
|
||||
|
||||
VCurveCLength *c2Length = new VCurveCLength(id, parentId, curve.data(), CurveCLength::C2, *GetPatternUnit());
|
||||
AddVariable(c2Length->GetName(), c2Length);
|
||||
AddVariable(new VCurveCLength(id, parentId, curve.data(), CurveCLength::C1, *GetPatternUnit()));
|
||||
AddVariable(new VCurveCLength(id, parentId, curve.data(), CurveCLength::C2, *GetPatternUnit()));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -521,22 +503,11 @@ void VContainer::AddCurveWithSegments(const QSharedPointer<VAbstractCubicBezierP
|
|||
{
|
||||
const VSpline spl = curve->GetSpline(i);
|
||||
|
||||
VCurveLength *length = new VCurveLength(id, parentId, curve->name(), spl, *GetPatternUnit(), i);
|
||||
AddVariable(length->GetName(), length);
|
||||
|
||||
VCurveAngle *startAngle = new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::StartAngle, i);
|
||||
AddVariable(startAngle->GetName(), startAngle);
|
||||
|
||||
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);
|
||||
AddVariable(new VCurveLength(id, parentId, curve->name(), spl, *GetPatternUnit(), i));
|
||||
AddVariable(new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::StartAngle, i));
|
||||
AddVariable(new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::EndAngle, i));
|
||||
AddVariable(new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C1, *GetPatternUnit(), i));
|
||||
AddVariable(new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C2, *GetPatternUnit(), i));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ public:
|
|||
VPiecePath GetPiecePath(quint32 id) const;
|
||||
quint32 GetPieceForPiecePath(quint32 id) const;
|
||||
template <typename T>
|
||||
QSharedPointer<T> GetVariable(QString name) const;
|
||||
QSharedPointer<T> GetVariable(const QString &name) const;
|
||||
quint32 getId() const;
|
||||
quint32 getNextId() const;
|
||||
void UpdateId(quint32 newId) const;
|
||||
|
@ -165,9 +165,9 @@ public:
|
|||
quint32 parentId = NULL_ID);
|
||||
|
||||
template <typename T>
|
||||
void AddVariable(const QString& name, T *var);
|
||||
void AddVariable(T *var);
|
||||
template <typename T>
|
||||
void AddVariable(const QString& name, const QSharedPointer<T> &var);
|
||||
void AddVariable(const QSharedPointer<T> &var);
|
||||
void RemoveVariable(const QString& name);
|
||||
void RemovePiece(quint32 id);
|
||||
|
||||
|
@ -287,7 +287,7 @@ const QSharedPointer<T> VContainer::GeometricObject(const quint32 &id) const
|
|||
* @return variable
|
||||
*/
|
||||
template <typename T>
|
||||
QSharedPointer<T> VContainer::GetVariable(QString name) const
|
||||
QSharedPointer<T> VContainer::GetVariable(const QString &name) const
|
||||
{
|
||||
SCASSERT(name.isEmpty()==false)
|
||||
if (d->variables.contains(name))
|
||||
|
@ -311,35 +311,36 @@ QSharedPointer<T> VContainer::GetVariable(QString name) const
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
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>
|
||||
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())
|
||||
{
|
||||
throw VExceptionBadId(tr("Can't cast object."), name);
|
||||
throw VExceptionBadId(tr("Can't cast object."), var->GetName());
|
||||
}
|
||||
*v = *var;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw VExceptionBadId(tr("Can't find object. Type mismatch."), name);
|
||||
throw VExceptionBadId(tr("Can't find object. Type mismatch."), var->GetName());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
d->variables.insert(name, var);
|
||||
uniqueNames[d->nspace].insert(name);
|
||||
d->variables.insert(var->GetName(), var);
|
||||
uniqueNames[d->nspace].insert(var->GetName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -484,5 +484,5 @@ void CurrentCurveLength(vidtype curveId, VContainer *data)
|
|||
SCASSERT(length != nullptr)
|
||||
length->SetName(currentLength);
|
||||
|
||||
data->AddVariable(currentLength, length);
|
||||
data->AddVariable(length);
|
||||
}
|
||||
|
|
|
@ -280,7 +280,7 @@ void DialogAlongLine::SetCurrentLength()
|
|||
length->SetName(currentLength);
|
||||
|
||||
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->SetDescription(tr("Current seam allowance"));
|
||||
|
||||
locData->AddVariable(currentSeamAllowance, currentSA);
|
||||
locData->AddVariable(currentSA);
|
||||
|
||||
EvalWidthBefore();
|
||||
EvalWidthAfter();
|
||||
|
|
|
@ -2147,7 +2147,7 @@ void DialogSeamAllowance::EvalWidth()
|
|||
currentSA->SetFormula(m_saWidth, QString().setNum(m_saWidth), true);
|
||||
currentSA->SetDescription(tr("Current seam allowance"));
|
||||
|
||||
locData->AddVariable(currentSeamAllowance, currentSA);
|
||||
locData->AddVariable(currentSA);
|
||||
|
||||
EvalWidthBefore();
|
||||
EvalWidthAfter();
|
||||
|
|
|
@ -129,7 +129,7 @@ VToolCutArc* VToolCutArc::Create(VToolCutArcInitData &initData)
|
|||
VCurveLength *length = new VCurveLength(initData.arcId, initData.arcId, arc.data(),
|
||||
*initData.data->GetPatternUnit());
|
||||
length->SetName(currentLength);
|
||||
initData.data->AddVariable(currentLength, length);
|
||||
initData.data->AddVariable(length);
|
||||
|
||||
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(),
|
||||
*initData.data->GetPatternUnit());
|
||||
length->SetName(currentLength);
|
||||
initData.data->AddVariable(currentLength, length);
|
||||
initData.data->AddVariable(length);
|
||||
|
||||
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(),
|
||||
*initData.data->GetPatternUnit());
|
||||
length->SetName(currentLength);
|
||||
initData.data->AddVariable(currentLength, length);
|
||||
initData.data->AddVariable(length);
|
||||
|
||||
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(),
|
||||
initData.secondPointId, *initData.data->GetPatternUnit());
|
||||
length->SetName(currentLength);
|
||||
initData.data->AddVariable(currentLength, length);
|
||||
initData.data->AddVariable(length);
|
||||
|
||||
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->SetDescription(tr("Current seam allowance"));
|
||||
|
||||
initData.data->AddVariable(currentSeamAllowance, currentSA);
|
||||
initData.data->AddVariable(currentSA);
|
||||
initData.id = initData.data->AddPiece(initData.detail);
|
||||
}
|
||||
else
|
||||
|
@ -136,7 +136,7 @@ VToolSeamAllowance *VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initD
|
|||
currentSA->SetFormula(calcWidth, initData.width, true);
|
||||
currentSA->SetDescription(tr("Current seam allowance"));
|
||||
|
||||
initData.data->AddVariable(currentSeamAllowance, currentSA);
|
||||
initData.data->AddVariable(currentSA);
|
||||
|
||||
initData.data->UpdatePiece(initData.id, initData.detail);
|
||||
if (initData.parse != Document::FullParse)
|
||||
|
|
Loading…
Reference in New Issue
Block a user