Commit c0e4c4b9 authored by Tiziano Munaro's avatar Tiziano Munaro

Refactor connector composition rules in state automata

Issue-Ref: 3962
Issue-Url: https://af3-developer.fortiss.org/issues/3962Signed-off-by: Tiziano Munaro's avatarTiziano Munaro <munaro@fortiss.org>
parent 677b3119
BehaviorComponentCompositor.java a1dbd75cfce361b709249b0d851f080cf63d243c GREEN
ConnectorConnectionCompositor.java 2111cd454554b3caf887a1381cc1184ba3ff13eb YELLOW
ConnectorConnectionCompositor.java cfa132219000b2f3048c56452e22eeac832314b3 YELLOW
ConnectorStateConnectionCompositor.java a0fb18af7ded52cbcb18be83cf1d9960028ceac2 GREEN
StateAutomatonCompositor.java 42625f27b7e2d5de0df39c56618173ff057ea7a5 GREEN
StateCompositor.java 299d369552fb940a1297d64606c3c0c1698e57a8 GREEN
......
......@@ -22,6 +22,7 @@ import org.fortiss.af3.state.model.State;
import org.fortiss.tooling.base.compose.ConnectorConnectionCompositorBase;
import org.fortiss.tooling.base.model.base.ConnectionSegmentBase;
import org.fortiss.tooling.base.model.base.ConnectorBase;
import org.fortiss.tooling.base.model.base.EntryConnectorBase;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.kernel.extension.data.IConnectionCompositionContext;
......@@ -40,21 +41,22 @@ public class ConnectorConnectionCompositor
// Do not allow connections from and to already occupied ports.
// Since a link can be drawn from an entry not to an exit node as well, both end
// points have to be checked for both incoming and outgoing links.
boolean freeSource, freeTarget;
// If both connectors are on the same level, they can be connected only once.
boolean freeSource = false;
boolean freeTarget = false;
// If both connectors are on the same level, they can be connected only once:
if(source.eContainer() == target.eContainer()) {
freeSource = source.getOutgoing().isEmpty() && source.getIncoming().isEmpty();
freeTarget = target.getIncoming().isEmpty() && target.getOutgoing().isEmpty();
} else {
freeSource = isSameLevelPortFree(source);
freeTarget = isSameLevelPortFree(target);
// In case on of the connections is attached to the parent, it is possible that a port
// has an incoming and an outcoming connection (one on each level).
if(source.eContainer() == target.eContainer().eContainer()) {
freeSource = source.getOutgoing().isEmpty();
freeTarget = target.getIncoming().isEmpty() && target.getOutgoing().isEmpty();
} else {
freeSource = source.getOutgoing().isEmpty() && source.getIncoming().isEmpty();
freeTarget = target.getIncoming().isEmpty();
}
// has an incoming and an outcoming connection (one on each level):
} else if(source.eContainer() == target.eContainer().eContainer()) {
// Case where the source is the cross-level port:
freeSource = isCrossLevelPortFree(source);
freeTarget = isSameLevelPortFree(target);
} else if(source.eContainer() != target.eContainer().eContainer()) {
// Case where the target is the cross-level port:
freeSource = isSameLevelPortFree(source);
freeTarget = isCrossLevelPortFree(target);
}
if(freeSource && freeTarget) {
return super.canConnect(source, target, parent, context);
......@@ -62,6 +64,29 @@ public class ConnectorConnectionCompositor
return false;
}
/**
* Checks whether a port is available for a connection on the same level. In this case the port
* cannot have any other connections.
*/
private boolean isSameLevelPortFree(ConnectorBase connector) {
return connector.getOutgoing().isEmpty() && connector.getIncoming().isEmpty();
}
/**
* Checks whether a port is available for a connection to or from another level. In this case
* the port may already have another connection on the other level. However, the port cannot
* have an existing connection on the level of the connection to be established.
*/
private boolean isCrossLevelPortFree(ConnectorBase connector) {
boolean isFree;
if(connector instanceof EntryConnectorBase) {
isFree = connector.getOutgoing().isEmpty();
} else {
isFree = connector.getIncoming().isEmpty();
}
return isFree;
}
/** {@inheritDoc} */
@Override
protected ConnectionSegmentBase createConnection() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment