Example #1
0
    def __init__(self, tobj, **options):

        Group.__init__(self, **options)

        # XXX should we take a copy???
        self.targetobj = tobj.copy()

        if self.controlobj is None:
            self.controlobj = Dot(r=self.dot_r)

        # fix up target and control points
        if type(self.target) in (type(()), type([])):
            pass
        elif isinstance(self.target, P):
            self.target = [self.target]
        elif self.target is None:
            self.target = [P(0, 0)]
        else:
            raise ValueError, "don't understand target structure for Gate"

        if type(self.control) in (type(()), type([])):
            pass
        elif isinstance(self.control, P):
            self.control = [self.control]
        elif self.control is None:
            self.control = []
        else:
            raise ValueError, "don't understand control structure for Gate"

        self._make()
Example #2
0
def SWAP(**options):
    """
    Swap gate
    """
    x = Group(Path(P(-.1, .1), P(.1, -.1)), Path(P(-.1, -.1), P(.1, .1)))
    options['controlobj'] = options.get('controlobj', x)
    return Gate(x, **options)
Example #3
0
def NOT(**options):
    """
    NOT gate
    """
    r = .2
    return Gate(
        Group(Circle(r=r), Path(P(0, r), P(0, -r)), Path(P(-r, 0), P(r, 0))),
        **options)
Example #4
0
    def __init__(self, obj, **options):

        Circle.__init__(self, **options)
        Group.__init__(self, **options)

        bbox = obj.bbox()

        w = bbox.width + 2 * self.pad
        h = bbox.height + 2 * self.pad

        self.r = options.get('r', max(w, h) / 2.)

        self.append(
            Circle(r=self.r,
                   bg=self.bg,
                   fg=self.fg,
                   c=obj.c,
                   linewidth=self.linewidth,
                   dash=self.dash),
            obj,
        )
Example #5
0
    def __init__(self, **args):
        Group.__init__(self, **args)

        h = self.height
        w = self.width

        self.append(Rectangle(width=1.8 * h, height=h, bg=self.bg))

        p = Path(P(.1, .1),
                 C(0, 0),
                 P(w - .1, .1),
                 P(w - .2, .1),
                 C(0, 0),
                 P(.2, .1),
                 closed=1,
                 bg=self.mcolor,
                 fg=None)

        self.append(
            p,
            Path(P(w / 2., .1), U(self.angle, h * .9)),
        )
Example #6
0
    def __init__(self, object=None, **options):
        if object is not None:
            # use the object's boundingbox when width and height not supplied
            bb = object.bbox()
            w = bb.width + 2 * self.pad
            h = bb.height + 2 * self.pad

            self.width = options.get("width", max(w, self.width))
            self.height = options.get("height", max(h, self.height))
        Group.__init__(self, **options)

        if self.width > self.height:
            p = Path(P(0, 0),
                     P(0, self.height),
                     P(self.width - self.height / 2., self.height),
                     C(90, 0),
                     P(self.width, self.height / 2.),
                     C(180, 90),
                     P(self.width - self.height / 2., 0),
                     closed=1)
        else:

            p = Path(P(0, 0),
                     P(0, self.height),
                     C(90, 0),
                     P(self.width, self.height / 2.),
                     C(180, 90),
                     closed=1)

        p(bg=options.get("bg", self.bg), fg=options.get("fg", self.fg))

        self.append(p)
        if object is not None:
            # object looks better if it's slightly off centre
            # since one side is curved. pad/3 is about right
            object.c = P(self.width / 2. - self.pad / 3., self.height / 2.)
            self.append(object)
Example #7
0
    def __init__(self, obj, **options):

        Rectangle.__init__(self, **options)
        Group.__init__(self, **options)

        bbox = obj.bbox()

        w = bbox.width + 2 * self.pad
        h = bbox.height + 2 * self.pad

        self.width = options.get('width', w)
        self.height = options.get('height', h)

        self.append(
            Rectangle(width=self.width,
                      height=self.height,
                      bg=self.bg,
                      fg=self.fg,
                      c=obj.c,
                      r=self.r,
                      linewidth=self.linewidth,
                      dash=self.dash),
            obj,
        )
Example #8
0
def classicalpath(*paths):
    '''
    @return: classical path
    @param paths: 1 or more Path() objects
    '''
    g = Group()

    for path in paths:
        g.append(path.copy(linewidth=2, fg=Color(0)))

    # reuse these paths
    for path in paths:
        g.append(path(linewidth=1, fg=Color(1)))

    return g
Example #9
0
    def __init__(self, *gates, **options):
        self.starthang = options.get('hang', self.hang)
        self.endhang = options.get('hang', self.hang)
        Group.__init__(self, **options)

        sequence = list(gates)

        # parse the list ...
        wires = []
        named = {}
        basetime = 0
        while len(sequence) > 0:
            # the gate ...
            gate = sequence.pop(0)

            # the target ...
            t = sequence.pop(0)
            wires.append(t)

            # optional controls ...
            if len(sequence) > 0 and \
                    isinstance(sequence[0], (IntType, FloatType)):
                c = sequence.pop(0)
                wires.append(c)
            elif len(sequence) > 0 and \
                    isinstance(sequence[0], (TupleType, ListType)):
                c = sequence.pop(0)
                wires.extend(c)
            else:
                c = None

            g = self.setgate(gate, t, c)

            # optional time label ...
            if len(sequence) > 0 and isinstance(sequence[0], StringType):
                l = sequence.pop(0)
                if named.has_key(l):
                    # group already exists
                    named[l].append(g)
                else:
                    # create new named group
                    G = named[l] = Group(g)
                    self.append(G)
            else:
                self.append(g)

        L = 0
        for ii in self:
            L += ii.width + self.gatespacing
        L -= self.gatespacing

        # XXX add distribute's options
        Distribute(self, p1=P(0, 0), p2=P(L, 0))
        self.recalc_size()

        # XXX should check wires are ints

        # add wires ...
        x0 = self.w.x - self.starthang
        x1 = self.e.x + self.endhang
        if len(self.wires) == 0:
            for w in range(-min(wires), -max(wires) - 1, -1):
                wire = QWire().set(w * self.wirespacing, x0, x1)
                self.insert(0, wire)
                self.wires.append(wire)
            print self.wires
        else:
            #w=-int(min(wires))
            w = -1
            wirestmp = []
            for wire in self.wires:
                # if it already an instance this will have no effect
                # otherwise create an instance
                wire = apply(wire, ())
                wire.set(w * self.wirespacing, x0, x1)
                self.insert(0, wire)
                wirestmp.append(wire)
                w -= 1
            self.wires = wirestmp
Example #10
0
 def __init__(self, **options):
     Group.__init__(self, **options)