2020-08-20 02:41:10 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import inkex
|
|
|
|
from inkex.paths import Path
|
|
|
|
from inkex import Circle
|
|
|
|
|
2021-06-02 23:30:37 +02:00
|
|
|
class DrawDirections(inkex.EffectExtension):
|
2020-08-20 02:41:10 +02:00
|
|
|
|
2020-08-20 02:59:53 +02:00
|
|
|
def drawCircle(self, group, color, point):
|
|
|
|
style = inkex.Style({'stroke': 'none', 'fill': color})
|
|
|
|
startCircle = group.add(Circle(cx=str(point[0]), cy=str(point[1]), r=str(self.svg.unittouu(str(self.options.dotsize/2) + "px"))))
|
|
|
|
startCircle.style = style
|
|
|
|
|
2021-04-15 17:03:47 +02:00
|
|
|
def add_arguments(self, pars):
|
|
|
|
pars.add_argument("--dotsize", type=int, default=10, help="Dot size (px) for self-intersecting points")
|
2020-08-20 02:41:10 +02:00
|
|
|
|
|
|
|
def effect(self):
|
2020-08-20 02:59:53 +02:00
|
|
|
dot_group = self.svg.add(inkex.Group())
|
2020-08-20 02:41:10 +02:00
|
|
|
|
2021-06-02 23:30:37 +02:00
|
|
|
for node in self.svg.selection.filter(inkex.PathElement).values():
|
2020-08-20 02:41:10 +02:00
|
|
|
points = list(node.path.end_points)
|
|
|
|
start = points[0]
|
|
|
|
end = points[len(points) - 1]
|
2020-08-20 02:59:53 +02:00
|
|
|
|
|
|
|
if start[0] == end[0] and start[1] == end[1]:
|
|
|
|
self.drawCircle(dot_group, '#00FF00', start)
|
|
|
|
self.drawCircle(dot_group, '#FFFF00', points[1]) #draw one point which gives direction of the path
|
|
|
|
else: #open contour with start and end point
|
|
|
|
self.drawCircle(dot_group, '#FF0000', start)
|
|
|
|
self.drawCircle(dot_group, '#0000FF', end)
|
2020-08-20 04:48:13 +02:00
|
|
|
|
2020-08-31 21:25:41 +02:00
|
|
|
if __name__ == '__main__':
|
2021-06-02 23:30:37 +02:00
|
|
|
DrawDirections().run()
|