~ubuntu-branches/ubuntu/jaunty/electric/jaunty

« back to all changes in this revision

Viewing changes to com/sun/electric/database/constraint/LayoutCell.java

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2009-01-08 02:05:08 UTC
  • mfrom: (1.1.2 upstream) (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090108020508-0h3li7zt9mu5gf0i
Tags: 8.08-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
import com.sun.electric.database.hierarchy.Cell;
34
34
import com.sun.electric.database.hierarchy.Export;
35
35
import com.sun.electric.database.id.CellUsage;
 
36
import com.sun.electric.database.id.PortProtoId;
36
37
import com.sun.electric.database.prototype.PortProto;
 
38
import com.sun.electric.database.text.ImmutableArrayList;
37
39
import com.sun.electric.database.topology.ArcInst;
38
40
import com.sun.electric.database.topology.Connection;
39
41
import com.sun.electric.database.topology.Geometric;
56
58
import java.util.LinkedHashSet;
57
59
import java.util.List;
58
60
import java.util.Map;
 
61
import java.util.NoSuchElementException;
59
62
 
60
63
/**
61
64
 * Class to implement the layout-constraint system for a specific Cell.
98
101
//    private HashMap<Geometric,Integer> changeClock;
99
102
    /** Set of nodes already moved not to move twice. */
100
103
    private HashSet<NodeInst> movedNodes;
 
104
    private CellBackup.Memoization m;
101
105
 
102
106
    LayoutCell(Cell cell, CellBackup oldBackup) {
103
107
        this.cell = cell;
135
139
    private void doCompute() {
136
140
//        changeClock = new HashMap<Geometric,Integer>();
137
141
        movedNodes = new HashSet<NodeInst>();
 
142
        m = cell.getMemoization();
138
143
 
139
144
        LinkedHashSet<NodeInst> modifiedInsts = new LinkedHashSet<NodeInst>();
140
145
        for (Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); ) {
163
168
            }
164
169
        }
165
170
        for (NodeInst ni : modifiedInsts) {
166
 
            if (ni.hasExports())
167
 
//            if (ni.getNumExports() != 0)
 
171
            if (hasExports(ni))
 
172
//            if (ni.hasExports())
168
173
                exportsModified = true;
169
174
            ImmutableNodeInst d = getOldD(ni);
170
175
            Orientation dOrient = d != null ? ni.getOrient().concatenate(d.orient.inverse()) : Orientation.IDENT;
177
182
                ensureArcInst(ai, Layout.isRigid(ai) ? AI_RIGID : AI_FLEX);
178
183
            }
179
184
        }
 
185
        m = null;
180
186
    }
181
187
 
182
188
        /**
200
206
        movedNodes.add(ni);
201
207
 
202
208
                // see if this nodeinst is a port of the current cell
203
 
                if (ni.hasExports())
204
 
//              if (ni.getNumExports() != 0)
 
209
                if (hasExports(ni))
 
210
//              if (ni.hasExports())
205
211
            exportsModified = true;
206
212
        }
207
213
 
238
244
 
239
245
                // build a list of the arcs with both ends on this nodeinst
240
246
                List<ArcInst> interiorArcs = new ArrayList<ArcInst>();
241
 
                for(Iterator<Connection> it = ni.getConnections(); it.hasNext(); )
 
247
                for(Iterator<Connection> it = getConnections(ni); it.hasNext(); )
 
248
//              for(Iterator<Connection> it = ni.getConnections(); it.hasNext(); )
242
249
                {
243
250
                        Connection con = it.next();
244
251
                        ArcInst ai = con.getArc();
290
297
        {
291
298
                // build a list of the rigid arcs on this nodeinst
292
299
                List<Connection> rigidArcs = new ArrayList<Connection>();
293
 
                for(Iterator<Connection> it = ni.getConnections(); it.hasNext(); )
 
300
                for(Iterator<Connection> it = getConnections(ni); it.hasNext(); )
 
301
//              for(Iterator<Connection> it = ni.getConnections(); it.hasNext(); )
294
302
                {
295
303
                        Connection con = it.next();
296
304
                        ArcInst ai = con.getArc();
430
438
        {
431
439
                // build a list of the flexible arcs on this nodeinst
432
440
                List<Connection> flexArcs = new ArrayList<Connection>();
433
 
                for(Iterator<Connection> it = ni.getConnections(); it.hasNext(); )
 
441
                for(Iterator<Connection> it = getConnections(ni); it.hasNext(); )
 
442
//              for(Iterator<Connection> it = ni.getConnections(); it.hasNext(); )
434
443
                {
435
444
                        Connection con = it.next();
436
445
                        ArcInst ai = con.getArc();
448
457
                if (flexArcs.size() == 0) return;
449
458
 
450
459
                // look at all of the flexible arcs on this nodeinst
 
460
//        long startTime = System.currentTimeMillis();
451
461
                for(Connection thisEnd : flexArcs)
452
462
                {
453
463
            ArcInst ai = thisEnd.getArc();
635
645
                                ") and tail=("+newPts[ArcInst.TAILEND].getX()+","+newPts[ArcInst.TAILEND].getY()+")");
636
646
                        doMoveArcInst(ai, newPts[ArcInst.HEADEND], newPts[ArcInst.TAILEND], AI_FLEX);
637
647
                }
 
648
//        long stopTime = System.currentTimeMillis();
 
649
//        System.out.println("Moving in modFlex took " + (stopTime - startTime));
638
650
        }
639
651
 
640
652
        /**
655
667
                // look for longest other arc on "ono" to determine proper end position
656
668
                double bestDist = Double.NEGATIVE_INFINITY;
657
669
                ArcInst bestAI = null;
658
 
                for(Iterator<Connection> it = ai.getPortInst(thatEndIndex).getConnections(); it.hasNext(); )
659
 
//              for(Iterator<Connection> it = ono.getConnections(); it.hasNext(); )
 
670
                for(Iterator<Connection> it = getConnections(ai.getPortInst(thatEndIndex)); it.hasNext(); )
 
671
//              for(Iterator<Connection> it = ai.getPortInst(thatEndIndex).getConnections(); it.hasNext(); )
660
672
                {
661
673
                        Connection con = it.next();
662
674
                        ArcInst oai = con.getArc();
861
873
                Rectangle2D no2Bounds = no2pi.getPoly().getBounds2D();
862
874
                Point2D no2Pt = new Point2D.Double(no2Bounds.getCenterX(), no2Bounds.getCenterY());
863
875
 
864
 
                ArcInst ar1 = ArcInst.newInstanceBase(ap, wid, fpi, no2pi, headPt, no2Pt, null, 0);
865
 
//              ArcInst ar1 = ArcInst.newInstanceFull(ap, wid, fpi, no2pi, headPt, no2Pt, null, 0);
 
876
        int arcFlags = ai.getD().flags;
 
877
        String arcName = ai.getName();
 
878
        ai.kill(); // !!! See ai2.copyVarsFrom(ai) below
 
879
 
 
880
        int flags1 = ImmutableArcInst.TAIL_NEGATED.set(arcFlags, false);
 
881
                ArcInst ar1 = ArcInst.newInstanceBase(ap, wid, fpi, no2pi, headPt, no2Pt, null, 0, flags1);
866
882
                if (ar1 == null) return;
867
 
        ar1.copyConstraintsFrom(ai);
868
 
//              ar1.copyStateBits(ai);
 
883
//        ar1.copyConstraintsFrom(ai);
869
884
//              if (ai.isHeadNegated()) ar1.setHeadNegated(true);
870
 
                ArcInst ar2 = ArcInst.newInstanceBase(ap, wid, no2pi, no1pi, no2Pt, no1Pt, null, 0);
871
 
//              ArcInst ar2 = ArcInst.newInstanceFull(ap, wid, no2pi, no1pi, no2Pt, no1Pt, null, 0);
 
885
 
 
886
        int flags2 = ImmutableArcInst.TAIL_NEGATED.set(arcFlags, false);
 
887
        flags2 = ImmutableArcInst.HEAD_NEGATED.set(flags2, false);
 
888
                ArcInst ar2 = ArcInst.newInstanceBase(ap, wid, no2pi, no1pi, no2Pt, no1Pt, arcName, 0, flags2);
872
889
                if (ar2 == null) return;
873
 
        ar2.copyPropertiesFrom(ai);
874
 
//              ar2.copyStateBits(ai);
875
 
                ArcInst ar3 = ArcInst.newInstanceBase(ap, wid, no1pi, tpi, no1Pt, tailPt, null, 0);
876
 
//              ArcInst ar3 = ArcInst.newInstanceFull(ap, wid, no1pi, tpi, no1Pt, tailPt, null, 0);
 
890
        ar2.copyVarsFrom(ai); // !!! Referencing killed ai may cause problem in future versions
 
891
        ar2.copyTextDescriptorFrom(ai, ArcInst.ARC_NAME);
 
892
//        ar2.copyPropertiesFrom(ai);
 
893
 
 
894
        int flags3 = ImmutableArcInst.HEAD_NEGATED.set(arcFlags, false);
 
895
                ArcInst ar3 = ArcInst.newInstanceBase(ap, wid, no1pi, tpi, no1Pt, tailPt, null, flags3);
877
896
                if (ar3 == null) return;
878
 
        ar3.copyConstraintsFrom(ai);
879
 
//              ar3.copyStateBits(ai);
880
 
                if (ai.isTailNegated()) ar3.setTailNegated(true);
 
897
//        ar3.copyConstraintsFrom(ai);
 
898
//              if (ai.isTailNegated()) ar3.setTailNegated(true);
881
899
                if (ar1 == null || ar2 == null || ar3 == null)
882
900
                {
883
901
                        System.out.println("Problem creating jog arcs");
890
908
                setChangeClock(ar3, arctyp);
891
909
 
892
910
                // now kill the arcinst
893
 
                ar2.copyTextDescriptorFrom(ai, ArcInst.ARC_NAME);
894
 
                ai.kill();
895
 
                String oldName = ai.getName();
896
 
                if (oldName != null) ar2.setName(oldName);
 
911
//              ar2.copyTextDescriptorFrom(ai, ArcInst.ARC_NAME);
 
912
//              ai.kill();
 
913
//              String oldName = ai.getName();
 
914
//              if (oldName != null) ar2.setName(oldName);
897
915
        }
898
916
 
899
917
        /**
1030
1048
        if (oldD == null) return false;
1031
1049
        return ai.getHeadLocation() != oldD.headLocation || ai.getTailLocation() != oldD.tailLocation;
1032
1050
    }
 
1051
    
 
1052
    private boolean hasExports(NodeInst ni) {
 
1053
        return m.hasExports(ni.getD().nodeId);
 
1054
    }
 
1055
        /**
 
1056
         * Method to return an Iterator over all Connections on this NodeInst.
 
1057
         * @return an Iterator over all Connections on this NodeInst.
 
1058
         */
 
1059
    private Iterator<Connection> getConnections(NodeInst ni) {
 
1060
        return new ConnectionIterator(ni.getD().nodeId);
 
1061
    }
 
1062
 
 
1063
        /**
 
1064
         * Method to return an Iterator over Connections on this PortInst since portIndex.
 
1065
         * @return an Iterator over Connections on this NodeInst since portIndex.
 
1066
         */
 
1067
    Iterator<Connection> getConnections(PortInst pi) {
 
1068
        return new ConnectionIterator(pi.getNodeInst().getD().nodeId, pi.getPortProto().getId().getChronIndex());
 
1069
    }
 
1070
 
 
1071
    private class ConnectionIterator implements Iterator<Connection> {
 
1072
        private final ImmutableArrayList<ImmutableArcInst> arcs;
 
1073
        private final int nodeId;
 
1074
        private final int chronIndex;
 
1075
        int i;
 
1076
        ArcInst nextAi;
 
1077
        int nextConnIndex;
 
1078
 
 
1079
        ConnectionIterator(int nodeId) {
 
1080
            arcs = m.getArcs();
 
1081
            chronIndex = -1;
 
1082
            this.nodeId = nodeId;
 
1083
            i = m.searchConnectionByPort(nodeId, 0);
 
1084
            findNext();
 
1085
        }
 
1086
        ConnectionIterator(int nodeId, int chronIndex) {
 
1087
            arcs = m.getArcs();
 
1088
            this.nodeId = nodeId;
 
1089
            this.chronIndex = chronIndex;
 
1090
            i = m.searchConnectionByPort(nodeId, chronIndex);
 
1091
            findNext();
 
1092
        }
 
1093
        public boolean hasNext() { return nextAi != null; }
 
1094
        public Connection next() {
 
1095
            if (nextAi == null)
 
1096
                throw new NoSuchElementException();
 
1097
            Connection con = nextAi.getConnection(nextConnIndex);
 
1098
            findNext();
 
1099
            return con;
 
1100
        }
 
1101
        public void remove() { throw new UnsupportedOperationException(); }
 
1102
 
 
1103
        private void findNext() {
 
1104
            for (; i < m.connections.length; i++) {
 
1105
                int con = m.connections[i];
 
1106
                ImmutableArcInst a = arcs.get(con >>> 1);
 
1107
                int endIndex = con & 1;
 
1108
                int endNodeId = endIndex != 0 ? a.headNodeId : a.tailNodeId;
 
1109
                if (endNodeId != nodeId) break;
 
1110
                if (chronIndex >= 0) {
 
1111
                    PortProtoId endProtoId = endIndex != 0 ? a.headPortId : a.tailPortId;
 
1112
                    if (endProtoId.getChronIndex() != chronIndex) break;
 
1113
                }
 
1114
                ArcInst ai = cell.getArcById(a.arcId);
 
1115
                if (ai != null) {
 
1116
                    nextAi = ai;
 
1117
                    nextConnIndex = endIndex;
 
1118
                    i++;
 
1119
                    return;
 
1120
                }
 
1121
            }
 
1122
            nextAi = null;
 
1123
        }
 
1124
    }
 
1125
 
1033
1126
}
1034
1127
 
1035
1128
//    private HashMap/*<NodeInst,RigidCluster>*/ makeRigidClusters() {