Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Extension of FanRouter to reroute inverse connections
Extension of FanRouter to reroute inverse connections [message #153730] Tue, 12 October 2004 08:56 Go to next message
Eclipse UserFriend
Originally posted by: trost.ontoprise.de

Hi all,

I had the following problem with the FanRouter:

The router is able to reroute Connections if the starting anchor and the
end anchor are the same. But it did not work if the connection A has the
start anchor of connection B as end anchor and the end anchor of B as
start anchor. So this is somehow the case of "inverse connections". In
this case the connections overlay but the router did not recognize this
case.

To enable the FanRouter to reroute connections of this type of case, I
made the following changes:

Inner class HashKey from class AutomaticRouter:

private class HashKey {

private IFigure sourceFigure, targetFigure;

// use the parent figures instead of the anchors as they where
// different in case of inverse connections
HashKey(Connection conn) {
sourceFigure = conn.getSourceAnchor().getOwner().getParent();
targetFigure = conn.getTargetAnchor().getOwner().getParent();
}

public boolean equals(Object object) {
boolean isEqual = false;
HashKey hashKey;

if (object instanceof HashKey) {
hashKey = (HashKey)object;
IFigure hkA1 = hashKey.getSourceFigure();
IFigure hkA2 = hashKey.getTargetFigure();

isEqual = (hkA1.equals(sourceFigure) && hkA2.equals(targetFigure))
|| (hkA1.equals(targetFigure) && hkA2.equals(sourceFigure));
}
return isEqual;
}

public IFigure getSourceFigure() {
return sourceFigure;
}

public IFigure getTargetFigure() {
return targetFigure;
}

// to find the inverse connections the hashcode has to be
normalized
// so that the same pair of start and end point give the same
hashcode
// without taking into aspect of the direction of the connection
public int hashCode() {
if (sourceFigure.hashCode()<targetFigure.hashCode()) {
return sourceFigure.hashCode() ^ targetFigure.hashCode();
} else {
return targetFigure.hashCode() ^ sourceFigure.hashCode();
}
}
}

And the second change took place int the class AutomaticRouter in the
method invalidate. There the conditions for the operation had to be
adapted:

public void invalidate(Connection conn) {
if (conn.getSourceAnchor() == null || conn.getTargetAnchor() == null)
return;
if (conn.getSourceAnchor() != null && conn.getSourceAnchor().getOwner()
== null)
return;
if (conn.getTargetAnchor() != null && conn.getTargetAnchor().getOwner()
== null)
return;


This changes allow the FanRouter to rerout inverse connections as well as
the normal case of connections with the same direction. Nevertheless I did
not test this changes with other extensions of the AutomaticRouter!

best regards

Hans Trost
Re: Extension of FanRouter to reroute inverse connections [message #153747 is a reply to message #153730] Tue, 12 October 2004 15:25 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

FanRouter was designed to ignore the direction of the connections. Please
submit any test cases you have which fail in a bugzilla.
ConnectionAnchor.getOwner() may return NULL.

ConnectionAnchor.getOwner() may return null.

"Hans Trost" <trost@ontoprise.de> wrote in message
news:ckg67s$8in$1@eclipse.org...
> Hi all,
>
> I had the following problem with the FanRouter:
>
> The router is able to reroute Connections if the starting anchor and the
> end anchor are the same. But it did not work if the connection A has the
> start anchor of connection B as end anchor and the end anchor of B as
> start anchor. So this is somehow the case of "inverse connections". In
> this case the connections overlay but the router did not recognize this
> case.
>
> To enable the FanRouter to reroute connections of this type of case, I
> made the following changes:
>
> Inner class HashKey from class AutomaticRouter:
>
> private class HashKey {
>
> private IFigure sourceFigure, targetFigure;
>
> // use the parent figures instead of the anchors as they where
> // different in case of inverse connections
> HashKey(Connection conn) {
> sourceFigure = conn.getSourceAnchor().getOwner().getParent();
> targetFigure = conn.getTargetAnchor().getOwner().getParent();
> }
>
> public boolean equals(Object object) {
> boolean isEqual = false;
> HashKey hashKey;
>
> if (object instanceof HashKey) {
> hashKey = (HashKey)object;
> IFigure hkA1 = hashKey.getSourceFigure();
> IFigure hkA2 = hashKey.getTargetFigure();
>
> isEqual = (hkA1.equals(sourceFigure) && hkA2.equals(targetFigure))
> || (hkA1.equals(targetFigure) && hkA2.equals(sourceFigure));
> }
> return isEqual;
> }
>
> public IFigure getSourceFigure() {
> return sourceFigure;
> }
>
> public IFigure getTargetFigure() {
> return targetFigure;
> }
>
> // to find the inverse connections the hashcode has to be
> normalized
> // so that the same pair of start and end point give the same
> hashcode
> // without taking into aspect of the direction of the connection
> public int hashCode() {
> if (sourceFigure.hashCode()<targetFigure.hashCode()) {
> return sourceFigure.hashCode() ^ targetFigure.hashCode();
> } else {
> return targetFigure.hashCode() ^ sourceFigure.hashCode();
> }
> }
> }
>
> And the second change took place int the class AutomaticRouter in the
> method invalidate. There the conditions for the operation had to be
> adapted:
>
> public void invalidate(Connection conn) {
> if (conn.getSourceAnchor() == null || conn.getTargetAnchor() == null)
> return;
> if (conn.getSourceAnchor() != null && conn.getSourceAnchor().getOwner()
> == null)
> return;
> if (conn.getTargetAnchor() != null && conn.getTargetAnchor().getOwner()
> == null)
> return;
>
>
> This changes allow the FanRouter to rerout inverse connections as well as
> the normal case of connections with the same direction. Nevertheless I did
> not test this changes with other extensions of the AutomaticRouter!
>
> best regards
>
> Hans Trost
Previous Topic:visual feedback during connection creation
Next Topic:sorting an Outline view
Goto Forum:
  


Current Time: Fri Apr 26 16:21:13 GMT 2024

Powered by FUDForum. Page generated in 0.02964 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top