本文整理汇总了Python中PathScripts.PathUtil类的典型用法代码示例。如果您正苦于以下问题:Python PathUtil类的具体用法?Python PathUtil怎么用?Python PathUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PathUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
def read(self, filename, listname):
"imports a tooltable from a file"
try:
fileExtension = os.path.splitext(filename[0])[1].lower()
xmlHandler = None
if fileExtension == '.tooltable':
xmlHandler = HeeksTooltableHandler()
if fileExtension == '.xml':
xmlHandler = FreeCADTooltableHandler()
if xmlHandler:
parser = xml.sax.make_parser()
parser.setFeature(xml.sax.handler.feature_namespaces, 0)
parser.setContentHandler(xmlHandler)
parser.parse(PathUtil.toUnicode(filename[0]))
if not xmlHandler.tooltable:
return None
ht = xmlHandler.tooltable
else:
with open(PathUtil.toUnicode(filename[0]), "rb") as fp:
ht = self.tooltableFromAttrs(json.load(fp))
tt = self._findList(listname)
for t in ht.Tools:
newt = ht.getTool(t).copy()
tt.addTools(newt)
if listname == "<Main>":
self.saveMainLibrary(tt)
return True
except Exception as e:
print("could not parse file", e)
示例2: test00
def test00(self):
'''Check that isValidBaseObject detects solids.'''
box = self.doc.addObject('Part::Box', 'Box')
cylinder = self.doc.addObject('Part::Cylinder', 'Cylinder')
self.doc.recompute()
self.assertTrue(PathUtil.isValidBaseObject(box))
self.assertTrue(PathUtil.isValidBaseObject(cylinder))
示例3: test01
def test01(self):
'''Check that isValidBaseObject detects PDs.'''
body = self.doc.addObject('PartDesign::Body', 'Body')
box = self.doc.addObject('PartDesign::AdditiveBox', 'Box')
body.addObject(box)
self.doc.recompute()
self.assertTrue(PathUtil.isValidBaseObject(body))
示例4: test03
def test03(self):
'''Check that isValidBaseObject ignores sketches.'''
body = self.doc.addObject('PartDesign::Body', 'Body')
sketch = self.doc.addObject('Sketcher::SketchObject', 'Sketch')
body.addObject(sketch)
TestSketcherApp.CreateSlotPlateSet(sketch)
self.doc.recompute()
pad = self.doc.addObject('PartDesign::Pad', 'Pad')
body.addObject(pad)
pad.Profile = sketch
self.doc.recompute()
# the body and the pad are solids
self.assertTrue(PathUtil.isValidBaseObject(pad))
self.assertTrue(PathUtil.isValidBaseObject(body))
# however, the sketch is no
self.assertFalse(PathUtil.isValidBaseObject(sketch))
示例5: write
def write(self, filename, listname):
"exports the tooltable to a file"
tt = self._findList(listname)
if tt:
try:
def openFileWithExtension(name, ext):
fext = os.path.splitext(name)[1].lower()
if fext != ext:
name = "{}{}".format(name, ext)
return (open(PathUtil.toUnicode(name), 'wb'), name)
if filename[1] == self.TooltableTypeXML:
fp,fname = openFileWithExtension(filename[0], '.xml')
fp.write('<?xml version="1.0" encoding="UTF-8"?>\n')
fp.write(tt.Content)
elif filename[1] == self.TooltableTypeLinuxCNC:
fp,fname = openFileWithExtension(filename[0], '.tbl')
for key in tt.Tools:
t = tt.Tools[key]
fp.write("T{} P{} Y{} Z{} A{} B{} C{} U{} V{} W{} D{} I{} J{} Q{} ;{}\n".format(key,key,0,t.LengthOffset,0,0,0,0,0,0,t.Diameter,0,0,0,t.Name))
else:
fp,fname = openFileWithExtension(filename[0], '.json')
json.dump(self.templateAttrs(tt), fp, sort_keys=True, indent=2)
fp.close()
print("Written ", PathUtil.toUnicode(fname))
except Exception as e:
print("Could not write file:", e)
示例6: getTools
def getTools(self, tablename):
'''returns the tool data for a given table'''
tooldata = []
tt = self._findList(tablename)
headers = ["","Tool Num.","Name","Tool Type","Material","Diameter","Length Offset","Flat Radius","Corner Radius","Cutting Edge Angle","Cutting Edge Height"]
model = QtGui.QStandardItemModel()
model.setHorizontalHeaderLabels(headers)
def unitconv(ivalue):
val = FreeCAD.Units.Quantity(ivalue, FreeCAD.Units.Length)
displayed_val = val.UserString #just the displayed value-not the internal one
return displayed_val
if tt:
if len(tt.Tools) == 0:
tooldata.append([])
for number, t in PathUtil.keyValueIter(tt.Tools):
itemcheck = QtGui.QStandardItem()
itemcheck.setCheckable(True)
itemNumber = QtGui.QStandardItem(str(number))
itemName = QtGui.QStandardItem(t.Name)
itemToolType = QtGui.QStandardItem(t.ToolType)
itemMaterial = QtGui.QStandardItem(t.Material)
itemDiameter = QtGui.QStandardItem(unitconv(t.Diameter))
itemLengthOffset = QtGui.QStandardItem(unitconv(t.LengthOffset))
itemFlatRadius = QtGui.QStandardItem(unitconv(t.FlatRadius))
itmCornerRadius = QtGui.QStandardItem(unitconv(t.CornerRadius))
itemCuttingEdgeAngle = QtGui.QStandardItem(str(t.CuttingEdgeAngle))
itemCuttingEdgeHeight = QtGui.QStandardItem(unitconv(t.CuttingEdgeHeight))
row = [itemcheck, itemNumber, itemName, itemToolType, itemMaterial, itemDiameter, itemLengthOffset, itemFlatRadius, itmCornerRadius, itemCuttingEdgeAngle, itemCuttingEdgeHeight]
model.appendRow(row)
return model
示例7: _traverseTemplateAttributes
def _traverseTemplateAttributes(attrs, codec):
coded = {}
for key,value in PathUtil.keyValueIter(attrs):
if type(value) == dict:
PathLog.debug("%s is a dict" % key)
coded[key] = _traverseTemplateAttributes(value, codec)
elif type(value) == list:
PathLog.debug("%s is a list" % key)
coded[key] = [_traverseTemplateAttributes(attr, codec) for attr in value]
elif PathUtil.isString(value):
PathLog.debug("%s is a string" % key)
coded[key] = codec(value)
else:
PathLog.debug("%s is %s" % (key, type(value)))
coded[key] = value
return coded
示例8: candidates
def candidates(self, obj):
solids = [o for o in obj.Document.Objects if PathUtil.isSolid(o)]
if obj.Base in solids and PathJob.isResourceClone(obj, 'Base'):
solids.remove(obj.Base)
if obj.Stock in solids:
# regardless, what stock is/was, it's not a valid choice
solids.remove(obj.Stock)
return sorted(solids, key=lambda c: c.Label)
示例9: tooltableFromAttrs
def tooltableFromAttrs(self, stringattrs):
if stringattrs.get('Version') and 1 == int(stringattrs['Version']):
attrs = {}
for key, val in PathUtil.keyValueIter(stringattrs['Tools']):
attrs[int(key)] = val
return Path.Tooltable(attrs)
else:
PathLog.error(translate('PathToolLibraryManager', "Unsupported Path tooltable template version %s") % stringattrs.get('Version'))
return None
示例10: operationsWithSettings
def operationsWithSettings(self):
'''operationsWithSettings() ... returns a list of operations which currently have some settings defined.'''
ops = []
for name,value in PathUtil.keyValueIter(_RegisteredOps):
for prop in value.registeredPropertyNames(name):
if hasattr(self.obj, prop):
ops.append(name)
break
return list(sorted(ops))
示例11: Attach
def Attach(vobj, name):
'''Attach(vobj, name) ... attach the appropriate view provider to the view object.
If no view provider was registered for the given name a default IconViewProvider is created.'''
PathLog.track(vobj.Object.Label, name)
global _factory
for key,value in PathUtil.keyValueIter(_factory):
if key == name:
return value(vobj, name)
PathLog.track(vobj.Object.Label, name, 'PathIconViewProvider')
return ViewProvider(vobj, name)
示例12: __init__
def __init__(self, obj, form):
self.form = form
self.obj = obj
self.ops = sorted([OpTaskPanel(self.obj, name, op) for name, op in PathUtil.keyValueIter(PathSetupSheet._RegisteredOps)], key = lambda op: op.name)
if form:
parent = form.tabOpDefaults
for op in self.ops:
form.opDefaultOp.addItem(op.form.windowTitle(), op)
op.form.setParent(parent)
parent.layout().addWidget(op.form)
op.form.hide()
self.currentOp = None
示例13: onDelete
def onDelete(self, obj, arg2=None):
'''Called by the view provider, there doesn't seem to be a callback on the obj itself.'''
PathLog.track(obj.Label, arg2)
doc = obj.Document
# the first to tear down are the ops, they depend on other resources
PathLog.debug('taking down ops: %s' % [o.Name for o in self.allOperations()])
while obj.Operations.Group:
op = obj.Operations.Group[0]
if not op.ViewObject or not hasattr(op.ViewObject.Proxy, 'onDelete') or op.ViewObject.Proxy.onDelete(op.ViewObject, ()):
PathUtil.clearExpressionEngine(op)
doc.removeObject(op.Name)
obj.Operations.Group = []
doc.removeObject(obj.Operations.Name)
obj.Operations = None
# stock could depend on Base
if obj.Stock:
PathLog.debug('taking down stock')
PathUtil.clearExpressionEngine(obj.Stock)
doc.removeObject(obj.Stock.Name)
obj.Stock = None
# base doesn't depend on anything inside job
if obj.Base:
PathLog.debug('taking down base')
if isResourceClone(obj, 'Base'):
PathUtil.clearExpressionEngine(obj.Base)
doc.removeObject(obj.Base.Name)
obj.Base = None
# Tool controllers don't depend on anything
PathLog.debug('taking down tool controller')
for tc in obj.ToolController:
PathUtil.clearExpressionEngine(tc)
doc.removeObject(tc.Name)
obj.ToolController = []
# SetupSheet
PathUtil.clearExpressionEngine(obj.SetupSheet)
doc.removeObject(obj.SetupSheet.Name)
obj.SetupSheet = None
return True
示例14: test02
def test02(self):
'''Check that isValidBaseObject detects compounds.'''
box = self.doc.addObject('Part::Box', 'Box')
box.Length = 10
box.Width = 10
box.Height = 1
box.Placement = FreeCAD.Placement(FreeCAD.Vector(-5,-5,0), FreeCAD.Rotation(FreeCAD.Vector(0,0,1), 0))
cyl = self.doc.addObject('Part::Cylinder', 'Cylinder')
cyl.Radius = 1
cyl.Height = 10
box.Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,-5), FreeCAD.Rotation(FreeCAD.Vector(0,0,1), 0))
cut = self.doc.addObject('Part::Cut', 'Cut')
cut.Base = box
cut.Tool = cyl
self.doc.recompute()
self.assertTrue(PathUtil.isValidBaseObject(cut))
示例15: addBase
def addBase(self, obj, base, sub):
PathLog.track()
base = PathUtil.getPublicObject(base)
if self._setBaseAndStock(obj):
if base == self.job.Proxy.baseObject(self.job):
base = self.baseobject
baselist = obj.Base
if baselist is None:
baselist = []
item = (base, sub)
if item in baselist:
PathLog.notice(translate("Path", "this object already in the list" + "\n"))
else:
baselist.append(item)
obj.Base = baselist