Extensive Path Workbench improvements.

Implement libarea improvements for profile
Implement libarea pocketing.
consolidate occ and libarea pocketing operation into one with algorithm
switch
consolidate occ aand libarea profile op into one with algorithm switch
add basic engraving operation.
Add rough UI for profile holding tags
implement holding tags for libarea profile.
implement basic defaults for depth settings.
First move in Drilling is rapid to clearance height.

UI needs lots of work but is usable.
This commit is contained in:
sliptonic
2016-02-24 09:02:25 -06:00
committed by Yorik van Havre
parent a55f676134
commit b67f6f1886
71 changed files with 11954 additions and 727 deletions

View File

@@ -22,11 +22,23 @@
#* *
#***************************************************************************
import FreeCAD,FreeCADGui,Path,PathGui
import FreeCAD,Path
from FreeCAD import Vector
from PySide import QtCore,QtGui
from PathScripts import PathUtils,PathSelection,PathProject
if FreeCAD.GuiUp:
import FreeCADGui, PathGui
from PySide import QtCore, QtGui
from DraftTools import translate
from pivy import coin
else:
def translate(ctxt,txt):
return txt
__title__="Path Profile Operation"
__author__ = "sliptonic (Brad Collette)"
__url__ = "http://www.freecadweb.org"
"""Path Profile object and FreeCAD command"""
# Qt tanslation handling
@@ -38,59 +50,84 @@ except AttributeError:
def translate(context, text, disambig=None):
return QtGui.QApplication.translate(context, text, disambig)
def makeProfile(self, name="Profile"):
'''creates a Profile operation'''
#obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython",name)
#obj.Label = translate("Path",name)
obj=self
ObjectProfile(obj)
if FreeCAD.GuiUp:
_ViewProviderProfile(obj.ViewObject)
locations = []
angles = []
lengths = []
heights = []
obj.locs = locations
obj.angles = angles
obj.lengths = lengths
obj.heights = heights
FreeCAD.ActiveDocument.recompute()
return obj
class ObjectProfile:
def __init__(self,obj):
obj.addProperty("App::PropertyLinkSub","Base","Path","The base geometry of this toolpath")
obj.addProperty("App::PropertyLinkSub","Face1","Path","First Selected Face to help determine where final depth of tool path is")
obj.addProperty("App::PropertyLinkSub","Face2","Path","Second Selected Face to help determine where the upper level of tool path is")
obj.addProperty("App::PropertyBool","PathClosed","Path","If the toolpath is a closed polyline this is True")
obj.addProperty("App::PropertyLinkSub","Edge1","Path","First Selected Edge to help determine which geometry to make a toolpath around")
obj.addProperty("App::PropertyLinkSub","Edge2","Path","Second Selected Edge to help determine which geometry to make a toolpath around")
obj.addProperty("App::PropertyBool","Active","Path","Make False, to prevent operation from generating code")
obj.addProperty("App::PropertyBool","UsePlacements","Path","make True, if using the profile operation placement properties to transform toolpath in post processor")
obj.addProperty("App::PropertyLinkSub","Base","Path",translate("Parent Object","The base geometry of this toolpath"))
obj.addProperty("App::PropertyBool","Active","Path",translate("Path","Make False, to prevent operation from generating code"))
obj.addProperty("App::PropertyString","Comment","Path",translate("Path","An optional comment for this profile"))
obj.addProperty("App::PropertyIntegerConstraint","ToolNumber","Tool","The tool number in use")
obj.addProperty("App::PropertyEnumeration", "Algorithm", "Algorithm",translate("Path", "The library or algorithm used to generate the path"))
obj.Algorithm = ['OCC Native','libarea']
obj.addProperty("App::PropertyIntegerConstraint","ToolNumber","Tool",translate("Path","The tool number in use"))
obj.ToolNumber = (0,0,1000,1)
obj.setEditorMode('ToolNumber',1) #make this read only
#Depth Properties
obj.addProperty("App::PropertyDistance", "ClearanceHeight", "Depth","The height needed to clear clamps and obstructions")
obj.addProperty("App::PropertyLength", "StepDown", "Depth", "Incremental Step Down of Tool")
obj.addProperty("App::PropertyBool","UseStartDepth","Depth","make True, if manually specifying a Start Start Depth")
obj.addProperty("App::PropertyDistance", "StartDepth", "Depth", "Starting Depth of Tool- first cut depth in Z")
obj.addProperty("App::PropertyDistance", "FinalDepth", "Depth", "Final Depth of Tool- lowest value in Z")
obj.addProperty("App::PropertyDistance", "RetractHeight", "Depth","The height desired to retract tool when path is finished")
obj.addProperty("App::PropertyString","Comment","Path","An optional comment for this profile")
obj.addProperty("App::PropertyDistance", "ClearanceHeight", "Depth", translate("Path","The height needed to clear clamps and obstructions"))
obj.addProperty("App::PropertyDistance", "SafeHeight", "Depth", translate("Path","Rapid Safety Height between locations."))
obj.addProperty("App::PropertyFloatConstraint", "StepDown", "Depth", translate("Path","Incremental Step Down of Tool"))
obj.StepDown = (1,0.01,1000,0.5)
obj.addProperty("App::PropertyDistance", "StartDepth", "Depth", translate("Path","Starting Depth of Tool- first cut depth in Z"))
obj.addProperty("App::PropertyDistance", "FinalDepth", "Depth", translate("Path","Final Depth of Tool- lowest value in Z"))
#obj.addProperty("App::PropertyDistance", "RetractHeight", "Depth", translate("Retract Height","The height desired to retract tool when path is finished"))
#Feed Properties
obj.addProperty("App::PropertySpeed", "VertFeed", "Feed","Feed rate for vertical moves in Z")
obj.addProperty("App::PropertySpeed", "HorizFeed", "Feed","Feed rate for horizontal moves")
obj.addProperty("App::PropertySpeed", "VertFeed", "Feed",translate("Path","Feed rate for vertical moves in Z"))
obj.addProperty("App::PropertySpeed", "HorizFeed", "Feed",translate("Path","Feed rate for horizontal moves"))
#Start Point Properties
obj.addProperty("App::PropertyVector","StartPoint","Start Point","The start point of this path")
obj.addProperty("App::PropertyBool","UseStartPoint","Start Point","make True, if specifying a Start Point")
obj.addProperty("App::PropertyLength", "ExtendAtStart", "Start Point","extra length of tool path before start of part edge")
obj.addProperty("App::PropertyLength", "LeadInLineLen", "Start Point","length of straight segment of toolpath that comes in at angle to first part edge")
obj.addProperty("App::PropertyVector","StartPoint","Start Point",translate("Path_Profile","The start point of this path"))
obj.addProperty("App::PropertyBool","UseStartPoint","Start Point",translate("Path_Profile","make True, if specifying a Start Point"))
obj.addProperty("App::PropertyLength", "ExtendAtStart", "Start Point", translate("Path_Profile", "extra length of tool path before start of part edge"))
obj.addProperty("App::PropertyLength", "LeadInLineLen", "Start Point", translate("Path_Profile","length of straight segment of toolpath that comes in at angle to first part edge"))
#End Point Properties
obj.addProperty("App::PropertyBool","UseEndPoint","End Point","make True, if specifying an End Point")
obj.addProperty("App::PropertyLength", "ExtendAtEnd", "End Point","extra length of tool path after end of part edge")
obj.addProperty("App::PropertyLength", "LeadOutLineLen", "End Point","length of straight segment of toolpath that comes in at angle to last part edge")
obj.addProperty("App::PropertyVector","EndPoint","End Point","The end point of this path")
obj.addProperty("App::PropertyBool","UseEndPoint","End Point",translate("Path_Profile","make True, if specifying an End Point"))
obj.addProperty("App::PropertyLength", "ExtendAtEnd", "End Point", translate("Path_Profile","extra length of tool path after end of part edge"))
obj.addProperty("App::PropertyLength", "LeadOutLineLen", "End Point", translate("Path_Profile","length of straight segment of toolpath that comes in at angle to last part edge"))
obj.addProperty("App::PropertyVector","EndPoint","End Point",translate("Path_Profile","The end point of this path"))
#Profile Properties
obj.addProperty("App::PropertyEnumeration", "Side", "Profile","Side of edge that tool should cut")
obj.addProperty("App::PropertyEnumeration", "Side", "Profile", translate("Path_Profile","Side of edge that tool should cut"))
obj.Side = ['Left','Right','On'] #side of profile that cutter is on in relation to direction of profile
obj.addProperty("App::PropertyEnumeration", "Direction", "Profile","The direction that the toolpath should go around the part ClockWise CW or CounterClockWise CCW")
obj.addProperty("App::PropertyEnumeration", "Direction", "Profile",translate("Path_Profile", "The direction that the toolpath should go around the part ClockWise CW or CounterClockWise CCW"))
obj.Direction = ['CW','CCW'] #this is the direction that the profile runs
obj.addProperty("App::PropertyBool","UseComp","Profile",translate("Path_Profile","make True, if using Cutter Radius Compensation"))
obj.addProperty("App::PropertyDistance", "RollRadius", "Profile","Radius at start and end")
obj.addProperty("App::PropertyDistance", "OffsetExtra", "Profile","Extra value to stay away from final profile- good for roughing toolpath")
obj.addProperty("App::PropertyLength", "SegLen", "Profile","Tesselation value for tool paths made from beziers, bsplines, and ellipses")
obj.addProperty("App::PropertyDistance", "RollRadius", "Profile", translate("Path_Profile","Radius at start and end"))
obj.addProperty("App::PropertyDistance", "OffsetExtra", "Profile",translate("Path_Profile","Extra value to stay away from final profile- good for roughing toolpath"))
obj.addProperty("App::PropertyLength", "SegLen", "Profile",translate("Path_Profile","Tesselation value for tool paths made from beziers, bsplines, and ellipses"))
obj.addProperty("App::PropertyVectorList", "locs", "Tags", translate("Path_Profile", "List of holding tag locations"))
obj.addProperty("App::PropertyFloatList","angles","Tags", translate("Path_Profile", "List of angles for the holding tags"))
obj.addProperty("App::PropertyFloatList","heights","Tags", translate("Path_Profile", "List of angles for the holding tags"))
obj.addProperty("App::PropertyFloatList","lengths","Tags", translate("Path_Profile", "List of angles for the holding tags"))
obj.Proxy = self
@@ -101,68 +138,125 @@ class ObjectProfile:
return None
def execute(self,obj):
import Part, DraftGeomUtils, math
import PathScripts.PathKurveUtils as PathKurveUtils
from PathScripts.PathUtils import depth_params
if obj.Base:
# tie the toolnumber to the PathLoadTool object ToolNumber
if len(obj.InList)>0: #check to see if obj is in the Project group yet
project = obj.InList[0]
tl = int(PathUtils.changeTool(obj,project))
obj.ToolNumber= tl
tool = PathUtils.getTool(obj,obj.ToolNumber)
if tool:
radius = tool.Diameter/2
else:
# temporary value, to be taken from the properties later on
radius = 0.001
if obj.Base[0].Shape.ShapeType == "Wire": #a pure wire was picked
wire = obj.Base[0].Shape
else: #we are dealing with a face and it's edges or just a face
if obj.Edge1:
e1 = FreeCAD.ActiveDocument.getObject(obj.Base[0].Name).Shape.Edges[eval(obj.Edge1[1][0].lstrip('Edge'))-1]
if e1.BoundBox.ZMax <> e1.BoundBox.ZMin:
FreeCAD.Console.PrintError('vertical edges not valid yet\n')
return
if obj.Base[0].Shape.ShapeType =='Wire':
wire = obj.Base[0].Shape
if obj.Base[0].Shape.ShapeType =='Solid' or obj.Base[0].Shape.ShapeType =='Compound':
shape = obj.Base[0].Shape
for fw in shape.Wires:
if (fw.BoundBox.ZMax == e1.BoundBox.ZMax) and (fw.BoundBox.ZMin == e1.BoundBox.ZMin):
for e in fw.Edges:
if e.isSame(e1):
#FreeCAD.Console.PrintMessage('found the same objects\n')
wire = fw
elif obj.Face1: # we are only dealing with a face or faces
f1 = FreeCAD.ActiveDocument.getObject(obj.Base[0].Name).Shape.Faces[eval(obj.Face1[1][0].lstrip('Face'))-1]
# make the side Left and direction CW for normal cnc milling
obj.Direction = 'CW'
obj.Side = "Left"
# we only consider the outer wire if this is a single Face
wire = f1.OuterWire
# temporary value,in case we don't have any tools defined already
radius = 0.25
depthparams = depth_params (obj.ClearanceHeight.Value, obj.SafeHeight.Value, obj.StartDepth.Value, obj.StepDown, 0.0, obj.FinalDepth.Value, None)
clearance = obj.ClearanceHeight.Value
step_down=obj.StepDown
start_depth=obj.StartDepth.Value
final_depth=obj.FinalDepth.Value
rapid_safety_space=obj.SafeHeight.Value
side=obj.Side
offset_extra=obj.OffsetExtra.Value
use_CRC=obj.UseComp
vf=obj.VertFeed.Value
hf=obj.HorizFeed.Value
seglen=obj.SegLen.Value
direction = obj.Direction
# we only consider the outer wire if this is a Face
shape = getattr(obj.Base[0].Shape,obj.Base[1][0])
if shape.ShapeType in ["Edge"]:
edges = [getattr(obj.Base[0].Shape,sub) for sub in obj.Base[1]]
wire = Part.Wire(edges)
if not wire.Edges[0].isSame(shape):
wire.Edges.reverse()
if obj.Direction == 'CCW':
clockwise=False
else:
clockwise=True
output =""
output += '('+ str(obj.Comment)+')\n'
wire = shape.OuterWire
FirstEdge= None
if obj.Edge1:
ename = obj.Edge1[1][0]
edgeNumber = int(ename[4:])-1
FirstEdge = obj.Base[0].Shape.Edges[edgeNumber]
ZMax = obj.Base[0].Shape.BoundBox.ZMax
edgelist = wire.Edges
#edgelist = Part.__sortEdges__(wire.Edges)
ZCurrent = obj.ClearanceHeight.Value
if obj.UseStartDepth:
output += PathUtils.MakePath(wire,obj.Side,radius,clockwise,obj.ClearanceHeight.Value,obj.StepDown.Value,obj.StartDepth.Value, obj.FinalDepth.Value,FirstEdge,obj.PathClosed,obj.SegLen.Value,obj.VertFeed.Value,obj.HorizFeed.Value)
if obj.StartPoint and obj.UseStartPoint:
startpoint = obj.StartPoint
else:
output += PathUtils.MakePath(wire,obj.Side,radius,clockwise,obj.ClearanceHeight.Value,obj.StepDown.Value,ZMax, obj.FinalDepth.Value,FirstEdge,obj.PathClosed,obj.SegLen.Value,obj.VertFeed.Value,obj.HorizFeed.Value)
startpoint = None
if obj.EndPoint and obj.UseEndPoint:
endpoint = obj.EndPoint
else:
endpoint = None
edgelist = Part.__sortEdges__(edgelist)
if obj.Algorithm == "OCC Native":
output = ""
output += '('+ str(obj.Comment)+')\n'
if obj.Direction == 'CCW':
clockwise=False
else:
clockwise=True
FirstEdge= None
PathClosed = DraftGeomUtils.isReallyClosed(wire)
output += PathUtils.MakePath(wire, side, radius, clockwise, clearance, step_down, start_depth, final_depth, FirstEdge, PathClosed, seglen, vf, hf)
else:
try:
import area
except:
FreeCAD.Console.PrintError(translate("Path","libarea needs to be installed for this command to work.\n"))
return
PathKurveUtils.output('mem')
output = ""
curve = PathKurveUtils.makeAreaCurve(edgelist,direction,startpoint, endpoint)
'''The following line uses a profile function written for use with FreeCAD. It's clean but incomplete. It doesn't handle
holding tags
start location
CRC
or probably other features in heekscnc'''
#output += PathKurveUtils.profile(curve, side, radius, vf, hf, offset_extra, rapid_safety_space, clearance, start_depth, step_down, final_depth, use_CRC)
'''The following calls the original procedure from heekscnc profile function. This, in turn, calls many other procedures to modify the profile.
This procedure is hacked together from heekscnc and has not been thoroughly reviewed or understood for FreeCAD. It can probably be
thoroughly optimized and improved but it'll take a smarter mind than mine to do it. -sliptonic Feb16'''
roll_radius = 2.0
extend_at_start = 0.0
extend_at_end = 0.0
lead_in_line_len=0.0
lead_out_line_len= 0.0
'''
Right here, I need to know the Holding Tags group from the tree that refers to this profile operation and build up the tags for PathKurve Utils.
I need to access the location vector, length, angle in radians and height.
'''
PathKurveUtils.clear_tags()
for i in range(len(obj.locs)):
tag = obj.locs[i]
h = obj.heights[i]
l = obj.lengths[i]
a = math.radians(obj.angles[i])
PathKurveUtils.add_tag(area.Point(tag.x,tag.y), l, a, h)
PathKurveUtils.profile2(curve, side, radius, vf, hf, offset_extra, roll_radius, None,None, depthparams, extend_at_start, extend_at_end, lead_in_line_len,lead_out_line_len)
output += PathKurveUtils.retrieve_gcode()
if obj.Active:
path = Path.Path(output)
@@ -175,19 +269,141 @@ class ObjectProfile:
obj.ViewObject.Visibility = False
# class ViewProviderProfile:
# def __init__(self,vobj):
# vobj.Proxy = self
# def attach(self,vobj):
# self.Object = vobj.Object
# return
# def getIcon(self):
# return ":/icons/Path-Profile.svg"
# def __getstate__(self):
# return None
# def __setstate__(self,state):
# return None
class ViewProviderProfile:
class CommandPathProfile:
def GetResources(self):
return {'Pixmap' : 'Path-Profile',
'MenuText': QtCore.QT_TRANSLATE_NOOP("PathProfile","Profile"),
'Accel': "P, P",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathProfile","Creates a Path Profile object from selected faces")}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
def Activated(self):
import Path
from PathScripts import PathProject, PathUtils, PathKurve, PathKurveUtils
# check that the selection contains exactly what we want
selection = FreeCADGui.Selection.getSelectionEx()
if len(selection) != 1:
FreeCAD.Console.PrintError(translate("Path","Select one or more edges or a face from one Document object.\n"))
return
if len(selection[0].SubObjects) == 0:
FreeCAD.Console.PrintError(translate("Path","Select one or more edges or a face from one Document object.\n"))
return
for s in selection[0].SubObjects:
if s.ShapeType != "Edge":
if (s.ShapeType != "Face") or (len(selection[0].SubObjects) != 1):
FreeCAD.Console.PrintError(translate("Path","Please select only edges or a single face\n"))
return
if selection[0].SubObjects[0].ShapeType == "Edge":
try:
import Part
w = Part.Wire(selection[0].SubObjects)
except:
FreeCAD.Console.PrintError(translate("Path","The selected edges don't form a loop\n"))
return
# if everything is ok, execute and register the transaction in the undo/redo stack
# Take a guess at some reasonable values for Finish depth.
bb = selection[0].Object.Shape.BoundBox #parent boundbox
fbb = selection[0].SubObjects[0].BoundBox #feature boundbox
if fbb.ZMax < bb.ZMax:
zbottom = fbb.ZMax
else:
zbottom = bb.ZMin
FreeCAD.ActiveDocument.openTransaction(translate("Path","Create a Profile operation using libarea"))
FreeCADGui.addModule("PathScripts.PathProfile")
FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Profile")')
FreeCADGui.doCommand('PathScripts.PathProfile.makeProfile(obj)')
#FreeCADGui.doCommand('PathScripts.PathProfile.ObjectProfile(obj)')
FreeCADGui.doCommand('obj.Active = True')
subs ="["
for s in selection[0].SubElementNames:
subs += '"' + s + '",'
subs += "]"
FreeCADGui.doCommand('obj.Base = (FreeCAD.ActiveDocument.' + selection[0].ObjectName + ',' + subs + ')')
#FreeCADGui.doCommand('obj.ViewObject.Proxy = 0')
FreeCADGui.doCommand('obj.ClearanceHeight = ' + str(bb.ZMax + 10.0))
FreeCADGui.doCommand('obj.StepDown = 1.0')
FreeCADGui.doCommand('obj.StartDepth= ' + str(bb.ZMax))
FreeCADGui.doCommand('obj.FinalDepth=' + str(zbottom))
FreeCADGui.doCommand('obj.SafeHeight = '+ str(bb.ZMax + 2.0))
FreeCADGui.doCommand('obj.Side = "Left"')
FreeCADGui.doCommand('obj.OffsetExtra = 0.0')
FreeCADGui.doCommand('obj.Direction = "CW"')
FreeCADGui.doCommand('obj.UseComp = False')
FreeCADGui.doCommand('PathScripts.PathUtils.addToProject(obj)')
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
class _ViewProviderProfile:
"A View Provider for the Holding object"
def __init__(self,vobj):
vobj.Proxy = self
def attach(self,vobj):
self.Object = vobj.Object
return
def getIcon(self):
return ":/icons/Path-Profile.svg"
def claimChildren(self):
return []
def attach(self, vobj):
return
def getDisplayModes(self,vobj):
return ["Default"]
def getDefaultDisplayMode(self):
return "Default"
def setDisplayMode(self,mode):
return mode
def updateData(self,obj,prop):
return
def onChanged(self, vobj, prop):
return
def setEdit(self,vobj,mode=0):
FreeCADGui.Control.closeDialog()
taskd = _EditPanel()
taskd.obj = vobj.Object
taskd.update()
FreeCADGui.Control.showDialog(taskd)
return True
def unsetEdit(self,vobj,mode):
FreeCADGui.Control.closeDialog()
return
def doubleClicked(self,vobj):
self.setEdit(vobj)
def __getstate__(self):
return None
@@ -195,88 +411,160 @@ class ViewProviderProfile:
def __setstate__(self,state):
return None
class _EditPanel:
'''The editmode TaskPanel for profile tags'''
def __init__(self):
# the panel has a tree widget that contains categories
# for the subcomponents, such as additions, subtractions.
# the categories are shown only if they are not empty.
class CommandPathProfile:
def GetResources(self):
return {'Pixmap' : 'Path-Profile',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_Profile","Profile"),
'Accel': "P, P",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_Profile","Creates a Path Profile object from selected faces")}
self.updating = False
def IsActive(self):
return not FreeCAD.ActiveDocument is None
self.obj = None
self.form = QtGui.QWidget()
self.form.setObjectName("TaskPanel")
self.grid = QtGui.QGridLayout(self.form)
self.grid.setObjectName("grid")
self.title = QtGui.QLabel(self.form)
self.grid.addWidget(self.title, 0, 0, 1, 2)
# tree
self.tree = QtGui.QTreeWidget(self.form)
self.grid.addWidget(self.tree, 1, 0, 1, 2)
self.tree.setColumnCount(4)
self.tree.header().resizeSection(0,50)
self.tree.header().resizeSection(1,80)
self.tree.header().resizeSection(2,60)
self.tree.header().resizeSection(3,60)
# buttons
self.addButton = QtGui.QPushButton(self.form)
self.addButton.setObjectName("addButton")
self.addButton.setIcon(QtGui.QIcon(":/icons/Arch_Add.svg"))
self.grid.addWidget(self.addButton, 3, 0, 1, 1)
self.addButton.setEnabled(True)
self.delButton = QtGui.QPushButton(self.form)
self.delButton.setObjectName("delButton")
self.delButton.setIcon(QtGui.QIcon(":/icons/Arch_Remove.svg"))
self.grid.addWidget(self.delButton, 3, 1, 1, 1)
self.delButton.setEnabled(True)
QtCore.QObject.connect(self.addButton, QtCore.SIGNAL("clicked()"), self.addElement)
QtCore.QObject.connect(self.delButton, QtCore.SIGNAL("clicked()"), self.removeElement)
QtCore.QObject.connect(self.tree, QtCore.SIGNAL("itemChanged(QTreeWidgetItem *, int)"), self.edit)
self.update()
self.retranslateUi(self.form)
def isAllowedAlterSelection(self):
return False
def isAllowedAlterView(self):
return True
def getStandardButtons(self):
return int(QtGui.QDialogButtonBox.Close)
def update(self):
'fills the treewidget'
self.updating = True
self.tree.clear()
if self.obj:
for i in range(len(self.obj.locs)):
item = QtGui.QTreeWidgetItem(self.tree)
item.setText(0,str(i+1))
l = self.obj.locs[i]
item.setText(1,str(l.x)+", " + str(l.y) +", " + str(l.z))
item.setText(2,str(self.obj.heights[i]))
item.setText(3,str(self.obj.lengths[i]))
item.setText(4,str(self.obj.angles[i]))
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
item.setTextAlignment(0,QtCore.Qt.AlignLeft)
self.retranslateUi(self.form)
self.updating = False
return
def addElement(self):
self.updating = True
item = QtGui.QTreeWidgetItem(self.tree)
item.setText(0,str(self.tree.topLevelItemCount()))
item.setText(1,"0.0, 0.0, 0.0")
item.setText(2, str(float(4.0)))
item.setText(3, str(float(10.0)))
item.setText(4, str(float(45.0)))
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
self.updating = False
self.resetObject()
def removeElement(self):
it = self.tree.currentItem()
if it:
nr = int(it.text(0))-1
self.resetObject(remove=nr)
self.update()
def edit(self,item,column):
if not self.updating:
self.resetObject()
def resetObject(self,remove=None):
"transfers the values from the widget to the object"
loc = []
h = []
l = []
a = []
def Activated(self):
import Path
from PathScripts import PathUtils,PathProfile,PathProject
prjexists = False
selection = PathSelection.multiSelect()
for i in range(self.tree.topLevelItemCount()):
it = self.tree.findItems(str(i+1),QtCore.Qt.MatchExactly,0)[0]
if (remove == None) or (remove != i):
if it.text(1):
x = float(it.text(1).split()[0].rstrip(","))
y = float(it.text(1).split()[1].rstrip(","))
z = float(it.text(1).split()[2].rstrip(","))
loc.append(Vector(x,y,z))
if not selection:
return
else:
loc.append(0.0)
if it.text(2):
h.append(float(it.text(2)))
else:
h.append(4.0)
if it.text(3):
l.append(float(it.text(3)))
else:
l.append(5.0)
if it.text(4):
a.append(float(it.text(4)))
else:
a.append(45.0)
# if everything is ok, execute and register the transaction in the undo/redo stack
FreeCAD.ActiveDocument.openTransaction(translate("Path_Profile","Create Profile"))
FreeCADGui.addModule("PathScripts.PathProfile")
self.obj.locs = loc
self.obj.heights = h
self.obj.lengths = l
self.obj.angles = a
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Profile")
PathProfile.ObjectProfile(obj)
PathProfile.ViewProviderProfile(obj.ViewObject)
obj.Base = (FreeCAD.ActiveDocument.getObject(selection['objname']))
if selection['facenames']:
#FreeCAD.Console.PrintMessage('There are edges selected\n')
obj.Face1 = (FreeCAD.ActiveDocument.getObject(selection['objname']),selection['facenames'][0])
if len(selection['facenames'])>1:
obj.Face2 = (FreeCAD.ActiveDocument.getObject(selection['objname']),selection['facenames'][-1])
if selection['edgenames']:
#FreeCAD.Console.PrintMessage('There are edges selected\n')
obj.Edge1 =(FreeCAD.ActiveDocument.getObject(selection['objname']),(selection['edgenames'][0]))
if len(selection['edgenames'])>1:
obj.Edge2 =(FreeCAD.ActiveDocument.getObject(selection['objname']),(selection['edgenames'][-1]))
if selection['pointlist']:
FreeCADGui.doCommand('from FreeCAD import Vector')
stptX, stptY, stptZ = selection['pointlist'][0].X, selection['pointlist'][0].Y, selection['pointlist'][0].Z
obj.StartPoint = Vector((stptX),(stptY),(stptZ))
if len(selection['pointlist'])>1: # we have more than one point so we have an end point
endptX, endptY, endptZ = selection['pointlist'][-1].X, selection['pointlist'][-1].Y, selection['pointlist'][-1].Z
obj.EndPoint = Vector(endptX,endptY,endptZ)
if selection['pathwire'].isClosed():
obj.PathClosed = True
if selection['clockwise']:
obj.Side = "Left"
obj.Direction = "CW"
elif selection['clockwise'] == False:
obj.Side = "Right"
obj.Direction = "CCW"
else:
obj.Side = "On"
obj.Direction = "CCW"
obj.PathClosed = False
ZMax = obj.Base[0].Shape.BoundBox.ZMax
ZMin = obj.Base[0].Shape.BoundBox.ZMin
obj.StepDown.Value = 1.0
obj.StartDepth.Value = ZMax- obj.StepDown.Value
obj.FinalDepth.Value = ZMin-1.0
obj.ClearanceHeight.Value = ZMax + 5.0
obj.SegLen.Value = 0.5
obj.Active = True
obj.ViewObject.ShowFirstRapid = False
project = PathUtils.addToProject(obj)
tl = PathUtils.changeTool(obj,project)
if tl:
obj.ToolNumber = tl
FreeCAD.ActiveDocument.commitTransaction()
self.obj.touch()
FreeCAD.ActiveDocument.recompute()
def reject(self):
FreeCAD.ActiveDocument.recompute()
FreeCADGui.ActiveDocument.resetEdit()
return True
def retranslateUi(self, TaskPanel=None):
TaskPanel.setWindowTitle(QtGui.QApplication.translate("Path", "Holding Tags", None, QtGui.QApplication.UnicodeUTF8))
self.delButton.setText(QtGui.QApplication.translate("Path", "Remove", None, QtGui.QApplication.UnicodeUTF8))
self.addButton.setText(QtGui.QApplication.translate("Path", "Add", None, QtGui.QApplication.UnicodeUTF8))
self.title.setText(QtGui.QApplication.translate("Path", "Tag Locations and Properties", None, QtGui.QApplication.UnicodeUTF8))
self.tree.setHeaderLabels([QtGui.QApplication.translate("Path", "", None, QtGui.QApplication.UnicodeUTF8),
QtGui.QApplication.translate("Path", "Location", None, QtGui.QApplication.UnicodeUTF8),
QtGui.QApplication.translate("Path", "Height", None, QtGui.QApplication.UnicodeUTF8),
QtGui.QApplication.translate("Path", "Length", None, QtGui.QApplication.UnicodeUTF8),
QtGui.QApplication.translate("Path", "Angle", None, QtGui.QApplication.UnicodeUTF8)])
if FreeCAD.GuiUp:
# register the FreeCAD command
FreeCADGui.addCommand('Path_Profile',CommandPathProfile())