Overview
TheMeasurementController class provides interactive measurement tools for the sky widget, including rulers, circles, squares, and rectangles. All measurements are spherically accurate using great-circle distances and geodesic arcs.
Class Definition
Constants
Tool Types
TOOL_NONE: str = "none"- No active toolTOOL_RULER: str = "ruler"- Angular distance measurementTOOL_SQUARE: str = "square"- Square framing toolTOOL_RECTANGLE: str = "rectangle"- Rectangular framing tool with rotationTOOL_CIRCLE: str = "circle"- Circular framing tool
Drag Modes
DRAG_NONE: str = "none"- No drag operationDRAG_CREATING: str = "creating"- Creating new measurementDRAG_MOVING: str = "moving"- Moving existing measurementDRAG_RESIZING: str = "resizing"- Resizing via handle
Type Definitions
Dataclasses
MeasurementItem
Represents a single measurement on the sky.tool(str) - Type of measurement toola(SkyCoord) - First defining point (ruler start, circle center, rectangle origin)b(SkyCoord) - Second defining point (ruler end, circle edge, rectangle corner)rotation_deg(float) - Local-frame rotation for rectangles (default: 0.0)
RenderInfo
Contains rendering information for a measurement item.paths(List[List[SkyCoord]]) - Geodesic paths defining the shape boundarylabel(str) - Formatted measurement text (e.g., “Distance: 12.345deg”)anchor(SkyCoord) - Position for label placementhandles(Dict[str, SkyCoord]) - Interactive resize/rotate handleshit_polygon(Optional[List[SkyCoord]]) - Polygon for interior hit testing (circles and rectangles)
MeasurementController
Constructor
Attributes
active_tool: str- Currently active tool (default: TOOL_NONE)current_start: Optional[SkyCoord]- Start point of measurement being createdcurrent_cursor: Optional[SkyCoord]- Current cursor position during creationruler_first_point: Optional[SkyCoord]- First point for ruler (two-click mode)items: List[MeasurementItem]- List of all measurementsselected_index: Optional[int]- Index of selected measurementdrag_mode: str- Current drag operation moderesize_handle: Optional[str]- Name of handle being draggedlast_drag_sky: Optional[SkyCoord]- Last sky position during draghandle_hit_px: float- Hit radius for handles in pixels (default: 12.0)shape_hit_px: float- Hit distance for shape edges in pixels (default: 8.0)
Methods
Tool Management
tool(str) - Tool constant (TOOL_NONE, TOOL_RULER, TOOL_CIRCLE, TOOL_SQUARE, TOOL_RECTANGLE)
- bool - True if a measurement was deleted, False otherwise
- bool - True if user is currently interacting with measurements
Mouse Event Handling
sx(float) - Screen X coordinatesy(float) - Screen Y coordinateunproject_fn(Callable) - Function to convert screen coords to sky coordsproject_fn(Optional[Callable]) - Function to project sky coords to screen (required for hit testing)
- bool - True if event was consumed
- Checks for hits on existing measurements (handles first, then shapes)
- If hit, selects item and starts drag (resize if handle, move if shape body)
- If no hit, starts creating new measurement
- Ruler uses two-click mode (first click sets start, second click completes)
sx(float) - Screen X coordinatesy(float) - Screen Y coordinateunproject_fn(Callable) - Function to convert screen coords to sky coordsproject_fn(Optional[Callable]) - Function to project sky coords to screen
- bool - True if event was consumed
- Updates preview during creation
- Moves or resizes measurement during drag
- Updates ruler preview between first and second click
sx(float) - Screen X coordinatesy(float) - Screen Y coordinateunproject_fn(Callable) - Function to convert screen coords to sky coordsproject_fn(Optional[Callable]) - Function to project sky coords to screen
- bool - True if event was consumed
- Finalizes measurement creation and adds to items list
- Ends drag operation
- Resets drag state
sx(float) - Screen X coordinatesy(float) - Screen Y coordinateunproject_fn(Callable) - Function to convert screen coords to sky coords
Rendering
painter(QPainter) - Qt painter objectproject_fn(Callable) - Function to project sky coords (alt, az) to screen coords (x, y)formatters(Dict[str, Callable]) - Value formatters (currently unused, reserved for future)
- Draws all completed measurements
- Draws preview for measurement being created
- Highlights selected measurement with golden color
- Shows interactive handles for selected measurement
- Renders geodesic arcs (not straight lines) for spherical accuracy
- Displays HUD labels with measurements
Usage Example
Advanced Usage: Rectangle Rotation
Programmatic Measurement Creation
Integration Notes
- All measurements use spherical geometry (great-circle distances, geodesic arcs)
- Requires
unproject_fnto convert screen → sky andproject_fnfor sky → screen - Uses functions from
spherical_mathmodule:angular_distance(),destination_point(),slerp_arc_points(),angular_delta_signed() - Rectangle areas use small-angle approximation (sufficient for typical FOV framing)
- For large areas, consider implementing exact spherical cap area calculation
- Handles are automatically drawn for selected measurements
- HUD labels auto-size to fit content and use rounded dark backgrounds
- Hit testing works on both shape edges (polyline distance) and filled interiors (point-in-polygon)