diff --git a/src/Mod/Path/Gui/DlgSettingsPathColor.cpp b/src/Mod/Path/Gui/DlgSettingsPathColor.cpp index c9b5838588..f644bf056c 100644 --- a/src/Mod/Path/Gui/DlgSettingsPathColor.cpp +++ b/src/Mod/Path/Gui/DlgSettingsPathColor.cpp @@ -59,6 +59,7 @@ void DlgSettingsPathColor::saveSettings() DefaultPathMarkerColor->onSave(); DefaultExtentsColor->onSave(); DefaultProbePathColor->onSave(); + DefaultHighlightPathColor->onSave(); } void DlgSettingsPathColor::loadSettings() @@ -70,6 +71,7 @@ void DlgSettingsPathColor::loadSettings() DefaultPathMarkerColor->onRestore(); DefaultExtentsColor->onRestore(); DefaultProbePathColor->onRestore(); + DefaultHighlightPathColor->onRestore(); } /** diff --git a/src/Mod/Path/Gui/DlgSettingsPathColor.ui b/src/Mod/Path/Gui/DlgSettingsPathColor.ui index faffa6ff8b..fa7df4cd09 100644 --- a/src/Mod/Path/Gui/DlgSettingsPathColor.ui +++ b/src/Mod/Path/Gui/DlgSettingsPathColor.ui @@ -6,8 +6,8 @@ 0 0 - 297 - 281 + 310 + 304 @@ -204,13 +204,69 @@ + + + + + 182 + 0 + + + + Path Highlight Color + + + + + + + The default line color for new shapes + + + + 255 + 125 + 0 + + + + DefaultHighlightPathColor + + + Mod/Path + + + - DefaultRapidPathColor_2 - label_8 + label_6 + DefaultNormalPathColor + label_9 + DefaultPathLineWidth + label_10 + DefaultPathMarkerColor + label_7 + DefaultRapidPathColor + label + DefaultExtentsColor label_8 DefaultProbePathColor + label_11 + DefaultHighlightPathColor + + + + Qt::Vertical + + + + 20 + 217 + + + + @@ -224,19 +280,6 @@ - - - - Qt::Vertical - - - - 20 - 217 - - - - diff --git a/src/Mod/Path/PathScripts/PathInspect.py b/src/Mod/Path/PathScripts/PathInspect.py index 4312a12088..5119620602 100644 --- a/src/Mod/Path/PathScripts/PathInspect.py +++ b/src/Mod/Path/PathScripts/PathInspect.py @@ -25,7 +25,7 @@ from PySide import QtCore, QtGui import FreeCAD import FreeCADGui - +import Path # Qt tanslation handling try: _encoding = QtGui.QApplication.UnicodeUTF8 @@ -110,11 +110,21 @@ class GCodeHighlighter(QtGui.QSyntaxHighlighter): class GCodeEditorDialog(QtGui.QDialog): - def __init__(self, parent=FreeCADGui.getMainWindow()): - + def __init__(self, PathObj, parent=FreeCADGui.getMainWindow()): + self.PathObj = PathObj QtGui.QDialog.__init__(self, parent) layout = QtGui.QVBoxLayout(self) + p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path") + c = p.GetUnsigned("DefaultHighlightPathColor", 4286382335 ) + Q = QtGui.QColor(int((c >> 24) & 0xFF), int((c >> 16) & 0xFF), int((c >> 8) & 0xFF)) + highlightcolor = (Q.red()/255., Q.green()/255., Q.blue()/255., Q.alpha()/255.) + + self.selectionobj = FreeCAD.ActiveDocument.addObject("Path::Feature","selection") + self.selectionobj.ViewObject.LineWidth = 4 + self.selectionobj.ViewObject.NormalColor = highlightcolor + self.selectionobj.ViewObject.ShowFirstRapid = False + # nice text editor widget for editing the gcode self.editor = QtGui.QTextEdit() font = QtGui.QFont() @@ -140,6 +150,53 @@ class GCodeEditorDialog(QtGui.QDialog): layout.addWidget(self.buttons) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) + self.editor.selectionChanged.connect(self.hightlightpath) + self.finished.connect(self.cleanup) + + def cleanup(self): + FreeCAD.ActiveDocument.removeObject(self.selectionobj.Name) + + def hightlightpath(self): + cursor = self.editor.textCursor() + sp = cursor.selectionStart() + ep = cursor.selectionEnd() + cursor.setPosition(sp) + startrow = cursor.blockNumber() + cursor.setPosition(ep) + endrow = cursor.blockNumber() + + commands = self.PathObj.Commands + + #Derive the starting position for the first selected command + prevX = prevY = prevZ = None + prevcommands = commands[:startrow] + prevcommands.reverse() + for c in prevcommands: + if prevX is None: + if c.Parameters.get("X") is not None: + prevX = c.Parameters.get("X") + if prevY is None: + if c.Parameters.get("Y") is not None: + prevY = c.Parameters.get("Y") + if prevZ is None: + if c.Parameters.get("Z") is not None: + prevZ = c.Parameters.get("Z") + if prevX is not None and prevY is not None and prevZ is not None: + break + if prevX is None: + prevX = 0.0 + if prevY is None: + prevY = 0.0 + if prevZ is None: + prevZ = 0.0 + + #Build a new path with selection + p = Path.Path() + firstrapid = Path.Command("G0", {"X": prevX, "Y":prevY, "Z":prevZ}) + + selectionpath = [firstrapid] + commands[startrow:endrow +1] + p.Commands = selectionpath + self.selectionobj.Path = p def show(obj): @@ -147,7 +204,7 @@ def show(obj): if hasattr(obj, "Path"): if obj.Path: - dia = GCodeEditorDialog() + dia = GCodeEditorDialog(obj.Path) dia.editor.setText(obj.Path.toGCode()) result = dia.exec_() # exec_() returns 0 or 1 depending on the button pressed (Ok or