Further requests for assistance with Python extensions
I'm now in the process of optimising and documenting my Inkscape extensions that implement the International Orienteering Federation mapping standards. There are some areas of the extensions that I would like to improve to make them more universal / intuitive.
1) Currently, a number of my routines apply formatting and patterns of tags or dots to paths (strokes). I would like to extend the routines to also be compatible with rectangles and arcs / ellipses. I assume that the routines to do most of what I want already exist in one or other of the 'helper' files like cubicsuperpath, pathmodifier and simpletransform, but as yet I've not worked out how to make them work for me. I need to understand how to implement the following from within a Python extension:
a) Convert a rectangle to a path. Will rectToPath in pathmodifier do this and, if so, what do I need to provide for self amd node? b) Convert an arc/ellipse to a path. Will ArcToPath in cubicsuperpath do this and, if so, what do I need to provide for p1 and params?
2) I also need to understand how to apply a transform to a path (i.e. embed the transformation into the path so the transform is not required) so that effects applied to a heavil transformed path (as can happen when using ellipses / arcs) are applied correctly. Will one of the routines in simpletransform do what I want and, if so, which one and what would I need to supply to it?
3) I still need to provide the capability via an extension to convert a line into two lines of a given line width and a set distance apart. This will need to work with curved paths, both open and closed. The way that I would do this manually in Inkscape would be to create a stroke, duplicate it, set the widths of the two strokes such that the lower is the width of the two lines plus the gap and the upper is the width of the gap, convert both strokes to paths using Path - Stroke to Path and then to use the Path - Difference function to leave two lines of the required width and separation. How could I go about recreating this from within a extension? Is there an easier method to do this, given that the two lines should not be joined at the ends?
Still outstanding from a previous request are a couple of unanswered questions (rephrased):
4) Ho would I go about detecting whether a point lies within the bounds of a closed shape passed to a Python extension? Is there an existing routine in one of the Python extension 'helper' files that can do this?
5) How would I go about implementing a method to detect collision / distance between dots from within an extension? I'd like to implement something similar to the 'Remove Overlaps' capability available within the 'Align and Distribute' dialog as part of the routine generating the dots, but with a single (polar - sqrt(x^2 * y^2)) variable related to the user-selected dot density determining how close the dots can be placed to each other. I can see that this could get complex when the area, and hence the number of dots, gets large.
With regard to these last two, I believe there may be something possible using py2geom, but where do I find details of this? What are its capabilities and are they documented anywhere?
----- Jon
Jon wrote:
... a) Convert a rectangle to a path. Will rectToPath in pathmodifier do this and, if so, what do I need to provide for self amd node?
The self parameter is nothing to worry about, it has to do with Python's class syntax (you can compare it to explicitly passing the this pointer in C++, if that helps): http://docs.python.org/tutorial/classes.html#class-objects
From what I see in the code the node parameter should get an XML/SVG node.
b) Convert an arc/ellipse to a path. Will ArcToPath in
cubicsuperpath do this and, if so, what do I need to provide for p1 and params?
It can probably do that, but it appears to be used internally when parsing paths, so I'm not quite sure what the parameters are exactly. But you could try figuring it out by looking at CubicSuperPath and perhaps placing a few prints here and there.
- I also need to understand how to apply a transform to a path (i.e.
embed the transformation into the path so the transform is not required) so that effects applied to a heavil transformed path (as can happen when using ellipses / arcs) are applied correctly. Will one of the routines in simpletransform do what I want and, if so, which one and what would I need to supply to it?
applyTransformToPath would be the likely candidate. It needs a matrix (mat, a list of lists, see parseTransform) and a "path" (probably as returned by CubicSuperPath).
I still need to provide the capability via an extension to
convert a line into two lines of a given line width and a set distance apart. This will need to work with curved paths, both open and closed. The way that I would do this manually in Inkscape would be to create a stroke, duplicate it, set the widths of the two strokes such that the lower is the width of the two lines plus the gap and the upper is the width of the gap, convert both strokes to paths using _P_ath - _S_troke to Path and then to use the _P_ath - _D_ifference function to leave two lines of the required width and separation. How could I go about recreating this from within a extension? Is there an easier method to do this, given that the two lines should not be joined at the ends?
Possibly the python bindings for lib2geom can help you here. I'd also look at using inset/outset.
... With regard to these last two, I believe there may be something possible using py2geom, but where do I find details of this? What are its capabilities and are they documented anywhere?
In the python shell, import the python bindings and use help(...) (fill in the module name, a class name, or a function name).
participants (2)
-
Jasper van de Gronde
-
Jon