start setting up to use flags
Signed-off-by: John Thornton <bjt128@gmail.com>
This commit is contained in:
36
dxf2gcode.go
36
dxf2gcode.go
@ -2,22 +2,41 @@ package main
|
|||||||
|
|
||||||
// DXF to G code converter
|
// DXF to G code converter
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jethornton/dxf2gcode/dxfutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"github.com/jethornton/dxf2gcode/dxfutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
file *string
|
||||||
|
port *int
|
||||||
|
yesno *bool
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
usr, _ := user.Current() // get user information
|
usr, _ := user.Current() // get user information
|
||||||
cwd, _ := os.Getwd() // get current working directory
|
cwd, _ := os.Getwd() // get current working directory
|
||||||
iniMap := make(map[string]string)
|
iniMap := make(map[string]string)
|
||||||
var inFile string
|
var inFile string
|
||||||
|
|
||||||
if len(os.Args) == 2 {
|
if len(os.Args) == 2 {
|
||||||
switch os.Args[1] {
|
switch os.Args[1] {
|
||||||
case "-v":
|
case "-v":
|
||||||
fmt.Println("Version 0.001")
|
fmt.Println("Version 0.001")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
case "-p":
|
||||||
|
fmt.Println("-p")
|
||||||
default:
|
default:
|
||||||
inFile = os.Args[1]
|
inFile = os.Args[1]
|
||||||
}
|
}
|
||||||
@ -31,26 +50,13 @@ func main() {
|
|||||||
dxfutil.Readini(iniMap, cwd)
|
dxfutil.Readini(iniMap, cwd)
|
||||||
lines := dxfutil.GetLines(inFile)
|
lines := dxfutil.GetLines(inFile)
|
||||||
entities := dxfutil.GetEntities(lines)
|
entities := dxfutil.GetEntities(lines)
|
||||||
/*
|
|
||||||
for _, e := range entities {
|
|
||||||
fmt.Printf("%2d %4s G10 %8s G11 %8s G20 %8s G21 %8s G50 %9s G51 %9s\n",
|
|
||||||
e.Test, e.G0, e.G10, e.G11, e.G20, e.G21, e.G50, e.G51)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
entities = dxfutil.GetEndPoints(entities)
|
entities = dxfutil.GetEndPoints(entities)
|
||||||
/*
|
|
||||||
for _, e := range entities {
|
|
||||||
fmt.Printf("%2d %4s Xs %9f Ys %9f Xe %9f Ye %9f\n",
|
|
||||||
e.Test, e.G0, e.Xs, e.Ys, e.Xe, e.Ye)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
entities = dxfutil.GetOrder(entities)
|
entities = dxfutil.GetOrder(entities)
|
||||||
|
dxfutil.GenGcode(entities, iniMap["SAVEAS"])
|
||||||
/*
|
/*
|
||||||
for _, e := range entities {
|
for _, e := range entities {
|
||||||
fmt.Printf("%2d %2d %4s Xs %9f Xe %9f Ys %9f Ye %9f\n",
|
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)
|
e.Test, e.Index, e.G0, e.Xs, e.Xe, e.Ys, e.Ye)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
dxfutil.GenGcode(entities, iniMap["SAVEAS"])
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -170,28 +170,30 @@ func GetEndPoints (e []Ent) ([]Ent){
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetOrder(e []Ent) ([]Ent) {
|
func GetOrder(e []Ent) ([]Ent) {
|
||||||
// search for a match for e[0] then search for a match to what matched e[0]
|
c := 3 // entity to search from
|
||||||
// this way I can say where to start... sounds good to me now to make it work
|
dir := "CW" // direction of travel
|
||||||
c := 0
|
|
||||||
x := 0
|
|
||||||
//fmt.Println("len(e)", len(e))
|
|
||||||
Search:
|
Search:
|
||||||
for i := range e {
|
for i := range e {
|
||||||
x++
|
|
||||||
//fmt.Println("x i",x, i)
|
|
||||||
if i == len(e) - 1 { break } // don't process the last one
|
if i == len(e) - 1 { break } // don't process the last one
|
||||||
|
// if direction is CW and it is an arc reverse the arc before processing
|
||||||
if i == 0 { // this will need to be smarter to figure out if it is G2 or G3
|
if i == 0 { // this will need to be smarter to figure out if it is G2 or G3
|
||||||
switch e[i].G0 {
|
fmt.Printf("e[c].G0 %s e[c].G50 %s e[c].G51 %s\n", e[c].G0, e[c].G50, e[c].G51)
|
||||||
|
switch e[c].G0 {
|
||||||
case "ARC":
|
case "ARC":
|
||||||
e[i].G = "3"
|
if dir == "CW" {
|
||||||
|
e[c].G = "2"
|
||||||
|
e[c].Xe, e[c].Xs = e[c].Xs, e[c].Xe
|
||||||
|
e[c].Ye, e[c].Ys = e[c].Ys, e[c].Ye
|
||||||
|
e[c].G50, e[c].G51 = e[c].G51, e[c].G50
|
||||||
|
} else {
|
||||||
|
e[c].G = "3"
|
||||||
|
}
|
||||||
case "LINE":
|
case "LINE":
|
||||||
e[i].G = "1"
|
e[c].G = "1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for j := range e {
|
for j := range e {
|
||||||
if c != j && floatCompare(e[c].Xe, e[j].Xs) && floatCompare(e[c].Ye, e[j].Ys) {
|
if c != j && floatCompare(e[c].Xe, e[j].Xs) && floatCompare(e[c].Ye, e[j].Ys) {
|
||||||
//fmt.Println("ccw x i j",x, i, j)
|
|
||||||
//fmt.Printf("ccw c%2d matched i%2d\n", c, i)
|
|
||||||
e[j].Index = i + 1
|
e[j].Index = i + 1
|
||||||
c = j
|
c = j
|
||||||
switch e[j].G0 {
|
switch e[j].G0 {
|
||||||
@ -205,8 +207,6 @@ func GetOrder(e []Ent) ([]Ent) {
|
|||||||
}
|
}
|
||||||
for k := range e {
|
for k := range e {
|
||||||
if c != k && floatCompare(e[c].Xe, e[k].Xe) && floatCompare(e[c].Ye, e[k].Ye) {
|
if c != k && floatCompare(e[c].Xe, e[k].Xe) && floatCompare(e[c].Ye, e[k].Ye) {
|
||||||
//fmt.Println("cw x i k",x, i, k)
|
|
||||||
//fmt.Printf("cw c%2d matched i%2d\n", c, i)
|
|
||||||
// swap end points
|
// swap end points
|
||||||
e[k].Xe, e[k].Xs = e[k].Xs, e[k].Xe
|
e[k].Xe, e[k].Xs = e[k].Xs, e[k].Xe
|
||||||
e[k].Ye, e[k].Ys = e[k].Ys, e[k].Ye
|
e[k].Ye, e[k].Ys = e[k].Ys, e[k].Ye
|
||||||
@ -226,7 +226,7 @@ func GetOrder(e []Ent) ([]Ent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("GetOrder Done")
|
|
||||||
sort.Sort(ByIndex(e))
|
sort.Sort(ByIndex(e))
|
||||||
|
fmt.Println("GetOrder Done")
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user