Alias field for tool Spline Path.

This commit is contained in:
Roman Telezhynskyi 2020-11-04 15:26:22 +02:00
parent 648d1f1897
commit b1f9327393
13 changed files with 98 additions and 21 deletions

View File

@ -2099,6 +2099,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolSplinePath(VPE::VProperty *prope
case 61: // AttrNotes
SetNotes<VToolSplinePath>(property);
break;
case 62: // AttrAlias
SetAlias<VToolSplinePath>(property);
break;
default:
qWarning()<<"Unknown property type. id = "<<id;
break;
@ -2849,6 +2852,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSplinePath(QGraphicsItem *item)
formView->setTitle(tr("Tool for path curve"));
AddPropertyObjectName(i, tr("Name:"), true);
AddPropertyAlias(i, tr("Alias:"));
AddPropertyCurvePenStyle(i, tr("Pen style:"), CurvePenStylesPics());
AddPropertyLineColor(i, tr("Color:"), VAbstractTool::ColorsList(), AttrColor);
AddPropertyApproximationScale(tr("Approximation scale:"), i->getSplinePath().GetApproximationScale());
@ -3693,6 +3697,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSplinePath()
idToProperty[AttrAScale]->setValue(valueApproximationScale);
idToProperty[AttrNotes]->setValue(i->GetNotes());
idToProperty[AttrAlias]->setValue(i->GetAliasSuffix());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -2739,6 +2739,7 @@ void VPattern::ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement
initData.penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine);
initData.duplicate = GetParametrUInt(domElement, AttrDuplicate, QChar('0'));
initData.approximationScale = GetParametrDouble(domElement, AttrAScale, QChar('0'));
initData.aliasSuffix = GetParametrEmptyString(domElement, AttrAlias);
const QDomNodeList nodeList = domElement.childNodes();
const qint32 num = nodeList.size();

View File

@ -81,20 +81,32 @@ VCurveAngle::VCurveAngle(const quint32 &id, const quint32 &parentId, const VAbst
}
//---------------------------------------------------------------------------------------------------------------------
VCurveAngle::VCurveAngle(const quint32 &id, const quint32 &parentId, const QString &baseCurveName, const VSpline &spl,
CurveAngle angle, qint32 segment)
VCurveAngle::VCurveAngle(const quint32 &id, const quint32 &parentId, const VAbstractCurve *baseCurve,
const VSpline &spl, CurveAngle angle, qint32 segment)
:VCurveVariable(id, parentId)
{
SCASSERT(baseCurve != nullptr)
SetType(VarType::CurveAngle);
if (angle == CurveAngle::StartAngle)
{
SetValue(spl.GetStartAngle());
SetName(angle1_V + baseCurveName + QLatin1String("_") + seg_ + QString().setNum(segment));
SetName(angle1_V + baseCurve->name() + QLatin1String("_") + seg_ + QString().setNum(segment));
if (not baseCurve->GetAlias().isEmpty())
{
SetAlias(angle1_V + baseCurve->GetAlias() + QLatin1String("_") + seg_ + QString().setNum(segment));
}
}
else
{
SetValue(spl.GetEndAngle());
SetName(angle2_V + baseCurveName + QLatin1String("_") + seg_ + QString().setNum(segment));
SetName(angle2_V + baseCurve->name() + QLatin1String("_") + seg_ + QString().setNum(segment));
if (not baseCurve->GetAlias().isEmpty())
{
SetAlias(angle2_V + baseCurve->GetAlias() + QLatin1String("_") + seg_ + QString().setNum(segment));
}
}
}

View File

@ -46,7 +46,7 @@ class VCurveAngle : public VCurveVariable
public:
VCurveAngle();
VCurveAngle(const quint32 &id, const quint32 &parentId, const VAbstractCurve *curve, CurveAngle angle);
VCurveAngle(const quint32 &id, const quint32 &parentId, const QString &baseCurveName, const VSpline &spl,
VCurveAngle(const quint32 &id, const quint32 &parentId, const VAbstractCurve *baseCurve, const VSpline &spl,
CurveAngle angle, qint32 segment);
protected:
VCurveAngle(const quint32 &id, const quint32 &parentId);

View File

@ -74,20 +74,32 @@ VCurveCLength::VCurveCLength(const quint32 &id, const quint32 &parentId, const V
}
//---------------------------------------------------------------------------------------------------------------------
VCurveCLength::VCurveCLength(const quint32 &id, const quint32 &parentId, const QString &baseCurveName,
VCurveCLength::VCurveCLength(const quint32 &id, const quint32 &parentId, const VAbstractBezier *baseCurve,
const VSpline &spl, CurveCLength cType, Unit patternUnit, qint32 segment)
: VCurveVariable(id, parentId)
{
SCASSERT(baseCurve != nullptr)
SetType(VarType::CurveCLength);
if (cType == CurveCLength::C1)
{
SetValue(FromPixel(spl.GetC1Length(), patternUnit));
SetName(c1Length_V + baseCurveName + QLatin1String("_") + seg_ + QString().setNum(segment));
SetName(c1Length_V + baseCurve->name() + QLatin1String("_") + seg_ + QString().setNum(segment));
if (not baseCurve->GetAlias().isEmpty())
{
SetAlias(c1Length_V + baseCurve->GetAlias() + QLatin1String("_") + seg_ + QString().setNum(segment));
}
}
else
{
SetValue(FromPixel(spl.GetC2Length(), patternUnit));
SetName(c2Length_V + baseCurveName + QLatin1String("_") + seg_ + QString().setNum(segment));
SetName(c2Length_V + baseCurve->name() + QLatin1String("_") + seg_ + QString().setNum(segment));
if (not baseCurve->GetAlias().isEmpty())
{
SetAlias(c2Length_V + baseCurve->GetAlias() + QLatin1String("_") + seg_ + QString().setNum(segment));
}
}
}

View File

@ -46,7 +46,7 @@ public:
VCurveCLength();
VCurveCLength(const quint32 &id, const quint32 &parentId, const VAbstractBezier *curve, CurveCLength cType,
Unit patternUnit);
VCurveCLength(const quint32 &id, const quint32 &parentId, const QString &baseCurveName, const VSpline &spl,
VCurveCLength(const quint32 &id, const quint32 &parentId, const VAbstractBezier *baseCurve, const VSpline &spl,
CurveCLength cType, Unit patternUnit, qint32 segment);
VCurveCLength(const VCurveCLength &var);
VCurveCLength &operator=(const VCurveCLength &var);

View File

@ -60,14 +60,20 @@ VCurveLength::VCurveLength(const quint32 &id, const quint32 &parentId, const VAb
}
//---------------------------------------------------------------------------------------------------------------------
VCurveLength::VCurveLength(const quint32 &id, const quint32 &parentId, const QString &baseCurveName, const VSpline &spl,
Unit patternUnit, qint32 segment)
VCurveLength::VCurveLength(const quint32 &id, const quint32 &parentId, const VAbstractCurve *baseCurve,
const VSpline &spl, Unit patternUnit, qint32 segment)
:VCurveVariable(id, parentId)
{
SCASSERT(not baseCurveName.isEmpty())
SCASSERT(baseCurve != nullptr)
SetType(VarType::CurveLength);
SetName(baseCurveName + QLatin1String("_") + seg_ + QString().setNum(segment));
SetName(baseCurve->name() + QLatin1String("_") + seg_ + QString().setNum(segment));
if (not baseCurve->GetAlias().isEmpty())
{
SetAlias(baseCurve->GetAlias() + QLatin1String("_") + seg_ + QString().setNum(segment));
}
SetValue(FromPixel(spl.GetLength(), patternUnit));
}

View File

@ -45,7 +45,7 @@ class VCurveLength : public VCurveVariable
public:
VCurveLength();
VCurveLength(const quint32 &id, const quint32 &parentId, const VAbstractCurve *curve, Unit patternUnit);
VCurveLength(const quint32 &id, const quint32 &parentId, const QString &baseCurveName, const VSpline &spl,
VCurveLength(const quint32 &id, const quint32 &parentId, const VAbstractCurve *baseCurve, const VSpline &spl,
Unit patternUnit, qint32 segment);
VCurveLength(const VCurveLength &var);
VCurveLength &operator=(const VCurveLength &var);

View File

@ -509,11 +509,11 @@ void VContainer::AddCurveWithSegments(const QSharedPointer<VAbstractCubicBezierP
{
const VSpline spl = curve->GetSpline(i);
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));
AddVariable(new VCurveLength(id, parentId, curve.data(), spl, *GetPatternUnit(), i));
AddVariable(new VCurveAngle(id, parentId, curve.data(), spl, CurveAngle::StartAngle, i));
AddVariable(new VCurveAngle(id, parentId, curve.data(), spl, CurveAngle::EndAngle, i));
AddVariable(new VCurveCLength(id, parentId, curve.data(), spl, CurveCLength::C1, *GetPatternUnit(), i));
AddVariable(new VCurveCLength(id, parentId, curve.data(), spl, CurveCLength::C2, *GetPatternUnit(), i));
}
}

View File

@ -125,6 +125,8 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, quint32 toolId, QWidg
connect(ui->pushButtonGrowLength1, &QPushButton::clicked, this, &DialogSplinePath::DeployLength1TextEdit);
connect(ui->pushButtonGrowLength2, &QPushButton::clicked, this, &DialogSplinePath::DeployLength2TextEdit);
connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogSplinePath::ValidateAlias);
vis = new VisToolSplinePath(data);
auto path = qobject_cast<VisToolSplinePath *>(vis);
SCASSERT(path != nullptr)
@ -167,6 +169,9 @@ void DialogSplinePath::SetPath(const VSplinePath &value)
ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name()));
ui->doubleSpinBoxApproximationScale->setValue(path.GetApproximationScale());
ui->lineEditAlias->setText(path.GetAliasSuffix());
ValidateAlias();
ChangeCurrentData(ui->comboBoxPenStyle, path.GetPenStyle());
ChangeCurrentData(ui->comboBoxColor, path.GetColor());
@ -490,6 +495,25 @@ void DialogSplinePath::FXLength2()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::ValidateAlias()
{
VSplinePath tempPath = path;
tempPath.SetAliasSuffix(ui->lineEditAlias->text());
if (not ui->lineEditAlias->text().isEmpty() && not data->IsUnique(tempPath.GetAlias()))
{
flagAlias = false;
ChangeColor(ui->labelAlias, errorColor);
}
else
{
flagAlias = true;
ChangeColor(ui->labelAlias, OkColor(this));
}
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::EvalAngle1()
{
@ -874,6 +898,7 @@ void DialogSplinePath::SavePath()
path.SetApproximationScale(ui->doubleSpinBoxApproximationScale->value());
path.SetPenStyle(GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine));
path.SetColor(GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack));
path.SetAliasSuffix(ui->lineEditAlias->text());
}
//---------------------------------------------------------------------------------------------------------------------
@ -945,7 +970,7 @@ bool DialogSplinePath::IsValid() const
fLength2 = fLength2 && flagLength2.at(i);
}
return fAngle1 && fAngle2 && fLength1 && fLength2 && flagError;
return fAngle1 && fAngle2 && fLength1 && fLength2 && flagError && flagAlias;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -88,6 +88,8 @@ private slots:
void FXAngle2();
void FXLength1();
void FXLength2();
void ValidateAlias();
private:
Q_DISABLE_COPY(DialogSplinePath)
@ -111,6 +113,7 @@ private:
QVector<bool> flagLength1;
QVector<bool> flagLength2;
bool flagError;
bool flagAlias{true};
void EvalAngle1();
void EvalAngle2();

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>460</width>
<height>647</height>
<height>677</height>
</rect>
</property>
<property name="windowTitle">
@ -887,6 +887,16 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelAlias">
<property name="text">
<string>Alias:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lineEditAlias"/>
</item>
</layout>
</item>
<item>

View File

@ -270,6 +270,7 @@ VToolSplinePath *VToolSplinePath::Create(VToolSplinePathInitData &initData)
path->SetColor(initData.color);
path->SetPenStyle(initData.penStyle);
path->SetApproximationScale(initData.approximationScale);
path->SetAliasSuffix(initData.aliasSuffix);
return VToolSplinePath::Create(initData, path);
}
@ -402,6 +403,7 @@ void VToolSplinePath::SetSplinePathAttributes(QDomElement &domElement, const VSp
doc->SetAttribute(domElement, AttrColor, path.GetColor());
doc->SetAttribute(domElement, AttrPenStyle, path.GetPenStyle());
doc->SetAttribute(domElement, AttrAScale, path.GetApproximationScale());
doc->SetAttributeOrRemoveIf(domElement, AttrAlias, path.GetAliasSuffix(), path.GetAliasSuffix().isEmpty());
UpdatePathPoints(doc, domElement, path);
}