All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.powsybl.sld.cgmes.layout.CgmesSubstationLayout Maven / Gradle / Ivy

There is a newer version: 4.6.1
Show newest version
/**
 * Copyright (c) 2019, 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/.
 * SPDX-License-Identifier: MPL-2.0
 */
package com.powsybl.sld.cgmes.layout;

import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VoltageLevel;
import com.powsybl.sld.layout.LayoutParameters;
import com.powsybl.sld.model.nodes.Node;
import com.powsybl.sld.model.nodes.MiddleTwtNode;
import com.powsybl.sld.model.graphs.SubstationGraph;
import com.powsybl.sld.model.graphs.VoltageLevelGraph;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Objects;

/**
 * @author Massimo Ferraro {@literal }
 * @author Franck Lecuyer {@literal }
 */
public class CgmesSubstationLayout extends AbstractCgmesLayout {

    private static final Logger LOG = LoggerFactory.getLogger(CgmesSubstationLayout.class);

    private final SubstationGraph graph;

    public CgmesSubstationLayout(SubstationGraph graph, Network network) {
        this.network = Objects.requireNonNull(network);
        Objects.requireNonNull(graph);
        for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) {
            removeFictitiousNodes(vlGraph, network.getVoltageLevel(vlGraph.getVoltageLevelInfos().getId()));
        }
        fixTransformersLabel = true;
        this.graph = graph;
    }

    @Override
    public void run(LayoutParameters layoutParam) {
        String diagramName = layoutParam.getCgmesDiagramName();
        if (!checkDiagram(diagramName, "substation " + graph.getSubstationId())) {
            return;
        }
        LOG.info("Applying CGMES-DL layout to network {}, substation {}, diagram name {}", network.getId(), graph.getSubstationId(), diagramName);
        for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) {
            VoltageLevel vl = network.getVoltageLevel(vlGraph.getVoltageLevelInfos().getId());
            setNodeCoordinates(vl, vlGraph, diagramName, layoutParam.isCgmesUseNames());
        }
        for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) {
            vlGraph.getNodes().forEach(node -> shiftNodeCoordinates(node, layoutParam.getCgmesScaleFactor()));
        }
        if (layoutParam.getCgmesScaleFactor() != 1) {
            for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) {
                vlGraph.getNodes().forEach(node -> scaleNodeCoordinates(node, layoutParam.getCgmesScaleFactor()));
            }
        }
        for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) {
            setVoltageLevelCoord(vlGraph);
        }

        setMultiNodesCoord();
    }

    private void setMultiNodesCoord() {
        for (MiddleTwtNode multiNode : graph.getMultiTermNodes()) {
            List adjacentNodes = multiNode.getAdjacentNodes();
            multiNode.setCoordinates(adjacentNodes.get(0).getCoordinates());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy