Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save textnode movement nad #126

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export type OnMoveTextNodeCallbackType = (
connectionShiftX: number,
connectionShiftY: number,
connectionShiftXOrig: number,
connectionShiftYOrig: number
connectionShiftYOrig: number,
mousePosition: Point
) => void;

export type OnSelectNodeCallbackType = (equipmentId: string, nodeId: string) => void;
Expand Down Expand Up @@ -180,15 +181,31 @@ export class NetworkAreaDiagramViewer {
);
return node?.svgId || null;
}

private getTextNodeIdFromEquipmentId(equipmentId: string) {
const node: TextNodeMetadata | undefined = this.diagramMetadata?.textNodes.find(
(node) => node.equipmentId == equipmentId
);
return node?.svgId || null;
}
public moveNodeToCoordinates(equipmentId: string, x: number, y: number) {
const nodeId = this.getNodeIdFromEquipmentId(equipmentId);
if (nodeId != null) {
const elemToMove: SVGElement | null = this.container.querySelector('[id="' + nodeId + '"]');
if (elemToMove) {
const newPosition = new Point(x, y);
this.onDragStart(elemToMove);
this.onDragEnd(newPosition, false);
this.onDragEnd(newPosition, false, false);
}
}
}
public moveTextNodeToCoordinates(equipmentId: string, x: number, y: number) {
const textnodeId = this.getTextNodeIdFromEquipmentId(equipmentId);
if (textnodeId != null) {
const elemToMove: SVGElement | null = this.container.querySelector('[id="' + textnodeId + '"]');
if (elemToMove) {
const newPosition = new Point(x, y);
this.onDragStart(elemToMove);
this.onDragEnd(newPosition, false, false);
}
}
}
Expand Down Expand Up @@ -425,17 +442,17 @@ export class NetworkAreaDiagramViewer {
// check if I moved or selected an element
if (this.draggedElement) {
// moving node
this.onDragEnd(this.getMousePosition(event), true);
this.onDragEnd(this.getMousePosition(event), true, true);
} else if (this.selectedElement) {
// selecting node
this.onSelectEnd();
}
}

private onDragEnd(newPosition: Point, callMoveNodeCallback: boolean) {
private onDragEnd(newPosition: Point, callMoveNodeCallback: boolean, callMoveTextNodeCallback: boolean) {
if (this.textNodeSelected) {
this.dragVoltageLevelText(newPosition);
this.updateTextNodeMetadataCallCallback(newPosition);
this.updateTextNodeMetadataCallCallback(newPosition, callMoveTextNodeCallback);
} else {
this.dragVoltageLevelNode(newPosition);
this.updateNodeMetadataCallCallback(newPosition, callMoveNodeCallback);
Expand Down Expand Up @@ -1223,7 +1240,7 @@ export class NetworkAreaDiagramViewer {
}
}

private updateTextNodeMetadataCallCallback(mousePosition: Point) {
private updateTextNodeMetadataCallCallback(mousePosition: Point, callMoveTextNodeCallback: boolean) {
sBouzols marked this conversation as resolved.
Show resolved Hide resolved
if (this.onMoveTextNodeCallback != null) {
// get from metadata node connected to moved text node
const node: NodeMetadata | undefined = this.diagramMetadata?.nodes.find(
Expand All @@ -1242,19 +1259,22 @@ export class NetworkAreaDiagramViewer {
textNode.connectionShiftX = textNodeMoves[1].xNew;
textNode.connectionShiftY = textNodeMoves[1].yNew;
// call the node move callback, if defined
this.onMoveTextNodeCallback(
node.equipmentId,
node.svgId,
textNode.svgId,
textNodeMoves[0].xNew,
textNodeMoves[0].yNew,
textNodeMoves[0].xOrig,
textNodeMoves[0].yOrig,
textNodeMoves[1].xNew,
textNodeMoves[1].yNew,
textNodeMoves[1].xOrig,
textNodeMoves[1].yOrig
);
if (callMoveTextNodeCallback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move test over this.onMoveTextNodeCallback here

if (this.onMoveTextNodeCallback != null && callMoveTextNodeCallback) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should create another bug I think. If you don't define a onMoveTextNodeCallback function then moving textNode should not work at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? still able to move node even if onMoveTextNodeCallback (tested)

this.onMoveTextNodeCallback(
node.equipmentId,
node.svgId,
textNode.svgId,
textNodeMoves[0].xNew,
textNodeMoves[0].yNew,
textNodeMoves[0].xOrig,
textNodeMoves[0].yOrig,
textNodeMoves[1].xNew,
textNodeMoves[1].yNew,
textNodeMoves[1].xOrig,
textNodeMoves[1].yOrig,
mousePosition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need mousePosition here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mousePosition to save the newPosition of dragged text node

);
}
}
}
}
Expand Down
Loading