Fixed wrong handling with true darts points inside tool detail.

(grafted from c84b1a66716faa7e171e5acb2824a7fb5702dd27)

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-03-08 19:49:16 +02:00
parent f69186b7b3
commit d72ea565cb
12 changed files with 194 additions and 58 deletions

View File

@ -11,6 +11,9 @@
- [#325] Check pattern for inverse compatibility.
- [#385] Add 'Open Recent' option in Tape.exe, 'File' dropdown menu.
# Version 0.4.4
- Fixed wrong handling with true darts points inside tool detail.
# Version 0.4.3 March 6, 2016
- [#456] Crash: broken formula + clicking on the f(x) symbol.
- [#454] Crash: using CRTL+Z while using line tool

View File

@ -322,16 +322,16 @@ VDetail VDetail::RemoveEdge(const quint32 &index) const
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Missing find missing ids in detail. When we deleted object in detail and return this detail need
* @brief Missing find missing nodes in detail. When we deleted object in detail and return this detail need
* understand, what nodes need make invisible.
* @param det changed detail.
* @return list with missing detail.
* @return list with missing nodes.
*/
QList<quint32> VDetail::Missing(const VDetail &det) const
QVector<VNodeDetail> VDetail::Missing(const VDetail &det) const
{
if (d->nodes.size() == det.CountNode()) //-V807
{
return QList<quint32>();
return QVector<VNodeDetail>();
}
QSet<quint32> set1;
@ -346,9 +346,18 @@ QList<quint32> VDetail::Missing(const VDetail &det) const
set2.insert(det.at(j).getId());
}
QSet<quint32> set3 = set1.subtract(set2);
const QList<quint32> set3 = set1.subtract(set2).toList();
QVector<VNodeDetail> nodes;
for (qint32 i = 0; i < set3.size(); ++i)
{
const int index = indexOfNode(d->nodes, set3.at(i));
if (index != -1)
{
nodes.append(d->nodes.at(index));
}
}
return set3.toList();
return nodes;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -76,7 +76,7 @@ public:
void NodeOnEdge(const quint32 &index, VNodeDetail &p1, VNodeDetail &p2)const;
VDetail RemoveEdge(const quint32 &index) const;
QList<quint32> Missing(const VDetail &det) const;
QVector<VNodeDetail> Missing(const VDetail &det) const;
QVector<QPointF> ContourPoints(const VContainer *data) const;
QVector<QPointF> SeamAllowancePoints(const VContainer *data) const;

View File

@ -119,6 +119,57 @@ QString VNodePoint::getTagName() const
return VNodePoint::TagName;
}
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::incrementReferens()
{
++_referens;
if (_referens == 1)
{
if (idTool != NULL_ID)
{
doc->IncrementReferens(idTool);
}
else
{
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(idNode);
doc->IncrementReferens(point->getIdTool());
}
ShowNode();
QDomElement domElement = doc->elementById(id);
if (domElement.isElement())
{
doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::InUse);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::decrementReferens()
{
if (_referens > 0)
{
--_referens;
}
if (_referens == 0)
{
if (idTool != NULL_ID)
{
doc->DecrementReferens(idTool);
}
else
{
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(idNode);
doc->DecrementReferens(point->getIdTool());
}
HideNode();
QDomElement domElement = doc->elementById(id);
if (domElement.isElement())
{
doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::NotInUse);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::PointChoosed()
{

View File

@ -56,6 +56,9 @@ public:
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::NodePoint)};
virtual QString getTagName() const Q_DECL_OVERRIDE;
virtual void incrementReferens() Q_DECL_OVERRIDE;
virtual void decrementReferens() Q_DECL_OVERRIDE;
public slots:
virtual void FullUpdateFromFile() Q_DECL_OVERRIDE;
void NameChangePosition(const QPointF &pos);

View File

@ -457,15 +457,8 @@ void VToolUnionDetails::incrementReferens()
++_referens;
if (_referens == 1)
{
for (int i = 0; i < d1.CountNode(); ++i)
{
doc->IncrementReferens(d1.at(i).getId());
}
for (int i = 0; i < d2.CountNode(); ++i)
{
doc->IncrementReferens(d2.at(i).getId());
}
IncrementReferences(d1);
IncrementReferences(d2);
QDomElement domElement = doc->elementById(id);
if (domElement.isElement())
@ -484,15 +477,8 @@ void VToolUnionDetails::decrementReferens()
}
if (_referens == 0)
{
for (int i = 0; i < d1.CountNode(); ++i)
{
doc->DecrementReferens(d1.at(i).getId());
}
for (int i = 0; i < d2.CountNode(); ++i)
{
doc->DecrementReferens(d2.at(i).getId());
}
DecrementReferences(d1);
DecrementReferences(d2);
QDomElement domElement = doc->elementById(id);
if (domElement.isElement())
@ -900,6 +886,56 @@ void VToolUnionDetails::AddToModeling(const QDomElement &domElement)
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolUnionDetails::IncrementReferences(const VDetail &d) const
{
for (int i = 0; i < d.CountNode(); ++i)
{
switch (d.at(i).getTypeTool())
{
case (Tool::NodePoint):
{
const auto point = VAbstractTool::data.GeometricObject<VPointF>(d.at(i).getId());
doc->IncrementReferens(point->getIdTool());
break;
}
case (Tool::NodeArc):
case (Tool::NodeSpline):
case (Tool::NodeSplinePath):
doc->IncrementReferens(d.at(i).getId());
break;
default:
qDebug()<<"Get wrong tool type. Ignore.";
break;
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolUnionDetails::DecrementReferences(const VDetail &d) const
{
for (int i = 0; i < d.CountNode(); ++i)
{
switch (d.at(i).getTypeTool())
{
case (Tool::NodePoint):
{
const auto point = VAbstractTool::data.GeometricObject<VPointF>(d.at(i).getId());
doc->DecrementReferens(point->getIdTool());
break;
}
case (Tool::NodeArc):
case (Tool::NodeSpline):
case (Tool::NodeSplinePath):
doc->DecrementReferens(d.at(i).getId());
break;
default:
qDebug()<<"Get wrong tool type. Ignore.";
break;
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolUnionDetails::SaveChildren(VAbstractPattern *doc, quint32 id, const QVector<quint32> &children)
{

View File

@ -113,6 +113,8 @@ private:
void AddNode(QDomElement &domElement, const VNodeDetail &node);
QDomNode UpdateDetail(const QDomNode &domNode, const VDetail &d);
void AddToModeling(const QDomElement &domElement);
void IncrementReferences(const VDetail &d) const;
void DecrementReferences(const VDetail &d) const;
static void SaveChildren(VAbstractPattern *doc, quint32 id, const QVector<quint32> &children);
static QVector<quint32> AllChildren(VAbstractPattern *doc, quint32 id);

View File

@ -59,14 +59,7 @@ void AddDet::undo()
return;
}
QVector<VNodeDetail> nodes = detail.getNodes();
if (nodes.size()>0)
{
for (qint32 i = 0; i < nodes.size(); ++i)
{
doc->DecrementReferens(nodes.at(i).getId());
}
}
DecrementReferences(detail.getNodes());
}
else
{

View File

@ -89,15 +89,7 @@ void DeleteDetail::redo()
SCASSERT(toolDet != nullptr);
toolDet->hide();
QVector<VNodeDetail> nodes = detail.getNodes();
if (nodes.size()>0)
{
for (qint32 i = 0; i < nodes.size(); ++i)
{
doc->DecrementReferens(nodes.at(i).getId());
}
}
DecrementReferences(detail.getNodes());
emit NeedFullParsing(); // Doesn't work when UnionDetail delete detail.
}
else

View File

@ -59,14 +59,7 @@ void SaveDetailOptions::undo()
{
VToolDetail::AddNode(doc, domElement, oldDet.at(i));
}
QVector<VNodeDetail> nodes = oldDet.getNodes();
if (nodes.size()>0)
{
for (qint32 i = 0; i < nodes.size(); ++i)
{
doc->IncrementReferens(nodes.at(i).getId());
}
}
IncrementReferences(oldDet.getNodes());
emit NeedLiteParsing(Document::LiteParse);
}
else
@ -90,14 +83,8 @@ void SaveDetailOptions::redo()
{
VToolDetail::AddNode(doc, domElement, newDet.at(i));
}
QList<quint32> list = oldDet.Missing(newDet);
if (list.size()>0)
{
for (qint32 i = 0; i < list.size(); ++i)
{
doc->DecrementReferens(list.at(i));
}
}
DecrementReferences(oldDet.Missing(newDet));
emit NeedLiteParsing(Document::LiteParse);
}
else

View File

@ -28,6 +28,8 @@
#include "vundocommand.h"
#include "../vmisc/def.h"
#include "../vgeometry/vpointf.h"
#include "../vtools/tools/vabstracttool.h"
Q_LOGGING_CATEGORY(vUndo, "v.undo")
@ -65,3 +67,57 @@ void VUndoCommand::UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &s
parentNode.insertAfter(xml, refElement);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VUndoCommand::IncrementReferences(const QVector<VNodeDetail> &nodes) const
{
for (qint32 i = 0; i < nodes.size(); ++i)
{
switch (nodes.at(i).getTypeTool())
{
case (Tool::NodePoint):
{
auto tool = qobject_cast<VAbstractTool *>(doc->getTool(nodeId));
SCASSERT(tool != nullptr);
const auto point = tool->getData()->GeometricObject<VPointF>(nodes.at(i).getId());
doc->IncrementReferens(point->getIdTool());
break;
}
case (Tool::NodeArc):
case (Tool::NodeSpline):
case (Tool::NodeSplinePath):
doc->IncrementReferens(nodes.at(i).getId());
break;
default:
qDebug()<<"Get wrong tool type. Ignore.";
break;
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VUndoCommand::DecrementReferences(const QVector<VNodeDetail> &nodes) const
{
for (qint32 i = 0; i < nodes.size(); ++i)
{
switch (nodes.at(i).getTypeTool())
{
case (Tool::NodePoint):
{
auto tool = qobject_cast<VAbstractTool *>(doc->getTool(nodeId));
SCASSERT(tool != nullptr);
const auto point = tool->getData()->GeometricObject<VPointF>(nodes.at(i).getId());
doc->DecrementReferens(point->getIdTool());
break;
}
case (Tool::NodeArc):
case (Tool::NodeSpline):
case (Tool::NodeSplinePath):
doc->DecrementReferens(nodes.at(i).getId());
break;
default:
qDebug()<<"Get wrong tool type. Ignore.";
break;
}
}
}

View File

@ -53,6 +53,7 @@ enum class UndoCommand: char { AddPatternPiece,
};
class VPattern;
class VNodeDetail;
class VUndoCommand : public QObject, public QUndoCommand
{
@ -71,6 +72,9 @@ protected:
bool redoFlag;
virtual void RedoFullParsing();
void UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const;
void IncrementReferences(const QVector<VNodeDetail> &nodes) const;
void DecrementReferences(const QVector<VNodeDetail> &nodes) const;
private:
Q_DISABLE_COPY(VUndoCommand)
};