public class TLspPointToPointSnapper extends Object implements 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: TLspEditOperationType.INSERT_POINT
TLspIndexedPointDescriptor
property for
the the property key of the INSERT_POINT
operation...
TLspEditOperationType.MOVE
TLspMoveDescriptor
property for
the the property key of the MOVE
operation...
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.
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_HIGHLIGHT_SENSITIVITY
The default sensitivity for finding snapping highlights.
|
static double |
DEFAULT_PIXEL_SENSITIVITY
The default sensitivity for finding snap targets
|
static String |
OBJECT_PROPERTY_KEY
The key for getting actual object from TLspSnapTarget
|
Constructor and Description |
---|
TLspPointToPointSnapper()
Constructs a new
TLspPointToPointSnapper . |
Modifier and Type | Method and Description |
---|---|
boolean |
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.
Method has been deprecated in favor of the more verbose
getSnapTargets , which provides a lot more context information and better filtering capabilities to allow for
more fine-grained control over snapping customization. |
double |
getHighlightSensitivity()
Returns the sensitivity for displaying a highlight (in pixels).
|
double |
getPixelSensitivity()
Returns the sensitivity for finding snap targets.
|
ILspSnapper |
getSnapper(AWTEvent aAWTEvent,
TLspContext aContext)
Returns a snapper for the given AWT event and context.
|
ILspSnapper |
getSnapper(javafx.event.Event aEvent,
TLspContext aContext)
JavaFX equivalent of
ILspSnapperProvider.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.
|
List<TLspPaintRepresentationState> |
getSupportedStates()
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 this
TLspPointToPointSnapper . |
TLspSnapOperation |
snap(TLspEditOperation aIncomingOperation,
TLspEditContext aContext)
Performs snapping, if possible, based on the incoming edit operation.
|
public static final double DEFAULT_HIGHLIGHT_SENSITIVITY
getHighlightSensitivity()
,
Constant Field Valuespublic static final double DEFAULT_PIXEL_SENSITIVITY
getPixelSensitivity()
,
Constant Field Valuespublic static final String OBJECT_PROPERTY_KEY
getSnapTargets(com.luciad.shape.ILcdPoint, com.luciad.view.lightspeed.editor.operation.TLspEditOperation, com.luciad.view.lightspeed.editor.TLspEditContext, java.util.Map<com.luciad.view.lightspeed.editor.snapping.TLspSnapperGeometryType, java.util.Collection<com.luciad.view.lightspeed.style.styler.ALspStyleTargetProvider>>)
,
Constant Field Valuespublic TLspPointToPointSnapper()
TLspPointToPointSnapper
.public double getPixelSensitivity()
public void setPixelSensitivity(double aPixelSensitivity)
aPixelSensitivity
- the new pixel sensitivity.public double getHighlightSensitivity()
getPixelSensitivity()
), so that visual feedback
about a snapping operation is given slightly before the operation is actually performed.public void setHighlightSensitivity(double aHighlightSensitivity)
aHighlightSensitivity
- the new sensitivitypublic List<TLspPaintRepresentationState> getSupportedStates()
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)
public void setSupportedStates(List<TLspPaintRepresentationState> aSupportedStates)
TLspPointToPointSnapper
.aSupportedStates
- the supported paint representation states by this TLspPointToPointSnapper.getSupportedStates()
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 are snap 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);
}
}
}
;
}
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 the ALspStyler
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 the ALspStyler
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.protected Collection<ILcdPoint> convertObjectToPointSnapTargets(Object aObject, ILspLayer aLayer, ILspView aView)
getSnapTargets
, which provides a lot more context information and better filtering capabilities to allow for
more fine-grained control over snapping customization.ILcdShape
objects, but it can be overridden to add support for other objects.aObject
- the object to convert to point snap targetsaLayer
- the layer the object is painted inaView
- the view the object is painted inpublic ILspSnapper getSnapper(AWTEvent aAWTEvent, TLspContext aContext)
ILspSnapperProvider
null
.getSnapper
in interface ILspSnapperProvider
aAWTEvent
- the event generated by the edit controlleraContext
- the given contextnull
.public ILspSnapper getSnapper(javafx.event.Event aEvent, TLspContext aContext)
ILspSnapperProvider
ILspSnapperProvider.getSnapper(AWTEvent, TLspContext)
.getSnapper
in interface ILspSnapperProvider
public TLspSnapOperation snap(TLspEditOperation aIncomingOperation, TLspEditContext aContext)
ILspSnapper
TLspSnapOperation
containing a new list of edit operations. The contents
of this list may be identical to these of aIncomingOperation
.snap
in interface ILspSnapper
aIncomingOperation
- the incoming edit operation to be processed by the snapperaContext
- provides context information for the edit operationTLspSnapOperation
containing a new list of edit operations.public boolean canSnap(TLspEditOperation aIncomingEvent, TLspEditContext aContext)
ILspSnapper
canSnap
in interface ILspSnapper
aIncomingEvent
- the operation that may be processed by the snapperaContext
- provides context information for the edit operation