Exemplo n.º 1
0
def make_interp_parabola(FL, rmin, rmax, segments=50):
    A = 1./(4*FL)
    x = numpy.linspace(rmin, rmax, segments)
    y = (A * x**2) - FL
    
    points = [(X,0,Z) for X,Z in zip(x,y)]
    points.append((x[0],0,y[-1]))
    
    def pairs(itr):
        a,b = itertools.tee(itr)
        next(b)
        return zip(a,b)
    
    edges = (BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
                    gp.gp_Pnt(*p1), gp.gp_Pnt(*p2))
                    for p1, p2 in pairs(points))
    last_edge = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
                    gp.gp_Pnt(*points[-1]), 
                    gp.gp_Pnt(*points[0]))
    
    wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    for e in edges:
        wire.Add(e.Edge())
    wire.Add(last_edge.Edge())
    
    face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire())
    
    ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0),
                   gp.gp_Dir(0,0,1))
    
    revol = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax)
    
    return revol.Shape()
Exemplo n.º 2
0
def makeOffsetTestWire():
    "creates difficult test cases for offsetting"
    p1 = OCCUtil.pnt(11.0, 0)
    p2 = OCCUtil.pnt(7.0, 8.0)
    p3 = OCCUtil.pnt(7.0, 12.0)
    p4 = OCCUtil.pnt(17.0, 22.0)
    p5 = OCCUtil.pnt(0.0, 22.0)
    p6 = OCCUtil.pnt(3.0, 17.0)
    p7 = OCCUtil.pnt(4.0, 8.0)
    c1 = OCCUtil.pnt(10.0, 18.5)
    c2 = OCCUtil.pnt(6.0, 3.0)

    edges = []
    edges.append(OCCUtil.edgeFromTwoPoints(p1, p2))
    edges.append(OCCUtil.edgeFromTwoPoints(p2, p3))

    circle = GC.GC_MakeArcOfCircle(p3, c1, p4)
    #circle through 3 points
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle.Value()).Edge()
    edges.append(e2)

    edges.append(OCCUtil.edgeFromTwoPoints(p4, p5))
    edges.append(OCCUtil.edgeFromTwoPoints(p5, p6))
    edges.append(OCCUtil.edgeFromTwoPoints(p6, p7))

    circle = GC.GC_MakeArcOfCircle(p1, c2, p7)
    #circle through 3 points
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle.Value()).Edge()
    edges.append(e3)

    return OCCUtil.wireFromEdges(edges)
Exemplo n.º 3
0
def make_wire(listOfPoints, close=False):
    vertices = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*p))
                for p in listOfPoints]
    edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(),v2.Vertex())
         for v1,v2 in pairs(vertices)]
    if close:
        edges.append(BRepBuilderAPI.BRepBuilderAPI_MakeEdge(vertices[-1].Vertex(),
                                                            vertices[0].Vertex()))
    wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    for e in edges:
        wire.Add(e.Edge())
    return toshape(wire)
Exemplo n.º 4
0
def makeHeartWire():
    "make a heart wire"
    e1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(4.0, 4.0, 0))
    circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(2, 4, 0),
                                  gp.gp().DZ()), 2)
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(4, 4, 0),
                                                gp.gp_Pnt(0, 4, 0)).Edge()
    circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(-2, 4, 0),
                                  gp.gp().DZ()), 2)
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(0, 4, 0),
                                                gp.gp_Pnt(-4, 4, 0)).Edge()
    e4 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(-4, 4, 0), gp.gp_Pnt(0, 0, 0))
    return Wrappers.wireFromEdges([e1, e2, e3, e4])
Exemplo n.º 5
0
def makeReversedWire():
    "this is a square"
    p1 = gp.gp_Pnt(.5, .5, 0)
    p2 = gp.gp_Pnt(1, 4, 0)
    p3 = gp.gp_Pnt(2, 4, 0)
    e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3, p2).Edge()
    e2.Reverse()
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3, p1).Edge()
    mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    mw.Add(e1)
    mw.Add(e2)
    mw.Add(e3)
    return mw.Wire()
Exemplo n.º 6
0
    def preview(self, inp, direction):
        if self.step == 0:
            self.previous_data = [inp]
            return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()]
        elif self.step == 1:
            point0 = self.previous_data[0]
            point1 = inp
            # checking if the previous points are identical: This is necessary
            # before continuing in order to avoid a crash on Windows
            if point0 == point1:
                raise InvalidInputException
            dirvec = vec(0, 0, 0)
            dirvec[direction] = 1
            axis = gp.gp_Ax2(point0, dirvec.to_gp_Dir())

            d = point0 - inp
            d[direction] = 0
            dist = d.length()

            a = Geom.Geom_Circle(axis, dist).GetHandle()
            b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge()
            c = BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire()
            d = BRepBuilderAPI.BRepBuilderAPI_MakeFace(c).Face()
            self._final = [d]
            return self._final
Exemplo n.º 7
0
def edgeFromTwoPoints(p1, p2):
    builder = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p1, p2)
    builder.Build()
    if builder.IsDone():
        return builder.Edge()
    else:
        return None
Exemplo n.º 8
0
def makeBsplineEdge():
    pts = []
    pts.append(OCCUtil.pnt(0.0, 0))
    pts.append(OCCUtil.pnt(1.0, 0.0))
    pts.append(OCCUtil.pnt(1.2, 0.1))
    pts.append(OCCUtil.pnt(2.0, 2.0))
    pts.append(OCCUtil.pnt(2.0, 2.4))
    pts.append(OCCUtil.pnt(3.0, 2.4))
    pts.append(OCCUtil.pnt(4.0, 1.5))
    pts.append(OCCUtil.pnt(5.0, 1.5))
    pts.append(OCCUtil.pnt(4.0, 0))
    pts.append(OCCUtil.pnt(3.0, -0.1))
    pts.append(OCCUtil.pnt(2.0, -0.1))
    pts.append(OCCUtil.pnt(2.0, -0.1))
    pts.append(OCCUtil.pnt(2.0, 0.2))
    pts.append(OCCUtil.pnt(3.0, 0.5))
    pts.append(OCCUtil.pnt(3.0, 1.0))

    points = TColgp.TColgp_HArray1OfPnt(1, len(pts))
    i = 1
    for p in pts:
        points.SetValue(i, p)
        i += 1

    #q = time.clock();
    #for i in range(1000):
    gi = GeomAPI.GeomAPI_Interpolate(points.GetHandle(), False, 0.001)
    gi.Perform()
    curve = gi.Curve()
    #print "1000 iters: Elapsed: %0.3f " % ( time.clock() -  q)

    builder = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(curve)
    return builder.Edge()
Exemplo n.º 9
0
def normalEdgesAlongEdge(edge, length , interval):
	"compute an edge having length at the specified parameter on the supplied curve:"

	edgeList = [];
	
	ew = Wrappers.Edge(edge);
	zDir = gp.gp().DZ();
	zVec = gp.gp_Vec(zDir);
	
	curve = ew.curve;
	pStart = ew.firstParameter;
	pEnd = ew.lastParameter;
	
	for p in Wrappers.frange6(pStart,pEnd,interval):
		tangent = gp.gp_Vec();
		tanpoint = gp.gp_Pnt();
		curve.D1(p,tanpoint,tangent );
		axis = gp.gp_Ax1(tanpoint, gp.gp_Dir(tangent.Crossed(zVec) ) );
	
		line = Geom.Geom_Line(axis );
		e = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(line.GetHandle(),0, length).Edge();	
		if e:
			edgeList.append(e);
			
	return edgeList;
Exemplo n.º 10
0
 def preview(self, input, direction):
     point = input
     if self.step == 0 and point is not None:
         point1 = gp_.gp_Pnt_([0, 0, 0])
         a = GC.GC_MakeSegment(point1, point).Value()
         self._final = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Shape()
         return self._final,
Exemplo n.º 11
0
def makeSquareWire():
    "this is a square"
    p1 = gp.gp_Pnt(0, 0, 0)
    p2 = gp.gp_Pnt(5, 0, 0)
    p3 = gp.gp_Pnt(5, 5, 0)
    p4 = gp.gp_Pnt(0, 5, 0)
    e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2, p3).Edge()
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3, p4).Edge()
    e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4, p1).Edge()
    mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    mw.Add(e1)
    mw.Add(e2)
    mw.Add(e3)
    mw.Add(e4)
    return mw.Wire()
Exemplo n.º 12
0
def edgeFromTwoPoints(p1, p2):
    "make a linear edge from two points "
    builder = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p1, p2)
    builder.Build()
    if builder.IsDone():
        return builder.Edge()
    else:
        return None
Exemplo n.º 13
0
def makeKeyHoleWire():
    circle2 = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(40, 40, 2), gp.gp_Dir(0, 0, 1)),
                         10)
    Edge4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle2,
                                                   gp.gp_Pnt(40, 50, 2),
                                                   gp.gp_Pnt(50, 40,
                                                             2)).Edge()
    ExistingWire2 = BRepBuilderAPI.BRepBuilderAPI_MakeWire(Edge4).Wire()
    P1 = gp.gp_Pnt(50, 40, 2)
    P2 = gp.gp_Pnt(80, 40, 2)  #5,204,0
    Edge5 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(P1, P2).Edge()
    MW = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    MW.Add(Edge5)
    MW.Add(ExistingWire2)

    if MW.IsDone():
        WhiteWire = MW.Wire()
        return [WhiteWire, Edge5, ExistingWire2]
Exemplo n.º 14
0
def makeCircleWire():
    "designed to be include inside the square to simulate an island"

    circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(2, 2, 0),
                                  gp.gp().DZ()), 1)
    e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle).Edge()
    mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    mw.Add(e1)
    return mw.Wire()
Exemplo n.º 15
0
def segment_():

    p0 = gp_.gp_Pnt_([0, 0, 0])
    p1 = gp_.gp_Pnt_([1, 1, 1])
    a = GC.GC_MakeSegment(p0, p1).Value()
    print(type(a))
    print(dir(a.GetObject()))
    final = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Shape()
    print(type(final))
    print(dir(final.TShape().GetObject()))
    print(dir(final))
Exemplo n.º 16
0
def make_spherical_lens2(CT1, CT2, diameter, 
                         curvature1, curvature2, 
                        centre, direction, x_axis):
    cax = gp.gp_Ax2(gp.gp_Pnt(0,0,CT1-curvature1),
                    gp.gp_Dir(0,sign(curvature1),0),
                    gp.gp_Dir(1,0,0))
    circ = Geom.Geom_Circle(cax, abs(curvature1))
    h_circ = Geom.Handle_Geom_Circle(circ)
    
    cax2 = gp.gp_Ax2(gp.gp_Pnt(0,0,CT2-curvature2),
                    gp.gp_Dir(0,-sign(curvature2),0),
                    gp.gp_Dir(1,0,0))
    circ2 = Geom.Geom_Circle(cax2, abs(curvature2))
    h_circ2 = Geom.Handle_Geom_Circle(circ2)
    
    r = diameter/2.
    
    h2 = CT1 - curvature1 + numpy.sqrt(curvature1**2 - r**2)*sign(curvature1)
    h3 = CT2 - curvature2 + numpy.sqrt(curvature2**2 - r**2)*sign(curvature2)
    p1 = gp.gp_Pnt(0,0,CT1)
    p2 = gp.gp_Pnt(r,0,h2)
    p3 = gp.gp_Pnt(r,0,h3)
    p4 = gp.gp_Pnt(0,0,CT2)
    
    e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ, p1, p2)    
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2,p3)
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ2, p3,p4)
    e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4,p1)
    
    wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    for e in (e1,e2,e3,e4):
        print(e)
        wire.Add(e.Edge())
    
    face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire())
    
    ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0),
                   gp.gp_Dir(0,0,1))
    solid = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax)
    
    return position_shape(toshape(solid), centre, direction, x_axis)
Exemplo n.º 17
0
    def preview(self, input, direction):
        if self.step == 0:
            # object to rotate
            self.prev_dat['object'] = input
            return []
        elif self.step == 1:
            # axis to rotate about
            dirvec = vec(0, 0, 0)
            dirvec[direction] = 1
            axis = gp.gp_Ax1(input, dirvec.to_gp_Dir())

            # make a copy (copy.copy does not work)
            point = gp_.gp_Pnt_(input)
            point[direction] += 2
            input[direction] -= .2
            axis_plot = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
                GC.GC_MakeSegment(input, point).Value()).Edge()

            self.prev_dat['point'] = input
            self.prev_dat['dirvec'] = dirvec
            self.prev_dat['axis'] = axis
            self.prev_dat['axis-plot'] = axis_plot
            return [axis_plot]
        elif self.step == 2:
            # start point
            self.prev_dat['point_start'] = input
            return [self.prev_dat['axis-plot']]
        elif self.step == 3:
            p0 = self.prev_dat['point']
            vec0 = self.prev_dat['point_start'] - p0
            vec1 = input - p0

            dirvec = self.prev_dat['dirvec']
            n0 = dirvec.cross(vec0)
            n1 = dirvec.cross(vec1)
            try:
                cos = n0.dot(n1) / (n0.length() * n1.length())
            except ZeroDivisionError:
                raise InvalidInputException
            angle = math.acos(min(max(cos, -1), 1))  # cos might be (-)1.000001

            oriented_dirvec = n0.cross(n1)
            if oriented_dirvec == vec(0, 0, 0):
                raise InvalidInputException
            axis = gp.gp_Ax1(p0, oriented_dirvec.to_gp_Dir())

            tr = gp.gp_Trsf()
            tr.SetRotation(axis, angle)
            t = self.prev_dat['object'].Moved(TopLoc.TopLoc_Location(tr))
            t = copy_geom.copy(t)
            self._final = [t]
            self.remove = [self.prev_dat['object']]
            return [t, self.prev_dat['axis-plot']]
Exemplo n.º 18
0
def makeSquareWithRoundHole():

    points = [(0, 0), (0.05, -1.0), (1.0, 0), (2.0, 0), (2.0, 6.0), (0.0, 6.0)]
    ow = makeWireFromPointList(points)

    circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(1.0, 2, 0),
                                  gp.gp().DZ()), 0.75)
    e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle).Edge()
    mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    mw.Add(e1)
    circle = mw.Wire()
    builder = BRepBuilderAPI.BRepBuilderAPI_MakeFace(ow, True)
    builder.Add(circle)
    return builder.Face()
Exemplo n.º 19
0
 def preview(self, inp, direction):
     if self.step == 0:
         self.previous_data = [inp]
         return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()]
     elif self.step == 1:
         point0 = self.previous_data[0]
         # checking if the previous points are identical: This is necessary
         # before continuing in order to avoid a crash on Windows
         if point0 == inp:
             raise InvalidInputException
         a = GC.GC_MakeSegment(inp, point0).Value()
         b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge()
         self._final = [BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire()]
         return self._final
Exemplo n.º 20
0
def make_ellipsoid_2(focus1, focus2, major_axis):
    f1 = numpy.asarray(focus1)
    f2 = numpy.asarray(focus2)
    direction = -(f1 - f2)
    centre = (f1 + f2)/2.
    sep = numpy.sqrt((direction**2).sum())
    minor_axis = numpy.sqrt( major_axis**2 - (sep/2.)**2 )
    
    el = gp.gp_Elips(gp.gp_Ax2(gp.gp_Pnt(0,0,0), gp.gp_Dir(1,0,0)), 
                          major_axis, minor_axis)
    edge1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(el, 
                                                  gp.gp_Pnt(0,0,major_axis),
                                                  gp.gp_Pnt(0,0,-major_axis))
    edge2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(gp.gp_Pnt(0,0,-major_axis),
                                                  gp.gp_Pnt(0,0,major_axis))
    
    wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    wire.Add(edge1.Edge())
    wire.Add(edge2.Edge())
    
    face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire())
    
    el = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), 
                                           gp.gp_Ax1(gp.gp_Pnt(0,0,0),
                                                     gp.gp_Dir(0,0,1)),
                                           numpy.pi*2)
    
    loc = gp.gp_Ax3()
    loc.SetLocation(gp.gp_Pnt(*centre))
    loc.SetDirection(gp.gp_Dir(*direction))
    
    tr = gp.gp_Trsf()
    tr.SetTransformation(loc, gp.gp_Ax3())
    
    trans = BRepBuilderAPI.BRepBuilderAPI_Transform(el.Shape(), tr)
    shape = toshape(trans)
    return shape
Exemplo n.º 21
0
def make_spherical_lens(CT, diameter, curvature, 
                        centre, direction, x_axis):
    cax = gp.gp_Ax2(gp.gp_Pnt(0,0,CT-curvature),
                    gp.gp_Dir(0,1,0),
                    gp.gp_Dir(1,0,0))
    circ = Geom.Geom_Circle(cax, curvature)
    h_circ = Geom.Handle_Geom_Circle(circ)
    
    r = diameter/2.
    h2 = CT - curvature + numpy.sqrt(curvature**2 - r**2)
    p1 = gp.gp_Pnt(0,0,CT)
    p2 = gp.gp_Pnt(r,0,h2)
    p3 = gp.gp_Pnt(r,0,0)
    p4 = gp.gp_Pnt(0,0,0)
    
    #ps = p1,p2,p3,p4
    #vs = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(p) for p in ps]
    
    e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ, p1,
                                                p2)    
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2,p3)
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3,p4)
    e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4,p1)
    
    wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    for e in (e1,e2,e3,e4):
        print(e)
        wire.Add(e.Edge())
    
    face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire())
    
    ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0),
                   gp.gp_Dir(0,0,1))
    solid = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax)
    
    return position_shape(toshape(solid), centre, direction, x_axis)
Exemplo n.º 22
0
def normalEdgeAtParameter(edge, param, length ):
	"compute an edge having length at the specified parameter on the supplied curve:"

	ew = Wrappers.Edge(edge);
	zDir = gp.gp().DZ();
	zVec = gp.gp_Vec(zDir);
	
	tangent = gp.gp_Vec();
	tanpoint = gp.gp_Pnt();
	
	curve = ew.curve;
	curve.D1(param,tanpoint,tangent );
	axis = gp.gp_Ax1(tanpoint, gp.gp_Dir(tangent.Crossed(zVec) ) );
	
	line = Geom.Geom_Line(axis );
	return  BRepBuilderAPI.BRepBuilderAPI_MakeEdge(line.GetHandle(),0, length).Edge();
Exemplo n.º 23
0
 def preview(self, inp, direction):
     if self.step == 0:
         self.previous_data = [inp]
         return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()]
     elif self.step == 1:
         point0 = self.previous_data[0]
         # checking if the previous points are identical: This is necessary
         # before continuing in order to avoid a crash on Windows
         if point0 == inp:
             raise InvalidInputException
         point1 = inp
         dir_ = point1 - point0
         len = dir_.length()
         p0 = point0 + 1000/len * dir_
         p1 = point0 - 1000/len * dir_
         a = GC.GC_MakeSegment(p0.to_gp_Pnt(), p1.to_gp_Pnt()).Value()
         b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge()
         self._final = [BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire()]
         return self._final
Exemplo n.º 24
0
def test_check_shape():
    r"""check_shape() tests"""
    # Null shapes should raise a ValueError
    with pytest.raises(ValueError):
        check_shape(TopoDS.TopoDS_Shape())
    with pytest.raises(ValueError):
        check_shape(TopoDS.TopoDS_Shell())

    builderapi_makeedge = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
        gp.gp_Pnt(), gp.gp_Pnt(10, 10, 10))
    shape = builderapi_makeedge.Shape()

    # a ValueError should be raised is check_shape() is not give a TopoDS_Shape or subclass
    with pytest.raises(ValueError):
        check_shape(gp.gp_Pnt())
    with pytest.raises(ValueError):
        check_shape(builderapi_makeedge)

    # a TopoDS_Shape should pass the check without raising any exception
    check_shape(shape)

    # a subclass of shape should not raise any exception
    check_shape(next(Topo(shape).edges()))
Exemplo n.º 25
0
def edgeFromTwoPointsOnCurve(handleCurve, p1, p2):
    "make an edge from a curve and two parameters"
    #log.info("Making Edge from Parameters %0.2f, %0.2f" %( p1, p2) );

    a = p1
    b = p2
    rev = False
    if p1 > p2:
        a = p2
        b = p1
        #log.info("Parameters are inverted, so we'll reverse the resulting edge");
        rev = True

    builder = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(handleCurve, a, b)
    builder.Build()
    if builder.IsDone():
        e = builder.Edge()
        if rev:
            e.Reverse()
        return e
    else:
        #log.error( "Error building Edge: Error Number %d" % builder.Error());
        raise ValueError, "Error building Edge: Error Number %d" % builder.Error(
        )
Exemplo n.º 26
0
def pairs(itr):
    a,b = tee(itr)
    b.next()
    return izip(a,b)

points = [(0,0,0),
          (1,1,1),
          (0,0,-2),
          (0,2,0)]

vertices = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*p))
            for p in points]
#print "verts", vertices
#edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(),v2.Vertex())
#         for v1,v2 in pairs(vertices)]
v=vertices
edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v[i].Vertex(),v[j].Vertex())
         for i,j, in [(0,1),(0,2),(0,3)] ]
         

#print "edges", edges
wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
for e in edges:
    wire.Add(e.Edge())
    
print wire

step_export = STEPControl.STEPControl_Writer()
step_export.Transfer(wire.Shape(), STEPControl.STEPControl_AsIs)
step_export.Write("/home/bryan/test_wire.stp")
Exemplo n.º 27
0
from viewer import view

from OCC import Geom, GeomAPI, gp, BRepBuilderAPI, BRep, TopoDS

radius = 25.0
sph = Geom.Geom_SphericalSurface(gp.gp_Ax3(), radius)
h_sph = Geom.Handle_Geom_SphericalSurface(sph)

c_rad = 12.0  #cylinder radius
cyl = Geom.Geom_CylindricalSurface(gp.gp_Ax3(), c_rad)
h_cyl = Geom.Handle_Geom_CylindricalSurface(cyl)

intersect = GeomAPI.GeomAPI_IntSS(h_sph, h_cyl, 1e-7)

edges = (BRepBuilderAPI.BRepBuilderAPI_MakeEdge(intersect.Line(i))
         for i in xrange(1,
                         intersect.NbLines() + 1))

wires = [BRepBuilderAPI.BRepBuilderAPI_MakeWire(e.Edge()) for e in edges]

g_sph = gp.gp_Sphere(gp.gp_Ax3(), radius)
faces = [BRepBuilderAPI.BRepBuilderAPI_MakeFace(w.Wire()) for w in wires]
cyl_face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(h_cyl)
#cyl_face.Add(wires[0].Wire())
#cyl_face.Add(wires[1].Wire())

#shell = TopoDS.TopoDS_Shell()
shell_builder = BRep.BRep_Builder()
#shell_builder.MakeShell(shell)
#shell_builder.Add(shell, cyl_face.Shape())
#for f in faces:
Exemplo n.º 28
0
 def MakeEdge(v1, v2):
     e = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(), v2.Vertex())
     #print "make edge", v1, v2, e
     return e
Exemplo n.º 29
0
#!/usr/bin/python
# coding: utf-8
r"""test_revolve.py"
"""

from math import pi

from OCC import BRepPrimAPI, gp, BRepBuilderAPI
from viewer import view

el = gp.gp_Elips(gp.gp_Ax2(gp.gp_Pnt(0, 0, 0), gp.gp_Dir(1, 0, 0)), 20.0, 10.0)
edge1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(el, gp.gp_Pnt(0, 0, 20),
                                               gp.gp_Pnt(0, 0, -20))
edge2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(gp.gp_Pnt(0, 0, -20),
                                               gp.gp_Pnt(0, 0, 20))

wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
wire.Add(edge1.Edge())
wire.Add(edge2.Edge())

face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire())

el = BRepPrimAPI.BRepPrimAPI_MakeRevol(
    face.Shape(), gp.gp_Ax1(gp.gp_Pnt(0, 0, 0), gp.gp_Dir(0, 0, 1)), pi * 2)

# h_curve = Geom.Handle_Geom_Ellipse(curve)
# rev = BRepPrimAPI.BRepPrimAPI_MakeRevolution(h_curve, 120.1)
# #nurbs = BRepBuilderAPI.BRepBuilderAPI_NurbsConvert(rev.Shape())
view(el.Shape())
Exemplo n.º 30
0
def makeCircleWire():
    circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(0, 2, 0),
                                  gp.gp().DZ()), .75)
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(0, 1.25, 0),
                                                gp.gp_Pnt(0, 1.25, 0)).Edge()
    return Wrappers.wireFromEdges([e2])