PATH: Highlighting in Inspect

This commit is contained in:
sliptonic
2016-12-11 12:43:10 -06:00
parent 8df5eb8c78
commit 7cd375073a
3 changed files with 123 additions and 21 deletions

View File

@@ -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();
}
/**

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>297</width>
<height>281</height>
<width>310</width>
<height>304</height>
</rect>
</property>
<property name="windowTitle">
@@ -204,13 +204,69 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_11">
<property name="minimumSize">
<size>
<width>182</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Path Highlight Color</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="Gui::PrefColorButton" name="DefaultHighlightPathColor">
<property name="toolTip">
<string>The default line color for new shapes</string>
</property>
<property name="color" stdset="0">
<color>
<red>255</red>
<green>125</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultHighlightPathColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
</layout>
<zorder>DefaultRapidPathColor_2</zorder>
<zorder>label_8</zorder>
<zorder>label_6</zorder>
<zorder>DefaultNormalPathColor</zorder>
<zorder>label_9</zorder>
<zorder>DefaultPathLineWidth</zorder>
<zorder>label_10</zorder>
<zorder>DefaultPathMarkerColor</zorder>
<zorder>label_7</zorder>
<zorder>DefaultRapidPathColor</zorder>
<zorder>label</zorder>
<zorder>DefaultExtentsColor</zorder>
<zorder>label_8</zorder>
<zorder>DefaultProbePathColor</zorder>
<zorder>label_11</zorder>
<zorder>DefaultHighlightPathColor</zorder>
</widget>
</item>
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>217</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
@@ -224,19 +280,6 @@
</property>
</spacer>
</item>
<item row="1" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>217</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>

View File

@@ -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