Class TLcyShapeObserver
- All Implemented Interfaces:
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:
- A link to the domain object for which this observer was created.
- A
list of domain objects
that are currently being observed by this observer. - Methods to start and stop observing objects.
- During the visibility calculations, certain settings are used for each observer and observee.
These settings are derived from the
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);
}
- Since:
- 2019.1
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canObserve
(TLcdDomainObjectContext aDomainObjectContext) Returnstrue
when the specified domain object context can be observed by this observer.Returns theILcdBounds
by which the geometry of thisILcdBounded
object is bounded.Returns the list of domain object contexts this observer is currently observing.Returns the domain object context for which this observer was created.Returns the altitude mode indicating how to interpret the Z-values of the observer shape.Returns the point shape based on the point that was created by theTLcyShapeVisibilityAddOn.createPointObserverShapeProvider()
function for this observer, and which is used in the visibility calculations.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.
-
Method Details
-
getObserver
Returns the domain object context for which this observer was created.- Returns:
- the domain object context which this observer was created.
-
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:
- is defined in the model reference of the model containing the observer.
- has a Z-value that should be interpreted using
getObserverCoverageAltitudeMode()
.
The returned point should not be modified.
- Returns:
- the point shape used in the visibility calculations for this observer
- Since:
- 2020.1
- See Also:
-
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.- Returns:
- the altitude mode for the observer shape.
- Since:
- 2020.1
- See Also:
-
getObservees
Returns the list of domain object contexts this observer is currently observing.
This list cannot be modified directly. Use the
startObserving(TLcdDomainObjectContext)
andstopObserving(TLcdDomainObjectContext)
methods to start or stop observing specific domain objects.- Returns:
- the list of domain object contexts this observer is currently observing.
Possibly empty, never
null
-
canObserve
Returns
true
when the specified domain object context can be observed by this observer.Currently this method only returns
true
when:- The view in the context is the same view as the one for which this observer was created.
- The domain object is not the same as the one for which this observer was created: the observer cannot observe itself.
- The model, layer and view are specified in the context.
- The model in the context is not a model created by the
TLcyShapeVisibilityAddOn
. - This observer is not yet observing the domain object.
- The
TLcyShapeVisibilityAddOn.createObserveeShapeProvider()
function can retrieve a shape for the context.
- Parameters:
aDomainObjectContext
- The context to check- Returns:
true
when the specified domain object context can be observed by this observer.
-
startObserving
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.- Parameters:
aDomainObjectContext
- The domain object this observer needs to observe.- Returns:
- The observation result for
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. - Throws:
IllegalArgumentException
- When the specified context cannot be observed (by this observer).- See Also:
-
stopObserving
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(); }
- Parameters:
aDomainObjectContext
- The domain object this observer should stop observing.
-
getBounds
Description copied from interface:ILcdBounded
Returns theILcdBounds
by which the geometry of thisILcdBounded
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 ofTLcdLonLatBounds
orTLcdXYBounds
.- Specified by:
getBounds
in interfaceILcdBounded
- Returns:
- the
ILcdBounds
by which the geometry of thisILcdBounded
object is bounded.
-