Skip to content

Commit

Permalink
[2796] Add power node descriptions to Flow view DSL
Browse files Browse the repository at this point in the history
Bug: #2796
Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
  • Loading branch information
frouene authored and pcdavid committed Jan 16, 2024
1 parent 57f55ab commit 62243b6
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public EObject drop(EObject self, Node selectedNode, IDiagramContext diagramCont
}

public int computeDataSourceHeight(DataSource self) {
if (self.getName().equals("Camera") || self.getName().equals("Radar") || self.getName().equals("Sensor")) {
if (self.getName() != null && (self.getName().equals("Camera") || self.getName().equals("Radar") || self.getName().equals("Sensor"))) {
return self.getVolume() * 15;
}
return self.getVolume() * 11;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class FlowViewBuilder {
public static final String RADAR_SVG_ID = "a6e0845d-971f-33c7-ae25-6ac4f47056dc";
public static final String SENSOR_SVG_ID = "6c07834a-5ff6-3819-8326-0614d3dcd674";
public static final String FAN_SVG_ID = "9019f843-5511-3318-8f89-0e50994c98e8";
public static final String POWER_OUTPUT_SVG_ID = "bca5ab3c-b13c-38b4-910d-3ec4b8e81321";
public static final String POWER_INPUT_SVG_ID = "f9219f29-df22-31a6-9473-5955f5962287";
public static final String ENGINE_HIGH_SVG_ID = "0449ce13-3eed-3426-a9f7-d1f68c8a2b8f";
public static final String ENGINE_LOW_SVG_ID = "b0617610-43e0-3636-b7eb-c77aec046f5f";
public static final String ENGINE_OVER_SVG_ID = "a960705f-dab1-3dbb-b1e4-ce8d71b51317";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public NodeDescription create() {
.labelExpression("aql:self.name")
.defaultHeightExpression("aql:self.volume*15")
.defaultWidthExpression("aql:self.computeDataSourceHeight()")
.userResizable(false)
.keepAspectRatio(true)
.style(this.flowViewBuilder.createImageNodeStyleDescription(SENSOR_SVG_ID, this.colorProvider))
.synchronizationPolicy(this.synchronizationPolicy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public NodeDescription create() {
.labelExpression("feature:speed")
.defaultHeightExpression("aql:self.speed/2")
.defaultWidthExpression("aql:self.speed/2")
.userResizable(false)
.keepAspectRatio(true)
.style(this.flowViewBuilder.createImageNodeStyleDescription(FAN_SVG_ID, this.colorProvider))
.synchronizationPolicy(this.synchronizationPolicy)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.flow.starter.view.descriptions;

import static org.eclipse.sirius.components.flow.starter.view.FlowViewBuilder.POWER_INPUT_SVG_ID;

import java.util.Objects;

import org.eclipse.sirius.components.flow.starter.view.FlowViewBuilder;
import org.eclipse.sirius.components.view.builder.IViewDiagramElementFinder;
import org.eclipse.sirius.components.view.builder.generated.DiagramBuilders;
import org.eclipse.sirius.components.view.builder.providers.IColorProvider;
import org.eclipse.sirius.components.view.builder.providers.INodeDescriptionProvider;
import org.eclipse.sirius.components.view.diagram.DiagramDescription;
import org.eclipse.sirius.components.view.diagram.DiagramFactory;
import org.eclipse.sirius.components.view.diagram.NodeDescription;
import org.eclipse.sirius.components.view.diagram.NodePalette;
import org.eclipse.sirius.components.view.diagram.SynchronizationPolicy;

/**
* Used to create the powerInput node description.
*
* @author frouene
*/
public class PowerInputDescriptionProvider implements INodeDescriptionProvider {

public static final String NAME = "PowerInput Node";

private final IColorProvider colorProvider;

private final DiagramBuilders diagramBuilderHelper = new DiagramBuilders();

private final FlowViewBuilder flowViewBuilder = new FlowViewBuilder();

public PowerInputDescriptionProvider(IColorProvider colorProvider) {
this.colorProvider = Objects.requireNonNull(colorProvider);
}


@Override
public NodeDescription create() {

return this.diagramBuilderHelper.newNodeDescription()
.name(NAME)
.domainType("flow::PowerInput")
.semanticCandidatesExpression("feature:powerInputs")
.childrenLayoutStrategy(DiagramFactory.eINSTANCE.createFreeFormLayoutStrategyDescription())
.defaultHeightExpression("50")
.defaultWidthExpression("50")
.userResizable(false)
.keepAspectRatio(true)
.style(this.flowViewBuilder.createImageNodeStyleDescription(POWER_INPUT_SVG_ID, this.colorProvider))
.synchronizationPolicy(SynchronizationPolicy.SYNCHRONIZED)
.palette(this.createNodePalette())
.build();
}

@Override
public void link(DiagramDescription diagramDescription, IViewDiagramElementFinder cache) {
cache.getNodeDescription(NAME).ifPresent(nodeDescription -> diagramDescription.getNodeDescriptions().add(nodeDescription));
}

private NodePalette createNodePalette() {

return this.diagramBuilderHelper.newNodePalette()
.deleteTool(this.flowViewBuilder.createDeleteTool())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.flow.starter.view.descriptions;

import static org.eclipse.sirius.components.flow.starter.view.FlowViewBuilder.POWER_OUTPUT_SVG_ID;

import java.util.Objects;

import org.eclipse.sirius.components.flow.starter.view.FlowViewBuilder;
import org.eclipse.sirius.components.view.builder.IViewDiagramElementFinder;
import org.eclipse.sirius.components.view.builder.generated.DiagramBuilders;
import org.eclipse.sirius.components.view.builder.providers.IColorProvider;
import org.eclipse.sirius.components.view.builder.providers.INodeDescriptionProvider;
import org.eclipse.sirius.components.view.diagram.DiagramDescription;
import org.eclipse.sirius.components.view.diagram.DiagramFactory;
import org.eclipse.sirius.components.view.diagram.NodeDescription;
import org.eclipse.sirius.components.view.diagram.NodePalette;
import org.eclipse.sirius.components.view.diagram.SynchronizationPolicy;

/**
* Used to create the powerOutput node description.
*
* @author frouene
*/
public class PowerOutputDescriptionProvider implements INodeDescriptionProvider {

public static final String NAME = "PowerOutput Node";

private final IColorProvider colorProvider;

private final DiagramBuilders diagramBuilderHelper = new DiagramBuilders();

private final FlowViewBuilder flowViewBuilder = new FlowViewBuilder();

public PowerOutputDescriptionProvider(IColorProvider colorProvider) {
this.colorProvider = Objects.requireNonNull(colorProvider);
}


@Override
public NodeDescription create() {

return this.diagramBuilderHelper.newNodeDescription()
.name(NAME)
.domainType("flow::PowerOutput")
.semanticCandidatesExpression("feature:powerOutputs")
.childrenLayoutStrategy(DiagramFactory.eINSTANCE.createFreeFormLayoutStrategyDescription())
.defaultHeightExpression("50")
.defaultWidthExpression("50")
.userResizable(false)
.keepAspectRatio(true)
.style(this.flowViewBuilder.createImageNodeStyleDescription(POWER_OUTPUT_SVG_ID, this.colorProvider))
.synchronizationPolicy(SynchronizationPolicy.SYNCHRONIZED)
.palette(this.createNodePalette())
.build();
}

@Override
public void link(DiagramDescription diagramDescription, IViewDiagramElementFinder cache) {
cache.getNodeDescription(NAME).ifPresent(nodeDescription -> diagramDescription.getNodeDescriptions().add(nodeDescription));
}

private NodePalette createNodePalette() {

return this.diagramBuilderHelper.newNodePalette()
.deleteTool(this.flowViewBuilder.createDeleteTool())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public NodeDescription create() {
.labelExpression("aql:self.name")
.defaultHeightExpression("aql:self.capacity*15")
.defaultWidthExpression("aql:self.capacity*15")
.userResizable(false)
.keepAspectRatio(true)
.style(this.flowViewBuilder.createImageNodeStyleDescription(CPU_UNUSED_SVG_ID, this.colorProvider))
.synchronizationPolicy(this.synchronizationPolicy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ public NodeDescription create() {
.style(this.getRectangularNodeStyleDescription("Flow_Orange", "Flow_Orange"))
.build())
.synchronizationPolicy(this.synchronizationPolicy)
.reusedChildNodeDescriptions();

.borderNodesDescriptions(new PowerOutputDescriptionProvider(this.colorProvider).create(),
new PowerInputDescriptionProvider(this.colorProvider).create());

if (this.autoLayout) {
nodeDescription.childrenDescriptions(this.createDescriptionNode());
}
Expand All @@ -89,19 +90,15 @@ public NodeDescription create() {

@Override
public void link(DiagramDescription diagramDescription, IViewDiagramElementFinder cache) {
var optionalSystemNodeDescription = cache.getNodeDescription(NAME);
var optionalProcessorNodeDescription = cache.getNodeDescription(ProcessorDescriptionProvider.NAME);
var optionalFanNodeDescription = cache.getNodeDescription(FanDescriptionProvider.NAME);
var optionalDataSourceNodeDescription = cache.getNodeDescription(DataSourceDescriptionProvider.NAME);

if (optionalSystemNodeDescription.isPresent() && optionalProcessorNodeDescription.isPresent()
&& optionalFanNodeDescription.isPresent() && optionalDataSourceNodeDescription.isPresent()) {
diagramDescription.getNodeDescriptions().add(optionalSystemNodeDescription.get());
optionalSystemNodeDescription.get().getReusedChildNodeDescriptions().add(optionalProcessorNodeDescription.get());
optionalSystemNodeDescription.get().getReusedChildNodeDescriptions().add(optionalFanNodeDescription.get());
optionalSystemNodeDescription.get().getReusedChildNodeDescriptions().add(optionalDataSourceNodeDescription.get());
optionalSystemNodeDescription.get().setPalette(this.createNodePalette(cache));
}
cache.getNodeDescription(NAME).ifPresent(nodeDescription -> {
diagramDescription.getNodeDescriptions().add(nodeDescription);
cache.getNodeDescription(ProcessorDescriptionProvider.NAME).ifPresent(reusedChildNode -> nodeDescription.getReusedChildNodeDescriptions().add(reusedChildNode));
cache.getNodeDescription(FanDescriptionProvider.NAME)
.ifPresent(reusedChildNode -> nodeDescription.getReusedChildNodeDescriptions().add(reusedChildNode));
cache.getNodeDescription(DataSourceDescriptionProvider.NAME)
.ifPresent(reusedChildNode -> nodeDescription.getReusedChildNodeDescriptions().add(reusedChildNode));
nodeDescription.setPalette(this.createNodePalette(cache));
});
}

private RectangularNodeStyleDescription getRectangularNodeStyleDescription(String borderColor, String labelColor) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 62243b6

Please sign in to comment.