Class TLspPointToPointSnapper
- All Implemented Interfaces:
ILspSnapper
,ILspSnapperProvider
An ILspSnapper
implementation used to snap points to other nearby points.
This snapper detects nearby points in the view. Only points within a specified pixel
distance (getPixelSensitivity()
) are taken into account.
Nearby points may originate from any visible snappable layer (ILspSnappable
) and
from every instance of ILcdShape
.
To customize behavior, override the getSnapTargets
method.
This method allows you to filter, convert or add snap candidates based on full context information for each
object, geometry, paintrepresentation and layer combination possible. Have a look at the method javadoc
for more details on how to customize snapping.
Note that each layer's stylers are taken into account when searching for nearby points. Hence
snapping points are computed based on the geometry (ALspStyleTargetProvider
) provided
by each styler.
TLspPointToPointSnapper
can handle point insertion operations and move operations.
A valid point insertion operation has: - type
TLspEditOperationType.INSERT_POINT
- a corresponding
TLspIndexedPointDescriptor
property for the the property key of theINSERT_POINT
operation... - ...with a valid point and model reference
- type
TLspEditOperationType.MOVE
- a
corresponding
TLspMoveDescriptor
property for the the property key of theMOVE
operation... - which is constrained not to move along the Z-axis
- ...with a model reference and no start point.
getHighlightSensitivity()
) are taken into account.
As a convenience, TLspPointToPointSnapper
also implements ILspSnapperProvider
. By default, it returns this
when the control key is not down,
null
otherwise.
- Since:
- 2012.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final double
The default sensitivity for finding snapping highlights.static final double
The default sensitivity for finding snap targetsstatic final String
The key for getting actual object from TLspSnapTarget -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canSnap
(TLspEditOperation aIncomingEvent, TLspEditContext aContext) Returns true if snapping can be performed on the given incoming operation.protected Collection
<ILcdPoint> convertObjectToPointSnapTargets
(Object aObject, ILspLayer aLayer, ILspView aView) Deprecated.double
Returns the sensitivity for displaying a highlight (in pixels).double
Returns the sensitivity for finding snap targets.getSnapper
(AWTEvent aAWTEvent, TLspContext aContext) Returns a snapper for the given AWT event and context.getSnapper
(Event aEvent, TLspContext aContext) JavaFX equivalent ofILspSnapperProvider.getSnapper(AWTEvent, TLspContext)
.protected void
getSnapTargets
(ILcdPoint aSnapFromPoint, ILcdGeoReference aSnapFromPointReference, TLspDomainObjectContext aSnapFromContext, Object aSnapFromGeometry, TLspDomainObjectContext aSnapToContext, Object aSnapToGeometry, List<ILcdPoint> aSnapPointTargetsSFCT) A method that you can override to customize snapping.Gets the supported paint representation states used for snapping.void
setHighlightSensitivity
(double aHighlightSensitivity) Sets the sensitivity for displaying a highlight (in pixels).void
setPixelSensitivity
(double aPixelSensitivity) Sets the sensitivity for finding snap targets (in pixels).void
setSupportedStates
(List<TLspPaintRepresentationState> aSupportedStates) Sets the supported paint representation states of thisTLspPointToPointSnapper
.snap
(TLspEditOperation aIncomingOperation, TLspEditContext aContext) Performs snapping, if possible, based on the incoming edit operation.
-
Field Details
-
DEFAULT_HIGHLIGHT_SENSITIVITY
public static final double DEFAULT_HIGHLIGHT_SENSITIVITYThe default sensitivity for finding snapping highlights.- See Also:
-
DEFAULT_PIXEL_SENSITIVITY
public static final double DEFAULT_PIXEL_SENSITIVITYThe default sensitivity for finding snap targets- See Also:
-
OBJECT_PROPERTY_KEY
The key for getting actual object from TLspSnapTarget- See Also:
-
-
Constructor Details
-
TLspPointToPointSnapper
public TLspPointToPointSnapper()Constructs a newTLspPointToPointSnapper
.
-
-
Method Details
-
getPixelSensitivity
public double getPixelSensitivity()Returns the sensitivity for finding snap targets.- Returns:
- the sensitivity for finding snap targets.
-
setPixelSensitivity
public void setPixelSensitivity(double aPixelSensitivity) Sets the sensitivity for finding snap targets (in pixels).- Parameters:
aPixelSensitivity
- the new pixel sensitivity.
-
getHighlightSensitivity
public double getHighlightSensitivity()Returns the sensitivity for displaying a highlight (in pixels). This is typically a larger value than the pixel sensitivity (getPixelSensitivity()
), so that visual feedback about a snapping operation is given slightly before the operation is actually performed.- Returns:
- the sensitivity for displaying a highlight
-
setHighlightSensitivity
public void setHighlightSensitivity(double aHighlightSensitivity) Sets the sensitivity for displaying a highlight (in pixels).- Parameters:
aHighlightSensitivity
- the new sensitivity
-
getSupportedStates
Gets the supported paint representation states used for snapping. By default this is a list containing:- TLspPaintRepresentationState.REGULAR_BODY
- TLspPaintRepresentationState.SELECTED_BODY
- TLspPaintRepresentationState.EDITED_BODY
TLspPaintRepresentationState
objects defined and would like snapping in those paint representations, add them to this list.You can set your own supported paint representations with
setSupportedStates(List)
- Returns:
- The supported paint representation states used for snapping.
-
setSupportedStates
Sets the supported paint representation states of thisTLspPointToPointSnapper
.- Parameters:
aSupportedStates
- the supported paint representation states by this TLspPointToPointSnapper.- See Also:
-
getSnapTargets
protected void getSnapTargets(ILcdPoint aSnapFromPoint, ILcdGeoReference aSnapFromPointReference, TLspDomainObjectContext aSnapFromContext, Object aSnapFromGeometry, TLspDomainObjectContext aSnapToContext, Object aSnapToGeometry, List<ILcdPoint> aSnapPointTargetsSFCT) A method that you can override to customize snapping. You get full context info on both which objects you are snapping from, and what object you are snapping to, as well as what styler geometry is being considered. You also get additional context info such as layer, view, paint-representation and the actual point that is being snapped from (which is not necessarily the geometry itself).
This method is called once for every geometry produced by the
styler
for all paint-states in all layers that aresnap targets
.By default this method will delegate all of its work to
convertObjectToPointSnapTargets(Object, ILspLayer, ILspView)
.Example usage:
public void getSnapTargets(ILcdPoint aSnapFromPoint, ILcdGeoReference aSnapFromPointReference, TLspDomainObjectContext aSnapFromContext, Object aSnapFromGeometry, TLspDomainObjectContext aSnapToContext, Object aSnapToGeometry, List<ILcdPoint> aSnapPointTargetsSFCT) { if(aSnapToGeometry instanceof TLcdLonLatPolyline){ //Example 1: Prevent snapping to all TLcdLonLatPolyline shapes return; } super.getSnapTargets(aSnapFromPoint, aSnapFromPointReference, aSnapFromContext, aSnapFromGeometry, aSnapToContext, aSnapToGeometry, aSnapPointTargetsSFCT); if(aSnapToGeometry instanceof ILcdCircle && aSnapToGeometry instanceof ILcdCurve){ //Example 2: Add 12 additional points to circle at its radius for( int i = 0 ; i < 12 ; i++ ){ TLcdLonLatHeightPoint tempPoint = new TLcdLonLatHeightPoint(); ((ILcdCurve) aSnapToGeometry).computePointSFCT((double)i/12.0, tempPoint); aSnapPointTargetsSFCT.add(tempPoint); } } }
; }- Parameters:
aSnapFromPoint
- The point in model coordinates that is being snapped from. This point is typically part of the geometry of the domain object that is being snapped from. (Like a point inside a pointlist, or the centerpoint of an circle, etc...)aSnapFromPointReference
- The georeference of aSnapFromPoint. Can possibly be null if the aSnapFromPoint parameter does not have a georeference, as is the case with view-space based points.aSnapFromContext
- Context information about the object that is being snapped from. (layer, view, domain object)aSnapFromGeometry
- The geometry that is being snapped from. The geometry is the shape produced by theALspStyler
of your layer, based on the domain object. The domain object itself can be found in the aSnapFromContext. Example: If aSnapFromPoint is a point from a point-list, then this parameter will be the pointlist itself.aSnapToContext
- Context information about the object that is being snapped to. (layer, view, domain object)aSnapToGeometry
- The geometry that is being snapped to. The geometry is the shape produced by theALspStyler
of your layer, based on the domain object. The domain object itself can be found in the aSnapToContext.aSnapPointTargetsSFCT
- A list of points that candidates to be snapped to. These points need to be defined in the same reference as aSnapFromPointReference.
-
convertObjectToPointSnapTargets
protected Collection<ILcdPoint> convertObjectToPointSnapTargets(Object aObject, ILspLayer aLayer, ILspView aView) Deprecated.Method has been deprecated in favor of the more verbosegetSnapTargets
, which provides a lot more context information and better filtering capabilities to allow for more fine-grained control over snapping customization.Converts the given object to a set of point snap targets. By default this method can handle allILcdShape
objects, but it can be overridden to add support for other objects.- Parameters:
aObject
- the object to convert to point snap targetsaLayer
- the layer the object is painted inaView
- the view the object is painted in- Returns:
- a collection of points to snap to for the given object
-
getSnapper
Description copied from interface:ILspSnapperProvider
Returns a snapper for the given AWT event and context. May benull
.- Specified by:
getSnapper
in interfaceILspSnapperProvider
- Parameters:
aAWTEvent
- the event generated by the edit controlleraContext
- the given context- Returns:
- a snapper fit for the given AWT event and context. May be
null
.
-
getSnapper
Description copied from interface:ILspSnapperProvider
JavaFX equivalent ofILspSnapperProvider.getSnapper(AWTEvent, TLspContext)
.- Specified by:
getSnapper
in interfaceILspSnapperProvider
-
snap
Description copied from interface:ILspSnapper
Performs snapping, if possible, based on the incoming edit operation. Returns aTLspSnapOperation
containing a new list of edit operations. The contents of this list may be identical to these ofaIncomingOperation
.- Specified by:
snap
in interfaceILspSnapper
- Parameters:
aIncomingOperation
- the incoming edit operation to be processed by the snapperaContext
- provides context information for the edit operation- Returns:
- a
TLspSnapOperation
containing a new list of edit operations.
-
canSnap
Description copied from interface:ILspSnapper
Returns true if snapping can be performed on the given incoming operation. This method allows the snapper to quickly reject edit operations which it does not understand.- Specified by:
canSnap
in interfaceILspSnapper
- Parameters:
aIncomingEvent
- the operation that may be processed by the snapperaContext
- provides context information for the edit operation- Returns:
- true if the snapper can process the given incoming operation
-
getSnapTargets
, which provides a lot more context information and better filtering capabilities to allow for more fine-grained control over snapping customization.