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(point != 0);
point->setId(id);
// if (gObjects.contains(id))
// {
// delete gObjects.value(id);
// }
if (gObjects.contains(id))
{
delete gObjects.value(id);
gObjects.remove(id);
}
obj[id] = point;
UpdateId(id);
}
@ -620,10 +621,10 @@ void VContainer::Clear()
lengthArcs.clear();
lineAngles.clear();
details.clear();
ClearObject();
ClearGObjects();
}
void VContainer::ClearObject()
void VContainer::ClearGObjects()
{
if (gObjects.size()>0)
{
@ -632,6 +633,23 @@ void VContainer::ClearObject()
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
{
if (base.contains(name))

View File

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

View File

@ -402,6 +402,20 @@ QString DialogHistory::Record(const VToolRecord &tool)
}
}
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:
qWarning()<<tr("Got wrong tool type. Ignore.");
break;

View File

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

View File

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

View File

@ -111,3 +111,75 @@ void VDetail::setId(const qint64 &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;
qint64 id() const;
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:
qint64 _id;
/**

View File

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

View File

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

View File

@ -30,8 +30,8 @@
qreal VDrawTool::factor = 1;
VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent)
:VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), ignoreFullUpdate(false),
VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id)
:VAbstractTool(doc, data, id), ignoreContextMenuEvent(false), ignoreFullUpdate(false),
nameActivDraw(doc->GetNameActivDraw())
{
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);
}
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)
{
Q_UNUSED(id);

View File

@ -48,19 +48,12 @@ public:
* @param id
* @param parent
*/
VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0);
VDrawTool(VDomDocument *doc, VContainer *data, qint64 id);
virtual ~VDrawTool() {}
/**
* @brief 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
* @param enable

View File

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

View File

@ -46,17 +46,20 @@ public:
* @param idNode
* @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() {}
/**
* @brief AttrIdObject
*/
static const QString AttrIdObject;
static const QString AttrIdTool;
protected:
/**
* @brief idNode
*/
qint64 idNode;
qint64 idTool;
/**
* @brief AddToModeling
* @param domElement

View File

@ -34,8 +34,8 @@ const QString VNodeArc::TagName = QStringLiteral("arc");
const QString VNodeArc::ToolType = QStringLiteral("modeling");
VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Tool::Sources &typeCreation,
QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idArc), QGraphicsPathItem(parent)
const qint64 &idTool, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idArc, idTool), QGraphicsPathItem(parent)
{
RefreshGeometry();
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,
const Tool::Sources &typeCreation)
const Tool::Sources &typeCreation, const qint64 &idTool)
{
VAbstractTool::AddRecord(id, Tool::NodeArc, doc);
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);
doc->AddTool(id, arc);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idArc);
}
}
else
{
doc->UpdateToolData(id, data);
@ -78,6 +86,10 @@ void VNodeArc::AddToFile()
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrIdObject, idNode);
if (idTool != 0)
{
AddAttribute(domElement, AttrIdTool, idTool);
}
AddToModeling(domElement);
}
@ -87,7 +99,11 @@ void VNodeArc::RefreshDataInFile()
QDomElement domElement = doc->elementById(QString().setNum(id));
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
*/
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
* @param doc dom document container
@ -60,7 +60,7 @@ public:
* @param typeCreation
*/
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
*/

View File

@ -34,8 +34,8 @@ const QString VNodePoint::TagName = QStringLiteral("point");
const QString VNodePoint::ToolType = QStringLiteral("modeling");
VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint,
const Tool::Sources &typeCreation, QGraphicsItem *parent)
:VAbstractNode(doc, data, id, idPoint), QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0),
const Tool::Sources &typeCreation, const qint64 &idTool, QGraphicsItem *parent)
:VAbstractNode(doc, data, id, idPoint, idTool), QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0),
lineName(0)
{
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,
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)
{
VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation);
VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, idTool);
Q_ASSERT(point != 0);
doc->AddTool(id, point);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idPoint);
}
}
else
{
doc->UpdateToolData(id, data);
@ -88,6 +96,10 @@ void VNodePoint::AddToFile()
AddAttribute(domElement, AttrIdObject, idNode);
AddAttribute(domElement, AttrMx, toMM(point->mx()));
AddAttribute(domElement, AttrMy, toMM(point->my()));
if (idTool != 0)
{
AddAttribute(domElement, AttrIdTool, idTool);
}
AddToModeling(domElement);
}
@ -101,6 +113,10 @@ void VNodePoint::RefreshDataInFile()
domElement.setAttribute(AttrIdObject, idNode);
domElement.setAttribute(AttrMx, toMM(point->mx()));
domElement.setAttribute(AttrMy, toMM(point->my()));
if (idTool != 0)
{
domElement.setAttribute(AttrIdTool, idTool);
}
}
}

View File

@ -49,7 +49,7 @@ public:
* @param parent
*/
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
* @param doc dom document container
@ -60,7 +60,7 @@ public:
* @param typeCreation
*/
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
*/

View File

@ -34,8 +34,8 @@ const QString VNodeSpline::TagName = QStringLiteral("spline");
const QString VNodeSpline::ToolType = QStringLiteral("modelingSpline");
VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Tool::Sources &typeCreation, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline), QGraphicsPathItem(parent)
const Tool::Sources &typeCreation, const qint64 &idTool, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline, idTool), QGraphicsPathItem(parent)
{
RefreshGeometry();
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,
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;
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);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idSpline);
}
}
else
{
doc->UpdateToolData(id, data);
@ -79,6 +88,10 @@ void VNodeSpline::AddToFile()
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrIdObject, idNode);
if (idTool != 0)
{
AddAttribute(domElement, AttrIdTool, idTool);
}
AddToModeling(domElement);
}
@ -89,6 +102,10 @@ void VNodeSpline::RefreshDataInFile()
if (domElement.isElement())
{
domElement.setAttribute(AttrIdObject, QString().setNum(idNode));
if (idTool != 0)
{
domElement.setAttribute(AttrIdTool, idTool);
}
}
}

View File

@ -49,7 +49,7 @@ public:
* @param parent
*/
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
* @param doc dom document container
@ -61,7 +61,8 @@ public:
* @return
*/
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
*/

View File

@ -34,8 +34,8 @@ const QString VNodeSplinePath::TagName = QStringLiteral("spline");
const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath");
VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Tool::Sources &typeCreation, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline), QGraphicsPathItem(parent)
const Tool::Sources &typeCreation, const qint64 &idTool, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline, idTool), QGraphicsPathItem(parent)
{
RefreshGeometry();
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,
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)
{
VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation);
VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, idTool);
Q_ASSERT(splPath != 0);
doc->AddTool(id, splPath);
const VSplinePath *path = data->GeometricObject<const VSplinePath *>(id);
const QVector<VSplinePoint> *points = path->GetPoint();
for (qint32 i = 0; i<points->size(); ++i)
{
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(points->at(i).P().id());
}
}
}
else
{
doc->UpdateToolData(id, data);
@ -83,6 +91,10 @@ void VNodeSplinePath::AddToFile()
AddAttribute(domElement, AttrId, id);
AddAttribute(domElement, AttrType, ToolType);
AddAttribute(domElement, AttrIdObject, idNode);
if (idTool != 0)
{
AddAttribute(domElement, AttrIdTool, idTool);
}
AddToModeling(domElement);
}
@ -93,6 +105,10 @@ void VNodeSplinePath::RefreshDataInFile()
if (domElement.isElement())
{
domElement.setAttribute(AttrIdObject, QString().setNum(idNode));
if (idTool != 0)
{
domElement.setAttribute(AttrIdTool, idTool);
}
}
}

View File

@ -49,7 +49,8 @@ public:
* @param parent
*/
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
* @param doc dom document container
@ -60,7 +61,7 @@ public:
* @param typeCreation
*/
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
*/

View File

@ -65,8 +65,8 @@ const QString VAbstractTool::AttrAxisP2 = QStringLiteral("axisP2");
const QString VAbstractTool::TypeLineNone = QStringLiteral("none");
const QString VAbstractTool::TypeLineLine = QStringLiteral("hair");
VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent)
:VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black)
VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id)
:VDataTool(data), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black)
{
Q_ASSERT(doc != 0);
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();
*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 parent
*/
VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0);
VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id);
virtual ~VAbstractTool() {}
/**
* @brief LineIntersectRect
@ -239,6 +239,13 @@ public:
* @brief 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:
/**
* @brief FullUpdateFromFile

View File

@ -81,8 +81,8 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id,
void VToolDetail::setDialog()
{
Q_ASSERT(dialogDetail.isNull() == false);
const VDetail *detail = VAbstractTool::data.GeometricObject<const VDetail *>(id);
dialogDetail->setDetails(*detail);
VDetail detail = VAbstractTool::data.GetDetail(id);
dialogDetail->setDetails(detail);
}
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);
}
}
VAbstractTool::AddRecord(id, Tool::Detail, doc);
if (parse == Document::FullParse)
{
VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene);
@ -170,7 +171,7 @@ void VToolDetail::Remove()
RemoveReferens();
element.removeChild(domElement);
//update xml file
emit FullUpdateTree();
//emit FullUpdateTree();
//remove form scene
emit RemoveTool(this);
}
@ -310,7 +311,30 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
}
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::TagDetail = QStringLiteral("det");
const QString VToolUnionDetails::TagNode = QStringLiteral("node");
const QString VToolUnionDetails::AttrD1P1 = QStringLiteral("d1P1");
const QString VToolUnionDetails::AttrD1P2 = QStringLiteral("d1P2");
const QString VToolUnionDetails::AttrD2P1 = QStringLiteral("d2P1");
const QString VToolUnionDetails::AttrD2P2 = QStringLiteral("d2P2");
const QString VToolUnionDetails::AttrIndexD1 = QStringLiteral("indexD1");
const QString VToolUnionDetails::AttrIndexD2 = QStringLiteral("indexD2");
const QString VToolUnionDetails::AttrIdObject = QStringLiteral("idObject");
const QString VToolUnionDetails::AttrNodeType = QStringLiteral("nodeType");
const QString VToolUnionDetails::NodeTypeContour = QStringLiteral("Contour");
const QString VToolUnionDetails::NodeTypeModeling = QStringLiteral("Modeling");
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 qint64 &d2P2, const Tool::Sources &typeCreation)
:VAbstractTool(doc, data, id), d1(d1), d2(d2), d1P1(d1P1), d1P2(d1P2), d2P1(d2P1), d2P2(d2P2)
const VDetail &d2, const ptrdiff_t &indexD1, const ptrdiff_t &indexD2,
const Tool::Sources &typeCreation)
: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)
{
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)
{
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;
qint64 id = 0, idObject = 0;
switch (det.at(i).getTypeTool())
{
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()));
Q_ASSERT(point != 0);
point->setMode(Draw::Modeling);
BiasRotatePoint(point, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(),
angle);
id = data->AddGObject(point);
VNodePoint::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui );
idObject = data->AddGObject(point);
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;
@ -149,8 +111,15 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons
l1.angle(), QString().setNum(l1.angle()), l2.angle(),
QString().setNum(l2.angle()));
Q_ASSERT(arc1 != 0);
id = data->AddGObject(arc1);
VNodeArc::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui);
arc1->setMode(Draw::Modeling);
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;
@ -181,8 +150,15 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons
qint64 idP4 = data->AddGObject(p4);
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve());
Q_ASSERT(spl != 0);
spl->setMode(Draw::Modeling);
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;
@ -196,6 +172,7 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons
{
VSplinePath *path = new VSplinePath();
Q_ASSERT(path != 0);
path->setMode(Draw::Modeling);
const VSplinePath *splinePath = data->GeometricObject<const VSplinePath *>(det.at(i).getId());
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(),
splinePath->at(i).KAsm1()));
}
id = data->AddGObject(path);
VNodeSplinePath::Create(doc, data, id, det.at(i).getId(), Document::FullParse, Tool::FromGui);
idObject = data->AddGObject(path);
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;
@ -243,40 +225,31 @@ void VToolUnionDetails::AddToNewDetail(VContainer *data, VDetail newDetail, cons
}
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,
const ptrdiff_t &b, const qreal &dx, const qreal &dy, const qint64 &pRotate,
const qreal &angle) const
{
qint64 idCount = 0;
for (ptrdiff_t i = a; i <= b; ++i)
void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &i,
qint64 &idCount, const qreal &dx, const qreal &dy, const qint64 &pRotate,
const qreal &angle)
{
switch (det.at(i).getTypeTool())
{
case (Tool::NodePoint):
{
if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0)
{
++idCount;
}
else
if (qFuzzyCompare(dx+1, 1) == false && qFuzzyCompare(dy+1, 1) == false && pRotate != 0)
{
VPointF *point = new VPointF(*data->GeometricObject<const VPointF *>(det.at(i).getId()));
Q_ASSERT(point != 0);
point->setMode(Draw::Modeling);
BiasRotatePoint(point, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
++idCount;
data->UpdateGObject(idDetail+idCount, point);
++idCount;
}
}
break;
case (Tool::NodeArc):
{
if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0)
{
++idCount;
}
else
if (qFuzzyCompare(dx+1, 1) == false && qFuzzyCompare(dy+1, 1) == false && pRotate != 0)
{
const VArc *arc = data->GeometricObject<const VArc *>(det.at(i).getId());
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(),
QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle()));
Q_ASSERT(arc1);
arc1->setMode(Draw::Modeling);
++idCount;
data->UpdateGObject(idDetail+idCount, arc1);
++idCount;
}
}
break;
case (Tool::NodeSpline):
{
if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0)
{
++idCount;
}
else
if (qFuzzyCompare(dx+1, 1) == false && qFuzzyCompare(dy+1, 1) == false && pRotate != 0)
{
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());
Q_ASSERT(spl != 0);
spl->setMode(Draw::Modeling);
++idCount;
data->UpdateGObject(idDetail+idCount, spl);
++idCount;
}
}
break;
case (Tool::NodeSplinePath):
{
if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0)
{
++idCount;
}
else
if (qFuzzyCompare(dx+1, 1) == false && qFuzzyCompare(dy+1, 1) == false && pRotate != 0)
{
VSplinePath *path = new VSplinePath();
Q_ASSERT(path != 0);
path->setMode(Draw::Modeling);
const VSplinePath *splinePath = data->GeometricObject<const VSplinePath *>(det.at(i).getId());
for (qint32 i = 1; i <= splinePath->Count(); ++i)
{
@ -380,6 +352,8 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
}
++idCount;
data->UpdateGObject(idDetail+idCount, path);
++idCount;
}
}
break;
@ -388,15 +362,14 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
break;
}
}
}
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->setY(point->y()+dy);
QLineF line(pRotate, point->toQPointF());
line.setAngle(angle);
line.setAngle(line.angle()+angle);
point->setX(line.p2().x());
point->setY(line.p2().y());
}
@ -406,20 +379,17 @@ void VToolUnionDetails::Create(QSharedPointer<DialogUnionDetails> &dialog, VMain
{
VDetail d1 = data->GetDetail(dialog->getD1());
VDetail d2 = data->GetDetail(dialog->getD2());
qint64 d1P1 = dialog->getD1P1();
qint64 d1P2 = dialog->getD1P2();
qint64 d2P1 = dialog->getD2P1();
qint64 d2P2 = dialog->getD2P2();
Create(0, d1, d2, dialog->getD1(), dialog->getD2(), d1P1, d1P2, d2P1, d2P2, scene, doc, data, Document::FullParse,
ptrdiff_t indexD1 = dialog->getIndexD1();
ptrdiff_t indexD2 = dialog->getIndexD2();
Create(0, d1, d2, dialog->getD1(), dialog->getD2(), indexD1, indexD2, scene, doc, data, Document::FullParse,
Tool::FromGui);
}
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 &d2P2, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const qint64 &d2id, const ptrdiff_t &indexD1, const ptrdiff_t &indexD2,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VToolUnionDetails *unionDetails = 0;
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
@ -432,9 +402,10 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai
doc->UpdateToolData(id, data);
}
}
VAbstractTool::AddRecord(id, Tool::UnionDetails, doc);
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();
tools->insert(id, unionDetails);
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)
{
//Update corected points
qint64 d1P1 = unionDetails->getD1P1();
qint64 d1P2 = unionDetails->getD1P2();
qint64 d2P1 = unionDetails->getD2P1();
qint64 d2P2 = unionDetails->getD2P2();
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.
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 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,
d1P2, angle);
VNodeDetail det2p1;
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");
VToolDetail::Create(0, newDetail, scene, doc, data, parse, Tool::FromTool);
QHash<qint64, VDataTool*>* tools = doc->getTools();
VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(d1id));
toolDet->Remove();
toolDet = qobject_cast<VToolDetail*>(tools->value(d2id));
toolDet->Remove();
}
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));
VNodeDetail det1p2 = d1.at(d1.indexOfNode(d1P2));
do
{
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());
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,
d1P2, angle);
VNodeDetail det2p1;
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)
{
QDomNodeList nodeList = domElement.childNodes();
VDetail d;
QDomNodeList nodeList = element.childNodes();
qint32 num = nodeList.size();
for (qint32 j = 0; j < num; ++j)
{
@ -552,10 +617,11 @@ QVector<VDetail> VToolUnionDetails::GetDetailFromFile(VDomDocument *doc, const Q
{
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, AttrType, ToolType);
AddAttribute(domElement, AttrD1P1, d1P1);
AddAttribute(domElement, AttrD1P2, d1P2);
AddAttribute(domElement, AttrD2P1, d2P1);
AddAttribute(domElement, AttrD2P2, d2P2);
AddAttribute(domElement, AttrIndexD1, indexD1);
AddAttribute(domElement, AttrIndexD2, indexD2);
AddDetail(domElement, d1);
AddDetail(domElement, d2);
@ -584,10 +648,8 @@ void VToolUnionDetails::RefreshDataInFile()
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
domElement.setAttribute(AttrD1P1, d1P1);
domElement.setAttribute(AttrD1P2, d1P2);
domElement.setAttribute(AttrD2P1, d2P1);
domElement.setAttribute(AttrD2P2, d2P2);
domElement.setAttribute(AttrIndexD1, indexD1);
domElement.setAttribute(AttrIndexD2, indexD2);
QDomNode domNode = domElement.firstChild();
domNode = UpdateDetail(domNode, d1);
@ -607,7 +669,7 @@ void VToolUnionDetails::AddDetail(QDomElement &domElement, VDetail &d)
domElement.appendChild(det);
}
void VToolUnionDetails::AddNode(QDomElement &domElement, VNodeDetail &node)
void VToolUnionDetails::AddNode(QDomElement &domElement, const VNodeDetail &node)
{
QDomElement nod = doc->createElement(TagNode);
@ -643,7 +705,7 @@ void VToolUnionDetails::AddNode(QDomElement &domElement, VNodeDetail &node)
domElement.appendChild(nod);
}
QDomNode VToolUnionDetails::UpdateDetail(QDomNode &domNode, VDetail &d)
QDomNode VToolUnionDetails::UpdateDetail(const QDomNode &domNode, const VDetail &d)
{
//QDomNode domNode = domElement.firstChild();
while (domNode.isNull() == false)
@ -655,10 +717,12 @@ QDomNode VToolUnionDetails::UpdateDetail(QDomNode &domNode, VDetail &d)
{
if (domElement.tagName() == VToolUnionDetails::TagDetail)
{
doc->removeAllChilds(domElement);//delete all nodes in detail
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();
}
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)
{
QDomElement modelingElement;

View File

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

View File

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

View File

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

View File

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

View File

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