def append_pose(self, context):
    global pd
    # validate new action
    pos0 = pd.current_action.p0
    pos1 = pd.current_action.p1

    idx = bpy.context.scene.selected_robot_props.prop_robot_id
    robot = robot_tools.RobotSet().getRobot(idx)
    robot_obj = bpy.data.objects[robot.name]
    area_robot_obj = bpy.data.objects[robot.area_name]

    res = is_colliding(idx, robot_obj, area_robot_obj, pos0, pos1)

    if res:
        self.report({'ERROR'}, "Collision detected: Robot will collide if takes this path")
        return {'FINISHED'}
    else:
        self.report({'INFO'}, "Undetected collision")

    # Guardamos nueva action y dibujamos la informacion para la action previa
    pd.current_action.draw_annotation(context)
    pc.TempPathContainer().appendAction(pd.current_action)

    # Siguiente action
    p0 = pd.current_action.p1
    p1 = pd.current_action.p1
    pd.current_action = path.Action(p0, p1)

    cl.CursorListener.select_cursor()

    return {'FINISHED'}
    def notifyStop(self, operator):
        pathContainer = pc.PathContainer()
        temp = pc.TempPathContainer()

        temp.pushActions()

        del self.current_action
        self.current_action = None
        showCeil()
    def execute(self, context):
        global pd

        for obj in context.selected_objects:
            for action_index, action in enumerate(pc.TempPathContainer()):
                if obj.name_full == action._arrow:

                    next_action_index = -1
                    if len(pc.TempPathContainer()) > action_index + 1:
                        next_action_index = action_index + 1

                    # Comprobar colision
                    pos0 = action.p0
                    pos1 = pd.current_action.p1 if next_action_index < 0 else pc.TempPathContainer()[next_action_index].p1

                    idx = bpy.context.scene.selected_robot_props.prop_robot_id
                    robot = robot_tools.RobotSet().getRobot(idx)
                    robot_obj = bpy.data.objects[robot.name]
                    area_robot_obj = bpy.data.objects[robot.area_name]

                    res = is_colliding(idx, robot_obj, area_robot_obj, pos0, pos1)

                    if res:
                        self.report({'ERROR'}, "Collision detected: Resulting path after deleting this point is not valid")
                        return {'FINISHED'}
                    else:
                        self.report({'INFO'}, "Undetected collision")



                    p0 = action.p0
                    if next_action_index < 0:
                        # mover punto fijo del current_action a action.p1
                        pd.current_action.move_fixed(p0)
                    else:
                        # mover punto fijo del next_action a action.p1
                        pc.TempPathContainer()[next_action_index].move_fixed(p0)
                    action.del_annotation()
                    pc.TempPathContainer().remove(action_index)

                    return {'FINISHED'}
        return {'FINISHED'}
    def execute(self, context):
        global pd

        for obj in context.selected_objects:
            for action_index, action in enumerate(pc.TempPathContainer()):
                if obj.name_full == action._arrow:
                    cl.CursorListener.set_pose(action.p1)
                    pd.current_action = action

                    if len(pc.TempPathContainer()) > action_index + 1:
                        next_action = pc.TempPathContainer()[action_index + 1]
                        pd.next_action = next_action

                    cl.CursorListener.select_cursor()

                    # remove anotation
                    pd.current_action.del_annotation()

                    context.scene.isModifying = True
                    return {'FINISHED'}
        return {'FINISHED'}
    def execute(self, context):
        import datetime as dt
        date = str(dt.datetime.now())

        global update_time
        update = update_time < pc.PathContainer().getLastUpdate()
        update_time = pc.PathContainer().getLastUpdate()

        log = "PathEditor | " + date + " | update = " + str(update) + " : " + str(update_time) + "\n"
        log += "\tPathContainer : " + str(len(pc.PathContainer())) + "\n"
        for p in pc.PathContainer().poses:
            log += "\t\t" + str(p) + "\n"
        log += "\tTempPathContainer : " + str(len(pc.TempPathContainer())) + "\n"
        self.report({'INFO'}, log)
        return {'FINISHED'}
def apply_modification(self, context):
    global pd
    # validate current_action and next_action
    pos0 = pd.current_action.p0
    pos1 = pd.current_action.p1
    pos2 = getattr(pd.next_action, 'p1', None)

    idx = bpy.context.scene.selected_robot_props.prop_robot_id
    robot = robot_tools.RobotSet().getRobot(idx)
    robot_obj = bpy.data.objects[robot.name]
    area_robot_obj = bpy.data.objects[robot.area_name]

    res_first_action = is_colliding(idx, robot_obj, area_robot_obj, pos0, pos1)

    res_second_action = is_colliding(idx, robot_obj, area_robot_obj, pos1, pos2) if pos2 is not None else False

    if res_first_action or res_second_action:
        self.report({'ERROR'}, "Collision detected: Robot will collide if takes this path")
        return {'FINISHED'}
    else:
        self.report({'INFO'}, "Undetected collision")

    # Guardamos nueva action y dibujamos la informacion para la action previa
    pd.current_action.draw_annotation(context)
    #pc.TempPathContainer().appendAction(pd.current_action)

    last_action = pc.TempPathContainer().getLastAction()
    pd.next_action = None

    # Siguiente action
    p1 = last_action.p1
    pd.current_action = path.Action(p1, p1)

    cl.CursorListener.select_cursor()
    context.scene.isModifying = False

    cl.CursorListener.set_pose(p1)

    return {'FINISHED'}
    def notifyStart(self, operator):
        bpy.context.scene.cursor.location = Vector((0.0, 0.0, 0.0))
        bpy.context.scene.cursor.rotation_euler = Euler((0.0, 0.0, 0.0))

        if len(robot_tools.RobotSet()) <= 0:
            operator.report({'ERROR'}, 'No robot available : add a robot to create a path')
            bpy.ops.scene.stop_cursor_listener('INVOKE_DEFAULT')
            return

        idx = bpy.context.scene.selected_robot_props.prop_robot_id
        assert idx >= 0 and idx in robot_tools.RobotSet(), "Error : no robot selected or not in list"

        robot = robot_tools.RobotSet().getRobot(idx)

        last_action = pc.PathContainer().getLastAction()

        if len(pc.PathContainer()) > 0 and last_action is not None:
            # Obtenemos ultima pose como inicio para crear nuevas poses
            loc = last_action.p1.loc
            angle = last_action.p1.rotation
        else:
            loc = robot.loc + Vector((bpy.context.scene.TOL, bpy.context.scene.TOL, bpy.context.scene.TOL))
            angle = robot.rotation

        # Movemos el cursor a la posicion de comienzo
        new_pose = path.Pose.fromVector(loc, angle)
        cl.CursorListener.set_pose(new_pose)

        self.current_action = path.Action(new_pose, new_pose)

        if len(pc.PathContainer()) == 0:
            self.current_action.set_first_action()

        cl.CursorListener.select_cursor()
        hideCeil()

        pc.TempPathContainer().loadActions()
 def poll(cls, context):
     return len(pc.TempPathContainer()) > 0 and not context.scene.isModifying