X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.selection%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fselection%2FElementSelector.java;h=6de06ff690ea23a03304e119e412309301e581c1;hb=a8ee8f9b04151b0443dd0ff9a1f2ddc6fba0c73c;hp=f015bddf0f2ccc0814788c956d59ff05064f90dd;hpb=2c1785eb5f5764aa82305c32973705c735f15dfc;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.selection/src/org/simantics/district/selection/ElementSelector.java b/org.simantics.district.selection/src/org/simantics/district/selection/ElementSelector.java index f015bddf..6de06ff6 100644 --- a/org.simantics.district.selection/src/org/simantics/district/selection/ElementSelector.java +++ b/org.simantics.district.selection/src/org/simantics/district/selection/ElementSelector.java @@ -56,6 +56,8 @@ public class ElementSelector { Selector selector; Condition condition; + private float[] color; + static Logger LOG = LoggerFactory.getLogger(ElementSelector.class); static ElementSelectionResource ES; @@ -81,6 +83,9 @@ public class ElementSelector { try { this.name = graph.getRelatedValue(resource, L0.HasLabel); this.expression = getExpression(graph, resource); + + float[] color = graph.getPossibleRelatedValue(resource, ES.Selection_HasHighlightColor); + this.color = color; } catch (DatabaseException e) { LOG.error("Error reading element selector", e); throw e; @@ -149,6 +154,13 @@ public class ElementSelector { public Condition getCondition() { return condition; } + + /** + * Get the selection highlight color as a four element BGRA array. + */ + public float[] getColor() { + return color; + } /** * @@ -636,7 +648,7 @@ public class ElementSelector { // Select sorting direction Comparator> comparator = smallest ? (p1, p2) -> Double.compare(p1.second, p2.second) : - (p1, p2) -> Double.compare(p1.second, p2.second); + (p1, p2) -> Double.compare(p2.second, p1.second); // Get association list to property values List> result2 = elements.stream() @@ -689,11 +701,14 @@ public class ElementSelector { Condition(ReadGraph graph, Resource r) throws DatabaseException { this(r); + ElementSelectionResource ES = ElementSelectionResource.getInstance(graph); isInverse = graph.hasStatement(r, ES.Condition_IsInverse, r); } public abstract boolean match(ReadGraph graph, Resource r) throws DatabaseException; public Resource update(WriteGraph graph) throws DatabaseException { + ElementSelectionResource ES = ElementSelectionResource.getInstance(graph); + assert(resource != null); if (isInverse) graph.claim(resource, ES.Condition_IsInverse, resource); @@ -707,6 +722,7 @@ public class ElementSelector { public PropertyCondition(ReadGraph graph, Resource r) throws DatabaseException { super(graph, r); + ElementSelectionResource ES = ElementSelectionResource.getInstance(graph); this.propertyName = graph.getRelatedValue(resource, ES.PropertyCondition_HasPropertyName); this.lowerLimit = graph.getPossibleRelatedValue(resource, ES.PropertyCondition_HasLowerLimit); this.upperLimit = graph.getPossibleRelatedValue(resource, ES.PropertyCondition_HasUpperLimit); @@ -768,6 +784,7 @@ public class ElementSelector { public RegionCondition(ReadGraph graph, Resource r) throws DatabaseException { super(graph, r); + ElementSelectionResource ES = ElementSelectionResource.getInstance(graph); DiagramRegionsResource DR = DiagramRegionsResource.getInstance(graph); this.regionResource = graph.getPossibleObject(resource, ES.RegionCondition_HasRegion); this.region = regionResource != null ? graph.getRelatedValue(regionResource, DR.Region_area) : null; @@ -802,8 +819,9 @@ public class ElementSelector { @Override public Resource update(WriteGraph graph) throws DatabaseException { - ElementSelectionResource ES = ElementSelectionResource.getInstance(graph); Layer0 L0 = Layer0.getInstance(graph); + ElementSelectionResource ES = ElementSelectionResource.getInstance(graph); + DiagramRegionsResource DR = DiagramRegionsResource.getInstance(graph); if (resource == null) { resource = graph.newResource(); @@ -815,7 +833,6 @@ public class ElementSelector { graph.claim(resource, ES.RegionCondition_HasRegion, regionResource); // Re-read region data to match DB - DiagramRegionsResource DR = DiagramRegionsResource.getInstance(graph); this.region = regionResource != null ? graph.getRelatedValue(regionResource, DR.Region_area, Bindings.DOUBLE_ARRAY) : null; this.path = createPathForRegion(region); @@ -927,8 +944,8 @@ public class ElementSelector { @Override public Resource update(WriteGraph graph) throws DatabaseException { - ElementSelectionResource ES = ElementSelectionResource.getInstance(graph); Layer0 L0 = Layer0.getInstance(graph); + ElementSelectionResource ES = ElementSelectionResource.getInstance(graph); if (resource == null) { resource = graph.newResource();