diff --git a/embind/bindings.cpp b/embind/bindings.cpp index c1f1d12..caded3b 100644 --- a/embind/bindings.cpp +++ b/embind/bindings.cpp @@ -104,7 +104,10 @@ EMSCRIPTEN_BINDINGS(my_module) { .value("ConnType_Orthogonal", Avoid::ConnType_Orthogonal); class_("Checkpoint") - .constructor(); + .constructor() + .constructor(); + + register_vector("CheckpointVector"); class_("ConnRef") .constructor() @@ -115,6 +118,8 @@ EMSCRIPTEN_BINDINGS(my_module) { .function("setDestEndpoint", &Avoid::ConnRef::setDestEndpoint) .function("routingType", &Avoid::ConnRef::routingType) .function("setRoutingType", &Avoid::ConnRef::setRoutingType) + .function("setRoutingCheckpoints", &Avoid::ConnRef::setRoutingCheckpoints, allow_raw_pointers()) + .function("routingCheckpoints", &Avoid::ConnRef::routingCheckpoints) .function("displayRoute", &Avoid::ConnRef::displayRoute, allow_raw_pointers()) .function("setHateCrossings", &Avoid::ConnRef::setHateCrossings) .function("doesHateCrossings", &Avoid::ConnRef::doesHateCrossings); diff --git a/typings/libavoid.d.ts b/typings/libavoid.d.ts index 66cb67d..e84015a 100644 --- a/typings/libavoid.d.ts +++ b/typings/libavoid.d.ts @@ -6,6 +6,28 @@ declare interface Point { y: number; } +declare enum RoutingParameter { + "segmentPenalty", + "anglePenalty", + "crossingPenalty", + "clusterCrossingPenalty", + "fixedSharedPathPenalty", + "portDirectionPenalty", + "shapeBufferDistance", + "idealNudgingDistance", + "reverseDirectionPenalty", +} + +declare enum RoutingOption { + "nudgeOrthogonalSegmentsConnectedToShapes", + "improveHyperedgeRoutesMovingJunctions", + "penaliseOrthogonalSharedPathsAtConnEnds", + "nudgeOrthogonalTouchingColinearSegments", + "performUnifyingNudgingPreprocessingStep", + "improveHyperedgeRoutesMovingAddingAndDeletingJunctions", + "nudgeSharedPathsWithCommonEndPoint", +} + declare interface Router { new (flags: number): Router; @@ -13,16 +35,18 @@ declare interface Router { printInfo(): void; deleteConnector(connRef: ConnRef): void; - moveShape(shape: ShapeRef, newPolygon: Polygon); - moveShape(shape: ShapeRef, xDiff: number, yDiff: number); + moveShape_poly(shape: ShapeRef, newPolygon: Polygon); + moveShape_delta(shape: ShapeRef, xDiff: number, yDiff: number); deleteShape(shape: ShapeRef); - setRoutingParameter(parameter: number, value: number): void; - setRoutingOption(option: number, value: boolean): void; + setRoutingParameter(parameter: RoutingParameter, value: number): void; + setRoutingOption(option: RoutingOption, value: boolean): void; + + delete(): void; } declare interface PolyLine { size(): number; - get_ps(index: number): Point; + at(index: number): Point; } declare interface ConnEnd { @@ -31,6 +55,16 @@ declare interface ConnEnd { createConnEndFromJunctionRef(JunctionRef: JunctionRef, classId: number): ConnEnd; } +declare interface Checkpoint { + new (point: Point): Checkpoint; + new (point: Point, ad: ConnDirFlags, dd: ConnDirFlags): Checkpoint; +} + +declare interface CheckpointVector { + new (): CheckpointVector; + push_back(checkpoint: Checkpoint): void; +} + declare interface ConnRef { new (router: Router): ConnRef; new (router: Router, srcConnEnd: ConnEnd, dstConnEnd: ConnEnd): ConnRef; @@ -39,6 +73,9 @@ declare interface ConnRef { setSourceEndpoint(srcPoint: ConnEnd): void; setDestEndpoint(dstPoint: ConnEnd): void; setRoutingType(type: number): void; + setRoutingCheckpoints(checkpoints: CheckpointVector): void; + routingCheckpoints(): CheckpointVector; + // connRefPtr is raw pointer to the object, to get ConnRef object use: // `const connRef = Avoid.wrapPointer(connRefPtr, Avoid.ConnRef)` // more details: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html#pointers-and-comparisons @@ -62,6 +99,7 @@ declare interface ShapeConnectionPin { directions(): ConnDirFlags; position(): Point; updatePosition(newPosition: Point): void; + delete(): void; } @@ -101,6 +139,8 @@ export interface Avoid { ConnEnd: ConnEnd; ConnRef: ConnRef; + Checkpoint: Checkpoint; + CheckpointVector: CheckpointVector; Point: Point; Rectangle: Rectangle; Router: Router; @@ -109,6 +149,9 @@ export interface Avoid { JunctionRef: JunctionRef; ShapeConnectionPin: ShapeConnectionPin; + RoutingParameter: Record; + RoutingOption: Record; + destroy(obj: any): void; getPointer(obj: any): number; wrapPointer(ptr: number, Class: T): T;