Cleaned codefor sudoku and sheet conus
This commit is contained in:
parent
07e8373224
commit
904581fdf1
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
# please, stick to pep8 formatting for this file
|
# please, stick to pep8 formatting for this file
|
||||||
|
|
||||||
|
# seems to be lost in year 2016 https://wiki.inkscape.org/wiki/index.php?title=Inkscape_Extensions&oldid=99881
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Migrator: Mario Voigt / FabLab Chemnitz
|
Migrator: Mario Voigt / FabLab Chemnitz
|
||||||
Mail: mario.voigt@stadtfabrikanten.org
|
Mail: mario.voigt@stadtfabrikanten.org
|
||||||
@ -307,13 +309,6 @@ class ErrorVisualization(object):
|
|||||||
attrs = {"id": group_id, "style": "opacity:.5", inkex.addNS("label", "inkscape"): "Precut Errors"}
|
attrs = {"id": group_id, "style": "opacity:.5", inkex.addNS("label", "inkscape"): "Precut Errors"}
|
||||||
self.g = etree.SubElement(parent, inkex.addNS("g", "svg"), attrs)
|
self.g = etree.SubElement(parent, inkex.addNS("g", "svg"), attrs)
|
||||||
|
|
||||||
def getColorString(self, pickerColor):
|
|
||||||
longcolor = int(pickerColor)
|
|
||||||
if longcolor < 0:
|
|
||||||
longcolor = longcolor & 0xFFFFFFFF
|
|
||||||
return '#' + format(longcolor >> 8, '06X')
|
|
||||||
|
|
||||||
|
|
||||||
def fmt_point(self, point):
|
def fmt_point(self, point):
|
||||||
return "%s %s" % point
|
return "%s %s" % point
|
||||||
|
|
||||||
@ -330,7 +325,7 @@ class ErrorVisualization(object):
|
|||||||
path.append("M%s" % self.fmt_point(head))
|
path.append("M%s" % self.fmt_point(head))
|
||||||
for point in tail:
|
for point in tail:
|
||||||
path.append("L%s" % self.fmt_point(point))
|
path.append("L%s" % self.fmt_point(point))
|
||||||
attrs = {"d": " ".join(path), "style": "stroke:%s;stroke-width:5px;" % self.getColorString(self.color)}
|
attrs = {"d": " ".join(path), "style": "stroke:%s;stroke-width:5px;" % self.color}
|
||||||
etree.SubElement(self.g, inkex.addNS("path", "svg"), attrs)
|
etree.SubElement(self.g, inkex.addNS("path", "svg"), attrs)
|
||||||
|
|
||||||
def vis_point(geom):
|
def vis_point(geom):
|
||||||
|
@ -26,11 +26,11 @@
|
|||||||
<param name="puzzle_gap" type="int" min="1" max="100" gui-text="Puzzle Gap">1</param>
|
<param name="puzzle_gap" type="int" min="1" max="100" gui-text="Puzzle Gap">1</param>
|
||||||
</page>
|
</page>
|
||||||
<page name="colors" gui-text="Colors">
|
<page name="colors" gui-text="Colors">
|
||||||
<param name="color_text" type="color" appearance="colorbutton" gui-text="Text color ">0</param>
|
<param name="color_text" type="color" appearance="colorbutton" gui-text="Text color ">255</param>
|
||||||
<param name="color_bkgnd" type="color" appearance="colorbutton" gui-text="Background color">-1</param>
|
<param name="color_bkgnd" type="color" appearance="colorbutton" gui-text="Background color">4243148799</param>
|
||||||
<param name="color_puzzle" type="color" appearance="colorbutton" gui-text="Puzzle Border color">0</param>
|
<param name="color_puzzle" type="color" appearance="colorbutton" gui-text="Puzzle Border color">2290779647</param>
|
||||||
<param name="color_boxes" type="color" appearance="colorbutton" gui-text="Box Border color ">0</param>
|
<param name="color_boxes" type="color" appearance="colorbutton" gui-text="Box Border color ">3298820351</param>
|
||||||
<param name="color_cells" type="color" appearance="colorbutton" gui-text="Cell Border color">-791621617</param>
|
<param name="color_cells" type="color" appearance="colorbutton" gui-text="Cell Border color">1923076095</param>
|
||||||
</page>
|
</page>
|
||||||
</param>
|
</param>
|
||||||
<effect>
|
<effect>
|
||||||
|
@ -27,6 +27,7 @@ __version__ = "0.1"
|
|||||||
import inkex
|
import inkex
|
||||||
import subprocess
|
import subprocess
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
from inkex import Color
|
||||||
|
|
||||||
class SVGSudoku (inkex.Effect):
|
class SVGSudoku (inkex.Effect):
|
||||||
|
|
||||||
@ -38,19 +39,13 @@ class SVGSudoku (inkex.Effect):
|
|||||||
self.arg_parser.add_argument("--cols", type=int, default=1, help='Number of puzzle columns.')
|
self.arg_parser.add_argument("--cols", type=int, default=1, help='Number of puzzle columns.')
|
||||||
self.arg_parser.add_argument("--puzzle_size", type=int, default=6, help='The width & height of each puzzle.')
|
self.arg_parser.add_argument("--puzzle_size", type=int, default=6, help='The width & height of each puzzle.')
|
||||||
self.arg_parser.add_argument("--puzzle_gap", type=int, default=1, help='The space between puzzles.')
|
self.arg_parser.add_argument("--puzzle_gap", type=int, default=1, help='The space between puzzles.')
|
||||||
self.arg_parser.add_argument("--color_text", type=int, default=0, help='Color for given numbers.')
|
self.arg_parser.add_argument("--color_text", type=Color, default=255, help='Color for given numbers.')
|
||||||
self.arg_parser.add_argument("--color_bkgnd", type=int, default=-1, help='Color for the puzzle background.')
|
self.arg_parser.add_argument("--color_bkgnd", type=Color, default=4243148799, help='Color for the puzzle background.')
|
||||||
self.arg_parser.add_argument("--color_puzzle",default=0, help='Border color for the puzzles.')
|
self.arg_parser.add_argument("--color_puzzle",type=Color, default=2290779647, help='Border color for the puzzles.')
|
||||||
self.arg_parser.add_argument("--color_boxes", default=0, help='Border color for puzzle boxes.')
|
self.arg_parser.add_argument("--color_boxes", type=Color, default=3298820351, help='Border color for puzzle boxes.')
|
||||||
self.arg_parser.add_argument("--color_cells", default=-1061109505, help='Border color for the puzzle cells.')
|
self.arg_parser.add_argument("--color_cells", type=Color, default=1923076095, help='Border color for the puzzle cells.')
|
||||||
self.arg_parser.add_argument("--units", help="The unit of the dimensions")
|
self.arg_parser.add_argument("--units", help="The unit of the dimensions")
|
||||||
|
|
||||||
def getColorString(self, pickerColor):
|
|
||||||
longcolor = int(pickerColor)
|
|
||||||
if longcolor < 0:
|
|
||||||
longcolor = longcolor & 0xFFFFFFFF
|
|
||||||
return '#' + format(longcolor >> 8, '06X')
|
|
||||||
|
|
||||||
def draw_grid(self, g_puz, x, y):
|
def draw_grid(self, g_puz, x, y):
|
||||||
bkgnd_style = {'stroke':'none', 'stroke-width':'2', 'fill':self.options.color_bkgnd }
|
bkgnd_style = {'stroke':'none', 'stroke-width':'2', 'fill':self.options.color_bkgnd }
|
||||||
puzzle_style = {'stroke':self.options.color_puzzle, 'stroke-width':'2', 'fill':'none' }
|
puzzle_style = {'stroke':self.options.color_puzzle, 'stroke-width':'2', 'fill':'none' }
|
||||||
@ -97,15 +92,7 @@ class SVGSudoku (inkex.Effect):
|
|||||||
args.extend(["--difficulty", self.options.difficulty])
|
args.extend(["--difficulty", self.options.difficulty])
|
||||||
data = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0].splitlines()
|
data = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0].splitlines()
|
||||||
#inkex.utils.debug(data)
|
#inkex.utils.debug(data)
|
||||||
#
|
|
||||||
# convert colors
|
|
||||||
#inkex.utils.debug("%s"%(self.options.color_cells))
|
|
||||||
self.options.color_text = self.getColorString(self.options.color_text)
|
|
||||||
self.options.color_bkgnd = self.getColorString(self.options.color_bkgnd)
|
|
||||||
self.options.color_puzzle = self.getColorString(self.options.color_puzzle)
|
|
||||||
self.options.color_boxes = self.getColorString(self.options.color_boxes)
|
|
||||||
self.options.color_cells = self.getColorString(self.options.color_cells)
|
|
||||||
#
|
|
||||||
parent = self.document.getroot()
|
parent = self.document.getroot()
|
||||||
self.doc_w = self.svg.unittouu(parent.get('width'))
|
self.doc_w = self.svg.unittouu(parent.get('width'))
|
||||||
self.doc_h = self.svg.unittouu(parent.get('height'))
|
self.doc_h = self.svg.unittouu(parent.get('height'))
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<param name="name" type="description" xml:space="preserve">Constructs a flat pattern projection (sheet cutting layout)
|
<param name="name" type="description" xml:space="preserve">Constructs a flat pattern projection (sheet cutting layout)
|
||||||
that can be rolled or bent into a cone or frustum (truncated cone).
|
that can be rolled or bent into a cone or frustum (truncated cone).
|
||||||
If Cut diameter=0 then cone will not be truncated.</param>
|
If Cut diameter=0 then cone will not be truncated.</param>
|
||||||
<param name="strokeColour" type="color" appearance="colorbutton" gui-text="Line colour: ">0</param>
|
<param name="strokeColour" type="color" appearance="colorbutton" gui-text="Line color: ">255</param>
|
||||||
<effect>
|
<effect>
|
||||||
<object-type>all</object-type>
|
<object-type>all</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
|
@ -7,6 +7,7 @@ import inkex
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from inkex.transforms import Transform
|
from inkex.transforms import Transform
|
||||||
|
from inkex import Color
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
def calc_angle_between_points(p1, p2):
|
def calc_angle_between_points(p1, p2):
|
||||||
@ -56,24 +57,15 @@ class SheetMetalConus(inkex.Effect):
|
|||||||
'marker-end' : 'url(#ArrowDIN-end)' }
|
'marker-end' : 'url(#ArrowDIN-end)' }
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" Parses the command line options ( Base diameter, cut diameter and height of cone).
|
|
||||||
"""
|
|
||||||
inkex.Effect.__init__(self) # Call the base class constructor.
|
inkex.Effect.__init__(self) # Call the base class constructor.
|
||||||
# Describe parameters
|
|
||||||
self.arg_parser.add_argument('-b', '--diaBase', type = float, dest = 'diaBase', default = 300.0, help = 'The diameter of the cones base.')
|
self.arg_parser.add_argument('-b', '--diaBase', type = float, dest = 'diaBase', default = 300.0, help = 'The diameter of the cones base.')
|
||||||
self.arg_parser.add_argument('-c', '--diaCut', type = float, default = 100.0, help = 'The diameter of cones cut (0.0 if cone is not cut.')
|
self.arg_parser.add_argument('-c', '--diaCut', type = float, default = 100.0, help = 'The diameter of cones cut (0.0 if cone is not cut.')
|
||||||
self.arg_parser.add_argument('-l', '--heightCone', type = float, default = 200.0, help = 'The height of the (cut) cone.')
|
self.arg_parser.add_argument('-l', '--heightCone', type = float, default = 200.0, help = 'The height of the (cut) cone.')
|
||||||
self.arg_parser.add_argument('-u', '--units', default = 'mm', help = 'The units in which the cone values are given. mm or in for real objects')
|
self.arg_parser.add_argument('-u', '--units', default = 'mm', help = 'The units in which the cone values are given. mm or in for real objects')
|
||||||
self.arg_parser.add_argument('-w', '--strokeWidth', type = float, default = 0.3, help = 'The line thickness in given unit. For laser cutting it should be rather small.')
|
self.arg_parser.add_argument('-w', '--strokeWidth', type = float, default = 0.3, help = 'The line thickness in given unit. For laser cutting it should be rather small.')
|
||||||
self.arg_parser.add_argument('-f', '--strokeColour', default = 896839168, help = 'The line colour.')
|
self.arg_parser.add_argument('-f', '--strokeColour', type=Color, default = 255, help = 'The line colour.')
|
||||||
self.arg_parser.add_argument('-d', '--verbose', type = inkex.Boolean, default = False, help = 'Enable verbose output of calculated parameters. Used for debugging or is someone needs the calculated values.')
|
self.arg_parser.add_argument('-d', '--verbose', type = inkex.Boolean, default = False, help = 'Enable verbose output of calculated parameters. Used for debugging or is someone needs the calculated values.')
|
||||||
|
|
||||||
def getColorString(self, pickerColor):
|
|
||||||
longcolor = int(pickerColor)
|
|
||||||
if longcolor < 0:
|
|
||||||
longcolor = longcolor & 0xFFFFFFFF
|
|
||||||
return '#' + format(longcolor >> 8, '06X')
|
|
||||||
|
|
||||||
# Marker arrows
|
# Marker arrows
|
||||||
def makeMarkerstyle(self, name, rotate):
|
def makeMarkerstyle(self, name, rotate):
|
||||||
" Markers added to defs for reuse "
|
" Markers added to defs for reuse "
|
||||||
@ -229,9 +221,7 @@ class SheetMetalConus(inkex.Effect):
|
|||||||
- Overrides base class' method and draws rolled out sheet metal cone into SVG document.
|
- Overrides base class' method and draws rolled out sheet metal cone into SVG document.
|
||||||
"""
|
"""
|
||||||
# calc scene scale
|
# calc scene scale
|
||||||
convFactor = self.svg.unittouu("1" + self.options.units)
|
convFactor = self.svg.unittouu("1" + self.options.units)
|
||||||
# convert color
|
|
||||||
self.options.strokeColour = self.getColorString(self.options.strokeColour)
|
|
||||||
# Store all the relevants values in a dictionary for easy access
|
# Store all the relevants values in a dictionary for easy access
|
||||||
dictCone={'diaBase': self.options.diaBase,
|
dictCone={'diaBase': self.options.diaBase,
|
||||||
'diaCut': self.options.diaCut,
|
'diaCut': self.options.diaCut,
|
||||||
@ -437,6 +427,4 @@ class SheetMetalConus(inkex.Effect):
|
|||||||
text.text = "%4.3f" %(base_dia)
|
text.text = "%4.3f" %(base_dia)
|
||||||
text.transform = Transform(frustrum_repos) * text.transform
|
text.transform = Transform(frustrum_repos) * text.transform
|
||||||
|
|
||||||
# Create effect instance and apply it.
|
SheetMetalConus().run()
|
||||||
effect = SheetMetalConus()
|
|
||||||
effect.run()
|
|
Reference in New Issue
Block a user