2013-08-28 10:55:11 +02:00
|
|
|
#include "vtooldetail.h"
|
2013-09-10 14:29:06 +02:00
|
|
|
#include "nodeDetails/nodedetails.h"
|
2013-08-28 10:55:11 +02:00
|
|
|
#include <QDebug>
|
2013-09-10 14:29:06 +02:00
|
|
|
#include "modelingTools/vmodelingtool.h"
|
|
|
|
#include "modelingTools/modelingtools.h"
|
2013-08-28 10:55:11 +02:00
|
|
|
|
|
|
|
VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, VDetail &oldDetail,
|
|
|
|
Tool::Enum typeCreation, Document::Enum parse,
|
|
|
|
VMainGraphicsScene *scene, QGraphicsItem *parent)
|
2013-09-10 14:29:06 +02:00
|
|
|
:VAbstractTool(doc, data, id), QGraphicsPathItem(parent),
|
|
|
|
dialogDetail(QSharedPointer<DialogDetail>()), sceneDetails(scene){
|
2013-08-28 10:55:11 +02:00
|
|
|
VDetail detail = data->GetDetail(id);
|
|
|
|
for(qint32 i = 0; i< detail.CountNode(); ++i){
|
|
|
|
switch(detail[i].getTypeTool()){
|
2013-09-10 14:29:06 +02:00
|
|
|
case(Tools::NodePoint):{
|
|
|
|
VNodePoint *point = VNodePoint::Create(doc, data, detail[i].getId(), oldDetail[i].getId(),
|
|
|
|
detail[i].getMode(), parse, typeCreation);
|
|
|
|
connect(point, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-08-28 10:55:11 +02:00
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
tools->insert(detail[i].getId(),point);
|
|
|
|
point->setParentItem(this);
|
2013-09-10 14:29:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::NodeArc):{
|
|
|
|
VNodeArc *arc = VNodeArc::Create(doc, data, detail[i].getId(), oldDetail[i].getId(),
|
|
|
|
detail[i].getMode(), parse, typeCreation);
|
|
|
|
connect(arc, &VNodeArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
tools->insert(detail[i].getId(), arc);
|
|
|
|
arc->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::NodeSpline):{
|
|
|
|
VNodeSpline *spl = VNodeSpline::Create(doc, data, detail[i].getId(), oldDetail[i].getId(),
|
|
|
|
detail[i].getMode(), parse, typeCreation);
|
|
|
|
connect(spl, &VNodeSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-08-28 10:55:11 +02:00
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
tools->insert(detail[i].getId(), spl);
|
|
|
|
spl->setParentItem(this);
|
2013-09-10 14:29:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::NodeSplinePath):{
|
|
|
|
VNodeSplinePath *splPath = VNodeSplinePath::Create(doc, data, detail[i].getId(),
|
|
|
|
oldDetail[i].getId(),
|
|
|
|
detail[i].getMode(), parse, typeCreation);
|
|
|
|
connect(splPath, &VNodeSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-08-28 10:55:11 +02:00
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
tools->insert(detail[i].getId(), splPath);
|
|
|
|
splPath->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
2013-09-10 14:29:06 +02:00
|
|
|
case(Tools::AlongLineTool):{
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VModelingAlongLine *tool = qobject_cast<VModelingAlongLine*>(tools->value(detail[i].getId()));
|
|
|
|
Q_CHECK_PTR(tool);
|
|
|
|
connect(tool, &VModelingAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::ArcTool):{
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VModelingArc *tool = qobject_cast<VModelingArc*>(tools->value(detail[i].getId()));
|
|
|
|
Q_CHECK_PTR(tool);
|
|
|
|
connect(tool, &VModelingArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::BisectorTool):{
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VModelingBisector *tool = qobject_cast<VModelingBisector*>(tools->value(detail[i].getId()));
|
|
|
|
Q_CHECK_PTR(tool);
|
|
|
|
connect(tool, &VModelingBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::EndLineTool):{
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VModelingEndLine *tool = qobject_cast<VModelingEndLine*>(tools->value(detail[i].getId()));
|
|
|
|
Q_CHECK_PTR(tool);
|
|
|
|
connect(tool, &VModelingEndLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::LineIntersectTool):{
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VModelingLineIntersect *tool = qobject_cast<VModelingLineIntersect*>(tools->value(detail[i].getId()));
|
|
|
|
Q_CHECK_PTR(tool);
|
|
|
|
connect(tool, &VModelingLineIntersect::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::LineTool):{
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VModelingLine *tool = qobject_cast<VModelingLine*>(tools->value(detail[i].getId()));
|
|
|
|
Q_CHECK_PTR(tool);
|
|
|
|
connect(tool, &VModelingLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::NormalTool):{
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VModelingNormal *tool = qobject_cast<VModelingNormal*>(tools->value(detail[i].getId()));
|
|
|
|
Q_CHECK_PTR(tool);
|
|
|
|
connect(tool, &VModelingNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::PointOfContact):{
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VModelingPointOfContact *tool = qobject_cast<VModelingPointOfContact*>(tools->value(detail[i].getId()));
|
|
|
|
Q_CHECK_PTR(tool);
|
|
|
|
connect(tool, &VModelingPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::ShoulderPointTool):{
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VModelingShoulderPoint *tool = qobject_cast<VModelingShoulderPoint*>(tools->value(detail[i].getId()));
|
|
|
|
Q_CHECK_PTR(tool);
|
|
|
|
connect(tool, &VModelingShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::SplinePathTool):{
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VModelingSplinePath *tool = qobject_cast<VModelingSplinePath*>(tools->value(detail[i].getId()));
|
|
|
|
Q_CHECK_PTR(tool);
|
|
|
|
connect(tool, &VModelingSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(Tools::SplineTool):{
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VModelingSpline *tool = qobject_cast<VModelingSpline*>(tools->value(detail[i].getId()));
|
|
|
|
Q_CHECK_PTR(tool);
|
|
|
|
connect(tool, &VModelingSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
RefreshGeometry();
|
|
|
|
this->setPos(detail.getMx(), detail.getMy());
|
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
|
|
if(typeCreation == Tool::FromGui){
|
|
|
|
AddToFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolDetail::setDialog(){
|
|
|
|
Q_ASSERT(!dialogDetail.isNull());
|
|
|
|
if(!dialogDetail.isNull()){
|
|
|
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
|
|
|
dialogDetail->setDetails(detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-11 16:14:21 +02:00
|
|
|
void VToolDetail::Create(QSharedPointer<DialogDetail> &dialog, VMainGraphicsScene *scene,
|
|
|
|
VDomDocument *doc, VContainer *data){
|
2013-08-28 10:55:11 +02:00
|
|
|
VDetail detail = dialog->getDetails();
|
|
|
|
VDetail det;
|
|
|
|
for(qint32 i = 0; i< detail.CountNode(); ++i){
|
|
|
|
qint64 id = 0;
|
|
|
|
switch(detail[i].getTypeTool()){
|
2013-09-10 14:29:06 +02:00
|
|
|
case(Tools::NodePoint):{
|
2013-08-28 10:55:11 +02:00
|
|
|
VPointF point;
|
|
|
|
if(detail[i].getMode() == Draw::Calculation){
|
|
|
|
point = data->GetPoint(detail[i].getId());
|
|
|
|
} else {
|
|
|
|
point = data->GetModelingPoint(detail[i].getId());
|
|
|
|
}
|
|
|
|
id = data->AddModelingPoint(point);
|
|
|
|
}
|
|
|
|
break;
|
2013-09-10 14:29:06 +02:00
|
|
|
case(Tools::NodeArc):{
|
2013-08-28 10:55:11 +02:00
|
|
|
VArc arc;
|
|
|
|
if(detail[i].getMode() == Draw::Calculation){
|
|
|
|
arc = data->GetArc(detail[i].getId());
|
|
|
|
} else {
|
|
|
|
arc = data->GetModelingArc(detail[i].getId());
|
|
|
|
}
|
|
|
|
id = data->AddModelingArc(arc);
|
|
|
|
}
|
|
|
|
break;
|
2013-09-10 14:29:06 +02:00
|
|
|
case(Tools::NodeSpline):{
|
2013-08-28 10:55:11 +02:00
|
|
|
VSpline spline;
|
|
|
|
if(detail[i].getMode() == Draw::Calculation){
|
|
|
|
spline = data->GetSpline(detail[i].getId());
|
|
|
|
} else {
|
|
|
|
spline = data->GetModelingSpline(detail[i].getId());
|
|
|
|
}
|
|
|
|
id = data->AddModelingSpline(spline);
|
|
|
|
}
|
|
|
|
break;
|
2013-09-10 14:29:06 +02:00
|
|
|
case(Tools::NodeSplinePath):{
|
2013-08-28 10:55:11 +02:00
|
|
|
VSplinePath splinePath;
|
|
|
|
if(detail[i].getMode() == Draw::Calculation){
|
|
|
|
splinePath = data->GetSplinePath(detail[i].getId());
|
|
|
|
} else {
|
|
|
|
splinePath = data->GetModelingSplinePath(detail[i].getId());
|
|
|
|
}
|
|
|
|
id = data->AddModelingSplinePath(splinePath);
|
|
|
|
}
|
|
|
|
break;
|
2013-09-10 14:29:06 +02:00
|
|
|
default:
|
|
|
|
qWarning()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
2013-08-28 10:55:11 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-09-10 14:29:06 +02:00
|
|
|
VNodeDetail node(id, detail[i].getTypeTool(), detail[i].getMode(), NodeDetail::Contour);
|
2013-08-28 10:55:11 +02:00
|
|
|
det.append(node);
|
|
|
|
}
|
|
|
|
det.setName(detail.getName());
|
|
|
|
Create(0, det, detail, scene, doc, data, Document::FullParse, Tool::FromGui);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolDetail::Create(const qint64 _id, VDetail &newDetail, VDetail &oldDetail,
|
|
|
|
VMainGraphicsScene *scene, VDomDocument *doc,
|
|
|
|
VContainer *data, Document::Enum parse, Tool::Enum typeCreation){
|
|
|
|
qint64 id = _id;
|
|
|
|
if(typeCreation == Tool::FromGui){
|
|
|
|
id = data->AddDetail(newDetail);
|
|
|
|
} else {
|
|
|
|
data->UpdateDetail(id, newDetail);
|
|
|
|
if(parse != Document::FullParse){
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
VDataTool *tool = tools->value(id);
|
|
|
|
if(tool != 0){
|
|
|
|
tool->VDataTool::setData(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(qint32 i = 0; i< newDetail.CountNode(); ++i){
|
|
|
|
VDataTool *tool = tools->value(newDetail[i].getId());
|
|
|
|
if(tool != 0){
|
|
|
|
tool->VDataTool::setData(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(parse == Document::FullParse){
|
|
|
|
VToolDetail *detail = new VToolDetail(doc, data, id, oldDetail, typeCreation, parse, scene);
|
|
|
|
scene->addItem(detail);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(detail, &VToolDetail::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-08-28 10:55:11 +02:00
|
|
|
//connect(detail, &VToolBisector::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
|
|
|
|
QMap<qint64, VDataTool*>* tools = doc->getTools();
|
|
|
|
tools->insert(id, detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolDetail::FullUpdateFromFile(){
|
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2013-08-29 12:31:50 +02:00
|
|
|
void VToolDetail::FullUpdateFromGui(int result){
|
|
|
|
Q_UNUSED(result);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VToolDetail::AddToFile(){
|
|
|
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
|
|
|
QDomElement domElement = doc->createElement("detail");
|
|
|
|
|
|
|
|
AddAttribute(domElement, "id", id);
|
|
|
|
AddAttribute(domElement, "name", detail.getName());
|
|
|
|
AddAttribute(domElement, "mx", detail.getMx());
|
|
|
|
AddAttribute(domElement, "my", detail.getMy());
|
|
|
|
|
|
|
|
for(qint32 i = 0; i < detail.CountNode(); ++i){
|
|
|
|
AddNode(domElement, detail[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDomElement element;
|
|
|
|
bool ok = doc->GetActivDetailsElement(element);
|
|
|
|
if(ok){
|
|
|
|
element.appendChild(domElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){
|
|
|
|
if (change == ItemPositionHasChanged && scene()) {
|
|
|
|
// value - это новое положение.
|
|
|
|
QPointF newPos = value.toPointF();
|
2013-09-10 14:29:06 +02:00
|
|
|
//qDebug()<<newPos;
|
2013-08-28 10:55:11 +02:00
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if(domElement.isElement()){
|
|
|
|
domElement.setAttribute("mx", QString().setNum(toMM(newPos.x())));
|
|
|
|
domElement.setAttribute("my", QString().setNum(toMM(newPos.y())));
|
|
|
|
//I don't now why but signal does not work.
|
|
|
|
doc->FullUpdateTree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
|
|
|
|
if(event->button() == Qt::LeftButton){
|
|
|
|
emit ChoosedTool(id, Scene::Detail);
|
|
|
|
}
|
|
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-08-28 10:55:11 +02:00
|
|
|
void VToolDetail::AddNode(QDomElement &domElement, VNodeDetail &node){
|
|
|
|
QDomElement nod = doc->createElement("node");
|
|
|
|
|
2013-09-11 16:14:21 +02:00
|
|
|
AddAttribute(nod, "idObject", node.getId());
|
2013-09-10 14:29:06 +02:00
|
|
|
if(node.getTypeNode() == NodeDetail::Contour){
|
|
|
|
AddAttribute(nod, "nodeType", "Contour");
|
|
|
|
} else {
|
|
|
|
AddAttribute(nod, "nodeType", "Modeling");
|
|
|
|
}
|
2013-08-28 10:55:11 +02:00
|
|
|
switch(node.getTypeTool()){
|
2013-09-10 14:29:06 +02:00
|
|
|
case(Tools::AlongLineTool):
|
|
|
|
AddAttribute(nod, "type", "AlongLineTool");
|
|
|
|
break;
|
|
|
|
case(Tools::ArcTool):
|
|
|
|
AddAttribute(nod, "type", "ArcTool");
|
|
|
|
break;
|
|
|
|
case(Tools::BisectorTool):
|
|
|
|
AddAttribute(nod, "type", "BisectorTool");
|
|
|
|
break;
|
|
|
|
case(Tools::EndLineTool):
|
|
|
|
AddAttribute(nod, "type", "EndLineTool");
|
|
|
|
break;
|
|
|
|
case(Tools::LineIntersectTool):
|
|
|
|
AddAttribute(nod, "type", "LineIntersectTool");
|
|
|
|
break;
|
|
|
|
case(Tools::LineTool):
|
|
|
|
AddAttribute(nod, "type", "LineTool");
|
|
|
|
break;
|
|
|
|
case(Tools::NodeArc):
|
|
|
|
AddAttribute(nod, "type", "NodeArc");
|
|
|
|
break;
|
|
|
|
case(Tools::NodePoint):
|
|
|
|
AddAttribute(nod, "type", "NodePoint");
|
|
|
|
break;
|
|
|
|
case(Tools::NodeSpline):
|
|
|
|
AddAttribute(nod, "type", "NodeSpline");
|
|
|
|
break;
|
|
|
|
case(Tools::NodeSplinePath):
|
|
|
|
AddAttribute(nod, "type", "NodeSplinePath");
|
|
|
|
break;
|
|
|
|
case(Tools::NormalTool):
|
|
|
|
AddAttribute(nod, "type", "NormalTool");
|
|
|
|
break;
|
|
|
|
case(Tools::PointOfContact):
|
|
|
|
AddAttribute(nod, "type", "PointOfContact");
|
|
|
|
break;
|
|
|
|
case(Tools::ShoulderPointTool):
|
|
|
|
AddAttribute(nod, "type", "ShoulderPointTool");
|
|
|
|
break;
|
|
|
|
case(Tools::SplinePathTool):
|
|
|
|
AddAttribute(nod, "type", "SplinePathTool");
|
|
|
|
break;
|
|
|
|
case(Tools::SplineTool):
|
|
|
|
AddAttribute(nod, "type", "SplineTool");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qWarning()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
2013-08-28 10:55:11 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
domElement.appendChild(nod);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolDetail::RefreshGeometry(){
|
2013-08-29 12:31:50 +02:00
|
|
|
QPainterPath path = VAbstractTool::data.ContourPath(id);
|
2013-08-28 10:55:11 +02:00
|
|
|
this->setPath(path);
|
|
|
|
}
|