示例#1
0
文件: sphere.py 项目: hmeyer/qtmium
  def __init__(self, r=None, radius=None, d=None, diameter=None, phi=360, center=False):

    if radius: r = radius
    if d: r = d/2.0
    if diameter: r = diameter/2.0
    self.instance = BRepPrimAPI_MakeSphere(r, phi*math.pi/180)
    Solid.__init__(self, self.instance.Shape(), center=center)
示例#2
0
文件: cone.py 项目: OpenFlex/cadmium
  def __init__(self, r=None, radius=None, h=None, height=None, 
    pie=360, center=False):

    if radius: r = radius
    if height: h = height
    self.instance = BRepPrimAPI_MakeCone(r, 0.01, h, pie*math.pi/180)
    Solid.__init__(self, self.instance.Shape(), center=center)
示例#3
0
文件: circle.py 项目: hmeyer/qtmium
  def __init__(self, r=None, radius=None, phi=360, center=False):

    if radius: r = radius
    C = Geom2d_Circle( gp_OX2d(), r )
    self.instance = BRepBuilderAPI_MakeEdge2d(C.Circ2d())
#    self.instance = BRepPrimAPI_MakeSphere(r, phi*math.pi/180)
    Solid.__init__(self, self.instance.Shape(), center=center)
示例#4
0
文件: cylinder.py 项目: hmeyer/qtmium
 def __init__(
     self,
     r=None,
     radius=None,
     r1=None,
     r2=None,
     diameter=None,
     d=None,
     d1=None,
     d2=None,
     height=None,
     h=None,
     pie=360,
     center=False,
 ):
     if diameter:
         d = diameter
     if d:
         r = d * 0.5
     if d1:
         r1 = d1 * 0.5
     if d2:
         r2 = d2 * 0.5
     if radius:
         r = radius
     if height:
         h = height
     if r1 != r2:
         self.instance = BRepPrimAPI_MakeCone(r1, r2, h, pie * math.pi / 180)
         Solid.__init__(self, self.instance.Shape(), center=center)
     else:
         if not r:
             r = r1 = r2
         self.instance = BRepPrimAPI_MakeCylinder(r, h, pie * math.pi / 180)
         Solid.__init__(self, self.instance.Shape(), center=center)
示例#5
0
  def __init__(self, text, fontpath, thickness=1,
    width=0, height=0, center=False):

    self.text = text

    self.font = self.load_font(fontpath)

    self.width = 0
    self.instance = None
    for char in text:
      c = None
      if char >= 'a' and char <= 'z':
        c = char
      elif char >= 'A' and char <= 'Z':
        c = char
      elif char == ' ':
        space = self.font['space']
        space_width = space.left_side_bearing + space.right_side_bearing
        self.width += space_width
        self.xmax += space_width
      else:
        c = self._char_map_.get(char)
      
      if not c: continue
        
      g = Glyph(c, thickness=1, font=self.font, center=True)
      g_xmin, g_ymin, g_zmin, g_xmax, g_ymax, g_zmax = g.getBoundingBox()
      g_xspan = g_xmax - g_xmin
      g_yspan = g_ymax - g_ymin
      g_zspan = g_zmax - g_zmin

      if self.instance:
        g.translate(x=(self.width+g.left_side_bearing+(g_xspan/2)))
        ymax_target = g.bbox[3]
        g.translate(y=(ymax_target-g_yspan/2))

        self.instance += g
        self.width += g.left_side_bearing+g_xspan+g.right_side_bearing
      else:
        ymax_target = g.bbox[3]
        g.translate(y=(ymax_target-g_yspan/2))
        self.instance = g
        self.width = (g_xspan/2)+g.right_side_bearing

    Solid.__init__(self, self.instance, center=center)

    xmin, ymin, zmin, xmax, ymax, zmax = self.getBoundingBox()
    if width and height:
      self.scale(scaleX = width*1.0/(xmax-xmin),
        scaleY = height*1.0/(ymax-ymin),
        scaleZ = thickness)
    elif (width and not height):
      self.scale(scaleX = width*1.0/(xmax-xmin),
        scaleY = width*1.0/(xmax-xmin),
        scaleZ = thickness)
    elif (height and not width):
      self.scale(scaleX = height*1.0/(ymax-ymin),
        scaleY = height*1.0/(ymax-ymin),
        scaleZ = thickness)
示例#6
0
文件: wedge.py 项目: hmeyer/qtmium
  def __init__(self, dx=5, dy=5, dz=5, center=True, ltx=0):
    if center:
      self.centerTranslation = (0,-dy/2.0,0)
    else:
      self.centerTranslation = (0,0,0)

    self.instance = BRepPrimAPI_MakeWedge(dx, dy, dz, ltx)
    Solid.__init__(self, self.instance.Shape())

    self.translate(delta=self.centerTranslation,  inplace = True)
示例#7
0
    def __init__(self, dx=5, dy=5, dz=5, center=True, ltx=0):
        if center:
            self.centerTranslation = (0, -dy / 2.0, 0)
        else:
            self.centerTranslation = (0, 0, 0)

        self.instance = BRepPrimAPI_MakeWedge(dx, dy, dz, ltx)
        Solid.__init__(self, self.instance.Shape())

        self.translate(delta=self.centerTranslation)
示例#8
0
    def __init__(self,
                 r=None,
                 radius=None,
                 h=None,
                 height=None,
                 pie=360,
                 center=False):

        if radius: r = radius
        if height: h = height
        self.instance = BRepPrimAPI_MakeCone(r, 0.01, h, pie * math.pi / 180)
        Solid.__init__(self, self.instance.Shape(), center=center)
示例#9
0
  def __init__(self, r=None, radius=None, r1=None, r2=None, height=None, 
    h=None, pie=360, center=False):

    if radius: r=radius
    if height: h=height
    if r1 != r2:
      self.instance = BRepPrimAPI_MakeCone(r1, r2, h, pie*math.pi/180)
      Solid.__init__(self, self.instance.Shape(), center=center)
    else:
      if not r: r = r1 = r2
      self.instance = BRepPrimAPI_MakeCylinder(r, h, pie*math.pi/180)
      Solid.__init__(self, self.instance.Shape(), center=center)
示例#10
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)
示例#11
0
文件: text.py 项目: hmeyer/qtmium
  def __init__(self, char, thickness, font=None, fontpath=None, center=False):
    if font:
      self.font = font
    elif fontpath:
      self.font = fontforge.open(fontpath)

    self.char = char
    self.center = center
    glyph = self.font[str(char)]

    self.thickness = thickness
    self.bbox = glyph.boundingBox()
    self.left_side_bearing = glyph.left_side_bearing
    self.right_side_bearing = glyph.right_side_bearing

    if cadmium._brep_caching_enabled_:
      breppath = os.path.join(cadmium._brep_cache_path_,
        self.get_signature(char,self.font.path,thickness,center))
      if os.path.exists(breppath):
        Solid.__init__(self, None)
        self.fromBREP(breppath)
      else:
        Solid.__init__(self, self.char_to_solid(glyph), center=center)
        self.toBREP(breppath)
示例#12
0
  def __init__(self, char, thickness, font=None, fontpath=None, center=False):
    if font:
      self.font = font
    elif fontpath:
      self.font = fontforge.open(fontpath)

    self.char = char
    self.center = center
    glyph = self.font[str(char)]

    self.thickness = thickness
    self.bbox = glyph.boundingBox()
    self.left_side_bearing = glyph.left_side_bearing
    self.right_side_bearing = glyph.right_side_bearing

    if cadmium._brep_caching_enabled_:
      breppath = os.path.join(cadmium._brep_cache_path_,
        self.get_signature(char,self.font.path,thickness,center))
      if os.path.exists(breppath):
        Solid.__init__(self, None)
        self.fromBREP(breppath)
      else:
        Solid.__init__(self, self.char_to_solid(glyph), center=center)
        self.toBREP(breppath)
示例#13
0
文件: torus.py 项目: OpenFlex/cadmium
  def __init__(self, r1=None, r2=None, angle=360, center=False):

    self.instance = BRepPrimAPI_MakeTorus(r1,r2,angle*math.pi/180)
    Solid.__init__(self, self.instance.Shape(), center=center)
示例#14
0
    def __init__(self, r1=None, r2=None, angle=360, center=False):

        self.instance = BRepPrimAPI_MakeTorus(r1, r2, angle * math.pi / 180)
        Solid.__init__(self, self.instance.Shape(), center=center)
示例#15
0
文件: box.py 项目: OpenFlex/cadmium
 def __init__(self, x=10, y=10, z=10, center=False):
   self.instance = BRepPrimAPI_MakeBox(x,y,z)
   Solid.__init__(self, self.instance.Shape(), center=center)
示例#16
0
  def __init__(self, r=None, radius=None, phi=360, center=False):

    if radius: r = radius
    self.instance = BRepPrimAPI_MakeSphere(r, phi*math.pi/180)
    Solid.__init__(self, self.instance.Shape(), center=center)
示例#17
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)
示例#18
0
文件: box.py 项目: hmeyer/qtmium
 def __init__(self, x=10, y=None, z=None, center=False):
   if not y: y = x
   if not z: z = y
   self.instance = BRepPrimAPI_MakeBox(x,y,z)
   Solid.__init__(self, self.instance.Shape(), center=center)
示例#19
0
文件: union.py 项目: hmeyer/qtmium
 def __init__(self, shapelist):
     t = shapelist[0]
     for x in shapelist[1:]:
         t += x
     Solid.__init__(self, t.shape)
示例#20
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)
示例#21
0
 def __init__(self, x=10, y=10, z=10, center=False):
     self.instance = BRepPrimAPI_MakeBox(x, y, z)
     Solid.__init__(self, self.instance.Shape(), center=center)