2015-10-23 07:52:28 -05:00
|
|
|
package main
|
2015-10-23 17:26:24 -05:00
|
|
|
|
2015-10-23 07:53:42 -05:00
|
|
|
// DXF to G code converter
|
2015-10-23 07:52:28 -05:00
|
|
|
import (
|
2015-10-31 12:56:08 -05:00
|
|
|
"flag"
|
2015-10-23 07:52:28 -05:00
|
|
|
"fmt"
|
2015-10-23 17:26:24 -05:00
|
|
|
"os"
|
|
|
|
"os/user"
|
2015-10-31 12:56:08 -05:00
|
|
|
"github.com/jethornton/dxf2gcode/dxfutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
file *string
|
|
|
|
port *int
|
|
|
|
yesno *bool
|
2015-10-23 07:52:28 -05:00
|
|
|
)
|
|
|
|
|
2015-10-31 12:56:08 -05:00
|
|
|
// Basic flag declarations are available for string, integer, and boolean options.
|
|
|
|
func init() {
|
|
|
|
file = flag.String("f", "/dxf/test.dxf", "Path to a DXF to convert")
|
|
|
|
port = flag.Int("port", 3000, "an int")
|
|
|
|
yesno = flag.Bool("yesno", true, "a bool")
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-23 17:26:24 -05:00
|
|
|
func main() {
|
2015-10-31 12:56:08 -05:00
|
|
|
flag.Parse()
|
2015-10-25 12:51:08 -05:00
|
|
|
usr, _ := user.Current() // get user information
|
|
|
|
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-31 12:56:08 -05:00
|
|
|
|
2015-10-23 07:52:28 -05:00
|
|
|
if len(os.Args) == 2 {
|
2015-10-23 17:26:24 -05:00
|
|
|
switch os.Args[1] {
|
2015-10-23 07:52:28 -05:00
|
|
|
case "-v":
|
|
|
|
fmt.Println("Version 0.001")
|
|
|
|
os.Exit(0)
|
2015-10-31 12:56:08 -05:00
|
|
|
case "-p":
|
|
|
|
fmt.Println("-p")
|
2015-10-23 07:52:28 -05:00
|
|
|
default:
|
|
|
|
inFile = os.Args[1]
|
|
|
|
}
|
|
|
|
} else {
|
2015-10-25 12:51:08 -05:00
|
|
|
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-25 12:51:08 -05:00
|
|
|
dxfutil.Readini(iniMap, cwd)
|
2015-10-23 07:52:28 -05:00
|
|
|
lines := dxfutil.GetLines(inFile)
|
|
|
|
entities := dxfutil.GetEntities(lines)
|
|
|
|
entities = dxfutil.GetEndPoints(entities)
|
2015-10-30 17:18:21 -05:00
|
|
|
entities = dxfutil.GetOrder(entities)
|
2015-10-31 12:56:08 -05:00
|
|
|
dxfutil.GenGcode(entities, iniMap["SAVEAS"])
|
2015-10-31 08:06:00 -05:00
|
|
|
/*
|
2015-10-23 07:52:28 -05:00
|
|
|
for _, e := range entities {
|
2015-10-30 13:20:49 -05:00
|
|
|
fmt.Printf("%2d %2d %4s Xs %9f Xe %9f Ys %9f Ye %9f\n",
|
2015-10-30 17:18:21 -05:00
|
|
|
e.Test, e.Index, e.G0, e.Xs, e.Xe, e.Ys, e.Ye)
|
2015-10-23 07:52:28 -05:00
|
|
|
}
|
2015-10-31 08:06:00 -05:00
|
|
|
*/
|
2015-10-23 07:52:28 -05:00
|
|
|
}
|