def Setup(self, stlfile): if type(stlfile) in (type(r""), type(u""), type("")) and os.path.isfile(stlfile): r = STLTools.reader(stlfile) fl = open(stlfile, r.isascii and "r" or "rb") r.ReadFacets(fl) fl.close() self.xlo, self.xhi, self.ylo, self.yhi, self.zlo, self.zhi = r.mr.xlo, r.mr.xhi, r.mr.ylo, r.mr.yhi, r.mr.zlo, r.mr.zhi elif type(stlfile) == type((0,)): self.xlo, self.xhi, self.ylo, self.yhi, self.zlo, self.zhi = stlfile elif not stlfile: return w, h = self.siz self.margin = 10 sx = (float(w) - 2.0 * self.margin) / (self.xhi - self.xlo) sy = (float(h) - 2.0 * self.margin) / (self.yhi - self.ylo) if sx > sy: sx = sy else: sy = sx px = float(w) * 0.5 - sx * (self.xhi + self.xlo) * 0.5 py = float(h) * 0.5 - sy * (self.yhi + self.ylo) * 0.5 self.pan = (px, py) self.scale = (sx, sy)
def LoadSurfaceWithList(fn, workplane): class Wrapper: def __init__(self, fssurf, workplane): if workplane: self.fs = STLTools.FacetTrans(workplane, fssurf) else: self.fs = fssurf self.trialist = [ ] def PushTriangle(self, x0, y0, z0, x1, y1, z1, x2, y2, z2): self.trialist.append((x0, y0, z0, x1, y1, z1, x2, y2, z2)) self.fs.PushTriangle(x0, y0, z0, x1, y1, z1, x2, y2, z2) fssurf = fsp.FsSurf.New() # surface object w = Wrapper(fssurf, workplane) # read STL file and call PushTriangle (method in fssurf) for each triangle r = STLTools.reader(fn) fl = open(fn, r.isascii and "r" or "rb") try: if r.isascii: r.AsciiReadFacets(fl, w) else: r.BinaryReadFacets(fl, w) except: sys.stderr.write("Failed to read STL file: %s" % fn) fl.close() return fl.close() fssurf.Build(1.0) # build surface boxing return (fssurf, w.trialist)
def __init__(self, fn, stlfile, w, h, rad, offset): SliceWriterNone.__init__(self, fn, w, h) self.fil = open(fn, "wb") if type(stlfile) == type((0,)): xlo, xhi, ylo, yhi, zlo, zhi = stlfile else: # CLI has to be moved into "positive" space r = STLTools.reader(stlfile) fl = open(stlfile, r.isascii and "r" or "rb") r.ReadFacets(fl) fl.close() xlo, xhi, ylo, yhi = r.mr.xlo, r.mr.xhi, r.mr.ylo, r.mr.yhi if rad != None and offset != None: panx, pany = self.pan if (xlo < (rad - offset)): panx = -xlo + (rad - offset) + 0.1 if (ylo < (rad - offset)): pany = -ylo + (rad - offset) + 0.1 self.pan = panx, pany if (self.pan != (0, 0)): print "Moving for CLI: ", self.pan
def LoadSurface(fn, workplane): fssurf = fsp.FsSurf.New() # surface object # read STL file and call PushTriangle (method in fssurf) for each triangle r = STLTools.reader(fn) if workplane: fs = STLTools.FacetTrans(workplane, fssurf) else: fs = fssurf fl = open(fn, r.isascii and "r" or "rb") try: if r.isascii: r.AsciiReadFacets(fl, fs) else: r.BinaryReadFacets(fl, fs) except: sys.stderr.write("Failed to read STL file: %s" % fn) fl.close() return fl.close() fssurf.Build(1.0) # build surface boxing return fssurf