def test11(self): """Verify FromTemplate cylinder creation.""" radius = 7 height = 12 placement = FreeCAD.Placement( FreeCAD.Vector(99, 88, 77), FreeCAD.Vector(1, 1, 1), 123 ) orig = PathStock.CreateCylinder(self.job, radius, height, placement) # full template template = PathStock.TemplateAttributes(orig) stock = PathStock.CreateFromTemplate(self.job, template) self.assertEqual( PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock) ) self.assertEqual(orig.Radius, stock.Radius) self.assertEqual(orig.Height, stock.Height) self.assertPlacement(orig.Placement, stock.Placement) # no extent in template template = PathStock.TemplateAttributes(orig, False, True) stock = PathStock.CreateFromTemplate(self.job, template) self.assertEqual( PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock) ) self.assertRoughly(R, stock.Radius.Value) self.assertEqual(300, stock.Height) self.assertPlacement(orig.Placement, stock.Placement) # no placement template - and no base template = PathStock.TemplateAttributes(orig, True, False) stock = PathStock.CreateFromTemplate(None, template) self.assertEqual( PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock) ) self.assertEqual(orig.Radius, stock.Radius) self.assertEqual(orig.Height, stock.Height) self.assertPlacement(FreeCAD.Placement(), stock.Placement) # no placement template - but base template = PathStock.TemplateAttributes(orig, True, False) stock = PathStock.CreateFromTemplate(self.job, template) self.assertEqual( PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock) ) self.assertEqual(orig.Radius, stock.Radius) self.assertEqual(orig.Height, stock.Height) self.assertPlacement( FreeCAD.Placement(FreeCAD.Vector(50, 100, 0), FreeCAD.Rotation()), stock.Placement, )
def test12(self): '''Verify FromTemplate from Base creation.''' neg = FreeCAD.Vector(1, 2, 3) pos = FreeCAD.Vector(9, 8, 7) orig = PathStock.CreateFromBase(self.job, neg, pos) # Make sure we have a different base object for the creation self.base.Length = 11 self.base.Width = 12 self.base.Height = 13 # full template template = PathStock.TemplateAttributes(orig) stock = PathStock.CreateFromTemplate(self.job, template) self.assertEqual(PathStock.StockType.FromBase, PathStock.StockType.FromStock(stock)) self.assertEqual(orig.ExtXneg, stock.ExtXneg) self.assertEqual(orig.ExtXpos, stock.ExtXpos) self.assertEqual(orig.ExtYneg, stock.ExtYneg) self.assertEqual(orig.ExtYpos, stock.ExtYpos) self.assertEqual(orig.ExtZneg, stock.ExtZneg) self.assertEqual(orig.ExtZpos, stock.ExtZpos) bb = stock.Shape.BoundBox self.assertEqual(neg.x + pos.x + 11, bb.XLength) self.assertEqual(neg.y + pos.y + 12, bb.YLength) self.assertEqual(neg.z + pos.z + 13, bb.ZLength)
def assignTemplate(self, obj, template): '''assignTemplate(obj, template) ... extract the properties from the given template file and assign to receiver. This will also create any TCs stored in the template.''' tcs = [] if template: tree = xml.parse(template) for job in tree.getroot().iter(JobTemplate.Job): if job.get(JobTemplate.GeometryTolerance): obj.GeometryTolerance = float( job.get(JobTemplate.GeometryTolerance)) if job.get(JobTemplate.PostProcessor): obj.PostProcessor = job.get(JobTemplate.PostProcessor) if job.get(JobTemplate.PostProcessorArgs): obj.PostProcessorArgs = job.get( JobTemplate.PostProcessorArgs) else: obj.PostProcessorArgs = '' if job.get(JobTemplate.PostProcessorOutputFile): obj.PostProcessorOutputFile = job.get( JobTemplate.PostProcessorOutputFile) if job.get(JobTemplate.Description): obj.Description = job.get(JobTemplate.Description) for tc in tree.getroot().iter(JobTemplate.ToolController): tcs.append(PathToolController.FromTemplate(tc)) for stock in tree.getroot().iter(JobTemplate.Stock): obj.Stock = PathStock.CreateFromTemplate(self, stock) else: tcs.append(PathToolController.Create()) PathLog.debug("setting tool controllers (%d)" % len(tcs)) obj.ToolController = tcs
def setFromTemplateFile(self, obj, template): """setFromTemplateFile(obj, template) ... extract the properties from the given template file and assign to receiver. This will also create any TCs stored in the template.""" tcs = [] if template: with open(PathUtil.toUnicode(template), "rb") as fp: attrs = json.load(fp) if attrs.get(JobTemplate.Version) and 1 == int(attrs[JobTemplate.Version]): attrs = self.setupSheet.decodeTemplateAttributes(attrs) if attrs.get(JobTemplate.SetupSheet): self.setupSheet.setFromTemplate(attrs[JobTemplate.SetupSheet]) if attrs.get(JobTemplate.GeometryTolerance): obj.GeometryTolerance = float( attrs.get(JobTemplate.GeometryTolerance) ) if attrs.get(JobTemplate.PostProcessor): obj.PostProcessor = attrs.get(JobTemplate.PostProcessor) if attrs.get(JobTemplate.PostProcessorArgs): obj.PostProcessorArgs = attrs.get(JobTemplate.PostProcessorArgs) else: obj.PostProcessorArgs = "" if attrs.get(JobTemplate.PostProcessorOutputFile): obj.PostProcessorOutputFile = attrs.get( JobTemplate.PostProcessorOutputFile ) if attrs.get(JobTemplate.Description): obj.Description = attrs.get(JobTemplate.Description) if attrs.get(JobTemplate.ToolController): for tc in attrs.get(JobTemplate.ToolController): tcs.append(PathToolController.FromTemplate(tc)) if attrs.get(JobTemplate.Stock): obj.Stock = PathStock.CreateFromTemplate( obj, attrs.get(JobTemplate.Stock) ) if attrs.get(JobTemplate.Fixtures): obj.Fixtures = [ x for y in attrs.get(JobTemplate.Fixtures) for x in y ] if attrs.get(JobTemplate.OrderOutputBy): obj.OrderOutputBy = attrs.get(JobTemplate.OrderOutputBy) if attrs.get(JobTemplate.SplitOutput): obj.SplitOutput = attrs.get(JobTemplate.SplitOutput) PathLog.debug("setting tool controllers (%d)" % len(tcs)) obj.Tools.Group = tcs else: PathLog.error( "Unsupported PathJob template version {}".format( attrs.get(JobTemplate.Version) ) ) if not tcs: self.addToolController(PathToolController.Create())
def __init__(self, obj, models, templateFile = None): self.obj = obj obj.addProperty("App::PropertyFile", "PostProcessorOutputFile", "Output", QtCore.QT_TRANSLATE_NOOP("PathJob","The NC output file for this project")) obj.addProperty("App::PropertyEnumeration", "PostProcessor", "Output", QtCore.QT_TRANSLATE_NOOP("PathJob","Select the Post Processor")) obj.addProperty("App::PropertyString", "PostProcessorArgs", "Output", QtCore.QT_TRANSLATE_NOOP("PathJob", "Arguments for the Post Processor (specific to the script)")) obj.addProperty("App::PropertyString", "Description", "Path", QtCore.QT_TRANSLATE_NOOP("PathJob","An optional description for this job")) obj.addProperty("App::PropertyString", "CycleTime", "Path", QtCore.QT_TRANSLATE_NOOP("PathOp", "Operations Cycle Time Estimation")) obj.setEditorMode('CycleTime', 1) # read-only obj.addProperty("App::PropertyDistance", "GeometryTolerance", "Geometry", QtCore.QT_TRANSLATE_NOOP("PathJob", "For computing Paths; smaller increases accuracy, but slows down computation")) obj.addProperty("App::PropertyLink", "Stock", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "Solid object to be used as stock.")) obj.addProperty("App::PropertyLink", "Operations", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "Compound path of all operations in the order they are processed.")) obj.addProperty("App::PropertyLinkList", "ToolController", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "Collection of tool controllers available for this job.")) obj.addProperty("App::PropertyBool", "SplitOutput", "Output", QtCore.QT_TRANSLATE_NOOP("PathJob","Split output into multiple gcode files")) obj.addProperty("App::PropertyEnumeration", "OrderOutputBy", "WCS", QtCore.QT_TRANSLATE_NOOP("PathJob", "If multiple WCS, order the output this way")) obj.addProperty("App::PropertyStringList", "Fixtures", "WCS", QtCore.QT_TRANSLATE_NOOP("PathJob", "The Work Coordinate Systems for the Job")) obj.OrderOutputBy = ['Fixture', 'Tool', 'Operation'] obj.Fixtures = ['G54'] obj.PostProcessorOutputFile = PathPreferences.defaultOutputFile() #obj.setEditorMode("PostProcessorOutputFile", 0) # set to default mode obj.PostProcessor = postProcessors = PathPreferences.allEnabledPostProcessors() defaultPostProcessor = PathPreferences.defaultPostProcessor() # Check to see if default post processor hasn't been 'lost' (This can happen when Macro dir has changed) if defaultPostProcessor in postProcessors: obj.PostProcessor = defaultPostProcessor else: obj.PostProcessor = postProcessors[0] obj.PostProcessorArgs = PathPreferences.defaultPostProcessorArgs() obj.GeometryTolerance = PathPreferences.defaultGeometryTolerance() ops = FreeCAD.ActiveDocument.addObject("Path::FeatureCompoundPython", "Operations") if ops.ViewObject: ops.ViewObject.Proxy = 0 ops.ViewObject.Visibility = False obj.Operations = ops obj.setEditorMode('Operations', 2) # hide obj.setEditorMode('Placement', 2) self.setupSetupSheet(obj) self.setupBaseModel(obj, models) self.tooltip = None self.tooltipArgs = None obj.Proxy = self self.setFromTemplateFile(obj, templateFile) if not obj.Stock: stockTemplate = PathPreferences.defaultStockTemplate() if stockTemplate: obj.Stock = PathStock.CreateFromTemplate(obj, json.loads(stockTemplate)) if not obj.Stock: obj.Stock = PathStock.CreateFromBase(obj) if obj.Stock.ViewObject: obj.Stock.ViewObject.Visibility = False
def test10(self): """Verify FromTemplate box creation.""" extent = FreeCAD.Vector(17, 13, 77) placement = FreeCAD.Placement( FreeCAD.Vector(3, 8, -4), FreeCAD.Vector(0, 0, 1), -90 ) orig = PathStock.CreateBox(self.job, extent, placement) # collect full template template = PathStock.TemplateAttributes(orig) stock = PathStock.CreateFromTemplate(self.job, template) self.assertEqual( PathStock.StockType.CreateBox, PathStock.StockType.FromStock(stock) ) self.assertEqual(orig.Length, stock.Length) self.assertEqual(orig.Width, stock.Width) self.assertEqual(orig.Height, stock.Height) self.assertPlacement(orig.Placement, stock.Placement) # don't store extent in template template = PathStock.TemplateAttributes(orig, False, True) stock = PathStock.CreateFromTemplate(self.job, template) self.assertEqual( PathStock.StockType.CreateBox, PathStock.StockType.FromStock(stock) ) self.assertEqual(100, stock.Length) self.assertEqual(200, stock.Width) self.assertEqual(300, stock.Height) self.assertPlacement(orig.Placement, stock.Placement) # don't store placement in template template = PathStock.TemplateAttributes(orig, True, False) stock = PathStock.CreateFromTemplate(self.job, template) self.assertEqual( PathStock.StockType.CreateBox, PathStock.StockType.FromStock(stock) ) self.assertEqual(orig.Length, stock.Length) self.assertEqual(orig.Width, stock.Width) self.assertEqual(orig.Height, stock.Height) self.assertPlacement(FreeCAD.Placement(), stock.Placement)
def setupStock(self, obj): """setupStock(obj)... setup the Stock for the Job object.""" if not obj.Stock: stockTemplate = PathPreferences.defaultStockTemplate() if stockTemplate: obj.Stock = PathStock.CreateFromTemplate(obj, json.loads(stockTemplate)) if not obj.Stock: obj.Stock = PathStock.CreateFromBase(obj) if obj.Stock.ViewObject: obj.Stock.ViewObject.Visibility = False
def setFromTemplateFile(self, obj, template): '''setFromTemplateFile(obj, template) ... extract the properties from the given template file and assign to receiver. This will also create any TCs stored in the template.''' tcs = [] if template: with open(PathUtil.toUnicode(template), 'rb') as fp: attrs = json.load(fp) if attrs.get(JobTemplate.Version) and 1 == int( attrs[JobTemplate.Version]): attrs = self.setupSheet.decodeTemplateAttributes(attrs) if attrs.get(JobTemplate.SetupSheet): self.setupSheet.setFromTemplate( attrs[JobTemplate.SetupSheet]) if attrs.get(JobTemplate.GeometryTolerance): obj.GeometryTolerance = float( attrs.get(JobTemplate.GeometryTolerance)) if attrs.get(JobTemplate.PostProcessor): obj.PostProcessor = attrs.get(JobTemplate.PostProcessor) if attrs.get(JobTemplate.PostProcessorArgs): obj.PostProcessorArgs = attrs.get( JobTemplate.PostProcessorArgs) else: obj.PostProcessorArgs = '' if attrs.get(JobTemplate.PostProcessorOutputFile): obj.PostProcessorOutputFile = attrs.get( JobTemplate.PostProcessorOutputFile) if attrs.get(JobTemplate.Description): obj.Description = attrs.get(JobTemplate.Description) if attrs.get(JobTemplate.ToolController): for tc in attrs.get(JobTemplate.ToolController): tcs.append(PathToolController.FromTemplate(tc)) if attrs.get(JobTemplate.Stock): obj.Stock = PathStock.CreateFromTemplate( obj, attrs.get(JobTemplate.Stock)) PathLog.debug("setting tool controllers (%d)" % len(tcs)) obj.ToolController = tcs else: PathLog.error( translate('PathJob', "Unsupported PathJob template version %s") % attrs.get(JobTemplate.Version)) if not tcs: self.addToolController(PathToolController.Create())
def __init__(self, obj, base, templateFile = None): self.obj = obj obj.addProperty("App::PropertyFile", "PostProcessorOutputFile", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property","The NC output file for this project")) obj.addProperty("App::PropertyEnumeration", "PostProcessor", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property","Select the Post Processor")) obj.addProperty("App::PropertyString", "PostProcessorArgs", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property", "Arguments for the Post Processor (specific to the script)")) obj.addProperty("App::PropertyString", "Description", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property","An optional description for this job")) obj.addProperty("App::PropertyDistance", "GeometryTolerance", "Geometry", QtCore.QT_TRANSLATE_NOOP("App::Property", "For computing Paths; smaller increases accuracy, but slows down computation")) obj.addProperty("App::PropertyLink", "Base", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "The base object for all operations")) obj.addProperty("App::PropertyLink", "Stock", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "Solid object to be used as stock.")) obj.addProperty("App::PropertyLink", "Operations", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "Compound path of all operations in the order they are processed.")) obj.addProperty("App::PropertyLinkList", "ToolController", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "Collection of tool controllers available for this job.")) obj.PostProcessorOutputFile = PathPreferences.defaultOutputFile() #obj.setEditorMode("PostProcessorOutputFile", 0) # set to default mode obj.PostProcessor = postProcessors = PathPreferences.allEnabledPostProcessors() defaultPostProcessor = PathPreferences.defaultPostProcessor() # Check to see if default post processor hasn't been 'lost' (This can happen when Macro dir has changed) if defaultPostProcessor in postProcessors: obj.PostProcessor = defaultPostProcessor else: obj.PostProcessor = postProcessors[0] obj.PostProcessorArgs = PathPreferences.defaultPostProcessorArgs() obj.GeometryTolerance = PathPreferences.defaultGeometryTolerance() ops = FreeCAD.ActiveDocument.addObject("Path::FeatureCompoundPython", "Operations") obj.Operations = ops obj.setEditorMode('Operations', 2) # hide obj.setEditorMode('Placement', 2) self.setupSetupSheet(obj) obj.Base = createResourceClone(obj, base, 'Base', 'BaseGeometry') obj.Proxy = self self.setFromTemplateFile(obj, templateFile) if not obj.Stock: stockTemplate = PathPreferences.defaultStockTemplate() if stockTemplate: obj.Stock = PathStock.CreateFromTemplate(obj, json.loads(stockTemplate)) if not obj.Stock: obj.Stock = PathStock.CreateFromBase(obj) if obj.Stock.ViewObject: obj.Stock.ViewObject.Visibility = False