当前位置: 首页>>代码示例>>Python>>正文


Python PathScripts.PathUtil类代码示例

本文整理汇总了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)
开发者ID:DevJohan,项目名称:FreeCAD_sf_master,代码行数:33,代码来源:PathToolLibraryManager.py

示例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))
开发者ID:itain,项目名称:FreeCAD,代码行数:7,代码来源:TestPathUtil.py

示例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))
开发者ID:itain,项目名称:FreeCAD,代码行数:7,代码来源:TestPathUtil.py

示例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))
开发者ID:itain,项目名称:FreeCAD,代码行数:16,代码来源:TestPathUtil.py

示例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)
开发者ID:DevJohan,项目名称:FreeCAD_sf_master,代码行数:29,代码来源:PathToolLibraryManager.py

示例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
开发者ID:DevJohan,项目名称:FreeCAD_sf_master,代码行数:35,代码来源:PathToolLibraryManager.py

示例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
开发者ID:DevJohan,项目名称:FreeCAD_sf_master,代码行数:16,代码来源:PathSetupSheet.py

示例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)
开发者ID:pgilfernandez,项目名称:FreeCAD,代码行数:8,代码来源:PathJobGui.py

示例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
开发者ID:DevJohan,项目名称:FreeCAD_sf_master,代码行数:9,代码来源:PathToolLibraryManager.py

示例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))
开发者ID:DevJohan,项目名称:FreeCAD_sf_master,代码行数:9,代码来源:PathSetupSheet.py

示例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)
开发者ID:DevJohan,项目名称:FreeCAD_sf_master,代码行数:11,代码来源:PathIconViewProvider.py

示例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
开发者ID:DevJohan,项目名称:FreeCAD_sf_master,代码行数:12,代码来源:PathSetupSheetGui.py

示例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
开发者ID:AjinkyaDahale,项目名称:FreeCAD,代码行数:38,代码来源:PathJob.py

示例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))
开发者ID:itain,项目名称:FreeCAD,代码行数:16,代码来源:TestPathUtil.py

示例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
开发者ID:peterl94,项目名称:FreeCAD_sf_master,代码行数:16,代码来源:PathOp.py


注:本文中的PathScripts.PathUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。