Resolved issue #483. File lost.

Fixed crash after redo Unite tool. Caused by wrong position of modeling objects.
(grafted from 671b55b4fb9d5c12f980e2c5bc91b75208cac6a9)

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2016-06-30 19:09:40 +03:00
parent e1273d87f9
commit 0e1155d63e
15 changed files with 90 additions and 55 deletions

View File

@ -1292,7 +1292,7 @@ void VPattern::ParseNodePoint(const QDomElement &domElement, const Document &par
}
data->UpdateGObject(id, new VPointF(point->toQPointF(), point->name(), mx, my, idObject,
Draw::Modeling));
VNodePoint::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, idTool);
VNodePoint::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, "", idTool);
}
catch (const VExceptionBadId &e)
{
@ -1922,7 +1922,7 @@ void VPattern::ParseNodeSpline(const QDomElement &domElement, const Document &pa
spl->setIdObject(idObject);
spl->setMode(Draw::Modeling);
data->UpdateGObject(id, spl);
VNodeSpline::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, idTool);
VNodeSpline::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, "", idTool);
}
catch (const VExceptionBadId &e)
{
@ -1957,7 +1957,7 @@ void VPattern::ParseNodeSplinePath(const QDomElement &domElement, const Document
path->setIdObject(idObject);
path->setMode(Draw::Modeling);
data->UpdateGObject(id, path);
VNodeSplinePath::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, idTool);
VNodeSplinePath::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, "", idTool);
}
catch (const VExceptionBadId &e)
{
@ -2037,7 +2037,7 @@ void VPattern::ParseNodeArc(const QDomElement &domElement, const Document &parse
arc->setIdObject(idObject);
arc->setMode(Draw::Modeling);
data->UpdateGObject(id, arc);
VNodeArc::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, idTool);
VNodeArc::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, "", idTool);
}
catch (const VExceptionBadId &e)
{

View File

@ -45,9 +45,9 @@ const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool");
* @param parent parent object.
*/
VAbstractNode::VAbstractNode(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &idNode,
const quint32 &idTool, QObject *parent)
const QString &drawName, const quint32 &idTool, QObject *parent)
: VAbstractTool(doc, data, id, parent), parentType(ParentType::Item), idNode(idNode), idTool(idTool),
currentColor(Qt::black)
currentColor(Qt::black), m_drawName(drawName)
{
_referens = 0;
}
@ -115,6 +115,6 @@ void VAbstractNode::SetParentType(const ParentType &value)
*/
void VAbstractNode::AddToModeling(const QDomElement &domElement)
{
AddDetNode *addNode = new AddDetNode(domElement, doc);
AddDetNode *addNode = new AddDetNode(domElement, doc, m_drawName);
qApp->getUndoStack()->push(addNode);
}

View File

@ -43,7 +43,7 @@ class VAbstractNode : public VAbstractTool
Q_OBJECT
public:
VAbstractNode(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &idNode,
const quint32 &idTool, QObject *parent = nullptr);
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *parent = nullptr);
virtual ~VAbstractNode() Q_DECL_OVERRIDE {}
static const QString AttrIdObject;
static const QString AttrIdTool;
@ -66,6 +66,8 @@ protected:
/** @brief currentColor current tool color. */
QColor currentColor;
QString m_drawName;
void AddToModeling(const QDomElement &domElement);
virtual void SetVisualization() {}

View File

@ -47,8 +47,8 @@ const QString VNodeArc::ToolType = QStringLiteral("modeling");
* @param parent parent object.
*/
VNodeArc::VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation,
const quint32 &idTool, QObject *qoParent, QGraphicsItem *parent)
:VAbstractNode(doc, data, id, idArc, idTool, qoParent), QGraphicsPathItem(parent)
const QString &drawName, const quint32 &idTool, QObject *qoParent, QGraphicsItem *parent)
:VAbstractNode(doc, data, id, idArc, drawName, idTool, qoParent), QGraphicsPathItem(parent)
{
RefreshGeometry();
this->setPen(QPen(baseColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))));
@ -69,12 +69,13 @@ VNodeArc::VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32
* @param parent QObject parent
*/
void VNodeArc::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id, quint32 idArc,
const Document &parse, const Source &typeCreation, const quint32 &idTool, QObject *parent)
const Document &parse, const Source &typeCreation, const QString &drawName, const quint32 &idTool,
QObject *parent)
{
VAbstractTool::AddRecord(id, Tool::NodeArc, doc);
if (parse == Document::FullParse)
{
VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, idTool, parent);
VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, drawName, idTool, parent);
doc->AddTool(id, arc);
if (idTool != NULL_ID)

View File

@ -40,11 +40,13 @@ class VNodeArc :public VAbstractNode, public QGraphicsPathItem
Q_OBJECT
public:
VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation,
const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr);
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr,
QGraphicsItem * parent = nullptr);
static void Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id,
quint32 idArc, const Document &parse,
const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = nullptr);
const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0,
QObject *parent = nullptr);
static const QString TagName;
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}

View File

@ -49,8 +49,8 @@ const QString VNodePoint::ToolType = QStringLiteral("modeling");
* @param parent parent object.
*/
VNodePoint::VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idPoint, const Source &typeCreation,
const quint32 &idTool, QObject *qoParent, QGraphicsItem *parent)
:VAbstractNode(doc, data, id, idPoint, idTool, qoParent), QGraphicsEllipseItem(parent), radius(0),
const QString &drawName, const quint32 &idTool, QObject *qoParent, QGraphicsItem *parent)
:VAbstractNode(doc, data, id, idPoint, drawName, idTool, qoParent), QGraphicsEllipseItem(parent), radius(0),
namePoint(nullptr), lineName(nullptr)
{
radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm);
@ -81,14 +81,14 @@ VNodePoint::VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quin
*/
void VNodePoint::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene,
quint32 id, quint32 idPoint, const Document &parse,
const Source &typeCreation, const quint32 &idTool, QObject *parent)
const Source &typeCreation, const QString &drawName, const quint32 &idTool, QObject *parent)
{
VAbstractTool::AddRecord(id, Tool::NodePoint, doc);
if (parse == Document::FullParse)
{
//TODO Need create garbage collector and remove all nodes, what we don't use.
//Better check garbage before each saving file. Check only modeling tags.
VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, idTool, parent);
VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, drawName, idTool, parent);
connect(scene, &VMainGraphicsScene::EnableToolMove, point, &VNodePoint::EnableToolMove);
doc->AddTool(id, point);

View File

@ -46,11 +46,13 @@ class VNodePoint: public VAbstractNode, public QGraphicsEllipseItem
public:
VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idPoint, const Source &typeCreation,
const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr );
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr,
QGraphicsItem * parent = nullptr );
static void Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene,
quint32 id, quint32 idPoint, const Document &parse,
const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = nullptr);
const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0,
QObject *parent = nullptr);
static const QString TagName;
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}

View File

@ -47,9 +47,9 @@ const QString VNodeSpline::ToolType = QStringLiteral("modelingSpline");
* @param parent QGraphicsItem parent.
*/
VNodeSpline::VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline,
const Source &typeCreation, const quint32 &idTool, QObject *qoParent,
const Source &typeCreation, const QString &drawName, const quint32 &idTool, QObject *qoParent,
QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline, idTool, qoParent), QGraphicsPathItem(parent)
:VAbstractNode(doc, data, id, idSpline, drawName, idTool, qoParent), QGraphicsPathItem(parent)
{
RefreshGeometry();
this->setPen(QPen(baseColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))));
@ -71,13 +71,14 @@ VNodeSpline::VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, qu
*/
VNodeSpline *VNodeSpline::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id,
quint32 idSpline, const Document &parse,
const Source &typeCreation, const quint32 &idTool, QObject *parent)
const Source &typeCreation, const QString &drawName, const quint32 &idTool,
QObject *parent)
{
VAbstractTool::AddRecord(id, Tool::NodeSpline, doc);
VNodeSpline *spl = nullptr;
if (parse == Document::FullParse)
{
spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, idTool, parent);
spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, drawName, idTool, parent);
doc->AddTool(id, spl);
if (idTool != NULL_ID)

View File

@ -40,11 +40,13 @@ class VNodeSpline:public VAbstractNode, public QGraphicsPathItem
Q_OBJECT
public:
VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation,
const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr);
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr,
QGraphicsItem * parent = nullptr);
static VNodeSpline *Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id,
quint32 idSpline, const Document &parse,
const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = nullptr);
const Source &typeCreation, const QString &drawName = QString(),
const quint32 &idTool = 0, QObject *parent = nullptr);
static const QString TagName;
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}

View File

@ -48,9 +48,9 @@ const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath");
* @param parent parent object.
*/
VNodeSplinePath::VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline,
const Source &typeCreation, const quint32 &idTool, QObject *qoParent,
QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline, idTool, qoParent), QGraphicsPathItem(parent)
const Source &typeCreation, const QString &drawName, const quint32 &idTool,
QObject *qoParent, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline, drawName, idTool, qoParent), QGraphicsPathItem(parent)
{
RefreshGeometry();
this->setPen(QPen(baseColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))));
@ -71,13 +71,13 @@ VNodeSplinePath::VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint3
* @param parent QObject parent.
*/
void VNodeSplinePath::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id,
quint32 idSpline, const Document &parse,
const Source &typeCreation, const quint32 &idTool, QObject *parent)
quint32 idSpline, const Document &parse, const Source &typeCreation,
const QString &drawName, const quint32 &idTool, QObject *parent)
{
VAbstractTool::AddRecord(id, Tool::NodeSplinePath, doc);
if (parse == Document::FullParse)
{
VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, idTool, parent);
VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, drawName, idTool, parent);
doc->AddTool(id, splPath);
if (idTool != NULL_ID)

View File

@ -40,10 +40,11 @@ class VNodeSplinePath : public VAbstractNode, public QGraphicsPathItem
Q_OBJECT
public:
VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation,
const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr);
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr,
QGraphicsItem * parent = nullptr);
static void Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id,
quint32 idSpline, const Document &parse,
const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = 0);
quint32 idSpline, const Document &parse, const Source &typeCreation,
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *parent = 0);
static const QString TagName;
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}

View File

@ -97,6 +97,8 @@ VToolUnionDetails::VToolUnionDetails(VAbstractPattern *doc, VContainer *data, co
* @param det detail what we union.
* @param i index node in detail.
* @param idTool id tool union details.
* @param children
* @param drawName
* @param dx bias node x axis.
* @param dy bias node y axis.
* @param pRotate point rotation.
@ -104,8 +106,8 @@ VToolUnionDetails::VToolUnionDetails(VAbstractPattern *doc, VContainer *data, co
*/
void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data, VDetail &newDetail, const VDetail &det, const int &i,
const quint32 &idTool, QVector<quint32> &children, const qreal &dx,
const qreal &dy, const quint32 &pRotate, const qreal &angle)
const quint32 &idTool, QVector<quint32> &children, const QString &drawName,
const qreal &dx, const qreal &dy, const quint32 &pRotate, const qreal &angle)
{
quint32 id = 0, idObject = 0;
switch (det.at(i).getTypeTool())
@ -127,7 +129,8 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene,
VPointF *point1 = new VPointF(*point);
point1->setMode(Draw::Modeling);
id = data->AddGObject(point1);
VNodePoint::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
VNodePoint::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, drawName,
idTool, tool);
}
}
break;
@ -164,7 +167,8 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene,
arc2->setMode(Draw::Modeling);
id = data->AddGObject(arc2);
VNodeArc::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
VNodeArc::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui,
drawName, idTool, tool);
}
}
break;
@ -199,7 +203,8 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene,
VSpline *spl1 = new VSpline(*spl);
spl1->setMode(Draw::Modeling);
id = data->AddGObject(spl1);
VNodeSpline::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
VNodeSpline::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui,
drawName, idTool, tool);
delete p4;
delete p1;
@ -255,8 +260,8 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene,
VSplinePath *path1 = new VSplinePath(*path);
path1->setMode(Draw::Modeling);
id = data->AddGObject(path1);
VNodeSplinePath::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, idTool,
tool);
VNodeSplinePath::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, drawName,
idTool, tool);
}
}
break;
@ -579,7 +584,7 @@ VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d
QVector<quint32> children;
do
{
AddToNewDetail(unionDetails, scene, doc, data, newDetail, d1.RemoveEdge(indexD1), i, id, children);
AddToNewDetail(unionDetails, scene, doc, data, newDetail, d1.RemoveEdge(indexD1), i, id, children, drawName);
++i;
if (i > d1.indexOfNode(det1p1.getId()) && pointsD2 < countNodeD2-1)
{
@ -591,7 +596,7 @@ VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d
{
j=0;
}
AddToNewDetail(unionDetails, scene, doc, data, newDetail, d2.RemoveEdge(indexD2), j, id, children,
AddToNewDetail(unionDetails, scene, doc, data, newDetail, d2.RemoveEdge(indexD2), j, id, children, drawName,
dx, dy, det1p1.getId(), angle);
++pointsD2;
++j;

View File

@ -73,7 +73,7 @@ public:
static const QString NodeTypeModeling;
static void AddToNewDetail(QObject *tool, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
VDetail &newDetail, const VDetail &det, const int &i, const quint32 &idTool,
QVector<quint32> &children, const qreal &dx = 0,
QVector<quint32> &children, const QString &drawName, const qreal &dx = 0,
const qreal &dy = 0, const quint32 &pRotate = 0, const qreal &angle = 0);
static void UpdatePoints(VContainer *data, const VDetail &det, const int &i,
QVector<quint32> &children, const qreal &dx = 0, const qreal &dy = 0,

View File

@ -29,8 +29,8 @@
#include "adddetnode.h"
//---------------------------------------------------------------------------------------------------------------------
AddDetNode::AddDetNode(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent)
: VUndoCommand(xml, doc, parent)
AddDetNode::AddDetNode(const QDomElement &xml, VAbstractPattern *doc, const QString &drawName, QUndoCommand *parent)
: VUndoCommand(xml, doc, parent), m_drawName(drawName)
{
setText(QObject::tr("add node"));
nodeId = doc->GetParametrId(xml);
@ -45,13 +45,13 @@ void AddDetNode::undo()
{
qCDebug(vUndo, "Undo.");
QDomElement modelingElement;
if (doc->GetActivNodeElement(VAbstractPattern::TagModeling, modelingElement))
QDomElement modeling = GetModelingSection();
if (not modeling.isNull())
{
QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement())
{
if (modelingElement.removeChild(domElement).isNull())
if (modeling.removeChild(domElement).isNull())
{
qCDebug(vUndo, "Can't delete node.");
return;
@ -75,10 +75,10 @@ void AddDetNode::redo()
{
qCDebug(vUndo, "Redo.");
QDomElement modelingElement;
if (doc->GetActivNodeElement(VAbstractPattern::TagModeling, modelingElement))
QDomElement modeling = GetModelingSection();
if (not modeling.isNull())
{
modelingElement.appendChild(xml);
modeling.appendChild(xml);
}
else
{
@ -86,3 +86,18 @@ void AddDetNode::redo()
return;
}
}
//---------------------------------------------------------------------------------------------------------------------
QDomElement AddDetNode::GetModelingSection() const
{
QDomElement modeling;
if (m_drawName.isEmpty())
{
doc->GetActivNodeElement(VAbstractPattern::TagModeling, modeling);
}
else
{
modeling = doc->GetDraw(m_drawName).firstChildElement(VAbstractPattern::TagModeling);
}
return modeling;
}

View File

@ -35,12 +35,16 @@ class AddDetNode : public VUndoCommand
{
Q_OBJECT
public:
AddDetNode(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = 0);
AddDetNode(const QDomElement &xml, VAbstractPattern *doc, const QString &drawName, QUndoCommand *parent = 0);
virtual ~AddDetNode() Q_DECL_OVERRIDE;
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(AddDetNode)
QString m_drawName;
QDomElement GetModelingSection() const;
};
#endif // ADDDETNODE_H