Ejemplo n.º 1
0
    def _findPrintOrder(self):
        #Construct a hit map, where object_hit_map[n][m] == True says when printing object N the head will hit object M
        object_list = self._scene.getObjects()
        use_list = [False] * len(object_list)
        object_hit_map = [[]] * len(object_list)
        for n in xrange(0, len(object_list)):
            object_hit_map[n] = [False] * len(object_list)
            use_list[n] = self._scene.checkPlatform(object_list[n])
        for n in xrange(0, len(object_list)):
            if use_list[n]:
                for m in xrange(0, len(object_list)):
                    if n == m or not use_list[m]:
                        object_hit_map[n][m] = False
                    else:
                        object_hit_map[n][m] = polygon.polygonCollision(object_list[n].getHeadHitShape(), object_list[m].getObjectBoundary())

        for n in xrange(0, len(object_list)):
            for m in xrange(0, len(object_list)):
                if n != m and use_list[n] and use_list[m] and object_hit_map[n][m] and object_hit_map[m][n]:
                    return False

        #Generate a list of which indexes we all need to print and sort in a proper print order.
        index_list = []
        for n in xrange(0, len(object_list)):
            if use_list[n]:
                index_list.append(n)

        #Sort from least to most hit objects.
        index_list.sort(lambda a, b: sum(object_hit_map[a]) - sum(object_hit_map[b]))

        todo_list = [([], index_list)]
        while len(todo_list) > 0:
            done_list, index_list = todo_list.pop()
            for add_index in index_list:
                can_add = True
                #Check if this to-add object does not hit an already placed object.
                for idx in done_list:
                    if object_hit_map[add_index][idx]:
                        can_add = False
                        break
                if not can_add:
                    continue
                #Check if this to-add object does not block the placing of a later object.
                for idx in index_list:
                    if add_index != idx and object_hit_map[idx][add_index]:
                        can_add = False
                        break
                if not can_add:
                    continue

                if len(index_list) == 1:
                    #We are done, all items added. Return the order we found
                    return done_list + [add_index]

                #Add this option to the todo_list so it gets evaluated deeper.
                new_index_list = index_list[:]
                new_index_list.remove(add_index)
                todo_list.append((done_list + [add_index], new_index_list))
        return False
Ejemplo n.º 2
0
 def checkPlatform(self, obj):
     area = obj.getObjectBoundary()
     if self._machine is None:
         return False
     if obj.getMesh() is None:
         return False
     if obj.getSize()[2] > self._machine.getSettingValueByKeyFloat('machine_height'):
         return False
     if not polygon.fullInside(area, self._machine.getShape()):
         return False
     #Check the "no go zones"
     for poly in self._machine.getDisallowedZones():
         if polygon.polygonCollision(poly, area):
             return False
     return True