diff --git a/pyslm/hatching/hatching.py b/pyslm/hatching/hatching.py index e24cbb4..4f1b5be 100755 --- a/pyslm/hatching/hatching.py +++ b/pyslm/hatching/hatching.py @@ -711,6 +711,7 @@ def __init__(self): super().__init__() # Contour private attributes + self._scanContourFirst = False self._numInnerContours = 1 self._numOuterContours = 1 self._spotCompensation = 0.08 # mm @@ -759,12 +760,24 @@ def hatchSortMethod(self): return self._hatchSortMethod @hatchSortMethod.setter - def hatchSortMethod(self, sortObj): + def hatchSortMethod(self, sortObj: Any): if not isinstance(sortObj, BaseSort): raise TypeError("The Hatch Sort Method should be derived from the BaseSort class") self._hatchSortMethod = sortObj + @property + def scanContourFirst(self) -> bool: + """ + Determines if the contour/border vectors :class:`LayerGeometry` are scanned first before the hatch vectors. By + default this is set to `False`. + """ + return self._scanContourFirst + + @scanContourFirst.setter + def scanContourFirst(self, value: bool): + self._scanContourFirst = value + @property def numInnerContours(self) -> int: """ @@ -818,7 +831,7 @@ def hatch(self, boundaryFeature): :return: A :class:`Layer` object containing a list of :class:`LayerGeometry` objects generated """ if len(boundaryFeature) == 0: - return + return None layer = Layer(0, 0) # First generate a boundary with the spot compensation applied @@ -826,6 +839,10 @@ def hatch(self, boundaryFeature): offsetDelta = 0.0 offsetDelta -= self._spotCompensation + # Store all contour layer geometries to before adding at the end of each layer + contourLayerGeometries = [] + hatchLayerGeometries = [] + for i in range(self._numOuterContours): offsetDelta -= self._contourOffset offsetBoundary = self.offsetBoundary(boundaryFeature, offsetDelta) @@ -835,7 +852,7 @@ def hatch(self, boundaryFeature): contourGeometry = ContourGeometry() contourGeometry.coords = np.array(path)[:, :2] contourGeometry.subType = "outer" - layer.geometry.append(contourGeometry) # Append to the layer + contourLayerGeometries.append(contourGeometry) # Append to the layer # Repeat for inner contours for i in range(self._numInnerContours): @@ -848,7 +865,7 @@ def hatch(self, boundaryFeature): contourGeometry = ContourGeometry() contourGeometry.coords = np.array(path)[:, :2] contourGeometry.subType = "inner" - layer.geometry.append(contourGeometry) # Append to the layer + contourLayerGeometries.append(contourGeometry) # Append to the layer # The final offset is applied to the boundary @@ -920,7 +937,6 @@ def hatch(self, boundaryFeature): scanVectors.append(clippedLines) - if len(clippedLines) > 0: # Scan vectors have been created for the hatched region @@ -929,16 +945,21 @@ def hatch(self, boundaryFeature): # Only copy the (x,y) points from the coordinate array. hatchVectors = np.vstack(scanVectors) - hatchVectors = hatchVectors[:, :, :2].reshape(-1, 2) + hatchVectors = hatchVectors[:, :, :2].reshape(-1, 2) # Note the does not require positional sorting if self.hatchSortMethod: hatchVectors = self.hatchSortMethod.sort(hatchVectors) hatchGeom.coords = hatchVectors + hatchLayerGeometries.append(hatchGeom) - layer.geometry.append(hatchGeom) + if self._scanContourFirst: + layer.geometry.extend(contourLayerGeometries + hatchLayerGeometries) + else: + layer.geometry.extend(hatchLayerGeometries + contourLayerGeometries) + # Append the contours hatch vecotrs return layer