예제 #1
0
    def restore_location(self, dct):
        scale = dct["scale"]
        eye = point3(dct["eye"])
        center = point3(dct["center"])

        self.set_center(center)
        self.set_eye(eye)
        self.set_scale(scale)
        self.redraw()

        self.update_orient1_from_view()
        self.location_changed_handle()
예제 #2
0
파일: curve_algo.py 프로젝트: mirmik/zencad
    def endpoints(self):
        """Get tuple of start and finish point of current curve object 
           (if it exists)."""

        assert (self.is_wire_or_edge())

        if self.is_wire():
            a, b = TopoDS_Vertex(), TopoDS_Vertex()
            topexp.Vertices(self.Wire(), a, b)
            return point3(a), point3(b)

        elif self.is_edge():
            a = topexp.FirstVertex(self.Edge())
            b = topexp.LastVertex(self.Edge())
            return point3(a), point3(b)
예제 #3
0
    def svg_elliptic_arc(self, rx, ry, x_axis_angle, large, sweep, x, y):

        centers = zencad.gutil.restore_ellipse_centers(self.current,
                                                       point3(x, y), rx, ry,
                                                       x_axis_angle)
        target = point3(x, y)

        for cent in centers:
            full_edge = zencad.ellipse(rx, ry, wire=True) \
             .rotZ(x_axis_angle)            \
             .mov(cent)

            start_point_parameter = full_edge.project(self.current)
            finish_point_parameter = full_edge.project(target)

            diff = finish_point_parameter - start_point_parameter

            if not sweep:
                if diff < 0: diff += 2 * math.pi
                if start_point_parameter > finish_point_parameter:
                    start_point_parameter -= 2 * math.pi

                assert start_point_parameter < finish_point_parameter
            else:
                if diff > 0: diff -= 2 * math.pi
                if start_point_parameter < finish_point_parameter:
                    start_point_parameter += 2 * math.pi

                assert start_point_parameter > finish_point_parameter

            if abs(diff) < math.pi and large:
                continue

            if abs(diff) > math.pi and not large:
                continue
            if not sweep:
                trimmed = full_edge.trim(start_point_parameter,
                                         finish_point_parameter)
            else:
                trimmed = full_edge.trim(finish_point_parameter,
                                         start_point_parameter)

            self.edges.append(trimmed)
            break

        self.current = target
예제 #4
0
파일: curve_algo.py 프로젝트: mirmik/zencad
    def circle_parameters(self):
        if self.curvetype() != "circle":
            raise Exception("curve is not circle")

        o = self.AdaptorCurve().Circle()
        p = o.Position()

        return (point3(p.Location()), o.Radius(), vector3(p.XDirection()),
                vector3(p.YDirection()))
예제 #5
0
파일: curve_algo.py 프로젝트: mirmik/zencad
    def ellipse_parameters(self):
        if self.curvetype() != "ellipse":
            raise Exception("curve is not ellipse")

        o = self.AdaptorCurve().Ellipse()
        p = o.Position()

        return (point3(p.Location()), o.MajorRadius(), o.MinorRadius(),
                vector3(p.XDirection()), vector3(p.YDirection()))
예제 #6
0
def _ngon(r, n, wire=False):
    pnts = [0] * n

    for i in range(n):
        angle = 2 * math.pi / n * i
        pnts[i] = point3(r * math.cos(angle), r * math.sin(angle), 0)

    if wire:
        return wire_module.polysegment(pnts, closed=True)
    return polygon(pnts)
예제 #7
0
    def intersect_point(self, x, y):
        self.Select(x, y)

        viewLine = self.viewline(x, y)

        for i in range(len(self.selected_shapes)):
            hShape = AIS_Shape.DownCast(self.selected_ishapes[i])
            shape = hShape.Shape()

            loc = self.Context.Location(hShape)
            loc_shape = shape.Located(loc)

            shapeIntersector = IntCurvesFace_ShapeIntersector()
            shapeIntersector.Load(loc_shape, precision_Confusion())
            shapeIntersector.Perform(viewLine, float("-inf"), float("+inf"))

            if shapeIntersector.NbPnt() >= 1:
                ip = shapeIntersector.Pnt(1)
                return point3(ip), True
            else:
                continue

        return point3(), False
예제 #8
0
    def plane_circle_arc(self, r, angle, large, sweep, x, y):
        centers = zencad.gutil.restore_circle_centers(
            self.current, point3(x, y), r)
        target = point3(x, y)

        cent = None

        if centers[0].early(centers[1]):
            cent = centers[0]

            if sweep:
                self.arc(cent, r, deg(180))
            else:
                self.arc(cent, r, -deg(180))

        else:
            for c in centers:

                cv = self.current - c
                tv = target - c

                angle = cv.angle(tv)
                if cv.cross(tv).z < 0:
                    angle = -angle

                if large:
                    if angle <= 0:
                        angle += math.pi * 2
                    else:
                        angle -= math.pi * 2

                if angle >= 0 and sweep is True:
                    self.arc(c, r, angle)

                if angle < 0 and sweep is False:
                    self.arc(c, r, angle)
예제 #9
0
    def vertices(self):
        verts = self.native_vertices()
        pnts = []
        pnts_filtered = []

        for vertex in verts:
            pnt = BRep_Tool.Pnt(vertex.Vertex())
            pnts.append(point3(pnt))

        # Фильтруем вершины, исключая близколежащие.
        for p in pnts:
            for f in pnts_filtered:
                if numpy.linalg.norm(p-f) < 1e-5:
                    break
            else:
                pnts_filtered.append(p)

        return pnts_filtered
예제 #10
0
 def eye(self):
     return point3(self._display.View.Eye())
예제 #11
0
 def restart(self, pnt, y=None, z=None):
     pnt = self.collect_point(pnt, y, z)
     self.edges = []
     self.current = point3(pnt)
     self.start = self.current
     return self
예제 #12
0
 def __init__(self, start=(0, 0, 0), defrel=False):
     self.edges = []
     self.current = point3(start)
     self.start = self.current
     self.default_rel = defrel
예제 #13
0
def circle_arc(p1, p2, p3):
    """Построение дуги круга по трем точкам"""
    return pyservoce.circle_arc(point3(p1), point3(p2), point3(p3))
예제 #14
0
파일: project.py 프로젝트: mirmik/zencad
def project_point_on_curve(pnt, crv):
    algo = GeomAPI_ProjectPointOnCurve(to_Pnt(pnt), crv.Curve())
    return point3(algo.NearestPoint())
예제 #15
0
def restore_ellipse_centers(apnt, bpnt, r1, r2, phi):
    """
            Поиск центра двумерного элипса по радиусам, углу наклона главной оси и двум точкам.
    """

    rot = rotateZ(phi)
    irot = rot.inverse()

    x1, y1, _ = irot(apnt)
    x2, y2, _ = irot(bpnt)

    a, b = r1**2, r2**2

    if abs(a - b) < 1e-5 and abs(sqrt((x1 - x2)**2 +
                                      (y1 - y2)**2) - r1 * 2) < 1e-5:
        return point3((apnt.x + bpnt.x) / 2, (apnt.y + bpnt.y) / 2), point3(
            (apnt.x + bpnt.x) / 2, (apnt.y + bpnt.y) / 2)

    if abs(x1 - x2) < 1e-5:
        y01 = (y1 + y2) / 2
        x01 = x1 - sqrt(-a * b *
                        (-4 * b + y1**2 - 2 * y1 * y2 + y2**2)) / (2 * b)
        y02 = (y1 + y2) / 2
        x02 = x1 + sqrt(-a * b *
                        (-4 * b + y1**2 - 2 * y1 * y2 + y2**2)) / (2 * b)

    elif abs(y1 - y2) < 1e-5:
        y01 = y1 - sqrt(-a * b *
                        (-4 * a + x1**2 - 2 * x1 * x2 + x2**2)) / (2 * a)
        x01 = (x1 + x2) / 2
        y02 = y1 + sqrt(-a * b *
                        (-4 * a + x1**2 - 2 * x1 * x2 + x2**2)) / (2 * a)
        x02 = (x1 + x2) / 2

    else:
        y01 = -(-a * y1**2 + a * y2**2 - b * x1**2 + b * x2**2 +
                (2 * b * x1 - 2 * b * x2) *
                (x1 / 2 + x2 / 2 -
                 sqrt(-a * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 +
                                b * x1**2 - 2 * b * x1 * x2 + b * x2**2) *
                      (-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 +
                       b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) /
                 (2 * b *
                  (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
                   2 * b * x1 * x2 + b * x2**2)))) / (2 * a * (y1 - y2))
        x01 = x1 / 2 + x2 / 2 - sqrt(
            -a * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
                      2 * b * x1 * x2 + b * x2**2) *
            (-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
             2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) / (
                 2 * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
                          2 * b * x1 * x2 + b * x2**2))

        y02 = -(-a * y1**2 + a * y2**2 - b * x1**2 + b * x2**2 +
                (2 * b * x1 - 2 * b * x2) *
                (x1 / 2 + x2 / 2 +
                 sqrt(-a * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 +
                                b * x1**2 - 2 * b * x1 * x2 + b * x2**2) *
                      (-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 +
                       b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) /
                 (2 * b *
                  (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
                   2 * b * x1 * x2 + b * x2**2)))) / (2 * a * (y1 - y2))
        x02 = x1 / 2 + x2 / 2 + sqrt(
            -a * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
                      2 * b * x1 * x2 + b * x2**2) *
            (-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
             2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) / (
                 2 * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
                          2 * b * x1 * x2 + b * x2**2))

    c0, c1 = point3(x01, y01), point3(x02, y02)
    c0, c1 = rot(c0), rot(c1)

    return c0, c1
예제 #16
0
파일: line.py 프로젝트: mirmik/zencad
 def set_points(self, p1, p2):
     self.p1 = point3(p1)
     self.p2 = point3(p2)
     p1 = Geom_CartesianPoint(to_Pnt(self.p1))
     p2 = Geom_CartesianPoint(to_Pnt(self.p2))
     self.ais_object.SetPoints(p1, p2)
예제 #17
0
                      (-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 +
                       b * x1**2 - 2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) /
                 (2 * b *
                  (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
                   2 * b * x1 * x2 + b * x2**2)))) / (2 * a * (y1 - y2))
        x02 = x1 / 2 + x2 / 2 + sqrt(
            -a * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
                      2 * b * x1 * x2 + b * x2**2) *
            (-4 * a * b + a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
             2 * b * x1 * x2 + b * x2**2)) * (y1 - y2) / (
                 2 * b * (a * y1**2 - 2 * a * y1 * y2 + a * y2**2 + b * x1**2 -
                          2 * b * x1 * x2 + b * x2**2))

    c0, c1 = point3(x01, y01), point3(x02, y02)
    c0, c1 = rot(c0), rot(c1)

    return c0, c1


def restore_circle_centers(apnt, bpnt, r):
    """
            Поиск центра двумерной окружности по радиусу, углу наклона главной оси и двум точкам.
    """

    return restore_ellipse_centers(apnt, bpnt, r, r, 0)


# TEST
if __name__ == "__main__":
    print(restore_ellipse_centers(point3(15, 10), point3(5, 10), 5, 5, 0))
예제 #18
0
def scale(factor, center):
    if factor is list or factor is tuple:
        return pyservoce.scaleXYZ(factor[0], factor[1], factor[2])
    return pyservoce.scale(factor, point3(center).to_servoce())
예제 #19
0
파일: curve_algo.py 프로젝트: mirmik/zencad
 def d0(self, arg):
     assert (self.is_edge())
     adaptor = self.AdaptorCurve()
     pnt = gp_Pnt()
     self.AdaptorCurve().D0(arg, pnt)
     return point3(pnt.X(), pnt.Y(), pnt.Z())
예제 #20
0
파일: trans.py 프로젝트: mirmik/zencad
def scale(s, center=(0, 0, 0)):
    trsf = gp_Trsf()
    trsf.SetScale(point3(center).Pnt(), s)
    return Transformation(trsf)
예제 #21
0
파일: transform.py 프로젝트: sevikkk/zencad
def scale(factor, center):
    return pyservoce.scale(factor, point3(center).to_servoce())
예제 #22
0
 def center(self):
     return point3(self._display.View.Camera().Center())
예제 #23
0
def _scale_do(self, factor, center=pyservoce.libservoce.point3(0, 0, 0)):
    if isinstance(factor, (list, tuple)):
        return pyservoce.Shape.scaleXYZ(self, factor[0], factor[1], factor[2])
    return pyservoce.Shape.scale(self, factor, point3(center))
예제 #24
0
 def centering(self):
     self.set_center(point3(0, 0, 0))