-
Notifications
You must be signed in to change notification settings - Fork 13
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
Modify nad and sld api for better consistency #475
Changes from 14 commits
9796a36
a28a309
8cc6cd6
2dca5c3
9589a8b
f50503f
97a108f
aad6361
7f09aad
c78fcdd
f3937ee
d01e87f
f4d3037
030f16d
f840a1f
cdc6f6f
6ea6e43
7709829
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.powsybl.nad; | ||
|
||
import com.powsybl.nad.build.iidm.IdProvider; | ||
import com.powsybl.nad.layout.LayoutFactory; | ||
import com.powsybl.nad.layout.LayoutParameters; | ||
import com.powsybl.nad.svg.LabelProvider; | ||
import com.powsybl.nad.svg.StyleProvider; | ||
import com.powsybl.nad.svg.SvgParameters; | ||
|
||
public class NetworkAreaDiagramConfiguration { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could simplify this with |
||
|
||
SvgParameters svgParameters; | ||
LayoutParameters layoutParameters; | ||
StyleProvider styleProvider; | ||
LabelProvider labelProvider; | ||
LayoutFactory layoutFactory; | ||
IdProvider idProvider; | ||
|
||
public NetworkAreaDiagramConfiguration(SvgParameters svgParameters, LayoutParameters layoutParameters, StyleProvider styleProvider, LabelProvider labelProvider, LayoutFactory layoutFactory, IdProvider idProvider) { | ||
this.svgParameters = svgParameters; | ||
this.layoutParameters = layoutParameters; | ||
this.styleProvider = styleProvider; | ||
this.labelProvider = labelProvider; | ||
this.layoutFactory = layoutFactory; | ||
this.idProvider = idProvider; | ||
} | ||
|
||
public SvgParameters getSvgParameters() { | ||
return svgParameters; | ||
} | ||
|
||
public LayoutParameters getLayoutParameters() { | ||
return layoutParameters; | ||
} | ||
|
||
public StyleProvider getStyleProvider() { | ||
return styleProvider; | ||
} | ||
|
||
public LabelProvider getLabelProvider() { | ||
return labelProvider; | ||
} | ||
|
||
public LayoutFactory getLayoutFactory() { | ||
return layoutFactory; | ||
} | ||
|
||
public IdProvider getIdProvider() { | ||
return idProvider; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,73 @@ | ||||||||||||||||
package com.powsybl.nad; | ||||||||||||||||
|
||||||||||||||||
import com.powsybl.iidm.network.Network; | ||||||||||||||||
import com.powsybl.nad.build.iidm.IdProvider; | ||||||||||||||||
import com.powsybl.nad.build.iidm.IntIdProvider; | ||||||||||||||||
import com.powsybl.nad.layout.BasicForceLayoutFactory; | ||||||||||||||||
import com.powsybl.nad.layout.LayoutFactory; | ||||||||||||||||
import com.powsybl.nad.layout.LayoutParameters; | ||||||||||||||||
import com.powsybl.nad.svg.LabelProvider; | ||||||||||||||||
import com.powsybl.nad.svg.StyleProvider; | ||||||||||||||||
import com.powsybl.nad.svg.SvgParameters; | ||||||||||||||||
import com.powsybl.nad.svg.iidm.DefaultLabelProvider; | ||||||||||||||||
import com.powsybl.nad.svg.iidm.TopologicalStyleProvider; | ||||||||||||||||
|
||||||||||||||||
import java.util.function.BiFunction; | ||||||||||||||||
|
||||||||||||||||
public class NetworkAreaDiagramConfigurationBuilder { | ||||||||||||||||
SvgParameters svgParameters = new SvgParameters(); | ||||||||||||||||
LayoutParameters layoutParameters = new LayoutParameters(); | ||||||||||||||||
StyleProvider styleProvider; | ||||||||||||||||
LabelProvider labelProvider; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can remove this parameter, we shouldn't create it before build call. Or in fact it should maybe be build only when calling |
||||||||||||||||
BiFunction<Network, SvgParameters, LabelProvider> labelProviderCreator = DefaultLabelProvider::new; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
LayoutFactory layoutFactory = new BasicForceLayoutFactory(); | ||||||||||||||||
IdProvider idProvider = new IntIdProvider(); | ||||||||||||||||
Network network; | ||||||||||||||||
|
||||||||||||||||
private static <R extends LabelProvider> R factory(Network network, SvgParameters svgParameters, BiFunction<Network, SvgParameters, R> function) { | ||||||||||||||||
return function.apply(network, svgParameters); | ||||||||||||||||
} | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
public NetworkAreaDiagramConfigurationBuilder(Network network) { | ||||||||||||||||
this.network = network; | ||||||||||||||||
this.styleProvider = new TopologicalStyleProvider(network); | ||||||||||||||||
this.labelProvider = factory(network, svgParameters, labelProviderCreator); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
public NetworkAreaDiagramConfigurationBuilder withSvgParameters(SvgParameters svgParameters) { | ||||||||||||||||
this.svgParameters = svgParameters; | ||||||||||||||||
this.labelProvider = factory(network, svgParameters, labelProviderCreator); | ||||||||||||||||
return this; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
public NetworkAreaDiagramConfigurationBuilder withLayoutParameters(LayoutParameters layoutParameters) { | ||||||||||||||||
this.layoutParameters = layoutParameters; | ||||||||||||||||
return this; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
public NetworkAreaDiagramConfigurationBuilder withStyleProvider(StyleProvider styleProvider) { | ||||||||||||||||
this.styleProvider = styleProvider; | ||||||||||||||||
return this; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
public NetworkAreaDiagramConfigurationBuilder withLabelProviderCreator(BiFunction<Network, SvgParameters, LabelProvider> labelProviderCreator) { | ||||||||||||||||
this.labelProviderCreator = labelProviderCreator; | ||||||||||||||||
this.labelProvider = factory(network, svgParameters, labelProviderCreator); | ||||||||||||||||
return this; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
public NetworkAreaDiagramConfigurationBuilder withLayoutFactory(LayoutFactory layoutFactory) { | ||||||||||||||||
this.layoutFactory = layoutFactory; | ||||||||||||||||
return this; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
public NetworkAreaDiagramConfigurationBuilder withIdProvider(IdProvider idProvider) { | ||||||||||||||||
this.idProvider = idProvider; | ||||||||||||||||
return this; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
public NetworkAreaDiagramConfiguration build() { | ||||||||||||||||
return new NetworkAreaDiagramConfiguration(svgParameters, layoutParameters, styleProvider, labelProvider, layoutFactory, idProvider); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,7 @@ | |
import com.google.common.jimfs.Configuration; | ||
import com.google.common.jimfs.Jimfs; | ||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.nad.build.iidm.IdProvider; | ||
import com.powsybl.nad.build.iidm.IntIdProvider; | ||
import com.powsybl.nad.build.iidm.VoltageLevelFilter; | ||
import com.powsybl.nad.layout.BasicForceLayoutFactory; | ||
import com.powsybl.nad.layout.LayoutFactory; | ||
import com.powsybl.nad.layout.LayoutParameters; | ||
import com.powsybl.nad.svg.LabelProvider; | ||
import com.powsybl.nad.svg.NetworkTestFactory; | ||
|
@@ -60,14 +56,6 @@ protected LabelProvider getLabelProvider(Network network) { | |
}; | ||
} | ||
|
||
private LayoutFactory getLayoutFactory() { | ||
return new BasicForceLayoutFactory(); | ||
} | ||
|
||
private IdProvider getIdProvider() { | ||
return new IntIdProvider(); | ||
} | ||
|
||
private String getContentFile(Path svgFile) { | ||
try (Stream<String> lines = Files.lines(svgFile)) { | ||
return lines.collect(Collectors.joining("\n")) + "\n"; | ||
|
@@ -79,14 +67,12 @@ private String getContentFile(Path svgFile) { | |
@Test | ||
public void testDrawSvg() { | ||
Network network = NetworkTestFactory.createThreeVoltageLevelsFiveBuses(); | ||
NetworkAreaDiagram nad = new NetworkAreaDiagram(network, VoltageLevelFilter.NO_FILTER); | ||
|
||
Path svgFile = fileSystem.getPath("nad-test.svg"); | ||
nad.draw(svgFile, | ||
getSvgParameters(), | ||
getLayoutParameters(), | ||
getStyleProvider(network)); | ||
|
||
NetworkAreaDiagramConfiguration networkAreaDiagramConfiguration = new NetworkAreaDiagramConfigurationBuilder(network) | ||
.withSvgParameters(getSvgParameters()) | ||
.withStyleProvider(getStyleProvider(network)) | ||
.build(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indenting isn't right |
||
NetworkAreaDiagram.draw(network, svgFile, networkAreaDiagramConfiguration, VoltageLevelFilter.NO_FILTER); | ||
assertEquals(toString("/dangling_line_connected.svg"), getContentFile(svgFile)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright and authorship are missing for the new files of this PR