Program: 73831
Project: 73831
Buggy source:
/** 
 * Traverse a composite KNode containing corresponding Kieler nodes, ports and edges for the Ptolemy model and apply all layout information contained by it back to the Ptolemy model. Do most changes to the Ptolemy model via MoMLChangeRequests. Set location attributes for all visible Ptolemy nodes. So far Ptolemy does not support setting of connection bendpoints explicitly. The Ptolemy connection router does not consider obstruction avoidance so there are likely to be connection overlappings in the diagram. <p> Optionally route edges explicitly by inserting new relation vertices for each bend point.
 * @see #setApplyEdgeLayout(boolean)
 * @param kgraph The Kieler graph object containing all layout information to apply to the Ptolemy model
 * @exception IllegalActionException Exception can be thrown if routing of edges fails due to not allowed unlinking or linking of new relations.
 */
private void _applyLayout(KNode kgraph) throws IllegalActionException {
  GraphModel graph=this.getLayoutTarget().getGraphModel();
  if (graph instanceof ActorGraphModel) {
    Collection<KNode> kNodes=kgraph.getChildren();
    if (_doBoxLayout) {
      kNodes=_kieler2ptolemyEntityNodes.keySet();
    }
    for (    KNode knode : kNodes) {
      KShapeLayout absoluteLayout=KielerGraphUtil._getAbsoluteLayout(knode);
      NamedObj namedObj=_kieler2ptolemyEntityNodes.get(knode);
      _kNode2Ptolemy(absoluteLayout,knode);
      if (namedObj instanceof Relation) {
        Vertex vertex=(Vertex)_kieler2ptolemyDivaNodes.get(knode);
        PtolemyModelUtil._setLocation(vertex,(Relation)namedObj,absoluteLayout.getXpos(),absoluteLayout.getYpos());
      }
 else {
        PtolemyModelUtil._setLocation(namedObj,absoluteLayout.getXpos(),absoluteLayout.getYpos());
      }
    }
    if (_doApplyEdgeLayout) {
      Set<Relation> relationsToDelete=new HashSet<Relation>();
      for (      KEdge kedge : _kieler2PtolemyDivaEdges.keySet()) {
        Relation oldRelation=_applyEdgeLayout(kedge);
        if (oldRelation != null) {
          relationsToDelete.add(oldRelation);
        }
      }
      _ptolemyModelUtil._removeRelations(relationsToDelete);
    }
  }
  _ptolemyModelUtil._performChangeRequest(_compositeActor);
}

Fixed version (ground truth):
/** 
 * Traverse a composite KNode containing corresponding Kieler nodes, ports and edges for the Ptolemy model and apply all layout information contained by it back to the Ptolemy model. Do most changes to the Ptolemy model via MoMLChangeRequests. Set location attributes for all visible Ptolemy nodes. So far Ptolemy does not support setting of connection bendpoints explicitly. The Ptolemy connection router does not consider obstruction avoidance so there are likely to be connection overlappings in the diagram. <p> Optionally route edges explicitly by inserting new relation vertices for each bend point.
 * @see #setApplyEdgeLayout(boolean)
 * @param kgraph The Kieler graph object containing all layout information to apply to the Ptolemy model
 * @exception IllegalActionException Exception can be thrown if routing of edges fails due to not allowed unlinking or linking of new relations.
 */
private void _applyLayout(KNode kgraph) throws IllegalActionException {
  GraphModel graph=this.getLayoutTarget().getGraphModel();
  if (graph instanceof ActorGraphModel) {
    Collection<KNode> kNodes=kgraph.getChildren();
    if (_doBoxLayout) {
      kNodes=_kieler2ptolemyEntityNodes.keySet();
    }
    for (    KNode knode : kNodes) {
      KShapeLayout absoluteLayout=KielerGraphUtil._getAbsoluteLayout(knode);
      NamedObj namedObj=_kieler2ptolemyEntityNodes.get(knode);
      _kNode2Ptolemy(absoluteLayout,knode);
      if (namedObj instanceof Relation) {
        Vertex vertex=(Vertex)_kieler2ptolemyDivaNodes.get(knode);
        _ptolemyModelUtil._setLocation(vertex,(Relation)namedObj,absoluteLayout.getXpos(),absoluteLayout.getYpos());
      }
 else {
        _ptolemyModelUtil._setLocation(namedObj,absoluteLayout.getXpos(),absoluteLayout.getYpos());
      }
    }
    if (_doApplyEdgeLayout) {
      Set<Relation> relationsToDelete=new HashSet<Relation>();
      for (      KEdge kedge : _kieler2PtolemyDivaEdges.keySet()) {
        Relation oldRelation=_applyEdgeLayout(kedge);
        if (oldRelation != null) {
          relationsToDelete.add(oldRelation);
        }
      }
      _ptolemyModelUtil._removeRelations(relationsToDelete);
    }
  }
  _ptolemyModelUtil._performChangeRequest(_compositeActor);
}