Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion embind/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ EMSCRIPTEN_BINDINGS(my_module) {
.value("ConnType_Orthogonal", Avoid::ConnType_Orthogonal);

class_<Avoid::Checkpoint>("Checkpoint")
.constructor<const Avoid::Point&>();
.constructor<const Avoid::Point&>()
.constructor<const Avoid::Point&, Avoid::ConnDirFlags, Avoid::ConnDirFlags>();

register_vector<Avoid::Checkpoint>("CheckpointVector");

class_<Avoid::ConnRef>("ConnRef")
.constructor<Avoid::Router*, const Avoid::ConnEnd&, const Avoid::ConnEnd&>()
Expand All @@ -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);
Expand Down
53 changes: 48 additions & 5 deletions typings/libavoid.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,47 @@ 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;

processTransaction(): void;
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 {
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -62,6 +99,7 @@ declare interface ShapeConnectionPin {
directions(): ConnDirFlags;
position(): Point;
updatePosition(newPosition: Point): void;
delete(): void;
}


Expand Down Expand Up @@ -101,6 +139,8 @@ export interface Avoid {

ConnEnd: ConnEnd;
ConnRef: ConnRef;
Checkpoint: Checkpoint;
CheckpointVector: CheckpointVector;
Point: Point;
Rectangle: Rectangle;
Router: Router;
Expand All @@ -109,6 +149,9 @@ export interface Avoid {
JunctionRef: JunctionRef;
ShapeConnectionPin: ShapeConnectionPin;

RoutingParameter: Record<keyof typeof RoutingParameter, RoutingParameter>;
RoutingOption: Record<keyof typeof RoutingOption, RoutingOption>;

destroy(obj: any): void;
getPointer(obj: any): number;
wrapPointer<T>(ptr: number, Class: T): T;
Expand Down