diff --git a/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui b/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui index 973e0aca8d..d44e89982d 100644 --- a/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui +++ b/src/Mod/Draft/Resources/ui/preferences-draftsnap.ui @@ -247,38 +247,18 @@ - + - If checked, the Snap toolbar will be shown whenever you use snapping + If checked, the Snap toolbar will only be visible during commands - Show Draft snap toolbar + Only show the Draft snap toolbar during commands - true + false - showSnapBar - - - Mod/Draft - - - - - - - - - - - true - - - If checked, the Draft snap toolbar is hidden after use - - - hideSnapBar + SnapBarShowOnlyDuringCommands Mod/Draft @@ -402,7 +382,7 @@ if they match the X, Y or Z axis of the global coordinate system - + @@ -448,7 +428,7 @@ if they match the X, Y or Z axis of the global coordinate system - + @@ -503,7 +483,7 @@ if they match the X, Y or Z axis of the global coordinate system - + @@ -555,7 +535,7 @@ if they match the X, Y or Z axis of the global coordinate system - + @@ -636,7 +616,7 @@ if they match the X, Y or Z axis of the global coordinate system - + @@ -694,7 +674,7 @@ if they match the X, Y or Z axis of the global coordinate system - + @@ -811,12 +791,6 @@ if they match the X, Y or Z axis of the global coordinate system comboBox_modsnap setDisabled(bool) - - checkBox_showSnapBar - toggled(bool) - checkBox_hideSnapBar - setEnabled(bool) - checkBox_alwaysShowGrid toggled(bool) diff --git a/src/Mod/Draft/draftguitools/gui_snapper.py b/src/Mod/Draft/draftguitools/gui_snapper.py index 6b3821eb25..ab9b305787 100644 --- a/src/Mod/Draft/draftguitools/gui_snapper.py +++ b/src/Mod/Draft/draftguitools/gui_snapper.py @@ -244,7 +244,7 @@ class Snapper: self.spoint = None - if Draft.getParam("showSnapBar", True): + if Draft.getParam("SnapBarShowOnlyDuringCommands", False): toolbar = self.get_snap_toolbar() if toolbar: toolbar.show() @@ -1213,7 +1213,7 @@ class Snapper: self.grid.lowerTracker() - def off(self, hideSnapBar=False): + def off(self): """Finish snapping.""" if self.tracker: self.tracker.off() @@ -1238,7 +1238,7 @@ class Snapper: self.unconstrain() self.radius = 0 self.setCursor() - if hideSnapBar or Draft.getParam("hideSnapBar", False): + if Draft.getParam("SnapBarShowOnlyDuringCommands", False): toolbar = self.get_snap_toolbar() if toolbar: toolbar.hide() @@ -1486,31 +1486,12 @@ class Snapper: def get_snap_toolbar(self): """Get the snap toolbar.""" - if not (hasattr(self, "toolbar") and self.toolbar): mw = Gui.getMainWindow() self.toolbar = mw.findChild(QtGui.QToolBar, "Draft snap") if self.toolbar: - # Make sure the Python generated BIM snap toolbar shows up in the - # toolbar area context menu after switching back to that workbench: - self.toolbar.toggleViewAction().setVisible(True) return self.toolbar - # Code required for the BIM workbench which has to work with FC0.20 - # and FC0.21/1.0. The code relies on the Snapping menu in the BIM WB - # to create the actions. - self.toolbar = QtGui.QToolBar(mw) - mw.addToolBar(QtCore.Qt.TopToolBarArea, self.toolbar) - self.toolbar.setObjectName("Draft snap") - self.toolbar.setWindowTitle(translate("Workbench", "Draft snap")) - for cmd in get_draft_snap_commands(): - if cmd == "Separator": - self.toolbar.addSeparator() - else: - action = Gui.Command.get(cmd).getAction()[0] - self.toolbar.addAction(action) - return self.toolbar - def toggleGrid(self): """Toggle FreeCAD Draft Grid.""" @@ -1593,24 +1574,12 @@ class Snapper: def show(self): - """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() + """Show the grid in all 3D views where it was previously visible.""" self.show_hide_grids(show=True) def hide(self): - """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) + """Hide the grid in all 3D views.""" self.show_hide_grids(show=False) diff --git a/src/Mod/Draft/draftguitools/gui_snaps.py b/src/Mod/Draft/draftguitools/gui_snaps.py index f09df543cc..651469771b 100644 --- a/src/Mod/Draft/draftguitools/gui_snaps.py +++ b/src/Mod/Draft/draftguitools/gui_snaps.py @@ -282,7 +282,9 @@ class ShowSnapBar(Draft_Snap_Base): def Activated(self): """Execute when the command is called.""" if hasattr(Gui, "Snapper"): - Gui.Snapper.show() + toolbar = Gui.Snapper.get_snap_toolbar() + if toolbar is not None: + toolbar.show() Gui.addCommand('Draft_ShowSnapBar', ShowSnapBar()) diff --git a/src/Mod/Draft/draftutils/params.py b/src/Mod/Draft/draftutils/params.py index 7821a9a4fa..7ebbb80e7c 100644 --- a/src/Mod/Draft/draftutils/params.py +++ b/src/Mod/Draft/draftutils/params.py @@ -32,6 +32,7 @@ from draftutils import utils from draftutils.translate import translate from draftviewproviders import view_base + class ParamObserver: def slotParamChanged(self, param, tp, name, value): @@ -39,6 +40,9 @@ class ParamObserver: "gridSpacing", "gridSize", "gridTransparency", "gridColor"): _param_observer_callback_grid() return + if name == "SnapBarShowOnlyDuringCommands": + _param_observer_callback_snapbar(value) + return if name == "DisplayStatusbarSnapWidget": _param_observer_callback_snapwidget() return @@ -73,28 +77,26 @@ def _param_observer_callback_grid(): pass +def _param_observer_callback_snapbar(value): + # value is a string: "0" or "1" + if Gui.activeWorkbench().name() not in ("DraftWorkbench", "ArchWorkbench", "BIMWorkbench"): + return + if hasattr(Gui, "Snapper"): + toolbar = Gui.Snapper.get_snap_toolbar() + if toolbar is not None: + toolbar.setVisible(value == "0") + + def _param_observer_callback_snapwidget(): if Gui.activeWorkbench().name() == "DraftWorkbench": init_draft_statusbar.hide_draft_statusbar() init_draft_statusbar.show_draft_statusbar() - return - msg = translate("draft", -"""The Snap widget is only available in the Draft Workbench. -Switch to that workbench to see the result of this change.""") - QtGui.QMessageBox.information(None, "Update Draft statusbar widget", msg, - QtGui.QMessageBox.Ok) def _param_observer_callback_scalewidget(): if Gui.activeWorkbench().name() == "DraftWorkbench": init_draft_statusbar.hide_draft_statusbar() init_draft_statusbar.show_draft_statusbar() - return - msg = translate("draft", -"""The Annotation scale widget is only available in the Draft Workbench. -Switch to that workbench to see the result of this change.""") - QtGui.QMessageBox.information(None, "Update Draft statusbar widget", msg, - QtGui.QMessageBox.Ok) def _param_observer_callback_snapstyle(): @@ -112,6 +114,27 @@ def _param_observer_callback_svg_pattern(): utils.load_svg_patterns() if App.ActiveDocument is None: return + + pats = list(utils.svg_patterns()) + pats.sort() + pats = ["None"] + pats + + data = [] + for doc in App.listDocuments().values(): + vobjs = [] + for obj in doc.Objects: + if hasattr(obj, "ViewObject"): + vobj = obj.ViewObject + if hasattr(vobj, "Pattern") \ + and hasattr(vobj, "Proxy") \ + and isinstance(vobj.Proxy, view_base.ViewProviderDraft) \ + and vobj.getEnumerationsOfProperty("Pattern") != pats: + vobjs.append(vobj) + if vobjs: + data.append([doc, vobjs]) + if not data: + return + msg = translate("draft", """Do you want to update the SVG pattern options of existing objects in all opened documents?""") @@ -120,25 +143,18 @@ of existing objects in all opened documents?""") QtGui.QMessageBox.No) if res == QtGui.QMessageBox.No: return - pats = list(utils.svg_patterns()) - pats.sort() - pats = ["None"] + pats - for doc in App.listDocuments().values(): + + for doc, vobjs in data: doc.openTransaction("SVG pattern update") - for obj in doc.Objects: - if hasattr(obj, "ViewObject") \ - and hasattr(obj.ViewObject, "Pattern") \ - and hasattr(obj.ViewObject, "Proxy") \ - and isinstance(obj.ViewObject.Proxy, view_base.ViewProviderDraft): - vobj = obj.ViewObject - old = vobj.Pattern - if old in pats: - vobj.Pattern = pats - else: - tmp_pats = [old] + pats[1:] - tmp_pats.sort() - vobj.Pattern = ["None"] + tmp_pats - vobj.Pattern = old + for vobj in vobjs: + old = vobj.Pattern + if old in pats: + vobj.Pattern = pats + else: + tmp_pats = [old] + pats[1:] + tmp_pats.sort() + vobj.Pattern = ["None"] + tmp_pats + vobj.Pattern = old doc.commitTransaction() diff --git a/src/Mod/Draft/draftutils/utils.py b/src/Mod/Draft/draftutils/utils.py index e811d5daf0..4dd6681524 100644 --- a/src/Mod/Draft/draftutils/utils.py +++ b/src/Mod/Draft/draftutils/utils.py @@ -185,8 +185,8 @@ def get_param_type(param): return "float" elif param in ("selectBaseObjects", "alwaysSnap", "grid", "fillmode", "maxSnap", "DimShowLine", - "SvgLinesBlack", "dxfStdSize", "showSnapBar", - "hideSnapBar", "alwaysShowGrid", "renderPolylineWidth", + "SvgLinesBlack", "dxfStdSize", "SnapBarShowOnlyDuringCommands", + "alwaysShowGrid", "renderPolylineWidth", "showPlaneTracker", "UsePartPrimitives", "DiscretizeEllipses", "showUnit", "coloredGridAxes", "Draft_array_fuse", "Draft_array_Link", "gridBorder"):