Merge pull request #11477 from Roy-043/Draft-improved-handling-of-snap-prefs

Draft: improved handling of snap prefs
This commit is contained in:
Roy-043
2023-11-21 18:40:42 +01:00
committed by GitHub
2 changed files with 56 additions and 45 deletions

View File

@@ -94,7 +94,6 @@ class Snapper:
self.cursorMode = None
if Draft.getParam("maxSnap", 0):
self.maxEdges = Draft.getParam("maxSnapEdges", 0)
self.snapStyle = Draft.getParam("snapStyle", 0)
# we still have no 3D view when the draft module initializes
self.tracker = None
@@ -144,34 +143,7 @@ class Snapper:
]
self.init_active_snaps()
# the snapmarker has "dot","circle" and "square" available styles
if self.snapStyle:
self.mk = coll.OrderedDict([('passive', 'empty'),
('extension', 'empty'),
('parallel', 'empty'),
('grid', 'quad'),
('endpoint', 'quad'),
('midpoint', 'quad'),
('perpendicular', 'quad'),
('angle', 'quad'),
('center', 'quad'),
('ortho', 'quad'),
('intersection', 'quad'),
('special', 'quad')])
else:
self.mk = coll.OrderedDict([('passive', 'circle'),
('extension', 'circle'),
('parallel', 'circle'),
('grid', 'circle'),
('endpoint', 'dot'),
('midpoint', 'square'),
('perpendicular', 'dot'),
('angle', 'square'),
('center', 'dot'),
('ortho', 'dot'),
('intersection', 'dot'),
('special', 'dot')])
self.set_snap_style()
self.cursors = \
coll.OrderedDict([('passive', ':/icons/Draft_Snap_Near.svg'),
@@ -206,6 +178,37 @@ class Snapper:
i += 1
def set_snap_style(self):
self.snapStyle = Draft.getParam("snapStyle", 0)
# the snapmarker has "dot","circle" and "square" available styles
if self.snapStyle:
self.mk = coll.OrderedDict([('passive', 'empty'),
('extension', 'empty'),
('parallel', 'empty'),
('grid', 'quad'),
('endpoint', 'quad'),
('midpoint', 'quad'),
('perpendicular', 'quad'),
('angle', 'quad'),
('center', 'quad'),
('ortho', 'quad'),
('intersection', 'quad'),
('special', 'quad')])
else:
self.mk = coll.OrderedDict([('passive', 'circle'),
('extension', 'circle'),
('parallel', 'circle'),
('grid', 'circle'),
('endpoint', 'dot'),
('midpoint', 'square'),
('perpendicular', 'dot'),
('angle', 'square'),
('center', 'dot'),
('ortho', 'dot'),
('intersection', 'dot'),
('special', 'dot')])
def cstr(self, lastpoint, constrain, point):
"""Return constraints if needed."""
if constrain or self.mask:

View File

@@ -148,22 +148,27 @@ class snapTracker(Tracker):
"""Define Snap Mark tracker, used by tools that support snapping."""
def __init__(self):
color = coin.SoBaseColor()
color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap")
self.marker = coin.SoMarkerSet() # this is the marker symbol
self.marker.markerIndex = FreeCADGui.getMarkerIndex("", 9)
self.coords = coin.SoCoordinate3() # this is the coordinate
self.coords.point.setValue((0, 0, 0))
node = coin.SoAnnotation()
node.addChild(self.coords)
node.addChild(color)
node.addChild(self.marker)
super().__init__(children=[node], name="snapTracker")
self.setColor()
def setMarker(self, style):
"""Set the marker index."""
self.marker.markerIndex = FreeCADGui.getMarkerIndex(style, 9)
def setColor(self, color=None):
"""Set the color."""
if color is None:
self.color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap")
else:
self.color.rgb = color
def setCoords(self, point):
"""Set the coordinates to the point."""
self.coords.point.setValue((point.x, point.y, point.z))
@@ -678,14 +683,11 @@ class ghostTracker(Tracker):
else:
self.coords = coin.SoCoordinate3()
self.coords.point.setValue((obj.X, obj.Y, obj.Z))
color = coin.SoBaseColor()
color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap")
self.marker = coin.SoMarkerSet() # this is the marker symbol
self.marker.markerIndex = FreeCADGui.getMarkerIndex("quad", 9)
node = coin.SoAnnotation()
selnode = coin.SoSeparator()
selnode.addChild(self.coords)
selnode.addChild(color)
selnode.addChild(self.marker)
node.addChild(selnode)
rootsep.addChild(node)
@@ -694,6 +696,14 @@ class ghostTracker(Tracker):
self.children.append(rootsep)
super().__init__(dotted, scolor, swidth,
children=self.children, name="ghostTracker")
self.setColor()
def setColor(self, color=None):
"""Set the color."""
if color is None:
self.color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap")
else:
self.color.rgb = color
def remove(self):
"""Remove the ghost when switching to and from subelement mode."""
@@ -812,11 +822,6 @@ class editTracker(Tracker):
def __init__(self, pos=Vector(0, 0, 0), name=None, idx=0, objcol=None,
marker=FreeCADGui.getMarkerIndex("quad", 9),
inactive=False):
self.color = coin.SoBaseColor()
if objcol:
self.color.rgb = objcol[:3]
else:
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
@@ -833,12 +838,15 @@ class editTracker(Tracker):
self.selnode.subElementName.setValue("EditNode" + str(idx))
node = coin.SoAnnotation()
self.selnode.addChild(self.coords)
self.selnode.addChild(self.color)
self.selnode.addChild(self.marker)
node.addChild(self.selnode)
ontop = not inactive
super().__init__(children=[node],
ontop=ontop, name="editTracker")
if objcol is None:
self.setColor()
else:
self.setColor(objcol[:3])
self.on()
def set(self, pos):
@@ -872,12 +880,12 @@ class editTracker(Tracker):
"""Get the point and add a delta, and set the new point."""
self.set(self.get().add(delta))
def setColor(self, color):
def setColor(self, color=None):
"""Set the color."""
if color:
self.color.rgb = color
else:
if color is None:
self.color.rgb = FreeCADGui.draftToolBar.getDefaultColor("snap")
else:
self.color.rgb = color
class PlaneTracker(Tracker):