adding command line flags and analyze

Signed-off-by: John Thornton <bjt128@gmail.com>
This commit is contained in:
John Thornton
2015-11-04 10:25:29 -06:00
parent 3812449fda
commit 7418380bea
7 changed files with 2376 additions and 135 deletions

View File

@ -1,10 +1,10 @@
# dxf2gcode
Don't confuse this with other dxf2gcode programs.
Status: Not Functioning
Current: adding command line flags and analyze
At this time dxf2gcode will convert a single layer DXF file to G code.
This is for G17 applications only at this time.
Set the output file directory to some directory you have.
Place the ini file in your home directory.

171
dxf.glade
View File

@ -39,12 +39,7 @@
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-convert</property>
</object>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
<property name="stock">gtk-find</property>
</object>
<object class="GtkWindow" id="main_window">
<property name="width_request">600</property>
@ -72,35 +67,33 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="file_open">
<property name="label">gtk-open</property>
<object class="GtkMenuItem" id="file_open">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">Open</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_file_open" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="file_convert">
<property name="label" translatable="yes">Convert</property>
<object class="GtkMenuItem" id="file_analyze">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="image">image1</property>
<property name="use_stock">False</property>
<signal name="activate" handler="on_file_convert" swapped="no"/>
<property name="label" translatable="yes">Analyze</property>
<signal name="activate" handler="on_file_analyze" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem3">
<property name="label">gtk-save</property>
<object class="GtkMenuItem" id="file_convert">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="label" translatable="yes">Convert</property>
<signal name="activate" handler="on_file_convert" swapped="no"/>
</object>
</child>
<child>
@ -111,13 +104,22 @@
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="file_quit">
<property name="label">gtk-quit</property>
<object class="GtkMenuItem" id="file_save">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">Save</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="file_quit">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">Quit</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_file_quit" swapped="no"/>
</object>
</child>
@ -137,43 +139,39 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem6">
<property name="label">gtk-cut</property>
<object class="GtkMenuItem" id="imagemenuitem6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">gtk-cut</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem7">
<property name="label">gtk-copy</property>
<object class="GtkMenuItem" id="imagemenuitem7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">gtk-copy</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem8">
<property name="label">gtk-paste</property>
<object class="GtkMenuItem" id="imagemenuitem8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">gtk-paste</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem9">
<property name="label">gtk-delete</property>
<object class="GtkMenuItem" id="imagemenuitem9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">gtk-delete</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
@ -192,14 +190,11 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="view_test">
<property name="label" translatable="yes">Test</property>
<object class="GtkMenuItem" id="view_test">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="image">image2</property>
<property name="use_stock">False</property>
<signal name="activate" handler="on_view_test" swapped="no"/>
<property name="label" translatable="yes">Test</property>
</object>
</child>
</object>
@ -218,14 +213,12 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="help_about">
<property name="label">gtk-about</property>
<object class="GtkMenuItem" id="help_about">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">gtk-about</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_help_about" swapped="no"/>
</object>
</child>
</object>
@ -288,17 +281,6 @@ Help &gt; About</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="tolerance_entry">
<property name="visible">True</property>
@ -332,26 +314,6 @@ Help &gt; About</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
@ -401,7 +363,7 @@ Help &gt; About</property>
<object class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
<property name="label" translatable="yes">Default file name:</property>
</object>
<packing>
<property name="top_attach">3</property>
@ -409,7 +371,7 @@ Help &gt; About</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry4">
<object class="GtkEntry" id="output_name_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
@ -425,6 +387,65 @@ Help &gt; About</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="save_directory_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="invisible_char_set">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="find_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="image">image1</property>
<property name="image_position">right</property>
<signal name="clicked" handler="on_find_button" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Directory to save G code in:</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>

31
dxf.py
View File

@ -16,18 +16,23 @@ class Buglump:
self.builder.add_from_file('dxf.glade')
self.builder.connect_signals(self)
self.window = self.builder.get_object('main_window')
self.aboutdialog = self.builder.get_object("aboutdialog")
self.aboutdialog = self.builder.get_object('aboutdialog')
self.aboutdialog.set_version(version)
self.file_analyze = self.builder.get_object('file_analyze')
self.file_convert = self.builder.get_object('file_convert')
self.tolerance = self.builder.get_object('tolerance_entry')
self.path = self.builder.get_object('path_entry')
self.status = self.builder.get_object("status_label")
self.status.set_text('No File Open')
self.current_folder = os.path.expanduser('~')
self.label2 = self.builder.get_object('label2')
self.save_directory = self.builder.get_object('save_directory_entry')
self.output_name = self.builder.get_object('output_name_entry')
self.file_name = ''
self.ini_file = ''
self.config = ConfigParser.ConfigParser()
self.config.optionxform = str
self.user_home = os.path.expanduser('~')
self.window.show()
self.ini_check()
@ -48,10 +53,15 @@ class Buglump:
self.status.set_text('File Selected %s' % self.fcd.get_filename())
self.file_name = "-f=" + self.fcd.get_filename()
self.current_folder = os.path.dirname(self.fcd.get_uri()[7:])
self.file_analyze.set_sensitive(True)
self.file_convert.set_sensitive(True)
else:
self.status.set_text('No File Open')
self.fcd.destroy()
def on_file_analyze(self, menuitem, data=None):
print 'Analyze %s' % self.file_name
def on_file_convert(self, file_name, data=None):
if len(self.file_name) > 0:
self.args = self.file_name
@ -95,10 +105,12 @@ class Buglump:
self.build_ini()
def build_ini(self):
cfgfile = open(self.ini_file,'w')
cfgfile = open(self.ini_file,'w+')
self.config.add_section('Configuration')
self.config.set('Configuration', 'TOLERANCE', '0.000001')
self.config.set('Configuration', 'PATH', 'CCW')
self.config.set('Configuration', 'SAVE_DIR', '')
self.config.set('Configuration', 'OUTPUT', 'output.ngc')
self.config.write(cfgfile)
cfgfile.close
@ -110,16 +122,31 @@ class Buglump:
try:
self.tolerance.set_text(self.config.get('Configuration', 'TOLERANCE'))
self.path.set_text(self.config.get('Configuration', 'PATH'))
self.save_directory.set_text(self.config.get('Configuration', 'SAVE_DIR'))
self.output_name.set_text(self.config.get('Configuration', 'OUTPUT'))
except:
message = 'The preferences file is corrupt.\nRebuild with default settings?'
result = yesno_dialog(message)
if result == gtk.RESPONSE_YES:
self.build_ini()
def on_find_button(self, data=None):
self.fcd = gtk.FileChooserDialog("Open...", None,
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
self.fcd.set_current_folder(self.user_home)
self.response = self.fcd.run()
if self.response == gtk.RESPONSE_OK:
print "Selected filepath: %s" % self.fcd.get_filename()
self.save_directory.set_text(self.fcd.get_filename())
self.fcd.destroy()
def on_save_preferences(self, data=None):
cfgfile = open(self.ini_file, 'w')
self.config.set('Configuration', 'TOLERANCE', self.tolerance.get_text())
self.config.set('Configuration', 'PATH', self.path.get_text())
self.config.set('Configuration', 'SAVE_DIR', self.save_directory.get_text())
self.config.set('Configuration', 'OUTPUT', self.output_name.get_text())
self.config.write(cfgfile)
cfgfile.close()

View File

@ -903,7 +903,7 @@ LAYER
100
AcDbSymbolTable
70
1
2
0
LAYER
5
@ -925,6 +925,28 @@ CONTINUOUS
370
0
390
F
0
LAYER
5
43
100
AcDbSymbolTableRecord
100
AcDbLayerTableRecord
2
Inside
70
0
62
7
6
CONTINUOUS
290
1
370
0
390
F
0
ENDTAB
@ -1253,7 +1275,7 @@ ENTITIES
0
ARC
5
43
44
100
AcDbEntity
8
@ -1283,7 +1305,7 @@ AcDbArc
0
LINE
5
44
45
100
AcDbEntity
100
@ -1311,7 +1333,7 @@ ByLayer
0
ARC
5
45
46
100
AcDbEntity
8
@ -1341,7 +1363,7 @@ AcDbArc
0
LINE
5
46
47
100
AcDbEntity
100
@ -1369,7 +1391,7 @@ ByLayer
0
ARC
5
47
48
100
AcDbEntity
8
@ -1399,34 +1421,6 @@ AcDbArc
0
LINE
5
48
100
AcDbEntity
100
AcDbLine
8
0
62
256
370
-1
6
ByLayer
10
1.0
20
0.0
30
0.0
11
9.0
21
0.0
31
0.0
0
LINE
5
49
100
AcDbEntity
@ -1437,6 +1431,34 @@ AcDbLine
62
256
370
-1
6
ByLayer
10
1.0
20
0.0
30
0.0
11
9.0
21
0.0
31
0.0
0
LINE
5
4A
100
AcDbEntity
100
AcDbLine
8
0
62
256
370
-1
6
ByLayer
@ -1455,7 +1477,7 @@ ByLayer
0
ARC
5
4A
4B
100
AcDbEntity
8
@ -1483,6 +1505,118 @@ AcDbArc
51
270.0
0
LINE
5
4C
100
AcDbEntity
100
AcDbLine
8
Inside
62
256
370
-1
6
ByLayer
10
1.0
20
1.0
30
0.0
11
9.0
21
1.0
31
0.0
0
LINE
5
4D
100
AcDbEntity
100
AcDbLine
8
Inside
62
256
370
-1
6
ByLayer
10
9.0
20
1.0
30
0.0
11
9.0
21
9.0
31
0.0
0
LINE
5
4E
100
AcDbEntity
100
AcDbLine
8
Inside
62
256
370
-1
6
ByLayer
10
9.0
20
9.0
30
0.0
11
1.0
21
9.0
31
0.0
0
LINE
5
4F
100
AcDbEntity
100
AcDbLine
8
Inside
62
256
370
-1
6
ByLayer
10
1.0
20
9.0
30
0.0
11
1.0
21
1.0
31
0.0
0
ENDSEC
0
SECTION
@ -1521,7 +1655,7 @@ E
3
AcDbVariableDictionary
350
4B
50
0
DICTIONARY
5
@ -1985,7 +2119,7 @@ Layout2
0
DICTIONARY
5
4B
50
100
AcDbDictionary
281
@ -1993,15 +2127,15 @@ AcDbDictionary
3
DIMASSOC
350
4D
52
3
HIDETEXT
350
4C
51
0
DICTIONARYVAR
5
4C
51
100
DictionaryVariables
280
@ -2011,7 +2145,7 @@ DictionaryVariables
0
DICTIONARYVAR
5
4D
52
100
DictionaryVariables
280

2024
dxf/test.dxf~ Executable file

File diff suppressed because it is too large Load Diff

View File

@ -12,33 +12,55 @@ import (
)
var ( // flag variables
file *string
input *string
direction *string
output *string
analyze *bool
convert *bool
//port *int
//yesno *bool
)
// 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")
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")
//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"))
if flag.NFlag() == 0 { // if no flags are passed print usage
flag.Usage()
fmt.Println("Analyze", *analyze)
fmt.Println("Flags", flag.NFlag())
os.Exit(1)
}
if *convert {
fmt.Println("Convert was true")
}
iniMap := make(map[string]string)
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
dxfutil.Readini(iniMap, dir)
lines := dxfutil.GetLines(*input)
entities := dxfutil.GetEntities(lines)
if *analyze {
dxfutil.GetLayers(entities)
}
os.Exit(1)
usr, _ := user.Current() // get user information
inipath := usr.HomeDir + "/.config/dxf2emc"
fmt.Println(inipath)
//fmt.Println(dxfutil.PathExists(inipath + "/dxf2emc.ini"))
//fmt.Println(dir)
//cwd, _ := os.Getwd() // get current working directory
iniMap := make(map[string]string)
//var inFile string
/*
if len(os.Args) == 2 {
@ -58,9 +80,7 @@ func main() {
fmt.Println("Usage is: dxf2gcode -v")
os.Exit(0)
}*/
dxfutil.Readini(iniMap, dir)
lines := dxfutil.GetLines(*file)
entities := dxfutil.GetEntities(lines)
entities = dxfutil.GetEndPoints(entities)
entities = dxfutil.GetOrder(entities)
dxfutil.GenGcode(entities, iniMap["SAVEAS"])

View File

@ -1,6 +1,5 @@
package dxfutil
import (
"bufio"
"os"
@ -141,6 +140,22 @@ func GetEntities(list []string) ([]Ent){
return e
}
func GetLayers(e []Ent){
var layers []string
Search:
for i := range e {
if len(layers) == 0 {
layers = append(layers, e[i].G8)
continue Search
}
for j := range layers {
if e[i].G8 == layers[j]{ continue Search }
}
layers = append(layers, e[i].G8)
}
fmt.Println(layers)
}
func GetEndPoints (e []Ent) ([]Ent){
// add error handling
for i := range e {