Class TLcyShapeVisibilityManager
java.lang.Object
com.luciad.lucy.addons.tea.shapevisibility.TLcyShapeVisibilityManager
- All Implemented Interfaces:
ILcdDisposable,AutoCloseable
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 theaddObserver(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);
}
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();
}
- Since:
- 2019.1
-
Method Summary
Modifier and TypeMethodDescriptionaddObserver(TLcdDomainObjectContext aDomainObjectContext) Create and add a new observer for the specified domain object, allowing to calculate the visibility between this domain object and other domain objects.booleancanAddObserver(TLcdDomainObjectContext aDomainObjectContext) Returnstruewhen a new observer can be created foraDomainObjectContext.booleancanRemoveObserver(TLcdDomainObjectContext aDomainObjectContext) Returnstruewhen an observer was previously created foraDomainObjectContext, and it can be removed.voiddispose()Disposes of this object and allows it to release any system resources that it is holding.voidremoveObserver(TLcdDomainObjectContext aDomainObjectContext) Removes the observer for the specified domain object.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.luciad.util.ILcdDisposable
close
-
Method Details
-
canAddObserver
Returnstruewhen a new observer can be created foraDomainObjectContext. 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:
truewhen a new observer can be created foraDomainObjectContext
-
canRemoveObserver
Returnstruewhen an observer was previously created foraDomainObjectContext, and it can be removed.- Parameters:
aDomainObjectContext- The domain object context for which an observer was created before.- Returns:
truewhen there still exists an observer foraDomainObjectContext, 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 foraDomainObjectContext- See Also:
-
removeObserver
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:ILcdDisposableDisposes 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:
disposein interfaceILcdDisposable
-