Exemplo n.º 1
0
 def test_const_Standard_Real_byref(self):
     '''
     Test wrapper for const Standard_Real &
     '''
     t = TColStd_Array1OfReal(1, 10)
     t.SetValue(3, 3.14)
     self.assertEqual(t.Value(3), 3.14)
Exemplo n.º 2
0
  def __init__(self,
    knotVector=[], controlPoints=[], degree=3, center=False, axis=2):

    uniqueKnots = unique(knotVector)
    frequency = [ knotVector.count(knot) for knot in uniqueKnots ]

    knots = TColStd_Array1OfReal(0, len(uniqueKnots)-1)
    for i in range(len(uniqueKnots)):
      knots.SetValue(i, uniqueKnots[i])

    mults = TColStd_Array1OfInteger(0, len(frequency)-1)
    for i in range(len(frequency)):
      mults.SetValue(i,frequency[i])

    poles = TColgp_Array1OfPnt(0, len(controlPoints)-1)
    for i in range(len(controlPoints)):
      p = controlPoints[i]
      poles.SetValue(i, gp_Pnt(p[0],p[1],p[2]))

    poles2d = TColgp_Array1OfPnt2d(0, len(controlPoints)-1)
    plane = get_principal_plane(controlPoints)
    for i in range(len(controlPoints)):
      p = controlPoints[i]
      if plane == 0:
        poles2d.SetValue(i, gp_Pnt2d(p[1],p[2]))
      elif plane == 1:
        poles2d.SetValue(i, gp_Pnt2d(p[0],p[2]))
      elif plane == 2:
        poles2d.SetValue(i, gp_Pnt2d(p[0],p[1]))

    curve2d = Geom2d_BSplineCurve(poles2d, knots, mults, degree)
    if is_self_intersecting(curve2d.GetHandle()):
      from cadmium import CadmiumException
      raise CadmiumException('Self intersecting BSpline not allowed')

    curve = Geom_BSplineCurve(poles, knots, mults, degree)
    h_curve = Handle_Geom_BSplineCurve(curve)

    axes = [
      gp_Ax2(gp_Pnt(0,0,0),gp_Dir(1,0,0)),
      gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,1,0)),
      gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,0,1)),
    ]
    
    self.instance = BRepPrimAPI_MakeRevolution(axes[axis], h_curve)
    Solid.__init__(self, self.instance.Shape(), center=center)
Exemplo n.º 3
0
    def __init__(self,
                 knotVector=[],
                 controlPoints=[],
                 degree=3,
                 thickness=10,
                 axis=0,
                 center=False):

        self.thickness = thickness

        wire = BRepBuilderAPI_MakeWire()

        uniqueKnots = unique(knotVector)
        frequency = [knotVector.count(knot) for knot in uniqueKnots]

        knots = TColStd_Array1OfReal(0, len(uniqueKnots) - 1)
        for i in range(len(uniqueKnots)):
            knots.SetValue(i, uniqueKnots[i])

        mults = TColStd_Array1OfInteger(0, len(frequency) - 1)
        for i in range(len(frequency)):
            mults.SetValue(i, frequency[i])

        poles = TColgp_Array1OfPnt(0, len(controlPoints) - 1)
        for i in range(len(controlPoints)):
            p = controlPoints[i]
            poles.SetValue(i, gp_Pnt(p[0], p[1], p[2]))

        poles2d = TColgp_Array1OfPnt2d(0, len(controlPoints) - 1)
        plane = get_principal_plane(controlPoints)
        for i in range(len(controlPoints)):
            p = controlPoints[i]
            if plane == 0:
                poles2d.SetValue(i, gp_Pnt2d(p[1], p[2]))
            elif plane == 1:
                poles2d.SetValue(i, gp_Pnt2d(p[0], p[2]))
            elif plane == 2:
                poles2d.SetValue(i, gp_Pnt2d(p[0], p[1]))

        curve2d = Geom2d_BSplineCurve(poles2d, knots, mults, degree)
        if is_self_intersecting(curve2d.GetHandle()):
            from cadmium import CadmiumException
            raise CadmiumException('Self intersecting BSpline not allowed')

        curve = Geom_BSplineCurve(poles, knots, mults, degree)

        me = BRepBuilderAPI_MakeEdge(curve.GetHandle())
        wire.Add(me.Edge())

        first = controlPoints[0]
        first = gp_Pnt(first[0], first[1], first[2])
        last = controlPoints[-1]
        last = gp_Pnt(last[0], last[1], last[2])

        if not first.IsEqual(last, 1.0e-9):
            closer = BRepBuilderAPI_MakeEdge(
                gp_Lin(first, gp_Dir(gp_Vec(first, last))), first, last)
            wire.Add(closer.Edge())

        face = BRepBuilderAPI_MakeFace(wire.Wire())
        if axis == 0:
            extrusion_vector = gp_Vec(self.thickness, 0, 0)
        elif axis == 1:
            extrusion_vector = gp_Vec(0, self.thickness, 0)
        elif axis == 2:
            extrusion_vector = gp_Vec(0, 0, self.thickness)

        self.instance = BRepPrimAPI_MakePrism(face.Shape(), extrusion_vector)
        Solid.__init__(self, self.instance.Shape(), center=center)