Example #1
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            solids = self.inputs[0].sv_get()

            faces = []
            faces_add = faces.extend if self.flat_output else faces.append
            wires = []
            wires_add = wires.extend if self.flat_output else wires.append
            face_trims_out = []
            for solid in solids:
                face_surface = []
                outer_wires = []
                for f in solid.Faces:
                    surface = SvSolidFaceSurface(f)
                    if self.nurbs_output:
                        out_surface = SvNurbsSurface.get(surface)
                        if out_surface is None:
                            out_surface = surface
                    else:
                        out_surface = surface
                    face_surface.append(out_surface)
                    outer_wire = []
                    face_trims = []
                    for e in f.OuterWire.Edges:
                        try:
                            if self.nurbs_output:
                                outer_wire.append(
                                    SvSolidEdgeCurve(e).to_nurbs())
                            else:
                                outer_wire.append(SvSolidEdgeCurve(e))
                        except TypeError:
                            pass
                        trim, m, M = f.curveOnSurface(e)
                        if self.nurbs_output:
                            trim = trim.toBSpline(m, M)
                            trim = SvFreeCadNurbsCurve(trim, ndim=2)
                        else:
                            #trim = trim.trim(m, M)
                            trim = SvFreeCadCurve(trim, (m, M), ndim=2)
                        face_trims.append(trim)
                    #face_trims = SvConcatCurve(face_trims)

                    outer_wires.append(outer_wire)
                    face_trims_out.append(face_trims)

                faces_add(face_surface)
                wires_add(outer_wires)

            self.outputs['Solid Faces'].sv_set(faces)
            self.outputs['Outer Wire'].sv_set(wires)
            if 'TrimCurves' in self.outputs:
                self.outputs['TrimCurves'].sv_set(face_trims_out)
Example #2
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            solids_in = self.inputs[0].sv_get(deepcopy=False)
            matrixes = self.inputs[1].sv_get(deepcopy=False)
            slices = []
            slices_face = []
            faces_add = slices_face.extend if self.flat_output else slices_face.append
            slices_add = slices.extend if self.flat_output else slices.append

            for solid, matrix in zip(*mlr([solids_in, matrixes])):

                location = matrix.decompose()[0]
                norm = (matrix @ Vector((0, 0, 1))) - location
                dist = norm.dot(location)

                wires = solid.slice(Base.Vector(norm), dist)
                edges_curves = []
                faces = []
                for wire in wires:
                    for edge in wire.Edges:
                        curve = SvSolidEdgeCurve(edge)
                        edges_curves.append(curve)

                if wires:
                    face = Part.Face(wires)
                    faces.append(SvSolidFaceSurface(face).to_nurbs())
                if faces:
                    faces_add(faces)
                if edges_curves:
                    slices_add(edges_curves)

            self.outputs['Edges'].sv_set(slices)
            self.outputs['Faces'].sv_set(slices_face)
Example #3
0
    def project(self, face_surface, sv_curve, point, vector):
        nurbs_curve = curve_to_freecad_nurbs(sv_curve)
        if nurbs_curve is None:
            raise Exception("Curve is not NURBS!")
        fc_curve = nurbs_curve.curve
        fc_edge = Part.Edge(fc_curve)
        # face_surface : SvFreeCadNurbsSurface
        fc_face = face_surface.face

        if self.projection_type == 'PARALLEL':
            vector = Base.Vector(*vector)
            projection = fc_face.makeParallelProjection(fc_edge, vector).Edges
        elif self.projection_type == 'PERSPECTIVE':
            point = Base.Vector(*point)
            projection = fc_face.makePerspectiveProjection(fc_edge,
                                                           point).Edges
        else:  # ORTHO
            projection = fc_face.project([fc_edge]).Edges

        if not projection:
            if self.projection_type == 'PARALLEL':
                words = f"along {vector}"
            elif self.projection_type == 'PERSPECTIVE':
                words = f"from {point}"
            else:
                words = ""
            raise Exception(
                f"Projection {words} of {sv_curve} onto {face_surface} is empty for some reason"
            )

        trims = [self.get_trim(fc_face, edge) for edge in projection]
        edges = [SvSolidEdgeCurve(edge).to_nurbs() for edge in projection]

        return edges, trims
Example #4
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            solids = self.inputs[0].sv_get()

            edges = []
            edges_add = edges.extend if self.flat_output else edges.append
            for solid in solids:
                edges_curves = []
                for e in solid.Edges:
                    try:
                        curve = SvSolidEdgeCurve(e)
                        if self.nurbs_output:
                            curve = curve.to_nurbs()
                        edges_curves.append(curve)
                    except TypeError:
                        pass

                edges_add(edges_curves)

            self.outputs['Edges'].sv_set(edges)
Example #5
0
    def cut(self, face_surface, sv_curves, point, vector):
        # face_surface : SvFreeCadNurbsSurface
        nurbs = [SvNurbsCurve.to_nurbs(curve) for curve in sv_curves]
        if any(c is None for c in nurbs):
            raise Exception("One of curves is not a NURBS!")
        fc_nurbs_curves = [SvFreeCadNurbsCurve.from_any_nurbs(c) for c in nurbs]
        fc_nurbs = [c.curve for c in fc_nurbs_curves]
        if self.projection_type in {'PARALLEL', 'PERSPECTIVE', 'ORTHO'}:
            try:
                fc_edges = [Part.Edge(c) for c in fc_nurbs]
            except Exception as e:
                raise Exception(f"Can't build edges from {fc_nurbs}: {e}")
        fc_face = Part.Face(face_surface.surface)

        if self.projection_type == 'PARALLEL':
            vector = Base.Vector(*vector)
            projections = [fc_face.makeParallelProjection(edge, vector) for edge in fc_edges]
            projections = [p.Edges for p in projections]
        elif self.projection_type == 'PERSPECTIVE':
            point = Base.Vector(*point)
            projections = [fc_face.makePerspectiveProjection(edge, point).Edges for edge in fc_edges]
        elif self.projection_type == 'ORTHO':
            projections = [fc_face.project(fc_edges).Edges]
        else: # UV
            uv_curves = [c.to_2d() for c in fc_nurbs_curves]
            fc_nurbs_2d = [c.curve for c in uv_curves]
            projections = [[c.toShape(face_surface.surface) for c in fc_nurbs_2d]]

        projections = sum(projections, [])
        if not projections:
            words = f"along {vector}" if self.projection_type == 'PARALLEL' else f"from {point}"
            raise Exception(f"Projection {words} of {sv_curves} onto {face_surface} is empty for some reason")
        try:
            wire = Part.Wire(projections)
        except Exception as e:
            ps = [SvFreeCadNurbsCurve(p.Curve) for p in projections]
            raise Exception(f"Can't make a valid Wire out of curves {sv_curves} projected onto {face_surface}:\n{e}\nProjections are: {ps}")

        cut_fc_face = Part.Face(face_surface.surface, wire)
        cut_face_surface = SvFreeCadNurbsSurface(face_surface.surface, face=cut_fc_face) 

        if self.projection_type != 'UV':
            uv_curves = []
            for edge in cut_fc_face.OuterWire.Edges:
                trim,m,M = cut_fc_face.curveOnSurface(edge)
                trim = SvFreeCadCurve(trim, (m,M), ndim=2)
                uv_curves.append(trim)

        projections = [SvSolidEdgeCurve(p) for p in projections]
        return uv_curves, projections, cut_face_surface
Example #6
0
            def get_faces(solid):
                face_surface = []
                outer_wires = []
                trims = []
                for f in solid.Faces:
                    surface = SvSolidFaceSurface(f)
                    if self.nurbs_output:
                        out_surface = SvNurbsSurface.get(surface)
                        if out_surface is None:
                            out_surface = surface
                    else:
                        out_surface = surface
                    face_surface.append(out_surface)
                    outer_wire = []
                    face_trims = []
                    for e in f.OuterWire.Edges:
                        try:
                            if self.nurbs_output:
                                outer_wire.append(SvSolidEdgeCurve(e).to_nurbs())
                            else:
                                outer_wire.append(SvSolidEdgeCurve(e))
                        except TypeError:
                            pass
                        trim,m,M = f.curveOnSurface(e)
                        if self.nurbs_output:
                            trim = trim.toBSpline(m,M)
                            trim = SvFreeCadNurbsCurve(trim, ndim=2)
                        else:
                            #trim = trim.trim(m, M)
                            trim = SvFreeCadCurve(trim, (m,M), ndim=2)
                        face_trims.append(trim)

                    outer_wires.append(outer_wire)
                    trims.append(face_trims)

                return face_surface, outer_wires, trims