2020-08-17 18:40:16 +02:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
'''
|
|
|
|
Copyright (C) 2020 Christian Hoffmann christian@lehrer-hoffmann.de
|
|
|
|
|
|
|
|
##This extension allows you to draw a Cartesian grid in Inkscape.
|
|
|
|
##There is a wide range of options including subdivision, subsubdivions
|
|
|
|
## and logarithmic scales. Custom line widths are also possible.
|
|
|
|
##All elements are grouped with similar elements (eg all x-subdivs)
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Fraanklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
'''
|
|
|
|
|
|
|
|
import inkex
|
|
|
|
|
2021-04-04 01:51:59 +02:00
|
|
|
class Pathpoints2Dots(inkex.EffectExtension):
|
2020-08-17 18:40:16 +02:00
|
|
|
def __init__(self):
|
|
|
|
inkex.Effect.__init__(self)
|
|
|
|
self.arg_parser.add_argument("--tab")
|
|
|
|
self.arg_parser.add_argument("--endpoints", type=inkex.Boolean, default=True)
|
|
|
|
self.arg_parser.add_argument("--controlpoints", type=inkex.Boolean, default=False)
|
|
|
|
|
|
|
|
def effect(self):
|
|
|
|
if len(self.svg.selected) != 2:
|
2020-08-30 11:51:54 +02:00
|
|
|
inkex.errormsg("Please select exact two objects:\n1. object representing path,\n2. object representing dots.")
|
2020-08-17 18:40:16 +02:00
|
|
|
return
|
|
|
|
|
2020-08-30 11:51:54 +02:00
|
|
|
nodes = list(self.svg.selected.items())
|
|
|
|
iddot = nodes[0][0]
|
|
|
|
idpath = nodes[1][0]
|
|
|
|
dot = self.svg.selected[iddot]
|
|
|
|
path = self.svg.selected[idpath]
|
2020-08-17 18:40:16 +02:00
|
|
|
self.svg.selected.popitem()
|
|
|
|
self.svg.selected.popitem()
|
|
|
|
bb = dot.bounding_box()
|
|
|
|
parent = path.find('..')
|
|
|
|
group = inkex.Group()
|
|
|
|
parent.add(group)
|
|
|
|
|
|
|
|
end_points = list(path.path.end_points)
|
|
|
|
control_points = []
|
|
|
|
for cp in path.path.control_points:
|
|
|
|
is_endpoint = False
|
|
|
|
for ep in end_points:
|
|
|
|
if cp.x == ep.x and cp.y == ep.y:
|
|
|
|
is_endpoint = True
|
|
|
|
break
|
|
|
|
if not is_endpoint:
|
|
|
|
control_points.append(cp)
|
|
|
|
|
|
|
|
pointlist = []
|
|
|
|
if self.options.endpoints:
|
|
|
|
pointlist += end_points
|
|
|
|
if self.options.controlpoints:
|
|
|
|
pointlist += control_points
|
|
|
|
for point in pointlist:
|
|
|
|
clone = inkex.Use()
|
|
|
|
clone.set('xlink:href','#'+iddot)
|
|
|
|
clone.set('x',point.x-bb.center.x)
|
|
|
|
clone.set('y',point.y-bb.center.y)
|
|
|
|
group.add(clone)
|
|
|
|
|
2020-08-31 21:25:41 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
Pathpoints2Dots().run()
|