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: # Inserta una nueva action en medio de la pose seleccionada y la anterior p0 = action.p0 p1 = action.p1 xm, ym = (p1.x + p0.x)/2. , (p1.y + p0.y)/2. med_pose = path.Pose(xm, ym, p0.z, p0.alpha, p0.beta, p0.gamma) # Crea un nuevo action desde la pose añadida hasta la pose seleccionada next_action = path.Action(med_pose, p1) next_action.draw_annotation(context) # Se traslada la action seleccionada al punto intermedio # La pose de este action será el nuevo punto intermedio action.move(med_pose) action.del_annotation() pc.TempPathContainer().insert(action_index + 1, next_action) # Cambia pathdrawer pd.current_action = action pd.next_action = next_action cl.CursorListener.set_pose(action.p1) cl.CursorListener.select_cursor() context.scene.isModifying = True return {'FINISHED'} return {'FINISHED'}
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 loadPoses(self, poses_list, context=None): self.clear() for pose_index in range(len(poses_list) - 1): action = path.Action(poses_list[pose_index], poses_list[pose_index + 1]) if context is not None: action.draw_annotation(context) if pose_index == 0: action.set_first_action() PathContainer.__instance.__list.append(action) self.__last_update = int(time.time())
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()