def generate_gcode(self, obj): ''' Base function to generate gcode for the OP by writing path command to self.commandlist Calls operations op_generate_gcode. ''' opTool = obj.ToolController.Tool # only toolbits are supported if isinstance(opTool, Path.Tool): raise RuntimeError( translate('PathTurn', "Path Turn: Legacy Tools Not Supported ")) # create a liblathe tool and assign the toolbit parameters turnTool = Tool() # TODO: set some sensible default values or raise error if attribute not available if hasattr(opTool, "TipAngle"): turnTool.set_tip_angle(opTool.TipAngle.Value) if hasattr(opTool, "EdgeLength"): turnTool.set_edge_length(opTool.EdgeLength.Value) if hasattr(opTool, "TipRadius"): turnTool.set_nose_radius(opTool.TipRadius.Value) if hasattr(opTool, "Rotation"): turnTool.set_rotation(opTool.Rotation.Value) self.op_generate_gcode(obj, turnTool)
def test_get_max_doc(self): max_doc = self.tool.get_max_doc() self.assertEqual(max_doc, 1.5875) with self.assertRaises(Warning): tool = Tool() max_doc = tool.get_max_doc()
def setUp(self): # Define Part Geometry part_segments = [] PartPt1 = Point(0, 0, 10) PartPt2 = Point(-5, 0, -9) PartPt3 = Point(-9.5, 0, -15.85) PartPt4 = Point(-5.4, 0, -22) PartPt5 = Point(-5.4, 0, -30) PartPt6 = Point(-5.4, 0, -35) PartPt7 = Point(-5.4, 0, -40) PartPt8 = Point(-13, 0, -45) PartPt9 = Point(-13, 0, -48) PartPt10 = Point(0, 0, -48) part_segments.append(Segment(PartPt1, PartPt2, -0.75)) part_segments.append(Segment(PartPt2, PartPt3)) part_segments.append(Segment(PartPt3, PartPt4)) part_segments.append(Segment(PartPt4, PartPt5, 0.25)) part_segments.append(Segment(PartPt5, PartPt6)) part_segments.append(Segment(PartPt6, PartPt8)) part_segments.append(Segment(PartPt7, PartPt8)) part_segments.append(Segment(PartPt8, PartPt9)) part_segments.append(Segment(PartPt9, PartPt10)) # Define stock bounds stockPt1 = Point(0, 0, 15) stockPt2 = Point(-25, 0, -55) stock_boundbox = BoundBox(stockPt1, stockPt2) # set feed rate to test self.hfeed = 10 # Define Operations Properties params = {} params['min_dia'] = 0 params['extra_dia'] = 0 params['start_offset'] = 0 params['end_offset'] = 0 params['allow_grooving'] = True params['step_over'] = 1 params['finish_passes'] = 3 params['stock_to_leave'] = 0 params['hfeed'] = self.hfeed params['vfeed'] = 10 self.op = ProfileOP() self.op.set_params(params) self.op.add_stock(stock_boundbox) self.op.add_part_edges(part_segments) tool = Tool() tool.set_tool_from_string('DCMT070204R') self.op.add_tool(tool)
def test_create_tool(self): shape = "D" length = self.tool.edge_length nose_radius = self.tool.nose_radius direction = self.tool.direction orientation = self.tool.orientation self.assertEqual(shape, "D") self.assertEqual(length, 6.35) self.assertEqual(nose_radius, 0.4) self.assertEqual(direction, "R") self.assertEqual(orientation, ToolOri.X) with self.assertRaises(ValueError): Tool('xyz')
class test_tool(unittest.TestCase): """Test for tool.py""" def setUp(self): self.tool = Tool() self.tool.set_tool_from_string('DCMT070204R') def test_create_tool(self): shape = "D" length = self.tool.length nose_radius = self.tool.nose_radius direction = self.tool.direction orientation = self.tool.orientation self.assertEqual(shape, "D") self.assertEqual(length, 6.35) self.assertEqual(nose_radius, 0.4) self.assertEqual(direction, "R") self.assertEqual(orientation, ToolOri.X) with self.assertRaises(ValueError): Tool('xyz') def test_get_tool_cutting_angle(self): cuttingAngle = self.tool.get_tool_cutting_angle() self.assertEqual(cuttingAngle, 303) def test_getShapeAngle(self): shapeAngle = self.tool.get_tip_angle_from_shape("D") self.assertEqual(shapeAngle, 55) def test_getEdgeLength(self): edgeLength = self.tool.getEdgeLength("D", "07") self.assertEqual(edgeLength, 6.35) def test_getNoseRadius(self): noseRadius = self.tool.getNoseRadius("04") self.assertEqual(noseRadius, 0.4) def test_getCuttingDirection(self): cuttingDirection = self.tool.getCuttingDirection() self.assertEqual(cuttingDirection, "R") def test_getRotation(self): rotation = self.tool.getRotation() self.assertEqual(rotation, 0)
def setUp(self): self.tool = Tool() self.tool.set_tool_from_string('DCMT070204R')
class test_tool(unittest.TestCase): """Test for tool.py""" def setUp(self): self.tool = Tool() self.tool.set_tool_from_string('DCMT070204R') def test_create_tool(self): shape = "D" length = self.tool.edge_length nose_radius = self.tool.nose_radius direction = self.tool.direction orientation = self.tool.orientation self.assertEqual(shape, "D") self.assertEqual(length, 6.35) self.assertEqual(nose_radius, 0.4) self.assertEqual(direction, "R") self.assertEqual(orientation, ToolOri.X) with self.assertRaises(ValueError): Tool('xyz') def test_get_tool_cutting_angle(self): cuttingAngle = self.tool.get_tool_cutting_angle() self.assertEqual(cuttingAngle, 209.5) def test_getShapeAngle(self): shapeAngle = self.tool.get_tip_angle_from_shape("D") self.assertEqual(shapeAngle, 55) def test_get_edge_length(self): edgeLength = self.tool.get_edge_length("D", "07") self.assertEqual(edgeLength, 6.35) with self.assertRaises(Warning): self.tool.get_edge_length("A", "A") with self.assertRaises(Warning): self.tool.get_edge_length("D", "A") def test_get_nose_radius(self): noseRadius = self.tool.get_nose_radius("04") self.assertEqual(noseRadius, 0.4) with self.assertRaises(Warning): self.tool.get_nose_radius("A") def test_get_cutting_direction(self): cuttingDirection = self.tool.get_cutting_direction() self.assertEqual(cuttingDirection, "R") def test_get_rotation(self): rotation = self.tool.get_rotation() self.assertEqual(rotation, 0) def test_get_max_doc(self): max_doc = self.tool.get_max_doc() self.assertEqual(max_doc, 1.5875) with self.assertRaises(Warning): tool = Tool() max_doc = tool.get_max_doc() def test_set_tip_angle(self): self.tool.set_tip_angle(22.5) self.assertEqual(self.tool.tip_angle, 22.5) with self.assertRaises(Warning): self.tool.set_tip_angle("A") with self.assertRaises(Warning): self.tool.set_tip_angle(-1) def test_set_edge_length(self): self.tool.set_edge_length(5) self.assertEqual(self.tool.edge_length, 5) with self.assertRaises(Warning): self.tool.set_edge_length("A") with self.assertRaises(Warning): self.tool.set_edge_length(-1) def test_set_nose_radius(self): self.tool.set_nose_radius(0.5) self.assertEqual(self.tool.nose_radius, 0.5) with self.assertRaises(Warning): self.tool.set_nose_radius("A") with self.assertRaises(Warning): self.tool.set_nose_radius(-1) def test_set_direction(self): self.tool.set_direction("N") self.assertEqual(self.tool.direction, "N") with self.assertRaises(Warning): self.tool.set_direction("A") def test_set_rotation(self): self.tool.set_rotation(45) self.assertEqual(self.tool.tool_rotation, 45) self.tool.set_rotation(22.5) self.assertEqual(self.tool.tool_rotation, 22.5) with self.assertRaises(Warning): self.tool.set_rotation(361) with self.assertRaises(Warning): self.tool.set_rotation(-1) with self.assertRaises(Warning): self.tool.set_rotation("A") def test_set_orientation(self): self.tool.set_orientation(ToolOri.X) self.assertEqual(self.tool.orientation, ToolOri.X) with self.assertRaises(Warning): self.tool.set_orientation("X")
params['extra_dia'] = 0 params['start_offset'] = 0 params['end_offset'] = 0 params['allow_grooving'] = True params['step_over'] = 0.25 params['finish_passes'] = 10 params['stock_to_leave'] = 0 params['hfeed'] = 10 params['vfeed'] = 10 # Create Profile Operation profileOP = ProfileOP() profileOP.set_params(params) profileOP.add_stock(StockBoundingBox) profileOP.add_part_edges(part_segments) tool = Tool() tool.set_tool_from_string('DCMT070204R') tool.set_rotation(75) profileOP.add_tool(tool) gcode = profileOP.get_gcode() plot = Plot() plot.backplot(gcode) # Write the gcode to a file in the Examples folder f = open(thisFolder + "/profile.gcode", "w") for command in gcode: f.write(command.to_string() + "\n") f.close()
params['min_dia'] = 0 params['extra_dia'] = 0 params['start_offset'] = 0 params['end_offset'] = 0 params['allow_grooving'] = False params['step_over'] = 1 params['finish_passes'] = 2 params['stock_to_leave'] = 0 params['hfeed'] = 10 params['vfeed'] = 10 # Create Profile Operation profileOP = ProfileOP() profileOP.set_params(params) profileOP.add_stock(StockBoundingBox) profileOP.add_part_edges(part_segments) tool = Tool() tool.set_tool_from_string('DCMT070204R') profileOP.add_tool(tool) gcode = profileOP.get_gcode() # plot = Plot() # plot.backplot(gcode) # Write the gcode to a file in the Examples folder f = open(thisFolder + "/profile.gcode", "w") for command in gcode: f.write(command.to_string() + "\n") f.close()