Refactor VPiece class. Instead of method AppendInternalPath() use overloaded

getter.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-01-31 16:26:28 +02:00
parent f2e88c71da
commit a58a479db5
7 changed files with 53 additions and 44 deletions

View File

@ -304,6 +304,12 @@ QVector<quint32> VPiece::GetInternalPaths() const
return d->m_internalPaths; return d->m_internalPaths;
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<quint32> &VPiece::GetInternalPaths()
{
return d->m_internalPaths;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPiece::SetInternalPaths(const QVector<quint32> &iPaths) void VPiece::SetInternalPaths(const QVector<quint32> &iPaths)
{ {
@ -311,13 +317,13 @@ void VPiece::SetInternalPaths(const QVector<quint32> &iPaths)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPiece::AppendInternalPath(quint32 path) QVector<CustomSARecord> VPiece::GetCustomSARecords() const
{ {
d->m_internalPaths.append(path); return d->m_customSARecords;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<CustomSARecord> VPiece::GetCustomSARecords() const QVector<CustomSARecord> &VPiece::GetCustomSARecords()
{ {
return d->m_customSARecords; return d->m_customSARecords;
} }
@ -329,9 +335,21 @@ void VPiece::SetCustomSARecords(const QVector<CustomSARecord> &records)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPiece::AppendCustomSARecord(const CustomSARecord &record) QVector<quint32> VPiece::GetPins() const
{ {
d->m_customSARecords.append(record); return d->m_pins;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<quint32> &VPiece::GetPins()
{
return d->m_pins;
}
//---------------------------------------------------------------------------------------------------------------------
void VPiece::SetPins(const QVector<quint32> &pins)
{
d->m_pins = pins;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -85,12 +85,16 @@ public:
void SetFormulaSAWidth(const QString &formula, qreal value); void SetFormulaSAWidth(const QString &formula, qreal value);
QVector<quint32> GetInternalPaths() const; QVector<quint32> GetInternalPaths() const;
QVector<quint32> &GetInternalPaths();
void SetInternalPaths(const QVector<quint32> &iPaths); void SetInternalPaths(const QVector<quint32> &iPaths);
void AppendInternalPath(quint32 path);
QVector<CustomSARecord> GetCustomSARecords() const; QVector<CustomSARecord> GetCustomSARecords() const;
QVector<CustomSARecord> &GetCustomSARecords();
void SetCustomSARecords(const QVector<CustomSARecord> &records); void SetCustomSARecords(const QVector<CustomSARecord> &records);
void AppendCustomSARecord(const CustomSARecord &record);
QVector<quint32> GetPins() const;
QVector<quint32> &GetPins();
void SetPins(const QVector<quint32> &pins);
QVector<quint32> MissingNodes(const VPiece &det) const; QVector<quint32> MissingNodes(const VPiece &det) const;
QVector<quint32> MissingCSAPath(const VPiece &det) const; QVector<quint32> MissingCSAPath(const VPiece &det) const;

View File

@ -54,6 +54,7 @@ public:
m_united(false), m_united(false),
m_customSARecords(), m_customSARecords(),
m_internalPaths(), m_internalPaths(),
m_pins(),
m_ppData(), m_ppData(),
m_piPatternInfo(), m_piPatternInfo(),
m_glGrainline(), m_glGrainline(),
@ -69,6 +70,7 @@ public:
m_united(detail.m_united), m_united(detail.m_united),
m_customSARecords(detail.m_customSARecords), m_customSARecords(detail.m_customSARecords),
m_internalPaths(detail.m_internalPaths), m_internalPaths(detail.m_internalPaths),
m_pins(detail.m_pins),
m_ppData(detail.m_ppData), m_ppData(detail.m_ppData),
m_piPatternInfo(detail.m_piPatternInfo), m_piPatternInfo(detail.m_piPatternInfo),
m_glGrainline(detail.m_glGrainline), m_glGrainline(detail.m_glGrainline),
@ -88,6 +90,7 @@ public:
QVector<CustomSARecord> m_customSARecords; QVector<CustomSARecord> m_customSARecords;
QVector<quint32> m_internalPaths; QVector<quint32> m_internalPaths;
QVector<quint32> m_pins;
/** @brief Pattern piece data */ /** @brief Pattern piece data */
VPatternPieceData m_ppData; VPatternPieceData m_ppData;

View File

@ -127,18 +127,16 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece)
ui->listWidgetCustomSA->blockSignals(true); ui->listWidgetCustomSA->blockSignals(true);
ui->listWidgetCustomSA->clear(); ui->listWidgetCustomSA->clear();
const QVector<CustomSARecord> records = piece.GetCustomSARecords(); for (int i = 0; i < piece.GetCustomSARecords().size(); ++i)
for (int i = 0; i < records.size(); ++i)
{ {
NewCustomSA(records.at(i)); NewCustomSA(piece.GetCustomSARecords().at(i));
} }
ui->listWidgetCustomSA->blockSignals(false); ui->listWidgetCustomSA->blockSignals(false);
ui->listWidgetInternalPaths->clear(); ui->listWidgetInternalPaths->clear();
const QVector<quint32> iPaths = piece.GetInternalPaths(); for (int i = 0; i < piece.GetInternalPaths().size(); ++i)
for (int i = 0; i < iPaths.size(); ++i)
{ {
NewInternalPath(iPaths.at(i)); NewInternalPath(piece.GetInternalPaths().at(i));
} }
ui->comboBoxStartPoint->blockSignals(true); ui->comboBoxStartPoint->blockSignals(true);

View File

@ -211,18 +211,14 @@ void VToolPiecePath::AddToFile()
if (path.GetType() == PiecePathType::InternalPath) if (path.GetType() == PiecePathType::InternalPath)
{ {
QVector<quint32> iPaths = newDet.GetInternalPaths(); newDet.GetInternalPaths().append(id);
iPaths.append(id);
newDet.SetInternalPaths(iPaths);
} }
else if (path.GetType() == PiecePathType::CustomSeamAllowance) else if (path.GetType() == PiecePathType::CustomSeamAllowance)
{ {
CustomSARecord record; CustomSARecord record;
record.path = id; record.path = id;
QVector<CustomSARecord> records = newDet.GetCustomSARecords(); newDet.GetCustomSARecords().append(record);
records.append(record);
newDet.SetCustomSARecords(records);
} }
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId); SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId);

View File

@ -1116,25 +1116,23 @@ void VToolSeamAllowance::InitNodes(const VPiece &detail, VMainGraphicsScene *sce
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::InitCSAPaths(const VPiece &detail) void VToolSeamAllowance::InitCSAPaths(const VPiece &detail)
{ {
QVector<CustomSARecord> records = detail.GetCustomSARecords(); for (int i = 0; i < detail.GetCustomSARecords().size(); ++i)
for (int i = 0; i < records.size(); ++i)
{ {
doc->IncrementReferens(records.at(i).path); doc->IncrementReferens(detail.GetCustomSARecords().at(i).path);
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::InitInternalPaths(const VPiece &detail) void VToolSeamAllowance::InitInternalPaths(const VPiece &detail)
{ {
QVector<quint32> records = detail.GetInternalPaths(); for (int i = 0; i < detail.GetInternalPaths().size(); ++i)
for (int i = 0; i < records.size(); ++i)
{ {
VToolPiecePath *tool = qobject_cast<VToolPiecePath*>(doc->getTool(records.at(i))); VToolPiecePath *tool = qobject_cast<VToolPiecePath*>(doc->getTool(detail.GetInternalPaths().at(i)));
SCASSERT(tool != nullptr); SCASSERT(tool != nullptr);
tool->setParentItem(this); tool->setParentItem(this);
tool->SetParentType(ParentType::Item); tool->SetParentType(ParentType::Item);
tool->show(); tool->show();
doc->IncrementReferens(records.at(i)); doc->IncrementReferens(detail.GetInternalPaths().at(i));
} }
} }

View File

@ -958,12 +958,10 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector<quint32>
const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy,
quint32 pRotate, qreal angle) quint32 pRotate, qreal angle)
{ {
QVector<CustomSARecord> newList = newDetail.GetCustomSARecords();
const QVector<CustomSARecord> oldList = d.GetCustomSARecords();
QVector<quint32> nodeChildren; QVector<quint32> nodeChildren;
for(int i=0; i < oldList.size(); ++i) for(int i=0; i < d.GetCustomSARecords().size(); ++i)
{ {
CustomSARecord record = oldList.at(i); CustomSARecord record = d.GetCustomSARecords().at(i);
const VPiecePath path = initData.data->GetPiecePath(record.path); const VPiecePath path = initData.data->GetPiecePath(record.path);
VPiecePath newPath = path; VPiecePath newPath = path;
newPath.Clear();//Clear nodes newPath.Clear();//Clear nodes
@ -975,21 +973,19 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector<quint32>
VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse, VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse,
Source::FromTool, drawName, id); Source::FromTool, drawName, id);
record.path = idPath; record.path = idPath;
newList.append(record); newDetail.GetCustomSARecords().append(record);
nodeChildren.prepend(idPath); nodeChildren.prepend(idPath);
} }
children += nodeChildren; children += nodeChildren;
newDetail.SetCustomSARecords(newList);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName, void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName,
const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
{ {
const QVector<CustomSARecord> d1Records = d1.GetCustomSARecords(); for (int i = 0; i < d1.GetCustomSARecords().size(); ++i)
for (int i = 0; i < d1Records.size(); ++i)
{ {
newDetail.AppendCustomSARecord(d1Records.at(i)); newDetail.GetCustomSARecords().append(d1.GetCustomSARecords().at(i));
} }
QVector<quint32> children; QVector<quint32> children;
@ -1004,12 +1000,10 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector
const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx,
qreal dy, quint32 pRotate, qreal angle) qreal dy, quint32 pRotate, qreal angle)
{ {
QVector<quint32> newList = newDetail.GetInternalPaths();
const QVector<quint32> oldList = d.GetInternalPaths();
QVector<quint32> nodeChildren; QVector<quint32> nodeChildren;
for(int i=0; i < oldList.size(); ++i) for(int i=0; i < d.GetInternalPaths().size(); ++i)
{ {
const VPiecePath path = initData.data->GetPiecePath(oldList.at(i)); const VPiecePath path = initData.data->GetPiecePath(d.GetInternalPaths().at(i));
VPiecePath newPath = path; VPiecePath newPath = path;
newPath.Clear();//Clear nodes newPath.Clear();//Clear nodes
@ -1020,11 +1014,10 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector
const quint32 idPath = initData.data->AddPiecePath(newPath); const quint32 idPath = initData.data->AddPiecePath(newPath);
VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse, VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse,
Source::FromTool, drawName, id); Source::FromTool, drawName, id);
newList.append(idPath); newDetail.GetInternalPaths().append(idPath);
nodeChildren.prepend(idPath); nodeChildren.prepend(idPath);
} }
children += nodeChildren; children += nodeChildren;
newDetail.SetInternalPaths(newList);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1032,10 +1025,9 @@ void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece
const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy,
quint32 pRotate, qreal angle) quint32 pRotate, qreal angle)
{ {
const QVector<quint32> d1Internal = d1.GetInternalPaths(); for (int i = 0; i < d1.GetInternalPaths().size(); ++i)
for (int i = 0; i < d1Internal.size(); ++i)
{ {
newDetail.AppendInternalPath(d1Internal.at(i)); newDetail.GetInternalPaths().append(d1.GetInternalPaths().at(i));
} }
QVector<quint32> children; QVector<quint32> children;