Files
dxftogcode/dxf2gcode.go

74 lines
1.8 KiB
Go
Raw Normal View History

2015-10-23 07:52:28 -05:00
package main
// DXF to G code converter
2015-10-23 07:52:28 -05:00
import (
"flag"
"path/filepath"
"log"
2015-10-23 07:52:28 -05:00
"fmt"
"os"
"os/user"
"github.com/jethornton/dxf2gcode/dxfutil"
)
var ( // flag variables
file *string
direction *string
//port *int
//yesno *bool
2015-10-23 07:52:28 -05:00
)
// Basic flag declarations are available for string, integer, and boolean options.
func init() { // flag.Type(flag, default, help string)
file = flag.String("f", "test.dxf", "Path to a DXF to convert")
direction = flag.String("d", "CCW", "Direction of path")
//port = flag.Int("port", 3000, "an int")
//yesno = flag.Bool("yesno", true, "a bool")
}
func main() {
flag.Parse()
usr, _ := user.Current() // get user information
inipath := usr.HomeDir + "/.config/dxf2emc"
fmt.Println(inipath)
//fmt.Println(dxfutil.PathExists(inipath + "/dxf2emc.ini"))
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
//fmt.Println(dir)
//cwd, _ := os.Getwd() // get current working directory
2015-10-23 07:52:28 -05:00
iniMap := make(map[string]string)
//var inFile string
/*
2015-10-23 07:52:28 -05:00
if len(os.Args) == 2 {
switch os.Args[1] {
2015-10-23 07:52:28 -05:00
case "-v":
fmt.Println("Version 0.001")
os.Exit(0)
case "-p":
fmt.Println("-p")
2015-10-23 07:52:28 -05:00
default:
inFile = os.Args[1]
}
} else {
fmt.Println("Current Working Directory is:", cwd)
2015-10-23 07:52:28 -05:00
fmt.Println("Current User Directory is:", usr.HomeDir)
fmt.Println("Usage is: dxf2gcode filename.ext")
fmt.Println("Usage is: dxf2gcode -v")
os.Exit(0)
}*/
dxfutil.Readini(iniMap, dir)
lines := dxfutil.GetLines(*file)
2015-10-23 07:52:28 -05:00
entities := dxfutil.GetEntities(lines)
entities = dxfutil.GetEndPoints(entities)
entities = dxfutil.GetOrder(entities)
dxfutil.GenGcode(entities, iniMap["SAVEAS"])
/*
2015-10-23 07:52:28 -05:00
for _, e := range entities {
fmt.Printf("%2d %2d %4s Xs %9f Xe %9f Ys %9f Ye %9f\n",
e.Test, e.Index, e.G0, e.Xs, e.Xe, e.Ys, e.Ye)
2015-10-23 07:52:28 -05:00
}
*/
2015-10-23 07:52:28 -05:00
}