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-11-05 08:20:53 -06:00
|
|
|
//"path/filepath"
|
|
|
|
//"log"
|
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"
|
|
|
|
)
|
|
|
|
|
2015-11-02 10:08:41 -06:00
|
|
|
var ( // flag variables
|
2015-11-04 10:25:29 -06:00
|
|
|
input *string
|
2015-11-02 10:08:41 -06:00
|
|
|
direction *string
|
2015-11-04 10:25:29 -06:00
|
|
|
output *string
|
|
|
|
analyze *bool
|
|
|
|
convert *bool
|
2015-11-02 10:08:41 -06:00
|
|
|
//port *int
|
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.
|
2015-11-02 10:08:41 -06:00
|
|
|
func init() { // flag.Type(flag, default, help string)
|
2015-11-04 10:25:29 -06:00
|
|
|
input = flag.String("i", "dxf/test.dxf", "Input file path")
|
|
|
|
output = flag.String("o", "output.ngc", "Output file path")
|
2015-11-02 10:08:41 -06:00
|
|
|
direction = flag.String("d", "CCW", "Direction of path")
|
2015-11-04 10:25:29 -06:00
|
|
|
analyze = flag.Bool("a", false, "Analyze contents of the file")
|
|
|
|
convert = flag.Bool("c", false, "Convert contents of the file")
|
2015-11-02 10:08:41 -06:00
|
|
|
//port = flag.Int("port", 3000, "an int")
|
2015-10-31 12:56:08 -05:00
|
|
|
}
|
|
|
|
|
2015-10-23 17:26:24 -05:00
|
|
|
func main() {
|
2015-10-31 12:56:08 -05:00
|
|
|
flag.Parse()
|
2015-11-04 10:25:29 -06:00
|
|
|
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)
|
2015-11-05 08:20:53 -06:00
|
|
|
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)
|
2015-11-04 10:25:29 -06:00
|
|
|
lines := dxfutil.GetLines(*input)
|
|
|
|
entities := dxfutil.GetEntities(lines)
|
|
|
|
if *analyze {
|
|
|
|
dxfutil.GetLayers(entities)
|
|
|
|
}
|
2015-11-05 08:20:53 -06:00
|
|
|
if *convert {
|
|
|
|
fmt.Println("Convert was true")
|
|
|
|
}
|
2015-11-04 10:25:29 -06:00
|
|
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
2015-11-05 08:20:53 -06:00
|
|
|
/*
|
|
|
|
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
//cwd, _ := os.Getwd() // get current working directory
|
2015-11-02 10:08:41 -06:00
|
|
|
//var inFile string
|
|
|
|
/*
|
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-11-02 10:08:41 -06:00
|
|
|
}*/
|
2015-11-04 10:25:29 -06:00
|
|
|
|
2015-10-23 07:52:28 -05:00
|
|
|
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
|
|
|
}
|