Page 1 of 1

Hatch explode

Posted: Thu Apr 26, 2018 10:59 am
by ggglo
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.

Re: Hatch explode

Posted: Mon Apr 30, 2018 10:53 am
by andrew
Please refer to Explode.js for an example:
https://github.com/qcad/qcad/blob/maste ... Explode.js
(search for "Hatch").

Re: Hatch explode

Posted: Thu May 03, 2018 2:40 am
by ggglo
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 :(
                //...
            }
        }
    }

Re: Hatch explode

Posted: Thu May 03, 2018 9:07 am
by andrew
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.

Re: Hatch explode

Posted: Mon May 07, 2018 2:44 am
by ggglo
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.

Re: Hatch explode

Posted: Thu Jan 02, 2020 8:49 pm
by CVH
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