Skip to content

Commit

Permalink
Draft: Don't snap to ImagePlanes
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Jan 12, 2021
1 parent c745f4e commit d7d20ba
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/Mod/Draft/draftguitools/gui_snapper.py
Expand Up @@ -57,6 +57,7 @@
__author__ = "Yorik van Havre"
__url__ = "https://www.freecadweb.org"

UNSNAPPABLES = ('Image::ImagePlane',)

class Snapper:
"""Classes to manage snapping in Draft and Arch.
Expand Down Expand Up @@ -125,7 +126,7 @@ def __init__(self):

# snap keys, it's important that they are in this order for
# saving in preferences and for properly restoring the toolbar
self.snaps = ['Lock', # 0
self.snaps = ['Lock', # 0
'Near', # 1 former "passive" snap
'Extension', # 2
'Parallel', # 3
Expand Down Expand Up @@ -311,6 +312,8 @@ def snap(self, screenpos,
point, eline = self.snapToExtensions(point, lastpoint,
constrain, eline)

# Check if we have an object under the cursor and try to
# snap to it
_view = Draft.get3DView()
objectsUnderCursor = _view.getObjectsInfo((screenpos[0], screenpos[1]))
if objectsUnderCursor:
Expand All @@ -319,8 +322,10 @@ def snap(self, screenpos,
self.snapInfo = objectsUnderCursor[self.snapObjectIndex]

if self.snapInfo and "Component" in self.snapInfo:
return self.snapToObject(lastpoint, active, constrain,
osnap = self.snapToObject(lastpoint, active, constrain,
eline, point, oldActive)
if osnap:
return osnap

# Nothing has been snapped.
# Check for grid snap and ext crossings
Expand Down Expand Up @@ -352,6 +357,7 @@ def cycleSnapObject(self):
def snapToObject(self, lastpoint, active, constrain,
eline, point, oldActive):
"""Snap to an object."""

parent = self.snapInfo.get('ParentObject', None)
if parent:
subname = self.snapInfo['SubName']
Expand All @@ -368,6 +374,9 @@ def snapToObject(self, lastpoint, active, constrain,
snaps = []
self.lastSnappedObject = obj

if obj and (Draft.getType(obj) in UNSNAPPABLES):
return []

if hasattr(obj.ViewObject, "Selectable"):
if not obj.ViewObject.Selectable:
self.spoint = self.cstr(lastpoint, constrain, point)
Expand Down Expand Up @@ -609,9 +618,9 @@ def snapToExtensions(self, point, last, constrain, eline):
self.setCursor(tsnap[1])
return tsnap[2], eline

for o in (self.lastObj[1], self.lastObj[0]):
if o and (self.isEnabled('Extension')
or self.isEnabled('Parallel')):
for o in (self.lastObj[1], self.lastObj[0]):
if o and (self.isEnabled('Extension')
or self.isEnabled('Parallel')):
ob = App.ActiveDocument.getObject(o)
if not ob:
continue
Expand Down Expand Up @@ -1480,8 +1489,8 @@ def init_draft_snap_buttons(self, commands, context, button_suffix):
Parameters:
commands Snap command list,
use: get_draft_snap_commands():
context The toolbar or action group the buttons have
to be added to
context The toolbar or action group the buttons have
to be added to
button_suffix The suffix that have to be applied to the command name
to define the button name
"""
Expand All @@ -1492,7 +1501,7 @@ def init_draft_snap_buttons(self, commands, context, button_suffix):
gb = self.init_grid_button(self.toolbar)
context.addAction(gb)
QtCore.QObject.connect(gb, QtCore.SIGNAL("triggered()"),
lambda f=Gui.doCommand,
lambda f=Gui.doCommand,
arg='Gui.runCommand("Draft_ToggleGrid")':f(arg))
continue
# setup toolbar buttons
Expand All @@ -1508,7 +1517,7 @@ def init_draft_snap_buttons(self, commands, context, button_suffix):
context.addAction(b)
QtCore.QObject.connect(b,
QtCore.SIGNAL("triggered()"),
lambda f=Gui.doCommand,
lambda f=Gui.doCommand,
arg=command:f(arg))

for b in context.actions():
Expand All @@ -1520,7 +1529,7 @@ def init_grid_button(self, context):
"""Add grid button to the given toolbar"""
b = QtGui.QAction(context)
b.setIcon(QtGui.QIcon.fromTheme("Draft", QtGui.QIcon(":/icons/"
"Draft_Grid.svg")))
"Draft_Grid.svg")))
b.setText(QtCore.QCoreApplication.translate("Draft_Snap", "Toggles Grid On/Off"))
b.setToolTip(QtCore.QCoreApplication.translate("Draft_Snap", "Toggle Draft Grid"))
b.setObjectName("Grid_Button")
Expand Down Expand Up @@ -1703,7 +1712,7 @@ def setTrackers(self):
self.trackers[8].append(self.extLine2)
self.trackers[9].append(self.holdTracker)
self.activeview = v

if self.grid and (not self.forceGridOff):
self.grid.set()

Expand Down

0 comments on commit d7d20ba

Please sign in to comment.