Fixed issue #230. Program hangs when I try to open saved file.

--HG--
branch : develop
This commit is contained in:
dismine 2015-01-27 15:56:44 +02:00
parent 665d276e96
commit 2a27ebfe1f
6 changed files with 75 additions and 20 deletions

View File

@ -103,6 +103,11 @@ void DialogSplinePath::ChosenObject(quint32 id, const SceneObject &type)
{
if (type == SceneObject::Point)
{
if (path.CountPoint() >= 2 && path.at(path.CountPoint()-1).P().id() == id)
{
return;
}
NewItem(id, 1, 0, 1, 180);
emit ToolTip(tr("Select point of curve path"));

View File

@ -294,6 +294,17 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2,
qreal x3, qreal y3, qreal x4, qreal y4,
qint16 level, QVector<qreal> &px, QVector<qreal> &py)
{
if (px.size() >= 2)
{
for (int i=1; i < px.size(); ++i)
{
if (QPointF(px.at(i-1), py.at(i-1)) == QPointF(px.at(i), py.at(i)))
{
qCritical("All neighbors points in path must be unique.");
}
}
}
const double curve_collinearity_epsilon = 1e-30;
const double curve_angle_tolerance_epsilon = 0.01;
const double m_angle_tolerance = 0.0;

View File

@ -47,6 +47,11 @@ VSplinePath::~VSplinePath()
//---------------------------------------------------------------------------------------------------------------------
void VSplinePath::append(const VSplinePoint &point)
{
if (d->path.size() > 0 && d->path.last().P().toQPointF() == point.P().toQPointF())
{
return;
}
d->path.append(point);
QString name = splPath;
name.append(QString("_%1").arg(d->path.first().P().name()));

View File

@ -251,20 +251,18 @@ void VToolSplinePath::RefreshSplinePath(VSplinePath &splPath)
*/
void VToolSplinePath::UpdatePathPoint(VPattern *doc, QDomNode& node, const VSplinePath &path)
{
SCASSERT(doc != nullptr)
QDomNodeList nodeList = node.childNodes();
qint32 num = nodeList.size();
for (qint32 i = 0; i < num; ++i)
SCASSERT(doc != nullptr);
QDomElement element = node.toElement();
if (element.isElement() == false)
{
QDomElement domElement = nodeList.at(i).toElement();
if (domElement.isNull() == false)
{
VSplinePoint p = path.at(i);
doc->SetAttribute(domElement, AttrPSpline, p.P().id());
doc->SetAttribute(domElement, AttrKAsm1, p.KAsm1());
doc->SetAttribute(domElement, AttrKAsm2, p.KAsm2());
doc->SetAttribute(domElement, AttrAngle, p.Angle2());
}
qDebug()<<"Couldn't convert parent to element.";
return;
}
doc->removeAllChilds(element);
for (qint32 i = 0; i < path.CountPoint(); ++i)
{
AddPathPoint(doc, element, path.at(i));
}
}
@ -352,8 +350,9 @@ void VToolSplinePath::RefreshDataInFile()
* @param domElement dom element.
* @param splPoint spline path point.
*/
void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint)
void VToolSplinePath::AddPathPoint(VPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint)
{
SCASSERT(doc != nullptr);
QDomElement pathPoint = doc->createElement(AttrPathPoint);
doc->SetAttribute(pathPoint, AttrPSpline, splPoint.P().id());
@ -406,7 +405,7 @@ void VToolSplinePath::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &ob
doc->RemoveAllChild(tag);
for (qint32 i = 0; i < splPath->CountPoint(); ++i)
{
AddPathPoint(tag, splPath->at(i));
AddPathPoint(doc, tag, splPath->at(i));
}
}

View File

@ -80,7 +80,7 @@ protected:
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj);
private:
void RefreshGeometry();
void AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint);
static void AddPathPoint(VPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint);
void UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) const;
void RefreshSplinePath(VSplinePath &splPath);
};

View File

@ -301,6 +301,21 @@ bool VPattern::ChangeNamePP(const QString& oldName, const QString &newName)
void VPattern::Parse(const Document &parse)
{
qCDebug(vXML)<<"Parsing pattern.";
switch (parse)
{
case Document::FullParse:
qCDebug(vXML)<<"Full parse.";
break;
case Document::LiteParse:
qCDebug(vXML)<<"Lite parse.";
break;
case Document::LitePPParse:
qCDebug(vXML)<<"Lite pattern piece parse.";
break;
default:
break;
}
SCASSERT(sceneDraw != nullptr);
SCASSERT(sceneDetail != nullptr);
QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes
@ -317,6 +332,7 @@ void VPattern::Parse(const Document &parse)
switch (tags.indexOf(domElement.tagName()))
{
case 0: // TagDraw
qCDebug(vXML)<<"Tag draw.";
if (parse == Document::FullParse)
{
if (nameActivPP.isEmpty())
@ -336,22 +352,29 @@ void VPattern::Parse(const Document &parse)
ParseDrawElement(domElement, parse);
break;
case 1: // TagIncrements
qCDebug(vXML)<<"Tag increments.";
ParseIncrementsElement(domElement);
break;
case 2: // TagAuthor
qCDebug(vXML)<<"Tag author.";
break;
case 3: // TagDescription
qCDebug(vXML)<<"Tag description.";
break;
case 4: // TagNotes
qCDebug(vXML)<<"Tag notes.";
break;
case 5: // TagMeasurements
qCDebug(vXML)<<"Tag measurements.";
break;
case 6: // TagVersion
qCDebug(vXML)<<"Tag version.";
break;
case 7: // TagGradation
qCDebug(vXML)<<"Tag gradation.";
break;
default:
qDebug()<<"Wrong tag name"<<domElement.tagName()<<Q_FUNC_INFO;
qCDebug(vXML)<<"Wrong tag name"<<domElement.tagName();
break;
}
}
@ -883,17 +906,20 @@ void VPattern::ParseDrawElement(const QDomNode &node, const Document &parse)
switch (tags.indexOf(domElement.tagName()))
{
case 0: // TagCalculation
qCDebug(vXML)<<"Tag calculation.";
data->ClearCalculationGObjects();
ParseDrawMode(domElement, parse, Draw::Calculation);
break;
case 1: // TagModeling
qCDebug(vXML)<<"Tag modeling.";
ParseDrawMode(domElement, parse, Draw::Modeling);
break;
case 2: // TagDetails
qCDebug(vXML)<<"Tag details.";
ParseDetails(domElement, parse);
break;
default:
qDebug()<<"Wrong tag name"<<Q_FUNC_INFO;
qCDebug(vXML)<<"Wrong tag name";
break;
}
}
@ -933,22 +959,27 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const
switch (tags.indexOf(domElement.tagName()))
{
case 0: // TagPoint
qCDebug(vXML)<<"Tag point.";
ParsePointElement(scene, domElement, parse, domElement.attribute(AttrType, ""));
break;
case 1: // TagLine
qCDebug(vXML)<<"Tag line.";
ParseLineElement(scene, domElement, parse);
break;
case 2: // TagSpline
qCDebug(vXML)<<"Tag spline.";
ParseSplineElement(scene, domElement, parse, domElement.attribute(AttrType, ""));
break;
case 3: // TagArc
qCDebug(vXML)<<"Tag arc.";
ParseArcElement(scene, domElement, parse, domElement.attribute(AttrType, ""));
break;
case 4: // TagTools
qCDebug(vXML)<<"Tag tools.";
ParseToolsElement(scene, domElement, parse, domElement.attribute(AttrType, ""));
break;
default:
qDebug()<<"Wrong tag name"<<Q_FUNC_INFO;
qCDebug(vXML)<<"Wrong tag name";
break;
}
}
@ -1813,6 +1844,7 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &
switch (splines.indexOf(type))
{
case 0: //VToolSpline::ToolType
qCDebug(vXML)<<"VToolSpline.";
try
{
ToolsCommonAttributes(domElement, id);
@ -1835,6 +1867,7 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &
}
break;
case 1: //VToolSplinePath::ToolType
qCDebug(vXML)<<"VToolSplinePath.";
try
{
ToolsCommonAttributes(domElement, id);
@ -1879,6 +1912,7 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &
}
break;
case 2: //VNodeSpline::ToolType
qCDebug(vXML)<<"VNodeSpline.";
try
{
SplinesCommonAttributes(domElement, id, idObject, idTool);
@ -1896,6 +1930,7 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &
}
break;
case 3: //VNodeSplinePath::ToolType
qCDebug(vXML)<<"VNodeSplinePath.";
try
{
SplinesCommonAttributes(domElement, id, idObject, idTool);
@ -1913,7 +1948,7 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &
}
break;
default:
qDebug() << "Illegal spline type in VDomDocument::ParseSplineElement().";
qCDebug(vXML) << "Illegal spline type in VDomDocument::ParseSplineElement().";
break;
}
}