Refactor tool clases to pass data in structure.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-09-18 11:37:23 +03:00
parent 783f2f1296
commit e7db934fb5
99 changed files with 3365 additions and 3131 deletions

View File

@ -263,9 +263,19 @@ void MainWindow::AddPP(const QString &PPName)
ui->view->itemClicked(nullptr);//hide options previous tool
const QString label = doc->GenerateLabel(LabelType::NewPatternPiece);
const QPointF startPosition = StartPositionNewPP();
VPointF *point = new VPointF(startPosition.x(), startPosition.y(), label, 5, 10);
auto spoint = VToolBasePoint::Create(0, PPName, point, sceneDraw, doc, pattern, Document::FullParse,
Source::FromGui);
VToolBasePointInitData initData;
initData.scene = sceneDraw;
initData.doc = doc;
initData.data = pattern;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
initData.x = startPosition.x();
initData.y = startPosition.y();
initData.name = label;
initData.nameActivPP = PPName;
auto spoint = VToolBasePoint::Create(initData);
ui->view->itemClicked(spoint);
SetEnableTool(true);

File diff suppressed because it is too large Load Diff

View File

@ -36,6 +36,8 @@
class VMainGraphicsScene;
class VNodeDetail;
class VToolSinglePointInitData;
class VToolLinePointInitData;
/**
* @brief The VPattern class working with pattern file.
@ -155,10 +157,8 @@ private:
void ParseIncrementsElement(const QDomNode& node);
void PrepareForParse(const Document &parse);
void ToolsCommonAttributes(const QDomElement &domElement, quint32 &id);
void PointsCommonAttributes(const QDomElement &domElement, quint32 &id, QString &name, qreal &mx,
qreal &my, bool &labelVisible, QString &typeLine, QString &lineColor);
void PointsCommonAttributes(const QDomElement &domElement, quint32 &id, QString &name, qreal &mx,
qreal &my, bool &labelVisible);
void PointsWithLineCommonAttributes(const QDomElement &domElement, VToolLinePointInitData &initData);
void PointsCommonAttributes(const QDomElement &domElement, VToolSinglePointInitData &initData);
void PointsCommonAttributes(const QDomElement &domElement, quint32 &id, qreal &mx, qreal &my);
void SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject,
quint32 &idTool);

View File

@ -46,21 +46,19 @@ VAbstractFlipping::VAbstractFlipping(VAbstractPattern *doc, VContainer *data, qu
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractFlipping::CreateDestination(Source typeCreation, quint32 &id, QVector<DestinationItem> &dest,
const QVector<quint32> &source, const QPointF &fPoint, const QPointF &sPoint,
const QString &suffix, VAbstractPattern *doc, VContainer *data,
const Document &parse)
void VAbstractFlipping::CreateDestination(VAbstractOperationInitData &initData, const QPointF &fPoint,
const QPointF &sPoint)
{
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
dest.clear();// Try to avoid mistake, value must be empty
initData.destination.clear();// Try to avoid mistake, value must be empty
id = VContainer::getNextId();//Just reserve id for tool
initData.id = VContainer::getNextId();//Just reserve id for tool
for (int i = 0; i < source.size(); ++i)
for (int i = 0; i < initData.source.size(); ++i)
{
const quint32 idObject = source.at(i);
const QSharedPointer<VGObject> obj = data->GetGObject(idObject);
const quint32 idObject = initData.source.at(i);
const QSharedPointer<VGObject> obj = initData.data->GetGObject(idObject);
// This check helps to find missed objects in the switch
Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 7, "Not all objects were handled.");
@ -70,25 +68,34 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch(static_cast<GOType>(obj->getType()))
{
case GOType::Point:
dest.append(CreatePoint(id, idObject, fPoint, sPoint, suffix, data));
initData.destination.append(CreatePoint(initData.id, idObject, fPoint, sPoint, initData.suffix,
initData.data));
break;
case GOType::Arc:
dest.append(CreateArc<VArc>(id, idObject, fPoint, sPoint, suffix, data));
initData.destination.append(CreateArc<VArc>(initData.id, idObject, fPoint, sPoint, initData.suffix,
initData.data));
break;
case GOType::EllipticalArc:
dest.append(CreateArc<VEllipticalArc>(id, idObject, fPoint, sPoint, suffix, data));
initData.destination.append(CreateArc<VEllipticalArc>(initData.id, idObject, fPoint, sPoint,
initData.suffix, initData.data));
break;
case GOType::Spline:
dest.append(CreateCurve<VSpline>(id, idObject, fPoint, sPoint, suffix, data));
initData.destination.append(CreateCurve<VSpline>(initData.id, idObject, fPoint, sPoint,
initData.suffix, initData.data));
break;
case GOType::SplinePath:
dest.append(CreateCurveWithSegments<VSplinePath>(id, idObject, fPoint, sPoint, suffix, data));
initData.destination.append(CreateCurveWithSegments<VSplinePath>(initData.id, idObject, fPoint,
sPoint, initData.suffix,
initData.data));
break;
case GOType::CubicBezier:
dest.append(CreateCurve<VCubicBezier>(id, idObject, fPoint, sPoint, suffix, data));
initData.destination.append(CreateCurve<VCubicBezier>(initData.id, idObject, fPoint, sPoint,
initData.suffix, initData.data));
break;
case GOType::CubicBezierPath:
dest.append(CreateCurveWithSegments<VCubicBezierPath>(id, idObject, fPoint, sPoint, suffix, data));
initData.destination.append(CreateCurveWithSegments<VCubicBezierPath>(initData.id, idObject, fPoint,
sPoint, initData.suffix,
initData.data));
break;
case GOType::Unknown:
break;
@ -98,10 +105,10 @@ QT_WARNING_POP
}
else
{
for (int i = 0; i < source.size(); ++i)
for (int i = 0; i < initData.source.size(); ++i)
{
const quint32 idObject = source.at(i);
const QSharedPointer<VGObject> obj = data->GetGObject(idObject);
const quint32 idObject = initData.source.at(i);
const QSharedPointer<VGObject> obj = initData.data->GetGObject(idObject);
// This check helps to find missed objects in the switch
Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 7, "Not all objects were handled.");
@ -111,36 +118,44 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch(static_cast<GOType>(obj->getType()))
{
case GOType::Point:
UpdatePoint(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id, dest.at(i).mx,
dest.at(i).my);
{
const DestinationItem &item = initData.destination.at(i);
UpdatePoint(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, item.id, item.mx,
item.my);
break;
}
case GOType::Arc:
UpdateArc<VArc>(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id);
UpdateArc<VArc>(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::EllipticalArc:
UpdateArc<VEllipticalArc>(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id);
UpdateArc<VEllipticalArc>(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::Spline:
UpdateCurve<VSpline>(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id);
UpdateCurve<VSpline>(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::SplinePath:
UpdateCurveWithSegments<VSplinePath>(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id);
UpdateCurveWithSegments<VSplinePath>(initData.id, idObject, fPoint, sPoint, initData.suffix,
initData.data, initData.destination.at(i).id);
break;
case GOType::CubicBezier:
UpdateCurve<VCubicBezier>(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id);
UpdateCurve<VCubicBezier>(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::CubicBezierPath:
UpdateCurveWithSegments<VCubicBezierPath>(id, idObject, fPoint, sPoint, suffix, data,
dest.at(i).id);
UpdateCurveWithSegments<VCubicBezierPath>(initData.id, idObject, fPoint, sPoint, initData.suffix,
initData.data, initData.destination.at(i).id);
break;
case GOType::Unknown:
break;
}
QT_WARNING_POP
}
if (parse != Document::FullParse)
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
}

View File

@ -43,10 +43,7 @@ protected:
const QVector<quint32> &source, const QVector<DestinationItem> &destination,
QGraphicsItem *parent = nullptr);
static void CreateDestination(Source typeCreation, quint32 &id, QVector<DestinationItem> &dest,
const QVector<quint32> &source, const QPointF &fPoint, const QPointF &sPoint,
const QString &suffix, VAbstractPattern *doc, VContainer *data,
const Document &parse);
static void CreateDestination(VAbstractOperationInitData &initData, const QPointF &fPoint, const QPointF &sPoint);
static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint,
const QPointF &secondPoint, const QString &suffix, VContainer *data);

View File

@ -84,12 +84,19 @@ VToolFlippingByAxis *VToolFlippingByAxis::Create(QSharedPointer<DialogTool> dial
SCASSERT(not dialog.isNull())
QSharedPointer<DialogFlippingByAxis> dialogTool = dialog.objectCast<DialogFlippingByAxis>();
SCASSERT(not dialogTool.isNull())
const quint32 originPointId = dialogTool->GetOriginPointId();
const AxisType axisType = dialogTool->GetAxisType();
const QString suffix = dialogTool->GetSuffix();
const QVector<quint32> source = dialogTool->GetObjects();
VToolFlippingByAxis* operation = Create(0, originPointId, axisType, suffix, source, QVector<DestinationItem>(),
scene, doc, data, Document::FullParse, Source::FromGui);
VToolFlippingByAxisInitData initData;
initData.originPointId = dialogTool->GetOriginPointId();
initData.axisType = dialogTool->GetAxisType();
initData.suffix = dialogTool->GetSuffix();
initData.source = dialogTool->GetObjects();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolFlippingByAxis* operation = Create(initData);
if (operation != nullptr)
{
operation->m_dialog = dialogTool;
@ -98,17 +105,13 @@ VToolFlippingByAxis *VToolFlippingByAxis::Create(QSharedPointer<DialogTool> dial
}
//---------------------------------------------------------------------------------------------------------------------
VToolFlippingByAxis *VToolFlippingByAxis::Create(const quint32 _id, quint32 originPointId, AxisType axisType,
const QString &suffix, const QVector<quint32> &source,
const QVector<DestinationItem> &destination, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
VToolFlippingByAxis *VToolFlippingByAxis::Create(VToolFlippingByAxisInitData initData)
{
const auto originPoint = *data->GeometricObject<VPointF>(originPointId);
const auto originPoint = *initData.data->GeometricObject<VPointF>(initData.originPointId);
const QPointF fPoint = static_cast<QPointF>(originPoint);
QPointF sPoint;
if (axisType == AxisType::VerticalAxis)
if (initData.axisType == AxisType::VerticalAxis)
{
sPoint = QPointF(fPoint.x(), fPoint.y() + 100);
}
@ -117,23 +120,19 @@ VToolFlippingByAxis *VToolFlippingByAxis::Create(const quint32 _id, quint32 orig
sPoint = QPointF(fPoint.x() + 100, fPoint.y());
}
QVector<DestinationItem> dest = destination;
CreateDestination(initData, fPoint, sPoint);
quint32 id = _id;
CreateDestination(typeCreation, id, dest, source, fPoint, sPoint, suffix, doc, data, parse);
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::FlippingByAxis, doc);
VToolFlippingByAxis *tool = new VToolFlippingByAxis(doc, data, id, originPointId, axisType, suffix, source,
dest, typeCreation);
scene->addItem(tool);
InitOperationToolConnections(scene, tool);
VAbstractPattern::AddTool(id, tool);
doc->IncrementReferens(originPoint.getIdTool());
for (int i = 0; i < source.size(); ++i)
VAbstractTool::AddRecord(initData.id, Tool::FlippingByAxis, initData.doc);
VToolFlippingByAxis *tool = new VToolFlippingByAxis(initData);
initData.scene->addItem(tool);
InitOperationToolConnections(initData.scene, tool);
VAbstractPattern::AddTool(initData.id, tool);
initData.doc->IncrementReferens(originPoint.getIdTool());
for (int i = 0; i < initData.source.size(); ++i)
{
doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool());
initData.doc->IncrementReferens(initData.data->GetGObject(initData.source.at(i))->getIdTool());
}
return tool;
}
@ -239,15 +238,13 @@ QString VToolFlippingByAxis::MakeToolTip() const
}
//---------------------------------------------------------------------------------------------------------------------
VToolFlippingByAxis::VToolFlippingByAxis(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 originPointId,
AxisType axisType, const QString &suffix,
const QVector<quint32> &source, const QVector<DestinationItem> &destination,
const Source &typeCreation, QGraphicsItem *parent)
: VAbstractFlipping(doc, data, id, suffix, source, destination, parent),
m_originPointId(originPointId),
m_axisType(axisType)
VToolFlippingByAxis::VToolFlippingByAxis(const VToolFlippingByAxisInitData &initData, QGraphicsItem *parent)
: VAbstractFlipping(initData.doc, initData.data, initData.id, initData.suffix, initData.source,
initData.destination, parent),
m_originPointId(initData.originPointId),
m_axisType(initData.axisType)
{
InitOperatedObjects();
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}

View File

@ -33,6 +33,18 @@
#include "vabstractflipping.h"
struct VToolFlippingByAxisInitData : public VAbstractOperationInitData
{
VToolFlippingByAxisInitData()
: VAbstractOperationInitData(),
originPointId(NULL_ID),
axisType(AxisType::VerticalAxis)
{}
quint32 originPointId;
AxisType axisType;
};
class VToolFlippingByAxis : public VAbstractFlipping
{
Q_OBJECT
@ -41,11 +53,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolFlippingByAxis* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolFlippingByAxis* Create(const quint32 _id, quint32 originPointId, AxisType axisType,
const QString &suffix, const QVector<quint32> &source,
const QVector<DestinationItem> &destination, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static VToolFlippingByAxis* Create(VToolFlippingByAxisInitData initData);
static const QString ToolType;
@ -72,10 +80,7 @@ private:
quint32 m_originPointId;
AxisType m_axisType;
VToolFlippingByAxis(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 originPointId,
AxisType axisType, const QString &suffix, const QVector<quint32> &source,
const QVector<DestinationItem> &destination, const Source &typeCreation,
QGraphicsItem *parent = nullptr);
VToolFlippingByAxis(const VToolFlippingByAxisInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLFLIPPINGBYAXIS_H

View File

@ -84,13 +84,19 @@ VToolFlippingByLine *VToolFlippingByLine::Create(QSharedPointer<DialogTool> dial
SCASSERT(not dialog.isNull())
QSharedPointer<DialogFlippingByLine> dialogTool = dialog.objectCast<DialogFlippingByLine>();
SCASSERT(not dialogTool.isNull())
const quint32 firstLinePointId = dialogTool->GetFirstLinePointId();
const quint32 secondLinePointId = dialogTool->GetSecondLinePointId();
const QString suffix = dialogTool->GetSuffix();
const QVector<quint32> source = dialogTool->GetObjects();
VToolFlippingByLine* operation = Create(0, firstLinePointId, secondLinePointId, suffix, source,
QVector<DestinationItem>(), scene, doc, data, Document::FullParse,
Source::FromGui);
VToolFlippingByLineInitData initData;
initData.firstLinePointId = dialogTool->GetFirstLinePointId();
initData.secondLinePointId = dialogTool->GetSecondLinePointId();
initData.suffix = dialogTool->GetSuffix();
initData.source = dialogTool->GetObjects();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolFlippingByLine* operation = Create(initData);
if (operation != nullptr)
{
operation->m_dialog = dialogTool;
@ -99,36 +105,28 @@ VToolFlippingByLine *VToolFlippingByLine::Create(QSharedPointer<DialogTool> dial
}
//---------------------------------------------------------------------------------------------------------------------
VToolFlippingByLine *VToolFlippingByLine::Create(const quint32 _id, quint32 firstLinePointId, quint32 secondLinePointId,
const QString &suffix, const QVector<quint32> &source,
const QVector<DestinationItem> &destination, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
VToolFlippingByLine *VToolFlippingByLine::Create(VToolFlippingByLineInitData initData)
{
const auto firstPoint = *data->GeometricObject<VPointF>(firstLinePointId);
const auto firstPoint = *initData.data->GeometricObject<VPointF>(initData.firstLinePointId);
const QPointF fPoint = static_cast<QPointF>(firstPoint);
const auto secondPoint = *data->GeometricObject<VPointF>(secondLinePointId);
const auto secondPoint = *initData.data->GeometricObject<VPointF>(initData.secondLinePointId);
const QPointF sPoint = static_cast<QPointF>(secondPoint);
QVector<DestinationItem> dest = destination;
CreateDestination(initData, fPoint, sPoint);
quint32 id = _id;
CreateDestination(typeCreation, id, dest, source, fPoint, sPoint, suffix, doc, data, parse);
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::FlippingByLine, doc);
VToolFlippingByLine *tool = new VToolFlippingByLine(doc, data, id, firstLinePointId, secondLinePointId, suffix,
source, dest, typeCreation);
scene->addItem(tool);
InitOperationToolConnections(scene, tool);
VAbstractPattern::AddTool(id, tool);
doc->IncrementReferens(firstPoint.getIdTool());
doc->IncrementReferens(secondPoint.getIdTool());
for (int i = 0; i < source.size(); ++i)
VAbstractTool::AddRecord(initData.id, Tool::FlippingByLine, initData.doc);
VToolFlippingByLine *tool = new VToolFlippingByLine(initData);
initData.scene->addItem(tool);
InitOperationToolConnections(initData.scene, tool);
VAbstractPattern::AddTool(initData.id, tool);
initData.doc->IncrementReferens(firstPoint.getIdTool());
initData.doc->IncrementReferens(secondPoint.getIdTool());
for (int i = 0; i < initData.source.size(); ++i)
{
doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool());
initData.doc->IncrementReferens(initData.data->GetGObject(initData.source.at(i))->getIdTool());
}
return tool;
}
@ -228,14 +226,12 @@ QString VToolFlippingByLine::MakeToolTip() const
}
//---------------------------------------------------------------------------------------------------------------------
VToolFlippingByLine::VToolFlippingByLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstLinePointId,
quint32 secondLinePointId, const QString &suffix,
const QVector<quint32> &source, const QVector<DestinationItem> &destination,
const Source &typeCreation, QGraphicsItem *parent)
: VAbstractFlipping(doc, data, id, suffix, source, destination, parent),
m_firstLinePointId(firstLinePointId),
m_secondLinePointId(secondLinePointId)
VToolFlippingByLine::VToolFlippingByLine(const VToolFlippingByLineInitData &initData, QGraphicsItem *parent)
: VAbstractFlipping(initData.doc, initData.data, initData.id, initData.suffix, initData.source,
initData.destination, parent),
m_firstLinePointId(initData.firstLinePointId),
m_secondLinePointId(initData.secondLinePointId)
{
InitOperatedObjects();
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}

View File

@ -33,6 +33,19 @@
#include "vabstractflipping.h"
struct VToolFlippingByLineInitData : public VAbstractOperationInitData
{
VToolFlippingByLineInitData()
: VAbstractOperationInitData(),
firstLinePointId(NULL_ID),
secondLinePointId(NULL_ID)
{}
quint32 firstLinePointId;
quint32 secondLinePointId;
};
class VToolFlippingByLine : public VAbstractFlipping
{
Q_OBJECT
@ -41,11 +54,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolFlippingByLine* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolFlippingByLine* Create(const quint32 _id, quint32 firstLinePointId, quint32 secondLinePointId,
const QString &suffix, const QVector<quint32> &source,
const QVector<DestinationItem> &destination, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static VToolFlippingByLine* Create(VToolFlippingByLineInitData initData);
static const QString ToolType;
@ -70,10 +79,7 @@ private:
quint32 m_firstLinePointId;
quint32 m_secondLinePointId;
VToolFlippingByLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstLinePointId,
quint32 secondLinePointId, const QString &suffix, const QVector<quint32> &source,
const QVector<DestinationItem> &destination, const Source &typeCreation,
QGraphicsItem *parent = nullptr);
VToolFlippingByLine(const VToolFlippingByLineInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLFLIPPINGBYLINE_H

View File

@ -85,8 +85,7 @@ void VAbstractOperation::paint(QPainter *painter, const QStyleOptionGraphicsItem
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractOperation::ExtractData(const QDomElement &domElement, QVector<quint32> &source,
QVector<DestinationItem> &destination)
void VAbstractOperation::ExtractData(const QDomElement &domElement, VAbstractOperationInitData &initData)
{
const QDomNodeList nodeList = domElement.childNodes();
for (qint32 i = 0; i < nodeList.size(); ++i)
@ -94,21 +93,21 @@ void VAbstractOperation::ExtractData(const QDomElement &domElement, QVector<quin
const QDomElement dataElement = nodeList.at(i).toElement();
if (not dataElement.isNull() && dataElement.tagName() == TagSource)
{
source.clear();
initData.source.clear();
const QDomNodeList srcList = dataElement.childNodes();
for (qint32 j = 0; j < srcList.size(); ++j)
{
const QDomElement element = srcList.at(j).toElement();
if (not element.isNull())
{
source.append(VDomDocument::GetParametrUInt(element, AttrIdObject, NULL_ID_STR));
initData.source.append(VDomDocument::GetParametrUInt(element, AttrIdObject, NULL_ID_STR));
}
}
}
if (not dataElement.isNull() && dataElement.tagName() == TagDestination)
{
destination.clear();
initData.destination.clear();
const QDomNodeList srcList = dataElement.childNodes();
for (qint32 j = 0; j < srcList.size(); ++j)
{
@ -119,7 +118,7 @@ void VAbstractOperation::ExtractData(const QDomElement &domElement, QVector<quin
d.id = VDomDocument::GetParametrUInt(element, AttrIdObject, NULL_ID_STR);
d.mx = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMx, QString::number(INT_MAX)));
d.my = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMy, QString::number(INT_MAX)));
destination.append(d);
initData.destination.append(d);
}
}
}

View File

@ -49,6 +49,20 @@ struct DestinationItem
qreal my;
};
struct VAbstractOperationInitData : public VAbstractToolInitData
{
VAbstractOperationInitData()
: VAbstractToolInitData(),
suffix(),
source(),
destination()
{}
QString suffix;
QVector<quint32> source;
QVector<DestinationItem> destination;
};
// FIXME. I don't know how to use QGraphicsItem properly, so just took first available finished class.
// QGraphicsItem itself produce case where clicking on empty space produce call to QGraphicsItem.
// And i don't know how to fix it.
@ -73,8 +87,7 @@ public:
virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
static void ExtractData(const QDomElement &domElement, QVector<quint32> &source,
QVector<DestinationItem> &destination);
static void ExtractData(const QDomElement &domElement, VAbstractOperationInitData &initData);
public slots:
virtual void FullUpdateFromFile() Q_DECL_OVERRIDE;

View File

@ -92,12 +92,19 @@ VToolMove *VToolMove::Create(QSharedPointer<DialogTool> dialog, VMainGraphicsSce
SCASSERT(not dialog.isNull())
QSharedPointer<DialogMove> dialogTool = dialog.objectCast<DialogMove>();
SCASSERT(not dialogTool.isNull())
QString angle = dialogTool->GetAngle();
QString length = dialogTool->GetLength();
const QString suffix = dialogTool->GetSuffix();
const QVector<quint32> source = dialogTool->GetObjects();
VToolMove* operation = Create(0, angle, length, suffix, source, QVector<DestinationItem>(), scene, doc, data,
Document::FullParse, Source::FromGui);
VToolMoveInitData initData;
initData.formulaAngle = dialogTool->GetAngle();
initData.formulaLength = dialogTool->GetLength();
initData.suffix = dialogTool->GetSuffix();
initData.source = dialogTool->GetObjects();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolMove* operation = Create(initData);
if (operation != nullptr)
{
operation->m_dialog = dialogTool;
@ -106,31 +113,24 @@ VToolMove *VToolMove::Create(QSharedPointer<DialogTool> dialog, VMainGraphicsSce
}
//---------------------------------------------------------------------------------------------------------------------
VToolMove *VToolMove::Create(quint32 _id, QString &formulaAngle, QString &formulaLength,
const QString &suffix, const QVector<quint32> &source,
const QVector<DestinationItem> &destination, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
VToolMove *VToolMove::Create(VToolMoveInitData &initData)
{
qreal calcAngle = 0;
qreal calcLength = 0;
calcAngle = CheckFormula(_id, formulaAngle, data);
calcLength = qApp->toPixel(CheckFormula(_id, formulaLength, data));
calcAngle = CheckFormula(initData.id, initData.formulaAngle, initData.data);
calcLength = qApp->toPixel(CheckFormula(initData.id, initData.formulaLength, initData.data));
QVector<DestinationItem> dest = destination;
quint32 id = _id;
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
dest.clear();// Try to avoid mistake, value must be empty
initData.destination.clear();// Try to avoid mistake, value must be empty
id = VContainer::getNextId();//Just reserve id for tool
initData.id = VContainer::getNextId();//Just reserve id for tool
for (int i = 0; i < source.size(); ++i)
for (int i = 0; i < initData.source.size(); ++i)
{
const quint32 idObject = source.at(i);
const QSharedPointer<VGObject> obj = data->GetGObject(idObject);
const quint32 idObject = initData.source.at(i);
const QSharedPointer<VGObject> obj = initData.data->GetGObject(idObject);
// This check helps to find missed objects in the switch
Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 7, "Not all objects were handled.");
@ -140,27 +140,35 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch(static_cast<GOType>(obj->getType()))
{
case GOType::Point:
dest.append(CreatePoint(id, idObject, calcAngle, calcLength, suffix, data));
initData.destination.append(CreatePoint(initData.id, idObject, calcAngle, calcLength,
initData.suffix, initData.data));
break;
case GOType::Arc:
dest.append(CreateArc<VArc>(id, idObject, calcAngle, calcLength, suffix, data));
initData.destination.append(CreateArc<VArc>(initData.id, idObject, calcAngle, calcLength,
initData.suffix, initData.data));
break;
case GOType::EllipticalArc:
dest.append(CreateArc<VEllipticalArc>(id, idObject, calcAngle, calcLength, suffix, data));
initData.destination.append(CreateArc<VEllipticalArc>(initData.id, idObject, calcAngle, calcLength,
initData.suffix, initData.data));
break;
case GOType::Spline:
dest.append(CreateCurve<VSpline>(id, idObject, calcAngle, calcLength, suffix, data));
initData.destination.append(CreateCurve<VSpline>(initData.id, idObject, calcAngle, calcLength,
initData.suffix, initData.data));
break;
case GOType::SplinePath:
dest.append(CreateCurveWithSegments<VSplinePath>(id, idObject, calcAngle, calcLength, suffix,
data));
initData.destination.append(CreateCurveWithSegments<VSplinePath>(initData.id, idObject, calcAngle,
calcLength, initData.suffix,
initData.data));
break;
case GOType::CubicBezier:
dest.append(CreateCurve<VCubicBezier>(id, idObject, calcAngle, calcLength, suffix, data));
initData.destination.append(CreateCurve<VCubicBezier>(initData.id, idObject, calcAngle, calcLength,
initData.suffix, initData.data));
break;
case GOType::CubicBezierPath:
dest.append(CreateCurveWithSegments<VCubicBezierPath>(id, idObject, calcAngle, calcLength, suffix,
data));
initData.destination.append(CreateCurveWithSegments<VCubicBezierPath>(initData.id, idObject,
calcAngle, calcLength,
initData.suffix,
initData.data));
break;
case GOType::Unknown:
break;
@ -170,10 +178,10 @@ QT_WARNING_POP
}
else
{
for (int i = 0; i < source.size(); ++i)
for (int i = 0; i < initData.source.size(); ++i)
{
const quint32 idObject = source.at(i);
const QSharedPointer<VGObject> obj = data->GetGObject(idObject);
const quint32 idObject = initData.source.at(i);
const QSharedPointer<VGObject> obj = initData.data->GetGObject(idObject);
// This check helps to find missed objects in the switch
Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 7, "Not all objects were handled.");
@ -183,51 +191,58 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch(static_cast<GOType>(obj->getType()))
{
case GOType::Point:
UpdatePoint(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id, dest.at(i).mx,
dest.at(i).my);
{
const DestinationItem &item = initData.destination.at(i);
UpdatePoint(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data, item.id,
item.mx, item.my);
break;
}
case GOType::Arc:
UpdateArc<VArc>(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id);
UpdateArc<VArc>(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::EllipticalArc:
UpdateArc<VEllipticalArc>(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id);
UpdateArc<VEllipticalArc>(initData.id, idObject, calcAngle, calcLength, initData.suffix,
initData.data, initData.destination.at(i).id);
break;
case GOType::Spline:
UpdateCurve<VSpline>(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id);
UpdateCurve<VSpline>(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::SplinePath:
UpdateCurveWithSegments<VSplinePath>(id, idObject, calcAngle, calcLength, suffix, data,
dest.at(i).id);
UpdateCurveWithSegments<VSplinePath>(initData.id, idObject, calcAngle, calcLength, initData.suffix,
initData.data, initData.destination.at(i).id);
break;
case GOType::CubicBezier:
UpdateCurve<VCubicBezier>(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id);
UpdateCurve<VCubicBezier>(initData.id, idObject, calcAngle, calcLength, initData.suffix,
initData.data, initData.destination.at(i).id);
break;
case GOType::CubicBezierPath:
UpdateCurveWithSegments<VCubicBezierPath>(id, idObject, calcAngle, calcLength, suffix, data,
dest.at(i).id);
UpdateCurveWithSegments<VCubicBezierPath>(initData.id, idObject, calcAngle, calcLength,
initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::Unknown:
break;
}
QT_WARNING_POP
}
if (parse != Document::FullParse)
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::Move, doc);
VToolMove *tool = new VToolMove(doc, data, id, formulaAngle, formulaLength, suffix, source, dest,
typeCreation);
scene->addItem(tool);
InitOperationToolConnections(scene, tool);
VAbstractPattern::AddTool(id, tool);
for (int i = 0; i < source.size(); ++i)
VAbstractTool::AddRecord(initData.id, Tool::Move, initData.doc);
VToolMove *tool = new VToolMove(initData);
initData.scene->addItem(tool);
InitOperationToolConnections(initData.scene, tool);
VAbstractPattern::AddTool(initData.id, tool);
for (int i = 0; i < initData.source.size(); ++i)
{
doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool());
initData.doc->IncrementReferens(initData.data->GetGObject(initData.source.at(i))->getIdTool());
}
return tool;
}
@ -361,16 +376,14 @@ QString VToolMove::MakeToolTip() const
}
//---------------------------------------------------------------------------------------------------------------------
VToolMove::VToolMove(VAbstractPattern *doc, VContainer *data, quint32 id,
const QString &formulaAngle, const QString &formulaLength, const QString &suffix,
const QVector<quint32> &source, const QVector<DestinationItem> &destination,
const Source &typeCreation, QGraphicsItem *parent)
: VAbstractOperation(doc, data, id, suffix, source, destination, parent),
formulaAngle(formulaAngle),
formulaLength(formulaLength)
VToolMove::VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent)
: VAbstractOperation(initData.doc, initData.data, initData.id, initData.suffix, initData.source,
initData.destination, parent),
formulaAngle(initData.formulaAngle),
formulaLength(initData.formulaLength)
{
InitOperatedObjects();
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -45,6 +45,18 @@
template <class T> class QSharedPointer;
class VFormula;
struct VToolMoveInitData : public VAbstractOperationInitData
{
VToolMoveInitData()
: VAbstractOperationInitData(),
formulaAngle(),
formulaLength()
{}
QString formulaAngle;
QString formulaLength;
};
class VToolMove : public VAbstractOperation
{
Q_OBJECT
@ -53,10 +65,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolMove* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolMove* Create(quint32 _id, QString &formulaAngle, QString &formulaLength, const QString &suffix,
const QVector<quint32> &source, const QVector<DestinationItem> &destination,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolMove* Create(VToolMoveInitData &initData);
static const QString ToolType;
@ -83,10 +92,7 @@ private:
QString formulaAngle;
QString formulaLength;
VToolMove(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &formulaAngle,
const QString &formulaLength, const QString &suffix, const QVector<quint32> &source,
const QVector<DestinationItem> &destination, const Source &typeCreation,
QGraphicsItem *parent = nullptr);
VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent = nullptr);
static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix,
VContainer *data);

View File

@ -80,16 +80,14 @@ template <class T> class QSharedPointer;
const QString VToolRotation::ToolType = QStringLiteral("rotation");
//---------------------------------------------------------------------------------------------------------------------
VToolRotation::VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId,
const QString &angle, const QString &suffix, const QVector<quint32> &source,
const QVector<DestinationItem> &destination, const Source &typeCreation,
QGraphicsItem *parent)
: VAbstractOperation(doc, data, id, suffix, source, destination, parent),
origPointId(origPointId),
formulaAngle(angle)
VToolRotation::VToolRotation(const VToolRotationInitData &initData, QGraphicsItem *parent)
: VAbstractOperation(initData.doc, initData.data, initData.id, initData.suffix, initData.source,
initData.destination, parent),
origPointId(initData.origin),
formulaAngle(initData.angle)
{
InitOperatedObjects();
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -110,12 +108,19 @@ VToolRotation *VToolRotation::Create(QSharedPointer<DialogTool> dialog, VMainGra
SCASSERT(not dialog.isNull())
QSharedPointer<DialogRotation> dialogTool = dialog.objectCast<DialogRotation>();
SCASSERT(not dialogTool.isNull())
const quint32 originPointId = dialogTool->GetOrigPointId();
QString angle = dialogTool->GetAngle();
const QString suffix = dialogTool->GetSuffix();
const QVector<quint32> source = dialogTool->GetObjects();
VToolRotation* operation = Create(0, originPointId, angle, suffix, source, QVector<DestinationItem>(),
scene, doc, data, Document::FullParse, Source::FromGui);
VToolRotationInitData initData;
initData.origin = dialogTool->GetOrigPointId();
initData.angle = dialogTool->GetAngle();
initData.suffix = dialogTool->GetSuffix();
initData.source = dialogTool->GetObjects();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolRotation* operation = Create(initData);
if (operation != nullptr)
{
operation->m_dialog = dialogTool;
@ -124,32 +129,25 @@ VToolRotation *VToolRotation::Create(QSharedPointer<DialogTool> dialog, VMainGra
}
//---------------------------------------------------------------------------------------------------------------------
VToolRotation *VToolRotation::Create(const quint32 _id, const quint32 &origin, QString &angle, const QString &suffix,
const QVector<quint32> &source,
const QVector<DestinationItem> &destination,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolRotation *VToolRotation::Create(VToolRotationInitData &initData)
{
qreal calcAngle = 0;
calcAngle = CheckFormula(_id, angle, data);
calcAngle = CheckFormula(initData.id, initData.angle, initData.data);
const auto originPoint = *data->GeometricObject<VPointF>(origin);
const auto originPoint = *initData.data->GeometricObject<VPointF>(initData.origin);
const QPointF oPoint = static_cast<QPointF>(originPoint);
QVector<DestinationItem> dest = destination;
quint32 id = _id;
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
dest.clear();// Try to avoid mistake, value must be empty
initData.destination.clear();// Try to avoid mistake, value must be empty
id = VContainer::getNextId();//Just reserve id for tool
initData.id = VContainer::getNextId();//Just reserve id for tool
for (int i = 0; i < source.size(); ++i)
for (int i = 0; i < initData.source.size(); ++i)
{
const quint32 idObject = source.at(i);
const QSharedPointer<VGObject> obj = data->GetGObject(idObject);
const quint32 idObject = initData.source.at(i);
const QSharedPointer<VGObject> obj = initData.data->GetGObject(idObject);
// This check helps to find missed objects in the switch
Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 7, "Not all objects were handled.");
@ -159,26 +157,34 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch(static_cast<GOType>(obj->getType()))
{
case GOType::Point:
dest.append(CreatePoint(id, idObject, oPoint, calcAngle, suffix, data));
initData.destination.append(CreatePoint(initData.id, idObject, oPoint, calcAngle, initData.suffix,
initData.data));
break;
case GOType::Arc:
dest.append(CreateArc<VArc>(id, idObject, oPoint, calcAngle, suffix, data));
initData.destination.append(CreateArc<VArc>(initData.id, idObject, oPoint, calcAngle,
initData.suffix, initData.data));
break;
case GOType::EllipticalArc:
dest.append(CreateArc<VEllipticalArc>(id, idObject, oPoint, calcAngle, suffix, data));
initData.destination.append(CreateArc<VEllipticalArc>(initData.id, idObject, oPoint, calcAngle,
initData.suffix, initData.data));
break;
case GOType::Spline:
dest.append(CreateCurve<VSpline>(id, idObject, oPoint, calcAngle, suffix, data));
initData.destination.append(CreateCurve<VSpline>(initData.id, idObject, oPoint, calcAngle,
initData.suffix, initData.data));
break;
case GOType::SplinePath:
dest.append(CreateCurveWithSegments<VSplinePath>(id, idObject, oPoint, calcAngle, suffix, data));
initData.destination.append(CreateCurveWithSegments<VSplinePath>(initData.id, idObject, oPoint,
calcAngle, initData.suffix,
initData.data));
break;
case GOType::CubicBezier:
dest.append(CreateCurve<VCubicBezier>(id, idObject, oPoint, calcAngle, suffix, data));
initData.destination.append(CreateCurve<VCubicBezier>(initData.id, idObject, oPoint, calcAngle,
initData.suffix, initData.data));
break;
case GOType::CubicBezierPath:
dest.append(CreateCurveWithSegments<VCubicBezierPath>(id, idObject, oPoint, calcAngle, suffix,
data));
initData.destination.append(CreateCurveWithSegments<VCubicBezierPath>(initData.id, idObject, oPoint,
calcAngle, initData.suffix,
initData.data));
break;
case GOType::Unknown:
break;
@ -188,10 +194,10 @@ QT_WARNING_POP
}
else
{
for (int i = 0; i < source.size(); ++i)
for (int i = 0; i < initData.source.size(); ++i)
{
const quint32 idObject = source.at(i);
const QSharedPointer<VGObject> obj = data->GetGObject(idObject);
const quint32 idObject = initData.source.at(i);
const QSharedPointer<VGObject> obj = initData.data->GetGObject(idObject);
// This check helps to find missed objects in the switch
Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 7, "Not all objects were handled.");
@ -201,50 +207,58 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch(static_cast<GOType>(obj->getType()))
{
case GOType::Point:
UpdatePoint(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id, dest.at(i).mx,
dest.at(i).my);
{
const DestinationItem &item = initData.destination.at(i);
UpdatePoint(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data,
item.id, item.mx, item.my);
break;
}
case GOType::Arc:
UpdateArc<VArc>(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id);
UpdateArc<VArc>(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::EllipticalArc:
UpdateArc<VEllipticalArc>(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id);
UpdateArc<VEllipticalArc>(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::Spline:
UpdateCurve<VSpline>(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id);
UpdateCurve<VSpline>(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::SplinePath:
UpdateCurveWithSegments<VSplinePath>(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id);
UpdateCurveWithSegments<VSplinePath>(initData.id, idObject, oPoint, calcAngle, initData.suffix,
initData.data, initData.destination.at(i).id);
break;
case GOType::CubicBezier:
UpdateCurve<VCubicBezier>(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id);
UpdateCurve<VCubicBezier>(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data,
initData.destination.at(i).id);
break;
case GOType::CubicBezierPath:
UpdateCurveWithSegments<VCubicBezierPath>(id, idObject, oPoint, calcAngle, suffix, data,
dest.at(i).id);
UpdateCurveWithSegments<VCubicBezierPath>(initData.id, idObject, oPoint, calcAngle, initData.suffix,
initData.data, initData.destination.at(i).id);
break;
case GOType::Unknown:
break;
}
QT_WARNING_POP
}
if (parse != Document::FullParse)
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::Rotation, doc);
VToolRotation *tool = new VToolRotation(doc, data, id, origin, angle, suffix, source, dest, typeCreation);
scene->addItem(tool);
InitOperationToolConnections(scene, tool);
VAbstractPattern::AddTool(id, tool);
doc->IncrementReferens(originPoint.getIdTool());
for (int i = 0; i < source.size(); ++i)
VAbstractTool::AddRecord(initData.id, Tool::Rotation, initData.doc);
VToolRotation *tool = new VToolRotation(initData);
initData.scene->addItem(tool);
InitOperationToolConnections(initData.scene, tool);
VAbstractPattern::AddTool(initData.id, tool);
initData.doc->IncrementReferens(originPoint.getIdTool());
for (int i = 0; i < initData.source.size(); ++i)
{
doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool());
initData.doc->IncrementReferens(initData.data->GetGObject(initData.source.at(i))->getIdTool());
}
return tool;
}

View File

@ -45,6 +45,18 @@
template <class T> class QSharedPointer;
class VFormula;
struct VToolRotationInitData : public VAbstractOperationInitData
{
VToolRotationInitData()
: VAbstractOperationInitData(),
origin(NULL_ID),
angle()
{}
quint32 origin;
QString angle;
};
class VToolRotation : public VAbstractOperation
{
Q_OBJECT
@ -53,10 +65,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolRotation* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolRotation* Create(const quint32 _id, const quint32 &origin, QString &angle, const QString &suffix,
const QVector<quint32> &source, const QVector<DestinationItem> &destination,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolRotation* Create(VToolRotationInitData &initData);
static const QString ToolType;
@ -83,10 +92,7 @@ private:
quint32 origPointId;
QString formulaAngle;
VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId,
const QString &angle, const QString &suffix, const QVector<quint32> &source,
const QVector<DestinationItem> &destination, const Source &typeCreation,
QGraphicsItem *parent = nullptr);
VToolRotation(const VToolRotationInitData &initData, QGraphicsItem *parent = nullptr);
static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
const QString &suffix, VContainer *data);

View File

@ -54,6 +54,18 @@
class VControlPointSpline;
template <class T> class QSharedPointer;
struct VAbstractSplineInitData : public VAbstractToolInitData
{
VAbstractSplineInitData()
: VAbstractToolInitData(),
color(ColorBlack),
penStyle(TypeLineLine)
{}
QString color;
QString penStyle;
};
class VAbstractSpline:public VDrawTool, public QGraphicsPathItem
{
Q_OBJECT

View File

@ -61,21 +61,16 @@ const QString VToolArc::ToolType = QStringLiteral("simple");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolArc constuctor.
* @param doc dom document container
* @param data container with variables
* @param id object id in container
* @param typeCreation way we create this tool.
* @param parent parent object
* @param initData init data
*/
VToolArc::VToolArc(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem *parent)
: VAbstractSpline(doc, data, id, parent)
VToolArc::VToolArc(const VToolArcInitData &initData, QGraphicsItem *parent)
: VAbstractSpline(initData.doc, initData.data, initData.id, parent)
{
sceneType = SceneObject::Arc;
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -110,14 +105,21 @@ VToolArc* VToolArc::Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene
SCASSERT(not dialog.isNull())
QSharedPointer<DialogArc> dialogTool = dialog.objectCast<DialogArc>();
SCASSERT(not dialogTool.isNull())
const quint32 center = dialogTool->GetCenter();
QString radius = dialogTool->GetRadius();
QString f1 = dialogTool->GetF1();
QString f2 = dialogTool->GetF2();
const QString color = dialogTool->GetColor();
const QString penStyle = dialogTool->GetPenStyle();
VToolArc* point = Create(0, center, radius, f1, f2, color, penStyle, scene, doc, data, Document::FullParse,
Source::FromGui);
VToolArcInitData initData;
initData.center = dialogTool->GetCenter();
initData.radius = dialogTool->GetRadius();
initData.f1 = dialogTool->GetF1();
initData.f2 = dialogTool->GetF2();
initData.color = dialogTool->GetColor();
initData.penStyle = dialogTool->GetPenStyle();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolArc* point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -128,56 +130,45 @@ VToolArc* VToolArc::Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool form GUI.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param center id arc center point.
* @param radius arc radius.
* @param f1 start angle of arc.
* @param f2 end angle of arc.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
*/
VToolArc* VToolArc::Create(const quint32 _id, const quint32 &center, QString &radius, QString &f1, QString &f2,
const QString &color, const QString &penStyle, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation)
VToolArc* VToolArc::Create(VToolArcInitData &initData)
{
qreal calcRadius = 0, calcF1 = 0, calcF2 = 0;
calcRadius = qApp->toPixel(CheckFormula(_id, radius, data));
calcRadius = qApp->toPixel(CheckFormula(initData.id, initData.radius, initData.data));
calcF1 = CheckFormula(_id, f1, data);
calcF2 = CheckFormula(_id, f2, data);
calcF1 = CheckFormula(initData.id, initData.f1, initData.data);
calcF2 = CheckFormula(initData.id, initData.f2, initData.data);
const VPointF c = *data->GeometricObject<VPointF>(center);
VArc *arc = new VArc(c, calcRadius, radius, calcF1, f1, calcF2, f2 );
arc->SetColor(color);
arc->SetPenStyle(penStyle);
quint32 id = _id;
if (typeCreation == Source::FromGui)
const VPointF c = *initData.data->GeometricObject<VPointF>(initData.center);
VArc *arc = new VArc(c, calcRadius, initData.radius, calcF1, initData.f1, calcF2, initData.f2 );
arc->SetColor(initData.color);
arc->SetPenStyle(initData.penStyle);
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(arc);
data->AddArc(data->GeometricObject<VArc>(id), id);
initData.id = initData.data->AddGObject(arc);
initData.data->AddArc(initData.data->GeometricObject<VArc>(initData.id), initData.id);
}
else
{
data->UpdateGObject(id, arc);
data->AddArc(data->GeometricObject<VArc>(id), id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, arc);
initData.data->AddArc(initData.data->GeometricObject<VArc>(initData.id), initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::Arc, doc);
VToolArc *toolArc = new VToolArc(doc, data, id, typeCreation);
scene->addItem(toolArc);
InitArcToolConnections(scene, toolArc);
VAbstractPattern::AddTool(id, toolArc);
doc->IncrementReferens(c.getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::Arc, initData.doc);
VToolArc *toolArc = new VToolArc(initData);
initData.scene->addItem(toolArc);
InitArcToolConnections(initData.scene, toolArc);
VAbstractPattern::AddTool(initData.id, toolArc);
initData.doc->IncrementReferens(c.getIdTool());
return toolArc;
}
return nullptr;

View File

@ -43,6 +43,22 @@
class VFormula;
template <class T> class QSharedPointer;
struct VToolArcInitData : public VAbstractSplineInitData
{
VToolArcInitData()
: VAbstractSplineInitData(),
center(NULL_ID),
radius("0"),
f1("0"),
f2("0")
{}
quint32 center;
QString radius;
QString f1;
QString f2;
};
/**
* @brief The VToolArc class tool for creation arc.
*/
@ -53,9 +69,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolArc* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolArc* Create(const quint32 _id, const quint32 &center, QString &radius, QString &f1, QString &f2,
const QString &color, const QString &penStyle, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation);
static VToolArc* Create(VToolArcInitData &initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
@ -88,8 +102,7 @@ protected:
private:
Q_DISABLE_COPY(VToolArc)
VToolArc(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem * parent = nullptr);
VToolArc(const VToolArcInitData &initData, QGraphicsItem * parent = nullptr);
};
#endif // VTOOLARC_H

View File

@ -59,15 +59,14 @@
const QString VToolArcWithLength::ToolType = QStringLiteral("arcWithLength");
//---------------------------------------------------------------------------------------------------------------------
VToolArcWithLength::VToolArcWithLength(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent)
VToolArcWithLength::VToolArcWithLength(const VToolArcWithLengthInitData &initData, QGraphicsItem *parent)
:VAbstractSpline(initData.doc, initData.data, initData.id, parent)
{
sceneType = SceneObject::Arc;
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -92,14 +91,21 @@ VToolArcWithLength *VToolArcWithLength::Create(QSharedPointer<DialogTool> dialog
SCASSERT(not dialog.isNull())
QSharedPointer<DialogArcWithLength> dialogTool = dialog.objectCast<DialogArcWithLength>();
SCASSERT(not dialogTool.isNull())
const quint32 center = dialogTool->GetCenter();
QString radius = dialogTool->GetRadius();
QString f1 = dialogTool->GetF1();
QString length = dialogTool->GetLength();
const QString color = dialogTool->GetColor();
const QString penStyle = dialogTool->GetPenStyle();
VToolArcWithLength* point = Create(0, center, radius, f1, length, color, penStyle, scene, doc, data,
Document::FullParse, Source::FromGui);
VToolArcWithLengthInitData initData;
initData.center = dialogTool->GetCenter();
initData.radius = dialogTool->GetRadius();
initData.f1 = dialogTool->GetF1();
initData.length = dialogTool->GetLength();
initData.color = dialogTool->GetColor();
initData.penStyle = dialogTool->GetPenStyle();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolArcWithLength* point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -108,45 +114,42 @@ VToolArcWithLength *VToolArcWithLength::Create(QSharedPointer<DialogTool> dialog
}
//---------------------------------------------------------------------------------------------------------------------
VToolArcWithLength *VToolArcWithLength::Create(const quint32 _id, const quint32 &center, QString &radius, QString &f1,
QString &length, const QString &color, const QString &penStyle,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolArcWithLength *VToolArcWithLength::Create(VToolArcWithLengthInitData &initData)
{
qreal calcRadius = 0, calcF1 = 0, calcLength = 0;
calcRadius = qApp->toPixel(CheckFormula(_id, radius, data));
calcLength = qApp->toPixel(CheckFormula(_id, length, data));
calcF1 = CheckFormula(_id, f1, data);
calcRadius = qApp->toPixel(CheckFormula(initData.id, initData.radius, initData.data));
calcLength = qApp->toPixel(CheckFormula(initData.id, initData.length, initData.data));
calcF1 = CheckFormula(initData.id, initData.f1, initData.data);
const VPointF c = *data->GeometricObject<VPointF>(center);
VArc *arc = new VArc(calcLength, length, c, calcRadius, radius, calcF1, f1);
arc->SetColor(color);
arc->SetPenStyle(penStyle);
quint32 id = _id;
if (typeCreation == Source::FromGui)
const VPointF c = *initData.data->GeometricObject<VPointF>(initData.center);
VArc *arc = new VArc(calcLength, initData.length, c, calcRadius, initData.radius, calcF1, initData.f1);
arc->SetColor(initData.color);
arc->SetPenStyle(initData.penStyle);
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(arc);
data->AddArc(data->GeometricObject<VArc>(id), id);
initData.id = initData.data->AddGObject(arc);
initData.data->AddArc(initData.data->GeometricObject<VArc>(initData.id), initData.id);
}
else
{
data->UpdateGObject(id, arc);
data->AddArc(data->GeometricObject<VArc>(id), id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, arc);
initData.data->AddArc(initData.data->GeometricObject<VArc>(initData.id), initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::ArcWithLength, doc);
VToolArcWithLength *toolArc = new VToolArcWithLength(doc, data, id, typeCreation);
scene->addItem(toolArc);
InitArcToolConnections(scene, toolArc);
VAbstractPattern::AddTool(id, toolArc);
doc->IncrementReferens(c.getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::ArcWithLength, initData.doc);
VToolArcWithLength *toolArc = new VToolArcWithLength(initData);
initData.scene->addItem(toolArc);
InitArcToolConnections(initData.scene, toolArc);
VAbstractPattern::AddTool(initData.id, toolArc);
initData.doc->IncrementReferens(c.getIdTool());
return toolArc;
}
return nullptr;

View File

@ -43,6 +43,22 @@
class VFormula;
template <class T> class QSharedPointer;
struct VToolArcWithLengthInitData : public VAbstractSplineInitData
{
VToolArcWithLengthInitData()
: VAbstractSplineInitData(),
center(NULL_ID),
radius("0"),
f1("0"),
length("0")
{}
quint32 center;
QString radius;
QString f1;
QString length;
};
class VToolArcWithLength : public VAbstractSpline
{
Q_OBJECT
@ -50,10 +66,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolArcWithLength* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolArcWithLength* Create(const quint32 _id, const quint32 &center, QString &radius, QString &f1,
QString &length, const QString &color, const QString &penStyle,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolArcWithLength* Create(VToolArcWithLengthInitData &initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
@ -86,8 +99,7 @@ protected:
private:
Q_DISABLE_COPY(VToolArcWithLength)
VToolArcWithLength(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem * parent = nullptr);
VToolArcWithLength(const VToolArcWithLengthInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLARCWITHLENGTH_H

View File

@ -57,15 +57,14 @@
const QString VToolCubicBezier::ToolType = QStringLiteral("cubicBezier");
//---------------------------------------------------------------------------------------------------------------------
VToolCubicBezier::VToolCubicBezier(VAbstractPattern *doc, VContainer *data, quint32 id,
const Source &typeCreation, QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent)
VToolCubicBezier::VToolCubicBezier(const VToolCubicBezierInitData &initData, QGraphicsItem *parent)
:VAbstractSpline(initData.doc, initData.data, initData.id, parent)
{
sceneType = SceneObject::Spline;
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -88,11 +87,17 @@ VToolCubicBezier *VToolCubicBezier::Create(QSharedPointer<DialogTool> dialog, VM
QSharedPointer<DialogCubicBezier> dialogTool = dialog.objectCast<DialogCubicBezier>();
SCASSERT(not dialogTool.isNull())
VCubicBezier *spline = new VCubicBezier(dialogTool->GetSpline());
spline->SetColor(dialogTool->GetColor());
spline->SetPenStyle(dialogTool->GetPenStyle());
VToolCubicBezierInitData initData;
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
initData.spline = new VCubicBezier(dialogTool->GetSpline());
initData.spline->SetColor(dialogTool->GetColor());
initData.spline->SetPenStyle(dialogTool->GetPenStyle());
auto spl = Create(0, spline, scene, doc, data, Document::FullParse, Source::FromGui);
auto spl = Create(initData);
if (spl != nullptr)
{
@ -102,37 +107,34 @@ VToolCubicBezier *VToolCubicBezier::Create(QSharedPointer<DialogTool> dialog, VM
}
//---------------------------------------------------------------------------------------------------------------------
VToolCubicBezier *VToolCubicBezier::Create(const quint32 _id, VCubicBezier *spline, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
VToolCubicBezier *VToolCubicBezier::Create(VToolCubicBezierInitData initData)
{
quint32 id = _id;
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(spline);
data->AddSpline(data->GeometricObject<VAbstractBezier>(id), id);
initData.id = initData.data->AddGObject(initData.spline);
initData.data->AddSpline(initData.data->GeometricObject<VAbstractBezier>(initData.id), initData.id);
}
else
{
data->UpdateGObject(id, spline);
data->AddSpline(data->GeometricObject<VAbstractBezier>(id), id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, initData.spline);
initData.data->AddSpline(initData.data->GeometricObject<VAbstractBezier>(initData.id), initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::CubicBezier, doc);
auto _spl = new VToolCubicBezier(doc, data, id, typeCreation);
scene->addItem(_spl);
InitSplineToolConnections(scene, _spl);
VAbstractPattern::AddTool(id, _spl);
doc->IncrementReferens(spline->GetP1().getIdTool());
doc->IncrementReferens(spline->GetP1().getIdTool());
doc->IncrementReferens(spline->GetP1().getIdTool());
doc->IncrementReferens(spline->GetP4().getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::CubicBezier, initData.doc);
auto _spl = new VToolCubicBezier(initData);
initData.scene->addItem(_spl);
InitSplineToolConnections(initData.scene, _spl);
VAbstractPattern::AddTool(initData.id, _spl);
initData.doc->IncrementReferens(initData.spline->GetP1().getIdTool());
initData.doc->IncrementReferens(initData.spline->GetP1().getIdTool());
initData.doc->IncrementReferens(initData.spline->GetP1().getIdTool());
initData.doc->IncrementReferens(initData.spline->GetP4().getIdTool());
return _spl;
}
return nullptr;

View File

@ -43,6 +43,16 @@
class VCubicBezier;
template <class T> class QSharedPointer;
struct VToolCubicBezierInitData : public VAbstractToolInitData
{
VToolCubicBezierInitData()
: VAbstractToolInitData(),
spline(nullptr)
{}
VCubicBezier *spline;
};
class VToolCubicBezier : public VAbstractSpline
{
Q_OBJECT
@ -51,9 +61,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolCubicBezier *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolCubicBezier *Create(const quint32 _id, VCubicBezier *spline, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static VToolCubicBezier *Create(VToolCubicBezierInitData initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::CubicBezier)};
@ -78,8 +86,7 @@ protected:
private:
Q_DISABLE_COPY(VToolCubicBezier)
VToolCubicBezier(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem * parent = nullptr);
VToolCubicBezier(const VToolCubicBezierInitData &initData, QGraphicsItem *parent = nullptr);
void SetSplineAttributes(QDomElement &domElement, const VCubicBezier &spl);
};

View File

@ -59,15 +59,14 @@
const QString VToolCubicBezierPath::ToolType = QStringLiteral("cubicBezierPath");
//---------------------------------------------------------------------------------------------------------------------
VToolCubicBezierPath::VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id,
const Source &typeCreation, QGraphicsItem *parent)
: VAbstractSpline(doc, data, id, parent)
VToolCubicBezierPath::VToolCubicBezierPath(const VToolCubicBezierPathInitData &initData, QGraphicsItem *parent)
: VAbstractSpline(initData.doc, initData.data, initData.id, parent)
{
sceneType = SceneObject::SplinePath;
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -89,17 +88,25 @@ VToolCubicBezierPath *VToolCubicBezierPath::Create(QSharedPointer<DialogTool> di
SCASSERT(not dialog.isNull())
QSharedPointer<DialogCubicBezierPath> dialogTool = dialog.objectCast<DialogCubicBezierPath>();
SCASSERT(not dialogTool.isNull())
auto path = new VCubicBezierPath(dialogTool->GetPath());
VToolCubicBezierPathInitData initData;
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
initData.path = new VCubicBezierPath(dialogTool->GetPath());
const QString color = dialogTool->GetColor();
const QString penStyle = dialogTool->GetPenStyle();
for (qint32 i = 0; i < path->CountPoints(); ++i)
for (qint32 i = 0; i < initData.path->CountPoints(); ++i)
{
doc->IncrementReferens((*path)[i].getIdTool());
doc->IncrementReferens((*initData.path)[i].getIdTool());
}
path->SetColor(color);
path->SetPenStyle(penStyle);
initData.path->SetColor(color);
initData.path->SetPenStyle(penStyle);
VToolCubicBezierPath* spl = Create(0, path, scene, doc, data, Document::FullParse, Source::FromGui);
VToolCubicBezierPath* spl = Create(initData);
if (spl != nullptr)
{
spl->m_dialog = dialogTool;
@ -108,33 +115,32 @@ VToolCubicBezierPath *VToolCubicBezierPath::Create(QSharedPointer<DialogTool> di
}
//---------------------------------------------------------------------------------------------------------------------
VToolCubicBezierPath *VToolCubicBezierPath::Create(const quint32 _id, VCubicBezierPath *path, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
VToolCubicBezierPath *VToolCubicBezierPath::Create(VToolCubicBezierPathInitData initData)
{
quint32 id = _id;
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(path);
data->AddCurveWithSegments(data->GeometricObject<VAbstractCubicBezierPath>(id), id);
initData.id = initData.data->AddGObject(initData.path);
initData.data->AddCurveWithSegments(initData.data->GeometricObject<VAbstractCubicBezierPath>(initData.id),
initData.id);
}
else
{
data->UpdateGObject(id, path);
data->AddCurveWithSegments(data->GeometricObject<VAbstractCubicBezierPath>(id), id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, initData.path);
initData.data->AddCurveWithSegments(initData.data->GeometricObject<VAbstractCubicBezierPath>(initData.id),
initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::CubicBezierPath, doc);
VToolCubicBezierPath *spl = new VToolCubicBezierPath(doc, data, id, typeCreation);
scene->addItem(spl);
InitSplinePathToolConnections(scene, spl);
VAbstractPattern::AddTool(id, spl);
VAbstractTool::AddRecord(initData.id, Tool::CubicBezierPath, initData.doc);
VToolCubicBezierPath *spl = new VToolCubicBezierPath(initData);
initData.scene->addItem(spl);
InitSplinePathToolConnections(initData.scene, spl);
VAbstractPattern::AddTool(initData.id, spl);
return spl;
}
return nullptr;

View File

@ -43,6 +43,16 @@
class VCubicBezierPath;
template <class T> class QSharedPointer;
struct VToolCubicBezierPathInitData : public VAbstractToolInitData
{
VToolCubicBezierPathInitData()
: VAbstractToolInitData(),
path(nullptr)
{}
VCubicBezierPath *path;
};
class VToolCubicBezierPath:public VAbstractSpline
{
Q_OBJECT
@ -51,9 +61,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolCubicBezierPath *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolCubicBezierPath *Create(const quint32 _id, VCubicBezierPath *path, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static VToolCubicBezierPath *Create(VToolCubicBezierPathInitData initData);
static const QString ToolType;
static void UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VCubicBezierPath &path);
@ -75,8 +83,7 @@ protected:
private:
Q_DISABLE_COPY(VToolCubicBezierPath)
VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id,
const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolCubicBezierPath(const VToolCubicBezierPathInitData &initData, QGraphicsItem * parent = nullptr);
static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VPointF &splPoint);
void SetSplinePathAttributes(QDomElement &domElement, const VCubicBezierPath &path);

View File

@ -61,21 +61,17 @@ const QString VToolEllipticalArc::ToolType = QStringLiteral("simple");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolEllipticalArc constuctor.
* @param doc dom document container
* @param data container with variables
* @param id object id in container
* @param typeCreation way we create this tool.
* @param initData init data
* @param parent parent object
*/
VToolEllipticalArc::VToolEllipticalArc(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent)
VToolEllipticalArc::VToolEllipticalArc(const VToolEllipticalArcInitData &initData, QGraphicsItem *parent)
:VAbstractSpline(initData.doc, initData.data, initData.id, parent)
{
sceneType = SceneObject::ElArc;
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -113,16 +109,22 @@ VToolEllipticalArc* VToolEllipticalArc::Create(QSharedPointer<DialogTool> dialog
QSharedPointer<DialogEllipticalArc> dialogTool = dialog.objectCast<DialogEllipticalArc>();
SCASSERT(not dialogTool.isNull())
const quint32 center = dialogTool->GetCenter();
QString radius1 = dialogTool->GetRadius1();
QString radius2 = dialogTool->GetRadius2();
QString f1 = dialogTool->GetF1();
QString f2 = dialogTool->GetF2();
QString rotationAngle = dialogTool->GetRotationAngle();
const QString color = dialogTool->GetColor();
const QString penStyle = dialogTool->GetPenStyle();
VToolEllipticalArc* point = Create(0, center, radius1, radius2, f1, f2, rotationAngle, color, penStyle, scene, doc,
data, Document::FullParse, Source::FromGui);
VToolEllipticalArcInitData initData;
initData.center = dialogTool->GetCenter();
initData.radius1 = dialogTool->GetRadius1();
initData.radius2 = dialogTool->GetRadius2();
initData.f1 = dialogTool->GetF1();
initData.f2 = dialogTool->GetF2();
initData.rotationAngle = dialogTool->GetRotationAngle();
initData.color = dialogTool->GetColor();
initData.penStyle = dialogTool->GetPenStyle();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolEllipticalArc* point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -134,63 +136,49 @@ VToolEllipticalArc* VToolEllipticalArc::Create(QSharedPointer<DialogTool> dialog
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool form GUI.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param center id elliptical arc center point.
* @param radius1 elliptical arc radius1.
* @param radius2 elliptical arc radius2.
* @param f1 start angle of elliptical arc.
* @param f2 end angle of elliptical arc.
* @param rotationAngle rotation angle of elliptical arc.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
*/
VToolEllipticalArc* VToolEllipticalArc::Create(const quint32 _id, const quint32 &center, QString &radius1,
QString &radius2, QString &f1, QString &f2, QString &rotationAngle,
const QString &color, const QString &penStyle, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
VToolEllipticalArc* VToolEllipticalArc::Create(VToolEllipticalArcInitData &initData)
{
qreal calcRadius1 = 0, calcRadius2 = 0, calcF1 = 0, calcF2 = 0, calcRotationAngle = 0;
calcRadius1 = qApp->toPixel(CheckFormula(_id, radius1, data));
calcRadius2 = qApp->toPixel(CheckFormula(_id, radius2, data));
calcRadius1 = qApp->toPixel(CheckFormula(initData.id, initData.radius1, initData.data));
calcRadius2 = qApp->toPixel(CheckFormula(initData.id, initData.radius2, initData.data));
calcF1 = CheckFormula(_id, f1, data);
calcF2 = CheckFormula(_id, f2, data);
calcRotationAngle = CheckFormula(_id, rotationAngle, data);
calcF1 = CheckFormula(initData.id, initData.f1, initData.data);
calcF2 = CheckFormula(initData.id, initData.f2, initData.data);
calcRotationAngle = CheckFormula(initData.id, initData.rotationAngle, initData.data);
const VPointF c = *data->GeometricObject<VPointF>(center);
VEllipticalArc *elArc = new VEllipticalArc(c, calcRadius1, calcRadius2, radius1, radius2, calcF1, f1, calcF2, f2,
calcRotationAngle, rotationAngle);
elArc->SetColor(color);
elArc->SetPenStyle(penStyle);
quint32 id = _id;
if (typeCreation == Source::FromGui)
const VPointF c = *initData.data->GeometricObject<VPointF>(initData.center);
VEllipticalArc *elArc = new VEllipticalArc(c, calcRadius1, calcRadius2, initData.radius1, initData.radius2, calcF1,
initData.f1, calcF2, initData.f2, calcRotationAngle,
initData.rotationAngle);
elArc->SetColor(initData.color);
elArc->SetPenStyle(initData.penStyle);
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(elArc);
data->AddArc(data->GeometricObject<VEllipticalArc>(id), id);
initData.id = initData.data->AddGObject(elArc);
initData.data->AddArc(initData.data->GeometricObject<VEllipticalArc>(initData.id), initData.id);
}
else
{
data->UpdateGObject(id, elArc);
data->AddArc(data->GeometricObject<VEllipticalArc>(id), id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, elArc);
initData.data->AddArc(initData.data->GeometricObject<VEllipticalArc>(initData.id), initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::EllipticalArc, doc);
VToolEllipticalArc *toolEllipticalArc = new VToolEllipticalArc(doc, data, id, typeCreation);
scene->addItem(toolEllipticalArc);
InitElArcToolConnections(scene, toolEllipticalArc);
VAbstractPattern::AddTool(id, toolEllipticalArc);
doc->IncrementReferens(c.getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::EllipticalArc, initData.doc);
VToolEllipticalArc *toolEllipticalArc = new VToolEllipticalArc(initData);
initData.scene->addItem(toolEllipticalArc);
InitElArcToolConnections(initData.scene, toolEllipticalArc);
VAbstractPattern::AddTool(initData.id, toolEllipticalArc);
initData.doc->IncrementReferens(c.getIdTool());
return toolEllipticalArc;
}
return nullptr;

View File

@ -43,6 +43,26 @@
class VFormula;
template <class T> class QSharedPointer;
struct VToolEllipticalArcInitData : public VAbstractSplineInitData
{
VToolEllipticalArcInitData()
: VAbstractSplineInitData(),
center(NULL_ID),
radius1("0"),
radius2("0"),
f1("0"),
f2("0"),
rotationAngle("0")
{}
quint32 center;
QString radius1;
QString radius2;
QString f1;
QString f2;
QString rotationAngle;
};
/**
* @brief The VToolEllipticalArc class tool for creation elliptical arc.
*/
@ -53,11 +73,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolEllipticalArc* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolEllipticalArc* Create(const quint32 _id, const quint32 &center, QString &radius1, QString &radius2,
QString &f1, QString &f2, QString &rotationAngle, const QString &color,
const QString &penStyle, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolEllipticalArc* Create(VToolEllipticalArcInitData &initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::EllipticalArc)};
@ -95,8 +111,7 @@ protected:
private:
Q_DISABLE_COPY(VToolEllipticalArc)
VToolEllipticalArc(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem * parent = nullptr);
VToolEllipticalArc(const VToolEllipticalArcInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLELLIPTICALARC_H

View File

@ -74,22 +74,19 @@ const QString VToolSpline::OldToolType = QStringLiteral("simple");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolSpline constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent), oldPosition()
VToolSpline::VToolSpline(VToolSplineInitData initData, QGraphicsItem *parent)
: VAbstractSpline(initData.doc, initData.data, initData.id, parent),
oldPosition()
{
sceneType = SceneObject::Spline;
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
const auto spl = VAbstractTool::data.GeometricObject<VSpline>(initData.id);
const bool freeAngle1 = qmu::QmuTokenParser::IsSingle(spl->GetStartAngleFormula());
const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl->GetC1LengthFormula());
@ -119,7 +116,7 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co
ShowHandles(false);
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -153,11 +150,18 @@ VToolSpline* VToolSpline::Create(QSharedPointer<DialogTool> dialog, VMainGraphic
QSharedPointer<DialogSpline> dialogTool = dialog.objectCast<DialogSpline>();
SCASSERT(not dialogTool.isNull())
VToolSplineInitData initData;
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VSpline *spline = new VSpline(dialogTool->GetSpline());
spline->SetColor(dialogTool->GetColor());
spline->SetPenStyle(dialogTool->GetPenStyle());
auto spl = Create(0, spline, scene, doc, data, Document::FullParse, Source::FromGui);
auto spl = Create(initData, spline);
if (spl != nullptr)
{
@ -169,74 +173,64 @@ VToolSpline* VToolSpline::Create(QSharedPointer<DialogTool> dialog, VMainGraphic
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param initData init data.
* @param spline spline.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @return the created tool
*/
VToolSpline* VToolSpline::Create(const quint32 _id, VSpline *spline, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data, const Document &parse, const Source &typeCreation)
VToolSpline* VToolSpline::Create(VToolSplineInitData &initData, VSpline *spline)
{
quint32 id = _id;
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(spline);
data->AddSpline(data->GeometricObject<VAbstractBezier>(id), id);
initData.id = initData.data->AddGObject(spline);
initData.data->AddSpline(initData.data->GeometricObject<VAbstractBezier>(initData.id), initData.id);
}
else
{
data->UpdateGObject(id, spline);
data->AddSpline(data->GeometricObject<VAbstractBezier>(id), id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, spline);
initData.data->AddSpline(initData.data->GeometricObject<VAbstractBezier>(initData.id), initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::Spline, doc);
auto _spl = new VToolSpline(doc, data, id, typeCreation);
scene->addItem(_spl);
InitSplineToolConnections(scene, _spl);
VAbstractPattern::AddTool(id, _spl);
doc->IncrementReferens(spline->GetP1().getIdTool());
doc->IncrementReferens(spline->GetP4().getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::Spline, initData.doc);
auto _spl = new VToolSpline(initData);
initData.scene->addItem(_spl);
InitSplineToolConnections(initData.scene, _spl);
VAbstractPattern::AddTool(initData.id, _spl);
initData.doc->IncrementReferens(spline->GetP1().getIdTool());
initData.doc->IncrementReferens(spline->GetP4().getIdTool());
return _spl;
}
return nullptr;
}
//---------------------------------------------------------------------------------------------------------------------
VToolSpline *VToolSpline::Create(const quint32 _id, quint32 point1, quint32 point4, QString &a1, QString &a2,
QString &l1, QString &l2, quint32 duplicate, const QString &color,
const QString &penStyle, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data, const Document &parse, const Source &typeCreation)
VToolSpline *VToolSpline::Create(VToolSplineInitData &initData)
{
const qreal calcAngle1 = CheckFormula(_id, a1, data);
const qreal calcAngle2 = CheckFormula(_id, a2, data);
const qreal calcAngle1 = CheckFormula(initData.id, initData.a1, initData.data);
const qreal calcAngle2 = CheckFormula(initData.id, initData.a2, initData.data);
const qreal calcLength1 = qApp->toPixel(CheckFormula(_id, l1, data));
const qreal calcLength2 = qApp->toPixel(CheckFormula(_id, l2, data));
const qreal calcLength1 = qApp->toPixel(CheckFormula(initData.id, initData.l1, initData.data));
const qreal calcLength2 = qApp->toPixel(CheckFormula(initData.id, initData.l2, initData.data));
auto p1 = data->GeometricObject<VPointF>(point1);
auto p4 = data->GeometricObject<VPointF>(point4);
auto p1 = initData.data->GeometricObject<VPointF>(initData.point1);
auto p4 = initData.data->GeometricObject<VPointF>(initData.point4);
auto spline = new VSpline(*p1, *p4, calcAngle1, a1, calcAngle2, a2, calcLength1, l1, calcLength2, l2);
if (duplicate > 0)
auto spline = new VSpline(*p1, *p4, calcAngle1, initData.a1, calcAngle2, initData.a2, calcLength1, initData.l1,
calcLength2, initData.l2);
if (initData.duplicate > 0)
{
spline->SetDuplicate(duplicate);
spline->SetDuplicate(initData.duplicate);
}
spline->SetColor(color);
spline->SetPenStyle(penStyle);
spline->SetColor(initData.color);
spline->SetPenStyle(initData.penStyle);
return VToolSpline::Create(_id, spline, scene, doc, data, parse, typeCreation);
return VToolSpline::Create(initData, spline);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -44,6 +44,28 @@
template <class T> class QSharedPointer;
struct VToolSplineInitData : public VAbstractSplineInitData
{
VToolSplineInitData()
: VAbstractSplineInitData(),
point1(NULL_ID),
point4(NULL_ID),
a1(),
a2(),
l1(),
l2(),
duplicate(0)
{}
quint32 point1;
quint32 point4;
QString a1;
QString a2;
QString l1;
QString l2;
quint32 duplicate;
};
/**
* @brief The VToolSpline class tool for creation spline. I mean bezier curve.
*/
@ -55,13 +77,8 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolSpline *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolSpline *Create(const quint32 _id, VSpline *spline,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolSpline *Create(const quint32 _id, quint32 point1, quint32 point4, QString &a1, QString &a2, QString &l1,
QString &l2, quint32 duplicate, const QString &color, const QString &penStyle,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolSpline *Create(VToolSplineInitData &initData, VSpline *spline);
static VToolSpline *Create(VToolSplineInitData &initData);
static const QString ToolType;
static const QString OldToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
@ -92,8 +109,7 @@ private:
Q_DISABLE_COPY(VToolSpline)
QPointF oldPosition;
VToolSpline (VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem * parent = nullptr );
VToolSpline (VToolSplineInitData initData, QGraphicsItem *parent = nullptr );
bool IsMovable() const;
void SetSplineAttributes(QDomElement &domElement, const VSpline &spl);

View File

@ -79,15 +79,11 @@ const QString VToolSplinePath::OldToolType = QStringLiteral("path");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolSplinePath constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem *parent)
: VAbstractSpline(doc, data, id, parent),
VToolSplinePath::VToolSplinePath(const VToolSplinePathInitData &initData, QGraphicsItem *parent)
: VAbstractSpline(initData.doc, initData.data, initData.id, parent),
oldPosition(),
splIndex(-1)
{
@ -96,7 +92,7 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(id);
const QSharedPointer<VSplinePath> splPath = initData.data->GeometricObject<VSplinePath>(initData.id);
for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i)
{
const VSpline spl = splPath->GetSpline(i);
@ -128,7 +124,7 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3
ShowHandles(false);
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -160,6 +156,14 @@ VToolSplinePath* VToolSplinePath::Create(QSharedPointer<DialogTool> dialog, VMai
SCASSERT(not dialog.isNull())
QSharedPointer<DialogSplinePath> dialogTool = dialog.objectCast<DialogSplinePath>();
SCASSERT(not dialogTool.isNull())
VToolSplinePathInitData initData;
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VSplinePath *path = new VSplinePath(dialogTool->GetPath());
for (qint32 i = 0; i < path->CountPoints(); ++i)
{
@ -169,7 +173,7 @@ VToolSplinePath* VToolSplinePath::Create(QSharedPointer<DialogTool> dialog, VMai
path->SetColor(dialogTool->GetColor());
path->SetPenStyle(dialogTool->GetPenStyle());
VToolSplinePath* spl = Create(0, path, scene, doc, data, Document::FullParse, Source::FromGui);
VToolSplinePath* spl = Create(initData, path);
if (spl != nullptr)
{
spl->m_dialog = dialogTool;
@ -180,79 +184,69 @@ VToolSplinePath* VToolSplinePath::Create(QSharedPointer<DialogTool> dialog, VMai
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param initData init data.
* @param path spline path.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
*/
VToolSplinePath* VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
VToolSplinePath* VToolSplinePath::Create(VToolSplinePathInitData &initData, VSplinePath *path)
{
quint32 id = _id;
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(path);
data->AddCurveWithSegments(data->GeometricObject<VAbstractCubicBezierPath>(id), id);
initData.id = initData.data->AddGObject(path);
initData.data->AddCurveWithSegments(initData.data->GeometricObject<VAbstractCubicBezierPath>(initData.id),
initData.id);
}
else
{
data->UpdateGObject(id, path);
data->AddCurveWithSegments(data->GeometricObject<VAbstractCubicBezierPath>(id), id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, path);
initData.data->AddCurveWithSegments(initData.data->GeometricObject<VAbstractCubicBezierPath>(initData.id),
initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::SplinePath, doc);
VToolSplinePath *spl = new VToolSplinePath(doc, data, id, typeCreation);
scene->addItem(spl);
InitSplinePathToolConnections(scene, spl);
VAbstractPattern::AddTool(id, spl);
VAbstractTool::AddRecord(initData.id, Tool::SplinePath, initData.doc);
VToolSplinePath *spl = new VToolSplinePath(initData);
initData.scene->addItem(spl);
InitSplinePathToolConnections(initData.scene, spl);
VAbstractPattern::AddTool(initData.id, spl);
return spl;
}
return nullptr;
}
//---------------------------------------------------------------------------------------------------------------------
VToolSplinePath *VToolSplinePath::Create(const quint32 _id, const QVector<quint32> &points, QVector<QString> &a1,
QVector<QString> &a2, QVector<QString> &l1, QVector<QString> &l2,
const QString &color, const QString &penStyle, quint32 duplicate,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolSplinePath *VToolSplinePath::Create(VToolSplinePathInitData &initData)
{
auto path = new VSplinePath();
if (duplicate > 0)
if (initData.duplicate > 0)
{
path->SetDuplicate(duplicate);
path->SetDuplicate(initData.duplicate);
}
for (int i = 0; i < points.size(); ++i)
for (int i = 0; i < initData.points.size(); ++i)
{
const qreal calcAngle1 = CheckFormula(_id, a1[i], data);
const qreal calcAngle2 = CheckFormula(_id, a2[i], data);
const qreal calcAngle1 = CheckFormula(initData.id, initData.a1[i], initData.data);
const qreal calcAngle2 = CheckFormula(initData.id, initData.a2[i], initData.data);
const qreal calcLength1 = qApp->toPixel(CheckFormula(_id, l1[i], data));
const qreal calcLength2 = qApp->toPixel(CheckFormula(_id, l2[i], data));
const qreal calcLength1 = qApp->toPixel(CheckFormula(initData.id, initData.l1[i], initData.data));
const qreal calcLength2 = qApp->toPixel(CheckFormula(initData.id, initData.l2[i], initData.data));
const auto p = *data->GeometricObject<VPointF>(points.at(i));
const auto p = *initData.data->GeometricObject<VPointF>(initData.points.at(i));
path->append(VSplinePoint(p, calcAngle1, a1.at(i), calcAngle2, a2.at(i), calcLength1, l1.at(i), calcLength2,
l2.at(i)));
path->append(VSplinePoint(p, calcAngle1, initData.a1.at(i), calcAngle2, initData.a2.at(i), calcLength1,
initData.l1.at(i), calcLength2, initData.l2.at(i)));
}
path->SetColor(color);
path->SetPenStyle(penStyle);
path->SetColor(initData.color);
path->SetPenStyle(initData.penStyle);
return VToolSplinePath::Create(_id, path, scene, doc, data, parse, typeCreation);
return VToolSplinePath::Create(initData, path);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -46,6 +46,26 @@
class VSplinePath;
template <class T> class QSharedPointer;
struct VToolSplinePathInitData : public VAbstractSplineInitData
{
VToolSplinePathInitData()
: VAbstractSplineInitData(),
points(),
a1(),
a2(),
l1(),
l2(),
duplicate(0)
{}
QVector<quint32> points;
QVector<QString> a1;
QVector<QString> a2;
QVector<QString> l1;
QVector<QString> l2;
quint32 duplicate;
};
/**
* @brief The VToolSplinePath class tool for creation spline path.
*/
@ -57,14 +77,8 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolSplinePath *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolSplinePath *Create(const quint32 _id, VSplinePath *path,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolSplinePath *Create(const quint32 _id, const QVector<quint32> &points, QVector<QString> &a1,
QVector<QString> &a2, QVector<QString> &l1, QVector<QString> &l2,
const QString &color, const QString &penStyle, quint32 duplicate,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolSplinePath *Create(VToolSplinePathInitData &initData, VSplinePath *path);
static VToolSplinePath *Create(VToolSplinePathInitData &initData);
static const QString ToolType;
static const QString OldToolType;
static void UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VSplinePath &path);
@ -108,8 +122,7 @@ private:
QPointF oldPosition;
int splIndex;
VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem *parent = nullptr);
VToolSplinePath(const VToolSplinePathInitData &initData, QGraphicsItem *parent = nullptr);
bool IsMovable(int index) const;
static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint);

View File

@ -55,26 +55,15 @@ template <class T> class QSharedPointer;
const QString VToolTrueDarts::ToolType = QStringLiteral("trueDarts");
//---------------------------------------------------------------------------------------------------------------------
VToolTrueDarts::VToolTrueDarts(VAbstractPattern *doc,
VContainer *data,
const quint32 &id,
const quint32 &p1id,
const quint32 &p2id,
const quint32 &baseLineP1Id,
const quint32 &baseLineP2Id,
const quint32 &dartP1Id,
const quint32 &dartP2Id,
const quint32 &dartP3Id,
const Source &typeCreation,
QGraphicsItem *parent)
:VToolDoublePoint(doc, data, id, p1id, p2id, parent),
baseLineP1Id (baseLineP1Id),
baseLineP2Id(baseLineP2Id),
dartP1Id(dartP1Id),
dartP2Id(dartP2Id),
dartP3Id(dartP3Id)
VToolTrueDarts::VToolTrueDarts(const VToolTrueDartsInitData &initData, QGraphicsItem *parent)
:VToolDoublePoint(initData.doc, initData.data, initData.id, initData.p1id, initData.p2id, parent),
baseLineP1Id (initData.baseLineP1Id),
baseLineP2Id(initData.baseLineP2Id),
dartP1Id(initData.dartP1Id),
dartP2Id(initData.dartP2Id),
dartP3Id(initData.dartP3Id)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -128,17 +117,21 @@ VToolTrueDarts *VToolTrueDarts::Create(QSharedPointer<DialogTool> dialog, VMainG
QSharedPointer<DialogTrueDarts> dialogTool = dialog.objectCast<DialogTrueDarts>();
SCASSERT(not dialogTool.isNull())
const QString point1Name = dialogTool->GetFirstNewDartPointName();
const QString point2Name = dialogTool->GetSecondNewDartPointName();
const quint32 baseLineP1Id = dialogTool->GetFirstBasePointId();
const quint32 baseLineP2Id = dialogTool->GetSecondBasePointId();
const quint32 dartP1Id = dialogTool->GetFirstDartPointId();
const quint32 dartP2Id = dialogTool->GetSecondDartPointId();
const quint32 dartP3Id = dialogTool->GetThirdDartPointId();
VToolTrueDartsInitData initData;
initData.name1 = dialogTool->GetFirstNewDartPointName();
initData.name2 = dialogTool->GetSecondNewDartPointName();
initData.baseLineP1Id = dialogTool->GetFirstBasePointId();
initData.baseLineP2Id = dialogTool->GetSecondBasePointId();
initData.dartP1Id = dialogTool->GetFirstDartPointId();
initData.dartP2Id = dialogTool->GetSecondDartPointId();
initData.dartP3Id = dialogTool->GetThirdDartPointId();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolTrueDarts *point = Create(0, 0, 0, baseLineP1Id, baseLineP2Id, dartP1Id, dartP2Id, dartP3Id,
point1Name, 5, 10, point2Name, 5, 10, scene, doc, data, Document::FullParse,
Source::FromGui);
VToolTrueDarts *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -147,61 +140,52 @@ VToolTrueDarts *VToolTrueDarts::Create(QSharedPointer<DialogTool> dialog, VMainG
}
//---------------------------------------------------------------------------------------------------------------------
VToolTrueDarts *VToolTrueDarts::Create(quint32 _id,
const quint32 &_p1id, const quint32 &_p2id,
const quint32 &baseLineP1Id,
const quint32 &baseLineP2Id,
const quint32 &dartP1Id,
const quint32 &dartP2Id,
const quint32 &dartP3Id,
const QString &point1Name, const qreal &mx1, const qreal &my1,
const QString &point2Name, const qreal &mx2, const qreal &my2,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolTrueDarts *VToolTrueDarts::Create(VToolTrueDartsInitData initData)
{
const QSharedPointer<VPointF> baseLineP1 = data->GeometricObject<VPointF>(baseLineP1Id);
const QSharedPointer<VPointF> baseLineP2 = data->GeometricObject<VPointF>(baseLineP2Id);
const QSharedPointer<VPointF> dartP1 = data->GeometricObject<VPointF>(dartP1Id);
const QSharedPointer<VPointF> dartP2 = data->GeometricObject<VPointF>(dartP2Id);
const QSharedPointer<VPointF> dartP3 = data->GeometricObject<VPointF>(dartP3Id);
const QSharedPointer<VPointF> baseLineP1 = initData.data->GeometricObject<VPointF>(initData.baseLineP1Id);
const QSharedPointer<VPointF> baseLineP2 = initData.data->GeometricObject<VPointF>(initData.baseLineP2Id);
const QSharedPointer<VPointF> dartP1 = initData.data->GeometricObject<VPointF>(initData.dartP1Id);
const QSharedPointer<VPointF> dartP2 = initData.data->GeometricObject<VPointF>(initData.dartP2Id);
const QSharedPointer<VPointF> dartP3 = initData.data->GeometricObject<VPointF>(initData.dartP3Id);
QPointF fPoint1;
QPointF fPoint2;
VToolTrueDarts::FindPoint(static_cast<QPointF>(*baseLineP1), static_cast<QPointF>(*baseLineP2),
static_cast<QPointF>(*dartP1), static_cast<QPointF>(*dartP2),
static_cast<QPointF>(*dartP3), fPoint1, fPoint2);
quint32 id = _id;
quint32 p1id = _p1id;
quint32 p2id = _p2id;
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = VContainer::getNextId();//Just reserve id for tool
p1id = data->AddGObject(new VPointF(fPoint1, point1Name, mx1, my1, id));
p2id = data->AddGObject(new VPointF(fPoint2, point2Name, mx2, my2, id));
initData.id = VContainer::getNextId();//Just reserve id for tool
initData.p1id = initData.data->AddGObject(new VPointF(fPoint1, initData.name1, initData.mx1, initData.my1,
initData.id));
initData.p2id = initData.data->AddGObject(new VPointF(fPoint2, initData.name2, initData.mx2, initData.my2,
initData.id));
}
else
{
data->UpdateGObject(p1id, new VPointF(fPoint1, point1Name, mx1, my1, id));
data->UpdateGObject(p2id, new VPointF(fPoint2, point2Name, mx2, my2, id));
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.p1id, new VPointF(fPoint1, initData.name1, initData.mx1, initData.my1,
initData.id));
initData.data->UpdateGObject(initData.p2id, new VPointF(fPoint2, initData.name2, initData.mx2, initData.my2,
initData.id));
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::TrueDarts, doc);
VToolTrueDarts *points = new VToolTrueDarts(doc, data, id, p1id, p2id, baseLineP1Id, baseLineP2Id,
dartP1Id, dartP2Id, dartP3Id, typeCreation);
scene->addItem(points);
InitToolConnections(scene, points);
VAbstractPattern::AddTool(id, points);
doc->IncrementReferens(baseLineP1->getIdTool());
doc->IncrementReferens(baseLineP2->getIdTool());
doc->IncrementReferens(dartP1->getIdTool());
doc->IncrementReferens(dartP2->getIdTool());
doc->IncrementReferens(dartP3->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::TrueDarts, initData.doc);
VToolTrueDarts *points = new VToolTrueDarts(initData);
initData.scene->addItem(points);
InitToolConnections(initData.scene, points);
VAbstractPattern::AddTool(initData.id, points);
initData.doc->IncrementReferens(baseLineP1->getIdTool());
initData.doc->IncrementReferens(baseLineP2->getIdTool());
initData.doc->IncrementReferens(dartP1->getIdTool());
initData.doc->IncrementReferens(dartP2->getIdTool());
initData.doc->IncrementReferens(dartP3->getIdTool());
return points;
}
return nullptr;

View File

@ -44,6 +44,40 @@
template <class T> class QSharedPointer;
struct VToolTrueDartsInitData : public VAbstractToolInitData
{
VToolTrueDartsInitData()
: VAbstractToolInitData(),
p1id(NULL_ID),
p2id(NULL_ID),
baseLineP1Id(NULL_ID),
baseLineP2Id(NULL_ID),
dartP1Id(NULL_ID),
dartP2Id(NULL_ID),
dartP3Id(NULL_ID),
name1(),
mx1(10),
my1(15),
name2(),
mx2(10),
my2(15)
{}
quint32 p1id;
quint32 p2id;
quint32 baseLineP1Id;
quint32 baseLineP2Id;
quint32 dartP1Id;
quint32 dartP2Id;
quint32 dartP3Id;
QString name1;
qreal mx1;
qreal my1;
QString name2;
qreal mx2;
qreal my2;
};
class VToolTrueDarts : public VToolDoublePoint
{
Q_OBJECT
@ -53,17 +87,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolTrueDarts* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolTrueDarts* Create(quint32 _id,
const quint32 &_p1id, const quint32 &_p2id,
const quint32 &baseLineP1Id,
const quint32 &baseLineP2Id,
const quint32 &dartP1Id,
const quint32 &dartP2Id,
const quint32 &dartP3Id,
const QString &point1Name, const qreal &mx1, const qreal &my1,
const QString &point2Name, const qreal &mx2, const qreal &my2,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolTrueDarts* Create(VToolTrueDartsInitData initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::TrueDarts)};
@ -108,18 +132,7 @@ private:
quint32 dartP2Id;
quint32 dartP3Id;
VToolTrueDarts(VAbstractPattern *doc,
VContainer *data,
const quint32 &id,
const quint32 &p1id,
const quint32 &p2id,
const quint32 &baseLineP1Id,
const quint32 &baseLineP2Id,
const quint32 &dartP1Id,
const quint32 &dartP2Id,
const quint32 &dartP3Id,
const Source &typeCreation,
QGraphicsItem * parent = nullptr);
VToolTrueDarts(const VToolTrueDartsInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLTRUEDARTS_H

View File

@ -59,19 +59,13 @@ const QString VToolCutArc::ToolType = QStringLiteral("cutArc");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolCutArc constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param formula string with formula length first arc.
* @param arcId id arc in data container.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolCutArc::VToolCutArc(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
const quint32 &arcId, const Source &typeCreation, QGraphicsItem * parent)
:VToolCut(doc, data, id, formula, arcId, parent)
VToolCutArc::VToolCutArc(const VToolCutArcInitData &initData, QGraphicsItem * parent)
:VToolCut(initData.doc, initData.data, initData.id, initData.formula, initData.arcId, parent)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -103,11 +97,18 @@ VToolCutArc* VToolCutArc::Create(QSharedPointer<DialogTool> dialog, VMainGraphic
SCASSERT(not dialog.isNull())
QSharedPointer<DialogCutArc> dialogTool = dialog.objectCast<DialogCutArc>();
SCASSERT(not dialogTool.isNull())
const QString pointName = dialogTool->getPointName();
QString formula = dialogTool->GetFormula();
const quint32 arcId = dialogTool->getArcId();
VToolCutArc* point = Create(0, pointName, formula, arcId, 5, 10, true, scene, doc, data, Document::FullParse,
Source::FromGui);
VToolCutArcInitData initData;
initData.formula = dialogTool->GetFormula();
initData.arcId = dialogTool->getArcId();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolCutArc* point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -118,67 +119,54 @@ VToolCutArc* VToolCutArc::Create(QSharedPointer<DialogTool> dialog, VMainGraphic
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param pointName point name.
* @param formula string with formula length first arc.
* @param arcId id arc in data container.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param initData init data.
* @param typeCreation way we create this tool.
*/
VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QString &formula, quint32 arcId,
qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data, const Document &parse, const Source &typeCreation)
VToolCutArc* VToolCutArc::Create(VToolCutArcInitData &initData)
{
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(arcId);
const QSharedPointer<VArc> arc = initData.data->GeometricObject<VArc>(initData.arcId);
const qreal result = CheckFormula(_id, formula, data);
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
VArc arc1;
VArc arc2;
QPointF point = arc->CutArc(qApp->toPixel(result), arc1, arc2);
quint32 id = _id;
VPointF *p = new VPointF(point, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
auto a1 = QSharedPointer<VArc>(new VArc(arc1));
auto a2 = QSharedPointer<VArc>(new VArc(arc2));
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
initData.id = initData.data->AddGObject(p);
a1->setId(VContainer::getNextId());
a2->setId(VContainer::getNextId());
data->AddArc(a1, a1->id(), id);
data->AddArc(a2, a2->id(), id);
initData.data->AddArc(a1, a1->id(), initData.id);
initData.data->AddArc(a2, a2->id(), initData.id);
}
else
{
data->UpdateGObject(id, p);
a1->setId(id + 1);
a2->setId(id + 2);
data->AddArc(a1, a1->id(), id);
data->AddArc(a2, a2->id(), id);
initData.data->UpdateGObject(initData.id, p);
a1->setId(initData.id + 1);
a2->setId(initData.id + 2);
initData.data->AddArc(a1, a1->id(), initData.id);
initData.data->AddArc(a2, a2->id(), initData.id);
if (parse != Document::FullParse)
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::CutArc, doc);
VToolCutArc *point = new VToolCutArc(doc, data, id, formula, arcId, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(arc->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::CutArc, initData.doc);
VToolCutArc *point = new VToolCutArc(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(arc->getIdTool());
return point;
}
return nullptr;

View File

@ -43,6 +43,18 @@
template <class T> class QSharedPointer;
struct VToolCutArcInitData : public VToolSinglePointInitData
{
VToolCutArcInitData()
: VToolSinglePointInitData(),
formula(),
arcId(NULL_ID)
{}
QString formula;
quint32 arcId;
};
/**
* @brief The VToolCutArc class tool for cutting arc.
*/
@ -53,10 +65,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolCutArc* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolCutArc* Create(const quint32 _id, const QString &pointName, QString &formula, quint32 arcId,
qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static VToolCutArc* Create(VToolCutArcInitData &initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::CutArc)};
@ -72,8 +81,7 @@ protected:
private:
Q_DISABLE_COPY(VToolCutArc)
VToolCutArc(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
const quint32 &arcId, const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolCutArc(const VToolCutArcInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLCUTARC_H

View File

@ -62,19 +62,13 @@ const QString VToolCutSpline::AttrSpline = QStringLiteral("spline");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolCutSpline constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param formula string with formula length first spline.
* @param splineId id spline in data container.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolCutSpline::VToolCutSpline(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
const quint32 &splineId, const Source &typeCreation, QGraphicsItem *parent)
:VToolCut(doc, data, id, formula, splineId, parent)
VToolCutSpline::VToolCutSpline(const VToolCutSplineInitData &initData, QGraphicsItem *parent)
:VToolCut(initData.doc, initData.data, initData.id, initData.formula, initData.splineId, parent)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -106,11 +100,18 @@ VToolCutSpline* VToolCutSpline::Create(QSharedPointer<DialogTool> dialog, VMainG
SCASSERT(not dialog.isNull())
QSharedPointer<DialogCutSpline> dialogTool = dialog.objectCast<DialogCutSpline>();
SCASSERT(not dialogTool.isNull())
const QString pointName = dialogTool->getPointName();
QString formula = dialogTool->GetFormula();
const quint32 splineId = dialogTool->getSplineId();
VToolCutSpline* point = Create(0, pointName, formula, splineId, 5, 10, true, scene, doc, data, Document::FullParse,
Source::FromGui);
VToolCutSplineInitData initData;
initData.formula = dialogTool->GetFormula();
initData.splineId = dialogTool->getSplineId();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolCutSpline* point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -121,64 +122,49 @@ VToolCutSpline* VToolCutSpline::Create(QSharedPointer<DialogTool> dialog, VMainG
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param pointName point name.
* @param formula string with formula length first spline.
* @param splineId id spline in data container.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
*/
VToolCutSpline* VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString &formula,
quint32 splineId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolCutSpline* VToolCutSpline::Create(VToolCutSplineInitData &initData)
{
const auto spl = data->GeometricObject<VAbstractCubicBezier>(splineId);
const auto spl = initData.data->GeometricObject<VAbstractCubicBezier>(initData.splineId);
const qreal result = CheckFormula(_id, formula, data);
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
QPointF point = spl->CutSpline(qApp->toPixel(result), spl1p2, spl1p3, spl2p2, spl2p3);
quint32 id = _id;
VPointF *p = new VPointF(point, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
auto spline1 = QSharedPointer<VAbstractBezier>(new VSpline(spl->GetP1(), spl1p2, spl1p3, *p));
auto spline2 = QSharedPointer<VAbstractBezier>(new VSpline(*p, spl2p2, spl2p3, spl->GetP4()));
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
data->AddSpline(spline1, NULL_ID, id);
data->AddSpline(spline2, NULL_ID, id);
initData.id = initData.data->AddGObject(p);
initData.data->AddSpline(spline1, NULL_ID, initData.id);
initData.data->AddSpline(spline2, NULL_ID, initData.id);
}
else
{
data->UpdateGObject(id, p);
data->AddSpline(spline1, NULL_ID, id);
data->AddSpline(spline2, NULL_ID, id);
initData.data->UpdateGObject(initData.id, p);
initData.data->AddSpline(spline1, NULL_ID, initData.id);
initData.data->AddSpline(spline2, NULL_ID, initData.id);
if (parse != Document::FullParse)
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::CutSpline, doc);
VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(spl->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::CutSpline, initData.doc);
VToolCutSpline *point = new VToolCutSpline(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(spl->getIdTool());
return point;
}
return nullptr;

View File

@ -43,6 +43,18 @@
template <class T> class QSharedPointer;
struct VToolCutSplineInitData : public VToolSinglePointInitData
{
VToolCutSplineInitData()
: VToolSinglePointInitData(),
formula(),
splineId(NULL_ID)
{}
QString formula;
quint32 splineId;
};
/**
* @brief The VToolCutSpline class for tool CutSpline. This tool find point on spline and cut spline on two.
*/
@ -53,11 +65,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolCutSpline *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolCutSpline *Create(const quint32 _id, const QString &pointName, QString &formula,
quint32 splineId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse,
const Source &typeCreation);
static VToolCutSpline *Create(VToolCutSplineInitData &initData);
static const QString ToolType;
static const QString AttrSpline;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
@ -74,8 +82,7 @@ protected:
private:
Q_DISABLE_COPY(VToolCutSpline)
VToolCutSpline(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
const quint32 &splineId, const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolCutSpline(const VToolCutSplineInitData &initData, QGraphicsItem * parent = nullptr);
};
#endif // VTOOLCUTSPLINE_H

View File

@ -65,20 +65,13 @@ const QString VToolCutSplinePath::AttrSplinePath = QStringLiteral("splinePath");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolCutSplinePath constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param formula string with formula length first splinePath.
* @param splinePathId id splinePath (we cut this splinePath) in data container.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolCutSplinePath::VToolCutSplinePath(VAbstractPattern *doc, VContainer *data, const quint32 &id,
const QString &formula, const quint32 &splinePathId,
const Source &typeCreation, QGraphicsItem *parent)
:VToolCut(doc, data, id, formula, splinePathId, parent)
VToolCutSplinePath::VToolCutSplinePath(const VToolCutSplinePathInitData &initData, QGraphicsItem *parent)
:VToolCut(initData.doc, initData.data, initData.id, initData.formula, initData.splinePathId, parent)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -110,11 +103,18 @@ VToolCutSplinePath* VToolCutSplinePath::Create(QSharedPointer<DialogTool> dialog
SCASSERT(not dialog.isNull())
QSharedPointer<DialogCutSplinePath> dialogTool = dialog.objectCast<DialogCutSplinePath>();
SCASSERT(not dialogTool.isNull())
const QString pointName = dialogTool->getPointName();
QString formula = dialogTool->GetFormula();
const quint32 splinePathId = dialogTool->getSplinePathId();
VToolCutSplinePath* point = Create(0, pointName, formula, splinePathId, 5, 10, true, scene, doc, data,
Document::FullParse, Source::FromGui);
VToolCutSplinePathInitData initData;
initData.formula = dialogTool->GetFormula();
initData.splinePathId = dialogTool->getSplinePathId();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolCutSplinePath* point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -125,69 +125,55 @@ VToolCutSplinePath* VToolCutSplinePath::Create(QSharedPointer<DialogTool> dialog
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param pointName point name.
* @param formula string with formula length first splinePath.
* @param splinePathId id of splinePath in data container.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
*/
VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QString &formula,
quint32 splinePathId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data, const Document &parse, const Source &typeCreation)
VToolCutSplinePath* VToolCutSplinePath::Create(VToolCutSplinePathInitData &initData)
{
const auto splPath = data->GeometricObject<VAbstractCubicBezierPath>(splinePathId);
const auto splPath = initData.data->GeometricObject<VAbstractCubicBezierPath>(initData.splinePathId);
SCASSERT(splPath != nullptr)
const qreal result = CheckFormula(_id, formula, data);
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
quint32 id = _id;
VSplinePath *splPath1 = nullptr;
VSplinePath *splPath2 = nullptr;
VPointF *p = VToolCutSplinePath::CutSplinePath(qApp->toPixel(result), splPath, pointName, &splPath1, &splPath2);
p->SetShowLabel(showLabel);
VPointF *p = VToolCutSplinePath::CutSplinePath(qApp->toPixel(result), splPath, initData.name, &splPath1, &splPath2);
p->SetShowLabel(initData.showLabel);
SCASSERT(splPath1 != nullptr)
SCASSERT(splPath2 != nullptr)
SCASSERT(p != nullptr)
p->setMx(mx);
p->setMy(my);
p->setMx(initData.mx);
p->setMy(initData.my);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
initData.id = initData.data->AddGObject(p);
data->AddSpline(QSharedPointer<VAbstractBezier>(splPath1), NULL_ID, id);
data->AddSpline(QSharedPointer<VAbstractBezier>(splPath2), NULL_ID, id);
initData.data->AddSpline(QSharedPointer<VAbstractBezier>(splPath1), NULL_ID, initData.id);
initData.data->AddSpline(QSharedPointer<VAbstractBezier>(splPath2), NULL_ID, initData.id);
}
else
{
data->UpdateGObject(id, p);
initData.data->UpdateGObject(initData.id, p);
data->AddSpline(QSharedPointer<VAbstractBezier>(splPath1), NULL_ID, id);
data->AddSpline(QSharedPointer<VAbstractBezier>(splPath2), NULL_ID, id);
initData.data->AddSpline(QSharedPointer<VAbstractBezier>(splPath1), NULL_ID, initData.id);
initData.data->AddSpline(QSharedPointer<VAbstractBezier>(splPath2), NULL_ID, initData.id);
if (parse != Document::FullParse)
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::CutSplinePath, doc);
VToolCutSplinePath *point = new VToolCutSplinePath(doc, data, id, formula, splinePathId, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(splPath->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::CutSplinePath, initData.doc);
VToolCutSplinePath *point = new VToolCutSplinePath(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(splPath->getIdTool());
return point;
}
return nullptr;

View File

@ -44,6 +44,18 @@
class VSplinePath;
template <class T> class QSharedPointer;
struct VToolCutSplinePathInitData : public VToolSinglePointInitData
{
VToolCutSplinePathInitData()
: VToolSinglePointInitData(),
formula(),
splinePathId(NULL_ID)
{}
QString formula;
quint32 splinePathId;
};
/**
* @brief The VToolCutSplinePath class for tool CutSplinePath. This tool find point on splinePath and cut splinePath on
* two.
@ -55,10 +67,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolCutSplinePath *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolCutSplinePath *Create(const quint32 _id, const QString &pointName, QString &formula,
quint32 splinePathId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolCutSplinePath *Create(VToolCutSplinePathInitData &initData);
static const QString ToolType;
static const QString AttrSplinePath;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
@ -80,8 +89,7 @@ protected:
private:
Q_DISABLE_COPY(VToolCutSplinePath)
VToolCutSplinePath(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
const quint32 &splinePathId, const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolCutSplinePath(const VToolCutSplinePathInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLCUTSPLINEPATH_H

View File

@ -71,13 +71,12 @@ const QString VToolAlongLine::ToolType = QStringLiteral("alongLine");
* @param typeCreation way we create this tool.
* @param parent parent object.
*/
VToolAlongLine::VToolAlongLine(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &formula,
const quint32 &firstPointId, const quint32 &secondPointId,
const QString &typeLine, const QString &lineColor, const Source &typeCreation,
QGraphicsItem *parent)
:VToolLinePoint(doc, data, id, typeLine, lineColor, formula, firstPointId, 0, parent), secondPointId(secondPointId)
VToolAlongLine::VToolAlongLine(const VToolAlongLineInitData &initData, QGraphicsItem *parent)
:VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, initData.formula,
initData.firstPointId, 0, parent),
secondPointId(initData.secondPointId)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -244,14 +243,21 @@ VToolAlongLine* VToolAlongLine::Create(QSharedPointer<DialogTool> dialog, VMainG
SCASSERT(not dialog.isNull())
QSharedPointer<DialogAlongLine> dialogTool = dialog.objectCast<DialogAlongLine>();
SCASSERT(not dialogTool.isNull())
QString formula = dialogTool->GetFormula();
const quint32 firstPointId = dialogTool->GetFirstPointId();
const quint32 secondPointId = dialogTool->GetSecondPointId();
const QString typeLine = dialogTool->GetTypeLine();
const QString lineColor = dialogTool->GetLineColor();
const QString pointName = dialogTool->getPointName();
VToolAlongLine *point = Create(0, pointName, typeLine, lineColor, formula, firstPointId, secondPointId,
5, 10, true, scene, doc, data, Document::FullParse, Source::FromGui);
VToolAlongLineInitData initData;
initData.formula = dialogTool->GetFormula();
initData.firstPointId = dialogTool->GetFirstPointId();
initData.secondPointId = dialogTool->GetSecondPointId();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolAlongLine *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -262,75 +268,55 @@ VToolAlongLine* VToolAlongLine::Create(QSharedPointer<DialogTool> dialog, VMainG
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param pointName point name. point name.
* @param typeLine line type.
* @param formula string with length formula.
* @param firstPointId id first point of line.
* @param secondPointId id second point of line.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param showLabel show/hide label.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
*/
VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine,
const QString &lineColor, QString &formula, const quint32 &firstPointId,
quint32 secondPointId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolAlongLine* VToolAlongLine::Create(VToolAlongLineInitData &initData)
{
const QSharedPointer<VPointF> firstPoint = data->GeometricObject<VPointF>(firstPointId);
const QSharedPointer<VPointF> secondPoint = data->GeometricObject<VPointF>(secondPointId);
const QSharedPointer<VPointF> firstPoint = initData.data->GeometricObject<VPointF>(initData.firstPointId);
const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.secondPointId);
QLineF line = QLineF(static_cast<QPointF>(*firstPoint), static_cast<QPointF>(*secondPoint));
//Declare special variable "CurrentLength"
VLengthLine *length = new VLengthLine(firstPoint.data(), firstPointId, secondPoint.data(),
secondPointId, *data->GetPatternUnit());
VLengthLine *length = new VLengthLine(firstPoint.data(), initData.firstPointId, secondPoint.data(),
initData.secondPointId, *initData.data->GetPatternUnit());
length->SetName(currentLength);
data->AddVariable(currentLength, length);
initData.data->AddVariable(currentLength, length);
line.setLength(qApp->toPixel(CheckFormula(_id, formula, data)));
line.setLength(qApp->toPixel(CheckFormula(initData.id, initData.formula, initData.data)));
quint32 id = _id;
VPointF *p = new VPointF(line.p2(), initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
VPointF *p = new VPointF(line.p2(), pointName, mx, my);
p->SetShowLabel(showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
initData.id = initData.data->AddGObject(p);
initData.data->AddLine(initData.firstPointId, initData.id);
initData.data->AddLine(initData.id, initData.secondPointId);
}
else
{
data->UpdateGObject(id, p);
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
initData.data->AddLine(initData.firstPointId, initData.id);
initData.data->AddLine(initData.id, initData.secondPointId);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
VToolAlongLine *point = nullptr;
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::AlongLine, doc);
point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, lineColor,
typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(firstPoint->getIdTool());
doc->IncrementReferens(secondPoint->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::AlongLine, initData.doc);
point = new VToolAlongLine(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(firstPoint->getIdTool());
initData.doc->IncrementReferens(secondPoint->getIdTool());
}
//Very important to delete it. Only this tool need this special variable.
data->RemoveVariable(currentLength);
initData.data->RemoveVariable(currentLength);
return point;
}

View File

@ -43,6 +43,20 @@
template <class T> class QSharedPointer;
struct VToolAlongLineInitData : public VToolLinePointInitData
{
VToolAlongLineInitData()
: VToolLinePointInitData(),
formula("100.0"),
firstPointId(NULL_ID),
secondPointId(NULL_ID)
{}
QString formula;
quint32 firstPointId;
quint32 secondPointId;
};
/**
* @brief The VToolAlongLine class tool for creation point along line.
*/
@ -53,12 +67,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolAlongLine* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolAlongLine* Create(const quint32 _id, const QString &pointName, const QString &typeLine,
const QString &lineColor, QString &formula, const quint32 &firstPointId,
quint32 secondPointId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse,
const Source &typeCreation);
static VToolAlongLine* Create(VToolAlongLineInitData &initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::AlongLine)};
@ -83,10 +92,7 @@ private:
/** @brief secondPointId id second point of line. */
quint32 secondPointId;
VToolAlongLine(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &formula,
const quint32 &firstPointId,
const quint32 &secondPointId, const QString &typeLine, const QString &lineColor,
const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolAlongLine(const VToolAlongLineInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLALONGLINE_H

View File

@ -59,25 +59,15 @@ const QString VToolBisector::ToolType = QStringLiteral("bisector");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolBisector constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param typeLine line type.
* @param formula string with formula length of bisector.
* @param firstPointId id first point of angle.
* @param secondPointId id second point of angle.
* @param thirdPointId id third point of angle.
* @param typeCreation way we create this tool.
* @param parent parent object.
* @param initData init data.
*/
VToolBisector::VToolBisector(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
const QString &lineColor, const QString &formula, const quint32 &firstPointId,
const quint32 &secondPointId, const quint32 &thirdPointId, const Source &typeCreation,
QGraphicsItem *parent)
:VToolLinePoint(doc, data, id, typeLine, lineColor, formula, secondPointId, 0, parent), firstPointId(firstPointId),
thirdPointId(thirdPointId)
VToolBisector::VToolBisector(const VToolBisectorInitData &initData, QGraphicsItem *parent)
:VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, initData.formula,
initData.secondPointId, 0, parent),
firstPointId(initData.firstPointId),
thirdPointId(initData.thirdPointId)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -148,15 +138,22 @@ VToolBisector* VToolBisector::Create(QSharedPointer<DialogTool> dialog, VMainGra
SCASSERT(not dialog.isNull())
QSharedPointer<DialogBisector> dialogTool = dialog.objectCast<DialogBisector>();
SCASSERT(not dialogTool.isNull())
QString formula = dialogTool->GetFormula();
const quint32 firstPointId = dialogTool->GetFirstPointId();
const quint32 secondPointId = dialogTool->GetSecondPointId();
const quint32 thirdPointId = dialogTool->GetThirdPointId();
const QString typeLine = dialogTool->GetTypeLine();
const QString lineColor = dialogTool->GetLineColor();
const QString pointName = dialogTool->getPointName();
VToolBisector *point = Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, lineColor,
pointName, 5, 10, true, scene, doc, data, Document::FullParse, Source::FromGui);
VToolBisectorInitData initData;
initData.formula = dialogTool->GetFormula();
initData.firstPointId = dialogTool->GetFirstPointId();
initData.secondPointId = dialogTool->GetSecondPointId();
initData.thirdPointId = dialogTool->GetThirdPointId();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolBisector *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -167,67 +164,47 @@ VToolBisector* VToolBisector::Create(QSharedPointer<DialogTool> dialog, VMainGra
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param formula string with formula.
* @param firstPointId id first point of angle.
* @param secondPointId id second point of angle.
* @param thirdPointId id third point of angle.
* @param typeLine line type.
* @param pointName point name.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param showLabel show/hide label.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
*/
VToolBisector* VToolBisector::Create(const quint32 _id, QString &formula, quint32 firstPointId, quint32 secondPointId,
quint32 thirdPointId, const QString &typeLine, const QString &lineColor,
const QString &pointName, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolBisector* VToolBisector::Create(VToolBisectorInitData &initData)
{
const QSharedPointer<VPointF> firstPoint = data->GeometricObject<VPointF>(firstPointId);
const QSharedPointer<VPointF> secondPoint = data->GeometricObject<VPointF>(secondPointId);
const QSharedPointer<VPointF> thirdPoint = data->GeometricObject<VPointF>(thirdPointId);
const QSharedPointer<VPointF> firstPoint = initData.data->GeometricObject<VPointF>(initData.firstPointId);
const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.secondPointId);
const QSharedPointer<VPointF> thirdPoint = initData.data->GeometricObject<VPointF>(initData.thirdPointId);
const qreal result = CheckFormula(_id, formula, data);
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
QPointF fPoint = VToolBisector::FindPoint(static_cast<QPointF>(*firstPoint), static_cast<QPointF>(*secondPoint),
static_cast<QPointF>(*thirdPoint), qApp->toPixel(result));
quint32 id = _id;
VPointF *p = new VPointF(fPoint, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
data->AddLine(secondPointId, id);
initData.id = initData.data->AddGObject(p);
initData.data->AddLine(initData.secondPointId, initData.id);
}
else
{
data->UpdateGObject(id, p);
data->AddLine(secondPointId, id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
initData.data->AddLine(initData.secondPointId, initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::Bisector, doc);
VToolBisector *point = new VToolBisector(doc, data, id, typeLine, lineColor, formula, firstPointId,
secondPointId, thirdPointId, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(firstPoint->getIdTool());
doc->IncrementReferens(secondPoint->getIdTool());
doc->IncrementReferens(thirdPoint->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::Bisector, initData.doc);
VToolBisector *point = new VToolBisector(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(firstPoint->getIdTool());
initData.doc->IncrementReferens(secondPoint->getIdTool());
initData.doc->IncrementReferens(thirdPoint->getIdTool());
return point;
}
return nullptr;

View File

@ -44,6 +44,22 @@
template <class T> class QSharedPointer;
struct VToolBisectorInitData : public VToolLinePointInitData
{
VToolBisectorInitData()
: VToolLinePointInitData(),
formula("100.0"),
firstPointId(NULL_ID),
secondPointId(NULL_ID),
thirdPointId(NULL_ID)
{}
QString formula;
quint32 firstPointId;
quint32 secondPointId;
quint32 thirdPointId;
};
/**
* @brief The VToolBisector class tool for creation bisector point.
*/
@ -57,11 +73,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolBisector* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolBisector* Create(const quint32 _id, QString &formula, quint32 firstPointId, quint32 secondPointId,
quint32 thirdPointId, const QString &typeLine, const QString &lineColor,
const QString &pointName, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolBisector* Create(VToolBisectorInitData &initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::Bisector)};
@ -93,10 +105,7 @@ private:
/** @brief thirdPointId id third point of angle. */
quint32 thirdPointId;
VToolBisector(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
const QString &lineColor,
const QString &formula, const quint32 &firstPointId, const quint32 &secondPointId,
const quint32 &thirdPointId, const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolBisector(const VToolBisectorInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLBISECTOR_H

View File

@ -70,15 +70,14 @@ template <class T> class QSharedPointer;
const QString VToolCurveIntersectAxis::ToolType = QStringLiteral("curveIntersectAxis");
//---------------------------------------------------------------------------------------------------------------------
VToolCurveIntersectAxis::VToolCurveIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id,
const QString &typeLine, const QString &lineColor,
const QString &formulaAngle, const quint32 &basePointId,
const quint32 &curveId, const Source &typeCreation,
VToolCurveIntersectAxis::VToolCurveIntersectAxis(const VToolCurveIntersectAxisInitData &initData,
QGraphicsItem *parent)
:VToolLinePoint(doc, data, id, typeLine, lineColor, QString(), basePointId, 0, parent), formulaAngle(formulaAngle),
curveId(curveId)
:VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, QString(),
initData.basePointId, 0, parent),
formulaAngle(initData.formulaAngle),
curveId(initData.curveId)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -105,16 +104,21 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(QSharedPointer<DialogTo
SCASSERT(not dialog.isNull())
QSharedPointer<DialogCurveIntersectAxis> dialogTool = dialog.objectCast<DialogCurveIntersectAxis>();
SCASSERT(not dialogTool.isNull())
const QString pointName = dialogTool->getPointName();
const QString typeLine = dialogTool->GetTypeLine();
const QString lineColor = dialogTool->GetLineColor();
QString formulaAngle = dialogTool->GetAngle();
const quint32 basePointId = dialogTool->GetBasePointId();
const quint32 curveId = dialogTool->getCurveId();
VToolCurveIntersectAxis *point = Create(0, pointName, typeLine, lineColor, formulaAngle, basePointId,
curveId, 5, 10, true, scene, doc, data, Document::FullParse,
Source::FromGui);
VToolCurveIntersectAxisInitData initData;
initData.formulaAngle = dialogTool->GetAngle();
initData.basePointId = dialogTool->GetBasePointId();
initData.curveId = dialogTool->getCurveId();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolCurveIntersectAxis *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -123,57 +127,49 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(QSharedPointer<DialogTo
}
//---------------------------------------------------------------------------------------------------------------------
VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(const quint32 _id, const QString &pointName,
const QString &typeLine, const QString &lineColor,
QString &formulaAngle, quint32 basePointId,
quint32 curveId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data, const Document &parse,
const Source &typeCreation)
VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxisInitData &initData)
{
const QSharedPointer<VPointF> basePoint = data->GeometricObject<VPointF>(basePointId);
const qreal angle = CheckFormula(_id, formulaAngle, data);
const QSharedPointer<VAbstractCurve> curve = data->GeometricObject<VAbstractCurve>(curveId);
const QSharedPointer<VPointF> basePoint = initData.data->GeometricObject<VPointF>(initData.basePointId);
const qreal angle = CheckFormula(initData.id, initData.formulaAngle, initData.data);
const QSharedPointer<VAbstractCurve> curve = initData.data->GeometricObject<VAbstractCurve>(initData.curveId);
const QPointF fPoint = FindPoint(static_cast<QPointF>(*basePoint), angle, curve);
const qreal segLength = curve->GetLengthByPoint(fPoint);
quint32 id = _id;
VPointF *p = new VPointF(fPoint, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
data->AddLine(basePointId, id);
initData.id = initData.data->AddGObject(p);
initData.data->AddLine(initData.basePointId, initData.id);
VContainer::getNextId();
VContainer::getNextId();
InitSegments(curve->getType(), segLength, p, curveId, data);
InitSegments(curve->getType(), segLength, p, initData.curveId, initData.data);
}
else
{
data->UpdateGObject(id, p);
data->AddLine(basePointId, id);
initData.data->UpdateGObject(initData.id, p);
initData.data->AddLine(initData.basePointId, initData.id);
InitSegments(curve->getType(), segLength, p, curveId, data);
InitSegments(curve->getType(), segLength, p, initData.curveId, initData.data);
if (parse != Document::FullParse)
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::CurveIntersectAxis, doc);
VToolCurveIntersectAxis *point = new VToolCurveIntersectAxis(doc, data, id, typeLine, lineColor, formulaAngle,
basePointId, curveId, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(basePoint->getIdTool());
doc->IncrementReferens(curve->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::CurveIntersectAxis, initData.doc);
VToolCurveIntersectAxis *point = new VToolCurveIntersectAxis(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(basePoint->getIdTool());
initData.doc->IncrementReferens(curve->getIdTool());
return point;
}
return nullptr;

View File

@ -46,6 +46,20 @@
template <class T> class QSharedPointer;
struct VToolCurveIntersectAxisInitData : public VToolLinePointInitData
{
VToolCurveIntersectAxisInitData()
: VToolLinePointInitData(),
formulaAngle("0"),
basePointId(NULL_ID),
curveId(NULL_ID)
{}
QString formulaAngle;
quint32 basePointId;
quint32 curveId;
};
class VToolCurveIntersectAxis : public VToolLinePoint
{
Q_OBJECT
@ -55,11 +69,7 @@ public:
static VToolCurveIntersectAxis *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolCurveIntersectAxis *Create(const quint32 _id, const QString &pointName, const QString &typeLine,
const QString &lineColor, QString &formulaAngle, quint32 basePointId,
quint32 curveId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolCurveIntersectAxis *Create(VToolCurveIntersectAxisInitData &initData);
static QPointF FindPoint(const QPointF &point, qreal angle, const QSharedPointer<VAbstractCurve> &curve);
@ -88,9 +98,7 @@ private:
QString formulaAngle;
quint32 curveId;
VToolCurveIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
const QString &lineColor, const QString &formulaAngle, const quint32 &basePointId,
const quint32 &curveId, const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolCurveIntersectAxis(const VToolCurveIntersectAxisInitData &initData, QGraphicsItem *parent = nullptr);
template <class Item>
static void InitArc(VContainer *data, qreal segLength, const VPointF *p, quint32 curveId);

View File

@ -59,23 +59,15 @@ const QString VToolEndLine::ToolType = QStringLiteral("endLine");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolEndLine constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param typeLine line type.
* @param formulaLength string with formula length of line.
* @param formulaAngle formula angle of line.
* @param basePointId id first point of line.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolEndLine::VToolEndLine(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
const QString &lineColor, const QString &formulaLength, const QString &formulaAngle,
const quint32 &basePointId, const Source &typeCreation, QGraphicsItem *parent)
:VToolLinePoint(doc, data, id, typeLine, lineColor, formulaLength, basePointId, 0, parent),
formulaAngle(formulaAngle)
VToolEndLine::VToolEndLine(const VToolEndLineInitData &initData, QGraphicsItem *parent)
:VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor,
initData.formulaLength, initData.basePointId, 0, parent),
formulaAngle(initData.formulaAngle)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -112,15 +104,21 @@ VToolEndLine* VToolEndLine::Create(QSharedPointer<DialogTool> dialog, VMainGraph
SCASSERT(not dialog.isNull())
QSharedPointer<DialogEndLine> dialogTool = dialog.objectCast<DialogEndLine>();
SCASSERT(not dialogTool.isNull())
const QString pointName = dialogTool->getPointName();
const QString typeLine = dialogTool->GetTypeLine();
const QString lineColor = dialogTool->GetLineColor();
QString formulaLength = dialogTool->GetFormula();
QString formulaAngle = dialogTool->GetAngle();
const quint32 basePointId = dialogTool->GetBasePointId();
VToolEndLine *point = Create(0, pointName, typeLine, lineColor, formulaLength, formulaAngle,
basePointId, 5, 10, true, scene, doc, data, Document::FullParse, Source::FromGui);
VToolEndLineInitData initData;
initData.formulaLength = dialogTool->GetFormula();
initData.formulaAngle = dialogTool->GetAngle();
initData.basePointId = dialogTool->GetBasePointId();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolEndLine *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -131,63 +129,42 @@ VToolEndLine* VToolEndLine::Create(QSharedPointer<DialogTool> dialog, VMainGraph
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param pointName point name.
* @param typeLine line type.
* @param lineColor line color.
* @param formulaLength string with formula length of line.
* @param formulaAngle formula angle of line.
* @param basePointId id first point of line.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param showLabel show/hide label
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @return the created tool
* @param initData init data.
*/
VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine,
const QString &lineColor, QString &formulaLength, QString &formulaAngle,
quint32 basePointId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolEndLine* VToolEndLine::Create(VToolEndLineInitData &initData)
{
const QSharedPointer<VPointF> basePoint = data->GeometricObject<VPointF>(basePointId);
const QSharedPointer<VPointF> basePoint = initData.data->GeometricObject<VPointF>(initData.basePointId);
QLineF line = QLineF(static_cast<QPointF>(*basePoint), QPointF(basePoint->x()+100, basePoint->y()));
line.setAngle(CheckFormula(_id, formulaAngle, data)); //First set angle.
line.setLength(qApp->toPixel(CheckFormula(_id, formulaLength, data)));
quint32 id = _id;
line.setAngle(CheckFormula(initData.id, initData.formulaAngle, initData.data)); //First set angle.
line.setLength(qApp->toPixel(CheckFormula(initData.id, initData.formulaLength, initData.data)));
VPointF *p = new VPointF(line.p2(), pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(line.p2(), initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
data->AddLine(basePointId, id);
initData.id = initData.data->AddGObject(p);
initData.data->AddLine(initData.basePointId, initData.id);
}
else
{
data->UpdateGObject(id, p);
data->AddLine(basePointId, id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
initData.data->AddLine(initData.basePointId, initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::EndLine, doc);
VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, lineColor, formulaLength, formulaAngle,
basePointId, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(basePoint->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::EndLine, initData.doc);
VToolEndLine *point = new VToolEndLine(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(basePoint->getIdTool());
return point;
}
return nullptr;

View File

@ -44,6 +44,20 @@
template <class T> class QSharedPointer;
struct VToolEndLineInitData : public VToolLinePointInitData
{
VToolEndLineInitData()
: VToolLinePointInitData(),
formulaLength(),
formulaAngle(),
basePointId(NULL_ID)
{}
QString formulaLength;
QString formulaAngle;
quint32 basePointId;
};
/**
* @brief The VToolEndLine class tool for creation point on the line end.
*/
@ -55,12 +69,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolEndLine *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolEndLine *Create(const quint32 _id, const QString &pointName, const QString &typeLine,
const QString &lineColor, QString &formulaLength, QString &formulaAngle,
quint32 basePointId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse,
const Source &typeCreation);
static VToolEndLine *Create(VToolEndLineInitData &initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::EndLine)};
@ -80,10 +89,7 @@ private:
QString formulaAngle;
VToolEndLine(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
const QString &lineColor,
const QString &formulaLength, const QString &formulaAngle, const quint32 &basePointId,
const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolEndLine(const VToolEndLineInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLENDLINE_H

View File

@ -55,23 +55,16 @@ const QString VToolHeight::ToolType = QStringLiteral("height");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolHeight constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param typeLine line type.
* @param basePointId id base point of projection.
* @param p1LineId id first point of line.
* @param p2LineId id second point of line.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolHeight::VToolHeight(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
const QString &lineColor, const quint32 &basePointId, const quint32 &p1LineId,
const quint32 &p2LineId, const Source &typeCreation, QGraphicsItem * parent)
:VToolLinePoint(doc, data, id, typeLine, lineColor, QString(), basePointId, 0, parent), p1LineId(p1LineId),
p2LineId(p2LineId)
VToolHeight::VToolHeight(const VToolHeightInitData &initData, QGraphicsItem * parent)
:VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, QString(),
initData.basePointId, 0, parent),
p1LineId(initData.p1LineId),
p2LineId(initData.p2LineId)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -107,15 +100,21 @@ VToolHeight* VToolHeight::Create(QSharedPointer<DialogTool> dialog, VMainGraphic
SCASSERT(not dialog.isNull())
QSharedPointer<DialogHeight> dialogTool = dialog.objectCast<DialogHeight>();
SCASSERT(not dialogTool.isNull())
const QString pointName = dialogTool->getPointName();
const QString typeLine = dialogTool->GetTypeLine();
const QString lineColor = dialogTool->GetLineColor();
const quint32 basePointId = dialogTool->GetBasePointId();
const quint32 p1LineId = dialogTool->GetP1LineId();
const quint32 p2LineId = dialogTool->GetP2LineId();
VToolHeight *point = Create(0, pointName, typeLine, lineColor, basePointId, p1LineId, p2LineId, 5, 10, true, scene,
doc, data, Document::FullParse, Source::FromGui);
VToolHeightInitData initData;
initData.basePointId = dialogTool->GetBasePointId();
initData.p1LineId = dialogTool->GetP1LineId();
initData.p2LineId = dialogTool->GetP2LineId();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolHeight *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -126,68 +125,49 @@ VToolHeight* VToolHeight::Create(QSharedPointer<DialogTool> dialog, VMainGraphic
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool
* @param _id tool id, 0 if tool doesn't exist yet.
* @param pointName point name.
* @param typeLine line type.
* @param basePointId id base point of projection.
* @param p1LineId id first point of line.
* @param p2LineId id second point of line.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @return the created tool
* @param initData init data.
*/
VToolHeight* VToolHeight::Create(const quint32 _id, const QString &pointName, const QString &typeLine,
const QString &lineColor, quint32 basePointId, quint32 p1LineId,
quint32 p2LineId, qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
VToolHeight* VToolHeight::Create(VToolHeightInitData initData)
{
const QSharedPointer<VPointF> basePoint = data->GeometricObject<VPointF>(basePointId);
const QSharedPointer<VPointF> p1Line = data->GeometricObject<VPointF>(p1LineId);
const QSharedPointer<VPointF> p2Line = data->GeometricObject<VPointF>(p2LineId);
const QSharedPointer<VPointF> basePoint = initData.data->GeometricObject<VPointF>(initData.basePointId);
const QSharedPointer<VPointF> p1Line = initData.data->GeometricObject<VPointF>(initData.p1LineId);
const QSharedPointer<VPointF> p2Line = initData.data->GeometricObject<VPointF>(initData.p2LineId);
QPointF pHeight = FindPoint(QLineF(static_cast<QPointF>(*p1Line), static_cast<QPointF>(*p2Line)),
static_cast<QPointF>(*basePoint));
quint32 id = _id;
VPointF *p = new VPointF(pHeight, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(pHeight, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
data->AddLine(basePointId, id);
data->AddLine(p1LineId, id);
data->AddLine(p2LineId, id);
initData.id = initData.data->AddGObject(p);
initData.data->AddLine(initData.basePointId, initData.id);
initData.data->AddLine(initData.p1LineId, initData.id);
initData.data->AddLine(initData.p2LineId, initData.id);
}
else
{
data->UpdateGObject(id, p);
data->AddLine(basePointId, id);
data->AddLine(p1LineId, id);
data->AddLine(p2LineId, id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
initData.data->AddLine(initData.basePointId, initData.id);
initData.data->AddLine(initData.p1LineId, initData.id);
initData.data->AddLine(initData.p2LineId, initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::Height, doc);
VToolHeight *point = new VToolHeight(doc, data, id, typeLine, lineColor, basePointId, p1LineId, p2LineId,
typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(basePoint->getIdTool());
doc->IncrementReferens(p1Line->getIdTool());
doc->IncrementReferens(p2Line->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::Height, initData.doc);
VToolHeight *point = new VToolHeight(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(basePoint->getIdTool());
initData.doc->IncrementReferens(p1Line->getIdTool());
initData.doc->IncrementReferens(p2Line->getIdTool());
return point;
}
return nullptr;

View File

@ -45,6 +45,20 @@
template <class T> class QSharedPointer;
struct VToolHeightInitData : public VToolLinePointInitData
{
VToolHeightInitData()
: VToolLinePointInitData(),
basePointId(NULL_ID),
p1LineId(NULL_ID),
p2LineId(NULL_ID)
{}
quint32 basePointId;
quint32 p1LineId;
quint32 p2LineId;
};
/**
* @brief The VToolHeight class tool for creation point of height. Help find point of projection onto line.
*/
@ -55,11 +69,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolHeight *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolHeight *Create(const quint32 _id, const QString &pointName, const QString &typeLine,
const QString &lineColor, quint32 basePointId, quint32 p1LineId,
quint32 p2LineId, qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static VToolHeight *Create(VToolHeightInitData initData);
static QPointF FindPoint(const QLineF &line, const QPointF &point);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
@ -92,10 +102,7 @@ private:
/** @brief p2LineId id second point of line. */
quint32 p2LineId;
VToolHeight(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
const QString &lineColor,
const quint32 &basePointId, const quint32 &p1LineId, const quint32 &p2LineId,
const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolHeight(const VToolHeightInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLHEIGHT_H

View File

@ -56,15 +56,14 @@ template <class T> class QSharedPointer;
const QString VToolLineIntersectAxis::ToolType = QStringLiteral("lineIntersectAxis");
//---------------------------------------------------------------------------------------------------------------------
VToolLineIntersectAxis::VToolLineIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id,
const QString &typeLine, const QString &lineColor,
const QString &formulaAngle, const quint32 &basePointId,
const quint32 &firstPointId, const quint32 &secondPointId,
const Source &typeCreation, QGraphicsItem *parent)
:VToolLinePoint(doc, data, id, typeLine, lineColor, QString(), basePointId, 0, parent), formulaAngle(formulaAngle),
firstPointId(firstPointId), secondPointId(secondPointId)
VToolLineIntersectAxis::VToolLineIntersectAxis(const VToolLineIntersectAxisInitData &initData, QGraphicsItem *parent)
:VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, QString(),
initData.basePointId, 0, parent),
formulaAngle(initData.formulaAngle),
firstPointId(initData.firstPointId),
secondPointId(initData.secondPointId)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -91,17 +90,22 @@ VToolLineIntersectAxis *VToolLineIntersectAxis::Create(QSharedPointer<DialogTool
SCASSERT(not dialog.isNull())
QSharedPointer<DialogLineIntersectAxis> dialogTool = dialog.objectCast<DialogLineIntersectAxis>();
SCASSERT(not dialogTool.isNull())
const QString pointName = dialogTool->getPointName();
const QString typeLine = dialogTool->GetTypeLine();
const QString lineColor = dialogTool->GetLineColor();
QString formulaAngle = dialogTool->GetAngle();
const quint32 basePointId = dialogTool->GetBasePointId();
const quint32 firstPointId = dialogTool->GetFirstPointId();
const quint32 secondPointId = dialogTool->GetSecondPointId();
VToolLineIntersectAxis *point = Create(0, pointName, typeLine, lineColor, formulaAngle,
basePointId, firstPointId, secondPointId, 5, 10, true,
scene, doc, data, Document::FullParse, Source::FromGui);
VToolLineIntersectAxisInitData initData;
initData.formulaAngle = dialogTool->GetAngle();
initData.basePointId = dialogTool->GetBasePointId();
initData.firstPointId = dialogTool->GetFirstPointId();
initData.secondPointId = dialogTool->GetSecondPointId();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolLineIntersectAxis *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -110,59 +114,50 @@ VToolLineIntersectAxis *VToolLineIntersectAxis::Create(QSharedPointer<DialogTool
}
//---------------------------------------------------------------------------------------------------------------------
VToolLineIntersectAxis *VToolLineIntersectAxis::Create(const quint32 _id, const QString &pointName,
const QString &typeLine, const QString &lineColor,
QString &formulaAngle, quint32 basePointId,
quint32 firstPointId, quint32 secondPointId,
qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
VToolLineIntersectAxis *VToolLineIntersectAxis::Create(VToolLineIntersectAxisInitData &initData)
{
const QSharedPointer<VPointF> basePoint = data->GeometricObject<VPointF>(basePointId);
const QSharedPointer<VPointF> basePoint = initData.data->GeometricObject<VPointF>(initData.basePointId);
QLineF axis = QLineF(static_cast<QPointF>(*basePoint), QPointF(basePoint->x()+100, basePoint->y()));
axis.setAngle(CheckFormula(_id, formulaAngle, data));
axis.setAngle(CheckFormula(initData.id, initData.formulaAngle, initData.data));
const QSharedPointer<VPointF> firstPoint = data->GeometricObject<VPointF>(firstPointId);
const QSharedPointer<VPointF> secondPoint = data->GeometricObject<VPointF>(secondPointId);
const QSharedPointer<VPointF> firstPoint = initData.data->GeometricObject<VPointF>(initData.firstPointId);
const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.secondPointId);
QLineF line(static_cast<QPointF>(*firstPoint), static_cast<QPointF>(*secondPoint));
QPointF fPoint = FindPoint(axis, line);
quint32 id = _id;
VPointF *p = new VPointF(fPoint, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
data->AddLine(basePointId, id);
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
initData.id = initData.data->AddGObject(p);
initData.data->AddLine(initData.basePointId, initData.id);
initData.data->AddLine(initData.firstPointId, initData.id);
initData.data->AddLine(initData.id, initData.secondPointId);
}
else
{
data->UpdateGObject(id, p);
data->AddLine(basePointId, id);
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
initData.data->AddLine(initData.basePointId, initData.id);
initData.data->AddLine(initData.firstPointId, initData.id);
initData.data->AddLine(initData.id, initData.secondPointId);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::LineIntersectAxis, doc);
VToolLineIntersectAxis *point = new VToolLineIntersectAxis(doc, data, id, typeLine, lineColor, formulaAngle,
basePointId, firstPointId, secondPointId,
typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(basePoint->getIdTool());
doc->IncrementReferens(firstPoint->getIdTool());
doc->IncrementReferens(secondPoint->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::LineIntersectAxis, initData.doc);
VToolLineIntersectAxis *point = new VToolLineIntersectAxis(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(basePoint->getIdTool());
initData.doc->IncrementReferens(firstPoint->getIdTool());
initData.doc->IncrementReferens(secondPoint->getIdTool());
return point;
}
return nullptr;

View File

@ -46,6 +46,22 @@
template <class T> class QSharedPointer;
struct VToolLineIntersectAxisInitData : public VToolLinePointInitData
{
VToolLineIntersectAxisInitData()
: VToolLinePointInitData(),
formulaAngle("0"),
basePointId(NULL_ID),
firstPointId(NULL_ID),
secondPointId(NULL_ID)
{}
QString formulaAngle;
quint32 basePointId;
quint32 firstPointId;
quint32 secondPointId;
};
class VToolLineIntersectAxis : public VToolLinePoint
{
Q_OBJECT
@ -55,12 +71,7 @@ public:
static VToolLineIntersectAxis *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolLineIntersectAxis *Create(const quint32 _id, const QString &pointName, const QString &typeLine,
const QString &lineColor, QString &formulaAngle, quint32 basePointId,
quint32 firstPointId, quint32 secondPointId,
qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc,
VContainer *data, const Document &parse, const Source &typeCreation);
static VToolLineIntersectAxis *Create(VToolLineIntersectAxisInitData &initData);
static QPointF FindPoint(const QLineF &axis, const QLineF &line);
@ -96,10 +107,7 @@ private:
quint32 firstPointId;
quint32 secondPointId;
VToolLineIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
const QString &lineColor, const QString &formulaAngle, const quint32 &basePointId,
const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation,
QGraphicsItem * parent = nullptr);
VToolLineIntersectAxis(const VToolLineIntersectAxisInitData &initData, QGraphicsItem * parent = nullptr);
};
#endif // VTOOLLINEINTERSECTAXIS_H

View File

@ -42,6 +42,18 @@
template <class T> class QSharedPointer;
struct VToolLinePointInitData : public VToolSinglePointInitData
{
VToolLinePointInitData()
: VToolSinglePointInitData(),
typeLine(TypeLineLine),
lineColor(ColorBlack)
{}
QString typeLine;
QString lineColor;
};
/**
* @brief The VToolLinePoint class parent for all tools what create point with line.
*/

View File

@ -59,26 +59,16 @@ const QString VToolNormal::ToolType = QStringLiteral("normal");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolNormal constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param typeLine line type.
* @param formula string with formula normal length.
* @param angle additional angle.
* @param firstPointId id first line point.
* @param secondPointId id second line point.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolNormal::VToolNormal(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
const QString &lineColor, const QString &formula, const qreal &angle,
const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation,
QGraphicsItem *parent)
:VToolLinePoint(doc, data, id, typeLine, lineColor, formula, firstPointId, angle, parent),
secondPointId(secondPointId)
VToolNormal::VToolNormal(const VToolNormalInitData &initData, QGraphicsItem *parent)
:VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, initData.formula,
initData.firstPointId, initData.angle, parent),
secondPointId(initData.secondPointId)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -113,15 +103,22 @@ VToolNormal* VToolNormal::Create(QSharedPointer<DialogTool> dialog, VMainGraphic
SCASSERT(not dialog.isNull())
QSharedPointer<DialogNormal> dialogTool = dialog.objectCast<DialogNormal>();
SCASSERT(not dialogTool.isNull())
QString formula = dialogTool->GetFormula();
const quint32 firstPointId = dialogTool->GetFirstPointId();
const quint32 secondPointId = dialogTool->GetSecondPointId();
const QString typeLine = dialogTool->GetTypeLine();
const QString lineColor = dialogTool->GetLineColor();
const QString pointName = dialogTool->getPointName();
const qreal angle = dialogTool->GetAngle();
VToolNormal *point = Create(0, formula, firstPointId, secondPointId, typeLine, lineColor, pointName, angle, 5, 10,
true, scene, doc, data, Document::FullParse, Source::FromGui);
VToolNormalInitData initData;
initData.formula = dialogTool->GetFormula();
initData.firstPointId = dialogTool->GetFirstPointId();
initData.secondPointId = dialogTool->GetSecondPointId();
initData.angle = dialogTool->GetAngle();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolNormal *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -132,65 +129,45 @@ VToolNormal* VToolNormal::Create(QSharedPointer<DialogTool> dialog, VMainGraphic
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param formula string with formula normal length.
* @param firstPointId id first line point.
* @param secondPointId id second line point.
* @param typeLine line type.
* @param pointName point name.
* @param angle additional angle.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param showLabel show/hide label.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
*/
VToolNormal* VToolNormal::Create(const quint32 _id, QString &formula, quint32 firstPointId, quint32 secondPointId,
const QString &typeLine, const QString &lineColor,
const QString &pointName, qreal angle, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolNormal* VToolNormal::Create(VToolNormalInitData initData)
{
const QSharedPointer<VPointF> firstPoint = data->GeometricObject<VPointF>(firstPointId);
const QSharedPointer<VPointF> secondPoint = data->GeometricObject<VPointF>(secondPointId);
const QSharedPointer<VPointF> firstPoint = initData.data->GeometricObject<VPointF>(initData.firstPointId);
const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.secondPointId);
const qreal result = CheckFormula(_id, formula, data);
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
QPointF fPoint = VToolNormal::FindPoint(static_cast<QPointF>(*firstPoint), static_cast<QPointF>(*secondPoint),
qApp->toPixel(result), angle);
quint32 id = _id;
qApp->toPixel(result), initData.angle);
VPointF *p = new VPointF(fPoint, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
data->AddLine(firstPointId, id);
initData.id = initData.data->AddGObject(p);
initData.data->AddLine(initData.firstPointId, initData.id);
}
else
{
data->UpdateGObject(id, p);
data->AddLine(firstPointId, id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
initData.data->AddLine(initData.firstPointId, initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::Normal, doc);
VToolNormal *point = new VToolNormal(doc, data, id, typeLine, lineColor, formula, angle, firstPointId,
secondPointId, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(firstPoint->getIdTool());
doc->IncrementReferens(secondPoint->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::Normal, initData.doc);
VToolNormal *point = new VToolNormal(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(firstPoint->getIdTool());
initData.doc->IncrementReferens(secondPoint->getIdTool());
return point;
}
return nullptr;

View File

@ -44,6 +44,22 @@
template <class T> class QSharedPointer;
struct VToolNormalInitData : public VToolLinePointInitData
{
VToolNormalInitData()
: VToolLinePointInitData(),
formula(),
firstPointId(NULL_ID),
secondPointId(NULL_ID),
angle(0)
{}
QString formula;
quint32 firstPointId;
quint32 secondPointId;
qreal angle;
};
/**
* @brief The VToolNormal class tool for creation point on normal. Normal begin from first point of line.
*/
@ -54,11 +70,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolNormal* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolNormal* Create(const quint32 _id, QString &formula, quint32 firstPointId,
quint32 secondPointId, const QString &typeLine, const QString &lineColor,
const QString &pointName, const qreal angle, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolNormal* Create(VToolNormalInitData initData);
static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length,
const qreal &angle = 0);
static const QString ToolType;
@ -85,10 +97,7 @@ private:
/** @brief secondPointId id second line point. */
quint32 secondPointId;
VToolNormal(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
const QString &lineColor,
const QString &formula, const qreal &angle, const quint32 &firstPointId, const quint32 &secondPointId,
const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolNormal(const VToolNormalInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLNORMAL_H

View File

@ -61,26 +61,16 @@ const QString VToolShoulderPoint::ToolType = QStringLiteral("shoulder");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolShoulderPoint constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param typeLine line type.
* @param formula string with formula length.
* @param p1Line id first line point.
* @param p2Line id second line point.
* @param pShoulder id shoulder point.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolShoulderPoint::VToolShoulderPoint(VAbstractPattern *doc, VContainer *data, const quint32 &id,
const QString &typeLine,
const QString &lineColor, const QString &formula, const quint32 &p1Line,
const quint32 &p2Line, const quint32 &pShoulder, const Source &typeCreation,
QGraphicsItem * parent)
:VToolLinePoint(doc, data, id, typeLine, lineColor, formula, p1Line, 0, parent), p2Line(p2Line),
pShoulder(pShoulder)
VToolShoulderPoint::VToolShoulderPoint(const VToolShoulderPointInitData &initData, QGraphicsItem * parent)
:VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, initData.formula,
initData.p1Line, 0, parent),
p2Line(initData.p2Line),
pShoulder(initData.pShoulder)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -162,15 +152,22 @@ VToolShoulderPoint* VToolShoulderPoint::Create(QSharedPointer<DialogTool> dialog
SCASSERT(not dialog.isNull())
QSharedPointer<DialogShoulderPoint> dialogTool = dialog.objectCast<DialogShoulderPoint>();
SCASSERT(not dialogTool.isNull())
QString formula = dialogTool->GetFormula();
const quint32 p1Line = dialogTool->GetP1Line();
const quint32 p2Line = dialogTool->GetP2Line();
const quint32 pShoulder = dialogTool->GetP3();
const QString typeLine = dialogTool->GetTypeLine();
const QString lineColor = dialogTool->GetLineColor();
const QString pointName = dialogTool->getPointName();
VToolShoulderPoint * point = Create(0, formula, p1Line, p2Line, pShoulder, typeLine, lineColor, pointName, 5,
10, true, scene, doc, data, Document::FullParse, Source::FromGui);
VToolShoulderPointInitData initData;
initData.formula = dialogTool->GetFormula();
initData.p1Line = dialogTool->GetP1Line();
initData.p2Line = dialogTool->GetP2Line();
initData.pShoulder = dialogTool->GetP3();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolShoulderPoint * point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -181,72 +178,51 @@ VToolShoulderPoint* VToolShoulderPoint::Create(QSharedPointer<DialogTool> dialog
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param formula string with formula length.
* @param p1Line id first line point.
* @param p2Line id second line point.
* @param pShoulder id shoulder point.
* @param typeLine line type.
* @param pointName point name.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param showLabel show/hide label.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
* @return the created tool
*/
VToolShoulderPoint* VToolShoulderPoint::Create(const quint32 _id, QString &formula, quint32 p1Line, quint32 p2Line,
quint32 pShoulder, const QString &typeLine, const QString &lineColor,
const QString &pointName, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolShoulderPoint* VToolShoulderPoint::Create(VToolShoulderPointInitData &initData)
{
const QSharedPointer<VPointF> firstPoint = data->GeometricObject<VPointF>(p1Line);
const QSharedPointer<VPointF> secondPoint = data->GeometricObject<VPointF>(p2Line);
const QSharedPointer<VPointF> shoulderPoint = data->GeometricObject<VPointF>(pShoulder);
const QSharedPointer<VPointF> firstPoint = initData.data->GeometricObject<VPointF>(initData.p1Line);
const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.p2Line);
const QSharedPointer<VPointF> shoulderPoint = initData.data->GeometricObject<VPointF>(initData.pShoulder);
const qreal result = CheckFormula(_id, formula, data);
const qreal result = CheckFormula(initData.id, initData.formula, initData.data);
QPointF fPoint = VToolShoulderPoint::FindPoint(static_cast<QPointF>(*firstPoint),
static_cast<QPointF>(*secondPoint),
static_cast<QPointF>(*shoulderPoint), qApp->toPixel(result));
quint32 id = _id;
VPointF *p = new VPointF(fPoint, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
initData.id = initData.data->AddGObject(p);
initData.data->AddLine(initData.p1Line, initData.id);
initData.data->AddLine(initData.p2Line, initData.id);
}
else
{
data->UpdateGObject(id, p);
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
initData.data->AddLine(initData.p1Line, initData.id);
initData.data->AddLine(initData.p2Line, initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::ShoulderPoint, doc);
VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, lineColor, formula,
p1Line, p2Line, pShoulder,
typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(firstPoint->getIdTool());
doc->IncrementReferens(secondPoint->getIdTool());
doc->IncrementReferens(shoulderPoint->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::ShoulderPoint, initData.doc);
VToolShoulderPoint *point = new VToolShoulderPoint(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(firstPoint->getIdTool());
initData.doc->IncrementReferens(secondPoint->getIdTool());
initData.doc->IncrementReferens(shoulderPoint->getIdTool());
return point;
}
return nullptr;

View File

@ -44,6 +44,22 @@
template <class T> class QSharedPointer;
struct VToolShoulderPointInitData : public VToolLinePointInitData
{
VToolShoulderPointInitData()
: VToolLinePointInitData(),
formula(),
p1Line(NULL_ID),
p2Line(NULL_ID),
pShoulder(NULL_ID)
{}
QString formula;
quint32 p1Line;
quint32 p2Line;
quint32 pShoulder;
};
/**
* @brief The VToolShoulderPoint class tool for creation point on shoulder. This tool for special situation, when you
* want find point along line, but have only length from another point (shoulder).
@ -57,12 +73,7 @@ public:
const qreal &length);
static VToolShoulderPoint* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolShoulderPoint* Create(const quint32 _id, QString &formula, quint32 p1Line, quint32 p2Line,
quint32 pShoulder, const QString &typeLine, const QString &lineColor,
const QString &pointName, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse,
const Source &typeCreation);
static VToolShoulderPoint* Create(VToolShoulderPointInitData &initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::ShoulderPoint) };
@ -95,9 +106,7 @@ private:
/** @brief pShoulder id shoulder line point. */
quint32 pShoulder;
VToolShoulderPoint(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
const QString &lineColor, const QString &formula, const quint32 &p1Line, const quint32 &p2Line,
const quint32 &pShoulder, const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolShoulderPoint(const VToolShoulderPointInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLSHOULDERPOINT_H

View File

@ -73,21 +73,17 @@ const QString VToolBasePoint::ToolType = QStringLiteral("single");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolBasePoint constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolBasePoint::VToolBasePoint (VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
const QString &namePP, QGraphicsItem * parent )
:VToolSinglePoint(doc, data, id, parent), namePP(namePP)
VToolBasePoint::VToolBasePoint (const VToolBasePointInitData &initData, QGraphicsItem * parent )
:VToolSinglePoint(initData.doc, initData.data, initData.id, parent), namePP(initData.nameActivPP)
{
m_baseColor = Qt::red;
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
m_namePoint->setBrush(Qt::black);
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -104,33 +100,31 @@ void VToolBasePoint::setDialog()
}
//---------------------------------------------------------------------------------------------------------------------
VToolBasePoint *VToolBasePoint::Create(quint32 _id, const QString &nameActivPP, VPointF *point,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolBasePoint *VToolBasePoint::Create(VToolBasePointInitData initData)
{
SCASSERT(point != nullptr)
VPointF *point = new VPointF(initData.x, initData.y, initData.name, initData.mx, initData.my);
point->SetShowLabel(initData.showLabel);
quint32 id = _id;
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(point);
initData.id = initData.data->AddGObject(point);
}
else
{
data->UpdateGObject(id, point);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, point);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::BasePoint, doc);
VToolBasePoint *spoint = new VToolBasePoint(doc, data, id, typeCreation, nameActivPP);
scene->addItem(spoint);
InitToolConnections(scene, spoint);
VAbstractPattern::AddTool(id, spoint);
VAbstractTool::AddRecord(initData.id, Tool::BasePoint, initData.doc);
VToolBasePoint *spoint = new VToolBasePoint(initData);
initData.scene->addItem(spoint);
InitToolConnections(initData.scene, spoint);
VAbstractPattern::AddTool(initData.id, spoint);
return spoint;
}
return nullptr;

View File

@ -45,6 +45,20 @@
template <class T> class QSharedPointer;
struct VToolBasePointInitData : public VToolSinglePointInitData
{
VToolBasePointInitData()
: VToolSinglePointInitData(),
nameActivPP(),
x(10),
y(10)
{}
QString nameActivPP;
qreal x;
qreal y;
};
/**
* @brief The VToolBasePoint class tool for creation pattern base point. Only base point can move. All object
* pattern peace depend on base point.
@ -55,9 +69,7 @@ class VToolBasePoint : public VToolSinglePoint
public:
virtual ~VToolBasePoint() =default;
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolBasePoint *Create(quint32 _id, const QString &nameActivPP, VPointF *point,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolBasePoint *Create(VToolBasePointInitData initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::BasePoint)};
@ -94,8 +106,7 @@ private:
QString namePP;
VToolBasePoint (VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
const QString &namePP, QGraphicsItem * parent = nullptr );
VToolBasePoint (const VToolBasePointInitData &initData, QGraphicsItem * parent = nullptr );
};
#endif // VTOOLBASEPOINT_H

View File

@ -58,24 +58,17 @@ const QString VToolLineIntersect::ToolType = QStringLiteral("lineIntersect");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolLineIntersect constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param p1Line1 id first point first line.
* @param p2Line1 id second point first line.
* @param p1Line2 id first point second line.
* @param p2Line2 id second point second line.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolLineIntersect::VToolLineIntersect(VAbstractPattern *doc, VContainer *data, const quint32 &id,
const quint32 &p1Line1, const quint32 &p2Line1, const quint32 &p1Line2,
const quint32 &p2Line2, const Source &typeCreation,
QGraphicsItem *parent)
:VToolSinglePoint(doc, data, id, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2),
p2Line2(p2Line2)
VToolLineIntersect::VToolLineIntersect(const VToolLineIntersectInitData &initData, QGraphicsItem *parent)
:VToolSinglePoint(initData.doc, initData.data, initData.id, parent),
p1Line1(initData.p1Line1Id),
p2Line1(initData.p2Line1Id),
p1Line2(initData.p1Line2Id),
p2Line2(initData.p2Line2Id)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -110,13 +103,20 @@ VToolLineIntersect* VToolLineIntersect::Create(QSharedPointer<DialogTool> dialog
SCASSERT(not dialog.isNull())
QSharedPointer<DialogLineIntersect> dialogTool = dialog.objectCast<DialogLineIntersect>();
SCASSERT(not dialogTool.isNull())
const quint32 p1Line1Id = dialogTool->GetP1Line1();
const quint32 p2Line1Id = dialogTool->GetP2Line1();
const quint32 p1Line2Id = dialogTool->GetP1Line2();
const quint32 p2Line2Id = dialogTool->GetP2Line2();
const QString pointName = dialogTool->getPointName();
VToolLineIntersect* point = Create(0, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, pointName, 5, 10, true, scene,
doc, data, Document::FullParse, Source::FromGui);
VToolLineIntersectInitData initData;
initData.p1Line1Id = dialogTool->GetP1Line1();
initData.p2Line1Id = dialogTool->GetP2Line1();
initData.p1Line2Id = dialogTool->GetP1Line2();
initData.p2Line2Id = dialogTool->GetP2Line2();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolLineIntersect* point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -127,31 +127,15 @@ VToolLineIntersect* VToolLineIntersect::Create(QSharedPointer<DialogTool> dialog
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param p1Line1Id id first point first line.
* @param p2Line1Id id second point first line.
* @param p1Line2Id id first point second line.
* @param p2Line2Id id second point second line.
* @param pointName point name.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
* @return the created tool
*/
VToolLineIntersect* VToolLineIntersect::Create(const quint32 _id, quint32 p1Line1Id, quint32 p2Line1Id,
quint32 p1Line2Id, quint32 p2Line2Id, const QString &pointName,
qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
VToolLineIntersect* VToolLineIntersect::Create(VToolLineIntersectInitData initData)
{
const QSharedPointer<VPointF> p1Line1 = data->GeometricObject<VPointF>(p1Line1Id);
const QSharedPointer<VPointF> p2Line1 = data->GeometricObject<VPointF>(p2Line1Id);
const QSharedPointer<VPointF> p1Line2 = data->GeometricObject<VPointF>(p1Line2Id);
const QSharedPointer<VPointF> p2Line2 = data->GeometricObject<VPointF>(p2Line2Id);
const QSharedPointer<VPointF> p1Line1 = initData.data->GeometricObject<VPointF>(initData.p1Line1Id);
const QSharedPointer<VPointF> p2Line1 = initData.data->GeometricObject<VPointF>(initData.p2Line1Id);
const QSharedPointer<VPointF> p1Line2 = initData.data->GeometricObject<VPointF>(initData.p1Line2Id);
const QSharedPointer<VPointF> p2Line2 = initData.data->GeometricObject<VPointF>(initData.p2Line2Id);
QLineF line1(static_cast<QPointF>(*p1Line1), static_cast<QPointF>(*p2Line1));
QLineF line2(static_cast<QPointF>(*p1Line2), static_cast<QPointF>(*p2Line2));
@ -159,44 +143,41 @@ VToolLineIntersect* VToolLineIntersect::Create(const quint32 _id, quint32 p1Line
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
{
quint32 id = _id;
VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
VPointF *p = new VPointF(fPoint, pointName, mx, my);
p->SetShowLabel(showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
data->AddLine(id, p2Line2Id);
initData.id = initData.data->AddGObject(p);
initData.data->AddLine(initData.p1Line1Id, initData.id);
initData.data->AddLine(initData.id, initData.p2Line1Id);
initData.data->AddLine(initData.p1Line2Id, initData.id);
initData.data->AddLine(initData.id, initData.p2Line2Id);
}
else
{
data->UpdateGObject(id, p);
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
data->AddLine(id, p2Line2Id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
initData.data->AddLine(initData.p1Line1Id, initData.id);
initData.data->AddLine(initData.id, initData.p2Line1Id);
initData.data->AddLine(initData.p1Line2Id, initData.id);
initData.data->AddLine(initData.id, initData.p2Line2Id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::LineIntersect, doc);
VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id, p2Line1Id, p1Line2Id,
p2Line2Id, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(p1Line1->getIdTool());
doc->IncrementReferens(p2Line1->getIdTool());
doc->IncrementReferens(p1Line2->getIdTool());
doc->IncrementReferens(p2Line2->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::LineIntersect, initData.doc);
VToolLineIntersect *point = new VToolLineIntersect(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(p1Line1->getIdTool());
initData.doc->IncrementReferens(p2Line1->getIdTool());
initData.doc->IncrementReferens(p1Line2->getIdTool());
initData.doc->IncrementReferens(p2Line2->getIdTool());
return point;
}
}

View File

@ -43,6 +43,22 @@
template <class T> class QSharedPointer;
struct VToolLineIntersectInitData : public VToolSinglePointInitData
{
VToolLineIntersectInitData()
: VToolSinglePointInitData(),
p1Line1Id(NULL_ID),
p2Line1Id(NULL_ID),
p1Line2Id(NULL_ID),
p2Line2Id(NULL_ID)
{}
quint32 p1Line1Id;
quint32 p2Line1Id;
quint32 p1Line2Id;
quint32 p2Line2Id;
};
/**
* @brief The VToolLineIntersect class help find point intersection lines.
*/
@ -53,11 +69,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolLineIntersect *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolLineIntersect *Create(const quint32 _id, quint32 p1Line1Id, quint32 p2Line1Id,
quint32 p1Line2Id, quint32 p2Line2Id, const QString &pointName,
qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc,
VContainer *data, const Document &parse, const Source &typeCreation);
static VToolLineIntersect *Create(VToolLineIntersectInitData initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::LineIntersect)};
@ -104,9 +116,7 @@ private:
/** @brief p2Line2 id second point second line.*/
quint32 p2Line2;
VToolLineIntersect(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &p1Line1,
const quint32 &p2Line1, const quint32 &p1Line2, const quint32 &p2Line2,
const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolLineIntersect(const VToolLineIntersectInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLLINEINTERSECT_H

View File

@ -55,13 +55,14 @@ template <class T> class QSharedPointer;
const QString VToolPointFromArcAndTangent::ToolType = QStringLiteral("pointFromArcAndTangent");
//---------------------------------------------------------------------------------------------------------------------
VToolPointFromArcAndTangent::VToolPointFromArcAndTangent(VAbstractPattern *doc, VContainer *data, const quint32 &id,
quint32 arcId, quint32 tangentPointId,
CrossCirclesPoint crossPoint, const Source &typeCreation,
VToolPointFromArcAndTangent::VToolPointFromArcAndTangent(const VToolPointFromArcAndTangentInitData &initData,
QGraphicsItem *parent)
:VToolSinglePoint(doc, data, id, parent), arcId(arcId), tangentPointId(tangentPointId), crossPoint(crossPoint)
:VToolSinglePoint(initData.doc, initData.data, initData.id, parent),
arcId(initData.arcId),
tangentPointId(initData.tangentPointId),
crossPoint(initData.crossPoint)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -85,12 +86,19 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(QSharedPointer<
SCASSERT(not dialog.isNull())
QSharedPointer<DialogPointFromArcAndTangent> dialogTool = dialog.objectCast<DialogPointFromArcAndTangent>();
SCASSERT(not dialogTool.isNull())
const quint32 arcId = dialogTool->GetArcId();
const quint32 tangentPointId = dialogTool->GetTangentPointId();
const CrossCirclesPoint pType = dialogTool->GetCrossCirclesPoint();
const QString pointName = dialogTool->getPointName();
VToolPointFromArcAndTangent *point = Create(0, pointName, arcId, tangentPointId, pType, 5, 10, true, scene, doc,
data, Document::FullParse, Source::FromGui);
VToolPointFromArcAndTangentInitData initData;
initData.arcId = dialogTool->GetArcId();
initData.tangentPointId = dialogTool->GetTangentPointId();
initData.crossPoint = dialogTool->GetCrossCirclesPoint();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolPointFromArcAndTangent *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -99,45 +107,39 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(QSharedPointer<
}
//---------------------------------------------------------------------------------------------------------------------
VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(const quint32 _id, const QString &pointName,
quint32 arcId, quint32 tangentPointId,
CrossCirclesPoint crossPoint, qreal mx,
qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(VToolPointFromArcAndTangentInitData initData)
{
const VArc arc = *data->GeometricObject<VArc>(arcId);
const VPointF tPoint = *data->GeometricObject<VPointF>(tangentPointId);
const VArc arc = *initData.data->GeometricObject<VArc>(initData.arcId);
const VPointF tPoint = *initData.data->GeometricObject<VPointF>(initData.tangentPointId);
const QPointF point = VToolPointFromArcAndTangent::FindPoint(static_cast<QPointF>(tPoint), &arc, crossPoint);
quint32 id = _id;
const QPointF point = VToolPointFromArcAndTangent::FindPoint(static_cast<QPointF>(tPoint), &arc,
initData.crossPoint);
VPointF *p = new VPointF(point, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
initData.id = initData.data->AddGObject(p);
}
else
{
data->UpdateGObject(id, p);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::PointFromArcAndTangent, doc);
VToolPointFromArcAndTangent *point = new VToolPointFromArcAndTangent(doc, data, id, arcId, tangentPointId,
crossPoint, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(arc.getIdTool());
doc->IncrementReferens(tPoint.getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::PointFromArcAndTangent, initData.doc);
VToolPointFromArcAndTangent *point = new VToolPointFromArcAndTangent(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(arc.getIdTool());
initData.doc->IncrementReferens(tPoint.getIdTool());
return point;
}
return nullptr;

View File

@ -44,6 +44,20 @@
template <class T> class QSharedPointer;
struct VToolPointFromArcAndTangentInitData : public VToolSinglePointInitData
{
VToolPointFromArcAndTangentInitData()
: VToolSinglePointInitData(),
arcId(NULL_ID),
tangentPointId(NULL_ID),
crossPoint(CrossCirclesPoint::FirstPoint)
{}
quint32 arcId;
quint32 tangentPointId;
CrossCirclesPoint crossPoint;
};
class VToolPointFromArcAndTangent : public VToolSinglePoint
{
Q_OBJECT
@ -51,11 +65,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolPointFromArcAndTangent *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolPointFromArcAndTangent *Create(const quint32 _id, const QString &pointName, quint32 arcId,
quint32 tangentPointId, CrossCirclesPoint crossPoint, qreal mx,
qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static VToolPointFromArcAndTangent *Create(VToolPointFromArcAndTangentInitData initData);
static QPointF FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
@ -89,9 +99,7 @@ private:
quint32 tangentPointId;
CrossCirclesPoint crossPoint;
VToolPointFromArcAndTangent(VAbstractPattern *doc, VContainer *data, const quint32 &id, quint32 arcId,
quint32 tangentPointId, CrossCirclesPoint crossPoint, const Source &typeCreation,
QGraphicsItem * parent = nullptr);
VToolPointFromArcAndTangent(const VToolPointFromArcAndTangentInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLPOINTFROMARCANDTANGENT_H

View File

@ -56,15 +56,15 @@ template <class T> class QSharedPointer;
const QString VToolPointFromCircleAndTangent::ToolType = QStringLiteral("pointFromCircleAndTangent");
//---------------------------------------------------------------------------------------------------------------------
VToolPointFromCircleAndTangent::VToolPointFromCircleAndTangent(VAbstractPattern *doc, VContainer *data,
const quint32 &id,
quint32 circleCenterId, const QString &circleRadius,
quint32 tangentPointId, CrossCirclesPoint crossPoint,
const Source &typeCreation, QGraphicsItem *parent)
:VToolSinglePoint(doc, data, id, parent), circleCenterId(circleCenterId), tangentPointId(tangentPointId),
circleRadius(circleRadius), crossPoint(crossPoint)
VToolPointFromCircleAndTangent::VToolPointFromCircleAndTangent(const VToolPointFromCircleAndTangentInitData &initData,
QGraphicsItem *parent)
:VToolSinglePoint(initData.doc, initData.data, initData.id, parent),
circleCenterId(initData.circleCenterId),
tangentPointId(initData.tangentPointId),
circleRadius(initData.circleRadius),
crossPoint(initData.crossPoint)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -89,13 +89,20 @@ VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(QSharedPo
SCASSERT(not dialog.isNull())
QSharedPointer<DialogPointFromCircleAndTangent> dialogTool = dialog.objectCast<DialogPointFromCircleAndTangent>();
SCASSERT(not dialogTool.isNull())
const quint32 circleCenterId = dialogTool->GetCircleCenterId();
QString circleRadius = dialogTool->GetCircleRadius();
const quint32 tangentPointId = dialogTool->GetTangentPointId();
const CrossCirclesPoint pType = dialogTool->GetCrossCirclesPoint();
const QString pointName = dialogTool->getPointName();
VToolPointFromCircleAndTangent *point = Create(0, pointName, circleCenterId, circleRadius, tangentPointId, pType,
5, 10, true, scene, doc, data, Document::FullParse, Source::FromGui);
VToolPointFromCircleAndTangentInitData initData;
initData.circleCenterId = dialogTool->GetCircleCenterId();
initData.circleRadius = dialogTool->GetCircleRadius();
initData.tangentPointId = dialogTool->GetTangentPointId();
initData.crossPoint = dialogTool->GetCrossCirclesPoint();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolPointFromCircleAndTangent *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -104,51 +111,41 @@ VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(QSharedPo
}
//---------------------------------------------------------------------------------------------------------------------
VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(const quint32 _id, const QString &pointName,
quint32 circleCenterId, QString &circleRadius,
quint32 tangentPointId,
CrossCirclesPoint crossPoint, qreal mx,
qreal my, bool showLabel,
VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data,
const Document &parse,
const Source &typeCreation)
VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(VToolPointFromCircleAndTangentInitData &initData)
{
const qreal radius = qApp->toPixel(CheckFormula(_id, circleRadius, data));
const VPointF cPoint = *data->GeometricObject<VPointF>(circleCenterId);
const VPointF tPoint = *data->GeometricObject<VPointF>(tangentPointId);
const qreal radius = qApp->toPixel(CheckFormula(initData.id, initData.circleRadius, initData.data));
const VPointF cPoint = *initData.data->GeometricObject<VPointF>(initData.circleCenterId);
const VPointF tPoint = *initData.data->GeometricObject<VPointF>(initData.tangentPointId);
const QPointF point = VToolPointFromCircleAndTangent::FindPoint(static_cast<QPointF>(tPoint),
static_cast<QPointF>(cPoint), radius, crossPoint);
quint32 id = _id;
static_cast<QPointF>(cPoint), radius,
initData.crossPoint);
VPointF *p = new VPointF(point, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
initData.id = initData.data->AddGObject(p);
}
else
{
data->UpdateGObject(id, p);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::PointFromCircleAndTangent, doc);
VToolPointFromCircleAndTangent *point = new VToolPointFromCircleAndTangent(doc, data, id, circleCenterId,
circleRadius, tangentPointId,
crossPoint, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(cPoint.getIdTool());
doc->IncrementReferens(tPoint.getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::PointFromCircleAndTangent, initData.doc);
VToolPointFromCircleAndTangent *point = new VToolPointFromCircleAndTangent(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(cPoint.getIdTool());
initData.doc->IncrementReferens(tPoint.getIdTool());
return point;
}
return nullptr;

View File

@ -45,6 +45,22 @@
class VFormula;
template <class T> class QSharedPointer;
struct VToolPointFromCircleAndTangentInitData : public VToolSinglePointInitData
{
VToolPointFromCircleAndTangentInitData()
: VToolSinglePointInitData(),
circleCenterId(NULL_ID),
circleRadius("0"),
tangentPointId(NULL_ID),
crossPoint(CrossCirclesPoint::FirstPoint)
{}
quint32 circleCenterId;
QString circleRadius;
quint32 tangentPointId;
CrossCirclesPoint crossPoint;
};
class VToolPointFromCircleAndTangent : public VToolSinglePoint
{
Q_OBJECT
@ -52,11 +68,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolPointFromCircleAndTangent *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolPointFromCircleAndTangent *Create(const quint32 _id, const QString &pointName,
quint32 circleCenterId, QString &circleRadius, quint32 tangentPointId,
CrossCirclesPoint crossPoint, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolPointFromCircleAndTangent *Create(VToolPointFromCircleAndTangentInitData &initData);
static QPointF FindPoint(const QPointF &p, const QPointF &center, qreal radius, const CrossCirclesPoint crossPoint);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
@ -94,9 +106,8 @@ private:
QString circleRadius;
CrossCirclesPoint crossPoint;
VToolPointFromCircleAndTangent(VAbstractPattern *doc, VContainer *data, const quint32 &id, quint32 circleCenterId,
const QString &circleRadius, quint32 tangentPointId, CrossCirclesPoint crossPoint,
const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolPointFromCircleAndTangent(const VToolPointFromCircleAndTangentInitData &initData,
QGraphicsItem *parent = nullptr);
};
#endif // VTOOLPOINTFROMCIRCLEANDTANGENT_H

View File

@ -63,24 +63,17 @@ const QString VToolPointOfContact::ToolType = QStringLiteral("pointOfContact");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolPointOfContact constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param radius string with formula radius arc.
* @param center id center arc point.
* @param firstPointId id first line point.
* @param secondPointId id second line point.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolPointOfContact::VToolPointOfContact(VAbstractPattern *doc, VContainer *data, const quint32 &id,
const QString &radius, const quint32 &center,
const quint32 &firstPointId, const quint32 &secondPointId,
const Source &typeCreation, QGraphicsItem *parent)
: VToolSinglePoint(doc, data, id, parent), arcRadius(radius), center(center), firstPointId(firstPointId),
secondPointId(secondPointId)
VToolPointOfContact::VToolPointOfContact(const VToolPointOfContactInitData &initData, QGraphicsItem *parent)
: VToolSinglePoint(initData.doc, initData.data, initData.id, parent),
arcRadius(initData.radius),
center(initData.center),
firstPointId(initData.firstPointId),
secondPointId(initData.secondPointId)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -170,13 +163,20 @@ VToolPointOfContact* VToolPointOfContact::Create(QSharedPointer<DialogTool> dial
SCASSERT(not dialog.isNull())
QSharedPointer<DialogPointOfContact> dialogTool = dialog.objectCast<DialogPointOfContact>();
SCASSERT(not dialogTool.isNull())
QString radius = dialogTool->getRadius();
const quint32 center = dialogTool->getCenter();
const quint32 firstPointId = dialogTool->GetFirstPoint();
const quint32 secondPointId = dialogTool->GetSecondPoint();
const QString pointName = dialogTool->getPointName();
VToolPointOfContact *point = Create(0, radius, center, firstPointId, secondPointId, pointName, 5, 10, true, scene,
doc, data, Document::FullParse, Source::FromGui);
VToolPointOfContactInitData initData;
initData.radius = dialogTool->getRadius();
initData.center = dialogTool->getCenter();
initData.firstPointId = dialogTool->GetFirstPoint();
initData.secondPointId = dialogTool->GetSecondPoint();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolPointOfContact *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -187,69 +187,51 @@ VToolPointOfContact* VToolPointOfContact::Create(QSharedPointer<DialogTool> dial
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param radius string with formula radius arc.
* @param center id center arc point.
* @param firstPointId id first line point.
* @param secondPointId id second line point.
* @param pointName point name.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
*/
VToolPointOfContact* VToolPointOfContact::Create(const quint32 _id, QString &radius, quint32 center,
quint32 firstPointId, quint32 secondPointId,
const QString &pointName, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolPointOfContact* VToolPointOfContact::Create(VToolPointOfContactInitData &initData)
{
const QSharedPointer<VPointF> centerP = data->GeometricObject<VPointF>(center);
const QSharedPointer<VPointF> firstP = data->GeometricObject<VPointF>(firstPointId);
const QSharedPointer<VPointF> secondP = data->GeometricObject<VPointF>(secondPointId);
const QSharedPointer<VPointF> centerP = initData.data->GeometricObject<VPointF>(initData.center);
const QSharedPointer<VPointF> firstP = initData.data->GeometricObject<VPointF>(initData.firstPointId);
const QSharedPointer<VPointF> secondP = initData.data->GeometricObject<VPointF>(initData.secondPointId);
const qreal result = CheckFormula(_id, radius, data);
const qreal result = CheckFormula(initData.id, initData.radius, initData.data);
QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), static_cast<QPointF>(*centerP),
static_cast<QPointF>(*firstP), static_cast<QPointF>(*secondP));
quint32 id = _id;
VPointF *p = new VPointF(fPoint, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
data->AddLine(firstPointId, id);
data->AddLine(secondPointId, id);
data->AddLine(center, id);
initData.id = initData.data->AddGObject(p);
initData.data->AddLine(initData.firstPointId, initData.id);
initData.data->AddLine(initData.secondPointId, initData.id);
initData.data->AddLine(initData.center, initData.id);
}
else
{
data->UpdateGObject(id, p);
data->AddLine(firstPointId, id);
data->AddLine(secondPointId, id);
data->AddLine(center, id);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
initData.data->AddLine(initData.firstPointId, initData.id);
initData.data->AddLine(initData.secondPointId, initData.id);
initData.data->AddLine(initData.center, initData.id);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::PointOfContact, doc);
VToolPointOfContact *point = new VToolPointOfContact(doc, data, id, radius, center,
firstPointId, secondPointId, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(centerP->getIdTool());
doc->IncrementReferens(firstP->getIdTool());
doc->IncrementReferens(secondP->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::PointOfContact, initData.doc);
VToolPointOfContact *point = new VToolPointOfContact(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(centerP->getIdTool());
initData.doc->IncrementReferens(firstP->getIdTool());
initData.doc->IncrementReferens(secondP->getIdTool());
return point;
}
return nullptr;

View File

@ -45,6 +45,22 @@
class VFormula;
template <class T> class QSharedPointer;
struct VToolPointOfContactInitData : public VToolSinglePointInitData
{
VToolPointOfContactInitData()
: VToolSinglePointInitData(),
radius("0"),
center(NULL_ID),
firstPointId(NULL_ID),
secondPointId(NULL_ID)
{}
QString radius;
quint32 center;
quint32 firstPointId;
quint32 secondPointId;
};
/**
* @brief The VToolPointOfContact class tool for creation point intersection line and arc.
*/
@ -57,12 +73,7 @@ public:
const QPointF &secondPoint);
static VToolPointOfContact* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolPointOfContact* Create(const quint32 _id, QString &radius, quint32 center,
quint32 firstPointId, quint32 secondPointId,
const QString &pointName,
qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc,
VContainer *data, const Document &parse, const Source &typeCreation);
static VToolPointOfContact* Create(VToolPointOfContactInitData &initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::PointOfContact) };
@ -108,9 +119,7 @@ private:
/** @brief secondPointId id second line point. */
quint32 secondPointId;
VToolPointOfContact(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &radius,
const quint32 &center, const quint32 &firstPointId, const quint32 &secondPointId,
const Source &typeCreation, QGraphicsItem * parent = nullptr);
VToolPointOfContact(const VToolPointOfContactInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLPOINTOFCONTACT_H

View File

@ -56,20 +56,16 @@ const QString VToolPointOfIntersection::ToolType = QStringLiteral("pointOfInters
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolPointOfIntersection constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param firstPointId id first line point.
* @param secondPointId id second line point.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolPointOfIntersection::VToolPointOfIntersection(VAbstractPattern *doc, VContainer *data, const quint32 &id,
const quint32 &firstPointId, const quint32 &secondPointId,
const Source &typeCreation, QGraphicsItem *parent)
:VToolSinglePoint(doc, data, id, parent), firstPointId(firstPointId), secondPointId(secondPointId)
VToolPointOfIntersection::VToolPointOfIntersection(const VToolPointOfIntersectionInitData &initData,
QGraphicsItem *parent)
:VToolSinglePoint(initData.doc, initData.data, initData.id, parent),
firstPointId(initData.firstPointId),
secondPointId(initData.secondPointId)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -102,11 +98,18 @@ VToolPointOfIntersection *VToolPointOfIntersection::Create(QSharedPointer<Dialog
SCASSERT(not dialog.isNull())
QSharedPointer<DialogPointOfIntersection> dialogTool = dialog.objectCast<DialogPointOfIntersection>();
SCASSERT(not dialogTool.isNull())
const quint32 firstPointId = dialogTool->GetFirstPointId();
const quint32 secondPointId = dialogTool->GetSecondPointId();
const QString pointName = dialogTool->getPointName();
VToolPointOfIntersection *point = Create(0, pointName, firstPointId, secondPointId, 5, 10, true, scene, doc,
data, Document::FullParse, Source::FromGui);
VToolPointOfIntersectionInitData initData;
initData.firstPointId = dialogTool->GetFirstPointId();
initData.secondPointId = dialogTool->GetSecondPointId();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolPointOfIntersection *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -117,57 +120,41 @@ VToolPointOfIntersection *VToolPointOfIntersection::Create(QSharedPointer<Dialog
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param pointName point name.
* @param firstPointId id first line point.
* @param secondPointId id second line point.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
* @return the created tool
*/
VToolPointOfIntersection *VToolPointOfIntersection::Create(const quint32 _id, const QString &pointName,
quint32 firstPointId, quint32 secondPointId, qreal mx,
qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolPointOfIntersection *VToolPointOfIntersection::Create(VToolPointOfIntersectionInitData initData)
{
const QSharedPointer<VPointF> firstPoint = data->GeometricObject<VPointF>(firstPointId);
const QSharedPointer<VPointF> secondPoint = data->GeometricObject<VPointF>(secondPointId);
const QSharedPointer<VPointF> firstPoint = initData.data->GeometricObject<VPointF>(initData.firstPointId);
const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.secondPointId);
QPointF point(firstPoint->x(), secondPoint->y());
quint32 id = _id;
VPointF *p = new VPointF(point, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
initData.id = initData.data->AddGObject(p);
}
else
{
data->UpdateGObject(id, p);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::PointOfIntersection, doc);
VToolPointOfIntersection *point = new VToolPointOfIntersection(doc, data, id, firstPointId,
secondPointId, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(firstPoint->getIdTool());
doc->IncrementReferens(secondPoint->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::PointOfIntersection, initData.doc);
VToolPointOfIntersection *point = new VToolPointOfIntersection(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(firstPoint->getIdTool());
initData.doc->IncrementReferens(secondPoint->getIdTool());
return point;
}
return nullptr;

View File

@ -43,6 +43,18 @@
template <class T> class QSharedPointer;
struct VToolPointOfIntersectionInitData : public VToolSinglePointInitData
{
VToolPointOfIntersectionInitData()
: VToolSinglePointInitData(),
firstPointId(NULL_ID),
secondPointId(NULL_ID)
{}
quint32 firstPointId;
quint32 secondPointId;
};
/**
* @brief The VToolPointOfIntersection class tool for creation point intersection two lines.
*/
@ -53,10 +65,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolPointOfIntersection *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolPointOfIntersection *Create(const quint32 _id, const QString &pointName, quint32 firstPointId,
quint32 secondPointId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static VToolPointOfIntersection *Create(VToolPointOfIntersectionInitData initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::PointOfIntersection) };
@ -88,9 +97,7 @@ private:
/** @brief secondPointId id second line point. */
quint32 secondPointId;
VToolPointOfIntersection(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &firstPointId,
const quint32 &secondPointId, const Source &typeCreation,
QGraphicsItem * parent = nullptr);
VToolPointOfIntersection(const VToolPointOfIntersectionInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLPOINTOFINTERSECTION_H

View File

@ -55,13 +55,14 @@ template <class T> class QSharedPointer;
const QString VToolPointOfIntersectionArcs::ToolType = QStringLiteral("pointOfIntersectionArcs");
//---------------------------------------------------------------------------------------------------------------------
VToolPointOfIntersectionArcs::VToolPointOfIntersectionArcs(VAbstractPattern *doc, VContainer *data, const quint32 &id,
const quint32 &firstArcId, const quint32 &secondArcId,
CrossCirclesPoint pType, const Source &typeCreation,
VToolPointOfIntersectionArcs::VToolPointOfIntersectionArcs(const VToolPointOfIntersectionArcsInitData &initData,
QGraphicsItem *parent)
:VToolSinglePoint(doc, data, id, parent), firstArcId(firstArcId), secondArcId(secondArcId), crossPoint(pType)
:VToolSinglePoint(initData.doc, initData.data, initData.id, parent),
firstArcId(initData.firstArcId),
secondArcId(initData.secondArcId),
crossPoint(initData.pType)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -85,12 +86,19 @@ VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(QSharedPointe
SCASSERT(not dialog.isNull())
QSharedPointer<DialogPointOfIntersectionArcs> dialogTool = dialog.objectCast<DialogPointOfIntersectionArcs>();
SCASSERT(not dialogTool.isNull())
const quint32 firstArcId = dialogTool->GetFirstArcId();
const quint32 secondArcId = dialogTool->GetSecondArcId();
const CrossCirclesPoint pType = dialogTool->GetCrossArcPoint();
const QString pointName = dialogTool->getPointName();
VToolPointOfIntersectionArcs *point = Create(0, pointName, firstArcId, secondArcId, pType, 5, 10, true, scene, doc,
data, Document::FullParse, Source::FromGui);
VToolPointOfIntersectionArcsInitData initData;
initData.firstArcId = dialogTool->GetFirstArcId();
initData.secondArcId = dialogTool->GetSecondArcId();
initData.pType = dialogTool->GetCrossArcPoint();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolPointOfIntersectionArcs *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -99,45 +107,38 @@ VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(QSharedPointe
}
//---------------------------------------------------------------------------------------------------------------------
VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(const quint32 _id, const QString &pointName,
quint32 firstArcId, quint32 secondArcId,
CrossCirclesPoint pType, qreal mx, qreal my,
bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation)
VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(VToolPointOfIntersectionArcsInitData initData)
{
const QSharedPointer<VArc> firstArc = data->GeometricObject<VArc>(firstArcId);
const QSharedPointer<VArc> secondArc = data->GeometricObject<VArc>(secondArcId);
const QSharedPointer<VArc> firstArc = initData.data->GeometricObject<VArc>(initData.firstArcId);
const QSharedPointer<VArc> secondArc = initData.data->GeometricObject<VArc>(initData.secondArcId);
const QPointF point = FindPoint(firstArc.data(), secondArc.data(), pType);
quint32 id = _id;
const QPointF point = FindPoint(firstArc.data(), secondArc.data(), initData.pType);
VPointF *p = new VPointF(point, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
initData.id = initData.data->AddGObject(p);
}
else
{
data->UpdateGObject(id, p);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::PointOfIntersectionArcs, doc);
VToolPointOfIntersectionArcs *point = new VToolPointOfIntersectionArcs(doc, data, id, firstArcId,
secondArcId, pType, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(firstArc->getIdTool());
doc->IncrementReferens(secondArc->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::PointOfIntersectionArcs, initData.doc);
VToolPointOfIntersectionArcs *point = new VToolPointOfIntersectionArcs(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(firstArc->getIdTool());
initData.doc->IncrementReferens(secondArc->getIdTool());
return point;
}
return nullptr;

View File

@ -44,6 +44,20 @@
template <class T> class QSharedPointer;
struct VToolPointOfIntersectionArcsInitData : public VToolSinglePointInitData
{
VToolPointOfIntersectionArcsInitData()
: VToolSinglePointInitData(),
firstArcId(NULL_ID),
secondArcId(NULL_ID),
pType(CrossCirclesPoint::FirstPoint)
{}
quint32 firstArcId;
quint32 secondArcId;
CrossCirclesPoint pType;
};
class VToolPointOfIntersectionArcs : public VToolSinglePoint
{
Q_OBJECT
@ -52,11 +66,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolPointOfIntersectionArcs *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolPointOfIntersectionArcs *Create(const quint32 _id, const QString &pointName, quint32 firstArcId,
quint32 secondArcId, CrossCirclesPoint pType,
qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static VToolPointOfIntersectionArcs *Create(VToolPointOfIntersectionArcsInitData initData);
static QPointF FindPoint(const VArc *arc1, const VArc *arc2, const CrossCirclesPoint pType);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
@ -94,8 +104,7 @@ private:
CrossCirclesPoint crossPoint;
VToolPointOfIntersectionArcs(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &firstArcId,
const quint32 &secondArcId, CrossCirclesPoint pType, const Source &typeCreation,
VToolPointOfIntersectionArcs(const VToolPointOfIntersectionArcsInitData &initData,
QGraphicsItem * parent = nullptr);
};

View File

@ -56,19 +56,16 @@ template <class T> class QSharedPointer;
const QString VToolPointOfIntersectionCircles::ToolType = QStringLiteral("pointOfIntersectionCircles");
//---------------------------------------------------------------------------------------------------------------------
VToolPointOfIntersectionCircles::VToolPointOfIntersectionCircles(VAbstractPattern *doc, VContainer *data,
const quint32 &id,
quint32 firstCircleCenterId,
quint32 secondCircleCenterId,
const QString &firstCircleRadius,
const QString &secondCircleRadius,
CrossCirclesPoint crossPoint,
const Source &typeCreation, QGraphicsItem *parent)
:VToolSinglePoint(doc, data, id, parent), firstCircleCenterId(firstCircleCenterId),
secondCircleCenterId(secondCircleCenterId), firstCircleRadius(firstCircleRadius),
secondCircleRadius(secondCircleRadius), crossPoint(crossPoint)
VToolPointOfIntersectionCircles::VToolPointOfIntersectionCircles(
const VToolPointOfIntersectionCirclesInitData &initData, QGraphicsItem *parent)
:VToolSinglePoint(initData.doc, initData.data, initData.id, parent),
firstCircleCenterId(initData.firstCircleCenterId),
secondCircleCenterId(initData.secondCircleCenterId),
firstCircleRadius(initData.firstCircleRadius),
secondCircleRadius(initData.secondCircleRadius),
crossPoint(initData.crossPoint)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -93,18 +90,23 @@ VToolPointOfIntersectionCircles *VToolPointOfIntersectionCircles::Create(QShared
VAbstractPattern *doc, VContainer *data)
{
SCASSERT(not dialog.isNull())
QSharedPointer<DialogPointOfIntersectionCircles> dialogTool =
dialog.objectCast<DialogPointOfIntersectionCircles>();
QSharedPointer<DialogPointOfIntersectionCircles> dialogTool = dialog.objectCast<DialogPointOfIntersectionCircles>();
SCASSERT(not dialogTool.isNull())
const quint32 firstCircleCenterId = dialogTool->GetFirstCircleCenterId();
const quint32 secondCircleCenterId = dialogTool->GetSecondCircleCenterId();
QString firstCircleRadius = dialogTool->GetFirstCircleRadius();
QString secondCircleRadius = dialogTool->GetSecondCircleRadius();
const CrossCirclesPoint pType = dialogTool->GetCrossCirclesPoint();
const QString pointName = dialogTool->getPointName();
VToolPointOfIntersectionCircles *point = Create(0, pointName, firstCircleCenterId, secondCircleCenterId,
firstCircleRadius, secondCircleRadius, pType, 5, 10, true, scene,
doc, data, Document::FullParse, Source::FromGui);
VToolPointOfIntersectionCirclesInitData initData;
initData.firstCircleCenterId = dialogTool->GetFirstCircleCenterId();
initData.secondCircleCenterId = dialogTool->GetSecondCircleCenterId();
initData.firstCircleRadius = dialogTool->GetFirstCircleRadius();
initData.secondCircleRadius = dialogTool->GetSecondCircleRadius();
initData.crossPoint = dialogTool->GetCrossCirclesPoint();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolPointOfIntersectionCircles *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -113,57 +115,43 @@ VToolPointOfIntersectionCircles *VToolPointOfIntersectionCircles::Create(QShared
}
//---------------------------------------------------------------------------------------------------------------------
VToolPointOfIntersectionCircles *VToolPointOfIntersectionCircles::Create(const quint32 _id, const QString &pointName,
quint32 firstCircleCenterId,
quint32 secondCircleCenterId,
QString &firstCircleRadius,
QString &secondCircleRadius,
CrossCirclesPoint crossPoint, qreal mx,
qreal my, bool showLabel,
VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data,
const Document &parse,
const Source &typeCreation)
VToolPointOfIntersectionCircles *
VToolPointOfIntersectionCircles::Create(VToolPointOfIntersectionCirclesInitData &initData)
{
const qreal calcC1Radius = qApp->toPixel(CheckFormula(_id, firstCircleRadius, data));
const qreal calcC2Radius = qApp->toPixel(CheckFormula(_id, secondCircleRadius, data));
const qreal calcC1Radius = qApp->toPixel(CheckFormula(initData.id, initData.firstCircleRadius, initData.data));
const qreal calcC2Radius = qApp->toPixel(CheckFormula(initData.id, initData.secondCircleRadius, initData.data));
const VPointF c1Point = *data->GeometricObject<VPointF>(firstCircleCenterId);
const VPointF c2Point = *data->GeometricObject<VPointF>(secondCircleCenterId);
const VPointF c1Point = *initData.data->GeometricObject<VPointF>(initData.firstCircleCenterId);
const VPointF c2Point = *initData.data->GeometricObject<VPointF>(initData.secondCircleCenterId);
const QPointF point = FindPoint(static_cast<QPointF>(c1Point), static_cast<QPointF>(c2Point), calcC1Radius,
calcC2Radius, crossPoint);
quint32 id = _id;
calcC2Radius, initData.crossPoint);
VPointF *p = new VPointF(point, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
initData.id = initData.data->AddGObject(p);
}
else
{
data->UpdateGObject(id, p);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::PointOfIntersectionCircles, doc);
VToolPointOfIntersectionCircles *point = new VToolPointOfIntersectionCircles(doc, data, id, firstCircleCenterId,
secondCircleCenterId,
firstCircleRadius,
secondCircleRadius, crossPoint,
typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(c1Point.getIdTool());
doc->IncrementReferens(c2Point.getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::PointOfIntersectionCircles, initData.doc);
VToolPointOfIntersectionCircles *point = new VToolPointOfIntersectionCircles(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(c1Point.getIdTool());
initData.doc->IncrementReferens(c2Point.getIdTool());
return point;
}
return nullptr;

View File

@ -45,6 +45,24 @@
class VFormula;
template <class T> class QSharedPointer;
struct VToolPointOfIntersectionCirclesInitData : public VToolSinglePointInitData
{
VToolPointOfIntersectionCirclesInitData()
: VToolSinglePointInitData(),
firstCircleCenterId(NULL_ID),
secondCircleCenterId(NULL_ID),
firstCircleRadius("0"),
secondCircleRadius("0"),
crossPoint(CrossCirclesPoint::FirstPoint)
{}
quint32 firstCircleCenterId;
quint32 secondCircleCenterId;
QString firstCircleRadius;
QString secondCircleRadius;
CrossCirclesPoint crossPoint;
};
class VToolPointOfIntersectionCircles : public VToolSinglePoint
{
Q_OBJECT
@ -52,13 +70,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolPointOfIntersectionCircles *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolPointOfIntersectionCircles *Create(const quint32 _id, const QString &pointName,
quint32 firstCircleCenterId, quint32 secondCircleCenterId,
QString &firstCircleRadius, QString &secondCircleRadius,
CrossCirclesPoint crossPoint,
qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static VToolPointOfIntersectionCircles *Create(VToolPointOfIntersectionCirclesInitData &initData);
static QPointF FindPoint(const QPointF &c1Point, const QPointF &c2Point, qreal c1Radius, qreal c2Radius,
const CrossCirclesPoint crossPoint);
static const QString ToolType;
@ -103,10 +115,7 @@ private:
CrossCirclesPoint crossPoint;
VToolPointOfIntersectionCircles(VAbstractPattern *doc, VContainer *data, const quint32 &id, const
quint32 firstCircleCenterId, quint32 secondCircleCenterId,
const QString &firstCircleRadius, const QString &secondCircleRadius,
CrossCirclesPoint crossPoint, const Source &typeCreation,
VToolPointOfIntersectionCircles(const VToolPointOfIntersectionCirclesInitData &initData,
QGraphicsItem * parent = nullptr);
};

View File

@ -55,18 +55,15 @@ template <class T> class QSharedPointer;
const QString VToolPointOfIntersectionCurves::ToolType = QStringLiteral("pointOfIntersectionCurves");
//---------------------------------------------------------------------------------------------------------------------
VToolPointOfIntersectionCurves::VToolPointOfIntersectionCurves(VAbstractPattern *doc, VContainer *data,
const quint32 &id, const quint32 firstCurveId,
quint32 secondCurveId, VCrossCurvesPoint vCrossPoint,
HCrossCurvesPoint hCrossPoint, const Source &typeCreation,
VToolPointOfIntersectionCurves::VToolPointOfIntersectionCurves(const VToolPointOfIntersectionCurvesInitData &initData,
QGraphicsItem *parent)
:VToolSinglePoint(doc, data, id, parent),
firstCurveId(firstCurveId),
secondCurveId(secondCurveId),
vCrossPoint(vCrossPoint),
hCrossPoint(hCrossPoint)
:VToolSinglePoint(initData.doc, initData.data, initData.id, parent),
firstCurveId(initData.firstCurveId),
secondCurveId(initData.secondCurveId),
vCrossPoint(initData.vCrossPoint),
hCrossPoint(initData.hCrossPoint)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -91,13 +88,20 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(QSharedPo
SCASSERT(not dialog.isNull())
QSharedPointer<DialogPointOfIntersectionCurves> dialogTool = dialog.objectCast<DialogPointOfIntersectionCurves>();
SCASSERT(not dialogTool.isNull())
const quint32 firstCurveId = dialogTool->GetFirstCurveId();
const quint32 secondCurveId = dialogTool->GetSecondCurveId();
const VCrossCurvesPoint vCrossPoint = dialogTool->GetVCrossPoint();
const HCrossCurvesPoint hCrossPoint = dialogTool->GetHCrossPoint();
const QString pointName = dialogTool->getPointName();
VToolPointOfIntersectionCurves *point = Create(0, pointName, firstCurveId, secondCurveId, vCrossPoint, hCrossPoint,
5, 10, true, scene, doc, data, Document::FullParse, Source::FromGui);
VToolPointOfIntersectionCurvesInitData initData;
initData.firstCurveId = dialogTool->GetFirstCurveId();
initData.secondCurveId = dialogTool->GetSecondCurveId();
initData.vCrossPoint = dialogTool->GetVCrossPoint();
initData.hCrossPoint = dialogTool->GetHCrossPoint();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolPointOfIntersectionCurves *point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -106,49 +110,39 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(QSharedPo
}
//---------------------------------------------------------------------------------------------------------------------
VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(const quint32 _id, const QString &pointName,
quint32 firstCurveId, quint32 secondCurveId,
VCrossCurvesPoint vCrossPoint,
HCrossCurvesPoint hCrossPoint,qreal mx,
qreal my, bool showLabel,
VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data,
const Document &parse,
const Source &typeCreation)
VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(VToolPointOfIntersectionCurvesInitData initData)
{
auto curve1 = data->GeometricObject<VAbstractCurve>(firstCurveId);
auto curve2 = data->GeometricObject<VAbstractCurve>(secondCurveId);
auto curve1 = initData.data->GeometricObject<VAbstractCurve>(initData.firstCurveId);
auto curve2 = initData.data->GeometricObject<VAbstractCurve>(initData.secondCurveId);
const QPointF point = VToolPointOfIntersectionCurves::FindPoint(curve1->GetPoints(), curve2->GetPoints(),
vCrossPoint, hCrossPoint);
quint32 id = _id;
initData.vCrossPoint, initData.hCrossPoint);
VPointF *p = new VPointF(point, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
initData.id = initData.data->AddGObject(p);
}
else
{
data->UpdateGObject(id, p);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::PointOfIntersectionCurves, doc);
auto point = new VToolPointOfIntersectionCurves(doc, data, id, firstCurveId, secondCurveId, vCrossPoint,
hCrossPoint, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(curve1->getIdTool());
doc->IncrementReferens(curve2->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::PointOfIntersectionCurves, initData.doc);
auto point = new VToolPointOfIntersectionCurves(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(curve1->getIdTool());
initData.doc->IncrementReferens(curve2->getIdTool());
return point;
}
return nullptr;

View File

@ -45,6 +45,22 @@
template <class T> class QSharedPointer;
struct VToolPointOfIntersectionCurvesInitData : public VToolSinglePointInitData
{
VToolPointOfIntersectionCurvesInitData()
: VToolSinglePointInitData(),
firstCurveId(NULL_ID),
secondCurveId(NULL_ID),
vCrossPoint(VCrossCurvesPoint::HighestPoint),
hCrossPoint(HCrossCurvesPoint::LeftmostPoint)
{}
quint32 firstCurveId;
quint32 secondCurveId;
VCrossCurvesPoint vCrossPoint;
HCrossCurvesPoint hCrossPoint;
};
class VToolPointOfIntersectionCurves : public VToolSinglePoint
{
Q_OBJECT
@ -52,12 +68,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolPointOfIntersectionCurves *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolPointOfIntersectionCurves *Create(const quint32 _id, const QString &pointName,
quint32 firstCurveId, quint32 secondCurveId,
VCrossCurvesPoint vCrossPoint, HCrossCurvesPoint hCrossPoint,
qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static VToolPointOfIntersectionCurves *Create(VToolPointOfIntersectionCurvesInitData initData);
static QPointF FindPoint(const QVector<QPointF> &curve1Points, const QVector<QPointF> &curve2Points,
VCrossCurvesPoint vCrossPoint, HCrossCurvesPoint hCrossPoint);
static const QString ToolType;
@ -97,10 +108,8 @@ private:
VCrossCurvesPoint vCrossPoint;
HCrossCurvesPoint hCrossPoint;
explicit VToolPointOfIntersectionCurves(VAbstractPattern *doc, VContainer *data, const quint32 &id, const
quint32 firstCurveId, quint32 secondCurveId,
VCrossCurvesPoint vCrossPoint, HCrossCurvesPoint hCrossPoint,
const Source &typeCreation, QGraphicsItem * parent = nullptr);
explicit VToolPointOfIntersectionCurves(const VToolPointOfIntersectionCurvesInitData &initData,
QGraphicsItem *parent = nullptr);
};
#endif // VTOOLPOINTOFINTERSECTIONCURVES_H

View File

@ -44,6 +44,22 @@
template <class T> class QSharedPointer;
struct VToolSinglePointInitData : public VAbstractToolInitData
{
VToolSinglePointInitData()
: VAbstractToolInitData(),
name(),
mx(5),
my(10),
showLabel(true)
{}
QString name;
qreal mx;
qreal my;
bool showLabel;
};
/**
* @brief The VToolSinglePoint class parent for all tools what create points.
*/

View File

@ -58,23 +58,17 @@ const QString VToolTriangle::ToolType = QStringLiteral("triangle");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolTriangle constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param axisP1Id id first axis point.
* @param axisP2Id id second axis point.
* @param firstPointId id first triangle point, what lies on the hypotenuse.
* @param secondPointId id second triangle point, what lies on the hypotenuse.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolTriangle::VToolTriangle(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &axisP1Id,
const quint32 &axisP2Id, const quint32 &firstPointId, const quint32 &secondPointId,
const Source &typeCreation, QGraphicsItem *parent)
:VToolSinglePoint(doc, data, id, parent), axisP1Id(axisP1Id), axisP2Id(axisP2Id), firstPointId(firstPointId),
secondPointId(secondPointId)
VToolTriangle::VToolTriangle(const VToolTriangleInitData &initData, QGraphicsItem *parent)
:VToolSinglePoint(initData.doc, initData.data, initData.id, parent),
axisP1Id(initData.axisP1Id),
axisP2Id(initData.axisP2Id),
firstPointId(initData.firstPointId),
secondPointId(initData.secondPointId)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -109,13 +103,20 @@ VToolTriangle* VToolTriangle::Create(QSharedPointer<DialogTool> dialog, VMainGra
SCASSERT(not dialog.isNull())
QSharedPointer<DialogTriangle> dialogTool = dialog.objectCast<DialogTriangle>();
SCASSERT(not dialogTool.isNull())
const quint32 axisP1Id = dialogTool->GetAxisP1Id();
const quint32 axisP2Id = dialogTool->GetAxisP2Id();
const quint32 firstPointId = dialogTool->GetFirstPointId();
const quint32 secondPointId = dialogTool->GetSecondPointId();
const QString pointName = dialogTool->getPointName();
VToolTriangle* point = Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, true,
scene, doc, data, Document::FullParse, Source::FromGui);
VToolTriangleInitData initData;
initData.axisP1Id = dialogTool->GetAxisP1Id();
initData.axisP2Id = dialogTool->GetAxisP2Id();
initData.firstPointId = dialogTool->GetFirstPointId();
initData.secondPointId = dialogTool->GetSecondPointId();
initData.name = dialogTool->getPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolTriangle* point = Create(initData);
if (point != nullptr)
{
point->m_dialog = dialogTool;
@ -126,63 +127,46 @@ VToolTriangle* VToolTriangle::Create(QSharedPointer<DialogTool> dialog, VMainGra
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param pointName point name.
* @param axisP1Id id first axis point.
* @param axisP2Id id second axis point.
* @param firstPointId id first triangle point, what lies on the hypotenuse.
* @param secondPointId id second triangle point, what lies on the hypotenuse.
* @param mx label bias x axis.
* @param my label bias y axis.
* @param scene pointer to scene.
* @param doc dom document container.
* @param data container with variables.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param initData init data.
* @return the created tool
*/
VToolTriangle* VToolTriangle::Create(const quint32 _id, const QString &pointName, quint32 axisP1Id, quint32 axisP2Id,
quint32 firstPointId, quint32 secondPointId, qreal mx, qreal my, bool showLabel,
VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data, const Document &parse, const Source &typeCreation)
VToolTriangle* VToolTriangle::Create(VToolTriangleInitData initData)
{
const QSharedPointer<VPointF> axisP1 = data->GeometricObject<VPointF>(axisP1Id);
const QSharedPointer<VPointF> axisP2 = data->GeometricObject<VPointF>(axisP2Id);
const QSharedPointer<VPointF> firstPoint = data->GeometricObject<VPointF>(firstPointId);
const QSharedPointer<VPointF> secondPoint = data->GeometricObject<VPointF>(secondPointId);
const QSharedPointer<VPointF> axisP1 = initData.data->GeometricObject<VPointF>(initData.axisP1Id);
const QSharedPointer<VPointF> axisP2 = initData.data->GeometricObject<VPointF>(initData.axisP2Id);
const QSharedPointer<VPointF> firstPoint = initData.data->GeometricObject<VPointF>(initData.firstPointId);
const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.secondPointId);
QPointF point = FindPoint(static_cast<QPointF>(*axisP1), static_cast<QPointF>(*axisP2),
static_cast<QPointF>(*firstPoint), static_cast<QPointF>(*secondPoint));
quint32 id = _id;
VPointF *p = new VPointF(point, pointName, mx, my);
p->SetShowLabel(showLabel);
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel);
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddGObject(p);
initData.id = initData.data->AddGObject(p);
}
else
{
data->UpdateGObject(id, p);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, p);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::Triangle, doc);
VToolTriangle *point = new VToolTriangle(doc, data, id, axisP1Id, axisP2Id, firstPointId,
secondPointId, typeCreation);
scene->addItem(point);
InitToolConnections(scene, point);
VAbstractPattern::AddTool(id, point);
doc->IncrementReferens(axisP1->getIdTool());
doc->IncrementReferens(axisP2->getIdTool());
doc->IncrementReferens(firstPoint->getIdTool());
doc->IncrementReferens(secondPoint->getIdTool());
VAbstractTool::AddRecord(initData.id, Tool::Triangle, initData.doc);
VToolTriangle *point = new VToolTriangle(initData);
initData.scene->addItem(point);
InitToolConnections(initData.scene, point);
VAbstractPattern::AddTool(initData.id, point);
initData.doc->IncrementReferens(axisP1->getIdTool());
initData.doc->IncrementReferens(axisP2->getIdTool());
initData.doc->IncrementReferens(firstPoint->getIdTool());
initData.doc->IncrementReferens(secondPoint->getIdTool());
return point;
}
return nullptr;

View File

@ -44,6 +44,22 @@
template <class T> class QSharedPointer;
struct VToolTriangleInitData : public VToolSinglePointInitData
{
VToolTriangleInitData()
: VToolSinglePointInitData(),
axisP1Id(NULL_ID),
axisP2Id(NULL_ID),
firstPointId(NULL_ID),
secondPointId(NULL_ID)
{}
quint32 axisP1Id;
quint32 axisP2Id;
quint32 firstPointId;
quint32 secondPointId;
};
/**
* @brief The VToolTriangle class for tool that find point intersection two foots right triangle
* (triangle with 90 degree).
@ -55,10 +71,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolTriangle *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolTriangle *Create(const quint32 _id, const QString &pointName, quint32 axisP1Id,
quint32 axisP2Id, quint32 firstPointId, quint32 secondPointId,
qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data, const Document &parse, const Source &typeCreation);
static VToolTriangle *Create(VToolTriangleInitData initData);
static QPointF FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint,
const QPointF &secondPoint);
static const QString ToolType;
@ -105,10 +118,7 @@ private:
/** @brief secondPointId id second triangle point, what lies on the hypotenuse. */
quint32 secondPointId;
VToolTriangle(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &axisP1Id,
const quint32 &axisP2Id,
const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation,
QGraphicsItem * parent = nullptr);
VToolTriangle(const VToolTriangleInitData &initData, QGraphicsItem *parent = nullptr);
};
#endif // VTOOLTRIANGLE_H

View File

@ -57,33 +57,25 @@ template <class T> class QSharedPointer;
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolLine constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param firstPoint id first line point.
* @param secondPoint id second line point.
* @param typeLine line type.
* @param typeCreation way we create this tool.
* @param initData init data.
* @param parent parent object.
*/
VToolLine::VToolLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstPoint, quint32 secondPoint,
const QString &typeLine, const QString &lineColor, const Source &typeCreation,
QGraphicsItem *parent)
:VDrawTool(doc, data, id),
VToolLine::VToolLine(const VToolLineInitData &initData, QGraphicsItem *parent)
:VDrawTool(initData.doc, initData.data, initData.id),
QGraphicsLineItem(parent),
firstPoint(firstPoint),
secondPoint(secondPoint),
lineColor(lineColor),
firstPoint(initData.firstPoint),
secondPoint(initData.secondPoint),
lineColor(initData.lineColor),
m_isHovered(false)
{
this->m_lineType = typeLine;
this->m_lineType = initData.typeLine;
//Line
RefreshGeometry();
this->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
this->setAcceptHoverEvents(true);
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
@ -115,13 +107,19 @@ VToolLine *VToolLine::Create(QSharedPointer<DialogTool> dialog, VMainGraphicsSce
SCASSERT(not dialog.isNull())
QSharedPointer<DialogLine> dialogTool = dialog.objectCast<DialogLine>();
SCASSERT(not dialogTool.isNull())
const quint32 firstPoint = dialogTool->GetFirstPoint();
const quint32 secondPoint = dialogTool->GetSecondPoint();
const QString typeLine = dialogTool->GetTypeLine();
const QString lineColor = dialogTool->GetLineColor();
VToolLine *line = Create(0, firstPoint, secondPoint, typeLine, lineColor, scene, doc, data, Document::FullParse,
Source::FromGui);
VToolLineInitData initData;
initData.firstPoint = dialogTool->GetFirstPoint();
initData.secondPoint = dialogTool->GetSecondPoint();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
VToolLine *line = Create(initData);
if (line != nullptr)
{
line->m_dialog = dialogTool;
@ -142,45 +140,41 @@ VToolLine *VToolLine::Create(QSharedPointer<DialogTool> dialog, VMainGraphicsSce
* @param parse parser file mode.
* @param typeCreation way we create this tool.
*/
VToolLine * VToolLine::Create(const quint32 &_id, const quint32 &firstPoint, const quint32 &secondPoint,
const QString &typeLine, const QString &lineColor, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation)
VToolLine * VToolLine::Create(VToolLineInitData initData)
{
SCASSERT(scene != nullptr)
SCASSERT(doc != nullptr)
SCASSERT(data != nullptr)
quint32 id = _id;
if (typeCreation == Source::FromGui)
SCASSERT(initData.scene != nullptr)
SCASSERT(initData.doc != nullptr)
SCASSERT(initData.data != nullptr)
if (initData.typeCreation == Source::FromGui)
{
id = VContainer::getNextId();
data->AddLine(firstPoint, secondPoint);
initData.id = VContainer::getNextId();
initData.data->AddLine(initData.firstPoint, initData.secondPoint);
}
else
{
VContainer::UpdateId(id);
data->AddLine(firstPoint, secondPoint);
if (parse != Document::FullParse)
VContainer::UpdateId(initData.id);
initData.data->AddLine(initData.firstPoint, initData.secondPoint);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::Line, doc);
VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeLine, lineColor, typeCreation);
scene->addItem(line);
InitDrawToolConnections(scene, line);
connect(scene, &VMainGraphicsScene::EnableLineItemSelection, line, &VToolLine::AllowSelecting);
connect(scene, &VMainGraphicsScene::EnableLineItemHover, line, &VToolLine::AllowHover);
VAbstractPattern::AddTool(id, line);
VAbstractTool::AddRecord(initData.id, Tool::Line, initData.doc);
VToolLine *line = new VToolLine(initData);
initData.scene->addItem(line);
InitDrawToolConnections(initData.scene, line);
connect(initData.scene, &VMainGraphicsScene::EnableLineItemSelection, line, &VToolLine::AllowSelecting);
connect(initData.scene, &VMainGraphicsScene::EnableLineItemHover, line, &VToolLine::AllowHover);
VAbstractPattern::AddTool(initData.id, line);
const QSharedPointer<VPointF> first = data->GeometricObject<VPointF>(firstPoint);
const QSharedPointer<VPointF> second = data->GeometricObject<VPointF>(secondPoint);
const QSharedPointer<VPointF> first = initData.data->GeometricObject<VPointF>(initData.firstPoint);
const QSharedPointer<VPointF> second = initData.data->GeometricObject<VPointF>(initData.secondPoint);
doc->IncrementReferens(first->getIdTool());
doc->IncrementReferens(second->getIdTool());
initData.doc->IncrementReferens(first->getIdTool());
initData.doc->IncrementReferens(second->getIdTool());
return line;
}
return nullptr;

View File

@ -45,6 +45,22 @@
template <class T> class QSharedPointer;
struct VToolLineInitData : public VAbstractToolInitData
{
VToolLineInitData()
: VAbstractToolInitData(),
firstPoint(NULL_ID),
secondPoint(NULL_ID),
typeLine(TypeLineLine),
lineColor(ColorBlack)
{}
quint32 firstPoint;
quint32 secondPoint;
QString typeLine;
QString lineColor;
};
/**
* @brief The VToolLine class tool for creation line.
*/
@ -55,10 +71,7 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolLine *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolLine *Create(const quint32 &_id, const quint32 &firstPoint, const quint32 &secondPoint,
const QString &typeLine, const QString &lineColor, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation);
static VToolLine *Create(VToolLineInitData initData);
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::Line)};
@ -118,9 +131,7 @@ private:
bool m_isHovered;
VToolLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstPoint, quint32 secondPoint,
const QString &typeLine, const QString &lineColor, const Source &typeCreation,
QGraphicsItem * parent = nullptr);
VToolLine(const VToolLineInitData &initData, QGraphicsItem *parent = nullptr);
void RefreshGeometry();
};

View File

@ -41,6 +41,20 @@
enum class ParentType : bool {Scene, Item};
struct VAbstractNodeInitData : public VAbstractToolInitData
{
VAbstractNodeInitData()
: VAbstractToolInitData(),
idObject(NULL_ID),
drawName(),
idTool(NULL_ID)
{}
quint32 idObject;
QString drawName;
quint32 idTool;
};
/**
* @brief The VAbstractNode class parent class for all detail node.
*/

View File

@ -44,57 +44,45 @@ const QString VNodeArc::ToolType = QStringLiteral("modeling");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VNodeArc constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param idArc object id in containerArc.
* @param typeCreation way we create this tool.
* @param idTool tool id.
* @param initData init data.
* @param qoParent QObject parent
*/
VNodeArc::VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation,
const QString &drawName, const quint32 &idTool, QObject *qoParent)
:VAbstractNode(doc, data, id, idArc, drawName, idTool, qoParent)
VNodeArc::VNodeArc(const VAbstractNodeInitData &initData, QObject *qoParent)
:VAbstractNode(initData.doc, initData.data, initData.id, initData.idObject, initData.drawName, initData.idTool,
qoParent)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param idArc object id in containerArc.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param idTool tool id.
* @param initData init data.
*/
void VNodeArc::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc,
const Document &parse, const Source &typeCreation, const QString &drawName, const quint32 &idTool)
void VNodeArc::Create(VAbstractNodeInitData initData)
{
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::NodeArc, doc);
VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, drawName, idTool, doc);
VAbstractTool::AddRecord(initData.id, Tool::NodeArc, initData.doc);
VNodeArc *arc = new VNodeArc(initData);
VAbstractPattern::AddTool(id, arc);
if (idTool != NULL_ID)
VAbstractPattern::AddTool(initData.id, arc);
if (initData.idTool != NULL_ID)
{
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = VAbstractPattern::getTool(idTool);
VDataTool *tool = VAbstractPattern::getTool(initData.idTool);
SCASSERT(tool != nullptr)
arc->setParent(tool);// Adopted by a tool
}
else
{
// Help to delete the node before each FullParse
doc->AddToolOnRemove(arc);
initData.doc->AddToolOnRemove(arc);
}
}
else
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}

View File

@ -47,8 +47,7 @@ class VNodeArc :public VAbstractNode
{
Q_OBJECT
public:
static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document &parse,
const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0);
static void Create(VAbstractNodeInitData initData);
static const QString ToolType;
virtual QString getTagName() const Q_DECL_OVERRIDE;
@ -63,8 +62,7 @@ protected:
private:
Q_DISABLE_COPY(VNodeArc)
VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation,
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr);
VNodeArc(const VAbstractNodeInitData &initData, QObject *qoParent = nullptr);
};
#endif // VNODEARC_H4

View File

@ -42,32 +42,30 @@
const QString VNodeEllipticalArc::ToolType = QStringLiteral("modeling");
//---------------------------------------------------------------------------------------------------------------------
void VNodeEllipticalArc::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc,
const Document &parse, const Source &typeCreation, const QString &drawName,
const quint32 &idTool)
void VNodeEllipticalArc::Create(VAbstractNodeInitData initData)
{
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::NodeElArc, doc);
VNodeEllipticalArc *arc = new VNodeEllipticalArc(doc, data, id, idArc, typeCreation, drawName, idTool, doc);
VAbstractTool::AddRecord(initData.id, Tool::NodeElArc, initData.doc);
VNodeEllipticalArc *arc = new VNodeEllipticalArc(initData);
VAbstractPattern::AddTool(id, arc);
if (idTool != NULL_ID)
VAbstractPattern::AddTool(initData.id, arc);
if (initData.idTool != NULL_ID)
{
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = VAbstractPattern::getTool(idTool);
VDataTool *tool = VAbstractPattern::getTool(initData.idTool);
SCASSERT(tool != nullptr)
arc->setParent(tool);// Adopted by a tool
}
else
{
// Help to delete the node before each FullParse
doc->AddToolOnRemove(arc);
initData.doc->AddToolOnRemove(arc);
}
}
else
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
@ -108,10 +106,9 @@ void VNodeEllipticalArc::AddToFile()
}
//---------------------------------------------------------------------------------------------------------------------
VNodeEllipticalArc::VNodeEllipticalArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc,
const Source &typeCreation, const QString &drawName, const quint32 &idTool,
QObject *qoParent)
:VAbstractNode(doc, data, id, idArc, drawName, idTool, qoParent)
VNodeEllipticalArc::VNodeEllipticalArc(const VAbstractNodeInitData &initData, QObject *qoParent)
:VAbstractNode(initData.doc, initData.data, initData.id, initData.idObject, initData.drawName, initData.idTool,
qoParent)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}

View File

@ -44,9 +44,7 @@ class VNodeEllipticalArc :public VAbstractNode
{
Q_OBJECT
public:
static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document &parse,
const Source &typeCreation, const QString &drawName = QString(),
const quint32 &idTool = NULL_ID);
static void Create(VAbstractNodeInitData initData);
static const QString ToolType;
virtual QString getTagName() const Q_DECL_OVERRIDE;
@ -61,8 +59,7 @@ protected:
private:
Q_DISABLE_COPY(VNodeEllipticalArc)
VNodeEllipticalArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation,
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr);
VNodeEllipticalArc(const VAbstractNodeInitData &initData, QObject *qoParent = nullptr);
};
#endif // VNODEELLIPTICALARC_H

View File

@ -60,18 +60,12 @@ const QString VNodePoint::ToolType = QStringLiteral("modeling");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VNodePoint constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param idPoint object id in containerPoint.
* @param typeCreation way we create this tool.
* @param idTool tool id.
* @param qoParent QObject parent
* @param initData init data.
* @param parent parent object.
*/
VNodePoint::VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idPoint, const Source &typeCreation,
const QString &drawName, const quint32 &idTool, QObject *qoParent, QGraphicsItem *parent)
: VAbstractNode(doc, data, id, idPoint, drawName, idTool, qoParent),
VNodePoint::VNodePoint(const VAbstractNodeInitData &initData, QObject *qoParent, QGraphicsItem *parent)
: VAbstractNode(initData.doc, initData.data, initData.id, initData.idObject, initData.drawName, initData.idTool,
qoParent),
VScenePoint(parent)
{
connect(m_namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VNodePoint::PointChoosed);
@ -81,56 +75,48 @@ VNodePoint::VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quin
{
emit ShowContextMenu(event);
});
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<VPointF>(id));
ToolCreation(typeCreation);
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<VPointF>(initData.id));
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param idPoint object id in containerPoint.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param idTool tool id.
* @param initData init data.
*/
void VNodePoint::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene,
quint32 id, quint32 idPoint, const Document &parse,
const Source &typeCreation, const QString &drawName, const quint32 &idTool)
void VNodePoint::Create(VAbstractNodeInitData initData)
{
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::NodePoint, doc);
VAbstractTool::AddRecord(initData.id, Tool::NodePoint, initData.doc);
//TODO Need create garbage collector and remove all nodes, what we don't use.
//Better check garbage before each saving file. Check only modeling tags.
VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, drawName, idTool, doc);
VNodePoint *point = new VNodePoint(initData);
connect(scene, &VMainGraphicsScene::EnableToolMove, point, &VNodePoint::EnableToolMove);
connect(scene, &VMainGraphicsScene::EnablePointItemHover, point, &VNodePoint::AllowHover);
connect(scene, &VMainGraphicsScene::EnablePointItemSelection, point, &VNodePoint::AllowSelecting);
connect(scene, &VMainGraphicsScene::EnableLabelItemHover, point, &VNodePoint::AllowLabelHover);
connect(scene, &VMainGraphicsScene::EnableLabelItemSelection, point, &VNodePoint::AllowLabelSelecting);
VAbstractPattern::AddTool(id, point);
if (idTool != NULL_ID)
connect(initData.scene, &VMainGraphicsScene::EnableToolMove, point, &VNodePoint::EnableToolMove);
connect(initData.scene, &VMainGraphicsScene::EnablePointItemHover, point, &VNodePoint::AllowHover);
connect(initData.scene, &VMainGraphicsScene::EnablePointItemSelection, point, &VNodePoint::AllowSelecting);
connect(initData.scene, &VMainGraphicsScene::EnableLabelItemHover, point, &VNodePoint::AllowLabelHover);
connect(initData.scene, &VMainGraphicsScene::EnableLabelItemSelection, point, &VNodePoint::AllowLabelSelecting);
VAbstractPattern::AddTool(initData.id, point);
if (initData.idTool != NULL_ID)
{
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = VAbstractPattern::getTool(idTool);
VDataTool *tool = VAbstractPattern::getTool(initData.idTool);
SCASSERT(tool != nullptr)
point->setParent(tool);// Adopted by a tool
}
else
{
// Try to prevent memory leak
scene->addItem(point);// First adopted by scene
initData.scene->addItem(point);// First adopted by scene
point->hide();// If no one will use node, it will stay hidden
point->SetParentType(ParentType::Scene);
}
}
else
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}

View File

@ -50,9 +50,7 @@ class VNodePoint: public VAbstractNode, public VScenePoint
{
Q_OBJECT
public:
static void Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene,
quint32 id, quint32 idPoint, const Document &parse,
const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0);
static void Create(VAbstractNodeInitData initData);
static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
@ -86,9 +84,7 @@ protected:
private:
Q_DISABLE_COPY(VNodePoint)
VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idPoint, const Source &typeCreation,
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr,
QGraphicsItem * parent = nullptr );
VNodePoint(const VAbstractNodeInitData &initData, QObject *qoParent = nullptr, QGraphicsItem *parent = nullptr);
};
#endif // VNODEPOINT_H

View File

@ -44,60 +44,47 @@ const QString VNodeSpline::ToolType = QStringLiteral("modelingSpline");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VNodeSpline constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param idSpline object id in containerSpline.
* @param typeCreation way we create this tool.
* @param idTool id node.
* @param initData init data.
* @param qoParent QObject parent.
*/
VNodeSpline::VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline,
const Source &typeCreation, const QString &drawName, const quint32 &idTool, QObject *qoParent)
:VAbstractNode(doc, data, id, idSpline, drawName, idTool, qoParent)
VNodeSpline::VNodeSpline(const VAbstractNodeInitData &initData, QObject *qoParent)
:VAbstractNode(initData.doc, initData.data, initData.id, initData.idObject, initData.drawName, initData.idTool,
qoParent)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param idSpline object id in containerSpline.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param idTool id node.
* @param initData init data.
* @return pointer to node.
*/
VNodeSpline *VNodeSpline::Create(VAbstractPattern *doc, VContainer *data, quint32 id,
quint32 idSpline, const Document &parse,
const Source &typeCreation, const QString &drawName, const quint32 &idTool)
VNodeSpline *VNodeSpline::Create(VAbstractNodeInitData initData)
{
VNodeSpline *spl = nullptr;
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::NodeSpline, doc);
spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, drawName, idTool, doc);
VAbstractTool::AddRecord(initData.id, Tool::NodeSpline, initData.doc);
spl = new VNodeSpline(initData);
VAbstractPattern::AddTool(id, spl);
if (idTool != NULL_ID)
VAbstractPattern::AddTool(initData.id, spl);
if (initData.idTool != NULL_ID)
{
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = VAbstractPattern::getTool(idTool);
VDataTool *tool = VAbstractPattern::getTool(initData.idTool);
SCASSERT(tool != nullptr)
spl->setParent(tool);// Adopted by a tool
}
else
{
// Help to delete the node before each FullParse
doc->AddToolOnRemove(spl);
initData.doc->AddToolOnRemove(spl);
}
}
else
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
return spl;
}

View File

@ -47,10 +47,7 @@ class VNodeSpline:public VAbstractNode
{
Q_OBJECT
public:
static VNodeSpline *Create(VAbstractPattern *doc, VContainer *data, quint32 id,
quint32 idSpline, const Document &parse,
const Source &typeCreation, const QString &drawName = QString(),
const quint32 &idTool = 0);
static VNodeSpline *Create(VAbstractNodeInitData initData);
static const QString ToolType;
virtual QString getTagName() const Q_DECL_OVERRIDE;
@ -65,8 +62,7 @@ protected:
private:
Q_DISABLE_COPY(VNodeSpline)
VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation,
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr);
VNodeSpline(const VAbstractNodeInitData &initData, QObject *qoParent = nullptr);
};
#endif // VNODESPLINE_H

View File

@ -44,59 +44,45 @@ const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VNodeSplinePath constructor.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param idSpline object id in containerSpline.
* @param typeCreation way we create this tool.
* @param idTool tool id.
* @param initData init data.
* @param qoParent QObject parent.
*/
VNodeSplinePath::VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline,
const Source &typeCreation, const QString &drawName, const quint32 &idTool,
QObject *qoParent)
:VAbstractNode(doc, data, id, idSpline, drawName, idTool, qoParent)
VNodeSplinePath::VNodeSplinePath(const VAbstractNodeInitData &initData, QObject *qoParent)
:VAbstractNode(initData.doc, initData.data, initData.id, initData.idObject, initData.drawName, initData.idTool,
qoParent)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param doc dom document container.
* @param data container with variables.
* @param id object id in container.
* @param idSpline object id in containerSpline.
* @param parse parser file mode.
* @param typeCreation way we create this tool.
* @param idTool tool id.
* @param initData init data.
*/
void VNodeSplinePath::Create(VAbstractPattern *doc, VContainer *data, quint32 id,
quint32 idSpline, const Document &parse, const Source &typeCreation,
const QString &drawName, const quint32 &idTool)
void VNodeSplinePath::Create(VAbstractNodeInitData initData)
{
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::NodeSplinePath, doc);
VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, drawName, idTool, doc);
VAbstractTool::AddRecord(initData.id, Tool::NodeSplinePath, initData.doc);
VNodeSplinePath *splPath = new VNodeSplinePath(initData);
VAbstractPattern::AddTool(id, splPath);
if (idTool != NULL_ID)
VAbstractPattern::AddTool(initData.id, splPath);
if (initData.idTool != NULL_ID)
{
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = VAbstractPattern::getTool(idTool);
VDataTool *tool = VAbstractPattern::getTool(initData.idTool);
SCASSERT(tool != nullptr)
splPath->setParent(tool);// Adopted by a tool
}
else
{
// Help to delete the node before each FullParse
doc->AddToolOnRemove(splPath);
initData.doc->AddToolOnRemove(splPath);
}
}
else
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}

View File

@ -47,9 +47,7 @@ class VNodeSplinePath : public VAbstractNode
{
Q_OBJECT
public:
static void Create(VAbstractPattern *doc, VContainer *data, quint32 id,
quint32 idSpline, const Document &parse,
const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0);
static void Create(VAbstractNodeInitData initData);
static const QString ToolType;
virtual QString getTagName() const Q_DECL_OVERRIDE;
@ -64,8 +62,7 @@ protected:
private:
Q_DISABLE_COPY(VNodeSplinePath)
VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation,
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr);
VNodeSplinePath(const VAbstractNodeInitData &initData, QObject *qoParent = nullptr);
};
#endif // VNODESPLINEPATH_H

View File

@ -40,55 +40,61 @@ VToolPiecePath *VToolPiecePath::Create(QSharedPointer<DialogTool> dialog, VMainG
SCASSERT(not dialog.isNull());
QSharedPointer<DialogPiecePath> dialogTool = dialog.objectCast<DialogPiecePath>();
SCASSERT(not dialogTool.isNull())
VPiecePath path = dialogTool->GetPiecePath();
const quint32 pieceId = dialogTool->GetPieceId();
qApp->getUndoStack()->beginMacro("add path");
path.SetNodes(PrepareNodes(path, scene, doc, data));
VToolPiecePath *pathTool = Create(0, path, pieceId, scene, doc, data, Document::FullParse, Source::FromGui);
VToolPiecePathInitData initData;
initData.path = dialogTool->GetPiecePath();
initData.idObject = dialogTool->GetPieceId();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
qApp->getUndoStack()->beginMacro("add path");
initData.path.SetNodes(PrepareNodes(initData.path, scene, doc, data));
VToolPiecePath *pathTool = Create(initData);
return pathTool;
}
//---------------------------------------------------------------------------------------------------------------------
VToolPiecePath *VToolPiecePath::Create(quint32 _id, const VPiecePath &path, quint32 pieceId, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation, const QString &drawName, const quint32 &idTool)
VToolPiecePath *VToolPiecePath::Create(VToolPiecePathInitData initData)
{
quint32 id = _id;
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = data->AddPiecePath(path);
initData.id = initData.data->AddPiecePath(initData.path);
}
else
{
data->UpdatePiecePath(id, path);
if (parse != Document::FullParse)
initData.data->UpdatePiecePath(initData.id, initData.path);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::PiecePath, doc);
VAbstractTool::AddRecord(initData.id, Tool::PiecePath, initData.doc);
//TODO Need create garbage collector and remove all nodes, that we don't use.
//Better check garbage before each saving file. Check only modeling tags.
VToolPiecePath *pathTool = new VToolPiecePath(doc, data, id, pieceId, typeCreation, drawName, idTool, doc);
VToolPiecePath *pathTool = new VToolPiecePath(initData);
VAbstractPattern::AddTool(id, pathTool);
if (idTool != NULL_ID)
VAbstractPattern::AddTool(initData.id, pathTool);
if (initData.idTool != NULL_ID)
{
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = VAbstractPattern::getTool(idTool);
VDataTool *tool = VAbstractPattern::getTool(initData.idTool);
SCASSERT(tool != nullptr);
pathTool->setParent(tool);// Adopted by a tool
}
else
{
if (typeCreation == Source::FromGui && path.GetType() == PiecePathType::InternalPath)
if (initData.typeCreation == Source::FromGui && initData.path.GetType() == PiecePathType::InternalPath)
{ // Seam allowance tool already initializated and can't init the path
SCASSERT(pieceId > NULL_ID);
VToolSeamAllowance *saTool = qobject_cast<VToolSeamAllowance*>(VAbstractPattern::getTool(pieceId));
SCASSERT(initData.idObject > NULL_ID);
VToolSeamAllowance *saTool =
qobject_cast<VToolSeamAllowance*>(VAbstractPattern::getTool(initData.idObject));
SCASSERT(saTool != nullptr);
pathTool->setParentItem(saTool);
pathTool->SetParentType(ParentType::Item);
@ -96,7 +102,7 @@ VToolPiecePath *VToolPiecePath::Create(quint32 _id, const VPiecePath &path, quin
else
{
// Try to prevent memory leak
scene->addItem(pathTool);// First adopted by scene
initData.scene->addItem(pathTool);// First adopted by scene
pathTool->hide();// If no one will use node, it will stay hidden
pathTool->SetParentType(ParentType::Scene);
}
@ -285,16 +291,14 @@ void VToolPiecePath::ToolCreation(const Source &typeCreation)
}
//---------------------------------------------------------------------------------------------------------------------
VToolPiecePath::VToolPiecePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pieceId,
const Source &typeCreation, const QString &drawName, const quint32 &idTool,
QObject *qoParent, QGraphicsItem *parent)
:VAbstractNode(doc, data, id, 0, drawName, idTool, qoParent),
VToolPiecePath::VToolPiecePath(const VToolPiecePathInitData &initData, QObject *qoParent, QGraphicsItem *parent)
:VAbstractNode(initData.doc, initData.data, initData.id, NULL_ID, initData.drawName, initData.idTool, qoParent),
QGraphicsPathItem(parent),
m_pieceId(pieceId)
m_pieceId(initData.idObject)
{
IncrementNodes(VAbstractTool::data.GetPiecePath(id));
IncrementNodes(VAbstractTool::data.GetPiecePath(initData.id));
RefreshGeometry();
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -35,16 +35,23 @@
class DialogTool;
struct VToolPiecePathInitData : public VAbstractNodeInitData
{
VToolPiecePathInitData()
: VAbstractNodeInitData(),
path()
{}
VPiecePath path;
};
class VToolPiecePath : public VAbstractNode, public QGraphicsPathItem
{
Q_OBJECT
public:
static VToolPiecePath* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolPiecePath *Create(quint32 _id, const VPiecePath &path, quint32 pieceId, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation, const QString &drawName = QString(),
const quint32 &idTool = 0);
static VToolPiecePath *Create(VToolPiecePathInitData initData);
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::PiecePath)};
@ -71,8 +78,7 @@ private:
quint32 m_pieceId;
VToolPiecePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pieceId, const Source &typeCreation,
const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr,
VToolPiecePath(const VToolPiecePathInitData &initData, QObject *qoParent = nullptr,
QGraphicsItem *parent = nullptr);
void RefreshGeometry();

View File

@ -40,28 +40,31 @@ VToolPin *VToolPin::Create(QSharedPointer<DialogTool> dialog, VAbstractPattern *
SCASSERT(not dialog.isNull());
QSharedPointer<DialogPin> dialogTool = dialog.objectCast<DialogPin>();
SCASSERT(not dialogTool.isNull())
const quint32 pointId = dialogTool->GetPointId();
const quint32 pieceId = dialogTool->GetPieceId();
return Create(0, pointId, pieceId, doc, data, Document::FullParse, Source::FromGui);
VToolPinInitData initData;
initData.pointId = dialogTool->GetPointId();
initData.idObject = dialogTool->GetPieceId();
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
return Create(initData);
}
//---------------------------------------------------------------------------------------------------------------------
VToolPin *VToolPin::Create(quint32 _id, quint32 pointId, quint32 pieceId, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation, const QString &drawName,
const quint32 &idTool)
VToolPin *VToolPin::Create(VToolPinInitData initData)
{
quint32 id = _id;
if (typeCreation == Source::FromGui)
if (initData.typeCreation == Source::FromGui)
{
id = CreateNode<VPointF>(data, pointId);
initData.id = CreateNode<VPointF>(initData.data, initData.pointId);
}
else
{
QSharedPointer<VPointF> point;
try
{
point = data->GeometricObject<VPointF>(pointId);
point = initData.data->GeometricObject<VPointF>(initData.pointId);
}
catch (const VExceptionBadId &e)
{ // Possible case. Parent was deleted, but the node object is still here.
@ -70,35 +73,35 @@ VToolPin *VToolPin::Create(quint32 _id, quint32 pointId, quint32 pieceId, VAbstr
}
VPointF *pinPoint = new VPointF(*point);
pinPoint->setMode(Draw::Modeling);
data->UpdateGObject(id, pinPoint);
if (parse != Document::FullParse)
initData.data->UpdateGObject(initData.id, pinPoint);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
VAbstractTool::AddRecord(id, Tool::Pin, doc);
VAbstractTool::AddRecord(initData.id, Tool::Pin, initData.doc);
VToolPin *point = nullptr;
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
point = new VToolPin(doc, data, id, pointId, pieceId, typeCreation, drawName, idTool, doc);
point = new VToolPin(initData);
VAbstractPattern::AddTool(id, point);
if (idTool != NULL_ID)
VAbstractPattern::AddTool(initData.id, point);
if (initData.idTool != NULL_ID)
{
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = VAbstractPattern::getTool(idTool);
VDataTool *tool = VAbstractPattern::getTool(initData.idTool);
SCASSERT(tool != nullptr)
point->setParent(tool);// Adopted by a tool
}
else
{
// Help to delete the node before each FullParse
doc->AddToolOnRemove(point);
initData.doc->AddToolOnRemove(point);
}
}
else
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
return point;
}
@ -153,10 +156,10 @@ void VToolPin::AddToFile()
}
//---------------------------------------------------------------------------------------------------------------------
VToolPin::VToolPin(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pointId, quint32 pieceId,
const Source &typeCreation, const QString &drawName, const quint32 &idTool, QObject *qoParent)
: VAbstractNode(doc, data, id, pointId, drawName, idTool, qoParent),
m_pieceId(pieceId)
VToolPin::VToolPin(const VToolPinInitData &initData, QObject *qoParent)
: VAbstractNode(initData.doc, initData.data, initData.id, initData.pointId, initData.drawName, initData.idTool,
qoParent),
m_pieceId(initData.idObject)
{
ToolCreation(typeCreation);
ToolCreation(initData.typeCreation);
}

View File

@ -35,14 +35,22 @@
class DialogTool;
struct VToolPinInitData : public VAbstractNodeInitData
{
VToolPinInitData()
: VAbstractNodeInitData(),
pointId(NULL_ID)
{}
quint32 pointId;
};
class VToolPin : public VAbstractNode
{
Q_OBJECT
public:
static VToolPin* Create(QSharedPointer<DialogTool> dialog, VAbstractPattern *doc, VContainer *data);
static VToolPin *Create(quint32 _id, quint32 pointId, quint32 pieceId, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation, const QString &drawName = QString(),
const quint32 &idTool = 0);
static VToolPin *Create(VToolPinInitData initData);
static const QString ToolType;
virtual QString getTagName() const Q_DECL_OVERRIDE;
@ -59,9 +67,7 @@ private:
quint32 m_pieceId;
VToolPin(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pointId, quint32 pieceId,
const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0,
QObject *qoParent = nullptr);
VToolPin(const VToolPinInitData &initData, QObject *qoParent = nullptr);
};
#endif // VTOOLPIN_H

View File

@ -618,32 +618,38 @@ quint32 VAbstractTool::PrepareNode(const VPieceNode &node, VMainGraphicsScene *s
SCASSERT(doc != nullptr)
SCASSERT(data != nullptr)
quint32 id = NULL_ID;
VAbstractNodeInitData initData;
initData.idObject = node.GetId();
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
switch (node.GetTypeTool())
{
case (Tool::NodePoint):
id = CreateNode<VPointF>(data, node.GetId());
VNodePoint::Create(doc, data, scene, id, node.GetId(), Document::FullParse, Source::FromGui);
initData.id = CreateNode<VPointF>(data, node.GetId());
VNodePoint::Create(initData);
break;
case (Tool::NodeArc):
id = CreateNode<VArc>(data, node.GetId());
VNodeArc::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui);
initData.id = CreateNode<VArc>(data, node.GetId());
VNodeArc::Create(initData);
break;
case (Tool::NodeElArc):
id = CreateNode<VEllipticalArc>(data, node.GetId());
VNodeEllipticalArc::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui);
initData.id = CreateNode<VEllipticalArc>(data, node.GetId());
VNodeEllipticalArc::Create(initData);
break;
case (Tool::NodeSpline):
id = CreateNodeSpline(data, node.GetId());
VNodeSpline::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui);
initData.id = CreateNodeSpline(data, node.GetId());
VNodeSpline::Create(initData);
break;
case (Tool::NodeSplinePath):
id = CreateNodeSplinePath(data, node.GetId());
VNodeSplinePath::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui);
initData.id = CreateNodeSplinePath(data, node.GetId());
VNodeSplinePath::Create(initData);
break;
default:
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
break;
}
return id;
return initData.id;
}

View File

@ -49,6 +49,26 @@
class VGraphicsSimpleTextItem;
class VAbstractNode;
struct VAbstractToolInitData
{
VAbstractToolInitData()
: id(NULL_ID),
scene(nullptr),
doc(nullptr),
data(nullptr),
parse(Document::FullParse),
typeCreation(Source::FromFile)
{}
/** @brief id tool id, 0 if tool doesn't exist yet.*/
quint32 id;
VMainGraphicsScene *scene;
VAbstractPattern *doc;
VContainer *data;
Document parse;
Source typeCreation;
};
/**
* @brief The VAbstractTool abstract class for all tools.
*/

View File

@ -91,12 +91,20 @@ VToolSeamAllowance *VToolSeamAllowance::Create(QSharedPointer<DialogTool> dialog
SCASSERT(not dialog.isNull());
QSharedPointer<DialogSeamAllowance> dialogTool = dialog.objectCast<DialogSeamAllowance>();
SCASSERT(not dialogTool.isNull())
VPiece detail = dialogTool->GetPiece();
QString width = detail.GetFormulaSAWidth();
qApp->getUndoStack()->beginMacro("add detail");
detail.GetPath().SetNodes(PrepareNodes(detail.GetPath(), scene, doc, data));
VToolSeamAllowance *piece = Create(0, detail, width, scene, doc, data, Document::FullParse, Source::FromGui);
VToolSeamAllowanceInitData initData;
initData.detail = dialogTool->GetPiece();
initData.width = initData.detail.GetFormulaSAWidth();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
qApp->getUndoStack()->beginMacro("add detail");
initData.detail.GetPath().SetNodes(PrepareNodes(initData.detail.GetPath(), scene, doc, data));
VToolSeamAllowance *piece = Create(initData);
if (piece != nullptr)
{
@ -106,45 +114,47 @@ VToolSeamAllowance *VToolSeamAllowance::Create(QSharedPointer<DialogTool> dialog
}
//---------------------------------------------------------------------------------------------------------------------
VToolSeamAllowance *VToolSeamAllowance::Create(quint32 id, VPiece newPiece, QString &width, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation, const QString &drawName)
VToolSeamAllowance *VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initData)
{
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
if (initData.typeCreation == Source::FromGui || initData.typeCreation == Source::FromTool)
{
data->AddVariable(currentSeamAllowance, new VIncrement(data, currentSeamAllowance, 0, newPiece.GetSAWidth(),
width, true, tr("Current seam allowance")));
id = data->AddPiece(newPiece);
initData.data->AddVariable(currentSeamAllowance, new VIncrement(initData.data, currentSeamAllowance, 0,
initData.detail.GetSAWidth(),
initData.width, true,
tr("Current seam allowance")));
initData.id = initData.data->AddPiece(initData.detail);
}
else
{
const qreal calcWidth = CheckFormula(id, width, data);
newPiece.SetFormulaSAWidth(width, calcWidth);
const qreal calcWidth = CheckFormula(initData.id, initData.width, initData.data);
initData.detail.SetFormulaSAWidth(initData.width, calcWidth);
data->AddVariable(currentSeamAllowance, new VIncrement(data, currentSeamAllowance, 0, calcWidth,
width, true, tr("Current seam allowance")));
initData.data->AddVariable(currentSeamAllowance, new VIncrement(initData.data, currentSeamAllowance, 0,
calcWidth, initData.width, true,
tr("Current seam allowance")));
data->UpdatePiece(id, newPiece);
if (parse != Document::FullParse)
initData.data->UpdatePiece(initData.id, initData.detail);
if (initData.parse != Document::FullParse)
{
doc->UpdateToolData(id, data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
VToolSeamAllowance *piece = nullptr;
if (parse == Document::FullParse)
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::Piece, doc);
piece = new VToolSeamAllowance(doc, data, id, typeCreation, scene, drawName);
scene->addItem(piece);
connect(piece, &VToolSeamAllowance::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
connect(scene, &VMainGraphicsScene::EnableDetailItemHover, piece, &VToolSeamAllowance::AllowHover);
connect(scene, &VMainGraphicsScene::EnableDetailItemSelection, piece, &VToolSeamAllowance::AllowSelecting);
connect(scene, &VMainGraphicsScene::HighlightDetail, piece, &VToolSeamAllowance::Highlight);
VAbstractPattern::AddTool(id, piece);
VAbstractTool::AddRecord(initData.id, Tool::Piece, initData.doc);
piece = new VToolSeamAllowance(initData);
initData.scene->addItem(piece);
connect(piece, &VToolSeamAllowance::ChoosedTool, initData.scene, &VMainGraphicsScene::ChoosedItem);
connect(initData.scene, &VMainGraphicsScene::EnableDetailItemHover, piece, &VToolSeamAllowance::AllowHover);
connect(initData.scene, &VMainGraphicsScene::EnableDetailItemSelection, piece,
&VToolSeamAllowance::AllowSelecting);
connect(initData.scene, &VMainGraphicsScene::HighlightDetail, piece, &VToolSeamAllowance::Highlight);
VAbstractPattern::AddTool(initData.id, piece);
}
//Very important to delete it. Only this tool need this special variable.
data->RemoveVariable(currentSeamAllowance);
initData.data->RemoveVariable(currentSeamAllowance);
return piece;
}
@ -1103,23 +1113,21 @@ void VToolSeamAllowance::SetDialog()
}
//---------------------------------------------------------------------------------------------------------------------
VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data, const quint32 &id,
const Source &typeCreation, VMainGraphicsScene *scene,
const QString &drawName, QGraphicsItem *parent)
: VInteractiveTool(doc, data, id),
VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem *parent)
: VInteractiveTool(initData.doc, initData.data, initData.id),
QGraphicsPathItem(parent),
m_mainPath(),
m_mainPathRect(),
m_sceneDetails(scene),
m_drawName(drawName),
m_sceneDetails(initData.scene),
m_drawName(initData.drawName),
m_seamAllowance(new VNoBrushScalePathItem(this)),
m_dataLabel(new VTextGraphicsItem(this)),
m_patternInfo(new VTextGraphicsItem(this)),
m_grainLine(new VGrainlineItem(this)),
m_passmarks(new QGraphicsPathItem(this))
{
VPiece detail = data->GetPiece(id);
InitNodes(detail, scene);
VPiece detail = initData.data->GetPiece(initData.id);
InitNodes(detail, initData.scene);
InitCSAPaths(detail);
InitInternalPaths(detail);
InitPins(detail);
@ -1130,9 +1138,9 @@ VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data,
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove);
connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolSeamAllowance::ResetChildren);
ToolCreation(typeCreation);
connect(initData.scene, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove);
connect(initData.scene, &VMainGraphicsScene::ItemClicked, this, &VToolSeamAllowance::ResetChildren);
ToolCreation(initData.typeCreation);
setAcceptHoverEvents(true);
connect(m_dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolSeamAllowance::SaveMoveDetail);

View File

@ -41,6 +41,20 @@
class DialogTool;
class VNoBrushScalePathItem;
struct VToolSeamAllowanceInitData : public VAbstractToolInitData
{
VToolSeamAllowanceInitData()
: VAbstractToolInitData(),
detail(),
width("0"),
drawName()
{}
VPiece detail;
QString width;
QString drawName;
};
class VToolSeamAllowance : public VInteractiveTool, public QGraphicsPathItem
{
Q_OBJECT
@ -49,9 +63,7 @@ public:
static VToolSeamAllowance* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolSeamAllowance* Create(quint32 id, VPiece newPiece, QString &width, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data, const Document &parse,
const Source &typeCreation, const QString &drawName = QString());
static VToolSeamAllowance* Create(VToolSeamAllowanceInitData &initData);
static const quint8 pieceVersion;
@ -152,8 +164,7 @@ private:
VGrainlineItem *m_grainLine;
QGraphicsPathItem *m_passmarks;
VToolSeamAllowance(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation,
VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr);
VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem * parent = nullptr);
void UpdateExcludeState();
void RefreshGeometry();

View File

@ -359,7 +359,7 @@ void UnionInitParameters(const VToolUnionDetailsInitData &initData, const VPiece
}
//---------------------------------------------------------------------------------------------------------------------
quint32 AddNodePoint(const VPieceNode &node, const VToolUnionDetailsInitData &initData, quint32 idTool,
quint32 AddNodePoint(const VPieceNode &node, const VToolUnionDetailsInitData &initData,
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy,
quint32 pRotate, qreal angle)
{
@ -378,13 +378,23 @@ quint32 AddNodePoint(const VPieceNode &node, const VToolUnionDetailsInitData &in
children.append(idObject);
point1->setMode(Draw::Modeling);
const quint32 id = initData.data->AddGObject(point1.take());
VNodePoint::Create(initData.doc, initData.data, initData.scene, id, idObject, Document::FullParse, Source::FromTool,
drawName, idTool);
VAbstractNodeInitData initNodeData;
initNodeData.id = id;
initNodeData.idObject = idObject;
initNodeData.doc = initData.doc;
initNodeData.data = initData.data;
initNodeData.parse = Document::FullParse;
initNodeData.typeCreation = Source::FromTool;
initNodeData.idTool = initData.id;
initNodeData.drawName = drawName;
VNodePoint::Create(initNodeData);
return id;
}
//---------------------------------------------------------------------------------------------------------------------
quint32 AddPin(quint32 id, const VToolUnionDetailsInitData &initData, quint32 idTool, QVector<quint32> &children,
quint32 AddPin(quint32 id, const VToolUnionDetailsInitData &initData, QVector<quint32> &children,
const QString &drawName, qreal dx, qreal dy, quint32 pRotate, qreal angle)
{
QScopedPointer<VPointF> point(new VPointF(*initData.data->GeometricObject<VPointF>(id)));
@ -402,13 +412,24 @@ quint32 AddPin(quint32 id, const VToolUnionDetailsInitData &initData, quint32 id
children.append(idObject);
point1->setMode(Draw::Modeling);
const quint32 idPin = initData.data->AddGObject(point1.take());
VToolPin::Create(idPin, idObject, 0, initData.doc, initData.data, Document::FullParse, Source::FromTool, drawName,
idTool);
VToolPinInitData initNodeData;
initNodeData.id = idPin;
initNodeData.pointId = idObject;
initNodeData.idObject = NULL_ID;
initNodeData.doc = initData.doc;
initNodeData.data = initData.data;
initNodeData.parse = Document::FullParse;
initNodeData.typeCreation = Source::FromTool;
initNodeData.idTool = initData.id;
initNodeData.drawName = drawName;
VToolPin::Create(initNodeData);
return idPin;
}
//---------------------------------------------------------------------------------------------------------------------
quint32 AddNodeArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData, quint32 idTool,
quint32 AddNodeArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData,
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy,
quint32 pRotate, qreal angle)
{
@ -444,13 +465,22 @@ quint32 AddNodeArc(const VPieceNode &node, const VToolUnionDetailsInitData &init
arc2->setMode(Draw::Modeling);
const quint32 id = initData.data->AddGObject(arc2.take());
VNodeArc::Create(initData.doc, initData.data, id, idObject, Document::FullParse, Source::FromTool, drawName,
idTool);
VAbstractNodeInitData initNodeData;
initNodeData.id = id;
initNodeData.idObject = idObject;
initNodeData.doc = initData.doc;
initNodeData.data = initData.data;
initNodeData.parse = Document::FullParse;
initNodeData.typeCreation = Source::FromTool;
initNodeData.idTool = initData.id;
initNodeData.drawName = drawName;
VNodeArc::Create(initNodeData);
return id;
}
//---------------------------------------------------------------------------------------------------------------------
quint32 AddNodeElArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData, quint32 idTool,
quint32 AddNodeElArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData,
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy,
quint32 pRotate, qreal angle)
{
@ -488,13 +518,22 @@ quint32 AddNodeElArc(const VPieceNode &node, const VToolUnionDetailsInitData &in
arc2->setMode(Draw::Modeling);
const quint32 id = initData.data->AddGObject(arc2.take());
VNodeEllipticalArc::Create(initData.doc, initData.data, id, idObject, Document::FullParse, Source::FromTool,
drawName, idTool);
VAbstractNodeInitData initNodeData;
initNodeData.id = id;
initNodeData.idObject = idObject;
initNodeData.doc = initData.doc;
initNodeData.data = initData.data;
initNodeData.parse = Document::FullParse;
initNodeData.typeCreation = Source::FromTool;
initNodeData.idTool = initData.id;
initNodeData.drawName = drawName;
VNodeEllipticalArc::Create(initNodeData);
return id;
}
//---------------------------------------------------------------------------------------------------------------------
quint32 AddNodeSpline(const VPieceNode &node, const VToolUnionDetailsInitData &initData, quint32 idTool,
quint32 AddNodeSpline(const VPieceNode &node, const VToolUnionDetailsInitData &initData,
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy,
quint32 pRotate, qreal angle)
{
@ -523,13 +562,23 @@ quint32 AddNodeSpline(const VPieceNode &node, const VToolUnionDetailsInitData &i
VSpline *spl1 = new VSpline(*spl);
spl1->setMode(Draw::Modeling);
const quint32 id = initData.data->AddGObject(spl1);
VNodeSpline::Create(initData.doc, initData.data, id, idObject, Document::FullParse, Source::FromTool, drawName,
idTool);
VAbstractNodeInitData initNodeData;
initNodeData.id = id;
initNodeData.idObject = idObject;
initNodeData.doc = initData.doc;
initNodeData.data = initData.data;
initNodeData.parse = Document::FullParse;
initNodeData.typeCreation = Source::FromTool;
initNodeData.idTool = initData.id;
initNodeData.drawName = drawName;
VNodeSpline::Create(initNodeData);
return id;
}
//---------------------------------------------------------------------------------------------------------------------
quint32 AddNodeSplinePath(const VPieceNode &node, const VToolUnionDetailsInitData &initData, quint32 idTool,
quint32 AddNodeSplinePath(const VPieceNode &node, const VToolUnionDetailsInitData &initData,
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy,
quint32 pRotate, qreal angle)
{
@ -587,8 +636,17 @@ quint32 AddNodeSplinePath(const VPieceNode &node, const VToolUnionDetailsInitDat
path1->setMode(Draw::Modeling);
const quint32 id = initData.data->AddGObject(path1.take());
VNodeSplinePath::Create(initData.doc, initData.data, id, idObject, Document::FullParse, Source::FromTool, drawName,
idTool);
VAbstractNodeInitData initNodeData;
initNodeData.id = id;
initNodeData.idObject = idObject;
initNodeData.doc = initData.doc;
initNodeData.data = initData.data;
initNodeData.parse = Document::FullParse;
initNodeData.typeCreation = Source::FromTool;
initNodeData.idTool = initData.id;
initNodeData.drawName = drawName;
VNodeSplinePath::Create(initNodeData);
return id;
}
@ -597,30 +655,30 @@ quint32 AddNodeSplinePath(const VPieceNode &node, const VToolUnionDetailsInitDat
* @brief AddToNewDetail create united detail adding one node per time.
*/
void AddNodeToNewPath(const VToolUnionDetailsInitData &initData, VPiecePath &newPath, VPieceNode node,
quint32 idTool, QVector<quint32> &children, const QString &drawName, qreal dx = 0, qreal dy = 0,
QVector<quint32> &children, const QString &drawName, qreal dx = 0, qreal dy = 0,
quint32 pRotate = NULL_ID, qreal angle = 0);
void AddNodeToNewPath(const VToolUnionDetailsInitData &initData, VPiecePath &newPath, VPieceNode node,
quint32 idTool, QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy,
quint32 pRotate, qreal angle)
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy, quint32 pRotate,
qreal angle)
{
quint32 id = 0;
switch (node.GetTypeTool())
{
case (Tool::NodePoint):
id = AddNodePoint(node, initData, idTool, children, drawName, dx, dy, pRotate, angle);
id = AddNodePoint(node, initData, children, drawName, dx, dy, pRotate, angle);
break;
case (Tool::NodeArc):
id = AddNodeArc(node, initData, idTool, children, drawName, dx, dy, pRotate, angle);
id = AddNodeArc(node, initData, children, drawName, dx, dy, pRotate, angle);
break;
case (Tool::NodeElArc):
id = AddNodeElArc(node, initData, idTool, children, drawName, dx, dy, pRotate, angle);
id = AddNodeElArc(node, initData, children, drawName, dx, dy, pRotate, angle);
break;
case (Tool::NodeSpline):
id = AddNodeSpline(node, initData, idTool, children, drawName, dx, dy, pRotate, angle);
id = AddNodeSpline(node, initData, children, drawName, dx, dy, pRotate, angle);
break;
case (Tool::NodeSplinePath):
id = AddNodeSplinePath(node, initData, idTool, children, drawName, dx, dy, pRotate, angle);
id = AddNodeSplinePath(node, initData, children, drawName, dx, dy, pRotate, angle);
break;
default:
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
@ -979,7 +1037,7 @@ void UpdatePathNode(VContainer *data, const VPieceNode &node, QVector<quint32> &
}
//---------------------------------------------------------------------------------------------------------------------
void CreateUnitedNodes(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName,
void CreateUnitedNodes(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName,
const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
{
const VPiecePath d1Path = d1.GetPath().RemoveEdge(initData.indexD1);
@ -995,23 +1053,22 @@ void CreateUnitedNodes(VPiece &newDetail, const VPiece &d1, const VPiece &d2, qu
{
if (unitedPath.at(i).first)
{// first piece
AddNodeToNewPath(initData, newPath, unitedPath.at(i).second, id, children, drawName);
AddNodeToNewPath(initData, newPath, unitedPath.at(i).second, children, drawName);
}
else
{// second piece
AddNodeToNewPath(initData, newPath, unitedPath.at(i).second, id, children, drawName, dx, dy, pRotate,
angle);
AddNodeToNewPath(initData, newPath, unitedPath.at(i).second, children, drawName, dx, dy, pRotate, angle);
}
}
newDetail.SetPath(newPath);
SCASSERT(not children.isEmpty())
SaveNodesChildren(initData.doc, id, children);
SaveNodesChildren(initData.doc, initData.id, children);
}
//---------------------------------------------------------------------------------------------------------------------
void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector<quint32> &children, quint32 id,
void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector<quint32> &children,
const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy,
quint32 pRotate, qreal angle)
{
@ -1024,11 +1081,23 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector<quint32>
newPath.Clear();//Clear nodes
for (int i=0; i < path.CountNodes(); ++i)
{
AddNodeToNewPath(initData, newPath, path.at(i), id, nodeChildren, drawName, dx, dy, pRotate, angle);
AddNodeToNewPath(initData, newPath, path.at(i), nodeChildren, drawName, dx, dy, pRotate, angle);
}
const quint32 idPath = initData.data->AddPiecePath(newPath);
VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse,
Source::FromTool, drawName, id);
VToolPiecePathInitData initNodeData;
initNodeData.id = idPath;
initNodeData.idObject = NULL_ID;
initNodeData.scene = initData.scene;
initNodeData.doc = initData.doc;
initNodeData.data = initData.data;
initNodeData.parse = Document::FullParse;
initNodeData.typeCreation = Source::FromTool;
initNodeData.idTool = initData.id;
initNodeData.drawName = drawName;
initNodeData.path = newPath;
VToolPiecePath::Create(initNodeData);
record.path = idPath;
newDetail.GetCustomSARecords().append(record);
nodeChildren.prepend(idPath);
@ -1037,7 +1106,7 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector<quint32>
}
//---------------------------------------------------------------------------------------------------------------------
void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName,
void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName,
const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
{
for (int i = 0; i < d1.GetCustomSARecords().size(); ++i)
@ -1046,12 +1115,12 @@ void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quin
}
QVector<quint32> children;
CreateUnitedDetailCSA(newDetail, d2, children, id, drawName, initData, dx, dy, pRotate, angle);
SaveCSAChildren(initData.doc, id, children);
CreateUnitedDetailCSA(newDetail, d2, children, drawName, initData, dx, dy, pRotate, angle);
SaveCSAChildren(initData.doc, initData.id, children);
}
//---------------------------------------------------------------------------------------------------------------------
void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector<quint32> &children, quint32 id,
void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector<quint32> &children,
const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx,
qreal dy, quint32 pRotate, qreal angle)
{
@ -1064,11 +1133,23 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector
for (int i=0; i < path.CountNodes(); ++i)
{
AddNodeToNewPath(initData, newPath, path.at(i), id, nodeChildren, drawName, dx, dy, pRotate, angle);
AddNodeToNewPath(initData, newPath, path.at(i), nodeChildren, drawName, dx, dy, pRotate, angle);
}
const quint32 idPath = initData.data->AddPiecePath(newPath);
VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse,
Source::FromTool, drawName, id);
VToolPiecePathInitData initNodeData;
initNodeData.id = idPath;
initNodeData.idObject = NULL_ID;
initNodeData.scene = initData.scene;
initNodeData.doc = initData.doc;
initNodeData.data = initData.data;
initNodeData.parse = Document::FullParse;
initNodeData.typeCreation = Source::FromTool;
initNodeData.idTool = initData.id;
initNodeData.drawName = drawName;
initNodeData.path = newPath;
VToolPiecePath::Create(initNodeData);
newDetail.GetInternalPaths().append(idPath);
nodeChildren.prepend(idPath);
}
@ -1076,9 +1157,9 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector
}
//---------------------------------------------------------------------------------------------------------------------
void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id,
const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy,
quint32 pRotate, qreal angle)
void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName,
const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
qreal angle)
{
for (int i = 0; i < d1.GetInternalPaths().size(); ++i)
{
@ -1086,20 +1167,20 @@ void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece
}
QVector<quint32> children;
CreateUnitedDetailInternalPaths(newDetail, d2, children, id, drawName, initData, dx, dy, pRotate, angle);
CreateUnitedDetailInternalPaths(newDetail, d2, children, drawName, initData, dx, dy, pRotate, angle);
SaveInternalPathsChildren(initData.doc, id, children);
SaveInternalPathsChildren(initData.doc, initData.id, children);
}
//---------------------------------------------------------------------------------------------------------------------
void CreateUnitedDetailPins(VPiece &newDetail, const VPiece &d, QVector<quint32> &children, quint32 idTool,
void CreateUnitedDetailPins(VPiece &newDetail, const VPiece &d, QVector<quint32> &children,
const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy,
quint32 pRotate, qreal angle)
{
QVector<quint32> nodeChildren;
for(int i=0; i < d.GetPins().size(); ++i)
{
const quint32 id = AddPin(d.GetPins().at(i), initData, idTool, children, drawName, dx, dy, pRotate, angle);
const quint32 id = AddPin(d.GetPins().at(i), initData, children, drawName, dx, dy, pRotate, angle);
newDetail.GetPins().append(id);
nodeChildren.prepend(id);
}
@ -1107,7 +1188,7 @@ void CreateUnitedDetailPins(VPiece &newDetail, const VPiece &d, QVector<quint32>
}
//---------------------------------------------------------------------------------------------------------------------
void CreateUnitedPins(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName,
void CreateUnitedPins(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName,
const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
{
for (int i = 0; i < d1.GetPins().size(); ++i)
@ -1116,21 +1197,20 @@ void CreateUnitedPins(VPiece &newDetail, const VPiece &d1, const VPiece &d2, qui
}
QVector<quint32> children;
CreateUnitedDetailPins(newDetail, d2, children, id, drawName, initData, dx, dy, pRotate, angle);
SavePinsChildren(initData.doc, id, children);
CreateUnitedDetailPins(newDetail, d2, children, drawName, initData, dx, dy, pRotate, angle);
SavePinsChildren(initData.doc, initData.id, children);
}
//---------------------------------------------------------------------------------------------------------------------
void UpdateUnitedNodes(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
qreal angle)
void UpdateUnitedNodes(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
{
const VPiecePath d1REPath = GetPiece1MainPath(initData.doc, id).RemoveEdge(initData.indexD1);
const VPiecePath d2REPath = GetPiece2MainPath(initData.doc, id).RemoveEdge(initData.indexD2);
const VPiecePath d1REPath = GetPiece1MainPath(initData.doc, initData.id).RemoveEdge(initData.indexD1);
const VPiecePath d2REPath = GetPiece2MainPath(initData.doc, initData.id).RemoveEdge(initData.indexD2);
const qint32 countNodeD1 = d1REPath.CountNodes();
const qint32 countNodeD2 = d2REPath.CountNodes();
QVector<quint32> children = GetNodesChildren(initData.doc, id);
QVector<quint32> children = GetNodesChildren(initData.doc, initData.id);
if (not children.isEmpty())
{
// This check need for backward compatibility
@ -1210,7 +1290,7 @@ void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx
}
//---------------------------------------------------------------------------------------------------------------------
void UpdateUnitedDetailCSA(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
void UpdateUnitedDetailCSA(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
qreal angle, const QVector<CustomSARecord> &records)
{
QVector<quint32> idRecords;
@ -1218,21 +1298,22 @@ void UpdateUnitedDetailCSA(quint32 id, const VToolUnionDetailsInitData &initData
{
idRecords.append(records.at(i).path);
}
UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, idRecords, GetCSAChildren(initData.doc, id));
UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, idRecords, GetCSAChildren(initData.doc, initData.id));
}
//---------------------------------------------------------------------------------------------------------------------
void UpdateUnitedDetailInternalPaths(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy,
void UpdateUnitedDetailInternalPaths(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy,
quint32 pRotate, qreal angle, const QVector<quint32> &records)
{
UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, records, GetInternalPathsChildren(initData.doc, id));
UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, records,
GetInternalPathsChildren(initData.doc, initData.id));
}
//---------------------------------------------------------------------------------------------------------------------
void UpdateUnitedDetailPins(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy,
quint32 pRotate, qreal angle, const QVector<quint32> &records)
void UpdateUnitedDetailPins(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle,
const QVector<quint32> &records)
{
QVector<quint32> children = GetPinChildren(initData.doc, id);
QVector<quint32> children = GetPinChildren(initData.doc, initData.id);
for (int i = 0; i < records.size(); ++i)
{
@ -1248,8 +1329,7 @@ void UpdateUnitedDetailPins(quint32 id, const VToolUnionDetailsInitData &initDat
}
//---------------------------------------------------------------------------------------------------------------------
void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
qreal angle)
void CreateUnitedDetail(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
{
const QString drawName = DrawName(initData.doc, initData.d1id, initData.d2id);
SCASSERT(not drawName.isEmpty())
@ -1259,10 +1339,10 @@ void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, q
VPiece newDetail;
CreateUnitedNodes(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle);
CreateUnitedCSA(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle);
CreateUnitedInternalPaths(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle);
CreateUnitedPins(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle);
CreateUnitedNodes(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle);
CreateUnitedCSA(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle);
CreateUnitedInternalPaths(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle);
CreateUnitedPins(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle);
newDetail.SetName(QObject::tr("United detail"));
QString formulaSAWidth = d1.GetFormulaSAWidth();
@ -1270,8 +1350,18 @@ void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, q
newDetail.SetMx(d1.GetMx());
newDetail.SetMy(d1.GetMy());
newDetail.SetUnited(true);
VToolSeamAllowance::Create(0, newDetail, formulaSAWidth, initData.scene, initData.doc, initData.data,
initData.parse, Source::FromTool, drawName);
VToolSeamAllowanceInitData pieceInitData;
pieceInitData.detail = newDetail;
pieceInitData.width = formulaSAWidth;
pieceInitData.scene = initData.scene;
pieceInitData.doc = initData.doc;
pieceInitData.data = initData.data;
pieceInitData.parse = initData.parse;
pieceInitData.typeCreation = Source::FromTool;
pieceInitData.drawName = drawName;
VToolSeamAllowance::Create(pieceInitData);
auto RemoveDetail = [initData](quint32 id)
{
@ -1292,17 +1382,17 @@ void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, q
}
//---------------------------------------------------------------------------------------------------------------------
void UpdateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
qreal angle)
void UpdateUnitedDetail(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
{
UpdateUnitedNodes(id, initData, dx, dy, pRotate, angle);
UpdateUnitedDetailCSA(id, initData, dx, dy, pRotate, angle, GetPiece2CSAPaths(initData.doc, id));
UpdateUnitedDetailInternalPaths(id, initData, dx, dy, pRotate, angle, GetPiece2InternalPaths(initData.doc, id));
UpdateUnitedDetailPins(id, initData, dx, dy, pRotate, angle, GetPiece2Pins(initData.doc, id));
UpdateUnitedNodes(initData, dx, dy, pRotate, angle);
UpdateUnitedDetailCSA(initData, dx, dy, pRotate, angle, GetPiece2CSAPaths(initData.doc, initData.id));
UpdateUnitedDetailInternalPaths(initData, dx, dy, pRotate, angle,
GetPiece2InternalPaths(initData.doc, initData.id));
UpdateUnitedDetailPins(initData, dx, dy, pRotate, angle, GetPiece2Pins(initData.doc, initData.id));
}
//---------------------------------------------------------------------------------------------------------------------
void UniteDetails(quint32 id, const VToolUnionDetailsInitData &initData)
void UniteDetails(const VToolUnionDetailsInitData &initData)
{
VPieceNode det1p1;
qreal dx = 0;
@ -1314,14 +1404,14 @@ void UniteDetails(quint32 id, const VToolUnionDetailsInitData &initData)
const VPiece d1 = initData.data->GetPiece(initData.d1id);
const VPiece d2 = initData.data->GetPiece(initData.d2id);
UnionInitParameters(initData, d1.GetPath(), d2.GetPath(), det1p1, dx, dy, angle);
CreateUnitedDetail(id, initData, dx, dy, det1p1.GetId(), angle);
CreateUnitedDetail(initData, dx, dy, det1p1.GetId(), angle);
}
else
{
const VPiecePath d1Path = GetPiece1MainPath(initData.doc, id);
const VPiecePath d2Path = GetPiece2MainPath(initData.doc, id);
const VPiecePath d1Path = GetPiece1MainPath(initData.doc, initData.id);
const VPiecePath d2Path = GetPiece2MainPath(initData.doc, initData.id);
UnionInitParameters(initData, d1Path, d2Path, det1p1, dx, dy, angle);
UpdateUnitedDetail(id, initData, dx, dy, det1p1.GetId(), angle);
UpdateUnitedDetail(initData, dx, dy, det1p1.GetId(), angle);
}
}
} // static functions
@ -1329,13 +1419,11 @@ void UniteDetails(quint32 id, const VToolUnionDetailsInitData &initData)
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VToolUnionDetails costructor.
* @param id object id in container.
* @param initData global init data.
* @param parent parent object.
*/
VToolUnionDetails::VToolUnionDetails(quint32 id, const VToolUnionDetailsInitData &initData,
QObject *parent)
: VAbstractTool(initData.doc, initData.data, id, parent),
VToolUnionDetails::VToolUnionDetails(const VToolUnionDetailsInitData &initData, QObject *parent)
: VAbstractTool(initData.doc, initData.data, initData.id, parent),
d1id(initData.d1id),
d2id(initData.d2id),
indexD1(initData.indexD1),
@ -1431,7 +1519,7 @@ VToolUnionDetails* VToolUnionDetails::Create(QSharedPointer<DialogTool> dialog,
initData.retainPieces = dialogTool->RetainPieces();
qApp->getUndoStack()->beginMacro(tr("union details"));
VToolUnionDetails* tool = Create(0, initData);
VToolUnionDetails* tool = Create(initData);
qApp->getUndoStack()->endMacro();
return tool;
}
@ -1439,36 +1527,34 @@ VToolUnionDetails* VToolUnionDetails::Create(QSharedPointer<DialogTool> dialog,
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool.
* @param _id tool id, 0 if tool doesn't exist yet.
* @param initData contains all init data.
*/
VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VToolUnionDetailsInitData &initData)
VToolUnionDetails* VToolUnionDetails::Create(VToolUnionDetailsInitData initData)
{
VToolUnionDetails *unionDetails = nullptr;
quint32 id = _id;
if (initData.typeCreation == Source::FromGui)
{
id = VContainer::getNextId();
initData.id = VContainer::getNextId();
}
else
{
if (initData.parse != Document::FullParse)
{
initData.doc->UpdateToolData(id, initData.data);
initData.doc->UpdateToolData(initData.id, initData.data);
}
}
//First add tool to file
if (initData.parse == Document::FullParse)
{
VAbstractTool::AddRecord(id, Tool::UnionDetails, initData.doc);
VAbstractTool::AddRecord(initData.id, Tool::UnionDetails, initData.doc);
//Scene doesn't show this tool, so doc will destroy this object.
unionDetails = new VToolUnionDetails(id, initData);
VAbstractPattern::AddTool(id, unionDetails);
unionDetails = new VToolUnionDetails(initData);
VAbstractPattern::AddTool(initData.id, unionDetails);
// Unfortunatelly doc will destroy all objects only in the end, but we should delete them before each FullParse
initData.doc->AddToolOnRemove(unionDetails);
}
UniteDetails(id, initData);
UniteDetails(initData);
return unionDetails;
}

View File

@ -47,18 +47,14 @@
class DialogTool;
struct VToolUnionDetailsInitData
struct VToolUnionDetailsInitData : public VAbstractToolInitData
{
VToolUnionDetailsInitData()
: d1id(NULL_ID),
: VAbstractToolInitData(),
d1id(NULL_ID),
d2id(NULL_ID),
indexD1(NULL_ID),
indexD2(NULL_ID),
scene(nullptr),
doc(nullptr),
data(nullptr),
parse(Document::FullParse),
typeCreation(Source::FromFile),
retainPieces(false)
{}
@ -66,11 +62,6 @@ struct VToolUnionDetailsInitData
quint32 d2id;
quint32 indexD1;
quint32 indexD2;
VMainGraphicsScene *scene;
VAbstractPattern *doc;
VContainer *data;
Document parse;
Source typeCreation;
bool retainPieces;
};
@ -83,7 +74,7 @@ class VToolUnionDetails : public VAbstractTool
public:
static VToolUnionDetails *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data);
static VToolUnionDetails *Create(const quint32 _id, const VToolUnionDetailsInitData &initData);
static VToolUnionDetails *Create(VToolUnionDetailsInitData initData);
static const QString ToolType;
static const QString TagDetail;
@ -129,7 +120,7 @@ private:
/** @brief indexD2 index edge in second detail. */
quint32 indexD2;
VToolUnionDetails(quint32 id, const VToolUnionDetailsInitData &initData, QObject *parent = nullptr);
VToolUnionDetails(const VToolUnionDetailsInitData &initData, QObject *parent = nullptr);
void AddDetail(QDomElement &domElement, const VPiece &d) const;
void AddToModeling(const QDomElement &domElement);