Class TLcyShapeVisibilityManager

java.lang.Object
com.luciad.lucy.addons.tea.shapevisibility.TLcyShapeVisibilityManager
All Implemented Interfaces:
ILcdDisposable, AutoCloseable

public final class TLcyShapeVisibilityManager extends Object implements ILcdDisposable

Creates and manages observers that calculate the visibility between the observer and other shapes on the map.

Note: all interactions with this class should happen on the AWT Thread (the Event Dispatch Thread).

Obtaining the manager

The manager is available as service on the Lucy back-end.
    //Retrieve the manager from the services
    TLcyShapeVisibilityManager manager = aLucyEnv.getService(TLcyShapeVisibilityManager.class);

Creating a point observer

You can create a point observer for a specific domain object using the addObserver(TLcdDomainObjectContext) method:
    //Retrieve the manager from the services
    TLcyShapeVisibilityManager manager = aLucyEnv.getService(TLcyShapeVisibilityManager.class);

    //Ask the manager to create an observer for the specified domain object
    //Interacting with the manager must happen on the AWT thread (Event Dispatch Thread)
    if (manager.canAddObserver(aDomainObjectContext)) {
      TLcyShapeObserver pointObserver = manager.addObserver(aDomainObjectContext);
    }
The returned TLcyShapeObserver will be kept in sync with the domain object for which it was created:
  • When the domain object moves (in x, y or z direction), the observer moves as well.
  • When the domain object gets removed, the observer is removed as well.

Start observing an object

When you have an observer, you can ask it to observe a specific object:
      //Find the observer model in the view
      ILcdModel pointObserverModel = view.getLayers()
                                         .stream()
                                         .map(ILcdLayer::getModel)
                                         .filter(model -> Objects.equals(TLcyShapeVisibilityAddOn.OBSERVER_MODEL_TYPE_NAME, model.getModelDescriptor().getTypeName()))
                                         .findFirst()
                                         .orElseThrow(() -> new RuntimeException("Cannot find the model containing the observers"));
      //Let the observer observe another shape
      //As this modifies the point observer, it requires a lock on the point observer model
      try (TLcdLockUtil.Lock autoUnlock = TLcdLockUtil.writeLock(pointObserverModel)) {
        if (pointObserver.canObserve(aDomainObjectContextToObserve)) {
          //Tell the observer to start observing another object
          pointObserver.startObserving(aDomainObjectContextToObserve);
          //Indicate to the model that the observer has been changed
          pointObserverModel.elementChanged(pointObserver, ILcdModel.FIRE_LATER);
        }
      } finally {
        pointObserverModel.fireCollectedModelChanges();
      }
Once the result of the calculation is available, it will become visible on the map.
Since:
2019.1
  • Method Details

    • canAddObserver

      public boolean canAddObserver(TLcdDomainObjectContext aDomainObjectContext)
      Returns true when a new observer can be created for aDomainObjectContext. Currently this requires that the domain object uses a point geometry, and that no observer exists yet for this domain object.
      Parameters:
      aDomainObjectContext - The domain object context
      Returns:
      true when a new observer can be created for aDomainObjectContext
    • canRemoveObserver

      public boolean canRemoveObserver(TLcdDomainObjectContext aDomainObjectContext)
      Returns true when an observer was previously created for aDomainObjectContext, and it can be removed.
      Parameters:
      aDomainObjectContext - The domain object context for which an observer was created before.
      Returns:
      true when there still exists an observer for aDomainObjectContext, and that observer can be removed.
    • addObserver

      public TLcyShapeObserver addObserver(TLcdDomainObjectContext aDomainObjectContext) throws IllegalArgumentException

      Create and add a new observer for the specified domain object, allowing to calculate the visibility between this domain object and other domain objects.

      The created observer will be added to the observer layer on the map. If no such layer exist yet, it will be created and added to the map.

      Parameters:
      aDomainObjectContext - The domain object for which to create an observer
      Returns:
      The newly created observer
      Throws:
      IllegalArgumentException - If no observer could be created for aDomainObjectContext
      See Also:
    • removeObserver

      public void removeObserver(TLcdDomainObjectContext aDomainObjectContext)
      Removes the observer for the specified domain object. This will also remove all visibility calculation results for that observer.
      Parameters:
      aDomainObjectContext - The domain object context for which the previously created observer must be removed
    • dispose

      public void dispose()
      Description copied from interface: ILcdDisposable

      Disposes of this object and allows it to release any system resources that it is holding.

      The result of calling any other method (other than finalize) on this object subsequent to a call to this method is undefined.

      Specified by:
      dispose in interface ILcdDisposable