コード例 #1
0
    def calc_nets(self, segments):
        """ Return a set of Nets from segments """

        points = {}  # (x,y) -> NetPoint

        def get_point(p):
            if p not in points:
                points[p] = NetPoint('%da%d' % p, *p)
            return points[p]

        # turn the (x, y) points into unique NetPoint objects
        segments = set((get_point(p1), get_point(p2)) for p1, p2 in segments)
        nets = []

        # Iterate over the segments, removing segments when added to a net
        while segments:
            seg = segments.pop()  # pick a point
            newnet = Net('')
            newnet.connect(seg)
            found = True

            while found:
                found = set()

                for seg in segments:  # iterate over segments
                    if newnet.connected(seg):  # segment touching the net
                        newnet.connect(seg)  # add the segment
                        found.add(seg)

                for seg in found:
                    segments.remove(seg)

            nets.append(newnet)

        return nets
コード例 #2
0
    def calc_nets(self, segments):
        """ Return a set of Nets from segments """

        points = {}  # (x,y) -> NetPoint

        def get_point(p):
            if p not in points:
                points[p] = NetPoint("%da%d" % p, *p)
            return points[p]

        # turn the (x, y) points into unique NetPoint objects
        segments = set((get_point(p1), get_point(p2)) for p1, p2 in segments)
        nets = []

        # Iterate over the segments, removing segments when added to a net
        while segments:
            seg = segments.pop()  # pick a point
            newnet = Net("")
            newnet.connect(seg)
            found = True

            while found:
                found = set()

                for seg in segments:  # iterate over segments
                    if newnet.connected(seg):  # segment touching the net
                        newnet.connect(seg)  # add the segment
                        found.add(seg)

                for seg in found:
                    segments.remove(seg)

            nets.append(newnet)

        return nets
コード例 #3
0
    def parse_net(self, args):
        """ Assembles a net from a list of junctions, segments, and labels. """
        thisnet = Net(args)
        subdata = defaultdict(list)
        for phrase in self.stream:
            print phrase
            cmd, _sep, args = phrase.partition(' ')
            if cmd not in ('J', 'S', 'A', 'L', 'Q', 'B'):
                self.stream.push(phrase)
                break
            print args
            k, v = self.parsenode(cmd)(args)
            subdata[k].append(v)
        # finish building thisnet
        for netpt in subdata['netpoint'][:]:
            # using a copy so that we can modify subdata['netpoint'] inside loop
            if netpt.point_id not in thisnet.points:
                thisnet.add_point(netpt)
            else:
                # oh yeah, a net can have a point more than once, because that
                # makes *great* sense.
                for point in netpt.connected_points:
                    thisnet.points[netpt.point_id].add_connected_point(point)
                for comp in netpt.connected_components:
                    thisnet.points[netpt.point_id].add_connected_component(comp)
                # update subdata['netpoint'] so that ref to netpt points to the
                # new combined point
                i = subdata['netpoint'].index(netpt)
                subdata['netpoint'][i] = thisnet.points[netpt.point_id]

        # yuck, passing in-band
        thisnet.ibpts = subdata['netpoint']

        for pt_a, pt_b in subdata['segment']:
            thisnet.connect((subdata['netpoint'][pt_a - 1],
                             subdata['netpoint'][pt_b - 1]))
        for annot in subdata['annot']:
            thisnet.add_annotation(annot)
            if '=' in annot.value:
                thisnet.add_attribute(*(annot.value.split('=', 1)))
        return ('net', thisnet)
コード例 #4
0
    def calc_nets(self, segments):
        """ Return a set of Nets from segments """

        points = {} # (x, y) -> NetPoint

        def get_point(point):
            """ Return a new or existing NetPoint for an (x,y) point """
            point = (make_length(point[0]), make_length(point[1]))
            if point not in points:
                points[point] = NetPoint('%da%d' % point, point[0], point[1])
            return points[point]

        # turn the (x, y) points into unique NetPoint objects
        segments = set((get_point(p1), get_point(p2)) for p1, p2 in segments)
        nets = []

        # Iterate over the segments, removing segments when added to a net
        while segments:
            seg = segments.pop() # pick a point
            newnet = Net('')
            newnet.connect(seg)
            found = True

            while found:
                found = set()

                for seg in segments: # iterate over segments
                    if newnet.connected(seg): # segment touching the net
                        newnet.connect(seg) # add the segment
                        found.add(seg)

                for seg in found:
                    segments.remove(seg)

            nets.append(newnet)

        return nets