Abstract base class for all CAD view implementations.

This class provides the foundation for rendering and interacting with CAD drawings. It manages:

  • Canvas and viewport dimensions
  • Mouse event handling and coordinate conversion
  • Entity selection and highlighting
  • View modes (selection, pan, etc.)
  • Spatial queries for entity picking
  • Hover/unhover detection with timing

Concrete implementations must provide specific rendering logic and coordinate transformations appropriate for their rendering technology (e.g., Three.js, SVG).

  • Input Management: Handles mouse events and user interactions
  • Selection: Manages selected entities and visual feedback
  • Coordinate Systems: Converts between screen and world coordinates
  • Spatial Queries: Finds entities at specific locations
  • View State: Tracks current position, zoom, and view mode
class MyView extends AcEdBaseView {
// Implement required abstract methods
get missedData() { return { fonts: {}, images: new Map() }; }
get mode() { return this._mode; }
set mode(value) { this._mode = value; }
// ... other abstract methods
}

const view = new MyView(canvasElement);
view.events.mouseMove.addEventListener(args => {
console.log('Mouse at world coords:', args.x, args.y);
});

Hierarchy (View Summary)

Constructors

  • Creates a new base view instance.

    Sets up the canvas, initializes internal state, and registers event listeners for mouse interactions and window resize events.

    Parameters

    • canvas: HTMLCanvasElement

      The HTML canvas element to render into

    Returns AcEdBaseView

Properties

_canvas: HTMLCanvasElement

The HTML canvas element for rendering

events: {
    hover: AcCmEventManager<AcEdViewHoverEventArgs>;
    mouseMove: AcCmEventManager<AcEdMouseEventArgs>;
    unhover: AcCmEventManager<AcEdViewHoverEventArgs>;
    viewResize: AcCmEventManager<AcEdViewResizedEventArgs>;
} = ...

Events fired by the view for various interactions

Type declaration

Accessors

  • get center(): AcGePoint2d

    Gets the center point of the current view in world coordinates.

    Returns AcGePoint2d

    The view center point

  • set center(value: AcGePoint2d): void

    Sets the center point of the current view in world coordinates.

    Parameters

    • value: AcGePoint2d

      The new center point

    Returns void

  • get editor(): AcEditor

    Gets the input manager for handling user interactions.

    The editor provides high-level methods for getting user input like point selection, entity selection, and cursor management.

    Returns AcEditor

    The editor instance

  • get missedData(): AcEdMissedData

    Gets information about missing data during rendering.

    This includes fonts that couldn't be loaded and images that are missing or inaccessible. Implementations should track and report this information to help users understand rendering issues.

    Returns AcEdMissedData

    Object containing missing fonts and images

  • get selectionBoxSize(): number

    Gets the size of the selection box used for entity picking.

    This determines how close the mouse needs to be to an entity to select it, measured in screen pixels.

    Returns number

    Selection box size in pixels

  • set selectionBoxSize(value: number): void

    Sets the size of the selection box used for entity picking.

    Parameters

    • value: number

      Selection box size in pixels

    Returns void

Methods

  • Add the specified entity in drawing database into the current scene and draw it

    Parameters

    • entity: AcDbEntity

      Input the entity to add into the current scene

    Returns void

  • Converts a point from client window coordinates to world coordinates.

    The client window coordinate system has its origin at the top-left corner of the canvas, with Y increasing downward. World coordinates use the CAD coordinate system with Y typically increasing upward.

    Parameters

    • point: AcGeVector2dLike

      Point in client window coordinates

    Returns AcGePoint2d

    Point in world coordinates

    const screenPoint = { x: 100, y: 200 }; // 100px right, 200px down
    const worldPoint = view.cwcs2Wcs(screenPoint);
    console.log('World coordinates:', worldPoint.x, worldPoint.y);
  • Pick entities intersected with the specified point in the world coordinate system.

    Parameters

    • Optionalpoint: AcGeVector2dLike

      Input the point to pick objects. If not provided, the position of current cursor is used.

    Returns string[]

    Return ids of entities intersected with the specified point

  • Select entities intersected with the specified point in the world coordinate system, add them to the current selection set, and highlight them.

    Parameters

    • Optionalpoint: AcGeVector2dLike

    Returns void

  • Select entities intersected with the specified bounding box in the world coordinate system, add them to the current selection set, and highlight them.

    Parameters

    • box: AcGeBox2d

      Input one bounding box in the world coordinate system.

    Returns void

  • Set layer's visibility

    Parameters

    • layerName: string

      Input layer name

    • visible: boolean

      Input visibility of the layer

    Returns void

  • Update the specified entity

    Parameters

    • entity: AcDbEntity

      Input the entity to update

    Returns void

  • Converts a point from world coordinates to client window coordinates.

    This is the inverse of cwcs2Wcs(), converting from the CAD world coordinate system to screen pixel coordinates.

    Parameters

    • point: AcGeVector2dLike

      Point in world coordinates

    Returns AcGePoint2d

    Point in client window coordinates

    const worldPoint = new AcGePoint2d(10, 20); // CAD coordinates
    const screenPoint = view.wcs2Cwcs(worldPoint);
    console.log('Screen position:', screenPoint.x, screenPoint.y);