Преглед изворни кода

- start working on QRCode Tool - serching for alternatives

Marius Stanciu пре 6 година
родитељ
комит
70fbb7f852
3 измењених фајлова са 22 додато и 9 уклоњено
  1. 1 0
      README.md
  2. 11 3
      flatcamParsers/ParseSVG.py
  3. 10 6
      flatcamTools/ToolQRCode.py

+ 1 - 0
README.md

@@ -13,6 +13,7 @@ CAD program, and create G-Code for Isolation routing.
 - working on 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 - serching for alternatives
 
 21.10.2019
 

+ 11 - 3
flatcamParsers/ParseSVG.py

@@ -22,7 +22,7 @@
 # import xml.etree.ElementTree as ET
 from svg.path import Line, Arc, CubicBezier, QuadraticBezier, parse_path
 from svg.path.path import Move
-from shapely.geometry import LineString
+from shapely.geometry import LineString, LinearRing, MultiLineString
 from shapely.affinity import skew, affine_transform, rotate
 import numpy as np
 
@@ -71,7 +71,6 @@ def path2shapely(path, object_type, res=1.0):
     rings = []
 
     for component in path:
-
         # Line
         if isinstance(component, Line):
             start = component.start
@@ -123,6 +122,8 @@ def path2shapely(path, object_type, res=1.0):
 
     if points:
         rings.append(points)
+
+    rings = MultiLineString(rings)
     if len(rings) > 0:
         if len(rings) == 1:
             # Polygons are closed and require more than 2 points
@@ -131,7 +132,14 @@ def path2shapely(path, object_type, res=1.0):
             else:
                 geo_element = LineString(rings[0])
         else:
-            geo_element = Polygon(rings[0], rings[1:])
+            try:
+                geo_element = Polygon(rings[0], rings[1:])
+            except Exception as e:
+                coords = list()
+                for line in rings:
+                    coords.append(line.coords[0])
+                    coords.append(line.coords[1])
+                geo_element = Polygon(coords)
         geometry.append(geo_element)
 
     return geometry

+ 10 - 6
flatcamTools/ToolQRCode.py

@@ -18,7 +18,8 @@ import math
 import io
 from datetime import datetime
 import logging
-import pyqrcode
+import qrcode
+import qrcode.image.svg
 from lxml import etree as ET
 
 import gettext
@@ -93,13 +94,16 @@ class QRCode(FlatCAMTool):
         self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper()
 
     def execute(self):
-        svg_file = io.StringIO('')
-        svg_class = pyqrcode.QRCode("FlatCAM - 2D - Computer aided PCB Manufacturing Tool")
-        svg_class.svg(svg_file, scale=4, xmldecl=False)
+        svg_file = io.BytesIO()
+        svg_file = qrcode.make("FlatCAM - 2D - Computer aided PCB Manufacturing Tool",
+                                image_factory=qrcode.image.svg.SvgFragmentImage)
 
         def obj_init(geo_obj, app_obj):
-            print(svg_file)
-            geo_obj.import_svg(svg_file)
+            units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value()
+            try:
+                geo_obj.import_svg(svg_file)
+            except Exception as e:
+                print(str(e))
 
         with self.app.proc_container.new("Import SVG"):