private Color color;
private Double stroke;
private transient Color dynamicColor = null;
+ private transient Color eventColor = null;
// Dimensions for shut-off valve symbol
private static final double left = -0.25;
}
g2d.setColor(dynamicColor != null ? dynamicColor : color);
+ g2d.setColor(eventColor != null ? eventColor : g2d.getColor());
g2d.setStroke(bs);
g2d.draw(path);
this.dynamicColor = color;
}
+ @PropertySetter(value = "eventColor")
+ public void setEventColor(Color color) {
+ this.eventColor = color;
+ }
+
+
@PropertySetter(value = "arrowLength")
public void setArrowLength(Double length) {
// find if there is a child deferred arrow node
private Color color;
private transient Color dynamicColor;
+ private transient Color eventColor;
private Rectangle2D bounds;
private transient Point2D point;
}
Color oldColor = g2d.getColor();
- Color newColor = dynamicColor != null ? dynamicColor : color;
+ Color newColor = eventColor != null ? eventColor : dynamicColor != null ? dynamicColor : color;
boolean changeColor = !oldColor.equals(newColor);
double scaleRecip = viewScaleRecip * nodeSize;
this.dynamicColor = color;
}
+ @PropertySetter(value = "eventColor")
+ public void setEventColor(Color colorr) {
+ this.eventColor = colorr;
+ }
+
@PropertySetter(value = "hidden")
public void setHidden(Boolean value) {
this.hidden = value;
child.setPoints(points);
}
}
+
}
import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant;
import org.simantics.g2d.element.IElement;
import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scl.runtime.tuple.Tuple2;
import org.simantics.utils.datastructures.hints.IHintContext.Key;
import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
public class DistrictFinderVisualisationParticipant extends AbstractDiagramParticipant {
private static final String TOPIC = "org/simantics/district/selection/elementQuerySelection";
+ private static final String TOPIC2 = "org/simantics/district/visualisationTrigger";
private IEventBroker broker;
}
}
});
+ broker.subscribe(TOPIC2, event -> {
+ Tuple2 data = (Tuple2) event.getProperty(IEventBroker.DATA);
+ Resource resource = (Resource) data.c0;
+ Color colorr = (Color) data.c1;
+ IElement element = DiagramNodeUtil.findElement(ctx, resource);
+ final G2DParentNode node = element.getHint(DistrictNetworkEdgeElement.KEY_DN_EDGE_NODE);
+ if (node != null) {
+ // color is a bit special - if not present then reset with null value
+ ((DistrictNetworkEdgeNode) node).setEventColor(colorr);
+ node.repaint();
+ } else {
+ final G2DParentNode vertexNode = element.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
+ ((DistrictNetworkVertexNode) vertexNode).setEventColor(colorr);
+ vertexNode.repaint();
+ }
+ });
}
@Override
org.simantics.district.network.changeset,
org.simantics.district.network.profile,
org.simantics.district.network.visualisations,
- org.simantics.district.network.visualisations.model
+ org.simantics.district.network.visualisations.model,
+ org.simantics.district.network.visualisations.triggers
Bundle-Vendor: THTH ry
Automatic-Module-Name: org.simantics.district.network
--- /dev/null
+importJava "org.simantics.district.network.visualisations.triggers.VisualisationTrigger" where
+ data VisualisationTrigger
+
+ @JavaName "<init>"
+ visualisationTriggerContribution :: String -> String -> Double -> String -> VisualisationTrigger
\ No newline at end of file
--- /dev/null
+package org.simantics.district.network.visualisations.triggers;
+
+import java.awt.Color;
+
+public class VisualisationTrigger {
+
+ private String moduleName;
+ private String attributeName;
+ private double threshold;
+ private Color color;
+
+ public VisualisationTrigger(String moduleName, String attributeName, double threshold, String colorHex) {
+ this.moduleName = moduleName;
+ this.attributeName = attributeName;
+ this.threshold = threshold;
+ this.color = hex2Rgb(colorHex);
+ }
+
+ public String getModuleName() {
+ return moduleName;
+ }
+
+ public String getAttributeName() {
+ return attributeName;
+ }
+
+ public double getThreshold() {
+ return threshold;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ /**
+ *
+ * @param colorStr e.g. "#FFFFFF"
+ * @return
+ */
+ private static Color hex2Rgb(String colorStr) {
+ return new Color(
+ Integer.valueOf( colorStr.substring( 1, 3 ), 16 ),
+ Integer.valueOf( colorStr.substring( 3, 5 ), 16 ),
+ Integer.valueOf( colorStr.substring( 5, 7 ), 16 ) );
+ }
+}
--- /dev/null
+package org.simantics.district.network.visualisations.triggers;
+
+import org.simantics.db.Resource;
+import org.simantics.structural.synchronization.base.ComponentBase;
+
+public class VisualisationTriggerComponent {
+
+ private Resource element;
+ private ComponentBase<?> component;
+ private VisualisationTrigger trigger;
+
+ public VisualisationTriggerComponent(Resource element, ComponentBase<?> component, VisualisationTrigger activeTrigger) {
+ this.element = element;
+ this.component = component;
+ this.trigger = activeTrigger;
+ }
+
+ public Resource getElement() {
+ return element;
+ }
+
+ public ComponentBase<?> getComponent() {
+ return component;
+ }
+
+ public VisualisationTrigger getTrigger() {
+ return trigger;
+ }
+
+}
--- /dev/null
+package org.simantics.district.network.visualisations.triggers;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.simantics.NameLabelUtil;
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.NamedResource;
+import org.simantics.db.common.request.ObjectsWithSupertype;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.layer0.Layer0;
+import org.simantics.scl.compiler.top.ValueNotFound;
+import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.tuple.Tuple0;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class VisualisationTriggersContributions {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(VisualisationTriggersContributions.class);
+ private static final String VISUALISATIONS_TRIGGERS_MODULE = "VisualisationTriggers";
+ private static final String VISUALISATION_TRIGGER_CONTRIBUTION = "visualisationTriggers";
+
+ public static Map<String, List<VisualisationTrigger>> visualisationTriggers(ReadGraph graph) throws DatabaseException {
+ List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
+
+ Map<String, List<VisualisationTrigger>> results = new HashMap<>();
+ Layer0 L0 = Layer0.getInstance(graph);
+
+ Object oldGraph = SCLContext.getCurrent().get("graph");
+ try {
+ SCLContext.getCurrent().put("graph", graph);
+ for (Resource sharedOntology : sharedOntologies) {
+
+ Collection<Resource> userComponents = graph.syncRequest(new ObjectsWithSupertype(sharedOntology, Layer0.getInstance(graph).ConsistsOf, StructuralResource2.getInstance(graph).Component));
+
+ for (Resource userComponent : userComponents) {
+ NamedResource moduleType = new NamedResource(NameLabelUtil.modalName(graph, userComponent), userComponent);
+ List<VisualisationTrigger> visualisationTriggerContributions = visualisationTriggerContribution(graph, moduleType);
+ if (visualisationTriggerContributions != null)
+ results.put(moduleType.getName(), visualisationTriggerContributions);
+ }
+ }
+ } finally {
+ SCLContext.getCurrent().put("graph", oldGraph);
+ }
+ return results;
+ }
+
+ private static List<VisualisationTrigger> visualisationTriggerContribution(ReadGraph graph, NamedResource moduleType) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, VISUALISATIONS_TRIGGERS_MODULE);
+ if (sclModule != null) {
+ String moduleURI = graph.getURI(sclModule);
+ try {
+ List<VisualisationTrigger> result = (List<VisualisationTrigger>) SCLOsgi.MODULE_REPOSITORY.getValue(moduleURI, VISUALISATION_TRIGGER_CONTRIBUTION);
+ return result;
+ } catch (ValueNotFound e) {
+ LOGGER.error("Could not find contributions for module {} and expression {}", moduleURI, VISUALISATION_TRIGGER_CONTRIBUTION, e);
+ }
+ }
+ return null;
+ }
+
+}
+