Hatch explode

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

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

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: 9037
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: 9037
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 544 times
test.dxf
(32.6 KiB) Downloaded 549 times

CVH
Premier Member
Posts: 3416
Joined: Wed Sep 27, 2017 4:17 pm

Re: Hatch explode

Post by CVH » Thu Jan 02, 2020 8:49 pm

Hi,
Your pat file ends with '*'

reading your pat:
Infinite line angle 0 start (0,0) dXshift 0 dYoffset 1500
dashed line angle 90 start(0,0) dXshift 1500 dYoffset 1250 ON 1500 OFF 1500

From such a wide hatch not a lot will be seen.

How far did you get with this?
Regards,
CVH

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”