import "http://www.simantics.org/ElementSelection-1.0" as ES import "Simantics/DB" importJava "org.simantics.district.selection.ElementSelector" where data ElementSelector """ Get a selection resource represented as an ElementSelector object. """ getSelector :: Resource -> ElementSelector """ Get the name of the selection from an element selector object. """ @JavaName getName getSelectorName :: ElementSelector -> String """ Get an expression that represents the selection from an element selector object. """ @JavaName getExpression getSelectorExpression :: ElementSelector -> String """ Get the selection resource form an element selector object. """ @JavaName getResource getSelectorResource :: ElementSelector -> Resource @JavaName selectElementsFrom selectElementsFrom' :: ElementSelector -> Resource -> SelectionResult """ Get the elements selected by an element selector object. `selectedElements = selectElementsFrom elementSelector model` """ selectElementsFrom :: ElementSelector -> Resource -> [Resource] selectElementsFrom s r = selectedElements $ selectElementsFrom' s r importJava "org.simantics.district.selection.ElementSelector$SelectionResult" where data SelectionResult "Get the list of selected elements" @JavaName elements selectedElements :: SelectionResult -> [Resource] "Number of selected elements with equal selection criteria (for n lowest/n highest selections)" tailCount :: SelectionResult -> Integer "Actual number of elements with selection criteria equal to the last selected element (for n lowest/n highest selections)" tailSize :: SelectionResult -> Integer data Generator = Model | Diagram Resource | Explicit [Resource] data Selector = All | NLowest String Integer | NHighest String Integer data Condition = PropertyCondition String (Maybe Double) (Maybe Double) | Region Resource | Route Resource | Conjunction [Condition] | Disjunction [Condition] | Negation [Condition] | Not Condition data Selection = Selection Generator Selector (Maybe Condition) """ Write a selection expression into the database. `selectionResource = writeSelection parentResource selectionName selection` """ writeSelection :: Resource -> String -> Selection -> Resource writeSelection root name (Selection generator selector maybeCondition) = let selection = newEntity [hasName name, hasLabel name, hasType ES.Selection, hasParent root] generator = match generator with Model -> newEntity [hasType ES.Generator.Model] Diagram diagram -> newEntity [hasType ES.Generator.Diagram, hasStatement ES.Generator.HasDiagram diagram] Explicit elements -> let g = newEntity [hasType ES.Generator.Explicit] for elements (claim g ES.Generator.HasSelectedElement) in g claim selection ES.Selection.HasGenerator generator selector = match selector with All -> newEntity [hasType ES.Selector.All] NLowest propertyName count -> newEntity [hasType ES.Selector.NLowest, hasProperty ES.PropertySelector.HasSelectionPropertyName propertyName, hasProperty ES.PropertySelector.HasResultCount count] NHighest propertyName count -> newEntity [hasType ES.Selector.NHighest, hasProperty ES.PropertySelector.HasSelectionPropertyName propertyName, hasProperty ES.PropertySelector.HasResultCount count] claim selection ES.Selection.HasSelector selector for maybeCondition \condition -> claim selection ES.Selection.HasCondition $ writeCondition condition in selection where writeCondition condition = match condition with PropertyCondition propertyName lowerLimit upperLimit -> let cond = newEntity [hasType ES.PropertyCondition, hasProperty ES.PropertyCondition.HasPropertyName propertyName] for lowerLimit \limit -> claimRelatedValue cond ES.PropertyCondition.HasLowerLimit limit for upperLimit \limit -> claimRelatedValue cond ES.PropertyCondition.HasUpperLimit limit in cond Region region -> newEntity [hasType ES.RegionCondition, hasProperty ES.RegionCondition.HasRegion region] Route route -> newEntity [hasType ES.RouteCondition, hasProperty ES.RouteCondition.HasRoute route] Conjunction conds -> writeAggregateCondition ES.Conjunction conds Disjunction conds -> writeAggregateCondition ES.Disjunction conds Negation conds -> writeAggregateCondition ES.Negation conds Not cond -> writeAggregateCondition ES.Negation [cond] writeAggregateCondition condType conds = let cond = newEntity [hasType condType] for conds \c -> claim cond ES.HasSubcondition $ writeCondition c in cond