1 import "http://www.simantics.org/ElementSelection-1.0" as ES
4 importJava "org.simantics.district.selection.ElementSelector" where
8 Get a selection resource represented as an ElementSelector object.
10 getSelector :: Resource -> <ReadGraph> ElementSelector
13 Get the name of the selection from an element selector object.
16 getSelectorName :: ElementSelector -> String
19 Get an expression that represents the selection from an element selector object.
21 @JavaName getExpression
22 getSelectorExpression :: ElementSelector -> String
25 Get the selection resource form an element selector object.
28 getSelectorResource :: ElementSelector -> Resource
31 Get the elements selected by an element selector object.
33 `selectedElements = selectElementsFrom elementSelector model`
35 @JavaName selectElementsFrom
36 selectElementsFrom :: ElementSelector -> Resource -> <ReadGraph> [Resource]
38 data Generator = Model | Diagram Resource | Explicit [Resource]
39 data Selector = All | NLowest String Integer | NHighest String Integer
40 data Condition = PropertyCondition String (Maybe Double) (Maybe Double)
41 | Region Resource | Route Resource
42 | Conjunction [Condition] | Disjunction [Condition] | Negation [Condition]
44 data Selection = Selection Generator Selector (Maybe Condition)
47 Write a selection expression into the database.
49 `selectionResource = writeSelection parentResource selectionName selection`
51 writeSelection :: Resource -> String -> Selection -> <WriteGraph> Resource
52 writeSelection root name (Selection generator selector maybeCondition) = let
53 selection = newEntity [hasName name, hasLabel name, hasType ES.Selection, hasParent root]
54 generator = match generator with
55 Model -> newEntity [hasType ES.Generator.Model]
56 Diagram diagram -> newEntity [hasType ES.Generator.Diagram, hasStatement ES.Generator.HasDiagram diagram]
57 Explicit elements -> let
58 g = newEntity [hasType ES.Generator.Explicit]
59 for elements (claim g ES.Generator.HasSelectedElement)
61 claim selection ES.Selection.HasGenerator generator
62 selector = match selector with
63 All -> newEntity [hasType ES.Selector.All]
64 NLowest propertyName count -> newEntity [hasType ES.Selector.NLowest,
65 hasProperty ES.PropertySelector.HasSelectionPropertyName propertyName,
66 hasProperty ES.PropertySelector.HasResultCount count]
67 NHighest propertyName count -> newEntity [hasType ES.Selector.NHighest,
68 hasProperty ES.PropertySelector.HasSelectionPropertyName propertyName,
69 hasProperty ES.PropertySelector.HasResultCount count]
70 claim selection ES.Selection.HasSelector selector
71 for maybeCondition \condition -> claim selection ES.Selection.HasCondition $ writeCondition condition
74 writeCondition condition = match condition with
75 PropertyCondition propertyName lowerLimit upperLimit -> let
76 cond = newEntity [hasType ES.PropertyCondition, hasProperty ES.PropertyCondition.HasPropertyName propertyName]
77 for lowerLimit \limit -> claimRelatedValue cond ES.PropertyCondition.HasLowerLimit limit
78 for upperLimit \limit -> claimRelatedValue cond ES.PropertyCondition.HasUpperLimit limit
80 Region region -> newEntity [hasType ES.RegionCondition, hasProperty ES.RegionCondition.HasRegion region]
81 Route route -> newEntity [hasType ES.RouteCondition, hasProperty ES.RouteCondition.HasRoute route]
82 Conjunction conds -> writeAggregateCondition ES.Conjunction conds
83 Disjunction conds -> writeAggregateCondition ES.Disjunction conds
84 Negation conds -> writeAggregateCondition ES.Negation conds
85 Not cond -> writeAggregateCondition ES.Negation [cond]
86 writeAggregateCondition condType conds = let
87 cond = newEntity [hasType condType]
88 for conds \c -> claim cond ES.HasSubcondition $ writeCondition c