Skip to content

Commit

Permalink
Fix base geometry reference to use tuple in PropertyLinkSubList
Browse files Browse the repository at this point in the history
Also improves the naive test of vertical/horizontal faces for profiling.

replace naive test of verticality

Fix base references to use tuple in PropertyLinkSubList
78b92d4
  • Loading branch information
sliptonic committed Jun 2, 2016
1 parent d3b6911 commit 6425ef7
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 122 deletions.
108 changes: 56 additions & 52 deletions src/Mod/Path/PathScripts/PathDrilling.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,57 +103,57 @@ def execute(self, obj):
else:
obj.Label = obj.UserLabel + " (" + obj.ToolDescription + ")"

locations = []
output = "(Begin Drilling)\n"
if obj.Base:
locations = []
for loc in obj.Base:

if "Face" in loc[1] or "Edge" in loc[1]:
s = getattr(loc[0].Shape, loc[1])
else:
s = loc[0].Shape

if s.ShapeType in ['Wire', 'Edge']:
X = s.Edges[0].Curve.Center.x
Y = s.Edges[0].Curve.Center.y
Z = s.Edges[0].Curve.Center.z
elif s.ShapeType in ['Vertex']:
X = s.Point.x
Y = s.Point.y
Z = s.Point.z
elif s.ShapeType in ['Face']:
#if abs(s.normalAt(0, 0).z) == 1: # horizontal face
X = s.CenterOfMass.x
Y = s.CenterOfMass.y
Z = s.CenterOfMass.z




locations.append(FreeCAD.Vector(X, Y, Z))

output = "G90 G98\n"
# rapid to clearance height
output += "G0 Z" + str(obj.ClearanceHeight.Value)
# rapid to first hole location, with spindle still retracted:
p0 = locations[0]
output += "G0 X" + str(p0.x) + " Y" + str(p0.y) + "\n"
# move tool to clearance plane
output += "G0 Z" + str(obj.ClearanceHeight.Value) + "\n"
if obj.PeckDepth.Value > 0:
cmd = "G83"
qword = " Q" + str(obj.PeckDepth.Value)
else:
cmd = "G81"
qword = ""
for p in locations:
output += cmd + \
" X" + str(p.x) + \
" Y" + str(p.y) + \
" Z" + str(obj.FinalDepth.Value) + qword + \
" R" + str(obj.RetractHeight.Value) + \
" F" + str(self.vertFeed) + "\n" \

output += "G80\n"
for sub in loc[1]:

if "Face" in sub or "Edge" in sub:
s = getattr(loc[0].Shape, sub)
else:
s = loc[0].Shape

if s.ShapeType in ['Wire', 'Edge']:
X = s.Edges[0].Curve.Center.x
Y = s.Edges[0].Curve.Center.y
Z = s.Edges[0].Curve.Center.z
elif s.ShapeType in ['Vertex']:
X = s.Point.x
Y = s.Point.y
Z = s.Point.z
elif s.ShapeType in ['Face']:
#if abs(s.normalAt(0, 0).z) == 1: # horizontal face
X = s.CenterOfMass.x
Y = s.CenterOfMass.y
Z = s.CenterOfMass.z

locations.append(FreeCAD.Vector(X, Y, Z))


output += "G90 G98\n"
# rapid to clearance height
output += "G0 Z" + str(obj.ClearanceHeight.Value)
# rapid to first hole location, with spindle still retracted:
p0 = locations[0]
output += "G0 X" + str(p0.x) + " Y" + str(p0.y) + "\n"
# move tool to clearance plane
output += "G0 Z" + str(obj.ClearanceHeight.Value) + "\n"
if obj.PeckDepth.Value > 0:
cmd = "G83"
qword = " Q" + str(obj.PeckDepth.Value)
else:
cmd = "G81"
qword = ""
for p in locations:
output += cmd + \
" X" + str(p.x) + \
" Y" + str(p.y) + \
" Z" + str(obj.FinalDepth.Value) + qword + \
" R" + str(obj.RetractHeight.Value) + \
" F" + str(self.vertFeed) + "\n" \

output += "G80\n"

path = Path.Path(output)
obj.Path = path
Expand Down Expand Up @@ -319,7 +319,8 @@ def setFields(self):

self.form.baseList.clear()
for i in self.obj.Base:
self.form.baseList.addItem(i[0].Name + "." + i[1])
for sub in i[1]:
self.form.baseList.addItem(i[0].Name + "." + sub)


def open(self):
Expand All @@ -341,8 +342,11 @@ def addBase(self):
self.obj.Proxy.addDrillableLocation(self.obj, s.Object)

self.setFields() # defaults may have changed. Reload.
# for i in self.obj.Base:
# self.form.baseList.addItem(i[0].Name + "." + i[1])
self.form.baseList.clear()

for i in self.obj.Base:
for sub in i[1]:
self.form.baseList.addItem(i[0].Name + "." + sub)

def deleteBase(self):
dlist = self.form.baseList.selectedItems()
Expand Down
116 changes: 63 additions & 53 deletions src/Mod/Path/PathScripts/PathPocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,59 +380,60 @@ def execute(self, obj):

if obj.Base:
for b in obj.Base:
print "object base: " + str(b)
import Part
import PathScripts.PathKurveUtils
if "Face" in b[1]:
print "inside"
shape = getattr(b[0].Shape, b[1])
wire = shape.OuterWire
edges = wire.Edges
else:
print "in else"
edges = [getattr(b[0].Shape, sub) for sub in b[1]]
print "myedges: " + str(edges)
wire = Part.Wire(edges)
shape = None

# output = ""
if obj.Algorithm == "OCC Native":
if shape is None:
shape = wire
output += self.buildpathocc(obj, shape)
else:
try:
import area
except:
FreeCAD.Console.PrintError(translate("PathKurve", "libarea needs to be installed for this command to work.\n"))
return

a = area.Area()
if shape is None:
c = PathScripts.PathKurveUtils.makeAreaCurve(wire.Edges, 'CW')
a.append(c)
for sub in b[1]:
print "object base: " + str(b)
import Part
import PathScripts.PathKurveUtils
if "Face" in sub:
print "inside"
shape = getattr(b[0].Shape, sub)
wire = shape.OuterWire
edges = wire.Edges
else:
print "in else"
edges = [getattr(b[0].Shape, sub) for sub in b[1]]
print "myedges: " + str(edges)
wire = Part.Wire(edges)
shape = None

# output = ""
if obj.Algorithm == "OCC Native":
if shape is None:
shape = wire
output += self.buildpathocc(obj, shape)
else:
for w in shape.Wires:
c = PathScripts.PathKurveUtils.makeAreaCurve(w.Edges, 'CW')
# if w.isSame(shape.OuterWire):
# print "outerwire"
# if c.IsClockwise():
# c.Reverse()
# print "reverse outterwire"
# else:
# print "inner wire"
# if not c.IsClockwise():
# c.Reverse()
# print "reverse inner"
try:
import area
except:
FreeCAD.Console.PrintError(translate("PathKurve", "libarea needs to be installed for this command to work.\n"))
return

a = area.Area()
if shape is None:
c = PathScripts.PathKurveUtils.makeAreaCurve(wire.Edges, 'CW')
a.append(c)

########
# This puts out some interesting information from libarea
print a.text()
########

a.Reorder()
output += self.buildpathlibarea(obj, a)
else:
for w in shape.Wires:
c = PathScripts.PathKurveUtils.makeAreaCurve(w.Edges, 'CW')
# if w.isSame(shape.OuterWire):
# print "outerwire"
# if c.IsClockwise():
# c.Reverse()
# print "reverse outterwire"
# else:
# print "inner wire"
# if not c.IsClockwise():
# c.Reverse()
# print "reverse inner"
a.append(c)

########
# This puts out some interesting information from libarea
print a.text()
########

a.Reorder()
output += self.buildpathlibarea(obj, a)

if obj.Active:
path = Path.Path(output)
Expand Down Expand Up @@ -598,8 +599,12 @@ def setFields(self):
if index >= 0:
self.form.algorithmSelect.setCurrentIndex(index)

# for i in self.obj.Base:
# self.form.baseList.addItem(i[0].Name + "." + i[1][0])

for i in self.obj.Base:
self.form.baseList.addItem(i[0].Name + "." + i[1])
for sub in i[1]:
self.form.baseList.addItem(i[0].Name + "." + sub)



Expand Down Expand Up @@ -628,8 +633,13 @@ def addBase(self):

self.setFields() # defaults may have changed. Reload.
self.form.baseList.clear()

for i in self.obj.Base:
self.form.baseList.addItem(i[0].Name + "." + i[1])
for sub in i[1]:
self.form.baseList.addItem(i[0].Name + "." + sub)

# for i in self.obj.Base:
# self.form.baseList.addItem(i[0].Name + "." + i[1][0])

def deleteBase(self):
dlist = self.form.baseList.selectedItems()
Expand Down
37 changes: 20 additions & 17 deletions src/Mod/Path/PathScripts/PathProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import FreeCAD
import Path
import numpy
from FreeCAD import Vector
from PathScripts import PathUtils
from PathScripts.PathUtils import depth_params
Expand Down Expand Up @@ -290,15 +291,18 @@ def execute(self, obj):
wires = []

for b in obj.Base:
# we only consider the outer wire if this is a Face
# Horizontal and vertical faces are handled differently
shape = getattr(b[0].Shape, b[1])
if abs(shape.normalAt(0, 0).z) == 1: # horizontal face
hfaces.append(shape)

elif abs(shape.normalAt(0, 0).z) == 0: # vertical face
vfaces.append(shape)

for sub in b[1]:
# we only consider the outer wire if this is a Face
# Horizontal and vertical faces are handled differently
shape = getattr(b[0].Shape, sub)
if numpy.isclose(shape.normalAt(0, 0).z, 1): # horizontal face
hfaces.append(shape)

elif numpy.isclose(shape.normalAt(0, 0).z, 0): # vertical face
vfaces.append(shape)
else:
FreeCAD.Console.PrintError(translate("Path", "Face doesn't appear to be parallel or perpendicular to the XY plane. No path will be generated for: \n"))
FreeCAD.Console.PrintError(b[0].Name + "." + sub + "\n")
for h in hfaces:
wires.append(h.OuterWire)

Expand Down Expand Up @@ -443,9 +447,6 @@ def IsActive(self):
return FreeCAD.ActiveDocument is not None

def Activated(self):
# import Path
# from PathScripts import PathProject, PathUtils, PathKurveUtils

ztop = 10.0
zbottom = 0.0

Expand Down Expand Up @@ -553,7 +554,8 @@ def setFields(self):
self.form.direction.setCurrentIndex(index)

for i in self.obj.Base:
self.form.baseList.addItem(i[0].Name + "." + i[1])
for sub in i[1]:
self.form.baseList.addItem(i[0].Name + "." + sub)

for i in range(len(self.obj.locs)):
item = QtGui.QTreeWidgetItem(self.form.tagTree)
Expand Down Expand Up @@ -586,15 +588,16 @@ def addBase(self):
FreeCAD.Console.PrintError(translate("PathProject", "Please select faces from one solid\n"))
return

# if s.HasSubObjects:
for i in sel.SubElementNames:
self.obj.Proxy.addprofilebase(self.obj, sel.Object, i)
#else:
#self.obj.Proxy.addprofilebase(self.obj, s.Object)

self.setFields() # defaults may have changed. Reload.
self.form.baseList.clear()

for i in self.obj.Base:
self.form.baseList.addItem(i[0].Name + "." + i[1])
for sub in i[1]:
self.form.baseList.addItem(i[0].Name + "." + sub)


def deleteBase(self):
dlist = self.form.baseList.selectedItems()
Expand Down

0 comments on commit 6425ef7

Please sign in to comment.