//Defines the clone tool used to copy Node/Connector
class CustomConnectorDrawingTool extends ConnectorDrawingTool {
public diagram: Diagram = null;
private node: NodeModel;
public mouseMove(args: MouseEventArgs): boolean {
return super.mouseMove(args);
}
public mouseUp(args: MouseEventArgs): Promise<void> {
args.source = this.node as IElement;
if (args.source) args.sourceWrapper = args.source.wrapper;
let portId = null;
console.log(args)
let target = args.target as any as NodeModel;
for(let port of target.ports as Port[]){
if((port.constraints & PortConstraints.OutConnect) && !port.outEdges || port.outEdges.length == 0){
portId = port.id;
break;
}
}
(this.drawingObject as ConnectorModel).targetPortID = portId;
let superReturn = super.mouseUp(args);
return superReturn;
}
mouseLeave(args: MouseEventArgs): void {
args.source = this.node as IElement;
if (args.source) args.sourceWrapper = args.source.wrapper;
}
public mouseDown(args: MouseEventArgs): Promise<void> {
this.node = this.diagram.selectedItems.nodes[0] as IElement;
//find an open port
let portId = null;
if(this.node.id != "start") {
for (let port of this.node.ports as Port[]) {
if ((port.constraints & PortConstraints.InConnect) && !port.outEdges || port.outEdges.length == 0) {
portId = port.id;
break;
}
}
}
args.position = {
x: this.node.offsetX,
y: this.node.offsetY
};
args.source = this.node as IElement;
args.actualObject = this.node as IElement;
if (args.source) args.sourceWrapper = args.source.wrapper;
let connectionModel: ConnectorModel = {
type: "Orthogonal",
constraints: ConnectorConstraints.Default | ConnectorConstraints.LineRouting,
sourceID: args.actualObject.wrapper.id,
sourcePortID: portId,
}
this.diagram.drawingObject = connectionModel;
return super.mouseDown(args);
}
|
public nodeDefaults(node: NodeModel): NodeModel {
let obj: NodeModel = {};
//sets height and width for nodes
obj.height = 65;
obj.width = 100;
obj.style = { fill: "#ebf8fb", strokeColor: "#baeaf5" };
for (let i: number = 0; i < node.ports.length; i++) {
//sets styles for the ports
node.ports[i].style = {
fill: "#366f8c",
strokeColor: "#366f8c"
};
node.ports[i].width = 10;
node.ports[i].height = 10;
node.ports[i].visibility = PortVisibility.Visible;
node.ports[i].constraints =
PortConstraints.Default | PortConstraints.Draw;
}
return obj;
} |
for(let port of target.ports as Port[]){
if((port.constraints & PortConstraints.InConnect) && (!port.inEdges || port.inEdges.length == 0)){
portId = port.id;
break;
}
}