From cc25701e4cf629a5129fff76f44f48efcf3c712c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kurlbaum?= Date: Tue, 25 Apr 2023 23:24:12 +0200 Subject: [PATCH] new path2D function from pySLM --- .../Resources/LaserCladding.qrc | 2 +- .../Resources/icons/Laser_Workbench.svg | 351 ------------------ freecad/LaserCladdingWorkbench/init_gui.py | 5 +- freecad/LaserCladdingWorkbench/pad.py | 9 +- freecad/LaserCladdingWorkbench/path.py | 3 +- freecad/LaserCladdingWorkbench/program.py | 6 +- freecad/LaserCladdingWorkbench/utils.py | 33 +- 7 files changed, 36 insertions(+), 373 deletions(-) delete mode 100644 freecad/LaserCladdingWorkbench/Resources/icons/Laser_Workbench.svg diff --git a/freecad/LaserCladdingWorkbench/Resources/LaserCladding.qrc b/freecad/LaserCladdingWorkbench/Resources/LaserCladding.qrc index c33b049..bba511f 100644 --- a/freecad/LaserCladdingWorkbench/Resources/LaserCladding.qrc +++ b/freecad/LaserCladdingWorkbench/Resources/LaserCladding.qrc @@ -1,6 +1,6 @@ - icons/Laser_Workbench.svg + icons/LaserWorkbench.svg icons/LaserCreatePad.svg icons/LaserCreateProg.svg icons/LaserRecomputePad.svg diff --git a/freecad/LaserCladdingWorkbench/Resources/icons/Laser_Workbench.svg b/freecad/LaserCladdingWorkbench/Resources/icons/Laser_Workbench.svg deleted file mode 100644 index a5c94df..0000000 --- a/freecad/LaserCladdingWorkbench/Resources/icons/Laser_Workbench.svg +++ /dev/null @@ -1,351 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - Mon Oct 10 13:44:52 2011 +0000 - - - [wmayer] - - - - - FreeCAD LGPL2+ - - - - - FreeCAD - - - FreeCAD/src/Mod/Draft/Resources/icons/Draft_2DShapeView.svg - http://www.freecadweb.org/wiki/index.php?title=Artwork - - - [agryson] Alexander Gryson - - - - - box - plane - rectangle - - - A box floating above a projection of its lower face - - - - - - - - - - - - diff --git a/freecad/LaserCladdingWorkbench/init_gui.py b/freecad/LaserCladdingWorkbench/init_gui.py index f16e9ea..211e3e3 100644 --- a/freecad/LaserCladdingWorkbench/init_gui.py +++ b/freecad/LaserCladdingWorkbench/init_gui.py @@ -9,8 +9,9 @@ import os class LaserCladding (Gui.Workbench): MenuText = "Laser Cladding" ToolTip = "Create Simple Paths on workpieces for Laser Cladding" - Icon = ":/icons/Laser_Workbench.svg" - + Icon = os.path.join(App.getUserAppDataDir(), + "Mod", "fc_lasercladding_wb","freecad", "LaserCladdingWorkbench", + "Resources", "icons", "LaserWorkbench.svg") def __init__(self): pass diff --git a/freecad/LaserCladdingWorkbench/pad.py b/freecad/LaserCladdingWorkbench/pad.py index 827c0ff..000909f 100644 --- a/freecad/LaserCladdingWorkbench/pad.py +++ b/freecad/LaserCladdingWorkbench/pad.py @@ -64,6 +64,9 @@ class LaserPad: myHatcher.hatchSortMethod = hatching.AlternateSort() polygon_coords = get_coords_from_shape(face) + print("===== coords from shape ======") + print("{}", polygon_coords) + print("===== ======") layer = myHatcher.hatch(polygon_coords) contours_geoms = layer.getContourGeometry() @@ -97,7 +100,8 @@ class LaserPad: def onChanged(self, fp, prop): '''Do something when a property has changed''' - App.Console.PrintMessage("Change property: " + str(prop) + "\n") + # App.Console.PrintMessage("Change property: " + str(prop) + "\n") + pass def execute(self, fp): App.Console.PrintMessage("Recompute LaserPad\n") @@ -149,10 +153,11 @@ class ViewProviderLaserPad: def onChanged(self, vp, prop): '''Here we can do something when a single property got changed''' - App.Console.PrintMessage("Change property: " + str(prop) + "\n") + # App.Console.PrintMessage("Change property: " + str(prop) + "\n") # if prop == "Color": # c = vp.getPropertyByName("Color") # self.color.rgb.setValue(c[0],c[1],c[2]) + pass def getIcon(self): '''Return the icon in XPM format which will appear in the tree view. This method is\ diff --git a/freecad/LaserCladdingWorkbench/path.py b/freecad/LaserCladdingWorkbench/path.py index b5edf87..67b697f 100644 --- a/freecad/LaserCladdingWorkbench/path.py +++ b/freecad/LaserCladdingWorkbench/path.py @@ -11,7 +11,8 @@ class LaserPath: def onChanged(self, fp, prop): '''Do something when a property has changed''' - App.Console.PrintMessage("Change property: " + str(prop) + "\n") + #App.Console.PrintMessage("Change property: " + str(prop) + "\n") + pass def execute(self, fp): App.Console.PrintMessage("Recompute LaserPath\n") diff --git a/freecad/LaserCladdingWorkbench/program.py b/freecad/LaserCladdingWorkbench/program.py index bf8310e..4839b63 100644 --- a/freecad/LaserCladdingWorkbench/program.py +++ b/freecad/LaserCladdingWorkbench/program.py @@ -54,7 +54,8 @@ class LaserProgram: def onChanged(self, fp, prop): '''Do something when a property has changed''' - App.Console.PrintMessage("Change property: " + str(prop) + "\n") + #App.Console.PrintMessage("Change property: " + str(prop) + "\n") + pass def execute(self, fp): '''Do something when doing a recomputation, this method is mandatory''' @@ -95,10 +96,11 @@ class ViewProviderLaserProgram: def onChanged(self, vp, prop): '''Here we can do something when a single property got changed''' - App.Console.PrintMessage("Change property: " + str(prop) + "\n") + # App.Console.PrintMessage("Change property: " + str(prop) + "\n") #if prop == "Color": # c = vp.getPropertyByName("Color") # self.color.rgb.setValue(c[0],c[1],c[2]) + pass def getIcon(self): '''Return the icon in XPM format which will appear in the tree view. This method is\ diff --git a/freecad/LaserCladdingWorkbench/utils.py b/freecad/LaserCladdingWorkbench/utils.py index 9d29a2c..b7f2a75 100644 --- a/freecad/LaserCladdingWorkbench/utils.py +++ b/freecad/LaserCladdingWorkbench/utils.py @@ -4,6 +4,7 @@ import FreeCADGui as Gui import numpy as np import math import Part +import shapely from shapely.geometry import Polygon, Point from pyslm import hatching as hatching from pyslm.geometry.geometry import LayerGeometryType @@ -33,24 +34,27 @@ def map_wire(wire, surface): return Part.Wire(mapped_edges) -def path2DToPathList(shapes: List[Polygon]) -> List[np.ndarray]: + +def path2DToPathList(shapes: List[shapely.geometry.polygon.Polygon]) -> List[np.ndarray]: """ - Returns the list of paths and coordinates from a cross-section (i.e. Trimesh Path2D). This is required to be - done for performing boolean operations and offsetting with the internal PyClipper package. - :param shapes: A list of :class:`shapely.geometry.Polygon` representing a cross-section or container of - closed polygons + Returns the list of paths and coordinates from a cross-section (i.e. :class:`Trimesh.path.Path2D` objects). + This is required to be done for performing boolean operations and offsetting with the internal PyClipper package. + + :param shapes: A list of Shapely Polygons representing a cross-section or container of + closed polygons :return: A list of paths (Numpy Coordinate Arrays) describing fully closed and oriented paths. - """ + """ + paths = [] for poly in shapes: coords = np.array(poly.exterior.coords) - paths.append(coords) - - for path in poly.interiors: - coords = np.array(path.coords) paths.append(coords) + for path in poly.interiors: + coords = np.array(path.coords) + paths.append(coords) + return paths @@ -100,7 +104,7 @@ def tuple_is_equal(t1, t2): def get_polygon_from_subshape(subshape): # print("START NEW POLYGON") polygon = [] - for edge in Part.__sortEdges__(subshape.Edges): + for edge in subshape.Edges: # Part.__sortEdges__(subshape.Edges): poly_points = [] if type(edge.Curve) in [Part.Ellipse, Part.BSplineCurve, Part.Circle]: n = math.floor(edge.Length/2.3) @@ -131,6 +135,7 @@ def get_coords_from_shape(face): tmp = get_polygon_from_subshape(inner_wire) inner_polys.append(tmp) poly = Polygon(outerpoly, holes=inner_polys) + print("Polygon: ", poly) return path2DToPathList([poly]) @@ -153,8 +158,8 @@ def create_contour_lines(geoms): for geom in geoms: if geom.type() == LayerGeometryType.Polygon: # print("Contour with {} coords".format(len(geom.coords))) - coords = rdp.rdp(geom.coords, epsilon=0.3, algo="iter", return_mask=False) - # print("Simplfied Poly:", len(coords)) - pp = Part.makePolygon([App.Vector(x,y,0) for (x,y) in coords]) + #coords = rdp.rdp(geom.coords, epsilon=0.3, algo="iter", return_mask=False) + #print("Simplfied Poly:", len(coords)) + pp = Part.makePolygon([App.Vector(x,y,0) for (x,y) in geom.coords]) contours.append(pp) return contours