Merge pull request #24807 from tarman3/inspect

CAM: Line numbers in Inspect window
This commit is contained in:
sliptonic
2025-11-28 11:48:24 -06:00
committed by GitHub

View File

@@ -30,6 +30,7 @@ import FreeCADGui
import Path
from PySide.QtCore import QT_TRANSLATE_NOOP
import PathScripts.PathUtils as PathUtils
from Path.Main.Gui.Editor import CodeEditor
translate = FreeCAD.Qt.translate
@@ -112,15 +113,15 @@ class GCodeEditorDialog(QtGui.QDialog):
self.selectionobj.ViewObject.LineWidth = 4
self.selectionobj.ViewObject.NormalColor = highlightcolor
# nice text editor widget for editing the gcode
self.editor = QtGui.QTextEdit()
# self.editor = QtGui.QTextEdit() # without lines enumeration
self.editor = CodeEditor() # with lines enumeration
font = QtGui.QFont()
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Editor")
font.setFamily(p.GetString("Font", "Courier"))
font.setFixedPitch(True)
font.setPointSize(p.GetInt("FontSize", 10))
self.editor.setFont(font)
self.editor.setText("G01 X55 Y4.5 F300.0")
self.editor.setPlainText("G01 X55 Y4.5 F300.0")
layout.addWidget(self.editor)
# Note
@@ -128,7 +129,8 @@ class GCodeEditorDialog(QtGui.QDialog):
lab.setText(
translate(
"CAM_Inspect",
"<b>Note</b>: This dialog shows path commands in FreeCAD base units (mm/s). \n Values will be converted to the desired unit during post processing.",
"<b>Note</b>: This dialog shows path commands in FreeCAD base units (mm/s)."
"<br>Values will be converted to the desired unit during post processing.",
)
)
lab.setWordWrap(True)
@@ -221,11 +223,11 @@ def show(obj):
if hasattr(obj, "Path"):
if obj.Path:
dia = GCodeEditorDialog(obj)
dia.editor.setText(obj.Path.toGCode())
dia.editor.setPlainText(obj.Path.toGCode())
gcodeSize = len(dia.editor.toPlainText())
if gcodeSize <= mhs:
# because of poor performance, syntax highlighting is
# limited to mhs octets (default 512 KB).
# limited to mhs octets (default 256 KB).
# It seems than the response time curve has an inflexion near 500 KB
# beyond 500 KB, the response time increases exponentially.
dia.highlighter = GCodeHighlighter(dia.editor.document())
@@ -239,8 +241,7 @@ def show(obj):
)
)
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:
p = Path.Path(dia.editor.toPlainText())
FreeCAD.ActiveDocument.openTransaction("Edit Path")