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;
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;
+
*/
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;
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);
}
}
} 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();
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);
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);
}
}
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);
// 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
// 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);
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) {
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);
}
// 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);
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);
}
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);
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);
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.
*