Union details tool.

--HG--
branch : feature
This commit is contained in:
dismine 2014-01-02 17:50:01 +02:00
parent 3b1a654581
commit 7cf058bf70
30 changed files with 839 additions and 582 deletions

View File

@ -561,10 +561,11 @@ void VContainer::UpdateObject(QHash<qint64, val> &obj, const qint64 &id, val poi
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
Q_ASSERT(point != 0); Q_ASSERT(point != 0);
point->setId(id); point->setId(id);
// if (gObjects.contains(id)) if (gObjects.contains(id))
// { {
// delete gObjects.value(id); delete gObjects.value(id);
// } gObjects.remove(id);
}
obj[id] = point; obj[id] = point;
UpdateId(id); UpdateId(id);
} }
@ -620,10 +621,10 @@ void VContainer::Clear()
lengthArcs.clear(); lengthArcs.clear();
lineAngles.clear(); lineAngles.clear();
details.clear(); details.clear();
ClearObject(); ClearGObjects();
} }
void VContainer::ClearObject() void VContainer::ClearGObjects()
{ {
if (gObjects.size()>0) if (gObjects.size()>0)
{ {
@ -632,6 +633,23 @@ void VContainer::ClearObject()
gObjects.clear(); gObjects.clear();
} }
void VContainer::ClearCalculationGObjects()
{
if (gObjects.size()>0)
{
QHashIterator<qint64, VGObject*> i(gObjects);
while (i.hasNext())
{
i.next();
if (i.value()->getMode() == Draw::Calculation)
{
delete i.value();
gObjects.remove(i.key());
}
}
}
}
qreal VContainer::FindVar(const QString &name, bool *ok)const qreal VContainer::FindVar(const QString &name, bool *ok)const
{ {
if (base.contains(name)) if (base.contains(name))

View File

@ -263,7 +263,8 @@ public:
/** /**
* @brief ClearObject points, splines, arcs, spline paths will be cleared. * @brief ClearObject points, splines, arcs, spline paths will be cleared.
*/ */
void ClearObject(); void ClearGObjects();
void ClearCalculationGObjects();
/** /**
* @brief ClearIncrementTable clear increment table * @brief ClearIncrementTable clear increment table
*/ */

View File

@ -402,6 +402,20 @@ QString DialogHistory::Record(const VToolRecord &tool)
} }
} }
break; break;
//Because "history" not only show history of pattern, but help restore current data for each pattern's piece, we
//need add record about details and nodes, but don't show them.
case Tool::Detail:
break;
case Tool::UnionDetails:
break;
case Tool::NodeArc:
break;
case Tool::NodePoint:
break;
case Tool::NodeSpline:
break;
case Tool::NodeSplinePath:
break;
default: default:
qWarning()<<tr("Got wrong tool type. Ignore."); qWarning()<<tr("Got wrong tool type. Ignore.");
break; break;

View File

@ -30,8 +30,8 @@
#include "ui_dialoguniondetails.h" #include "ui_dialoguniondetails.h"
DialogUnionDetails::DialogUnionDetails(const VContainer *data, QWidget *parent) : DialogUnionDetails::DialogUnionDetails(const VContainer *data, QWidget *parent) :
DialogTool(data, parent), ui(new Ui::DialogUnionDetails), d1(0), d2(0), d1P1(0), d1P2(0), DialogTool(data, parent), ui(new Ui::DialogUnionDetails), indexD1(0), indexD2(0), d1(0), d2(0), numberD(0),
d2P1(0), d2P2(0), numberD(0), numberP(0) numberP(0), p1(0), p2(0)
{ {
ui->setupUi(this); ui->setupUi(this);
bOk = ui->buttonBox->button(QDialogButtonBox::Ok); bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
@ -49,11 +49,11 @@ void DialogUnionDetails::ChoosedObject(qint64 id, const Scene::Scenes &type)
{ {
if (numberD == 0) if (numberD == 0)
{ {
ChoosedDetail(id, type, d1, d1P1, d1P2); ChoosedDetail(id, type, d1, indexD1);
} }
else else
{ {
ChoosedDetail(id, type, d2, d2P1, d2P2); ChoosedDetail(id, type, d2, indexD2);
} }
} }
@ -72,8 +72,7 @@ bool DialogUnionDetails::CheckObject(const qint64 &id, const qint64 &idDetail) c
return det.Containes(id); return det.Containes(id);
} }
void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, qint64 &p1, void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, ptrdiff_t &index)
qint64 &p2)
{ {
if (idDetail == 0) if (idDetail == 0)
{ {
@ -95,25 +94,41 @@ void DialogUnionDetails::ChoosedDetail(const qint64 &id, const Scene::Scenes &ty
p1 = id; p1 = id;
++numberP; ++numberP;
emit ToolTip(tr("Select second point")); emit ToolTip(tr("Select second point"));
return;
} }
if (numberP == 1) if (numberP == 1)
{ {
if (id == p1) if (id == p1)
{ {
emit ToolTip(tr("Select another second point"));
return; return;
} }
p2 = id; VDetail d = data->GetDetail(idDetail);
++numberD; if (d.OnEdge(p1, id))
if (numberD > 1)
{ {
++numberP; p2 = id;
emit ToolTip(""); index = d.Edge(p1, p2);
this->show(); ++numberD;
if (numberD > 1)
{
++numberP;
emit ToolTip("");
this->show();
return;
}
else
{
numberP = 0;
p1 = 0;
p2 = 0;
emit ToolTip(tr("Select detail"));
return;
}
} }
else else
{ {
numberP = 0; emit ToolTip(tr("Select another second point"));
emit ToolTip(tr("Select detail")); return;
} }
} }
} }

View File

@ -42,12 +42,10 @@ class DialogUnionDetails : public DialogTool
public: public:
explicit DialogUnionDetails(const VContainer *data, QWidget *parent = 0); explicit DialogUnionDetails(const VContainer *data, QWidget *parent = 0);
~DialogUnionDetails(); ~DialogUnionDetails();
inline qint64 getD1() const {return d1;} inline qint64 getD1() const {return d1;}
inline qint64 getD2() const {return d2;} inline qint64 getD2() const {return d2;}
inline qint64 getD1P1() const {return d1P1;} inline ptrdiff_t getIndexD1() const {return indexD1;}
inline qint64 getD1P2() const {return d1P2;} inline ptrdiff_t getIndexD2() const {return indexD2;}
inline qint64 getD2P1() const {return d2P1;}
inline qint64 getD2P2() const {return d2P2;}
public slots: public slots:
/** /**
* @brief ChoosedObject gets id and type of selected object. Save correct data and ignore wrong. * @brief ChoosedObject gets id and type of selected object. Save correct data and ignore wrong.
@ -62,17 +60,16 @@ public slots:
private: private:
Q_DISABLE_COPY(DialogUnionDetails) Q_DISABLE_COPY(DialogUnionDetails)
Ui::DialogUnionDetails *ui; Ui::DialogUnionDetails *ui;
ptrdiff_t indexD1;
ptrdiff_t indexD2;
qint64 d1; qint64 d1;
qint64 d2; qint64 d2;
qint64 d1P1; qint32 numberD; // number of detail, what we already have
qint64 d1P2; qint32 numberP; // number of points, what we already have
qint64 d2P1; qint64 p1;
qint64 d2P2; qint64 p2;
qint32 numberD;
qint32 numberP;
bool CheckObject(const qint64 &id, const qint64 &idDetail) const; bool CheckObject(const qint64 &id, const qint64 &idDetail) const;
void ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, qint64 &p1, void ChoosedDetail(const qint64 &id, const Scene::Scenes &type, qint64 &idDetail, ptrdiff_t &index);
qint64 &p2);
}; };
#endif // DIALOGUNIONDETAILS_H #endif // DIALOGUNIONDETAILS_H

View File

@ -111,3 +111,75 @@ void VDetail::setId(const qint64 &id)
{ {
_id = id; _id = id;
} }
bool VDetail::OnEdge(const qint64 &p1, const qint64 &p2) const
{
ptrdiff_t i = indexOfNode(p1);
ptrdiff_t j1 = 0, j2 = 0;
if (i == nodes.size() - 1)
{
j1 = i-1;
j2 = 0;
}
else if (i == 0)
{
j1 = nodes.size() - 1;
j2 = i + 1;
}
else
{
j1 = i - 1;
j2 = i + 1;
}
if (nodes.at(j1).getId() == p2 || nodes.at(j2).getId() == p2)
{
return true;
}
else
{
return false;
}
}
ptrdiff_t VDetail::Edge(const qint64 &p1, const qint64 &p2) const
{
if (OnEdge(p1, p2) == false)
{
qWarning()<<"Points don't on edge.";
return -1;
}
ptrdiff_t i = indexOfNode(p1);
ptrdiff_t j = indexOfNode(p2);
ptrdiff_t min = qMin(i, j);
if (min == 0 && (i == nodes.size() - 1 || j == nodes.size() - 1))
{
return nodes.size() - 1;
}
else
{
return min;
}
}
void VDetail::NodeOnEdge(const ptrdiff_t &index, VNodeDetail &p1, VNodeDetail &p2) const
{
if (index <= 0 || index > nodes.size())
{
qWarning()<<"Wrong edge index";
return;
}
p1 = nodes.at(index);
if (index + 1 > nodes.size() - 1)
{
p2 = nodes.at(0);
}
else
{
p2 = nodes.at(index+1);
}
}

View File

@ -176,9 +176,11 @@ public:
*/ */
inline void setNodes(const QVector<VNodeDetail> &value) {nodes = value;} inline void setNodes(const QVector<VNodeDetail> &value) {nodes = value;}
ptrdiff_t indexOfNode(const qint64 &id) const; ptrdiff_t indexOfNode(const qint64 &id) const;
qint64 id() const; qint64 id() const;
void setId(const qint64 &id); void setId(const qint64 &id);
bool OnEdge(const qint64 &p1, const qint64 &p2)const;
ptrdiff_t Edge(const qint64 &p1, const qint64 &p2)const;
void NodeOnEdge(const ptrdiff_t &index, VNodeDetail &p1, VNodeDetail &p2)const;
private: private:
qint64 _id; qint64 _id;
/** /**

View File

@ -60,7 +60,7 @@ MainWindow::MainWindow(QWidget *parent)
dialogCutSpline(QSharedPointer<DialogCutSpline>()), dialogCutSplinePath (QSharedPointer<DialogCutSplinePath>()), dialogCutSpline(QSharedPointer<DialogCutSpline>()), dialogCutSplinePath (QSharedPointer<DialogCutSplinePath>()),
dialogUnionDetails(QSharedPointer<DialogUnionDetails>()), dialogUnionDetails(QSharedPointer<DialogUnionDetails>()),
dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false),
mode(Draw::Calculation) mode(Draw::Calculation), currentDrawIndex(0)
{ {
ui->setupUi(this); ui->setupUi(this);
ToolBarOption(); ToolBarOption();
@ -179,7 +179,7 @@ void MainWindow::ActionNewDraw()
} }
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&MainWindow::currentDrawChanged); &MainWindow::currentDrawChanged);
pattern->ClearObject(); pattern->ClearGObjects();
//Create single point //Create single point
qint64 id = pattern->AddGObject(new VPointF(toPixel((10+comboBoxDraws->count()*5)), toPixel(10), "А", 5, 10)); qint64 id = pattern->AddGObject(new VPointF(toPixel((10+comboBoxDraws->count()*5)), toPixel(10), "А", 5, 10));
VToolSinglePoint *spoint = new VToolSinglePoint(doc, pattern, id, Tool::FromGui); VToolSinglePoint *spoint = new VToolSinglePoint(doc, pattern, id, Tool::FromGui);
@ -504,6 +504,8 @@ void MainWindow::ToolUnionDetails(bool checked)
{ {
SetToolButton(checked, Tool::UnionDetails, ":/cursor/union_cursor.png", SetToolButton(checked, Tool::UnionDetails, ":/cursor/union_cursor.png",
tr("Select detail"), dialogUnionDetails, &MainWindow::ClosedDialogUnionDetails); tr("Select detail"), dialogUnionDetails, &MainWindow::ClosedDialogUnionDetails);
//Must disconnect this signal here.
disconnect(doc, &VDomDocument::FullUpdateFromFile, dialogUnionDetails.data(), &DialogUnionDetails::UpdateList);
} }
void MainWindow::ClosedDialogUnionDetails(int result) void MainWindow::ClosedDialogUnionDetails(int result)
@ -801,6 +803,12 @@ void MainWindow::CanselTool()
currentScene->setFocus(Qt::OtherFocusReason); currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection(); currentScene->clearSelection();
break; break;
case Tool::UnionDetails:
dialogUnionDetails.clear();
ui->toolButtonUnionDetails->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break;
default: default:
qWarning()<<"Get wrong tool type. Ignore."; qWarning()<<"Get wrong tool type. Ignore.";
break; break;
@ -854,6 +862,8 @@ void MainWindow::ActionDraw(bool checked)
verScrollBar = view->verticalScrollBar(); verScrollBar = view->verticalScrollBar();
verScrollBar->setValue(currentScene->getVerScrollBar()); verScrollBar->setValue(currentScene->getVerScrollBar());
comboBoxDraws->setCurrentIndex(currentDrawIndex);
mode = Draw::Calculation; mode = Draw::Calculation;
SetEnableTool(true); SetEnableTool(true);
doc->setCurrentData(); doc->setCurrentData();
@ -883,6 +893,10 @@ void MainWindow::ActionDetails(bool checked)
horScrollBar->setValue(currentScene->getHorScrollBar()); horScrollBar->setValue(currentScene->getHorScrollBar());
verScrollBar = view->verticalScrollBar(); verScrollBar = view->verticalScrollBar();
verScrollBar->setValue(currentScene->getVerScrollBar()); verScrollBar->setValue(currentScene->getVerScrollBar());
currentDrawIndex = comboBoxDraws->currentIndex();
comboBoxDraws->setCurrentIndex(comboBoxDraws->count()-1);
mode = Draw::Modeling; mode = Draw::Modeling;
SetEnableTool(true); SetEnableTool(true);
ui->toolBox->setCurrentIndex(4); ui->toolBox->setCurrentIndex(4);

View File

@ -506,6 +506,7 @@ private:
* @brief mode * @brief mode
*/ */
Draw::Draws mode; Draw::Draws mode;
qint32 currentDrawIndex;
/** /**
* @brief ToolBarOption * @brief ToolBarOption
*/ */

View File

@ -30,8 +30,8 @@
qreal VDrawTool::factor = 1; qreal VDrawTool::factor = 1;
VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id)
:VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), ignoreFullUpdate(false), :VAbstractTool(doc, data, id), ignoreContextMenuEvent(false), ignoreFullUpdate(false),
nameActivDraw(doc->GetNameActivDraw()) nameActivDraw(doc->GetNameActivDraw())
{ {
connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VDrawTool::ChangedActivDraw); connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VDrawTool::ChangedActivDraw);
@ -39,30 +39,6 @@ VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *pa
connect(this->doc, &VDomDocument::ShowTool, this, &VDrawTool::ShowTool); connect(this->doc, &VDomDocument::ShowTool, this, &VDrawTool::ShowTool);
} }
void VDrawTool::AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc)
{
qint64 cursor = doc->getCursor();
QVector<VToolRecord> *history = doc->getHistory();
if (cursor <= 0)
{
history->append(VToolRecord(id, toolType, doc->GetNameActivDraw()));
}
else
{
qint32 index = 0;
for (qint32 i = 0; i<history->size(); ++i)
{
VToolRecord rec = history->at(i);
if (rec.getId() == cursor)
{
index = i;
break;
}
}
history->insert(index+1, VToolRecord(id, toolType, doc->GetNameActivDraw()));
}
}
void VDrawTool::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) void VDrawTool::ShowTool(qint64 id, Qt::GlobalColor color, bool enable)
{ {
Q_UNUSED(id); Q_UNUSED(id);

View File

@ -48,19 +48,12 @@ public:
* @param id * @param id
* @param parent * @param parent
*/ */
VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); VDrawTool(VDomDocument *doc, VContainer *data, qint64 id);
virtual ~VDrawTool() {} virtual ~VDrawTool() {}
/** /**
* @brief setDialog * @brief setDialog
*/ */
virtual void setDialog() {} virtual void setDialog() {}
/**
* @brief AddRecord
* @param id
* @param toolType
* @param doc dom document container
*/
static void AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc);
/** /**
* @brief ignoreContextMenu * @brief ignoreContextMenu
* @param enable * @param enable

View File

@ -30,9 +30,11 @@
#include <QDebug> #include <QDebug>
const QString VAbstractNode::AttrIdObject = QStringLiteral("idObject"); const QString VAbstractNode::AttrIdObject = QStringLiteral("idObject");
const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool");
VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, qint64 id, qint64 idNode, QObject *parent) VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &idNode,
: VAbstractTool(doc, data, id, parent), idNode(idNode) const qint64 &idTool)
: VAbstractTool(doc, data, id), idNode(idNode), idTool(idTool)
{ {
_referens = 0; _referens = 0;
} }

View File

@ -46,17 +46,20 @@ public:
* @param idNode * @param idNode
* @param parent * @param parent
*/ */
VAbstractNode(VDomDocument *doc, VContainer *data, qint64 id, qint64 idNode, QObject *parent = 0 ); VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &idNode,
const qint64 &idTool);
virtual ~VAbstractNode() {} virtual ~VAbstractNode() {}
/** /**
* @brief AttrIdObject * @brief AttrIdObject
*/ */
static const QString AttrIdObject; static const QString AttrIdObject;
static const QString AttrIdTool;
protected: protected:
/** /**
* @brief idNode * @brief idNode
*/ */
qint64 idNode; qint64 idNode;
qint64 idTool;
/** /**
* @brief AddToModeling * @brief AddToModeling
* @param domElement * @param domElement

View File

@ -34,8 +34,8 @@ const QString VNodeArc::TagName = QStringLiteral("arc");
const QString VNodeArc::ToolType = QStringLiteral("modeling"); const QString VNodeArc::ToolType = QStringLiteral("modeling");
VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Tool::Sources &typeCreation, VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Tool::Sources &typeCreation,
QGraphicsItem * parent) const qint64 &idTool, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idArc), QGraphicsPathItem(parent) :VAbstractNode(doc, data, id, idArc, idTool), QGraphicsPathItem(parent)
{ {
RefreshGeometry(); RefreshGeometry();
this->setPen(QPen(baseColor, widthHairLine)); this->setPen(QPen(baseColor, widthHairLine));
@ -51,14 +51,22 @@ VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc,
} }
void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse, void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse,
const Tool::Sources &typeCreation) const Tool::Sources &typeCreation, const qint64 &idTool)
{ {
VAbstractTool::AddRecord(id, Tool::NodeArc, doc);
if (parse == Document::FullParse) if (parse == Document::FullParse)
{ {
VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation); VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, idTool);
Q_ASSERT(arc != 0); Q_ASSERT(arc != 0);
doc->AddTool(id, arc); doc->AddTool(id, arc);
doc->IncrementReferens(idArc); if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idArc);
}
} }
else else
{ {
@ -78,6 +86,10 @@ void VNodeArc::AddToFile()
AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType); AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrIdObject, idNode); AddAttribute(domElement, AttrIdObject, idNode);
if (idTool != 0)
{
AddAttribute(domElement, AttrIdTool, idTool);
}
AddToModeling(domElement); AddToModeling(domElement);
} }
@ -87,7 +99,11 @@ void VNodeArc::RefreshDataInFile()
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement()) if (domElement.isElement())
{ {
domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); domElement.setAttribute(AttrIdObject, idNode);
if (idTool != 0)
{
domElement.setAttribute(AttrIdTool, idTool);
}
} }
} }

View File

@ -49,7 +49,7 @@ public:
* @param parent * @param parent
*/ */
VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc,
const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); const Tool::Sources &typeCreation, const qint64 &idTool = 0, QGraphicsItem * parent = 0);
/** /**
* @brief Create * @brief Create
* @param doc dom document container * @param doc dom document container
@ -60,7 +60,7 @@ public:
* @param typeCreation * @param typeCreation
*/ */
static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse, static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse,
const Tool::Sources &typeCreation); const Tool::Sources &typeCreation, const qint64 &idTool = 0);
/** /**
* @brief TagName * @brief TagName
*/ */

View File

@ -34,8 +34,8 @@ const QString VNodePoint::TagName = QStringLiteral("point");
const QString VNodePoint::ToolType = QStringLiteral("modeling"); const QString VNodePoint::ToolType = QStringLiteral("modeling");
VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint,
const Tool::Sources &typeCreation, QGraphicsItem *parent) const Tool::Sources &typeCreation, const qint64 &idTool, QGraphicsItem *parent)
:VAbstractNode(doc, data, id, idPoint), QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0), :VAbstractNode(doc, data, id, idPoint, idTool), QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0),
lineName(0) lineName(0)
{ {
namePoint = new VGraphicsSimpleTextItem(this); namePoint = new VGraphicsSimpleTextItem(this);
@ -58,14 +58,22 @@ VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 id
} }
void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint,
const Document::Documents &parse, const Tool::Sources &typeCreation) const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool)
{ {
VAbstractTool::AddRecord(id, Tool::NodePoint, doc);
if (parse == Document::FullParse) if (parse == Document::FullParse)
{ {
VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation); VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, idTool);
Q_ASSERT(point != 0); Q_ASSERT(point != 0);
doc->AddTool(id, point); doc->AddTool(id, point);
doc->IncrementReferens(idPoint); if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idPoint);
}
} }
else else
{ {
@ -88,6 +96,10 @@ void VNodePoint::AddToFile()
AddAttribute(domElement, AttrIdObject, idNode); AddAttribute(domElement, AttrIdObject, idNode);
AddAttribute(domElement, AttrMx, toMM(point->mx())); AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my())); AddAttribute(domElement, AttrMy, toMM(point->my()));
if (idTool != 0)
{
AddAttribute(domElement, AttrIdTool, idTool);
}
AddToModeling(domElement); AddToModeling(domElement);
} }
@ -101,6 +113,10 @@ void VNodePoint::RefreshDataInFile()
domElement.setAttribute(AttrIdObject, idNode); domElement.setAttribute(AttrIdObject, idNode);
domElement.setAttribute(AttrMx, toMM(point->mx())); domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my())); domElement.setAttribute(AttrMy, toMM(point->my()));
if (idTool != 0)
{
domElement.setAttribute(AttrIdTool, idTool);
}
} }
} }

View File

@ -49,7 +49,7 @@ public:
* @param parent * @param parent
*/ */
VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint,
const Tool::Sources &typeCreation, QGraphicsItem * parent = 0 ); const Tool::Sources &typeCreation, const qint64 &idTool = 0, QGraphicsItem * parent = 0 );
/** /**
* @brief Create * @brief Create
* @param doc dom document container * @param doc dom document container
@ -60,7 +60,7 @@ public:
* @param typeCreation * @param typeCreation
*/ */
static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint,
const Document::Documents &parse, const Tool::Sources &typeCreation); const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0);
/** /**
* @brief TagName * @brief TagName
*/ */

View File

@ -34,8 +34,8 @@ const QString VNodeSpline::TagName = QStringLiteral("spline");
const QString VNodeSpline::ToolType = QStringLiteral("modelingSpline"); const QString VNodeSpline::ToolType = QStringLiteral("modelingSpline");
VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Tool::Sources &typeCreation, QGraphicsItem * parent) const Tool::Sources &typeCreation, const qint64 &idTool, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline), QGraphicsPathItem(parent) :VAbstractNode(doc, data, id, idSpline, idTool), QGraphicsPathItem(parent)
{ {
RefreshGeometry(); RefreshGeometry();
this->setPen(QPen(baseColor, widthHairLine)); this->setPen(QPen(baseColor, widthHairLine));
@ -51,14 +51,23 @@ VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64
} }
VNodeSpline *VNodeSpline::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, VNodeSpline *VNodeSpline::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Document::Documents &parse, const Tool::Sources &typeCreation) const Document::Documents &parse, const Tool::Sources &typeCreation,
const qint64 &idTool)
{ {
VAbstractTool::AddRecord(id, Tool::NodeSpline, doc);
VNodeSpline *spl = 0; VNodeSpline *spl = 0;
if (parse == Document::FullParse) if (parse == Document::FullParse)
{ {
spl = new VNodeSpline(doc, data, id, idSpline, typeCreation); spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, idTool);
doc->AddTool(id, spl); doc->AddTool(id, spl);
doc->IncrementReferens(idSpline); if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idSpline);
}
} }
else else
{ {
@ -79,6 +88,10 @@ void VNodeSpline::AddToFile()
AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType); AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrIdObject, idNode); AddAttribute(domElement, AttrIdObject, idNode);
if (idTool != 0)
{
AddAttribute(domElement, AttrIdTool, idTool);
}
AddToModeling(domElement); AddToModeling(domElement);
} }
@ -89,6 +102,10 @@ void VNodeSpline::RefreshDataInFile()
if (domElement.isElement()) if (domElement.isElement())
{ {
domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); domElement.setAttribute(AttrIdObject, QString().setNum(idNode));
if (idTool != 0)
{
domElement.setAttribute(AttrIdTool, idTool);
}
} }
} }

View File

@ -49,7 +49,7 @@ public:
* @param parent * @param parent
*/ */
VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); const Tool::Sources &typeCreation, const qint64 &idTool = 0, QGraphicsItem * parent = 0);
/** /**
* @brief Create * @brief Create
* @param doc dom document container * @param doc dom document container
@ -61,7 +61,8 @@ public:
* @return * @return
*/ */
static VNodeSpline *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, static VNodeSpline *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Document::Documents &parse, const Tool::Sources &typeCreation); const Document::Documents &parse, const Tool::Sources &typeCreation,
const qint64 &idTool = 0);
/** /**
* @brief TagName * @brief TagName
*/ */

View File

@ -34,8 +34,8 @@ const QString VNodeSplinePath::TagName = QStringLiteral("spline");
const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath"); const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath");
VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Tool::Sources &typeCreation, QGraphicsItem * parent) const Tool::Sources &typeCreation, const qint64 &idTool, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline), QGraphicsPathItem(parent) :VAbstractNode(doc, data, id, idSpline, idTool), QGraphicsPathItem(parent)
{ {
RefreshGeometry(); RefreshGeometry();
this->setPen(QPen(baseColor, widthHairLine)); this->setPen(QPen(baseColor, widthHairLine));
@ -51,18 +51,26 @@ VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id,
} }
void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Document::Documents &parse, const Tool::Sources &typeCreation) const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool)
{ {
VAbstractTool::AddRecord(id, Tool::NodeSplinePath, doc);
if (parse == Document::FullParse) if (parse == Document::FullParse)
{ {
VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation); VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, idTool);
Q_ASSERT(splPath != 0); Q_ASSERT(splPath != 0);
doc->AddTool(id, splPath); doc->AddTool(id, splPath);
const VSplinePath *path = data->GeometricObject<const VSplinePath *>(id); const VSplinePath *path = data->GeometricObject<const VSplinePath *>(id);
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)
{ {
doc->IncrementReferens(points->at(i).P().id()); if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(points->at(i).P().id());
}
} }
} }
else else
@ -83,6 +91,10 @@ void VNodeSplinePath::AddToFile()
AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType); AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrIdObject, idNode); AddAttribute(domElement, AttrIdObject, idNode);
if (idTool != 0)
{
AddAttribute(domElement, AttrIdTool, idTool);
}
AddToModeling(domElement); AddToModeling(domElement);
} }
@ -93,6 +105,10 @@ void VNodeSplinePath::RefreshDataInFile()
if (domElement.isElement()) if (domElement.isElement())
{ {
domElement.setAttribute(AttrIdObject, QString().setNum(idNode)); domElement.setAttribute(AttrIdObject, QString().setNum(idNode));
if (idTool != 0)
{
domElement.setAttribute(AttrIdTool, idTool);
}
} }
} }

View File

@ -49,7 +49,8 @@ public:
* @param parent * @param parent
*/ */
VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); const Tool::Sources &typeCreation, const qint64 &idTool = 0,
QGraphicsItem * parent = 0);
/** /**
* @brief Create * @brief Create
* @param doc dom document container * @param doc dom document container
@ -60,7 +61,7 @@ public:
* @param typeCreation * @param typeCreation
*/ */
static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Document::Documents &parse, const Tool::Sources &typeCreation); const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0);
/** /**
* @brief TagName * @brief TagName
*/ */

View File

@ -65,8 +65,8 @@ const QString VAbstractTool::AttrAxisP2 = QStringLiteral("axisP2");
const QString VAbstractTool::TypeLineNone = QStringLiteral("none"); const QString VAbstractTool::TypeLineNone = QStringLiteral("none");
const QString VAbstractTool::TypeLineLine = QStringLiteral("hair"); const QString VAbstractTool::TypeLineLine = QStringLiteral("hair");
VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id)
:VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black) :VDataTool(data), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black)
{ {
Q_ASSERT(doc != 0); Q_ASSERT(doc != 0);
connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange);
@ -186,3 +186,27 @@ void VAbstractTool::LineCoefficients(const QLineF &line, qreal *a, qreal *b, qre
*b = p1.x() - line.p2().x(); *b = p1.x() - line.p2().x();
*c = - *a * p1.x() - *b * p1.y(); *c = - *a * p1.x() - *b * p1.y();
} }
void VAbstractTool::AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc)
{
qint64 cursor = doc->getCursor();
QVector<VToolRecord> *history = doc->getHistory();
if (cursor <= 0)
{
history->append(VToolRecord(id, toolType, doc->GetNameActivDraw()));
}
else
{
qint32 index = 0;
for (qint32 i = 0; i<history->size(); ++i)
{
VToolRecord rec = history->at(i);
if (rec.getId() == cursor)
{
index = i;
break;
}
}
history->insert(index+1, VToolRecord(id, toolType, doc->GetNameActivDraw()));
}
}

View File

@ -46,7 +46,7 @@ public:
* @param id * @param id
* @param parent * @param parent
*/ */
VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id);
virtual ~VAbstractTool() {} virtual ~VAbstractTool() {}
/** /**
* @brief LineIntersectRect * @brief LineIntersectRect
@ -239,6 +239,13 @@ public:
* @brief TypeLineLine * @brief TypeLineLine
*/ */
static const QString TypeLineLine; static const QString TypeLineLine;
/**
* @brief AddRecord
* @param id
* @param toolType
* @param doc dom document container
*/
static void AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc);
public slots: public slots:
/** /**
* @brief FullUpdateFromFile * @brief FullUpdateFromFile

View File

@ -81,8 +81,8 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id,
void VToolDetail::setDialog() void VToolDetail::setDialog()
{ {
Q_ASSERT(dialogDetail.isNull() == false); Q_ASSERT(dialogDetail.isNull() == false);
const VDetail *detail = VAbstractTool::data.GeometricObject<const VDetail *>(id); VDetail detail = VAbstractTool::data.GetDetail(id);
dialogDetail->setDetails(*detail); dialogDetail->setDetails(detail);
} }
void VToolDetail::Create(QSharedPointer<DialogDetail> &dialog, VMainGraphicsScene *scene, VDomDocument *doc, void VToolDetail::Create(QSharedPointer<DialogDetail> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
@ -146,6 +146,7 @@ void VToolDetail::Create(const qint64 _id, VDetail newDetail, VMainGraphicsScene
doc->UpdateToolData(id, data); doc->UpdateToolData(id, data);
} }
} }
VAbstractTool::AddRecord(id, Tool::Detail, doc);
if (parse == Document::FullParse) if (parse == Document::FullParse)
{ {
VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene); VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene);
@ -170,7 +171,7 @@ void VToolDetail::Remove()
RemoveReferens(); RemoveReferens();
element.removeChild(domElement); element.removeChild(domElement);
//update xml file //update xml file
emit FullUpdateTree(); //emit FullUpdateTree();
//remove form scene //remove form scene
emit RemoveTool(this); emit RemoveTool(this);
} }
@ -310,7 +311,30 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
} }
if (selectedAction == actionRemove) if (selectedAction == actionRemove)
{ {
Remove(); //remove form xml file
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
QDomNode element = domElement.parentNode();
if (element.isNull() == false)
{
//deincrement referens
RemoveReferens();
element.removeChild(domElement);
//update xml file
emit FullUpdateTree();
//remove form scene
emit RemoveTool(this);
}
else
{
qWarning()<<"parentNode isNull"<<Q_FUNC_INFO;
}
}
else
{
qWarning()<<"Can't get element by id = "<<id<<Q_FUNC_INFO;
}
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -37,7 +37,7 @@ class VToolUnionDetails : public VAbstractTool
Q_OBJECT Q_OBJECT
public: public:
VToolUnionDetails(VDomDocument *doc, VContainer *data, const qint64 &id, const VDetail &d1, const VDetail &d2, VToolUnionDetails(VDomDocument *doc, VContainer *data, const qint64 &id, const VDetail &d1, const VDetail &d2,
const qint64 &d1P1, const qint64 &d1P2, const qint64 &d2P1, const qint64 &d2P2, const ptrdiff_t &indexD1, const ptrdiff_t &indexD2,
const Tool::Sources &typeCreation); const Tool::Sources &typeCreation);
virtual void setDialog() {} virtual void setDialog() {}
/** /**
@ -59,9 +59,9 @@ public:
* @param typeCreation * @param typeCreation
*/ */
static void Create(const qint64 _id, const VDetail &d1, const VDetail &d2, const qint64 &d1id, const qint64 &d2id, static void Create(const qint64 _id, const VDetail &d1, const VDetail &d2, const qint64 &d1id, const qint64 &d2id,
const qint64 &d1P1, const qint64 &d1P2, const qint64 &d2P1, const qint64 &d2P2, const ptrdiff_t &indexD1, const ptrdiff_t &indexD2, VMainGraphicsScene *scene,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, VDomDocument *doc, VContainer *data, const Document::Documents &parse,
const Document::Documents &parse, const Tool::Sources &typeCreation); const Tool::Sources &typeCreation);
static QVector<VDetail> GetDetailFromFile(VDomDocument *doc, const QDomElement &domElement); static QVector<VDetail> GetDetailFromFile(VDomDocument *doc, const QDomElement &domElement);
/** /**
* @brief TagName * @brief TagName
@ -70,27 +70,21 @@ public:
static const QString ToolType; static const QString ToolType;
static const QString TagDetail; static const QString TagDetail;
static const QString TagNode; static const QString TagNode;
static const QString AttrD1P1; static const QString AttrIndexD1;
static const QString AttrD1P2; static const QString AttrIndexD2;
static const QString AttrD2P1;
static const QString AttrD2P2;
static const QString AttrIdObject; static const QString AttrIdObject;
static const QString AttrNodeType; static const QString AttrNodeType;
static const QString NodeTypeContour; static const QString NodeTypeContour;
static const QString NodeTypeModeling; static const QString NodeTypeModeling;
inline qint64 getD1P1() const{return d1P1;} static void AddToNewDetail(VDomDocument *doc, VContainer *data, VDetail &newDetail, const VDetail &det,
inline qint64 getD1P2() const{return d1P2;} const ptrdiff_t &i, const qint64 &idTool, const qreal &dx = 0, const qreal &dy = 0,
inline qint64 getD2P1() const{return d2P1;} const qint64 &pRotate = 0, const qreal &angle = 0);
inline qint64 getD2P2() const{return d2P2;} static void UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &i,
void AddToNewDetail(VContainer *data, VDetail newDetail, const VDetail &det, const ptrdiff_t &a, qint64 &idCount, const qreal &dx = 0, const qreal &dy = 0, const qint64 &pRotate = 0,
const ptrdiff_t &b, const qreal &dx = 0, const qreal &dy = 0, const qint64 &pRotate = 0, const qreal &angle = 0);
const qreal &angle = 0) const; static void BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate,
void UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &a, const qreal angle);
const ptrdiff_t &b, const qreal &dx = 0, const qreal &dy = 0, const qint64 &pRotate = 0,
const qreal &angle = 0) const;
void BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate,
const qreal angle)const;
public slots: public slots:
/** /**
* @brief FullUpdateFromFile * @brief FullUpdateFromFile
@ -109,17 +103,12 @@ private:
Q_DISABLE_COPY(VToolUnionDetails) Q_DISABLE_COPY(VToolUnionDetails)
VDetail d1; VDetail d1;
VDetail d2; VDetail d2;
qint64 d1P1; ptrdiff_t indexD1;
qint64 d1P2; ptrdiff_t indexD2;
qint64 d2P1;
qint64 d2P2;
void AddDetail(QDomElement &domElement, VDetail &d); void AddDetail(QDomElement &domElement, VDetail &d);
void AddNode(QDomElement &domElement, VNodeDetail &node); void AddNode(QDomElement &domElement, const VNodeDetail &node);
QDomNode UpdateDetail(QDomNode &domNode, VDetail &d); QDomNode UpdateDetail(const QDomNode &domNode, const VDetail &d);
void UpdateNode(QDomNode &domNode, VNodeDetail &node);
void AddToModeling(const QDomElement &domElement); void AddToModeling(const QDomElement &domElement);
void CorectPoints(const VDetail &detail, qint64 &p1, qint64 &p2);
}; };
#endif // VTOOLUNIONDETAILS_H #endif // VTOOLUNIONDETAILS_H

View File

@ -28,8 +28,8 @@
#include "vsimplesplinepath.h" #include "vsimplesplinepath.h"
VSimpleSplinePath::VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor, QObject *parent) VSimpleSplinePath::VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor)
:VAbstractTool(doc, data, id, parent), factor(factor) :VAbstractTool(doc, data, id), factor(factor)
{ {
} }

View File

@ -36,7 +36,7 @@ class VSimpleSplinePath : public VAbstractTool, public QGraphicsPathItem
{ {
Q_OBJECT Q_OBJECT
public: public:
VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor, QObject *parent = 0); VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor);
protected: protected:
/** /**
* @brief mouseReleaseEvent * @brief mouseReleaseEvent

View File

@ -40,20 +40,20 @@
#include <QMessageBox> #include <QMessageBox>
VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode) VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, QObject *parent)
: QDomDocument(), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data), : QObject(parent), QDomDocument(), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data),
tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0), tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0),
comboBoxDraws(comboBoxDraws), mode(mode){} comboBoxDraws(comboBoxDraws), mode(mode){}
VDomDocument::VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, VDomDocument::VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode,
Draw::Draws *mode) QObject *parent)
:QDomDocument(name), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data), :QObject(parent), QDomDocument(name), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data),
tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0), tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0),
comboBoxDraws(comboBoxDraws), mode(mode){} comboBoxDraws(comboBoxDraws), mode(mode){}
VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws,
Draw::Draws *mode) Draw::Draws *mode, QObject *parent)
:QDomDocument(doctype), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data), :QObject(parent), QDomDocument(doctype), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data),
tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0), tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0),
comboBoxDraws(comboBoxDraws), mode(mode){} comboBoxDraws(comboBoxDraws), mode(mode){}
@ -78,6 +78,23 @@ QDomElement VDomDocument::elementById(const QString& id)
return QDomElement(); return QDomElement();
} }
void VDomDocument::removeAllChilds(QDomElement &element)
{
QDomNode domNode = element.firstChild();
while (domNode.isNull() == false)
{
if (domNode.isElement())
{
QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
element.removeChild(domElement);
}
}
domNode = element.firstChild();
}
}
bool VDomDocument::find(const QDomElement &node, const QString& id) bool VDomDocument::find(const QDomElement &node, const QString& id)
{ {
if (node.hasAttribute("id")) if (node.hasAttribute("id"))
@ -510,7 +527,7 @@ void VDomDocument::ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphics
{ {
if (domElement.tagName() == "calculation") if (domElement.tagName() == "calculation")
{ {
data->ClearObject(); data->ClearCalculationGObjects();
ParseDrawMode(sceneDraw, sceneDetail, domElement, parse, Draw::Calculation); ParseDrawMode(sceneDraw, sceneDetail, domElement, parse, Draw::Calculation);
} }
if (domElement.tagName() == "modeling") if (domElement.tagName() == "modeling")
@ -891,12 +908,13 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
{ {
qint64 id = GetParametrId(domElement); qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0");
qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0");
const VPointF *point = data->GeometricObject<const VPointF *>(idObject ); const VPointF *point = data->GeometricObject<const VPointF *>(idObject );
qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0")); qreal mx = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMx, "10.0"));
qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0")); qreal my = toPixel(GetParametrDouble(domElement, VAbstractTool::AttrMy, "15.0"));
data->UpdateGObject(id, new VPointF(point->x(), point->y(), point->name(), mx, my, idObject, data->UpdateGObject(id, new VPointF(point->x(), point->y(), point->name(), mx, my, idObject,
Draw::Modeling)); Draw::Modeling));
VNodePoint::Create(this, data, id, idObject, parse, Tool::FromFile); VNodePoint::Create(this, data, id, idObject, parse, Tool::FromFile, idTool);
return; return;
} }
catch (const VExceptionBadId &e) catch (const VExceptionBadId &e)
@ -1122,11 +1140,12 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
{ {
qint64 id = GetParametrId(domElement); qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0");
qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0");
VSpline *spl = new VSpline(*data->GeometricObject<const VSpline *>(idObject)); VSpline *spl = new VSpline(*data->GeometricObject<const VSpline *>(idObject));
Q_ASSERT(spl != 0); Q_ASSERT(spl != 0);
spl->setIdObject(idObject); spl->setIdObject(idObject);
data->UpdateGObject(id, spl); data->UpdateGObject(id, spl);
VNodeSpline::Create(this, data, id, idObject, parse, Tool::FromFile); VNodeSpline::Create(this, data, id, idObject, parse, Tool::FromFile, idTool);
return; return;
} }
catch (const VExceptionBadId &e) catch (const VExceptionBadId &e)
@ -1142,11 +1161,12 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
{ {
qint64 id = GetParametrId(domElement); qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0");
qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0");
VSplinePath *path = new VSplinePath(*data->GeometricObject<const VSplinePath *>(idObject)); VSplinePath *path = new VSplinePath(*data->GeometricObject<const VSplinePath *>(idObject));
Q_ASSERT(path != 0); Q_ASSERT(path != 0);
path->setIdObject(idObject); path->setIdObject(idObject);
data->UpdateGObject(id, path); data->UpdateGObject(id, path);
VNodeSplinePath::Create(this, data, id, idObject, parse, Tool::FromFile); VNodeSplinePath::Create(this, data, id, idObject, parse, Tool::FromFile, idTool);
return; return;
} }
catch (const VExceptionBadId &e) catch (const VExceptionBadId &e)
@ -1191,11 +1211,12 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement
{ {
qint64 id = GetParametrId(domElement); qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0"); qint64 idObject = GetParametrLongLong(domElement, VAbstractNode::AttrIdObject, "0");
qint64 idTool = GetParametrLongLong(domElement, VAbstractNode::AttrIdTool, "0");
VArc *arc = new VArc(*data->GeometricObject<const VArc *>(idObject)); VArc *arc = new VArc(*data->GeometricObject<const VArc *>(idObject));
Q_ASSERT(arc != 0); Q_ASSERT(arc != 0);
arc->setIdObject(idObject); arc->setIdObject(idObject);
data->UpdateGObject(id, arc); data->UpdateGObject(id, arc);
VNodeArc::Create(this, data, id, idObject, parse, Tool::FromFile); VNodeArc::Create(this, data, id, idObject, parse, Tool::FromFile, idTool);
return; return;
} }
catch (const VExceptionBadId &e) catch (const VExceptionBadId &e)
@ -1218,14 +1239,12 @@ void VDomDocument::ParseToolsElement(VMainGraphicsScene *scene, const QDomElemen
try try
{ {
qint64 id = GetParametrId(domElement); qint64 id = GetParametrId(domElement);
qint64 d1P1 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD1P1, "0"); qint64 indexD1 = GetParametrLongLong(domElement, VToolUnionDetails::AttrIndexD1, "-1");
qint64 d1P2 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD1P2, "0"); qint64 indexD2 = GetParametrLongLong(domElement, VToolUnionDetails::AttrIndexD2, "-1");
qint64 d2P1 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD2P1, "0");
qint64 d2P2 = GetParametrLongLong(domElement, VToolUnionDetails::AttrD2P2, "0");
QVector<VDetail> vector = VToolUnionDetails::GetDetailFromFile(this, domElement); QVector<VDetail> vector = VToolUnionDetails::GetDetailFromFile(this, domElement);
VToolUnionDetails::Create(id, vector[0], vector[1], 0, 0, d1P1, d1P2, d2P1, d2P2, scene, this, data, parse, VToolUnionDetails::Create(id, vector[0], vector[1], 0, 0, indexD1, indexD2, scene, this, data, parse,
Tool::FromFile); Tool::FromFile);
return; return;
@ -1245,7 +1264,7 @@ void VDomDocument::FullUpdateTree()
Q_ASSERT(scene != 0); Q_ASSERT(scene != 0);
try try
{ {
data->ClearObject(); data->ClearGObjects();
Parse(Document::LiteParse, scene, scene); Parse(Document::LiteParse, scene, scene);
} }
catch (const std::bad_alloc &) catch (const std::bad_alloc &)

View File

@ -66,7 +66,7 @@ public:
* @param comboBoxDraws * @param comboBoxDraws
* @param mode * @param mode
*/ */
VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode); VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, QObject *parent = 0);
/** /**
* @brief VDomDocument * @brief VDomDocument
* @param name * @param name
@ -74,7 +74,8 @@ public:
* @param comboBoxDraws * @param comboBoxDraws
* @param mode * @param mode
*/ */
VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode); VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode,
QObject *parent = 0);
/** /**
* @brief VDomDocument * @brief VDomDocument
* @param doc dom document containertype * @param doc dom document containertype
@ -83,7 +84,7 @@ public:
* @param mode * @param mode
*/ */
VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws,
Draw::Draws *mode); Draw::Draws *mode, QObject *parent = 0);
~VDomDocument(){} ~VDomDocument(){}
/** /**
* @brief elementById * @brief elementById
@ -91,6 +92,7 @@ public:
* @return * @return
*/ */
QDomElement elementById(const QString& id); QDomElement elementById(const QString& id);
void removeAllChilds(QDomElement &element);
/** /**
* @brief CreateEmptyFile * @brief CreateEmptyFile
*/ */