示例#1
0
    def apply(self, info):
        if (not (info.mSecond.bound().tl_Pt().y - info.mFirst.bound().br_Pt().y
                 <= self.mGroupDistanceVerticalTheshold)):
            return False

        for neighbour in info.mNeighbours:
            if (neighbour != info.mFirst and neighbour != info.mSecond
                    and RectUtil.above(info.mSecond, neighbour)
                    and RectUtil.below(info.mFirst, neighbour)):
                return False
        return True
示例#2
0
    def validateList(self, listMetadataRoot):
        alignmentType = listMetadataRoot.mAlignmentType
        groups = listMetadataRoot.mListItemMetadatas

        # We only support more than one base view
        for listItem in groups:
            if len(listItem.baseViews) <= 1:
                return False
        # and all base views of each list item should have same size
        currentSize = -sys.maxint - 1

        for listItem in groups:
            if (currentSize == -sys.maxint - 1):
                currentSize = len(listItem.baseViews)
            elif (currentSize != listItem.baseViews.size()):
                return False

        # They have to be align
        if alignmentType == RectUtil.ALIGNMENT_RIGHT:
            for i in range(len(groups) - 1):
                current = groups[i]
                _next = groups[i + 1]
                for currentBase in current.baseViews:
                    for nextBase in _next.baseViews:
                        if (not RectUtil.above(currentBase, nextBase)):
                            return False
        if alignmentType == RectUtil.ALIGNMENT_BOTTOM:
            for i in range(len(groups) - 1):
                current = groups[i]
                _next = groups[i + 1]
                for currentBase in current.baseViews:
                    for nextBase in _next.baseViews:
                        if (not RectUtil.onTheLeft(currentBase, nextBase)):
                            return False

        return True
示例#3
0
    def canGenerateListAndGetAdditionListInfo(self, listMetadataRoot):
        groups = listMetadataRoot.getListItemMetadatas()

        if len(groups) <= 1:
            return None

        newGroups = []
        ratio = 0
        # only allow list not too much different from each other in size
        alignmentType = listMetadataRoot.getAlignmentType()
        if alignmentType == RectUtil.ALIGNMENT_RIGHT:
            newGroups = []
            newGroups.extend(groups)
            newGroups.sort(key=cmp_to_key(RectUtil.getTopBottomComparator()))

            ratio = groups[0].bound.height * self.MAX_DISTANCE_RATIO_OF_LIST
            for i in range(len(groups) - 1):
                current = groups[i]
                _next = groups[i + 1]
                if (RectUtil.verticalDistance(current.bound, _next.bound) >
                        ratio):
                    return None
        if alignmentType == RectUtil.ALIGNMENT_BOTTOM:
            newGroups = []
            newGroups.extend(groups)
            newGroups.sort(key=cmp_to_key(RectUtil.getLeftRightComparator()))
            ratio = groups[0].bound.width * self.MAX_DISTANCE_RATIO_OF_LIST
            for i in range(len(groups) - 1):
                current = groups[i]
                _next = groups[i + 1]
                if (RectUtil.horizontalDistance(current.bound, _next.bound) >
                        ratio):
                    return None

        # and all base views of each list item should have same size
        currentSize = -sys.maxint - 1
        for listItem in groups:
            if (currentSize == -sys.maxint - 1):
                currentSize = len(listItem.baseViews)
            elif (currentSize != len(listItem.baseViews)):
                return None

        # same addition size
        currentSize = -sys.maxint - 1
        for listItem in groups:
            if (currentSize == -sys.maxint - 1):
                currentSize = len(listItem.additionalViews)
            elif currentSize != len(listItem.additionalViews):
                return None

        # We only support more than one base view
        for listItem in groups:
            if len(listItem.baseViews) <= 1:
                return None
        # They have to be align
        if alignmentType == RectUtil.ALIGNMENT_RIGHT:
            for i in range(len(groups) - 1):
                current = groups[i]
                _next = groups[i + 1]
                for currentBase in current.baseViews:
                    for nextBase in _next.baseViews:
                        if (not RectUtil.above(currentBase, nextBase)):
                            return None
        if alignmentType == RectUtil.ALIGNMENT_BOTTOM:
            for i in range(len(groups) - 1):
                current = groups[i]
                _next = groups[i + 1]
                for currentBase in current.baseViews:
                    for nextBase in _next.baseViews:
                        if (not RectUtil.onTheLeft(currentBase, nextBase)):
                            return None

        # We only support base view is image view for now
        for listItem in groups:
            for baseView in listItem.baseViews:
                if (baseView.mType != RectView.VIEW_TYPE_IMAGE):
                    return None

        # We already check that all additional view has same size
        sameLevelViews = []

        for listItemMetadata in groups:
            additionalViewRecusive = []
            for rectView in listItemMetadata.additionalViews:
                self.getAllLeaveViewRecusively(additionalViewRecusive,
                                               rectView,
                                               listItemMetadata.bound.x,
                                               listItemMetadata.bound.y)
            sameLevelViews.add(additionalViewRecusive)

        # make sure it all overlap and have same type
        if len(sameLevelViews) <= 1:
            return None

        # same recursive addition size
        currentSize = -sys.maxint - 1
        for listItem in sameLevelViews:
            if (currentSize == -sys.maxint - 1):
                currentSize = len(listItem)
            elif currentSize != len(listItem):
                return None

        firstList = sameLevelViews[0]
        for t in firstList:
            t.overlapFlag = True
            t.relativeViews.append(t)

        for i in range(len(sameLevelViews)):
            for t in firstList:
                for o in sameLevelViews[i]:
                    if (not o.overlapFlag and RectUtil.intersects(t, o)
                            and o.mType == t.mType):
                        o.overlapFlag = True
                        t.relativeViews.append(o)
                        break

        # Make sure all items is marked
        for listItem in sameLevelViews:
            for r in listItem:
                if (not r.overlapFlag):
                    return None

        # Make sure we get all relative view
        for t in firstList:
            if len(t.relativeViews) != len(groups):
                return None

        return firstList