Tool Library replaces ToolTable Job replaces Project
This commit is contained in:
committed by
Yorik van Havre
parent
0bca05a5f2
commit
cddccdf4c7
@@ -1,34 +1,35 @@
|
||||
#***************************************************************************
|
||||
#* (c) Yorik van Havre (yorik@uncreated.net) 2015 *
|
||||
#* *
|
||||
#* This file is part of the FreeCAD CAx development system. *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* FreeCAD is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Lesser General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with FreeCAD; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************/
|
||||
# ***************************************************************************
|
||||
# * (c) Yorik van Havre (yorik@uncreated.net) 2015 *
|
||||
# * *
|
||||
# * This file is part of the FreeCAD CAx development system. *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * FreeCAD is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Lesser General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with FreeCAD; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
|
||||
from PySide import QtCore, QtGui
|
||||
import FreeCAD,FreeCADGui
|
||||
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
|
||||
# Qt tanslation handling
|
||||
try:
|
||||
_encoding = QtGui.QApplication.UnicodeUTF8
|
||||
|
||||
def translate(context, text, disambig=None):
|
||||
return QtGui.QApplication.translate(context, text, disambig, _encoding)
|
||||
except AttributeError:
|
||||
@@ -38,7 +39,6 @@ except AttributeError:
|
||||
|
||||
class OldHighlighter(QtGui.QSyntaxHighlighter):
|
||||
|
||||
|
||||
def highlightBlock(self, text):
|
||||
|
||||
myClassFormat = QtGui.QTextCharFormat()
|
||||
@@ -56,11 +56,10 @@ class OldHighlighter(QtGui.QSyntaxHighlighter):
|
||||
|
||||
class GCodeHighlighter(QtGui.QSyntaxHighlighter):
|
||||
|
||||
|
||||
def __init__(self, parent=None):
|
||||
|
||||
|
||||
def convertcolor(c):
|
||||
return QtGui.QColor(int((c>>24)&0xFF),int((c>>16)&0xFF),int((c>>8)&0xFF))
|
||||
return QtGui.QColor(int((c >> 24) & 0xFF), int((c >> 16) & 0xFF), int((c >> 8) & 0xFF))
|
||||
|
||||
super(GCodeHighlighter, self).__init__(parent)
|
||||
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Editor")
|
||||
@@ -74,26 +73,29 @@ class GCodeHighlighter(QtGui.QSyntaxHighlighter):
|
||||
if c:
|
||||
colors.append(convertcolor(c))
|
||||
else:
|
||||
colors.append(QtGui.QColor(0,170,0))
|
||||
colors.append(QtGui.QColor(0, 170, 0))
|
||||
c = p.GetUnsigned("Define name")
|
||||
if c:
|
||||
colors.append(convertcolor(c))
|
||||
else:
|
||||
colors.append(QtGui.QColor(160,160,164))
|
||||
|
||||
colors.append(QtGui.QColor(160, 160, 164))
|
||||
|
||||
self.highlightingRules = []
|
||||
numberFormat = QtGui.QTextCharFormat()
|
||||
numberFormat.setForeground(colors[0])
|
||||
self.highlightingRules.append((QtCore.QRegExp("[\\-0-9\\.]"),numberFormat))
|
||||
self.highlightingRules.append(
|
||||
(QtCore.QRegExp("[\\-0-9\\.]"), numberFormat))
|
||||
keywordFormat = QtGui.QTextCharFormat()
|
||||
keywordFormat.setForeground(colors[1])
|
||||
keywordFormat.setFontWeight(QtGui.QFont.Bold)
|
||||
keywordPatterns = ["\\bG[0-9]+\\b", "\\bM[0-9]+\\b"]
|
||||
self.highlightingRules.extend([(QtCore.QRegExp(pattern), keywordFormat) for pattern in keywordPatterns])
|
||||
self.highlightingRules.extend(
|
||||
[(QtCore.QRegExp(pattern), keywordFormat) for pattern in keywordPatterns])
|
||||
speedFormat = QtGui.QTextCharFormat()
|
||||
speedFormat.setFontWeight(QtGui.QFont.Bold)
|
||||
speedFormat.setForeground(colors[2])
|
||||
self.highlightingRules.append((QtCore.QRegExp("\\bF[0-9\\.]+\\b"),speedFormat))
|
||||
self.highlightingRules.append(
|
||||
(QtCore.QRegExp("\\bF[0-9\\.]+\\b"), speedFormat))
|
||||
|
||||
def highlightBlock(self, text):
|
||||
|
||||
@@ -108,30 +110,29 @@ class GCodeHighlighter(QtGui.QSyntaxHighlighter):
|
||||
|
||||
class GCodeEditorDialog(QtGui.QDialog):
|
||||
|
||||
def __init__(self, parent=FreeCADGui.getMainWindow()):
|
||||
|
||||
def __init__(self, parent = FreeCADGui.getMainWindow()):
|
||||
|
||||
QtGui.QDialog.__init__(self,parent)
|
||||
QtGui.QDialog.__init__(self, parent)
|
||||
layout = QtGui.QVBoxLayout(self)
|
||||
|
||||
# nice text editor widget for editing the gcode
|
||||
self.editor = QtGui.QTextEdit()
|
||||
font = QtGui.QFont()
|
||||
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Editor")
|
||||
font.setFamily(p.GetString("Font","Courier"))
|
||||
font.setFamily(p.GetString("Font", "Courier"))
|
||||
font.setFixedPitch(True)
|
||||
font.setPointSize(p.GetInt("FontSize",10))
|
||||
font.setPointSize(p.GetInt("FontSize", 10))
|
||||
self.editor.setFont(font)
|
||||
self.editor.setText("G01 X55 Y4.5 F300.0")
|
||||
self.highlighter = GCodeHighlighter(self.editor.document())
|
||||
layout.addWidget(self.editor)
|
||||
|
||||
|
||||
# Note
|
||||
lab = QtGui.QLabel()
|
||||
lab.setText(translate("PathInspect","<b>Note</b>: Pressing OK will commit any change you make above to the object, but if the object is parametric, these changes will be overridden on recompute."))
|
||||
lab.setText(translate("PathInspect", "<b>Note</b>: Pressing OK will commit any change you make above to the object, but if the object is parametric, these changes will be overridden on recompute."))
|
||||
lab.setWordWrap(True)
|
||||
layout.addWidget(lab)
|
||||
|
||||
|
||||
# OK and Cancel buttons
|
||||
self.buttons = QtGui.QDialogButtonBox(
|
||||
QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel,
|
||||
@@ -142,15 +143,15 @@ class GCodeEditorDialog(QtGui.QDialog):
|
||||
|
||||
|
||||
def show(obj):
|
||||
|
||||
"show(obj): shows the G-code data of the given Path object in a dialog"
|
||||
|
||||
if hasattr(obj,"Path"):
|
||||
if obj.Path:
|
||||
if hasattr(obj, "Path"):
|
||||
if obj.Path:
|
||||
dia = GCodeEditorDialog()
|
||||
dia.editor.setText(obj.Path.toGCode())
|
||||
result = dia.exec_()
|
||||
# exec_() returns 0 or 1 depending on the button pressed (Ok or Cancel)
|
||||
# exec_() returns 0 or 1 depending on the button pressed (Ok or
|
||||
# Cancel)
|
||||
if result:
|
||||
import Path
|
||||
p = Path.Path(dia.editor.toPlainText())
|
||||
@@ -162,31 +163,36 @@ def show(obj):
|
||||
|
||||
class CommandPathInspect:
|
||||
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Path-Inspect',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_Inspect","Inspect G-code"),
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_Inspect","Inspects the G-code contents of a path")}
|
||||
return {'Pixmap': 'Path-Inspect',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_Inspect", "Inspect G-code"),
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_Inspect", "Inspects the G-code contents of a path")}
|
||||
|
||||
def IsActive(self):
|
||||
return not FreeCAD.ActiveDocument is None
|
||||
|
||||
if FreeCAD.ActiveDocument is not None:
|
||||
for o in FreeCAD.ActiveDocument.Objects:
|
||||
if o.Name[:3] == "Job":
|
||||
return True
|
||||
return False
|
||||
|
||||
def Activated(self):
|
||||
# check that the selection contains exactly what we want
|
||||
selection = FreeCADGui.Selection.getSelection()
|
||||
if len(selection) != 1:
|
||||
FreeCAD.Console.PrintError(translate("Path_Inspect","Please select exactly one path object\n"))
|
||||
FreeCAD.Console.PrintError(
|
||||
translate("Path_Inspect", "Please select exactly one path object\n"))
|
||||
return
|
||||
if not(selection[0].isDerivedFrom("Path::Feature")):
|
||||
FreeCAD.Console.PrintError(translate("Path_Inspect","Please select exactly one path object\n"))
|
||||
FreeCAD.Console.PrintError(
|
||||
translate("Path_Inspect", "Please select exactly one path object\n"))
|
||||
return
|
||||
|
||||
|
||||
# if everything is ok, execute
|
||||
FreeCADGui.addModule("PathScripts.PathInspect")
|
||||
FreeCADGui.doCommand('PathScripts.PathInspect.show(FreeCAD.ActiveDocument.' + selection[0].Name + ')')
|
||||
FreeCADGui.doCommand(
|
||||
'PathScripts.PathInspect.show(FreeCAD.ActiveDocument.' + selection[0].Name + ')')
|
||||
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
if FreeCAD.GuiUp:
|
||||
# register the FreeCAD command
|
||||
FreeCADGui.addCommand('Path_Inspect',CommandPathInspect())
|
||||
|
||||
FreeCADGui.addCommand('Path_Inspect', CommandPathInspect())
|
||||
|
||||
Reference in New Issue
Block a user