From: Marko Luukkainen Date: Thu, 17 Dec 2020 15:01:03 +0000 (+0200) Subject: Diagram API fixes. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=a93da57d733f096747647e5ebf1e0b2578417ac3;p=simantics%2Finterop.git Diagram API fixes. Allow connection type customization Switch to slf4j logger. Remove Apros specific intefaces (these were not used in the code anyway). gitlab #7 Change-Id: I2b4962e75c9a389cd01791c1454b1715710da9eb --- diff --git a/org.simantics.interop.diagram/src/org/simantics/interop/diagram/Symbol.java b/org.simantics.interop.diagram/src/org/simantics/interop/diagram/Symbol.java index c86ca7a..1ae1c6c 100644 --- a/org.simantics.interop.diagram/src/org/simantics/interop/diagram/Symbol.java +++ b/org.simantics.interop.diagram/src/org/simantics/interop/diagram/Symbol.java @@ -13,7 +13,6 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Statement; import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.Logger; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; @@ -27,6 +26,9 @@ import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.structural2.utils.StructuralUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + @@ -35,6 +37,8 @@ import org.simantics.structural2.utils.StructuralUtils; */ public abstract class Symbol { + private static Logger Logger = LoggerFactory.getLogger(Symbol.class); + private static boolean USE_UNRELIABLE_CONNECT = false; private static boolean PREVENT_SELF_CONNECTIONS = false; @@ -122,12 +126,12 @@ public abstract class Symbol { if (this.equals(symbolConf2)) { if (PREVENT_SELF_CONNECTIONS) { String err = "Preventing connection to self: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(componentConRel1) + " "+ componentConRel1 + " " + g.getPossibleURI(componentConRel2) + " "+ componentConRel2; - Logger.defaultLogError(err); + Logger.error(err); return new ConnectionErrorImpl(err); } if (componentConRel1.equals(componentConRel2)) { String err = "Preventing connection to self: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(componentConRel1) + " "+ componentConRel1 + " " + g.getPossibleURI(componentConRel2) + " "+ componentConRel2; - Logger.defaultLogError(err); + Logger.error(err); return new ConnectionErrorImpl(err); } } @@ -150,7 +154,7 @@ public abstract class Symbol { } else { err = "Unable to connect " + component + " " + NameUtils.getSafeName(g, component) + " to " + symbolConf2.component + " " + NameUtils.getSafeName(g, symbolConf2.component) + " cannot find proper connection type for terminals " + g.getPossibleURI(componentConRel1) + " "+ componentConRel1 + " " + g.getPossibleURI(componentConRel2) + " "+ componentConRel2; } - Logger.defaultLogInfo(err); + Logger.info(err); return new ConnectionErrorImpl(err); } else { usedConnType = matching.iterator().next(); @@ -197,12 +201,12 @@ public abstract class Symbol { usedConnType = connType2.iterator().next(); else { String err = "Cannot locate connection type for: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2; - Logger.defaultLogError(err); + Logger.error(err); return new ConnectionErrorImpl(err); } if (!diagram.equals(symbolConf2.diagram)) { String err = "Element connections must be done on the same diagram: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2; - Logger.defaultLogError(err); + Logger.error(err); return new ConnectionErrorImpl(err); } return connectElement(g, symbolConf2, elementConRel1, elementConRel2, usedConnType); @@ -212,12 +216,12 @@ public abstract class Symbol { if (this.equals(symbolConf2)) { if (PREVENT_SELF_CONNECTIONS) { String err = "Preventing connection to self: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2; - Logger.defaultLogError(err); + Logger.error(err); return new ConnectionErrorImpl(err); } if (elementConRel1.equals(elementConRel2)) { String err = "Preventing connection to self: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2; - Logger.defaultLogError(err); + Logger.error(err); return new ConnectionErrorImpl(err); } } @@ -251,6 +255,22 @@ public abstract class Symbol { return new ConnectionErrorImpl("Symbol is already connected"); } + protected Resource componentConnectionType(ReadGraph g, Resource componentConRel1, Resource componentConRel2) throws DatabaseException { + StructuralResource2 s = StructuralResource2.getInstance(g); + return s.Connection; + } + + protected Resource diagramConnectionType(ReadGraph g, Resource componentConnectionType) throws DatabaseException { + ModelingResources MOD = ModelingResources.getInstance(g); + if (componentConnectionType != null) { + Resource ct = g.getPossibleObject(componentConnectionType, MOD.ConnectionTypeToDiagramConnectionType); + if (ct != null) + return ct; + } + DiagramResource d = DiagramResource.getInstance(g); + return d.RouteGraphConnection; + } + private SymbolConnectionData _connect(WriteGraph g, Symbol symbolConf2, Resource componentConRel1, Resource componentConRel2, Resource connectorType) throws DatabaseException { Layer0 b = Layer0.getInstance(g); StructuralResource2 s = StructuralResource2.getInstance(g); @@ -275,7 +295,8 @@ public abstract class Symbol { // connection object in module level Resource moduleConnection = g.newResource(); - g.claim(moduleConnection, b.InstanceOf, s.Connection); + Resource moduleConnectionType = componentConnectionType(g, componentConRel1, componentConRel2); + g.claim(moduleConnection, b.InstanceOf, moduleConnectionType); // connect the modules @@ -284,7 +305,7 @@ public abstract class Symbol { // connection object in diagram level Resource diagramConnection = g.newResource(); - g.claim(diagramConnection, b.InstanceOf, d.RouteGraphConnection); + g.claim(diagramConnection, b.InstanceOf, diagramConnectionType(g, moduleConnectionType)); DiagramUtils.addElementFirst(g, diagram, diagramConnection); g.claim(diagramConnection, s.HasConnectionType, connectorType); @@ -332,7 +353,7 @@ public abstract class Symbol { if (current.component.equals(symbolConf2.component)) return new SymbolExistsImpl(); String err = "Cannot connect, terminal 1 is reserved: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2; - Logger.defaultLogError(err); + Logger.error(err); return new ConnectionErrorImpl(err); } if (g.isInstanceOf(elementConRel2, b.FunctionalRelation) && symbolConf2.getDiagramSingleConnected(g, elementConRel2) != null) { @@ -340,7 +361,7 @@ public abstract class Symbol { if (current.component.equals(component)) return new SymbolExistsImpl(); String err = "Cannot connect, terminal 2 is reserved: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2; - Logger.defaultLogError(err); + Logger.error(err); return new ConnectionErrorImpl(err); } @@ -355,7 +376,7 @@ public abstract class Symbol { // connection object in diagram level Resource diagramConnection = g.newResource(); - g.claim(diagramConnection, b.InstanceOf, d.RouteGraphConnection); + g.claim(diagramConnection, b.InstanceOf, diagramConnectionType(g, null)); DiagramUtils.addElementFirst(g, diagram, diagramConnection); g.claim(diagramConnection, s.HasConnectionType, connectorType); @@ -405,12 +426,12 @@ public abstract class Symbol { if (g.isInstanceOf(componentConRel1, l0.FunctionalRelation) && getSingleConnected(g, componentConRel1) != null) { String err = "Cannot flag connect " + component + " " + NameUtils.getSafeName(g, component) + " to " + symbolConf2.component + " " + NameUtils.getSafeName(g, symbolConf2.component) + " since the first terminal is already reserved"; - Logger.defaultLogError(err); + Logger.error(err); return new ConnectionErrorImpl(err); } if (g.isInstanceOf(componentConRel2, l0.FunctionalRelation) && symbolConf2.getSingleConnected(g, componentConRel2) != null) { String err = "Cannot flag connect " + component + " " + NameUtils.getSafeName(g, component) + " to " + symbolConf2.component + " " + NameUtils.getSafeName(g, symbolConf2.component) + " since the second terminal is already reserved"; - Logger.defaultLogError(err); + Logger.error(err); return new ConnectionErrorImpl(err); } @@ -427,10 +448,11 @@ public abstract class Symbol { g.claim(diagram2.getComposite(), s.HasConnectionJoin, connectionJoin); Resource connection1 = g.newResource(); - g.claim(connection1, l0.InstanceOf, s.Connection); + Resource ct = componentConnectionType(g, componentConRel1, componentConRel2); + g.claim(connection1, l0.InstanceOf, ct); Resource connection2 = g.newResource(); - g.claim(connection2, l0.InstanceOf, s.Connection); + g.claim(connection2, l0.InstanceOf, ct); g.claim(component, componentConRel1, connection1); g.claim(symbolConf2.component, componentConRel2, connection2); @@ -441,12 +463,13 @@ public abstract class Symbol { g.claim(flag2.element, d.FlagIsJoinedBy, connectionJoin); Resource diagConnection1 = g.newResource(); - g.claim(diagConnection1, l0.InstanceOf, d.RouteGraphConnection); + Resource dct = diagramConnectionType(g, ct); + g.claim(diagConnection1, l0.InstanceOf, dct); DiagramUtils.addElementFirst(g, diagram, diagConnection1); g.claim(diagConnection1, s.HasConnectionType, connectionType); Resource diagConnection2 = g.newResource(); - g.claim(diagConnection2, l0.InstanceOf, d.RouteGraphConnection); + g.claim(diagConnection2, l0.InstanceOf, dct); DiagramUtils.addElementFirst(g, diagram2, diagConnection2); g.claim(diagConnection2, s.HasConnectionType, connectionType); @@ -945,23 +968,6 @@ public abstract class Symbol { public Symbol getSecondFlag(); } - - /** - * Interface for signal connections. - * - */ - public interface SignalConnectionData extends SymbolConnectionData { - public Resource getSignalComponent(); - } - - /** - * Interface for Point connections. - * - */ - public interface PointConnectionData extends SymbolConnectionData { - Symbol getPoint(); - } - /** * Interface for "connection" that merged the connected symbols into one symbol. *