Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
PATH: Inspect editor now preserves last size and position
  • Loading branch information
brad committed Jun 8, 2019
1 parent 89e1824 commit f549550
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions src/Mod/Path/PathScripts/PathInspect.py
Expand Up @@ -27,26 +27,11 @@
import FreeCADGui
import Path


# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)

# class OldHighlighter(QtGui.QSyntaxHighlighter):

# def highlightBlock(self, text):

# myClassFormat = QtGui.QTextCharFormat()
# myClassFormat.setFontWeight(QtGui.QFont.Bold)
# myClassFormat.setForeground(QtCore.Qt.green)
# # the regex pattern to be colored
# pattern = "(G.*?|M.*?)\\s"
# expression = QtCore.QRegExp(pattern)
# index = text.index(expression)
# while index >= 0:
# length = expression.matchedLength()
# setFormat(index, length, myClassFormat)
# index = text.index(expression, index + length)


class GCodeHighlighter(QtGui.QSyntaxHighlighter):

Expand Down Expand Up @@ -110,11 +95,11 @@ def __init__(self, PathObj, parent=FreeCADGui.getMainWindow()):
layout = QtGui.QVBoxLayout(self)

p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
c = p.GetUnsigned("DefaultHighlightPathColor", 4286382335 )
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.)
highlightcolor = (Q.red() / 255., Q.green() / 255., Q.blue() / 255., Q.alpha() / 255.)

self.selectionobj = FreeCAD.ActiveDocument.addObject("Path::Feature","selection")
self.selectionobj = FreeCAD.ActiveDocument.addObject("Path::Feature", "selection")
self.selectionobj.ViewObject.LineWidth = 4
self.selectionobj.ViewObject.NormalColor = highlightcolor

Expand Down Expand Up @@ -146,7 +131,20 @@ def __init__(self, PathObj, parent=FreeCADGui.getMainWindow()):
self.editor.selectionChanged.connect(self.highlightpath)
self.finished.connect(self.cleanup)

prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
Xpos = int(prefs.GetString('inspecteditorX', "0"))
Ypos = int(prefs.GetString('inspecteditorY', "0"))
height = int(prefs.GetString('inspecteditorH', "500"))
width = int(prefs.GetString('inspecteditorW', "600"))
self.move(Xpos, Ypos)
self.resize(width, height)

def cleanup(self):
prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
prefs.SetString('inspecteditorX', str(self.x()))
prefs.SetString('inspecteditorY', str(self.y()))
prefs.SetString('inspecteditorW', str(self.width()))
prefs.SetString('inspecteditorH', str(self.height()))
FreeCAD.ActiveDocument.removeObject(self.selectionobj.Name)

def highlightpath(self):
Expand All @@ -160,7 +158,7 @@ def highlightpath(self):

commands = self.PathObj.Commands

#Derive the starting position for the first selected command
# Derive the starting position for the first selected command
prevX = prevY = prevZ = None
prevcommands = commands[:startrow]
prevcommands.reverse()
Expand All @@ -183,11 +181,11 @@ def highlightpath(self):
if prevZ is None:
prevZ = 0.0

#Build a new path with selection
# Build a new path with selection
p = Path.Path()
firstrapid = Path.Command("G0", {"X": prevX, "Y":prevY, "Z":prevZ})
firstrapid = Path.Command("G0", {"X": prevX, "Y": prevY, "Z": prevZ})

selectionpath = [firstrapid] + commands[startrow:endrow +1]
selectionpath = [firstrapid] + commands[startrow:endrow + 1]
p.Commands = selectionpath
self.selectionobj.Path = p

Expand Down Expand Up @@ -231,11 +229,11 @@ def Activated(self):
selection = FreeCADGui.Selection.getSelection()
if len(selection) != 1:
FreeCAD.Console.PrintError(
translate("Path_Inspect", "Please select exactly one path object")+"\n")
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")
translate("Path_Inspect", "Please select exactly one path object") + "\n")
return

# if everything is ok, execute
Expand Down

0 comments on commit f549550

Please sign in to comment.