Jeff Doyle (nfz) 2015-12-07 12:36:06 -04:00
commit a18811a644
2 zmienionych plików z 111 dodań i 76 usunięć

Wyświetl plik

@ -1,4 +1,10 @@
import Polygon
import shapely
from shapely.geometry import polygon as spolygon
from shapely import ops
from shapely import geometry
from cam import simple
from cam.simple import *
@ -606,7 +612,28 @@ def parentChild(parents, children, o):
if parent!=child:
parent.children.append(child)
child.parents.append(parent)
def chunksToShapely(chunks):#this does more cleve chunks to Poly with hierarchies... ;)
#print ('analyzing paths')
#verts=[]
#pverts=[]
polys=[]
for ch in chunks:#first convert chunk to poly
if len(ch.points)>2:
pchunk=[]
for v in ch.points:
pchunk.append((v[0],v[1]))
ch.poly=spolygon.Polygon(pchunk)
#ch.poly.simplify()
returnpolys=[]
for ch in chunks:#export only the booleaned polygons
returnpolys.append(ch.poly)
#print(len(returnpolys))
return returnpolys
def chunksToPolys(chunks):#this does more cleve chunks to Poly with hierarchies... ;)
#print ('analyzing paths')
#verts=[]

Wyświetl plik

@ -53,7 +53,7 @@ from cam.polygon_utils_cam import *
from cam import image_utils
from cam.image_utils import *
from . import nc
from cam.opencamlib.opencamlib import oclSample, oclSamplePoints, oclResampleChunks, oclGetWaterline
from cam.opencamlib.opencamlib import oclSample, oclSamplePoints, oclResampleChunks, oclGetWaterline
try:
from shapely.geometry import polygon as spolygon
@ -254,7 +254,7 @@ def samplePathLow(o,ch1,ch2,dosample):
#print(len(bpath))
pixsize=o.pixsize
if dosample:
if not (o.use_opencamlib and o.use_exact):
if not (o.use_opencamlib and o.use_exact):
if o.use_exact:
cutterdepth=o.cutter_shape.dimensions.z/2
for p in bpath.points:
@ -279,10 +279,10 @@ def sampleChunks(o,pathSamples,layers):
getAmbient(o)
if o.use_exact:#prepare collision world
if o.use_opencamlib:
oclSample(o, pathSamples)
cutterdepth=0
else:
if o.use_opencamlib:
oclSample(o, pathSamples)
cutterdepth=0
else:
if o.update_bullet_collision_tag:
prepareBulletCollision(o)
@ -352,11 +352,11 @@ def sampleChunks(o,pathSamples,layers):
if not o.ambient.isInside(x,y):
newsample=(x,y,1)
else:
if o.use_opencamlib and o.use_exact:
z=s[2]
if minz>z:
z=minz
newsample=(x,y,z)
if o.use_opencamlib and o.use_exact:
z=s[2]
if minz>z:
z=minz
newsample=(x,y,z)
####sampling
elif o.use_exact and not o.use_opencamlib:
@ -817,20 +817,20 @@ def doSimulation(name,operations):
numpysave(i,iname)
i=bpy.data.images.load(iname)
createSimulationObject(name,operations,i)
def extendChunks5axis(chunks,o):
s=bpy.context.scene
m=s.cam_machine
m=s.cam_machine
s=bpy.context.scene
free_movement_height = o.free_movement_height# o.max.z +
if m.use_position_definitions:# dhull
cutterstart=Vector((m.starting_position.x, m.starting_position.y ,max(o.max.z, m.starting_position.z)))#start point for casting
else:
cutterstart=Vector((0,0,max(o.max.z,free_movement_height)))#start point for casting
cutterend=Vector((0,0,o.min.z))
oriname=o.name+' orientation'
ori=s.objects[oriname]
cutterstart=Vector((0,0,max(o.max.z,free_movement_height)))#start point for casting
cutterend=Vector((0,0,o.min.z))
oriname=o.name+' orientation'
ori=s.objects[oriname]
#rotationaxes = rotTo2axes(ori.rotation_euler,'CA')#warning-here it allready is reset to 0!!
print('rot',o.rotationaxes)
a,b=o.rotationaxes#this is all nonsense by now.
@ -846,23 +846,23 @@ def extendChunks5axis(chunks,o):
def chunksToMesh(chunks,o):
'''convert sampled chunks to path, optimization of paths'''
t=time.time()
s=bpy.context.scene
m=s.cam_machine
'''convert sampled chunks to path, optimization of paths'''
t=time.time()
s=bpy.context.scene
m=s.cam_machine
verts=[]
free_movement_height = o.free_movement_height#o.max.z +
if o.machine_axes=='3':
if m.use_position_definitions:
origin=(m.starting_position.x, m.starting_position.y, m.starting_position.z)# dhull
origin=(m.starting_position.x, m.starting_position.y, m.starting_position.z)# dhull
else:
origin=(0,0,free_movement_height)
verts = [origin]
if o.machine_axes!='3':
verts_rotations=[]#(0,0,0)
origin=(0,0,free_movement_height)
verts = [origin]
if o.machine_axes!='3':
verts_rotations=[]#(0,0,0)
if (o.machine_axes == '5' and o.strategy5axis=='INDEXED') or (o.machine_axes=='4' and o.strategy4axis=='INDEXED'):
extendChunks5axis(chunks,o)
@ -1035,27 +1035,27 @@ def exportGcodePath(filename,vertslist,operations):
elif m.post_processor=='GRAVOS':
extension = '.nc'
from .nc import gravos as postprocessor
elif m.post_processor=='WIN-PC' :
extension='.din'
from .nc import winpc as postprocessor
elif m.post_processor=='WIN-PC' :
extension='.din'
from .nc import winpc as postprocessor
elif m.post_processor=='SHOPBOT MTC':
extension='.sbp'
from .nc import shopbot_mtc as postprocessor
elif m.post_processor=='LYNX_OTTER_O':
extension='.nc'
from .nc import lynx_otter_o as postprocessor
if s.unit_settings.system=='METRIC':
unitcorr=1000.0
elif s.unit_settings.system=='IMPERIAL':
unitcorr=1/0.0254;
else:
unitcorr=1;
rotcorr=180.0/pi
if s.unit_settings.system=='METRIC':
unitcorr=1000.0
elif s.unit_settings.system=='IMPERIAL':
unitcorr=1/0.0254;
else:
unitcorr=1;
rotcorr=180.0/pi
def startNewFile():
def startNewFile():
fileindex=''
if split:
fileindex='_'+str(findex)
@ -1064,15 +1064,15 @@ def exportGcodePath(filename,vertslist,operations):
c.file_open(filename)
#unit system correction
###############
if s.unit_settings.system=='METRIC':
c.metric()
elif s.unit_settings.system=='IMPERIAL':
###############
if s.unit_settings.system=='METRIC':
c.metric()
elif s.unit_settings.system=='IMPERIAL':
c.imperial()
#start program
#start program
c.program_begin(0,filename)
c.flush_nc()
c.flush_nc()
c.comment('G-code generated with BlenderCAM and NC library')
#absolute coordinates
c.absolute()
@ -1117,35 +1117,35 @@ def exportGcodePath(filename,vertslist,operations):
c.flush_nc()
if m.spindle_start_time>0:
c.dwell(m.spindle_start_time)
c.flush_nc()
# dhull c.feedrate(unitcorr*o.feedrate)
c.flush_nc()
# dhull c.feedrate(unitcorr*o.feedrate)
#commands=[]
m=bpy.context.scene.cam_machine
millfeedrate=min(o.feedrate,m.feedrate_max)
millfeedrate=unitcorr*max(millfeedrate,m.feedrate_min)
plungefeedrate= millfeedrate*o.plunge_feedrate/100
plungefeedrate= millfeedrate*o.plunge_feedrate/100
freefeedrate=m.feedrate_max*unitcorr
fadjust=False
fadjust=False
if o.do_simulation_feedrate and mesh.shape_keys!= None and mesh.shape_keys.key_blocks.find('feedrates')!=-1:
shapek = mesh.shape_keys.key_blocks['feedrates']
fadjust=True
if m.use_position_definitions:# dhull
last=Vector((m.starting_position.x, m.starting_position.y, m.starting_position.z))
else:
last=Vector((0.0,0.0,free_movement_height))#nonsense values so first step of the operation gets written for sure
lastrot=Euler((0,0,0))
duration=0.0
else:
last=Vector((0.0,0.0,free_movement_height))#nonsense values so first step of the operation gets written for sure
lastrot=Euler((0,0,0))
duration=0.0
f=millfeedrate
fadjustval = 1 # if simulation load data is Not present
downvector= Vector((0,0,-1))
plungelimit=(pi/2-o.plunge_angle)
@ -1281,7 +1281,11 @@ def curveToPolys(cob):
chunks=curveToChunks(cob)
polys=chunksToPolys(chunks)
return polys
def curveToShapely(cob):
chunks=curveToChunks(cob)
polys=chunksToShapely(chunks)
return polys
#separate function in blender, so you can offset any curve.
#FIXME: same algorithms as the cutout strategy, because that is hierarchy-respecting.
@ -1482,7 +1486,7 @@ def sortChunks(chunks,o):
progress('sorting paths')
sys.setrecursionlimit(100000)# the getNext() function of CamPathChunk was running out of recursion limits.
sortedchunks=[]
chunks_to_resample=[]
chunks_to_resample=[]
lastch=None
i=len(chunks)
@ -1526,7 +1530,7 @@ def sortChunks(chunks,o):
print(len(ch.points))
'''
sys.setrecursionlimit(1000)
if o.strategy!='DRILL':
sortedchunks = connectChunksLow(sortedchunks,o)
@ -2295,6 +2299,12 @@ def getPath3axis(context, operation):
chunksFromCurve=[]
lastchunks=[]
centers=None
checkCenters=False
if o.dist_between_paths>o.cutter_diameter/2.0:
checkCenters=True
o.warnings=o.warnings+'Distance between paths larger\n than cutter radius can result in uncut areas!\n '
while len(p)>0:
nchunks=polyToChunks(p,o.min.z)
nchunks=limitChunks(nchunks,o)
@ -2304,9 +2314,7 @@ def getPath3axis(context, operation):
pnew=outlinePoly(p,o.dist_between_paths,o.circle_detail,o.optimize,o.optimize_threshold,False)
if o.dist_between_paths>o.cutter_diameter/2.0:#this mess under this IF condition is here ONLY because of the ability to have stepover> than cutter radius. Other CAM softwares don't allow this at all, maybe because of this mathematical problem and performance cost, but into soft materials, this is good to have.
o.warnings=o.warnings+'Distance between paths larger\n than cutter radius can result in uncut areas!\n '
if checkCenters:
contours_before=len(p)
if centers==None:
@ -2584,16 +2592,16 @@ def getPath3axis(context, operation):
elif o.strategy=='WATERLINE' and o.use_opencamlib:
getAmbient(o)
chunks=[]
oclGetWaterline(o, chunks)
chunks=limitChunks(chunks,o)
getAmbient(o)
chunks=[]
oclGetWaterline(o, chunks)
chunks=limitChunks(chunks,o)
if (o.movement_type=='CLIMB' and o.spindle_rotation_direction=='CW') or (o.movement_type=='CONVENTIONAL' and o.spindle_rotation_direction=='CCW'):
for ch in chunks:
ch.points.reverse()
chunksToMesh(chunks,o)
chunksToMesh(chunks,o)
elif o.strategy=='WATERLINE' and not o.use_opencamlib:
topdown=True
tw=time.time()