Fill a solid circle with QCAD dxflib [Solved]

Please use this forum to post feedback and suggestions related to dxflib.

Moderator: andrew

Post Reply
spiovesan
Newbie Member
Posts: 4
Joined: Mon Jan 09, 2023 8:10 am

Fill a solid circle with QCAD dxflib [Solved]

Post by spiovesan » Mon Jan 09, 2023 10:55 am

I use QCAD C++ dxflib to create dxf files.
I can create shapes as circles, but I cannot fill them with a solid hatch. I cannot figure it out from the examples.
May you help me?
Last edited by spiovesan on Tue Jan 17, 2023 4:06 pm, edited 1 time in total.

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

Re: Fill a solid circle with QCAD dxflib

Post by CVH » Mon Jan 09, 2023 10:17 pm

Hi,
Are you working in radians or are you using degrees ... :roll:
Read: https://www.qcad.org/rsforum/viewtopic. ... 941&#p8942


Or maybe the issue is based on how boundaries of a Hatch are defined.

If we create a circular hatched area with the QCAD GUI then it is initially stored as Circle for boundary until saved/reloaded.
After reloading they appear to be stored as a full 2PI Arc ... Or the bulging factor = 1.66312e+16.
That itself is an error because the bulging factor of an Arc is equal to tan(Sweep/4) and for a full circular Arc the tangent of PI/2 does not exist.

The same is true for Polylines with bulging segments and in a way that was fixed.
Newer art is that a Circle explodes to a Polyline with 2 semi circular arcs ... Or both the bulging factors are 1.00 and thus not an error.

I found 'the examples' via Stack Overflow linked to: :wink:
https://github.com/qcad/qcad/blob/maste ... b/main.cpp
This shows how a 2PI Arc segment is added to a hatch with one single boundary loop.
All starts with configuring attributes in line 70 and ends in line 95.

For a solid hatch DL_HatchData data(1, true, 1.0, 0.0, pattern, 0.0, 0.0);
pattern should not matter I think, perhaps an empty string or 'SOLID'.
For now I can not pinpoint what the values in red are for. :oops: (only found dxflib/2.5/classref)

Regards,
CVH

spiovesan
Newbie Member
Posts: 4
Joined: Mon Jan 09, 2023 8:10 am

Re: Fill a solid circle with QCAD dxflib

Post by spiovesan » Tue Jan 10, 2023 12:41 pm

Thanks,
I don't know if I should call it a hatch, but my goal is to fill with solid white a circle I have inserted.
Looking at the dxf file (done with QCAD), if
this is the simple circle:

Code: Select all

AcDbCircle
 10
0.0
 20
0.0
 30
0.0
 40
100.0
  0

this is the dxf section added when I insert the solid hatch:

Code: Select all

HATCH
  5
109
330
127
100
AcDbEntity
  8
0
440
 33554687
100
AcDbHatch
 10
0.0
 20
0.0
 30
0.0
210
0.0
220
0.0
230
1.0
  2
SOLID
 70
     1
 71
     0
 91
        1
 92
        0
 93
        1
 72
     2
 10
0.0
 20
0.0
 40
100.0
 50
0.0
 51
360.0
 73
     1
 97
        0
 75
     0
 76
     1
 98
        0
  0
How this can be done programmatically with dxflib?

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

Re: Fill a solid circle with QCAD dxflib

Post by CVH » Tue Jan 10, 2023 8:56 pm

spiovesan wrote:
Tue Jan 10, 2023 12:41 pm
I don't know if I should call it a hatch.
A solid fill of an arbitrary closed shape is by hatching it.
It is even possible to omit the boundary shape itself.
spiovesan wrote:
Tue Jan 10, 2023 12:41 pm
How this can be done programmatically with dxflib?
I think the linked examples speak for themselves.
https://github.com/qcad/qcad/blob/maste ... b/main.cpp
Line 70 : set attributes
Line 73 : start hatch with one loop (A hatch can have multiple boundary loops)
Line 77 : start loop 1
Line 81 : write edge (In this case one single edge ... a full arc See: https://qcad.org/doc/dxflib/2.5/classre ... _data.html)
Line 92 : end loop 1
Line 95 : end hatch

This one is very similar:
https://www.qcad.org/rsforum/viewtopic. ... 941&#p8942

That is how far I can help you with this.

Regards,
CVH

spiovesan
Newbie Member
Posts: 4
Joined: Mon Jan 09, 2023 8:10 am

Re: Fill a solid circle with QCAD dxflib

Post by spiovesan » Mon Jan 16, 2023 7:53 am

Finally, I realized why pasting the example in my code was not working; I was using this version

Code: Select all

DL_Codes::version exportVersion = DL_Codes::AC1009;
and the hatch seems not to be working in that version (the sample too). Setting the version to

Code: Select all

DL_Codes::version exportVersion = DL_Codes::AC1015;
then it works.

Thanks for the help.

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

Re: Fill a solid circle with QCAD dxflib

Post by CVH » Mon Jan 16, 2023 8:25 am

Both given examples included DL_Codes::AC1015. :wink:

Glad it worked out ... :P
Could you provide the dxf with the full arc just as reference?
I suspect the bulge to be 1.66312e+16 what in fact is an error.
The arc is then 359.99999999999998622° what is about 1ULP less than a circular arc.

Please add [Solved] to the title of your initial posting.

Regards,
CVH

spiovesan
Newbie Member
Posts: 4
Joined: Mon Jan 09, 2023 8:10 am

Re: Fill a solid circle with QCAD dxflib

Post by spiovesan » Mon Jan 16, 2023 2:50 pm

Here is a dxf
hatch.dxf
(4.23 KiB) Downloaded 736 times
with a single circle.
For some reason even if I use the BYLAYER fill color, the fill is black :? ...

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

Re: Fill a solid circle with QCAD dxflib

Post by CVH » Mon Jan 16, 2023 7:45 pm

spiovesan wrote:
Mon Jan 16, 2023 2:50 pm
For some reason even if I use the BYLAYER fill color, the fill is black ...
There is indeed a Black Hatch -> handle 0x1000e
But also a mystery Black Hatch -> handle 0x1000c
And a circle R=10 -> handle 0x1000d

On AutoSave I get:
Exception occurred. Entity NOT saved: 1000c

This Hatch has zero vertices listed :shock: ... X,Y&Z are blank. :roll:

Regards,
CVH

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

Re: Fill a solid circle with QCAD dxflib

Post by CVH » Mon Jan 16, 2023 7:59 pm

Have a look here:
https://qcad.org/doc/dxflib/2.5/classre ... butes.html

Color is the second attribute and it is of type 'int'.
See also: https://qcad.org/doc/dxflib/2.5/classre ... codes.html

Regards,
CVH

Post Reply

Return to “dxflib Suggestions and Feedback”