diff --git a/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui b/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui
index 0fb8a0d076..973e0aca8d 100644
--- a/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui
+++ b/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui
@@ -30,20 +30,20 @@
9
-
-
+
Snapping
-
+
-
-
+
-
-
+
- If this is checked, snapping is activated without the need to press the snap mod key
+ If checked, snapping is activated without the need to press the Snap mod key
- Always snap (disable snap mod)
+ Always snap
true
@@ -59,29 +59,102 @@
-
-
+
-
-
+
+
+ false
+
- Constrain mod
+ Snap mod
-
-
+
Qt::Horizontal
40
- 20
+ 0
-
-
+
+
+
+ 140
+ 0
+
+
+
+ false
+
+
+ The Snap modifier key
+
+
+ 1
+
+
+ modsnap
+
+
+ Mod/Draft
+
+
-
+
+ Shift
+
+
+ -
+
+ Ctrl
+
+
+ -
+
+ Alt
+
+
+
+
+
+
+ -
+
+
-
+
+
+ Constrain mod
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 0
+
+
+
+
+ -
+
+
+
+ 140
+ 0
+
+
The Constraining modifier key
@@ -113,9 +186,9 @@
-
-
-
+
- Snap mod
+ Alt mod
@@ -127,70 +200,21 @@
40
- 20
+ 0
-
-
-
- The snap modifier key
-
-
- 1
-
-
- modsnap
-
-
- Mod/Draft
-
-
-
-
- Shift
-
-
- -
-
- Ctrl
-
-
- -
-
- Alt
-
-
-
-
-
-
- -
-
-
-
-
-
- Alt mod
-
-
-
- -
-
-
- Qt::Horizontal
-
-
+
+
- 40
- 20
+ 140
+ 0
-
-
- -
-
- The Alt modifier key
+ The Alt modifier key. The function of this key depends on the command.
2
@@ -221,14 +245,14 @@
-
-
+
-
-
+
If checked, the Snap toolbar will be shown whenever you use snapping
- Show Draft Snap toolbar
+ Show Draft snap toolbar
true
@@ -246,9 +270,12 @@
-
-
-
+
+
+ true
+
- Hide Draft snap toolbar after use
+ If checked, the Draft snap toolbar is hidden after use
hideSnapBar
@@ -261,43 +288,19 @@
-
-
-
-
-
+
Grid
-
-
+
- If checked, a grid will appear when drawing
-
-
- Use grid
-
-
- true
-
-
- grid
-
-
- Mod/Draft
-
-
-
- -
-
-
- true
-
-
- If checked, the Draft grid will always be visible when the Draft workbench is active. Otherwise only when using a command
+ If checked, the grid will always be visible in new views.
+Use Draft ToggleGrid to change this for the active view.
Always show the grid
@@ -314,7 +317,30 @@
-
-
+
+
+ false
+
+
+ If checked, the grid will be visible during commands in new views.
+Use Draft ToggleGrid to change this for the active view.
+
+
+ Show the grid during commands
+
+
+ true
+
+
+ grid
+
+
+ Mod/Draft
+
+
+
+ -
+
If checked, an additional border is displayed around the grid, showing the main square size in the bottom left border
@@ -333,9 +359,13 @@
-
-
+
+
+ true
+
- <html><head/><body><p>If checked, the outline of a human figure is displayed at the bottom left corner of the grid. This option is only effective if the BIM workbench is installed and if "Show grid border" option is enabled.</p></body></html>
+ If checked, the outline of a human figure is displayed at the bottom left corner of the grid.
+This option is only effective if the BIM workbench is installed and if Show grid border is enabled.
Show human figure
@@ -352,9 +382,10 @@
-
-
+
- If set, the grid will have its two main axes colored in red, green or blue when they match global axes
+ If checked, the two main axes of the grid will be colored red, green or blue
+if they match the X, Y or Z axis of the global coordinate system
Use colored axes
@@ -371,40 +402,37 @@
-
-
+
-
-
-
- true
-
+
Main lines every
-
-
+
Qt::Horizontal
40
- 20
+ 0
-
-
-
- true
+
+
+
+ 140
+ 0
+
- Mainlines will be drawn thicker. Specify here how many squares between mainlines.
-
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+ The number of squares between main grid lines. These lines are thicker than normal grid lines.
10
@@ -420,40 +448,37 @@
-
-
+
-
-
-
- true
-
+
Grid spacing
-
-
+
Qt::Horizontal
40
- 20
+ 0
-
-
-
- true
+
+
+
+ 140
+ 0
+
- The spacing between each grid line
-
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+ The distance between grid lines
4
@@ -478,34 +503,37 @@
-
-
+
-
-
+
Grid size
-
-
+
Qt::Horizontal
40
- 20
+ 0
-
-
-
- The number of horizontal or vertical lines of the grid
+
+
+
+ 140
+ 0
+
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+ The number of horizontal and vertical lines of the grid
lines
@@ -527,29 +555,35 @@
-
-
+
-
-
+
Grid color and transparency
-
-
+
Qt::Horizontal
40
- 20
+ 0
-
-
+
+
+
+ 0
+ 0
+
+
The color of the grid
@@ -569,7 +603,13 @@
-
-
+
+
+
+ 140
+ 0
+
+
The overall transparency of the grid
@@ -590,61 +630,46 @@
-
-
-
- Draft Edit preferences
-
+
Edit
-
+
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
+
-
-
+
- Maximum number of contemporary edited objects
+ Maximum number of objects for Draft Edit
-
-
+
Qt::Horizontal
40
- 20
+ 0
-
-
-
- true
+
+
+
+ 140
+ 0
+
- <html><head/><body><p>Sets the maximum number of objects Draft Edit</p><p>can process at the same time</p></body></html>
-
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+ The maximum number of objects Draft Edit is allowed to process at the same time
1
@@ -669,52 +694,40 @@
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
+
-
-
+
- Draft edit pick radius
+ Pick radius for Draft Edit
-
-
+
Qt::Horizontal
40
- 20
+ 0
-
-
-
- true
+
+
+
+ 140
+ 0
+
- Controls pick radius of edit nodes
-
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+ The pick radius (in pixels) of edit nodes
1
@@ -736,13 +749,13 @@
-
-
+
Qt::Vertical
- 20
+ 0
40
@@ -787,20 +800,34 @@
- gui::prefcheckbox_7
- clicked(bool)
- gui::prefcheckbox_9
+ checkBox_alwaysSnap
+ toggled(bool)
+ label_modsnap
+ setDisabled(bool)
+
+
+ checkBox_alwaysSnap
+ toggled(bool)
+ comboBox_modsnap
+ setDisabled(bool)
+
+
+ checkBox_showSnapBar
+ toggled(bool)
+ checkBox_hideSnapBar
+ setEnabled(bool)
+
+
+ checkBox_alwaysShowGrid
+ toggled(bool)
+ checkBox_grid
+ setDisabled(bool)
+
+
+ checkBox_gridBorder
+ toggled(bool)
+ checkBox_gridShowHuman
setEnabled(bool)
-
-
- 158
- 290
-
-
- 400
- 293
-
-
diff --git a/src/Mod/Draft/draftguitools/gui_edit.py b/src/Mod/Draft/draftguitools/gui_edit.py
index 9759d15b83..67d4569551 100644
--- a/src/Mod/Draft/draftguitools/gui_edit.py
+++ b/src/Mod/Draft/draftguitools/gui_edit.py
@@ -335,8 +335,6 @@ class Edit(gui_base_original.Modifier):
self.deformat_objects_after_editing(self.edited_objects)
super(Edit, self).finish()
- if Gui.Snapper.grid:
- Gui.Snapper.grid.set()
self.running = False
# delay resetting edit mode otherwise it doesn't happen
from PySide import QtCore
diff --git a/src/Mod/Draft/draftguitools/gui_grid.py b/src/Mod/Draft/draftguitools/gui_grid.py
index 0173dd8dc2..e5a3d2127d 100644
--- a/src/Mod/Draft/draftguitools/gui_grid.py
+++ b/src/Mod/Draft/draftguitools/gui_grid.py
@@ -31,9 +31,11 @@
# @{
from PySide.QtCore import QT_TRANSLATE_NOOP
+import FreeCAD as App
import FreeCADGui as Gui
-import draftguitools.gui_base as gui_base
+import WorkingPlane
+from draftguitools import gui_base
from draftutils.translate import translate
@@ -48,34 +50,42 @@ class ToggleGrid(gui_base.GuiCommandSimplest):
"""
def __init__(self):
- super(ToggleGrid, self).__init__(name=translate("draft","Toggle grid"))
+ super().__init__(name=translate("draft", "Toggle grid"))
def GetResources(self):
"""Set icon, menu and tooltip."""
- d = {'Pixmap': 'Draft_Grid',
- 'Accel': "G,R",
- 'MenuText': QT_TRANSLATE_NOOP("Draft_ToggleGrid","Toggle grid"),
- 'ToolTip': QT_TRANSLATE_NOOP("Draft_ToggleGrid","Toggles the Draft grid on and off."),
- 'CmdType': 'ForEdit'}
-
- return d
+ return {"Pixmap": "Draft_Grid",
+ "Accel": "G, R",
+ "MenuText": QT_TRANSLATE_NOOP("Draft_ToggleGrid", "Toggle grid"),
+ "ToolTip": QT_TRANSLATE_NOOP("Draft_ToggleGrid",
+ "Toggles the Draft grid on and off."),
+ "CmdType": "ForEdit"}
def Activated(self):
"""Execute when the command is called."""
- super(ToggleGrid, self).Activated()
+ super().Activated()
- if hasattr(Gui, "Snapper"):
- Gui.Snapper.setTrackers(tool=True)
- if Gui.Snapper.grid:
- if Gui.Snapper.grid.Visible:
- Gui.Snapper.grid.off()
- Gui.Snapper.forceGridOff = True
- else:
- Gui.Snapper.grid.on()
- Gui.Snapper.forceGridOff = False
+ if not hasattr(Gui, "Snapper"):
+ return
+ Gui.Snapper.setTrackers(update_grid=False)
+ grid = Gui.Snapper.grid
+ # This command is never set as App.activeDraftCommand.
+ cmdactive = hasattr(App, "activeDraftCommand") and App.activeDraftCommand
+ if grid.Visible:
+ grid.off()
+ grid.show_always = False
+ if cmdactive:
+ grid.show_during_command = False
+ elif cmdactive:
+ grid.on()
+ grid.show_during_command = True
+ else:
+ grid.on()
+ WorkingPlane.get_working_plane()
+ grid.show_always = True
-Gui.addCommand('Draft_ToggleGrid', ToggleGrid())
+Gui.addCommand("Draft_ToggleGrid", ToggleGrid())
## @}
diff --git a/src/Mod/Draft/draftguitools/gui_snapper.py b/src/Mod/Draft/draftguitools/gui_snapper.py
index a541b3aebd..847b865e99 100644
--- a/src/Mod/Draft/draftguitools/gui_snapper.py
+++ b/src/Mod/Draft/draftguitools/gui_snapper.py
@@ -53,6 +53,7 @@ import draftguitools.gui_trackers as trackers
from draftutils.init_tools import get_draft_snap_commands
from draftutils.messages import _wrn
from draftutils.translate import translate
+from draftutils.todo import ToDo
__title__ = "FreeCAD Draft Snap tools"
__author__ = "Yorik van Havre"
@@ -109,7 +110,6 @@ class Snapper:
self.snapInfo = None
self.lastSnappedObject = None
self.active = True
- self.forceGridOff = False
self.lastExtensions = []
# the trackers are stored in lists because there can be several views,
# each with its own set
@@ -1228,7 +1228,7 @@ class Snapper:
if self.dim2:
self.dim2.off()
if self.grid:
- if not Draft.getParam("alwaysShowGrid", True):
+ if self.grid.show_always is False:
self.grid.off()
if self.holdTracker:
self.holdTracker.clear()
@@ -1563,44 +1563,58 @@ class Snapper:
param.SetString("snapModes",snap_modes)
+ def show_hide_grids(self, show=True):
+ """Show the grid in all 3D views where it was previously visible, or
+ hide the grid in all 3D view. Used when switching to different workbenches.
+
+ Hiding the grid can be prevented by setting the GridHideInOtherWorkbenches
+ preference to `False`.
+ """
+ param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
+ if (not show) and (not param.GetBool("GridHideInOtherWorkbenches", True)):
+ return
+ mw = Gui.getMainWindow()
+ views = mw.getWindowsOfType(App.Base.TypeId.fromName("Gui::View3DInventor")) # All 3D views.
+ for view in views:
+ if view in self.trackers[0]:
+ i = self.trackers[0].index(view)
+ grid = self.trackers[1][i]
+ if show and grid.show_always:
+ grid.on()
+ else:
+ grid.off()
+
+
def show(self):
- """Show the toolbar and the grid."""
+ """Show the toolbar, show the grid in all 3D views where it was
+ previously visible, and start the trackers for the active 3D view
+ if it is `tracker-less`.
+ """
toolbar = self.get_snap_toolbar()
if toolbar:
if Draft.getParam("showSnapBar", True):
toolbar.show()
else:
toolbar.hide()
-
- if Gui.ActiveDocument:
- self.setTrackers()
- if not App.ActiveDocument.Objects:
- if Gui.ActiveDocument.ActiveView:
- if Gui.ActiveDocument.ActiveView.getCameraType() == 'Orthographic':
- c = Gui.ActiveDocument.ActiveView.getCameraNode()
- if c.orientation.getValue().getValue() == (0.0, 0.0, 0.0, 1.0):
- p = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
- h = p.GetInt("defaultCameraHeight",0)
- if h:
- c.height.setValue(h)
+ self.show_hide_grids(show=True)
def hide(self):
- """Hide the toolbar."""
+ """Hide the toolbar and hide the grid in all 3D views."""
if hasattr(self, "toolbar") and self.toolbar:
self.toolbar.hide()
self.toolbar.toggleViewAction().setVisible(False)
+ self.show_hide_grids(show=False)
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(tool)
+ if self.grid.Visible:
+ self.grid.set(tool)
- def setTrackers(self, tool=False):
+ def setTrackers(self, tool=False, update_grid=True):
"""Set the trackers."""
v = Draft.get3DView()
if v and (v != self.activeview):
@@ -1616,14 +1630,11 @@ class Snapper:
self.extLine2 = self.trackers[8][i]
self.holdTracker = self.trackers[9][i]
else:
+ self.grid = trackers.gridTracker()
+ if Draft.getParam("alwaysShowGrid", True):
+ self.grid.show_always = True
if Draft.getParam("grid", True):
- self.grid = trackers.gridTracker()
- if Draft.getParam("alwaysShowGrid", True) or tool:
- self.grid.on()
- else:
- self.grid.off()
- else:
- self.grid = None
+ self.grid.show_during_command = True
self.tracker = trackers.snapTracker()
self.trackLine = trackers.lineTracker()
if self.snapStyle:
@@ -1651,8 +1662,14 @@ class Snapper:
self.trackers[9].append(self.holdTracker)
self.activeview = v
- if tool and self.grid and (not self.forceGridOff):
- self.grid.set(tool)
+ if not update_grid:
+ return
+
+ if self.grid.show_always \
+ or (self.grid.show_during_command \
+ and hasattr(App, "activeDraftCommand") \
+ and App.activeDraftCommand):
+ self.grid.set()
def addHoldPoint(self):
diff --git a/src/Mod/Draft/draftguitools/gui_trackers.py b/src/Mod/Draft/draftguitools/gui_trackers.py
index a54ffed8ba..312aaa5625 100644
--- a/src/Mod/Draft/draftguitools/gui_trackers.py
+++ b/src/Mod/Draft/draftguitools/gui_trackers.py
@@ -1065,6 +1065,8 @@ class gridTracker(Tracker):
s.addChild(texts)
super().__init__(children=[s], name="gridTracker")
+ self.show_during_command = False
+ self.show_always = False
self.reset()
def getGridColor(self):
@@ -1245,8 +1247,7 @@ class gridTracker(Tracker):
self.trans.translation.setValue([P.x, P.y, P.z])
self.displayHumanFigure(wp)
self.setAxesColor(wp)
- if tool:
- self.on()
+ self.on()
def getClosestNode(self, point):
"""Return the closest node from the given point."""