Base class for interactive drawing operations (jigs) in the CAD editor.

A jig is an interactive operation that allows users to dynamically preview and modify geometric elements during creation. Common examples include:

  • Drawing lines with real-time preview as the mouse moves
  • Selecting rectangular areas with visual feedback
  • Dynamic entity placement with instant visual updates

The jig system provides:

  • Real-time visual feedback during user interaction
  • Event-driven updates based on mouse movement
  • Asynchronous completion handling
  • Cancellation and error handling
class RectangleSelectionJig extends AcEdJig<Rectangle> {
private startPoint?: Point;
private currentPoint?: Point;

async sampler() {
// Get start point
this.startPoint = await this.view.editor.getPoint();

// Continue updating until complete
this.view.events.mouseMove.addEventListener(this.onMouseMove);
}

update() {
if (this.startPoint && this.currentPoint) {
// Update preview rectangle
this.drawPreviewRectangle(this.startPoint, this.currentPoint);
}
}

private onMouseMove = (args) => {
this.currentPoint = args;
// Jig loop will call update() automatically
}
}

// Usage
const jig = new RectangleSelectionJig(view);
const rectangle = await jig.drag();

Type Parameters

  • TResult

    The type of result returned when the jig completes

Hierarchy (View Summary)

Constructors

Accessors

Methods

Constructors

Accessors

Methods

  • Starts the interactive jig operation.

    This method initiates both the jig loop and the sampling process. It returns a promise that resolves when the jig operation completes or rejects if an error occurs.

    Returns Promise<void>

    Promise that resolves when the jig operation completes

    const jig = new MyCustomJig(view);
    try {
    const result = await jig.drag();
    console.log('Jig completed with result:', result);
    } catch (error) {
    console.log('Jig was cancelled or failed:', error);
    }
  • Rejects the jig operation with an error.

    This method should be called when the jig operation fails or is cancelled. It cleans up event listeners and rejects the underlying promise.

    Parameters

    • reason: string

      The reason for the rejection

    Returns void

    // If user cancels or invalid input is detected
    if (userPressedEscape) {
    this.reject('Operation cancelled by user');
    }
  • Resolves the jig operation with the specified result.

    This method should be called when the jig operation completes successfully. It cleans up event listeners and resolves the underlying promise.

    Parameters

    • result: TResult

      The result to return from the jig operation

    Returns void

    // In a line drawing jig, when user completes the line
    if (this.hasValidEndPoint()) {
    const line = new Line(this.startPoint, this.endPoint);
    this.resolve(line);
    }
  • Abstract method for handling jig input sampling.

    This method should be overridden by subclasses to implement the specific input handling logic for the jig. It typically:

    • Gets initial user input (like a start point)
    • Sets up event listeners for dynamic updates
    • Handles user interaction until completion

    The sampler runs concurrently with the jig loop and should call resolve() or reject() when the operation completes.

    Returns Promise<void>

    async sampler() {
    // Get initial point
    const startPoint = await this.view.editor.getPoint();

    // Set up mouse tracking for dynamic preview
    this.view.events.mouseMove.addEventListener(this.onMouseMove);
    this.view.events.mouseClick.addEventListener(this.onMouseClick);
    }
  • Called during each update cycle to refresh the jig display.

    This method should be overridden by subclasses to implement the visual update logic. It's called automatically by the jig loop whenever the display needs to be refreshed (typically on mouse movement).

    Common update operations include:

    • Redrawing preview geometry
    • Updating dimension displays
    • Refreshing visual feedback elements

    Returns void

    update() {
    if (this.startPoint && this.currentMousePoint) {
    // Clear previous preview
    this.clearPreview();

    // Draw new preview line
    this.drawPreviewLine(this.startPoint, this.currentMousePoint);
    }
    }