1 /*******************************************************************************
\r
2 * Copyright (c) 2010 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.editor;
\r
14 import org.simantics.db.ReadGraph;
\r
15 import org.simantics.db.Resource;
\r
16 import org.simantics.db.exception.DatabaseException;
\r
17 import org.simantics.layer0.utils.binaryPredicates.InversePredicate;
\r
18 import org.simantics.layer0.utils.binaryPredicates.OrderedSetElementsPredicate;
\r
19 import org.simantics.mapping.constraint.instructions.IInstruction;
\r
20 import org.simantics.mapping.constraint.instructions.TypedBracketInstruction.CreationInstruction;
\r
21 import org.simantics.mapping.rule.instructions.IRuleInstruction;
\r
22 import org.simantics.sysdyn.SysdynResource;
\r
24 public class DiagramToCompositeMapping3 extends org.simantics.modeling.mapping.DiagramToCompositeMapping3 {
\r
26 private SysdynResource sdr;
\r
28 public DiagramToCompositeMapping3(ReadGraph g, Resource mapping)
\r
29 throws DatabaseException {
\r
34 protected void setup(ReadGraph graph) {
\r
35 sdr = SysdynResource.getInstance(graph);
\r
39 protected Resource getConfigurationConnectionType() {
\r
40 return sdr.DependencyConnection;
\r
44 public CreationInstruction componentCreationInstruction(int component, int componentType, int configuration) {
\r
45 return new SysdynCreationInstruction(project, configurationRoot, component, componentType, configuration);
\r
49 protected IRuleInstruction additiveRule() {
\r
52 if_(bf(OrderedSetElementsPredicate.INSTANCE, Diagram, Element),
\r
54 if_(and(bf(L0.InstanceOf, Element, ElementType),
\r
55 bf(MOD.SymbolToComponentType, ElementType, ComponentType)
\r
57 // If element type of the element has a corresponding component type
\r
58 createComponentRule(),
\r
60 if_(and(b(DIA.Connection, Element), bf(L0.InstanceOf, Element, ElementType), bf(MOD.DiagramConnectionTypeToConnectionType, ElementType, ComponentType)),
\r
61 createNormalConnectionRule(),
\r
63 if_(b(DIA.Flag, Element),
\r
73 protected IRuleInstruction destructiveRule() {
\r
75 if_(and(bf(L0.ConsistsOf, Configuration, Component),
\r
76 b(mapped, Component) // handle only mapped components
\r
79 if_(and(bf(MOD.ComponentToElement, Component, Element),
\r
80 bf(new InversePredicate(OrderedSetElementsPredicate.INSTANCE), Element, Diagram)
\r
82 // If component has a corresponding element in the diagram
\r
83 if_(and(statement_bff(Component, ConnectionRelation, Connection, STR.IsConnectedTo),
\r
84 b(mapped, Connection)
\r
86 // If component has a mapped connection
\r
88 bf(MOD.ConnectionToDiagramConnection, Connection, DiagramConnectionRelation),
\r
89 // If the configuration connection does not have a correspondence in the diagram remove it
\r
90 and(deny(exists(Connection)))
\r
95 bf(MOD.ConnectionToDiagramConnection, Component, Element),
\r
96 // If the configuration connection does not have a correspondence in the diagram remove it
\r
97 and(deny(exists(Component)))
\r
106 protected IInstruction claimBasicConnection() {
\r
108 bf(MOD.DiagramConnectionToConnection, Element, Connection),
\r
111 bb(L0.InstanceOf, Connection, ComponentType),
\r
112 bb(L0.PartOf, Connection, Configuration),
\r
113 b(mapped, Connection)
\r
119 // protected IInstruction claimBasicConnection() {
\r
120 // return and(exists(
\r
121 // bf(MOD.DiagramConnectionToConnection, Element, Connection),
\r
124 // bb(L0.InstanceOf, Connection, ComponentType),
\r
125 // b(mapped, Connection),
\r
126 // bb(L0.PartOf, Connection, Configuration)
\r