Fill a solid circle with QCAD dxflib [Solved]
Moderator: andrew
Fill a solid circle with QCAD dxflib [Solved]
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?
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.
Re: Fill a solid circle with QCAD dxflib
Hi,
Are you working in radians or are you using degrees ...
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:
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. (only found dxflib/2.5/classref)
Regards,
CVH
Are you working in radians or are you using degrees ...
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:
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. (only found dxflib/2.5/classref)
Regards,
CVH
Re: Fill a solid circle with QCAD dxflib
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:
this is the dxf section added when I insert the solid hatch:
How this can be done programmatically with dxflib?
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
Re: Fill a solid circle with QCAD dxflib
A solid fill of an arbitrary closed shape is by hatching it.
It is even possible to omit the boundary shape itself.
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
Re: Fill a solid circle with QCAD dxflib
Finally, I realized why pasting the example in my code was not working; I was using this version and the hatch seems not to be working in that version (the sample too). Setting the version to then it works.
Thanks for the help.
Code: Select all
DL_Codes::version exportVersion = DL_Codes::AC1009;
Code: Select all
DL_Codes::version exportVersion = DL_Codes::AC1015;
Thanks for the help.
Re: Fill a solid circle with QCAD dxflib
Both given examples included DL_Codes::AC1015.
Glad it worked out ...
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
Glad it worked out ...
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
Re: Fill a solid circle with QCAD dxflib
Here is a dxf
For some reason even if I use the BYLAYER fill color, the fill is black ...
with a single circle. For some reason even if I use the BYLAYER fill color, the fill is black ...
Re: Fill a solid circle with QCAD dxflib
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 ... X,Y&Z are blank.
Regards,
CVH
Re: Fill a solid circle with QCAD dxflib
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
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