Skip to content

Commit

Permalink
[Draft] Edit: preview node with mouseover
Browse files Browse the repository at this point in the history
Preview editing nodes with mouse move.
Modified edit trackers to store in self.color the value. Also added a method to it to set color.
  • Loading branch information
carlopav authored and yorikvanhavre committed Oct 17, 2019
1 parent d599de4 commit f3f15b1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
29 changes: 27 additions & 2 deletions src/Mod/Draft/DraftEdit.py
Expand Up @@ -41,6 +41,20 @@
from PySide import QtCore
from PySide.QtCore import QT_TRANSLATE_NOOP
from DraftTools import translate

COLORS = {
"default": FreeCADGui.draftToolBar.getDefaultColor("snap"),
"black": (0., 0., 0.),
"white": (1., 1., 1.),
"grey": (.5, .5, .5),
"red": (1., 0., 0.),
"green": (0., 1., 0.),
"blue": (0., 0., 1.),
"yellow": (1., 1., 0.),
"cyan": (0., 1., 1.),
"magenta":(1., 0., 1.)
}


class Edit():

Expand All @@ -49,6 +63,7 @@ class Edit():
def __init__(self):
self.running = False
self.trackers = {'object':[]}
self.overNode = None # preselected node with mouseover
self.obj = None
self.editing = None

Expand Down Expand Up @@ -271,8 +286,18 @@ def mouseMoved(self, event_callback):
if self.editing != None:
self.updateTrackerAndGhost(event)
else:
# TODO add preselection color change for trackers
pass
# look for a node in mouse position and highlight it
pos = event.getPosition()
node = self.getEditNode(pos)
ep = self.getEditNodeIndex(node)
if ep != None:
if self.overNode != None: self.overNode.setColor(COLORS["default"])
self.trackers[str(node.objectName.getValue())][ep].setColor(COLORS["red"])
self.overNode = self.trackers[str(node.objectName.getValue())][ep]
else:
if self.overNode != None:
self.overNode.setColor(COLORS["default"])
self.overNode = None

def startEditing(self, event):
"start editing selected EditNode"
Expand Down
14 changes: 10 additions & 4 deletions src/Mod/Draft/DraftTrackers.py
Expand Up @@ -709,11 +709,11 @@ class editTracker(Tracker):
"""A node edit tracker"""
def __init__(self,pos=Vector(0,0,0),name=None,idx=0,objcol=None,\
marker=FreeCADGui.getMarkerIndex("quad", 9),inactive=False):
color = coin.SoBaseColor()
self.color = coin.SoBaseColor()
if objcol:
color.rgb = objcol[:3]
self.color.rgb = objcol[:3]
else:
color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap")
self.color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap")
self.marker = coin.SoMarkerSet() # this is the marker symbol
self.marker.markerIndex = marker
self.coords = coin.SoCoordinate3() # this is the coordinate
Expand All @@ -729,7 +729,7 @@ def __init__(self,pos=Vector(0,0,0),name=None,idx=0,objcol=None,\
selnode.subElementName.setValue("EditNode"+str(idx))
node = coin.SoAnnotation()
selnode.addChild(self.coords)
selnode.addChild(color)
selnode.addChild(self.color)
selnode.addChild(self.marker)
node.addChild(selnode)
ontop = not inactive
Expand All @@ -746,6 +746,12 @@ def get(self):
def move(self,delta):
self.set(self.get().add(delta))

def setColor(self,color):
if color:
self.color.rgb = color
else:
self.color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap")

class PlaneTracker(Tracker):
"""A working plane tracker"""
def __init__(self):
Expand Down

0 comments on commit f3f15b1

Please sign in to comment.