FreeCAD Python
Public Member Functions | List of all members
DraftSnap.Snapper Class Reference

Detailed Description

The Snapper objects contains all the functionality used by draft
and arch module to manage object snapping. It is responsible for
finding snap points and displaying snap markers. Usually You
only need to invoke it's snap() function, all the rest is taken
care of.

3 functions are useful for the scriptwriter: snap(), constrain()
or getPoint() which is an all-in-one combo.

The individual snapToXXX() functions return a snap definition in
the form [real_point,marker_type,visual_point], and are not
meant to be used directly, they are all called when necessary by
the general snap() function.

The Snapper lives inside FreeCADGui once the Draft module has been
loaded.

Public Member Functions

def snap (self, screenpos, lastpoint=None, active=True, constrain=False, noTracker=False)
 
def constrain (self, point, basepoint=None, axis=None)
 
def getPoint (self, last=None, callback=None, movecallback=None, extradlg=None, title=None, mode="point")
 

Member Function Documentation

◆ constrain()

def DraftSnap.Snapper.constrain (   self,
  point,
  basepoint = None,
  axis = None 
)
constrain(point,basepoint=None,axis=None: Returns a
constrained point. Axis can be "x","y" or "z" or a custom vector. If None,
the closest working plane axis will be picked.
Basepoint is the base point used to figure out from where the point
must be constrained. If no basepoint is given, the current point is
used as basepoint.

◆ getPoint()

def DraftSnap.Snapper.getPoint (   self,
  last = None,
  callback = None,
  movecallback = None,
  extradlg = None,
  title = None,
  mode = "point" 
)
getPoint([last],[callback],[movecallback],[extradlg],[title]) : gets a 3D point
from the screen. You can provide an existing point, in that case additional
snap options and a tracker are available.
You can also pass a function as callback, which will get called
with the resulting point as argument, when a point is clicked, and optionally
another callback which gets called when the mouse is moved.

If the operation gets cancelled (the user pressed Escape), no point is returned.

Example:

def cb(point):
    if point:
print "got a 3D point: ",point

FreeCADGui.Snapper.getPoint(callback=cb)

If the callback function accepts more than one argument, it will also receive
the last snapped object. Finally, a qt widget can be passed as an extra taskbox.
title is the title of the point task box
mode is the dialog box you want (default is point, you can also use wire and line)

If getPoint() is invoked without any argument, nothing is done but the callbacks
are removed, so it can be used as a cancel function.

◆ snap()

def DraftSnap.Snapper.snap (   self,
  screenpos,
  lastpoint = None,
  active = True,
  constrain = False,
  noTracker = False 
)
snap(screenpos,lastpoint=None,active=True,constrain=False,noTracker=False): returns a snapped
point from the given (x,y) screenpos (the position of the mouse cursor), active is to
activate active point snapping or not (passive), lastpoint is an optional
other point used to draw an imaginary segment and get additional snap locations. Constrain can
be True to constrain the point against the closest working plane axis.
Screenpos can be a list, a tuple or a coin.SbVec2s object. If noTracker is True,
the tracking line is not displayed.