Fixed issue #752. Valentina produces corrupted file if unite two pieces.

(grafted from e0e2d27ac2a1f8f43879218a97924481ae674c77)

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-09-11 15:56:18 +03:00
parent d6a956b7fa
commit 27f605dc65
5 changed files with 88 additions and 65 deletions

View File

@ -51,6 +51,7 @@
- Fix translation variables. - Fix translation variables.
- [#744] Check for Updates button produces error. - [#744] Check for Updates button produces error.
- Remove space as thousands separator when return formula to user. - Remove space as thousands separator when return formula to user.
- [#752] Valentina produces corrupted file if unite two pieces.
# Version 0.5.0 May 9, 2017 # Version 0.5.0 May 9, 2017
- [#581] User can now filter input lists by keyword in function wizard. - [#581] User can now filter input lists by keyword in function wizard.

View File

@ -622,31 +622,34 @@ VPiecePath VPiecePath::RemoveEdge(quint32 index) const
// Edge can be only segment. We ignore all curves inside segments. // Edge can be only segment. We ignore all curves inside segments.
const quint32 edges = static_cast<quint32>(ListNodePoint().size()); const quint32 edges = static_cast<quint32>(ListNodePoint().size());
quint32 k = 0;
for (quint32 i=0; i<edges; ++i) for (quint32 i=0; i<edges; ++i)
{
if (i == index)
{
path.Append(this->at(static_cast<int>(k)));
++k;
}
else
{ {
VPieceNode p1; VPieceNode p1;
VPieceNode p2; VPieceNode p2;
this->NodeOnEdge(i, p1, p2); this->NodeOnEdge(i, p1, p2);
const int j1 = this->indexOfNode(p1.GetId()); const int j1 = this->indexOfNode(p1.GetId());
int j2 = this->indexOfNode(p2.GetId());
if (j2 == 0) if (i == index)
{ {
j2 = this->CountNodes(); path.Append(this->at(j1));
} }
for (int j=j1; j<j2; ++j) else
{// Add "segment" except last point. Inside can be curves too. {
const int j2 = this->indexOfNode(p2.GetId());
int j = j1;
do
{
// Add "segment" except last point. Inside can be curves too.
path.Append(this->at(j)); path.Append(this->at(j));
++k; ++j;
if (j2 < j1 && j == this->CountNodes())
{
j = 0;
} }
} }
while (j != j2);
}
} }
return path; return path;
} }

View File

@ -124,5 +124,6 @@ private:
}; };
Q_DECLARE_TYPEINFO(VPiecePath, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(VPiecePath, Q_MOVABLE_TYPE);
Q_DECLARE_METATYPE(VPiecePath)
#endif // VPIECEPATH_H #endif // VPIECEPATH_H

View File

@ -985,34 +985,24 @@ void CreateUnitedNodes(VPiece &newDetail, const VPiece &d1, const VPiece &d2, qu
const VPiecePath d1Path = d1.GetPath().RemoveEdge(initData.indexD1); const VPiecePath d1Path = d1.GetPath().RemoveEdge(initData.indexD1);
const VPiecePath d2Path = d2.GetPath().RemoveEdge(initData.indexD2); const VPiecePath d2Path = d2.GetPath().RemoveEdge(initData.indexD2);
const qint32 countNodeD1 = d1Path.CountNodes(); const QVector<QPair<bool, VPieceNode> > unitedPath = VToolUnionDetails::CalcUnitedPath(d1Path, d2Path,
const qint32 countNodeD2 = d2Path.CountNodes(); initData.indexD2, pRotate);
qint32 pointsD2 = 0; //Keeps number points the second detail, what we have already added.
qint32 i = 0;
QVector<quint32> children; QVector<quint32> children;
VPiecePath newPath; VPiecePath newPath;
const int det1P1Index = d1.GetPath().indexOfNode(pRotate);
do for (int i=0; i < unitedPath.size(); ++i)
{ {
AddNodeToNewPath(initData, newPath, d1Path.at(i), id, children, drawName); if (unitedPath.at(i).first)
++i; {// first piece
if (i > det1P1Index && pointsD2 < countNodeD2-1) AddNodeToNewPath(initData, newPath, unitedPath.at(i).second, id, children, drawName);
{ }
qint32 j = 0; else
FindIndexJ(pointsD2, d2.GetPath(), initData.indexD2, j); {// second piece
do AddNodeToNewPath(initData, newPath, unitedPath.at(i).second, id, children, drawName, dx, dy, pRotate,
{ angle);
if (j >= countNodeD2)
{
j=0;
} }
AddNodeToNewPath(initData, newPath, d2Path.at(j), id, children, drawName, dx, dy, pRotate, angle);
++pointsD2;
++j;
} while (pointsD2 < countNodeD2-1);
} }
} while (i < countNodeD1);
newDetail.SetPath(newPath); newDetail.SetPath(newPath);
@ -1134,11 +1124,8 @@ void CreateUnitedPins(VPiece &newDetail, const VPiece &d1, const VPiece &d2, qui
void UpdateUnitedNodes(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, void UpdateUnitedNodes(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
qreal angle) qreal angle)
{ {
const VPiecePath d1Path = GetPiece1MainPath(initData.doc, id); const VPiecePath d1REPath = GetPiece1MainPath(initData.doc, id).RemoveEdge(initData.indexD1);
const VPiecePath d1REPath = d1Path.RemoveEdge(initData.indexD1); const VPiecePath d2REPath = GetPiece2MainPath(initData.doc, id).RemoveEdge(initData.indexD2);
const VPiecePath d2Path = GetPiece2MainPath(initData.doc, id);
const VPiecePath d2REPath = d2Path.RemoveEdge(initData.indexD2);
const qint32 countNodeD1 = d1REPath.CountNodes(); const qint32 countNodeD1 = d1REPath.CountNodes();
const qint32 countNodeD2 = d2REPath.CountNodes(); const qint32 countNodeD2 = d2REPath.CountNodes();
@ -1152,35 +1139,27 @@ void UpdateUnitedNodes(quint32 id, const VToolUnionDetailsInitData &initData, qr
"Time to refactor the code."); "Time to refactor the code.");
if (children.size() == countNodeD1 + countNodeD2-1) if (children.size() == countNodeD1 + countNodeD2-1)
{ {
qint32 pointsD2 = 0; //Keeps number points the second detail, what we have already added. const QVector<QPair<bool, VPieceNode> > unitedPath = VToolUnionDetails::CalcUnitedPath(d1REPath, d2REPath,
qint32 i = 0; initData.indexD2,
const int indexOfNode = d1Path.indexOfNode(pRotate); pRotate);
do
for (int i=0; i < unitedPath.size(); ++i)
{ {
UpdatePathNode(initData.data, d1REPath.at(i), children); if (unitedPath.at(i).first)
++i; {// first piece
if (i > indexOfNode && pointsD2 < countNodeD2-1) UpdatePathNode(initData.data, unitedPath.at(i).second, children);
{ }
qint32 j = 0; else
FindIndexJ(pointsD2, d2Path, initData.indexD2, j); {// second piece
do UpdatePathNode(initData.data, unitedPath.at(i).second, children, dx, dy, pRotate, angle);
{
if (j >= countNodeD2)
{
j=0;
} }
UpdatePathNode(initData.data, d2REPath.at(j), children, dx, dy, pRotate, angle);
++pointsD2;
++j;
} while (pointsD2 < countNodeD2-1);
} }
} while (i<countNodeD1);
} }
else // remove if min version is 0.3.2 else // remove if min version is 0.3.2
{ {
qint32 pointsD2 = 0; //Keeps number points the second detail, what we have already added. qint32 pointsD2 = 0; //Keeps number points the second detail, what we have already added.
qint32 i = 0; qint32 i = 0;
const int indexOfNode = d1Path.indexOfNode(pRotate); const int indexOfNode = d1REPath.indexOfNode(pRotate);
do do
{ {
++i; ++i;
@ -1188,7 +1167,7 @@ void UpdateUnitedNodes(quint32 id, const VToolUnionDetailsInitData &initData, qr
{ {
const int childrenCount = children.size(); const int childrenCount = children.size();
qint32 j = 0; qint32 j = 0;
FindIndexJ(pointsD2, d2Path, initData.indexD2, j); FindIndexJ(pointsD2, d2REPath, initData.indexD2, j);
do do
{ {
if (j >= countNodeD2) if (j >= countNodeD2)
@ -1636,3 +1615,39 @@ QVector<quint32> VToolUnionDetails::ReferenceObjects(const QDomElement &root, co
return objects; return objects;
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<QPair<bool, VPieceNode> > VToolUnionDetails::CalcUnitedPath(const VPiecePath &d1Path, const VPiecePath &d2Path,
quint32 indexD2, quint32 pRotate)
{
QVector<QPair<bool, VPieceNode> > path;
const qint32 countNodeD1 = d1Path.CountNodes();
const qint32 countNodeD2 = d2Path.CountNodes();
qint32 pointsD2 = 0; //Keeps number points the second detail, that we have already added.
qint32 i = 0;
const int det1P1Index = d1Path.indexOfNode(pRotate);
do
{
path.append(qMakePair(true, d1Path.at(i)));
++i;
if (i > det1P1Index && pointsD2 < countNodeD2-1)
{
qint32 j = 0;
FindIndexJ(pointsD2, d2Path, indexD2, j);
do
{
if (j >= countNodeD2)
{
j=0;
}
path.append(qMakePair(false, d2Path.at(j)));
++pointsD2;
++j;
} while (pointsD2 < countNodeD2-1);
}
} while (i < countNodeD1);
return path;
}

View File

@ -102,6 +102,9 @@ public:
virtual void incrementReferens() Q_DECL_OVERRIDE; virtual void incrementReferens() Q_DECL_OVERRIDE;
virtual void decrementReferens() Q_DECL_OVERRIDE; virtual void decrementReferens() Q_DECL_OVERRIDE;
virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE;
static QVector<QPair<bool, VPieceNode> > CalcUnitedPath(const VPiecePath &d1Path, const VPiecePath &d2Path,
quint32 indexD2, quint32 pRotate);
public slots: public slots:
/** /**
* @brief FullUpdateFromFile update tool data form file. * @brief FullUpdateFromFile update tool data form file.