mkeeter / kokopelli

Script-based CAD/CAM in Python (deprecated)
https://mattkeeter.com/projects/kokopelli
Other
299 stars 49 forks source link

PCB library. Rotating a component does not rotate the pin_labels #13

Open PartyTonight opened 10 years ago

PartyTonight commented 10 years ago

Hi Matt,

We are trying to figure out how to rotare the pin_labels, we tryed modifying the pin_labels property but there is something we are missing.

class Component(object): ''' Generic PCB component. ''' def init(self, x, y, rot=0, name=''): ''' Constructs a Component object x X position y Y position rotation angle (degrees) name String ''' self.x = x self.y = y self.rot = rot

    self.name = name

def __getitem__(self, i):
    if isinstance(i, str):
        try:
            pin = [p for p in self.pins if p.name == i][0]
        except IndexError:
            raise IndexError("No pin with name %s" % i)
    elif isinstance(i, int):
        try:
            pin = self.pins[i-1]
        except IndexError:
            raise IndexError("Pin %i is not in array" %i)
    return BoundPin(pin, self)

@property
def pads(self):
    pads = reduce(operator.add, [p.pad for p in self.pins])
    return s2d.move(s2d.rotate(pads, self.rot), self.x, self.y)

@property
def pin_labels(self):
    L = []
    for p in self.pins:
        p = BoundPin(p, self)
        if p.pin.name:
            L.append(text(p.pin.name, p.x, p.y, 0.03))
    pin_labels=reduce(operator.add, L) if L else None
    return s2d.rotate(pin_labels,self.rot)  #this raises error 'NoneType' object has no attribute 'map'

@property
def label(self):
    return text(self.name, self.x, self.y, 0.03)
PartyTonight commented 10 years ago

@property def pin_labels(self): L = [] for p in self.pins: p = BoundPin(p, self) if p.pin.name: L.append(text(p.pin.name, p.x, p.y, 0.03)) return s2d.rotate(reduce(operator.add, L),self.rot) if L else None

This rotates the labels but they are not in the correct position