Skip to content

Commit

Permalink
Extend TargetPin Searching Across Subapp boundaries
Browse files Browse the repository at this point in the history
Target pins are now searched and shown also across subapp boundaries.
  • Loading branch information
azoitl authored and oberlehner committed May 8, 2024
1 parent 15ae927 commit 1911205
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 27 deletions.
Expand Up @@ -77,23 +77,35 @@ private Set<EObject> getCurrentTargets() {
final Set<EObject> currTargets = new HashSet<>();

if (refEditPart.isInput()) {
for (final Connection con : model.getInputConnections()) {
currTargets.add(con);
if (con.getSource() != null) {
currTargets.add(con.getSource());
}
}
model.getInputConnections().forEach(srcCon -> checkInputConns(currTargets, srcCon));
} else {
for (final Connection con : model.getOutputConnections()) {
currTargets.add(con);
final IInterfaceElement dest = con.getDestination();
if (dest != null) {
currTargets.add(dest);
currTargets.addAll(dest.getOutputConnections()); // needed for correctly handling undo
}
}
model.getOutputConnections().forEach(dstCon -> checkoutOutputConns(currTargets, dstCon));
}
return currTargets;
}

private static void checkInputConns(final Set<EObject> currTargets, final Connection con) {
currTargets.add(con);
final IInterfaceElement source = con.getSource();
if (source != null) {
currTargets.add(con.getSource());
if (TargetPinManager.followConnections(source.getFBNetworkElement(), source.getInputConnections())) {
source.getInputConnections().forEach(srcCon -> checkInputConns(currTargets, srcCon));
}
}
}

private static void checkoutOutputConns(final Set<EObject> currTargets, final Connection con) {
currTargets.add(con);
final IInterfaceElement dest = con.getDestination();
if (dest != null) {
currTargets.add(dest);
if (TargetPinManager.followConnections(dest.getFBNetworkElement(), dest.getOutputConnections())) {
dest.getOutputConnections().forEach(dstCon -> checkoutOutputConns(currTargets, dstCon));
} else {
currTargets.addAll(dest.getOutputConnections()); // needed for correctly handling undo
}
}
}

}
Expand Up @@ -18,11 +18,14 @@
import java.util.Objects;
import java.util.stream.Stream;

import org.eclipse.emf.common.util.EList;
import org.eclipse.fordiac.ide.gef.editparts.InterfaceEditPart;
import org.eclipse.fordiac.ide.model.libraryElement.Connection;
import org.eclipse.fordiac.ide.model.libraryElement.FBNetwork;
import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement;
import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement;
import org.eclipse.fordiac.ide.model.libraryElement.SubApp;
import org.eclipse.fordiac.ide.model.libraryElement.UntypedSubApp;

public class TargetPinManager {

Expand Down Expand Up @@ -52,22 +55,38 @@ private IInterfaceElement getModel() {

private List<IInterfaceElement> getTargetPins() {
return getModel().getOutputConnections().stream()
.filter(con -> (!con.isVisible() && con.getDestination() != null)).flatMap(con -> {
if (con.getDestination().getFBNetworkElement() instanceof final SubApp subapp
&& subapp.isUnfolded()) {
return con.getDestination().getOutputConnections().stream();
}
return Stream.of(con);
}).map(Connection::getDestination).filter(Objects::nonNull).toList();
.filter(con -> (!con.isVisible() && con.getDestination() != null))
.flatMap(TargetPinManager::getTargetPins).filter(Objects::nonNull).toList();
}

private static Stream<IInterfaceElement> getTargetPins(final Connection con) {
final IInterfaceElement destination = con.getDestination();
if (destination != null
&& followConnections(destination.getFBNetworkElement(), destination.getOutputConnections())) {
return destination.getOutputConnections().stream().flatMap(TargetPinManager::getTargetPins);
}
return Stream.of(destination);
}

private List<IInterfaceElement> getSourcePins() {
return getModel().getInputConnections().stream().filter(con -> (!con.isVisible() && con.getSource() != null))
.flatMap(con -> {
if (con.getSource().getFBNetworkElement() instanceof final SubApp subapp && subapp.isUnfolded()) {
return con.getSource().getInputConnections().stream();
}
return Stream.of(con);
}).map(Connection::getSource).filter(Objects::nonNull).toList();
.flatMap(TargetPinManager::getSourcePins).filter(Objects::nonNull).toList();
}

private static Stream<IInterfaceElement> getSourcePins(final Connection con) {
final IInterfaceElement source = con.getSource();
if (source != null && followConnections(source.getFBNetworkElement(), source.getInputConnections())) {
return source.getInputConnections().stream().flatMap(TargetPinManager::getSourcePins);
}
return Stream.of(source);
}

static boolean followConnections(final FBNetworkElement fbnEl, final EList<Connection> conList) {
return fbnEl instanceof final UntypedSubApp subapp && !isContainedInUnfoldedSubapp(subapp)
&& !conList.isEmpty();
}

private static boolean isContainedInUnfoldedSubapp(final UntypedSubApp subapp) {
return subapp.getOuterFBNetworkElement() instanceof final SubApp outerSubApp && outerSubApp.isUnfolded();
}
}

0 comments on commit 1911205

Please sign in to comment.