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

nad-viewer: update bus connections #163

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

clementleclercRTE
Copy link

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem?

What kind of change does this PR introduce?

Adding bus connection capability to branches in the Network Area Diagram viewer

Does this PR introduce a new Powsybl Action implying to be implemented in simulators or pypowsybl?

  • Yes, the corresponding issue is here
  • No

What is the current behavior?

Currently, the NetworkAreaDiagramViewer allows moving branches and updating their states, but doesn't support dynamically changing which bus a branch is connected to within a voltage level.

What is the new behavior (if this is a feature change)?

Automatically redraw the voltage level node and affected edges when bus connections change
Maintain proper branch positioning and visual representation after bus connection changes

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

If yes, please check if the following requirements are fulfilled

  • The Breaking Change or Deprecated label has been added
  • The migration steps are described in the following section

What changes might users need to make in their application due to this PR? (migration steps)

Other information:

Signed-off-by: Leclerc Clement <[email protected]>
Signed-off-by: Leclerc Clement <[email protected]>
Signed-off-by: Leclerc Clement <[email protected]>
Signed-off-by: Leclerc Clement <[email protected]>
Signed-off-by: Leclerc Clement <[email protected]>
Signed-off-by: Leclerc Clement <[email protected]>
Signed-off-by: Leclerc Clement <[email protected]>
@@ -160,8 +159,8 @@ export const addNadToDemo = () => {
?.getElementsByTagName('svg')[0]
.setAttribute('style', 'border:2px; border-style:solid;');

// add button to update branch labels
Copy link
Contributor

Choose a reason for hiding this comment

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

could you update the comment rather than removing it?

return;
}

const edge = this.diagramMetadata?.edges.find((e) => e.svgId === edgeId);
Copy link
Contributor

Choose a reason for hiding this comment

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

the edge is already known by the caller, as edgesMap.get(branchState.branchId) is called. So you could have the edge instead of the edgeId in setBranchBusConnection

const currentBusNode = this.diagramMetadata?.busNodes.find((busNode) => busNode.svgId === currentBusNodeId);

if (currentBusNode && currentBusNode.vlNode !== targetBusNode.vlNode) {
console.warn('Skipping updating branch ' + branchId + ' side ' + side + ' status: Cannot connect to bus from different voltage level');
Copy link
Contributor

Choose a reason for hiding this comment

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

yes we can! the only thing we can't so far is to connect two buses from the same voltage level (we didn't draw loops in network-viewer so far, we only translate them). It's just a bit more complex, as it has some side effects for parallel edges. Should we do this in current PR?

Comment on lines +1689 to +1702
this.moveStraightEdge(edge, vlElement, currentPosition);
const vlBusNodes = this.diagramMetadata?.busNodes.filter(
(busNode) => busNode.vlNode === targetBusNode.vlNode
);
const busNodeEdges = new Map<string, EdgeMetadata[]>();
vlBusNodes?.forEach((busNode) => {
const busEdges = this.diagramMetadata?.edges.filter(
(e) => e.busNode1 === busNode.svgId || e.busNode2 === busNode.svgId
);
if (busEdges?.length) {
busNodeEdges.set(busNode.svgId, busEdges);
}
});
this.redrawVoltageLevelNode(vlElement, busNodeEdges, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only working for straight edges, not for parallel fork edges. To avoid that I think you can call directly moveEdges(vlNode, position) instead of all that, can't you? One drawback, it's doing more than needed

value2: -611 + value * 20,
connected1: true,
connected2: true,
connectedBus1: value < 10 ? '4' : '5',
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to add this new slider, you should do this in the first one

@@ -1201,20 +1203,17 @@ export class NetworkAreaDiagramViewer {
if (typeof edgeAngle !== 'undefined') {
traversingBusEdgesAngles.push(edgeAngle);
}
// redraw only if there is an edge going to another voltage level
if (edge.node1 != edge.node2) {
Copy link
Contributor

@flo-dup flo-dup Feb 5, 2025

Choose a reason for hiding this comment

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

I'm not sure to understand why you did remove this? EDIT: just got it, it was to avoid redrawing a bus node which contained only loops. If you remove it, you lose this tiny optimization

@flo-dup flo-dup changed the title network aera diagram viewer animation fix nad-viewer: update bus connections Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants