- QRCode Tool - a SVG object is generated and plotted on screen having the QRCode data
- fixed an import error in Distance Tool
This commit is contained in:
parent
70fbb7f852
commit
c8a97e69d0
|
@ -7478,7 +7478,10 @@ class App(QtCore.QObject):
|
||||||
for obj_orig in obj.solid_geometry:
|
for obj_orig in obj.solid_geometry:
|
||||||
new_elem = dict()
|
new_elem = dict()
|
||||||
new_elem['solid'] = obj_orig
|
new_elem['solid'] = obj_orig
|
||||||
|
try:
|
||||||
new_elem['follow'] = obj_orig.exterior
|
new_elem['follow'] = obj_orig.exterior
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
apertures[str(apid)]['geometry'].append(deepcopy(new_elem))
|
apertures[str(apid)]['geometry'].append(deepcopy(new_elem))
|
||||||
apertures[str(apid)]['size'] = 0.0
|
apertures[str(apid)]['size'] = 0.0
|
||||||
apertures[str(apid)]['type'] = 'C'
|
apertures[str(apid)]['type'] = 'C'
|
||||||
|
|
|
@ -15,8 +15,7 @@ from shapely.geometry import Point, Polygon, MultiPolygon, MultiLineString, Line
|
||||||
from shapely.ops import cascaded_union
|
from shapely.ops import cascaded_union
|
||||||
import shapely.affinity as affinity
|
import shapely.affinity as affinity
|
||||||
|
|
||||||
import copy
|
from copy import deepcopy, copy
|
||||||
from copy import deepcopy
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
import traceback
|
import traceback
|
||||||
import inspect # TODO: For debugging only.
|
import inspect # TODO: For debugging only.
|
||||||
|
|
|
@ -14,6 +14,8 @@ CAD program, and create G-Code for Isolation routing.
|
||||||
- finished the GUI layout for the Calibrate Excellon Tool
|
- finished the GUI layout for the Calibrate Excellon Tool
|
||||||
- start working on QRCode Tool - not working yet
|
- start working on QRCode Tool - not working yet
|
||||||
- start working on QRCode Tool - serching for alternatives
|
- start working on QRCode Tool - serching for alternatives
|
||||||
|
- QRCode Tool - a SVG object is generated and plotted on screen having the QRCode data
|
||||||
|
- fixed an import error in Distance Tool
|
||||||
|
|
||||||
21.10.2019
|
21.10.2019
|
||||||
|
|
||||||
|
|
|
@ -1027,6 +1027,7 @@ class Geometry(object):
|
||||||
# w = float(svg_root.get('width'))
|
# w = float(svg_root.get('width'))
|
||||||
h = svgparselength(svg_root.get('height'))[0] # TODO: No units support yet
|
h = svgparselength(svg_root.get('height'))[0] # TODO: No units support yet
|
||||||
geos = getsvggeo(svg_root, object_type)
|
geos = getsvggeo(svg_root, object_type)
|
||||||
|
|
||||||
if flip:
|
if flip:
|
||||||
geos = [translate(scale(g, 1.0, -1.0, origin=(0, 0)), yoff=h) for g in geos]
|
geos = [translate(scale(g, 1.0, -1.0, origin=(0, 0)), yoff=h) for g in geos]
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ from FlatCAMTool import FlatCAMTool
|
||||||
from flatcamGUI.VisPyVisuals import *
|
from flatcamGUI.VisPyVisuals import *
|
||||||
from flatcamGUI.GUIElements import FCEntry
|
from flatcamGUI.GUIElements import FCEntry
|
||||||
|
|
||||||
import copy
|
from copy import copy
|
||||||
import math
|
import math
|
||||||
import logging
|
import logging
|
||||||
import gettext
|
import gettext
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
from PyQt5 import QtWidgets, QtCore
|
from PyQt5 import QtWidgets, QtCore
|
||||||
|
|
||||||
from FlatCAMTool import FlatCAMTool
|
from FlatCAMTool import FlatCAMTool
|
||||||
from flatcamGUI.GUIElements import FCDoubleSpinner, EvalEntry, FCCheckBox
|
from flatcamGUI.GUIElements import RadioSet, FCTextArea, FCSpinner
|
||||||
from camlib import *
|
from camlib import *
|
||||||
|
|
||||||
from shapely.geometry import Point
|
from shapely.geometry import Point
|
||||||
|
@ -56,6 +56,124 @@ class QRCode(FlatCAMTool):
|
||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
self.layout.addWidget(title_label)
|
self.layout.addWidget(title_label)
|
||||||
|
self.layout.addWidget(QtWidgets.QLabel(''))
|
||||||
|
|
||||||
|
# ## Grid Layout
|
||||||
|
i_grid_lay = QtWidgets.QGridLayout()
|
||||||
|
self.layout.addLayout(i_grid_lay)
|
||||||
|
i_grid_lay.setColumnStretch(0, 0)
|
||||||
|
i_grid_lay.setColumnStretch(1, 1)
|
||||||
|
|
||||||
|
self.grb_object_combo = QtWidgets.QComboBox()
|
||||||
|
self.grb_object_combo.setModel(self.app.collection)
|
||||||
|
self.grb_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||||
|
self.grb_object_combo.setCurrentIndex(1)
|
||||||
|
|
||||||
|
self.grbobj_label = QtWidgets.QLabel("<b>%s:</b>" % _("GERBER"))
|
||||||
|
self.grbobj_label.setToolTip(
|
||||||
|
_("Gerber Object to which the QRCode will be added.")
|
||||||
|
)
|
||||||
|
|
||||||
|
i_grid_lay.addWidget(self.grbobj_label, 0, 0)
|
||||||
|
i_grid_lay.addWidget(self.grb_object_combo, 0, 1, 1, 2)
|
||||||
|
i_grid_lay.addWidget(QtWidgets.QLabel(''), 1, 0)
|
||||||
|
|
||||||
|
# ## Grid Layout
|
||||||
|
grid_lay = QtWidgets.QGridLayout()
|
||||||
|
self.layout.addLayout(grid_lay)
|
||||||
|
grid_lay.setColumnStretch(0, 0)
|
||||||
|
grid_lay.setColumnStretch(1, 1)
|
||||||
|
|
||||||
|
self.qrcode_label = QtWidgets.QLabel('<b>%s</b>' % _('QRCode Parameters'))
|
||||||
|
self.qrcode_label.setToolTip(
|
||||||
|
_("Contain the expected calibration points and the\n"
|
||||||
|
"ones measured.")
|
||||||
|
)
|
||||||
|
grid_lay.addWidget(self.qrcode_label, 0, 0, 1, 2)
|
||||||
|
|
||||||
|
# VERSION #
|
||||||
|
self.version_label = QtWidgets.QLabel('%s:' % _("Version"))
|
||||||
|
self.version_label.setToolTip(
|
||||||
|
_("QRCode version can have values from 1 (21x21 boxes)\n"
|
||||||
|
"to 40 (177x177 boxes).")
|
||||||
|
)
|
||||||
|
self.version_entry = FCSpinner()
|
||||||
|
self.version_entry.set_range(1, 40)
|
||||||
|
self.version_entry.setWrapping(True)
|
||||||
|
|
||||||
|
grid_lay.addWidget(self.version_label, 1, 0)
|
||||||
|
grid_lay.addWidget(self.version_entry, 1, 1)
|
||||||
|
|
||||||
|
# ERROR CORRECTION #
|
||||||
|
self.error_label = QtWidgets.QLabel('%s:' % _("Error correction"))
|
||||||
|
self.error_label.setToolTip(
|
||||||
|
_("Parameter that controls the error correction used for the QR Code.\n"
|
||||||
|
"L = maximum 7% errors can be corrected\n"
|
||||||
|
"M = maximum 15% errors can be corrected\n"
|
||||||
|
"Q = maximum 25% errors can be corrected\n"
|
||||||
|
"H = maximum 30% errors can be corrected.")
|
||||||
|
)
|
||||||
|
self.error_radio = RadioSet([{'label': 'L', 'value': 'L'},
|
||||||
|
{'label': 'M', 'value': 'M'},
|
||||||
|
{'label': 'Q', 'value': 'Q'},
|
||||||
|
{'label': 'H', 'value': 'H'}])
|
||||||
|
self.error_radio.setToolTip(
|
||||||
|
_("Parameter that controls the error correction used for the QR Code.\n"
|
||||||
|
"L = maximum 7% errors can be corrected\n"
|
||||||
|
"M = maximum 15% errors can be corrected\n"
|
||||||
|
"Q = maximum 25% errors can be corrected\n"
|
||||||
|
"H = maximum 30% errors can be corrected.")
|
||||||
|
)
|
||||||
|
grid_lay.addWidget(self.error_label, 2, 0)
|
||||||
|
grid_lay.addWidget(self.error_radio, 2, 1)
|
||||||
|
|
||||||
|
# BOX SIZE #
|
||||||
|
self.bsize_label = QtWidgets.QLabel('%s:' % _("Box Size"))
|
||||||
|
self.bsize_label.setToolTip(
|
||||||
|
_("Box size control the overall size of the QRcode\n"
|
||||||
|
"by adjusting the size of each box in the code.")
|
||||||
|
)
|
||||||
|
self.bsize_entry = FCSpinner()
|
||||||
|
self.bsize_entry.set_range(1, 9999)
|
||||||
|
self.bsize_entry.setWrapping(True)
|
||||||
|
|
||||||
|
grid_lay.addWidget(self.bsize_label, 3, 0)
|
||||||
|
grid_lay.addWidget(self.bsize_entry, 3, 1)
|
||||||
|
|
||||||
|
# BORDER SIZE #
|
||||||
|
self.border_size_label = QtWidgets.QLabel('%s:' % _("Border Size"))
|
||||||
|
self.border_size_label.setToolTip(
|
||||||
|
_("Size of the QRCode border. How many boxes thick is the border.\n"
|
||||||
|
"Default value is 4.")
|
||||||
|
)
|
||||||
|
self.border_size_entry = FCSpinner()
|
||||||
|
self.border_size_entry.set_range(1, 9999)
|
||||||
|
self.border_size_entry.setWrapping(True)
|
||||||
|
self.border_size_entry.set_value(4)
|
||||||
|
|
||||||
|
grid_lay.addWidget(self.border_size_label, 4, 0)
|
||||||
|
grid_lay.addWidget(self.border_size_entry, 4, 1)
|
||||||
|
|
||||||
|
# Text box
|
||||||
|
self.text_label = QtWidgets.QLabel('%s:' % _("QRCode Data"))
|
||||||
|
self.text_label.setToolTip(
|
||||||
|
_("QRCode Data. Alphanumeric text to be encoded in the QRCode.")
|
||||||
|
)
|
||||||
|
self.text_data = FCTextArea()
|
||||||
|
|
||||||
|
grid_lay.addWidget(self.text_label, 5, 0)
|
||||||
|
grid_lay.addWidget(self.text_data, 6, 0, 1, 2)
|
||||||
|
|
||||||
|
# ## Create QRCode
|
||||||
|
self.qrcode_button = QtWidgets.QPushButton(_("Create QRCode"))
|
||||||
|
self.qrcode_button.setToolTip(
|
||||||
|
_("Create the QRCode object.")
|
||||||
|
)
|
||||||
|
grid_lay.addWidget(self.qrcode_button, 7, 0, 1, 2)
|
||||||
|
|
||||||
|
grid_lay.addWidget(QtWidgets.QLabel(''), 8, 0)
|
||||||
|
|
||||||
|
self.layout.addStretch()
|
||||||
|
|
||||||
def run(self, toggle=True):
|
def run(self, toggle=True):
|
||||||
self.app.report_usage("QRCode()")
|
self.app.report_usage("QRCode()")
|
||||||
|
@ -85,33 +203,66 @@ class QRCode(FlatCAMTool):
|
||||||
|
|
||||||
self.app.ui.notebook.setTabText(2, _("QRCode Tool"))
|
self.app.ui.notebook.setTabText(2, _("QRCode Tool"))
|
||||||
|
|
||||||
self.execute()
|
|
||||||
|
|
||||||
def install(self, icon=None, separator=None, **kwargs):
|
def install(self, icon=None, separator=None, **kwargs):
|
||||||
FlatCAMTool.install(self, icon, separator, shortcut='ALT+Q', **kwargs)
|
FlatCAMTool.install(self, icon, separator, shortcut='ALT+Q', **kwargs)
|
||||||
|
|
||||||
def set_tool_ui(self):
|
def set_tool_ui(self):
|
||||||
self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper()
|
self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value()
|
||||||
|
self.version_entry.set_value(1)
|
||||||
|
self.error_radio.set_value('M')
|
||||||
|
self.bsize_entry.set_value(3)
|
||||||
|
self.border_size_entry.set_value(4)
|
||||||
|
|
||||||
|
# Signals #
|
||||||
|
self.qrcode_button.clicked.connect(self.execute)
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
|
|
||||||
|
text_data = self.text_data.get_value()
|
||||||
|
if text_data == '':
|
||||||
|
self.app.inform.emit('[ERROR_NOTCL] %s' % _("Cancelled. There is no QRCode Data in the text box."))
|
||||||
|
return 'fail'
|
||||||
|
|
||||||
svg_file = io.BytesIO()
|
svg_file = io.BytesIO()
|
||||||
svg_file = qrcode.make("FlatCAM - 2D - Computer aided PCB Manufacturing Tool",
|
error_code = {
|
||||||
image_factory=qrcode.image.svg.SvgFragmentImage)
|
'L': qrcode.constants.ERROR_CORRECT_L,
|
||||||
|
'M': qrcode.constants.ERROR_CORRECT_M,
|
||||||
|
'Q': qrcode.constants.ERROR_CORRECT_Q,
|
||||||
|
'H': qrcode.constants.ERROR_CORRECT_H
|
||||||
|
}[self.error_radio.get_value()]
|
||||||
|
|
||||||
|
qr = qrcode.QRCode(
|
||||||
|
version=self.version_entry.get_value(),
|
||||||
|
error_correction=error_code,
|
||||||
|
box_size=self.bsize_entry.get_value(),
|
||||||
|
border=self.border_size_entry.get_value(),
|
||||||
|
image_factory=qrcode.image.svg.SvgFragmentImage
|
||||||
|
)
|
||||||
|
qr.add_data(text_data)
|
||||||
|
qr.make()
|
||||||
|
|
||||||
|
img = qr.make_image()
|
||||||
|
img.save(svg_file)
|
||||||
|
|
||||||
|
svg_text = StringIO(svg_file.getvalue().decode('UTF-8'))
|
||||||
|
|
||||||
def obj_init(geo_obj, app_obj):
|
def obj_init(geo_obj, app_obj):
|
||||||
units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value()
|
geo_obj.import_svg(svg_text, units=self.units)
|
||||||
try:
|
geo_obj.solid_geometry = unary_union(geo_obj.solid_geometry).buffer(0.0000001)
|
||||||
geo_obj.import_svg(svg_file)
|
geo_obj.solid_geometry = geo_obj.solid_geometry.buffer(-0.0000001)
|
||||||
except Exception as e:
|
|
||||||
print(str(e))
|
|
||||||
|
|
||||||
with self.app.proc_container.new("Import SVG"):
|
|
||||||
|
|
||||||
|
with self.app.proc_container.new(_("Generating QRCode...")):
|
||||||
# Object creation
|
# Object creation
|
||||||
self.app.new_object('geometry', 'generated_qrcode', obj_init, plot=False)
|
self.app.new_object('gerber', 'QRCode', obj_init, plot=True)
|
||||||
|
|
||||||
# # Register recent file
|
def make(self):
|
||||||
# self.app.file_opened.emit("svg", img)
|
pass
|
||||||
#
|
|
||||||
# # GUI feedback
|
def utility_geo(self):
|
||||||
# self.app.inform.emit("Opened: " + img)
|
pass
|
||||||
|
|
||||||
|
def on_mouse_move(self, event):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def on_mouse_release(self, event):
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue