Commit 46b75a3d authored by lode_leroy's avatar lode_leroy

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@14 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 406b32f2
BRLCAD=/opt/brlcad/bin
BRLCAD=c:/Software/BRL-CAD/bin
MGED=$(BRLCAD)/mged
G-STL=$(BRLCAD)/g-stl
VER=0.1.4
all:
.PHONY: dist
dist:
(cd ..; tar zcf pycam/pycam.tgz pycam/*{Makefile,TXT} pycam/*.py pycam/tests/*.py pycam/pycam/*/*.py pycam/pycam/*.py pycam/Samples/*/*.stl)
dist-ver:
(cd ..; tar zcf pycam-$(VER)/pycam-$(VER).tgz pycam-$(VER)/*{Makefile,TXT} pycam-$(VER)/*.py pycam-$(VER)/tests/*.py pycam-$(VER)/pycam/*/*.py pycam-$(VER)/pycam/*.py pycam-$(VER)/Samples/*/*.stl)
test:
rm -f test.g; $(MGED) test.g < test.txt; $(MGED) test.g
test0:
rm -f test.g; $(MGED) test.g < cutter0.txt; $(MGED) test.g
test1:
rm -f test.g; $(MGED) test.g < cutter1.txt; $(MGED) test.g
test2:
rm -f test.g; $(MGED) test.g < cutter2.txt; $(MGED) test.g
test3:
rm -f test.g; $(MGED) test.g < cutter3.txt; $(MGED) test.g
TestModel.stl:
./Tests/MGEDExporterTest.py
rm -f TestModel.g
$(MGED) TestModel.g < TestModel.txt
$(G-STL) -o TestModel.stl TestModel.g model0
import sys import sys
import os import os
sys.path.insert(0, os.path.join(sys.prefix, "PyOpenGL-3.0.0b5-py2.5.egg")) sys.path.insert(0, os.path.join(sys.prefix, "PyOpenGL-3.0.0b5-py2.5.egg"))
sys.path.insert(0, os.path.join(sys.prefix, "setuptools-0.6c8-py2.5.egg")) sys.path.insert(0, os.path.join(sys.prefix, "setuptools-0.6c8-py2.5.egg"))
from pycam.Gui.SimpleGui import SimpleGui from pycam.Gui.SimpleGui import SimpleGui
from pycam.Importers.TestModel import TestModel from pycam.Importers.TestModel import TestModel
gui = SimpleGui() gui = SimpleGui()
gui.model = TestModel() gui.model = TestModel()
gui.mainloop() gui.mainloop()
from pycam.PathProcessors import * from pycam.PathProcessors import *
from pycam.Geometry import * from pycam.Geometry import *
from pycam.Geometry.utils import * from pycam.Geometry.utils import *
class Hit: class Hit:
def __init__(self, cl, t, d, dir): def __init__(self, cl, t, d, dir):
self.cl = cl self.cl = cl
self.t = t self.t = t
self.d = d self.d = d
self.dir = dir self.dir = dir
def cmp(a,b): def cmp(a,b):
return cmp(a.d, b.d) return cmp(a.d, b.d)
class PushCutter: class PushCutter:
def __init__(self, cutter, model, pathextractor=None): def __init__(self, cutter, model, pathextractor=None):
self.cutter = cutter self.cutter = cutter
self.model = model self.model = model
self.pa = pathextractor self.pa = pathextractor
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz): def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz):
if dx==0: if dx==0:
forward = Point(1,0,0) forward = Point(1,0,0)
backward = Point(-1,0,0) backward = Point(-1,0,0)
elif dy == 0: elif dy == 0:
forward = Point(0,1,0) forward = Point(0,1,0)
backward = Point(0,-1,0) backward = Point(0,-1,0)
z = maxz z = maxz
c = self.cutter c = self.cutter
model = self.model model = self.model
paths = [] paths = []
while z >= minz: while z >= minz:
self.pa.new_direction(0) self.pa.new_direction(0)
x = minx x = minx
y = miny y = miny
while x<=maxx and y<=maxy: while x<=maxx and y<=maxy:
self.pa.new_scanline() self.pa.new_scanline()
# find all hits along scan line # find all hits along scan line
hits = [] hits = []
prev = Point(x,y,z) prev = Point(x,y,z)
c.moveto(prev) c.moveto(prev)
for t in model.triangles(): for t in model.triangles():
if t.normal().z < 0: continue; if t.normal().z < 0: continue;
# normals point outward... and we want to approach the model from the outside! # normals point outward... and we want to approach the model from the outside!
n = t.normal().dot(forward) n = t.normal().dot(forward)
if n>=0: if n>=0:
(cl,d) = c.intersect(backward, t) (cl,d) = c.intersect(backward, t)
if cl: if cl:
# print "< cl=",cl,",d=",-d,",t=",t # print "< cl=",cl,",d=",-d,",t=",t
hits.append(Hit(cl,t,-d,backward)) hits.append(Hit(cl,t,-d,backward))
if n<=0: if n<=0:
(cl,d) = c.intersect(forward, t) (cl,d) = c.intersect(forward, t)
if cl: if cl:
# print "> cl=",cl,",d=",d,",t=",t # print "> cl=",cl,",d=",d,",t=",t
hits.append(Hit(cl,t,d,forward)) hits.append(Hit(cl,t,d,forward))
# sort along the scan direction # sort along the scan direction
hits.sort(Hit.cmp) hits.sort(Hit.cmp)
# remove duplicates (typically edges) # remove duplicates (typically edges)
i = 1 i = 1
while i < len(hits): while i < len(hits):
while i<len(hits) and abs(hits[i].d - hits[i-1].d)<epsilon: while i<len(hits) and abs(hits[i].d - hits[i-1].d)<epsilon:
del hits[i] del hits[i]
i += 1 i += 1
# find parts of scanline where model is below z-level # find parts of scanline where model is below z-level
i = 0 i = 0
while i < len(hits): while i < len(hits):
next = hits[i].cl next = hits[i].cl
self.pa.append(prev) self.pa.append(prev)
self.pa.append(next) self.pa.append(next)
i += 1 i += 1
# find next hit cutter location that is below z-level # find next hit cutter location that is below z-level
while i < len(hits): while i < len(hits):
prev = hits[i].cl prev = hits[i].cl
c.moveto(prev) c.moveto(prev)
c.moveto(prev.sub(hits[i].dir.mul(epsilon))) c.moveto(prev.sub(hits[i].dir.mul(epsilon)))
zmax = -INFINITE zmax = -INFINITE
for t in model.triangles(): for t in model.triangles():
if t.normal().z < 0: continue; if t.normal().z < 0: continue;
cl = c.drop(t) cl = c.drop(t)
if cl and cl.z > zmax and cl.z < INFINITE: if cl and cl.z > zmax and cl.z < INFINITE:
zmax = cl.z zmax = cl.z
i += 1 i += 1
if zmax <= z+epsilon: if zmax <= z+epsilon:
break break
if dx == 0: if dx == 0:
x = maxx x = maxx
if dy == 0: if dy == 0:
y = maxy y = maxy
next = Point(x,y,z) next = Point(x,y,z)
self.pa.append(prev) self.pa.append(prev)
self.pa.append(next) self.pa.append(next)
if dx != 0: if dx != 0:
x += dx x += dx
else: else:
x = minx x = minx
if dy != 0: if dy != 0:
y += dy y += dy
else: else:
y = miny y = miny
self.pa.end_scanline() self.pa.end_scanline()
self.pa.end_direction() self.pa.end_direction()
self.pa.finish() self.pa.finish()
paths += self.pa.paths paths += self.pa.paths
z -= dz z -= dz
return paths return paths
__all__ = [ "Utils", "Geometry", "Cutters", "PathGenerators", "PathProcessors", "Importers", "Exporters", "Gui"] __all__=["Cutters","Exporters","Geometry","Gui","Importers","PathGenerators","PathProcessors","Utils"]
import pycam.Utils
import pycam.Geometry
import pycam.Cutters
import pycam.PathGenerators
import pycam.PathProcessors
import pycam.Importers
import pycam.Exporters
import pycam.Gui
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment