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;
} }
VDetail d = data->GetDetail(idDetail);
if (d.OnEdge(p1, id))
{
p2 = id; p2 = id;
index = d.Edge(p1, p2);
++numberD; ++numberD;
if (numberD > 1) if (numberD > 1)
{ {
++numberP; ++numberP;
emit ToolTip(""); emit ToolTip("");
this->show(); this->show();
return;
} }
else else
{ {
numberP = 0; numberP = 0;
p1 = 0;
p2 = 0;
emit ToolTip(tr("Select detail")); emit ToolTip(tr("Select detail"));
return;
}
}
else
{
emit ToolTip(tr("Select another second point"));
return;
} }
} }
} }

View File

@ -44,10 +44,8 @@ public:
~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

@ -178,7 +178,9 @@ public:
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,15 +51,23 @@ 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);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idArc); doc->IncrementReferens(idArc);
} }
}
else else
{ {
doc->UpdateToolData(id, data); doc->UpdateToolData(id, data);
@ -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,15 +58,23 @@ 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);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idPoint); doc->IncrementReferens(idPoint);
} }
}
else else
{ {
doc->UpdateToolData(id, data); doc->UpdateToolData(id, data);
@ -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,15 +51,24 @@ 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);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idSpline); doc->IncrementReferens(idSpline);
} }
}
else else
{ {
doc->UpdateToolData(id, data); doc->UpdateToolData(id, data);
@ -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,20 +51,28 @@ 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)
{
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{ {
doc->IncrementReferens(points->at(i).P().id()); doc->IncrementReferens(points->at(i).P().id());
} }
} }
}
else else
{ {
doc->UpdateToolData(id, data); doc->UpdateToolData(id, data);
@ -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;
}
} }
} }

View File

@ -34,23 +34,18 @@ const QString VToolUnionDetails::TagName = QStringLiteral("tools");
const QString VToolUnionDetails::ToolType = QStringLiteral("unionDetails"); const QString VToolUnionDetails::ToolType = QStringLiteral("unionDetails");
const QString VToolUnionDetails::TagDetail = QStringLiteral("det"); const QString VToolUnionDetails::TagDetail = QStringLiteral("det");
const QString VToolUnionDetails::TagNode = QStringLiteral("node"); const QString VToolUnionDetails::TagNode = QStringLiteral("node");
const QString VToolUnionDetails::AttrD1P1 = QStringLiteral("d1P1"); const QString VToolUnionDetails::AttrIndexD1 = QStringLiteral("indexD1");
const QString VToolUnionDetails::AttrD1P2 = QStringLiteral("d1P2"); const QString VToolUnionDetails::AttrIndexD2 = QStringLiteral("indexD2");
const QString VToolUnionDetails::AttrD2P1 = QStringLiteral("d2P1");
const QString VToolUnionDetails::AttrD2P2 = QStringLiteral("d2P2");
const QString VToolUnionDetails::AttrIdObject = QStringLiteral("idObject"); const QString VToolUnionDetails::AttrIdObject = QStringLiteral("idObject");
const QString VToolUnionDetails::AttrNodeType = QStringLiteral("nodeType"); const QString VToolUnionDetails::AttrNodeType = QStringLiteral("nodeType");
const QString VToolUnionDetails::NodeTypeContour = QStringLiteral("Contour"); const QString VToolUnionDetails::NodeTypeContour = QStringLiteral("Contour");
const QString VToolUnionDetails::NodeTypeModeling = QStringLiteral("Modeling"); const QString VToolUnionDetails::NodeTypeModeling = QStringLiteral("Modeling");
VToolUnionDetails::VToolUnionDetails(VDomDocument *doc, VContainer *data, const qint64 &id, const VDetail &d1, VToolUnionDetails::VToolUnionDetails(VDomDocument *doc, VContainer *data, const qint64 &id, const VDetail &d1,
const VDetail &d2, const qint64 &d1P1, const qint64 &d1P2, const qint64 &d2P1, const VDetail &d2, const ptrdiff_t &indexD1, const ptrdiff_t &indexD2,
const qint64 &d2P2, const Tool::Sources &typeCreation) const Tool::Sources &typeCreation)
:VAbstractTool(doc, data, id), d1(d1), d2(d2), d1P1(d1P1), d1P2(d1P2), d2P1(d2P1), d2P2(d2P2) :VAbstractTool(doc, data, id), d1(d1), d2(d2), indexD1(indexD1), indexD2(indexD2)
{ {
CorectPoints(this->d1, this->d1P1, this->d1P2);
CorectPoints(this->d2, this->d2P1, this->d2P2);
if (typeCreation == Tool::FromGui) if (typeCreation == Tool::FromGui)
{ {
AddToFile(); AddToFile();
@ -61,49 +56,11 @@ VToolUnionDetails::VToolUnionDetails(VDomDocument *doc, VContainer *data, const
} }
} }
void VToolUnionDetails::CorectPoints(const VDetail &detail, qint64 &p1, qint64 &p2) void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDetail &newDetail, const VDetail &det,
const ptrdiff_t &i, const qint64 &idTool, const qreal &dx, const qreal &dy,
const qint64 &pRotate, const qreal &angle)
{ {
if (p1 == p2) qint64 id = 0, idObject = 0;
{
qWarning()<<"Union points equal.";
return;
}
bool p1flag = false;
bool p2flag = false;
for (ptrdiff_t i = 0; i< detail.CountNode(); ++i)
{
if (detail.at(i).getTypeTool() == Tool::NodePoint)
{
if (p1 == detail.at(i).getId())
{
p1flag = true;
}
if (p2 == detail.at(i).getId())
{
p2flag = true;
}
if (p1flag == true && p2flag == false)
{
return;
}
if (p2flag == true && p1flag == false)
{
qint64 p = p1;
p1 = p2;
p2 = p;
return;
}
}
}
}
void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, const VDetail &det, const ptrdiff_t &a,
const ptrdiff_t &b, const qreal &dx, const qreal &dy, const qint64 &pRotate,
const qreal &angle) const
{
for (ptrdiff_t i = a; i <= b; ++i)
{
qint64 id = 0;
switch (det.at(i).getTypeTool()) switch (det.at(i).getTypeTool())
{ {
case (Tool::NodePoint): case (Tool::NodePoint):
@ -116,10 +73,15 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons
{ {
VPointF *point = new VPointF(*data->GeometricObject<const VPointF *>(det.at(i).getId())); VPointF *point = new VPointF(*data->GeometricObject<const VPointF *>(det.at(i).getId()));
Q_ASSERT(point != 0); Q_ASSERT(point != 0);
point->setMode(Draw::Modeling);
BiasRotatePoint(point, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), BiasRotatePoint(point, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(),
angle); angle);
id = data->AddGObject(point); idObject = data->AddGObject(point);
VNodePoint::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui ); VPointF *point1 = new VPointF(*point);
Q_ASSERT(point1 != 0);
point1->setMode(Draw::Modeling);
id = data->AddGObject(point1);
VNodePoint::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool);
} }
} }
break; break;
@ -149,8 +111,15 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons
l1.angle(), QString().setNum(l1.angle()), l2.angle(), l1.angle(), QString().setNum(l1.angle()), l2.angle(),
QString().setNum(l2.angle())); QString().setNum(l2.angle()));
Q_ASSERT(arc1 != 0); Q_ASSERT(arc1 != 0);
id = data->AddGObject(arc1); arc1->setMode(Draw::Modeling);
VNodeArc::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui); idObject = data->AddGObject(arc1);
VArc *arc2 = new VArc(*arc1);
Q_ASSERT(arc2 != 0);
arc2->setMode(Draw::Modeling);
id = data->AddGObject(arc2);
VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool);
} }
} }
break; break;
@ -181,8 +150,15 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons
qint64 idP4 = data->AddGObject(p4); qint64 idP4 = data->AddGObject(p4);
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve()); VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve());
Q_ASSERT(spl != 0);
spl->setMode(Draw::Modeling);
id = data->AddGObject(spl); id = data->AddGObject(spl);
VNodeSpline::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui);
VSpline *spl1 = new VSpline(*spl);
Q_ASSERT(spl1 != 0);
spl1->setMode(Draw::Modeling);
idObject = data->AddGObject(spl1);
VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool);
} }
} }
break; break;
@ -196,6 +172,7 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons
{ {
VSplinePath *path = new VSplinePath(); VSplinePath *path = new VSplinePath();
Q_ASSERT(path != 0); Q_ASSERT(path != 0);
path->setMode(Draw::Modeling);
const VSplinePath *splinePath = data->GeometricObject<const VSplinePath *>(det.at(i).getId()); const VSplinePath *splinePath = data->GeometricObject<const VSplinePath *>(det.at(i).getId());
for (qint32 i = 1; i <= splinePath->Count(); ++i) for (qint32 i = 1; i <= splinePath->Count(); ++i)
{ {
@ -232,8 +209,13 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons
path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(), path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(),
splinePath->at(i).KAsm1())); splinePath->at(i).KAsm1()));
} }
id = data->AddGObject(path); idObject = data->AddGObject(path);
VNodeSplinePath::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui);
VSplinePath *path1 = new VSplinePath(*path);
Q_ASSERT(path1 != 0);
path1->setMode(Draw::Modeling);
id = data->AddGObject(path1);
VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool);
} }
} }
break; break;
@ -243,40 +225,31 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons
} }
newDetail.append(VNodeDetail(id, det.at(i).getTypeTool(), NodeDetail::Contour)); newDetail.append(VNodeDetail(id, det.at(i).getTypeTool(), NodeDetail::Contour));
} }
}
void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &a, void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &i,
const ptrdiff_t &b, const qreal &dx, const qreal &dy, const qint64 &pRotate, qint64 &idCount, const qreal &dx, const qreal &dy, const qint64 &pRotate,
const qreal &angle) const const qreal &angle)
{
qint64 idCount = 0;
for (ptrdiff_t i = a; i <= b; ++i)
{ {
switch (det.at(i).getTypeTool()) switch (det.at(i).getTypeTool())
{ {
case (Tool::NodePoint): case (Tool::NodePoint):
{ {
if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) if (qFuzzyCompare(dx+1, 1) == false && qFuzzyCompare(dy+1, 1) == false && pRotate != 0)
{
++idCount;
}
else
{ {
VPointF *point = new VPointF(*data->GeometricObject<const VPointF *>(det.at(i).getId())); VPointF *point = new VPointF(*data->GeometricObject<const VPointF *>(det.at(i).getId()));
Q_ASSERT(point != 0); Q_ASSERT(point != 0);
point->setMode(Draw::Modeling);
BiasRotatePoint(point, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle); BiasRotatePoint(point, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
++idCount; ++idCount;
data->UpdateGObject(idDetail+idCount, point); data->UpdateGObject(idDetail+idCount, point);
++idCount;
} }
} }
break; break;
case (Tool::NodeArc): case (Tool::NodeArc):
{ {
if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) if (qFuzzyCompare(dx+1, 1) == false && qFuzzyCompare(dy+1, 1) == false && pRotate != 0)
{
++idCount;
}
else
{ {
const VArc *arc = data->GeometricObject<const VArc *>(det.at(i).getId()); const VArc *arc = data->GeometricObject<const VArc *>(det.at(i).getId());
VPointF p1 = VPointF(arc->GetP1()); VPointF p1 = VPointF(arc->GetP1());
@ -294,18 +267,17 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(), l1.angle(), VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(), l1.angle(),
QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle())); QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle()));
Q_ASSERT(arc1); Q_ASSERT(arc1);
arc1->setMode(Draw::Modeling);
++idCount; ++idCount;
data->UpdateGObject(idDetail+idCount, arc1); data->UpdateGObject(idDetail+idCount, arc1);
++idCount;
} }
} }
break; break;
case (Tool::NodeSpline): case (Tool::NodeSpline):
{ {
if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) if (qFuzzyCompare(dx+1, 1) == false && qFuzzyCompare(dy+1, 1) == false && pRotate != 0)
{
++idCount;
}
else
{ {
const VSpline *spline = data->GeometricObject<const VSpline *>(det.at(i).getId()); const VSpline *spline = data->GeometricObject<const VSpline *>(det.at(i).getId());
@ -327,21 +299,21 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve()); VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve());
Q_ASSERT(spl != 0); Q_ASSERT(spl != 0);
spl->setMode(Draw::Modeling);
++idCount; ++idCount;
data->UpdateGObject(idDetail+idCount, spl); data->UpdateGObject(idDetail+idCount, spl);
++idCount;
} }
} }
break; break;
case (Tool::NodeSplinePath): case (Tool::NodeSplinePath):
{ {
if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0) if (qFuzzyCompare(dx+1, 1) == false && qFuzzyCompare(dy+1, 1) == false && pRotate != 0)
{
++idCount;
}
else
{ {
VSplinePath *path = new VSplinePath(); VSplinePath *path = new VSplinePath();
Q_ASSERT(path != 0); Q_ASSERT(path != 0);
path->setMode(Draw::Modeling);
const VSplinePath *splinePath = data->GeometricObject<const VSplinePath *>(det.at(i).getId()); const VSplinePath *splinePath = data->GeometricObject<const VSplinePath *>(det.at(i).getId());
for (qint32 i = 1; i <= splinePath->Count(); ++i) for (qint32 i = 1; i <= splinePath->Count(); ++i)
{ {
@ -380,6 +352,8 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
} }
++idCount; ++idCount;
data->UpdateGObject(idDetail+idCount, path); data->UpdateGObject(idDetail+idCount, path);
++idCount;
} }
} }
break; break;
@ -388,15 +362,14 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
break; break;
} }
} }
}
void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate, void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate,
const qreal angle) const const qreal angle)
{ {
point->setX(point->x()+dx); point->setX(point->x()+dx);
point->setY(point->y()+dy); point->setY(point->y()+dy);
QLineF line(pRotate, point->toQPointF()); QLineF line(pRotate, point->toQPointF());
line.setAngle(angle); line.setAngle(line.angle()+angle);
point->setX(line.p2().x()); point->setX(line.p2().x());
point->setY(line.p2().y()); point->setY(line.p2().y());
} }
@ -406,20 +379,17 @@ void VToolUnionDetails::Create(QSharedPointer<DialogUnionDetails> &dialog, VMain
{ {
VDetail d1 = data->GetDetail(dialog->getD1()); VDetail d1 = data->GetDetail(dialog->getD1());
VDetail d2 = data->GetDetail(dialog->getD2()); VDetail d2 = data->GetDetail(dialog->getD2());
qint64 d1P1 = dialog->getD1P1(); ptrdiff_t indexD1 = dialog->getIndexD1();
qint64 d1P2 = dialog->getD1P2(); ptrdiff_t indexD2 = dialog->getIndexD2();
qint64 d2P1 = dialog->getD2P1(); Create(0, d1, d2, dialog->getD1(), dialog->getD2(), indexD1, indexD2, scene, doc, data, Document::FullParse,
qint64 d2P2 = dialog->getD2P2();
Create(0, d1, d2, dialog->getD1(), dialog->getD2(), d1P1, d1P2, d2P1, d2P2, scene, doc, data, Document::FullParse,
Tool::FromGui); Tool::FromGui);
} }
void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetail &d2, const qint64 &d1id, void VToolUnionDetails::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 &d2id, const ptrdiff_t &indexD1, const ptrdiff_t &indexD2,
const qint64 &d2P2, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation) const Document::Documents &parse, const Tool::Sources &typeCreation)
{ {
VToolUnionDetails *unionDetails = 0;
qint64 id = _id; qint64 id = _id;
if (typeCreation == Tool::FromGui) if (typeCreation == Tool::FromGui)
{ {
@ -432,9 +402,10 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai
doc->UpdateToolData(id, data); doc->UpdateToolData(id, data);
} }
} }
VAbstractTool::AddRecord(id, Tool::UnionDetails, doc);
if (parse == Document::FullParse) if (parse == Document::FullParse)
{ {
unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, d1P1, d1P2, d2P1, d2P2, typeCreation); VToolUnionDetails *unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation);
QHash<qint64, VDataTool*>* tools = doc->getTools(); QHash<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id, unionDetails); tools->insert(id, unionDetails);
for (ptrdiff_t i = 0; i < d1.CountNode(); ++i) for (ptrdiff_t i = 0; i < d1.CountNode(); ++i)
@ -450,62 +421,155 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai
if (typeCreation == Tool::FromGui) if (typeCreation == Tool::FromGui)
{ {
//Update corected points qint32 j = 0, i = 0;
qint64 d1P1 = unionDetails->getD1P1(); qint32 nD1 = d1.CountNode();
qint64 d1P2 = unionDetails->getD1P2(); qint32 nD2 = d2.CountNode();
qint64 d2P1 = unionDetails->getD2P1(); qint32 pointsD2 = 0; //Keeps count points second detail, what we already add.
qint64 d2P2 = unionDetails->getD2P2();
VDetail newDetail; VDetail newDetail;
unionDetails->AddToNewDetail(data, newDetail, d1, d1.indexOfNode(d1P1), d1.indexOfNode(d1P2));
const VNodeDetail det1p2 = d1.at(d1.indexOfNode(d1P2)); do
{
AddToNewDetail(doc, data, newDetail, d1, i, id);
++i;
if (i > indexD1 && pointsD2 < nD2-2)
{
VNodeDetail det1p1;
VNodeDetail det1p2;
d1.NodeOnEdge(indexD1, det1p1, det1p2);
const VPointF *point1 = data->GeometricObject<const VPointF *>(det1p1.getId());
const VPointF *point2 = data->GeometricObject<const VPointF *>(det1p2.getId()); const VPointF *point2 = data->GeometricObject<const VPointF *>(det1p2.getId());
const VNodeDetail det2p1 = d2.at(d2.indexOfNode(d2P1));
const VPointF *point1 = data->GeometricObject<const VPointF *>(det2p1.getId());
qreal dx = point2->x() - point1->x();
qreal dy = point2->y() - point1->y();
const VNodeDetail det1p1 = d1.at(d1.indexOfNode(d1P1));
const VPointF *point3 = data->GeometricObject<const VPointF *>(det1p1.getId());
const VNodeDetail det2p2 = d1.at(d1.indexOfNode(d2P2));
const VPointF *point4 = data->GeometricObject<const VPointF *>(det2p2.getId());
QLineF l1(point3->toQPointF(), point2->toQPointF());
QLineF l2(point4->toQPointF(), point1->toQPointF());
qreal angle = l2.angle() + l2.angleTo(l1);
unionDetails->AddToNewDetail(data, newDetail, d2, d2.indexOfNode(d2P1)+1, d2.indexOfNode(d2P2)-1, dx, dy, VNodeDetail det2p1;
d1P2, angle); VNodeDetail det2p2;
d2.NodeOnEdge(indexD2, det2p1, det2p2);
VPointF point3 = VPointF(*data->GeometricObject<const VPointF *>(det2p1.getId()));
VPointF point4 = VPointF(*data->GeometricObject<const VPointF *>(det2p2.getId()));
qreal dx = point1->x() - point4.x();
qreal dy = point1->y() - point4.y();
point3.setX(point3.x()+dx);
point3.setY(point3.y()+dy);
point4.setX(point4.x()+dx);
point4.setY(point4.y()+dy);
QLineF l1(point1->toQPointF(), point2->toQPointF());
QLineF l2(point4.toQPointF(), point3.toQPointF());
qreal angle = l2.angleTo(l1);
do
{
if (pointsD2 == 0)
{
VNodeDetail node1;
VNodeDetail node2;
d2.NodeOnEdge(indexD2, node1, node2);
ptrdiff_t k = d2.indexOfNode(node2.getId());
if (k == d2.CountNode()-1)
{
j = 0;
}
else
{
j = d2.indexOfNode(node2.getId())+1;
}
}
if (pointsD2 == nD2 -2)
{
break;
}
if (j >= nD2)
{
j=0;
}
AddToNewDetail(doc, data, newDetail, d2, j, id, dx, dy, det1p1.getId(), angle);
++pointsD2;
++j;
} while (pointsD2 < nD2);
}
}while(i<nD1);
newDetail.setName("Detail"); newDetail.setName("Detail");
VToolDetail::Create(0, newDetail, scene, doc, data, parse, Tool::FromTool); VToolDetail::Create(0, newDetail, scene, doc, data, parse, Tool::FromTool);
QHash<qint64, VDataTool*>* tools = doc->getTools(); QHash<qint64, VDataTool*>* tools = doc->getTools();
VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(d1id)); VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(d1id));
toolDet->Remove(); toolDet->Remove();
toolDet = qobject_cast<VToolDetail*>(tools->value(d2id)); toolDet = qobject_cast<VToolDetail*>(tools->value(d2id));
toolDet->Remove(); toolDet->Remove();
} }
else else
{ {
unionDetails = qobject_cast<VToolUnionDetails *>(doc->getTool(id)); qint64 idCount = 0;
qint32 j = 0, i = 0;
qint32 nD1 = d1.CountNode();
qint32 nD2 = d2.CountNode();
qint32 pointsD2 = 0; //Keeps count points second detail, what we already add.
unionDetails->UpdatePoints(id, data, d1, d1.indexOfNode(d1P1), d1.indexOfNode(d1P2)); do
{
VNodeDetail det1p2 = d1.at(d1.indexOfNode(d1P2)); UpdatePoints(id, data, d1, i, idCount);
++i;
if (i > indexD1 && pointsD2 < nD2-2)
{
VNodeDetail det1p1;
VNodeDetail det1p2;
d1.NodeOnEdge(indexD1, det1p1, det1p2);
const VPointF *point1 = data->GeometricObject<const VPointF *>(det1p1.getId());
const VPointF *point2 = data->GeometricObject<const VPointF *>(det1p2.getId()); const VPointF *point2 = data->GeometricObject<const VPointF *>(det1p2.getId());
VNodeDetail det2p1 = d2.at(d2.indexOfNode(d2P1));
const VPointF *point1 = data->GeometricObject<const VPointF *>(det2p1.getId());
qreal dx = point2->x() - point1->x();
qreal dy = point2->y() - point1->y();
const VNodeDetail det1p1 = d1.at(d1.indexOfNode(d1P1));
const VPointF *point3 = data->GeometricObject<const VPointF *>(det1p1.getId());
const VNodeDetail det2p2 = d1.at(d1.indexOfNode(d2P2));
const VPointF *point4 = data->GeometricObject<const VPointF *>(det2p2.getId());
QLineF l1(point3->toQPointF(), point2->toQPointF());
QLineF l2(point4->toQPointF(), point1->toQPointF());
qreal angle = l2.angle() + l2.angleTo(l1);
unionDetails->UpdatePoints(id, data, d2, d2.indexOfNode(d2P1)+1, d2.indexOfNode(d2P2)-1, dx, dy, VNodeDetail det2p1;
d1P2, angle); VNodeDetail det2p2;
d2.NodeOnEdge(indexD2, det2p1, det2p2);
VPointF point3 = VPointF(*data->GeometricObject<const VPointF *>(det2p1.getId()));
VPointF point4 = VPointF(*data->GeometricObject<const VPointF *>(det2p2.getId()));
qreal dx = point1->x() - point4.x();
qreal dy = point1->y() - point4.y();
point3.setX(point3.x()+dx);
point3.setY(point3.y()+dy);
point4.setX(point4.x()+dx);
point4.setY(point4.y()+dy);
QLineF l1(point1->toQPointF(), point2->toQPointF());
QLineF l2(point4.toQPointF(), point3.toQPointF());
qreal angle = l2.angleTo(l1);
do
{
if (pointsD2 == 0)
{
VNodeDetail node1;
VNodeDetail node2;
d2.NodeOnEdge(indexD2, node1, node2);
ptrdiff_t k = d2.indexOfNode(node2.getId());
if (k == d2.CountNode()-1)
{
j = 0;
}
else
{
j = d2.indexOfNode(node2.getId())+1;
}
}
if (pointsD2 == nD2-2)
{
break;
}
if (j >= nD2)
{
j=0;
}
UpdatePoints(id, data, d2, j, idCount, dx, dy, det1p1.getId(), angle);
++pointsD2;
++j;
} while (pointsD2 < nD2);
}
}while(i<nD1);
} }
} }
@ -521,7 +585,8 @@ QVector<VDetail> VToolUnionDetails::GetDetailFromFile(VDomDocument *doc, const Q
{ {
if (element.tagName() == VToolUnionDetails::TagDetail) if (element.tagName() == VToolUnionDetails::TagDetail)
{ {
QDomNodeList nodeList = domElement.childNodes(); VDetail d;
QDomNodeList nodeList = element.childNodes();
qint32 num = nodeList.size(); qint32 num = nodeList.size();
for (qint32 j = 0; j < num; ++j) for (qint32 j = 0; j < num; ++j)
{ {
@ -552,10 +617,11 @@ QVector<VDetail> VToolUnionDetails::GetDetailFromFile(VDomDocument *doc, const Q
{ {
tool = Tool::NodeSplinePath; tool = Tool::NodeSplinePath;
} }
vector[i].append(VNodeDetail(id, tool, nodeType, mx, my)); d.append(VNodeDetail(id, tool, nodeType, mx, my));
} }
} }
} }
vector.append(d);
} }
} }
} }
@ -568,10 +634,8 @@ void VToolUnionDetails::AddToFile()
AddAttribute(domElement, AttrId, id); AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType); AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrD1P1, d1P1); AddAttribute(domElement, AttrIndexD1, indexD1);
AddAttribute(domElement, AttrD1P2, d1P2); AddAttribute(domElement, AttrIndexD2, indexD2);
AddAttribute(domElement, AttrD2P1, d2P1);
AddAttribute(domElement, AttrD2P2, d2P2);
AddDetail(domElement, d1); AddDetail(domElement, d1);
AddDetail(domElement, d2); AddDetail(domElement, d2);
@ -584,10 +648,8 @@ void VToolUnionDetails::RefreshDataInFile()
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement()) if (domElement.isElement())
{ {
domElement.setAttribute(AttrD1P1, d1P1); domElement.setAttribute(AttrIndexD1, indexD1);
domElement.setAttribute(AttrD1P2, d1P2); domElement.setAttribute(AttrIndexD2, indexD2);
domElement.setAttribute(AttrD2P1, d2P1);
domElement.setAttribute(AttrD2P2, d2P2);
QDomNode domNode = domElement.firstChild(); QDomNode domNode = domElement.firstChild();
domNode = UpdateDetail(domNode, d1); domNode = UpdateDetail(domNode, d1);
@ -607,7 +669,7 @@ void VToolUnionDetails::AddDetail(QDomElement &domElement, VDetail &d)
domElement.appendChild(det); domElement.appendChild(det);
} }
void VToolUnionDetails::AddNode(QDomElement &domElement, VNodeDetail &node) void VToolUnionDetails::AddNode(QDomElement &domElement, const VNodeDetail &node)
{ {
QDomElement nod = doc->createElement(TagNode); QDomElement nod = doc->createElement(TagNode);
@ -643,7 +705,7 @@ void VToolUnionDetails::AddNode(QDomElement &domElement, VNodeDetail &node)
domElement.appendChild(nod); domElement.appendChild(nod);
} }
QDomNode VToolUnionDetails::UpdateDetail(QDomNode &domNode, VDetail &d) QDomNode VToolUnionDetails::UpdateDetail(const QDomNode &domNode, const VDetail &d)
{ {
//QDomNode domNode = domElement.firstChild(); //QDomNode domNode = domElement.firstChild();
while (domNode.isNull() == false) while (domNode.isNull() == false)
@ -655,10 +717,12 @@ QDomNode VToolUnionDetails::UpdateDetail(QDomNode &domNode, VDetail &d)
{ {
if (domElement.tagName() == VToolUnionDetails::TagDetail) if (domElement.tagName() == VToolUnionDetails::TagDetail)
{ {
doc->removeAllChilds(domElement);//delete all nodes in detail
for (ptrdiff_t i = 0; i < d.CountNode(); ++i) for (ptrdiff_t i = 0; i < d.CountNode(); ++i)
{ {
UpdateNode(domElement, d[i]); AddNode(domElement, d.at(i));//rewrite nodes of detail
} }
break;
} }
} }
} }
@ -666,53 +730,6 @@ QDomNode VToolUnionDetails::UpdateDetail(QDomNode &domNode, VDetail &d)
return domNode.nextSibling(); return domNode.nextSibling();
} }
void VToolUnionDetails::UpdateNode(QDomNode &domNode, VNodeDetail &node)
{
while (domNode.isNull() == false)
{
if (domNode.isElement())
{
QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
if (domElement.tagName() == VToolUnionDetails::TagNode)
{
domElement.setAttribute( AttrIdObject, node.getId());
domElement.setAttribute(AttrMx, toMM(node.getMx()));
domElement.setAttribute(AttrMy, toMM(node.getMy()));
if (node.getTypeNode() == NodeDetail::Contour)
{
domElement.setAttribute(AttrNodeType, NodeTypeContour);
}
else
{
domElement.setAttribute(AttrNodeType, NodeTypeModeling);
}
switch (node.getTypeTool())
{
case (Tool::NodeArc):
domElement.setAttribute(AttrType, QStringLiteral("NodeArc"));
break;
case (Tool::NodePoint):
domElement.setAttribute(AttrType, QStringLiteral("NodePoint"));
break;
case (Tool::NodeSpline):
domElement.setAttribute(AttrType, QStringLiteral("NodeSpline"));
break;
case (Tool::NodeSplinePath):
domElement.setAttribute(AttrType, QStringLiteral("NodeSplinePath"));
break;
default:
qWarning()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
break;
}
}
}
}
domNode = domNode.nextSibling();
}
}
void VToolUnionDetails::AddToModeling(const QDomElement &domElement) void VToolUnionDetails::AddToModeling(const QDomElement &domElement)
{ {
QDomElement modelingElement; QDomElement modelingElement;

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
*/ */