added some more options to knob_scale and fixed some 0 division error in

vertical scale
This commit is contained in:
Mario Voigt 2022-09-25 18:53:36 +02:00
parent dff4e51976
commit 7e8872efcd
3 changed files with 22 additions and 9 deletions

View File

@ -7,11 +7,13 @@
<param name="x" type="float" min="-1000" max="10000" precision="3" gui-text="Center X:">0</param> <param name="x" type="float" min="-1000" max="10000" precision="3" gui-text="Center X:">0</param>
<param name="y" type="float" min="-1000" max="10000" precision="3" gui-text="Center Y:">0</param> <param name="y" type="float" min="-1000" max="10000" precision="3" gui-text="Center Y:">0</param>
<param name="radius" type="float" min="0.001" max="10000" precision="3" gui-text="Knob radius:">100</param> <param name="radius" type="float" min="0.001" max="10000" precision="3" gui-text="Knob radius:">100</param>
<param name="angle" type="float" min="90.0" max="360.0" precision="3" gui-text="Angle">300</param> <param name="angle" type="float" min="1.0" max="360.0" precision="3" gui-text="Angle (°)">300</param>
<param name="angle_shifting" type="float" min="0.0" max="360.0" precision="3" gui-text="Angle shifting (°)">300</param>
<param name="linewidth" type="float" min="0.001" max="100" precision="3" gui-text="Line width">1</param> <param name="linewidth" type="float" min="0.001" max="100" precision="3" gui-text="Line width">1</param>
<param name="draw_arc" type="bool" gui-text="Draw Arc">true</param> <param name="draw_arc" type="bool" gui-text="Draw Arc">true</param>
<param name="draw_centering_circle" type="bool" gui-text="Draw Centering Circle">false</param> <param name="draw_centering_circle" type="bool" gui-text="Draw Centering Circle">false</param>
<param name="logarithmic_scale" type="bool" gui-text="Logarithmic Scale">false</param> <param name="logarithmic_scale" type="bool" gui-text="Logarithmic Scale">false</param>
<param name="invert" type="bool" gui-text="Invert direction">false</param>
<param name="units" type="optiongroup" gui-text="Units" appearance="combo"> <param name="units" type="optiongroup" gui-text="Units" appearance="combo">
<option value="px">px</option> <option value="px">px</option>
<option value="mm">mm</option> <option value="mm">mm</option>

View File

@ -32,9 +32,11 @@ class KnobScale(inkex.EffectExtension):
pars.add_argument("--radius", type=float, default=100.0, help="Knob radius") pars.add_argument("--radius", type=float, default=100.0, help="Knob radius")
pars.add_argument("--linewidth", type=float, default=1) pars.add_argument("--linewidth", type=float, default=1)
pars.add_argument("--angle", type=float, default=260.0, help="Angle of the knob scale in degrees") pars.add_argument("--angle", type=float, default=260.0, help="Angle of the knob scale in degrees")
pars.add_argument("--angle_shifting", type=float, default=0.0, help="Angle shifting")
pars.add_argument("--draw_arc", type=inkex.Boolean, default='True') pars.add_argument("--draw_arc", type=inkex.Boolean, default='True')
pars.add_argument("--draw_centering_circle", type=inkex.Boolean, default='False') pars.add_argument("--draw_centering_circle", type=inkex.Boolean, default='False')
pars.add_argument("--logarithmic_scale", type=inkex.Boolean, default='False', help="") pars.add_argument("--logarithmic_scale", type=inkex.Boolean, default='False', help="")
pars.add_argument("--invert", type=inkex.Boolean, default='False', help="")
pars.add_argument("-u", "--units", default="px", help="units to measure size of knob") pars.add_argument("-u", "--units", default="px", help="units to measure size of knob")
# Tick settings # Tick settings
@ -74,10 +76,10 @@ class KnobScale(inkex.EffectExtension):
text.set('style', str(inkex.Style(style))) text.set('style', str(inkex.Style(style)))
parent.append(text) parent.append(text)
def draw_knob_arc(self, radius, parent, angle, transform='' ): def draw_knob_arc(self, radius, parent, angle, angle_shifting, transform='' ):
start_point_angle = (angle - pi)/2.0 start_point_angle = angle_shifting + (angle - pi)/2.0
end_point_angle = pi - start_point_angle end_point_angle = pi - start_point_angle + angle_shifting*2
style = { 'stroke' : '#000000', style = { 'stroke' : '#000000',
'stroke-width' : str(self.options.linewidth), 'stroke-width' : str(self.options.linewidth),
@ -161,6 +163,7 @@ class KnobScale(inkex.EffectExtension):
self.x_offset = self.svg.unittouu(str(self.options.x) + self.options.units) self.x_offset = self.svg.unittouu(str(self.options.x) + self.options.units)
self.y_offset = self.svg.unittouu(str(self.options.y) + self.options.units) self.y_offset = self.svg.unittouu(str(self.options.y) + self.options.units)
angle = self.options.angle*pi/180.0 angle = self.options.angle*pi/180.0
angle_shifting = self.options.angle_shifting*pi/180.0
n_ticks = self.options.n_ticks n_ticks = self.options.n_ticks
n_subticks = self.options.n_subticks n_subticks = self.options.n_subticks
is_outer = True is_outer = True
@ -173,6 +176,10 @@ class KnobScale(inkex.EffectExtension):
# Labeling settings # Labeling settings
if self.options.invert is True:
end_num = self.options.start_value
start_num = self.options.stop_value
else:
start_num = self.options.start_value start_num = self.options.start_value
end_num = self.options.stop_value end_num = self.options.stop_value
text_spacing = self.svg.unittouu(str(self.options.text_offset) + self.options.units) text_spacing = self.svg.unittouu(str(self.options.text_offset) + self.options.units)
@ -186,13 +193,13 @@ class KnobScale(inkex.EffectExtension):
arc_radius = radius arc_radius = radius
if self.options.draw_arc: if self.options.draw_arc:
self.draw_knob_arc(arc_radius, parent, angle) self.draw_knob_arc(arc_radius, parent, angle, angle_shifting)
if self.options.draw_centering_circle: if self.options.draw_centering_circle:
self.draw_centering_circle(arc_radius + tick_length + text_size + text_spacing, parent) self.draw_centering_circle(arc_radius + tick_length + text_size + text_spacing, parent)
if self.options.logarithmic_scale: if self.options.logarithmic_scale:
start_ticks_angle = 1.5*pi - 0.5*angle start_ticks_angle = 1.5*pi - 0.5*angle + angle_shifting
for tick in range(n_ticks): for tick in range(n_ticks):
self.draw_tick(radius, start_ticks_angle + angle*log(tick+1)/log(n_ticks), self.draw_tick(radius, start_ticks_angle + angle*log(tick+1)/log(n_ticks),
tick_length, parent) tick_length, parent)
@ -218,7 +225,7 @@ class KnobScale(inkex.EffectExtension):
subtick_length, parent) subtick_length, parent)
else: else:
ticks_delta = angle / (n_ticks - 1) ticks_delta = angle / (n_ticks - 1)
start_ticks_angle = 1.5*pi - 0.5*angle start_ticks_angle = 1.5*pi - 0.5*angle + angle_shifting
for tick in range(n_ticks): for tick in range(n_ticks):
self.draw_tick(radius, start_ticks_angle + ticks_delta*tick, self.draw_tick(radius, start_ticks_angle + ticks_delta*tick,

View File

@ -442,6 +442,10 @@ class VerticalHorizontalScale(inkex.EffectExtension):
scalefrom = self.options.scalefrom scalefrom = self.options.scalefrom
scaleto = self.options.scaleto scaleto = self.options.scaleto
if scalefrom - scaleto == 0:
inkex.utils.debug("Offset between number labels needs to be at least 1")
exit()
scaleGroup = self.svg.get_current_layer().add(inkex.Group()) scaleGroup = self.svg.get_current_layer().add(inkex.Group())
groups = [None, None, None, None] groups = [None, None, None, None]
markArray = [self.options.mark0, self.options.mark1, self.options.mark2] markArray = [self.options.mark0, self.options.mark1, self.options.mark2]