def mouse_move_object(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return # remove from initiated set session.erase_el(command[1]) command = command[2] # check if it's a mouse move to object command if not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_move_obj], sc_core.pm.SC_CONST): return # remove command from initiated set sc_utils.removeFromSet(session, command, keynodes.ui.init_base_user_cmd) # make command activated sc_utils.appendIntoSet(session, _segment, command, keynodes.ui.active_base_user_cmd, sc_core.pm.SC_CONST | sc_core.pm.SC_POS) # get target object object = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, 0), True, 3) if not object: return object = object[2] obj = ScObject._sc2Objects(object) if len(obj) == 0: return obj = obj[0] # print obj._getScAddr().this # FIXME: find element in specified window (root window) init_pos = (0, 0) # target_pos = None # if isinstance(obj, suit.core.objects.ObjectDepth): # target_pos = render_engine.pos3dTo2dWindow(obj.getPosition()) # else: # target_pos = obj.getCenter() cmd = commands.MouseMove(init_pos, obj) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def mouse_move_object(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return # remove from initiated set session.erase_el(command[1]) command = command[2] # check if it's a mouse move to object command if not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_move_obj], sc_core.pm.SC_CONST): return # remove command from initiated set sc_utils.removeFromSet(session, command, keynodes.ui.init_base_user_cmd) # make command activated sc_utils.appendIntoSet(session, _segment, command, keynodes.ui.active_base_user_cmd, sc_core.pm.SC_CONST | sc_core.pm.SC_POS) # get target object object = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, 0), True, 3) if not object: return object = object[2] obj = ScObject._sc2Objects(object) if len(obj) == 0: return obj = obj[0] # print obj._getScAddr().this # FIXME: find element in specified window (root window) init_pos = (0, 0) # target_pos = None # if isinstance(obj, suit.core.objects.ObjectDepth): # target_pos = render_engine.pos3dTo2dWindow(obj.getPosition()) # else: # target_pos = obj.getCenter() cmd = commands.MouseMove(init_pos, obj) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def finish_callback(cmd): session = Kernel.session() # remove command from active commands set sc_utils.removeFromSet(session, cmds[cmd], keynodes.ui.active_base_user_cmd) # append command into finished command set sc_utils.appendIntoSet(session, Kernel.segment(), cmds[cmd], keynodes.ui.finish_base_user_cmd, sc_core.pm.SC_CONST | sc_core.pm.SC_POS) cmds.pop(cmd) cmd.delete()
def mouse_move_to_empty_place(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return command = command[2] # check if it's a mouse move to emty place command if not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_move_to_empty_place], sc_core.pm.SC_CONST): return # remove command from initiated set sc_utils.removeFromSet(session, command, keynodes.ui.init_base_user_cmd) # make command activated sc_utils.appendIntoSet(session, _segment, command, keynodes.ui.active_base_user_cmd, sc_core.pm.SC_CONST | sc_core.pm.SC_POS) window_width = render_engine._ogreViewport.getActualWidth() window_height = render_engine._ogreViewport.getActualHeight() kernel = Kernel.getSingleton() init_pos = (window_width / 2, window_height / 2) # check whether there is object under the mouse cursor objects = kernel.getRootSheet()._getObjectsUnderMouse(True, True, init_pos) # looking for a place without object while len(objects) > 0: init_pos = calculate_next_mouse_position(init_pos, window_height, window_width, 30, 30) objects = kernel.getRootSheet()._getObjectsUnderMouse( True, True, init_pos) cmd = commands.MouseMoveTo(init_pos) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def mouse_move_to_empty_place(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return command = command[2] # check if it's a mouse move to emty place command if not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_move_to_empty_place], sc_core.pm.SC_CONST): return # remove command from initiated set sc_utils.removeFromSet(session, command, keynodes.ui.init_base_user_cmd) # make command activated sc_utils.appendIntoSet(session, _segment, command, keynodes.ui.active_base_user_cmd, sc_core.pm.SC_CONST | sc_core.pm.SC_POS) window_width = render_engine._ogreViewport.getActualWidth() window_height = render_engine._ogreViewport.getActualHeight() kernel = Kernel.getSingleton() init_pos = (window_width / 2, window_height / 2) # check whether there is object under the mouse cursor objects = kernel.getRootSheet()._getObjectsUnderMouse(True, True, init_pos) # looking for a place without object while len(objects) > 0: init_pos = calculate_next_mouse_position(init_pos, window_height, window_width, 30, 30) objects = kernel.getRootSheet()._getObjectsUnderMouse(True, True, init_pos) cmd = commands.MouseMoveTo(init_pos) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def cmd_finished(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.finish_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return # remove finished state (that need to replay it in future) session.erase_el(command[1]) command = command[2] # trying to find next command res = sc_utils.searchOneShotFullBinPairsAttrFromNode( session, command, keynodes.common.nrel_base_order, sc_core.pm.SC_CONST) if res is None: return next_command = res[2] # check if command isn't active if sc_utils.checkIncToSets(session, next_command, [keynodes.ui.active_base_user_cmd], sc_core.pm.SC_CONST): raise RuntimeWarning("Command %s is active" % str(next_command)) # if next command included into finished commands set, then we need to remove it from that set if sc_utils.checkIncToSets(session, next_command, [keynodes.ui.finish_base_user_cmd], sc_core.pm.SC_CONST): sc_utils.removeFromSet(session, next_command, keynodes.ui.finish_base_user_cmd) # append command into set of initialized commands sc_utils.appendIntoSet(session, Kernel.segment(), next_command, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_CONST)
def cmd_finished(_params, _segment): session = Kernel.session() # getting command node command = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.ui.finish_base_user_cmd, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if not command: return # remove finished state (that need to replay it in future) session.erase_el(command[1]) command = command[2] # trying to find next command res = sc_utils.searchOneShotFullBinPairsAttrFromNode(session, command, keynodes.common.nrel_base_order, sc_core.pm.SC_CONST) if res is None: return next_command = res[2] # check if command isn't active if sc_utils.checkIncToSets(session, next_command, [keynodes.ui.active_base_user_cmd], sc_core.pm.SC_CONST): raise RuntimeWarning("Command %s is active" % str(next_command)) # if next command included into finished commands set, then we need to remove it from that set if sc_utils.checkIncToSets(session, next_command, [keynodes.ui.finish_base_user_cmd], sc_core.pm.SC_CONST): sc_utils.removeFromSet(session, next_command, keynodes.ui.finish_base_user_cmd) # append command into set of initialized commands sc_utils.appendIntoSet(session, Kernel.segment(), next_command, keynodes.ui.init_base_user_cmd, sc_core.pm.SC_CONST)