public final class TLcyShapeObserver extends Object implements ILcdBounded
Domain object representing an observer in a shape visibility calculation.
Currently only point shapes are supported as observers.
These observers are contained in the observer model
of the map.
Each observer has:
list of domain objects
that are currently being observed by this observer.ILcyVisibilityCalculationPropertiesProvider
which is created in the add-on.
Creating observer instances is done through the TLcyShapeVisibilityManager
:
//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);
}
Modifier and Type | Method and Description |
---|---|
boolean |
canObserve(TLcdDomainObjectContext aDomainObjectContext)
Returns
true when the specified domain object context can be observed by this observer. |
ILcdBounds |
getBounds()
Returns the
ILcdBounds by which the geometry of this ILcdBounded object
is bounded. |
List<TLcdDomainObjectContext> |
getObservees()
Returns the list of domain object contexts this observer is currently observing.
|
TLcdDomainObjectContext |
getObserver()
Returns the domain object context for which this observer was created.
|
TLcdCoverageAltitudeMode |
getObserverCoverageAltitudeMode()
Returns the altitude mode indicating how to interpret the Z-values of the observer shape.
|
ILcdPoint |
getObserverShape()
Returns the point shape based on the point that was created by the
TLcyShapeVisibilityAddOn.createPointObserverShapeProvider() function
for this observer, and which is used in the visibility calculations. |
TLcyShapeObservationResult |
startObserving(TLcdDomainObjectContext aDomainObjectContext)
Start observing the specified domain object using this observer.
|
void |
stopObserving(TLcdDomainObjectContext aDomainObjectContext)
Stop observing the specified domain object with this observer.
|
public TLcdDomainObjectContext getObserver()
public ILcdPoint getObserverShape()
Returns the point shape based on the point that was created by the TLcyShapeVisibilityAddOn.createPointObserverShapeProvider()
function
for this observer, and which is used in the visibility calculations.
The returned point:
getObserverCoverageAltitudeMode()
.The returned point should not be modified.
getObserverCoverageAltitudeMode()
public TLcdCoverageAltitudeMode getObserverCoverageAltitudeMode()
Returns the altitude mode indicating how to interpret the Z-values of the observer shape.
This altitude mode is determined by the TLcyShapeVisibilityAddOn.createPointObserverShapeProvider()
function.
getObserverShape()
public List<TLcdDomainObjectContext> getObservees()
Returns the list of domain object contexts this observer is currently observing.
This list cannot be modified directly.
Use the startObserving(TLcdDomainObjectContext)
and stopObserving(TLcdDomainObjectContext)
methods to start or stop observing specific domain objects.
null
public boolean canObserve(TLcdDomainObjectContext aDomainObjectContext)
Returns true
when the specified domain object context can be observed by this observer.
Currently this method only returns true
when:
TLcyShapeVisibilityAddOn
.TLcyShapeVisibilityAddOn.createObserveeShapeProvider()
function can retrieve a shape for the context.aDomainObjectContext
- The context to checktrue
when the specified domain object context can be observed by this observer.public TLcyShapeObservationResult startObserving(TLcdDomainObjectContext aDomainObjectContext) throws IllegalArgumentException
Start observing the specified domain object using this observer. This method modifies the observer, so it must be called under a write lock as illustrated below:
//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();
}
This method returns immediately and doesn't wait for the calculation to finish. This means the matrix in the observation result will not yet contain the result of this observer.
When the calculation finishes, the TLcyShapeObservationResult
instance will be updated and a
model change event is fired for the observation results model.
aDomainObjectContext
- The domain object this observer needs to observe.aDomainObjectContext
.
If the object was not yet under observation by a different observer, this will be a new instance.
If the object was already under observation by other observers, the existing result for that observee is updated and returned.IllegalArgumentException
- When the specified context cannot be observed (by this observer).canObserve(TLcdDomainObjectContext)
public void stopObserving(TLcdDomainObjectContext aDomainObjectContext)
Stop observing the specified domain object with this observer. This method modifies the observer, so it must be called under a write lock as illustrated blow:
//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"));
//Stop observing a specific shape
//As this modifies the point observer, it requires a lock on the point observer model
try (TLcdLockUtil.Lock autoUnlock = TLcdLockUtil.writeLock(pointObserverModel)) {
//Tell the observer to stop observing a specific object
pointObserver.stopObserving(aDomainObjectContextToObserve);
//Indicate to the model that the observer has been changed
pointObserverModel.elementChanged(pointObserver, ILcdModel.FIRE_LATER);
} finally {
pointObserverModel.fireCollectedModelChanges();
}
aDomainObjectContext
- The domain object this observer should stop observing.public ILcdBounds getBounds()
ILcdBounded
ILcdBounds
by which the geometry of this ILcdBounded
object
is bounded.
If the geometry does not allow retrieving valid bounds (for example a polyline with 0 points)
the return value is unspecified.
It is highly recommended to return an undefined
bounds.
You can create undefined bounds using the default constructors
of TLcdLonLatBounds
or TLcdXYBounds
.
getBounds
in interface ILcdBounded
ILcdBounds
by which the geometry of this ILcdBounded
object
is bounded.