// ParseLine parses LINE entities. func ParseLine(d *drawing.Drawing, data [][2]string) (entity.Entity, error) { l := entity.NewLine() var err error for _, dt := range data { switch dt[0] { default: continue case "8": layer, err := d.Layer(dt[1], false) if err == nil { l.SetLayer(layer) } case "10": err = setFloat(dt, func(val float64) { l.Start[0] = val }) case "20": err = setFloat(dt, func(val float64) { l.Start[1] = val }) case "30": err = setFloat(dt, func(val float64) { l.Start[2] = val }) case "11": err = setFloat(dt, func(val float64) { l.End[0] = val }) case "21": err = setFloat(dt, func(val float64) { l.End[1] = val }) case "31": err = setFloat(dt, func(val float64) { l.End[2] = val }) } if err != nil { return l, err } } return l, nil }
// ParseBlock parses each BLOCK, which starts with "0\nBLOCK\n" and ends with "0\nENDBLK\n". func ParseBlock(d *drawing.Drawing, data [][2]string) error { b := block.NewBlock("", "") var err error for _, dt := range data { switch dt[0] { case "2": b.Name = dt[1] case "1": // 4? b.Description = dt[1] case "8": layer, err := d.Layer(dt[1], false) if err == nil { b.SetLayer(layer) } case "10": err = setFloat(dt, func(val float64) { b.Coord[0] = val }) case "20": err = setFloat(dt, func(val float64) { b.Coord[1] = val }) case "30": err = setFloat(dt, func(val float64) { b.Coord[2] = val }) case "70": val, err := strconv.ParseInt(strings.TrimSpace(dt[1]), 10, 64) if err != nil { return err } b.Flag = int(val) } if err != nil { return err } } return nil }