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

View File

@ -42,12 +42,10 @@ class DialogUnionDetails : public DialogTool
public:
explicit DialogUnionDetails(const VContainer *data, QWidget *parent = 0);
~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 qint64 getD1() const {return d1;}
inline qint64 getD2() const {return d2;}
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

@ -176,9 +176,11 @@ public:
*/
inline void setNodes(const QVector<VNodeDetail> &value) {nodes = value;}
ptrdiff_t indexOfNode(const qint64 &id) const;
qint64 id() const;
void setId(const qint64 &id);
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,14 +51,22 @@ VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc,
}
void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse,
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);
doc->IncrementReferens(idArc);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idArc);
}
}
else
{
@ -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,14 +58,22 @@ 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);
doc->IncrementReferens(idPoint);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idPoint);
}
}
else
{
@ -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,14 +51,23 @@ 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);
doc->IncrementReferens(idSpline);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idSpline);
}
}
else
{
@ -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,18 +51,26 @@ 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)
{
doc->IncrementReferens(points->at(i).P().id());
if(idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(points->at(i).P().id());
}
}
}
else
@ -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;
}
}
}

File diff suppressed because it is too large Load Diff

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