Help adding support for dxf arc on dxf_outlines.py
Hi,
I'm trying to add dxf arc to the dxf_outlines extension but I'm having some problems:
At first I'm using only the arcs that have the same radius, basically the code goes like this
def dxf_arc(self,arc_info): """Draw an arc in the DXF format""" self.handle += 1 self.dxf_add(" 0\nARC\n 5\n%x\n100\nAcDbEntity\n 8\n%s\n 62\n%d\n100\nAcDbCircle\n" % (self.handle, self.layer, self.color)) self.dxf_add(" 10\n%f\n 20\n%f\n 30\n0.0\n 40\n%f\n100\nAcDbArc\n 50\n%f\n 51\n%f\n" % (arc_info[0],arc_info[1], arc_info[2], arc_info[3], arc_info[4]) def arc_info(previous_end_point, arc_path): Ax = previous_end_point[0] Ay = previous_end_point[1] radius = arc_path[1] Bx = arc_path[-2] By = arc_path[-1] ... return [center_point_x, centerpoint_y, radius, start_angle, end_angle]
The problem is for this to work it must be before converting the path to superpath or all the svg arc information will be lost as it will become a curves but somewhere in the code there's the information that there is some issues when transforming(matrix) the path before converting it to superpath.
So I'm thinking if it would be possible to use something like simplepath (but now it's decrepted) and convert the path into segments and then the segments to curve as they go into the process_shape loop and separating the arcs that fulfill the conditions(same radius) from the others that should be converted to curves and then to dxf spline.
It would go like this:
path -> transform matrix -> simplepath -> separate the arcs from the others (M L C etc) -> arcs goes to arc_info and the others goes to either dxf line or dxf spline
as opposed to what it is now
path -> superpath -> transform matrix -> separed lines from curves to go to dxf line and dxf spline respectively
So my questions are :
How to convert the path to some sort of superpath but without converting it curves?
Does a command to do this exist or should I write a function to do it?
And if I should write one, what's the format of a superpath so it could match with my function?
What was the issues of having the transform matrix before converting it to a superpath?
It is possible to do it the way i intend?
Any help would be appreciated
Hi Sandro,
I'll try my best to answer each of your questions:
On Tue, 2020-09-29 at 02:15 +0100, Sandro Duarte wrote:
How to convert the path to some sort of superpath but without converting it curves?
CubicSuperPaths are formatted as bezier lists. There aren't any strait lines, or even close path instructions. When they are converted back to paths these elements are inferred.
But as you can imagine inferring an arc would be really hard.
Does a command to do this exist or should I write a function to do it?
No function exists. Only write one if you really need to, and consider adding it to the super path or utilities functions so it's widely available. But...
And if I should write one, what's the format of a superpath so it could match with my function?
The format is bezier, so there's no format to fit an arc into it (that I know of).
What was the issues of having the transform matrix before converting it to a superpath?
There shouldn't be a problem with transforming paths, if there is and you are seeing some problematic results please report them. It's important to fix issues of transformation and path maths because they are key to so many complex extensions.
It is possible to do it the way i intend?
I don't think it is. It sounds very much like you need to take a step back from SuperPaths and use the regular segmented paths directly. This means looping through the path to get subpaths and then looping through those to get lists of Line, Curve, Arc objects.
It should be possible to get any information from the segments you would have gotten from the superpath. The logic for the conversion is in inkex/paths.py:1395 and it sounds like you may just need the previous coordinates, and be sure to convert to absolute coordinates to eliminate a source of uncertainty.
Come to chat.inkscape.org we have an extensions channel.
Best Regards, Martin Owens Herpetarium Janitor
participants (2)
-
doctormo@gmail.com
-
Sandro Duarte