Files
dxftogcode/dxf2gcode.go

96 lines
2.2 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
input *string
direction *string
output *string
analyze *bool
convert *bool
//port *int
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)
input = flag.String("i", "dxf/test.dxf", "Input file path")
output = flag.String("o", "output.ngc", "Output file path")
direction = flag.String("d", "CCW", "Direction of path")
analyze = flag.Bool("a", false, "Analyze contents of the file")
convert = flag.Bool("c", false, "Convert contents of the file")
//port = flag.Int("port", 3000, "an int")
}
func main() {
flag.Parse()
if flag.NFlag() == 0 { // if no flags are passed print usage
flag.Usage()
fmt.Println("Flags", flag.NFlag())
os.Exit(1)
}
iniMap := make(map[string]string)
usr, _ := user.Current() // get user information
iniFile := usr.HomeDir + "/.config/dxf2emc/dxf2emc.ini"
dxfutil.Readini(iniMap, iniFile)
//fmt.Println("OUTPUT", iniMap["OUTPUT"])
//i, ok := iniMap["OUTPUT"]
//fmt.Println(i, ok)
lines := dxfutil.GetLines(*input)
entities := dxfutil.GetEntities(lines)
if *analyze {
dxfutil.GetLayers(entities)
}
if *convert {
fmt.Println("Convert was true")
}
os.Exit(1)
/*
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
*/
//cwd, _ := os.Getwd() // get current working directory
//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)
}*/
2015-10-23 07:52:28 -05:00
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
}