linuxcnc tool table exporter

This commit is contained in:
sliptonic
2020-03-15 16:07:19 -05:00
parent 663d5f3086
commit baba091596
5 changed files with 153 additions and 60 deletions

View File

@@ -24,8 +24,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>559</width>
<height>626</height>
<width>571</width>
<height>670</height>
</rect>
</property>
<attribute name="label">
@@ -61,7 +61,7 @@
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Type</string>
<string>Shape File</string>
</property>
</widget>
</item>
@@ -185,8 +185,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>559</width>
<height>626</height>
<width>571</width>
<height>670</height>
</rect>
</property>
<attribute name="label">

View File

@@ -6,18 +6,21 @@
<rect>
<x>0</x>
<y>0</y>
<width>958</width>
<height>508</height>
<width>954</width>
<height>587</height>
</rect>
</property>
<property name="windowTitle">
<string>ToolBit Library</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="createToolBit">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Create a New Toolbit and add it to the library&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Create Toolbit</string>
</property>
@@ -55,6 +58,19 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="toolEnumerate">
<property name="toolTip">
@@ -71,15 +87,9 @@
</item>
</layout>
</item>
<item>
<item row="1" column="0">
<widget class="QWidget" name="toolTableGroup" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QTableView" name="toolTable">
<property name="acceptDrops">
@@ -108,28 +118,10 @@
</attribute>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_3" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<item row="2" column="0">
<widget class="QPushButton" name="addToolController">
<property name="text">
<string>Add Selected as Tool Controllers in the Job</string>
@@ -140,8 +132,15 @@
</property>
</widget>
</item>
<item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@@ -168,8 +167,11 @@
</item>
<item>
<widget class="QPushButton" name="libraryCancel">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Close the Tool Bit Library Editor&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Cancel</string>
<string>Close</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
@@ -179,6 +181,9 @@
</item>
<item>
<widget class="QPushButton" name="librarySave">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save the current Library&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Save</string>
</property>
@@ -190,6 +195,9 @@
</item>
<item>
<widget class="QPushButton" name="librarySaveAs">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save the library to a new file&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Save As...</string>
</property>

View File

@@ -24,8 +24,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>467</width>
<height>448</height>
<width>424</width>
<height>537</height>
</rect>
</property>
<attribute name="label">
@@ -142,8 +142,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>665</width>
<height>449</height>
<width>424</width>
<height>537</height>
</rect>
</property>
<attribute name="label">
@@ -348,8 +348,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>431</width>
<height>718</height>
<width>407</width>
<height>570</height>
</rect>
</property>
<attribute name="label">
@@ -625,8 +625,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>412</width>
<height>461</height>
<width>424</width>
<height>537</height>
</rect>
</property>
<attribute name="label">
@@ -653,6 +653,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Remember last library</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">

View File

@@ -158,10 +158,14 @@ def toolsReallyUseLegacyTools():
def toolsStoreAbsolutePaths():
return preferences().GetBool(UseAbsoluteToolPaths, False)
def toolsOpenLastLibrary():
return preferences().GetBool(OpenLastLibrary, False)
def setToolsSettings(legacy, relative):
pref = preferences()
pref.SetBool(UseLegacyTools, legacy)
pref.SetBool(UseAbsoluteToolPaths, relative)
pref.SetBool(OpenLastLibrary, False)
def defaultJobTemplate():
template = preferences().GetString(DefaultJobTemplate)

View File

@@ -23,6 +23,7 @@
# ***************************************************************************
import FreeCAD
import FreeCADGui
import PathScripts.PathLog as PathLog
import PathScripts.PathPreferences as PathPreferences
@@ -41,6 +42,9 @@ import uuid as UUID
_UuidRole = PySide.QtCore.Qt.UserRole + 1
_PathRole = PySide.QtCore.Qt.UserRole + 2
def translate(context, text, disambig=None):
return PySide.QtCore.QCoreApplication.translate(context, text, disambig)
class _TableView(PySide.QtGui.QTableView):
'''Subclass of QTableView to support rearrange and copying of ToolBits'''
@@ -224,10 +228,14 @@ class ToolBitLibrary(object):
def libraryOpen(self):
PathLog.track()
foo = PySide.QtGui.QFileDialog.getOpenFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl')
if foo and foo[0]:
path = foo[0]
PathPreferences.setLastPathToolLibrary(os.path.dirname(path))
filename = PySide.QtGui.QFileDialog.getOpenFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl')
if filename and filename[0]:
path = filename[0]
PathPreferences.setLastPathToolLibrary(filename[0])
if not PathPreferences.toolsOpenLastLibrary():
path = os.path.dirname(path)
self.libraryLoad(path)
def libraryLoad(self, path):
@@ -259,9 +267,9 @@ class ToolBitLibrary(object):
def createToolBit(self):
tool = PathToolBit.ToolBitFactory().Create()
self.dialog = PySide.QtGui.QDialog(self.form)
layout = PySide.QtGui.QVBoxLayout(self.dialog)
self.editor = PathToolBitEdit.ToolBitEditor(tool, self.dialog)
#self.dialog = PySide.QtGui.QDialog(self.form)
#layout = PySide.QtGui.QVBoxLayout(self.dialog)
self.editor = PathToolBitEdit.ToolBitEditor(tool, self.form.toolTableGroup)
self.editor.setupUI()
self.buttons = PySide.QtGui.QDialogButtonBox(
PySide.QtGui.QDialogButtonBox.Ok | PySide.QtGui.QDialogButtonBox.Cancel,
@@ -287,14 +295,80 @@ class ToolBitLibrary(object):
with open(self.path, 'w') as fp:
json.dump(library, fp, sort_keys=True, indent=2)
def libararySaveLinuxCNC(self, path):
with open(path, 'w') as fp:
fp.write(";\n")
for row in range(self.model.rowCount()):
toolNr = self.model.data(self.model.index(row, 0), PySide.QtCore.Qt.EditRole)
toolPath = self.model.data(self.model.index(row, 0), _PathRole)
bit = PathToolBit.Factory.CreateFrom(toolPath)
if bit:
PathLog.track(bit)
pocket = bit.Pocket if hasattr(bit, "Pocket") else ""
xoffset = bit.Xoffset if hasattr(bit, "Xoffset") else "0"
yoffset = bit.Yoffset if hasattr(bit, "Yoffset") else "0"
zoffset = bit.Zoffset if hasattr(bit, "Zoffset") else "0"
aoffset = bit.Aoffset if hasattr(bit, "Aoffset") else "0"
boffset = bit.Boffset if hasattr(bit, "Boffset") else "0"
coffset = bit.Coffset if hasattr(bit, "Coffset") else "0"
uoffset = bit.Uoffset if hasattr(bit, "Uoffset") else "0"
voffset = bit.Voffset if hasattr(bit, "Voffset") else "0"
woffset = bit.Woffset if hasattr(bit, "Woffset") else "0"
diameter = bit.Diameter if hasattr(bit, "Diameter") else "0"
frontangle = bit.FrontAngle if hasattr(bit, "FrontAngle") else "0"
backangle = bit.BackAngle if hasattr(bit, "BackAngle") else "0"
orientation = bit.Orientation if hasattr(bit, "Orientation") else "0"
remark = bit.Label
fp.write(f"T{toolNr} "\
f"P{pocket} "\
f"X{xoffset} "\
f"Y{yoffset} "\
f"Z{zoffset} "\
f"A{aoffset} "\
f"B{boffset} "\
f"C{coffset} "\
f"U{uoffset} "\
f"V{voffset} "\
f"W{woffset} "\
f"D{diameter} "\
f"I{frontangle} "\
f"J{backangle} "\
f"Q{orientation} ;"\
f"{remark}\n")
FreeCAD.ActiveDocument.removeObject(bit.Name)
else:
PathLog.error("Could not find tool #{}: {}".format(nr, library['tools'][nr]))
def librarySaveAs(self):
foo = PySide.QtGui.QFileDialog.getSaveFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl')
if foo and foo[0]:
path = foo[0] if foo[0].endswith('.fctl') else "{}.fctl".format(foo[0])
PathPreferences.setLastPathToolLibrary(os.path.dirname(path))
self.path = path
self.librarySave()
self.updateToolbar()
TooltableTypeJSON = translate("PathToolLibraryManager", "Tooltable JSON (*.fctl)")
TooltableTypeLinuxCNC = translate("PathToolLibraryManager", "LinuxCNC tooltable (*.tbl)")
filename = PySide.QtGui.QFileDialog.getSaveFileName(self.form, \
translate("TooltableEditor", "Save toolbit library", None), \
None, "{};;{}".format(TooltableTypeJSON, \
TooltableTypeLinuxCNC))
# filename = PySide.QtGui.QFileDialog.getSaveFileName(self.form, \
# 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl')
if filename and filename[0]:
if filename[1] == TooltableTypeLinuxCNC:
path = filename[0] if filename[0].endswith('.tbl') else "{}.tbl".format(filename[0])
self.libararySaveLinuxCNC(path)
else:
path = filename[0] if filename[0].endswith('.fctl') else "{}.fctl".format(filename[0])
PathPreferences.setLastPathToolLibrary(os.path.dirname(path))
self.path = path
self.librarySave()
self.updateToolbar()
def libraryCancel(self):
self.form.close()
def columnNames(self):
return ['Nr', 'Tool', 'Shape', 'Diameter']
@@ -317,7 +391,7 @@ class ToolBitLibrary(object):
self.form.libraryOpen.clicked.connect(self.libraryOpen)
self.form.librarySave.clicked.connect(self.librarySave)
self.form.librarySaveAs.clicked.connect(self.librarySaveAs)
#self.form.libraryCancel.clicked.connect(self.cancel)
self.form.libraryCancel.clicked.connect(self.libraryCancel)
self.toolSelect([], [])
self.updateToolbar()