示例#1
0
/**
 * @brief RemoveReferens decrement value of reference.
 */
void VToolDetail::RemoveReferens()
{
    VDetail detail = VAbstractTool::data.GetDetail(id);
    for (ptrdiff_t i = 0; i< detail.CountNode(); ++i)
    {
        doc->DecrementReferens(detail.at(i).getId());
    }
}
示例#2
0
/**
 * @brief RefreshGeometry refresh item on scene.
 */
void VToolDetail::RefreshGeometry()
{
    this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
    QPainterPath path = VEquidistant().ContourPath(id, this->getData());
    this->setPath(path);

    VDetail detail = VAbstractTool::data.GetDetail(id);
    this->setPos(detail.getMx(), detail.getMy());
    this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
示例#3
0
/**
 * @brief GetDetailFromFile parse detail from file.
 * @param doc dom document container.
 * @param domElement tag in xml tree.
 * @return detail stored in file.
 */
QVector<VDetail> VToolUnionDetails::GetDetailFromFile(VPattern *doc, const QDomElement &domElement)
{
    QVector<VDetail> vector;
    QDomNodeList detailList = domElement.childNodes();
    qint32 num = detailList.size();
    for (qint32 i = 0; i < num; ++i)
    {
        QDomElement element = detailList.at(i).toElement();
        if (element.isNull() == false)
        {
            if (element.tagName() == VToolUnionDetails::TagDetail)
            {
                VDetail d;
                QDomNodeList nodeList = element.childNodes();
                qint32 num = nodeList.size();
                for (qint32 j = 0; j < num; ++j)
                {
                    QDomElement element = nodeList.at(j).toElement();
                    if (element.isNull() == false)
                    {
                        if (element.tagName() == VToolUnionDetails::TagNode)
                        {
                            quint32 id = doc->GetParametrUInt(element, VToolDetail::AttrIdObject, NULL_ID_STR);
                            qreal mx = qApp->toPixel(doc->GetParametrDouble(element, VAbstractTool::AttrMx, "0.0"));
                            qreal my = qApp->toPixel(doc->GetParametrDouble(element, VAbstractTool::AttrMy, "0.0"));
                            Tool tool = Tool::NodePoint;
                            NodeDetail nodeType = NodeDetail::Contour;
                            QString t = doc->GetParametrString(element, "type", "NodePoint");
                            if (t == "NodePoint")
                            {
                                tool = Tool::NodePoint;
                            }
                            else if (t == "NodeArc")
                            {
                                tool = Tool::NodeArc;
                            }
                            else if (t == "NodeSpline")
                            {
                                tool = Tool::NodeSpline;
                            }
                            else if (t == "NodeSplinePath")
                            {
                                tool = Tool::NodeSplinePath;
                            }
                            d.append(VNodeDetail(id, tool, nodeType, mx, my));
                        }
                    }
                }
                vector.append(d);
            }
        }
    }
    return vector;
}
示例#4
0
/**
 * @brief AddDetail add detail to xml file.
 * @param domElement tag in xml tree.
 * @param d detail.
 */
void VToolUnionDetails::AddDetail(QDomElement &domElement, VDetail &d)
{
    QDomElement det = doc->createElement(TagDetail);

    for (int i = 0; i < d.CountNode(); ++i)
    {
        AddNode(det, d.at(i));
    }

    domElement.appendChild(det);
}
示例#5
0
//---------------------------------------------------------------------------------------------------------------------
void VToolUnionDetails::PointsOnEdge(const VDetail &d, const quint32 &index, VPointF &p1, VPointF &p2, VContainer *data)
{
    VNodeDetail det2p1;
    VNodeDetail det2p2;
    d.NodeOnEdge(index, det2p1, det2p2);
    p1 = VPointF(*data->GeometricObject<VPointF>(det2p1.getId()));
    p2 = VPointF(*data->GeometricObject<VPointF>(det2p2.getId()));
}
示例#6
0
//---------------------------------------------------------------------------------------------------------------------
void VToolUnionDetails::FindJ(const qint32 &pointsD2, const VDetail &d2, const quint32 &indexD2, qint32 &j)
{
    if (pointsD2 == 0)
    {
        VNodeDetail node1;
        VNodeDetail node2;
        d2.NodeOnEdge(indexD2, node1, node2);
        int k = d2.RemoveEdge(indexD2).indexOfNode(node2.getId());
        if (k == d2.RemoveEdge(indexD2).CountNode()-1)
        {
            j = 0;
        }
        else
        {
            j = d2.RemoveEdge(indexD2).indexOfNode(node2.getId())+1;
        }
    }
}
示例#7
0
//---------------------------------------------------------------------------------------------------------------------
QList<quint32> VDetail::Missing(const VDetail &det) const
{
    if (d->nodes.size() == det.CountNode())
    {
        return QList<quint32>();
    }

    QSet<quint32> set1;
    for (qint32 i = 0; i < d->nodes.size(); ++i)
    {
        set1.insert(d->nodes.at(i).getId());
    }

    QSet<quint32> set2;
    for (qint32 j = 0; j < det.CountNode(); ++j)
    {
        set2.insert(det.at(j).getId());
    }

    QSet<quint32> set3 = set1.subtract(set2);

    return set3.toList();
}
示例#8
0
/**
 * @brief UpdateDetail update detail in xml tree.
 * @param domNode dom node.
 * @param d detail.
 * @return return next detail tag in xml tree if exist.
 */
QDomNode VToolUnionDetails::UpdateDetail(const QDomNode &domNode, const VDetail &d)
{
    //QDomNode domNode = domElement.firstChild();
    while (domNode.isNull() == false)
    {
        if (domNode.isElement())
        {
            QDomElement domElement = domNode.toElement();
            if (domElement.isNull() == false)
            {
                if (domElement.tagName() == VToolUnionDetails::TagDetail)
                {
                    doc->removeAllChilds(domElement);//delete all nodes in detail
                    for (int i = 0; i < d.CountNode(); ++i)
                    {
                        AddNode(domElement, d.at(i));//rewrite nodes of detail
                    }
                    break;
                }
            }
        }
    }
    return domNode.nextSibling();
}
示例#9
0
/**
 * @brief AddToFile add tag with informations about tool into file.
 */
void VToolDetail::AddToFile()
{
    VDetail detail = VAbstractTool::data.GetDetail(id);
    QDomElement domElement = doc->createElement(TagName);

    doc->SetAttribute(domElement, VDomDocument::AttrId, id);
    doc->SetAttribute(domElement, AttrName, detail.getName());
    doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(detail.getMx()));
    doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(detail.getMy()));
    doc->SetAttribute(domElement, AttrSupplement, detail.getSeamAllowance());
    doc->SetAttribute(domElement, AttrClosed, detail.getClosed());
    doc->SetAttribute(domElement, AttrWidth, detail.getWidth());

    for (ptrdiff_t i = 0; i < detail.CountNode(); ++i)
    {
       AddNode(doc, domElement, detail.at(i));
    }

    AddDet *addDet = new AddDet(domElement, doc);
    connect(addDet, &AddDet::NeedFullParsing, doc, &VPattern::NeedFullParsing);
    qApp->getUndoStack()->push(addDet);
}
示例#10
0
/**
 * @brief VToolDetail 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 scene pointer to scene.
 * @param parent parent object
 */
VToolDetail::VToolDetail(VPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation,
                         VMainGraphicsScene *scene, QGraphicsItem *parent)
    :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialog(nullptr), sceneDetails(scene)
{
    VDetail detail = data->GetDetail(id);
    for (ptrdiff_t i = 0; i< detail.CountNode(); ++i)
    {
        switch (detail.at(i).getTypeTool())
        {
            case (Tool::NodePoint):
                InitTool<VNodePoint>(scene, detail.at(i));
                break;
            case (Tool::NodeArc):
                InitTool<VNodeArc>(scene, detail.at(i));
                break;
            case (Tool::NodeSpline):
                InitTool<VNodeSpline>(scene, detail.at(i));
                break;
            case (Tool::NodeSplinePath):
                InitTool<VNodeSplinePath>(scene, detail.at(i));
                break;
            default:
                qDebug()<<"Get wrong tool type. Ignore.";
                break;
        }
        doc->IncrementReferens(detail.at(i).getId());
    }
    this->setFlag(QGraphicsItem::ItemIsMovable, true);
    this->setFlag(QGraphicsItem::ItemIsSelectable, true);
    RefreshGeometry();
    this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
    this->setFlag(QGraphicsItem::ItemIsFocusable, true);
    if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
    {
        AddToFile();
        if (typeCreation != Source::FromTool)
        {
            qApp->getUndoStack()->endMacro();
        }
    }
}
示例#11
0
/**
 * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
 */
void VToolDetail::RefreshDataInFile()
{
    QDomElement domElement = doc->elementById(QString().setNum(id));
    if (domElement.isElement())
    {
        VDetail det = VAbstractTool::data.GetDetail(id);
        doc->SetAttribute(domElement, AttrName, det.getName());
        doc->SetAttribute(domElement, AttrSupplement, QString().setNum(det.getSeamAllowance()));
        doc->SetAttribute(domElement, AttrClosed, QString().setNum(det.getClosed()));
        doc->SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth()));
        doc->RemoveAllChild(domElement);
        for (ptrdiff_t i = 0; i < det.CountNode(); ++i)
        {
           AddNode(doc, domElement, det.at(i));
        }
    }
}
示例#12
0
/**
 * @brief Create help create tool from GUI.
 * @param dialog dialog.
 * @param scene pointer to scene.
 * @param doc dom document container.
 * @param data container with variables.
 */
void VToolDetail::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data)
{
    SCASSERT(dialog != nullptr);
    DialogDetail *dialogTool = qobject_cast<DialogDetail*>(dialog);
    SCASSERT(dialogTool != nullptr);
    VDetail detail = dialogTool->getDetails();
    VDetail det;
    qApp->getUndoStack()->beginMacro("add detail");
    for (ptrdiff_t i = 0; i< detail.CountNode(); ++i)
    {
        quint32 id = 0;
        switch (detail.at(i).getTypeTool())
        {
            case (Tool::NodePoint):
            {
                id = CreateNode<VPointF>(data, detail.at(i).getId());
                VNodePoint::Create(doc, data, id, detail.at(i).getId(), Document::FullParse, Source::FromGui);
            }
            break;
            case (Tool::NodeArc):
            {
                id = CreateNode<VArc>(data, detail.at(i).getId());
                VNodeArc::Create(doc, data, id, detail.at(i).getId(), Document::FullParse, Source::FromGui);
            }
            break;
            case (Tool::NodeSpline):
            {
                id = CreateNode<VSpline>(data, detail.at(i).getId());
                VNodeSpline::Create(doc, data, id, detail.at(i).getId(), Document::FullParse, Source::FromGui);
            }
            break;
            case (Tool::NodeSplinePath):
            {
                id = CreateNode<VSplinePath>(data, detail.at(i).getId());
                VNodeSplinePath::Create(doc, data, id, detail.at(i).getId(), Document::FullParse, Source::FromGui);
            }
            break;
            default:
                qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
                break;
        }
        VNodeDetail node(id, detail.at(i).getTypeTool(), NodeDetail::Contour);
        det.append(node);
    }
    det.setName(detail.getName());
    det.setWidth(detail.getWidth());
    Create(0, det, scene, doc, data, Document::FullParse, Source::FromGui);
}
示例#13
0
/**
 * @brief AddToNewDetail create united detail adding one node per time.
 * @param tool tool that make union.
 * @param doc dom document container.
 * @param data container with variables.
 * @param newDetail united detail.
 * @param det detail what we union.
 * @param i index node in detail.
 * @param idTool id tool union details.
 * @param dx bias node x axis.
 * @param dy bias node y axis.
 * @param pRotate point rotation.
 * @param angle angle rotation.
 */
void VToolUnionDetails::AddToNewDetail(QObject *tool, VPattern *doc, VContainer *data, VDetail &newDetail,
                                       const VDetail &det, const int &i, const quint32 &idTool, const qreal &dx,
                                       const qreal &dy, const quint32 &pRotate, const qreal &angle)
{
    quint32 id = 0, idObject = 0;
    switch (det.at(i).getTypeTool())
    {
        case (Tool::NodePoint):
        {
            if ( qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && (pRotate == 0))
            {
                id = det.at(i).getId();
            }
            else
            {
                VPointF *point = new VPointF(*data->GeometricObject<VPointF>(det.at(i).getId()));
                point->setMode(Draw::Modeling);
                BiasRotatePoint(point, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
                                angle);
                idObject = data->AddGObject(point);
                VPointF *point1 = new VPointF(*point);
                point1->setMode(Draw::Modeling);
                id = data->AddGObject(point1);
                VNodePoint::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
            }
        }
        break;
        case (Tool::NodeArc):
        {
            if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0)
            {
                id = det.at(i).getId();
            }
            else
            {
                const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(det.at(i).getId());
                VPointF p1 = VPointF(arc->GetP1(), "A", 0, 0);
                BiasRotatePoint(&p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
                VPointF p2 = VPointF(arc->GetP2(), "A", 0, 0);
                BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
                VPointF *center = new VPointF(arc->GetCenter());
                BiasRotatePoint(center, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
                                angle);

                QLineF l1(center->toQPointF(), p1.toQPointF());
                QLineF l2(center->toQPointF(), p2.toQPointF());
                center->setMode(Draw::Modeling);
                quint32 idCenter = data->AddGObject(center);
                Q_UNUSED(idCenter);
                VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(),
                                 l1.angle(), QString().setNum(l1.angle()), l2.angle(),
                                 QString().setNum(l2.angle()));
                arc1->setMode(Draw::Modeling);
                idObject = data->AddGObject(arc1);

                VArc *arc2 = new VArc(*arc1);
                arc2->setMode(Draw::Modeling);
                id = data->AddGObject(arc2);

                VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
            }
        }
        break;
        case (Tool::NodeSpline):
        {
            if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0)
            {
                id = det.at(i).getId();
            }
            else
            {
                const QSharedPointer<VSpline> spline = data->GeometricObject<VSpline>(det.at(i).getId());

                VPointF *p1 = new VPointF(spline->GetP1());
                BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
                //quint32 idP1 = data->AddGObject(p1);

                VPointF p2 = VPointF(spline->GetP2());
                BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);

                VPointF p3 = VPointF(spline->GetP3());
                BiasRotatePoint(&p3, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);

                VPointF *p4 = new VPointF(spline->GetP4());
                BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
                //quint32 idP4 = data->AddGObject(p4);

                VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0,
                Draw::Modeling);
                idObject = data->AddGObject(spl);

                VSpline *spl1 = new VSpline(*spl);
                spl1->setMode(Draw::Modeling);
                id = data->AddGObject(spl1);
                VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);

                delete p4;
                delete p1;
            }
        }
        break;
        case (Tool::NodeSplinePath):
        {
            if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0)
            {
                id = det.at(i).getId();
            }
            else
            {
                VSplinePath *path = new VSplinePath();
                path->setMode(Draw::Modeling);
                const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId());
                qint32 k = splinePath->getMaxCountPoints();
                for (qint32 i = 1; i <= splinePath->Count(); ++i)
                {
                    VSpline spline(splinePath->at(i-1).P(), splinePath->at(i).P(),
                            splinePath->at(i-1).Angle2(), splinePath->at(i).Angle1(), splinePath->at(i-1).KAsm2(),
                            splinePath->at(i).KAsm1(), splinePath->getKCurve());

                    VPointF *p1 = new VPointF(spline.GetP1());
                    BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
                                    angle);
                    //quint32 idP1 = data->AddGObject(p1);
                    --k;

                    VPointF p2 = VPointF(spline.GetP2());
                    BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
                                    angle);

                    VPointF p3 = VPointF(spline.GetP3());
                    BiasRotatePoint(&p3, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
                                    angle);

                    VPointF *p4 = new VPointF(spline.GetP4());
                    BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
                                    angle);
                    //quint32 idP4 = data->AddGObject(p4);
                    --k;

                    VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve());
                    if (i==1)
                    {
                        path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1()+180,
                                                  splinePath->at(i-1).KAsm2(), spl.GetAngle1()));
                    }
                    path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2(),
                                              splinePath->at(i).KAsm2(), spl.GetAngle2()+180));
                    delete p4;
                    delete p1;
                }
                while (k>=0)
                {
                    data->getNextId();
                    --k;
                }
                idObject = data->AddGObject(path);

                VSplinePath *path1 = new VSplinePath(*path);
                path1->setMode(Draw::Modeling);
                id = data->AddGObject(path1);
                VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
            }
        }
        break;
        default:
            qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
            break;
    }
    newDetail.append(VNodeDetail(id, det.at(i).getTypeTool(), NodeDetail::Contour));
}
示例#14
0
/**
 * @brief Create help create tool.
 * @param _id tool id, 0 if tool doesn't exist yet.
 * @param d1 first detail.
 * @param d2 second detail.
 * @param d1id id first detail.
 * @param d2id id second detail.
 * @param indexD1 index edge in first detail.
 * @param indexD2 index edge in second detail.
 * @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.
 */
VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDetail &d2,
                                             const quint32 &d1id, const quint32 &d2id, const quint32 &indexD1,
                                             const quint32 &indexD2, VMainGraphicsScene *scene, VPattern *doc,
                                             VContainer *data, const Document &parse, const Source &typeCreation)
{
    VToolUnionDetails *unionDetails = 0;
    quint32 id = _id;
    if (typeCreation == Source::FromGui)
    {
        id = data->getNextId();
    }
    else
    {
        if (parse != Document::FullParse)
        {
            doc->UpdateToolData(id, data);
        }
    }
    VAbstractTool::AddRecord(id, Tool::UnionDetails, doc);
    if (parse == Document::FullParse)
    {
        //Scene doesn't show this tool, so doc will destroy this object.
        unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation, doc);
        QHash<quint32, VDataTool*>* tools = doc->getTools();
        tools->insert(id, unionDetails);
        for (int i = 0; i < d1.CountNode(); ++i)
        {
            doc->IncrementReferens(d1.at(i).getId());
        }
        for (int i = 0; i < d2.CountNode(); ++i)
        {
            doc->IncrementReferens(d2.at(i).getId());
        }

    }
    VNodeDetail det1p1;
    VNodeDetail det1p2;
    d1.NodeOnEdge(indexD1, det1p1, det1p2);
    Q_UNUSED(det1p2);

    VPointF point1;
    VPointF point2;
    PointsOnEdge(d1, indexD1, point1, point2, data);

    VPointF point3;
    VPointF point4;
    PointsOnEdge(d2, indexD2, point3, point4, data);

    const qreal dx = point1.x() - point4.x();
    const qreal dy = point1.y() - point4.y();

    point3.setX(point3.x()+dx);
    point3.setY(point3.y()+dy);

    point4.setX(point4.x()+dx);
    point4.setY(point4.y()+dy);

    const qreal angle = QLineF(point4.toQPointF(), point3.toQPointF()).angleTo(QLineF(point1.toQPointF(),
                                                                                      point2.toQPointF()));
    qint32 pointsD2 = 0; //Keeps count points second detail, what we already add.

    if (typeCreation == Source::FromGui)
    {
        qint32 j = 0, i = 0;
        VDetail newDetail;
        do
        {
            AddToNewDetail(unionDetails, doc, data, newDetail, d1.RemoveEdge(indexD1), i, id);
            ++i;
            if (i > d1.indexOfNode(det1p1.getId()) && pointsD2 < d2.RemoveEdge(indexD2).CountNode()-2)
            {
                do
                {
                    FindJ(pointsD2, d2, indexD2, j);
                    if (pointsD2 == d2.RemoveEdge(indexD2).CountNode() -2)
                    {
                        break;
                    }
                    if (j >= d2.RemoveEdge(indexD2).CountNode())
                    {
                        j=0;
                    }
                    AddToNewDetail(unionDetails, doc, data, newDetail, d2.RemoveEdge(indexD2), j, id, dx, dy,
                                   det1p1.getId(), angle);
                    ++pointsD2;
                    ++j;
                } while (pointsD2 < d2.RemoveEdge(indexD2).CountNode());
            }
        } while (i < d1.RemoveEdge(indexD1).CountNode());

        newDetail.setName("Detail");
        newDetail.setWidth(d1.getWidth());
        VToolDetail::Create(0, newDetail, scene, doc, data, parse, Source::FromTool);
        QHash<quint32, VDataTool*>* tools = doc->getTools();
        SCASSERT(tools != nullptr);

        {
            VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(d1id));
            SCASSERT(toolDet != nullptr);
            bool ask = false;
            toolDet->Remove(ask);
        }

        VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(d2id));
        SCASSERT(toolDet != nullptr);
        bool ask = false;
        toolDet->Remove(ask);
    }
    else
    {
        quint32 idCount = 0;
        qint32 j = 0, i = 0;
        do
        {
            UpdatePoints(id, data, d1.RemoveEdge(indexD1), i, idCount);
            ++i;
            if (i > d1.indexOfNode(det1p1.getId()) && pointsD2 < d2.RemoveEdge(indexD2).CountNode()-2)
            {
                do
                {
                    FindJ(pointsD2, d2, indexD2, j);
                    if (pointsD2 == d2.RemoveEdge(indexD2).CountNode()-2)
                    {
                        break;
                    }
                    if (j >= d2.RemoveEdge(indexD2).CountNode())
                    {
                        j=0;
                    }
                    UpdatePoints(id, data, d2.RemoveEdge(indexD2), j, idCount, dx, dy, det1p1.getId(), angle);
                    ++pointsD2;
                    ++j;
                } while (pointsD2 < d2.RemoveEdge(indexD2).CountNode());
            }
        } while (i<d1.RemoveEdge(indexD1).CountNode());
    }
    return nullptr;
}
示例#15
0
/**
 * @brief UpdatePoints update data for united details.
 * @param idDetail id united detail.
 * @param data container with variables.
 * @param det detail what we union.
 * @param i index node in detail.
 * @param idCount count updated or created objects.
 * @param dx bias node x axis.
 * @param dy bias node y axis.
 * @param pRotate point rotation.
 * @param angle angle rotation.
 */
void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data, const VDetail &det, const int &i,
                                     quint32 &idCount, const qreal &dx, const qreal &dy, const quint32 &pRotate,
                                     const qreal &angle)
{
    switch (det.at(i).getTypeTool())
    {
        case (Tool::NodePoint):
        {
            if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0)
            {
                VPointF *point = new VPointF(*data->GeometricObject<VPointF>(det.at(i).getId()));
                point->setMode(Draw::Modeling);
                BiasRotatePoint(point, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
                ++idCount;
                data->UpdateGObject(idDetail+idCount, point);

                ++idCount;
            }
        }
        break;
        case (Tool::NodeArc):
        {
            if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0)
            {
                const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(det.at(i).getId());
                VPointF p1 = VPointF(arc->GetP1());
                BiasRotatePoint(&p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
                VPointF p2 = VPointF(arc->GetP2());
                BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
                VPointF *center = new VPointF(arc->GetCenter());
                BiasRotatePoint(center, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
                                angle);

                QLineF l1(center->toQPointF(), p1.toQPointF());
                QLineF l2(center->toQPointF(), p2.toQPointF());
                ++idCount;
                center->setMode(Draw::Modeling);
                data->UpdateGObject(idDetail+idCount, center);
                VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(), l1.angle(),
                                     QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle()));
                arc1->setMode(Draw::Modeling);
                ++idCount;
                data->UpdateGObject(idDetail+idCount, arc1);

                ++idCount;
            }
        }
        break;
        case (Tool::NodeSpline):
        {
            if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0)
            {
                const QSharedPointer<VSpline> spline = data->GeometricObject<VSpline>(det.at(i).getId());

                VPointF *p1 = new VPointF(spline->GetP1());
                BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
                ++idCount;
                data->UpdateGObject(idDetail+idCount, p1);

                VPointF p2 = VPointF(spline->GetP2());
                BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);

                VPointF p3 = VPointF(spline->GetP3());
                BiasRotatePoint(&p3, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);

                VPointF *p4 = new VPointF(spline->GetP4());
                BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
                ++idCount;
                data->UpdateGObject(idDetail+idCount, p4);

                VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0,
                Draw::Modeling);

                ++idCount;
                data->UpdateGObject(idDetail+idCount, spl);

                ++idCount;
            }
        }
        break;
        case (Tool::NodeSplinePath):
        {
            if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0)
            {
                VSplinePath *path = new VSplinePath();
                path->setMode(Draw::Modeling);
                const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId());
                SCASSERT(splinePath != nullptr);
                qint32 k = splinePath->getMaxCountPoints();
                for (qint32 i = 1; i <= splinePath->Count(); ++i)
                {
                    VSpline spline(splinePath->at(i-1).P(), splinePath->at(i).P(),
                            splinePath->at(i-1).Angle2(), splinePath->at(i).Angle1(), splinePath->at(i-1).KAsm2(),
                            splinePath->at(i).KAsm1(), splinePath->getKCurve());

                    VPointF *p1 = new VPointF(spline.GetP1());
                    BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
                                    angle);
                    ++idCount;
                    data->UpdateGObject(idDetail+idCount, p1);
                    --k;

                    VPointF p2 = VPointF(spline.GetP2());
                    BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
                                    angle);

                    VPointF p3 = VPointF(spline.GetP3());
                    BiasRotatePoint(&p3, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
                                    angle);

                    VPointF *p4 = new VPointF(spline.GetP4());
                    BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
                                    angle);
                    ++idCount;
                    data->UpdateGObject(idDetail+idCount, p4);
                    --k;

                    VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve());
                    if (i==1)
                    {
                        path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1()+180,
                                                  splinePath->at(i-1).KAsm2(), spl.GetAngle1()));
                    }
                    path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2(),
                                              splinePath->at(i).KAsm2(), spl.GetAngle2()+180));
                }

                while (k>=0)
                {
                    data->getNextId();
                    --k;
                    ++idCount;
                }

                ++idCount;
                data->UpdateGObject(idDetail+idCount, path);

                ++idCount;
            }
        }
        break;
        default:
            qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
            break;
    }
}