Skip to content

Commit

Permalink
Fix deprecation warnings and inx for 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhoek committed Feb 27, 2020
1 parent 96dbe82 commit b977def
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Inkscape extension: isometric projection converter
==================================================

*This version of the extension is for Inkscape 1.0 or later. For older versions of
Inkscape, please use [v1.2](../../tree/v1.2).*

This [Inkscape](https://inkscape.org) extension transforms objects drawn on a
two-dimensional plane to an isometric projection.

Expand Down
5 changes: 2 additions & 3 deletions isometric_projection.inx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>Isometric Projection</_name>
<name>Isometric Projection</name>
<id>nl.jeroenhoek.inkscape.filter.isometric_projection_tool</id>
<dependency type="executable" location="extensions">isometric_projection.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
<param name="conversion" type="optiongroup" gui-text="Convert flat projection to">
<option value="top">Isometric top side</option>
<option value="left">Isometric left-hand side</option>
<option value="right">Isometric right-hand side</option>
</param>
<param name="reverse" type="boolean" gui-text="Reverse transformation">false</param>
<param name="reverse" type="bool" gui-text="Reverse transformation">false</param>
<effect>
<object-type>all</object-type>
<effects-menu>
Expand Down
37 changes: 18 additions & 19 deletions isometric_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import math
import sys
import inkex
from simpletransform import parseTransform, formatTransform
from simpletransform import computeBBox, applyTransformToPoint
from simpletransform import Transform

sys.path.append('/usr/share/inkscape/extensions')
inkex.localize()
inkex.localization.localize()


class IsometricProjectionTools(inkex.Effect):
Expand Down Expand Up @@ -75,12 +74,12 @@ def __init__(self):

inkex.Effect.__init__(self)

self.OptionParser.add_option(
'-c', '--conversion', action='store', type='string',
self.arg_parser.add_argument(
'-c', '--conversion',
dest='conversion', default='top',
help='Conversion to perform: (top|left|right)')
self.OptionParser.add_option(
'-r', '--reverse', action='store', type='string',
self.arg_parser.add_argument(
'-r', '--reverse',
dest='reverse', default="false",
help='Reverse the transformation from isometric projection ' +
'to flat 2D')
Expand Down Expand Up @@ -121,15 +120,14 @@ def getMidPoint(self, bbox, node):

return [x, y]

def translateBetweenPoints(self, matrix, here, there):
def translateBetweenPoints(self, tr, here, there):
"""
Add a translation to a matrix that moves between two points.
"""

x = there[0] - here[0]
y = there[1] - here[1]
matrix[0][2] += x
matrix[1][2] += y
tr.add_translate(x, y)

def moveTransformationCenter(self, node, midpoint, center_new):
"""
Expand Down Expand Up @@ -159,7 +157,7 @@ def effect(self):
else:
conversion = "to_" + self.options.conversion

if len(self.selected) == 0:
if len(self.svg.selected) == 0:
inkex.errormsg(_("Please select an object to perform the " +
"isometric projection transformation on."))
return
Expand All @@ -169,30 +167,31 @@ def effect(self):
effect_matrix = self.transformations.get(
conversion, self.transformations.get('to_top'))

for id, node in self.selected.items():
bbox = computeBBox([node])
for id, node in self.svg.selected.items():
bbox = node.bounding_box()
midpoint = self.getMidPoint(bbox, node)
center_old = self.getTransformCenter(midpoint, node)
transform = node.get("transform")
# Combine our transformation matrix with any pre-existing
# transform.
matrix = parseTransform(transform, effect_matrix)
tr = Transform(transform) * Transform(effect_matrix)

# Compute the location of the transformation center after applying
# the transformation matrix.
center_new = center_old[:]
applyTransformToPoint(matrix, center_new)
applyTransformToPoint(matrix, midpoint)
#Transform(matrix).apply_to_point(center_new)
tr.apply_to_point(center_new)
tr.apply_to_point(midpoint)

# Add a translation transformation that will move the object to
# keep its transformation center in the same place.
self.translateBetweenPoints(matrix, center_new, center_old)
self.translateBetweenPoints(tr, center_new, center_old)

node.set('transform', formatTransform(matrix))
node.set('transform', str(tr))

# Adjust the transformation center.
self.moveTransformationCenter(node, midpoint, center_new)

# Create effect instance and apply it.
effect = IsometricProjectionTools()
effect.affect()
effect.run()

0 comments on commit b977def

Please sign in to comment.