diff --git a/src/Mod/Draft/draftguitools/gui_base.py b/src/Mod/Draft/draftguitools/gui_base.py index d3f072b7d3..86cc109d88 100644 --- a/src/Mod/Draft/draftguitools/gui_base.py +++ b/src/Mod/Draft/draftguitools/gui_base.py @@ -33,7 +33,7 @@ import draftutils.todo as todo from draftutils.messages import _msg, _log -class GuiCommandSimplest: +class GuiCommandSimplest(object): """Simplest base class for GuiCommands. This class only sets up the command name and the document object @@ -126,100 +126,7 @@ class GuiCommandNeedsSelection(GuiCommandSimplest): return False -class GuiCommandSimplest: - """Simplest base class for GuiCommands. - - This class only sets up the command name and the document object - to use for the command. - When it is executed, it logs the command name to the log file, - and prints the command name to the console. - - It implements the `IsActive` method, which must return `True` - when the command should be available. - It should return `True` when there is an active document, - otherwise the command (button or menu) should be disabled. - - This class is meant to be inherited by other GuiCommand classes - to quickly log the command name, and set the correct document object. - - Parameter - --------- - name: str, optional - It defaults to `'None'`. - The name of the action that is being run, - for example, `'Heal'`, `'Flip dimensions'`, - `'Line'`, `'Circle'`, etc. - - doc: App::Document, optional - It defaults to the value of `App.activeDocument()`. - The document object itself, which indicates where the actions - of the command will be executed. - - Attributes - ---------- - command_name: str - This is the command name, which is assigned by `name`. - - doc: App::Document - This is the document object itself, which is assigned by `doc`. - - This attribute should be used by functions to make sure - that the operations are performed in the correct document - and not in other documents. - To set the active document we can use - - >>> App.setActiveDocument(self.doc.Name) - """ - - def __init__(self, name="None", doc=App.activeDocument()): - self.command_name = name - self.doc = doc - - def IsActive(self): - """Return True when this command should be available. - - It is `True` when there is a document. - """ - if App.activeDocument(): - return True - else: - return False - - def Activated(self): - """Execute when the command is called. - - Log the command name to the log file and console. - Also update the `doc` attribute. - """ - self.doc = App.activeDocument() - _log("Document: {}".format(self.doc.Label)) - _log("GuiCommand: {}".format(self.command_name)) - _msg("{}".format(16*"-")) - _msg("GuiCommand: {}".format(self.command_name)) - - -class GuiCommandNeedsSelection(GuiCommandSimplest): - """Base class for GuiCommands that need a selection to be available. - - It re-implements the `IsActive` method to return `True` - when there is both an active document and an active selection. - - It inherits `GuiCommandSimplest` to set up the document - and other behavior. See this class for more information. - """ - - def IsActive(self): - """Return True when this command should be available. - - It is `True` when there is a selection. - """ - if App.activeDocument() and Gui.Selection.getSelection(): - return True - else: - return False - - -class GuiCommandBase: +class GuiCommandBase(object): """Generic class that is the basis of all Gui commands. This class should eventually replace `DraftTools.DraftTool`, diff --git a/src/Mod/Draft/draftguitools/gui_snapper.py b/src/Mod/Draft/draftguitools/gui_snapper.py index 542acf76d8..7e680899d4 100644 --- a/src/Mod/Draft/draftguitools/gui_snapper.py +++ b/src/Mod/Draft/draftguitools/gui_snapper.py @@ -32,26 +32,33 @@ defined by `gui_trackers.gridTracker`. # This module provides tools to handle point snapping and # everything that goes with it (toolbar buttons, cursor icons, etc.). +import FreeCAD as App +import FreeCADGui as Gui + +from pivy import coin +from PySide import QtCore, QtGui + import collections as coll import inspect import itertools import math -from pivy import coin -from PySide import QtCore, QtGui -import FreeCAD as App -import FreeCADGui as Gui import Draft import DraftVecUtils -from FreeCAD import Vector +import DraftGeomUtils + +import Part + import draftguitools.gui_trackers as trackers from draftutils.init_tools import get_draft_snap_commands from draftutils.messages import _msg, _wrn + __title__ = "FreeCAD Draft Snap tools" __author__ = "Yorik van Havre" __url__ = "https://www.freecadweb.org" + class Snapper: """Classes to manage snapping in Draft and Arch. @@ -75,6 +82,7 @@ class Snapper: """ def __init__(self): + self.activeview = None self.lastObj = [None, None] self.maxEdges = 0 @@ -180,6 +188,7 @@ class Snapper: ('intersection', ':/icons/Snap_Intersection.svg'), ('special', ':/icons/Snap_Special.svg')]) + def init_active_snaps(self): """ set self.active_snaps according to user prefs @@ -193,6 +202,7 @@ class Snapper: self.active_snaps.append(self.snaps[i]) i += 1 + def cstr(self, lastpoint, constrain, point): """Return constraints if needed.""" if constrain or self.mask: @@ -204,6 +214,7 @@ class Snapper: self.radiusTracker.update(fpt) return fpt + def snap(self, screenpos, lastpoint=None, active=True, constrain=False, noTracker=False): @@ -225,8 +236,6 @@ class Snapper: self.running = True - global Part, DraftGeomUtils - import Part, DraftGeomUtils self.spoint = None if not hasattr(self, "toolbar"): @@ -332,10 +341,12 @@ class Snapper: self.running = False return fp + def cycleSnapObject(self): """Increse the index of the snap object by one.""" self.snapObjectIndex = self.snapObjectIndex + 1 + def snapToObject(self, lastpoint, active, constrain, eline, point, oldActive): """Snap to an object.""" @@ -513,6 +524,7 @@ class Snapper: self.running = False return self.spoint + def toWP(self, point): """Project the given point on the working plane, if needed.""" if self.isEnabled("WorkingPlane"): @@ -520,6 +532,7 @@ class Snapper: return App.DraftWorkingPlane.projectPoint(point) return point + def getApparentPoint(self, x, y): """Return a 3D point, projected on the current working plane.""" view = Draft.get3DView() @@ -535,6 +548,7 @@ class Snapper: return App.DraftWorkingPlane.projectPoint(pt, dv) return pt + def snapToDim(self, obj): snaps = [] if obj.ViewObject: @@ -543,6 +557,7 @@ class Snapper: snaps.append([obj.ViewObject.Proxy.p3, 'endpoint', self.toWP(obj.ViewObject.Proxy.p3)]) return snaps + def snapToExtensions(self, point, last, constrain, eline): """Return a point snapped to extension or parallel line. @@ -652,6 +667,7 @@ class Snapper: return np,de return point,eline + def snapToCrossExtensions(self, point): """Snap to the intersection of the last 2 extension lines.""" if self.isEnabled('Extension'): @@ -682,6 +698,7 @@ class Snapper: return p return None + def snapToPolar(self,point,last): """Snap to polar lines from the given point.""" if self.isEnabled('Ortho') and (not self.mask): @@ -721,6 +738,7 @@ class Snapper: return np,de return point, None + def snapToGrid(self, point): """Return a grid snap point if available.""" if self.grid: @@ -738,6 +756,7 @@ class Snapper: return np return point + def snapToEndpoints(self, shape): """Return a list of endpoints snap locations.""" snaps = [] @@ -756,6 +775,7 @@ class Snapper: snaps.append([v, 'endpoint', self.toWP(v)]) return snaps + def snapToMidpoint(self, shape): """Return a list of midpoints snap locations.""" snaps = [] @@ -766,6 +786,7 @@ class Snapper: snaps.append([mp, 'midpoint', self.toWP(mp)]) return snaps + def snapToPerpendicular(self, shape, last): """Return a list of perpendicular snap locations.""" snaps = [] @@ -789,6 +810,7 @@ class Snapper: snaps.append([np, 'perpendicular', self.toWP(np)]) return snaps + def snapToOrtho(self, shape, last, constrain): """Return a list of ortho snap locations.""" snaps = [] @@ -806,6 +828,7 @@ class Snapper: snaps.append([p, 'ortho', self.toWP(p)]) return snaps + def snapToExtOrtho(self, last, constrain, eline): """Return an ortho X extension snap location.""" if self.isEnabled("Extension") and self.isEnabled("Ortho"): @@ -827,6 +850,7 @@ class Snapper: return None return None + def snapToHold(self, point): """Return a snap location that is orthogonal to hold points. @@ -877,6 +901,7 @@ class Snapper: return [p, 'extension', fp] return None + def snapToExtPerpendicular(self, last): """Return a perpendicular X extension snap location.""" if self.isEnabled("Extension") and self.isEnabled("Perpendicular"): @@ -887,6 +912,7 @@ class Snapper: return [np, 'perpendicular', np] return None + def snapToElines(self, e1, e2): """Return a snap at the infinite intersection of the given edges.""" snaps = [] @@ -899,6 +925,7 @@ class Snapper: snaps.append([p, 'intersection', self.toWP(p)]) return snaps + def snapToAngles(self, shape): """Return a list of angle snap locations.""" snaps = [] @@ -916,6 +943,7 @@ class Snapper: snaps.append([cur, 'angle', self.toWP(cur)]) return snaps + def snapToCenter(self, shape): """Return a list of center snap locations.""" snaps = [] @@ -929,14 +957,15 @@ class Snapper: 195, 217.5, 232.5, 255, 285, 307.5, 322.5, 345): ang = math.radians(i) - cur = Vector(math.sin(ang) * rad + pos.x, - math.cos(ang) * rad + pos.y, - pos.z) + cur = App.Vector(math.sin(ang) * rad + pos.x, + math.cos(ang) * rad + pos.y, + pos.z) snaps.append([cur, 'center', c]) else: snaps.append([c, 'center', c]) return snaps + def snapToFace(self, shape): """Return a face center snap location.""" snaps = [] @@ -946,6 +975,7 @@ class Snapper: snaps.append([pos, 'center', c]) return snaps + def snapToIntersection(self, shape): """Return a list of intersection snap locations.""" snaps = [] @@ -978,6 +1008,7 @@ class Snapper: # when trying to read their types return snaps + def snapToPolygon(self, obj): """Return a list of polygon center snap locations.""" snaps = [] @@ -993,6 +1024,19 @@ class Snapper: return snaps + def snapToVertex(self,info,active=False): + p = App.Vector(info['x'],info['y'],info['z']) + if active: + if self.isEnabled("Near"): + return [p,'endpoint',self.toWP(p)] + else: + return [] + elif self.isEnabled("Near"): + return [p,'passive',p] + else: + return [] + + def snapToSpecials(self, obj, lastpoint=None, eline=None): """Return special snap locations, if any.""" snaps = [] @@ -1028,6 +1072,7 @@ class Snapper: return snaps + def getScreenDist(self, dist, cursor): """Return a distance in 3D space from a screen pixels distance.""" view = Draft.get3DView() @@ -1035,6 +1080,7 @@ class Snapper: p2 = view.getPoint((cursor[0] + dist, cursor[1])) return (p2.sub(p1)).Length + def getPerpendicular(self, edge, pt): """Return a point on an edge, perpendicular to the given point.""" dv = pt.sub(edge.Vertexes[0].Point) @@ -1042,6 +1088,7 @@ class Snapper: np = (edge.Vertexes[0].Point).add(nv) return np + def setArchDims(self, p1, p2): """Show arc dimensions between 2 points.""" if self.isEnabled("Dimensions"): @@ -1058,6 +1105,7 @@ class Snapper: if self.dim2.Distance: self.dim2.on() + def setCursor(self, mode=None): """Set or reset the cursor to the given mode or resets.""" if self.selectMode: @@ -1091,11 +1139,13 @@ class Snapper: w.setCursor(cur) self.cursorMode = mode + def restack(self): """Lower the grid tracker so it doesn't obscure other objects.""" if self.grid: self.grid.lowerTracker() + def off(self, hideSnapBar=False): """Finish snapping.""" if self.tracker: @@ -1129,6 +1179,7 @@ class Snapper: self.running = False self.holdPoints = [] + def setSelectMode(self, mode): """Set the snapper into select mode (hides snapping temporarily).""" self.selectMode = mode @@ -1138,6 +1189,7 @@ class Snapper: if self.trackLine: self.trackLine.off() + def setAngle(self, delta=None): """Keep the current angle.""" if delta: @@ -1148,6 +1200,7 @@ class Snapper: if self.trackLine.Visible: self.mask = self.trackLine.p2().sub(self.trackLine.p1()) + def constrain(self, point, basepoint=None, axis=None): """Return a constrained point. @@ -1222,6 +1275,7 @@ class Snapper: return npoint + def unconstrain(self): """Unset the basepoint and the constrain line.""" self.basepoint = None @@ -1229,6 +1283,7 @@ class Snapper: if self.constrainLine: self.constrainLine.off() + def getPoint(self, last=None, callback=None, movecallback=None, extradlg=None, title=None, mode="point"): """Get a 3D point from the screen. @@ -1289,6 +1344,7 @@ class Snapper: if movecallback: movecallback(self.pt, self.snapInfo) + def getcoords(point, relative=False): """Get the global coordinates from a point.""" self.pt = point @@ -1297,12 +1353,14 @@ class Snapper: self.pt = last.add(v) accept() + def click(event_cb): event = event_cb.getEvent() if event.getButton() == 1: if event.getState() == coin.SoMouseButtonEvent.DOWN: accept() + def accept(): if self.callbackClick: self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick) @@ -1320,6 +1378,7 @@ class Snapper: callback(self.pt) self.pt = None + def cancel(): if self.callbackClick: self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick) @@ -1351,6 +1410,7 @@ class Snapper: self.callbackClick = self.view.addEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(),click) self.callbackMove = self.view.addEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(),move) + def makeSnapToolBar(self): """Build the Snap toolbar.""" mw = Gui.getMainWindow() @@ -1366,6 +1426,7 @@ class Snapper: if not Draft.getParam("showSnapBar",True): self.toolbar.hide() + def init_draft_snap_buttons(self, commands, context, button_suffix): """ Init Draft Snap toolbar buttons. @@ -1399,6 +1460,7 @@ class Snapper: if len(b.statusTip()) == 0: b.setStatusTip(b.toolTip()) + def restore_snap_buttons_state(self, toolbar, button_suffix): """ Restore toolbar button's checked state according to @@ -1425,6 +1487,7 @@ class Snapper: else: a.setToolTip(a.toolTip()+" (OFF)") + def get_snap_toolbar(self): """retuns snap toolbar object""" mw = Gui.getMainWindow() @@ -1434,10 +1497,12 @@ class Snapper: return toolbar return None + def toggleGrid(self): "toggle FreeCAD Draft Grid" Gui.runCommand("Draft_ToggleGrid") + def showradius(self): """Show the snap radius indicator.""" self.radius = self.getScreenDist(Draft.getParam("snapRange", 8), @@ -1446,6 +1511,7 @@ class Snapper: self.radiusTracker.update(self.radius) self.radiusTracker.on() + def isEnabled(self, snap): "Returns true if the given snap is on" if "Lock" in self.active_snaps and snap in self.active_snaps: @@ -1453,6 +1519,7 @@ class Snapper: else: return False + def toggle_snap(self, snap, set_to = None): "Sets the given snap on/off according to the given parameter" if set_to: # set mode @@ -1474,6 +1541,7 @@ class Snapper: self.save_snap_state() return status + def save_snap_state(self): """ save snap state to user preferences to be restored in next session @@ -1487,6 +1555,7 @@ class Snapper: snap_modes += "0" param.SetString("snapModes",snap_modes) + def show(self): """Show the toolbar and the grid.""" if not hasattr(self, "toolbar"): @@ -1510,12 +1579,14 @@ class Snapper: if h: c.height.setValue(h) + def hide(self): """Hide the toolbar.""" if hasattr(self, "toolbar"): self.toolbar.hide() self.toolbar.toggleViewAction().setVisible(True) + def setGrid(self): """Set the grid, if visible.""" self.setTrackers() @@ -1523,6 +1594,7 @@ class Snapper: if self.grid.Visible: self.grid.set() + def setTrackers(self): """Set the trackers.""" v = Draft.get3DView() @@ -1570,9 +1642,11 @@ class Snapper: 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() + def addHoldPoint(self): """Add hold snap point to list of hold points.""" if self.spoint and self.spoint not in self.holdPoints: diff --git a/src/Mod/Draft/draftguitools/gui_snaps.py b/src/Mod/Draft/draftguitools/gui_snaps.py index 75eb999335..57b005c18f 100644 --- a/src/Mod/Draft/draftguitools/gui_snaps.py +++ b/src/Mod/Draft/draftguitools/gui_snaps.py @@ -28,23 +28,72 @@ # \brief Provide the Draft_Snap commands used by the snapping mechanism # in Draft. -import draftguitools.gui_base as gui_base import FreeCADGui as Gui import draftguitools.gui_base as gui_base -from draftutils.translate import _tr +from PySide import QtGui from PySide.QtCore import QT_TRANSLATE_NOOP from draftutils.translate import _tr -class Draft_Snap_Lock(gui_base.GuiCommandSimplest): - """GuiCommand for the Draft_Snap_Lock tool. +# UTILITIES ----------------------------------------------------------------- - Activate or deactivate all snap methods at once. - """ - def __init__(self): - super().__init__(name=_tr("Main toggle snap")) +def get_snap_statusbar_widget(): + """retuns snap statusbar button""" + mw = Gui.getMainWindow() + if mw: + sb = mw.statusBar() + if sb: + return sb.findChild(QtGui.QToolBar,"draft_snap_widget") + return None + + +def sync_snap_toolbar_button(button, status): + """set snap toolbar button to given state""" + snap_toolbar = Gui.Snapper.get_snap_toolbar() + if not snap_toolbar: + return + for a in snap_toolbar.actions(): + if a.objectName() == button: + if button == "Draft_Snap_Lock_Button": + # for lock button + snap_toolbar.actions()[0].setChecked(status) + for a in snap_toolbar.actions()[1:]: + a.setEnabled(status) + else: + # for every other button + a.setChecked(status) + if a.isChecked(): + a.setToolTip(a.toolTip().replace("OFF","ON")) + else: + a.setToolTip(a.toolTip().replace("ON","OFF")) + + +def sync_snap_statusbar_button(button, status): + """set snap statusbar button to given state""" + ssw = get_snap_statusbar_widget() + if not ssw: + return + for child in ssw.children(): + if child.objectName() == "Snap_Statusbutton": + ssb = child + actions = [] + for a in ssb.menu().actions() + ssw.children()[-6:]: + actions.append(a) + + if button == "Draft_Snap_Lock_Statusbutton": + ssb.setChecked(status) + for a in actions[1:]: + a.setEnabled(status) + else: + for a in actions: + if a.objectName() == button: + a.setChecked(status) + + +# SNAP GUI TOOLS ------------------------------------------------------------ + class Draft_Snap_Lock(gui_base.GuiCommandSimplest): """GuiCommand for the Draft_Snap_Lock tool. @@ -53,7 +102,7 @@ class Draft_Snap_Lock(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Main toggle snap")) + super(Draft_Snap_Lock, self).__init__(name=_tr("Main toggle snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -68,17 +117,14 @@ class Draft_Snap_Lock(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() - + super(Draft_Snap_Lock, self).Activated() + if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "masterbutton"): - Gui.Snapper.masterbutton.toggle() + status = Gui.Snapper.toggle_snap('Lock') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Lock"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Lock"+"_Statusbutton", status) - if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "masterbutton"): - Gui.Snapper.masterbutton.toggle() - -Gui.addCommand('Draft_Snap_Lock', Draft_Snap_Lock()) Gui.addCommand('Draft_Snap_Lock', Draft_Snap_Lock()) @@ -90,7 +136,7 @@ class Draft_Snap_Midpoint(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Midpoint snap")) + super(Draft_Snap_Midpoint, self).__init__(name=_tr("Midpoint snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -103,13 +149,13 @@ class Draft_Snap_Midpoint(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Midpoint, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonmidpoint": - b.toggle() + status = Gui.Snapper.toggle_snap('Midpoint') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Midpoint"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Midpoint_Statusbutton", status) Gui.addCommand('Draft_Snap_Midpoint', Draft_Snap_Midpoint()) @@ -122,7 +168,7 @@ class Draft_Snap_Perpendicular(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Perpendicular snap")) + super(Draft_Snap_Perpendicular, self).__init__(name=_tr("Perpendicular snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -137,13 +183,13 @@ class Draft_Snap_Perpendicular(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Perpendicular, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonperpendicular": - b.toggle() + status = Gui.Snapper.toggle_snap('Perpendicular') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Perpendicular"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Perpendicular_Statusbutton", status) Gui.addCommand('Draft_Snap_Perpendicular', Draft_Snap_Perpendicular()) @@ -156,7 +202,7 @@ class Draft_Snap_Grid(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Grid snap")) + super(Draft_Snap_Grid, self).__init__(name=_tr("Grid snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -168,13 +214,13 @@ class Draft_Snap_Grid(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Grid, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtongrid": - b.toggle() + status = Gui.Snapper.toggle_snap('Grid') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Grid"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Grid_Statusbutton", status) Gui.addCommand('Draft_Snap_Grid', Draft_Snap_Grid()) @@ -187,7 +233,7 @@ class Draft_Snap_Intersection(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Intersection snap")) + super(Draft_Snap_Intersection, self).__init__(name=_tr("Intersection snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -202,13 +248,13 @@ class Draft_Snap_Intersection(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Intersection, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonintersection": - b.toggle() + status = Gui.Snapper.toggle_snap('Intersection') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Intersection"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Intersection_Statusbutton", status) Gui.addCommand('Draft_Snap_Intersection', Draft_Snap_Intersection()) @@ -221,7 +267,7 @@ class Draft_Snap_Parallel(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Parallel snap")) + super(Draft_Snap_Parallel, self).__init__(name=_tr("Parallel snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -234,13 +280,13 @@ class Draft_Snap_Parallel(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Parallel, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonparallel": - b.toggle() + status = Gui.Snapper.toggle_snap('Parallel') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Parallel"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Parallel_Statusbutton", status) Gui.addCommand('Draft_Snap_Parallel', Draft_Snap_Parallel()) @@ -253,7 +299,7 @@ class Draft_Snap_Endpoint(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Endpoint snap")) + super(Draft_Snap_Endpoint, self).__init__(name=_tr("Endpoint snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -266,13 +312,13 @@ class Draft_Snap_Endpoint(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Endpoint, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonendpoint": - b.toggle() + status = Gui.Snapper.toggle_snap('Endpoint') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Endpoint"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Endpoint_Statusbutton", status) Gui.addCommand('Draft_Snap_Endpoint', Draft_Snap_Endpoint()) @@ -286,7 +332,7 @@ class Draft_Snap_Angle(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Angle snap (30 and 45 degrees)")) + super(Draft_Snap_Angle, self).__init__(name=_tr("Angle snap (30 and 45 degrees)")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -300,13 +346,13 @@ class Draft_Snap_Angle(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Angle, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonangle": - b.toggle() + status = Gui.Snapper.toggle_snap('Angle') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Angle"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Angle_Statusbutton", status) Gui.addCommand('Draft_Snap_Angle', Draft_Snap_Angle()) @@ -319,7 +365,7 @@ class Draft_Snap_Center(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Arc center snap")) + super(Draft_Snap_Center, self).__init__(name=_tr("Arc center snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -331,13 +377,13 @@ class Draft_Snap_Center(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Center, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtoncenter": - b.toggle() + status = Gui.Snapper.toggle_snap('Center') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Center"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Center_Statusbutton", status) Gui.addCommand('Draft_Snap_Center', Draft_Snap_Center()) @@ -350,7 +396,7 @@ class Draft_Snap_Extension(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Edge extension snap")) + super(Draft_Snap_Extension, self).__init__(name=_tr("Edge extension snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -363,13 +409,13 @@ class Draft_Snap_Extension(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Extension, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonextension": - b.toggle() + status = Gui.Snapper.toggle_snap('Extension') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Extension"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Extension_Statusbutton", status) Gui.addCommand('Draft_Snap_Extension', Draft_Snap_Extension()) @@ -382,7 +428,7 @@ class Draft_Snap_Near(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Near snap")) + super(Draft_Snap_Near, self).__init__(name=_tr("Near snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -394,13 +440,13 @@ class Draft_Snap_Near(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Near, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonpassive": - b.toggle() + status = Gui.Snapper.toggle_snap('Near') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Near"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Near_Statusbutton", status) Gui.addCommand('Draft_Snap_Near', Draft_Snap_Near()) @@ -414,7 +460,7 @@ class Draft_Snap_Ortho(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Orthogonal snap")) + super(Draft_Snap_Ortho, self).__init__(name=_tr("Orthogonal snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -428,13 +474,13 @@ class Draft_Snap_Ortho(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Ortho, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonortho": - b.toggle() + status = Gui.Snapper.toggle_snap('Ortho') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Ortho"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Ortho"+"_Statusbutton", status) Gui.addCommand('Draft_Snap_Ortho', Draft_Snap_Ortho()) @@ -447,7 +493,7 @@ class Draft_Snap_Special(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Special point snap")) + super(Draft_Snap_Special, self).__init__(name=_tr("Special point snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -460,13 +506,13 @@ class Draft_Snap_Special(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Special, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonspecial": - b.toggle() + status = Gui.Snapper.toggle_snap('Special') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Special"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Special_Statusbutton", status) Gui.addCommand('Draft_Snap_Special', Draft_Snap_Special()) @@ -480,7 +526,7 @@ class Draft_Snap_Dimensions(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Dimension display")) + super(Draft_Snap_Dimensions, self).__init__(name=_tr("Dimension display")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -494,13 +540,13 @@ class Draft_Snap_Dimensions(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_Dimensions, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonDimensions": - b.toggle() + status = Gui.Snapper.toggle_snap('Dimensions') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_Dimensions"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_Dimensions"+"_Statusbutton", status) Gui.addCommand('Draft_Snap_Dimensions', Draft_Snap_Dimensions()) @@ -516,7 +562,7 @@ class Draft_Snap_WorkingPlane(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Working plane snap")) + super(Draft_Snap_WorkingPlane, self).__init__(name=_tr("Working plane snap")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -536,13 +582,13 @@ class Draft_Snap_WorkingPlane(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(Draft_Snap_WorkingPlane, self).Activated() if hasattr(Gui, "Snapper"): - if hasattr(Gui.Snapper, "toolbarButtons"): - for b in Gui.Snapper.toolbarButtons: - if b.objectName() == "SnapButtonWorkingPlane": - b.toggle() + status = Gui.Snapper.toggle_snap('WorkingPlane') + # change interface consistently + sync_snap_toolbar_button("Draft_Snap_WorkingPlane"+"_Button", status) + sync_snap_statusbar_button("Draft_Snap_WorkingPlane_Statusbutton", status) Gui.addCommand('Draft_Snap_WorkingPlane', Draft_Snap_WorkingPlane()) @@ -555,7 +601,7 @@ class ShowSnapBar(gui_base.GuiCommandSimplest): """ def __init__(self): - super().__init__(name=_tr("Show snap toolbar")) + super(ShowSnapBar, self).__init__(name=_tr("Show snap toolbar")) def GetResources(self): """Set icon, menu and tooltip.""" @@ -569,7 +615,7 @@ class ShowSnapBar(gui_base.GuiCommandSimplest): def Activated(self): """Execute when the command is called.""" - super().Activated() + super(ShowSnapBar, self).Activated() if hasattr(Gui, "Snapper"): Gui.Snapper.show()