Draft: Fixes grid on/off behaviour - fixes #5878

- If grid is on and auto grid on: Grid always appears
- If grid is on and auto grid off: Grid off at start, on when using a tool, off afterwards
- If grid is off: Grid never appears
This commit is contained in:
Yorik van Havre
2023-03-10 12:19:27 +01:00
parent 31fa8187d5
commit 53bc32b03e
5 changed files with 14 additions and 10 deletions

View File

@@ -148,7 +148,7 @@ class DraftTool:
if utils.get_param("showPlaneTracker", False):
self.planetrack = trackers.PlaneTracker()
if hasattr(Gui, "Snapper"):
Gui.Snapper.setTrackers()
Gui.Snapper.setTrackers(tool=True)
_msg("{}".format(16*"-"))
_msg("GuiCommand: {}".format(self.featureName))

View File

@@ -66,7 +66,7 @@ class ToggleGrid(gui_base.GuiCommandSimplest):
super(ToggleGrid, self).Activated()
if hasattr(Gui, "Snapper"):
Gui.Snapper.setTrackers()
Gui.Snapper.setTrackers(tool=True)
if Gui.Snapper.grid:
if Gui.Snapper.grid.Visible:
Gui.Snapper.grid.off()

View File

@@ -139,7 +139,7 @@ class Line(gui_base_original.Creator):
if self.oldWP:
App.DraftWorkingPlane.setFromParameters(self.oldWP)
if hasattr(Gui, "Snapper"):
Gui.Snapper.setGrid()
Gui.Snapper.setGrid(tool=True)
Gui.Snapper.restack()
self.oldWP = None

View File

@@ -1594,15 +1594,15 @@ class Snapper:
self.toolbar.toggleViewAction().setVisible(False)
def setGrid(self):
def setGrid(self, tool=False):
"""Set the grid, if visible."""
self.setTrackers()
if self.grid and (not self.forceGridOff):
if self.grid.Visible:
self.grid.set()
self.grid.set(tool)
def setTrackers(self):
def setTrackers(self, tool=False):
"""Set the trackers."""
v = Draft.get3DView()
if v and (v != self.activeview):
@@ -1620,7 +1620,10 @@ class Snapper:
else:
if Draft.getParam("grid", True):
self.grid = trackers.gridTracker()
self.grid.on()
if Draft.getParam("alwaysShowGrid", True) or tool:
self.grid.on()
else:
self.grid.off()
else:
self.grid = None
self.tracker = trackers.snapTracker()
@@ -1651,7 +1654,7 @@ class Snapper:
self.activeview = v
if self.grid and (not self.forceGridOff):
self.grid.set()
self.grid.set(tool)
def addHoldPoint(self):

View File

@@ -1216,7 +1216,7 @@ class gridTracker(Tracker):
self.numlines = Draft.getParam("gridSize", 100)
self.update()
def set(self):
def set(self,tool=False):
"""Move and rotate the grid according to the current working plane."""
self.reset()
Q = FreeCAD.DraftWorkingPlane.getRotation().Rotation.Q
@@ -1225,7 +1225,8 @@ class gridTracker(Tracker):
self.trans.translation.setValue([P.x, P.y, P.z])
self.displayHumanFigure()
self.setAxesColor()
self.on()
if tool:
self.on()
def getClosestNode(self, point):
"""Return the closest node from the given point."""