Often, you need to know the visual details of the objects that are currently displayed. For example, you need to know the view or world bounds of an object, or you need to know what objects are displayed at a certain screen location.

To get that information, you can use the ILspInteractivePaintableLayer.query method. It accepts a query object, and returns the relevant information. The return value is dependent on the query. This allows you to write concise queries. This general construct is shown in Program: Retrieving information through ILspInteractivePaintableLayer.query.

Program: Retrieving information through ILspInteractivePaintableLayer.query
queryResult = layer.query(queryObject, context);

The LuciadLightspeed API offers several pre-defined queries:

  • TLspPaintedObjectsQuery: returns all domain objects overlapping with a certain region on the screen. Only currently painted objects are taken into account.

  • TLspPaintedObjectsTouchQuery: returns all domain objects overlapping with a certain screen region or screen point. The query also returns the coordinates at which the object touches the region or point. Only currently painted objects are taken into account.

  • TLspPaintedObjectsBoundsQuery: returns all domain objects overlapping with a certain screen region or screen point. The query also returns the view or world bounds of those objects. Only currently painted objects are taken into account.

  • TLspIsTouchedQuery: indicates whether the specified domain object or label is painted at a certain screen point. The query also returns the coordinates at which the object touches this point. This also works if the object has not been painted yet.

  • TLspBoundsQuery: returns the view or world bounds of the given domain object or label. This also works if the object has not been painted yet.

Note that these queries are delegated to the painter implementations. The painters take the actual representation on the screen into account as much as possible. If the size of the object changed on the screen through a specific styling or an icon, for example, the painters will use the size of the object on the screen to perform the query.

Program: Using query’s to determine the object under the cursor. demonstrates how the highlight controller uses queries to determine the object under the mouse cursor. It first determines the different paint steps taken by the view (not demonstrated in the program). Then it performs a TLspPaintedObjectsTouchQuery for each of the paint steps and keeps track of the object that is closest to the viewer. Note that we override the touched methods so that we can handle the results immediately as they become available, instead of copying them into a list first.

Program: Using queries to determine the object under the cursor. (from samples/lightspeed/customization/style/highlighting/HighlightController)
// Perform a query for each of the paint steps and update the highlighting candidate
final CandidateChooser candidateChooser = new CandidateChooser(aViewPoint);
for (ILspPaintingOrder.PaintStep paintStep : paintSteps) {
  // Query for the current paint step
  final ILspInteractivePaintableLayer layer = (ILspInteractivePaintableLayer) paintStep.getLayer();
  layer.query(
      new TLspPaintedObjectsTouchQuery(
          paintStep.getPaintRepresentationState(),
          aViewPoint,
          SENSITIVITY
      ) {
        @Override
        public boolean touched(ALspWorldTouchInfo aTouchInfo) {
          // We have touched an object at a point in world coordinates, update the candidate
          candidateChooser.touched(layer, getPaintRepresentationState(), aTouchInfo);
          return true;
        }

        @Override
        public boolean touched(ALspViewTouchInfo aTouchInfo) {
          // We have touched an object at a point in view coordinates, update the candidate
          candidateChooser.touched(layer, getPaintRepresentationState(), aTouchInfo);
          return true;
        }
      },
      new TLspContext(layer, view)
  );
}
return candidateChooser.getCandidate();