예제 #1
0
	def __init__(self, fn, startIdx, zzero, xoffset, yoffset, cb=None):
		self.vertexMap = {}
		self.vertexVal = []
		self.vertexIdx = startIdx
		self.triangles = []
		self.name = fn
		self.cb = cb
		
		self.stl = stltool.stl(cb = cb, filename=fn, zZero=zzero, xOffset=xoffset, yOffset=yoffset)
		if cb:
			cb("Processing facets for AMF formatting...")
			
		fx = 0
		for f in self.stl.facets:
			triangle = [None, None, None]
			for px in range(3):
				key = str(f[1][px][0]) + ";" + str(f[1][px][1]) + ";" + str(f[1][px][2])
				if key not in self.vertexMap.keys():
					self.vertexMap[key] = self.vertexIdx
					self.vertexVal.append(key)
					self.vertexIdx += 1
			
				triangle[px] = self.vertexMap[key]
	
			self.triangles.append(triangle)
			if cb:
				fx += 1
				if fx % 10000 == 0:
					cb("Processed %d facets" % fx)
예제 #2
0
def genscape(data = [[0, 1, 0, 0], [1, 0, 2, 0], [1, 0, 0, 0], [0, 1, 0, 1]],
             pscale = 1.0, bheight = 1.0, zscale = 1.0):
    o = stl(None)
    datal = len(data)
    datah = len(data[0])
    # create bottom:
    bmidpoint = (pscale * (datal - 1) / 2.0, pscale * (datah - 1) / 2.0)
    # print range(datal), bmidpoint
    for i in zip(range(datal + 1)[:-1], range(datal + 1)[1:])[:-1]:
        # print (pscale*i[0], pscale*i[1])
        o.facets += [[[0, 0, -1], [[0.0, pscale * i[0], 0.0], [0.0, pscale * i[1], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]]
        o.facets += [[[0, 0, -1], [[2.0 * bmidpoint[1], pscale * i[1], 0.0], [2.0 * bmidpoint[1], pscale * i[0], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]]
        o.facets += [genfacet([[0.0, pscale * i[0], data[i[0]][0] * zscale + bheight], [0.0, pscale * i[1], data[i[1]][0] * zscale + bheight], [0.0, pscale * i[1], 0.0]])]
        o.facets += [genfacet([[2.0 * bmidpoint[1], pscale * i[1], data[i[1]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[0], data[i[0]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[1], 0.0]])]
        o.facets += [genfacet([[0.0, pscale * i[0], data[i[0]][0] * zscale + bheight], [0.0, pscale * i[1], 0.0], [0.0, pscale * i[0], 0.0]])]
        o.facets += [genfacet([[2.0 * bmidpoint[1], pscale * i[1], 0.0], [2.0 * bmidpoint[1], pscale * i[0], data[i[0]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[0], 0.0]])]
    for i in zip(range(datah + 1)[: - 1], range(datah + 1)[1:])[: - 1]:
        # print (pscale * i[0], pscale * i[1])
        o.facets += [[[0, 0, -1], [[pscale * i[1], 0.0, 0.0], [pscale * i[0], 0.0, 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]]
        o.facets += [[[0, 0, -1], [[pscale * i[0], 2.0 * bmidpoint[0], 0.0], [pscale * i[1], 2.0 * bmidpoint[0], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]]
        o.facets += [genfacet([[pscale * i[1], 0.0, data[0][i[1]] * zscale + bheight], [pscale * i[0], 0.0, data[0][i[0]] * zscale + bheight], [pscale * i[1], 0.0, 0.0]])]
        o.facets += [genfacet([[pscale * i[0], 2.0 * bmidpoint[0], data[datal - 1][i[0]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], data[datal - 1][i[1]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], 0.0]])]
        o.facets += [genfacet([[pscale * i[1], 0.0, 0.0], [pscale * i[0], 0.0, data[0][i[0]] * zscale + bheight], [pscale * i[0], 0.0, 0.0]])]
        o.facets += [genfacet([[pscale * i[0], 2.0 * bmidpoint[0], data[datal - 1][i[0]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], 0.0], [pscale * i[0], 2.0 * bmidpoint[0], 0.0]])]
    for i in xrange(datah - 1):
        for j in xrange(datal - 1):
            o.facets += [genfacet([[pscale * i, pscale * j, data[j][i] * zscale + bheight], [pscale * (i + 1), pscale * (j), data[j][i + 1] * zscale + bheight], [pscale * (i + 1), pscale * (j + 1), data[j + 1][i + 1] * zscale + bheight]])]
            o.facets += [genfacet([[pscale * (i), pscale * (j + 1), data[j + 1][i] * zscale + bheight], [pscale * i, pscale * j, data[j][i] * zscale + bheight], [pscale * (i + 1), pscale * (j + 1), data[j + 1][i + 1] * zscale + bheight]])]
            # print o.facets[-1]
    return o
예제 #3
0
	def doAdd(self, evt):
		wildcard = "STL (*.stl)|*.stl;*.STL|"	 \
			"All files (*.*)|*.*"
			
		dlg = wx.FileDialog(
			self, message="Choose an STL file",
			defaultDir=self.settings.lastdirectory, 
			defaultFile="",
			wildcard=wildcard,
			style=wx.FD_OPEN)

		rc = dlg.ShowModal()
		if rc == wx.ID_OK:
			path = dlg.GetPath().encode('ascii','ignore')
		dlg.Destroy()
		if rc != wx.ID_OK:
			return
		
		self.settings.lastdirectory = os.path.dirname(path)
		
		if self.settings.preview:
			stlObj = stl(filename = path)
			dlg = StlViewer(self, stlObj, path, True, self.images, self.settings)
			rc = dlg.ShowModal()
			dlg.Destroy()
			dlg = None
		
		if not self.settings.preview or rc == wx.ID_OK:
			ud = UserData(path, stlObj, self.seq)
			self.files.addFile(ud)
			self.stlCanvas.addHull(stlObj, self.seq)
			self.seq += 1
			self.modified = True
			self.enableButtons()
예제 #4
0
def main():
    global opts
    (progdir, progname) = os.path.split(sys.argv[0])

    usage = "usage: %prog [options] [stl file]"
    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()
    parser.add_options(options)
    (opts, args) = parser.parse_args()

    filename = None
    if len(args):
        filename = args[0]
    a = stltool.stl(filename)
    (points, faces) = a.unique_vertices(a.facets)

    if opts.boundary:
        (pxmin, pymin, pxmax, pymax) = map(float, opts.boundary.split(','))

    x = np.array(map(lambda p: p[0], points))
    y = np.array(map(lambda p: p[1], points))
    z = np.array(map(lambda p: p[2], points))

    fig = pp.figure()
    if opts.boundary:
        pp.axis([pxmin, pxmax, pymin, pymax])
    pp.tricontourf(x, y, z, 256)
    pp.colorbar()
    pp.triplot(x, y, faces, 'wo-')
    pp.title('Correction mesh contour')
    pp.show()
예제 #5
0
def load_file(b, filename):
    a = stltool.stl(filename)
    (vertices, faces) = a.unique_vertices(a.facets)

    nv = len(vertices)
    nf = len(faces)
    req = hdr + nv * vsize + nf * fsize

    if opts.debug:
        print >> sys.stderr, "%d vertices, %d faces" % (nv, nf)
        print >> sys.stderr, "shared memory size %d, used %d" % (len(b), req)

    if len(b) < req:
        raise Exception, "Buffer too small, have %d need %d" % (len(b), req)

    set_header(b, 0, 0)  # disable while loading

    for i in range(nv):
        (v0, v1, v2) = vertices[i]
        pack_into('ddd', b, hdr + i * vsize, v0, v1, v2)

    for i in range(nf):
        (f0, f1, f2) = faces[i]
        pack_into('iii', b, hdr + nv * vsize + i * fsize, f0, f1, f2)

    set_header(b, nv, nf)  # activate new set

    if opts.debug:
        print >> sys.stderr, "loaded."
예제 #6
0
파일: plater.py 프로젝트: ccalica/Printrun
 def right(self,event):
     dlg=wx.FileDialog(self,"Open file to print",self.basedir,style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
     dlg.SetWildcard("STL files (;*.stl;)")
     if(dlg.ShowModal() == wx.ID_OK):
         name=dlg.GetPath()
         if not(os.path.exists(name)):
             return
         path = os.path.split(name)[0]
         self.basedir=path
         t=time.time()
         #print name
         if name.lower().endswith(".stl"):
             newname=name
             c=1
             while newname in self.models:
                 newname=name+"(%d)"%c
                 c+=1
             self.models[newname]=stltool.stl(name)
             self.models[newname].offsets=[0,0,0]
             #print time.time()-t
             self.l.Append([stlwrap(self.models[newname],newname)])
             i=self.l.GetFirstSelected()
             if i != -1:
                 self.l.Select(i,0)
         
             self.l.Select(self.l.GetItemCount()-1)
         self.Refresh()
예제 #7
0
파일: zscaper.py 프로젝트: imclab/Printrun
def genscape(data = [[0, 1, 0, 0], [1, 0, 2, 0], [1, 0, 0, 0], [0, 1, 0, 1]],
             pscale = 1.0, bheight = 1.0, zscale = 1.0):
    o = stl(None)
    datal = len(data)
    datah = len(data[0])
    #create bottom:
    bmidpoint = (pscale * (datal - 1) / 2.0, pscale * (datah - 1) / 2.0)
    #print range(datal), bmidpoint
    for i in zip(range(datal + 1)[:-1], range(datal + 1)[1:])[:-1]:
        #print (pscale*i[0], pscale*i[1])
        o.facets += [[[0, 0, -1], [[0.0, pscale * i[0], 0.0], [0.0, pscale * i[1], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]]
        o.facets += [[[0, 0, -1], [[2.0 * bmidpoint[1], pscale * i[1], 0.0], [2.0 * bmidpoint[1], pscale * i[0], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]]
        o.facets += [genfacet([[0.0, pscale * i[0], data[i[0]][0] * zscale + bheight], [0.0, pscale * i[1], data[i[1]][0] * zscale + bheight], [0.0, pscale * i[1], 0.0]])]
        o.facets += [genfacet([[2.0 * bmidpoint[1], pscale * i[1], data[i[1]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[0], data[i[0]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[1], 0.0]])]
        o.facets += [genfacet([[0.0, pscale * i[0], data[i[0]][0] * zscale + bheight], [0.0, pscale * i[1], 0.0], [0.0, pscale * i[0], 0.0]])]
        o.facets += [genfacet([[2.0 * bmidpoint[1], pscale * i[1], 0.0], [2.0 * bmidpoint[1], pscale * i[0], data[i[0]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[0], 0.0]])]
    for i in zip(range(datah + 1)[: - 1], range(datah + 1)[1:])[: - 1]:
        #print (pscale * i[0], pscale * i[1])
        o.facets += [[[0, 0, -1], [[pscale * i[1], 0.0, 0.0], [pscale * i[0], 0.0, 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]]
        o.facets += [[[0, 0, -1], [[pscale * i[0], 2.0 * bmidpoint[0], 0.0], [pscale * i[1], 2.0 * bmidpoint[0], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]]
        o.facets += [genfacet([[pscale * i[1], 0.0, data[0][i[1]] * zscale + bheight], [pscale * i[0], 0.0, data[0][i[0]] * zscale + bheight], [pscale * i[1], 0.0, 0.0]])]
        o.facets += [genfacet([[pscale * i[0], 2.0 * bmidpoint[0], data[datal - 1][i[0]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], data[datal - 1][i[1]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], 0.0]])]
        o.facets += [genfacet([[pscale * i[1], 0.0, 0.0], [pscale * i[0], 0.0, data[0][i[0]] * zscale + bheight], [pscale * i[0], 0.0, 0.0]])]
        o.facets += [genfacet([[pscale * i[0], 2.0 * bmidpoint[0], data[datal - 1][i[0]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], 0.0], [pscale * i[0], 2.0 * bmidpoint[0], 0.0]])]
    for i in xrange(datah - 1):
        for j in xrange(datal - 1):
            o.facets += [genfacet([[pscale * i, pscale * j, data[j][i] * zscale + bheight], [pscale * (i + 1), pscale * (j), data[j][i + 1] * zscale + bheight], [pscale * (i + 1), pscale * (j + 1), data[j + 1][i + 1] * zscale + bheight]])]
            o.facets += [genfacet([[pscale * (i), pscale * (j + 1), data[j + 1][i] * zscale + bheight], [pscale * i, pscale * j, data[j][i] * zscale + bheight], [pscale * (i + 1), pscale * (j + 1), data[j + 1][i + 1] * zscale + bheight]])]
            #print o.facets[-1]
    return o
예제 #8
0
 def load_stl_into_model(self,path,name,offset=[0,0,0],rotation=0):
     newname=os.path.split(name.lower())[1]
     c=1
     while newname in self.models:
         newname=os.path.split(name.lower())[1]
         newname=newname+"(%d)"%c
         c+=1
     self.models[newname]=stltool.stl(path)
     self.models[newname].offsets=offset
     self.models[newname].rot=rotation
     self.models[newname].filename=name
     minx,miny,minz,maxx,maxy,maxz=(10000,10000,10000,0,0,0)
     for i in self.models[newname].facets:
         for j in i[1]:
             if j[0]<minx:
                 minx=j[0]
             if j[1]<miny:
                 miny=j[1]
             if j[2]<minz:
                 minz=j[2]
             if j[0]>maxx:
                 maxx=j[0]
             if j[1]>maxy:
                 maxy=j[1]
             if j[2]>maxz:
                 maxz=j[2]
     self.models[newname].dims=[minx,maxx,miny,maxy,minz,maxz]
     #if minx<0:
     #    self.models[newname].offsets[0]=-minx
     #if miny<0:
     #    self.models[newname].offsets[1]=-miny
     self.models[newname].bitmap=wx.EmptyBitmap(800,800,32)
     dc=wx.MemoryDC()
     dc.SelectObject(self.models[newname].bitmap)
     dc.SetBackground(wx.Brush((0,0,0,0)))
     dc.SetBrush(wx.Brush((0,0,0,255)))
     #dc.DrawRectangle(-1,-1,10000,10000)
     dc.SetBrush(wx.Brush(wx.Colour(128,255,128)))
     dc.SetPen(wx.Pen(wx.Colour(128,128,128)))
     m=self.models[newname]
     #m.offsets=[10,10,0]
     print m.offsets,m.dims
     scale=2
     for i in m.facets:#random.sample(m.facets,min(100000,len(m.facets))):
         dc.DrawPolygon([wx.Point(400+scale*p[0],(400+scale*p[1])) for p in i[1]])
         #if(time.time()-t)>5:
         #    break
     dc.SelectObject(wx.NullBitmap)
     m.bitmap.SetMask(wx.Mask(m.bitmap,wx.Colour(0,0,0,255)))
     
     #print time.time()-t
     self.l.Append(newname)
     i=self.l.GetSelection()
     if i==wx.NOT_FOUND:
         self.l.Select(0)
 
     self.l.Select(self.l.GetCount()-1)
예제 #9
0
 def right(self,event):
     dlg=wx.FileDialog(self,"Open file to print",self.basedir,style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
     dlg.SetWildcard("STL files (;*.stl;)")
     if(dlg.ShowModal() == wx.ID_OK):
         name=dlg.GetPath()
         if not(os.path.exists(name)):
             return
         path = os.path.split(name)[0]
         self.basedir=path
         if name.lower().endswith(".stl"):
             self.models[name]=stltool.stl(name)
             self.l.Append([stlwrap(self.models[name],name)])
         self.Refresh()
예제 #10
0
 def create_objects(self):
     '''create opengl objects when opengl is initialized'''
     import stltool
     batch = pyglet.graphics.Batch()
     s = stltool.stl("x-end-idler.stl")
     stl = stlview(s.facets, batch=batch)
     #print "added vertices"
     self.batches += [[[50, 50, 0], batch, 0]]
     #batch = pyglet.graphics.Batch()
     #s= stltool.stl("../prusa/metric-prusa/mbotplate1.stl")
     #stl = stlview(s.facets, batch=batch)
     #print "added vertices"
     #self.batches+=[([-50,-50,0],batch)]
     self.initialized = 1
     wx.CallAfter(self.Refresh)
예제 #11
0
 def create_objects(self):
     '''create opengl objects when opengl is initialized'''
     import stltool
     batch = pyglet.graphics.Batch()
     s= stltool.stl("x-end-idler.stl")
     stl = stlview(s.facets, batch=batch)
     #print "added vertices"
     self.batches+=[[[50,50,0],batch,0]]
     #batch = pyglet.graphics.Batch()
     #s= stltool.stl("../prusa/metric-prusa/mbotplate1.stl")
     #stl = stlview(s.facets, batch=batch)
     #print "added vertices"
     #self.batches+=[([-50,-50,0],batch)]
     self.initialized=1
     wx.CallAfter(self.Refresh)
예제 #12
0
파일: plater.py 프로젝트: TeamMin/Printrun
    def load_stl_into_model(self,
                            path,
                            name,
                            offset=[0, 0, 0],
                            rotation=0,
                            scale=[1.0, 1.0, 1.0]):
        newname = os.path.split(name.lower())[1]
        c = 1
        while newname in self.models:
            newname = os.path.split(name.lower())[1]
            newname = newname + "(%d)" % c
            c += 1
        self.models[newname] = stltool.stl(path)
        self.models[newname].offsets = offset
        self.models[newname].rot = rotation
        self.models[newname].scale = scale
        self.models[newname].filename = name
        minx, miny, minz, maxx, maxy, maxz = (10000, 10000, 10000, 0, 0, 0)
        for i in self.models[newname].facets:
            for j in i[1]:
                if j[0] < minx:
                    minx = j[0]
                if j[1] < miny:
                    miny = j[1]
                if j[2] < minz:
                    minz = j[2]
                if j[0] > maxx:
                    maxx = j[0]
                if j[1] > maxy:
                    maxy = j[1]
                if j[2] > maxz:
                    maxz = j[2]
        self.models[newname].dims = [minx, maxx, miny, maxy, minz, maxz]
        #if minx < 0:
        #    self.models[newname].offsets[0] = -minx
        #if miny < 0:
        #    self.models[newname].offsets[1] = -miny
        self.s.drawmodel(self.models[newname], 2)

        #print time.time() - t
        self.l.Append(newname)
        i = self.l.GetSelection()
        if i == wx.NOT_FOUND:
            self.l.Select(0)

        self.l.Select(self.l.GetCount() - 1)
예제 #13
0
	def __init__(self, fn, startIdx, zzero, xoffset, yoffset):
		self.vertexMap = {}
		self.vertexVal = []
		self.vertexIdx = startIdx
		self.triangles = []
		self.name = fn
		
		self.stl = stltool.stl(filename=fn, zZero=zzero, xOffset=xoffset, yOffset=yoffset)
		for f in self.stl.facets:
			triangle = [None, None, None]
			for px in range(3):
				key = str(f[1][px][0]) + ";" + str(f[1][px][1]) + ";" + str(f[1][px][2])
				if key not in self.vertexMap.keys():
					self.vertexMap[key] = self.vertexIdx
					self.vertexVal.append(key)
					self.vertexIdx += 1
			
				triangle[px] = self.vertexMap[key]
	
			self.triangles.append(triangle)
예제 #14
0
파일: plater.py 프로젝트: malx122/Software
 def load_stl_into_model(self,path,name,offset=[0,0,0],rotation=0,scale=[1.0,1.0,1.0]):
     newname=os.path.split(name.lower())[1]
     c=1
     while newname in self.models:
         newname=os.path.split(name.lower())[1]
         newname=newname+"(%d)"%c
         c+=1
     self.models[newname]=stltool.stl(path)
     self.models[newname].offsets=offset
     self.models[newname].rot=rotation
     self.models[newname].scale=scale
     self.models[newname].filename=name
     minx,miny,minz,maxx,maxy,maxz=(10000,10000,10000,0,0,0)
     for i in self.models[newname].facets:
         for j in i[1]:
             if j[0]<minx:
                 minx=j[0]
             if j[1]<miny:
                 miny=j[1]
             if j[2]<minz:
                 minz=j[2]
             if j[0]>maxx:
                 maxx=j[0]
             if j[1]>maxy:
                 maxy=j[1]
             if j[2]>maxz:
                 maxz=j[2]
     self.models[newname].dims=[minx,maxx,miny,maxy,minz,maxz]
     #if minx<0:
     #    self.models[newname].offsets[0]=-minx
     #if miny<0:
     #    self.models[newname].offsets[1]=-miny
     self.s.drawmodel(self.models[newname],2)
     
     #print time.time()-t
     self.l.Append(newname)
     i=self.l.GetSelection()
     if i==wx.NOT_FOUND:
         self.l.Select(0)
 
     self.l.Select(self.l.GetCount()-1)
예제 #15
0
파일: plater.py 프로젝트: jbernardis/plater
	def doAdd(self):
		while True:
			confirmed = False
			fn = askopenfilename(filetypes=[("STL files", "*.stl")], initialdir=self.settings.lastdirectory)
			if fn:
				if self.preview:
					subprocess.Popen([self.settings.viewer, fn])
					if askyesno("Confirm Add", "Add this object?"):
						confirmed = True
				else:
					confirmed = True
			else:
				return
					
			if confirmed:
				self.modified = True
				self.filename = fn
				dn = os.path.dirname(fn)
				if dn != self.settings.lastdirectory:
					self.settings.lastdirectory = dn
					self.settings.setModified()
				
				name = "OBJECT%03d" % self.objNumber
				index = self.lbFiles.index(END)
				self.lbFiles.insert(END, "%2d: %s" % (self.objNumber, fn))
				if self.lbSelection is not None:
					self.lbFiles.selection_clear(self.lbSelection)
				self.lbFiles.selection_set(index)
				self.lbSelection = index
				self.objNumber += 1
				stlFile = stltool.stl(filename=fn, name=name)
				self.lbMap.append(stlFile)
				self.stlFrame.addStl(stlFile, highlight=True)
				self.bDel.config(state=NORMAL)
				self.bDelAll.config(state=NORMAL)
				self.bExport.config(state=NORMAL)
				self.bArrange.config(state=NORMAL)
				self.bClone.config(state=NORMAL)
				return
예제 #16
0
	def splitUpdate(self, evt):
		finished = False
		if evt.state == SPLIT_LAST_OBJECT:
			finished = True
			if self.part == 0:
				dlg = wx.MessageDialog(self,
					"Object consists of a single mesh",
					"Cannot Split",
					wx.OK | wx.ICON_EXCLAMATION)
				dlg.ShowModal()
				dlg.Destroy()
				self.splitter = None
				self.enableButtons()
				return
			
		nf = evt.facets
		if self.part == 0:
			ud = self.files.getSelection()
			ud.getStlObj().setFacets(nf)
			ud.setPart(self.part)
			self.files.refreshFilesList(ud.getSeqNbr())
			self.stlCanvas.refreshHull(ud.getSeqNbr())
		else:
			nobj = stl(filename=None)
			nobj.setFacets(nf)
			ud = UserData(self.partfn, nobj, self.seq)
			ud.setPart(self.part)
			self.files.addFile(ud)
			self.stlCanvas.addHull(nobj, self.seq)
			self.seq += 1
			
		self.part += 1
		
		if finished:
			self.modified = True
			self.splitter = None
			self.enableButtons()
		else:
			self.disableButtons()
예제 #17
0
def main():
    """
    """
    global opts
    (progdir, progname) = os.path.split(sys.argv[0])

    usage = "usage: %prog [options] file.stl"
    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()
    parser.add_options(options)
    (opts, args) = parser.parse_args()

    filename = None

    if len(args):
        filename = args[0]

    if opts.clear:
        b = get_buffer()
        set_header(b, 0, 0)

        if opts.debug:
            print >> sys.stderr, "corrections cleared"
        sys.exit(0)

    if opts.load:
        b = get_buffer()
        load_file(b, filename)
        sys.exit(0)

    if opts.dump:
        b = get_buffer()
        dump_buffer(b)
        sys.exit(0)

    scale = None
    rotate = None
    translate = None

    s = stltool.stl(filename=filename)
    if opts.scale:
        scale = map(float, opts.scale.split(',')[0:])
        if opts.debug:
            print >> sys.stderr, "scale:", scale
        s = s.scale(v=scale)

    if opts.rotate:
        rotate = map(float, opts.rotate.split(',')[0:])
        if opts.debug:
            print >> sys.stderr, "rotate:", rotate
        s = s.rotate(v=rotate)

    if opts.translate:
        translate = map(float, opts.translate.split(',')[0:])
        if opts.debug:
            print >> sys.stderr, "translate:", translate
        s = s.translate(v=translate)
    if opts.bbox:
        print >> sys.stderr, "bounding box: ", s.bbox

    if opts.gcode:
        gcode(s, filename, scale, rotate, translate)
    else:
        s.export(binary=opts.binary)
예제 #18
0
 def right(self,event):
     dlg=wx.FileDialog(self,"Open file to print",self.basedir,style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
     dlg.SetWildcard("STL files (;*.stl;)")
     if(dlg.ShowModal() == wx.ID_OK):
         name=dlg.GetPath()
         if not(os.path.exists(name)):
             return
         path = os.path.split(name)[0]
         self.basedir=path
         t=time.time()
         #print name
         if name.lower().endswith(".stl"):
             #Filter out the path, just show the STL filename.
             newname=os.path.split(name.lower())[1]
             c=1
             while newname in self.models:
                 newname=os.path.split(name.lower())[1]
                 newname=newname+"(%d)"%c
                 c+=1
             self.models[newname]=stltool.stl(name)
             self.models[newname].offsets=[0,0,0]
             self.models[newname].rot=0
             minx,miny,minz,maxx,maxy,maxz=(10000,10000,10000,0,0,0)
             for i in self.models[newname].facets:
                 for j in i[1]:
                     if j[0]<minx:
                         minx=j[0]
                     if j[1]<miny:
                         miny=j[1]
                     if j[2]<minz:
                         minz=j[2]
                     if j[0]>maxx:
                         maxx=j[0]
                     if j[1]>maxy:
                         maxy=j[1]
                     if j[2]>maxz:
                         maxz=j[2]
             self.models[newname].dims=[minx,maxx,miny,maxy,minz,maxz]
             #if minx<0:
             #    self.models[newname].offsets[0]=-minx
             #if miny<0:
             #    self.models[newname].offsets[1]=-miny
             self.models[newname].bitmap=wx.EmptyBitmap(800,800,32)
             dc=wx.MemoryDC()
             dc.SelectObject(self.models[newname].bitmap)
             dc.SetBackground(wx.Brush((0,0,0,0)))
             dc.SetBrush(wx.Brush((0,0,0,255)))
             #dc.DrawRectangle(-1,-1,10000,10000)
             dc.SetBrush(wx.Brush(wx.Colour(128,255,128)))
             dc.SetPen(wx.Pen(wx.Colour(128,128,128)))
             m=self.models[newname]
             #m.offsets=[10,10,0]
             print m.offsets,m.dims
             scale=2
             for i in m.facets:#random.sample(m.facets,min(100000,len(m.facets))):
                 dc.DrawPolygon([wx.Point(400+scale*p[0],(400+scale*p[1])) for p in i[1]])
                 #if(time.time()-t)>5:
                 #    break
             dc.SelectObject(wx.NullBitmap)
             m.bitmap.SetMask(wx.Mask(m.bitmap,wx.Colour(0,0,0,255)))
             
             #print time.time()-t
             self.l.Append(newname)
             i=self.l.GetSelection()
             if i==wx.NOT_FOUND:
                 self.l.Select(0)
         
             self.l.Select(self.l.GetCount()-1)
         self.Refresh()
예제 #19
0
    def right(self, event):
        dlg = wx.FileDialog(self,
                            "Open file to print",
                            self.basedir,
                            style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        dlg.SetWildcard("STL files (;*.stl;)")
        if (dlg.ShowModal() == wx.ID_OK):
            name = dlg.GetPath()
            if not (os.path.exists(name)):
                return
            path = os.path.split(name)[0]
            self.basedir = path
            t = time.time()
            #print name
            if name.lower().endswith(".stl"):
                #Filter out the path, just show the STL filename.
                newname = os.path.split(name.lower())[1]
                c = 1
                while newname in self.models:
                    newname = os.path.split(name.lower())[1]
                    newname = newname + "(%d)" % c
                    c += 1
                self.models[newname] = stltool.stl(name)
                self.models[newname].offsets = [0, 0, 0]
                self.models[newname].rot = 0
                minx, miny, minz, maxx, maxy, maxz = (10000, 10000, 10000, 0,
                                                      0, 0)
                for i in self.models[newname].facets:
                    for j in i[1]:
                        if j[0] < minx:
                            minx = j[0]
                        if j[1] < miny:
                            miny = j[1]
                        if j[2] < minz:
                            minz = j[2]
                        if j[0] > maxx:
                            maxx = j[0]
                        if j[1] > maxy:
                            maxy = j[1]
                        if j[2] > maxz:
                            maxz = j[2]
                self.models[newname].dims = [
                    minx, maxx, miny, maxy, minz, maxz
                ]
                #if minx<0:
                #    self.models[newname].offsets[0]=-minx
                #if miny<0:
                #    self.models[newname].offsets[1]=-miny
                self.models[newname].bitmap = wx.EmptyBitmap(800, 800, 32)
                dc = wx.MemoryDC()
                dc.SelectObject(self.models[newname].bitmap)
                dc.SetBackground(wx.Brush((0, 0, 0, 0)))
                dc.SetBrush(wx.Brush((0, 0, 0, 255)))
                #dc.DrawRectangle(-1,-1,10000,10000)
                dc.SetBrush(wx.Brush(wx.Colour(128, 255, 128)))
                dc.SetPen(wx.Pen(wx.Colour(128, 128, 128)))
                m = self.models[newname]
                #m.offsets=[10,10,0]
                print m.offsets, m.dims
                scale = 2
                for i in m.facets:  #random.sample(m.facets,min(100000,len(m.facets))):
                    dc.DrawPolygon([
                        wx.Point(400 + scale * p[0], (400 + scale * p[1]))
                        for p in i[1]
                    ])
                    #if(time.time()-t)>5:
                    #    break
                dc.SelectObject(wx.NullBitmap)
                m.bitmap.SetMask(wx.Mask(m.bitmap, wx.Colour(0, 0, 0, 255)))

                #print time.time()-t
                self.l.Append(newname)
                i = self.l.GetSelection()
                if i == wx.NOT_FOUND:
                    self.l.Select(0)

                self.l.Select(self.l.GetCount() - 1)
            self.Refresh()