def transform_csg(layerdef_from, layerdef_to, inshift, outshift, step,
                  geom_from, geoms_to, csg_laminate, scale_x, scale_y):
    from popupcad.filetypes.laminate import Laminate
    import shapely.affinity as aff
    from popupcad.algorithms.points import calctransformfrom2lines

    lsout = Laminate(layerdef_to)

    for layer_from, layer_to in zip(layerdef_from.layers[::step][inshift:],
                                    layerdef_to.layers[outshift:]):
        newgeoms = []
        for geom in geoms_to:
            for designgeom in csg_laminate.layer_sequence[layer_from].geoms:
                try:
                    from_line = geom_from.exteriorpoints(
                        scaling=popupcad.csg_processing_scaling)
                    to_line = geom.exteriorpoints(
                        scaling=popupcad.csg_processing_scaling)
                    transform = calctransformfrom2lines(from_line,
                                                        to_line,
                                                        scale_x=scale_x,
                                                        scale_y=scale_y)
                    transformed_geom = aff.affine_transform(
                        designgeom, transform)
                    newgeoms.append(transformed_geom)
                except IndexError:
                    pass
        result1 = popupcad.algorithms.csg_shapely.unary_union_safe(newgeoms)
        results2 = popupcad.algorithms.csg_shapely.condition_shapely_entities(
            result1)
        lsout.replacelayergeoms(layer_to, results2)

    return lsout
Beispiel #2
0
    def operate(self,design):
        import shapely.affinity as aff
        subdesign = design.subdesigns[self.subdesignid]

        locateline = subdesign.findlocateline()

        try:
            designgeometry = subdesign.operations[subdesign.operation_index(self.subopid)].output[self.getoutputref()].csg
        except AttributeError:
            subdesign.reprocessoperations()
            designgeometry = subdesign.operations[subdesign.operation_index(self.subopid)].output[self.getoutputref()].csg
            
        sketch = design.sketches[self.sketchid]

        if self.transformtype==self.transformtypes.place:
            scale_x = 1.
            scale_y = 1.
        elif self.transformtype==self.transformtypes.stretch:
            scale_x = None
            scale_y = 1.
        if self.transformtype==self.transformtypes.scale:
            scale_x = None
            scale_y = None
        if self.transformtype==self.transformtypes.custom:
            scale_x = self.scalex
            scale_y = self.scaley

        lsout = Laminate(design.return_layer_definition())
        step = 1
        if self.flip:
            step = -1
        if self.shift > 0:
            outshift = self.shift
            inshift = 0
        elif self.shift <0:
            outshift = 0
            inshift = -self.shift
        else:
            outshift = 0
            inshift = 0
            
        for layerout,layerin in zip(design.return_layer_definition().layers[outshift:],subdesign.return_layer_definition().layers[::step][inshift:]):
            newgeoms = []
            for geom in sketch.operationgeometry:
                for designgeom in designgeometry.layer_sequence[layerin].geoms:
                    try:
                        newgeoms.append(aff.affine_transform(designgeom,calctransformfrom2lines(locateline.exteriorpoints(),geom.exteriorpoints(),scale_x = scale_x,scale_y = scale_y)))
                    except IndexError:
                        pass
            newgeoms = customshapely.unary_union_safe(newgeoms)
            newgeoms = popupcad.geometry.customshapely.multiinit(newgeoms)
            lsout.replacelayergeoms(layerout,newgeoms)
            
        return lsout
def cross_section(layerdef, sketch, parent, scale_value):
    from popupcad.filetypes.laminate import Laminate
    from popupcad.filetypes.genericshapes import GenericLine
    import shapely.affinity as aff
    import popupcad.algorithms.points as points
    import shapely.geometry as sg
    import numpy

    laminate = Laminate(layerdef)
    for item in sketch.operationgeometry:
        if isinstance(item, GenericLine):
            line = item
            b = line.exteriorpoints(scaling=popupcad.csg_processing_scaling)[0]
            c = numpy.array(b) + numpy.array([1, 0])
            a = points.calctransformfrom2lines(
                line.exteriorpoints(scaling=popupcad.csg_processing_scaling),
                [b, c.tolist()],
                scale_x=1,
                scale_y=1)
            sketch_csg = sketch.output_csg()

            for layer in layerdef.layers:
                laminate.replacelayergeoms(layer, sketch_csg)
            result = parent.intersection(laminate)
            laminate2 = Laminate(layerdef)
            for ii, layerid in enumerate(layerdef.layers):
                yshift = layerdef.z_values[
                    layerid] * popupcad.csg_processing_scaling * scale_value
                layer = result.layer_sequence[layerid]
                thickness = layerid.thickness * popupcad.csg_processing_scaling * scale_value
                newgeoms = [item for item in layer.geoms]
                newgeoms = [aff.affine_transform(item, a) for item in newgeoms]
                newgeoms2 = []
                for geom in newgeoms:
                    newgeom = sg.box(geom.coords[0][0], geom.coords[0][1],
                                     geom.coords[-1][0],
                                     geom.coords[-1][1] + thickness)
                    newgeoms2.append(newgeom)
                newgeoms = newgeoms2
                newgeoms = [
                    aff.translate(item, yoff=yshift) for item in newgeoms
                ]
                newgeoms = popupcad.algorithms.csg_shapely.condition_shapely_entities(
                    *newgeoms)
                laminate2[ii] = newgeoms
            return laminate2

    return laminate
Beispiel #4
0
    def operate(self,design):
        from popupcad.filetypes.genericshapes import GenericLine
        import shapely.affinity as aff
        import popupcad.algorithms.points as points
        import popupcad
        import shapely.geometry as sg
        import numpy
        
        parent_ref,parent_index  = self.operation_links['source'][0]
        parent = design.op_from_ref(parent_ref).output[parent_index].csg
        
        sketch = design.sketches[self.sketch_links['cross_section'][0]]
        
        layerdef = design.return_layer_definition()
        laminate = Laminate(layerdef)
        for item in sketch.operationgeometry:
            if isinstance(item,GenericLine):
                line = item
                b = line.exteriorpoints()[0]
                c = numpy.array(b)+numpy.array([1,0])
                a = points.calctransformfrom2lines(line.exteriorpoints(),[b,c.tolist()],scale_x=1,scale_y=1)            
                sketch_csg = sketch.output_csg()
                
                for layer in layerdef.layers:
                    laminate.replacelayergeoms(layer,sketch_csg)
                result = parent.intersection(laminate)
                laminate2 = Laminate(layerdef)
                for ii,layerid in enumerate(layerdef.layers):
#                for ii,layer in enumerate(result):
                    yshift = layerdef.zvalue[layerid] * self.scale_value
                    layer = result.layer_sequence[layerid]
                    thickness = layerid.thickness*popupcad.internal_argument_scaling*self.scale_value
                    newgeoms = [item for item in layer.geoms]
                    newgeoms = [aff.affine_transform(item,a) for item in newgeoms]
#                    newgeoms = [item.buffer(bufferval) for item in newgeoms]
                    newgeoms2 = []
                    for geom in newgeoms:
                        newgeom = sg.box(geom.coords[0][0],geom.coords[0][1],geom.coords[-1][0],geom.coords[-1][1]+thickness)
                        newgeoms2.append(newgeom)
                    newgeoms = newgeoms2
                    newgeoms = [aff.translate(item,yoff = yshift) for item in newgeoms]
                    newgeoms = popupcad.geometry.customshapely.multiinit(*newgeoms)
                    laminate2[ii] = newgeoms
                return laminate2

        return laminate
def cross_section(layerdef, sketch, parent, scale_value):
    from popupcad.filetypes.laminate import Laminate
    from popupcad.filetypes.genericshapes import GenericLine
    import shapely.affinity as aff
    import popupcad.algorithms.points as points
    import shapely.geometry as sg
    import numpy

    laminate = Laminate(layerdef)
    for item in sketch.operationgeometry:
        if isinstance(item, GenericLine):
            line = item
            b = line.exteriorpoints(scaling = popupcad.csg_processing_scaling)[0]
            c = numpy.array(b) + numpy.array([1, 0])
            a = points.calctransformfrom2lines(
                line.exteriorpoints(scaling = popupcad.csg_processing_scaling), [
                    b, c.tolist()], scale_x=1, scale_y=1)
            sketch_csg = sketch.output_csg()

            for layer in layerdef.layers:
                laminate.replacelayergeoms(layer, sketch_csg)
            result = parent.intersection(laminate)
            laminate2 = Laminate(layerdef)
            for ii, layerid in enumerate(layerdef.layers):
                #                for ii,layer in enumerate(result):
                yshift = layerdef.zvalue[layerid] * popupcad.csg_processing_scaling * scale_value
                layer = result.layer_sequence[layerid]
                thickness = layerid.thickness * popupcad.csg_processing_scaling * scale_value
                newgeoms = [item for item in layer.geoms]
                newgeoms = [aff.affine_transform(item, a) for item in newgeoms]
#                    newgeoms = [item.buffer(bufferval) for item in newgeoms]
                newgeoms2 = []
                for geom in newgeoms:
                    newgeom = sg.box(geom.coords[0][0],
                                     geom.coords[0][1],
                                     geom.coords[-1][0],
                                     geom.coords[-1][1] + thickness)
                    newgeoms2.append(newgeom)
                newgeoms = newgeoms2
                newgeoms = [aff.translate(item,yoff=yshift) for item in newgeoms]
                newgeoms = popupcad.algorithms.csg_shapely.condition_shapely_entities(*newgeoms)
                laminate2[ii] = newgeoms
            return laminate2

    return laminate
def transform(
        layerdef,
        layerdef_subdesign,
        inshift,
        outshift,
        step,
        sketch,
        designgeometry,
        locateline,
        scale_x,
        scale_y):
    from popupcad.filetypes.laminate import Laminate
    import shapely.affinity as aff
    from popupcad.algorithms.points import calctransformfrom2lines

    lsout = Laminate(layerdef)

    for layerout, layerin in zip(
        layerdef.layers[
            outshift:], layerdef_subdesign.layers[
            ::step][
                inshift:]):
        newgeoms = []
        for geom in sketch.operationgeometry:
            if not geom.is_construction():
                for designgeom in designgeometry.layer_sequence[layerin].geoms:
                    try:
                        newgeoms.append(
                            aff.affine_transform(
                                designgeom,
                                calctransformfrom2lines(
                                    locateline.exteriorpoints(scaling = popupcad.csg_processing_scaling),
                                    geom.exteriorpoints(scaling = popupcad.csg_processing_scaling),
                                    scale_x=scale_x,
                                    scale_y=scale_y)))
                    except IndexError:
                        pass
        result1 = popupcad.algorithms.csg_shapely.unary_union_safe(newgeoms)
        results2 = popupcad.algorithms.csg_shapely.condition_shapely_entities(result1)
        lsout.replacelayergeoms(layerout, results2)

    return lsout