Commits

Martin Vejnár  committed 36d4016

Pins.

  • Participants
  • Parent commits 0405121

Comments (0)

Files changed (1)

                 wire.x1, -wire.y1, wire.radius, wire.radius, angle > math.pi, 0 if wire.ccw else 1, wire.x2, -wire.y2,
                 self.color_map[layer.color], wire.width*2))
 
-    def print_pin(self, pin):
+    def print_pin(self, pin, mirror=False, rot=0):
         len = pin.length * 2540 * 10
 
         def _get_target(x, y, len, angle):
             rx, ry = _rotate_one(angle, len, 0)
             return x + rx, y + ry
 
+        def _get_target_xy(x, y, lenx, leny, angle):
+            rx, ry = _rotate_one(angle, lenx, leny)
+            return x + rx, y + ry
+
         if (pin.function & pin.PIN_FUNCTION_FLAG_CLK) != 0 and pin.length >= 1:
             p1, p2, p3 = _rotate(pin.angle, [(len, 9906), (len + 19810, 0), (len, -9906)])
 
 
             self.print_wire(wire)
 
+        factor = 0.7
         if pin.visible & pin.PIN_VISIBLE_FLAG_PIN:
-            factor = 0.7
+            o = Text()
+            o.value = pin.name.split('@')[0]
+            o.layer = 95
+            o.size = int(7620*2.5/2)
+            o.angle = pin.angle * 0x400
+            o.mirror = 0
+
             text_distance = 2540*15
-            layer = self.root.layer_map[95]
-            color = self.color_map[layer.color]
+            o.x, o.y = _get_target_xy(pin.x, pin.y, len + text_distance, -int(7620*2.5/2), pin.angle)
+            self.print_text(o, mirror=mirror, rotate=rot)
 
-            x, y = _get_target(pin.x, pin.y, len, pin.angle)
+        if 0 and (pin.visible & pin.PIN_VISIBLE_FLAG_PAD):
+            # TODO: we need to get the pad this pin is connected to
+            o = Text()
+            o.value = str(pin.angle)
+            # TODO: o.font, o.ratio
+            o.layer = 95
+            o.size = int(7620*2.5/2)
+            if pin.angle == 0:
+                o.angle = 0
+                o.mirror = True
+            elif pin.angle == 1:
+                o.angle = 3*0x400
+                o.mirror = True
+            elif pin.angle == 2:
+                o.angle = 0
+                o.mirror = False
+            elif pin.angle == 3:
+                o.angle = 0x400
+                o.mirror = False
 
-            if pin.angle == 0 or pin.angle == 1:
-                self.out.append("""<text x="%d" y="%d" fill="%s" font-size="%d">%s</text>""" % (
-                    x + text_distance * factor, -y + 7620 * factor, color, 2*15240 * factor, pin.name))
-            elif pin.angle == 2 or pin.angle == 3:
-                self.out.append("""<text text-anchor="end" x="%d" y="%d" fill="%s" font-size="%d">%s</text>""" % (
-                    x - text_distance * factor, -y + 7620 * factor, color, 2*15240 * factor, pin.name))
-
+            o.x, o.y = _get_target_xy(pin.x, pin.y, max(0, len - 2540 * 10), 2540 if pin.angle < 2 else -2540, pin.angle)
+            self.print_text(o, mirror=mirror, rotate=rot)
 
     def print_text(self, text, mirror=False, rotate=0):
         self.update_bb(text.x - text.size, text.y - text.size)
         right_adjust = text.mirror
         top_adjust = False
 
-        adjusted_angle = ((total_rot + rotate + (359.9 if text.mirror else 0.1)) % 360)
+        if mirror:
+            adjusted_outer_rot = -rotate
+        else:
+            adjusted_outer_rot = rotate
+
+        adjusted_angle = ((total_rot + adjusted_outer_rot + 359.9) % 360)
         flip = abs(180 - adjusted_angle) < 90
 
         trans = []
         self.bb_stack.append([0, 0, 0, 0])
         for wire in sym.wires:
             self.print_wire(wire)
-        for pin in sym.pins:
-            self.print_pin(pin)
         for poly in sym.polygons:
             self.print_polygon(poly)
         for rect in sym.rectangles:
         trans.append('rotate(%f)' % (-rot,))
         self.out.append("""<g transform="%s"><use xlink:href="#g%d"/>""" % (' '.join(trans), sym.group_id))
 
+        for pin in sym.pins:
+            self.print_pin(pin, mirror=inst.mirror, rot=inst.angle)
+
         if not inst.smashed:
             for text in sym.texts:
                 _print_text(text)