fixes in units in inx descriptors; added triangle extension

This commit is contained in:
Mario Voigt 2021-10-25 17:46:31 +02:00
parent 2e18ef9cd0
commit 70aa196e93
22 changed files with 254 additions and 61 deletions

View File

@ -5,11 +5,7 @@
<param name="unit" type="optiongroup" appearance="combo" gui-text="Unit">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
<option value="in">in</option>
<option value="ft">ft</option>
<option value="yd">yd</option>
<option value="pt">pt</option>
<option value="px">px</option>
<option value="pc">pc</option>

View File

@ -5,11 +5,7 @@
<param name="unit" type="optiongroup" appearance="combo" gui-text="Unit">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
<option value="in">in</option>
<option value="ft">ft</option>
<option value="yd">yd</option>
<option value="pt">pt</option>
<option value="px">px</option>
<option value="pc">pc</option>

View File

@ -5,11 +5,7 @@
<param name="unit" type="optiongroup" appearance="combo" gui-text="Unit">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
<option value="in">in</option>
<option value="ft">ft</option>
<option value="yd">yd</option>
<option value="pt">pt</option>
<option value="px">px</option>
<option value="pc">pc</option>

View File

@ -7,11 +7,7 @@
<param name="unit" type="optiongroup" appearance="combo" gui-text="Unit">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
<option value="in">in</option>
<option value="ft">ft</option>
<option value="yd">yd</option>
<option value="pt">pt</option>
<option value="px">px</option>
<option value="pc">pc</option>

View File

@ -5,11 +5,7 @@
<param name="unit" type="optiongroup" appearance="combo" gui-text="Unit">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
<option value="in">in</option>
<option value="ft">ft</option>
<option value="yd">yd</option>
<option value="pt">pt</option>
<option value="px">px</option>
<option value="pc">pc</option>

View File

@ -16,13 +16,10 @@
<param name="unit" type="optiongroup" appearance="combo" gui-text="Dimensional units:">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
<option value="px">px</option>
<option value="pt">pt</option>
<option value="pc">pc</option>
<option value="in">in</option>
<option value="ft">ft</option>
<option value="yd">yd</option>
</param>
<label appearance="header">Styles</label>
<param name="generate_decorative_wrapper" type="bool" gui-text="Generate decorative wrapper">false</param>

View File

@ -27,7 +27,6 @@
<option value="pt">pt</option>
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
</param>
<param name="digit" type="int" min="-3" max="5" gui-text="Precision">0</param>
<!--

View File

@ -13,13 +13,10 @@
<param name="unit" type="optiongroup" appearance="combo" gui-text="Dimensional units:">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
<option value="px">px</option>
<option value="pt">pt</option>
<option value="pc">pc</option>
<option value="in">in</option>
<option value="ft">ft</option>
<option value="yd">yd</option>
</param>
<label appearance="header">Styles</label>
<param name="generate_decorative_wrapper" type="bool" gui-text="Generate decorative wrapper">false</param>

View File

@ -6,7 +6,10 @@
<param name="unit" gui-text="Unit" type="optiongroup" appearance="combo">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="px">px</option>
<option value="pt">pt</option>
<option value="pc">pc</option>
<option value="in">in</option>
</param>
<label appearance="header">Threshold</label>
<param name="min_filter_enable" type="bool" gui-text="Enable filtering min.">false</param>

View File

@ -31,12 +31,7 @@ Alignment groups shall contain an object to mark its 'rotation center'. The exte
<option value="in">in</option>
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
<option value="Q">Q</option>
<option value="pc">pc</option>
<option value="yd">yd</option>
<option value="ft">ft</option>
</param>
</hbox>
<param name="reverse" type="bool" gui-text="Translate in opposite direction">false</param>
@ -74,12 +69,7 @@ Alignment groups shall contain an object to mark its 'rotation center'. The exte
<option value="in">in</option>
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
<option value="Q">Q</option>
<option value="pc">pc</option>
<option value="yd">yd</option>
<option value="ft">ft</option>
</param>
</hbox>
<param name="reverseG" type="bool" gui-text="Rotate group by an additional angle of 180 degrees" gui-description="This may be handy in case the start- and end-node of the controlling path segment are reversed.">false</param>

View File

@ -12,13 +12,10 @@
<param name="unit" type="optiongroup" appearance="combo" gui-text="Dimensional units of above parameters and the selected paths:">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
<option value="px">px</option>
<option value="pt">pt</option>
<option value="pc">pc</option>
<option value="in">in</option>
<option value="ft">ft</option>
<option value="yd">yd</option>
</param>
<label appearance="header">Styles</label>
<param name="generate_decorative_wrapper" type="bool" gui-text="Generate decorative wrapper">false</param>

View File

@ -41,7 +41,6 @@
<param name="unit" type="optiongroup" appearance="combo" gui-text="Units">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="in">in</option>
<option value="pt">pt</option>
<option value="px">px</option>

View File

@ -6,7 +6,6 @@
<param name="focal_length_unit" type="optiongroup" appearance="combo" gui-text=" ">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="in">in</option>
</param>
<param name="diameter" type="float" gui-text="Diameter:" min="0" max="10000" precision="3">1</param>
@ -14,14 +13,12 @@
<option value="in">in</option>
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
</param>
<param name="edge_thickness" type="float" gui-text="Edge thickness:" min="0" max="10000" precision="3">2</param>
<param name="edge_thickness_unit" type="optiongroup" appearance="combo" gui-text=" ">
<option value="mm">mm</option>
<option value="in">in</option>
<option value="cm">cm</option>
<option value="m">m</option>
</param>
<param name="optical_index" type="float" min="1." max="3." precision="4" gui-text="Optical index:">1.5168</param>
<param name="lens_type" type="optiongroup" appearance="combo" gui-text="Lens type:">

View File

@ -16,9 +16,7 @@
</param>
<param name="unit" type="optiongroup" appearance="combo" gui-text="Unit">
<option value="cm">cm</option>
<option value="ft">ft</option>
<option value="in">in</option>
<option value="m">m</option>
<option value="mm">mm</option>
<option value="pc">pc</option>
<option value="pt">pt</option>

View File

@ -8,14 +8,11 @@
<param name="length" type="float" min="0.1" max="100000.0" precision="3" gui-text="Length of scaling path:" gui-description="Real-world length of the scaling path">100.0</param>
<param name="unit" type="optiongroup" appearance="combo" gui-text="Unit: " gui-description="Real-world unit for drawing">
<option value="px">px</option>
<option value="pc">pc</option>
<option value="pt">pt</option>
<option value="in">in</option>
<option value="ft">ft</option>
<option value="yd">yd</option>
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
</param>
<label appearance="header">Scale Drawing</label>
<param name="choosescale" gui-text="Scale Category" gui-description="Select which kind of scaling you would like to use, then select the actual scale in the corresponding dropdown." type="optiongroup" appearance="combo">

View File

@ -5,7 +5,6 @@
<param name="unit" gui-text="Unit" type="optiongroup" appearance="combo">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="in">in</option>
<option value="pt">pt</option>
<option value="px">px</option>

View File

@ -11,7 +11,6 @@
<param name="unit" type="optiongroup" appearance="combo" gui-text="Units">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="in">in</option>
<option value="pt">pt</option>
<option value="px">px</option>

View File

@ -16,13 +16,10 @@
<param name="unit" type="optiongroup" appearance="combo" gui-text="Dimensional units of above parameters and the selected paths:">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="km">km</option>
<option value="px">px</option>
<option value="pt">pt</option>
<option value="pc">pc</option>
<option value="in">in</option>
<option value="ft">ft</option>
<option value="yd">yd</option>
</param>
<label appearance="header">Styles</label>
<param name="cosmetic_dash_style" type="bool" gui-text="Cosmetic dash lines" gui-description="If entered dash line length is zero we can apply some cosmetic style only">false</param>

View File

@ -0,0 +1,20 @@
[
{
"name": "Triangle",
"id": "fablabchemnitz.de.triangle",
"path": "triangle",
"original_name": "Triangle",
"original_id": "math.triangle",
"license": "GNU GPL v2",
"license_url": "https://gitlab.com/inkscape/extensions/-/blob/master/LICENSE.txt",
"comment": "",
"source_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X/src/branch/master/extensions/fablabchemnitz/triangle",
"fork_url": "https://gitlab.com/inkscape/extensions/",
"documentation_url": "https://stadtfabrikanten.org/display/IFM/Triangle",
"inkscape_gallery_url": null,
"main_authors": [
"John Beard:john.j.beard@gmail.com",
"github.com/vmario89"
]
}
]

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Triangle</name>
<id>fablabchemnitz.de.triangle</id>
<param name="unit" type="optiongroup" appearance="combo" gui-text="Units:">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="px">px</option>
<option value="pt">pt</option>
<option value="pc">pc</option>
<option value="in">in</option>
</param>
<param name="s_a" type="float" min="0.01" max="10000" gui-text="Side Length a:">100.0</param>
<param name="s_b" type="float" min="0.01" max="10000" gui-text="Side Length b:">100.0</param>
<param name="s_c" type="float" min="0.01" max="10000" gui-text="Side Length c:">100.0</param>
<param name="a_a" type="float" min="0" max="180" gui-text="Angle a (deg):">60</param>
<param name="a_b" type="float" min="0" max="180" gui-text="Angle b (deg):">30</param>
<param name="a_c" type="float" min="0" max="180" gui-text="Angle c (deg):">90</param>
<param name="mode" type="optiongroup" appearance="combo" gui-text="Mode:">
<option value="3_sides">From Three Sides</option>
<option value="s_ab_a_c">From Sides a, b and Angle c</option>
<option value="s_ab_a_a">From Sides a, b and Angle a</option>
<option value="s_a_a_ab">From Side a and Angles a, b</option>
<option value="s_c_a_ab">From Side c and Angles a, b</option>
</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz">
<submenu name="Shape/Pattern from Generator" />
</submenu>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">triangle.py</command>
</script>
</inkscape-extension>

View File

@ -0,0 +1,188 @@
#! /usr/bin/python3
#
# Copyright (C) 2007 John Beard john.j.beard@gmail.com
#
# 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 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
"""
This extension allows you to draw a triangle given certain information
about side length or angles.
Measurements of the triangle
C(x_c,y_c)
/`__
/ a_c``--__
/ ``--__ s_a
s_b / ``--__
/a_a a_b`--__
/--------------------------------``B(x_b, y_b)
A(x_a,y_a) s_b
"""
import sys
from math import acos, asin, cos, pi, sin, sqrt
import inkex
X, Y = range(2)
def draw_SVG_tri(point1, point2, point3, offset, width, name, parent):
style = {'stroke': '#000000', 'stroke-width': str(width), 'fill': 'none'}
elem = parent.add(inkex.PathElement())
elem.update(**{
'style': style,
'inkscape:label': name,
'd': 'M ' + str(point1[X] + offset[X]) + ',' + str(point1[Y] + offset[Y]) +
' L ' + str(point2[X] + offset[X]) + ',' + str(point2[Y] + offset[Y]) +
' L ' + str(point3[X] + offset[X]) + ',' + str(point3[Y] + offset[Y]) +
' L ' + str(point1[X] + offset[X]) + ',' + str(point1[Y] + offset[Y]) + ' z'})
return elem
def angle_from_3_sides(a, b, c): # return the angle opposite side c
cosx = (a * a + b * b - c * c) / (2 * a * b) # use the cosine rule
return acos(cosx)
def third_side_from_enclosed_angle(s_a, s_b, a_c): # return the side opposite a_c
c_squared = s_a * s_a + s_b * s_b - 2 * s_a * s_b * cos(a_c)
if c_squared > 0:
return sqrt(c_squared)
else:
return 0 # means we have an invalid or degenerate triangle (zero is caught at the drawing stage)
def pt_on_circ(radius, angle): # return the x,y coordinate of the polar coordinate
x = radius * cos(angle)
y = radius * sin(angle)
return [x, y]
def v_add(point1, point2): # add an offset to coordinates
return [point1[X] + point2[X], point1[Y] + point2[Y]]
def is_valid_tri_from_sides(a, b, c): # check whether triangle with sides a,b,c is valid
return (a + b) > c and (a + c) > b and (b + c) > a and a > 0 and b > 0 and c > 0 # two sides must always be greater than the third
# no zero-length sides, no degenerate case
def draw_tri_from_3_sides(s_a, s_b, s_c, offset, width, parent): # draw a triangle from three sides (with a given offset
if is_valid_tri_from_sides(s_a, s_b, s_c):
a_b = angle_from_3_sides(s_a, s_c, s_b)
a = (0, 0) # a is the origin
b = v_add(a, (s_c, 0)) # point B is horizontal from the origin
c = v_add(b, pt_on_circ(s_a, pi - a_b)) # get point c
c[1] = -c[1]
offx = max(b[0], c[0]) / 2 # b or c could be the furthest right
offy = c[1] / 2 # c is the highest point
offset = (offset[0] - offx, offset[1] - offy) # add the centre of the triangle to the offset
draw_SVG_tri(a, b, c, offset, width, 'Triangle', parent)
else:
inkex.errormsg('Invalid Triangle Specifications.')
class Triangle(inkex.EffectExtension):
def add_arguments(self, pars):
pars.add_argument("--unit", default="mm", help="Units")
pars.add_argument("--s_a", type=float, default=100.0, help="Side Length a")
pars.add_argument("--s_b", type=float, default=100.0, help="Side Length b")
pars.add_argument("--s_c", type=float, default=100.0, help="Side Length c")
pars.add_argument("--a_a", type=float, default=60.0, help="Angle a")
pars.add_argument("--a_b", type=float, default=30.0, help="Angle b")
pars.add_argument("--a_c", type=float, default=90.0, help="Angle c")
pars.add_argument("--mode", default='3_sides', help="Side Length c")
def effect(self):
tri = self.svg.get_current_layer()
offset = self.svg.namedview.center
self.options.s_a = self.svg.unittouu(str(self.options.s_a) + self.options.unit)
self.options.s_b = self.svg.unittouu(str(self.options.s_b) + self.options.unit)
self.options.s_c = self.svg.unittouu(str(self.options.s_c) + self.options.unit)
stroke_width = self.svg.unittouu('1px')
if self.options.mode == '3_sides':
s_a = self.options.s_a
s_b = self.options.s_b
s_c = self.options.s_c
draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri)
elif self.options.mode == 's_ab_a_c':
s_a = self.options.s_a
s_b = self.options.s_b
a_c = self.options.a_c * pi / 180 # in rad
s_c = third_side_from_enclosed_angle(s_a, s_b, a_c)
draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri)
elif self.options.mode == 's_ab_a_a':
s_a = self.options.s_a
s_b = self.options.s_b
a_a = self.options.a_a * pi / 180 # in rad
if (a_a < pi / 2.0) and (s_a < s_b) and (s_a > s_b * sin(a_a)): # this is an ambiguous case
ambiguous = True # we will give both answers
else:
ambiguous = False
sin_a_b = s_b * sin(a_a) / s_a
if (sin_a_b <= 1) and (sin_a_b >= -1): # check the solution is possible
a_b = asin(sin_a_b) # acute solution
a_c = pi - a_a - a_b
error = False
else:
sys.stderr.write('Error:Invalid Triangle Specifications.\n') # signal an error
error = True
if not error and (a_b < pi) and (a_c < pi): # check that the solution is valid, if so draw acute solution
s_c = third_side_from_enclosed_angle(s_a, s_b, a_c)
draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri)
if not error and ((a_b > pi) or (a_c > pi) or ambiguous): # we want the obtuse solution
a_b = pi - a_b
a_c = pi - a_a - a_b
s_c = third_side_from_enclosed_angle(s_a, s_b, a_c)
draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri)
elif self.options.mode == 's_a_a_ab':
s_a = self.options.s_a
a_a = self.options.a_a * pi / 180 # in rad
a_b = self.options.a_b * pi / 180 # in rad
a_c = pi - a_a - a_b
s_b = s_a * sin(a_b) / sin(a_a)
s_c = s_a * sin(a_c) / sin(a_a)
draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri)
elif self.options.mode == 's_c_a_ab':
s_c = self.options.s_c
a_a = self.options.a_a * pi / 180 # in rad
a_b = self.options.a_b * pi / 180 # in rad
a_c = pi - a_a - a_b
s_a = s_c * sin(a_a) / sin(a_c)
s_b = s_c * sin(a_b) / sin(a_c)
draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri)
if __name__ == '__main__':
Triangle().run()

View File

@ -18,7 +18,6 @@
<param name="unit" gui-text="Unit" type="optiongroup" appearance="combo">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="in">in</option>
<option value="pt">pt</option>
<option value="px">px</option>