Add base realization of equdistant. Fix two bugs.

This commit is contained in:
dismine 2013-09-11 17:14:21 +03:00
parent 46acd73b5b
commit 2ed982faeb
15 changed files with 537 additions and 372 deletions

View File

@ -256,15 +256,118 @@ QPainterPath VContainer::ContourPath(qint64 idDetail) const{
break; break;
} }
} }
QPainterPath ekv = Equidistant(points, Detail::CloseEquidistant, toPixel(10));
QPainterPath path; QPainterPath path;
path.moveTo(points[0]); path.moveTo(points[0]);
for (qint32 i = 1; i < points.count(); ++i){ for (qint32 i = 1; i < points.count(); ++i){
path.lineTo(points[i]); path.lineTo(points[i]);
} }
path.lineTo(points[0]); path.lineTo(points[0]);
path.addPath(ekv);
return path; return path;
} }
QPainterPath VContainer::Equidistant(QVector<QPointF> points, const Detail::Equidistant &eqv,
const qreal &width) const{
QPainterPath ekv;
QVector<QPointF> ekvPoints;
if ( points.size() < 3 ){
qDebug()<<"Not enough points for build equidistant.\n";
return ekv;
}
for (qint32 i = 0; i < points.size(); ++i ){
if(i != points.size()-1){
if(points[i] == points[i+1]){
points.remove(i+1);
}
} else {
if(points[i] == points[0]){
points.remove(i);
}
}
}
if(eqv == Detail::CloseEquidistant){
points.append(points.at(0));
}
for (qint32 i = 0; i < points.size(); ++i ){
if ( i == 0 && eqv == Detail::CloseEquidistant){//перша точка, ламана замкнена
ekvPoints<<EkvPoint(QLineF(points[points.size()-2], points[points.size()-1]),
QLineF(points[1], points[0]), width);
continue;
} else if(i == 0 && eqv == Detail::OpenEquidistant){//перша точка, ламана не замкнена
ekvPoints.append(SingleParallelPoint(QLineF(points[0], points[1]), 90, width));
continue;
}
if(i == points.size()-1 && eqv == Detail::CloseEquidistant){//остання точка, ламана замкнена
ekvPoints.append(ekvPoints.at(0));
continue;
} else if(i == points.size()-1 && eqv == Detail::OpenEquidistant){//остання точка, ламана не замкнена
ekvPoints.append(SingleParallelPoint(QLineF(points[points.size()-1],
points[points.size()-2]), -90, width));
continue;
}
//точка яка не лежить ні на початку ні в кінці
ekvPoints<<EkvPoint(QLineF(points[i-1], points[i]), QLineF(points[i+1], points[i]), width);
}
ekv.moveTo(ekvPoints[0]);
for (qint32 i = 1; i < ekvPoints.count(); ++i){
ekv.lineTo(ekvPoints[i]);
}
return ekv;
}
QLineF VContainer::ParallelLine(const QLineF &line, qreal width) const{
Q_ASSERT(width > 0);
QLineF paralel = QLineF (SingleParallelPoint(line, 90, width),
SingleParallelPoint(QLineF(line.p2(), line.p1()), -90, width));
return paralel;
}
QPointF VContainer::SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width) const{
Q_ASSERT(width > 0);
QLineF l = line;
l.setAngle( l.angle() + angle );
l.setLength( width );
return l.p2();
}
QVector<QPointF> VContainer::EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width) const{
Q_ASSERT(width > 0);
QVector<QPointF> points;
if(line1.p2() != line2.p2()){
qWarning()<<"Last point of two lines must be equal.";
}
QPointF CrosPoint;
QLineF bigLine1 = ParallelLine(line1, width );
QLineF bigLine2 = ParallelLine(QLineF(line2.p2(), line2.p1()), width );
QLineF::IntersectType type = bigLine1.intersect( bigLine2, &CrosPoint );
switch(type){
case(QLineF::BoundedIntersection):
points.append(CrosPoint);
return points;
break;
case(QLineF::UnboundedIntersection):{
QLineF line( line1.p2(), CrosPoint );
if(line.length() > width + toPixel(3)){
points.append(bigLine1.p2());
line.setLength( width );
points.append(line.p2() );
points.append(bigLine2.p1());
} else {
points.append(CrosPoint);
return points;
}
break;
}
case(QLineF::NoIntersection):
/*If we have correct lines this means lines lie on a line.*/
points.append(bigLine1.p2());
return points;
break;
}
return points;
}
void VContainer::PrepareDetails(QVector<VItem *> &list) const{ void VContainer::PrepareDetails(QVector<VItem *> &list) const{
QMapIterator<qint64, VDetail> iDetail(details); QMapIterator<qint64, VDetail> iDetail(details);
while (iDetail.hasNext()) { while (iDetail.hasNext()) {
@ -279,6 +382,7 @@ void VContainer::RemoveIncrementTableRow(const QString& name){
template <typename val> template <typename val>
void VContainer::UpdateObject(QMap<qint64, val> &obj, const qint64 &id, const val& point){ void VContainer::UpdateObject(QMap<qint64, val> &obj, const qint64 &id, const val& point){
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
obj[id] = point; obj[id] = point;
UpdateId(id); UpdateId(id);
} }

View File

@ -122,6 +122,11 @@ public:
void UpdateId(qint64 newId); void UpdateId(qint64 newId);
void IncrementReferens(qint64 id, Scene::Type obj, Draw::Mode mode = Draw::Calculation); void IncrementReferens(qint64 id, Scene::Type obj, Draw::Mode mode = Draw::Calculation);
QPainterPath ContourPath(qint64 idDetail) const; QPainterPath ContourPath(qint64 idDetail) const;
QPainterPath Equidistant(QVector<QPointF> points, const Detail::Equidistant &eqv,
const qreal &width)const;
QLineF ParallelLine(const QLineF &line, qreal width ) const;
QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width)const;
QVector<QPointF> EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width)const;
void PrepareDetails(QVector<VItem*> & list)const; void PrepareDetails(QVector<VItem*> & list)const;
private: private:
static qint64 _id; static qint64 _id;

View File

@ -3,6 +3,7 @@
#include <QCloseEvent> #include <QCloseEvent>
#include "container/calculator.h" #include "container/calculator.h"
#include "geometry/vdetail.h" #include "geometry/vdetail.h"
#include <QDebug>
DialogTool::DialogTool(const VContainer *data, Draw::Mode mode, QWidget *parent):QDialog(parent), data(data), DialogTool::DialogTool(const VContainer *data, Draw::Mode mode, QWidget *parent):QDialog(parent), data(data),
isInitialized(false), flagName(true), flagFormula(true), timerFormula(0), bOk(0), spinBoxAngle(0), isInitialized(false), flagName(true), flagFormula(true), timerFormula(0), bOk(0), spinBoxAngle(0),

View File

@ -6,6 +6,20 @@
#include <QString> #include <QString>
#include <QPainterPath> #include <QPainterPath>
namespace Detail{
enum Contour
{
OpenContour,
CloseContour
};
enum Equidistant
{
OpenEquidistant,
CloseEquidistant
};
}
class VDetail class VDetail
{ {
public: public:

View File

@ -771,12 +771,27 @@ QVector<QPointF> VSpline::SplinePoints(QPointF p1, QPointF p4, qreal angle1, qre
return GetPoints(p1, p2, p3, p4); return GetPoints(p1, p2, p3, p4);
} }
qint64 VSpline::getIdObject() const qint64 VSpline::getIdObject() const{
{
return idObject; return idObject;
} }
void VSpline::setIdObject(const qint64 &value) void VSpline::setIdObject(const qint64 &value){
{
idObject = value; idObject = value;
} }
const VSpline &VSpline::operator =(const VSpline &spline){
this->p1 = spline.GetP1 ();
this->p2 = spline.GetP2 ();
this->p3 = spline.GetP3 ();
this->p4 = spline.GetP4 ();
this->angle1 = spline.GetAngle1 ();
this->angle2 = spline.GetAngle2 ();
this->kAsm1 = spline.GetKasm1();
this->kAsm2 = spline.GetKasm2();
this->kCurve = spline.GetKcurve();
this->points = spline.GetDataPoints();
this->_referens = 0;
this->mode = spline.getMode();
this->idObject = spline.getIdObject();
return *this;
}

View File

@ -168,7 +168,7 @@ public:
qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve); qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve);
qint64 getIdObject() const; qint64 getIdObject() const;
void setIdObject(const qint64 &value); void setIdObject(const qint64 &value);
const VSpline &operator=(const VSpline &spl);
protected: protected:
/** /**
* @brief GetPoints повертає точки з яких складається сплайн. * @brief GetPoints повертає точки з яких складається сплайн.

View File

@ -1,4 +1,5 @@
#include "vdrawtool.h" #include "vdrawtool.h"
#include <QDebug>
VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) : VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) :
VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false),

View File

@ -4,6 +4,7 @@ VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64
const QString &typeLine, const QString &formula, const qint64 &basePointId, const QString &typeLine, const QString &formula, const qint64 &basePointId,
const qint32 &angle, QGraphicsItem *parent):VToolPoint(doc, data, id, parent), const qint32 &angle, QGraphicsItem *parent):VToolPoint(doc, data, id, parent),
typeLine(typeLine), formula(formula), angle(angle), basePointId(basePointId), mainLine(0){ typeLine(typeLine), formula(formula), angle(angle), basePointId(basePointId), mainLine(0){
Q_ASSERT_X(basePointId > 0, Q_FUNC_INFO, "basePointId <= 0");
//Лінія, що з'єднує дві точки //Лінія, що з'єднує дві точки
QPointF point1 = data->GetPoint(basePointId).toQPointF(); QPointF point1 = data->GetPoint(basePointId).toQPointF();
QPointF point2 = data->GetPoint(id).toQPointF(); QPointF point2 = data->GetPoint(id).toQPointF();

View File

@ -78,10 +78,7 @@ VModelingSpline *VModelingSpline::Create(const qint64 _id, const qint64 &p1, con
} else { } else {
data->UpdateModelingSpline(id, spline); data->UpdateModelingSpline(id, spline);
if(parse != Document::FullParse){ if(parse != Document::FullParse){
QMap<qint64, VDataTool*>* tools = doc->getTools(); doc->UpdateToolData(id, data);
VDataTool *tool = tools->value(id);
Q_CHECK_PTR(tool);
tool->VDataTool::setData(data);
data->IncrementReferens(id, Scene::Spline, Draw::Modeling); data->IncrementReferens(id, Scene::Spline, Draw::Modeling);
} }
} }
@ -136,7 +133,7 @@ void VModelingSpline::FullUpdateFromGui(int result){
} }
void VModelingSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, void VModelingSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position,
const QPointF pos){ const QPointF pos){
Q_UNUSED(indexSpline); Q_UNUSED(indexSpline);
VSpline spl = VAbstractTool::data.GetModelingSpline(id); VSpline spl = VAbstractTool::data.GetModelingSpline(id);
if(position == SplinePoint::FirstPoint){ if(position == SplinePoint::FirstPoint){

View File

@ -1,4 +1,5 @@
#include "vmodelingtool.h" #include "vmodelingtool.h"
#include <QDebug>
VModelingTool::VModelingTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent): VModelingTool::VModelingTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent):
VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false){ VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false){

View File

@ -17,6 +17,5 @@ VContainer VDataTool::getData() const{
} }
void VDataTool::setData(const VContainer *value){ void VDataTool::setData(const VContainer *value){
data.Clear();
data = *value; data = *value;
} }

View File

@ -157,8 +157,8 @@ void VToolDetail::setDialog(){
} }
} }
void VToolDetail::Create(QSharedPointer<DialogDetail> &dialog, VMainGraphicsScene *scene, VDomDocument *doc, void VToolDetail::Create(QSharedPointer<DialogDetail> &dialog, VMainGraphicsScene *scene,
VContainer *data){ VDomDocument *doc, VContainer *data){
VDetail detail = dialog->getDetails(); VDetail detail = dialog->getDetails();
VDetail det; VDetail det;
for(qint32 i = 0; i< detail.CountNode(); ++i){ for(qint32 i = 0; i< detail.CountNode(); ++i){
@ -302,7 +302,7 @@ void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
void VToolDetail::AddNode(QDomElement &domElement, VNodeDetail &node){ void VToolDetail::AddNode(QDomElement &domElement, VNodeDetail &node){
QDomElement nod = doc->createElement("node"); QDomElement nod = doc->createElement("node");
AddAttribute(nod, "id", node.getId()); AddAttribute(nod, "idObject", node.getId());
if(node.getTypeNode() == NodeDetail::Contour){ if(node.getTypeNode() == NodeDetail::Contour){
AddAttribute(nod, "nodeType", "Contour"); AddAttribute(nod, "nodeType", "Contour");
} else { } else {

View File

@ -46,18 +46,8 @@ void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){
QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){
if (change == ItemPositionChange && scene()) { if (change == ItemPositionChange && scene()) {
// value - это новое положение. // value - new position.
QPointF newPos = value.toPointF(); QPointF newPos = value.toPointF();
// qDebug()<<this->rect();
// QRectF rect = scene()->sceneRect();
// if (!rect.contains(newPos)) {
// // Сохраняем элемент внутри прямоугольника сцены.
// newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
// newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
// emit ControlPointChangePosition(indexSpline, position, newPos);
// return newPos;
// }
emit ControlPointChangePosition(indexSpline, position, newPos); emit ControlPointChangePosition(indexSpline, position, newPos);
} }
return QGraphicsItem::itemChange(change, value); return QGraphicsItem::itemChange(change, value);

View File

@ -82,6 +82,7 @@ void VDomDocument::CreateEmptyFile(){
} }
bool VDomDocument::CheckNameDraw(const QString& name) const{ bool VDomDocument::CheckNameDraw(const QString& name) const{
Q_ASSERT_X(!name.isEmpty(), "CheckNameDraw", "name draw is empty");
QDomNodeList elements = this->documentElement().elementsByTagName( "draw" ); QDomNodeList elements = this->documentElement().elementsByTagName( "draw" );
if(elements.size() == 0){ if(elements.size() == 0){
return false; return false;
@ -99,6 +100,7 @@ bool VDomDocument::CheckNameDraw(const QString& name) const{
} }
bool VDomDocument::appendDraw(const QString& name){ bool VDomDocument::appendDraw(const QString& name){
Q_ASSERT_X(!name.isEmpty(), "appendDraw", "name draw is empty");
if(name.isEmpty()){ if(name.isEmpty()){
return false; return false;
} }
@ -132,6 +134,7 @@ bool VDomDocument::appendDraw(const QString& name){
} }
void VDomDocument::ChangeActivDraw(const QString& name, Document::Enum parse){ void VDomDocument::ChangeActivDraw(const QString& name, Document::Enum parse){
Q_ASSERT_X(!name.isEmpty(), "ChangeActivDraw", "name draw is empty");
if(CheckNameDraw(name) == true){ if(CheckNameDraw(name) == true){
this->nameActivDraw = name; this->nameActivDraw = name;
if(parse == Document::FullParse){ if(parse == Document::FullParse){
@ -141,12 +144,14 @@ void VDomDocument::ChangeActivDraw(const QString& name, Document::Enum parse){
} }
void VDomDocument::SetNameDraw(const QString& name){ void VDomDocument::SetNameDraw(const QString& name){
Q_ASSERT_X(!name.isEmpty(), "SetNameDraw", "name draw is empty");
QString oldName = nameActivDraw; QString oldName = nameActivDraw;
nameActivDraw = name; nameActivDraw = name;
emit ChangedNameDraw(oldName, nameActivDraw); emit ChangedNameDraw(oldName, nameActivDraw);
} }
void VDomDocument::SetActivDraw(const QString& name){ void VDomDocument::SetActivDraw(const QString& name){
Q_ASSERT_X(!name.isEmpty(), "SetActivDraw", "name draw is empty");
this->nameActivDraw = name; this->nameActivDraw = name;
} }
@ -201,6 +206,7 @@ bool VDomDocument::GetActivDetailsElement(QDomElement &element){
} }
bool VDomDocument::GetActivNodeElement(const QString& name, QDomElement &element){ bool VDomDocument::GetActivNodeElement(const QString& name, QDomElement &element){
Q_ASSERT_X(!name.isEmpty(), "GetActivNodeElement", "name draw is empty");
QDomElement drawElement; QDomElement drawElement;
bool drawOk = this->GetActivDrawElement(drawElement); bool drawOk = this->GetActivDrawElement(drawElement);
if(drawOk == true){ if(drawOk == true){
@ -219,7 +225,10 @@ bool VDomDocument::GetActivNodeElement(const QString& name, QDomElement &element
} }
} }
void VDomDocument::Parse(Document::Enum parse, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail){ void VDomDocument::Parse(Document::Enum parse, VMainGraphicsScene *sceneDraw,
VMainGraphicsScene *sceneDetail){
Q_CHECK_PTR(sceneDraw);
Q_CHECK_PTR(sceneDetail);
if(parse == Document::FullParse){ if(parse == Document::FullParse){
data->Clear(); data->Clear();
nameActivDraw.clear(); nameActivDraw.clear();
@ -277,16 +286,12 @@ void VDomDocument::ParseIncrementsElement(const QDomNode &node){
QDomElement domElement = domNode.toElement(); QDomElement domElement = domNode.toElement();
if(!domElement.isNull()){ if(!domElement.isNull()){
if(domElement.tagName() == "increment"){ if(domElement.tagName() == "increment"){
QString name,desc; qint64 id = GetParametrId(domElement);
qreal base; QString name = GetParametrString(domElement, "name");
qreal ksize, kgrowth; qreal base = GetParametrDouble(domElement, "base");
qint64 id; qreal ksize = GetParametrDouble(domElement, "ksize");
id = domElement.attribute("id", "").toLongLong(); qreal kgrowth = GetParametrDouble(domElement, "kgrowth");
name = domElement.attribute("name", ""); QString desc = GetParametrString(domElement, "description");
base = domElement.attribute("base","").toDouble();
ksize = domElement.attribute("ksize","").toDouble();
kgrowth = domElement.attribute("kgrowth","").toDouble();
desc = domElement.attribute("description","");
data->UpdateId(id); data->UpdateId(id);
data->AddIncrementTableRow(name, data->AddIncrementTableRow(name,
VIncrementTableRow(id, base, ksize, kgrowth, desc)); VIncrementTableRow(id, base, ksize, kgrowth, desc));
@ -297,6 +302,48 @@ void VDomDocument::ParseIncrementsElement(const QDomNode &node){
} }
} }
qint64 VDomDocument::GetParametrId(const QDomElement &domElement) const{
qint64 id = GetParametrLongLong(domElement, "id");
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
return id;
}
qint64 VDomDocument::GetParametrLongLong(const QDomElement &domElement, const QString &name) const{
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
bool ok = false;
QString parametr = GetParametrString(domElement, name);
qint64 id = parametr.toLongLong(&ok);
QString error("can't convert parametr ");
error.append(name);
Q_ASSERT_X(ok, Q_FUNC_INFO, error.toLatin1().data());
return id;
}
QString VDomDocument::GetParametrString(const QDomElement &domElement, const QString &name) const{
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
QString parametr = domElement.attribute(name, "");
QString error("get empty parametr ");
error.append(name);
Q_ASSERT_X(!parametr.isEmpty(), Q_FUNC_INFO, error.toLatin1().data());
return parametr;
}
qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QString &name) const{
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
bool ok = false;
QString parametr = GetParametrString(domElement, name);
qreal param = parametr.toDouble(&ok);
QString error("can't convert parametr ");
error.append(name);
Q_ASSERT_X(ok, Q_FUNC_INFO, error.toLatin1().data());
return param;
}
void VDomDocument::ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, void VDomDocument::ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
const QDomNode& node, Document::Enum parse){ const QDomNode& node, Document::Enum parse){
QDomNode domNode = node.firstChild(); QDomNode domNode = node.firstChild();
@ -322,6 +369,8 @@ void VDomDocument::ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphics
void VDomDocument::ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, void VDomDocument::ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
const QDomNode& node, Document::Enum parse, Draw::Mode mode){ const QDomNode& node, Document::Enum parse, Draw::Mode mode){
Q_CHECK_PTR(sceneDraw);
Q_CHECK_PTR(sceneDetail);
VMainGraphicsScene *scene = 0; VMainGraphicsScene *scene = 0;
if(mode == Draw::Calculation){ if(mode == Draw::Calculation){
scene = sceneDraw; scene = sceneDraw;
@ -351,78 +400,80 @@ void VDomDocument::ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsSce
void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
Document::Enum parse){ Document::Enum parse){
if(!domElement.isNull()){ Q_CHECK_PTR(sceneDetail);
VDetail detail; Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
VDetail oldDetail; VDetail detail;
qint64 id = domElement.attribute("id", "").toLongLong(); VDetail oldDetail;
detail.setName(domElement.attribute("name", "")); qint64 id = GetParametrId(domElement);
detail.setMx(toPixel(domElement.attribute("mx","").toDouble())); detail.setName(GetParametrString(domElement, "name"));
detail.setMy(toPixel(domElement.attribute("my","").toDouble())); detail.setMx(toPixel(GetParametrDouble(domElement, "mx")));
detail.setMy(toPixel(GetParametrDouble(domElement, "my")));
QDomNodeList nodeList = domElement.childNodes(); QDomNodeList nodeList = domElement.childNodes();
qint32 num = nodeList.size(); qint32 num = nodeList.size();
for(qint32 i = 0; i < num; ++i){ for(qint32 i = 0; i < num; ++i){
QDomElement element = nodeList.at(i).toElement(); QDomElement element = nodeList.at(i).toElement();
if(!element.isNull()){ if(!element.isNull()){
if(element.tagName() == "node"){ if(element.tagName() == "node"){
qint64 id = element.attribute("id","").toLongLong(); qint64 id = GetParametrLongLong(element, "idObject");
Tools::Enum tool; Tools::Enum tool;
Draw::Mode mode; Draw::Mode mode;
NodeDetail::Type nodeType = NodeDetail::Contour; NodeDetail::Type nodeType = NodeDetail::Contour;
QString t = element.attribute("type",""); QString t = GetParametrString(element, "type");
if(t == "NodePoint"){ if(t == "NodePoint"){
tool = Tools::NodePoint; tool = Tools::NodePoint;
VPointF point = data->GetModelingPoint(id); VPointF point = data->GetModelingPoint(id);
mode = point.getMode(); mode = point.getMode();
oldDetail.append(VNodeDetail(point.getIdObject(), tool, mode, NodeDetail::Contour)); oldDetail.append(VNodeDetail(point.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "NodeArc"){ } else if(t == "NodeArc"){
tool = Tools::NodeArc; tool = Tools::NodeArc;
VArc arc = data->GetModelingArc(id); VArc arc = data->GetModelingArc(id);
mode = arc.getMode(); mode = arc.getMode();
oldDetail.append(VNodeDetail(arc.getIdObject(), tool, mode, NodeDetail::Contour)); oldDetail.append(VNodeDetail(arc.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "NodeSpline"){ } else if(t == "NodeSpline"){
tool = Tools::NodeSpline; tool = Tools::NodeSpline;
VSpline spl = data->GetModelingSpline(id); VSpline spl = data->GetModelingSpline(id);
mode = spl.getMode(); mode = spl.getMode();
oldDetail.append(VNodeDetail(spl.getIdObject(), tool, mode, NodeDetail::Contour)); oldDetail.append(VNodeDetail(spl.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "NodeSplinePath"){ } else if(t == "NodeSplinePath"){
tool = Tools::NodeSplinePath; tool = Tools::NodeSplinePath;
VSplinePath splPath = data->GetModelingSplinePath(id); VSplinePath splPath = data->GetModelingSplinePath(id);
mode = splPath.getMode(); mode = splPath.getMode();
oldDetail.append(VNodeDetail(splPath.getIdObject(), tool, mode, NodeDetail::Contour)); oldDetail.append(VNodeDetail(splPath.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "AlongLineTool"){ } else if(t == "AlongLineTool"){
tool = Tools::AlongLineTool; tool = Tools::AlongLineTool;
} else if(t == "ArcTool"){ } else if(t == "ArcTool"){
tool = Tools::ArcTool; tool = Tools::ArcTool;
} else if(t == "BisectorTool"){ } else if(t == "BisectorTool"){
tool = Tools::BisectorTool; tool = Tools::BisectorTool;
} else if(t == "EndLineTool"){ } else if(t == "EndLineTool"){
tool = Tools::EndLineTool; tool = Tools::EndLineTool;
} else if(t == "LineIntersectTool"){ } else if(t == "LineIntersectTool"){
tool = Tools::LineIntersectTool; tool = Tools::LineIntersectTool;
} else if(t == "LineTool"){ } else if(t == "LineTool"){
tool = Tools::LineTool; tool = Tools::LineTool;
} else if(t == "NormalTool"){ } else if(t == "NormalTool"){
tool = Tools::NormalTool; tool = Tools::NormalTool;
} else if(t == "PointOfContact"){ } else if(t == "PointOfContact"){
tool = Tools::PointOfContact; tool = Tools::PointOfContact;
} else if(t == "ShoulderPointTool"){ } else if(t == "ShoulderPointTool"){
tool = Tools::ShoulderPointTool; tool = Tools::ShoulderPointTool;
} else if(t == "SplinePathTool"){ } else if(t == "SplinePathTool"){
tool = Tools::SplinePathTool; tool = Tools::SplinePathTool;
} else if(t == "SplineTool"){ } else if(t == "SplineTool"){
tool = Tools::SplineTool; tool = Tools::SplineTool;
}
detail.append(VNodeDetail(id, tool, mode, nodeType));
} }
detail.append(VNodeDetail(id, tool, mode, nodeType));
} }
} }
VToolDetail::Create(id, detail, oldDetail, sceneDetail, this, data, parse, Tool::FromFile);
} }
VToolDetail::Create(id, detail, oldDetail, sceneDetail, this, data, parse, Tool::FromFile);
} }
void VDomDocument::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, void VDomDocument::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
Document::Enum parse){ Document::Enum parse){
Q_CHECK_PTR(sceneDetail);
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
QDomNode domNode = domElement.firstChild(); QDomNode domNode = domElement.firstChild();
while(!domNode.isNull()){ while(!domNode.isNull()){
if(domNode.isElement()){ if(domNode.isElement()){
@ -439,307 +490,285 @@ void VDomDocument::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomEleme
void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement,
Document::Enum parse, const QString& type, Draw::Mode mode){ Document::Enum parse, const QString& type, Draw::Mode mode){
Q_CHECK_PTR(scene);
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of point is empty");
if(type == "single"){ if(type == "single"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); QString name = GetParametrString(domElement, "name");
Q_ASSERT(id > 0); qreal x = toPixel(GetParametrDouble(domElement, "x"));
QString name = domElement.attribute("name", ""); qreal y = toPixel(GetParametrDouble(domElement, "y"));
qreal x = domElement.attribute("x","").toDouble()*PrintDPI/25.4; qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal y = domElement.attribute("y","").toDouble()*PrintDPI/25.4; qreal my = toPixel(GetParametrDouble(domElement, "my"));
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
data->UpdatePoint(id, VPointF(x, y, name, mx, my)); data->UpdatePoint(id, VPointF(x, y, name, mx, my));
VDrawTool::AddRecord(id, Tools::SinglePointTool, this); VDrawTool::AddRecord(id, Tools::SinglePointTool, this);
if(parse != Document::FullParse){ if(parse != Document::FullParse){
VDataTool *tool = tools.value(id); UpdateToolData(id, data);
Q_CHECK_PTR(tool); }
tool->VDataTool::setData(data); if(parse == Document::FullParse){
} VToolSinglePoint *spoint = new VToolSinglePoint(this, data, id, Tool::FromFile);
if(parse == Document::FullParse){ Q_CHECK_PTR(spoint);
VToolSinglePoint *spoint = new VToolSinglePoint(this, data, id, Tool::FromFile); scene->addItem(spoint);
scene->addItem(spoint); connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); tools[id] = spoint;
tools[id] = spoint;
}
} }
return; return;
} }
if(type == "endLine"){ if(type == "endLine"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); QString name = GetParametrString(domElement, "name");
QString name = domElement.attribute("name", ""); qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qreal my = toPixel(GetParametrDouble(domElement, "my"));
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; QString typeLine = GetParametrString(domElement, "typeLine");
QString typeLine = domElement.attribute("typeLine", ""); QString formula = GetParametrString(domElement, "length");
QString formula = domElement.attribute("length", ""); qint64 basePointId = GetParametrLongLong(domElement, "basePoint");
qint64 basePointId = domElement.attribute("basePoint", "").toLongLong(); qreal angle = GetParametrDouble(domElement, "angle");
qint32 angle = domElement.attribute("angle", "").toInt(); if(mode == Draw::Calculation){
if(mode == Draw::Calculation){ VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, scene, this,
VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, scene, this, data, parse, Tool::FromFile);
} else {
VModelingEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, this,
data, parse, Tool::FromFile); data, parse, Tool::FromFile);
} else {
VModelingEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, this,
data, parse, Tool::FromFile);
}
} }
return; return;
} }
if(type == "alongLine"){ if(type == "alongLine"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); QString name = GetParametrString(domElement, "name");
QString name = domElement.attribute("name", ""); qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qreal my = toPixel(GetParametrDouble(domElement, "my"));
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; QString typeLine = GetParametrString(domElement, "typeLine");
QString typeLine = domElement.attribute("typeLine", ""); QString formula = GetParametrString(domElement, "length");
QString formula = domElement.attribute("length", ""); qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong(); qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong(); if(mode == Draw::Calculation){
if(mode == Draw::Calculation){ VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my,
VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my, scene, this, data, parse, Tool::FromFile);
scene, this, data, parse, Tool::FromFile); } else {
} else { VModelingAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my,
VModelingAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my, this, data, parse, Tool::FromFile);
this, data, parse, Tool::FromFile);
}
} }
return; return;
} }
if(type == "shoulder"){ if(type == "shoulder"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); QString name = GetParametrString(domElement, "name");
QString name = domElement.attribute("name", ""); qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qreal my = toPixel(GetParametrDouble(domElement, "my"));
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; QString typeLine = GetParametrString(domElement, "typeLine");
QString typeLine = domElement.attribute("typeLine", ""); QString formula = GetParametrString(domElement, "length");
QString formula = domElement.attribute("length", ""); qint64 p1Line = GetParametrLongLong(domElement, "p1Line");
qint64 p1Line = domElement.attribute("p1Line", "").toLongLong(); qint64 p2Line = GetParametrLongLong(domElement, "p2Line");
qint64 p2Line = domElement.attribute("p2Line", "").toLongLong(); qint64 pShoulder = GetParametrLongLong(domElement, "pShoulder");
qint64 pShoulder = domElement.attribute("pShoulder", "").toLongLong(); if(mode == Draw::Calculation){
if(mode == Draw::Calculation){ VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my,
VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my, scene, this, data, parse, Tool::FromFile);
scene, this, data, parse, Tool::FromFile); } else {
} else { VModelingShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx,
VModelingShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my, this, data, parse, Tool::FromFile);
my, this, data, parse, Tool::FromFile);
}
} }
return; return;
} }
if(type == "normal"){ if(type == "normal"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); QString name = GetParametrString(domElement, "name");
QString name = domElement.attribute("name", ""); qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qreal my = toPixel(GetParametrDouble(domElement, "my"));
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; QString typeLine = GetParametrString(domElement, "typeLine");
QString typeLine = domElement.attribute("typeLine", ""); QString formula = GetParametrString(domElement, "length");
QString formula = domElement.attribute("length", ""); qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong(); qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong(); qreal angle = GetParametrDouble(domElement, "angle");
qreal angle = domElement.attribute("angle", "").toDouble(); if(mode == Draw::Calculation){
if(mode == Draw::Calculation){ VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle,
VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle, mx, my, scene, this, data, parse, Tool::FromFile);
mx, my, scene, this, data, parse, Tool::FromFile); } else {
} else { VModelingNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle,
VModelingNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle, mx, my, this, data, parse, Tool::FromFile);
mx, my, this, data, parse, Tool::FromFile);
}
} }
return; return;
} }
if(type == "bisector"){ if(type == "bisector"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); QString name = GetParametrString(domElement, "name");
QString name = domElement.attribute("name", ""); qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qreal my = toPixel(GetParametrDouble(domElement, "my"));
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; QString typeLine = GetParametrString(domElement, "typeLine");
QString typeLine = domElement.attribute("typeLine", ""); QString formula = GetParametrString(domElement, "length");
QString formula = domElement.attribute("length", ""); qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong(); qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong(); qint64 thirdPointId = GetParametrLongLong(domElement, "thirdPoint");
qint64 thirdPointId = domElement.attribute("thirdPoint", "").toLongLong(); if(mode == Draw::Calculation){
if(mode == Draw::Calculation){ VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine,
VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine, name, mx, my, scene, this, data, parse, Tool::FromFile);
name, mx, my, scene, this, data, parse, Tool::FromFile); } else {
} else { VModelingBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine,
VModelingBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine, name, mx, my, this, data, parse, Tool::FromFile);
name, mx, my, this, data, parse, Tool::FromFile);
}
} }
return; return;
} }
if(type == "lineIntersect"){ if(type == "lineIntersect"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); QString name = GetParametrString(domElement, "name");
QString name = domElement.attribute("name", ""); qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qreal my = toPixel(GetParametrDouble(domElement, "my"));
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; qint64 p1Line1Id = GetParametrLongLong(domElement, "p1Line1");
qint64 p1Line1Id = domElement.attribute("p1Line1", "").toLongLong(); qint64 p2Line1Id = GetParametrLongLong(domElement, "p2Line1");
qint64 p2Line1Id = domElement.attribute("p2Line1", "").toLongLong(); qint64 p1Line2Id = GetParametrLongLong(domElement, "p1Line2");
qint64 p1Line2Id = domElement.attribute("p1Line2", "").toLongLong(); qint64 p2Line2Id = GetParametrLongLong(domElement, "p2Line2");
qint64 p2Line2Id = domElement.attribute("p2Line2", "").toLongLong(); if(mode == Draw::Calculation){
if(mode == Draw::Calculation){ VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my,
VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my, scene, this, data, parse, Tool::FromFile);
scene, this, data, parse, Tool::FromFile); } else {
} else { VModelingLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my,
VModelingLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my, this, data, parse, Tool::FromFile);
this, data, parse, Tool::FromFile);
}
} }
return; return;
} }
if(type == "pointOfContact"){ if(type == "pointOfContact"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); QString name = GetParametrString(domElement, "name");
QString name = domElement.attribute("name", ""); qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4; qreal my = toPixel(GetParametrDouble(domElement, "my"));
qreal my = domElement.attribute("my","").toDouble()*PrintDPI/25.4; QString radius = GetParametrString(domElement, "radius");
QString radius = domElement.attribute("radius", ""); qint64 center = GetParametrLongLong(domElement, "center");
qint64 center = domElement.attribute("center", "").toLongLong(); qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 firstPointId = domElement.attribute("firstPoint", "").toLongLong(); qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
qint64 secondPointId = domElement.attribute("secondPoint", "").toLongLong(); if(mode == Draw::Calculation){
if(mode == Draw::Calculation){ VToolPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my,
VToolPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my, scene, this, data, parse, Tool::FromFile);
scene, this, data, parse, Tool::FromFile); } else {
} else { VModelingPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx,
VModelingPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my, this, data, parse, Tool::FromFile);
my, this, data, parse, Tool::FromFile);
}
} }
return; return;
} }
if(type == "modeling"){ if(type == "modeling"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); qint64 idObject = GetParametrLongLong(domElement, "idObject");
qint64 idObject = domElement.attribute("idObject", "").toLongLong(); QString tObject = GetParametrString(domElement, "typeObject");
QString tObject = domElement.attribute("typeObject", ""); VPointF point;
VPointF point; Draw::Mode typeObject;
Draw::Mode typeObject; if(tObject == "Calculation"){
if(tObject == "Calculation"){ typeObject = Draw::Calculation;
typeObject = Draw::Calculation; point = data->GetPoint(idObject );
point = data->GetPoint(idObject ); } else {
} else { typeObject = Draw::Modeling;
typeObject = Draw::Modeling; point = data->GetModelingPoint(idObject);
point = data->GetModelingPoint(idObject);
}
qreal mx = toPixel(domElement.attribute("mx","").toDouble());
qreal my = toPixel(domElement.attribute("my","").toDouble());
data->UpdateModelingPoint(id, VPointF(point.x(), point.y(), point.name(), mx, my, typeObject,
idObject ));
data->IncrementReferens(idObject, Scene::Point, typeObject);
} }
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
data->UpdateModelingPoint(id, VPointF(point.x(), point.y(), point.name(), mx, my, typeObject,
idObject ));
data->IncrementReferens(idObject, Scene::Point, typeObject);
return; return;
} }
} }
void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement, void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement,
Document::Enum parse, Draw::Mode mode){ Document::Enum parse, Draw::Mode mode){
if(!domElement.isNull()){ Q_CHECK_PTR(scene);
qint64 id = domElement.attribute("id", "").toLongLong(); Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
qint64 firstPoint = domElement.attribute("firstPoint", "").toLongLong(); qint64 id = GetParametrId(domElement);
qint64 secondPoint = domElement.attribute("secondPoint", "").toLongLong(); qint64 firstPoint = GetParametrLongLong(domElement, "firstPoint");
if(mode == Draw::Calculation){ qint64 secondPoint = GetParametrLongLong(domElement, "secondPoint");
VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile); if(mode == Draw::Calculation){
} else { VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile);
VModelingLine::Create(id, firstPoint, secondPoint, this, data, parse, Tool::FromFile); } else {
} VModelingLine::Create(id, firstPoint, secondPoint, this, data, parse, Tool::FromFile);
} }
} }
void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &domElement, void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &domElement,
Document::Enum parse, const QString &type, Draw::Mode mode){ Document::Enum parse, const QString &type, Draw::Mode mode){
Q_CHECK_PTR(scene);
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of spline is empty");
if(type == "simple"){ if(type == "simple"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); qint64 point1 = GetParametrLongLong(domElement, "point1");
qint64 point1 = domElement.attribute("point1", "").toLongLong(); qint64 point4 = GetParametrLongLong(domElement, "point4");
qint64 point4 = domElement.attribute("point4", "").toLongLong(); qreal angle1 = GetParametrDouble(domElement, "angle1");
qreal angle1 = domElement.attribute("angle1","").toDouble(); qreal angle2 = GetParametrDouble(domElement, "angle2");
qreal angle2 = domElement.attribute("angle2","").toDouble(); qreal kAsm1 = GetParametrDouble(domElement, "kAsm1");
qreal kAsm1 = domElement.attribute("kAsm1","").toDouble(); qreal kAsm2 = GetParametrDouble(domElement, "kAsm2");
qreal kAsm2 = domElement.attribute("kAsm2","").toDouble(); qreal kCurve = GetParametrDouble(domElement, "kCurve");
qreal kCurve = domElement.attribute("kCurve","").toDouble(); if(mode == Draw::Calculation){
if(mode == Draw::Calculation){ VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this,
VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data, parse, Tool::FromFile);
} else {
VModelingSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, this,
data, parse, Tool::FromFile); data, parse, Tool::FromFile);
} else {
VModelingSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, this,
data, parse, Tool::FromFile);
}
} }
return; return;
} }
if(type == "path"){ if(type == "path"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); qreal kCurve = GetParametrDouble(domElement, "kCurve");
qreal kCurve = domElement.attribute("kCurve","").toDouble(); VSplinePath path(data->DataPoints(), kCurve);
VSplinePath path(data->DataPoints(), kCurve);
QDomNodeList nodeList = domElement.childNodes(); QDomNodeList nodeList = domElement.childNodes();
qint32 num = nodeList.size(); qint32 num = nodeList.size();
for(qint32 i = 0; i < num; ++i){ for(qint32 i = 0; i < num; ++i){
QDomElement element = nodeList.at(i).toElement(); QDomElement element = nodeList.at(i).toElement();
if(!element.isNull()){ if(!element.isNull()){
if(element.tagName() == "pathPoint"){ if(element.tagName() == "pathPoint"){
qint64 pSpline = element.attribute("pSpline","").toLongLong(); qint64 pSpline = GetParametrLongLong(domElement, "pSpline");
qreal kAsm1 = element.attribute("kAsm1","").toDouble(); qreal kAsm1 = GetParametrDouble(domElement, "kAsm1");
qreal angle = element.attribute("angle","").toDouble(); qreal angle = GetParametrDouble(domElement, "angle");
qreal kAsm2 = element.attribute("kAsm2","").toDouble(); qreal kAsm2 = GetParametrDouble(domElement, "kAsm2");
VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2); VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2);
path.append(splPoint); path.append(splPoint);
}
} }
} }
if(mode == Draw::Calculation){ }
VToolSplinePath::Create(id, path, scene, this, data, parse, Tool::FromFile); if(mode == Draw::Calculation){
} else { VToolSplinePath::Create(id, path, scene, this, data, parse, Tool::FromFile);
VModelingSplinePath::Create(id, path, this, data, parse, Tool::FromFile); } else {
} VModelingSplinePath::Create(id, path, this, data, parse, Tool::FromFile);
} }
return; return;
} }
if(type == "modelingSpline"){ if(type == "modelingSpline"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); qint64 idObject = GetParametrLongLong(domElement, "idObject");
qint64 idObject = domElement.attribute("idObject", "").toLongLong(); QString tObject = GetParametrString(domElement, "typeObject");
QString tObject = domElement.attribute("typeObject", ""); VSpline spl;
VSpline spl; Draw::Mode typeObject;
Draw::Mode typeObject; if(tObject == "Calculation"){
if(tObject == "Calculation"){ typeObject = Draw::Calculation;
typeObject = Draw::Calculation; spl = data->GetSpline(idObject);
spl = data->GetSpline(idObject); } else {
} else { typeObject = Draw::Modeling;
typeObject = Draw::Modeling; spl = data->GetModelingSpline(idObject);
spl = data->GetModelingSpline(idObject);
}
spl.setMode(typeObject);
spl.setIdObject(idObject);
data->UpdateModelingSpline(id, spl);
data->IncrementReferens(spl.GetP1(), Scene::Point, Draw::Modeling);
data->IncrementReferens(spl.GetP4(), Scene::Point, Draw::Modeling);
} }
spl.setMode(typeObject);
spl.setIdObject(idObject);
data->UpdateModelingSpline(id, spl);
data->IncrementReferens(spl.GetP1(), Scene::Point, Draw::Modeling);
data->IncrementReferens(spl.GetP4(), Scene::Point, Draw::Modeling);
return; return;
} }
if(type == "modelingPath"){ if(type == "modelingPath"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); qint64 idObject = GetParametrLongLong(domElement, "idObject");
qint64 idObject = domElement.attribute("idObject", "").toLongLong(); QString tObject = GetParametrString(domElement, "typeObject");
QString tObject = domElement.attribute("typeObject", ""); VSplinePath path;
VSplinePath path; Draw::Mode typeObject;
Draw::Mode typeObject; if(tObject == "Calculation"){
if(tObject == "Calculation"){ typeObject = Draw::Calculation;
typeObject = Draw::Calculation; path = data->GetSplinePath(idObject);
path = data->GetSplinePath(idObject); } else {
} else { typeObject = Draw::Modeling;
typeObject = Draw::Modeling; path = data->GetModelingSplinePath(idObject);
path = data->GetModelingSplinePath(idObject); }
} path.setMode(typeObject);
path.setMode(typeObject); path.setIdObject(idObject);
path.setIdObject(idObject); data->UpdateModelingSplinePath(id, path);
data->UpdateModelingSplinePath(id, path); const QVector<VSplinePoint> *points = path.GetPoint();
const QVector<VSplinePoint> *points = path.GetPoint(); for(qint32 i = 0; i<points->size(); ++i){
for(qint32 i = 0; i<points->size(); ++i){ data->IncrementReferens(points->at(i).P(), Scene::Point, Draw::Modeling);
data->IncrementReferens(points->at(i).P(), Scene::Point, Draw::Modeling);
}
} }
return; return;
} }
@ -747,45 +776,45 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement &domElement, void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement &domElement,
Document::Enum parse, const QString &type, Draw::Mode mode){ Document::Enum parse, const QString &type, Draw::Mode mode){
Q_CHECK_PTR(scene);
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of spline is empty");
if(type == "simple"){ if(type == "simple"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); qint64 center = GetParametrLongLong(domElement, "center");
qint64 center = domElement.attribute("center", "").toLongLong(); QString radius = GetParametrString(domElement, "radius");
QString radius = domElement.attribute("radius", ""); QString f1 = GetParametrString(domElement, "angle1");
QString f1 = domElement.attribute("angle1", ""); QString f2 = GetParametrString(domElement, "angle2");
QString f2 = domElement.attribute("angle2",""); if(mode == Draw::Calculation){
if(mode == Draw::Calculation){ VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile);
VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile); } else {
} else { VModelingArc::Create(id, center, radius, f1, f2, this, data, parse, Tool::FromFile);
VModelingArc::Create(id, center, radius, f1, f2, this, data, parse, Tool::FromFile);
}
} }
return; return;
} }
if(type == "modeling"){ if(type == "modeling"){
if(!domElement.isNull()){ qint64 id = GetParametrId(domElement);
qint64 id = domElement.attribute("id", "").toLongLong(); qint64 idObject = GetParametrLongLong(domElement, "idObject");
qint64 idObject = domElement.attribute("idObject", "").toLongLong(); QString tObject = GetParametrString(domElement, "typeObject");
QString tObject = domElement.attribute("typeObject", ""); VArc arc;
VArc arc; Draw::Mode typeObject;
Draw::Mode typeObject; if(tObject == "Calculation"){
if(tObject == "Calculation"){ typeObject = Draw::Calculation;
typeObject = Draw::Calculation; arc = data->GetArc(idObject);
arc = data->GetArc(idObject); } else {
} else { typeObject = Draw::Modeling;
typeObject = Draw::Modeling; arc = data->GetModelingArc(idObject);
arc = data->GetModelingArc(idObject);
}
arc.setMode(typeObject);
arc.setIdObject(idObject);
data->UpdateModelingArc(id, arc);
} }
arc.setMode(typeObject);
arc.setIdObject(idObject);
data->UpdateModelingArc(id, arc);
return; return;
} }
} }
void VDomDocument::FullUpdateTree(){ void VDomDocument::FullUpdateTree(){
VMainGraphicsScene *scene = new VMainGraphicsScene(); VMainGraphicsScene *scene = new VMainGraphicsScene();
Q_CHECK_PTR(scene);
data->ClearObject(); data->ClearObject();
Parse(Document::LiteParse, scene, scene); Parse(Document::LiteParse, scene, scene);
delete scene; delete scene;
@ -843,6 +872,7 @@ void VDomDocument::setCurrentData(){
void VDomDocument::GarbageCollector(){ void VDomDocument::GarbageCollector(){
const QMap<qint64, VPointF> *points = data->DataPoints(); const QMap<qint64, VPointF> *points = data->DataPoints();
Q_CHECK_PTR(points);
QMapIterator<qint64, VPointF> p(*points); QMapIterator<qint64, VPointF> p(*points);
while (p.hasNext()) { while (p.hasNext()) {
p.next(); p.next();
@ -860,6 +890,7 @@ void VDomDocument::GarbageCollector(){
} }
const QMap<qint64, VArc> *arc = data->DataArcs(); const QMap<qint64, VArc> *arc = data->DataArcs();
Q_CHECK_PTR(arc);
QMapIterator<qint64, VArc> a(*arc); QMapIterator<qint64, VArc> a(*arc);
while (a.hasNext()) { while (a.hasNext()) {
a.next(); a.next();
@ -877,6 +908,7 @@ void VDomDocument::GarbageCollector(){
} }
const QMap<qint64, VSpline> *spl = data->DataSplines(); const QMap<qint64, VSpline> *spl = data->DataSplines();
Q_CHECK_PTR(spl);
QMapIterator<qint64, VSpline> s(*spl); QMapIterator<qint64, VSpline> s(*spl);
while (s.hasNext()) { while (s.hasNext()) {
s.next(); s.next();
@ -894,6 +926,7 @@ void VDomDocument::GarbageCollector(){
} }
const QMap<qint64, VSplinePath> *splPath = data->DataSplinePaths(); const QMap<qint64, VSplinePath> *splPath = data->DataSplinePaths();
Q_CHECK_PTR(splPath);
QMapIterator<qint64, VSplinePath> q(*splPath); QMapIterator<qint64, VSplinePath> q(*splPath);
while (q.hasNext()) { while (q.hasNext()) {
q.next(); q.next();
@ -912,15 +945,15 @@ void VDomDocument::GarbageCollector(){
} }
void VDomDocument::AddTool(const qint64 &id, VDataTool *tool){ void VDomDocument::AddTool(const qint64 &id, VDataTool *tool){
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
Q_CHECK_PTR(tool);
tools.insert(id, tool); tools.insert(id, tool);
} }
void VDomDocument::UpdateToolData(const qint64 &id, VContainer *data){ void VDomDocument::UpdateToolData(const qint64 &id, VContainer *data){
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
Q_CHECK_PTR(data);
VDataTool *tool = tools.value(id); VDataTool *tool = tools.value(id);
if(tool != 0){ Q_CHECK_PTR(tool);
tool->VDataTool::setData(data); tool->VDataTool::setData(data);
} else {
qWarning()<<"Can't find tool with id ="<< id<<".";
}
} }

View File

@ -78,11 +78,11 @@ private:
void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
const QDomNode& node, Document::Enum parse); const QDomNode& node, Document::Enum parse);
void ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, void ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
const QDomNode& node, Document::Enum parse, Draw::Mode mode); const QDomNode& node, Document::Enum parse, Draw::Mode mode);
void ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, void ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
Document::Enum parse); Document::Enum parse);
void ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, void ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
Document::Enum parse); Document::Enum parse);
void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement,
Document::Enum parse, const QString &type, Draw::Mode mode); Document::Enum parse, const QString &type, Draw::Mode mode);
void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement,
@ -90,8 +90,12 @@ private:
void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement,
Document::Enum parse, const QString& type, Draw::Mode mode); Document::Enum parse, const QString& type, Draw::Mode mode);
void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement,
Document::Enum parse, const QString& type, Draw::Mode mode); Document::Enum parse, const QString& type, Draw::Mode mode);
void ParseIncrementsElement(const QDomNode& node); void ParseIncrementsElement(const QDomNode& node);
qint64 GetParametrId(const QDomElement& domElement) const;
qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name) const;
QString GetParametrString(const QDomElement& domElement, const QString &name) const;
qreal GetParametrDouble(const QDomElement& domElement, const QString &name) const;
}; };
#pragma GCC diagnostic pop #pragma GCC diagnostic pop