def __init__(self, **kwargs):
        self.start_pos = Point(kwargs['start'])
        self.end_pos = Point(kwargs['end'])

        polygone_line = [{
            'x': self.start_pos.x,
            'y': self.start_pos.y
        }, {
            'x': self.start_pos.x,
            'y': self.end_pos.y
        }, {
            'x': self.end_pos.x,
            'y': self.end_pos.y
        }, {
            'x': self.end_pos.x,
            'y': self.start_pos.y
        }, {
            'x': self.start_pos.x,
            'y': self.start_pos.y
        }]

        PolygoneLine.__init__(self,
                              polygone=polygone_line,
                              layer=kwargs.get('layer', 'F.SilkS'),
                              width=kwargs.get('width'))
    def __init__(self, **kwargs):
        Node.__init__(self)
        self.start_pos = Point(kwargs['start'])
        self.end_pos = Point(kwargs['end'])

        self.layer = kwargs.get('layer', 'F.SilkS')
        self.width = kwargs.get('width')
Beispiel #3
0
    def calculateBoundingBox(self):
        # TODO: finish implementation
        min_x = min(self.start_pos.x, self._calulateEndPos().x)
        min_y = min(self.start_pos.x, self._calulateEndPos().y)
        max_x = max(self.start_pos.x, self._calulateEndPos().x)
        max_y = max(self.start_pos.x, self._calulateEndPos().y)
        '''
        for angle in range(4):
            float_angle = angle * math.pi/2.

            start_angle = _calculateStartAngle(self)
            end_angle = start_angle + math.radians(self.angle)

            # TODO: +- pi border
            if float_angle < start_angle:
                continue
            if float_angle > end_angle:
                continue

            print("TODO: add angle side: {1}".format(float_angle))
        '''

        return Node.calculateBoundingBox({
            'min': Point((min_x, min_y)),
            'max': Point((max_x, max_y))
        })
Beispiel #4
0
 def _initSize(self, **kwargs):
     if not kwargs.get('size'):
         raise KeyError('pad size not declared (like "size=[1,1]")')
     if type(kwargs.get('size')) in [int, float]:
         # when the attribute is a simple number, use it for x and y
         self.size = Point([kwargs.get('size'), kwargs.get('size')])
     else:
         self.size = Point(kwargs.get('size'))
Beispiel #5
0
    def __init__(self, **kwargs):
        Node.__init__(self)
        self.center_pos = Point(kwargs['center'])
        self.start_pos = Point(kwargs['start'])
        self.angle = kwargs['angle']

        self.layer = kwargs.get('layer', 'F.SilkS')
        self.width = kwargs.get('width')
    def __init__(self, **kwargs):
        Node.__init__(self)
        self.start_pos = Point(kwargs['start'])
        self.end_pos = Point(kwargs['end'])

        self.layer = kwargs.get('layer', 'F.SilkS')
        self.width = kwargs.get('width', 0.12)  # TODO: auto detection

        self.virtual_childs = self._createChildNodes(self.start_pos, self.end_pos, self.layer, self.width)
    def __init__(self, **kwargs):
        Node.__init__(self)
        self.center_pos = Point(kwargs['center'])
        self.radius = kwargs['radius']

        self.end_pos = Point(
            [self.center_pos.x + self.radius, self.center_pos.y])

        self.layer = kwargs.get('layer', 'F.SilkS')
        self.width = kwargs.get('width')
    def calculateBoundingBox(self):
        width = len(self.text)*self.size['x']
        height = self.size['y']

        min_x = self.at[x]-width/2.
        min_y = self.at[y]-height/2.
        max_x = self.at[x]+width/2.
        max_y = self.at[y]+height/2.

        return Node.calculateBoundingBox({'min': Point(min_x, min_y), 'max': Point(max_x, max_y)})
Beispiel #9
0
    def calculateBoundingBox(self):
        render_start_pos = self.getRealPosition(self.start_pos)
        render_end_pos = self.getRealPosition(self.end_pos)

        min_x = min([render_start_pos.x, render_end_pos.x])
        min_y = min([render_start_pos.y, render_end_pos.y])
        max_x = max([render_start_pos.x, render_end_pos.x])
        max_y = max([render_start_pos.y, render_end_pos.y])

        return Node.calculateBoundingBox({'min': Point(min_x, min_y), 'max': Point(max_x, max_y)})
Beispiel #10
0
    def __init__(self, **kwargs):
        self.start_pos = Point(kwargs['start'])
        self.end_pos = Point(kwargs['end'])

        # If specifed, an 'offset' can be applied to the RectLine.
        # For example, creating a border around a given Rect of a specified size
        if kwargs.get('offset'):
            # offset for the rect line
            # e.g. for creating a rectLine 0.5mm LARGER than the given rect, or similar
            offset = [0, 0]

            # Has an offset / inset been specified?
            if type(kwargs['offset']) in [int, float]:
                offset[0] = offset[1] = kwargs['offset']
            elif type(kwargs['offset']) in [list, tuple] and len(
                    kwargs['offset']) == 2:
                # Ensure that all offset params are numerical
                if all([type(i) in [int, float] for i in kwargs['offset']]):
                    offset = kwargs['offset']

            # For the offset to work properly, start-pos must be top-left, and end-pos must be bottom-right
            x1 = min(self.start_pos.x, self.end_pos.x)
            x2 = max(self.start_pos.x, self.end_pos.x)

            y1 = min(self.start_pos.y, self.end_pos.y)
            y2 = max(self.start_pos.y, self.end_pos.y)

            # Put the offset back in
            self.start_pos.x = x1 - offset[0]
            self.start_pos.y = y1 - offset[1]

            self.end_pos.x = x2 + offset[0]
            self.end_pos.y = y2 + offset[1]

        polygone_line = [{
            'x': self.start_pos.x,
            'y': self.start_pos.y
        }, {
            'x': self.start_pos.x,
            'y': self.end_pos.y
        }, {
            'x': self.end_pos.x,
            'y': self.end_pos.y
        }, {
            'x': self.end_pos.x,
            'y': self.start_pos.y
        }, {
            'x': self.start_pos.x,
            'y': self.start_pos.y
        }]

        PolygoneLine.__init__(self,
                              polygone=polygone_line,
                              layer=kwargs['layer'],
                              width=kwargs.get('width'))
Beispiel #11
0
    def getRealPosition(self, coordinate, rotation=None):
        '''
        return position of point after applying all transformation and rotation operations
        '''
        if not self._parent:
            if rotation is None:
                return Point(coordinate)
            else:
                return Point(coordinate), rotation

        return self._parent.getRealPosition(coordinate, rotation)
Beispiel #12
0
    def __init__(self, **kwargs):
        Node.__init__(self)
        self.start_pos = Point(kwargs['start'])
        self.end_pos = Point(kwargs['end'])

        self.layer = kwargs.get('layer', 'F.SilkS')
        self.width = kwargs.get(
            'width', 0.15)  # TODO: better variation to get line width

        self.virtual_childs = self._createChildNodes(self.start_pos,
                                                     self.end_pos, self.layer,
                                                     self.width)
Beispiel #13
0
    def __init__(self, **kwargs):
        Node.__init__(self)
        self.type = kwargs['type']
        self.text = kwargs['text']
        self.at = Point(kwargs['at'])
        self.rotation = kwargs.get('rotation', 0)

        self.layer = kwargs['layer']
        self.size = Point(kwargs.get('size', [1, 1]))
        self.thickness = kwargs.get('thickness', 0.15)

        self.hide = kwargs.get('hide', False)
    def testInit(self):
        p1 = Point([1, 2, 3])
        self.assertEqual(p1.x, 1)
        self.assertEqual(p1.y, 2)
        self.assertEqual(p1.z, 3)

        p1_xy = Point([1, 2])
        self.assertEqual(p1_xy.x, 1)
        self.assertEqual(p1_xy.y, 2)
        self.assertEqual(p1_xy.z, 0)

        p2 = Point((4, 5, 6))
        self.assertEqual(p2.x, 4)
        self.assertEqual(p2.y, 5)
        self.assertEqual(p2.z, 6)

        p2_xy = Point((4, 5))
        self.assertEqual(p2_xy.x, 4)
        self.assertEqual(p2_xy.y, 5)
        self.assertEqual(p2_xy.z, 0)

        p3 = Point({'x': 7, 'y': 8, 'z': 9})
        self.assertEqual(p3.x, 7)
        self.assertEqual(p3.y, 8)
        self.assertEqual(p3.z, 9)

        p3_xy = Point({'x': 7, 'y': 8})
        self.assertEqual(p3_xy.x, 7)
        self.assertEqual(p3_xy.y, 8)
        self.assertEqual(p3_xy.z, 0)

        p3_empty = Point({})
        self.assertEqual(p3_empty.x, 0)
        self.assertEqual(p3_empty.y, 0)
        self.assertEqual(p3_empty.z, 0)

        p4 = Point(p1)
        self.assertEqual(p4.x, 1)
        self.assertEqual(p4.y, 2)
        self.assertEqual(p4.z, 3)

        p5 = Point(1, 2, 3)
        self.assertEqual(p5.x, 1)
        self.assertEqual(p5.y, 2)
        self.assertEqual(p5.z, 3)

        p5_xy = Point(1, 2)
        self.assertEqual(p5_xy.x, 1)
        self.assertEqual(p5_xy.y, 2)
        self.assertEqual(p5_xy.z, 0)
Beispiel #15
0
 def _initDrill(self, **kwargs):
     if self.type in [Pad.TYPE_THT, Pad.TYPE_NPTH]:
         if not kwargs.get('drill'):
             raise KeyError('drill size required (like "drill=1")')
         if type(kwargs.get('drill')) in [int, float]:
             # when the attribute is a simple number, use it for x and y
             self.drill = Point([kwargs.get('drill'), kwargs.get('drill')])
         else:
             self.drill = Point(kwargs.get('drill'))
         if self.drill.x < 0 or self.drill.y < 0:
             raise ValueError("negative drill size not allowed")
     else:
         self.drill = None
         if kwargs.get('drill'):
             pass  # TODO: throw warning because drill is not supported
    def testSub(self):
        p1 = Point([1, 2, 3])
        self.assertEqual(p1.x, 1)
        self.assertEqual(p1.y, 2)
        self.assertEqual(p1.z, 3)

        p2 = p1 - 5
        self.assertEqual(p2.x, -4)
        self.assertEqual(p2.y, -3)
        self.assertEqual(p2.z, -2)

        p3 = p1 - (-5)
        self.assertEqual(p3.x, 6)
        self.assertEqual(p3.y, 7)
        self.assertEqual(p3.z, 8)

        p4 = p1 - [4, 2, -2]
        self.assertEqual(p4.x, -3)
        self.assertEqual(p4.y, 0)
        self.assertEqual(p4.z, 5)

        p5 = p1 - [-5, -3]
        self.assertEqual(p5.x, 6)
        self.assertEqual(p5.y, 5)
        self.assertEqual(p5.z, 3)
Beispiel #17
0
    def _createChildNodes(self, start_pos, end_pos, layer, width):
        nodes = []

        cur_y_pos = min([start_pos.y, end_pos.y])
        max_y_pos = max([start_pos.y, end_pos.y])

        while (cur_y_pos + width) < max_y_pos:
            cur_y_pos += width
            new_node = Line(start=Point(start_pos.x, cur_y_pos),
                            end=Point(end_pos.x, cur_y_pos),
                            layer=layer,
                            width=width)
            new_node._parent = self
            nodes.append(new_node)

        return nodes
    def testDiv(self):
        p1 = Point([1, 2, 3])
        self.assertEqual(p1.x, 1)
        self.assertEqual(p1.y, 2)
        self.assertEqual(p1.z, 3)

        p2 = p1 / 5
        self.assertEqual(p2.x, 0.2)
        self.assertEqual(p2.y, 0.4)
        self.assertEqual(p2.z, 0.6)

        p3 = p1 / (-5)
        self.assertEqual(p3.x, -0.2)
        self.assertEqual(p3.y, -0.4)
        self.assertEqual(p3.z, -0.6)

        p4 = p1 / [4, 5, -2]
        self.assertEqual(p4.x, 0.25)
        self.assertEqual(p4.y, 0.4)
        self.assertEqual(p4.z, -1.5)

        p5 = p1 / [-5, -2]
        self.assertEqual(p5.x, -0.2)
        self.assertEqual(p5.y, -1)
        self.assertEqual(p5.z, 3)
    def testMul(self):
        p1 = Point([1, 2, 3])
        self.assertEqual(p1.x, 1)
        self.assertEqual(p1.y, 2)
        self.assertEqual(p1.z, 3)

        p2 = p1 * 5
        self.assertEqual(p2.x, 5)
        self.assertEqual(p2.y, 10)
        self.assertEqual(p2.z, 15)

        p3 = p1 * (-5)
        self.assertEqual(p3.x, -5)
        self.assertEqual(p3.y, -10)
        self.assertEqual(p3.z, -15)

        p4 = p1 * [4, 5, -2]
        self.assertEqual(p4.x, 4)
        self.assertEqual(p4.y, 10)
        self.assertEqual(p4.z, -6)

        p5 = p1 * [-5, -3]
        self.assertEqual(p5.x, -5)
        self.assertEqual(p5.y, -6)
        self.assertEqual(p5.z, 3)
    def __init__(self, **kwargs):
        Node.__init__(self)
        self.start_pos = Point(kwargs['start'])
        self.end_pos = Point(kwargs['end'])

        self.layer = kwargs.get('layer', 'F.SilkS')
        self.width = kwargs.get(
            'width', 0.15)  # TODO: better variation to get line width

        rect_line = RectLine(**kwargs)
        rect_line._parent = self

        rect_fill = RectFill(**kwargs)
        rect_fill._parent = self

        self.virtual_childs = [rect_line, rect_fill]
    def testAdd(self):
        p1 = Point([1, 2, 3])
        self.assertEqual(p1.x, 1)
        self.assertEqual(p1.y, 2)
        self.assertEqual(p1.z, 3)

        p2 = p1 + 5
        self.assertEqual(p2.x, 6)
        self.assertEqual(p2.y, 7)
        self.assertEqual(p2.z, 8)

        p3 = p1 + (-5)
        self.assertEqual(p3.x, -4)
        self.assertEqual(p3.y, -3)
        self.assertEqual(p3.z, -2)

        p4 = p1 + [4, 2, -2]
        self.assertEqual(p4.x, 5)
        self.assertEqual(p4.y, 4)
        self.assertEqual(p4.z, 1)

        p5 = p1 + [-5, -3]
        self.assertEqual(p5.x, -4)
        self.assertEqual(p5.y, -1)
        self.assertEqual(p5.z, 3)
Beispiel #22
0
    def getRealPosition(self, coordinate, rotation=None):
        if rotation is None:
            rotation = 0

        parsed_coordinate = Point(coordinate)

        phi = self.rotation * math.pi / 180
        rotation_coordinate = {
            'x':
            parsed_coordinate.x * math.cos(phi) +
            parsed_coordinate.y * math.sin(phi),
            'y':
            -parsed_coordinate.x * math.sin(phi) +
            parsed_coordinate.y * math.cos(phi)
        }

        if not self._parent:
            if rotation is None:
                return rotation_coordinate
            else:
                return rotation_coordinate, rotation + self.rotation
        else:
            if rotation is None:
                rotation = 0
            return self._parent.getRealPosition(rotation_coordinate,
                                                rotation + self.rotation)
Beispiel #23
0
    def calculateBoundingBox(self, outline=None):
        min_x, min_y = 0, 0
        max_x, max_y = 0, 0

        if outline:
            min_x = outline['min']['x']
            min_y = outline['min']['y']
            max_x = outline['max']['x']
            max_y = outline['max']['y']

        for child in self.getAllChilds():
            child_outline = child.calculateBoundingBox()

            min_x = min([min_x, child_outline['min']['x']])
            min_y = min([min_y, child_outline['min']['y']])
            max_x = max([max_x, child_outline['max']['x']])
            max_y = max([max_y, child_outline['max']['y']])

        return {'min': Point(min_x, min_y), 'max': Point(max_x, max_y)}
Beispiel #24
0
    def getRealPosition(self, coordinate, rotation=None):
        parsed_coordinate = Point(coordinate)

        # calculate translation
        translation_coordinate = {'x': parsed_coordinate.x + self.offset_x,
                                  'y': parsed_coordinate.y + self.offset_y}

        if not self._parent:
            if rotation is None:
                return translation_coordinate
            else:
                return translation_coordinate, rotation
        else:
            return self._parent.getRealPosition(translation_coordinate, rotation)
Beispiel #25
0
    def _getRenderTreeText(self):
        render_text = Node._getRenderTreeText(self)
        render_text += " ["

        node_strings = []
        for node in self.polygone_line:
            node_position = Point(node)
            node_strings.append("[x: {x}, y: {y}]".format(x=node_position.x,
                                                          y=node_position.y))

        if len(node_strings) <= 6:
            render_text += " ,".join(node_strings)
        else:
            # display only a few nodes of the beginning and the end of the polygone line
            render_text += " ,".join(node_strings[:3])
            render_text += " ,... ,"
            render_text += " ,".join(node_strings[-3:])

        render_text += "]"

        return render_text
 def __init__(self, **kwargs):
     Node.__init__(self)
     self.filename = kwargs['filename']
     self.at = Point(kwargs.get('at', [0, 0, 0]))
     self.scale = Point(kwargs.get('scale', [1, 1, 1]))
     self.rotate = Point(kwargs.get('rotate', [0, 0, 0]))
 def __init__(self, vertices=None):
     self.vertices = []
     if vertices != None:
         for vertex in vertices:
             self.vertices.append(Point(vertex))
Beispiel #28
0
    def _calulateEndPos(self):
        radius = self._calculateRadius()

        angle = self._calculateStartAngle() + math.radians(self.angle)

        return Point(math.sin(angle) * radius, math.cos(angle) * radius)
Beispiel #29
0
    def _initPosition(self, **kwargs):
        if not kwargs.get('at'):
            raise KeyError('center position not declared (like "at=[0,0]")')
        self.at = Point(kwargs.get('at'))

        self.rotation = kwargs.get('rotation', 0)
Beispiel #30
0
 def _initOffset(self, **kwargs):
     self.offset = Point(kwargs.get('offset', [0, 0]))