Exemple #1
0
    def __init__(self, crv, pln, direction=None, keep_param=True):
        super(ProjectCurveToPlane, self).__init__()

        direction = CheckGeom.to_direction(direction)
        if not CheckGeom.is_direction(direction):
            direction = pln.object.Pln().Axis().Direction()

        # OCC projection
        hcrv = GeomProjLib.ProjectOnPlane_(crv.object, pln.object, direction,
                                           keep_param)

        self._crv = Curve(hcrv)
Exemple #2
0
    def cut_hole(self, d, ds, u0=None, is_rel=False):
        """
        Cut a hole in the part and update its shape.

        :param float d: Diameter of hole.
        :param float ds: The distance.
        :param float u0: The parameter. If not provided the first parameter
            of the reference curve will be used.
        :param bool is_rel: Option specifying if the distance is absolute or
            a relative to the length of the reference curve. If relative, then
            *ds* is multiplied by the curve length to get the absolute value.

        :return: The status of the Boolean operation that will cut the hole.
            *True* if the operation was performed, *False* if not.
        :rtype: bool

        :raise AttributeError: If the part does not have a reference curve or
            surface.
        """
        if not self.has_cref:
            msg = 'Part does not have a reference curve.'
            raise AttributeError(msg)

        if not self.has_sref:
            msg = 'Part does not have a reference surface.'
            raise AttributeError(msg)

        # Intersect the shape with a plane to use for the hole height location
        pln = self.plane_from_parameter(ds, u0, is_rel)
        bop = IntersectShapes(self._shape, pln)
        wires = WiresByShape(bop.shape).wires
        los = LengthOfShapes(wires)
        max_length = los.max_length
        wire = los.longest_shape
        if not isinstance(wire, Wire):
            return False
        mid_length = max_length / 2.
        p = PointAlongShape(wire, mid_length).point
        u, v = self.invert_sref(p)
        v = self.sref.norm(u, v)
        v = CheckGeom.to_direction(v)
        ax1 = Axis1(p, v)

        # Cut the hole
        r = d / 2.
        bop = CutCylindricalHole(self._shape, r, ax1)
        self.set_shape(bop.shape)

        return bop.is_done
Exemple #3
0
    def __init__(self, pnt, srf, direction=None, update=False, tol=1.0e-7):
        super(ProjectPointToSurface, self).__init__()

        pnt = CheckGeom.to_point(pnt)
        direction = CheckGeom.to_direction(direction)
        adp_srf = AdaptorSurface.to_adaptor(srf)
        self._results = []

        if not direction:
            ext = Extrema_ExtPS(pnt, adp_srf.object, tol, tol)
            npts = ext.NbExt()
            for i in range(1, npts + 1):
                pos = ext.Point(i)
                ui, vi = pos.Parameter(0., 0.)
                pi = adp_srf.eval(ui, vi)
                di = sqrt(ext.SquareDistance(i))
                self._results.append([pi, (ui, vi), di])
        else:
            # Use minimum distance between line and surface to project point
            # along a direction.
            line = Line.by_direction(pnt, direction)
            adp_crv = AdaptorCurve.to_adaptor(line)
            ext = Extrema_ExtCS(adp_crv.object, adp_srf.object, tol, tol)
            npts = ext.NbExt()
            for i in range(1, npts + 1):
                poc, pos = Extrema_POnCurv(), Extrema_POnSurf()
                ext.Points(i, poc, pos)
                ui, vi = pos.Parameter(0., 0.)
                pi = adp_srf.eval(ui, vi)
                di = sqrt(ext.SquareDistance(i))
                self._results.append([pi, (ui, vi), di])

        # Sort by distance and return.
        if self._results:
            self._results.sort(key=lambda lst: lst[2])

        if update:
            pnt.set_xyz(self.nearest_point)
Exemple #4
0
    def __init__(self, pnt, crv, direction=None, update=False):
        super(ProjectPointToCurve, self).__init__()

        pnt = CheckGeom.to_point(pnt)
        direction = CheckGeom.to_direction(direction)
        adp_crv = AdaptorCurve.to_adaptor(crv)
        self._results = []

        if not direction:
            ext = Extrema_ExtPC(pnt, adp_crv.object)
            npts = ext.NbExt()
            for i in range(1, npts + 1):
                poc = ext.Point(i)
                ui = poc.Parameter()
                pi = adp_crv.eval(ui)
                di = sqrt(ext.SquareDistance(i))
                self._results.append([pi, ui, di])
        else:
            # Use minimum distance between line and curve to project point
            # along a direction.
            line = Line.by_direction(pnt, direction)
            adp_crv2 = AdaptorCurve.to_adaptor(line)
            ext = Extrema_ExtCC(adp_crv.object, adp_crv2.object)
            npts = ext.NbExt()
            for i in range(1, npts + 1):
                poc1, poc2 = Extrema_POnCurv(), Extrema_POnCurv()
                ext.Points(i, poc1, poc2)
                ui = poc1.Parameter()
                pi = adp_crv.eval(ui)
                di = sqrt(ext.SquareDistance(i))
                self._results.append([pi, ui, di])

        # Sort by distance and return.
        if self._results:
            self._results.sort(key=lambda lst: lst[2])

        if update:
            pnt.set_xyz(self.nearest_point)