Skip to content

Commit bd8af47

Browse files
authored
Feature/checkpoints support (#33)
* feat: added checkpoints binding methods * feat: added checkpoint methods types * feat: added RoutingParameter and RoutingOption enums to types * fix: several fixes related with using of embind instead of WebIDLBinder
1 parent 062b856 commit bd8af47

2 files changed

Lines changed: 54 additions & 6 deletions

File tree

embind/bindings.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ EMSCRIPTEN_BINDINGS(my_module) {
104104
.value("ConnType_Orthogonal", Avoid::ConnType_Orthogonal);
105105

106106
class_<Avoid::Checkpoint>("Checkpoint")
107-
.constructor<const Avoid::Point&>();
107+
.constructor<const Avoid::Point&>()
108+
.constructor<const Avoid::Point&, Avoid::ConnDirFlags, Avoid::ConnDirFlags>();
109+
110+
register_vector<Avoid::Checkpoint>("CheckpointVector");
108111

109112
class_<Avoid::ConnRef>("ConnRef")
110113
.constructor<Avoid::Router*, const Avoid::ConnEnd&, const Avoid::ConnEnd&>()
@@ -115,6 +118,8 @@ EMSCRIPTEN_BINDINGS(my_module) {
115118
.function("setDestEndpoint", &Avoid::ConnRef::setDestEndpoint)
116119
.function("routingType", &Avoid::ConnRef::routingType)
117120
.function("setRoutingType", &Avoid::ConnRef::setRoutingType)
121+
.function("setRoutingCheckpoints", &Avoid::ConnRef::setRoutingCheckpoints, allow_raw_pointers())
122+
.function("routingCheckpoints", &Avoid::ConnRef::routingCheckpoints)
118123
.function("displayRoute", &Avoid::ConnRef::displayRoute, allow_raw_pointers())
119124
.function("setHateCrossings", &Avoid::ConnRef::setHateCrossings)
120125
.function("doesHateCrossings", &Avoid::ConnRef::doesHateCrossings);

typings/libavoid.d.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,47 @@ declare interface Point {
66
y: number;
77
}
88

9+
declare enum RoutingParameter {
10+
"segmentPenalty",
11+
"anglePenalty",
12+
"crossingPenalty",
13+
"clusterCrossingPenalty",
14+
"fixedSharedPathPenalty",
15+
"portDirectionPenalty",
16+
"shapeBufferDistance",
17+
"idealNudgingDistance",
18+
"reverseDirectionPenalty",
19+
}
20+
21+
declare enum RoutingOption {
22+
"nudgeOrthogonalSegmentsConnectedToShapes",
23+
"improveHyperedgeRoutesMovingJunctions",
24+
"penaliseOrthogonalSharedPathsAtConnEnds",
25+
"nudgeOrthogonalTouchingColinearSegments",
26+
"performUnifyingNudgingPreprocessingStep",
27+
"improveHyperedgeRoutesMovingAddingAndDeletingJunctions",
28+
"nudgeSharedPathsWithCommonEndPoint",
29+
}
30+
931
declare interface Router {
1032
new (flags: number): Router;
1133

1234
processTransaction(): void;
1335
printInfo(): void;
1436
deleteConnector(connRef: ConnRef): void;
1537

16-
moveShape(shape: ShapeRef, newPolygon: Polygon);
17-
moveShape(shape: ShapeRef, xDiff: number, yDiff: number);
38+
moveShape_poly(shape: ShapeRef, newPolygon: Polygon);
39+
moveShape_delta(shape: ShapeRef, xDiff: number, yDiff: number);
1840
deleteShape(shape: ShapeRef);
19-
setRoutingParameter(parameter: number, value: number): void;
20-
setRoutingOption(option: number, value: boolean): void;
41+
setRoutingParameter(parameter: RoutingParameter, value: number): void;
42+
setRoutingOption(option: RoutingOption, value: boolean): void;
43+
44+
delete(): void;
2145
}
2246

2347
declare interface PolyLine {
2448
size(): number;
25-
get_ps(index: number): Point;
49+
at(index: number): Point;
2650
}
2751

2852
declare interface ConnEnd {
@@ -31,6 +55,16 @@ declare interface ConnEnd {
3155
createConnEndFromJunctionRef(JunctionRef: JunctionRef, classId: number): ConnEnd;
3256
}
3357

58+
declare interface Checkpoint {
59+
new (point: Point): Checkpoint;
60+
new (point: Point, ad: ConnDirFlags, dd: ConnDirFlags): Checkpoint;
61+
}
62+
63+
declare interface CheckpointVector {
64+
new (): CheckpointVector;
65+
push_back(checkpoint: Checkpoint): void;
66+
}
67+
3468
declare interface ConnRef {
3569
new (router: Router): ConnRef;
3670
new (router: Router, srcConnEnd: ConnEnd, dstConnEnd: ConnEnd): ConnRef;
@@ -39,6 +73,9 @@ declare interface ConnRef {
3973
setSourceEndpoint(srcPoint: ConnEnd): void;
4074
setDestEndpoint(dstPoint: ConnEnd): void;
4175
setRoutingType(type: number): void;
76+
setRoutingCheckpoints(checkpoints: CheckpointVector): void;
77+
routingCheckpoints(): CheckpointVector;
78+
4279
// connRefPtr is raw pointer to the object, to get ConnRef object use:
4380
// `const connRef = Avoid.wrapPointer(connRefPtr, Avoid.ConnRef)`
4481
// more details: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html#pointers-and-comparisons
@@ -62,6 +99,7 @@ declare interface ShapeConnectionPin {
6299
directions(): ConnDirFlags;
63100
position(): Point;
64101
updatePosition(newPosition: Point): void;
102+
delete(): void;
65103
}
66104

67105

@@ -101,6 +139,8 @@ export interface Avoid {
101139

102140
ConnEnd: ConnEnd;
103141
ConnRef: ConnRef;
142+
Checkpoint: Checkpoint;
143+
CheckpointVector: CheckpointVector;
104144
Point: Point;
105145
Rectangle: Rectangle;
106146
Router: Router;
@@ -109,6 +149,9 @@ export interface Avoid {
109149
JunctionRef: JunctionRef;
110150
ShapeConnectionPin: ShapeConnectionPin;
111151

152+
RoutingParameter: Record<keyof typeof RoutingParameter, RoutingParameter>;
153+
RoutingOption: Record<keyof typeof RoutingOption, RoutingOption>;
154+
112155
destroy(obj: any): void;
113156
getPointer(obj: any): number;
114157
wrapPointer<T>(ptr: number, Class: T): T;

0 commit comments

Comments
 (0)