Class TLspPointToPointSnapper

java.lang.Object
com.luciad.view.lightspeed.editor.snapping.TLspPointToPointSnapper
All Implemented Interfaces:
ILspSnapper, ILspSnapperProvider

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:

A valid move operation has:

Finally this snapper returns a visual component which provides a hint (highlight) to which points snapping is possible. Only points within a specified pixel distance (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 Details

  • Constructor Details

    • TLspPointToPointSnapper

      public TLspPointToPointSnapper()
      Constructs a new TLspPointToPointSnapper.
  • 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

      public List<TLspPaintRepresentationState> 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
      When performing snapping operations, only geometry defined in this list of paint representations is considered a snapping candidate. If you have your own 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

      public void setSupportedStates(List<TLspPaintRepresentationState> aSupportedStates)
      Sets the supported paint representation states of this TLspPointToPointSnapper.
      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 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);
              }
            }
          }
        ;
       }
      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 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.
    • convertObjectToPointSnapTargets

      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.
      Converts the given object to a set of point snap targets.

      By default this method can handle all ILcdShape objects, but it can be overridden to add support for other objects.

      Parameters:
      aObject - the object to convert to point snap targets
      aLayer - the layer the object is painted in
      aView - the view the object is painted in
      Returns:
      a collection of points to snap to for the given object
    • getSnapper

      public ILspSnapper getSnapper(AWTEvent aAWTEvent, TLspContext aContext)
      Description copied from interface: ILspSnapperProvider
      Returns a snapper for the given AWT event and context. May be null.
      Specified by:
      getSnapper in interface ILspSnapperProvider
      Parameters:
      aAWTEvent - the event generated by the edit controller
      aContext - the given context
      Returns:
      a snapper fit for the given AWT event and context. May be null.
    • getSnapper

      public ILspSnapper getSnapper(Event aEvent, TLspContext aContext)
      Description copied from interface: ILspSnapperProvider
      Specified by:
      getSnapper in interface ILspSnapperProvider
    • snap

      public TLspSnapOperation snap(TLspEditOperation aIncomingOperation, TLspEditContext aContext)
      Description copied from interface: ILspSnapper
      Performs snapping, if possible, based on the incoming edit operation. Returns a TLspSnapOperation containing a new list of edit operations. The contents of this list may be identical to these of aIncomingOperation.
      Specified by:
      snap in interface ILspSnapper
      Parameters:
      aIncomingOperation - the incoming edit operation to be processed by the snapper
      aContext - provides context information for the edit operation
      Returns:
      a TLspSnapOperation containing a new list of edit operations.
    • canSnap

      public boolean canSnap(TLspEditOperation aIncomingEvent, TLspEditContext aContext)
      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 interface ILspSnapper
      Parameters:
      aIncomingEvent - the operation that may be processed by the snapper
      aContext - provides context information for the edit operation
      Returns:
      true if the snapper can process the given incoming operation