Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Create model #2

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 21 additions & 0 deletions src/main/java/com/powsybl/nad/model/AbstractEdge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

public abstract class AbstractEdge implements Edge {

private final String id;

protected AbstractEdge(String id) {
this.id = id;
}

@Override
public String getDiagramId() {
return id;
}
}
48 changes: 48 additions & 0 deletions src/main/java/com/powsybl/nad/model/AbstractNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

public abstract class AbstractNode implements Node {

private final String diagramId;
private int width;
private int height;
private Point position;

protected AbstractNode(String diagramId) {
this.diagramId = diagramId;
position = new Point();
width = 0;
height = 0;
}

@Override
public String getDiagramId() {
return diagramId;
}

@Override
public void setPosition(double x, double y) {
position = new Point(x, y);
}

public int getWidth() {
return width;
}

public void setWidth(int width) {
this.width = width;
}

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
}
}
47 changes: 47 additions & 0 deletions src/main/java/com/powsybl/nad/model/AbstractTransformerEdge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public abstract class AbstractTransformerEdge extends AbstractEdge implements BranchEdge {

private final List<VoltageLevelNode> adjacentNodes = new ArrayList<>();
private final Point transformerPosition = new Point();
private final List<List<Point>> polylines = new ArrayList<>();

protected AbstractTransformerEdge(String id, VoltageLevelNode node1, VoltageLevelNode node2) {
super(id);
adjacentNodes.add(node1);
adjacentNodes.add(node2);
}

protected AbstractTransformerEdge(String id, VoltageLevelNode node1, VoltageLevelNode node2, VoltageLevelNode node3) {
super(id);
adjacentNodes.add(node1);
adjacentNodes.add(node2);
adjacentNodes.add(node3);
}

public List<VoltageLevelNode> getAdjacentNodes() {
return Collections.unmodifiableList(adjacentNodes);
}

public Point getTransformerPosition() {
return transformerPosition;
}

public List<List<Point>> getEdgePolylines() {
return Collections.unmodifiableList(polylines);
}

public void addPolyline(List<Point> polyline) {
polylines.add(polyline);
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/powsybl/nad/model/BranchEdge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

import java.util.List;

public interface BranchEdge extends Edge {

List<VoltageLevelNode> getAdjacentNodes();

}
4 changes: 4 additions & 0 deletions src/main/java/com/powsybl/nad/model/BusNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.powsybl.nad.model;

public class BusNode {
}
17 changes: 17 additions & 0 deletions src/main/java/com/powsybl/nad/model/Edge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

import java.util.List;

public interface Edge {

String getDiagramId();

List<? extends Node> getAdjacentNodes();

}
43 changes: 43 additions & 0 deletions src/main/java/com/powsybl/nad/model/Graph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;

public class Graph {

private final Map<String, Node> nodes = new LinkedHashMap<>();
private final Map<String, Edge> edges = new LinkedHashMap<>();

public void addNode(Node node) {
nodes.put(node.getDiagramId(), node);
}

public void addEdge(Edge edge) {
edges.put(edge.getDiagramId(), edge);
}

public Stream<Node> getNodesStream() {
return nodes.values().stream();
}

public Stream<Edge> getEdgesStream() {
return edges.values().stream();
}

public Optional<Node> getNode(String diagramId) {
return Optional.ofNullable(nodes.get(diagramId));
}

public Optional<Edge> getEdge(String diagramId) {
return Optional.ofNullable(edges.get(diagramId));
}

}
37 changes: 37 additions & 0 deletions src/main/java/com/powsybl/nad/model/LineEdge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class LineEdge extends AbstractEdge implements BranchEdge {
private final List<VoltageLevelNode> adjacentNodes = new LinkedList<>();
private List<Point> polyline = new ArrayList<>();

public LineEdge(String id, VoltageLevelNode node1, VoltageLevelNode node2) {
super(id);
adjacentNodes.add(node1);
adjacentNodes.add(node2);
}

@Override
public List<VoltageLevelNode> getAdjacentNodes() {
return Collections.unmodifiableList(adjacentNodes);
}

public List<Point> getPolyline() {
return Collections.unmodifiableList(polyline);
}

public void setPolyline(List<Point> polyline) {
this.polyline = new ArrayList<>(polyline);
}

}
19 changes: 19 additions & 0 deletions src/main/java/com/powsybl/nad/model/Node.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

import java.util.List;

public interface Node {

String getDiagramId();

List<? extends Edge> getAdjacentEdges();

void setPosition(double x, double y);

}
38 changes: 38 additions & 0 deletions src/main/java/com/powsybl/nad/model/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

public class Point {

private double x;
private double y;

public Point(double x, double y) {
this.x = x;
this.y = y;
}

public Point() {
this(0, 0);
}

public double getY() {
return y;
}

public void setY(double y) {
this.y = y;
}

public double getX() {
return x;
}

public void setX(double x) {
this.x = x;
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/powsybl/nad/model/TextEdge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

import java.util.Arrays;
import java.util.List;

public class TextEdge implements Edge {

private final String id;

private VoltageLevelNode vlNode;
private TextNode textNode;

public TextEdge(String id) {
this.id = id;
}

@Override
public String getDiagramId() {
return id;
}

@Override
public List<Node> getAdjacentNodes() {
return Arrays.asList(vlNode, textNode);
}

public VoltageLevelNode getVoltageLevelNode() {
return vlNode;
}

public TextNode getTextNode() {
return textNode;
}

}
34 changes: 34 additions & 0 deletions src/main/java/com/powsybl/nad/model/TextNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

import java.util.Collections;
import java.util.List;

public class TextNode extends AbstractNode {

private final String text;
private TextEdge edge;

protected TextNode(String diagramId, String text) {
super(diagramId);
this.text = text;
}

@Override
public List<TextEdge> getAdjacentEdges() {
return Collections.singletonList(edge);
}

public void setEdge(TextEdge edge) {
this.edge = edge;
}

public String getText() {
return text;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.nad.model;

public class ThreeWindingsTransformerEdge extends AbstractTransformerEdge {
protected ThreeWindingsTransformerEdge(String id, VoltageLevelNode node1, VoltageLevelNode node2, VoltageLevelNode node3) {
super(id, node1, node2, node3);
}
}
Loading