Hatch explode

Discussion forum for contributors and developers who are using the QCAD ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Post Reply
ggglo
Newbie Member
Posts: 3
Joined: Thu Apr 26, 2018 10:51 am

Hatch explode

Post by ggglo » Thu Apr 26, 2018 10:59 am

Hi Andrew:
I want to develop a pat file creator based in qcad, which can open in autocad. I want to explode the hatch entity so that autocad can show the user-defined hatch.the problem is I called getpainterpath of REntity(not solid and draft == false), but it returnd QList<RPainterPath> is empty. hope can get some help from you, thanks very much.

User avatar
andrew
Site Admin
Posts: 5604
Joined: Fri Mar 30, 2007 6:07 am

Re: Hatch explode

Post by andrew » Mon Apr 30, 2018 10:53 am

Please refer to Explode.js for an example:
https://github.com/qcad/qcad/blob/maste ... Explode.js
(search for "Hatch").

ggglo
Newbie Member
Posts: 3
Joined: Thu Apr 26, 2018 10:51 am

Re: Hatch explode

Post by ggglo » Thu May 03, 2018 2:40 am

Hi Andrew,
Thanks for the reply!
I tried but at line No.258 of Explode.js, the method getPainterPaths(false) always returned empty QList, and the reason is RHatchData::getSegments() always returned empty QList either. I tried many times but still cannot figure why. Thank you so much.
//to draw hatch

Code: Select all

        RHatchData *pData = new RHatchData(false, 1, fRotation * M_PI /180, sPatName);
        pData->setDocument(&pDocIf->getDocument());
        pData->newLoop();
        QList<RVector> verticList = area.getVertices();
        for(int i = 0; i < verticList.size() - 1; i++)
        {
            QSharedPointer<RShape> sp(new RLine(verticList[i], verticList[i + 1]));
            pData->addBoundary(sp);
            if(verticList.size() - 2 == i)
            {
                QSharedPointer<RShape> sp(new RLine(verticList[i + 1], verticList[0]));
                pData->addBoundary(sp);
            }
        };
        pData->setLineweight(RLineweight::Weight005);
        RHatchEntity* pEntity = new RHatchEntity(&pDocIf->getDocument(), *pData);
        QSharedPointer<RObject> spHatchEntity(pEntity);
        RAddObjectsOperation operation;
        operation.addObject(spHatchEntity, false, false);
        operation.apply(pDocIf->getDocument());
//to explode hatch

Code: Select all

    QSet<REntity::Id> entityIds = pDocIf->getDocument().queryAllEntities();
    foreach (REntity::Id id, entityIds)
    {
        QSharedPointer<REntity> e = pDocIf->getDocument().queryEntity(id);
        if(RS::EntityType::EntityHatch == e->getType())
        {
            QSharedPointer<RHatchEntity> hEntity = e.dynamicCast<RHatchEntity>();
            if(hEntity.isNull())
            {
                continue;
            }
            QString sName = hEntity->getData().getPatternName();
            {
                QList<RPainterPath> painterPaths = hEntity->getPainterPaths(false); //painterPaths is always empty :(
                //...
            }
        }
    }

User avatar
andrew
Site Admin
Posts: 5604
Joined: Fri Mar 30, 2007 6:07 am

Re: Hatch explode

Post by andrew » Thu May 03, 2018 9:07 am

I'd suggest to export your programmatically generated data to DXF (using RDocumentInterface::exportFile("myfile.dxf")) and load that DXF in QCAD to check if the data is correct.

ggglo
Newbie Member
Posts: 3
Joined: Thu Apr 26, 2018 10:51 am

Re: Hatch explode

Post by ggglo » Mon May 07, 2018 2:44 am

Hi Andrew:
Saving "YJG_5671fa409d.pat" of attchments in qcad path "QCAD\patterns\metric" then opening the test.dxf, you will see the hatch style. It can be exploded in qcad but it won't work in qcad project because of previous reasons.
Thank you so much.
Attachments
YJG_5671fa409d.pat
(86 Bytes) Downloaded 28 times
test.dxf
(32.6 KiB) Downloaded 28 times

Post Reply

Return to “QCAD Developers and Contributors”