Skip to content

Commit

Permalink
Draft: gui_snapper.py clean up imports and spaces
Browse files Browse the repository at this point in the history
Small spacing fixes like imports in separate lines
for more clarity.
Also use the `OrderedDict` prefixed with the `collections` module.
  • Loading branch information
vocx-fc authored and yorikvanhavre committed Apr 7, 2020
1 parent f33dcf6 commit a9a10a7
Showing 1 changed file with 72 additions and 57 deletions.
129 changes: 72 additions & 57 deletions src/Mod/Draft/draftguitools/gui_snapper.py
Expand Up @@ -18,26 +18,37 @@
# * USA *
# * *
# ***************************************************************************

__title__ = "FreeCAD Draft Snap tools"
__author__ = "Yorik van Havre"
__url__ = "https://www.freecadweb.org"

## @package DraftSnap
"""Provide the Snapper class to control snapping in the Draft Workbench.
This module provides tools to handle point snapping and
everything that goes with it (toolbar buttons, cursor icons, etc.).
It also creates the Draft grid, which is actually a tracker
defined by `gui_trackers.gridTracker`.
"""
## @package gui_snapper
# \ingroup DRAFT
# \brief Snapping system used by Draft & Arch workbenches
# \brief Snapper class to control snapping in the Draft Workbench.
#
# This module provides tools to handle point snapping and
# everything that goes with it (toolbar buttons, cursor icons, etc)

# everything that goes with it (toolbar buttons, cursor icons, etc.).

import FreeCAD, FreeCADGui, math, Draft, DraftVecUtils, itertools
import draftguitools.gui_trackers as trackers
from collections import OrderedDict
from FreeCAD import Vector
import collections as coll
import itertools
import math
from pivy import coin
from PySide import QtCore, QtGui

import FreeCAD
import FreeCADGui
import Draft
import DraftVecUtils
from FreeCAD import Vector
import draftguitools.gui_trackers as trackers

__title__ = "FreeCAD Draft Snap tools"
__author__ = "Yorik van Havre"
__url__ = "https://www.freecadweb.org"


class Snapper:
"""Classes to manage snapping in Draft and Arch.
Expand All @@ -63,17 +74,17 @@ class Snapper:

def __init__(self):
self.activeview = None
self.lastObj = [None,None]
self.lastObj = [None, None]
self.maxEdges = 0
self.radius = 0
self.constraintAxis = None
self.basepoint = None
self.affinity = None
self.mask = None
self.cursorMode = None
if Draft.getParam("maxSnap",0):
self.maxEdges = Draft.getParam("maxSnapEdges",0)
self.snapStyle = Draft.getParam("snapStyle",0)
if Draft.getParam("maxSnap", 0):
self.maxEdges = Draft.getParam("maxSnapEdges", 0)
self.snapStyle = Draft.getParam("snapStyle", 0)

# we still have no 3D view when the draft module initializes
self.tracker = None
Expand All @@ -90,9 +101,12 @@ def __init__(self):
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
self.trackers = [[],[],[],[],[],[],[],[],[],[]] # view, grid, snap, extline, radius, dim1, dim2, trackLine, extline2, crosstrackers
self.polarAngles = [90,45]
# the trackers are stored in lists because there can be several views,
# each with its own set
# view, grid, snap, extline, radius, dim1, dim2, trackLine,
# extline2, crosstrackers
self.trackers = [[], [], [], [], [], [], [], [], [], []]
self.polarAngles = [90, 45]
self.selectMode = False
self.holdTracker = None
self.holdPoints = []
Expand All @@ -103,44 +117,45 @@ def __init__(self):

# the snapmarker has "dot","circle" and "square" available styles
if self.snapStyle:
self.mk = OrderedDict([('passive', 'empty'),
('extension', 'empty'),
('parallel', 'empty'),
('grid', 'quad'),
('endpoint', 'quad'),
('midpoint', 'quad'),
('perpendicular','quad'),
('angle', 'quad'),
('center', 'quad'),
('ortho', 'quad'),
('intersection', 'quad'),
('special', 'quad')])
self.mk = coll.OrderedDict([('passive', 'empty'),
('extension', 'empty'),
('parallel', 'empty'),
('grid', 'quad'),
('endpoint', 'quad'),
('midpoint', 'quad'),
('perpendicular', 'quad'),
('angle', 'quad'),
('center', 'quad'),
('ortho', 'quad'),
('intersection', 'quad'),
('special', 'quad')])
else:
self.mk = OrderedDict([('passive', 'circle'),
('extension', 'circle'),
('parallel', 'circle'),
('grid', 'circle'),
('endpoint', 'dot'),
('midpoint', 'square'),
('perpendicular','dot'),
('angle', 'square'),
('center', 'dot'),
('ortho', 'dot'),
('intersection', 'dot'),
('special', 'dot')])

self.cursors = OrderedDict([('passive', ':/icons/Snap_Near.svg'),
('extension', ':/icons/Snap_Extension.svg'),
('parallel', ':/icons/Snap_Parallel.svg'),
('grid', ':/icons/Snap_Grid.svg'),
('endpoint', ':/icons/Snap_Endpoint.svg'),
('midpoint', ':/icons/Snap_Midpoint.svg'),
('perpendicular', ':/icons/Snap_Perpendicular.svg'),
('angle', ':/icons/Snap_Angle.svg'),
('center', ':/icons/Snap_Center.svg'),
('ortho', ':/icons/Snap_Ortho.svg'),
('intersection', ':/icons/Snap_Intersection.svg'),
('special', ':/icons/Snap_Special.svg')])
self.mk = coll.OrderedDict([('passive', 'circle'),
('extension', 'circle'),
('parallel', 'circle'),
('grid', 'circle'),
('endpoint', 'dot'),
('midpoint', 'square'),
('perpendicular', 'dot'),
('angle', 'square'),
('center', 'dot'),
('ortho', 'dot'),
('intersection', 'dot'),
('special', 'dot')])

self.cursors = \
coll.OrderedDict([('passive', ':/icons/Snap_Near.svg'),
('extension', ':/icons/Snap_Extension.svg'),
('parallel', ':/icons/Snap_Parallel.svg'),
('grid', ':/icons/Snap_Grid.svg'),
('endpoint', ':/icons/Snap_Endpoint.svg'),
('midpoint', ':/icons/Snap_Midpoint.svg'),
('perpendicular', ':/icons/Snap_Perpendicular.svg'),
('angle', ':/icons/Snap_Angle.svg'),
('center', ':/icons/Snap_Center.svg'),
('ortho', ':/icons/Snap_Ortho.svg'),
('intersection', ':/icons/Snap_Intersection.svg'),
('special', ':/icons/Snap_Special.svg')])

def cstr(self, lastpoint, constrain, point):
"constrains if needed"
Expand Down

0 comments on commit a9a10a7

Please sign in to comment.