Beispiel #1
0
    def compare_child_node_order(self, parent, node1, node2):
        def compare(x, y):
            x = x.duplicate()
            y = y.duplicate()
            while x.node1 == y.node1 and x.node1.group is not None:
                x.node1 = x.node1.group
                y.node1 = y.node1.group

            # cmp x.node1.order and y.node1.order
            if x.node1.order < y.node1.order:
                return -1
            elif x.node1.order == y.node1.order:
                return 0
            else:
                return 1

        edges = (DiagramEdge.find(parent, node1) +
                 DiagramEdge.find(parent, node2))
        edges.sort(key=cmp_to_key(compare))
        if len(edges) == 0:
            return 0
        elif edges[0].node2 == node2:
            return 1
        else:
            return -1
Beispiel #2
0
    def description_table(self, diagram):
        nodes = diagram.traverse_nodes
        widths = [25] + [50] * (len(RackItem.desctable) - 1)
        headers = [RackItem.attrname[name] for name in RackItem.desctable]

        descriptions = [n.to_desctable() for n in nodes()]
        descriptions.sort(key=cmp_to_key(directives.cmp_node_number))

        # records for total
        total = ['-', 'Total'] + [''] * (len(RackItem.desctable) - 2)
        total[2] = u("%dU") % sum(n.colheight for n in nodes() if n.colheight)
        total[3] = u("%.1fA") % sum(n.ampere for n in nodes() if n.ampere)
        total[4] = u("%.1fkg") % sum(n.weight for n in nodes() if n.weight)
        descriptions.append(total)

        for i in range(len(headers) - 1, -1, -1):
            if any(desc[i] for desc in descriptions):
                pass
            else:
                widths.pop(i)
                headers.pop(i)
                for desc in descriptions:
                    desc.pop(i)

        return self._description_table(descriptions, widths, headers)
Beispiel #3
0
    def description_table(self, diagram):
        nodes = diagram.traverse_nodes
        widths = [25] + [50] * (len(RackItem.desctable) - 1)
        headers = [RackItem.attrname[name] for name in RackItem.desctable]

        descriptions = [n.to_desctable() for n in nodes()]
        descriptions.sort(key=cmp_to_key(directives.cmp_node_number))

        # records for total
        total = ['-', 'Total'] + [''] * (len(RackItem.desctable) - 2)
        total[2] = "%dU" % sum(n.colheight for n in nodes() if n.colheight)
        total[3] = "%.1fA" % sum(n.ampere for n in nodes() if n.ampere)
        total[4] = "%.1fkg" % sum(n.weight for n in nodes() if n.weight)
        descriptions.append(total)

        for i in range(len(headers) - 1, -1, -1):
            if any(desc[i] for desc in descriptions):
                pass
            else:
                widths.pop(i)
                headers.pop(i)
                for desc in descriptions:
                    desc.pop(i)

        return self._description_table(descriptions, widths, headers)
Beispiel #4
0
    def set_node_height(self, node, height=0):
        xy = XY(node.xy.x, height)
        if self.is_marked(node.lane, xy):
            return False
        node.xy = xy
        self.mark_xy(node)

        def cmp(x, y):
            if x.xy.x < y.xy.y:
                return -1
            elif x.xy.x == y.xy.y:
                return 0
            else:
                return 1

        count = 0
        children = self.get_child_nodes(node)
        children.sort(key=cmp_to_key(cmp))
        for child in children:
            if child.id in self.heightRefs:
                pass
            elif node is not None and node.xy.x >= child.xy.x:
                pass
            else:
                if node.lane == child.lane:
                    h = height
                else:
                    h = 0

                while True:
                    if self.set_node_height(child, h):
                        child.xy = XY(child.xy.x, h)
                        self.mark_xy(child)
                        self.heightRefs.append(child.id)

                        count += 1
                        break
                    elif node.lane != child.lane:
                        h += 1
                    else:
                        if count == 0:
                            return False

                        h += 1

                if node.lane == child.lane:
                    height = h + 1

        return True
Beispiel #5
0
    def set_node_height(self, node, height=0):
        xy = XY(node.xy.x, height)
        if self.is_marked(node.lane, xy):
            return False
        node.xy = xy
        self.mark_xy(node)

        def cmp(x, y):
            if x.xy.x < y.xy.y:
                return -1
            elif x.xy.x == y.xy.y:
                return 0
            else:
                return 1

        count = 0
        children = self.get_child_nodes(node)
        children.sort(key=cmp_to_key(cmp))
        for child in children:
            if child.id in self.heightRefs:
                pass
            elif node is not None and node.xy.x >= child.xy.x:
                pass
            else:
                if node.lane == child.lane:
                    h = height
                else:
                    h = 0

                while True:
                    if self.set_node_height(child, h):
                        child.xy = XY(child.xy.x, h)
                        self.mark_xy(child)
                        self.heightRefs.append(child.id)

                        count += 1
                        break
                    elif node.lane != child.lane:
                        h += 1
                    else:
                        if count == 0:
                            return False

                        h += 1

                if node.lane == child.lane:
                    height = h + 1

        return True
Beispiel #6
0
    def description_table(self, diagram):
        nodes = diagram.traverse_nodes
        widths = [25] + [50] * (len(FieldItem.desctable) - 1)
        headers = [FieldItem.attrname[name] for name in FieldItem.desctable]

        descriptions = [n.to_desctable() for n in nodes()]
        descriptions.sort(key=cmp_to_key(directives.cmp_node_number))

        for i in range(len(headers) - 1, -1, -1):
            if any(desc[i] for desc in descriptions):
                pass
            else:
                widths.pop(i)
                headers.pop(i)
                for desc in descriptions:
                    desc.pop(i)

        return self._description_table(descriptions, widths, headers)
Beispiel #7
0
    def set_node_ypos(self, node, height=0):
        for x in range(node.colwidth):
            for y in range(node.colheight):
                xy = XY(node.xy.x + x, height + y)
                if xy in self.coordinates:
                    return False
        node.xy = XY(node.xy.x, height)
        self.mark_xy(node.xy, node.colwidth, node.colheight)

        def cmp(x, y):
            if x.xy.x < y.xy.y:
                return -1
            elif x.xy.x == y.xy.y:
                return 0
            else:
                return 1

        count = 0
        children = self.get_child_nodes(node)
        children.sort(key=cmp_to_key(cmp))

        grandchild = 0
        for child in children:
            if self.get_child_nodes(child):
                grandchild += 1

        prev_child = None
        for child in children:
            if child.id in self.heightRefs:
                pass
            elif node.xy.x >= child.xy.x:
                pass
            else:
                if isinstance(node, NodeGroup):
                    parent_height = self.get_parent_node_ypos(node, child)
                    if parent_height and parent_height > height:
                        height = parent_height

                if (prev_child and grandchild > 1 and
                   (not self.is_rhombus(prev_child, child))):
                    coord = [p.y for p in self.coordinates if p.x > child.xy.x]
                    if coord and max(coord) >= node.xy.y:
                        height = max(coord) + 1

                while True:
                    if self.set_node_ypos(child, height):
                        child.xy = XY(child.xy.x, height)
                        self.mark_xy(child.xy, child.colwidth, child.colheight)
                        self.heightRefs.append(child.id)

                        count += 1
                        break
                    else:
                        if count == 0:
                            return False

                        height += 1

                height += 1
                prev_child = child

        return True